Skip to content

Commit 404fd67

Browse files
committed
Added MTU size to other Boards, Longer Names on Nano BLE
1 parent b2fefef commit 404fd67

7 files changed

+54
-21
lines changed

src/phyphoxBLE_ESP32.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ void PhyphoxBLE::configHandlerDebug(){
9090

9191
void PhyphoxBLE::setMTU(uint16_t mtuSize) {
9292
BLEDevice::setMTU(mtuSize+3); //user mtu size + 3 for overhead
93+
9394
PhyphoxBLE::MTU = mtuSize;
9495
PhyphoxBleExperiment::MTU = mtuSize;
9596

@@ -110,9 +111,11 @@ void PhyphoxBLE::start(uint8_t* exp_pointer, size_t len){
110111
void PhyphoxBLE::start(const char * DEVICE_NAME)
111112
{
112113
deviceName = DEVICE_NAME;
113-
if(printer){
114-
printer -> println("starting server");
115-
}
114+
#ifdef DEBUG
115+
if(printer){
116+
printer->println("starting server");
117+
}
118+
#endif
116119
if(p_exp == nullptr){
117120
PhyphoxBleExperiment defaultExperiment;
118121

@@ -350,31 +353,33 @@ void PhyphoxBLE::addExperiment(PhyphoxBleExperiment& exp)
350353
length += strlen(buffer);
351354
p_exp = &EXPARRAY[0];
352355
expLen = length;
353-
354-
if(printer){
356+
#ifdef DEBUG
357+
if(printer != nullptr){
355358
for(int i =0; i<length;i++){
356359
char test = EXPARRAY[i];
357-
Serial.print(test);
360+
358361
}
359362
}
360-
363+
#endif
361364
}
362365

363366
void PhyphoxBLE::disconnected(){
364-
if(printer){
367+
#ifdef DEBUG
368+
if(printer != nullptr){
365369
printer -> println("device disconnected");
366370
}
371+
#endif
367372
myAdvertising->start();
368373
}
369374

370375

371376
void PhyphoxBLE::begin(HardwareSerial* hwPrint)
372377
{
373-
374-
printer = hwPrint;
375-
if(printer)
378+
#ifdef DEBUG
379+
printer = hwPrint;
380+
if(printer)
376381
printer->begin(115200);
377-
382+
#endif
378383
}
379384

380385
#endif

src/phyphoxBLE_NINAB31.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ uint16_t PhyphoxBLE::maxConInterval = 48; //30ms
1818
uint16_t PhyphoxBLE::slaveLatency = 0;
1919
uint16_t PhyphoxBLE::timeout = 50;
2020

21+
uint16_t PhyphoxBLE::MTU = 20;
22+
uint16_t PhyphoxBleExperiment::MTU = 20;
2123

2224
int PhyphoxBLE::h_phyphoxExperimentService=0;
2325
int PhyphoxBLE::h_experimentCharacteristic=0;
@@ -39,6 +41,7 @@ uint8_t PhyphoxBLE::controlCharValue[21]={0};
3941
uint8_t PhyphoxBLE::configCharValue[21]={0};
4042

4143

44+
4245
void(*PhyphoxBLE::configHandler)() = nullptr;
4346

4447
void PhyphoxBLE::start(const char* DEVICE_NAME, uint8_t* exp_pointer, size_t len){
@@ -126,11 +129,28 @@ void PhyphoxBLE::read(float& f)
126129

127130
void PhyphoxBLE::addExperiment(PhyphoxBleExperiment& exp)
128131
{
129-
char buffer[4000] =""; //this should be reworked
130-
exp.getBytes(buffer);
131-
memcpy(&EXPARRAY[0],&buffer[0],strlen(buffer));
132-
p_exp = &EXPARRAY[0];
133-
expLen = strlen(buffer);
132+
char buffer[2500] ="";
133+
uint16_t length = 0;
134+
135+
exp.getFirstBytes(buffer, deviceName);
136+
memcpy(&EXPARRAY[length],&buffer[0],strlen(buffer));
137+
length += strlen(buffer);
138+
memset(&(buffer[0]), NULL, strlen(buffer));
139+
140+
for(uint8_t i=0;i<phyphoxBleNViews; i++){
141+
for(int j=0; j<phyphoxBleNElements; j++){
142+
exp.getViewBytes(buffer,i,j);
143+
memcpy(&EXPARRAY[length],&buffer[0],strlen(buffer));
144+
length += strlen(buffer);
145+
memset(&(buffer[0]), NULL, strlen(buffer));
146+
}
147+
}
148+
exp.getLastBytes(buffer);
149+
150+
memcpy(&EXPARRAY[length],&buffer[0],strlen(buffer));
151+
length += strlen(buffer);
152+
p_exp = &EXPARRAY[0];
153+
expLen = length;
134154
}
135155

136156

src/phyphoxBLE_NINAB31.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class PhyphoxBLE
6262
static uint16_t maxConInterval;
6363
static uint16_t slaveLatency;
6464
static uint16_t timeout;
65+
static uint16_t MTU;
6566

6667
};
6768

src/phyphoxBLE_NRF52.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const UUID PhyphoxBLE::phyphoxDataServiceUUID = UUID(phyphoxBleDataServiceUUID);
88
const UUID PhyphoxBLE::dataCharacteristicUUID = UUID(phyphoxBleDataCharacteristicUUID);
99
const UUID PhyphoxBLE::configCharacteristicUUID = UUID(phyphoxBleConfigCharacteristicUUID);
1010

11+
uint16_t PhyphoxBleExperiment::MTU = 20;
12+
1113
char PhyphoxBLE::name[50] = "";
1214

1315
Thread PhyphoxBLE::bleEventThread;
@@ -193,8 +195,7 @@ void PhyphoxBLE::bleInitComplete(BLE::InitializationCompleteCallbackContext* par
193195
ble::AdvertisingParameters adv_parameters(ble::advertising_type_t::CONNECTABLE_UNDIRECTED, ble::adv_interval_t(ble::millisecond_t(100)));
194196
adv_data_builder.setFlags();
195197
adv_data_builder.setLocalServiceList(mbed::make_Span(&phyphoxExperimentServiceUUID, 1));
196-
ble_error_t error = adv_data_builder.setName(name);
197-
198+
198199
#ifndef NDEBUG
199200
if(error == BLE_ERROR_BUFFER_OVERFLOW){
200201
output("BLE_ERROR_BUFFER_OVERFLOW");
@@ -207,6 +208,9 @@ void PhyphoxBLE::bleInitComplete(BLE::InitializationCompleteCallbackContext* par
207208

208209
ble.gap().setAdvertisingParameters(ble::LEGACY_ADVERTISING_HANDLE, adv_parameters);
209210
ble.gap().setAdvertisingPayload(ble::LEGACY_ADVERTISING_HANDLE,adv_data_builder.getAdvertisingData());
211+
adv_data_builder.clear();
212+
adv_data_builder.setName(name);
213+
ble.gap().setAdvertisingScanResponse(ble::LEGACY_ADVERTISING_HANDLE,adv_data_builder.getAdvertisingData());
210214
ble.gattServer().addService(phyphoxService);
211215
ble.gattServer().addService(phyphoxDataService);
212216

src/phyphoxBLE_NRF52.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class PhyphoxBLE
108108
static inline uint16_t maxConInterval = 24; //30ms
109109
static inline uint16_t slaveLatency = 0;
110110
static inline uint16_t timeout = 50;
111-
111+
static inline uint16_t MTU = 20;
112112
static inline uint16_t currentConnections = 0;
113113

114114
static void (*configHandler)();

src/phyphoxBLE_NanoIOT.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ uint16_t PhyphoxBLE::maxConInterval = 24; //30ms
1717
uint16_t PhyphoxBLE::slaveLatency = 0;
1818
uint16_t PhyphoxBLE::timeout = 50;
1919

20+
uint16_t PhyphoxBLE::MTU = 20;
21+
uint16_t PhyphoxBleExperiment::MTU = 20;
22+
2023
uint8_t* PhyphoxBLE::data = nullptr; //this pointer points to the data the user wants to write in the characteristic
2124
uint8_t* PhyphoxBLE::p_exp = nullptr; //this pointer will point to the byte array which holds an experiment
2225

src/phyphoxBLE_NanoIOT.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class PhyphoxBLE
5656
static uint16_t maxConInterval;
5757
static uint16_t slaveLatency;
5858
static uint16_t timeout;
59-
59+
static uint16_t MTU;
6060
};
6161

6262

0 commit comments

Comments
 (0)