テストモード追加、LED有効化 left -> SerialRX, Data Recieve Complete , Serial Tx , Light Tx
Dependencies: XBee mbed NetServicesMin
common/data_models.cpp@2:dec6319cf02c, 2012-04-18 (annotated)
- Committer:
- recotana
- Date:
- Wed Apr 18 07:52:46 2012 +0000
- Revision:
- 2:dec6319cf02c
- Parent:
- 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 | 1:36eb173eb52b | 5 | extern Serial pc; |
recotana | 1:36eb173eb52b | 6 | |
recotana | 0:42adca80439c | 7 | |
recotana | 0:42adca80439c | 8 | void initPayload(Payload *_payload) |
recotana | 0:42adca80439c | 9 | { |
recotana | 0:42adca80439c | 10 | _payload->size=sizeof(Payload); |
recotana | 0:42adca80439c | 11 | _payload->dummy = 0; |
recotana | 0:42adca80439c | 12 | _payload->ftype = Ftype_Type_B; |
recotana | 0:42adca80439c | 13 | |
recotana | 0:42adca80439c | 14 | Frame *frame=&_payload->frame; |
recotana | 0:42adca80439c | 15 | |
recotana | 0:42adca80439c | 16 | for(int i=0 ; i < sizeof(frame->id.personalId) ; i++) frame->id.personalId[i]=0; |
recotana | 0:42adca80439c | 17 | |
recotana | 0:42adca80439c | 18 | frame->message.frameNumber=0xFFFF; |
recotana | 0:42adca80439c | 19 | frame->message.device=SERVER; |
recotana | 0:42adca80439c | 20 | frame->message.command=PING; |
recotana | 0:42adca80439c | 21 | |
recotana | 0:42adca80439c | 22 | for(int i=0 ; i < sizeof(_payload->frame.message.data) ; i++) _payload->frame.message.data[i]=0; |
recotana | 0:42adca80439c | 23 | } |
recotana | 0:42adca80439c | 24 | |
recotana | 0:42adca80439c | 25 | void payloadToNetwork(Payload *_payload) |
recotana | 0:42adca80439c | 26 | { |
recotana | 0:42adca80439c | 27 | Frame *frame=&_payload->frame; |
recotana | 1:36eb173eb52b | 28 | _payload->size = htons(_payload->size); |
recotana | 1:36eb173eb52b | 29 | // frame->id.head = htons(frame->id.head); |
recotana | 0:42adca80439c | 30 | frame->message.totalSize = htons(frame->message.totalSize); |
recotana | 0:42adca80439c | 31 | frame->message.frameNumber = htons(frame->message.frameNumber); |
recotana | 1:36eb173eb52b | 32 | frame->message.sum = htons(frame->message.sum); |
recotana | 0:42adca80439c | 33 | |
recotana | 1:36eb173eb52b | 34 | if(frame->message.command == PING) { |
recotana | 1:36eb173eb52b | 35 | |
recotana | 1:36eb173eb52b | 36 | if(frame->message.device == SERVER) |
recotana | 1:36eb173eb52b | 37 | { |
recotana | 1:36eb173eb52b | 38 | |
recotana | 1:36eb173eb52b | 39 | PrefServer *data; |
recotana | 1:36eb173eb52b | 40 | data = (PrefServer*)frame->message.data; |
recotana | 1:36eb173eb52b | 41 | data->serverPort = htons(data->serverPort); |
recotana | 1:36eb173eb52b | 42 | data->destinationPort = htons(data->destinationPort); |
recotana | 1:36eb173eb52b | 43 | data->xbeeAdress = htonl(data->xbeeAdress); |
recotana | 1:36eb173eb52b | 44 | |
recotana | 1:36eb173eb52b | 45 | } |
recotana | 1:36eb173eb52b | 46 | else if(frame->message.device == LED_SENDER) |
recotana | 1:36eb173eb52b | 47 | { |
recotana | 1:36eb173eb52b | 48 | PrefSender *data; |
recotana | 1:36eb173eb52b | 49 | data = (PrefSender*)frame->message.data; |
recotana | 1:36eb173eb52b | 50 | data->xbeeAdress = htonl(data->xbeeAdress); |
recotana | 1:36eb173eb52b | 51 | data->currentFrameNumber = htons(data->currentFrameNumber); |
recotana | 1:36eb173eb52b | 52 | } |
recotana | 1:36eb173eb52b | 53 | else if(frame->message.device == LED_RECIEVER) |
recotana | 1:36eb173eb52b | 54 | { |
recotana | 1:36eb173eb52b | 55 | PrefReciever *data; |
recotana | 1:36eb173eb52b | 56 | data = (PrefReciever*)frame->message.data; |
recotana | 1:36eb173eb52b | 57 | data->xbeeAdress = htonl(data->xbeeAdress); |
recotana | 1:36eb173eb52b | 58 | } |
recotana | 1:36eb173eb52b | 59 | } |
recotana | 1:36eb173eb52b | 60 | |
recotana | 0:42adca80439c | 61 | } |
recotana | 0:42adca80439c | 62 | void networkToPayload(Payload *_payload) |
recotana | 0:42adca80439c | 63 | { |
recotana | 0:42adca80439c | 64 | Frame *frame=&_payload->frame; |
recotana | 1:36eb173eb52b | 65 | _payload->size = ntohs(_payload->size); |
recotana | 1:36eb173eb52b | 66 | // frame->id.head = ntohs(frame->id.head); |
recotana | 0:42adca80439c | 67 | frame->message.totalSize = ntohs(frame->message.totalSize); |
recotana | 0:42adca80439c | 68 | frame->message.frameNumber = ntohs(frame->message.frameNumber); |
recotana | 1:36eb173eb52b | 69 | frame->message.sum = ntohs(frame->message.sum); |
recotana | 1:36eb173eb52b | 70 | |
recotana | 1:36eb173eb52b | 71 | if(frame->message.command == PING){ |
recotana | 1:36eb173eb52b | 72 | |
recotana | 1:36eb173eb52b | 73 | if(frame->message.device == SERVER) |
recotana | 1:36eb173eb52b | 74 | { |
recotana | 1:36eb173eb52b | 75 | PrefServer *data; |
recotana | 1:36eb173eb52b | 76 | data = (PrefServer*)frame->message.data; |
recotana | 1:36eb173eb52b | 77 | data->serverPort = ntohs(data->serverPort); |
recotana | 1:36eb173eb52b | 78 | data->destinationPort = ntohs(data->destinationPort); |
recotana | 1:36eb173eb52b | 79 | data->xbeeAdress = ntohl(data->xbeeAdress); |
recotana | 1:36eb173eb52b | 80 | } |
recotana | 1:36eb173eb52b | 81 | else if(frame->message.device == LED_SENDER) |
recotana | 1:36eb173eb52b | 82 | { |
recotana | 1:36eb173eb52b | 83 | PrefSender *data; |
recotana | 1:36eb173eb52b | 84 | data = (PrefSender*)frame->message.data; |
recotana | 1:36eb173eb52b | 85 | data->xbeeAdress = ntohl(data->xbeeAdress); |
recotana | 1:36eb173eb52b | 86 | data->currentFrameNumber = ntohs(data->currentFrameNumber); |
recotana | 1:36eb173eb52b | 87 | } |
recotana | 1:36eb173eb52b | 88 | else if(frame->message.device == LED_RECIEVER) |
recotana | 1:36eb173eb52b | 89 | { |
recotana | 1:36eb173eb52b | 90 | PrefReciever *data; |
recotana | 1:36eb173eb52b | 91 | data = (PrefReciever*)frame->message.data; |
recotana | 1:36eb173eb52b | 92 | data->xbeeAdress = ntohl(data->xbeeAdress); |
recotana | 1:36eb173eb52b | 93 | } |
recotana | 1:36eb173eb52b | 94 | } |
recotana | 0:42adca80439c | 95 | } |
recotana | 0:42adca80439c | 96 | |
recotana | 1:36eb173eb52b | 97 | |
recotana | 1:36eb173eb52b | 98 | |
recotana | 0:42adca80439c | 99 | void initTestPayloadData(Payload *_payload) |
recotana | 0:42adca80439c | 100 | { |
recotana | 0:42adca80439c | 101 | Frame *frame=&_payload->frame; |
recotana | 0:42adca80439c | 102 | |
recotana | 0:42adca80439c | 103 | initPayload(_payload); |
recotana | 0:42adca80439c | 104 | _payload->size=sizeof(Payload); |
recotana | 0:42adca80439c | 105 | |
recotana | 1:36eb173eb52b | 106 | // frame->id.head=0x0000; |
recotana | 1:36eb173eb52b | 107 | // uint8_t tmpid[14]={0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x40,0x41,0x42,0x43,0x44}; |
recotana | 1:36eb173eb52b | 108 | uint8_t tmpid[16]={0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x40,0x41,0x42,0x43,0x44,0x45,0x46}; |
recotana | 0:42adca80439c | 109 | for(int i=0;i<sizeof(tmpid);i++) frame->id.personalId[i]=tmpid[i]; |
recotana | 0:42adca80439c | 110 | |
recotana | 0:42adca80439c | 111 | |
recotana | 0:42adca80439c | 112 | frame->message.frameNumber=1; |
recotana | 0:42adca80439c | 113 | frame->message.device=LED_SENDER; |
recotana | 0:42adca80439c | 114 | frame->message.command=SEND_SINGLE; |
recotana | 0:42adca80439c | 115 | |
recotana | 1:36eb173eb52b | 116 | uint8_t tmpdata[40]={ |
recotana | 0:42adca80439c | 117 | 1,2,3,4,5,6,7,8,9,10, |
recotana | 0:42adca80439c | 118 | 11,12,13,14,15,16,17,18,19,20, |
recotana | 0:42adca80439c | 119 | 21,22,23,24,25,26,27,28,29,30, |
recotana | 1:36eb173eb52b | 120 | 31,32,33,34,35,36,37,38,39,40}; |
recotana | 0:42adca80439c | 121 | for(int i=0;i<sizeof(tmpdata);i++) frame->message.data[i]=tmpdata[i]; |
recotana | 0:42adca80439c | 122 | |
recotana | 0:42adca80439c | 123 | frame->message.totalSize= |
recotana | 0:42adca80439c | 124 | sizeof(frame->message.totalSize) |
recotana | 0:42adca80439c | 125 | +sizeof(frame->message.frameNumber) |
recotana | 0:42adca80439c | 126 | +sizeof(frame->message.device) |
recotana | 0:42adca80439c | 127 | +sizeof(frame->message.command) |
recotana | 0:42adca80439c | 128 | +sizeof(frame->message.data); |
recotana | 1:36eb173eb52b | 129 | |
recotana | 1:36eb173eb52b | 130 | uint16_t sum = culcSum(_payload); |
recotana | 1:36eb173eb52b | 131 | |
recotana | 1:36eb173eb52b | 132 | frame->message.sum = sum; |
recotana | 0:42adca80439c | 133 | |
recotana | 0:42adca80439c | 134 | } |
recotana | 0:42adca80439c | 135 | |
recotana | 1:36eb173eb52b | 136 | uint16_t culcSum(Payload *_payload){ |
recotana | 1:36eb173eb52b | 137 | |
recotana | 1:36eb173eb52b | 138 | uint16_t tmpSum = _payload->ftype; |
recotana | 1:36eb173eb52b | 139 | uint8_t *data = (uint8_t *)&_payload->frame; |
recotana | 1:36eb173eb52b | 140 | |
recotana | 1:36eb173eb52b | 141 | for(uint8_t i=0 ; i<sizeof(Frame)-2 ; i++){ |
recotana | 1:36eb173eb52b | 142 | tmpSum += data[i]; |
recotana | 1:36eb173eb52b | 143 | } |
recotana | 1:36eb173eb52b | 144 | return tmpSum; |
recotana | 1:36eb173eb52b | 145 | } |
recotana | 0:42adca80439c | 146 | |
recotana | 0:42adca80439c | 147 | void dumpPayload(Payload *_payload) |
recotana | 0:42adca80439c | 148 | { |
recotana | 0:42adca80439c | 149 | Frame *frame=&_payload->frame; |
recotana | 1:36eb173eb52b | 150 | pc.printf("\r\n======== dump!!\r\n"); |
recotana | 1:36eb173eb52b | 151 | pc.printf("payload\nsize:%04X\r\n ",_payload->size); |
recotana | 1:36eb173eb52b | 152 | pc.printf("Type:%0X\r\n ",_payload->ftype); |
recotana | 0:42adca80439c | 153 | |
recotana | 1:36eb173eb52b | 154 | // pc.printf("Payload id_head:%04X\r\n personal id:",_payload->frame.id.head); |
recotana | 1:36eb173eb52b | 155 | pc.printf("personal id:"); |
recotana | 0:42adca80439c | 156 | for(int i=0 ; i < sizeof(frame->id.personalId) ; i++){ |
recotana | 1:36eb173eb52b | 157 | pc.printf("%02X:%c ",frame->id.personalId[i],frame->id.personalId[i]); |
recotana | 0:42adca80439c | 158 | } |
recotana | 0:42adca80439c | 159 | |
recotana | 1:36eb173eb52b | 160 | pc.printf("\r\n"); |
recotana | 0:42adca80439c | 161 | |
recotana | 1:36eb173eb52b | 162 | pc.printf("total size:%d , frame number:%d , divece:%0X , command:%02X , sum:%04X\r\n" |
recotana | 0:42adca80439c | 163 | ,frame->message.totalSize |
recotana | 0:42adca80439c | 164 | ,frame->message.frameNumber |
recotana | 0:42adca80439c | 165 | ,frame->message.device |
recotana | 1:36eb173eb52b | 166 | ,frame->message.command |
recotana | 1:36eb173eb52b | 167 | ,frame->message.sum); |
recotana | 0:42adca80439c | 168 | |
recotana | 1:36eb173eb52b | 169 | pc.printf("message data:\r\n"); |
recotana | 0:42adca80439c | 170 | for(int i=0 ; i < sizeof(frame->message.data) ; i++){ |
recotana | 1:36eb173eb52b | 171 | pc.printf("%d:%02X ",i,_payload->frame.message.data[i]); |
recotana | 0:42adca80439c | 172 | } |
recotana | 0:42adca80439c | 173 | |
recotana | 1:36eb173eb52b | 174 | pc.printf("\r\n--- RAW DATA -------\r\n"); |
recotana | 0:42adca80439c | 175 | for(int i=0 ; i < sizeof(Payload) ; i++){ |
recotana | 1:36eb173eb52b | 176 | pc.printf("%d:%02X ",i,((uint8_t*)_payload)[i]); |
recotana | 0:42adca80439c | 177 | } |
recotana | 1:36eb173eb52b | 178 | pc.printf("\r\n"); |
recotana | 0:42adca80439c | 179 | |
recotana | 1:36eb173eb52b | 180 | } |
recotana | 1:36eb173eb52b | 181 | |
recotana | 1:36eb173eb52b | 182 | void dumpPrefSender(PrefSender *prf) |
recotana | 1:36eb173eb52b | 183 | { |
recotana | 1:36eb173eb52b | 184 | pc.printf("current frame number:%d\n",prf->currentFrameNumber); |
recotana | 1:36eb173eb52b | 185 | pc.printf("gainData gain:%d\n",prf->gainData.gain); |
recotana | 1:36eb173eb52b | 186 | pc.printf("gainData middleLevel:%d\n",prf->gainData.middleLevel); |
recotana | 1:36eb173eb52b | 187 | pc.printf("lightsw:%d\n",prf->lightsw); |
recotana | 1:36eb173eb52b | 188 | pc.printf("continueusMode:%d\n",prf->continueusMode); |
recotana | 1:36eb173eb52b | 189 | pc.printf("isSend:%d\n",prf->isSend); |
recotana | 1:36eb173eb52b | 190 | pc.printf("xbeeAdress:%X\n",prf->xbeeAdress); |
recotana | 1:36eb173eb52b | 191 | |
recotana | 1:36eb173eb52b | 192 | } |
recotana | 1:36eb173eb52b | 193 | void dumpPrefReciever(PrefReciever *prf) |
recotana | 1:36eb173eb52b | 194 | { |
recotana | 1:36eb173eb52b | 195 | |
recotana | 1:36eb173eb52b | 196 | pc.printf("xbeeAdress:%X\n",prf->xbeeAdress); |
recotana | 1:36eb173eb52b | 197 | |
recotana | 1:36eb173eb52b | 198 | } |
recotana | 1:36eb173eb52b | 199 | void dumpPrefServer(PrefServer *prf) |
recotana | 1:36eb173eb52b | 200 | { |
recotana | 1:36eb173eb52b | 201 | pc.printf("xbeeAdress:%X\n",prf->xbeeAdress); |
recotana | 1:36eb173eb52b | 202 | pc.printf("server ip:%d.%d.%d.%d\n",prf->serverAddress[0],prf->serverAddress[1],prf->serverAddress[2],prf->serverAddress[3]); |
recotana | 1:36eb173eb52b | 203 | pc.printf("subnet ip:%d.%d.%d.%d\n",prf->subnetMask[0],prf->subnetMask[1],prf->subnetMask[2],prf->subnetMask[3]); |
recotana | 1:36eb173eb52b | 204 | pc.printf("router ip:%d.%d.%d.%d\n",prf->routerAddress[0],prf->routerAddress[1],prf->routerAddress[2],prf->routerAddress[3]); |
recotana | 1:36eb173eb52b | 205 | |
recotana | 1:36eb173eb52b | 206 | pc.printf("Server Port:%d\n",prf->serverPort); |
recotana | 1:36eb173eb52b | 207 | |
recotana | 1:36eb173eb52b | 208 | pc.printf("Destination ip:%d.%d.%d.%d\n",prf->destinationAddress[0],prf->destinationAddress[1],prf->destinationAddress[2],prf->destinationAddress[3]); |
recotana | 1:36eb173eb52b | 209 | pc.printf("Destination Port:%d\n",prf->destinationPort); |
recotana | 1:36eb173eb52b | 210 | |
recotana | 0:42adca80439c | 211 | } |