91 lines
2.3 KiB
C++
91 lines
2.3 KiB
C++
#include "common.h"
|
|
|
|
#define ARR_LEN(a) (sizeof(a)/sizeof((a)[0]))
|
|
|
|
static_assert(ARR_LEN(SystemStatusString) == SYSSTAT_COUNT, "SystemStatusString size mismatch");
|
|
static_assert(ARR_LEN(SpeedSourceString) == SPEEDSOURCE_COUNT, "SpeedSourceString size mismatch");
|
|
static_assert(ARR_LEN(GPSBaudRateString) == GPSBAUDRATE_COUNT, "GPSBaudRateString size mismatch");
|
|
static_assert(ARR_LEN(CANSourceString) == CANSOURCE_COUNT, "CANSourceString size mismatch");
|
|
|
|
static const char kUnknownStr[] = "Unknown";
|
|
|
|
// ---- System status string table ----
|
|
const char *const SystemStatusString[SYSSTAT_COUNT] = {
|
|
"Startup",
|
|
"Normal",
|
|
"Rain",
|
|
"Wash",
|
|
"Purge",
|
|
"Error",
|
|
"Shutdown",
|
|
};
|
|
|
|
// String representation of SpeedSource enum
|
|
const char *const SpeedSourceString[SPEEDSOURCE_COUNT] = {
|
|
#ifdef FEATURE_ENABLE_TIMER
|
|
"Timer",
|
|
#endif
|
|
"Impuls",
|
|
"GPS",
|
|
"CAN-Bus",
|
|
"OBD2 (K-Line)",
|
|
"OBD2 (CAN)",
|
|
};
|
|
|
|
// String representation of GPSBaudRate enum
|
|
const char *const GPSBaudRateString[GPSBAUDRATE_COUNT] = {
|
|
"4800",
|
|
"9600",
|
|
"19200",
|
|
"38400",
|
|
"57600",
|
|
"115200",
|
|
};
|
|
|
|
// String representation of CANSource enum
|
|
const char *const CANSourceString[CANSOURCE_COUNT] = {
|
|
"KTM 890 Adventure R (2021)",
|
|
"KTM 1290 Superduke R (2023)",
|
|
};
|
|
|
|
// ---- Centralized, safe getters ----
|
|
|
|
// ---- Local helper for range check ----
|
|
static inline bool in_range(int v, int max_exclusive)
|
|
{
|
|
return (v >= 0) && (v < max_exclusive);
|
|
}
|
|
|
|
// ---- Safe getter ----
|
|
const char *ToString(tSystem_Status v)
|
|
{
|
|
const int i = static_cast<int>(v);
|
|
return in_range(i, static_cast<int>(SYSSTAT_COUNT))
|
|
? SystemStatusString[i]
|
|
: kUnknownStr;
|
|
}
|
|
|
|
const char *ToString(SpeedSource_t v)
|
|
{
|
|
const int i = static_cast<int>(v);
|
|
return in_range(i, static_cast<int>(SPEEDSOURCE_COUNT))
|
|
? SpeedSourceString[i]
|
|
: kUnknownStr;
|
|
}
|
|
|
|
const char *ToString(GPSBaudRate_t v)
|
|
{
|
|
const int i = static_cast<int>(v);
|
|
return in_range(i, static_cast<int>(GPSBAUDRATE_COUNT))
|
|
? GPSBaudRateString[i]
|
|
: kUnknownStr;
|
|
}
|
|
|
|
const char *ToString(CANSource_t v)
|
|
{
|
|
const int i = static_cast<int>(v);
|
|
return in_range(i, static_cast<int>(CANSOURCE_COUNT))
|
|
? CANSourceString[i]
|
|
: kUnknownStr;
|
|
}
|