BOOL dll_addNodeBefore( struct DoubleLinkedList *pdll, struct dllnode *pNode, struct dllnode *pInsertNode ) { if ( NULL == pdll ) return FALSE; if ( NULL == pNode ) return FALSE; if ( NULL == pInsertNode ) return FALSE; if ( NULL == pNode->pPrev ) { // There is no nodes before this node dll_addNodeHead( pdll, pInsertNode ); } else { // Add the node between the two dll_insertNode( pdll, pNode, pInsertNode ); } // Calculate the number of elements in the list dll_getNodeCount( pdll ); return TRUE; }
void *workThreadTransmit( void *pObject ) #endif { #ifdef WIN32 DWORD errorCode = 0; #else int rv = 0; #endif CPeakObj * pobj = ( CPeakObj *)pObject; if ( NULL == pobj ) { #ifdef WIN32 ExitThread( errorCode ); // Fail #else pthread_exit( &rv ); #endif } while ( pobj->m_bRun ) { LOCK_MUTEX( pobj->m_peakMutex ); // Noting to do if we should end... if ( !pobj->m_bRun ) continue; // Is there something to transmit... int ret; while ( ( NULL != pobj->m_transmitList.pHead ) && ( NULL != pobj->m_transmitList.pHead->pObject ) ) { canalMsg msg; memcpy( &msg, pobj->m_transmitList.pHead->pObject, sizeof( canalMsg ) ); LOCK_MUTEX( pobj->m_transmitMutex ); dll_removeNode( &pobj->m_transmitList, pobj->m_transmitList.pHead ); UNLOCK_MUTEX( pobj->m_transmitMutex ); PeakCanMsg peakMsg; peakMsg.id = msg.id; peakMsg.msgType = 0; peakMsg.len = msg.sizeData; memcpy( peakMsg.data, msg.data, peakMsg.len ); // Check if RTR if ( ( msg.flags & CANAL_IDFLAG_RTR ) ) { peakMsg.msgType |= PCAN_MSGTYPE_RTR; } // Check if extended if ( ( msg.flags & CANAL_IDFLAG_EXTENDED ) ) { peakMsg.msgType |= PCAN_MSGTYPE_EXTENDED; } if ( PEAK_CAN_ERR_OK == ( ret = pobj->m_procWrite( &peakMsg ) ) ) { // Message sent successfully // Update statistics pobj->m_stat.cntTransmitData += msg.sizeData; pobj->m_stat.cntTransmitFrames += 1; } else { // Failed - put message back in queue front PCANALMSG pMsg = new canalMsg; if ( NULL != pMsg ) { // Copy in data memcpy ( pMsg, &msg, sizeof( canalMsg ) ); dllnode *pNode = new dllnode; if ( NULL != pNode ) { pNode->pObject = pMsg; LOCK_MUTEX( pobj->m_transmitMutex ); dll_addNodeHead( &pobj->m_transmitList, pNode ); UNLOCK_MUTEX( pobj->m_transmitMutex ); } else { delete pMsg; } } // unable to allocate storage } // faild to send message } // while data // No data to write UNLOCK_MUTEX( pobj->m_peakMutex ); SLEEP( 1 ); //} } // while #ifdef WIN32 ExitThread( errorCode ); #else pthread_exit( &rv ); #endif }
void *workThreadTransmit( void *pObject ) #endif { #ifdef WIN32 DWORD errorCode = 0; #else int rv = 0; #endif CIxxObj * pobj = ( CIxxObj *)pObject; if ( NULL == pobj ) { #ifdef WIN32 ExitThread( errorCode ); // Fail #else pthread_exit( &rv ); #endif } while ( pobj->m_bRun ) { LOCK_MUTEX( pobj->m_ixxMutex ); // Noting to do if we should end... if ( !pobj->m_bRun ) continue; // Is there something to transmit while ( ( NULL != pobj->m_transmitList.pHead ) && ( NULL != pobj->m_transmitList.pHead->pObject ) ) { canalMsg msg; memcpy( &msg, pobj->m_transmitList.pHead->pObject, sizeof( canalMsg ) ); LOCK_MUTEX( pobj->m_transmitMutex ); dll_removeNode( &pobj->m_transmitList, pobj->m_transmitList.pHead ); UNLOCK_MUTEX( pobj->m_transmitMutex ); if ( !( msg.flags & CANAL_IDFLAG_RTR ) ) { // Standard message if ( VCI_OK == VCI_TransmitObj( pobj->m_hBoard, pobj->m_hTxQue, msg.id, msg.sizeData, msg.data ) ) { // Message sent successfully // Update statistics pobj->m_stat.cntTransmitData += msg.sizeData; pobj->m_stat.cntTransmitFrames += 1; } else { // Failed - put message back in queue front PCANALMSG pMsg = new canalMsg; if ( NULL != pMsg ) { // Copy in data memcpy ( pMsg, &msg, sizeof( canalMsg ) ); dllnode *pNode = new dllnode; if ( NULL != pNode ) { pNode->pObject = pMsg; LOCK_MUTEX( pobj->m_transmitMutex ); dll_addNodeHead( &pobj->m_transmitList, pNode ); UNLOCK_MUTEX( pobj->m_transmitMutex ); } else { delete pMsg; } } } } else { // Remote request if ( VCI_OK == VCI_RequestObj( pobj->m_hBoard, pobj->m_hTxQue, msg.id, msg.sizeData ) ) { // Message sent successfully // Update statistics pobj->m_stat.cntTransmitFrames += 1; } else { // Failed - put message back in queue front PCANALMSG pMsg = new canalMsg; if ( NULL != pMsg ) { // Copy in data memcpy ( pMsg, &msg, sizeof( canalMsg ) ); dllnode *pNode = new dllnode; if ( NULL != pNode ) { pNode->pObject = pMsg; LOCK_MUTEX( pobj->m_transmitMutex ); dll_addNodeHead( &pobj->m_transmitList, pNode ); UNLOCK_MUTEX( pobj->m_transmitMutex ); } else { delete pMsg; } } } } } // while data // No data to write UNLOCK_MUTEX( pobj->m_ixxMutex ); SLEEP( 1 ); //} } // while #ifdef WIN32 ExitThread( errorCode ); #else pthread_exit( &rv ); #endif }
void *workThreadTransmit( void *pObject ) #endif { #ifdef WIN32 DWORD errorCode = 0; #else int rv = 0; #endif CVectorObj * pobj = ( CVectorObj *)pObject; if ( NULL == pobj ) { #ifdef WIN32 ExitThread( errorCode ); // Fail #else pthread_exit( &rv ); #endif } while ( pobj->m_bRun ) { LOCK_MUTEX( pobj->m_vectorMutex ); // Noting to do if we should end... if ( !pobj->m_bRun ) continue; // Is there something to transmit while ( ( NULL != pobj->m_transmitList.pHead ) && ( NULL != pobj->m_transmitList.pHead->pObject ) ) { canalMsg msg; memcpy( &msg, pobj->m_transmitList.pHead->pObject, sizeof( canalMsg ) ); LOCK_MUTEX( pobj->m_transmitMutex ); dll_removeNode( &pobj->m_transmitList, pobj->m_transmitList.pHead ); UNLOCK_MUTEX( pobj->m_transmitMutex ); VCAN_EVENT event; event.tag = V_TRANSMIT_MSG; // id event.tagData.msg.id = msg.id; if ( msg.flags & CANAL_IDFLAG_EXTENDED ) { event.tagData.msg.id |= VCAN_EXT_MSG_ID; // Extended } // size event.tagData.msg.dlc = msg.sizeData; // Vector flags event.tagData.msg.flags = 0; if ( msg.flags & CANAL_IDFLAG_RTR ) { event.tagData.msg.flags |= MSGFLAG_REMOTE_FRAME; // RTR } // Data memcpy( event.tagData.msg.data, msg.data, msg.sizeData ); if ( VERR_QUEUE_IS_FULL != ncdTransmit( pobj->m_portHandle, pobj->m_channelMask, &event ) ) { // Message sent successfully // Update statistics pobj->m_stat.cntTransmitData += msg.sizeData; pobj->m_stat.cntTransmitFrames += 1; } else { // Failed - put message back in queue front PCANALMSG pMsg = new canalMsg; if ( NULL != pMsg ) { // Copy in data memcpy ( pMsg, &msg, sizeof( canalMsg ) ); dllnode *pNode = new dllnode; if ( NULL != pNode ) { pNode->pObject = pMsg; LOCK_MUTEX( pobj->m_transmitMutex ); dll_addNodeHead( &pobj->m_transmitList, pNode ); UNLOCK_MUTEX( pobj->m_transmitMutex ); } else { delete pMsg; } } } // send message } // while data // No data to write UNLOCK_MUTEX( pobj->m_vectorMutex ); SLEEP( 1 ); //} } // while #ifdef WIN32 ExitThread( errorCode ); #else pthread_exit( &rv ); #endif }
void *workThreadTransmit( void *pObject ) #endif { #ifdef WIN32 DWORD errorCode = 0; #else int rv = 0; #endif CApoxObj * pobj = ( CApoxObj *)pObject; if ( NULL == pobj ) { #ifdef WIN32 ExitThread( errorCode ); // Fail #else pthread_exit( &rv ); #endif } while ( pobj->m_bRun ) { // Noting to do if we should end... if ( !pobj->m_bRun ) continue; // Is there something to transmit while ( ( NULL != pobj->m_transmitList.pHead ) && ( NULL != pobj->m_transmitList.pHead->pObject ) ) { canalMsg msg; memcpy( &msg, pobj->m_transmitList.pHead->pObject, sizeof( canalMsg ) ); LOCK_MUTEX( pobj->m_transmitMutex ); dll_removeNode( &pobj->m_transmitList, pobj->m_transmitList.pHead ); UNLOCK_MUTEX( pobj->m_transmitMutex ); // Outgoing CAN message // -------------------------- // [0] ([1][RTR][EXT][unused 0..4]) // [1] ID MSB // [2] ID // [3] ID // [4] ID LSB // [5] FUTURE USE (CANopen or DeviceNet) // ex. Wait for response? Etc.. // [6] FUTURE USE (CANopen or DeviceNet) // [7] RESERVED FOR TX FLAGS // [8] DATA LEN (0-8) // [9-16] uint8_t sendData[ 20 ]; short size = 0; sendData[ size++ ] = 0x80 | ( ( msg.flags & CANAL_IDFLAG_RTR ) ? 0x40:0x00) | ( ( msg.flags & CANAL_IDFLAG_EXTENDED ) ? 0x20 : 0x00 ); sendData[ size++ ] = ( uint8_t )( msg.id >> 24 ) & 0x1f; sendData[ size++ ] = ( uint8_t )( msg.id >> 16 ) & 0xff; sendData[ size++ ] = ( uint8_t )( msg.id >> 8 ) & 0xff; sendData[ size++ ] = ( uint8_t )( msg.id ) & 0xff; sendData[size++] = 0x00; // future use sendData[size++] = 0x00; // future use sendData[size++] = 0; // txFlags; sendData[size++] = msg.sizeData; memcpy( sendData, msg.data, msg.sizeData ); size += msg.sizeData; LOCK_MUTEX( pobj->m_apoxMutex ); if ( USB_OK == pobj->sendUSBMsg( sendData, size ) ) { // Message sent successfully // Update statistics pobj->m_stat.cntTransmitData += msg.sizeData; pobj->m_stat.cntTransmitFrames += 1; } else { // Failed - put message back in queue front PCANALMSG pMsg = new canalMsg; if ( NULL != pMsg ) { // Copy in data memcpy ( pMsg, &msg, sizeof( canalMsg ) ); dllnode *pNode = new dllnode; if ( NULL != pNode ) { pNode->pObject = pMsg; LOCK_MUTEX( pobj->m_transmitMutex ); dll_addNodeHead( &pobj->m_transmitList, pNode ); UNLOCK_MUTEX( pobj->m_transmitMutex ); } else { delete pMsg; } } } UNLOCK_MUTEX( pobj->m_apoxMutex ); } // while data // No data to write SLEEP( 1 ); //} } // while #ifdef WIN32 ExitThread( errorCode ); #else pthread_exit( &rv ); #endif }