void load(state_t *state){ state->data = receive_port(LPT_DATA); state->state = receive_port(LPT_STATE); state->control = receive_port(LPT_CONTROL); state->ir_left = norm_to_bool(state->control & IR_LEFT); state->ir_right = norm_to_bool(state->control & IR_RIGHT); state->cny_left = norm_to_bool(state->state & CNY_LEFT); state->cny_mid = norm_to_bool(state->state & CNY_MID); state->cny_right = norm_to_bool(state->state & CNY_RIGHT); state->echo = norm_to_bool(state->state & HC_SR04); }
/** \fn uint32_t send_port(HANDLE fpCom, uint32_t lenTx, char *Tx) \brief send data via comm port \param[in] fpCom handle to comm port \param[in] lenTx number of bytes to send \param[in] Tx array of bytes to send \return number of sent bytes send data via comm port. Use this function to facilitate serial communication on different platforms, e.g. Win32 and Posix. If g_UARTmode==1 (1-wire interface), read back LIN echo */ uint32_t send_port(HANDLE fpCom, uint32_t lenTx, char *Tx) { // for reading back LIN echo char Rx[1000]; uint32_t lenRx; ///////// // Win32 ///////// #ifdef WIN32 DWORD numChars; // send data & return number of sent bytes PurgeComm(fpCom, PURGE_RXABORT | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_TXCLEAR); WriteFile(fpCom, Tx, lenTx, &numChars, NULL); #endif // WIN32 ///////// // Posix ///////// #if defined(__APPLE__) || defined(__unix__) uint32_t numChars; // send data & return number of sent bytes numChars = write(fpCom, Tx, lenTx); #endif // __APPLE__ || __unix__ // for 1-wire interface, read back LIN echo and ignore if (g_UARTmode == 1) { lenRx = receive_port(fpCom, numChars, Rx); if (lenRx != numChars) { setConsoleColor(PRM_COLOR_RED); fprintf(stderr, "\n\nerror in 'send_port()': read 1-wire echo failed, exit!\n\n"); Exit(1, g_pauseOnExit); } //fprintf(stderr,"received echo %dB 0x%02x\n", (int) lenRx, Rx[0]); } // return number of sent bytes return((uint32_t) numChars); } // send_port