void workFunctionDiagnostic(MODEL_TYPE modelType) { std::string sFinalResult; if( TEST_BIT( nFunctionSelect, TIMER_16BIT_TEST)) { SixteenBitTimerTest timerTest; timerTest.diagnostic(); sFinalResult.append(timerTest.getResultString()); } if( TEST_BIT(nFunctionSelect, RANDOM_GEN_TEST)) { RandomGeneratorTest randomTest; randomTest.diagnostic(); sFinalResult.append(randomTest.getResultString()); } if( TEST_BIT(nFunctionSelect, CCTALK_TEST)) { CCTalkTest ccTalkTest(modelType); ccTalkTest.diagnostic(); sFinalResult.append(ccTalkTest.getResultString()); } if( TEST_BIT(nFunctionSelect, SAS_TEST)) { SASTest sasTest; sasTest.diagnostic(); sFinalResult.append(sasTest.getResultString()); } if( TEST_BIT(nFunctionSelect, SRAM_TEST)) { //SRAMTest sramTest; //sramTest.diagnostic(); //sFinalResult.append(sramTest.getResultString()); } if( TEST_BIT(nFunctionSelect, EEPROM_TEST)) { EEPROMTest eepromTest(modelType); eepromTest.diagnostic(); sFinalResult.append(eepromTest.getResultString()); } if( TEST_BIT(nFunctionSelect, GPO_TEST)) { GPOTest gpoTest; gpoTest.diagnostic(); sFinalResult.append(gpoTest.getResultString()); } if( TEST_BIT(nFunctionSelect, GPI_TEST)) { GPITest gpiTest; gpiTest.diagnostic(); sFinalResult.append(gpiTest.getResultString()); } if( TEST_BIT(nFunctionSelect, RTC_INSTURSION_TEST)) { PICIntrusionTest picTest(modelType); picTest.diagnostic(); sFinalResult.append(picTest.getResultString()); } if( TEST_BIT(nFunctionSelect, SPI_TEST)) { SPITest spiTest; spiTest.diagnostic(); sFinalResult.append(spiTest.getResultString()); } ClearScreen(); printf("Diagnostic Complete!\n\nResult:\n\n"); printf("%s", sFinalResult.c_str()); SystemPause(); }
static void main_task(void *pvParameters) { int i; char ch; bool selftestPasses = true; /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_I2C1_Init(); MX_USART1_UART_Init(); MX_SPI1_Init(); MX_USB_DEVICE_Init(); // Light up all LEDs to test ledOn(ledRanging); ledOn(ledSync); ledOn(ledMode); printf("\r\n\r\n====================\r\n"); printf("SYSTEM\t: CPU-ID: "); for (i=0; i<12; i++) { printf("%02x", uid[i]); } printf("\r\n"); // Initializing pressure sensor (if present ...) lps25hInit(&hi2c1); testSupportPrintStart("Initializing pressure sensor"); if (lps25hTestConnection()) { printf("[OK]\r\n"); lps25hSetEnabled(true); } else { printf("[FAIL] (%u)\r\n", (unsigned int)hi2c1.ErrorCode); selftestPasses = false; } testSupportPrintStart("Pressure sensor self-test"); testSupportReport(&selftestPasses, lps25hSelfTest()); // Initializing i2c eeprom eepromInit(&hi2c1); testSupportPrintStart("EEPROM self-test"); testSupportReport(&selftestPasses, eepromTest()); cfgInit(); // Initialising radio testSupportPrintStart("Initialize UWB "); uwbInit(); if (uwbTest()) { printf("[OK]\r\n"); } else { printf("[ERROR]: %s\r\n", uwbStrError()); selftestPasses = false; } if (!selftestPasses) { printf("TEST\t: One or more self-tests failed, blocking startup!\r\n"); usbcommSetSystemStarted(true); } // Printing UWB configuration struct uwbConfig_s * uwbConfig = uwbGetConfig(); printf("CONFIG\t: Address is 0x%X\r\n", uwbConfig->address[0]); printf("CONFIG\t: Mode is %s\r\n", uwbAlgorithmName(uwbConfig->mode)); printf("CONFIG\t: Tag mode anchor list (%i): ", uwbConfig->anchorListSize); for (i = 0; i < uwbConfig->anchorListSize; i++) { printf("0x%02X ", uwbConfig->anchors[i]); } printf("\r\n"); HAL_Delay(500); ledOff(ledRanging); ledOff(ledSync); ledOff(ledMode); printf("SYSTEM\t: Node started ...\r\n"); printf("SYSTEM\t: Press 'h' for help.\r\n"); usbcommSetSystemStarted(true); // Starts UWB protocol uwbStart(); // Main loop ... while(1) { usbcommPrintWelcomeMessage(); ledTick(); // // Measure pressure // if (uwbConfig.mode != modeSniffer) { // if(lps25hGetData(&pressure, &temperature, &asl)) { // pressure_ok = true; // } else { // printf("Fail reading pressure\r\n"); // printf("pressure not ok\r\n"); // } // } // Accepts serial commands #ifdef USE_FTDI_UART if (HAL_UART_Receive(&huart1, (uint8_t*)&ch, 1, 0) == HAL_OK) { #else if(usbcommRead(&ch, 1)) { #endif handleInput(ch); } } } /* Function required to use "printf" to print on serial console */ int _write (int fd, const void *buf, size_t count) { // stdout if (fd == 1) { #ifdef USE_FTDI_UART HAL_UART_Transmit(&huart1, (uint8_t *)buf, count, HAL_MAX_DELAY); #else usbcommWrite(buf, count); #endif } // stderr if (fd == 2) { HAL_UART_Transmit(&huart1, (uint8_t *)buf, count, HAL_MAX_DELAY); } return count; } static void handleInput(char ch) { bool configChanged = true; static enum menu_e {mainMenu, modeMenu} currentMenu = mainMenu; switch (currentMenu) { case mainMenu: switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': changeAddress(ch - '0'); break; case 'a': changeMode(MODE_ANCHOR); break; case 't': changeMode(MODE_TAG); break; case 's': changeMode(MODE_SNIFFER); break; case 'm': printModeList(); printf("Type 0-9 to choose new mode...\r\n"); currentMenu = modeMenu; configChanged = false; break; case 'd': restConfig(); break; case 'h': help(); configChanged = false; break; case '#': productionTestsRun(); printf("System halted, reset to continue\r\n"); while(true){} break; default: configChanged = false; break; } break; case modeMenu: switch(ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': changeMode(ch - '0'); currentMenu = mainMenu; break; default: printf("Incorrect mode '%c'\r\n", ch); currentMenu = mainMenu; configChanged = false; break; } break; } if (configChanged) { printf("EEPROM configuration changed, restart for it to take effect!\r\n"); } }