Compare commits

9 Commits

Author SHA1 Message Date
8cd866d16d Run test on native environment
Some checks failed
PlatformIO CI / build (push) Failing after 1m3s
2024-04-10 21:17:37 +10:00
38d91e6c30 WIP: Create Workflow for Gitea
Bump python version in workflow

Try different container
2024-04-10 21:15:20 +10:00
88caab56a2 Commit generated .vscode/extensions.json 2024-04-10 21:14:04 +10:00
d3325b71cd Fixes to unit tests to work on native platform 2024-04-10 21:13:45 +10:00
3d315be27f Add a native environment to platformio.ini 2024-04-10 21:12:33 +10:00
71dbf1f4ca Rename runParseUnityTests to just runUnityTests 2024-04-10 21:11:12 +10:00
7f7e02a8b7 Avoid including Arduino.h where possible 2024-04-10 21:10:31 +10:00
746d0fad6f Create initial tests
Tests are run via a PlatformIO project
2024-04-09 00:31:46 +10:00
4460224202 Reformat library.json 2024-04-04 21:50:14 +11:00
10 changed files with 274 additions and 30 deletions

View File

@@ -0,0 +1,25 @@
name: PlatformIO CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
container: catthehacker/ubuntu:act-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio
- uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install PlatformIO Core
run: pip install --upgrade platformio
- name: Build PlatformIO Project
run: pio test --environment native

10
.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}

View File

@@ -1,7 +1,7 @@
#ifndef BUFFERFILLER_H #ifndef BUFFERFILLER_H
#define BUFFERFILLER_H #define BUFFERFILLER_H
#include <Arduino.h> #include <stdint.h>
#include "PacketCRC.h" #include "PacketCRC.h"
#include "PacketTypes.h" #include "PacketTypes.h"

View File

@@ -1,7 +1,7 @@
#ifndef PACKET_PARSER_H #ifndef PACKET_PARSER_H
#define PACKET_PARSER_H #define PACKET_PARSER_H
#include <Arduino.h> #include <vector>
#include "PacketTypes.h" #include "PacketTypes.h"
class PacketParser { class PacketParser {

View File

@@ -1,7 +1,7 @@
#ifndef PACKET_TYPES_H #ifndef PACKET_TYPES_H
#define PACKET_TYPES_H #define PACKET_TYPES_H
#include <Arduino.h> #include <stdint.h>
#include <variant> #include <variant>
// Define packet types // Define packet types

View File

@@ -1,7 +1,7 @@
#ifndef RFPOWERVIEW_H #ifndef RFPOWERVIEW_H
#define RFPOWERVIEW_H #define RFPOWERVIEW_H
#include <Arduino.h> #include <stdint.h>
#include <RF24.h> #include <RF24.h>
#include "PacketReceiver.h" #include "PacketReceiver.h"
#include "PacketParser.h" #include "PacketParser.h"

View File

@@ -1,27 +1,24 @@
{ {
"name": "RFPowerView", "name": "RFPowerView",
"version": "0.0.3", "version": "0.0.3",
"description": "A library for receiving and sending PowerView packets via an nRF24L01 module", "description": "A library for receiving and sending PowerView packets via an nRF24L01 module",
"keywords": "powerview, hunterdouglas, luxaflex, rf, radio", "keywords": "powerview, hunterdouglas, luxaflex, rf, radio",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/mattyway/RFPowerView.git" "url": "https://github.com/mattyway/RFPowerView.git"
}, },
"authors": "authors": [
[ {
{ "name": "Matt Way",
"name": "Matt Way", "email": "mattyway@gmail.com"
"email": "mattyway@gmail.com" }
} ],
], "license": "GPL-2.0-only",
"license": "GPL-2.0-only", "dependencies": {
"dependencies": { "robtillaart/CRC": "1.0.2",
"robtillaart/CRC": "1.0.2", "nrf24/RF24": "1.4.8",
"nrf24/RF24": "1.4.8", "rlogiacco/CircularBuffer": "1.3.3"
"rlogiacco/CircularBuffer": "1.3.3" },
}, "frameworks": "arduino",
"frameworks": "arduino", "platforms": ["espressif8266"]
"platforms": [ }
"espressif8266"
]
}

33
platformio.ini Normal file
View File

@@ -0,0 +1,33 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
[env]
monitor_speed = 115200
test_build_src = true
test_framework = unity
lib_deps =
robtillaart/CRC @ 1.0.2
nrf24/RF24 @ 1.4.8
rlogiacco/CircularBuffer @ 1.3.3
[env:native]
platform = native
lib_deps =
${env.lib_deps}
ArduinoFake
build_src_filter =
+<**/*.cpp>
-<**/RFPowerView.cpp>
-<**/PacketReceiver.cpp>

View File

