diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9679ee280661c7a9af65b8f8d781fd1d00697231..3058117f1245d7fc99edee188945a9854d74bbcb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -55,7 +55,6 @@ format: stage: lint script: - ./scripts/linter.py --format src - allow_failure: true copyright: stage: lint diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6877fbd4a2947ca17e1a43cef429369ee6dcbdee..65ed1c41073c5e61b25667609388521502b0bb58 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,6 +22,7 @@ repos: hooks: - id: clang-format args: [ + -style=file, --dry-run, --Werror ] diff --git a/sbs b/sbs index 92ad65f1340826a23a70a1861d4d4159a3e7d103..daee658fbf6a7b3f25f668dbe26be5640635277d 100755 --- a/sbs +++ b/sbs @@ -79,7 +79,7 @@ find_deps() { configure() { ohai "Configure" - + defs="-DCMAKE_TOOLCHAIN_FILE=$sbs_base/libs/miosix-kernel/miosix/_tools/toolchain.cmake" defs="$defs -DCMAKE_C_FLAGS=-fdiagnostics-color=always -DCMAKE_CXX_FLAGS=-fdiagnostics-color=always" [ "$found_ccache" = true ] && defs="$defs -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache" @@ -114,14 +114,14 @@ check_configured() { configure echo fi - + true } build() { if check_configured; then ohai "Build" - + cmake --build "$build_dir" $(get_jobs_opt) --target "$1" fi } @@ -138,7 +138,7 @@ lint_clangformat() { ohai "Lint (clang-format)" # Real-time colored output of clang-format - find "$source_dir/src" -type f \( -iname \*.cpp -o -iname \*.h -o -iname \*.c \) -exec clang-format --dry-run --Werror {} \; + find "$source_dir/src" -type f \( -iname \*.cpp -o -iname \*.h -o -iname \*.c \) -exec clang-format -style=file --dry-run --Werror {} \; echo } diff --git a/scripts/linter.py b/scripts/linter.py index 7901b0ea83f2a548f5f7144d531abe07bf716457..44a7f6c846c772ff63ae93bd67998a8ba77b790e 100755 --- a/scripts/linter.py +++ b/scripts/linter.py @@ -194,7 +194,7 @@ def check_format(directory): # Dry run clang-format and check if we have an error returnCode = call( - ['clang-format', '--dry-run', '--Werror', '--ferror-limit=1', currentFilepath], stderr=DEVNULL) + ['clang-format', '-style=file', '--dry-run', '--Werror', '--ferror-limit=1', currentFilepath], stderr=DEVNULL) # If and error occurs warn the user if(returnCode != 0): diff --git a/src/entrypoints/kernel-testsuite.cpp b/src/entrypoints/kernel-testsuite.cpp index 671881e9095c1c2fe600bb2dec1beee39bb43450..fcdca9b19010b571cc239ce7872ca22335ce45b1 100644 --- a/src/entrypoints/kernel-testsuite.cpp +++ b/src/entrypoints/kernel-testsuite.cpp @@ -2402,7 +2402,7 @@ void test_14() // Test 1: join on joinable, not already deleted void *result = 0; t = Thread::create(t14_p2, STACK_SMALL, 0, (void *)0xdeadbeef, - Thread::JOINABLE); + Thread::JOINABLE); Thread::yield(); if (t->join(&result) == false) fail("Thread::join (1)"); @@ -2442,7 +2442,7 @@ void test_14() // Test 6: join on already deleted result = 0; t = Thread::create(t14_p1, STACK_SMALL, 0, (void *)0xdeadbeef, - Thread::JOINABLE); + Thread::JOINABLE); t->terminate(); Thread::sleep(10); if (Thread::exists(t) == false) diff --git a/src/shared/drivers/gps/nmea/nmea.c b/src/shared/drivers/gps/nmea/nmea.c index 68d659f5f85a3ff4a6644140db615a5fd3684f03..bcf831c855651a3d41ff4f02a2e28a94164b2871 100644 --- a/src/shared/drivers/gps/nmea/nmea.c +++ b/src/shared/drivers/gps/nmea/nmea.c @@ -5,12 +5,11 @@ * published by Sam Hocevar. See the COPYING file for more details. */ +#include <ctype.h> #include <drivers/gps/nmea/nmea.h> - +#include <stdarg.h> #include <stdlib.h> #include <string.h> -#include <ctype.h> -#include <stdarg.h> #include <time.h> #define boolstr(s) ((s) ? "true" : "false") @@ -54,11 +53,12 @@ bool minmea_check(const char *sentence, bool strict) return false; // The optional checksum is an XOR of all bytes between "$" and "*". - while (*sentence && *sentence != '*' && isprint((unsigned char) *sentence)) + while (*sentence && *sentence != '*' && isprint((unsigned char)*sentence)) checksum ^= *sentence++; // If checksum is present... - if (*sentence == '*') { + if (*sentence == '*') + { // Extract checksum. sentence++; int upper = hex2int(*sentence++); @@ -72,7 +72,9 @@ bool minmea_check(const char *sentence, bool strict) // Check for checksum mismatch. if (checksum != expected) return false; - } else if (strict) { + } + else if (strict) + { // Discard non-checksummed frames in strict mode. return false; } @@ -84,61 +86,75 @@ bool minmea_check(const char *sentence, bool strict) return true; } -static inline bool minmea_isfield(char c) { - return isprint((unsigned char) c) && c != ',' && c != '*'; +static inline bool minmea_isfield(char c) +{ + return isprint((unsigned char)c) && c != ',' && c != '*'; } bool minmea_scan(const char *sentence, const char *format, ...) { - bool result = false; + bool result = false; bool optional = false; va_list ap; va_start(ap, format); const char *field = sentence; -#define next_field() \ - do { \ - /* Progress to the next field. */ \ - while (minmea_isfield(*sentence)) \ - sentence++; \ +#define next_field() \ + do \ + { \ + /* Progress to the next field. */ \ + while (minmea_isfield(*sentence)) \ + sentence++; \ /* Make sure there is a field there. */ \ - if (*sentence == ',') { \ - sentence++; \ - field = sentence; \ - } else { \ - field = NULL; \ - } \ + if (*sentence == ',') \ + { \ + sentence++; \ + field = sentence; \ + } \ + else \ + { \ + field = NULL; \ + } \ } while (0) - while (*format) { + while (*format) + { char type = *format++; - if (type == ';') { + if (type == ';') + { // All further fields are optional. optional = true; continue; } - if (!field && !optional) { + if (!field && !optional) + { // Field requested but we ran out if input. Bail out. goto parse_error; } - switch (type) { - case 'c': { // Single character field (char). + switch (type) + { + case 'c': + { // Single character field (char). char value = '\0'; if (field && minmea_isfield(*field)) value = *field; *va_arg(ap, char *) = value; - } break; + } + break; - case 'd': { // Single character direction field (int). + case 'd': + { // Single character direction field (int). int value = 0; - if (field && minmea_isfield(*field)) { - switch (*field) { + if (field && minmea_isfield(*field)) + { + switch (*field) + { case 'N': case 'E': value = 1; @@ -153,29 +169,42 @@ bool minmea_scan(const char *sentence, const char *format, ...) } *va_arg(ap, int *) = value; - } break; + } + break; - case 'f': { // Fractional value with scale (struct minmea_float). - int sign = 0; + case 'f': + { // Fractional value with scale (struct minmea_float). + int sign = 0; int_least32_t value = -1; int_least32_t scale = 0; - if (field) { - while (minmea_isfield(*field)) { - if (*field == '+' && !sign && value == -1) { + if (field) + { + while (minmea_isfield(*field)) + { + if (*field == '+' && !sign && value == -1) + { sign = 1; - } else if (*field == '-' && !sign && value == -1) { + } + else if (*field == '-' && !sign && value == -1) + { sign = -1; - } else if (isdigit((unsigned char) *field)) { + } + else if (isdigit((unsigned char)*field)) + { int digit = *field - '0'; if (value == -1) value = 0; - if (value > (INT_LEAST32_MAX-digit) / 10) { + if (value > (INT_LEAST32_MAX - digit) / 10) + { /* we ran out of bits, what do we do? */ - if (scale) { + if (scale) + { /* truncate extra precision */ break; - } else { + } + else + { /* integer overflow. bail out. */ goto parse_error; } @@ -183,14 +212,20 @@ bool minmea_scan(const char *sentence, const char *format, ...) value = (10 * value) + digit; if (scale) scale *= 10; - } else if (*field == '.' && scale == 0) { + } + else if (*field == '.' && scale == 0) + { scale = 1; - } else if (*field == ' ') { + } + else if (*field == ' ') + { /* Allow spaces at the start of the field. Not NMEA * conformant, but some modules do this. */ if (sign != 0 || value != -1 || scale != 0) goto parse_error; - } else { + } + else + { goto parse_error; } field++; @@ -200,24 +235,31 @@ bool minmea_scan(const char *sentence, const char *format, ...) if ((sign || scale) && value == -1) goto parse_error; - if (value == -1) { + if (value == -1) + { /* No digits were scanned. */ value = 0; scale = 0; - } else if (scale == 0) { + } + else if (scale == 0) + { /* No decimal point. */ scale = 1; } if (sign) value *= sign; - *va_arg(ap, struct minmea_float *) = (struct minmea_float) {value, scale}; - } break; + *va_arg(ap, struct minmea_float *) = + (struct minmea_float){value, scale}; + } + break; - case 'i': { // Integer value, default 0 (int). + case 'i': + { // Integer value, default 0 (int). int value = 0; - if (field) { + if (field) + { char *endptr; value = strtol(field, &endptr, 10); if (minmea_isfield(*endptr)) @@ -225,107 +267,127 @@ bool minmea_scan(const char *sentence, const char *format, ...) } *va_arg(ap, int *) = value; - } break; + } + break; - case 's': { // String value (char *). + case 's': + { // String value (char *). char *buf = va_arg(ap, char *); - if (field) { + if (field) + { while (minmea_isfield(*field)) *buf++ = *field++; } *buf = '\0'; - } break; + } + break; - case 't': { // NMEA talker+sentence identifier (char *). + case 't': + { // NMEA talker+sentence identifier (char *). // This field is always mandatory. if (!field) goto parse_error; if (field[0] != '$') goto parse_error; - int f=0; - for (f=0; f<5; f++) - if (!minmea_isfield(field[1+f])) + int f = 0; + for (f = 0; f < 5; f++) + if (!minmea_isfield(field[1 + f])) goto parse_error; char *buf = va_arg(ap, char *); - memcpy(buf, field+1, 5); + memcpy(buf, field + 1, 5); buf[5] = '\0'; - } break; + } + break; - case 'D': { // Date (int, int, int), -1 if empty. + case 'D': + { // Date (int, int, int), -1 if empty. struct minmea_date *date = va_arg(ap, struct minmea_date *); int d = -1, m = -1, y = -1; - if (field && minmea_isfield(*field)) { + if (field && minmea_isfield(*field)) + { // Always six digits. - int f=0; - for (f=0; f<6; f++) - if (!isdigit((unsigned char) field[f])) + int f = 0; + for (f = 0; f < 6; f++) + if (!isdigit((unsigned char)field[f])) goto parse_error; char dArr[] = {field[0], field[1], '\0'}; char mArr[] = {field[2], field[3], '\0'}; char yArr[] = {field[4], field[5], '\0'}; - d = strtol(dArr, NULL, 10); - m = strtol(mArr, NULL, 10); - y = strtol(yArr, NULL, 10); + d = strtol(dArr, NULL, 10); + m = strtol(mArr, NULL, 10); + y = strtol(yArr, NULL, 10); } - date->day = d; + date->day = d; date->month = m; - date->year = y; - } break; + date->year = y; + } + break; - case 'T': { // Time (int, int, int, int), -1 if empty. + case 'T': + { // Time (int, int, int, int), -1 if empty. struct minmea_time *time_ = va_arg(ap, struct minmea_time *); int h = -1, i = -1, s = -1, u = -1; - if (field && minmea_isfield(*field)) { + if (field && minmea_isfield(*field)) + { // Minimum required: integer time. - int f=0; - for (f=0; f<6; f++) - if (!isdigit((unsigned char) field[f])) + int f = 0; + for (f = 0; f < 6; f++) + if (!isdigit((unsigned char)field[f])) goto parse_error; char hArr[] = {field[0], field[1], '\0'}; char iArr[] = {field[2], field[3], '\0'}; char sArr[] = {field[4], field[5], '\0'}; - h = strtol(hArr, NULL, 10); - i = strtol(iArr, NULL, 10); - s = strtol(sArr, NULL, 10); + h = strtol(hArr, NULL, 10); + i = strtol(iArr, NULL, 10); + s = strtol(sArr, NULL, 10); field += 6; // Extra: fractional time. Saved as microseconds. - if (*field++ == '.') { + if (*field++ == '.') + { int value = 0; int scale = 1000000; - while (isdigit((unsigned char) *field) && scale > 1) { + while (isdigit((unsigned char)*field) && scale > 1) + { value = (value * 10) + (*field++ - '0'); scale /= 10; } u = value * scale; - } else { + } + else + { u = 0; } } - time_->hours = h; - time_->minutes = i; - time_->seconds = s; + time_->hours = h; + time_->minutes = i; + time_->seconds = s; time_->microseconds = u; - } break; + } + break; - case '_': { // Ignore the field. - } break; + case '_': + { // Ignore the field. + } + break; - default: { // Unknown. + default: + { // Unknown. goto parse_error; - } break; + } + break; } next_field(); @@ -360,19 +422,19 @@ enum minmea_sentence_id minmea_sentence_id(const char *sentence, bool strict) if (!minmea_scan(sentence, "t", type)) return MINMEA_INVALID; - if (!strcmp(type+2, "RMC")) + if (!strcmp(type + 2, "RMC")) return MINMEA_SENTENCE_RMC; - if (!strcmp(type+2, "GGA")) + if (!strcmp(type + 2, "GGA")) return MINMEA_SENTENCE_GGA; - if (!strcmp(type+2, "GSA")) + if (!strcmp(type + 2, "GSA")) return MINMEA_SENTENCE_GSA; - if (!strcmp(type+2, "GLL")) + if (!strcmp(type + 2, "GLL")) return MINMEA_SENTENCE_GLL; - if (!strcmp(type+2, "GST")) + if (!strcmp(type + 2, "GST")) return MINMEA_SENTENCE_GST; - if (!strcmp(type+2, "GSV")) + if (!strcmp(type + 2, "GSV")) return MINMEA_SENTENCE_GSV; - if (!strcmp(type+2, "VTG")) + if (!strcmp(type + 2, "VTG")) return MINMEA_SENTENCE_VTG; return MINMEA_UNKNOWN; @@ -386,18 +448,12 @@ bool minmea_parse_rmc(struct minmea_sentence_rmc *frame, const char *sentence) int latitude_direction; int longitude_direction; int variation_direction; - if (!minmea_scan(sentence, "tTcfdfdffDfd", - type, - &frame->time, - &validity, - &frame->latitude, &latitude_direction, - &frame->longitude, &longitude_direction, - &frame->speed, - &frame->course, - &frame->date, - &frame->variation, &variation_direction)) + if (!minmea_scan(sentence, "tTcfdfdffDfd", type, &frame->time, &validity, + &frame->latitude, &latitude_direction, &frame->longitude, + &longitude_direction, &frame->speed, &frame->course, + &frame->date, &frame->variation, &variation_direction)) return false; - if (strcmp(type+2, "RMC")) + if (strcmp(type + 2, "RMC")) return false; frame->valid = (validity == 'A'); @@ -415,19 +471,14 @@ bool minmea_parse_gga(struct minmea_sentence_gga *frame, const char *sentence) int latitude_direction; int longitude_direction; - if (!minmea_scan(sentence, "tTfdfdiiffcfci_", - type, - &frame->time, - &frame->latitude, &latitude_direction, - &frame->longitude, &longitude_direction, - &frame->fix_quality, - &frame->satellites_tracked, - &frame->hdop, - &frame->altitude, &frame->altitude_units, - &frame->height, &frame->height_units, - &frame->dgps_age)) + if (!minmea_scan(sentence, "tTfdfdiiffcfci_", type, &frame->time, + &frame->latitude, &latitude_direction, &frame->longitude, + &longitude_direction, &frame->fix_quality, + &frame->satellites_tracked, &frame->hdop, &frame->altitude, + &frame->altitude_units, &frame->height, + &frame->height_units, &frame->dgps_age)) return false; - if (strcmp(type+2, "GGA")) + if (strcmp(type + 2, "GGA")) return false; frame->latitude.value *= latitude_direction; @@ -441,27 +492,14 @@ bool minmea_parse_gsa(struct minmea_sentence_gsa *frame, const char *sentence) // $GPGSA,A,3,04,05,,09,12,,,24,,,,,2.5,1.3,2.1*39 char type[6]; - if (!minmea_scan(sentence, "tciiiiiiiiiiiiifff", - type, - &frame->mode, - &frame->fix_type, - &frame->sats[0], - &frame->sats[1], - &frame->sats[2], - &frame->sats[3], - &frame->sats[4], - &frame->sats[5], - &frame->sats[6], - &frame->sats[7], - &frame->sats[8], - &frame->sats[9], - &frame->sats[10], - &frame->sats[11], - &frame->pdop, - &frame->hdop, - &frame->vdop)) + if (!minmea_scan( + sentence, "tciiiiiiiiiiiiifff", type, &frame->mode, + &frame->fix_type, &frame->sats[0], &frame->sats[1], &frame->sats[2], + &frame->sats[3], &frame->sats[4], &frame->sats[5], &frame->sats[6], + &frame->sats[7], &frame->sats[8], &frame->sats[9], &frame->sats[10], + &frame->sats[11], &frame->pdop, &frame->hdop, &frame->vdop)) return false; - if (strcmp(type+2, "GSA")) + if (strcmp(type + 2, "GSA")) return false; return true; @@ -474,15 +512,12 @@ bool minmea_parse_gll(struct minmea_sentence_gll *frame, const char *sentence) int latitude_direction; int longitude_direction; - if (!minmea_scan(sentence, "tfdfdTc;c", - type, - &frame->latitude, &latitude_direction, - &frame->longitude, &longitude_direction, - &frame->time, - &frame->status, - &frame->mode)) + if (!minmea_scan(sentence, "tfdfdTc;c", type, &frame->latitude, + &latitude_direction, &frame->longitude, + &longitude_direction, &frame->time, &frame->status, + &frame->mode)) return false; - if (strcmp(type+2, "GLL")) + if (strcmp(type + 2, "GLL")) return false; frame->latitude.value *= latitude_direction; @@ -496,18 +531,14 @@ bool minmea_parse_gst(struct minmea_sentence_gst *frame, const char *sentence) // $GPGST,024603.00,3.2,6.6,4.7,47.3,5.8,5.6,22.0*58 char type[6]; - if (!minmea_scan(sentence, "tTfffffff", - type, - &frame->time, - &frame->rms_deviation, - &frame->semi_major_deviation, - &frame->semi_minor_deviation, - &frame->semi_major_orientation, - &frame->latitude_error_deviation, + if (!minmea_scan( + sentence, "tTfffffff", type, &frame->time, &frame->rms_deviation, + &frame->semi_major_deviation, &frame->semi_minor_deviation, + &frame->semi_major_orientation, &frame->latitude_error_deviation, &frame->longitude_error_deviation, &frame->altitude_error_deviation)) return false; - if (strcmp(type+2, "GST")) + if (strcmp(type + 2, "GST")) return false; return true; @@ -522,31 +553,19 @@ bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence) // $GPGSV,4,4,13*7B char type[6]; - if (!minmea_scan(sentence, "tiii;iiiiiiiiiiiiiiii", - type, - &frame->total_msgs, - &frame->msg_nr, - &frame->total_sats, - &frame->sats[0].nr, - &frame->sats[0].elevation, - &frame->sats[0].azimuth, - &frame->sats[0].snr, - &frame->sats[1].nr, - &frame->sats[1].elevation, - &frame->sats[1].azimuth, - &frame->sats[1].snr, - &frame->sats[2].nr, - &frame->sats[2].elevation, - &frame->sats[2].azimuth, - &frame->sats[2].snr, - &frame->sats[3].nr, - &frame->sats[3].elevation, - &frame->sats[3].azimuth, - &frame->sats[3].snr - )) { + if (!minmea_scan( + sentence, "tiii;iiiiiiiiiiiiiiii", type, &frame->total_msgs, + &frame->msg_nr, &frame->total_sats, &frame->sats[0].nr, + &frame->sats[0].elevation, &frame->sats[0].azimuth, + &frame->sats[0].snr, &frame->sats[1].nr, &frame->sats[1].elevation, + &frame->sats[1].azimuth, &frame->sats[1].snr, &frame->sats[2].nr, + &frame->sats[2].elevation, &frame->sats[2].azimuth, + &frame->sats[2].snr, &frame->sats[3].nr, &frame->sats[3].elevation, + &frame->sats[3].azimuth, &frame->sats[3].snr)) + { return false; } - if (strcmp(type+2, "GSV")) + if (strcmp(type + 2, "GSV")) return false; return true; @@ -561,32 +580,23 @@ bool minmea_parse_vtg(struct minmea_sentence_vtg *frame, const char *sentence) char type[6]; char c_true, c_magnetic, c_knots, c_kph, c_faa_mode; - if (!minmea_scan(sentence, "tfcfcfcfc;c", - type, - &frame->true_track_degrees, - &c_true, - &frame->magnetic_track_degrees, - &c_magnetic, - &frame->speed_knots, - &c_knots, - &frame->speed_kph, - &c_kph, - &c_faa_mode)) + if (!minmea_scan(sentence, "tfcfcfcfc;c", type, &frame->true_track_degrees, + &c_true, &frame->magnetic_track_degrees, &c_magnetic, + &frame->speed_knots, &c_knots, &frame->speed_kph, &c_kph, + &c_faa_mode)) return false; - if (strcmp(type+2, "VTG")) + if (strcmp(type + 2, "VTG")) return false; // check chars - if (c_true != 'T' || - c_magnetic != 'M' || - c_knots != 'N' || - c_kph != 'K') + if (c_true != 'T' || c_magnetic != 'M' || c_knots != 'N' || c_kph != 'K') return false; - //frame->faa_mode = c_faa_mode; + // frame->faa_mode = c_faa_mode; return true; } /* -int minmea_gettime(struct timespec *ts, const struct minmea_date *date, const struct minmea_time *time_) +int minmea_gettime(struct timespec *ts, const struct minmea_date *date, const +struct minmea_time *time_) { if (date->year == -1 || time_->hours == -1) return -1; @@ -600,13 +610,9 @@ int minmea_gettime(struct timespec *ts, const struct minmea_date *date, const st tm.tm_min = time_->minutes; tm.tm_sec = time_->seconds; - time_t timestamp = timegm(&tm); //See README.md if your system lacks timegm(). - if (timestamp != -1) { - ts->tv_sec = timestamp; - ts->tv_nsec = time_->microseconds * 1000; - return 0; - } else { - return -1; + time_t timestamp = timegm(&tm); //See README.md if your system lacks +timegm(). if (timestamp != -1) { ts->tv_sec = timestamp; ts->tv_nsec = +time_->microseconds * 1000; return 0; } else { return -1; } } */