Merge branch 'gateway'

This commit is contained in:
Nicu Hodos 2023-02-20 20:19:56 +01:00
commit bfe2280d16
7 changed files with 84 additions and 48 deletions

View File

@ -8,26 +8,34 @@ platform:
arch: arm arch: arm
steps: steps:
- name: static check
commands:
- cd gateway
- pio check -e pro-mini
when:
target:
exclude:
- production
- name: native tests - name: native tests
commands: commands:
- cd gateway - cd gateway
- pio test -e native - pio test -e native
when:
- name: embedded tests target:
commands: exclude:
- cd gateway - production
- LD_LIBRARY_PATH=~/.platformio/packages/tool-simavr/lib/ pio test -e embedded --without-uploading
- name: upload firmware - name: upload firmware
commands: commands:
- cd gateway - cd gateway
- service ser2net stop - service ser2net stop
- pio run -e pro-mini - pio run -e pro-mini
- echo -n 'reset' > /dev/ttyUSB0; sleep 1s; avrdude -patmega328p -carduino -P/dev/ttyUSB0 -b115200 -D -Uflash:w:.pio/build/pro-mini/firmware.hex:i -v - echo 'reset' > /dev/ttyUSB0; sleep 1s; avrdude -patmega328p -carduino -P/dev/ttyUSB0 -b115200 -D -Uflash:w:.pio/build/pro-mini/firmware.hex:i -v
- service ser2net start - service ser2net start
when: when:
branch: target:
- gateway - production
trigger: trigger:
branch: branch:

View File

