Files
bobbycar-boardcomputer-firm…/main/taskmanager.cpp
T

178 lines
5.7 KiB
C++
Raw Normal View History

2021-12-05 00:50:37 +01:00
#include "taskmanager.h"
#include "sdkconfig.h"
2021-12-05 00:50:37 +01:00
// system includes
#include <iterator>
#include <chrono>
// esp-idf includes
#include <esp_log.h>
// 3rdparty lib includes
#include <schedulertask.h>
// local includes
#include "wifi_bobbycar.h"
#include "dpad.h"
#ifdef FEATURE_DPAD_3WIRESW
#include "dpad3wire.h"
#endif
#ifdef FEATURE_DPAD_5WIRESW
#include "dpad5wire.h"
#endif
#ifdef FEATURE_DPAD_5WIRESW_2OUT
#include "dpad5wire_2out.h"
#endif
#ifdef FEATURE_DPAD_6WIRESW
#include "dpad6wire.h"
#endif
#ifdef FEATURE_ROTARY
#include "rotary.h"
#endif
#ifdef FEATURE_MOSFETS
#include "mosfets.h"
#endif
2021-12-18 20:08:40 +01:00
#ifdef FEATURE_NTP
#include "time_bobbycar.h"
#endif
2021-12-19 01:55:48 +01:00
#include "potis.h"
2021-12-19 02:37:48 +01:00
#ifdef FEATURE_BLUETOOTH
#include "bluetooth_bobby.h"
2021-12-19 22:50:50 +01:00
#ifdef FEATURE_BMS
#include "bmsutils.h"
#endif
2021-12-19 02:37:48 +01:00
#endif
2021-12-19 03:33:51 +01:00
#ifdef FEATURE_CAN
#include "can.h"
#endif
2021-12-19 04:23:47 +01:00
#include "debuginputhandler.h"
2021-12-19 04:35:37 +01:00
#ifdef FEATURE_SERIAL
#include "serial_bobby.h"
#endif
2021-12-19 04:42:01 +01:00
#ifdef FEATURE_OTA
#include "ota.h"
#endif
2021-12-19 04:48:12 +01:00
#ifdef FEATURE_BLE
#include "ble_bobby.h"
#endif
2021-12-19 04:56:24 +01:00
#ifdef FEATURE_WEBSERVER
#include "webserver.h"
#endif
2021-12-19 16:42:45 +01:00
#ifdef FEATURE_LEDSTRIP
#include "ledstrip.h"
#endif
2021-12-19 16:48:42 +01:00
#ifdef FEATURE_ESPNOW
#include "espnowfunctions.h"
#endif
#ifdef FEATURE_CLOUD
#include "cloud.h"
#endif
#ifdef FEATURE_UDPCLOUD
#include "udpcloud.h"
#endif
2021-12-19 23:25:52 +01:00
#include "modes.h"
#include "drivingstatistics.h"
#ifdef FEATURE_DNS_NS
#include "dnsannounce.h"
#endif
#include "screens.h"
2021-12-05 00:50:37 +01:00
using namespace std::chrono_literals;
namespace {
constexpr const char * const TAG = "TASKS";
void not_needed() {}
2021-12-05 00:50:37 +01:00
espcpputils::SchedulerTask schedulerTasksArr[] {
espcpputils::SchedulerTask { "wifi", wifi_begin, wifi_update, 100ms },
#ifdef FEATURE_DPAD
2021-12-19 03:33:51 +01:00
espcpputils::SchedulerTask { "dpad", dpad::init, dpad::update, 20ms },
#endif
#ifdef FEATURE_DPAD_3WIRESW
2021-12-19 03:33:51 +01:00
espcpputils::SchedulerTask { "dpad3wire", dpad3wire::init, dpad3wire::update, 20ms },
#endif
#ifdef FEATURE_DPAD_5WIRESW
2021-12-19 03:33:51 +01:00
espcpputils::SchedulerTask { "dpad5wire", dpad5wire::init, dpad5wire::update, 20ms },
#endif
#ifdef FEATURE_DPAD_5WIRESW_2OUT
2021-12-19 03:33:51 +01:00
espcpputils::SchedulerTask { "dpad5wire_2out", dpad5wire_2out::init, dpad5wire_2out::update, 20ms },
#endif
#ifdef FEATURE_DPAD_6WIRESW
2021-12-19 03:33:51 +01:00
espcpputils::SchedulerTask { "dpad6wire", dpad6wire::init, dpad6wire::update, 20ms },
#endif
#ifdef FEATURE_ROTARY
2021-12-19 03:33:51 +01:00
espcpputils::SchedulerTask { "rotary", initRotary, updateRotary, 20ms },
#endif
#ifdef FEATURE_MOSFETS
2021-12-19 03:33:51 +01:00
espcpputils::SchedulerTask { "mosfets", init_mosfets, update_mosfets, 100ms },
#endif
2021-12-18 20:08:40 +01:00
#ifdef FEATURE_NTP
espcpputils::SchedulerTask { "time", initTime, updateTime, 100ms },
#endif
2021-12-19 03:33:51 +01:00
espcpputils::SchedulerTask { "potis", initPotis, readPotis, 20ms },
2021-12-19 02:37:48 +01:00
#ifdef FEATURE_BLUETOOTH
espcpputils::SchedulerTask { "bluetooth", bluetooth_init, bluetooth_update, 100ms },
2021-12-19 22:50:50 +01:00
#ifdef FEATURE_BMS
espcpputils::SchedulerTask { "bms", bms::init, bms::update, 100ms },
#endif
2021-12-19 02:37:48 +01:00
#endif
2021-12-19 03:33:51 +01:00
#ifdef FEATURE_CAN
2021-12-19 16:42:45 +01:00
espcpputils::SchedulerTask { "can", can::initCan, can::parseCanInput, 10ms },
2021-12-19 03:33:51 +01:00
#endif
2021-12-19 04:23:47 +01:00
espcpputils::SchedulerTask { "debuginput", initDebugInput, handleDebugInput, 50ms },
2021-12-19 04:35:37 +01:00
#ifdef FEATURE_SERIAL
espcpputils::SchedulerTask { "serial", initSerial, updateSerial, 50ms },
#endif
2021-12-19 04:42:01 +01:00
#ifdef FEATURE_OTA
espcpputils::SchedulerTask { "ota", initOta, handleOta, 50ms },
#endif
2021-12-19 04:48:12 +01:00
#ifdef FEATURE_BLE
espcpputils::SchedulerTask { "ble", initBle, handleBle, 100ms },
#endif
2021-12-19 04:56:24 +01:00
#ifdef FEATURE_WEBSERVER
espcpputils::SchedulerTask { "webserver", initWebserver, handleWebserver, 100ms },
#endif
2021-12-19 16:42:45 +01:00
#ifdef FEATURE_LEDSTRIP
espcpputils::SchedulerTask { "ledstrip", initLedStrip, updateLedStrip, 30ms },
#endif
2021-12-19 16:48:42 +01:00
#ifdef FEATURE_ESPNOW
espcpputils::SchedulerTask { "espnow", espnow::initESPNow, espnow::handle, 100ms },
#endif
#ifdef FEATURE_CLOUD
espcpputils::SchedulerTask { "cloud", initCloud, updateCloud, 50ms },
#endif
#ifdef FEATURE_UDPCLOUD
espcpputils::SchedulerTask { "udpcloud", udpCloudInit, udpCloudUpdate, 50ms },
#endif
2021-12-19 23:25:52 +01:00
espcpputils::SchedulerTask { "drivingmode", initDrivingMode, updateDrivingMode, 20ms },
espcpputils::SchedulerTask { "drivingstatistics", initStatistics, calculateStatistics, 100ms },
#ifdef FEATURE_DNS_NS
espcpputils::SchedulerTask { "dnsannounce", init_dns_announce, handle_dns_announce, 100ms },
#endif
espcpputils::SchedulerTask { "updateDisp", not_needed, updateDisplay, 20ms },
espcpputils::SchedulerTask { "redrawDisp", not_needed, redrawDisplay, 20ms },
2021-12-05 00:50:37 +01:00
};
} // namespace
cpputils::ArrayView<espcpputils::SchedulerTask> schedulerTasks{std::begin(schedulerTasksArr), std::end(schedulerTasksArr)};
2021-12-19 23:25:52 +01:00
const espcpputils::SchedulerTask &drivingModeTask = []() -> const espcpputils::SchedulerTask & {
auto iter = std::find_if(std::begin(schedulerTasksArr), std::end(schedulerTasksArr), [](const espcpputils::SchedulerTask &task){
return std::string_view{task.name()} == "drivingmode";
});
return *iter;
}();
2021-12-05 00:50:37 +01:00
void sched_pushStats(bool printTasks)
{
if (printTasks)
ESP_LOGI(TAG, "begin listing tasks...");
for (auto &schedulerTask : schedulerTasks)
schedulerTask.pushStats(printTasks);
if (printTasks)
ESP_LOGI(TAG, "end listing tasks");
}