mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 21:35:44 +03:00
Tidied blackbox_io.c
This commit is contained in:
parent
8a53aedb94
commit
e7a2f917f2
1 changed files with 19 additions and 29 deletions
|
@ -11,9 +11,6 @@
|
||||||
#include "blackbox.h"
|
#include "blackbox.h"
|
||||||
#include "blackbox_io.h"
|
#include "blackbox_io.h"
|
||||||
|
|
||||||
#include "build/version.h"
|
|
||||||
#include "build/build_config.h"
|
|
||||||
|
|
||||||
#include "common/encoding.h"
|
#include "common/encoding.h"
|
||||||
#include "common/maths.h"
|
#include "common/maths.h"
|
||||||
#include "common/printf.h"
|
#include "common/printf.h"
|
||||||
|
@ -21,9 +18,6 @@
|
||||||
#include "config/parameter_group.h"
|
#include "config/parameter_group.h"
|
||||||
#include "config/parameter_group_ids.h"
|
#include "config/parameter_group_ids.h"
|
||||||
|
|
||||||
#include "fc/config.h"
|
|
||||||
#include "fc/rc_controls.h"
|
|
||||||
|
|
||||||
#include "flight/pid.h"
|
#include "flight/pid.h"
|
||||||
|
|
||||||
#include "io/asyncfatfs/asyncfatfs.h"
|
#include "io/asyncfatfs/asyncfatfs.h"
|
||||||
|
@ -43,7 +37,7 @@ int32_t blackboxHeaderBudget;
|
||||||
STATIC_UNIT_TESTED serialPort_t *blackboxPort = NULL;
|
STATIC_UNIT_TESTED serialPort_t *blackboxPort = NULL;
|
||||||
#ifndef UNIT_TEST
|
#ifndef UNIT_TEST
|
||||||
static portSharing_e blackboxPortSharing;
|
static portSharing_e blackboxPortSharing;
|
||||||
#endif
|
#endif // UNIT_TEST
|
||||||
|
|
||||||
#ifdef USE_SDCARD
|
#ifdef USE_SDCARD
|
||||||
|
|
||||||
|
@ -76,7 +70,7 @@ void blackboxOpen()
|
||||||
mspSerialReleasePortIfAllocated(sharedBlackboxAndMspPort);
|
mspSerialReleasePortIfAllocated(sharedBlackboxAndMspPort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif // UNIT_TEST
|
||||||
|
|
||||||
void blackboxWrite(uint8_t value)
|
void blackboxWrite(uint8_t value)
|
||||||
{
|
{
|
||||||
|
@ -230,7 +224,8 @@ void blackboxWriteS16(int16_t value)
|
||||||
/**
|
/**
|
||||||
* Write a 2 bit tag followed by 3 signed fields of 2, 4, 6 or 32 bits
|
* Write a 2 bit tag followed by 3 signed fields of 2, 4, 6 or 32 bits
|
||||||
*/
|
*/
|
||||||
void blackboxWriteTag2_3S32(int32_t *values) {
|
void blackboxWriteTag2_3S32(int32_t *values)
|
||||||
|
{
|
||||||
static const int NUM_FIELDS = 3;
|
static const int NUM_FIELDS = 3;
|
||||||
|
|
||||||
//Need to be enums rather than const ints if we want to switch on them (due to being C)
|
//Need to be enums rather than const ints if we want to switch on them (due to being C)
|
||||||
|
@ -248,7 +243,6 @@ void blackboxWriteTag2_3S32(int32_t *values) {
|
||||||
BYTES_4 = 3
|
BYTES_4 = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
int x;
|
|
||||||
int selector = BITS_2, selector2;
|
int selector = BITS_2, selector2;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -262,7 +256,7 @@ void blackboxWriteTag2_3S32(int32_t *values) {
|
||||||
* 6 bits per field ss11 1111 0022 2222 0033 3333
|
* 6 bits per field ss11 1111 0022 2222 0033 3333
|
||||||
* 32 bits per field sstt tttt followed by fields of various byte counts
|
* 32 bits per field sstt tttt followed by fields of various byte counts
|
||||||
*/
|
*/
|
||||||
for (x = 0; x < NUM_FIELDS; x++) {
|
for (int x = 0; x < NUM_FIELDS; x++) {
|
||||||
//Require more than 6 bits?
|
//Require more than 6 bits?
|
||||||
if (values[x] >= 32 || values[x] < -32) {
|
if (values[x] >= 32 || values[x] < -32) {
|
||||||
selector = BITS_32;
|
selector = BITS_32;
|
||||||
|
@ -307,7 +301,7 @@ void blackboxWriteTag2_3S32(int32_t *values) {
|
||||||
selector2 = 0;
|
selector2 = 0;
|
||||||
|
|
||||||
//Encode in reverse order so the first field is in the low bits:
|
//Encode in reverse order so the first field is in the low bits:
|
||||||
for (x = NUM_FIELDS - 1; x >= 0; x--) {
|
for (int x = NUM_FIELDS - 1; x >= 0; x--) {
|
||||||
selector2 <<= 2;
|
selector2 <<= 2;
|
||||||
|
|
||||||
if (values[x] < 128 && values[x] >= -128) {
|
if (values[x] < 128 && values[x] >= -128) {
|
||||||
|
@ -325,7 +319,7 @@ void blackboxWriteTag2_3S32(int32_t *values) {
|
||||||
blackboxWrite((selector << 6) | selector2);
|
blackboxWrite((selector << 6) | selector2);
|
||||||
|
|
||||||
//And now the values according to the selectors we picked for them
|
//And now the values according to the selectors we picked for them
|
||||||
for (x = 0; x < NUM_FIELDS; x++, selector2 >>= 2) {
|
for (int x = 0; x < NUM_FIELDS; x++, selector2 >>= 2) {
|
||||||
switch (selector2 & 0x03) {
|
switch (selector2 & 0x03) {
|
||||||
case BYTES_1:
|
case BYTES_1:
|
||||||
blackboxWrite(values[x]);
|
blackboxWrite(values[x]);
|
||||||
|
@ -347,14 +341,15 @@ void blackboxWriteTag2_3S32(int32_t *values) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write an 8-bit selector followed by four signed fields of size 0, 4, 8 or 16 bits.
|
* Write an 8-bit selector followed by four signed fields of size 0, 4, 8 or 16 bits.
|
||||||
*/
|
*/
|
||||||
void blackboxWriteTag8_4S16(int32_t *values) {
|
void blackboxWriteTag8_4S16(int32_t *values)
|
||||||
|
{
|
||||||
|
|
||||||
//Need to be enums rather than const ints if we want to switch on them (due to being C)
|
//Need to be enums rather than const ints if we want to switch on them (due to being C)
|
||||||
enum {
|
enum {
|
||||||
|
@ -364,13 +359,9 @@ void blackboxWriteTag8_4S16(int32_t *values) {
|
||||||
FIELD_16BIT = 3
|
FIELD_16BIT = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t selector, buffer;
|
uint8_t selector = 0;
|
||||||
int nibbleIndex;
|
|
||||||
int x;
|
|
||||||
|
|
||||||
selector = 0;
|
|
||||||
//Encode in reverse order so the first field is in the low bits:
|
//Encode in reverse order so the first field is in the low bits:
|
||||||
for (x = 3; x >= 0; x--) {
|
for (int x = 3; x >= 0; x--) {
|
||||||
selector <<= 2;
|
selector <<= 2;
|
||||||
|
|
||||||
if (values[x] == 0) {
|
if (values[x] == 0) {
|
||||||
|
@ -386,9 +377,9 @@ void blackboxWriteTag8_4S16(int32_t *values) {
|
||||||
|
|
||||||
blackboxWrite(selector);
|
blackboxWrite(selector);
|
||||||
|
|
||||||
nibbleIndex = 0;
|
int nibbleIndex = 0;
|
||||||
buffer = 0;
|
uint8_t buffer = 0;
|
||||||
for (x = 0; x < 4; x++, selector >>= 2) {
|
for (int x = 0; x < 4; x++, selector >>= 2) {
|
||||||
switch (selector & 0x03) {
|
switch (selector & 0x03) {
|
||||||
case FIELD_ZERO:
|
case FIELD_ZERO:
|
||||||
//No-op
|
//No-op
|
||||||
|
@ -444,7 +435,6 @@ void blackboxWriteTag8_4S16(int32_t *values) {
|
||||||
void blackboxWriteTag8_8SVB(int32_t *values, int valueCount)
|
void blackboxWriteTag8_8SVB(int32_t *values, int valueCount)
|
||||||
{
|
{
|
||||||
uint8_t header;
|
uint8_t header;
|
||||||
int i;
|
|
||||||
|
|
||||||
if (valueCount > 0) {
|
if (valueCount > 0) {
|
||||||
//If we're only writing one field then we can skip the header
|
//If we're only writing one field then we can skip the header
|
||||||
|
@ -455,7 +445,7 @@ void blackboxWriteTag8_8SVB(int32_t *values, int valueCount)
|
||||||
header = 0;
|
header = 0;
|
||||||
|
|
||||||
// First field should be in low bits of header
|
// First field should be in low bits of header
|
||||||
for (i = valueCount - 1; i >= 0; i--) {
|
for (int i = valueCount - 1; i >= 0; i--) {
|
||||||
header <<= 1;
|
header <<= 1;
|
||||||
|
|
||||||
if (values[i] != 0) {
|
if (values[i] != 0) {
|
||||||
|
@ -465,7 +455,7 @@ void blackboxWriteTag8_8SVB(int32_t *values, int valueCount)
|
||||||
|
|
||||||
blackboxWrite(header);
|
blackboxWrite(header);
|
||||||
|
|
||||||
for (i = 0; i < valueCount; i++) {
|
for (int i = 0; i < valueCount; i++) {
|
||||||
if (values[i] != 0) {
|
if (values[i] != 0) {
|
||||||
blackboxWriteSignedVB(values[i]);
|
blackboxWriteSignedVB(values[i]);
|
||||||
}
|
}
|
||||||
|
@ -616,7 +606,7 @@ bool blackboxDeviceOpen(void)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif // UNIT_TEST
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Erase all blackbox logs
|
* Erase all blackbox logs
|
||||||
|
@ -677,7 +667,7 @@ void blackboxDeviceClose(void)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif // UNIT_TEST
|
||||||
|
|
||||||
#ifdef USE_SDCARD
|
#ifdef USE_SDCARD
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue