/* * We received a message, check if a generic action can be done or else forward * it to the right implementation */ void OnMsgVUE32(NETV_MESSAGE *msg) { if ( msg->msg_remote && msg->msg_type == VUE32_TYPE_GETVALUE ) { // If it's a request, let's see if we can answer it switch( msg->msg_cmd ) { case E_ID_VERSION: msg->msg_dest = msg->msg_source; msg->msg_remote = 0; msg->msg_data_length = 2; msg->msg_source = GetMyAddr(); msg->msg_data[0] = (unsigned char)(GetFirmVersion() >> 8); msg->msg_data[1] = (unsigned char)(GetFirmVersion() & 0x00FF); netv_send_message(msg); return; break; case E_ID_ADDRESS: msg->msg_dest = msg->msg_source; msg->msg_remote = 0; msg->msg_data_length = 1; msg->msg_source = GetMyAddr(); msg->msg_data[0] = GetMyAddr(); netv_send_message(msg); return; break; default: break; } } //Start Emetting (Long polling) ON_MSG_TYPE( VUE32_TYPE_STARTEMETTING) ActionStartEmettings(msg); END_OF_MSG_TYPE ON_MSG_TYPE( VUE32_TYPE_STOPEMETTING) DesactivateLongPolling(msg->msg_cmd); END_OF_MSG_TYPE #ifndef __32MX575F512H__ // Call the ID specific message parser gOnMsgFunc[GetBoardID()](msg); //Call Emergency Instruction Here ON_MSG_TYPE( NETV_TYPE_EMERGENCY ) gOnEmergencyMsgVUE32[GetBoardID()](); END_OF_MSG_TYPE #else // Call the BMS message parser OnMsgBMS(msg); #endif }
int main(void) { // Get the actual board ID VUE32_ID id = GetBoardID(); // Initialize the board (communication, timers, etc). InitBoard(); // Specific VUE32 initialization InitVUE32(id); //Most of the functions in the while(1) loop are timed by Timer1 while (1) { EVERY_X_MS(125) LED1 ^= 1; //Toggle LED 4Hz END_OF_EVERY // Process network stack NETV_MESSAGE oMsgRecep; if(netv_transceiver((unsigned char)id, &oMsgRecep)) OnMsgVUE32(&oMsgRecep); // Process state machine CallVUE32Impl(id); } return 0; }
BOOL CReader::Open(LPCTSTR lpDeviceName) { if (m_hDevice != INVALID_HANDLE_VALUE) return TRUE; m_hDevice = CreateFile(lpDeviceName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if (m_hDevice == INVALID_HANDLE_VALUE) return FALSE; DWORD nBytesReturned; BYTE outBuf[SECTOR_SIZE]; PSTORAGE_ADAPTER_DESCRIPTOR pAdpDesc = (PSTORAGE_ADAPTER_DESCRIPTOR)outBuf; STORAGE_PROPERTY_QUERY query; ZeroMemory(&m_ReaderID, sizeof(m_ReaderID)); if (!GetBoardID((LPBYTE)&m_ReaderID, &nBytesReturned)) return Close(); if (GetModel().Find(READER_SIGNATURE) != 0) return Close(); m_nState = HIBYTE(m_ReaderID.ModeUltraDMA) ? ReaderFree : ReaderBad; query.PropertyId = StorageAdapterProperty; query.QueryType = PropertyStandardQuery; if (!DeviceIoControl(m_hDevice, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(STORAGE_PROPERTY_QUERY), &outBuf, SECTOR_SIZE, &nBytesReturned, NULL)) { return Close(); } m_nMaxSectorCount = (WORD)(pAdpDesc->MaximumTransferLength / SECTOR_SIZE - 1); return TRUE; }
void ActionStartEmettings(NETV_MESSAGE *msg) { //Is it really a message of type VUE32_TYPE_STARTEMETTING if(msg->msg_type != VUE32_TYPE_STARTEMETTING) return; HDW_MAPPING *gVUE32_Ress = gHardwareMap[GetBoardID()]; if(gVUE32_Ress == 0) return; unsigned int unNbResourceId = gHardwareSize[GetBoardID()]; //Get parameters for long polling LP_PARAMS newLongPollingEvent; //Verify if this VUE32 has this ressource id unsigned int i; BOOL bResourceFound= 0; for(i = 0;i<unNbResourceId; i++) { if(gVUE32_Ress[i].ucResourceId == msg->msg_cmd) bResourceFound = 1; } //If this resource isn't available on this VUE32 if(!bResourceFound) return; //Load the delay between each transmetting event newLongPollingEvent.unDelay = 0; memcpy(&newLongPollingEvent.unDelay, msg->msg_data, 2); //Safety feature MINIMUM TIME FOR LONG POLLING if(newLongPollingEvent.unDelay <= LONG_POLLING_MINIMUM_DELAY) return; newLongPollingEvent.ucDestinataire = msg->msg_data[2]; newLongPollingEvent.ucResourceId = msg->msg_cmd; ActiveLongPolling(&newLongPollingEvent); }
/* * Initialize the board * Timers, Communication, etc * Note : Should only be called once at the begginning of the main */ void InitBoard(void) { // Initialize clock SYSTEMConfigPerformance(GetSystemClock()); SYSTEMConfig(GetSystemClock(), SYS_CFG_PCACHE); SYSTEMConfig(GetSystemClock(), SYS_CFG_PB_BUS); SYSTEMConfigPB(GetSystemClock()); INTEnableSystemMultiVectoredInt(); //Disable JTAG port DDPCONbits.JTAGEN = 0; // Initialize LEDs LED1_TRIS = 0; LED2_TRIS = 0; // Initialize Timers InitTimers(); // Initialize CAN bus CRX1_TRIS = 1; CTX1_TRIS = 0; netv_init_can_driver(GetBoardID(),CAN1); // Initialize digital IOs as inputs DIO_TRIS |= DIO_MASK; // Initialize Relays (low) RELAY1_TRIS = 0; RELAY2_TRIS = 0; RELAY1 = 0; RELAY2 = 0; // Initialize SPI pins as inputs SPICLK_TRIS = 1; SPISDO_TRIS = 1; SPI_CS_TRIS = 1; SPISDI_TRIS = 1; //TODO: Init unused pins as inputs // Read the board ID m_unBoardId = (DIO_PORT & DIO_MASK) ^ DIO_MASK; // Read the parameters previously saved in flash loadDataFromMemory(); //Enables the core to handle any pending interrupt requests asm volatile ("ei"); }