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