Implement Improv via Serial component (#2423)

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
Jesse Hills
2021-11-11 08:55:45 +13:00
committed by GitHub
parent 0bdb48bcac
commit 5ff7c8418c
17 changed files with 391 additions and 14 deletions
+7 -5
View File
@@ -7,11 +7,13 @@ ImprovCommand parse_improv_data(const std::vector<uint8_t> &data) {
}
ImprovCommand parse_improv_data(const uint8_t *data, size_t length) {
ImprovCommand improv_command;
Command command = (Command) data[0];
uint8_t data_length = data[1];
if (data_length != length - 3) {
return {.command = UNKNOWN};
improv_command.command = UNKNOWN;
return improv_command;
}
uint8_t checksum = data[length - 1];
@@ -22,7 +24,8 @@ ImprovCommand parse_improv_data(const uint8_t *data, size_t length) {
}
if ((uint8_t) calculated_checksum != checksum) {
return {.command = BAD_CHECKSUM};
improv_command.command = BAD_CHECKSUM;
return improv_command;
}
if (command == WIFI_SETTINGS) {
@@ -39,9 +42,8 @@ ImprovCommand parse_improv_data(const uint8_t *data, size_t length) {
return {.command = command, .ssid = ssid, .password = password};
}
return {
.command = command,
};
improv_command.command = command;
return improv_command;
}
std::vector<uint8_t> build_rpc_response(Command command, const std::vector<std::string> &datum) {
+6 -4
View File
@@ -1,8 +1,8 @@
#pragma once
#ifdef USE_ARDUINO
#ifdef ARDUINO
#include "WString.h"
#endif // USE_ARDUINO
#endif // ARDUINO
#include <cstdint>
#include <string>
@@ -38,6 +38,8 @@ enum Command : uint8_t {
UNKNOWN = 0x00,
WIFI_SETTINGS = 0x01,
IDENTIFY = 0x02,
GET_CURRENT_STATE = 0x02,
GET_DEVICE_INFO = 0x03,
BAD_CHECKSUM = 0xFF,
};
@@ -53,8 +55,8 @@ ImprovCommand parse_improv_data(const std::vector<uint8_t> &data);
ImprovCommand parse_improv_data(const uint8_t *data, size_t length);
std::vector<uint8_t> build_rpc_response(Command command, const std::vector<std::string> &datum);
#ifdef USE_ARDUINO
#ifdef ARDUINO
std::vector<uint8_t> build_rpc_response(Command command, const std::vector<String> &datum);
#endif // USE_ARDUINO
#endif // ARDUINO
} // namespace improv