shooting process

This commit is contained in:
2024-09-22 00:19:50 +03:00
parent 6746f19cf0
commit b98846eac1
12 changed files with 393 additions and 151 deletions

View File

@ -31,6 +31,7 @@ uint8_t checkLen(uint8_t cmd, uint8_t current_length, uint8_t required_length) {
return 1;
}
// 10
void UART3_SaveShot(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 8;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -44,9 +45,11 @@ void UART3_SaveShot(uint8_t *dataPtr, uint8_t len) {
shot.speedRollerTop = dataPtr[3] + 100;
shot.speedRollerBottom = dataPtr[4] + 100;
shot.speedScrew = map(dataPtr[5], 0, 120, 0, 100);
shot.rotationAxial = map(dataPtr[6], -99, 99, 0, 180);
shot.rotationHorizontal = map(dataPtr[7], -99, 99, 90 - 45, 90 + 45);
shot.rotationVertical = 180 - dataPtr[8];
shot.rotationAxial = map((int8_t)dataPtr[6], -99, 99, 0, 180);
shot.rotationHorizontal = map((int8_t)dataPtr[7], -99, 99, 0, 180);
shot.rotationVertical = 180 - (int8_t)dataPtr[8] - 90;
saveShot(shotIndx, &shot);
@ -106,6 +109,7 @@ void UART3_SaveMacro(uint8_t *dataPtr, uint8_t len) {
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))
@ -122,6 +126,7 @@ void UART3_StartProgram(uint8_t *dataPtr, uint8_t len) {
SendResponse(dataPtr[0], 0, NULL, 0);
}
// 102
void UART3_StartShot(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 1;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -129,19 +134,23 @@ void UART3_StartShot(uint8_t *dataPtr, uint8_t len) {
uint8_t shotIndx = dataPtr[1];
prepareShot(shotIndx);
startShooting();
startShooting(infoBlock.hwInfo.timings.preRun);
SendResponse(dataPtr[0], 0, NULL, 0);
}
// 110
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;
stopShooting();
SendResponse(dataPtr[0], 0, NULL, 0);
}
// 13
void UART3_DeleteShot(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 1;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -153,6 +162,7 @@ void UART3_DeleteShot(uint8_t *dataPtr, uint8_t len) {
SendResponse(dataPtr[0], 0, NULL, 0);
}
// 14
void UART3_DeleteProgram(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 0;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -164,6 +174,7 @@ void UART3_DeleteProgram(uint8_t *dataPtr, uint8_t len) {
SendResponse(dataPtr[0], 0, NULL, 0);
}
// 15
void UART3_DeleteMacro(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 0;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -175,7 +186,7 @@ void UART3_DeleteMacro(uint8_t *dataPtr, uint8_t len) {
SendResponse(dataPtr[0], 0, NULL, 0);
}
//120
// 120
void UART3_DeleteAllData(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 0;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -189,41 +200,45 @@ void UART3_DeleteAllData(uint8_t *dataPtr, uint8_t len) {
SendResponse(dataPtr[0], 0, NULL, 0);
}
//180
// 180
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;
uint8_t res = currentInfo.state.isShooting;
uint8_t res = currentInfo.state == RUN;
SendResponse(dataPtr[0], 0, &res, sizeof(res));
}
//200
// 200
void UART3_SetServoOffset(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 3;
const uint8_t MIN_PARAM_LENGTH = 2;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
return;
ServoMap servo = dataPtr[1];
ServoSetting *currentServo = &infoBlock.hwInfo.servos[servo];
int16_t newDef = (dataPtr[2] << 8) | dataPtr[3];
uint8_t newDef = dataPtr[2];
printNumber(newDef);
print("\n");
newDef += 90; // from center
if (newDef < 0)
newDef = 0;
if (newDef > 180)
newDef = 180;
currentServo->def = newDef;
printNumber(newDef);
print("\n");
saveInfoBlock();
SendResponse(dataPtr[0], 0, NULL, 0);
}
//204
// 205
void UART3_GetServoOffset(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 1;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -240,7 +255,7 @@ void UART3_GetServoOffset(uint8_t *dataPtr, uint8_t len) {
SendResponse(dataPtr[0], 0, res, sizeof(res));
}
//201
// 201
void UART3_SetServoMaxAngle(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 3;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -260,6 +275,26 @@ void UART3_SetServoMaxAngle(uint8_t *dataPtr, uint8_t len) {
SendResponse(dataPtr[0], 0, NULL, 0);
}
// 202
void UART3_SetServoMinAngle(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 3;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
return;
ServoMap servo = dataPtr[1];
uint16_t minAngl = (dataPtr[2] << 8) | dataPtr[3];
ServoSetting *currentServo = &infoBlock.hwInfo.servos[servo];
if (minAngl > 180)
minAngl = 180;
if (minAngl < 0)
minAngl = 0;
currentServo->min = minAngl;
saveInfoBlock();
SendResponse(dataPtr[0], 0, NULL, 0);
}
void UART3_GetServoMaxAngle(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 1;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -276,26 +311,6 @@ void UART3_GetServoMaxAngle(uint8_t *dataPtr, uint8_t len) {
SendResponse(dataPtr[0], 0, res, sizeof(res));
}
//202
void UART3_SetServoMinAngle(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 3;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
return;
ServoMap servo = dataPtr[1];
uint16_t minAngl = (dataPtr[2] << 8) | dataPtr[3];
ServoSetting *currentServo = &infoBlock.hwInfo.servos[servo];
if (minAngl > 180)
minAngl = 180;
if (minAngl < 0)
minAngl = 0;
currentServo->min = minAngl;
saveInfoBlock();
SendResponse(dataPtr[0], 0, NULL, 0);
}
void UART3_GetServoMinAngle(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 1;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -312,7 +327,7 @@ void UART3_GetServoMinAngle(uint8_t *dataPtr, uint8_t len) {
SendResponse(dataPtr[0], 0, res, sizeof(res));
}
//203
// 203
void UART3_MoveServoToInitialPosition(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 1;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -323,7 +338,7 @@ void UART3_MoveServoToInitialPosition(uint8_t *dataPtr, uint8_t len) {
SendResponse(dataPtr[0], 0, NULL, 0);
}
//206
// 206
void UART3_SetStartupDelay(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 2;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -335,7 +350,7 @@ void UART3_SetStartupDelay(uint8_t *dataPtr, uint8_t len) {
SendResponse(dataPtr[0], 0, NULL, 0);
}
//207
// 207
void UART3_GetStartupDelay(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 0;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -349,7 +364,7 @@ void UART3_GetStartupDelay(uint8_t *dataPtr, uint8_t len) {
SendResponse(dataPtr[0], 0, res, sizeof(res));
}
//210 !!!!!!!!
// 210 !!!!!!!!
void UART3_SetMinRollerSpeed(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 0;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -358,7 +373,7 @@ void UART3_SetMinRollerSpeed(uint8_t *dataPtr, uint8_t len) {
SendResponse(dataPtr[0], 0, NULL, 0);
}
//211 !!!!!!!!!!!
// 211 !!!!!!!!!!!
void UART3_GetMinRollerSpeed(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 0;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -370,7 +385,7 @@ void UART3_GetMinRollerSpeed(uint8_t *dataPtr, uint8_t len) {
SendResponse(dataPtr[0], 0, res, sizeof(res));
}
//212
// 212
void UART3_SetMinScrewSpeed(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 1;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -382,7 +397,7 @@ void UART3_SetMinScrewSpeed(uint8_t *dataPtr, uint8_t len) {
SendResponse(dataPtr[0], 0, NULL, 0);
}
//215
// 215
void UART3_GetMinScrewSpeed(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 0;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -394,7 +409,7 @@ void UART3_GetMinScrewSpeed(uint8_t *dataPtr, uint8_t len) {
SendResponse(dataPtr[0], 0, res, sizeof(res));
}
//214
// 214
void UART3_SetServoInvertFlag(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 1;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -411,7 +426,7 @@ void UART3_SetServoInvertFlag(uint8_t *dataPtr, uint8_t len) {
SendResponse(dataPtr[0], 0, NULL, 0);
}
//215
// 215
void UART3_GetServoInvertFlag(uint8_t *dataPtr, uint8_t len) {
const uint8_t MIN_PARAM_LENGTH = 0;
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
@ -447,7 +462,7 @@ void UART3_ReadStatistics(uint8_t *dataPtr, uint8_t len) {
StatusStruct res;
res.status = currentInfo.state.isShooting;
res.status = currentInfo.state == RUN;
res.shot_number = currentInfo.shot.index;
res.program_number = currentInfo.program.index;
res.macro_number = currentInfo.macro.index;