Skip to content

Commit

Permalink
Merge pull request #289 from thelsing/openknx-merge
Browse files Browse the repository at this point in the history
Openknx merge
  • Loading branch information
thelsing authored Aug 9, 2024
2 parents 484e6ce + af96a76 commit 44f90bb
Show file tree
Hide file tree
Showing 120 changed files with 5,955 additions and 1,341 deletions.
10 changes: 0 additions & 10 deletions .vscode/extensions.json

This file was deleted.

7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
cmake_policy(SET CMP0048 NEW)
cmake_minimum_required(VERSION 3.16)
project(knx VERSION 1.5)


add_subdirectory(examples/knx-linux)
add_subdirectory(examples/knx-linux-coupler)
add_subdirectory(examples/knxPython)
add_subdirectory(examples/knxPython)
47 changes: 2 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,7 @@ This projects provides a knx-device stack for arduino (ESP8266, ESP32, SAMD21, R
It implements most of System-B specification and can be configured with ETS.
The necessary knxprod-files can be generated with the [Kaenx-Creator](https://github.com/OpenKNX/Kaenx-Creator) tool.

For ESP8266 and ESP32 [WifiManager](https://github.com/tzapu/WiFiManager) is used to configure wifi.

Don't forget to reset ESP8266 manually (disconnect power) after flashing. The reboot doen't work during configuration with ETS otherwise.

Generated documentation can be found [here](https://knx.readthedocs.io/en/latest/).

## Stack configuration possibilities

Specify prog button GPIO other then `GPIO0`:
```C++
knx.buttonPin(3); // Use GPIO3 Pin
```

Specify a LED GPIO for programming mode other then the `LED_BUILTIN`:
```C++
knx.ledPin(5);
```

Use a custom function instead of a LED connected to GPIO to indicate the programming mode:
```C++
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#include <knx.h>
// create a pixel strand with 1 pixel on PIN_NEOPIXEL
Adafruit_NeoPixel pixels(1, PIN_NEOPIXEL);

void progLedOff()
{
pixels.clear();
pixels.show();
}

void progLedOn()
{
pixels.setPixelColor(0, pixels.Color(20, 0, 0));
pixels.show();
}

void main ()
{
knx.setProgLedOffCallback(progLedOff);
knx.setProgLedOnCallback(progLedOn);
[...]
}
```
More configuration options can be found in the examples.
## Usage
See the examples for basic usage options
17 changes: 17 additions & 0 deletions examples/knx-demo/platformio-ci.ini
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,20 @@ build_flags =
-DMASK_VERSION=0x07B0
-Wno-unknown-pragmas
-DUSE_DATASECURE

;--- RP2040 -----------------------------------------------
[env:rp2040]
framework = arduino
platform = https://github.com/maxgerhardt/platform-raspberrypi.git#60d6ae8
platform_packages = framework-arduinopico @ https://github.com/earlephilhower/arduino-pico/releases/download/3.9.3/rp2040-3.9.3.zip
board = rpipico
board_build.core = earlephilhower

lib_deps =
knx

build_flags =
-DMASK_VERSION=0x07B0
-DKNX_FLASH_SIZE=4096
-D PIO_FRAMEWORK_ARDUINO_ENABLE_RTTI
-Wno-unknown-pragmas
23 changes: 23 additions & 0 deletions examples/knx-demo/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,26 @@ build_flags =
-Wno-unknown-pragmas

extra_scripts = ../scripts/stm32rdu.py


;--- RP2040 -----------------------------------------------
[env:rp2040]
framework = arduino
platform = https://github.com/maxgerhardt/platform-raspberrypi.git#60d6ae8
platform_packages = framework-arduinopico @ https://github.com/earlephilhower/arduino-pico/releases/download/3.9.3/rp2040-3.9.3.zip
board = rpipico
board_build.core = earlephilhower
; We consider that the this projects is opened within its project directory
; while working with VS Code.


lib_deps =
knx=file://../../../knx

lib_ldf_mode = deep+

build_flags =
-DMASK_VERSION=0x07B0
-DKNX_FLASH_SIZE=4096
-D PIO_FRAMEWORK_ARDUINO_ENABLE_RTTI
-Wno-unknown-pragmas
4 changes: 2 additions & 2 deletions examples/knx-linux-coupler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 2.7)
project(knx-linux-coupler)
cmake_minimum_required(VERSION 3.16)
project(knx-linux-coupler VERSION 1.5)
set(LIBRARIES_FROM_REFERENCES "")

set(SOURCES
Expand Down
2 changes: 0 additions & 2 deletions examples/knx-linux-coupler/fdsk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ int FdskCalculator::toBase32(uint8_t* in, long length, uint8_t*& out, bool usePa
char standardPaddingChar = '=';

int result = 0;
int count = 0;
int bufSize = 8;
int index = 0;
int size = 0; // size of temporary array
uint8_t* temp = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions examples/knx-linux/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 2.7)
project(knx-linux)
cmake_minimum_required(VERSION 3.16)
project(knx-linux VERSION 1.5)
set(LIBRARIES_FROM_REFERENCES "")

set(SOURCES
Expand Down
2 changes: 0 additions & 2 deletions examples/knx-linux/fdsk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ int FdskCalculator::toBase32(uint8_t* in, long length, uint8_t*& out, bool usePa
char standardPaddingChar = '=';

int result = 0;
int count = 0;
int bufSize = 8;
int index = 0;
int size = 0; // size of temporary array
uint8_t* temp = nullptr;
Expand Down
5 changes: 3 additions & 2 deletions examples/knx-usb/platformio-ci.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ framework = arduino

; VID must be changed to some known KNX Manufacturer
; so that the KNX USB interface gets recognized by ETS
;extra_scripts = pre:custom_hwids.py
;board_build.usb_product="KNX RF - USB Interface"
; not possible within ci
;;extra_scripts = pre:custom_hwids.py
;;board_build.usb_product="KNX RF - USB Interface"

lib_deps =
SPI
Expand Down
6 changes: 3 additions & 3 deletions examples/knxPython/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 2.7)
project(knx)
cmake_minimum_required(VERSION 3.16)
project(knx VERSION 1.5)

add_subdirectory(pybind11)

Expand Down Expand Up @@ -139,4 +139,4 @@ include_directories(../../src)
#set_target_properties(knx PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${outdir})
set_target_properties(knx PROPERTIES OUTPUT_NAME knx)
set_property(TARGET knx PROPERTY CXX_STANDARD 11)
target_compile_definitions(knx PUBLIC -DMASK_VERSION=0x57B0)
target_compile_definitions(knx PUBLIC -DMASK_VERSION=0x57B0)
16 changes: 16 additions & 0 deletions library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "knx",
"version": "1.5.0",
"dependencies": {
},
"description": "knx stack",
"authors": [
{
"name": "Thomas Kunze"
}
],
"repository": {
"type": "git",
"url": "https://github.com/thelsing/knx"
}
}
6 changes: 3 additions & 3 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name=knx
version=1.2.0
author=Thomas Kunze
version=1.5.0
author=Thomas Kunze, et. al.
maintainer=Thomas Kunze
sentence=knx stack
paragraph=
category=Communication
url=https://github.com/thelsing/knx
architectures=*
includes=knx.h
includes=knx.h
5 changes: 5 additions & 0 deletions src/arduino_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ size_t ArduinoPlatform::readBytesUart(uint8_t *buffer, size_t length)
return length;
}

void ArduinoPlatform::flushUart()
{
return _knxSerial->flush();
}

#ifndef KNX_NO_SPI
void ArduinoPlatform::setupSpi()
{
Expand Down
1 change: 1 addition & 0 deletions src/arduino_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ArduinoPlatform : public Platform
virtual size_t writeUart(const uint8_t* buffer, size_t size);
virtual int readUart();
virtual size_t readBytesUart(uint8_t* buffer, size_t length);
virtual void flushUart();

//spi
#ifndef KNX_NO_SPI
Expand Down
34 changes: 26 additions & 8 deletions src/esp32_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,50 @@ bool Esp32Platform::sendBytesMultiCast(uint8_t * buffer, uint16_t len)
return true;
}

int Esp32Platform::readBytesMultiCast(uint8_t * buffer, uint16_t maxLen)
int Esp32Platform::readBytesMultiCast(uint8_t * buffer, uint16_t maxLen, uint32_t& src_addr, uint16_t& src_port)
{
int len = _udp.parsePacket();
if (len == 0)
return 0;

if (len > maxLen)
{
KNX_DEBUG_SERIAL.printf("udp buffer to small. was %d, needed %d\n", maxLen, len);
fatalError();
println("Unexpected UDP data packet length - drop packet");
for (size_t i = 0; i < len; i++)
_udp.read();
return 0;
}

_udp.read(buffer, len);
//printHex("-> ", buffer, len);
_remoteIP = _udp.remoteIP();
_remotePort = _udp.remotePort();
src_addr = htonl(_remoteIP);
src_port = _remotePort;

// print("Remote IP: ");
// print(_udp.remoteIP().toString().c_str());
// printHex("-> ", buffer, len);

return len;
}

bool Esp32Platform::sendBytesUniCast(uint32_t addr, uint16_t port, uint8_t* buffer, uint16_t len)
{
IPAddress ucastaddr(htonl(addr));
println("sendBytesUniCast endPacket fail");
if(_udp.beginPacket(ucastaddr, port) == 1) {

if(!addr)
ucastaddr = _remoteIP;

if(!port)
port = _remotePort;

if(_udp.beginPacket(ucastaddr, port) == 1)
{
_udp.write(buffer, len);
if(_udp.endPacket() == 0) println("sendBytesUniCast endPacket fail");
}
else println("sendBytesUniCast beginPacket fail");
else
println("sendBytesUniCast beginPacket fail");
return true;
}

Expand Down
6 changes: 5 additions & 1 deletion src/esp32_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ class Esp32Platform : public ArduinoPlatform
void setupMultiCast(uint32_t addr, uint16_t port) override;
void closeMultiCast() override;
bool sendBytesMultiCast(uint8_t* buffer, uint16_t len) override;
int readBytesMultiCast(uint8_t* buffer, uint16_t maxLen) override;
int readBytesMultiCast(uint8_t* buffer, uint16_t maxLen, uint32_t& src_addr, uint16_t& src_port) override;

//unicast
bool sendBytesUniCast(uint32_t addr, uint16_t port, uint8_t* buffer, uint16_t len) override;

//memory
uint8_t* getEepromBuffer(uint32_t size);
void commitToEeprom();

protected: IPAddress _remoteIP;
protected: uint16_t _remotePort;

private:
WiFiUDP _udp;
int8_t _rxPin = -1;
Expand Down
Loading

0 comments on commit 44f90bb

Please sign in to comment.