/* --------------------------------------------------------------------------- * BpMessageFormat.c - v0.1 (c) 2008 Micro-key bv * --------------------------------------------------------------------------- * Micro-key bv * Industrieweg 28, 9804 TG Noordhorn * Postbus 92, 9800 AB Zuidhorn * The Netherlands * Tel: +31 594 503020 * Fax: +31 594 505825 * Email: support@microkey.nl * Web: www.microkey.nl * --------------------------------------------------------------------------- * Description: * --------------------------------------------------------------------------- * Version(s): 0.1, Jan 29, 2008, FSc * Creation. * --------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------- * System include files * --------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------- * Application include files * --------------------------------------------------------------------------- */ #include "BpMessageFormat.h" #include "Crc.h" /* --------------------------------------------------------------------------- * Local constant and macro definitions * --------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------- * Global variable definitions * --------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------- * Local variable definitions * --------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------- * Local function definitions * --------------------------------------------------------------------------- */ /** \brief Calculates the CRC over payload etc... and sets unique start byte * * \param msg Message over which the CRC should be calculated */ void bpmsgEncodeMessage( t_bpmsg_message * msg ) { UINT16 crc; crc = crcCalc( &msg->payloadSize, 1, 0); crc = crcCalc( msg->payload, msg->payloadSize, crc); msg->crc = crc; } void bpmsgAdd16bit(UINT8 *payloadlocation, UINT16 data) { UINT8 index = 0; payloadlocation[index] = (UINT8)(data >> 8); index++; payloadlocation[index] = (UINT8)(data & 0x00FF); } void bpmsgAdd32bit(UINT8 *payloadlocation, UINT32 data) { UINT8 index = 0; payloadlocation[index] = (UINT8)(data >> 24); index++; payloadlocation[index] = (UINT8)(data >> 16); index++; payloadlocation[index] = (UINT8)(data >> 8); index++; payloadlocation[index] = (UINT8)(data & 0xFF); } UINT8 bpmsgGet8bit(UINT8 *payload, UINT8 *payloadIndex) { UINT8 result; result = (UINT8)payload[*payloadIndex]; (*payloadIndex)++; return result; } UINT16 bpmsgGet16bit(UINT8 *payload, UINT8 *payloadIndex) { UINT16 result; result = ((UINT16)payload[*payloadIndex]) << 8; (*payloadIndex)++; result += ((UINT16)payload[*payloadIndex] & 0x00FF); (*payloadIndex)++; return result; } UINT32 bpmsgGet32bit(UINT8 *payload, UINT8 *payloadIndex) { UINT32 result; result = ((UINT32)payload[*payloadIndex]) << 24; (*payloadIndex)++; result += ((UINT32)payload[*payloadIndex]) << 16; (*payloadIndex)++; result += ((UINT32)payload[*payloadIndex]) << 8; (*payloadIndex)++; result += ((UINT32)payload[*payloadIndex] & 0x000000FF); (*payloadIndex)++; return result; }