Merge branch 'gateway'
This commit is contained in:
commit
bfe2280d16
24
.drone.yml
24
.drone.yml
@ -8,26 +8,34 @@ platform:
|
||||
arch: arm
|
||||
|
||||
steps:
|
||||
- name: static check
|
||||
commands:
|
||||
- cd gateway
|
||||
- pio check -e pro-mini
|
||||
when:
|
||||
target:
|
||||
exclude:
|
||||
- production
|
||||
|
||||
- name: native tests
|
||||
commands:
|
||||
- cd gateway
|
||||
- pio test -e native
|
||||
|
||||
- name: embedded tests
|
||||
commands:
|
||||
- cd gateway
|
||||
- LD_LIBRARY_PATH=~/.platformio/packages/tool-simavr/lib/ pio test -e embedded --without-uploading
|
||||
when:
|
||||
target:
|
||||
exclude:
|
||||
- production
|
||||
|
||||
- name: upload firmware
|
||||
commands:
|
||||
- cd gateway
|
||||
- service ser2net stop
|
||||
- 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
|
||||
when:
|
||||
branch:
|
||||
- gateway
|
||||
target:
|
||||
- production
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
|
||||
@ -8,33 +8,46 @@
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[platformio]
|
||||
default_envs = pro-mini
|
||||
|
||||
[env:pro-mini]
|
||||
platform = atmelavr
|
||||
board = miniatmega328
|
||||
board = pro16MHzatmega328
|
||||
framework = arduino
|
||||
lib_extra_dirs =
|
||||
../libraries
|
||||
lib_deps =
|
||||
sui77/rc-switch@^2.6.3
|
||||
bblanchon/ArduinoJson@6.16.1
|
||||
bblanchon/ArduinoJson@6.19.4
|
||||
adafruit/Adafruit Unified Sensor@^1.1.4
|
||||
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
|
||||
upload_port = /dev/ttyUSB0
|
||||
check_tool = cppcheck
|
||||
check_flags = --enable=all
|
||||
check_skip_packages = yes
|
||||
check_severity = medium, high
|
||||
|
||||
[env: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]
|
||||
platform = atmelavr
|
||||
framework = arduino
|
||||
board = miniatmega328
|
||||
board = pro16MHzatmega328
|
||||
lib_extra_dirs =
|
||||
../libraries
|
||||
lib_deps =
|
||||
sui77/rc-switch@^2.6.3
|
||||
bblanchon/ArduinoJson@6.16.1
|
||||
bblanchon/ArduinoJson@6.19.4
|
||||
|
||||
platform_packages =
|
||||
platformio/tool-simavr
|
||||
@ -46,4 +59,4 @@ test_testing_command =
|
||||
-f
|
||||
16000000L
|
||||
${platformio.build_dir}/${this.__env__}/firmware.elf
|
||||
test_filter = test_embedded
|
||||
test_filter = embedded/*
|
||||
|
||||
@ -3,13 +3,15 @@
|
||||
#include "Dht.h"
|
||||
#include "Protocol_1.h"
|
||||
#include "Protocol_2.h"
|
||||
#include <SerialReader.h>
|
||||
|
||||
#define RESET_PIN 10
|
||||
#define SEND_PIN 11
|
||||
#define RECEIVE_PIN 2
|
||||
|
||||
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
RCSwitch mySwitch;
|
||||
SerialReader<200> serialReader;
|
||||
|
||||
void setup() {
|
||||
digitalWrite(RESET_PIN, HIGH);
|
||||
@ -49,7 +51,7 @@ void readRcSwitch() {
|
||||
unsigned long value = mySwitch.getReceivedValue();
|
||||
mySwitch.resetAvailable();
|
||||
|
||||
StaticJsonDocument<200> jsonDoc;
|
||||
StaticJsonDocument<128> jsonDoc;
|
||||
Protocol* p = findProtocol(mySwitch.getReceivedProtocol());
|
||||
p->toJson(value, jsonDoc);
|
||||
delete p;
|
||||
@ -60,44 +62,42 @@ void readRcSwitch() {
|
||||
}
|
||||
}
|
||||
|
||||
void runJsonCommands(const char* cmd) {
|
||||
String origCmd = String(cmd);
|
||||
StaticJsonDocument<512> jsonArray;
|
||||
DeserializationError err = deserializeJson(jsonArray, cmd);
|
||||
void handleJsonError(DeserializationError err, const char* cmd) {
|
||||
StaticJsonDocument<50> jsonError;
|
||||
JsonObject error = jsonError.createNestedObject("error");
|
||||
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) {
|
||||
JsonArray array = jsonArray.as<JsonArray>();
|
||||
for (JsonVariant jsonDoc : array) {
|
||||
if (jsonDoc.containsKey("rcSwitch")) {
|
||||
JsonObjectConst rcSwitch = jsonDoc["rcSwitch"];
|
||||
Protocol* p = findProtocol(rcSwitch["protocol"]);
|
||||
p->fromJson(rcSwitch, mySwitch);
|
||||
delete p;
|
||||
serializeJson(jsonDoc, Serial);
|
||||
Serial.println();
|
||||
}
|
||||
if (jsonDoc.containsKey("rcSwitch")) {
|
||||
JsonObjectConst rcSwitch = jsonDoc["rcSwitch"];
|
||||
Protocol* p = findProtocol(rcSwitch["protocol"]);
|
||||
p->fromJson(rcSwitch, mySwitch);
|
||||
delete p;
|
||||
serializeJson(jsonDoc, Serial);
|
||||
Serial.println();
|
||||
}
|
||||
} else {
|
||||
Serial.print(err.c_str());
|
||||
Serial.print(": ");
|
||||
Serial.println(origCmd);
|
||||
handleJsonError(err, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void readCommand() {
|
||||
if (Serial.available() > 0) {
|
||||
String cmd = Serial.readStringUntil('\n');
|
||||
if (cmd == "reset") {
|
||||
if (serialReader.readLine(Serial) > 0) {
|
||||
char* cmd = serialReader.getBuffer();
|
||||
if (strcmp("reset", cmd) == 0) {
|
||||
Serial.println("resetting...");
|
||||
delay(200);
|
||||
delay(1200);
|
||||
digitalWrite(RESET_PIN, LOW);
|
||||
Serial.println("resetting failed");
|
||||
}
|
||||
if (cmd.endsWith(",")) {
|
||||
cmd = cmd.substring(0, cmd.lastIndexOf(','));
|
||||
}
|
||||
char buffer[cmd.length()+2];
|
||||
sprintf(buffer, "[%s]", cmd.c_str());
|
||||
runJsonCommands(buffer);
|
||||
runJsonCommand(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
18
gateway/test/embedded/test_dummy/dummy.cpp
Normal file
18
gateway/test/embedded/test_dummy/dummy.cpp
Normal 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() {
|
||||
}
|
||||
@ -1,4 +1,3 @@
|
||||
#include <Arduino.h>
|
||||
#include <unity.h>
|
||||
#include "TinyComponent.h"
|
||||
|
||||
@ -98,7 +97,7 @@ void test_oil_sensor_with_voltage(void) {
|
||||
TEST_ASSERT_EQUAL(2.847, diagnostic["voltage"]);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
int main(int argc, char **argv) {
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_unknown_sensor_type);
|
||||
RUN_TEST(test_max_temp);
|
||||
@ -110,7 +109,6 @@ void setup() {
|
||||
RUN_TEST(test_oil_sensor);
|
||||
RUN_TEST(test_oil_sensor_with_voltage);
|
||||
UNITY_END();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
return 0;
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
Subproject commit cb04b381f9b68cf60cac7ecb18346fb3291a80a6
|
||||
Loading…
x
Reference in New Issue
Block a user