![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
テストモード追加、LED有効化 left -> SerialRX, Data Recieve Complete , Serial Tx , Light Tx
Dependencies: XBee mbed NetServicesMin
Diff: common/data_models.cpp
- Revision:
- 0:42adca80439c
- Child:
- 1:36eb173eb52b
diff -r 000000000000 -r 42adca80439c common/data_models.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/data_models.cpp Thu Mar 22 12:40:48 2012 +0000 @@ -0,0 +1,106 @@ +#include "types.h" +#include "data_models.h" +#include "EthernetNetIf.h" + + +void initPayload(Payload *_payload) +{ + _payload->size=sizeof(Payload); + _payload->dummy = 0; + _payload->ftype = Ftype_Type_B; + + Frame *frame=&_payload->frame; + + for(int i=0 ; i < sizeof(frame->id.personalId) ; i++) frame->id.personalId[i]=0; + + frame->message.frameNumber=0xFFFF; + frame->message.device=SERVER; + frame->message.command=PING; + + for(int i=0 ; i < sizeof(_payload->frame.message.data) ; i++) _payload->frame.message.data[i]=0; +} + +void payloadToNetwork(Payload *_payload) +{ + Frame *frame=&_payload->frame; + _payload->size = htons(_payload->size); + frame->id.head = htons(frame->id.head); + frame->message.totalSize = htons(frame->message.totalSize); + frame->message.frameNumber = htons(frame->message.frameNumber); + +} +void networkToPayload(Payload *_payload) +{ + Frame *frame=&_payload->frame; + _payload->size = ntohs(_payload->size); + frame->id.head = ntohs(frame->id.head); + frame->message.totalSize = ntohs(frame->message.totalSize); + frame->message.frameNumber = ntohs(frame->message.frameNumber); +} + +void initTestPayloadData(Payload *_payload) +{ + Frame *frame=&_payload->frame; + + initPayload(_payload); + _payload->size=sizeof(Payload); + + frame->id.head=0x0000; + uint8_t tmpid[14]={0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x40,0x41,0x42,0x43,0x44}; + for(int i=0;i<sizeof(tmpid);i++) frame->id.personalId[i]=tmpid[i]; + + + frame->message.frameNumber=1; + frame->message.device=LED_SENDER; + frame->message.command=SEND_SINGLE; + + uint8_t tmpdata[42]={ + 1,2,3,4,5,6,7,8,9,10, + 11,12,13,14,15,16,17,18,19,20, + 21,22,23,24,25,26,27,28,29,30, + 31,32,33,34,35,36,37,38,39,40, + 41,42}; + for(int i=0;i<sizeof(tmpdata);i++) frame->message.data[i]=tmpdata[i]; + + frame->message.totalSize= + sizeof(frame->message.totalSize) + +sizeof(frame->message.frameNumber) + +sizeof(frame->message.device) + +sizeof(frame->message.command) + +sizeof(frame->message.data); + +} + + +void dumpPayload(Payload *_payload) +{ + Frame *frame=&_payload->frame; + printf("\r\n======== dump!!\r\n"); + printf("payload\nsize:%04X\r\n ",_payload->size); + printf("Type:%0X\r\n ",_payload->ftype); + + printf("Payload id_head:%04X\r\n personal id:",_payload->frame.id.head); + for(int i=0 ; i < sizeof(frame->id.personalId) ; i++){ + printf("%d:%02X ",i,frame->id.personalId[i]); + } + + printf("\r\n"); + + printf("total size:%d , frame number:%d , divece:%0X , command:%02X\r\n" + ,frame->message.totalSize + ,frame->message.frameNumber + ,frame->message.device + ,frame->message.command); + + printf("message data:\r\n"); + for(int i=0 ; i < sizeof(frame->message.data) ; i++){ + printf("%d:%02X ",i,_payload->frame.message.data[i]); + } + + printf("\r\n--- RAW DATA -------\r\n"); + for(int i=0 ; i < sizeof(Payload) ; i++){ + printf("%d:%02X ",i,((uint8_t*)_payload)[i]); + } + printf("\r\n"); + +} \ No newline at end of file