static bool CommandBoardDetails(int argc, char** argv) { bool result = false; if (ConfigStore_Config_Read() && ConfigStore_Config_IsValid() && ConfigStore_Config_IsMagicValid()) { StringBuilder response = StringBuilder_New(256); // DeviceType response = StringBuilder_Append(response, ConfigStore_GetDeviceType()); response = StringBuilder_Append(response, LINE_TERM); // MAC address response = StringBuilder_Append(response, ConfigStore_GetMacAddress()); response = StringBuilder_Append(response, LINE_TERM); // Serial number char snString[17]; memset((void*) snString, 0, 17); if (DeviceSerial_GetCpuSerialNumberHexString(snString, 17)) response = StringBuilder_Append(response, snString); else response = StringBuilder_Append(response, " "); response = StringBuilder_Append(response, LINE_TERM); // WiFi SoftAP SSID response = StringBuilder_Append(response, ConfigStore_GetSoftAPSSID()); response = StringBuilder_Append(response, LINE_TERM); // WiFi SoftAP password response = StringBuilder_Append(response, ConfigStore_GetSoftAPPassword()); response = StringBuilder_Append(response, LINE_TERM); char CB[2] = { 0, 0 }; int32_t byteCount = StringBuilder_GetLength(response); int32_t byteIndex = 0; for (byteIndex = 0; byteIndex < byteCount; byteIndex++) { CB[0] += (StringBuilder_GetCString(response))[byteIndex]; } // Compute checkbyte - 2's compliment of MOD-256 sum CB[0] ^= 0xFF; CB[0]++; response = StringBuilder_Append(response, CB); response = StringBuilder_Append(response, LINE_TERM); CreatorConsole_Puts(response); // Output entire response // TODO - delete? // byteCount = StringBuilder_GetLength(response); // uint8_t* _response = (uint8_t*) StringBuilder_GetCString(response); // for (byteIndex = 0; byteIndex < byteCount; byteIndex++) // { // if (((char *) _response)[byteIndex] == '\n') // CreatorConsole_Puts(LINE_TERM); // else // CreatorConsole_Putc(((char *) _response)[byteIndex]); // } //CreatorConsole_Puts(LINE_TERM); StringBuilder_Free(&response); result = true; } return result; }
/********************************************************************* * Function: void SYS_ArduinoMonitorTask(void) * * PreCondition: None * * Input: None * * Output: Receive and monitor communications with the Arduino-shield serial comms channel * * Side Effects: None * * Overview: This function implements the task for monitoring comms from the Arduino shield. * * Note: None ********************************************************************/ void SYS_ArduinoMonitorTask(FlowThread thread, void *taskParameters) { char incomingChar = 0; #define ARDUINO_SERIAL_PORT 6 #define ARDUINO_SERIAL_BAUD 115200 // power the PMODRS232 #if defined(MICROCHIP_PIC32) /* * UART 6 - Shield RS232 port * - u6Txd on pin RPB15 * - u6RXd on pin RPC2 */ // TXd Pin setup. PLIB_PORTS_PinModePerPortSelect (PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_15, PORTS_PIN_MODE_DIGITAL); PLIB_PORTS_PinDirectionOutputSet( PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_15 ); RPB15R = 0x04; // RXd Pin setup. PLIB_PORTS_PinModePerPortSelect (PORTS_ID_0, PORT_CHANNEL_C, PORTS_BIT_POS_2, PORTS_PIN_MODE_DIGITAL); PLIB_PORTS_PinDirectionInputSet( PORTS_ID_0, PORT_CHANNEL_C, PORTS_BIT_POS_2 ); U6RXR = 0x0C; // RPG8 3V3 supply Digilent PMODRS232 PLIB_PORTS_PinModePerPortSelect (PORTS_ID_0, PORT_CHANNEL_G, PORTS_BIT_POS_8, PORTS_PIN_MODE_DIGITAL); PLIB_PORTS_PinDirectionOutputSet( PORTS_ID_0, PORT_CHANNEL_G, PORTS_BIT_POS_8 ); PLIB_PORTS_PinSet( PORTS_ID_0, PORT_CHANNEL_G, PORTS_BIT_POS_8 ); // RPG7 0V supply to Digilent PMODRS232 PLIB_PORTS_PinModePerPortSelect (PORTS_ID_0, PORT_CHANNEL_G, PORTS_BIT_POS_7, PORTS_PIN_MODE_DIGITAL); PLIB_PORTS_PinDirectionOutputSet( PORTS_ID_0, PORT_CHANNEL_G, PORTS_BIT_POS_7 ); PLIB_PORTS_PinClear( PORTS_ID_0, PORT_CHANNEL_G, PORTS_BIT_POS_7 ); #endif arduinoSerial = FlowSerial_Init(ARDUINO_SERIAL_PORT, ARDUINO_SERIAL_BAUD); #define ARDUINO_CMD_BUFFER_LENGTH 255 char commandBuffer[ARDUINO_CMD_BUFFER_LENGTH+1]; char* cursor = commandBuffer; unsigned int freeBufferSize = ARDUINO_CMD_BUFFER_LENGTH; bool processCommand = false; memset(commandBuffer, '\0', ARDUINO_CMD_BUFFER_LENGTH+1); while(1) { while (FlowSerial_Ready(arduinoSerial)) { incomingChar = FlowSerial_Getc(arduinoSerial); if (freeBufferSize > 0 && incomingChar != '\n' && incomingChar != '\r') { *cursor = incomingChar; freeBufferSize--; cursor++; } else { *cursor = '\0'; processCommand = true; } if (processCommand) { cmdRequestID++; // Create a request to send to device owner StringBuilder request = StringBuilder_New(256); // Response Header request = StringBuilder_Append(request, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); request = StringBuilder_Append(request, "<command>"); char* datetime = CommandHandlers_GetTimeString(); request = StringBuilder_Append(request, "<sent type=\"datetime\">"); request = StringBuilder_Append(request, datetime); request = StringBuilder_Append(request, "</sent>"); Flow_MemFree((void **) &datetime); request = StringBuilder_Append(request, "<to>"); request = StringBuilder_Append(request, g_OwnerAoR); request = StringBuilder_Append(request, "</to>"); request = StringBuilder_Append(request, "<from>"); request = StringBuilder_Append(request, g_DeviceAoR); request = StringBuilder_Append(request, "</from>"); request = StringBuilder_Append(request, "<clientid type=\"integer\">"); request = StringBuilder_Append(request, g_ClientID); request = StringBuilder_Append(request, "</clientid>"); request = StringBuilder_Append(request, "<requestid type=\"integer\">"); request = StringBuilder_AppendInt(request, cmdRequestID); request = StringBuilder_Append(request, "</requestid>"); request = StringBuilder_Append(request, "<details>MIF DISPLAY "); request = StringBuilder_Append(request, commandBuffer); request = StringBuilder_Append(request, "</details>"); request = StringBuilder_Append(request, "</command>"); if (FlowMessaging_SendMessageToUser((FlowID) g_OwnerID, "text/plain", (char *)StringBuilder_GetCString(request), StringBuilder_GetLength(request), 60)) { FlowConsole_Printf("\n\rSuccessfully forwarded command received from Arduino-shield comms interface ('%s').\n\r", commandBuffer); } else { FlowConsole_Puts("\n\rWarning: Could not forward command received from Arduino-shield comms interface."); } // Clean up StringBuilder_Free(&request); processCommand = false; cursor = commandBuffer; freeBufferSize = ARDUINO_CMD_BUFFER_LENGTH; } } vTaskDelay( 100 / portTICK_RATE_MS ); } }