Skip to content

Commit 00bb976

Browse files
committed
clear logs
1 parent 63e9e4b commit 00bb976

File tree

6 files changed

+57
-67
lines changed

6 files changed

+57
-67
lines changed

src/ConfiguratorAgents/agents/BLE/BLEAgent.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class BLEAgentClass : public ConfiguratorAgent, BoardConfigurationProtocol {
9292
void clearInputBuffer();
9393
};
9494

95-
//extern BLEAgentClass BLEAgent;
9695
inline BLEAgentClass::BLEAgentClass()
9796
: _confService{ "5e5be887-c816-4d4f-b431-9eb34b02f4d9" },
9897
_inputStreamCharacteristic{ "0000ffe1-0000-1000-8000-00805f9b34fc", BLEWrite, 256 },
@@ -134,7 +133,7 @@ inline ConfiguratorAgent::AgentConfiguratorStates BLEAgentClass::begin() {
134133
BLE.advertise();
135134
LEDFeedbackClass::getInstance().setMode(LEDFeedbackClass::LEDFeedbackMode::BLE_AVAILABLE);
136135
_state = AgentConfiguratorStates::INIT;
137-
//DEBUG_DEBUG("BLEAgentClass begin completed");
136+
138137
return _state;
139138
}
140139

src/ConfiguratorAgents/agents/BoardConfigurationProtocol/BoardConfigurationProtocol.cpp

Lines changed: 55 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#include "CBORAdapter.h"
1111
#include "cbor/CBOR.h"
1212

13+
#ifndef BCP_DEBUG_PACKET
14+
#define BCP_DEBUG_PACKET 0
15+
#endif
16+
1317
#define PACKET_VALIDITY_MS 30000
1418