@@ -0,0 +1,98 @@
#include <unity.h>
#include <Arduino.h>
#include "PacketCRC.h"
void setUp()
{
}
void tearDown()
{
}
void run_calculate_test(const uint8_t *packet_data, const uint16_t expected_checksum)
{
PacketCRC packetCRC;
uint16_t actual_checksum = packetCRC.calculate(packet_data);
TEST_ASSERT_EQUAL_UINT16(expected_checksum, actual_checksum);
}
void test_calculate_withDataLengthOf15()
{
const uint8_t packet_data[] = {0xC0, 0x0F, 0x00, 0x05, 0xA1, 0xFF, 0xFF, 0x00, 0x00, 0x86, 0x04, 0xFF, 0x00, 0x00, 0x53, 0x47, 0x1B};
const uint16_t expected_checksum = 0x446B;
run_calculate_test(packet_data, expected_checksum);
}
void test_calculate_withDataLengthOf17()
{
const uint8_t packet_data[] = {0xC0, 0x11, 0x00, 0x05, 0xD7, 0xFF, 0xFF, 0x36, 0x9E, 0x86, 0x06, 0xB3, 0x04, 0x00, 0x36, 0x9E, 0x52, 0x53, 0x00};
const uint16_t expected_checksum = 0xE04C;
run_calculate_test(packet_data, expected_checksum);
}
void test_calculate_withDataLengthOf19()
{
const uint8_t packet_data[] = {0xC0, 0x13, 0x00, 0x05, 0xDD, 0xFF, 0xFF, 0x00, 0x00, 0x86, 0x05, 0x36, 0x4E, 0xF1, 0x00, 0x00, 0x3F, 0x5A, 0x02, 0x3F, 0x42};
const uint16_t expected_checksum = 0x9BD3;
run_calculate_test(packet_data, expected_checksum);
}
void test_calculate_withDataLengthOf20()
{
const uint8_t packet_data[] = {0xC0, 0x14, 0x10, 0x05, 0x59, 0xFF, 0xFF, 0x4E, 0xF1, 0x86, 0x05, 0xC2, 0x00, 0x00, 0x4E, 0xF1, 0x21, 0x5A, 0x03, 0x21, 0x42, 0x9C};
const uint16_t expected_checksum = 0x4A8B;
run_calculate_test(packet_data, expected_checksum);
}
void test_calculate_withDataLengthOf21()
{
const uint8_t packet_data[] = {0xC0, 0x15, 0x10, 0x05, 0xEA, 0xFF, 0xFF, 0x4E, 0xF1, 0x86, 0x05, 0x24, 0x00, 0x00, 0x4E, 0xF1, 0x21, 0x46, 0x4E, 0x98, 0x07, 0x08, 0x01};
const uint16_t expected_checksum = 0x9887;
run_calculate_test(packet_data, expected_checksum);
}
void test_calculate_withDataLengthOf25()
{
const uint8_t packet_data[] = {0xC0, 0x19, 0x00, 0x05, 0x47, 0xFF, 0xFF, 0x00, 0x00, 0x86, 0x05, 0x3D, 0x4E, 0xF1, 0x00, 0x00, 0x3F, 0x5A, 0x02, 0x3F, 0x50, 0x02, 0x3F, 0x4D, 0x02, 0x3F, 0x54};
const uint16_t expected_checksum = 0x8318;
run_calculate_test(packet_data, expected_checksum);
}
int runUnityTests(void)
{
UNITY_BEGIN();
RUN_TEST(test_calculate_withDataLengthOf15);
RUN_TEST(test_calculate_withDataLengthOf17);
RUN_TEST(test_calculate_withDataLengthOf19);
RUN_TEST(test_calculate_withDataLengthOf20);
RUN_TEST(test_calculate_withDataLengthOf21);
RUN_TEST(test_calculate_withDataLengthOf25);
return UNITY_END();
}
/**
* For Arduino framework
*/
void setup()
{
// Wait ~2 seconds before the Unity test runner
// establishes connection with a board Serial interface
delay(2000);
runUnityTests();
}
void loop() {}
int main(void)
{
return runUnityTests();
}

View File

@@ -0,0 +1,81 @@
#include <unity.h>
#include <Arduino.h>
#include "PacketParser.h"
void setUp()
{
}
void tearDown()
{
}
void run_parse_test(const uint8_t *packet_data, Packet &packet)
{
PacketParser packetParser;
bool result = packetParser.parsePacket(packet_data, packet);
TEST_ASSERT_TRUE(result);
}
void test_parse_stop()
{
const uint8_t packet_data[] = {0xC0, 0x11, 0x00, 0x05, 0x6C, 0xFF, 0xFF, 0x36, 0x9E, 0x86, 0x06, 0x3C, 0x04, 0x00, 0x36, 0x9E, 0x52, 0x53, 0x00};
Packet packet;
run_parse_test(packet_data, packet);
TEST_ASSERT_TRUE(packet.type == PacketType::STOP);
}
void test_parse_close()
{
const uint8_t packet_data[] = {0xC0, 0x11, 0x00, 0x05, 0x6C, 0xFF, 0xFF, 0x36, 0x9E, 0x86, 0x06, 0x3C, 0x04, 0x00, 0x36, 0x9E, 0x52, 0x44, 0x00};
Packet packet;
run_parse_test(packet_data, packet);
TEST_ASSERT_TRUE(packet.type == PacketType::CLOSE);
}
void test_parse_open()
{
const uint8_t packet_data[] = {0xC0, 0x11, 0x00, 0x05, 0x6C, 0xFF, 0xFF, 0x36, 0x9E, 0x86, 0x06, 0x3C, 0x04, 0x00, 0x36, 0x9E, 0x52, 0x55, 0x00};
Packet packet;
run_parse_test(packet_data, packet);
TEST_ASSERT_TRUE(packet.type == PacketType::OPEN);
}
int runUnityTests(void)
{
UNITY_BEGIN();
RUN_TEST(test_parse_stop);
RUN_TEST(test_parse_close);
RUN_TEST(test_parse_open);
return UNITY_END();
}
/**
* For Arduino framework
*/
void setup()
{
// Wait ~2 seconds before the Unity test runner
// establishes connection with a board Serial interface
delay(2000);
runUnityTests();
}
void loop() {}
int main(void)
{
return runUnityTests();
}