![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
テストモード追加、LED有効化 left -> SerialRX, Data Recieve Complete , Serial Tx , Light Tx
Dependencies: XBee mbed NetServicesMin
common/data_models.cpp@0:42adca80439c, 2012-03-22 (annotated)
- Committer:
- recotana
- Date:
- Thu Mar 22 12:40:48 2012 +0000
- Revision:
- 0:42adca80439c
- Child:
- 1:36eb173eb52b
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
recotana | 0:42adca80439c | 1 | #include "types.h" |
recotana | 0:42adca80439c | 2 | #include "data_models.h" |
recotana | 0:42adca80439c | 3 | #include "EthernetNetIf.h" |
recotana | 0:42adca80439c | 4 | |
recotana | 0:42adca80439c | 5 | |
recotana | 0:42adca80439c | 6 | void initPayload(Payload *_payload) |
recotana | 0:42adca80439c | 7 | { |
recotana | 0:42adca80439c | 8 | _payload->size=sizeof(Payload); |
recotana | 0:42adca80439c | 9 | _payload->dummy = 0; |
recotana | 0:42adca80439c | 10 | _payload->ftype = Ftype_Type_B; |
recotana | 0:42adca80439c | 11 | |
recotana | 0:42adca80439c | 12 | Frame *frame=&_payload->frame; |
recotana | 0:42adca80439c | 13 | |
recotana | 0:42adca80439c | 14 | for(int i=0 ; i < sizeof(frame->id.personalId) ; i++) frame->id.personalId[i]=0; |
recotana | 0:42adca80439c | 15 | |
recotana | 0:42adca80439c | 16 | frame->message.frameNumber=0xFFFF; |
recotana | 0:42adca80439c | 17 | frame->message.device=SERVER; |
recotana | 0:42adca80439c | 18 | frame->message.command=PING; |
recotana | 0:42adca80439c | 19 | |
recotana | 0:42adca80439c | 20 | for(int i=0 ; i < sizeof(_payload->frame.message.data) ; i++) _payload->frame.message.data[i]=0; |
recotana | 0:42adca80439c | 21 | } |
recotana | 0:42adca80439c | 22 | |
recotana | 0:42adca80439c | 23 | void payloadToNetwork(Payload *_payload) |
recotana | 0:42adca80439c | 24 | { |
recotana | 0:42adca80439c | 25 | Frame *frame=&_payload->frame; |
recotana | 0:42adca80439c | 26 | _payload->size = htons(_payload->size); |
recotana | 0:42adca80439c | 27 | frame->id.head = htons(frame->id.head); |
recotana | 0:42adca80439c | 28 | frame->message.totalSize = htons(frame->message.totalSize); |
recotana | 0:42adca80439c | 29 | frame->message.frameNumber = htons(frame->message.frameNumber); |
recotana | 0:42adca80439c | 30 | |
recotana | 0:42adca80439c | 31 | } |
recotana | 0:42adca80439c | 32 | void networkToPayload(Payload *_payload) |
recotana | 0:42adca80439c | 33 | { |
recotana | 0:42adca80439c | 34 | Frame *frame=&_payload->frame; |
recotana | 0:42adca80439c | 35 | _payload->size = ntohs(_payload->size); |
recotana | 0:42adca80439c | 36 | frame->id.head = ntohs(frame->id.head); |
recotana | 0:42adca80439c | 37 | frame->message.totalSize = ntohs(frame->message.totalSize); |
recotana | 0:42adca80439c | 38 | frame->message.frameNumber = ntohs(frame->message.frameNumber); |
recotana | 0:42adca80439c | 39 | } |
recotana | 0:42adca80439c | 40 | |
recotana | 0:42adca80439c | 41 | void initTestPayloadData(Payload *_payload) |
recotana | 0:42adca80439c | 42 | { |
recotana | 0:42adca80439c | 43 | Frame *frame=&_payload->frame; |
recotana | 0:42adca80439c | 44 | |
recotana | 0:42adca80439c | 45 | initPayload(_payload); |
recotana | 0:42adca80439c | 46 | _payload->size=sizeof(Payload); |
recotana | 0:42adca80439c | 47 | |
recotana | 0:42adca80439c | 48 | frame->id.head=0x0000; |
recotana | 0:42adca80439c | 49 | uint8_t tmpid[14]={0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x40,0x41,0x42,0x43,0x44}; |
recotana | 0:42adca80439c | 50 | for(int i=0;i<sizeof(tmpid);i++) frame->id.personalId[i]=tmpid[i]; |
recotana | 0:42adca80439c | 51 | |
recotana | 0:42adca80439c | 52 | |
recotana | 0:42adca80439c | 53 | frame->message.frameNumber=1; |
recotana | 0:42adca80439c | 54 | frame->message.device=LED_SENDER; |
recotana | 0:42adca80439c | 55 | frame->message.command=SEND_SINGLE; |
recotana | 0:42adca80439c | 56 | |
recotana | 0:42adca80439c | 57 | uint8_t tmpdata[42]={ |
recotana | 0:42adca80439c | 58 | 1,2,3,4,5,6,7,8,9,10, |
recotana | 0:42adca80439c | 59 | 11,12,13,14,15,16,17,18,19,20, |
recotana | 0:42adca80439c | 60 | 21,22,23,24,25,26,27,28,29,30, |
recotana | 0:42adca80439c | 61 | 31,32,33,34,35,36,37,38,39,40, |
recotana | 0:42adca80439c | 62 | 41,42}; |
recotana | 0:42adca80439c | 63 | for(int i=0;i<sizeof(tmpdata);i++) frame->message.data[i]=tmpdata[i]; |
recotana | 0:42adca80439c | 64 | |
recotana | 0:42adca80439c | 65 | frame->message.totalSize= |
recotana | 0:42adca80439c | 66 | sizeof(frame->message.totalSize) |
recotana | 0:42adca80439c | 67 | +sizeof(frame->message.frameNumber) |
recotana | 0:42adca80439c | 68 | +sizeof(frame->message.device) |
recotana | 0:42adca80439c | 69 | +sizeof(frame->message.command) |
recotana | 0:42adca80439c | 70 | +sizeof(frame->message.data); |
recotana | 0:42adca80439c | 71 | |
recotana | 0:42adca80439c | 72 | } |
recotana | 0:42adca80439c | 73 | |
recotana | 0:42adca80439c | 74 | |
recotana | 0:42adca80439c | 75 | void dumpPayload(Payload *_payload) |
recotana | 0:42adca80439c | 76 | { |
recotana | 0:42adca80439c | 77 | Frame *frame=&_payload->frame; |
recotana | 0:42adca80439c | 78 | printf("\r\n======== dump!!\r\n"); |
recotana | 0:42adca80439c | 79 | printf("payload\nsize:%04X\r\n ",_payload->size); |
recotana | 0:42adca80439c | 80 | printf("Type:%0X\r\n ",_payload->ftype); |
recotana | 0:42adca80439c | 81 | |
recotana | 0:42adca80439c | 82 | printf("Payload id_head:%04X\r\n personal id:",_payload->frame.id.head); |
recotana | 0:42adca80439c | 83 | for(int i=0 ; i < sizeof(frame->id.personalId) ; i++){ |
recotana | 0:42adca80439c | 84 | printf("%d:%02X ",i,frame->id.personalId[i]); |
recotana | 0:42adca80439c | 85 | } |
recotana | 0:42adca80439c | 86 | |
recotana | 0:42adca80439c | 87 | printf("\r\n"); |
recotana | 0:42adca80439c | 88 | |
recotana | 0:42adca80439c | 89 | printf("total size:%d , frame number:%d , divece:%0X , command:%02X\r\n" |
recotana | 0:42adca80439c | 90 | ,frame->message.totalSize |
recotana | 0:42adca80439c | 91 | ,frame->message.frameNumber |
recotana | 0:42adca80439c | 92 | ,frame->message.device |
recotana | 0:42adca80439c | 93 | ,frame->message.command); |
recotana | 0:42adca80439c | 94 | |
recotana | 0:42adca80439c | 95 | printf("message data:\r\n"); |
recotana | 0:42adca80439c | 96 | for(int i=0 ; i < sizeof(frame->message.data) ; i++){ |
recotana | 0:42adca80439c | 97 | printf("%d:%02X ",i,_payload->frame.message.data[i]); |
recotana | 0:42adca80439c | 98 | } |
recotana | 0:42adca80439c | 99 | |
recotana | 0:42adca80439c | 100 | printf("\r\n--- RAW DATA -------\r\n"); |
recotana | 0:42adca80439c | 101 | for(int i=0 ; i < sizeof(Payload) ; i++){ |
recotana | 0:42adca80439c | 102 | printf("%d:%02X ",i,((uint8_t*)_payload)[i]); |
recotana | 0:42adca80439c | 103 | } |
recotana | 0:42adca80439c | 104 | printf("\r\n"); |
recotana | 0:42adca80439c | 105 | |
recotana | 0:42adca80439c | 106 | } |