server/client

Dependencies:   mbed NetServicesMin

Committer:
recotana
Date:
Thu Feb 23 02:38:05 2012 +0000
Revision:
1:6e61ee662fd3
added standalone test mode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
recotana 1:6e61ee662fd3 1 #include "types.h"
recotana 1:6e61ee662fd3 2 #include "data_models.h"
recotana 1:6e61ee662fd3 3 #include "EthernetNetIf.h"
recotana 1:6e61ee662fd3 4
recotana 1:6e61ee662fd3 5
recotana 1:6e61ee662fd3 6 void initPayload(Payload *_payload)
recotana 1:6e61ee662fd3 7 {
recotana 1:6e61ee662fd3 8 _payload->size=sizeof(Payload);
recotana 1:6e61ee662fd3 9 for(int i=0 ; i < sizeof(_payload->id.personalId) ; i++) _payload->id.personalId[i]=0;
recotana 1:6e61ee662fd3 10
recotana 1:6e61ee662fd3 11 _payload->message.frameNumber=0;
recotana 1:6e61ee662fd3 12 _payload->message.device=SERVER;
recotana 1:6e61ee662fd3 13 _payload->message.command=SEND;
recotana 1:6e61ee662fd3 14
recotana 1:6e61ee662fd3 15 for(int i=0 ; i < sizeof(_payload->message.data) ; i++) _payload->message.data[i]=0;
recotana 1:6e61ee662fd3 16 }
recotana 1:6e61ee662fd3 17
recotana 1:6e61ee662fd3 18 void payloadToNetwork(Payload *_payload)
recotana 1:6e61ee662fd3 19 {
recotana 1:6e61ee662fd3 20
recotana 1:6e61ee662fd3 21 _payload->size = htons(_payload->size);
recotana 1:6e61ee662fd3 22 _payload->id.head = htons(_payload->id.head);
recotana 1:6e61ee662fd3 23 _payload->message.totalSize = htons(_payload->message.totalSize);
recotana 1:6e61ee662fd3 24 _payload->message.frameNumber = htons(_payload->message.frameNumber);
recotana 1:6e61ee662fd3 25
recotana 1:6e61ee662fd3 26 }
recotana 1:6e61ee662fd3 27 void networkToPayload(Payload *_payload)
recotana 1:6e61ee662fd3 28 {
recotana 1:6e61ee662fd3 29 _payload->size = ntohs(_payload->size);
recotana 1:6e61ee662fd3 30 _payload->id.head = ntohs(_payload->id.head);
recotana 1:6e61ee662fd3 31 _payload->message.totalSize = ntohs(_payload->message.totalSize);
recotana 1:6e61ee662fd3 32 _payload->message.frameNumber = ntohs(_payload->message.frameNumber);
recotana 1:6e61ee662fd3 33 }
recotana 1:6e61ee662fd3 34
recotana 1:6e61ee662fd3 35 void dumpPayload(Payload *_payload)
recotana 1:6e61ee662fd3 36 {
recotana 1:6e61ee662fd3 37 printf("\r\n======== dump!!\r\n");
recotana 1:6e61ee662fd3 38 printf("payload\nsize:%04X\r\n ",_payload->size);
recotana 1:6e61ee662fd3 39
recotana 1:6e61ee662fd3 40 printf("Payload id_head:%04X\r\n personal id:",_payload->id.head);
recotana 1:6e61ee662fd3 41 for(int i=0 ; i < sizeof(_payload->id.personalId) ; i++){
recotana 1:6e61ee662fd3 42 printf("%d:%02X ",i,_payload->id.personalId[i]);
recotana 1:6e61ee662fd3 43 }
recotana 1:6e61ee662fd3 44
recotana 1:6e61ee662fd3 45 printf("\r\n");
recotana 1:6e61ee662fd3 46
recotana 1:6e61ee662fd3 47 printf("total size:%d , frame number:%d , divece:%0X , command:%02X\r\n"
recotana 1:6e61ee662fd3 48 ,_payload->message.totalSize
recotana 1:6e61ee662fd3 49 ,_payload->message.frameNumber
recotana 1:6e61ee662fd3 50 ,_payload->message.device
recotana 1:6e61ee662fd3 51 ,_payload->message.command);
recotana 1:6e61ee662fd3 52
recotana 1:6e61ee662fd3 53 printf("message data:\r\n");
recotana 1:6e61ee662fd3 54 for(int i=0 ; i < sizeof(_payload->message.data) ; i++){
recotana 1:6e61ee662fd3 55 printf("%d:%02X ",i,_payload->message.data[i]);
recotana 1:6e61ee662fd3 56 }
recotana 1:6e61ee662fd3 57
recotana 1:6e61ee662fd3 58 printf("\r\n--- RAW DATA -------\r\n");
recotana 1:6e61ee662fd3 59 for(int i=0 ; i < sizeof(Payload) ; i++){
recotana 1:6e61ee662fd3 60 printf("%d:%02X ",i,((uint8_t*)_payload)[i]);
recotana 1:6e61ee662fd3 61 }
recotana 1:6e61ee662fd3 62 printf("\r\n");
recotana 1:6e61ee662fd3 63
recotana 1:6e61ee662fd3 64 }