project

Fork of X_NUCLEO_IDB0XA1 by ST

Committer:
Wolfgang Betz
Date:
Wed Oct 07 08:39:04 2015 +0200
Revision:
132:51056160fa4a
Andrea's version as of mail from 10/06/2015 05:56 PM

From: Andrea PALMIERI <andrea.palmieri@st.com>
To: Wolfgang BETZ <wolfgang.betz@st.com>, Rohit Grover <rohit.grover@arm.com>,
Antonio VILEI <antonio.vilei@st.com>, Mihail Stoyanov
<Mihail.Stoyanov@arm.com>
CC: Nicola CAPOVILLA <nicola.capovilla@st.com>, Silvio Lucio OLIVA
<silvio.oliva@st.com>, "jonathan.austin@arm.com" <jonathan.austin@arm.com>
Content-Class: urn:content-classes:message
Date: Tue, 6 Oct 2015 17:56:34 +0200
Subject: RE: Arduino Compatibility of X-NUCLEO-IDB04A1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wolfgang Betz 132:51056160fa4a 1 /* mbed Microcontroller Library
Wolfgang Betz 132:51056160fa4a 2 * Copyright (c) 2006-2013 ARM Limited
Wolfgang Betz 132:51056160fa4a 3 *
Wolfgang Betz 132:51056160fa4a 4 * Licensed under the Apache License, Version 2.0 (the "License");
Wolfgang Betz 132:51056160fa4a 5 * you may not use this file except in compliance with the License.
Wolfgang Betz 132:51056160fa4a 6 * You may obtain a copy of the License at
Wolfgang Betz 132:51056160fa4a 7 *
Wolfgang Betz 132:51056160fa4a 8 * http://www.apache.org/licenses/LICENSE-2.0
Wolfgang Betz 132:51056160fa4a 9 *
Wolfgang Betz 132:51056160fa4a 10 * Unless required by applicable law or agreed to in writing, software
Wolfgang Betz 132:51056160fa4a 11 * distributed under the License is distributed on an "AS IS" BASIS,
Wolfgang Betz 132:51056160fa4a 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Wolfgang Betz 132:51056160fa4a 13 * See the License for the specific language governing permissions and
Wolfgang Betz 132:51056160fa4a 14 * limitations under the License.
Wolfgang Betz 132:51056160fa4a 15 */
Wolfgang Betz 132:51056160fa4a 16
Wolfgang Betz 132:51056160fa4a 17 #include <Payload.h>
Wolfgang Betz 132:51056160fa4a 18
Wolfgang Betz 132:51056160fa4a 19 Payload::Payload() {
Wolfgang Betz 132:51056160fa4a 20 stringLength = 0;
Wolfgang Betz 132:51056160fa4a 21 payloadUnitCount = 0;
Wolfgang Betz 132:51056160fa4a 22 payload = NULL;
Wolfgang Betz 132:51056160fa4a 23 }
Wolfgang Betz 132:51056160fa4a 24
Wolfgang Betz 132:51056160fa4a 25 Payload::Payload(const uint8_t *tokenString, uint8_t string_ength) {
Wolfgang Betz 132:51056160fa4a 26 // initialize private data members
Wolfgang Betz 132:51056160fa4a 27 stringLength = string_ength;
Wolfgang Betz 132:51056160fa4a 28 payloadUnitCount = 0;
Wolfgang Betz 132:51056160fa4a 29 payload = NULL;
Wolfgang Betz 132:51056160fa4a 30
Wolfgang Betz 132:51056160fa4a 31 int index = 0;
Wolfgang Betz 132:51056160fa4a 32 while( index!=stringLength) {
Wolfgang Betz 132:51056160fa4a 33 int len=tokenString[index];
Wolfgang Betz 132:51056160fa4a 34 index=index+1+len;
Wolfgang Betz 132:51056160fa4a 35 payloadUnitCount++;
Wolfgang Betz 132:51056160fa4a 36 }
Wolfgang Betz 132:51056160fa4a 37
Wolfgang Betz 132:51056160fa4a 38 UnitPayload *obj = new UnitPayload[payloadUnitCount];
Wolfgang Betz 132:51056160fa4a 39 int i=0;
Wolfgang Betz 132:51056160fa4a 40 int c=0;
Wolfgang Betz 132:51056160fa4a 41 int j,k;
Wolfgang Betz 132:51056160fa4a 42
Wolfgang Betz 132:51056160fa4a 43 while(i<payloadUnitCount)
Wolfgang Betz 132:51056160fa4a 44 {
Wolfgang Betz 132:51056160fa4a 45 obj[i].length=tokenString[c];
Wolfgang Betz 132:51056160fa4a 46 obj[i].id=tokenString[c+1];
Wolfgang Betz 132:51056160fa4a 47
Wolfgang Betz 132:51056160fa4a 48 obj[i].data = new uint8_t[obj[i].length];
Wolfgang Betz 132:51056160fa4a 49 for(j=c+2,k=0;(j<(c+obj[i].length+1))&&(k<obj[i].length-1);j++,k++)
Wolfgang Betz 132:51056160fa4a 50 {
Wolfgang Betz 132:51056160fa4a 51 obj[i].data[k]=tokenString[j];
Wolfgang Betz 132:51056160fa4a 52
Wolfgang Betz 132:51056160fa4a 53 }
Wolfgang Betz 132:51056160fa4a 54
Wolfgang Betz 132:51056160fa4a 55 c=c+obj[i].length+1;
Wolfgang Betz 132:51056160fa4a 56 i++;
Wolfgang Betz 132:51056160fa4a 57
Wolfgang Betz 132:51056160fa4a 58 }
Wolfgang Betz 132:51056160fa4a 59 payload = obj;
Wolfgang Betz 132:51056160fa4a 60 }
Wolfgang Betz 132:51056160fa4a 61
Wolfgang Betz 132:51056160fa4a 62 uint8_t Payload::getPayloadUnitCount() {
Wolfgang Betz 132:51056160fa4a 63 return payloadUnitCount;
Wolfgang Betz 132:51056160fa4a 64 }
Wolfgang Betz 132:51056160fa4a 65
Wolfgang Betz 132:51056160fa4a 66 uint8_t Payload::getIDAtIndex(int index) {
Wolfgang Betz 132:51056160fa4a 67 return payload[index].get_id();
Wolfgang Betz 132:51056160fa4a 68 }
Wolfgang Betz 132:51056160fa4a 69
Wolfgang Betz 132:51056160fa4a 70 uint8_t Payload::getLengthAtIndex(int index) {
Wolfgang Betz 132:51056160fa4a 71 return payload[index].get_length();
Wolfgang Betz 132:51056160fa4a 72 }
Wolfgang Betz 132:51056160fa4a 73
Wolfgang Betz 132:51056160fa4a 74 uint8_t* Payload::getDataAtIndex(int index) {
Wolfgang Betz 132:51056160fa4a 75 return payload[index].get_data();
Wolfgang Betz 132:51056160fa4a 76 }
Wolfgang Betz 132:51056160fa4a 77
Wolfgang Betz 132:51056160fa4a 78 int8_t Payload::getInt8AtIndex(int index) {
Wolfgang Betz 132:51056160fa4a 79 uint8_t* str = payload[index].get_data();
Wolfgang Betz 132:51056160fa4a 80 int8_t value = (int8_t)str[0];
Wolfgang Betz 132:51056160fa4a 81 return value;
Wolfgang Betz 132:51056160fa4a 82 }
Wolfgang Betz 132:51056160fa4a 83
Wolfgang Betz 132:51056160fa4a 84 uint16_t Payload::getUint16AtIndex(int index) {
Wolfgang Betz 132:51056160fa4a 85 uint16_t* str = (uint16_t*)payload[index].get_data();
Wolfgang Betz 132:51056160fa4a 86 uint16_t value = str[0];
Wolfgang Betz 132:51056160fa4a 87 return value;
Wolfgang Betz 132:51056160fa4a 88 }
Wolfgang Betz 132:51056160fa4a 89
Wolfgang Betz 132:51056160fa4a 90 uint8_t* Payload::getSerializedAdDataAtIndex(int index) {
Wolfgang Betz 132:51056160fa4a 91 uint8_t length = payload[index].get_length();
Wolfgang Betz 132:51056160fa4a 92 uint8_t* data = payload[index].get_data();
Wolfgang Betz 132:51056160fa4a 93 uint8_t id = payload[index].get_id();
Wolfgang Betz 132:51056160fa4a 94 uint8_t *serializedAdData = new uint8_t[length];
Wolfgang Betz 132:51056160fa4a 95
Wolfgang Betz 132:51056160fa4a 96 serializedAdData[0] = id;
Wolfgang Betz 132:51056160fa4a 97 for(int i=0; i<length-1; i++) {
Wolfgang Betz 132:51056160fa4a 98 serializedAdData[i+1] = data[i];
Wolfgang Betz 132:51056160fa4a 99 }
Wolfgang Betz 132:51056160fa4a 100 return serializedAdData;
Wolfgang Betz 132:51056160fa4a 101 }