static void printfileinfo(BaseSequentialStream *sdp, EepromFileStream *efsp){ chprintf(sdp, "size = %u, position = %u, barrier_low = %u, barrier_hi = %u", chFileStreamGetSize(efsp), chFileStreamGetPosition(efsp), efsp->cfg->barrier_low, efsp->cfg->barrier_hi); cli_println(""); chThdSleepMilliseconds(100); }
/** * Working with parameters from CLI. * * examples: * wps 3 print waypoint #3 * wps 3 10.3 2.0 set waypoint #3 in (10.3,2.0) coordinates */ Thread* wps_clicmd(int argc, const char * const * argv, SerialDriver *sdp){ (void)sdp; int sscanf_status; uint16_t seq = 0; /* no arguments */ if (argc == 0) _wps_print_all_cmd(); /* 1 argument */ else if (argc == 1){ sscanf_status = sscanf(argv[0], "%hu", &seq); if (sscanf_status != 1){ cli_println("ERROR: Bad arguments."); _wps_cli_help(); } else _wps_print_wp(seq); } /* 2 arguments */ else if (argc == 2){ cli_println("ERROR: Bad arguments."); _wps_cli_help(); } /* 3 arguments */ else if (argc == 3){ _wps_cli_set_wp(argv); } /* error handler */ else{ cli_println("ERROR: too many arguments."); _wps_cli_help(); } /* stub */ return NULL; }
/** * Command to handle RTC. */ thread_t* date_clicmd(int argc, const char * const * argv, BaseChannel *bchnp) { (void)bchnp; time_t tv_sec = 0; int64_t tv_usec = 0; int sscanf_status; /**/ if (argc == 2) { if (0 == strcmp(argv[0], "set")) { sscanf_status = sscanf(argv[1], "%i", (int*)&tv_sec); if (sscanf_status != 1) cli_println("ERROR. Time value inconsistent"); else if (tv_sec < BUILD_TIME) cli_println("ERROR. Time in past"); else{ tv_usec = tv_sec; tv_usec *= 1000000; rtc_set_time_unix(tv_sec); TimeKeeper::utc(tv_usec); } } else if (0 == strcmp(argv[0], "drift")) { sscanf_status = sscanf(argv[1], "%i", (int*)&tv_sec); if (sscanf_status != 1) cli_println("ERROR. Value inconsistent"); else { timer_skew = tv_sec; } } } /* 1 argument */ else if (argc == 1) { if (0 == strcmp(argv[0], "drift")) { int tmp = timer_skew; cli_print(tmp); cli_println(""); } } /* error handler */ else { const size_t n = 40; size_t nres = 0; char str[n]; tv_usec = rtc_get_time_unix_usec(); nres = format_usec(str, n, tv_usec); cli_print("RTC: "); cli_print_long(str, n, nres); cli_print(" S since Unix epoch. "); TimeKeeper::format_time(tv_usec, str, n); cli_println(str); tv_usec = TimeKeeper::utc(); nres = format_usec(str, n, tv_usec); cli_print("CNT: "); cli_print_long(str, n, nres); cli_print(" S since Unix epoch. "); TimeKeeper::format_time(tv_usec, str, n); cli_println(str); chSysLock(); tv_usec = time_gps_us; chSysUnlock(); nres = format_usec(str, n, tv_usec); cli_print("GPS: "); cli_print_long(str, n, nres); cli_print(" S since Unix epoch. "); TimeKeeper::format_time(tv_usec, str, n); cli_println(str); nres = snprintf(str, n, "Drift estimate: %lld", drift_est.sample - drift_est.sample_prev - 1000000); cli_print_long(str, n, nres); cli_println(""); cli_println("To adjust time run 'date set N'"); cli_println(" where 'N' is count of seconds (UTC) since Unix epoch."); cli_println(" you can obtain this value from Unix command line: 'date -u +%s'"); } /* stub */ return nullptr; }
msg_t EepromTestThread(void *sdp){ chRegSetThreadName("EepromTst"); cli_println("basic tests"); cli_println("--------------------------------------------------------------"); cli_print("mount aligned file sized to whole test area"); ocfg.barrier_low = TEST_AREA_START; ocfg.barrier_hi = TEST_AREA_END; EepromFileOpen(&ofile, &ocfg); OK(); printfileinfo(sdp, &ofile); cli_print("test fill with 0xFF"); pattern_fill(&ofile, 0xFF); if (chThdShouldTerminate()){goto END;} OK(); cli_print("test fill with 0xAA"); pattern_fill(&ofile, 0xAA); if (chThdShouldTerminate()){goto END;} OK(); cli_print("test fill with 0x55"); pattern_fill(&ofile, 0x55); if (chThdShouldTerminate()){goto END;} OK(); cli_print("test fill with 0x00"); pattern_fill(&ofile, 0x00); if (chThdShouldTerminate()){goto END;} OK(); cli_print("Closing file"); chFileStreamClose(&ofile); OK(); uint32_t b1, b2, b3, b4, istart, ilen; uint8_t pattern = 0x55; b1 = TEST_AREA_START; b2 = TEST_AREA_START + EEPROM_PAGE_SIZE; b3 = TEST_AREA_END - EEPROM_PAGE_SIZE; b4 = TEST_AREA_END; istart = 0; ilen = b3-b2; cli_println(" Linear barriers testing."); chThdSleepMilliseconds(20); overflow_check( b1, b2, b3, b4, istart, ilen, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2, b3, b4, istart + 1, ilen - 1, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2, b3, b4, istart + 1, ilen, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2, b3, b4, istart + 1, ilen + 23, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2 - 1, b3 + 1, b4, istart, ilen, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2 - 2, b3 + 2, b4, istart + 2, ilen, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2 - 1, b3 + 1, b4, istart + 1, ilen + 23, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2 - 2, b3 + 2, b4, istart + 1, ilen + 23, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2 + 2, b3 - 3, b4, istart + 2, ilen, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2, b2 + 1, b4, istart, ilen, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2, b2 + 2, b4, istart, ilen, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2, b2 + 3, b4, istart, ilen, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2 + 1, b2 + 2, b4, istart, ilen, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2 + 1, b2 + 3, b4, istart, ilen, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2 + 1, b2 + 4, b4, istart, ilen, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2 - 1, b2, b4, istart, ilen, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2 - 1, b2 + 1, b4, istart, ilen, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2 - 1, b2 + 2, b4, istart, ilen, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2 - 1, b2 + 1, b4, istart + 1, ilen, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2 - 1, b2 + 2, b4, istart + 1, ilen, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; overflow_check( b1, b2 - 1, b2 + 3, b4, istart + 1, ilen, pattern, FALSE, sdp); if (chThdShouldTerminate()){goto END;} pattern++; cli_println(" Basic API testing."); chThdSleepMilliseconds(20); ocfg.barrier_low = TEST_AREA_START; ocfg.barrier_hi = TEST_AREA_END; EepromFileOpen(&ofile, &ocfg); chFileStreamSeek(&ofile, 0); EepromWriteByte(&ofile, 0x11); EepromWriteHalfword(&ofile, 0x2222); EepromWriteWord(&ofile, 0x33333333); chFileStreamSeek(&ofile, 0); if(EepromReadByte(&ofile) != 0x11) chDbgPanic(""); if(EepromReadHalfword(&ofile) != 0x2222) chDbgPanic(""); if(EepromReadWord(&ofile) != 0x33333333) chDbgPanic(""); chFileStreamClose(&ofile); OK(); cli_println("All tests passed successfully."); END: chThdExit(0); return 0; }
static void _wps_cli_help(void){ cli_println("Allowable commands in ground rover mode:"); }