void udb_init(void) { // If we were reest: if (mp_argc >= 2 && strcmp(mp_argv[1], UDB_HW_RESET_ARG) == 0) { mp_rcon = 128; // enable just the external/MCLR reset bit } int16_t i; for (i=0; i<4; i++) { leds[i] = LED_OFF; } udb_heartbeat_counter = 0; udb_flags.B = 0; sil_radio_on = 1; sil_ui_init(mp_rcon); gpsSocket = UDBSocket_init((SILSIM_GPS_RUN_AS_SERVER) ? UDBSocketUDPServer : UDBSocketUDPClient, SILSIM_GPS_PORT, SILSIM_GPS_HOST, NULL, 0); telemetrySocket = UDBSocket_init((SILSIM_TELEMETRY_RUN_AS_SERVER) ? UDBSocketUDPServer : UDBSocketUDPClient, SILSIM_TELEMETRY_PORT, SILSIM_TELEMETRY_HOST, NULL, 0); if (strlen(SILSIM_SERIAL_RC_INPUT_DEVICE) > 0) { serialSocket = UDBSocket_init(UDBSocketSerial, 0, NULL, SILSIM_SERIAL_RC_INPUT_DEVICE, SILSIM_SERIAL_RC_INPUT_BAUD); } }
void sil_ui_init(uint16_t mp_rcon) { printf("MatrixPilot SIL%s\n\n", (mp_rcon == 128) ? " (HW Reset)" : ""); print_help(); printf("\nINIT: Calibrating...\n"); stdioSocket = UDBSocket_init(UDBSocketStandardInOut, 0, NULL, NULL, 0); }
void StartServer(void) { fprintf(stderr, "--- trying server on port %d\n", PortNum); udpSock = UDBSocket_init(UDBSocketUDPServer, PortNum, NULL, NULL, 0); if (udpSock) { LoggingFile.mLogFile << "Opened UDP server on port " << PortNum << endl; } else { LoggingFile.mLogFile << "Open UDP server on port " << PortNum << " failed." << endl; LoggingFile.mLogFile << UDBSocketLastErrorMessage() << endl; printf("%s\n", UDBSocketLastErrorMessage()); } }
void StartSerial(void) { fprintf(stderr, "--- trying comm port %s\n", CommPortString.c_str()); serialSock = UDBSocket_init(UDBSocketSerial, 0, NULL, (char*)CommPortString.c_str(), CommPortSpeed); if (serialSock) { LoggingFile.mLogFile << "Opened serial port " << CommPortString.c_str() << endl; } else { LoggingFile.mLogFile << "Open serial port " << CommPortString.c_str() << " failed." << endl; LoggingFile.mLogFile << UDBSocketLastErrorMessage() << endl; printf("%s\n", UDBSocketLastErrorMessage()); } }
int main(int argc, char** argv) { UDBSocketType socketType = (!SILSIM_TELEMETRY_RUN_AS_SERVER) ? UDBSocketUDPServer : UDBSocketUDPClient; uint32_t udpPort = SILSIM_TELEMETRY_PORT; char *udpHost = SILSIM_TELEMETRY_HOST; char *serialPort = NULL; uint32_t serialBaud = 0; uint8_t argPos = 0; int i; for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { if (argv[i][1] == 'h') { printHelp(); return 0; } else if (argv[i][1] == 's') { socketType = UDBSocketUDPServer; } else if (argv[i][1] == 'c') { socketType = UDBSocketUDPClient; } else if (argv[i][1] == 'l') { socketType = UDBSocketSerial; } } else { if (argPos == 0) { if (socketType == UDBSocketSerial) { serialPort = argv[i]; } else { udpPort = atoi(argv[i]); } } else if (argPos == 1) { if (socketType == UDBSocketUDPClient) { udpHost = argv[i]; } else { serialBaud = atoi(argv[i]); } } else { printHelp(); return 0; } argPos++; } } stdioSocket = UDBSocket_init(UDBSocketStandardInOut, 0, NULL, NULL, 0); transportSocket = UDBSocket_init(socketType, udpPort, udpHost, serialPort, serialBaud); if (!transportSocket) { printf("ERROR: UDBSocket_init failed: %s\n", UDBSocketLastErrorMessage()); exit(1); } while (1) { if (!readSockets()) { usleep(1000); } } }