HW layer for the Nucleo board, it only work with old BLE_API

Dependents:   Hello_BLE F446RE-BLE

Fork of X_NUCLEO_IDB0XA1 by ST

Committer:
leonardoaraujosantos
Date:
Tue Nov 03 23:10:27 2015 +0000
Revision:
129:57997390c086
Parent:
70:d20d30f59b1c
Changing pin D13

Who changed what in which revision?

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