Skip to content

New version commands #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions extras/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ FetchContent_Declare(

FetchContent_Declare(
cloudutils
GIT_REPOSITORY https://github.com/andreagilardoni/Arduino_CloudUtils.git
GIT_TAG cbor-messages
GIT_REPOSITORY https://github.com/arduino-libraries/Arduino_CloudUtils.git
GIT_TAG main
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
)
Expand Down Expand Up @@ -125,12 +125,12 @@ set(TEST_TARGET_SRCS

##########################################################################

add_compile_definitions(BOARD_HAS_LORA BOARD_HAS_CATM1_NBIOT BOARD_HAS_WIFI BOARD_HAS_ETHERNET BOARD_HAS_CELLULAR BOARD_HAS_NB BOARD_HAS_GSM)
add_compile_definitions(CI_TEST BOARD_HAS_LORA BOARD_HAS_CATM1_NBIOT BOARD_HAS_WIFI BOARD_HAS_ETHERNET BOARD_HAS_CELLULAR BOARD_HAS_NB BOARD_HAS_GSM)
add_compile_options(-Wextra -Werror)
add_compile_options(-Wno-cast-function-type)

set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "--coverage")
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "--coverage -Wno-deprecated-copy")
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "--coverage -Wno-deprecated-copy -Wno-missing-field-initializers")

##########################################################################

Expand Down
1 change: 1 addition & 0 deletions extras/test/src/test_provisioning_command_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <Decoder.h>
#include <cbor/MessageDecoder.h>
#include "../../src/ConfiguratorAgents/agents/BoardConfigurationProtocol/cbor/CBOR.h"
#include "../../src/ConfiguratorAgents/agents/BoardConfigurationProtocol/cbor/CBORInstances.h"
#include <IPAddress.h>

/******************************************************************************
Expand Down
56 changes: 56 additions & 0 deletions extras/test/src/test_provisioning_command_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <Encoder.h>
#include <cbor/MessageEncoder.h>
#include "../../src/ConfiguratorAgents/agents/BoardConfigurationProtocol/cbor/CBOR.h"
#include "../../src/ConfiguratorAgents/agents/BoardConfigurationProtocol/cbor/CBORInstances.h"

/******************************************************************************
TEST CODE
Expand Down Expand Up @@ -233,4 +234,59 @@
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
}
}

WHEN("Encode a message with provisioning sketch version ")
{
ProvSketchVersionProvisioningMessage command;
command.c.id = ProvisioningMessageId::ProvSketchVersionProvisioningMessageId;
command.provSketchVersion = "1.6.0";
uint8_t buffer[512];
size_t bytes_encoded = sizeof(buffer);

CBORMessageEncoder encoder;
MessageEncoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);

uint8_t expected_result[] = {
0xda, 0x00, 0x01, 0x20, 0x15, 0x81, 0x65, 0x31, 0x2E, 0x36, 0x2E, 0x30
};

// Test the encoding is
// DA 00012015 # tag(73749)
// 81 # array(1)
// 65 # text(5)
// 312E362E30 # "1.6.0"
THEN("The encoding is successful") {
REQUIRE(err == MessageEncoder::Status::Complete);
REQUIRE(bytes_encoded == sizeof(expected_result));
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
}
}

WHEN("Encode a message with provisioning Network Configurator lib version ")
{
NetConfigLibVersionProvisioningMessage command;
command.c.id = ProvisioningMessageId::NetConfigLibVersProvisioningMessageId;
command.netConfigLibVersion = "1.6.0";
uint8_t buffer[512];
size_t bytes_encoded = sizeof(buffer);

CBORMessageEncoder encoder;
MessageEncoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);

uint8_t expected_result[] = {
0xda, 0x00, 0x01, 0x20, 0x16, 0x81, 0x65, 0x31, 0x2E, 0x36, 0x2E, 0x30
};

// Test the encoding is
// DA 00012016 # tag(73750)
// 81 # array(1)
// 65 # text(5)
// 312E362E30 # "1.6.0"
printf("res %d\n", (int)err);
THEN("The encoding is successful") {
REQUIRE(err == MessageEncoder::Status::Complete);
REQUIRE(bytes_encoded == sizeof(expected_result));
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
}
}
}
12 changes: 10 additions & 2 deletions src/ANetworkConfigurator_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
*/
#pragma once

