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 <Payload.h>
Wolfgang Betz 130:770ce14d3d15 18
Wolfgang Betz 130:770ce14d3d15 19 Payload::Payload() {
Wolfgang Betz 130:770ce14d3d15 20 stringLength = 0;
Wolfgang Betz 130:770ce14d3d15 21 payloadUnitCount = 0;
Wolfgang Betz 130:770ce14d3d15 22 payload = NULL;
Wolfgang Betz 130:770ce14d3d15 23 }
Wolfgang Betz 130:770ce14d3d15 24
Wolfgang Betz 130:770ce14d3d15 25 Payload::Payload(const uint8_t *tokenString, uint8_t string_ength) {
Wolfgang Betz 130:770ce14d3d15 26 // initialize private data members
Wolfgang Betz 130:770ce14d3d15 27 stringLength = string_ength;
Wolfgang Betz 130:770ce14d3d15 28 payloadUnitCount = 0;
Wolfgang Betz 130:770ce14d3d15 29 payload = NULL;
Wolfgang Betz 130:770ce14d3d15 30
Wolfgang Betz 130:770ce14d3d15 31 int index = 0;
Wolfgang Betz 130:770ce14d3d15 32 while( index!=stringLength) {
Wolfgang Betz 130:770ce14d3d15 33 int len=tokenString[index];
Wolfgang Betz 130:770ce14d3d15 34 index=index+1+len;
Wolfgang Betz 130:770ce14d3d15 35 payloadUnitCount++;
Wolfgang Betz 130:770ce14d3d15 36 }
Wolfgang Betz 130:770ce14d3d15 37
Wolfgang Betz 130:770ce14d3d15 38 UnitPayload *obj = new UnitPayload[payloadUnitCount];
Wolfgang Betz 130:770ce14d3d15 39 int i=0;
Wolfgang Betz 130:770ce14d3d15 40 int c=0;
Wolfgang Betz 130:770ce14d3d15 41 int j,k;
Wolfgang Betz 130:770ce14d3d15 42
Wolfgang Betz 130:770ce14d3d15 43 while(i<payloadUnitCount)
Wolfgang Betz 130:770ce14d3d15 44 {
Wolfgang Betz 130:770ce14d3d15 45 obj[i].length=tokenString[c];
Wolfgang Betz 130:770ce14d3d15 46 obj[i].id=tokenString[c+1];
Wolfgang Betz 130:770ce14d3d15 47
Wolfgang Betz 130:770ce14d3d15 48 obj[i].data = new uint8_t[obj[i].length];
Wolfgang Betz 130:770ce14d3d15 49 for(j=c+2,k=0;(j<(c+obj[i].length+1))&&(k<obj[i].length-1);j++,k++)
Wolfgang Betz 130:770ce14d3d15 50 {
Wolfgang Betz 130:770ce14d3d15 51 obj[i].data[k]=tokenString[j];
Wolfgang Betz 130:770ce14d3d15 52
Wolfgang Betz 130:770ce14d3d15 53 }
Wolfgang Betz 130:770ce14d3d15 54
Wolfgang Betz 130:770ce14d3d15 55 c=c+obj[i].length+1;
Wolfgang Betz 130:770ce14d3d15 56 i++;
Wolfgang Betz 130:770ce14d3d15 57
Wolfgang Betz 130:770ce14d3d15 58 }
Wolfgang Betz 130:770ce14d3d15 59 payload = obj;
Wolfgang Betz 130:770ce14d3d15 60 }
Wolfgang Betz 130:770ce14d3d15 61
Wolfgang Betz 130:770ce14d3d15 62 uint8_t Payload::getPayloadUnitCount() {
Wolfgang Betz 130:770ce14d3d15 63 return payloadUnitCount;
Wolfgang Betz 130:770ce14d3d15 64 }
Wolfgang Betz 130:770ce14d3d15 65
Wolfgang Betz 130:770ce14d3d15 66 uint8_t Payload::getIDAtIndex(int index) {
Wolfgang Betz 130:770ce14d3d15 67 return payload[index].get_id();
Wolfgang Betz 130:770ce14d3d15 68 }
Wolfgang Betz 130:770ce14d3d15 69
Wolfgang Betz 130:770ce14d3d15 70 uint8_t Payload::getLengthAtIndex(int index) {
Wolfgang Betz 130:770ce14d3d15 71 return payload[index].get_length();
Wolfgang Betz 130:770ce14d3d15 72 }
Wolfgang Betz 130:770ce14d3d15 73
Wolfgang Betz 130:770ce14d3d15 74 uint8_t* Payload::getDataAtIndex(int index) {
Wolfgang Betz 130:770ce14d3d15 75 return payload[index].get_data();
Wolfgang Betz 130:770ce14d3d15 76 }
Wolfgang Betz 130:770ce14d3d15 77
Wolfgang Betz 130:770ce14d3d15 78 int8_t Payload::getInt8AtIndex(int index) {
Wolfgang Betz 130:770ce14d3d15 79 uint8_t* str = payload[index].get_data();
Wolfgang Betz 130:770ce14d3d15 80 int8_t value = (int8_t)str[0];
Wolfgang Betz 130:770ce14d3d15 81 return value;
Wolfgang Betz 130:770ce14d3d15 82 }
Wolfgang Betz 130:770ce14d3d15 83
Wolfgang Betz 130:770ce14d3d15 84 uint16_t Payload::getUint16AtIndex(int index) {
Wolfgang Betz 130:770ce14d3d15 85 uint16_t* str = (uint16_t*)payload[index].get_data();
Wolfgang Betz 130:770ce14d3d15 86 uint16_t value = str[0];
Wolfgang Betz 130:770ce14d3d15 87 return value;
Wolfgang Betz 130:770ce14d3d15 88 }
Wolfgang Betz 130:770ce14d3d15 89
Wolfgang Betz 130:770ce14d3d15 90 uint8_t* Payload::getSerializedAdDataAtIndex(int index) {
Wolfgang Betz 130:770ce14d3d15 91 uint8_t length = payload[index].get_length();
Wolfgang Betz 130:770ce14d3d15 92 uint8_t* data = payload[index].get_data();
Wolfgang Betz 130:770ce14d3d15 93 uint8_t id = payload[index].get_id();
Wolfgang Betz 130:770ce14d3d15 94 uint8_t *serializedAdData = new uint8_t[length];
Wolfgang Betz 130:770ce14d3d15 95
Wolfgang Betz 130:770ce14d3d15 96 serializedAdData[0] = id;
Wolfgang Betz 130:770ce14d3d15 97 for(int i=0; i<length-1; i++) {
Wolfgang Betz 130:770ce14d3d15 98 serializedAdData[i+1] = data[i];
Wolfgang Betz 130:770ce14d3d15 99 }
Wolfgang Betz 130:770ce14d3d15 100 return serializedAdData;
Wolfgang Betz 130:770ce14d3d15 101 }