mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-27 10:17:45 +08:00
Code style fixes, no code changes
This commit is contained in:
@@ -8,7 +8,8 @@
|
|||||||
|
|
||||||
#include <drivers/sf0x/sf0x_parser.h>
|
#include <drivers/sf0x/sf0x_parser.h>
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
warnx("SF0X test started");
|
warnx("SF0X test started");
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@@ -18,22 +19,22 @@ int main(int argc, char *argv[]) {
|
|||||||
_linebuf[0] = '\0';
|
_linebuf[0] = '\0';
|
||||||
|
|
||||||
const char *lines[] = {"0.01\r\n",
|
const char *lines[] = {"0.01\r\n",
|
||||||
"0.02\r\n",
|
"0.02\r\n",
|
||||||
"0.03\r\n",
|
"0.03\r\n",
|
||||||
"0.04\r\n",
|
"0.04\r\n",
|
||||||
"0",
|
"0",
|
||||||
".",
|
".",
|
||||||
"0",
|
"0",
|
||||||
"5",
|
"5",
|
||||||
"\r",
|
"\r",
|
||||||
"\n",
|
"\n",
|
||||||
"0",
|
"0",
|
||||||
"3\r",
|
"3\r",
|
||||||
"\n"
|
"\n"
|
||||||
"\r\n",
|
"\r\n",
|
||||||
"0.06",
|
"0.06",
|
||||||
"\r\n"
|
"\r\n"
|
||||||
};
|
};
|
||||||
|
|
||||||
enum SF0X_PARSE_STATE state = SF0X_PARSE_STATE0_UNSYNC;
|
enum SF0X_PARSE_STATE state = SF0X_PARSE_STATE0_UNSYNC;
|
||||||
float dist_m;
|
float dist_m;
|
||||||
@@ -46,14 +47,14 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
int parse_ret;
|
int parse_ret;
|
||||||
|
|
||||||
for (int i = 0; i < strlen(lines[l]); i++)
|
for (int i = 0; i < strlen(lines[l]); i++) {
|
||||||
{
|
|
||||||
parse_ret = sf0x_parser(lines[l][i], _parserbuf, &_parsebuf_index, &state, &dist_m);
|
parse_ret = sf0x_parser(lines[l][i], _parserbuf, &_parsebuf_index, &state, &dist_m);
|
||||||
|
|
||||||
if (parse_ret == 0) {
|
if (parse_ret == 0) {
|
||||||
printf("\nparsed: %f %s\n", dist_m, (parse_ret == 0) ? "OK" : "");
|
printf("\nparsed: %f %s\n", dist_m, (parse_ret == 0) ? "OK" : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s", lines[l]);
|
printf("%s", lines[l]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
#ifdef SF0X_DEBUG
|
#ifdef SF0X_DEBUG
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
const char* parser_state[] = {
|
const char *parser_state[] = {
|
||||||
"0_UNSYNC",
|
"0_UNSYNC",
|
||||||
"1_SYNC",
|
"1_SYNC",
|
||||||
"2_GOT_DIGIT0",
|
"2_GOT_DIGIT0",
|
||||||
@@ -64,74 +64,87 @@ int sf0x_parser(char c, char *parserbuf, unsigned *parserbuf_index, enum SF0X_PA
|
|||||||
char *end;
|
char *end;
|
||||||
|
|
||||||
switch (*state) {
|
switch (*state) {
|
||||||
case SF0X_PARSE_STATE0_UNSYNC:
|
case SF0X_PARSE_STATE0_UNSYNC:
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
*state = SF0X_PARSE_STATE1_SYNC;
|
*state = SF0X_PARSE_STATE1_SYNC;
|
||||||
(*parserbuf_index) = 0;
|
(*parserbuf_index) = 0;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
case SF0X_PARSE_STATE1_SYNC:
|
break;
|
||||||
if (c >= '0' && c <= '9') {
|
|
||||||
*state = SF0X_PARSE_STATE2_GOT_DIGIT0;
|
|
||||||
parserbuf[*parserbuf_index] = c;
|
|
||||||
(*parserbuf_index)++;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SF0X_PARSE_STATE2_GOT_DIGIT0:
|
case SF0X_PARSE_STATE1_SYNC:
|
||||||
if (c >= '0' && c <= '9') {
|
if (c >= '0' && c <= '9') {
|
||||||
*state = SF0X_PARSE_STATE2_GOT_DIGIT0;
|
*state = SF0X_PARSE_STATE2_GOT_DIGIT0;
|
||||||
parserbuf[*parserbuf_index] = c;
|
parserbuf[*parserbuf_index] = c;
|
||||||
(*parserbuf_index)++;
|
(*parserbuf_index)++;
|
||||||
} else if (c == '.') {
|
}
|
||||||
*state = SF0X_PARSE_STATE3_GOT_DOT;
|
|
||||||
parserbuf[*parserbuf_index] = c;
|
|
||||||
(*parserbuf_index)++;
|
|
||||||
} else {
|
|
||||||
*state = SF0X_PARSE_STATE0_UNSYNC;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SF0X_PARSE_STATE3_GOT_DOT:
|
break;
|
||||||
if (c >= '0' && c <= '9') {
|
|
||||||
*state = SF0X_PARSE_STATE4_GOT_DIGIT1;
|
|
||||||
parserbuf[*parserbuf_index] = c;
|
|
||||||
(*parserbuf_index)++;
|
|
||||||
} else {
|
|
||||||
*state = SF0X_PARSE_STATE0_UNSYNC;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SF0X_PARSE_STATE4_GOT_DIGIT1:
|
case SF0X_PARSE_STATE2_GOT_DIGIT0:
|
||||||
if (c >= '0' && c <= '9') {
|
if (c >= '0' && c <= '9') {
|
||||||
*state = SF0X_PARSE_STATE5_GOT_DIGIT2;
|
*state = SF0X_PARSE_STATE2_GOT_DIGIT0;
|
||||||
parserbuf[*parserbuf_index] = c;
|
parserbuf[*parserbuf_index] = c;
|
||||||
(*parserbuf_index)++;
|
(*parserbuf_index)++;
|
||||||
} else {
|
|
||||||
*state = SF0X_PARSE_STATE0_UNSYNC;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SF0X_PARSE_STATE5_GOT_DIGIT2:
|
} else if (c == '.') {
|
||||||
if (c == '\r') {
|
*state = SF0X_PARSE_STATE3_GOT_DOT;
|
||||||
*state = SF0X_PARSE_STATE6_GOT_CARRIAGE_RETURN;
|
parserbuf[*parserbuf_index] = c;
|
||||||
} else {
|
(*parserbuf_index)++;
|
||||||
*state = SF0X_PARSE_STATE0_UNSYNC;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SF0X_PARSE_STATE6_GOT_CARRIAGE_RETURN:
|
} else {
|
||||||
if (c == '\n') {
|
*state = SF0X_PARSE_STATE0_UNSYNC;
|
||||||
parserbuf[*parserbuf_index] = '\0';
|
}
|
||||||
*dist = strtod(parserbuf, &end);
|
|
||||||
*state = SF0X_PARSE_STATE1_SYNC;
|
break;
|
||||||
*parserbuf_index = 0;
|
|
||||||
ret = 0;
|
case SF0X_PARSE_STATE3_GOT_DOT:
|
||||||
} else {
|
if (c >= '0' && c <= '9') {
|
||||||
*state = SF0X_PARSE_STATE0_UNSYNC;
|
*state = SF0X_PARSE_STATE4_GOT_DIGIT1;
|
||||||
}
|
parserbuf[*parserbuf_index] = c;
|
||||||
break;
|
(*parserbuf_index)++;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
*state = SF0X_PARSE_STATE0_UNSYNC;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SF0X_PARSE_STATE4_GOT_DIGIT1:
|
||||||
|
if (c >= '0' && c <= '9') {
|
||||||
|
*state = SF0X_PARSE_STATE5_GOT_DIGIT2;
|
||||||
|
parserbuf[*parserbuf_index] = c;
|
||||||
|
(*parserbuf_index)++;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
*state = SF0X_PARSE_STATE0_UNSYNC;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SF0X_PARSE_STATE5_GOT_DIGIT2:
|
||||||
|
if (c == '\r') {
|
||||||
|
*state = SF0X_PARSE_STATE6_GOT_CARRIAGE_RETURN;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
*state = SF0X_PARSE_STATE0_UNSYNC;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SF0X_PARSE_STATE6_GOT_CARRIAGE_RETURN:
|
||||||
|
if (c == '\n') {
|
||||||
|
parserbuf[*parserbuf_index] = '\0';
|
||||||
|
*dist = strtod(parserbuf, &end);
|
||||||
|
*state = SF0X_PARSE_STATE1_SYNC;
|
||||||
|
*parserbuf_index = 0;
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
*state = SF0X_PARSE_STATE0_UNSYNC;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SF0X_DEBUG
|
#ifdef SF0X_DEBUG
|
||||||
|
|||||||
Reference in New Issue
Block a user