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)
435 unsigned int id = bcPtr->dataHdr.id;
437 if (id<DID_COUNT && cmInstance->regData[
id].preTxFnc)
439 sendData = cmInstance->
regData[id].
preTxFnc(cmInstance, bcPtr->pHandle);
471 ((
com_manager_t*)cmInstance)->cmMsgHandlerAscii = handlerAscii;
472 ((
com_manager_t*)cmInstance)->cmMsgHandlerUblox = handlerUblox;
473 ((
com_manager_t*)cmInstance)->cmMsgHandlerRtcm3 = handlerRtcm3;
532 data.
ptr = (uint8_t*)&request;
533 data.
size =
sizeof(request);
569 bodyHdr.
ptr = (uint8_t*)&hdr;
570 bodyHdr.
size =
sizeof(hdr);
571 data.
ptr = (uint8_t*)dataPtr;
572 data.
size = dataSize;
593 bodyHdr.
ptr = (uint8_t*)&hdr;
594 bodyHdr.
size =
sizeof(hdr);
595 data.
ptr = (uint8_t*)dataPtr;
596 data.
size = dataSize;
617 bodyHdr.
ptr = (uint8_t*)&hdr;
618 bodyHdr.
size =
sizeof(hdr);
619 data.
ptr = (uint8_t*)dataPtr;
620 data.
size = dataSize;
633 data.
ptr = (uint8_t*)&dataId;
691 unsigned char* a1 = (
unsigned char*)a;
707 uint8_t pid = (uint8_t)(pkt->
hdr.
pid);
723 dataHdr = &(data->
hdr);
728 regd = &(cmInstance->
regData[dataHdr->
id]);
747 #if ENABLE_PACKET_CONTINUATION 751 if (additionalDataAvailable || (con->
hdr.
size != 0 && con->
hdr.
id == dataHdr->
id))
775 if (additionalDataAvailable)
802 regd->
pstRxFnc(cmInstance, pHandle, data);
809 cmInstance->
pstRxFnc(cmInstance, pHandle, data);
815 #if ENABLE_PACKET_CONTINUATION 927 if (dataSetPtr->
txPtr == 0 || dataSetPtr->
size == 0)
940 if (bcPtr->pHandle == pHandle && bcPtr->dataHdr.id == req->
id && bcPtr->dataHdr.size == req->
size && bcPtr->dataHdr.offset == req->
offset)
1038 if (periodMultiple > 0)
1067 if (pHandle < 0 || bcPtr->pHandle == pHandle)
1078 if ((pHandle < 0 || pHandle == bcPtr->pHandle) && bcPtr->dataHdr.id == disable->
id)
1088 req.
id = disable->
id;
1125 if (sendCallback == 0)
1144 uint32_t size = hdr.
size;
1145 uint32_t offset = 0;
1146 uint32_t
id = hdr.
id;
1149 #if ENABLE_PACKET_CONTINUATION 1158 hdrToSend->offset = hdr.
offset + offset;
1165 size -= hdrToSend->size;
1167 #if ENABLE_PACKET_CONTINUATION 1170 offset += hdrToSend->size;
1192 sendCallback(cmInstance, pHandle, bufToSend.
buf, bufToSend.
size);
1194 #if ENABLE_PACKET_CONTINUATION 1213 sendCallback(cmInstance, pHandle, bufToSend.
buf, bufToSend.
size);
1241 data.
ptr = (
unsigned char*)&ack;
1242 data.
size = ackSize;
1274 void* srcBuffer = dPkt->
body.
ptr;
1275 int srcBufferLength = dPkt->
body.
size;
1276 void* encodedPacket = pkt->
buf;
1282 return (-1 * ((
int)pkt->
size < 8));
1340 unsigned char searching = 1;
1342 #if ENABLE_FILTER_DUPLICATE_PACKETS 1344 #if ENABLE_FILTER_DUPLICATE_PACKETS_MATCH_ALL_CHARACTERS 1383 if (getData1->
id == getData2->
id &&
1384 getData1->
size == getData2->
size &&
1395 #if !ENABLE_FILTER_DUPLICATE_PACKETS_MATCH_ALL_CHARACTERS 1406 for (j = 0; j < dataSize; j++)
1457 memcpy(ePkt->
pktBody, data, dataSize);
1466 return &(ePkt->
pkt);
1564 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...
static int sendData(is_comm_instance_t *instance, uint32_t dataId, uint32_t offset, uint32_t size, void *data, uint32_t pid)
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)
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)
int(* pfnComManagerPreSend)(CMHANDLE cmHandle, int pHandle)
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)