Added support for obtaining BLE device name by parsing advertising data.
Fork of BLE_BlueNRG by
Payload.cpp@7:e293b0f43dc7, 2014-07-31 (annotated)
- Committer:
- hemddabral
- Date:
- Thu Jul 31 11:09:28 2014 +0000
- Revision:
- 7:e293b0f43dc7
Added support for parsing BLE device name from advertising data
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hemddabral | 7:e293b0f43dc7 | 1 | #include <Payload.h> |
hemddabral | 7:e293b0f43dc7 | 2 | |
hemddabral | 7:e293b0f43dc7 | 3 | Payload::Payload() { |
hemddabral | 7:e293b0f43dc7 | 4 | stringLength = 0; |
hemddabral | 7:e293b0f43dc7 | 5 | payloadUnitCount = 0; |
hemddabral | 7:e293b0f43dc7 | 6 | payload = NULL; |
hemddabral | 7:e293b0f43dc7 | 7 | } |
hemddabral | 7:e293b0f43dc7 | 8 | |
hemddabral | 7:e293b0f43dc7 | 9 | Payload::Payload(const uint8_t *tokenString, uint8_t string_ength) { |
hemddabral | 7:e293b0f43dc7 | 10 | // initialize private data members |
hemddabral | 7:e293b0f43dc7 | 11 | stringLength = string_ength; |
hemddabral | 7:e293b0f43dc7 | 12 | payloadUnitCount = 0; |
hemddabral | 7:e293b0f43dc7 | 13 | payload = NULL; |
hemddabral | 7:e293b0f43dc7 | 14 | |
hemddabral | 7:e293b0f43dc7 | 15 | int index = 0; |
hemddabral | 7:e293b0f43dc7 | 16 | while( index!=stringLength) { |
hemddabral | 7:e293b0f43dc7 | 17 | int len=tokenString[index]; |
hemddabral | 7:e293b0f43dc7 | 18 | index=index+1+len; |
hemddabral | 7:e293b0f43dc7 | 19 | payloadUnitCount++; |
hemddabral | 7:e293b0f43dc7 | 20 | } |
hemddabral | 7:e293b0f43dc7 | 21 | |
hemddabral | 7:e293b0f43dc7 | 22 | UnitPayload *obj = new UnitPayload[payloadUnitCount]; |
hemddabral | 7:e293b0f43dc7 | 23 | int i=0; |
hemddabral | 7:e293b0f43dc7 | 24 | int c=0; |
hemddabral | 7:e293b0f43dc7 | 25 | int j,k; |
hemddabral | 7:e293b0f43dc7 | 26 | |
hemddabral | 7:e293b0f43dc7 | 27 | while(i<payloadUnitCount) |
hemddabral | 7:e293b0f43dc7 | 28 | { |
hemddabral | 7:e293b0f43dc7 | 29 | obj[i].length=tokenString[c]; |
hemddabral | 7:e293b0f43dc7 | 30 | obj[i].id=tokenString[c+1]; |
hemddabral | 7:e293b0f43dc7 | 31 | |
hemddabral | 7:e293b0f43dc7 | 32 | obj[i].data = new uint8_t[obj[i].length]; |
hemddabral | 7:e293b0f43dc7 | 33 | for(j=c+2,k=0;(j<(c+obj[i].length+1))&&(k<obj[i].length-1);j++,k++) |
hemddabral | 7:e293b0f43dc7 | 34 | { |
hemddabral | 7:e293b0f43dc7 | 35 | obj[i].data[k]=tokenString[j]; |
hemddabral | 7:e293b0f43dc7 | 36 | |
hemddabral | 7:e293b0f43dc7 | 37 | } |
hemddabral | 7:e293b0f43dc7 | 38 | |
hemddabral | 7:e293b0f43dc7 | 39 | c=c+obj[i].length+1; |
hemddabral | 7:e293b0f43dc7 | 40 | i++; |
hemddabral | 7:e293b0f43dc7 | 41 | |
hemddabral | 7:e293b0f43dc7 | 42 | } |
hemddabral | 7:e293b0f43dc7 | 43 | payload = obj; |
hemddabral | 7:e293b0f43dc7 | 44 | } |
hemddabral | 7:e293b0f43dc7 | 45 | |
hemddabral | 7:e293b0f43dc7 | 46 | uint8_t Payload::getPayloadUnitCount() { |
hemddabral | 7:e293b0f43dc7 | 47 | return payloadUnitCount; |
hemddabral | 7:e293b0f43dc7 | 48 | } |
hemddabral | 7:e293b0f43dc7 | 49 | |
hemddabral | 7:e293b0f43dc7 | 50 | uint8_t Payload::getIDAtIndex(int index) { |
hemddabral | 7:e293b0f43dc7 | 51 | return payload[index].get_id(); |
hemddabral | 7:e293b0f43dc7 | 52 | } |
hemddabral | 7:e293b0f43dc7 | 53 | |
hemddabral | 7:e293b0f43dc7 | 54 | uint8_t Payload::getLengthAtIndex(int index) { |
hemddabral | 7:e293b0f43dc7 | 55 | return payload[index].get_length(); |
hemddabral | 7:e293b0f43dc7 | 56 | } |
hemddabral | 7:e293b0f43dc7 | 57 | |
hemddabral | 7:e293b0f43dc7 | 58 | uint8_t* Payload::getDataAtIndex(int index) { |
hemddabral | 7:e293b0f43dc7 | 59 | return payload[index].get_data(); |
hemddabral | 7:e293b0f43dc7 | 60 | } |