mirror of
https://github.com/DashyFox/StackSport.git
synced 2025-06-28 05:09:32 +00:00
Working UART
This commit is contained in:
@ -7,14 +7,25 @@
|
||||
|
||||
#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");
|
||||
if (current_length < required_length) {
|
||||
print("Invalid length for command ");
|
||||
printNumber(cmd);
|
||||
print(" len = ");
|
||||
printNumber(current_length);
|
||||
print("\n");
|
||||
return 0;
|
||||
}
|
||||
@ -226,7 +237,36 @@ void UART3_ReadStatistics(uint8_t *dataPtr, uint8_t len) {
|
||||
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||
return;
|
||||
|
||||
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||
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) {
|
||||
|
Reference in New Issue
Block a user