Merge pull request #2371 from martinbudden/bf_msp_tidy
Use sbufWriteData for some MSP serialisations
This commit is contained in:
commit
6f65008e88
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
@ -40,7 +39,6 @@
|
||||||
#include "config/parameter_group.h"
|
#include "config/parameter_group.h"
|
||||||
#include "config/parameter_group_ids.h"
|
#include "config/parameter_group_ids.h"
|
||||||
|
|
||||||
#include "drivers/system.h"
|
|
||||||
#include "drivers/accgyro.h"
|
#include "drivers/accgyro.h"
|
||||||
#include "drivers/bus_i2c.h"
|
#include "drivers/bus_i2c.h"
|
||||||
#include "drivers/compass.h"
|
#include "drivers/compass.h"
|
||||||
|
@ -74,8 +72,8 @@
|
||||||
#include "io/asyncfatfs/asyncfatfs.h"
|
#include "io/asyncfatfs/asyncfatfs.h"
|
||||||
#include "io/beeper.h"
|
#include "io/beeper.h"
|
||||||
#include "io/flashfs.h"
|
#include "io/flashfs.h"
|
||||||
#include "io/gps.h"
|
|
||||||
#include "io/gimbal.h"
|
#include "io/gimbal.h"
|
||||||
|
#include "io/gps.h"
|
||||||
#include "io/ledstrip.h"
|
#include "io/ledstrip.h"
|
||||||
#include "io/motors.h"
|
#include "io/motors.h"
|
||||||
#include "io/serial.h"
|
#include "io/serial.h"
|
||||||
|
@ -87,8 +85,8 @@
|
||||||
#include "msp/msp_protocol.h"
|
#include "msp/msp_protocol.h"
|
||||||
#include "msp/msp_serial.h"
|
#include "msp/msp_serial.h"
|
||||||
|
|
||||||
#include "rx/rx.h"
|
|
||||||
#include "rx/msp.h"
|
#include "rx/msp.h"
|
||||||
|
#include "rx/rx.h"
|
||||||
|
|
||||||
#include "scheduler/scheduler.h"
|
#include "scheduler/scheduler.h"
|
||||||
|
|
||||||
|
@ -256,14 +254,6 @@ static void mspRebootFn(serialPort_t *serialPort)
|
||||||
while (true) ;
|
while (true) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void serializeNames(sbuf_t *dst, const char *s)
|
|
||||||
{
|
|
||||||
const char *c;
|
|
||||||
for (c = s; *c; c++) {
|
|
||||||
sbufWriteU8(dst, *c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static const box_t *findBoxByActiveBoxId(uint8_t activeBoxId)
|
static const box_t *findBoxByActiveBoxId(uint8_t activeBoxId)
|
||||||
{
|
{
|
||||||
for (uint8_t boxIndex = 0; boxIndex < sizeof(boxes) / sizeof(box_t); boxIndex++) {
|
for (uint8_t boxIndex = 0; boxIndex < sizeof(boxes) / sizeof(box_t); boxIndex++) {
|
||||||
|
@ -288,20 +278,19 @@ static const box_t *findBoxByPermenantId(uint8_t permenantId)
|
||||||
|
|
||||||
static void serializeBoxNamesReply(sbuf_t *dst)
|
static void serializeBoxNamesReply(sbuf_t *dst)
|
||||||
{
|
{
|
||||||
int activeBoxId, flag = 1, count = 0, len;
|
int flag = 1, count = 0;
|
||||||
|
|
||||||
reset:
|
reset:
|
||||||
// in first run of the loop, we grab total size of junk to be sent
|
// in first run of the loop, we grab total size of junk to be sent
|
||||||
// then come back and actually send it
|
// then come back and actually send it
|
||||||
for (int i = 0; i < activeBoxIdCount; i++) {
|
for (int i = 0; i < activeBoxIdCount; i++) {
|
||||||
activeBoxId = activeBoxIds[i];
|
const int activeBoxId = activeBoxIds[i];
|
||||||
|
|
||||||
const box_t *box = findBoxByActiveBoxId(activeBoxId);
|
const box_t *box = findBoxByActiveBoxId(activeBoxId);
|
||||||
if (!box) {
|
if (!box) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = strlen(box->boxName);
|
const int len = strlen(box->boxName);
|
||||||
if (flag) {
|
if (flag) {
|
||||||
count += len;
|
count += len;
|
||||||
} else {
|
} else {
|
||||||
|
@ -579,9 +568,7 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSP_FC_VARIANT:
|
case MSP_FC_VARIANT:
|
||||||
for (int i = 0; i < FLIGHT_CONTROLLER_IDENTIFIER_LENGTH; i++) {
|
sbufWriteData(dst, flightControllerIdentifier, FLIGHT_CONTROLLER_IDENTIFIER_LENGTH);
|
||||||
sbufWriteU8(dst, flightControllerIdentifier[i]);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSP_FC_VERSION:
|
case MSP_FC_VERSION:
|
||||||
|
@ -591,9 +578,7 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSP_BOARD_INFO:
|
case MSP_BOARD_INFO:
|
||||||
for (int i = 0; i < BOARD_IDENTIFIER_LENGTH; i++) {
|
sbufWriteData(dst, boardIdentifier, BOARD_IDENTIFIER_LENGTH);
|
||||||
sbufWriteU8(dst, boardIdentifier[i]);
|
|
||||||
}
|
|
||||||
#ifdef USE_HARDWARE_REVISION_DETECTION
|
#ifdef USE_HARDWARE_REVISION_DETECTION
|
||||||
sbufWriteU16(dst, hardwareRevision);
|
sbufWriteU16(dst, hardwareRevision);
|
||||||
#else
|
#else
|
||||||
|
@ -602,15 +587,9 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSP_BUILD_INFO:
|
case MSP_BUILD_INFO:
|
||||||
for (int i = 0; i < BUILD_DATE_LENGTH; i++) {
|
sbufWriteData(dst, buildDate, BUILD_DATE_LENGTH);
|
||||||
sbufWriteU8(dst, buildDate[i]);
|
sbufWriteData(dst, buildTime, BUILD_TIME_LENGTH);
|
||||||
}
|
sbufWriteData(dst, shortGitRevision, GIT_SHORT_REVISION_LENGTH);
|
||||||
for (int i = 0; i < BUILD_TIME_LENGTH; i++) {
|
|
||||||
sbufWriteU8(dst, buildTime[i]);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < GIT_SHORT_REVISION_LENGTH; i++) {
|
|
||||||
sbufWriteU8(dst, shortGitRevision[i]);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// DEPRECATED - Use MSP_API_VERSION
|
// DEPRECATED - Use MSP_API_VERSION
|
||||||
|
@ -786,7 +765,9 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSP_PIDNAMES:
|
case MSP_PIDNAMES:
|
||||||
serializeNames(dst, pidnames);
|
for (const char *c = pidnames; *c; c++) {
|
||||||
|
sbufWriteU8(dst, *c);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSP_PID_CONTROLLER:
|
case MSP_PID_CONTROLLER:
|
||||||
|
@ -983,9 +964,7 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSP_RX_MAP:
|
case MSP_RX_MAP:
|
||||||
for (int i = 0; i < MAX_MAPPABLE_RX_INPUTS; i++) {
|
sbufWriteData(dst, rxConfig()->rcmap, MAX_MAPPABLE_RX_INPUTS);
|
||||||
sbufWriteU8(dst, rxConfig()->rcmap[i]);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSP_BF_CONFIG:
|
case MSP_BF_CONFIG:
|
||||||
|
@ -1111,9 +1090,7 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSP_BF_BUILD_INFO:
|
case MSP_BF_BUILD_INFO:
|
||||||
for (int i = 0; i < 11; i++) {
|
sbufWriteData(dst, buildDate, 11); // MMM DD YYYY as ascii, MMM = Jan/Feb... etc
|
||||||
sbufWriteU8(dst, buildDate[i]); // MMM DD YYYY as ascii, MMM = Jan/Feb... etc
|
|
||||||
}
|
|
||||||
sbufWriteU32(dst, 0); // future exp
|
sbufWriteU32(dst, 0); // future exp
|
||||||
sbufWriteU32(dst, 0); // future exp
|
sbufWriteU32(dst, 0); // future exp
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue