Wouter van Kleunen / X_NUCLEO_IDB0XA1

Fork of X_NUCLEO_IDB0XA1 by ST

Committer:
Wolfgang Betz
Date:
Tue Oct 06 14:25:08 2015 +0200
Revision:
130:770ce14d3d15
Include mbed-classic version

Derived from
- repo (on Codex): gitolite@codex.cro.st.com:x-nucleodev/X-NUCLEO-IKC01A1-MBED.git
- branch: ble_wb
- SHA1 ID: 5ccc73e35868169e42132c0d1c056f908a6d70c0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wolfgang Betz 130:770ce14d3d15 1 /* mbed Microcontroller Library
Wolfgang Betz 130:770ce14d3d15 2 * Copyright (c) 2006-2013 ARM Limited
Wolfgang Betz 130:770ce14d3d15 3 *
Wolfgang Betz 130:770ce14d3d15 4 * Licensed under the Apache License, Version 2.0 (the "License");
Wolfgang Betz 130:770ce14d3d15 5 * you may not use this file except in compliance with the License.
Wolfgang Betz 130:770ce14d3d15 6 * You may obtain a copy of the License at
Wolfgang Betz 130:770ce14d3d15 7 *
Wolfgang Betz 130:770ce14d3d15 8 * http://www.apache.org/licenses/LICENSE-2.0
Wolfgang Betz 130:770ce14d3d15 9 *
Wolfgang Betz 130:770ce14d3d15 10 * Unless required by applicable law or agreed to in writing, software
Wolfgang Betz 130:770ce14d3d15 11 * distributed under the License is distributed on an "AS IS" BASIS,
Wolfgang Betz 130:770ce14d3d15 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Wolfgang Betz 130:770ce14d3d15 13 * See the License for the specific language governing permissions and
Wolfgang Betz 130:770ce14d3d15 14 * limitations under the License.
Wolfgang Betz 130:770ce14d3d15 15 */
Wolfgang Betz 130:770ce14d3d15 16
Wolfgang Betz 130:770ce14d3d15 17 #include "mbed.h"
Wolfgang Betz 130:770ce14d3d15 18
Wolfgang Betz 130:770ce14d3d15 19 #ifndef __PAYLOAD_H__
Wolfgang Betz 130:770ce14d3d15 20 #define __PAYLOAD_H__
Wolfgang Betz 130:770ce14d3d15 21
Wolfgang Betz 130:770ce14d3d15 22 class UnitPayload
Wolfgang Betz 130:770ce14d3d15 23 {
Wolfgang Betz 130:770ce14d3d15 24 public:
Wolfgang Betz 130:770ce14d3d15 25 uint8_t length;
Wolfgang Betz 130:770ce14d3d15 26 uint8_t id;
Wolfgang Betz 130:770ce14d3d15 27 uint8_t *data;
Wolfgang Betz 130:770ce14d3d15 28 uint8_t *idptr;
Wolfgang Betz 130:770ce14d3d15 29
Wolfgang Betz 130:770ce14d3d15 30
Wolfgang Betz 130:770ce14d3d15 31
Wolfgang Betz 130:770ce14d3d15 32 void set_length(uint8_t l) {
Wolfgang Betz 130:770ce14d3d15 33 length=l;
Wolfgang Betz 130:770ce14d3d15 34 }
Wolfgang Betz 130:770ce14d3d15 35
Wolfgang Betz 130:770ce14d3d15 36 void set_id(uint8_t i) {
Wolfgang Betz 130:770ce14d3d15 37 id=i;
Wolfgang Betz 130:770ce14d3d15 38 }
Wolfgang Betz 130:770ce14d3d15 39
Wolfgang Betz 130:770ce14d3d15 40 void set_data(uint8_t* data1) {
Wolfgang Betz 130:770ce14d3d15 41 for(int j=0;j<length;j++)
Wolfgang Betz 130:770ce14d3d15 42 {
Wolfgang Betz 130:770ce14d3d15 43 data[j]=data1[j];
Wolfgang Betz 130:770ce14d3d15 44 }
Wolfgang Betz 130:770ce14d3d15 45 }
Wolfgang Betz 130:770ce14d3d15 46
Wolfgang Betz 130:770ce14d3d15 47 uint8_t get_length() {
Wolfgang Betz 130:770ce14d3d15 48 return length;
Wolfgang Betz 130:770ce14d3d15 49 }
Wolfgang Betz 130:770ce14d3d15 50
Wolfgang Betz 130:770ce14d3d15 51 uint8_t get_id() {
Wolfgang Betz 130:770ce14d3d15 52 return id;
Wolfgang Betz 130:770ce14d3d15 53 }
Wolfgang Betz 130:770ce14d3d15 54
Wolfgang Betz 130:770ce14d3d15 55 uint8_t* get_data() {
Wolfgang Betz 130:770ce14d3d15 56 return data;
Wolfgang Betz 130:770ce14d3d15 57 }
Wolfgang Betz 130:770ce14d3d15 58
Wolfgang Betz 130:770ce14d3d15 59 };
Wolfgang Betz 130:770ce14d3d15 60
Wolfgang Betz 130:770ce14d3d15 61 class Payload {
Wolfgang Betz 130:770ce14d3d15 62 UnitPayload *payload;
Wolfgang Betz 130:770ce14d3d15 63 int stringLength;
Wolfgang Betz 130:770ce14d3d15 64 int payloadUnitCount;
Wolfgang Betz 130:770ce14d3d15 65
Wolfgang Betz 130:770ce14d3d15 66 public:
Wolfgang Betz 130:770ce14d3d15 67 Payload(const uint8_t *tokenString, uint8_t string_ength);
Wolfgang Betz 130:770ce14d3d15 68 Payload();
Wolfgang Betz 130:770ce14d3d15 69 uint8_t getPayloadUnitCount();
Wolfgang Betz 130:770ce14d3d15 70
Wolfgang Betz 130:770ce14d3d15 71 uint8_t getIDAtIndex(int index);
Wolfgang Betz 130:770ce14d3d15 72 uint8_t getLengthAtIndex(int index);
Wolfgang Betz 130:770ce14d3d15 73 uint8_t* getDataAtIndex(int index);
Wolfgang Betz 130:770ce14d3d15 74 int8_t getInt8AtIndex(int index);
Wolfgang Betz 130:770ce14d3d15 75 uint16_t getUint16AtIndex(int index);
Wolfgang Betz 130:770ce14d3d15 76 uint8_t* getSerializedAdDataAtIndex(int index);
Wolfgang Betz 130:770ce14d3d15 77 };
Wolfgang Betz 130:770ce14d3d15 78
Wolfgang Betz 130:770ce14d3d15 79
Wolfgang Betz 130:770ce14d3d15 80 class PayloadUnit {
Wolfgang Betz 130:770ce14d3d15 81 private:
Wolfgang Betz 130:770ce14d3d15 82 uint8_t* lenPtr;
Wolfgang Betz 130:770ce14d3d15 83 uint8_t* adTypePtr;
Wolfgang Betz 130:770ce14d3d15 84 uint8_t* dataPtr;
Wolfgang Betz 130:770ce14d3d15 85
Wolfgang Betz 130:770ce14d3d15 86 public:
Wolfgang Betz 130:770ce14d3d15 87 PayloadUnit() {
Wolfgang Betz 130:770ce14d3d15 88 lenPtr = NULL;
Wolfgang Betz 130:770ce14d3d15 89 adTypePtr = NULL;
Wolfgang Betz 130:770ce14d3d15 90 dataPtr = NULL;
Wolfgang Betz 130:770ce14d3d15 91 }
Wolfgang Betz 130:770ce14d3d15 92
Wolfgang Betz 130:770ce14d3d15 93 PayloadUnit(uint8_t *len, uint8_t *adType, uint8_t* data) {
Wolfgang Betz 130:770ce14d3d15 94 lenPtr = len;
Wolfgang Betz 130:770ce14d3d15 95 adTypePtr = adType;
Wolfgang Betz 130:770ce14d3d15 96 dataPtr = data;
Wolfgang Betz 130:770ce14d3d15 97 }
Wolfgang Betz 130:770ce14d3d15 98
Wolfgang Betz 130:770ce14d3d15 99 void setLenPtr(uint8_t *len) {
Wolfgang Betz 130:770ce14d3d15 100 lenPtr = len;
Wolfgang Betz 130:770ce14d3d15 101 }
Wolfgang Betz 130:770ce14d3d15 102
Wolfgang Betz 130:770ce14d3d15 103 void setAdTypePtr(uint8_t *adType) {
Wolfgang Betz 130:770ce14d3d15 104 adTypePtr = adType;
Wolfgang Betz 130:770ce14d3d15 105 }
Wolfgang Betz 130:770ce14d3d15 106
Wolfgang Betz 130:770ce14d3d15 107 void setDataPtr(uint8_t *data) {
Wolfgang Betz 130:770ce14d3d15 108 dataPtr = data;
Wolfgang Betz 130:770ce14d3d15 109 }
Wolfgang Betz 130:770ce14d3d15 110
Wolfgang Betz 130:770ce14d3d15 111 uint8_t* getLenPtr() {
Wolfgang Betz 130:770ce14d3d15 112 return lenPtr;
Wolfgang Betz 130:770ce14d3d15 113 }
Wolfgang Betz 130:770ce14d3d15 114
Wolfgang Betz 130:770ce14d3d15 115 uint8_t* getAdTypePtr() {
Wolfgang Betz 130:770ce14d3d15 116 return adTypePtr;
Wolfgang Betz 130:770ce14d3d15 117 }
Wolfgang Betz 130:770ce14d3d15 118
Wolfgang Betz 130:770ce14d3d15 119 uint8_t* getDataPtr() {
Wolfgang Betz 130:770ce14d3d15 120 return dataPtr;
Wolfgang Betz 130:770ce14d3d15 121 }
Wolfgang Betz 130:770ce14d3d15 122
Wolfgang Betz 130:770ce14d3d15 123 void printDataAsHex() {
Wolfgang Betz 130:770ce14d3d15 124 int i = 0;
Wolfgang Betz 130:770ce14d3d15 125 printf("AdData=");
Wolfgang Betz 130:770ce14d3d15 126 for(i=0; i<*lenPtr-1; i++) {
Wolfgang Betz 130:770ce14d3d15 127 printf("0x%x ", dataPtr[i]);
Wolfgang Betz 130:770ce14d3d15 128 }
Wolfgang Betz 130:770ce14d3d15 129 printf("\n");
Wolfgang Betz 130:770ce14d3d15 130 }
Wolfgang Betz 130:770ce14d3d15 131
Wolfgang Betz 130:770ce14d3d15 132 void printDataAsString() {
Wolfgang Betz 130:770ce14d3d15 133 int i = 0;
Wolfgang Betz 130:770ce14d3d15 134 printf("AdData=");
Wolfgang Betz 130:770ce14d3d15 135 for(i=0; i<*lenPtr; i++) {
Wolfgang Betz 130:770ce14d3d15 136 printf("%c", dataPtr[i]);
Wolfgang Betz 130:770ce14d3d15 137 }
Wolfgang Betz 130:770ce14d3d15 138 printf("\n");
Wolfgang Betz 130:770ce14d3d15 139 }
Wolfgang Betz 130:770ce14d3d15 140
Wolfgang Betz 130:770ce14d3d15 141 };
Wolfgang Betz 130:770ce14d3d15 142
Wolfgang Betz 130:770ce14d3d15 143 class PayloadPtr {
Wolfgang Betz 130:770ce14d3d15 144 private:
Wolfgang Betz 130:770ce14d3d15 145 PayloadUnit *unit;
Wolfgang Betz 130:770ce14d3d15 146 int payloadUnitCount;
Wolfgang Betz 130:770ce14d3d15 147 public:
Wolfgang Betz 130:770ce14d3d15 148 PayloadPtr(const uint8_t *tokenString, uint8_t string_ength) {
Wolfgang Betz 130:770ce14d3d15 149 // initialize private data members
Wolfgang Betz 130:770ce14d3d15 150 int stringLength = string_ength;
Wolfgang Betz 130:770ce14d3d15 151 payloadUnitCount = 0;
Wolfgang Betz 130:770ce14d3d15 152
Wolfgang Betz 130:770ce14d3d15 153 int index = 0;
Wolfgang Betz 130:770ce14d3d15 154 while(index!=stringLength) {
Wolfgang Betz 130:770ce14d3d15 155 int len=tokenString[index];
Wolfgang Betz 130:770ce14d3d15 156 index=index+1+len;
Wolfgang Betz 130:770ce14d3d15 157 payloadUnitCount++;
Wolfgang Betz 130:770ce14d3d15 158 }
Wolfgang Betz 130:770ce14d3d15 159
Wolfgang Betz 130:770ce14d3d15 160 // allocate memory to unit
Wolfgang Betz 130:770ce14d3d15 161 unit = new PayloadUnit[payloadUnitCount];
Wolfgang Betz 130:770ce14d3d15 162 int i = 0;
Wolfgang Betz 130:770ce14d3d15 163 int nextUnitOffset = 0;
Wolfgang Betz 130:770ce14d3d15 164
Wolfgang Betz 130:770ce14d3d15 165 while(i<payloadUnitCount) {
Wolfgang Betz 130:770ce14d3d15 166 unit[i].setLenPtr((uint8_t *)tokenString+nextUnitOffset);
Wolfgang Betz 130:770ce14d3d15 167 unit[i].setAdTypePtr((uint8_t *)tokenString+nextUnitOffset+1);
Wolfgang Betz 130:770ce14d3d15 168 unit[i].setDataPtr((uint8_t *)tokenString+nextUnitOffset+2);
Wolfgang Betz 130:770ce14d3d15 169
Wolfgang Betz 130:770ce14d3d15 170 nextUnitOffset += *unit[i].getLenPtr()+1;
Wolfgang Betz 130:770ce14d3d15 171 i++;
Wolfgang Betz 130:770ce14d3d15 172
Wolfgang Betz 130:770ce14d3d15 173 }
Wolfgang Betz 130:770ce14d3d15 174 }
Wolfgang Betz 130:770ce14d3d15 175
Wolfgang Betz 130:770ce14d3d15 176 PayloadUnit getUnitAtIndex(int index) {
Wolfgang Betz 130:770ce14d3d15 177 return unit[index];
Wolfgang Betz 130:770ce14d3d15 178 }
Wolfgang Betz 130:770ce14d3d15 179
Wolfgang Betz 130:770ce14d3d15 180 int getPayloadUnitCount() { return payloadUnitCount; }
Wolfgang Betz 130:770ce14d3d15 181
Wolfgang Betz 130:770ce14d3d15 182
Wolfgang Betz 130:770ce14d3d15 183 };
Wolfgang Betz 130:770ce14d3d15 184
Wolfgang Betz 130:770ce14d3d15 185 #endif // __PAYLOAD_H__