#define NETWORK_CONFIGURATOR_COMPATIBLE 0
#define ZERO_TOUCH_ENABLED 0
#define ANetworkConfigurator_LIB_VERSION "0.1.0"

#if defined(ARDUINO_SAMD_MKRWIFI1010)
#define NETWORK_CONFIGURATOR_COMPATIBLE 1
Expand Down Expand Up @@ -119,6 +118,15 @@
#define LED_OFF HIGH
#endif

#ifdef CI_TEST
#define NETWORK_CONFIGURATOR_COMPATIBLE 1
#endif

#ifndef NETWORK_CONFIGURATOR_COMPATIBLE
#define NETWORK_CONFIGURATOR_COMPATIBLE 0
#define ZERO_TOUCH_ENABLED 0
#endif

#ifndef RESET_HOLD_TIME
#define RESET_HOLD_TIME 3000000
#endif
Expand Down
21 changes: 17 additions & 4 deletions src/Arduino_NetworkConfigurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ bool NetworkConfiguratorClass::begin() {

_agentsManager->addRequestHandler(RequestType::GET_WIFI_FW_VERSION, getWiFiFWVersionHandler);

_agentsManager->addRequestHandler(RequestType::GET_NETCONFIG_LIB_VERSION, getNetConfLibVersionHandler);

if (!_agentsManager->begin()) {
DEBUG_ERROR("NetworkConfiguratorClass::%s Failed to initialize the AgentsManagerClass", __FUNCTION__);
}
Expand Down Expand Up @@ -343,6 +345,10 @@ void NetworkConfiguratorClass::getWiFiFWVersionHandler() {
_receivedEvent = NetworkConfiguratorEvents::GET_WIFI_FW_VERSION;
}

void NetworkConfiguratorClass::getNetConfLibVersionHandler() {
_receivedEvent = NetworkConfiguratorEvents::GET_NET_CONF_LIB_VERSION;
}

bool NetworkConfiguratorClass::handleConnectRequest() {
if (_networkSetting.type == NetworkAdapter::NONE) {
sendStatus(StatusMessage::PARAMS_NOT_FOUND);
Expand Down Expand Up @@ -419,6 +425,12 @@ void NetworkConfiguratorClass::handleGetWiFiFWVersion() {
_agentsManager->sendMsg(fwVersionMsg);
}

void NetworkConfiguratorClass::handleGetNetConfLibVersion() {
ProvisioningOutputMessage libVersionMsg = { MessageOutputType::NETCONFIG_LIB_VERSION };
libVersionMsg.m.netConfigLibVersion = ANetworkConfigurator_LIB_VERSION;
_agentsManager->sendMsg(libVersionMsg);
}

void NetworkConfiguratorClass::startReconfigureProcedure() {
resetStoredConfiguration();
// Set to restart the BLE after reboot
Expand Down Expand Up @@ -507,10 +519,11 @@ NetworkConfiguratorStates NetworkConfiguratorClass::handleWaitingForConf() {
_agentsManager->update();
bool connecting = false;
switch (_receivedEvent) {
case NetworkConfiguratorEvents::SCAN_REQ: scanNetworkOptions (); break;
case NetworkConfiguratorEvents::CONNECT_REQ: connecting = handleConnectRequest (); break;
case NetworkConfiguratorEvents::GET_WIFI_FW_VERSION: handleGetWiFiFWVersion(); break;
case NetworkConfiguratorEvents::NEW_NETWORK_SETTINGS: break;
case NetworkConfiguratorEvents::SCAN_REQ: scanNetworkOptions (); break;
case NetworkConfiguratorEvents::CONNECT_REQ: connecting = handleConnectRequest (); break;
case NetworkConfiguratorEvents::GET_WIFI_FW_VERSION: handleGetWiFiFWVersion (); break;
case NetworkConfiguratorEvents::GET_NET_CONF_LIB_VERSION: handleGetNetConfLibVersion(); break;
case NetworkConfiguratorEvents::NEW_NETWORK_SETTINGS: break;
}
_receivedEvent = NetworkConfiguratorEvents::NONE;

Expand Down
5 changes: 4 additions & 1 deletion src/Arduino_NetworkConfigurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ class NetworkConfiguratorClass {
SCAN_REQ,
CONNECT_REQ,
NEW_NETWORK_SETTINGS,
GET_WIFI_FW_VERSION };
GET_WIFI_FW_VERSION,
GET_NET_CONF_LIB_VERSION };
static inline NetworkConfiguratorEvents _receivedEvent;

enum class ConnectionResult { SUCCESS,
Expand All @@ -193,6 +194,7 @@ class NetworkConfiguratorClass {
NetworkConfiguratorStates handleErrorState();
bool handleConnectRequest();
void handleGetWiFiFWVersion();
void handleGetNetConfLibVersion();

void startReconfigureProcedure();

Expand All @@ -213,6 +215,7 @@ class NetworkConfiguratorClass {
static void connectReqHandler();
static void setNetworkSettingsHandler(models::NetworkSetting *netSetting);
static void getWiFiFWVersionHandler();
static void getNetConfLibVersionHandler();
};

#endif // NETWORK_CONFIGURATOR_COMPATIBLE
26 changes: 15 additions & 11 deletions src/ConfiguratorAgents/AgentsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,13 @@ void AgentsManagerClass::updateProgressRequest(StatusMessage type) {
void AgentsManagerClass::updateProgressRequest(MessageOutputType type) {
RequestType key = RequestType::NONE;
switch (type) {
case MessageOutputType::NETWORK_OPTIONS: key = RequestType::SCAN ; break;
case MessageOutputType::UHWID: key = RequestType::GET_ID ; break;
case MessageOutputType::JWT: key = RequestType::GET_ID ; break;
case MessageOutputType::BLE_MAC_ADDRESS: key = RequestType::GET_BLE_MAC_ADDRESS; break;
case MessageOutputType::WIFI_FW_VERSION: key = RequestType::GET_WIFI_FW_VERSION; break;
case MessageOutputType::NETWORK_OPTIONS: key = RequestType::SCAN ; break;
case MessageOutputType::UHWID: key = RequestType::GET_ID ; break;
case MessageOutputType::JWT: key = RequestType::GET_ID ; break;
case MessageOutputType::BLE_MAC_ADDRESS: key = RequestType::GET_BLE_MAC_ADDRESS ; break;
case MessageOutputType::WIFI_FW_VERSION: key = RequestType::GET_WIFI_FW_VERSION ; break;
case MessageOutputType::PROV_SKETCH_VERSION: key = RequestType::GET_PROVISIONING_SKETCH_VERSION; break;
case MessageOutputType::NETCONFIG_LIB_VERSION: key = RequestType::GET_NETCONFIG_LIB_VERSION ; break;
}

if (key == RequestType::NONE) {
Expand Down Expand Up @@ -336,12 +338,14 @@ void AgentsManagerClass::handleReceivedCommands(RemoteCommands cmd) {

RequestType type = RequestType::NONE;
switch (cmd) {
case RemoteCommands::CONNECT: type = RequestType::CONNECT ; break;
case RemoteCommands::SCAN: type = RequestType::SCAN ; break;
case RemoteCommands::GET_ID: type = RequestType::GET_ID ; break;
case RemoteCommands::GET_BLE_MAC_ADDRESS: type = RequestType::GET_BLE_MAC_ADDRESS; break;
case RemoteCommands::RESET: type = RequestType::RESET ; break;
case RemoteCommands::GET_WIFI_FW_VERSION: type = RequestType::GET_WIFI_FW_VERSION; break;
case RemoteCommands::CONNECT: type = RequestType::CONNECT ; break;
case RemoteCommands::SCAN: type = RequestType::SCAN ; break;
case RemoteCommands::GET_ID: type = RequestType::GET_ID ; break;
case RemoteCommands::GET_BLE_MAC_ADDRESS: type = RequestType::GET_BLE_MAC_ADDRESS ; break;
case RemoteCommands::RESET: type = RequestType::RESET ; break;
case RemoteCommands::GET_WIFI_FW_VERSION: type = RequestType::GET_WIFI_FW_VERSION ; break;
case RemoteCommands::GET_PROVISIONING_SKETCH_VERSION: type = RequestType::GET_PROVISIONING_SKETCH_VERSION; break;
case RemoteCommands::GET_NETCONFIG_LIB_VERSION: type = RequestType::GET_NETCONFIG_LIB_VERSION ; break;
}

if(type == RequestType::NONE) {
Expand Down
6 changes: 4 additions & 2 deletions src/ConfiguratorAgents/AgentsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ enum class RequestType: int { NONE = -1,
GET_ID = 2,
RESET = 3,
GET_WIFI_FW_VERSION = 4,
GET_BLE_MAC_ADDRESS = 5 };
GET_BLE_MAC_ADDRESS = 5,
GET_PROVISIONING_SKETCH_VERSION = 6,
GET_NETCONFIG_LIB_VERSION = 7};

/**
* @class AgentsManagerClass
Expand Down Expand Up @@ -209,7 +211,7 @@ class AgentsManagerClass {
AgentsManagerStates _state;
std::list<ConfiguratorAgent *> _agentsList;
bool _enabledAgents[2];
ConfiguratorRequestHandler _reqHandlers[6];
ConfiguratorRequestHandler _reqHandlers[8];
ReturnTimestamp _returnTimestampCb;
ReturnNetworkSettings _returnNetworkSettingsCb;
ConfiguratorAgent *_selectedAgent;
Expand Down
20 changes: 13 additions & 7 deletions src/ConfiguratorAgents/MessagesDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ enum class StatusMessage {
};

/* Commands codes */
enum class RemoteCommands { CONNECT = 1,
GET_ID = 2,
GET_BLE_MAC_ADDRESS = 3,
RESET = 4,
SCAN = 100,
GET_WIFI_FW_VERSION = 101
enum class RemoteCommands { CONNECT = 1,
GET_ID = 2,
GET_BLE_MAC_ADDRESS = 3,
RESET = 4,
SCAN = 100,
GET_WIFI_FW_VERSION = 101,
GET_PROVISIONING_SKETCH_VERSION = 200,
GET_NETCONFIG_LIB_VERSION = 201,
};

/* Types of outgoing messages */
Expand All @@ -56,7 +58,9 @@ enum class MessageOutputType { STATUS,
UHWID,
JWT,
BLE_MAC_ADDRESS,
WIFI_FW_VERSION
WIFI_FW_VERSION,
PROV_SKETCH_VERSION,
NETCONFIG_LIB_VERSION,
};

/* Types of ingoing messages */
Expand All @@ -80,6 +84,8 @@ struct ProvisioningOutputMessage {
const char *jwt;
const uint8_t *BLEMacAddress;
const char *wifiFwVersion;
const char *provSketchVersion;
const char *netConfigLibVersion;
} m;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ bool BoardConfigurationProtocol::sendMsg(ProvisioningOutputMessage &msg) {
res = sendBleMacAddress(msg.m.BLEMacAddress, BLE_MAC_ADDRESS_SIZE);
break;
case MessageOutputType::WIFI_FW_VERSION:
res = sendWifiFWVersion(msg.m.wifiFwVersion);
res = sendVersion(msg.m.wifiFwVersion, msg.type);
break;
case MessageOutputType::PROV_SKETCH_VERSION:
res = sendVersion(msg.m.provSketchVersion, msg.type);
break;
case MessageOutputType::NETCONFIG_LIB_VERSION:
res = sendVersion(msg.m.netConfigLibVersion, msg.type);
break;
default:
break;
Expand Down Expand Up @@ -310,21 +316,27 @@ bool BoardConfigurationProtocol::sendBleMacAddress(const uint8_t *mac, size_t le
return res;
}

bool BoardConfigurationProtocol::sendWifiFWVersion(const char *wifiFWVersion) {
bool BoardConfigurationProtocol::sendVersion(const char *version, MessageOutputType type) {
bool res = false;

size_t cborDataLen = CBOR_MIN_WIFI_FW_VERSION_LEN + strlen(wifiFWVersion);
size_t cborDataLen = CBOR_MIN_WIFI_FW_VERSION_LEN + strlen(version);
uint8_t data[cborDataLen];

res = CBORAdapter::wifiFWVersionToCBOR(wifiFWVersion, data, &cborDataLen);
switch (type)
{
case MessageOutputType::WIFI_FW_VERSION: res = CBORAdapter::wifiFWVersionToCBOR (version, data, &cborDataLen); break;
case MessageOutputType::PROV_SKETCH_VERSION: res = CBORAdapter::provSketchVersionToCBOR (version, data, &cborDataLen); break;
case MessageOutputType::NETCONFIG_LIB_VERSION: res = CBORAdapter::netConfigLibVersionToCBOR(version, data, &cborDataLen); break;
default: return false;
}

if (!res) {
return res;
}

res = sendData(PacketManager::MessageType::DATA, data, cborDataLen);
if (!res) {
DEBUG_WARNING("BoardConfigurationProtocol::%s failed to send WiFi FW version", __FUNCTION__);
return res;
DEBUG_WARNING("BoardConfigurationProtocol::%s failed to send version of type %d", __FUNCTION__, (int)type);
}

return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class BoardConfigurationProtocol {
bool sendUhwid(const byte *uhwid);
bool sendJwt(const char *jwt, size_t len);
bool sendBleMacAddress(const uint8_t *mac, size_t len);
bool sendWifiFWVersion(const char *wifiFWVersion);
bool sendVersion(const char *version, MessageOutputType type);
TransmissionResult transmitStream();
void printPacket(const char *label, const uint8_t *data, size_t len);
std::list<OutputPacketBuffer> _outputMessagesList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,34 @@ bool CBORAdapter::wifiFWVersionToCBOR(const char *wifiFWVersion, uint8_t *data,
return status == MessageEncoder::Status::Complete ? true : false;
}

bool CBORAdapter::provSketchVersionToCBOR(const char *provSketchVersion, uint8_t *data, size_t *len) {
CBORMessageEncoder encoder;
if(*len < CBOR_MIN_PROV_SKETCH_VERSION_LEN + strlen(provSketchVersion)) {
return false;
}
ProvSketchVersionProvisioningMessage provSketchVersionMsg;
provSketchVersionMsg.c.id = ProvisioningMessageId::ProvSketchVersionProvisioningMessageId;
provSketchVersionMsg.provSketchVersion = provSketchVersion;

MessageEncoder::Status status = encoder.encode((Message *)&provSketchVersionMsg, data, *len);

return status == MessageEncoder::Status::Complete ? true : false;
}

bool CBORAdapter::netConfigLibVersionToCBOR(const char *netConfigLibVersion, uint8_t *data, size_t *len) {
CBORMessageEncoder encoder;
if(*len < CBOR_MIN_NETCONFIG_LIB_VERSION_LEN + strlen(netConfigLibVersion)) {
return false;
}
NetConfigLibVersionProvisioningMessage netConfigLibVersionMsg;
netConfigLibVersionMsg.c.id = ProvisioningMessageId::NetConfigLibVersProvisioningMessageId;
netConfigLibVersionMsg.netConfigLibVersion = netConfigLibVersion;

MessageEncoder::Status status = encoder.encode((Message *)&netConfigLibVersionMsg, data, *len);

return status == MessageEncoder::Status::Complete ? true : false;
}

bool CBORAdapter::networkOptionsToCBOR(const NetworkOptions *netOptions, uint8_t *data, size_t *len) {
bool result = false;
switch (netOptions->type) {
Expand Down
Loading
Loading