19 #define ENABLE_FILTER_DUPLICATE_PACKETS 1 22 #define ENABLE_FILTER_DUPLICATE_PACKETS_MATCH_ALL_CHARACTERS 0 24 #define PARSE_DOUBLE(str) strtod(str, 0) 25 #define PARSE_FLOAT(str) strtof(str, 0) 27 #define MIN_REQUEST_PERIOD_MS 1 // (ms) 1 KHz 28 #define MAX_REQUEST_PERIOD_MS 100000 // (ms) 29 #define MSG_PERIOD_SEND_ONCE -1 30 #define MSG_PERIOD_DISABLED 0 38 int maxEnsuredPackets,
39 int stepPeriodMilliseconds,
81 int maxEnsuredPackets,
82 int stepPeriodMilliseconds,
98 stepPeriodMilliseconds,
114 int maxEnsuredPackets,
115 int stepPeriodMilliseconds,
137 stepPeriodMilliseconds,
155 int maxEnsuredPackets,
156 int stepPeriodMilliseconds,
174 numHandles =
_CLAMP(numHandles, 1, 1024);
205 cmInstance->
ports = cmPorts;
206 for (i = 0; i < numHandles; i++)
214 #if ENABLE_PACKET_CONTINUATION 311 for (pHandle = 0; pHandle < cmInstance->
numHandles; pHandle++)
317 #if 0 // Read one byte (simple method) 321 while (cmInstance->
readCallback(cmInstance, pHandle, &c, 1))
326 #else // Read a set of bytes (fast method) 359 error = (uint8_t)cmInstance->
cmMsgHandlerUblox(cmInstance, pHandle, dataPtr, dataSize);
366 error = (uint8_t)cmInstance->
cmMsgHandlerRtcm3(cmInstance, pHandle, dataPtr, dataSize);
373 error = (uint8_t)cmInstance->
cmMsgHandlerAscii(cmInstance, pHandle, dataPtr, dataSize);
427 else if (bcPtr->period > 0)
430 if (++bcPtr->counter >= bcPtr->period)
437 cmInstance->
regData[bcPtr->dataHdr.id].
preTxFnc(cmInstance, bcPtr->pHandle);
466 ((
com_manager_t*)cmInstance)->cmMsgHandlerAscii = handlerAscii;
467 ((
com_manager_t*)cmInstance)->cmMsgHandlerUblox = handlerUblox;
468 ((
com_manager_t*)cmInstance)->cmMsgHandlerRtcm3 = handlerRtcm3;
527 data.
ptr = (uint8_t*)&request;
528 data.
size =
sizeof(request);
564 bodyHdr.
ptr = (uint8_t*)&hdr;
565 bodyHdr.
size =
sizeof(hdr);
566 data.
ptr = (uint8_t*)dataPtr;
567 data.
size = dataSize;
588 bodyHdr.
ptr = (uint8_t*)&hdr;
589 bodyHdr.
size =
sizeof(hdr);
590 data.
ptr = (uint8_t*)dataPtr;
591 data.
size = dataSize;
612 bodyHdr.
ptr = (uint8_t*)&hdr;
613 bodyHdr.
size =
sizeof(hdr);
614 data.
ptr = (uint8_t*)dataPtr;
615 data.
size = dataSize;
628 data.
ptr = (uint8_t*)&dataId;
686 unsigned char* a1 = (
unsigned char*)a;
702 uint8_t pid = (uint8_t)(pkt->
hdr.
pid);
718 dataHdr = &(data->
hdr);
726 regd = &(cmInstance->
regData[dataHdr->
id]);
744 #if ENABLE_PACKET_CONTINUATION 748 if (additionalDataAvailable || (con->
hdr.
size != 0 && con->
hdr.
id == dataHdr->
id))
772 if (additionalDataAvailable)
797 regd->
pstRxFnc(cmInstance, pHandle, data);
803 cmInstance->
pstRxFnc(cmInstance, pHandle, data);
809 #if ENABLE_PACKET_CONTINUATION 921 if (dataSetPtr->
txPtr == 0 || dataSetPtr->
size == 0)
934 if (bcPtr->pHandle == pHandle && bcPtr->dataHdr.id == req->
id && bcPtr->dataHdr.size == req->
size && bcPtr->dataHdr.offset == req->
offset)
1024 if (periodMultiple > 0)
1053 if (pHandle < 0 || bcPtr->pHandle == pHandle)
1064 if ((pHandle < 0 || pHandle == bcPtr->pHandle) && bcPtr->dataHdr.id == disable->
id)
1074 req.
id = disable->
id;
1111 if (sendCallback == 0)
1130 uint32_t size = hdr.
size;
1131 uint32_t offset = 0;
1132 uint32_t
id = hdr.
id;
1135 #if ENABLE_PACKET_CONTINUATION 1144 hdrToSend->offset = hdr.
offset + offset;
1151 size -= hdrToSend->size;
1153 #if ENABLE_PACKET_CONTINUATION 1156 offset += hdrToSend->size;
1178 sendCallback(cmInstance, pHandle, bufToSend.
buf, bufToSend.
size);
1180 #if ENABLE_PACKET_CONTINUATION 1199 sendCallback(cmInstance, pHandle, bufToSend.
buf, bufToSend.
size);
1227 data.
ptr = (
unsigned char*)&ack;
1228 data.
size = ackSize;
1260 void* srcBuffer = dPkt->
body.
ptr;
1261 int srcBufferLength = dPkt->
body.
size;
1262 void* encodedPacket = pkt->
buf;
1268 return (-1 * ((
int)pkt->
size < 8));
1326 unsigned char searching = 1;
1328 #if ENABLE_FILTER_DUPLICATE_PACKETS 1330 #if ENABLE_FILTER_DUPLICATE_PACKETS_MATCH_ALL_CHARACTERS 1369 if (getData1->
id == getData2->
id &&
1370 getData1->
size == getData2->
size &&
1381 #if !ENABLE_FILTER_DUPLICATE_PACKETS_MATCH_ALL_CHARACTERS 1392 for (j = 0; j < dataSize; j++)
1443 memcpy(ePkt->
pktBody, data, dataSize);
1452 return &(ePkt->
pkt);
1550 if (dHdr->
id == eHdr->
id &&
int comManagerDisableData(int pHandle, uint32_t dataId)
registered_data_t regData[DID_COUNT]
int comManagerSendDataNoAck(int pHandle, uint32_t dataId, void *dataPtr, int dataSize, int dataOffset)
ensured_pkt_t * ensuredPackets
int comManagerSendDataInstance(CMHANDLE cmInstance, int pHandle, uint32_t dataId, void *dataPtr, int dataSize, int dataOffset)
int(* pfnComManagerSendBufferAvailableBytes)(CMHANDLE cmHandle, int pHandle)
int comManagerSendRawData(int pHandle, uint32_t dataId, void *dataPtr, int dataSize, int dataOffset)
void comManagerSetCallbacksInstance(CMHANDLE cmInstance, pfnComManagerAsapMsg handlerRmc, pfnComManagerGenMsgHandler handlerAscii, pfnComManagerGenMsgHandler handlerUblox, pfnComManagerGenMsgHandler handlerRtcm3)
void comManagerStepRxInstance(CMHANDLE cmInstance_)
int asciiMessageCompare(const void *elem1, const void *elem2)
pfnComManagerGenMsgHandler cmMsgHandlerUblox
int processBinaryRxPacket(com_manager_t *cmInstance, int pHandle, packet_t *pkt)
Process binary packet content:
pfnComManagerAsapMsg cmMsgHandlerRmc
broadcast_msg_t * broadcastMessages
com_manager_status_t * comManagerGetStatus(int pHandle)
int comManagerValidateBaudRate(unsigned int baudRate)
#define MSG_PERIOD_DISABLED
bufTxRxPtr_t * comManagerGetRegisteredDataInfo(uint32_t dataId)
ensured_pkt_t * ensuredPackets
void(* pfnComManagerPostRead)(CMHANDLE cmHandle, int pHandle, p_data_t *dataRead)
#define PID_STOP_BROADCASTS_ALL_PORTS
pfnComManagerPostRead pstRxFnc
pfnComManagerSendBufferAvailableBytes txFreeCallback
void comManagerGetDataRmcInstance(CMHANDLE cmInstance, int pHandle, uint64_t rmcBits, uint32_t rmcOptions)
uint8_t buf[PKT_BUF_SIZE]
bufTxRxPtr_t * comManagerGetRegisteredDataInfoInstance(CMHANDLE _cmInstance, uint32_t dataId)
void comManagerDisableBroadcasts(int pHandle)
pfnComManagerPostRead pstRxFnc
void updatePacketRetryData(com_manager_t *cmInstance, packet_t *pkt)
Update packet retry. If the specific data requested or acknowledge is received, the retry list is upd...
uint32_t communicationErrorCount
uint8_t comm_buffer[PKT_BUF_SIZE]
void stepPacketRetry(com_manager_t *cmInstance)
stepPacketRetry - Resend the ensured packets after the ENSURE_RETRY_COUNT period if the expected resp...
int(* pfnComManagerAsapMsg)(CMHANDLE cmHandle, int pHandle, p_data_get_t *req)
broadcast_msg_t * broadcastMsg
#define MSG_PERIOD_SEND_ONCE
void disableDidBroadcast(com_manager_t *cmInstance, int pHandle, p_data_disable_t *disable)
void comManagerRegisterInstance(CMHANDLE cmInstance_, uint32_t dataId, pfnComManagerPreSend txFnc, pfnComManagerPostRead pstRxFnc, const void *txDataPtr, void *rxDataPtr, int dataSize, uint8_t pktFlags)
int comManagerSendInstance(CMHANDLE cmInstance, int pHandle, uint8_t pktInfo, bufPtr_t *bodyHdr, bufPtr_t *txData, uint8_t pktFlags)
void sendAck(com_manager_t *cmInstance, int pHandle, packet_t *pkt, unsigned char pid_ack)
uint8_t pktBody[PKT_BUF_SIZE]
protocol_type_t is_comm_parse_byte(is_comm_instance_t *instance, uint8_t byte)
void(* pfnComManagerDisableBroadcasts)(CMHANDLE cmHandle, int pHandle)
pfnComManagerRead readCallback
com_manager_status_t * comManagerGetStatusInstance(CMHANDLE cmInstance, int pHandle)
void comManagerDisableBroadcastsInstance(CMHANDLE cmInstance_, int pHandle)
int comManagerGetDataRequestInstance(CMHANDLE _cmInstance, int pHandle, p_data_get_t *req)
char copyDataPToStructP(void *sptr, const p_data_t *data, const unsigned int maxsize)
#define MIN_REQUEST_PERIOD_MS
void updatePacketRetryAck(com_manager_t *cmInstance, packet_t *pkt)
pfnComManagerPreSend preTxFnc
int comManagerGetDataRequest(int pHandle, p_data_get_t *req)
void(* pfnComManagerPreSend)(CMHANDLE cmHandle, int pHandle)
unsigned char messageId[4]
void comManagerStep(void)
com_manager_port_t * ports
int comManagerInitInstance(CMHANDLE cmHandle, int numHandles, int maxEnsuredPackets, int stepPeriodMilliseconds, int retryCount, pfnComManagerRead readFnc, pfnComManagerSend sendFnc, pfnComManagerSendBufferAvailableBytes txFreeFnc, pfnComManagerPostRead pstRxFnc, pfnComManagerPostAck pstAckFnc, pfnComManagerDisableBroadcasts disableBcastFnc, com_manager_init_t *buffers, com_manager_port_t *cmPorts)
#define COM_MANAGER_BUF_SIZE_BCAST_MSG(max_num_bcast_msgs)
#define MEMBERSIZE(type, member)
#define _LIMIT2(x, xmin, xmax)
packet_t * registerPacketRetry(com_manager_t *cmInstance, int pHandle, uint8_t pid, unsigned char data[], unsigned int dataSize)
registerPacketRetry - Saves data and packet header info to a retry list that will be resent if the co...
#define PID_STOP_BROADCASTS_CURRENT_PORT
int sendPacket(com_manager_t *cmInstance, int pHandle, packet_t *dPkt, uint8_t additionalPktFlags)
Encode and send out serial port the referenced packet structure.
int is_encode_binary_packet(void *srcBuffer, unsigned int srcBufferLength, packet_hdr_t *hdr, uint8_t additionalPktFlags, void *encodedPacket, int encodedPacketLength)
#define MAX_P_DATA_BODY_SIZE
int sendDataPacket(com_manager_t *cmInstance, int pHandle, pkt_info_t *msg)
int32_t maxEnsuredPackets
int comManagerSendEnsured(int pHandle, uint8_t pktInfo, unsigned char *data, unsigned int dataSize)
int is_comm_free(is_comm_instance_t *instance)
#define MAX_REQUEST_PERIOD_MS
int comManagerSendRawDataInstance(CMHANDLE cmInstance, int pHandle, uint32_t dataId, void *dataPtr, int dataSize, int dataOffset)
int initComManagerInstanceInternal(com_manager_t *cmInstance, int numHandles, int maxEnsuredPackets, int stepPeriodMilliseconds, int retryCount, pfnComManagerRead readFnc, pfnComManagerSend sendFnc, pfnComManagerSendBufferAvailableBytes txFreeFnc, pfnComManagerPostRead pstRxFnc, pfnComManagerPostAck pstAckFnc, pfnComManagerDisableBroadcasts disableBcastFnc, com_manager_init_t *buffers, com_manager_port_t *cmPorts)
int(* pfnComManagerGenMsgHandler)(CMHANDLE cmHandle, int pHandle, const unsigned char *msg, int msgSize)
void comManagerGetDataInstance(CMHANDLE cmInstance, int pHandle, uint32_t dataId, int offset, int size, int periodMultiple)
uint32_t broadcastMsgSize
const unsigned int g_validBaudRates[IS_BAUDRATE_COUNT]
pfnComManagerSend sendPacketCallback
int(* pfnComManagerSend)(CMHANDLE cmHandle, int pHandle, unsigned char *buffer, int numberOfBytes)
int findAsciiMessage(const void *a, const void *b)
void comManagerStepTxInstance(CMHANDLE cmInstance_)
#define _CLAMP(v, minV, maxV)
USBInterfaceDescriptor data
int(* pfnComManagerRead)(CMHANDLE cmHandle, int pHandle, uint8_t *buffer, int numberOfBytes)
com_manager_status_t status
int comManagerSendDataNoAckInstance(CMHANDLE cmInstance, int pHandle, uint32_t dataId, void *dataPtr, int dataSize, int dataOffset)
int32_t lastEnsuredPacketIndex
void comManagerAssignUserPointer(CMHANDLE cmInstance, void *userPointer)
void is_comm_init(is_comm_instance_t *instance, uint8_t *buffer, int bufferSize)
void stepComManagerSendMessagesInstance(CMHANDLE cmInstance)
int encodeBinaryPacket(com_manager_t *cmInstance, int pHandle, buffer_t *pkt, packet_t *dPkt, uint8_t additionalPktFlags)
Adds data to a packet: adds start, info, data length, data, checksum, and stop bytes. All data is communicated in the endianess of the sender, each packet has a bit that determines big or little endian. Process for Creating Tx Packet: 1.) Add to packet.
pfnComManagerGenMsgHandler cmMsgHandlerAscii
#define COM_MANAGER_BUF_SIZE_ENSURED_PKTS(max_num_ensured_pkts)
#define MAX_NUM_BCAST_MSGS
pfnComManagerGenMsgHandler cmMsgHandlerRtcm3
void disableBroadcastMsg(com_manager_t *cmInstance, broadcast_msg_t *msg)
void comManagerSetCallbacks(pfnComManagerAsapMsg handlerRmc, pfnComManagerGenMsgHandler handlerAscii, pfnComManagerGenMsgHandler handlerUblox, pfnComManagerGenMsgHandler handlerRtcm3)
void comManagerGetDataRmc(int pHandle, uint64_t rmcBits, uint32_t rmcOptions)
int comManagerSend(int pHandle, uint8_t pktInfo, bufPtr_t *bodyHdr, bufPtr_t *txData, uint8_t pFlags)
void stepComManagerSendMessages(void)
void * comManagerGetUserPointer(CMHANDLE cmInstance)
pfnComManagerPostAck pstAckFnc
int comManagerSendData(int pHandle, uint32_t dataId, void *dataPtr, int dataSize, int dataOffset)
int comManagerDisableDataInstance(CMHANDLE cmInstance, int pHandle, uint32_t dataId)
void enableBroadcastMsg(com_manager_t *cmInstance, broadcast_msg_t *msg, int periodMultiple)
#define PID_STOP_DID_BROADCAST
protocol_type_t is_comm_parse(is_comm_instance_t *instance)
void comManagerGetData(int pHandle, uint32_t dataId, int offset, int size, int periodMultiple)
Request data This function requests the specified data w/ offset and length for partial reads...
uint8_t buf[MAX_DATASET_SIZE]
int comManagerInit(int numHandles, int maxEnsuredPackets, int stepPeriodMilliseconds, int retryCount, pfnComManagerRead readFnc, pfnComManagerSend sendFnc, pfnComManagerSendBufferAvailableBytes txFreeFnc, pfnComManagerPostRead pstRxFnc, pfnComManagerPostAck pstAckFnc, pfnComManagerDisableBroadcasts disableBcastFnc, com_manager_init_t *buffers, com_manager_port_t *cmPorts)
#define _ARRAY_ELEMENT_COUNT(a)
int32_t stepPeriodMilliseconds
uint32_t bc_period_multiple
pfnComManagerDisableBroadcasts disableBcastFnc
void comManagerRegister(uint32_t dataId, pfnComManagerPreSend txFnc, pfnComManagerPostRead pstRxFnc, const void *txDataPtr, void *rxDataPtr, int dataSize, uint8_t pktFlags)
uint32_t ensuredPacketsSize
void(* pfnComManagerPostAck)(CMHANDLE cmHandle, int pHandle, p_ack_t *ack, unsigned char packetIdentifier)
void comManagerStepInstance(CMHANDLE cmInstance_)
static com_manager_t g_cm
int comManagerSendEnsuredInstance(CMHANDLE cmInstance, int pHandle, uint8_t pktInfo, unsigned char *data, unsigned int dataSize)
CMHANDLE comManagerGetGlobal(void)