178 lines
6.4 KiB
C
178 lines
6.4 KiB
C
////
|
|
//// Created by zemon on 18.11.22.
|
|
////
|
|
//
|
|
//
|
|
#include "CliCmd/FlipSetting.h"
|
|
#include "SystemDelayInterface.h"
|
|
#include "XfcProtProcessorUtilDefines.h"
|
|
#include "string.h"
|
|
#include "stream.h"
|
|
|
|
void CliCmd_flipModedHelp(void *env, tCliCmd *cli) {
|
|
CliCmd_PrintLnStatic(cli, " access sub commands:");
|
|
CliCmd_PrintLnStatic(cli, " command [ exit ] - exit as this sub mode");
|
|
CliCmd_PrintLnStatic(cli, " command [ help ] - help this as sub mode");
|
|
CliCmd_PrintLnStatic(cli, " command [ stop] - stop listing data acsel");
|
|
CliCmd_PrintLnStatic(cli, " command [ rec_angle ] - record this params");
|
|
CliCmd_PrintLnStatic(cli, " command [ rec_vector ] - record this params");
|
|
CliCmd_PrintLnStatic(cli, " press ENTER key to continue");
|
|
CliCmd_PrintLnStatic(cli, "");
|
|
}
|
|
|
|
char sps[] = " ";
|
|
|
|
void printSps(tCliCmd *cli) {
|
|
SerialPortTransmit(cli->serialCommandPort, (uint8_t *) sps, sizeof(sps) - 1, SystemWaitForever);
|
|
}
|
|
|
|
void updateData(tFlipSetting *tFlipSet) {
|
|
tFlipSet->val_x = tFlipSet->flipDetect->current.value.x;
|
|
tFlipSet->val_y = tFlipSet->flipDetect->current.value.y;
|
|
tFlipSet->val_z = tFlipSet->flipDetect->current.value.z;
|
|
tFlipSet->angleCos = tFlipSet->flipDetect->current.angleCos;
|
|
}
|
|
|
|
void printData(tFlipSetting *tFlipSet, tCliCmd *cli, uint32_t timeout) {
|
|
|
|
uint32_t endMs = SystemGetMs() + timeout;
|
|
|
|
updateData(tFlipSet);
|
|
|
|
SerialPortTransmit(cli->serialCommandPort, (uint8_t *) "angleCos=", sizeof("angleCos=") - 1, SystemWaitForever);
|
|
debug_printf(cli->serialCommandPort, "%f", *(float *) &tFlipSet->angleCos);
|
|
printSps(cli);
|
|
SerialPortTransmit(cli->serialCommandPort, (uint8_t *) "X=", 2, SystemWaitForever);
|
|
debug_printf(cli->serialCommandPort, "%f", *(float *) &tFlipSet->val_x);
|
|
printSps(cli);
|
|
SerialPortTransmit(cli->serialCommandPort, (uint8_t *) "Y=", 2, SystemWaitForever);
|
|
debug_printf(cli->serialCommandPort, "%f", *(float *) &tFlipSet->val_y);
|
|
printSps(cli);
|
|
SerialPortTransmit(cli->serialCommandPort, (uint8_t *) "Z=", 2, SystemWaitForever);
|
|
|
|
debug_printf(cli->serialCommandPort, "%f", *(float *) &tFlipSet->val_z);
|
|
CliCmd_PrintLnStatic(cli, "");
|
|
|
|
|
|
while (endMs > SystemGetMs()) {
|
|
SystemDelayMs(4);
|
|
}
|
|
}
|
|
|
|
|
|
uint8_t recordVarData(tFlipSetting *tFlipSet, tCliCmd *cli, uint8_t stat) {
|
|
char *nameFiled;
|
|
tVariableDescriptor *descriptor;
|
|
|
|
if (VariablesTable_RequireChange(tFlipSet->externTable, 10)) {
|
|
if (stat == 0) {
|
|
|
|
nameFiled = "FLIP_DETECT_TRESHOLD_ANGLE_COS";
|
|
descriptor = VariablesTable_GetByName(tFlipSet->externTable, nameFiled, strlen(nameFiled));
|
|
memcpy(descriptor->addr, &tFlipSet->angleCos, sizeof(tFlipSet->angleCos));
|
|
|
|
VariablesTable_VariableChanged(tFlipSet->externTable, descriptor);
|
|
VariablesTable_ReleaseChange(tFlipSet->externTable);
|
|
|
|
CliCmd_PrintLnStatic(cli, " record angle is success");
|
|
//осовбождаем доступ к измененению настроек
|
|
VariablesTable_ReleaseChange(tFlipSet->externTable);
|
|
|
|
} else {
|
|
|
|
nameFiled = "FLIP_DETECT_GRAVITY_X";
|
|
descriptor = VariablesTable_GetByName(tFlipSet->externTable, nameFiled, strlen(nameFiled));
|
|
memcpy(descriptor->addr, &tFlipSet->val_x, sizeof(tFlipSet->val_x));
|
|
|
|
nameFiled = "FLIP_DETECT_GRAVITY_Y";
|
|
descriptor = VariablesTable_GetByName(tFlipSet->externTable, nameFiled, strlen(nameFiled));
|
|
memcpy(descriptor->addr, &tFlipSet->val_y, sizeof(tFlipSet->val_y));
|
|
|
|
nameFiled = "FLIP_DETECT_GRAVITY_Z";
|
|
descriptor = VariablesTable_GetByName(tFlipSet->externTable, nameFiled, strlen(nameFiled));
|
|
memcpy(descriptor->addr, &tFlipSet->val_z, sizeof(tFlipSet->val_z));
|
|
|
|
VariablesTable_VariableChanged(tFlipSet->externTable, descriptor);
|
|
VariablesTable_ReleaseChange(tFlipSet->externTable);
|
|
|
|
//осовбождаем доступ к измененению настроек
|
|
VariablesTable_ReleaseChange(tFlipSet->externTable);
|
|
CliCmd_PrintLnStatic(cli, " record vector is success");
|
|
return 0;
|
|
}
|
|
} else {
|
|
//осовбождаем доступ к измененению настроек
|
|
VariablesTable_ReleaseChange(tFlipSet->externTable);
|
|
CliCmd_PrintLnStatic(cli, "Variable is busy");
|
|
return 0;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void getNewData(tFlipSetting *tFlipSet, tCliCmd *cli) {
|
|
CliCmd_PrintLnStatic(cli, "=================== THIS DATA ===================");
|
|
printData(tFlipSet, cli, 1);
|
|
CliCmd_PrintLnStatic(cli, "=================================================");
|
|
CliCmd_PrintLnStatic(cli, " [ rec_vector ] - record this vector data");
|
|
CliCmd_PrintLnStatic(cli, " [ rec_angle ] - record this angle data");
|
|
CliCmd_PrintLnStatic(cli, " [ ENTER_PRESS_KEY ] - update this data");
|
|
CliCmd_PrintLnStatic(cli, " [ exit ] - exiting as sub mode record/ and continue listing info");
|
|
}
|
|
|
|
void stopListing(tFlipSetting *tFlipSet, tCliCmd *cli) {
|
|
|
|
getNewData(tFlipSet, cli);
|
|
|
|
while (1) {
|
|
CliCmd_WaitLine(cli);
|
|
if (CliCmd_RxStartsWithStatic(cli, "rec_angle")) {
|
|
recordVarData(tFlipSet, cli, 0);
|
|
return;
|
|
}
|
|
|
|
if (CliCmd_RxStartsWithStatic(cli, "rec_vector")) {
|
|
recordVarData(tFlipSet, cli, 1);
|
|
return;
|
|
}
|
|
|
|
if (CliCmd_RxStartsWithStatic(cli, "")) {
|
|
printData(tFlipSet, cli, 1);
|
|
}
|
|
|
|
if (CliCmd_RxStartsWithStatic(cli, "exit")) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void CliCmd_FlipSettingInit(tFlipSetting *tFlipSet, tCarFlipDetection *tFlipBase, tVariablesTable *externTable) {
|
|
tFlipSet->flipDetect = tFlipBase;
|
|
tFlipSet->externTable = externTable;
|
|
}
|
|
|
|
uint8_t CliCmd_FlipSetting(tFlipSetting *tFlipSet, tCliCmd *cli) {
|
|
CliCmd_PrintLnStatic(cli, "THIS MODE FLIPPING SETTINGS");
|
|
while (1) {
|
|
|
|
CliCmd_WaitLineDelay(cli, 1500);
|
|
if (CliCmd_RxStartsWithStatic(cli, "exit")) {
|
|
CliCmd_PrintLnStatic(cli, "EXIT IN BASE MODE...");
|
|
return 0;
|
|
}
|
|
|
|
if (CliCmd_RxStartsWithStatic(cli, "help")) {
|
|
CliCmd_flipModedHelp(NULL, cli);
|
|
CliCmd_WaitLine(cli);
|
|
}
|
|
|
|
if (CliCmd_RxStartsWithStatic(cli, "stop")) {
|
|
stopListing(tFlipSet, cli);
|
|
}
|
|
|
|
printData(tFlipSet, cli, 1000);
|
|
SystemDelayMs(4);
|
|
}
|
|
}
|
|
|