@ -8,33 +8,46 @@
; Please visit documentation for the other options and examples ; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[platformio]
default_envs = pro-mini
[env:pro-mini] [env:pro-mini]
platform = atmelavr platform = atmelavr
board = miniatmega328 board = pro16MHzatmega328
framework = arduino framework = arduino
lib_extra_dirs = lib_extra_dirs =
../libraries ../libraries
lib_deps = lib_deps =
sui77/rc-switch@^2.6.3 sui77/rc-switch@^2.6.3
bblanchon/ArduinoJson@6.16.1 bblanchon/ArduinoJson@6.19.4
adafruit/Adafruit Unified Sensor@^1.1.4 adafruit/Adafruit Unified Sensor@^1.1.4
adafruit/DHT sensor library@1.3.10 adafruit/DHT sensor library@1.3.10
https://git.hodos.ro/arduino/lib_serial-reader.git@^1.0.0
build_flags = -D DHT_SENSOR=0 build_flags = -D DHT_SENSOR=0
upload_port = /dev/ttyUSB0 upload_port = /dev/ttyUSB0
check_tool = cppcheck
check_flags = --enable=all
check_skip_packages = yes
check_severity = medium, high
[env:native] [env:native]
platform = native platform = native
test_filter = test_native test_filter = native/*
lib_extra_dirs =
../libraries
lib_deps =
bblanchon/ArduinoJson@6.19.4
build_flags = -std=c++11
[env:embedded] [env:embedded]
platform = atmelavr platform = atmelavr
framework = arduino framework = arduino
board = miniatmega328 board = pro16MHzatmega328
lib_extra_dirs = lib_extra_dirs =
../libraries ../libraries
lib_deps = lib_deps =
sui77/rc-switch@^2.6.3 sui77/rc-switch@^2.6.3
bblanchon/ArduinoJson@6.16.1 bblanchon/ArduinoJson@6.19.4
platform_packages = platform_packages =
platformio/tool-simavr platformio/tool-simavr
@ -46,4 +59,4 @@ test_testing_command =
-f -f
16000000L 16000000L
${platformio.build_dir}/${this.__env__}/firmware.elf ${platformio.build_dir}/${this.__env__}/firmware.elf
test_filter = test_embedded test_filter = embedded/*

View File

@ -3,13 +3,15 @@
#include "Dht.h" #include "Dht.h"
#include "Protocol_1.h" #include "Protocol_1.h"
#include "Protocol_2.h" #include "Protocol_2.h"
#include <SerialReader.h>
#define RESET_PIN 10 #define RESET_PIN 10
#define SEND_PIN 11 #define SEND_PIN 11
#define RECEIVE_PIN 2 #define RECEIVE_PIN 2
RCSwitch mySwitch = RCSwitch(); RCSwitch mySwitch;
SerialReader<200> serialReader;
void setup() { void setup() {
digitalWrite(RESET_PIN, HIGH); digitalWrite(RESET_PIN, HIGH);
@ -49,7 +51,7 @@ void readRcSwitch() {
unsigned long value = mySwitch.getReceivedValue(); unsigned long value = mySwitch.getReceivedValue();
mySwitch.resetAvailable(); mySwitch.resetAvailable();
StaticJsonDocument<200> jsonDoc; StaticJsonDocument<128> jsonDoc;
Protocol* p = findProtocol(mySwitch.getReceivedProtocol()); Protocol* p = findProtocol(mySwitch.getReceivedProtocol());
p->toJson(value, jsonDoc); p->toJson(value, jsonDoc);
delete p; delete p;
@ -60,13 +62,19 @@ void readRcSwitch() {
} }
} }
void runJsonCommands(const char* cmd) { void handleJsonError(DeserializationError err, const char* cmd) {
String origCmd = String(cmd); StaticJsonDocument<50> jsonError;
StaticJsonDocument<512> jsonArray; JsonObject error = jsonError.createNestedObject("error");
DeserializationError err = deserializeJson(jsonArray, cmd); error["msg"] = err.c_str();
error["orig_cmd"] = cmd;
serializeJson(jsonError, Serial);
Serial.println();
}
void runJsonCommand(char* cmd) {
StaticJsonDocument<50> jsonDoc;
DeserializationError err = deserializeJson(jsonDoc, cmd);
if (err == DeserializationError::Ok) { if (err == DeserializationError::Ok) {
JsonArray array = jsonArray.as<JsonArray>();
for (JsonVariant jsonDoc : array) {
if (jsonDoc.containsKey("rcSwitch")) { if (jsonDoc.containsKey("rcSwitch")) {
JsonObjectConst rcSwitch = jsonDoc["rcSwitch"]; JsonObjectConst rcSwitch = jsonDoc["rcSwitch"];
Protocol* p = findProtocol(rcSwitch["protocol"]); Protocol* p = findProtocol(rcSwitch["protocol"]);
@ -75,29 +83,21 @@ void runJsonCommands(const char* cmd) {
serializeJson(jsonDoc, Serial); serializeJson(jsonDoc, Serial);
Serial.println(); Serial.println();
} }
}
} else { } else {
Serial.print(err.c_str()); handleJsonError(err, cmd);
Serial.print(": ");
Serial.println(origCmd);
} }
} }
void readCommand() { void readCommand() {
if (Serial.available() > 0) { if (serialReader.readLine(Serial) > 0) {
String cmd = Serial.readStringUntil('\n'); char* cmd = serialReader.getBuffer();
if (cmd == "reset") { if (strcmp("reset", cmd) == 0) {
Serial.println("resetting..."); Serial.println("resetting...");
delay(200); delay(1200);
digitalWrite(RESET_PIN, LOW); digitalWrite(RESET_PIN, LOW);
Serial.println("resetting failed"); Serial.println("resetting failed");
} }
if (cmd.endsWith(",")) { runJsonCommand(cmd);
cmd = cmd.substring(0, cmd.lastIndexOf(','));
}
char buffer[cmd.length()+2];
sprintf(buffer, "[%s]", cmd.c_str());
runJsonCommands(buffer);
} }
} }

View File

@ -0,0 +1,18 @@
#include <Arduino.h>
#include <unity.h>
void setUp(void) {
// set stuff up here
}
void tearDown(void) {
// clean stuff up here
}
void setup() {
UNITY_BEGIN();
UNITY_END();
}
void loop() {
}

View File

@ -1,4 +1,3 @@
#include <Arduino.h>
#include <unity.h> #include <unity.h>
#include "TinyComponent.h" #include "TinyComponent.h"
@ -98,7 +97,7 @@ void test_oil_sensor_with_voltage(void) {
TEST_ASSERT_EQUAL(2.847, diagnostic["voltage"]); TEST_ASSERT_EQUAL(2.847, diagnostic["voltage"]);
} }
void setup() { int main(int argc, char **argv) {
UNITY_BEGIN(); UNITY_BEGIN();
RUN_TEST(test_unknown_sensor_type); RUN_TEST(test_unknown_sensor_type);
RUN_TEST(test_max_temp); RUN_TEST(test_max_temp);
@ -110,7 +109,6 @@ void setup() {
RUN_TEST(test_oil_sensor); RUN_TEST(test_oil_sensor);
RUN_TEST(test_oil_sensor_with_voltage); RUN_TEST(test_oil_sensor_with_voltage);
UNITY_END(); UNITY_END();
}
void loop() { return 0;
} }

@ -1 +0,0 @@
Subproject commit cb04b381f9b68cf60cac7ecb18346fb3291a80a6