// See super class documentation. int LinkTestMessage::deserialize (IRIS_UBYTE *bufPtr, IRIS_UINT32 length) { IRIS_UBYTE *pktPtr = bufPtr; IRIS_UINT16 calcCrc, rcedCrc; // Restore the Message ID and check the CRC calcCrc = NetworkServices::calcCRC(bufPtr, serializedSize - 2); BYTE_SWAP_COPY_16(&bufPtr[serializedSize - 2], &rcedCrc); // set received crc to network order if(calcCrc != rcedCrc) return IRIS_NodeInterface::CRC_FAIL; // Copy individual members into the serial buffer pktPtr += 1; // Skip past the Message class data // Compatability code BYTE_SWAP_COPY_32(pktPtr, &compatabilityCode); pktPtr += 4; // Control Number BYTE_SWAP_COPY_32(pktPtr, &controlNumber); return IRIS_NodeInterface::OK; }
// See super class documentation. int GetRequestMessage::serialize (IRIS_UBYTE *bufPtr) { IRIS_UBYTE *pktPtr = bufPtr; IRIS_UINT16 crc; // Fill in the Message members (ID, Dest, Orig) Message::pktBuild(&pktPtr); // Copy individual members into the serial buffer // ID of the get message for this request *((IRIS_UBYTE *)pktPtr) = requestedMessageID; pktPtr++; // Now add the CRC crc = NetworkServices::calcCRC(bufPtr, ((IRIS_UINT32)(serializedSize - 2))); BYTE_SWAP_COPY_16(&crc, pktPtr); // set crc to network order and copy into the serialized packet return serializedSize; // Length of packet is auto generated }
// See super class documentation. int LinkTestMessage::serialize (IRIS_UBYTE *bufPtr) { IRIS_UBYTE *pktPtr = bufPtr; IRIS_UINT16 crc; // Fill in the Message members (ID, Dest, Orig) Message::pktBuild(&pktPtr); // Copy individual members into the serial buffer // Compatability code BYTE_SWAP_COPY_32(&compatabilityCode, pktPtr); pktPtr += 4; // Compatability code BYTE_SWAP_COPY_32(&controlNumber, pktPtr); pktPtr += 4; // Now add the CRC crc = NetworkServices::calcCRC(bufPtr, ((IRIS_UINT32)(serializedSize - 2))); BYTE_SWAP_COPY_16(&crc, pktPtr); // set crc to network order and copy into the serialized packet return serializedSize; // Length of packet is auto generated }
// See super class documentation. int GetRequestMessage::deserialize (IRIS_UBYTE *bufPtr, IRIS_UINT32 length) { IRIS_UBYTE *pktPtr = bufPtr; IRIS_UINT16 calcCrc, rcedCrc; // Restore the Message ID and check the CRC calcCrc = NetworkServices::calcCRC(bufPtr, serializedSize - 2); BYTE_SWAP_COPY_16(&bufPtr[serializedSize - 2], &rcedCrc); // set received crc to network order if(calcCrc != rcedCrc) { printf ("ERROR: calculated CRC: 0x%X, receiveded CRC: 0x%X\n", calcCrc, rcedCrc); //return IRIS_NodeInterface::CRC_FAIL; } // Copy individual members into the serial buffer pktPtr += 1; // Skip past the Message class data // ID of the get message for this request requestedMessageID = *pktPtr; printf ("CRC -OK. calculated CRC: 0x%X, receiveded CRC: 0x%X\n", calcCrc, rcedCrc); return IRIS_NodeInterface::OK; }
// See super class documentation. int StatusMessage::serialize (IRIS_UBYTE *bufPtr) { IRIS_UBYTE *pktPtr = bufPtr; IRIS_UINT16 crc; int ndx; // Fill in the Message members (ID, Dest, Orig) Message::pktBuild(&pktPtr); // Copy individual members into the serial buffer // originator *pktPtr++ = originator; // clientId *pktPtr++ = clientId; // numExtendedDataItems *pktPtr++ = numExtendedDataItems; // extendedDataSize BYTE_SWAP_COPY_16(&extendedDataSize, pktPtr); pktPtr += 2; // subsystemStatus *pktPtr++ = subsystemStatus; // partNumRev for(ndx = 0; ndx < HW_REV_LENGTH; ndx++) { *pktPtr++ = partNumRev[ndx]; } // serialNum for(ndx = 0; ndx < SERNO_LENGTH; ndx++) { *pktPtr++ = serialNum[ndx]; } // swRev for(ndx = 0; ndx < SW_REV_LENGTH; ndx++) { *pktPtr++ = swRev[ndx]; } // bootRev for(ndx = 0; ndx < BOOT_REV_LENGTH; ndx++) { *pktPtr++ = bootRev[ndx]; } // diagnosticCode *pktPtr++ = diagnosticCode; // Set serialized size using the received packet size serializedSize = basicSize + extendedDataSize + MESSAGE_CLASS_SERIALIZED_BYTE_COUNT; // Copy the message buffer data into the space allocated for the object for(ndx = 0; ndx < extendedDataSize; ndx ++) *pktPtr++ = buffer[ndx]; // Now add the CRC crc = NetworkServices::calcCRC(bufPtr, ((IRIS_UINT32)(serializedSize - 2))); BYTE_SWAP_COPY_16(&crc, pktPtr); // set crc to network order and copy into the serialized packet return serializedSize; // Length of packet is auto generated }
// See super class documentation. int StatusMessage::deserialize (IRIS_UBYTE *bufPtr, IRIS_UINT32 length) { IRIS_UBYTE *pktPtr = bufPtr; IRIS_UINT16 calcCrc, rcedCrc; int ndx; // Copy individual members into the serial buffer (must defer CRC check until after packet size is known) pktPtr += 1; // Skip past the Message class data // originator originator = *pktPtr; pktPtr += 1; // clientId clientId = *pktPtr++; // numExtendedDataItems numExtendedDataItems = *pktPtr++; // extendedDataSize BYTE_SWAP_COPY_16(pktPtr, &extendedDataSize); pktPtr += 2; // subsystemStatus subsystemStatus = *pktPtr++; // partNumRev for(ndx = 0; ndx < HW_REV_LENGTH; ndx++) { partNumRev[ndx] = *pktPtr++; } // serialNum for(ndx = 0; ndx < SERNO_LENGTH; ndx++) { serialNum[ndx] = *pktPtr++; } // swRev for(ndx = 0; ndx < SW_REV_LENGTH; ndx++) { swRev[ndx] = *pktPtr++; } // bootRev for(ndx = 0; ndx < BOOT_REV_LENGTH; ndx++) { bootRev[ndx] = *pktPtr++; } // diagnosticCode diagnosticCode = *pktPtr++; /* ** Figure out the size of the packet */ // Make sure the serialized message size does not exceed input buffer size IRIS_UINT32 tempSerSize = basicSize + extendedDataSize + MESSAGE_CLASS_SERIALIZED_BYTE_COUNT; if(tempSerSize <= length) { // Set serialized size using the received packet size serializedSize = tempSerSize; } else return IRIS_NodeInterface::CRC_FAIL; // Indicate failure, CRC check will overrun input buffer // Restore the Message ID and check the CRC calcCrc = NetworkServices::calcCRC(bufPtr, serializedSize - 2); BYTE_SWAP_COPY_16(&bufPtr[serializedSize - 2], &rcedCrc); // set received crc to network order if(calcCrc != rcedCrc) return IRIS_NodeInterface::CRC_FAIL; // Check to see if enough space is allocated for the serialized extended data if(extendedDataSize > allocatedBuffer) { // Not enough! allocate more // Delete the current one if it exists if(buffer != 0) { IRIS_UBYTE *tempB = buffer; buffer = 0; delete[] tempB; } // Now allocate the new larger one allocatedBuffer = extendedDataSize * 2; // Double sized for byte stuffing buffer = new unsigned char[allocatedBuffer]; } // Copy the serialized extended data into the space allocated for the object for(ndx = 0; ndx < extendedDataSize; ndx ++) buffer[ndx] = *pktPtr++; /* ** Map the serialized extended data into ExtendedStatusData objects ** The data in 'buffer' is essentially byte packed ExtendedStatusData objects in stream ** form. The buffer for 'data' is imbedded in this stream. */ { ExtendedStatusData *listItemPtr = extDataList; ExtendedStatusData *previous = extDataList; unsigned char *extDataBufNdx = buffer; // Setup the ExtendedStatusData objects adding new objects if needed for(ndx = 0; ndx < numExtendedDataItems; ndx++) { // Special Case: first item in list. if(extDataList == 0) { listItemPtr = extDataList = new ExtendedStatusData(); listItemPtr->next = 0; } // This position is empty, not the beginning of the list else if(listItemPtr == 0) { listItemPtr = new ExtendedStatusData(); listItemPtr->next = 0; // Link this item to the list previous->next = listItemPtr; } // Setup the ExtendedStatusData object with the serialized buffer data listItemPtr->idTag = *extDataBufNdx++; listItemPtr->size = *extDataBufNdx++; listItemPtr->data = extDataBufNdx; // Skip past the buffer data to the next object in the serial stream buffer extDataBufNdx += listItemPtr->size; // Remember the previous item previous = listItemPtr; // Go to the next listItemPtr = listItemPtr->next; } } return IRIS_NodeInterface::OK; }