void pgResetFn_boardConfig(boardConfig_t *boardConfig) { if (boardInformationIsSet()) { strncpy(boardConfig->manufacturerId, getManufacturerId(), MAX_MANUFACTURER_ID_LENGTH); strncpy(boardConfig->boardName, getBoardName(), MAX_BOARD_NAME_LENGTH); boardConfig->boardInformationSet = true; } else { #if !defined(GENERIC_TARGET) strncpy(boardConfig->boardName, targetName, MAX_BOARD_NAME_LENGTH); #if defined(TARGET_MANUFACTURER_IDENTIFIER) strncpy(boardConfig->manufacturerId, TARGET_MANUFACTURER_IDENTIFIER, MAX_MANUFACTURER_ID_LENGTH); #endif boardConfig->boardInformationSet = true; #else boardConfig->boardInformationSet = false; #endif // GENERIC_TARGET } #if defined(USE_SIGNATURE) if (signatureIsSet()) { memcpy(boardConfig->signature, getSignature(), SIGNATURE_LENGTH); boardConfig->signatureSet = true; } else { boardConfig->signatureSet = false; } #endif }
void mainBoardCommonMainInit(RobotConfig* robotConfig) { // LOG the BoardName appendStringCRLF(getAlwaysOutputStreamLogger(), getBoardName()); // Increase the Log Level to DEBUG if the config bit are set Logger* logger = getLoggerInstance(); if (isConfigSet(robotConfig, CONFIG_DEBUG)) { logger->globalLogLevel = LOG_LEVEL_DEBUG; } appendString(getInfoOutputStreamLogger(), "GLOBAL LEVEL : "); appendLevelAsString(getInfoOutputStreamLogger(), logger->globalLogLevel); println(getInfoOutputStreamLogger()); }
void HighScore::checkHighScore(int s, int e, long gameNum, QString &name) { int pos; QString board; getBoardName(name, board); // make this board name the current one! // creates it if it does not exist selectTable(board); for (pos=0; pos <numScores; pos++) { if (s > currTable->entries[pos].score) { break; } } if (pos >= numScores) { return; } for (int move= numScores-1; move >pos; move--) { currTable->entries[move].score = currTable->entries[move-1].score; currTable->entries[move].name = currTable->entries[move-1].name; currTable->entries[move].board = currTable->entries[move-1].board; currTable->entries[move].elapsed = currTable->entries[move-1].elapsed; } currTable->entries[pos].score = s; currTable->entries[pos].board = gameNum; currTable->entries[pos].elapsed = e; lineEdit->setEnabled(true); lineEdit->setGeometry( 40, 75+(pos*30), 150, 30 ); lineEdit->setFocus(); lineEdit->setText(""); selectedLine = pos; nameChanged(""); // no board change when entering data combo->setEnabled(false); exec(board); combo->setEnabled(true); selectedLine = -1; lineEdit->setGeometry( 40, 75+(20*30), 150, 30); lineEdit->setEnabled(false); // sync the hiscore table to disk now saveTables(); }
void HighScore::copyTableToScreen(const QString &name) { char buff[256]; QString base; getBoardName(name, base); selectTable(base); for (int p=0; p<numScores;p++) { scoresWidgets[p]->setNum((int)currTable->entries[p].score); namesWidgets[p]->setText(currTable->entries[p].name); boardWidgets[p]->setNum((int)currTable->entries[p].board); int e = currTable->entries[p].elapsed; int s = e % 60; e = e-s; int m = (e % (60*60)) / 60; e = e - (e % (60*60)); int h = (e % (60*60*60)) / (60*60); sprintf(buff, "%2.2d:%2.2d:%2.2d", h, m , s); elapsedWidgets[p]->setText(buff); } repaint(false); }
int main(void) { setBoardName("TITAN ELECTRONICAL MAIN BOARD 32bits V-JJ_7"); i2cMasterInitialize(); //setRobotMustStop(false); // Open the serial Link for debug openSerialLink(&debugSerialStreamLink, &debugInputBuffer, &debugInputBufferArray, MAIN_BOARD_DEBUG_INPUT_BUFFER_LENGTH, &debugOutputBuffer, &debugOutputBufferArray, MAIN_BOARD_DEBUG_OUTPUT_BUFFER_LENGTH, &debugOutputStream, SERIAL_PORT_DEBUG, DEFAULT_SERIAL_SPEED); // Open the serial Link for the PC openSerialLink(&pcSerialStreamLink, &pcInputBuffer, &pcInputBufferArray, MAIN_BOARD_PC_INPUT_BUFFER_LENGTH, &pcOutputBuffer, &pcOutputBufferArray, MAIN_BOARD_PC_OUTPUT_BUFFER_LENGTH, &pcOutputStream, SERIAL_PORT_PC, DEFAULT_SERIAL_SPEED); // LCD (LCD03 via Serial interface) initLCDOutputStream(&lcdOutputStream); initTimerList(&timerListArray, MAIN_BOARD_TIMER_LENGTH); // Init the logs initLog(DEBUG); addLogHandler(&debugSerialLogHandler, "UART", &debugOutputStream, DEBUG); addLogHandler(&lcdLogHandler, "LCD", &lcdOutputStream, ERROR); appendString(getAlwaysOutputStreamLogger(), getBoardName()); println(getAlwaysOutputStreamLogger()); initDevicesDescriptor(); initDriversDescriptor(); i2cMasterInitialize(); // Initialize EEPROM and RTC initClockPCF8563(&globalClock); init24C512Eeprom(&eeprom_); initRobotConfigPic32(&robotConfig); initStartMatchDetector32(&startMatchDetector); // Initializes the opponent robot // initOpponentRobot(); /* // Creates a composite to notify both PC and Debug initCompositeOutputStream(&compositePcAndDebugOutputStream); addOutputStream(&compositePcAndDebugOutputStream, &debugOutputStream); addOutputStream(&compositePcAndDebugOutputStream, &pcOutputStream); // Creates a composite to redirect to driverRequest and Debug initCompositeOutputStream(&compositeDriverAndDebugOutputStream); addOutputStream(&compositeDriverAndDebugOutputStream, &debugOutputStream); addOutputStream(&compositeDriverAndDebugOutputStream, getDriverRequestOutputStream()); */ appendString(&debugOutputStream, "DEBUG\n"); // Start interruptions //startTimerList(); //////RALENTI FORTEMENT LE PIC!!! PLANTE I2C !!!!!!!! // Configure data dispatcher //addLocalDriverDataDispatcher(); // Stream for motorBoard /* addI2CDriverDataDispatcher(&motorI2cDispatcher, "MOTOR_BOARD_DISPATCHER", &motorBoardInputBuffer, &motorBoardInputBufferArray, MAIN_BOARD_LINK_TO_MOTOR_BOARD_BUFFER_LENGTH, &motorBoardOutputStream, &motorBoardInputStream, MOTOR_BOARD_I2C_ADDRESS); */ /* // Stream for Mechanical Board 2 addI2CDriverDataDispatcher(&mechanical2I2cDispatcher, "MECHANICAL_BOARD_2_DISPATCHER", &mechanical2BoardInputBuffer, &mechanical2BoardInputBufferArray, MAIN_BOARD_LINK_TO_MECA_BOARD_2_BUFFER_LENGTH, &mechanical2BoardOutputStream, &mechanical2BoardInputStream, MECHANICAL_BOARD_2_I2C_ADDRESS); */ /* // Stream for Air Conditioning addI2CDriverDataDispatcher(&airConditioningI2cDispatcher, "AIR_CONDITIONING_DISPATCHER", &airConditioningBoardInputBuffer, &airConditioningBoardInputBufferArray, MAIN_BOARD_LINK_TO_AIR_CONDITIONING_BOARD_BUFFER_LENGTH, &airConditioningBoardOutputStream, &airConditioningBoardInputStream, AIR_CONDITIONING_BOARD_I2C_ADDRESS); */ // I2C Debug initI2CDebugBuffers(&i2cMasterDebugInputBuffer, &i2cMasterDebugInputBufferArray, MAIN_BOARD_I2C_DEBUG_MASTER_IN_BUFFER_LENGTH, &i2cMasterDebugOutputBuffer, &i2cMasterDebugOutputBufferArray, MAIN_BOARD_I2C_DEBUG_MASTER_OUT_BUFFER_LENGTH); appendStringConfig(&lcdOutputStream); //pingDriverDataDispatcherList(getDebugOutputStreamLogger()); // Inform PC waiting showWaitingStart(&debugOutputStream); // wait other board initialization delaymSec(1500); // 2012 VALUE unsigned int configValue = getConfigValue(); unsigned int homologationIndex = configValue & CONFIG_STRATEGY_MASK; unsigned int color = configValue & CONFIG_COLOR_BLUE_MASK; appendString(getAlwaysOutputStreamLogger(), "Homologation:"); appendCRLF(getAlwaysOutputStreamLogger()); appendDec(getAlwaysOutputStreamLogger(), homologationIndex); appendString(getAlwaysOutputStreamLogger(), "Config:"); appendHex4(getAlwaysOutputStreamLogger(), configValue); appendCRLF(getAlwaysOutputStreamLogger()); useBalise = configValue & CONFIG_USE_BALISE_MASK; useInfrared = configValue & CONFIG_USE_SONAR_MASK; if (color != 0) { appendString(getAlwaysOutputStreamLogger(), "COLOR:VIOLET\n"); } else { appendString(getAlwaysOutputStreamLogger(), "COLOR:RED\n"); } // TODO 2012 SV motionDriverMaintainPosition(); // wait for start // setInitialPosition(color); // notify game strategy // sendStrategyConfiguration(configValue); loopUntilStart(&waitForInstruction); // Enable the sonar Status only after start //setSonarStatus(configValue & CONFIG_USE_SONAR_MASK); // mark that match begins markStartMatch(); // write begin of match showStarted(&pcOutputStream); if (homologationIndex == 0) { // MATCH while (1) { waitForInstruction(); //CLOCK Read if (isEnd()) { break; } } } else { setReadyForNextMotion(true); while (1) { portableStartI2C(i2cBus); WaitI2C(i2cBus); portableMasterWriteI2C(FREE_ADDRESS_2);//0x54 WaitI2C(i2cBus); portableMasterWriteI2C('H'); WaitI2C(i2cBus); portableMasterWriteI2C('E'); WaitI2C(i2cBus); portableMasterWriteI2C('L'); WaitI2C(i2cBus); portableMasterWriteI2C('L'); WaitI2C(i2cBus); portableMasterWriteI2C('O'); portableStopI2C(i2cBus); WaitI2C(i2cBus); int data1,data2,data3; while(1){ waitForInstruction(); //globalClock.readClock(&globalClock); //printClock(&debugOutputStream,&globalClock); //appendCR(&debugOutputStream); int data = 0; portableMasterWaitSendI2C(i2cBus); portableStartI2C(i2cBus); IdleI2C1(); portableMasterWriteI2C(FREE_ADDRESS_2 + 1);//0x54 WaitI2C(i2cBus); data = portableMasterReadI2C(i2cBus); portableAckI2C(i2cBus); IdleI2C1(); data1 = portableMasterReadI2C(i2cBus); portableAckI2C(i2cBus); IdleI2C1(); data2= portableMasterReadI2C(i2cBus); portableAckI2C(i2cBus); IdleI2C1(); data3 = portableMasterReadI2C(i2cBus); portableNackI2C(i2cBus); IdleI2C1(); append(&lcdOutputStream,data); append(&lcdOutputStream,data1); append(&lcdOutputStream,data2); append(&lcdOutputStream,data3); portableStopI2C(i2cBus); IdleI2C1(); delaymSec(500); } homologation(homologationIndex, color); // We stop if we are in homologation mode if (isRobotMustStop()) { motionDriverStop(); break; } // ultimate tentative to restart the robot if it is blocked forceRobotNextStepIfNecessary(); } } showEnd(&lcdOutputStream); while (1) { // Avoid reboot even at end } }
void runMotorBoardPC(bool singleMode) { singleModeActivated = singleMode; setBoardName(MOTOR_BOARD_PC_NAME); moveConsole(HALF_SCREEN_WIDTH, 0, HALF_SCREEN_WIDTH, CONSOLE_HEIGHT); // We use http://patorjk.com/software/taag/#p=testall&v=2&f=Acrobatic&t=MOTOR%20BOARD%20PC // with Font : Jerusalem printf(" __ __ ___ _____ ___ ____ ____ ___ _ ____ ____ ____ ____\r\n"); printf("| \\/ |/ _ |_ _/ _ \\| _ \\ | __ ) / _ \\ / \\ | _ \\| _ \\ | _ \\ / ___|\r\n"); printf("| |\\/| | | | || || | | | |_) | | _ \\| | | |/ _ \\ | |_) | | | | | |_) | | \r\n"); printf("| | | | |_| || || |_| | _ < | |_) | |_| / ___ \\| _ <| |_| | | __/| |___ \r\n"); printf("|_| |_|\\___/ |_| \\___/|_| \\_\\ |____/ \\___/_/ \\_|_| \\_|____/ |_| \\____|\r\n"); printf("\r\n"); initLogs(DEBUG, (LogHandler(*)[]) &logHandlerListArray, MOTOR_BOARD_PC_LOG_HANDLER_LIST_LENGTH, LOG_HANDLER_CATEGORY_ALL_MASK); initConsoleInputStream(&consoleInputStream); initConsoleOutputStream(&consoleOutputStream); addConsoleLogHandler(DEBUG, LOG_HANDLER_CATEGORY_ALL_MASK); appendStringCRLF(getDebugOutputStreamLogger(), getBoardName()); initTimerList((Timer(*)[]) &timerListArray, MOTOR_BOARD_PC_TIMER_LENGTH); initBuffer(&consoleInputBuffer, (char(*)[]) &consoleInputBufferArray, MOTOR_BOARD_PC_CONSOLE_INPUT_BUFFER_LENGTH, "inputConsoleBuffer", "IN"); initBuffer(&consoleOutputBuffer, (char(*)[]) &consoleOutputBufferArray, MOTOR_BOARD_PC_CONSOLE_OUTPUT_BUFFER_LENGTH, "outputConsoleBuffer", "IN"); // Dispatchers initDriverDataDispatcherList((DriverDataDispatcher(*)[]) &driverDataDispatcherListArray, MOTOR_BOARD_PC_DATA_DISPATCHER_LIST_LENGTH); addLocalDriverDataDispatcher(); if (!singleModeActivated) { initI2cBus(&motorI2cBus, I2C_BUS_TYPE_SLAVE, I2C_BUS_PORT_1); initI2cBusConnection(&motorI2cBusConnection, &motorI2cBus, MOTOR_BOARD_PC_I2C_ADDRESS); openSlaveI2cStreamLink(&i2cSlaveStreamLink, &i2cSlaveInputBuffer, (char(*)[]) &i2cSlaveInputBufferArray, MOTOR_BOARD_PC_IN_BUFFER_LENGTH, &i2cSlaveOutputBuffer, (char(*)[]) &i2cSlaveOutputBufferArray, MOTOR_BOARD_PC_OUT_BUFFER_LENGTH, &motorI2cBusConnection ); // I2C Debug initI2CDebugBuffers(&i2cSlaveDebugInputBuffer, (char(*)[]) &i2cSlaveDebugInputBufferArray, MOTOR_BOARD_PC_I2C_DEBUG_SLAVE_IN_BUFFER_LENGTH, &i2cSlaveDebugOutputBuffer, (char(*)[]) &i2cSlaveDebugOutputBufferArray, MOTOR_BOARD_PC_I2C_DEBUG_SLAVE_OUT_BUFFER_LENGTH); } // Eeprom initEepromPc(&eeprom, "TODO"); // Battery initBattery(&battery, getBatteryVoltage); // Clock initSoftClock(&clock); // Devices initDeviceList((Device(*)[]) &deviceListArray, MOTOR_BOARD_PC_DEVICE_LIST_LENGTH); addLocalDevice(getTestDeviceInterface(), getTestDeviceDescriptor()); addLocalDevice(getI2cSlaveDebugDeviceInterface(), getI2cSlaveDebugDeviceDescriptor(&motorI2cBusConnection)); addLocalDevice(getSystemDeviceInterface(), getSystemDeviceDescriptor()); addLocalDevice(getMotorDeviceInterface(), getMotorDeviceDescriptor()); addLocalDevice(getEepromDeviceInterface(), getEepromDeviceDescriptor(&eeprom)); addLocalDevice(getBatteryDeviceInterface(), getBatteryDeviceDescriptor(&battery)); addLocalDevice(getClockDeviceInterface(), getClockDeviceDescriptor(&clock)); addLocalDevice(getRobotKinematicsDeviceInterface(), getRobotKinematicsDeviceDescriptor(&eeprom)); addLocalDevice(getPIDDeviceInterface(), getPIDDeviceDescriptor(&eeprom, true)); addLocalDevice(getMotorDeviceInterface(), getMotorDeviceDescriptor()); addLocalDevice(getCodersDeviceInterface(), getCodersDeviceDescriptor()); addLocalDevice(getTrajectoryDeviceInterface(), getTrajectoryDeviceDescriptor()); addLocalDevice(getMotionDeviceInterface(), getMotionDeviceDescriptor(&eeprom, true)); addLocalDevice(getMotionSimulationDeviceInterface(), getMotionSimulationDeviceDescriptor()); initDevices(); startTimerList(); setDebugI2cEnabled(false); while (1) { motorBoardWaitForInstruction(); } }
void runMainBoardPC(bool connectToRobotManagerMode) { connectToRobotManager = connectToRobotManagerMode; setBoardName(MAIN_BOARD_PC_NAME); moveConsole(0, 0, HALF_SCREEN_WIDTH, CONSOLE_HEIGHT); // We use http://patorjk.com/software/taag/#p=testall&v=2&f=Acrobatic&t=MOTOR%20BOARD%20PC // with Font : Jerusalem printf(" __ __ _ ___ _ _ ____ ___ _ ____ ____ ____ ____ \r\n"); printf("| \\/ | / \\ |_ _| \\ | | | __ ) / _ \\ / \\ | _ \\| _ \\ | _ \\ / ___|\r\n"); printf("| |\\/| | / _ \\ | || \\| | | _ \\| | | |/ _ \\ | |_) | | | | | |_) | | \r\n"); printf("| | | |/ ___ \\ | || |\\ | | |_) | |_| / ___ \\| _ <| |_| | | __/| |___ \r\n"); printf("|_| |_/_/ \\_|___|_| \\_| |____/ \\___/_/ \\_|_| \\_|____/ |_| \\____|\r\n"); printf("\r\n"); initLogs(DEBUG, (LogHandler(*)[]) &logHandlerListArray, MAIN_BOARD_PC_LOG_HANDLER_LIST_LENGTH, LOG_HANDLER_CATEGORY_ALL_MASK); initConsoleInputStream(&consoleInputStream); initConsoleOutputStream(&consoleOutputStream); addConsoleLogHandler(DEBUG, LOG_HANDLER_CATEGORY_ALL_MASK); appendStringCRLF(getDebugOutputStreamLogger(), getBoardName()); initTimerList((Timer(*)[]) &timerListArray, MAIN_BOARD_PC_TIMER_LENGTH); initBuffer(&consoleInputBuffer, (char(*)[]) &consoleInputBufferArray, MAIN_BOARD_PC_CONSOLE_INPUT_BUFFER_LENGTH, "inputConsoleBuffer", "IN"); initBuffer(&consoleOutputBuffer, (char(*)[]) &consoleOutputBufferArray, MAIN_BOARD_PC_CONSOLE_OUTPUT_BUFFER_LENGTH, "outputConsoleBuffer", "IN"); // Dispatchers initDriverDataDispatcherList((DriverDataDispatcher(*)[]) &driverDataDispatcherListArray, MAIN_BOARD_PC_DATA_DISPATCHER_LIST_LENGTH); addLocalDriverDataDispatcher(); initI2cBus(&motorBoardI2cBus, I2C_BUS_TYPE_MASTER, I2C_BUS_PORT_1); initI2cBusConnection(&motorBoardI2cBusConnection, &motorBoardI2cBus, MOTOR_BOARD_PC_I2C_ADDRESS); addI2CDriverDataDispatcher("MOTOR_BOARD_DISPATCHER", &motorBoardInputBuffer, (char(*)[]) &motorBoardInputBufferArray, MAIN_BOARD_PC_DATA_MOTOR_BOARD_DISPATCHER_BUFFER_LENGTH, &motorBoardOutputStream, &motorBoardInputStream, &motorBoardI2cBusConnection ); if (connectToRobotManager) { // Open the serial Link between RobotManager (C# Project) and the MainBoardPc openSerialLink(&robotManagerSerialStreamLink, &robotManagerInputBuffer, (char(*)[]) &robotManagerInputBufferArray, ROBOT_MANAGER_INPUT_BUFFER_LENGTH, &robotManagerOutputBuffer, (char(*)[]) &robotManagerOutputBufferArray, ROBOT_MANAGER_OUTPUT_BUFFER_LENGTH, &robotManagerOutputStream, SERIAL_PORT_ROBOT_MANAGER, 0); } // CONFIG initRobotConfigPc(&robotConfig); // EEPROM initEepromPc(&eeprom, "TODO"); initEepromFile(&eeprom); // Clock initPcClock(&clock); // Temperature initTemperaturePc(&temperature); // I2C Debug initI2CDebugBuffers(&i2cMasterDebugInputBuffer, (char(*)[]) &i2cMasterDebugInputBufferArray, MAIN_BOARD_PC_I2C_DEBUG_MASTER_IN_BUFFER_LENGTH, &i2cMasterDebugOutputBuffer, (char(*)[]) &i2cMasterDebugOutputBufferArray, MAIN_BOARD_PC_I2C_DEBUG_MASTER_OUT_BUFFER_LENGTH); // Init the drivers initDrivers(&driverRequestBuffer, (char(*)[]) &driverRequestBufferArray, MAIN_BOARD_PC_REQUEST_DRIVER_BUFFER_LENGTH, &driverResponseBuffer, (char(*)[]) &driverResponseBufferArray, MAIN_BOARD_PC_RESPONSE_DRIVER_BUFFER_LENGTH); // Get test driver for debug purpose addDriver(testDriverGetDescriptor(), TRANSMIT_LOCAL); // Devices initDeviceList((Device(*)[]) &deviceListArray, MAIN_BOARD_PC_DEVICE_LIST_LENGTH); // addLocalDevice(getTestDeviceInterface(), getTestDeviceDescriptor()); testDevice = addI2cRemoteDevice(getTestDeviceInterface(), MOTOR_BOARD_PC_I2C_ADDRESS); testDevice->deviceHandleNotification = mainBoardDeviceHandleNotification; // LOCAL BOARD addLocalDevice(getADCDeviceInterface(), getADCDeviceDescriptor()); addLocalDevice(getStrategyDeviceInterface(), getStrategyDeviceDescriptor()); addLocalDevice(getSystemDeviceInterface(), getSystemDeviceDescriptor()); addLocalDevice(getRobotConfigDeviceInterface(), getRobotConfigDeviceDescriptor(&robotConfig)); addLocalDevice(getI2cMasterDebugDeviceInterface(), getI2cMasterDebugDeviceDescriptor()); addLocalDevice(getDataDispatcherDeviceInterface(), getDataDispatcherDeviceDescriptor()); addLocalDevice(getServoDeviceInterface(), getServoDeviceDescriptor()); addLocalDevice(getTimerDeviceInterface(), getTimerDeviceDescriptor()); addLocalDevice(getClockDeviceInterface(), getClockDeviceDescriptor(&clock)); // addLocalDevice(getFileDeviceInterface(), getFileDeviceDescriptor()); addLocalDevice(getEepromDeviceInterface(), getEepromDeviceDescriptor(&eeprom)); addLocalDevice(getLogDeviceInterface(), getLogDeviceDescriptor()); addLocalDevice(getLCDDeviceInterface(), getLCDDeviceDescriptor()); addLocalDevice(getTemperatureSensorDeviceInterface(), getTemperatureSensorDeviceDescriptor(&temperature)); addLocalDevice(getNavigationDeviceInterface(), getNavigationDeviceDescriptor()); initStartMatch(&startMatch, isMatchStartedPc, mainBoardPcWaitForInstruction, &eeprom); addLocalDevice(getStartMatchDeviceInterface(), getStartMatchDeviceDescriptor(&startMatch)); // MOTOR BOARD addI2cRemoteDevice(getBatteryDeviceInterface(), MOTOR_BOARD_PC_I2C_ADDRESS); // addI2cRemoteDevice(getEepromDeviceInterface(), MOTOR_BOARD_PC_I2C_ADDRESS); addI2cRemoteDevice(getPIDDeviceInterface(), MOTOR_BOARD_PC_I2C_ADDRESS); addI2cRemoteDevice(getMotorDeviceInterface(), MOTOR_BOARD_PC_I2C_ADDRESS); addI2cRemoteDevice(getCodersDeviceInterface(), MOTOR_BOARD_PC_I2C_ADDRESS); addI2cRemoteDevice(getTrajectoryDeviceInterface(), MOTOR_BOARD_PC_I2C_ADDRESS); addI2cRemoteDevice(getMotionDeviceInterface(), MOTOR_BOARD_PC_I2C_ADDRESS); addI2cRemoteDevice(getRobotKinematicsDeviceInterface(), MOTOR_BOARD_PC_I2C_ADDRESS); addI2cRemoteDevice(getMotionSimulationDeviceInterface(), MOTOR_BOARD_PC_I2C_ADDRESS); initDevices(); delaymSec(100); setDebugI2cEnabled(false); // Ping if (!pingDriverDataDispatcherList()) { printf("PING PROBLEM !"); } // Set Clock for Motor Board ! // Read Clock ClockData* clockData = clock.readClock(&clock); // TODO : Change Dispatcher Index ... writeDateRemoteClockData(clockData, 0x01); writeHourRemoteClockData(clockData, 0x01); // testDriverIntensive(100); startTimerList(); while (1) { mainBoardPcWaitForInstruction(&startMatch); } // TODO : ShowEnd }
void deviceSystemHandleRawData(char header, InputStream* inputStream, OutputStream* outputStream) { if (header == COMMAND_PING) { // data ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_PING); // Read and write in output the pingIndex (to control that it's the right which does the response) unsigned char pingIndex = readHex2(inputStream); appendHex2(outputStream, pingIndex); } // Last Error else if (header == COMMAND_GET_LAST_ERROR) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_GET_LAST_ERROR); unsigned int lastError = getLastError(); appendHex4(outputStream, lastError); } else if (header == COMMAND_CLEAR_LAST_ERROR) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_CLEAR_LAST_ERROR); clearLastError(); } // Device list else if (header == COMMAND_DEVICE_LIST) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_DEVICE_LIST); printDeviceList(getInfoOutputStreamLogger()); // Usage } else if (header == COMMAND_USAGE) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_USAGE); printDeviceListUsage(getInfoOutputStreamLogger(), false); } else if (header == COMMAND_USAGE_PROBLEM) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_USAGE_PROBLEM); printDeviceListUsage(getInfoOutputStreamLogger(), true); } else if (header == COMMAND_USAGE_SPECIFIC_DEVICE) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_USAGE_SPECIFIC_DEVICE); char deviceHeader = readBinaryChar(inputStream); int size = getDeviceCount(); int i; for (i = 0; i < size; i++) { Device* device = getDevice(i); if (deviceHeader == device->deviceInterface->deviceHeader) { println(getInfoOutputStreamLogger()); printDeviceUsage(getInfoOutputStreamLogger(), device, false); return; } } appendString(getErrorOutputStreamLogger(), "Device Not Found ! "); } else if (header == COMMAND_CLS) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_CLS); #ifdef PC_COMPILER system("cls"); #else appendString(outputStream, "Unsupported Operation"); #endif // PC_COMPILER } else if (header == COMMAND_RESET) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_RESET); #ifdef PC_COMPILER appendString(outputStream, "Unsupported Operation"); #else // goto 0; #endif // PC_COMPILER } // Notifications else if (header == COMMAND_NOTIFICATION) { ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_NOTIFICATION); printDeviceListNotification(getInfoOutputStreamLogger(), false); } else if (header == COMMAND_WAIT) { appendAck(outputStream); int mSec = readHex4(inputStream); delaymSec(mSec); append(outputStream, SYSTEM_DEVICE_HEADER); append(outputStream, COMMAND_WAIT); } else if (header == COMMAND_BOARD_NAME) { appendString(getInfoOutputStreamLogger(), getBoardName()); println(getInfoOutputStreamLogger()); ackCommand(outputStream, SYSTEM_DEVICE_HEADER, COMMAND_BOARD_NAME); } }
int main(void) { setBoardName("MAIN BOARD"); setRobotMustStop(false); // LOG Global Configuration initLogs(DEBUG, &logHandlerListArray, MAIN_BOARD_LOG_HANDLER_LIST_LENGTH, LOG_HANDLER_CATEGORY_ALL_MASK); // LCD (LCD via Parallel interface) initLCDOutputStream(&lcdOutputStream); addLogHandler("LCD", &lcdOutputStream, LOG_LEVEL_ERROR, LOG_HANDLER_CATEGORY_ALL_MASK); // CONFIG initRobotConfigPic32(&robotConfig); // Open the serial Link for debug and LOG ! openSerialLink(&debugSerialStreamLink, &debugInputBuffer, &debugInputBufferArray, MAIN_BOARD_DEBUG_INPUT_BUFFER_LENGTH, &debugOutputBuffer, &debugOutputBufferArray, MAIN_BOARD_DEBUG_OUTPUT_BUFFER_LENGTH, &debugOutputStream, SERIAL_PORT_DEBUG, DEFAULT_SERIAL_SPEED); // Serial Debug LOG addLogHandler("UART", &debugOutputStream, DEBUG, LOG_HANDLER_CATEGORY_ALL_MASK); // LOG the BoardName appendString(getAlwaysOutputStreamLogger(), getBoardName()); println(getAlwaysOutputStreamLogger()); // SERIAL // Open the serial Link for the Motor Board openSerialLink(&motorSerialStreamLink, &motorInputBuffer, &motorInputBufferArray, MAIN_BOARD_MOTOR_INPUT_BUFFER_LENGTH, &motorOutputBuffer, &motorOutputBufferArray, MAIN_BOARD_MOTOR_OUTPUT_BUFFER_LENGTH, &motorOutputStream, SERIAL_PORT_MOTOR, DEFAULT_SERIAL_SPEED); // Open the serial Link for the Mechanical Board openSerialLink(&mechanicalBoard2SerialStreamLink, &mechanicalBoard2InputBuffer, &mechanicalBoard2InputBufferArray, MAIN_BOARD_MECA2_INPUT_BUFFER_LENGTH, &mechanicalBoard2OutputBuffer, &mechanicalBoard2OutputBufferArray, MAIN_BOARD_MECA2_OUTPUT_BUFFER_LENGTH, &mechanicalBoard2OutputStream, SERIAL_PORT_MECA2, DEFAULT_SERIAL_SPEED); // Open the serial Link for the PC openSerialLink(&pcSerialStreamLink, &pcInputBuffer, &pcInputBufferArray, MAIN_BOARD_PC_INPUT_BUFFER_LENGTH, &pcOutputBuffer, &pcOutputBufferArray, MAIN_BOARD_PC_OUTPUT_BUFFER_LENGTH, &pcOutputStream, SERIAL_PORT_PC, DEFAULT_SERIAL_SPEED); // MAIN I2C initI2cBus(&i2cBus, I2C_BUS_TYPE_MASTER, I2C_BUS_PORT_1); i2cMasterInitialize(&i2cBus); initI2cBusConnection(&motorI2cBusConnection, &i2cBus, MOTOR_BOARD_I2C_ADDRESS); initI2cBusConnection(&mechanicalBoard2I2cBusConnection, &i2cBus, MECHANICAL_BOARD_2_I2C_ADDRESS); // I2C Debug initI2CDebugBuffers(&i2cMasterDebugInputBuffer, &i2cMasterDebugInputBufferArray, MAIN_BOARD_I2C_DEBUG_MASTER_IN_BUFFER_LENGTH, &i2cMasterDebugOutputBuffer, &i2cMasterDebugOutputBufferArray, MAIN_BOARD_I2C_DEBUG_MASTER_OUT_BUFFER_LENGTH); setDebugI2cEnabled(false); // -> Eeproms initI2cBusConnection(&eepromI2cBusConnection, &i2cBus, ST24C512_ADDRESS_0); init24C512Eeprom(&eeprom, &eepromI2cBusConnection); // -> Clock initI2cBusConnection(&clockI2cBusConnection, &i2cBus, PCF8563_WRITE_ADDRESS); initClockPCF8563(&clock, &clockI2cBusConnection); // -> Temperature initI2cBusConnection(&temperatureI2cBusConnection, &i2cBus, LM75A_ADDRESS); initTemperatureLM75A(&temperature, &temperatureI2cBusConnection); // TIMERS initTimerList(&timerListArray, MAIN_BOARD_TIMER_LENGTH); // DEVICES, DRIVERS, DISPATCHERS initMainBoardDevicesDescriptor(); initMainBoardDriversDescriptor(); initMainBoardDriverDataDispatcherList(); // Start interruptions startTimerList(); loopUntilStart(&startMatch); counter = 1; clearBuffer(&mechanicalBoard2InputBuffer); // enableNotificationRobotInfraredDetector(DETECTOR_GROUP_TYPE_FORWARD); while (1) { if (!mainBoardWaitForInstruction(&startMatch)) { break; } } showEnd(getAlwaysOutputStreamLogger()); while (1) { // Avoid reboot even at end } }
int main(void) { setBoardName("STRATEGY_BOARD"); initStrategyBoardIO(); openSerialLink( &debugSerialStreamLink, &debugInputBuffer, &debugInputBufferArray, STRATEGY_BOARD_DEBUG_INPUT_BUFFER_LENGTH, &debugOutputBuffer, &debugOutputBufferArray, STRATEGY_BOARD_DEBUG_OUTPUT_BUFFER_LENGTH, &debugOutputStream, SERIAL_PORT_DEBUG, 0); initTimerList(&timerListArray, STRATEGY_BOARD_TIMER_LENGTH); // Init the logs initLog(DEBUG); addLogHandler(&serialLogHandler, "UART", &debugOutputStream, DEBUG); appendString(getInfoOutputStreamLogger(), getBoardName()); println(getInfoOutputStreamLogger()); openSlaveI2cStreamLink(&i2cSerialStreamLink, &i2cSlaveInputBuffer, &i2cSlaveInputBufferArray, STRATEGY_BOARD_I2C_INPUT_BUFFER_LENGTH, &i2cSlaveOutputBuffer, &i2cSlaveOutputBufferArray, STRATEGY_BOARD_I2C_OUTPUT_BUFFER_LENGTH, STRATEGY_BOARD_I2C_ADDRESS ); // init the devices initDevicesDescriptor(); initDriversDescriptor(); // initStrategy2012(0); //setColor(COLOR_VIOLET); // printGameboard(getInfoOutputStreamLogger()); // printStrategyAllDatas(getInfoOutputStreamLogger()); initStrategyHandler(); //addNavigationLocations(); //printDeviceListUsage(getInfoOutputStreamLogger()); while (nextStep()); while (1); // Init the timers management startTimerList(); while (1) { // I2C Stream handleStreamInstruction(&i2cSlaveInputBuffer, &i2cSlaveOutputBuffer, NULL, &filterRemoveCRLF, NULL); // UART Stream handleStreamInstruction(&debugInputBuffer, &debugOutputBuffer, &debugOutputStream, &filterRemoveCRLF, NULL); } return (0); }