add commit hash (manual!)

This commit is contained in:
Julian 2024-07-22 19:32:24 +02:00
parent a07d51f223
commit a4bea0d78b
4 changed files with 148 additions and 58 deletions

View File

@ -14,7 +14,7 @@
#define DRS_BUTTON_IDX (6)
#define DRS_PRESS_WAIT_CYCLES (10)
static drs_press_buf_cycles = 0;
static int drs_press_buf_cycles = 0;
void ui_thread_entry(ULONG _) {
GPIO_TypeDef *button_ports[NUM_BUTTONS] = {BTN1_GPIO_Port, BTN2_GPIO_Port,

View File

@ -29,6 +29,7 @@ cDefinitions:
cxxDefinitions:
- USE_HAL_DRIVER
- STM32H7A3xx
- COMPILER_GIT_BUILD_HASH="a07d51f"
asDefinitions: []
@ -170,3 +171,4 @@ customMakefileRules:
makeFlags:
# - -O # use this option when the output of make is mixed up only works for make version 4.0 and upwards
# - --silent # use this option to silence the output of the build
# - -j1

View File

@ -17,7 +17,7 @@ CountedEnum(DataFieldType, size_t, DF_TSState, DF_ASState, DF_ActiveMission,
DF_Speed, DF_BBal, DF_BPF, DF_BPR, DF_DistanceTotal, DF_TempMotL,
DF_TempMotR, DF_TempInvL, DF_TempInvR, DF_TempBrakeFL,
DF_TempBrakeFR, DF_TempBrakeRL, DF_TempBrakeRR, DF_LapBest,
DF_LapLast, DF_LVBatVoltage);
DF_LapLast, DF_LVBatVoltage, DF_GitBuildHash);
enum class NamedFieldKind { Float, Bool, Text, Int };

View File

@ -9,17 +9,27 @@
#include <algorithm>
#include <cstring>
#define _STRINGIZE(x) #x
#define STRINGIZE(x) _STRINGIZE(x)
#ifndef COMPILER_GIT_BUILD_HASH
#define COMPILER_GIT_BUILD_HASH "git id not found"
#endif
static const char* git_hash = STRINGIZE(COMPILER_GIT_BUILD_HASH);
#define VEH_FIELD(FIELD) []() { return (void *)&vehicle_state.FIELD; }
#define VEH_BIT_FIELD(FIELD) \
[]() { \
static int x; \
x = vehicle_state.FIELD; \
return (void *)&x; \
#define VEH_BIT_FIELD(FIELD) \
[]() { \
static int x; \
x = vehicle_state.FIELD; \
return (void *)&x; \
}
void *get_tsstate_text() {
void *get_tsstate_text()
{
const char *text;
switch (vehicle_state.ts_state) {
switch (vehicle_state.ts_state)
{
case TS_INACTIVE:
text = "INACT";
break;
@ -47,9 +57,11 @@ void *get_tsstate_text() {
return (void *)text;
}
void *get_asstate_text() {
void *get_asstate_text()
{
const char *text;
switch (vehicle_state.as_state) {
switch (vehicle_state.as_state)
{
case AS_OFF:
text = "OFF";
break;
@ -74,9 +86,11 @@ void *get_asstate_text() {
return (void *)text;
}
void *get_mission_text() {
void *get_mission_text()
{
const char *text;
switch (vehicle_state.active_mission) {
switch (vehicle_state.active_mission)
{
case MISSION_NONE:
text = "NONE";
break;
@ -107,9 +121,11 @@ void *get_mission_text() {
return (void *)text;
}
void *get_r2dprog_text() {
void *get_r2dprog_text()
{
const char *text;
switch (vehicle_state.r2d_progress) {
switch (vehicle_state.r2d_progress)
{
case R2D_NONE:
text = "NONE";
break;
@ -143,61 +159,106 @@ void *get_r2dprog_text() {
return (void *)text;
}
void *get_inichk_text() {
void *get_inichk_text()
{
return (void *)inichkstate_str(vehicle_state.ini_chk_state);
}
void *get_sdc_text() {
void *get_sdc_text()
{
const char *text;
if (vehicle_state.errors.sdc_bfl) {
if (vehicle_state.errors.sdc_bfl)
{
text = "BFL";
} else if (vehicle_state.errors.sdc_brl) {
}
else if (vehicle_state.errors.sdc_brl)
{
text = "BRL";
} else if (vehicle_state.errors.sdc_acc) {
}
else if (vehicle_state.errors.sdc_acc)
{
text = "ACC";
} else if (vehicle_state.errors.sdc_hvb) {
}
else if (vehicle_state.errors.sdc_hvb)
{
text = "HVB";
} else {
}
else
{
text = "CLOSED";
}
return (void *)text;
}
void *get_err_text() {
void *get_err_text()
{
const char *text;
if (vehicle_state.errors.err_sdc) {
if (vehicle_state.errors.err_sdc)
{
text = "SDC";
} else if (vehicle_state.errors.err_ams) {
}
else if (vehicle_state.errors.err_ams)
{
text = "AMS";
} else if (vehicle_state.errors.err_pdu) {
}
else if (vehicle_state.errors.err_pdu)
{
text = "PDU";
} else if (vehicle_state.errors.err_ini_chk) {
}
else if (vehicle_state.errors.err_ini_chk)
{
text = "IniChk";
} else if (vehicle_state.errors.err_con_mon) {
}
else if (vehicle_state.errors.err_con_mon)
{
text = "ConMon";
} else if (vehicle_state.errors.err_scs) {
}
else if (vehicle_state.errors.err_scs)
{
text = "SCS";
} else if (vehicle_state.errors.err_sbspd) {
}
else if (vehicle_state.errors.err_sbspd)
{
text = "sBSPD";
} else if (vehicle_state.errors.err_appsp) {
}
else if (vehicle_state.errors.err_appsp)
{
text = "APPSp";
} else if (vehicle_state.errors.err_as) {
}
else if (vehicle_state.errors.err_as)
{
text = "AS";
} else if (vehicle_state.errors.err_ros) {
}
else if (vehicle_state.errors.err_ros)
{
text = "ROS";
} else if (vehicle_state.errors.err_res) {
}
else if (vehicle_state.errors.err_res)
{
text = "RES";
} else if (vehicle_state.errors.err_invl) {
}
else if (vehicle_state.errors.err_invl)
{
text = "INVL";
} else if (vehicle_state.errors.err_invr) {
}
else if (vehicle_state.errors.err_invr)
{
text = "INVR";
} else {
}
else
{
text = "NONE";
}
return (void *)text;
}
void *get_zero() {
void *get_compiler_build_hash()
{
return (void *)git_hash;
}
void *get_zero()
{
static float zero = 0.0f;
return &zero;
}
@ -265,7 +326,7 @@ NamedFieldDescription dataFieldDescs[] = {
VEH_FIELD(lap_last)},
[DF_LVBatVoltage] = {NamedFieldKind::Float, "LVVBAT", 2, 2,
VEH_FIELD(lv_bat_voltage)},
};
[DF_GitBuildHash] = {NamedFieldKind::Text, "BLDHASH", 1, 0, get_compiler_build_hash}};
static_assert(sizeof(dataFieldDescs) / sizeof(dataFieldDescs[0]) ==
DataFieldType_COUNT,
@ -291,31 +352,38 @@ size_t dataFieldAlphaIndexByField[DataFieldType_COUNT];
ParamType paramByAlphaIndex[ParamType_COUNT];
size_t paramAlphaIndexByParam[ParamType_COUNT];
template <class T> struct NFAlphabeticComp {
template <class T>
struct NFAlphabeticComp
{
NFAlphabeticComp(const NamedFieldDescription *fieldDescs)
: fieldDescs{fieldDescs} {}
const NamedFieldDescription *fieldDescs;
bool operator()(const T &a, const T &b) const {
bool operator()(const T &a, const T &b) const
{
return strcmp(fieldDescs[a].title, fieldDescs[b].title) < 0;
}
};
template <class T>
void namedFieldSort(const NamedFieldDescription *fieldDescs, T *fieldByAlpha,
size_t *alphaIndexByField, size_t numFields) {
for (size_t i = 0; i < numFields; i++) {
size_t *alphaIndexByField, size_t numFields)
{
for (size_t i = 0; i < numFields; i++)
{
fieldByAlpha[i] = static_cast<T>(i);
}
std::sort(fieldByAlpha, fieldByAlpha + numFields,
NFAlphabeticComp<T>(fieldDescs));
for (size_t i = 0; i < numFields; i++) {
for (size_t i = 0; i < numFields; i++)
{
alphaIndexByField[fieldByAlpha[i]] = i;
}
}
void namedFieldSort() {
void namedFieldSort()
{
namedFieldSort(dataFieldDescs, dataFieldByAlphaIndex,
dataFieldAlphaIndexByField, DataFieldType_COUNT);
namedFieldSort(paramFieldDescs, paramByAlphaIndex, paramAlphaIndexByParam,
@ -326,7 +394,9 @@ template <class T>
NamedField<T>::NamedField(const NamedFieldDescription *fieldDescs)
: fieldDescs{fieldDescs} {}
template <class T> void NamedField<T>::setType(T type) {
template <class T>
void NamedField<T>::setType(T type)
{
this->type = type;
desc = &fieldDescs[type];
@ -338,11 +408,15 @@ template <class T> void NamedField<T>::setType(T type) {
updateValue();
}
template <class T> const T &NamedField<T>::getType() { return type; }
template <class T>
const T &NamedField<T>::getType() { return type; }
template <class T> void NamedField<T>::updateValue() {
template <class T>
void NamedField<T>::updateValue()
{
void *val = desc->getValue();
switch (desc->kind) {
switch (desc->kind)
{
case NamedFieldKind::Float:
setFloatValue(*static_cast<float *>(val));
break;
@ -358,32 +432,45 @@ template <class T> void NamedField<T>::updateValue() {
}
}
template <class T> void NamedField<T>::setFloatValue(float floatValue) {
template <class T>
void NamedField<T>::setFloatValue(float floatValue)
{
fieldValue.f = floatValue;
updateValueBuffer();
}
template <class T> void NamedField<T>::setBoolValue(int boolValue) {
template <class T>
void NamedField<T>::setBoolValue(int boolValue)
{
fieldValue.b = boolValue;
updateValueBuffer();
}
template <class T> void NamedField<T>::setIntValue(int intValue) {
template <class T>
void NamedField<T>::setIntValue(int intValue)
{
fieldValue.i = intValue;
updateValueBuffer();
}
template <class T> void NamedField<T>::setStrValue(const char *strValue) {
template <class T>
void NamedField<T>::setStrValue(const char *strValue)
{
touchgfx::Unicode::strncpy(valueBuffer, strValue,
sizeof(valueBuffer) / sizeof(*valueBuffer));
updateValueBuffer();
}
template <class T> void NamedField<T>::updateValueBuffer() {
switch (desc->kind) {
case NamedFieldKind::Float: {
template <class T>
void NamedField<T>::updateValueBuffer()
{
switch (desc->kind)
{
case NamedFieldKind::Float:
{
size_t width = desc->int_digits;
if (desc->decimal_digits != 0) {
if (desc->decimal_digits != 0)
{
width += desc->decimal_digits + 1; // 1 digit for the decimal point
}
float params[3] = {(float)width, (float)desc->decimal_digits, fieldValue.f};
@ -392,7 +479,8 @@ template <class T> void NamedField<T>::updateValueBuffer() {
params);
break;
}
case NamedFieldKind::Bool: {
case NamedFieldKind::Bool:
{
const char *str = fieldValue.b ? "YES" : "NO";
touchgfx::Unicode::strncpy(valueBuffer, str,
sizeof(valueBuffer) / sizeof(*valueBuffer));