Skip to content

Commit 27ff34b

Browse files
committed
examples/L2CAP: pin esp-hpl tag and clean whitespace
1 parent 36e59d6 commit 27ff34b

4 files changed

Lines changed: 42 additions & 41 deletions

File tree

examples/L2CAP/L2CAP_Client/main/idf_component.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ dependencies:
33
path: ../../../../../esp-nimble-cpp/
44
mickeyl/esp-hpl:
55
git: https://github.com/mickeyl/esp-hpl.git
6+
version: "1.1.0"

examples/L2CAP/L2CAP_Client/main/main.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,44 +79,44 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
7979
void statusTask(void *pvParameters) {
8080
while (true) {
8181
vTaskDelay(1000 / portTICK_PERIOD_MS);
82-
82+
8383
if (startTime > 0 && blocksSent > 0) {
8484
uint64_t currentTime = esp_timer_get_time();
8585
double elapsedSeconds = (currentTime - startTime) / 1000000.0;
8686
double bytesPerSecond = bytesSent / elapsedSeconds;
8787
double kbPerSecond = bytesPerSecond / 1024.0;
88-
88+
8989
// Heap monitoring
9090
size_t currentHeap = esp_get_free_heap_size();
9191
size_t minHeap = esp_get_minimum_free_heap_size();
92-
92+
9393
// Track heap for leak detection
9494
if (initialHeap == 0) {
9595
initialHeap = currentHeap;
9696
lastHeap = currentHeap;
9797
}
98-
98+
9999
// Check for consistent heap decrease
100100
if (currentHeap < lastHeap) {
101101
heapDecreaseCount++;
102102
if (heapDecreaseCount >= HEAP_LEAK_THRESHOLD) {
103103
printf("\n⚠️ WARNING: POSSIBLE MEMORY LEAK DETECTED! ⚠️\n");
104104
printf("Heap has decreased %zu times in a row\n", heapDecreaseCount);
105-
printf("Initial heap: %zu, Current heap: %zu, Lost: %zu bytes\n",
105+
printf("Initial heap: %zu, Current heap: %zu, Lost: %zu bytes\n",
106106
initialHeap, currentHeap, initialHeap - currentHeap);
107107
}
108108
} else if (currentHeap >= lastHeap) {
109109
heapDecreaseCount = 0; // Reset counter if heap stabilizes or increases
110110
}
111111
lastHeap = currentHeap;
112-
112+
113113
printf("\n=== STATUS UPDATE ===\n");
114114
printf("Blocks sent: %lu\n", (unsigned long)blocksSent);
115115
printf("Total bytes sent: %zu\n", bytesSent);
116116
printf("Current payload size: %zu bytes\n", currentPayloadSize);
117117
printf("Elapsed time: %.1f seconds\n", elapsedSeconds);
118118
printf("Bandwidth: %.2f KB/s (%.2f Mbps)\n", kbPerSecond, (bytesPerSecond * 8) / 1000000.0);
119-
printf("Heap: %zu free (min: %zu), Used since start: %zu\n",
119+
printf("Heap: %zu free (min: %zu), Used since start: %zu\n",
120120
currentHeap, minHeap, initialHeap > 0 ? initialHeap - currentHeap : 0);
121121
printf("==================\n\n");
122122
}
@@ -128,7 +128,7 @@ void connectTask(void *pvParameters) {
128128
uint8_t sequenceNumber = 0;
129129

130130
while (true) {
131-
131+
132132
if (!theDevice) {
133133
vTaskDelay(1000 / portTICK_PERIOD_MS);
134134
continue;
@@ -147,7 +147,7 @@ void connectTask(void *pvParameters) {
147147
break;
148148
}
149149
vTaskDelay(2000 / portTICK_PERIOD_MS);
150-
continue;
150+
continue;
151151
}
152152

153153
if (!theChannel) {
@@ -166,37 +166,37 @@ void connectTask(void *pvParameters) {
166166
// Create framed packet: [seqno 8bit] [16bit payload length] [payload]
167167
std::vector<uint8_t> packet;
168168
packet.reserve(3 + currentPayloadSize);
169-
169+
170170
// Add sequence number (8 bits)
171171
packet.push_back(sequenceNumber);
172-
172+
173173
// Add payload length (16 bits, big endian - network byte order)
174174
uint16_t payloadLen = currentPayloadSize;
175175
packet.push_back((payloadLen >> 8) & 0xFF); // High byte first
176176
packet.push_back(payloadLen & 0xFF); // Low byte second
177-
177+
178178
// Add payload
179179
for (size_t i = 0; i < currentPayloadSize; i++) {
180180
packet.push_back(i & 0xFF);
181181
}
182-
182+
183183
if (theChannel->write(packet)) {
184184
if (startTime == 0) {
185185
startTime = esp_timer_get_time();
186186
}
187187
bytesSent += packet.size();
188188
blocksSent++;
189-
189+
190190
// Print every block since we're sending slowly now
191-
printf("Sent block %lu (seq=%d, payload=%zu bytes, frame_size=%zu)\n",
191+
printf("Sent block %lu (seq=%d, payload=%zu bytes, frame_size=%zu)\n",
192192
(unsigned long)blocksSent, sequenceNumber, currentPayloadSize, packet.size());
193-
193+
194194
sequenceNumber++;
195-
195+
196196
// After every 50 blocks, double payload size
197197
if (blocksSent % BLOCKS_BEFORE_DOUBLE == 0) {
198198
size_t newSize = currentPayloadSize * 2;
199-
199+
200200
// Cap at maximum safe payload size
201201
if (newSize > MAX_PAYLOAD_SIZE) {
202202
if (currentPayloadSize < MAX_PAYLOAD_SIZE) {
@@ -211,9 +211,9 @@ void connectTask(void *pvParameters) {
211211
}
212212
} else {
213213
printf("failed to send!\n");
214-
abort();
214+
abort();
215215
}
216-
216+
217217
// No delay - send as fast as possible
218218
}
219219

examples/L2CAP/L2CAP_Server/main/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ dependencies:
33
path: ../../../../../esp-nimble-cpp/
44
mickeyl/esp-hpl:
55
git: https://github.com/mickeyl/esp-hpl.git
6-
version: "master"
6+
version: "1.1.0"

examples/L2CAP/L2CAP_Server/main/main.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,37 +56,37 @@ class L2CAPChannelCallbacks: public BLEL2CAPChannelCallbacks {
5656
if (startTime == 0) {
5757
startTime = esp_timer_get_time(); // start measuring once data flows
5858
}
59-
59+
6060
// Process complete frames from buffer
6161
while (buffer.size() >= 3) { // Minimum frame size: seqno(1) + len(2)
6262
// Parse frame header
6363
uint8_t seqno = buffer[0];
6464
uint16_t payloadLen = (buffer[1] << 8) | buffer[2]; // Big-endian
65-
65+
6666
size_t frameSize = 3 + payloadLen;
67-
67+
6868
// Check if we have complete frame
6969
if (buffer.size() < frameSize) {
7070
break; // Wait for more data
7171
}
72-
72+
7373
// Validate and process frame
7474
totalFramesReceived++;
7575
totalPayloadBytes += payloadLen;
76-
76+
7777
// Check sequence number
7878
if (seqno != expectedSequenceNumber) {
7979
sequenceErrors++;
80-
printf("Frame %zu: Sequence error - got %d, expected %d (payload=%d bytes)\n",
80+
printf("Frame %zu: Sequence error - got %d, expected %d (payload=%d bytes)\n",
8181
totalFramesReceived, seqno, expectedSequenceNumber, payloadLen);
8282
}
83-
83+
8484
// Update expected sequence number (wraps at 256)
8585
expectedSequenceNumber = (seqno + 1) & 0xFF;
86-
86+
8787
// Remove processed frame from buffer
8888
buffer.erase(buffer.begin(), buffer.begin() + frameSize);
89-
89+
9090
// Print progress every 100 frames
9191
if (totalFramesReceived % 100 == 0) {
9292
double elapsedSeconds = (esp_timer_get_time() - startTime) / 1000000.0;
@@ -97,7 +97,7 @@ class L2CAPChannelCallbacks: public BLEL2CAPChannelCallbacks {
9797
}
9898
}
9999
}
100-
100+
101101
void onDisconnect(NimBLEL2CAPChannel* channel) {
102102
printf("\nL2CAP disconnected\n");
103103
double elapsedSeconds = startTime > 0 ? (esp_timer_get_time() - startTime) / 1000000.0 : 0.0;
@@ -141,10 +141,10 @@ void app_main(void) {
141141
auto l2capChannelCallbacks = new L2CAPChannelCallbacks();
142142
auto channel = cocServer->createService(L2CAP_PSM, L2CAP_MTU, l2capChannelCallbacks);
143143
(void)channel; // prevent unused warning
144-
144+
145145
auto server = BLEDevice::createServer();
146146
server->setCallbacks(new GATTCallbacks());
147-
147+
148148
auto advertising = BLEDevice::getAdvertising();
149149
NimBLEAdvertisementData scanData;
150150
scanData.setName("l2cap");
@@ -156,46 +156,46 @@ void app_main(void) {
156156
// Status reporting loop
157157
while (true) {
158158
vTaskDelay(1000 / portTICK_PERIOD_MS);
159-
159+
160160
if (l2capChannelCallbacks->connected && l2capChannelCallbacks->totalBytesReceived > 0) {
161161
uint64_t currentTime = esp_timer_get_time();
162162
double elapsedSeconds = (currentTime - l2capChannelCallbacks->startTime) / 1000000.0;
163-
163+
164164
if (elapsedSeconds > 0) {
165165
double bytesPerSecond = l2capChannelCallbacks->totalBytesReceived / elapsedSeconds;
166166
double framesPerSecond = l2capChannelCallbacks->totalFramesReceived / elapsedSeconds;
167-
167+
168168
// Heap monitoring
169169
size_t currentHeap = esp_get_free_heap_size();
170170
size_t minHeap = esp_get_minimum_free_heap_size();
171-
171+
172172
// Track heap for leak detection
173173
if (initialHeap == 0) {
174174
initialHeap = currentHeap;
175175
lastHeap = currentHeap;
176176
}
177-
177+
178178
// Check for consistent heap decrease
179179
if (currentHeap < lastHeap) {
180180
heapDecreaseCount++;
181181
if (heapDecreaseCount >= HEAP_LEAK_THRESHOLD) {
182182
printf("\n⚠️ WARNING: POSSIBLE MEMORY LEAK DETECTED! ⚠️\n");
183183
printf("Heap has decreased %zu times in a row\n", heapDecreaseCount);
184-
printf("Initial heap: %zu, Current heap: %zu, Lost: %zu bytes\n",
184+
printf("Initial heap: %zu, Current heap: %zu, Lost: %zu bytes\n",
185185
initialHeap, currentHeap, initialHeap - currentHeap);
186186
}
187187
} else if (currentHeap >= lastHeap) {
188188
heapDecreaseCount = 0; // Reset counter if heap stabilizes or increases
189189
}
190190
lastHeap = currentHeap;
191-
191+
192192
printf("\n=== STATUS UPDATE ===\n");
193193
printf("Frames received: %zu (%.1f fps)\n", l2capChannelCallbacks->totalFramesReceived, framesPerSecond);
194194
printf("Total bytes: %zu\n", l2capChannelCallbacks->totalBytesReceived);
195195
printf("Payload bytes: %zu\n", l2capChannelCallbacks->totalPayloadBytes);
196196
printf("Bandwidth: %.2f KB/s (%.2f Mbps)\n", bytesPerSecond / 1024.0, (bytesPerSecond * 8) / 1000000.0);
197197
printf("Sequence errors: %zu\n", l2capChannelCallbacks->sequenceErrors);
198-
printf("Heap: %zu free (min: %zu), Used since start: %zu\n",
198+
printf("Heap: %zu free (min: %zu), Used since start: %zu\n",
199199
currentHeap, minHeap, initialHeap > 0 ? initialHeap - currentHeap : 0);
200200
printf("==================\n");
201201
}

0 commit comments

Comments
 (0)