/*! * \brief Prints the system low power status * \param io I/O channel to use for printing status */ static void TACHO_PrintStatus(const CLS1_StdIOType *io) { CLS1_SendStatusStr((unsigned char*)"Tacho", (unsigned char*)"\r\n", io->stdOut); CLS1_SendStatusStr((unsigned char*)" L speed", (unsigned char*)"", io->stdOut); CLS1_SendNum32s(TACHO_GetSpeed(TRUE), io->stdOut); CLS1_SendStr((unsigned char*)" steps/sec\r\n", io->stdOut); CLS1_SendStatusStr((unsigned char*)" R speed", (unsigned char*)"", io->stdOut); CLS1_SendNum32s(TACHO_GetSpeed(FALSE), io->stdOut); CLS1_SendStr((unsigned char*)" steps/sec\r\n", io->stdOut); }
/*! * \brief Prints the system low power status * \param io I/O channel to use for printing status */ static void TACHO_PrintStatus(const CLS1_StdIOType *io) { //TACHO_CalcSpeed(); /* only temporary until this is done periodically */ CLS1_SendStatusStr((unsigned char*)"Tacho", (unsigned char*)"\r\n", io->stdOut); CLS1_SendStatusStr((unsigned char*)" L speed", (unsigned char*)"", io->stdOut); CLS1_SendNum32s(TACHO_GetSpeed(TRUE), io->stdOut); CLS1_SendStr((unsigned char*)" steps/sec\r\n", io->stdOut); CLS1_SendStatusStr((unsigned char*)" R speed", (unsigned char*)"", io->stdOut); CLS1_SendNum32s(TACHO_GetSpeed(FALSE), io->stdOut); CLS1_SendStr((unsigned char*)" steps/sec\r\n", io->stdOut); }
/*! * \brief Parses a command * \param cmd Command string to be parsed * \param handled Sets this variable to TRUE if command was handled * \param io I/O stream to be used for input/output * \return Error code, ERR_OK if everything was fine */ uint8_t Q4CLeft_ParseCommand(const unsigned char *cmd, bool *handled, const CLS1_StdIOType *io) { uint8_t res=ERR_OK; if (UTIL1_strcmp((const char*)cmd, CLS1_CMD_HELP)==0 || UTIL1_strcmp((const char *)cmd, "Q4CLeft help")==0) { CLS1_SendHelpStr((const unsigned char*)"Q4CLeft", (const unsigned char*)"Q4CLeft command group\r\n", io->stdOut); CLS1_SendHelpStr((const unsigned char*)" help|status", (const unsigned char*)"Print help or status information\r\n", io->stdOut); CLS1_SendHelpStr((const unsigned char*)" reset", (const unsigned char*)"Reset the current position counter\r\n", io->stdOut); *handled = TRUE; } else if (UTIL1_strcmp((const char*)cmd, CLS1_CMD_STATUS)==0 || UTIL1_strcmp((const char*)cmd, "Q4CLeft status")==0) { CLS1_SendStr((const unsigned char*)"Q4CLeft:\r\n", io->stdOut); CLS1_SendStatusStr((const unsigned char*)" pos", (const unsigned char*)"", io->stdOut); #if Q4CLeft_CNTR_BITS==16 CLS1_SendNum16u(Q4CLeft_currPos, io->stdOut); #elif Q4CLeft_CNTR_BITS==32 CLS1_SendNum32u(Q4CLeft_currPos, io->stdOut); #else #error "unknown counter size!" #endif CLS1_SendStr((const unsigned char*)", ", io->stdOut); #if Q4CLeft_CNTR_BITS==16 CLS1_SendNum16s((int16_t)Q4CLeft_currPos, io->stdOut); #elif Q4CLeft_CNTR_BITS==32 CLS1_SendNum32s((int32_t)Q4CLeft_currPos, io->stdOut); #else #error "unknown counter size!" #endif CLS1_SendStr((const unsigned char*)"\r\n", io->stdOut); CLS1_SendStatusStr((const unsigned char*)" C1 C2", (const unsigned char*)"", io->stdOut); if (Q4CLeft_GET_C1_PIN()!=0) { CLS1_SendStr((const unsigned char*)"1 ", io->stdOut); } else { CLS1_SendStr((const unsigned char*)"0 ", io->stdOut); } if (Q4CLeft_GET_C2_PIN()!=0) { CLS1_SendStr((const unsigned char*)"1\r\n", io->stdOut); } else { CLS1_SendStr((const unsigned char*)"0\r\n", io->stdOut); } CLS1_SendStatusStr((const unsigned char*)" errors", (const unsigned char*)"", io->stdOut); CLS1_SendNum16u(Q4CLeft_nofErrors, io->stdOut); CLS1_SendStr((const unsigned char*)"\r\n", io->stdOut); *handled = TRUE; } else if (UTIL1_strcmp((const char*)cmd, "Q4CLeft reset")==0) { Q4CLeft_SetPos(0); Q4CLeft_nofErrors = 0; *handled = TRUE; } return res; }
/*! \brief Simple benchmark function: first we are going to write a file, then we will copy it */ static void benchmark(const CLS1_StdIOType *io) { static FIL fp; uint16_t i; UINT bw; uint8_t read_buf[10]; TIMEREC time, startTime; int32_t start_mseconds, mseconds; /* write benchmark */ CLS1_SendStr((const unsigned char*)"Benchmark: open file, write 10k times 10 bytes (100'000 bytes), close file:\r\n", io->stdOut); CLS1_SendStr((const unsigned char*)"Deleting any existing files...\r\n", io->stdOut); (void)FAT1_DeleteFile((const unsigned char*)"./bench.txt", io); (void)FAT1_DeleteFile((const unsigned char*)"./copy.txt", io); CLS1_SendStr((const unsigned char*)"Creating benchmark file...\r\n", io->stdOut); (void)TmDt1_GetTime(&startTime); if (FAT1_open(&fp, "./bench.txt", FA_CREATE_ALWAYS|FA_WRITE)!=FR_OK) { CLS1_SendStr((const unsigned char*)"*** Failed opening benchmark file!\r\n", io->stdErr); return; } for(i=0;i<10000;i++) { if (FAT1_write(&fp, "benchmark ", sizeof("benchmark ")-1, &bw)!=FR_OK) { CLS1_SendStr((const unsigned char*)"*** Failed writing file!\r\n", io->stdErr); (void)FAT1_close(&fp); return; } } (void)FAT1_close(&fp); (void)TmDt1_GetTime(&time); start_mseconds = startTime.Hour*60*60*1000 + startTime.Min*60*1000 + startTime.Sec*1000 + startTime.Sec100*10; mseconds = time.Hour*60*60*1000 + time.Min*60*1000 + time.Sec*1000 + time.Sec100*10 - start_mseconds; CLS1_SendNum32s(mseconds, io->stdOut); CLS1_SendStr((const unsigned char*)" mseconds needed for command.\r\n", io->stdOut); /* read benchmark */ CLS1_SendStr((const unsigned char*)"Reading benchmark file...\r\n", io->stdOut); (void)TmDt1_GetTime(&startTime); if (FAT1_open(&fp, "./bench.txt", FA_READ)!=FR_OK) { CLS1_SendStr((const unsigned char*)"*** Failed opening benchmark file!\r\n", io->stdErr); return; } for(i=0;i<10000;i++) { if (FAT1_read(&fp, &read_buf[0], sizeof(read_buf), &bw)!=FR_OK) { CLS1_SendStr((const unsigned char*)"*** Failed reading file!\r\n", io->stdErr); (void)FAT1_close(&fp); return; } } (void)FAT1_close(&fp); (void)TmDt1_GetTime(&time); start_mseconds = startTime.Hour*60*60*1000 + startTime.Min*60*1000 + startTime.Sec*1000 + startTime.Sec100*10; mseconds = time.Hour*60*60*1000 + time.Min*60*1000 + time.Sec*1000 + time.Sec100*10 - start_mseconds; CLS1_SendNum32s(mseconds, io->stdOut); CLS1_SendStr((const unsigned char*)" mseconds needed for command.\r\n", io->stdOut); /* copy benchmark */ CLS1_SendStr((const unsigned char*)"Benchmark: copy file (100'000 bytes):\r\n", io->stdOut); CLS1_SendStr((const unsigned char*)"Going to copy file...\r\n", io->stdOut); (void)TmDt1_GetTime(&startTime); (void)FAT1_CopyFile((const unsigned char*)"./bench.txt", (const unsigned char*)"./copy.txt", io); (void)TmDt1_GetTime(&time); start_mseconds = startTime.Hour*60*60*1000 + startTime.Min*60*1000 + startTime.Sec*1000 + startTime.Sec100*10; mseconds = time.Hour*60*60*1000 + time.Min*60*1000 + time.Sec*1000 + time.Sec100*10 - start_mseconds; CLS1_SendNum32s(mseconds, io->stdOut); CLS1_SendStr((const unsigned char*)" mseconds needed for command.\r\n", io->stdOut); CLS1_SendStr((const unsigned char*)"done!\r\n", io->stdOut); }