1519
/******************************************************************************
@@ -86,59 +90,59 @@ BoardConfigurationProtocol::TransmissionResult BoardConfigurationProtocol::sendA
8690
return TransmissionResult::PEER_NOT_AVAILABLE;
8791
}
8892

89-
if (hasReceivedBytes()) {
90-
int receivedDataLen = receivedBytes();
93+
if (_outputMessagesList.size() > 0) {
94+
checkOutputPacketValidity();
95+
transmitStream();
96+
}
97+
98+
if (!hasReceivedBytes()) {
99+
return transmissionRes;
100+
}
101+
102+
int receivedDataLen = receivedBytes();
91103

104+
for (int i = 0; i < receivedDataLen; i++) {
92105
PacketManager::ReceivingState res;
93106
PacketManager::ReceivedData receivedData;
94-
95-
for (int i = 0; i < receivedDataLen; i++) {
96-
uint8_t val = readByte();
97-
res = PacketManager::getInstance().handleReceivedByte(receivedData, val);
98-
if (res == PacketManager::ReceivingState::ERROR) {
99-
DEBUG_DEBUG("BoardConfigurationProtocol::%s Error receiving packet", __FUNCTION__);
100-
sendNak();
101-
clearInputBuffer();
102-
transmissionRes = TransmissionResult::INVALID_DATA;
103-
break;
104-
} else if (res == PacketManager::ReceivingState::RECEIVED) {
105-
switch (receivedData.type) {
106-
case PacketManager::MessageType::DATA:
107-
{
108-
//DEBUG_DEBUG("BoardConfigurationProtocol::%s Received data packet", __FUNCTION__);
109-
//printPacket("payload", receivedData.payload.get_ptr(), receivedData.payload.len());
110-
_inputMessagesList.push_back(receivedData.payload);
111-
//Consider all sent data as received
112-
_outputMessagesList.clear();
113-
transmissionRes = TransmissionResult::DATA_RECEIVED;
114-
}
115-
break;
116-
case PacketManager::MessageType::TRANSMISSION_CONTROL:
117-
{
118-
if (receivedData.payload.len() == 1 && receivedData.payload[0] == 0x03) {
119-
120-
//DEBUG_DEBUG("BoardConfigurationProtocol::%s Received NACK packet", __FUNCTION__);
121-
for (std::list<OutputPacketBuffer>::iterator packet = _outputMessagesList.begin(); packet != _outputMessagesList.end(); ++packet) {
122-
packet->startProgress();
123-
}
124-
} else if (receivedData.payload.len() == 1 && receivedData.payload[0] == 0x02) {
125-
//DEBUG_DEBUG("BoardConfigurationProtocol::%s Received disconnect request", __FUNCTION__);
126-
handleDisconnectRequest();
107+
uint8_t val = readByte();
108+
109+
res = PacketManager::getInstance().handleReceivedByte(receivedData, val);
110+
if (res == PacketManager::ReceivingState::ERROR) {
111+
DEBUG_DEBUG("BoardConfigurationProtocol::%s Malformed packet", __FUNCTION__);
112+
sendNak();
113+
clearInputBuffer();
114+
transmissionRes = TransmissionResult::INVALID_DATA;
115+
break;
116+
} else if (res == PacketManager::ReceivingState::RECEIVED) {
117+
switch (receivedData.type) {
118+
case PacketManager::MessageType::DATA:
119+
{
120+
#ifdef BCP_DEBUG_PACKET
121+
printPacket("payload", receivedData.payload.get_ptr(), receivedData.payload.len());
122+
#endif
123+
_inputMessagesList.push_back(receivedData.payload);
124+
//Consider all sent data as received
125+
_outputMessagesList.clear();
126+
transmissionRes = TransmissionResult::DATA_RECEIVED;
127+
}
128+
break;
129+
case PacketManager::MessageType::TRANSMISSION_CONTROL:
130+
{
131+
if (receivedData.payload.len() == 1 && receivedData.payload[0] == 0x03) {
132+
for (std::list<OutputPacketBuffer>::iterator packet = _outputMessagesList.begin(); packet != _outputMessagesList.end(); ++packet) {
133+
packet->startProgress();
127134
}
135+
} else if (receivedData.payload.len() == 1 && receivedData.payload[0] == 0x02) {
136+
handleDisconnectRequest();
128137
}
129-
break;
130-
default:
131-
break;
132-
}
138+
}
139+
break;
140+
default:
141+
break;
133142
}
134143
}
135144
}
136145

137-
if (_outputMessagesList.size() > 0) {
138-
checkOutputPacketValidity();
139-
transmitStream();
140-
}
141-
142146
return transmissionRes;
143147
}
144148

@@ -152,11 +156,12 @@ bool BoardConfigurationProtocol::sendData(PacketManager::MessageType type, const
152156
outputMsg.setValidityTs(millis() + PACKET_VALIDITY_MS);
153157

154158
if (!PacketManager::createPacket(outputMsg, type, data, len)) {
155-
//DEBUG_WARNING("BoardConfigurationProtocol::%s Failed to create packet", __FUNCTION__);
156159
return false;
157160
}
158161

159-
//printPacket("output message", outputMsg.get_ptr(), outputMsg.len());
162+
#ifdef BCP_DEBUG_PACKET
163+
printPacket("output message", outputMsg.get_ptr(), outputMsg.len());
164+
#endif
160165

161166
_outputMessagesList.push_back(outputMsg);
162167

@@ -198,7 +203,6 @@ bool BoardConfigurationProtocol::sendStatus(StatusMessage msg) {
198203
uint8_t data[len];
199204
res = CBORAdapter::statusToCBOR(msg, data, &len);
200205
if (!res) {
201-
//DEBUG_ERROR("BoardConfigurationProtocol::%s failed encode status: %d ", __FUNCTION__, (int)msg);
202206
return res;
203207
}
204208

@@ -249,13 +253,12 @@ bool BoardConfigurationProtocol::sendUhwid(const byte *uhwid) {
249253
res = CBORAdapter::uhwidToCBOR(uhwid, data, &cborDataLen);
250254

251255
if (!res) {
252-
//DEBUG_ERROR("BoardConfigurationProtocol::%s failed to convert uhwid to CBOR", __FUNCTION__);
253256
return res;
254257
}
255258

256259
res = sendData(PacketManager::MessageType::DATA, data, cborDataLen);
257260
if (!res) {
258-
DEBUG_ERROR("BoardConfigurationProtocol::%s failed to send uhwid", __FUNCTION__);
261+
DEBUG_WARNING("BoardConfigurationProtocol::%s failed to send uhwid", __FUNCTION__);
259262
return res;
260263
}
261264

@@ -265,7 +268,6 @@ bool BoardConfigurationProtocol::sendUhwid(const byte *uhwid) {
265268
bool BoardConfigurationProtocol::sendJwt(const char *jwt, size_t len) {
266269
bool res = false;
267270
if (len > MAX_JWT_SIZE) {
268-
//DEBUG_ERROR("BoardConfigurationProtocol::%s JWT too long", __FUNCTION__);
269271
return res;
270272
}
271273

@@ -274,14 +276,13 @@ bool BoardConfigurationProtocol::sendJwt(const char *jwt, size_t len) {
274276

275277
res = CBORAdapter::jwtToCBOR(jwt, data, &cborDataLen);
276278
if (!res) {
277-
//DEBUG_ERROR("BoardConfigurationProtocol::%s failed to convert JWT to CBOR", __FUNCTION__);
278279
return res;
279280
}
280281

281282
res = sendData(PacketManager::MessageType::DATA, data, cborDataLen);
282283

283284
if (!res) {
284-
DEBUG_ERROR("BoardConfigurationProtocol::%s failed to send JWT", __FUNCTION__);
285+
DEBUG_WARNING("BoardConfigurationProtocol::%s failed to send JWT", __FUNCTION__);
285286
return res;
286287
}
287288

@@ -291,7 +292,6 @@ bool BoardConfigurationProtocol::sendJwt(const char *jwt, size_t len) {
291292
bool BoardConfigurationProtocol::sendBleMacAddress(const uint8_t *mac, size_t len) {
292293
bool res = false;
293294
if (len != BLE_MAC_ADDRESS_SIZE) {
294-
//DEBUG_ERROR("BoardConfigurationProtocol::%s Invalid BLE MAC address", __FUNCTION__);
295295
return res;
296296
}
297297

@@ -300,13 +300,12 @@ bool BoardConfigurationProtocol::sendBleMacAddress(const uint8_t *mac, size_t le
300300

301301
res = CBORAdapter::BLEMacAddressToCBOR(mac, data, &cborDataLen);
302302
if (!res) {
303-
//DEBUG_ERROR("BoardConfigurationProtocol::%s failed to convert BLE MAC address to CBOR", __FUNCTION__);
304303
return res;
305304
}
306305

307306
res = sendData(PacketManager::MessageType::DATA, data, cborDataLen);
308307
if (!res) {
309-
DEBUG_ERROR("BoardConfigurationProtocol::%s failed to send BLE MAC address", __FUNCTION__);
308+
DEBUG_WARNING("BoardConfigurationProtocol::%s failed to send BLE MAC address", __FUNCTION__);
310309
return res;
311310
}
312311
return res;
@@ -320,13 +319,12 @@ bool BoardConfigurationProtocol::sendWifiFWVersion(const char *wifiFWVersion) {
320319

321320
res = CBORAdapter::wifiFWVersionToCBOR(wifiFWVersion, data, &cborDataLen);
322321
if (!res) {
323-
DEBUG_ERROR("BoardConfigurationProtocol::%s failed to convert WiFi FW version to CBOR", __FUNCTION__);
324322
return res;
325323
}
326324

327325
res = sendData(PacketManager::MessageType::DATA, data, cborDataLen);
328326
if (!res) {
329-
DEBUG_ERROR("BoardConfigurationProtocol::%s failed to send WiFi FW version", __FUNCTION__);
327+
DEBUG_WARNING("BoardConfigurationProtocol::%s failed to send WiFi FW version", __FUNCTION__);
330328
return res;
331329
}
332330

src/ConfiguratorAgents/agents/BoardConfigurationProtocol/CBORAdapter.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ bool CBORAdapter::jwtToCBOR(const char *jwt, uint8_t *data, size_t *len) {
3535
CBORMessageEncoder encoder;
3636

3737
if (*len < CBOR_DATA_JWT_LEN || strlen(jwt) > MAX_JWT_SIZE) {
38-
//Serial.println("CBORAdapter jwtToCBOR: Invalid jwt size");
3938
return false;
4039
}
4140

src/ConfiguratorAgents/agents/BoardConfigurationProtocol/cbor/Decoder.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "ProvisioningMessage.h"
1414
#include <Arduino_CBOR.h>
1515

16-
// TODO better naming
1716
class TimestampProvisioningMessageDecoder: public CBORMessageDecoderInterface {
1817
public:
1918
TimestampProvisioningMessageDecoder()

src/ConfiguratorAgents/agents/BoardConfigurationProtocol/cbor/Encoder.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "ProvisioningMessage.h"
1313
#include <Arduino_CBOR.h>
1414

15-
// TODO better naming
1615
class StatusProvisioningMessageEncoder: public CBORMessageEncoderInterface {
1716
public:
1817
StatusProvisioningMessageEncoder()

src/ConfiguratorAgents/agents/BoardConfigurationProtocol/cbor/ProvisioningMessage.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#pragma once
1010
#include <stdint.h>
1111
#include <stddef.h>
12-
#include <Arduino_CBOR.h> // FIXME maybe include only message.h
12+
#include <Arduino_CBOR.h>
1313
#include <ConnectionHandlerDefinitions.h>
1414
#include <settings/settings.h>
1515
#include <ConfiguratorAgents/NetworkOptionsDefinitions.h>
@@ -31,9 +31,6 @@
3131
#define MAX_WIFI_NETWORKS 20
3232
#define MAX_IP_SIZE 16
3333

34-
// TODO may be move this?
35-
// TODO put values
36-
// TODO maybe you need to put tag in the name?
3734
enum CBORProvisioningMessageTag: CBORTag {
3835
CBORTimestampProvisioningMessage = 0x012002,
3936
CBORCommandsProvisioningMessage = 0x012003,
@@ -53,7 +50,6 @@ enum CBORProvisioningMessageTag: CBORTag {
5350
CBORWiFiFWVersionProvisioningMessage = 0x012014,
5451
};
5552

56-
// FIXME naming a little bit redundant
5753
enum ProvisioningMessageId: MessageId {
5854
/* Provisioning commands*/
5955
StatusProvisioningMessageId = ArduinoProvisioningStartMessageId,

0 commit comments

Comments
 (0)