Added track crc
This commit is contained in:
@@ -39,6 +39,7 @@ enum Type : uint8_t {
|
|||||||
DisplayMsgLapCounterStart,
|
DisplayMsgLapCounterStart,
|
||||||
DisplayMsgLapCounterLapTime,
|
DisplayMsgLapCounterLapTime,
|
||||||
DisplayMsgCorruptedConfig,
|
DisplayMsgCorruptedConfig,
|
||||||
|
DisplayMsgCorruptedTrack,
|
||||||
ConfigTrackDetect,
|
ConfigTrackDetect,
|
||||||
ConfigWriteTempTrack,
|
ConfigWriteTempTrack,
|
||||||
ConfigTrackDelete,
|
ConfigTrackDelete,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "data/config_store.h"
|
#include "data/config_store.h"
|
||||||
#include "data/general_store.h"
|
#include "data/general_store.h"
|
||||||
#include "base/router.h"
|
#include "base/router.h"
|
||||||
|
#include "data/eeprom_layout.h"
|
||||||
|
|
||||||
char *Cmd::trimArg(char *input) {
|
char *Cmd::trimArg(char *input) {
|
||||||
if (input == nullptr) {
|
if (input == nullptr) {
|
||||||
@@ -149,6 +150,14 @@ Cmd::CommandId Cmd::parseCommandName(const char *input) {
|
|||||||
return DbgSendBlankLap;
|
return DbgSendBlankLap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strcmp(input, "DBG_CORRUPT_CONFIG") == 0) {
|
||||||
|
return DbgCorruptConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(input, "DBG_CORRUPT_TRACK") == 0) {
|
||||||
|
return DbgCorruptTrack;
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp(input, "HELP") == 0) {
|
if (strcmp(input, "HELP") == 0) {
|
||||||
return HelpGlobal;
|
return HelpGlobal;
|
||||||
}
|
}
|
||||||
@@ -676,6 +685,72 @@ int Cmd::handleDbgSendBlankLap(unsigned short argc) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Cmd::handleDbgCorruptConfig(unsigned short argc) {
|
||||||
|
if (argc != 1) {
|
||||||
|
#ifdef ERROR
|
||||||
|
if (logger_ != nullptr) {
|
||||||
|
logger_->error("DBG_CORRUPT_CONFIG expects no arguments");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!debug_locked_) {
|
||||||
|
#ifdef INFO
|
||||||
|
if (logger_ != nullptr) {
|
||||||
|
logger_->info("Corrupting config");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
uint16_t corrupted = 0xFFFF;
|
||||||
|
EEPROM.put(eeprom_layout::configCRCAddr(), corrupted);
|
||||||
|
} else {
|
||||||
|
#ifdef INFO
|
||||||
|
if (logger_ != nullptr) {
|
||||||
|
logger_->info("Unable to run debug commands when not in God Mode");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Cmd::handleDbgCorruptTrack(unsigned short argc, char* argv[]) {
|
||||||
|
if (argc != 2) {
|
||||||
|
#ifdef ERROR
|
||||||
|
if (logger_ != nullptr) {
|
||||||
|
logger_->error("DBG_CORRUPT_TRACK expects 1 argument");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!debug_locked_) {
|
||||||
|
unsigned short id;
|
||||||
|
|
||||||
|
if (parseTrackSlotId(argv[1], id) != 0) {
|
||||||
|
#ifdef ERROR
|
||||||
|
if (logger_ != nullptr) {
|
||||||
|
logger_->error(String("ID out of range: ") + String(argv[1]));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#ifdef INFO
|
||||||
|
if (logger_ != nullptr) {
|
||||||
|
logger_->info("Corrupting track");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
uint16_t corrupted = 0xFFFF;
|
||||||
|
EEPROM.put(eeprom_layout::trackCRCAddr(id), corrupted);
|
||||||
|
} else {
|
||||||
|
#ifdef INFO
|
||||||
|
if (logger_ != nullptr) {
|
||||||
|
logger_->info("Unable to run debug commands when not in God Mode");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int Cmd::handleUnknownCommand(unsigned short argc, char *argv[]) {
|
int Cmd::handleUnknownCommand(unsigned short argc, char *argv[]) {
|
||||||
#ifdef ERROR
|
#ifdef ERROR
|
||||||
@@ -745,6 +820,12 @@ int Cmd::dispatchCommand(CommandId command, unsigned short argc, char *argv[]) {
|
|||||||
|
|
||||||
case DbgSendBlankLap:
|
case DbgSendBlankLap:
|
||||||
return this->handleDbgSendBlankLap(argc);
|
return this->handleDbgSendBlankLap(argc);
|
||||||
|
|
||||||
|
case DbgCorruptConfig:
|
||||||
|
return this->handleDbgCorruptConfig(argc);
|
||||||
|
|
||||||
|
case DbgCorruptTrack:
|
||||||
|
return this->handleDbgCorruptTrack(argc, argv);
|
||||||
|
|
||||||
case HelpGlobal:
|
case HelpGlobal:
|
||||||
return this->handleHelpGlobal(argc);
|
return this->handleHelpGlobal(argc);
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ private:
|
|||||||
DebugUnlock,
|
DebugUnlock,
|
||||||
DebugLock,
|
DebugLock,
|
||||||
DbgSendBlankLap,
|
DbgSendBlankLap,
|
||||||
|
DbgCorruptConfig,
|
||||||
|
DbgCorruptTrack,
|
||||||
HelpGlobal,
|
HelpGlobal,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -74,6 +76,8 @@ private:
|
|||||||
int handleDebugUnlock(unsigned short argc);
|
int handleDebugUnlock(unsigned short argc);
|
||||||
int handleDebugLock(unsigned short argc);
|
int handleDebugLock(unsigned short argc);
|
||||||
int handleDbgSendBlankLap(unsigned short argc);
|
int handleDbgSendBlankLap(unsigned short argc);
|
||||||
|
int handleDbgCorruptConfig(unsigned short argc);
|
||||||
|
int handleDbgCorruptTrack(unsigned short argc, char *argv[]);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int push(const Task &task) override;
|
int push(const Task &task) override;
|
||||||
|
|||||||
@@ -21,7 +21,10 @@ static constexpr char kGlobalHelpText[] =
|
|||||||
" BATTERY_SET_LOW,<voltage>\n"
|
" BATTERY_SET_LOW,<voltage>\n"
|
||||||
" THERMO_SET_LOW,<temperature>\n"
|
" THERMO_SET_LOW,<temperature>\n"
|
||||||
" THERMO_SET_HIGH,<temperature>\n"
|
" THERMO_SET_HIGH,<temperature>\n"
|
||||||
|
" THERMO_SET_OFFSET,<offset>\n"
|
||||||
" DEBUG_UNLOCK\n"
|
" DEBUG_UNLOCK\n"
|
||||||
" DEBUG_LOCK\n"
|
" DEBUG_LOCK\n"
|
||||||
" DBG_SEND_BLANK_LAP\n";
|
" DBG_SEND_BLANK_LAP\n"
|
||||||
|
" DBG_CORRUPT_CONFIG\n"
|
||||||
|
" DBG_CORRUPT_TRACK,<slot>\n";
|
||||||
} // namespace cmd_help
|
} // namespace cmd_help
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ int Config::writeTrack(const TrackData &track_data) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
EEPROM.put(eeprom_layout::trackSlotAddr(track_copy.id_), track_copy);
|
EEPROM.put(eeprom_layout::trackSlotAddr(track_copy.id_), track_copy);
|
||||||
|
uint16_t crc = crc16_ccitt((uint8_t*)&track_copy, sizeof(track_copy));
|
||||||
|
EEPROM.put(eeprom_layout::trackCRCAddr(track_copy.id_), crc);
|
||||||
config_.track_slot_occupied_[track_copy.id_ - 1] = true;
|
config_.track_slot_occupied_[track_copy.id_ - 1] = true;
|
||||||
this->writeConfig();
|
this->writeConfig();
|
||||||
#ifdef INFO
|
#ifdef INFO
|
||||||
@@ -153,6 +155,26 @@ int Config::readConfig() {
|
|||||||
}
|
}
|
||||||
configGlobalWrite(config_);
|
configGlobalWrite(config_);
|
||||||
router::sendAll(module::Config, task::AllConfigUpdated);
|
router::sendAll(module::Config, task::AllConfigUpdated);
|
||||||
|
uint8_t i = 1;
|
||||||
|
for (bool status : config_.track_slot_occupied_) {
|
||||||
|
TrackData track;
|
||||||
|
int res = getTrack(i, track);
|
||||||
|
if (res == 0) {
|
||||||
|
uint16_t track_crc;
|
||||||
|
EEPROM.get(eeprom_layout::trackCRCAddr(i), track_crc);
|
||||||
|
int crc_res = crc16_ccitt_check((uint8_t*)&track, sizeof(track), track_crc);
|
||||||
|
if (crc_res != 0) {
|
||||||
|
#ifdef ERROR
|
||||||
|
if (logger_ != nullptr) {
|
||||||
|
logger_->error("Corrupted track slot: " + String(track.id_));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
router::send(module::Lcd, task::DisplayMsgCorruptedTrack, 5000);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -390,6 +390,20 @@ int Lcd::renderMsgCorruptedConfig() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Lcd::renderMsgCorruptedTrack() {
|
||||||
|
if (!base_rendered_) {
|
||||||
|
this->clear();
|
||||||
|
display_->setCursor(3, 1);
|
||||||
|
this->print("CRITICAL ERROR");
|
||||||
|
display_->setCursor(2, 2);
|
||||||
|
this->print("CORRUPTED TRACK");
|
||||||
|
display_->setCursor(0, 3);
|
||||||
|
this->print("Serial for more info");
|
||||||
|
base_rendered_ = true;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int Lcd::push(const Task &task) { return queue_.push(task); }
|
int Lcd::push(const Task &task) { return queue_.push(task); }
|
||||||
|
|
||||||
Lcd::Lcd()
|
Lcd::Lcd()
|
||||||
@@ -609,6 +623,10 @@ int Lcd::loop(unsigned long timeout_ms) {
|
|||||||
case task::DisplayMsgCorruptedConfig:
|
case task::DisplayMsgCorruptedConfig:
|
||||||
base_rendered_ = false;
|
base_rendered_ = false;
|
||||||
activateMessage(screen::MsgCorruptedConfig, next_task.data_);
|
activateMessage(screen::MsgCorruptedConfig, next_task.data_);
|
||||||
|
|
||||||
|
case task::DisplayMsgCorruptedTrack:
|
||||||
|
base_rendered_ = false;
|
||||||
|
activateMessage(screen::MsgCorruptedTrack, next_task.data_);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -687,6 +705,10 @@ int Lcd::loop(unsigned long timeout_ms) {
|
|||||||
case screen::MsgCorruptedConfig:
|
case screen::MsgCorruptedConfig:
|
||||||
this->renderMsgCorruptedConfig();
|
this->renderMsgCorruptedConfig();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case screen::MsgCorruptedTrack:
|
||||||
|
this->renderMsgCorruptedTrack();
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ enum LcdScreen : uint8_t {
|
|||||||
MsgLapCounterStart,
|
MsgLapCounterStart,
|
||||||
MsgLapCounterLapTime,
|
MsgLapCounterLapTime,
|
||||||
MsgCorruptedConfig,
|
MsgCorruptedConfig,
|
||||||
|
MsgCorruptedTrack,
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace screen
|
} // namespace screen
|
||||||
@@ -81,6 +82,7 @@ private:
|
|||||||
int renderMsgLapCounterStart();
|
int renderMsgLapCounterStart();
|
||||||
int renderMsgLapCounterLapTime();
|
int renderMsgLapCounterLapTime();
|
||||||
int renderMsgCorruptedConfig();
|
int renderMsgCorruptedConfig();
|
||||||
|
int renderMsgCorruptedTrack();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int push(const Task &task) override;
|
int push(const Task &task) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user