Added support for obtaining BLE device name by parsing advertising data.
Fork of BLE_BlueNRG by
Payload.h@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 "mbed.h" |
hemddabral | 7:e293b0f43dc7 | 2 | |
hemddabral | 7:e293b0f43dc7 | 3 | #ifndef __PAYLOAD_H__ |
hemddabral | 7:e293b0f43dc7 | 4 | #define __PAYLOAD_H__ |
hemddabral | 7:e293b0f43dc7 | 5 | |
hemddabral | 7:e293b0f43dc7 | 6 | class UnitPayload |
hemddabral | 7:e293b0f43dc7 | 7 | { |
hemddabral | 7:e293b0f43dc7 | 8 | public: |
hemddabral | 7:e293b0f43dc7 | 9 | uint8_t length; |
hemddabral | 7:e293b0f43dc7 | 10 | uint8_t id; |
hemddabral | 7:e293b0f43dc7 | 11 | uint8_t *data; |
hemddabral | 7:e293b0f43dc7 | 12 | |
hemddabral | 7:e293b0f43dc7 | 13 | void set_length(uint8_t l) { |
hemddabral | 7:e293b0f43dc7 | 14 | length=l; |
hemddabral | 7:e293b0f43dc7 | 15 | } |
hemddabral | 7:e293b0f43dc7 | 16 | |
hemddabral | 7:e293b0f43dc7 | 17 | void set_id(uint8_t i) { |
hemddabral | 7:e293b0f43dc7 | 18 | id=i; |
hemddabral | 7:e293b0f43dc7 | 19 | } |
hemddabral | 7:e293b0f43dc7 | 20 | |
hemddabral | 7:e293b0f43dc7 | 21 | void set_data(uint8_t* data1) { |
hemddabral | 7:e293b0f43dc7 | 22 | for(int j=0;j<length;j++) |
hemddabral | 7:e293b0f43dc7 | 23 | { |
hemddabral | 7:e293b0f43dc7 | 24 | data[j]=data1[j]; |
hemddabral | 7:e293b0f43dc7 | 25 | } |
hemddabral | 7:e293b0f43dc7 | 26 | } |
hemddabral | 7:e293b0f43dc7 | 27 | |
hemddabral | 7:e293b0f43dc7 | 28 | uint8_t get_length() { |
hemddabral | 7:e293b0f43dc7 | 29 | return length; |
hemddabral | 7:e293b0f43dc7 | 30 | } |
hemddabral | 7:e293b0f43dc7 | 31 | |
hemddabral | 7:e293b0f43dc7 | 32 | uint8_t get_id() { |
hemddabral | 7:e293b0f43dc7 | 33 | return id; |
hemddabral | 7:e293b0f43dc7 | 34 | } |
hemddabral | 7:e293b0f43dc7 | 35 | |
hemddabral | 7:e293b0f43dc7 | 36 | uint8_t* get_data() { |
hemddabral | 7:e293b0f43dc7 | 37 | return data; |
hemddabral | 7:e293b0f43dc7 | 38 | } |
hemddabral | 7:e293b0f43dc7 | 39 | |
hemddabral | 7:e293b0f43dc7 | 40 | }; |
hemddabral | 7:e293b0f43dc7 | 41 | |
hemddabral | 7:e293b0f43dc7 | 42 | class Payload { |
hemddabral | 7:e293b0f43dc7 | 43 | UnitPayload *payload; |
hemddabral | 7:e293b0f43dc7 | 44 | int stringLength; |
hemddabral | 7:e293b0f43dc7 | 45 | int payloadUnitCount; |
hemddabral | 7:e293b0f43dc7 | 46 | |
hemddabral | 7:e293b0f43dc7 | 47 | public: |
hemddabral | 7:e293b0f43dc7 | 48 | Payload(const uint8_t *tokenString, uint8_t string_ength); |
hemddabral | 7:e293b0f43dc7 | 49 | Payload::Payload(); |
hemddabral | 7:e293b0f43dc7 | 50 | uint8_t Payload::getPayloadUnitCount(); |
hemddabral | 7:e293b0f43dc7 | 51 | |
hemddabral | 7:e293b0f43dc7 | 52 | uint8_t Payload::getIDAtIndex(int index); |
hemddabral | 7:e293b0f43dc7 | 53 | uint8_t Payload::getLengthAtIndex(int index); |
hemddabral | 7:e293b0f43dc7 | 54 | uint8_t* Payload::getDataAtIndex(int index); |
hemddabral | 7:e293b0f43dc7 | 55 | }; |
hemddabral | 7:e293b0f43dc7 | 56 | |
hemddabral | 7:e293b0f43dc7 | 57 | #endif // __PAYLOAD_H__ |