Based on myBlueUSB and rosserial_mbed

Dependencies:   mbed myUSBHost AvailableMemory myBlueUSB

Committer:
OTL
Date:
Sat Sep 17 14:21:35 2011 +0000
Revision:
0:7684b95768c7

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
OTL 0:7684b95768c7 1 #ifndef SDP_DATA_H
OTL 0:7684b95768c7 2 #define SDP_DATA_H
OTL 0:7684b95768c7 3
OTL 0:7684b95768c7 4 #include <vector>
OTL 0:7684b95768c7 5
OTL 0:7684b95768c7 6 extern const unsigned char base_uuid[16];// = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0, 0x07, 0x70, 0, 0x10, 0, 0};
OTL 0:7684b95768c7 7
OTL 0:7684b95768c7 8 class sdp_data {
OTL 0:7684b95768c7 9 public:
OTL 0:7684b95768c7 10 enum elements { NULL_, UNSIGNED, SIGNED, UUID, STRING, BOOL, SEQUENCE, ALTERNATIVE, URL};
OTL 0:7684b95768c7 11 private:
OTL 0:7684b95768c7 12 enum elements type;
OTL 0:7684b95768c7 13 char size;
OTL 0:7684b95768c7 14 union {
OTL 0:7684b95768c7 15 unsigned data;
OTL 0:7684b95768c7 16 char *str;
OTL 0:7684b95768c7 17 #ifdef LONGUUID
OTL 0:7684b95768c7 18 unsigned short uuid[8];
OTL 0:7684b95768c7 19 #endif
OTL 0:7684b95768c7 20 };
OTL 0:7684b95768c7 21 vector<sdp_data*> sequence; //not allowed to be in union
OTL 0:7684b95768c7 22 static char ret[12];
OTL 0:7684b95768c7 23 char *longstr;
OTL 0:7684b95768c7 24 public:
OTL 0:7684b95768c7 25 sdp_data(): type(NULL_), size(0), longstr(0) {
OTL 0:7684b95768c7 26 //printf("NULL%d ", size);
OTL 0:7684b95768c7 27 }
OTL 0:7684b95768c7 28 sdp_data(unsigned d, unsigned sz=4): type(UNSIGNED), size(sz), longstr(0) {
OTL 0:7684b95768c7 29 data=d;
OTL 0:7684b95768c7 30 //printf("UINT%d=%u ", size, data);
OTL 0:7684b95768c7 31 }
OTL 0:7684b95768c7 32 sdp_data(unsigned short d, unsigned sz=2): type(UNSIGNED), size(sz), longstr(0) {
OTL 0:7684b95768c7 33 data=d;
OTL 0:7684b95768c7 34 //printf("UINT%d=%u ", size, data);
OTL 0:7684b95768c7 35 }
OTL 0:7684b95768c7 36 sdp_data(signed d, unsigned sz=4): type(SIGNED), size(sz), longstr(0) {
OTL 0:7684b95768c7 37 data=d;
OTL 0:7684b95768c7 38 //printf("INT%d=%d ", size, data);
OTL 0:7684b95768c7 39 }
OTL 0:7684b95768c7 40 sdp_data(bool d, unsigned sz=1): type(BOOL), size(sz), longstr(0) {
OTL 0:7684b95768c7 41 data=d;
OTL 0:7684b95768c7 42 //printf("BOOL%d=%u ", size, data);
OTL 0:7684b95768c7 43 }
OTL 0:7684b95768c7 44 sdp_data(char*s, unsigned sz=0): type(STRING), longstr(0) {
OTL 0:7684b95768c7 45 if (sz) size = sz+1;
OTL 0:7684b95768c7 46 else size = strlen(s)+1;
OTL 0:7684b95768c7 47 str = new char[size];
OTL 0:7684b95768c7 48 strncpy(str, s, size);
OTL 0:7684b95768c7 49 str[size-1] = '\0';
OTL 0:7684b95768c7 50 //printf("STR%d='%s' ", size, str);
OTL 0:7684b95768c7 51 }
OTL 0:7684b95768c7 52 sdp_data(enum elements t, unsigned d, unsigned sz=2): type(t), size(sz), longstr(0) {
OTL 0:7684b95768c7 53 if (t==UUID) {
OTL 0:7684b95768c7 54 #ifdef LONGUUID
OTL 0:7684b95768c7 55 memcpy(uuid, base_uuid, 16);
OTL 0:7684b95768c7 56 uuid[6] = d;
OTL 0:7684b95768c7 57 uuid[7] = d>>16;
OTL 0:7684b95768c7 58 // printf("UUID%d=%04X%04X ", size, uuid[7], uuid[6]);
OTL 0:7684b95768c7 59 #else
OTL 0:7684b95768c7 60 data = d;
OTL 0:7684b95768c7 61 #endif
OTL 0:7684b95768c7 62 } else printf("Please use other constructor for type %d\n", t);
OTL 0:7684b95768c7 63 }
OTL 0:7684b95768c7 64 sdp_data(enum elements t, char *d=0, unsigned sz=0): type(t), size(sz), longstr(0) {
OTL 0:7684b95768c7 65 switch (t) {
OTL 0:7684b95768c7 66 #ifdef LONGUUID
OTL 0:7684b95768c7 67 case UUID:
OTL 0:7684b95768c7 68 memcpy(uuid, d, size);
OTL 0:7684b95768c7 69 // printf("UUID%d=%08X ", size, uuid[6]);
OTL 0:7684b95768c7 70 break;
OTL 0:7684b95768c7 71 #endif
OTL 0:7684b95768c7 72 case URL:
OTL 0:7684b95768c7 73 //size = strlen(d)+1;
OTL 0:7684b95768c7 74 str = new char[size+1];
OTL 0:7684b95768c7 75 strcpy(str, d);
OTL 0:7684b95768c7 76 // printf("URL%d='%u' ", size, str);
OTL 0:7684b95768c7 77 break;
OTL 0:7684b95768c7 78 case SEQUENCE:
OTL 0:7684b95768c7 79 case ALTERNATIVE:
OTL 0:7684b95768c7 80 break;
OTL 0:7684b95768c7 81 default:
OTL 0:7684b95768c7 82 printf("Please use other constructor for type %d\n", t);
OTL 0:7684b95768c7 83 }
OTL 0:7684b95768c7 84 }
OTL 0:7684b95768c7 85 ~sdp_data() {
OTL 0:7684b95768c7 86 switch (type) {
OTL 0:7684b95768c7 87 case STRING:
OTL 0:7684b95768c7 88 case URL:
OTL 0:7684b95768c7 89 delete[] str;
OTL 0:7684b95768c7 90 break;
OTL 0:7684b95768c7 91 case SEQUENCE:
OTL 0:7684b95768c7 92 case ALTERNATIVE:
OTL 0:7684b95768c7 93 for (int i = 0; i < sequence.size(); i++)
OTL 0:7684b95768c7 94 delete sequence.at(i);
OTL 0:7684b95768c7 95 break;
OTL 0:7684b95768c7 96 }
OTL 0:7684b95768c7 97 if (longstr)
OTL 0:7684b95768c7 98 delete[] longstr;
OTL 0:7684b95768c7 99 }
OTL 0:7684b95768c7 100 void add_element(sdp_data *el) {
OTL 0:7684b95768c7 101 sequence.push_back(el);
OTL 0:7684b95768c7 102 size += el->Size();
OTL 0:7684b95768c7 103 }
OTL 0:7684b95768c7 104 unsigned asUnsigned() ;
OTL 0:7684b95768c7 105 const char* asString(bool alt=false) ;
OTL 0:7684b95768c7 106 unsigned Size() ;
OTL 0:7684b95768c7 107 unsigned items() { return sequence.size();}
OTL 0:7684b95768c7 108 sdp_data* item(int i) { return sequence[i];}
OTL 0:7684b95768c7 109 void remove(int i) { sequence[i] = 0;}
OTL 0:7684b95768c7 110 unsigned sizedesc(unsigned char *buf) ;
OTL 0:7684b95768c7 111 void revcpy(unsigned char*d, const unsigned char*s, int n) ;
OTL 0:7684b95768c7 112 unsigned build(unsigned char *buf, unsigned max) ;
OTL 0:7684b95768c7 113 bool findUUID(unsigned uuid);
OTL 0:7684b95768c7 114 };
OTL 0:7684b95768c7 115
OTL 0:7684b95768c7 116 #endif