mirror of
https://github.com/DashyFox/StackSport.git
synced 2025-05-04 07:10:17 +00:00
280 lines
7.0 KiB
C
280 lines
7.0 KiB
C
/*
|
|
* UART3_CMD_Handler.c
|
|
*
|
|
* Created on: Sep 12, 2024
|
|
* Author: DashyFox
|
|
*/
|
|
|
|
#include "UART3_CMD_Handler.h"
|
|
#include "Print.h"
|
|
#include "RobotFunctions.h"
|
|
#include "EEPROM.h"
|
|
|
|
#define HIGHBIT(b) (((b)>>8)&0xff)
|
|
#define LOWBIT(b) ((b)&0xff)
|
|
|
|
|
|
extern CurrentInfo currentInfo;
|
|
extern InfoBlock infoBlock;
|
|
|
|
extern void SendResponse(uint8_t command, uint8_t result, uint8_t *data,
|
|
uint8_t data_length);
|
|
|
|
uint8_t checkLen(uint8_t cmd, uint8_t current_length, uint8_t required_length) {
|
|
if (current_length < required_length) {
|
|
print("Invalid length for command ");
|
|
printNumber(cmd);
|
|
print(" len = ");
|
|
printNumber(current_length);
|
|
print("\n");
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
void UART3_SaveShot(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_SaveProgram(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_SaveMacro(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_StartMacro(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_StartProgram(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_StartShot(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_Stop(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_DeleteShot(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_DeleteProgram(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_DeleteMacro(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_DeleteAllData(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_GetDeviceStatus(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_SetServoOffset(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_GetServoOffset(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_SetServoMaxAngle(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_GetServoMaxAngle(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_MoveServoToInitialPosition(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_SetStartupDelay(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_GetStartupDelay(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_SetMinRollerSpeed(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_GetMinRollerSpeed(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_SetMinScrewSpeed(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_GetMinScrewSpeed(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_SetServoInvertFlag(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_GetServoInvertFlag(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|
|
void UART3_ReadStatistics(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
typedef struct __attribute__((packed)){
|
|
uint8_t status;
|
|
uint8_t macro_number;
|
|
uint8_t program_number;
|
|
uint8_t shot_number;
|
|
uint8_t total_macro_done_HIGH;
|
|
uint8_t total_macro_done_LOW;
|
|
uint8_t total_program_done_HIGH;
|
|
uint8_t total_program_done_LOW;
|
|
uint8_t total_shot_done_HIGH;
|
|
uint8_t total_shot_done_LOW;
|
|
} StatusStruct;
|
|
|
|
StatusStruct res;
|
|
|
|
res.status = currentInfo.state.isShooting && !currentInfo.state.isPause;
|
|
res.shot_number = currentInfo.shot.index;
|
|
res.program_number = currentInfo.program.index;
|
|
res.macro_number = currentInfo.macro.index;
|
|
|
|
res.total_shot_done_HIGH = HIGHBIT(infoBlock.statInfo.totalShots);
|
|
res.total_shot_done_LOW = LOWBIT(infoBlock.statInfo.totalShots);
|
|
|
|
res.total_program_done_HIGH = HIGHBIT(infoBlock.statInfo.totalPrograms);
|
|
res.total_program_done_LOW = LOWBIT(infoBlock.statInfo.totalPrograms);
|
|
|
|
res.total_macro_done_HIGH = HIGHBIT(infoBlock.statInfo.totalMacros);
|
|
res.total_macro_done_LOW = LOWBIT(infoBlock.statInfo.totalMacros);
|
|
|
|
SendResponse(dataPtr[0], 0, (uint8_t*)&res, sizeof(res));
|
|
}
|
|
|
|
void UART3_ResetStatistics(uint8_t *dataPtr, uint8_t len) {
|
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
|
return;
|
|
|
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
|
}
|
|
|