mirror of
https://github.com/thelsing/knx.git
synced 2025-08-26 13:51:28 +02:00
Merge branch 'master' into libretiny
This commit is contained in:
commit
9aa4bee130
34
.github/workflows/esp-idf.yml
vendored
Normal file
34
.github/workflows/esp-idf.yml
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
name: ESP-IDF
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: "ESP-IDF ${{ matrix.idf_ver }}"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 10
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
#idf_ver: ["v4.4.7", "v5.1.4", "v5.3.2"]
|
||||||
|
idf_ver: ["v5.4.1"]
|
||||||
|
idf_target: ["esp32"]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
path: ${{ github.workspace }}/app
|
||||||
|
|
||||||
|
- name: Compile
|
||||||
|
uses: espressif/esp-idf-ci-action@v1
|
||||||
|
with:
|
||||||
|
esp_idf_version: ${{ matrix.idf_ver }}
|
||||||
|
target: ${{ matrix.idf_target }}
|
||||||
|
path: app/examples/knx-demo-esp-idf
|
||||||
|
command: apt-get update && apt-get install -y python3-venv && idf.py build
|
@ -1,6 +1,6 @@
|
|||||||
# knx
|
# knx
|
||||||
|
|
||||||
This projects provides a knx-device stack for arduino (ESP8266, ESP32, SAMD21, RP2040, STM32), CC1310, LibreTiny (BK7231, RTL8710 and LN882H) and linux. (more are quite easy to add)
|
This projects provides a knx-device stack for Arduino (ESP8266, ESP32, SAMD21, RP2040, STM32), CC1310, ESP IDF, LibreTiny (BK7231, RTL8710 and LN882H) and Linux. (more are quite easy to add)
|
||||||
It implements most of System-B specification and can be configured with ETS.
|
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.
|
The necessary knxprod-files can be generated with the [Kaenx-Creator](https://github.com/OpenKNX/Kaenx-Creator) tool.
|
||||||
|
|
||||||
|
14
examples/knx-demo-esp-idf/CMakeLists.txt
Normal file
14
examples/knx-demo-esp-idf/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
|
||||||
|
# require for knx components
|
||||||
|
add_definitions(
|
||||||
|
-Wno-unknown-pragmas
|
||||||
|
-DMASK_VERSION=0x07B0
|
||||||
|
-DKNX_NO_AUTOMATIC_GLOBAL_INSTANCE
|
||||||
|
-DKNX_FLASH_SIZE=4096
|
||||||
|
#-DKNX_NO_PRINT
|
||||||
|
#-Wno-stringop-truncation
|
||||||
|
)
|
||||||
|
|
||||||
|
project(knx-demo-diy-idf)
|
29
examples/knx-demo-esp-idf/README.md
Normal file
29
examples/knx-demo-esp-idf/README.md
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# KNX Demo DIY (ESP-IDF 5.x Native)
|
||||||
|
|
||||||
|
This is a native ESP-IDF 5.x example project for KNX, based on the Arduino `knx-demo-diy` example but using the new `Esp32IdfPlatform` for direct ESP-IDF support.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
- Uses the native ESP-IDF APIs (no Arduino layer)
|
||||||
|
- Demonstrates KNX stack integration on ESP32
|
||||||
|
- Based on the logic of the Arduino `knx-demo-diy.ino` example
|
||||||
|
|
||||||
|
## How to Build
|
||||||
|
|
||||||
|
1. Install [ESP-IDF 5.x](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/)
|
||||||
|
2. Open a terminal in this directory (`examples/knx-demo-esp-idf`)
|
||||||
|
3. Run:
|
||||||
|
```sh
|
||||||
|
idf.py set-target esp32
|
||||||
|
idf.py build
|
||||||
|
idf.py -p /dev/ttyUSB0 flash monitor
|
||||||
|
```
|
||||||
|
(Replace `/dev/ttyUSB0` with your ESP32 serial port)
|
||||||
|
|
||||||
|
## Project Structure
|
||||||
|
- `main.c` — Main application file (C++ code, but named .c for ESP-IDF compatibility)
|
||||||
|
- `CMakeLists.txt` — ESP-IDF build configuration
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
- This project uses the new `Esp32IdfPlatform` class for native ESP-IDF support.
|
||||||
|
- You may need to adapt pin numbers and KNX configuration for your hardware.
|
||||||
|
- The logic is adapted from the Arduino `knx-demo-diy.ino` example.
|
11
examples/knx-demo-esp-idf/components/knx/CMakeLists.txt
Normal file
11
examples/knx-demo-esp-idf/components/knx/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Define the directory containing your source files
|
||||||
|
set(SOURCE_DIR "../../../../src")
|
||||||
|
set(SOURCE_DIR_1 "../../../../src/knx")
|
||||||
|
|
||||||
|
# Use file(GLOB) to find all .cpp files in the 'src' directory
|
||||||
|
file(GLOB SOURCE_FILES "${SOURCE_DIR}/*.cpp")
|
||||||
|
file(GLOB SOURCE_FILES_1 "${SOURCE_DIR_1}/*.cpp")
|
||||||
|
|
||||||
|
idf_component_register(SRCS ${SOURCE_FILES} ${SOURCE_FILES_1}
|
||||||
|
INCLUDE_DIRS "../../../../src" "../../../../src/knx"
|
||||||
|
REQUIRES esp_netif driver esp_timer esp_wifi freertos nvs_flash esp_system)
|
12
examples/knx-demo-esp-idf/main/CMakeLists.txt
Normal file
12
examples/knx-demo-esp-idf/main/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRCS "main.cpp"
|
||||||
|
INCLUDE_DIRS "."
|
||||||
|
REQUIRES
|
||||||
|
knx
|
||||||
|
esp_timer
|
||||||
|
nvs_flash
|
||||||
|
esp_wifi
|
||||||
|
esp_event
|
||||||
|
esp_netif
|
||||||
|
mdns
|
||||||
|
)
|
2
examples/knx-demo-esp-idf/main/idf_component.yml
Normal file
2
examples/knx-demo-esp-idf/main/idf_component.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
dependencies:
|
||||||
|
espressif/mdns: ^1.8.2
|
162
examples/knx-demo-esp-idf/main/main.cpp
Normal file
162
examples/knx-demo-esp-idf/main/main.cpp
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
#include "esp32_idf_platform.h"
|
||||||
|
#include "knx_facade.h"
|
||||||
|
#include "knx/bau07B0.h"
|
||||||
|
#include "knx/group_object.h"
|
||||||
|
#include "esp_wifi.h"
|
||||||
|
#include "nvs_flash.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include <esp_timer.h>
|
||||||
|
#include <freertos/FreeRTOS.h>
|
||||||
|
#include <freertos/task.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
#define WIFI_SSID "your_ssid"
|
||||||
|
#define WIFI_PASS "your_password"
|
||||||
|
#define MASK_VERSION 0x07B0
|
||||||
|
|
||||||
|
static const char *TAG = "knx-demo";
|
||||||
|
|
||||||
|
// --- KNX Group Object Shortcuts ---
|
||||||
|
#define goCurrent knx.getGroupObject(1)
|
||||||
|
#define goMax knx.getGroupObject(2)
|
||||||
|
#define goMin knx.getGroupObject(3)
|
||||||
|
#define goReset knx.getGroupObject(4)
|
||||||
|
|
||||||
|
// --- Global Variables ---
|
||||||
|
float currentValue = 0;
|
||||||
|
float maxValue = 0;
|
||||||
|
float minValue = RAND_MAX;
|
||||||
|
int64_t lastsend = 0;
|
||||||
|
|
||||||
|
// --- KNX Stack Instance (migrated pattern) ---
|
||||||
|
Esp32IdfPlatform knxPlatform(UART_NUM_1); // Use UART_NUM_1, change if needed
|
||||||
|
Bau07B0 knxBau(knxPlatform);
|
||||||
|
KnxFacade<Esp32IdfPlatform, Bau07B0> knx(knxBau);
|
||||||
|
|
||||||
|
// --- WiFi event handler ---
|
||||||
|
static esp_netif_t* s_wifi_netif = nullptr;
|
||||||
|
static void wifi_event_handler(void* arg, esp_event_base_t event_base,
|
||||||
|
int32_t event_id, void* event_data) {
|
||||||
|
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
|
||||||
|
esp_wifi_connect();
|
||||||
|
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||||
|
esp_wifi_connect();
|
||||||
|
ESP_LOGI(TAG, "Retrying connection to the WiFi AP");
|
||||||
|
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
||||||
|
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
|
||||||
|
ESP_LOGI(TAG, "Got IP: " IPSTR, IP2STR(&event->ip_info.ip));
|
||||||
|
if (s_wifi_netif) {
|
||||||
|
knxPlatform.setNetif(s_wifi_netif);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Button ISR (simulate with a function call or GPIO interrupt in real use) ---
|
||||||
|
void myButtonPressed() {
|
||||||
|
static int64_t lastpressed = 0;
|
||||||
|
int64_t now = esp_timer_get_time() / 1000; // ms
|
||||||
|
if (now - lastpressed > 200) {
|
||||||
|
knx.toggleProgMode();
|
||||||
|
lastpressed = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- KNX Reset Callback ---
|
||||||
|
void resetCallback(GroupObject& go) {
|
||||||
|
if (go.value()) {
|
||||||
|
maxValue = 0;
|
||||||
|
minValue = 10000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Simulate temperature measurement ---
|
||||||
|
void measureTemp() {
|
||||||
|
int64_t now = esp_timer_get_time() / 1000; // ms
|
||||||
|
if ((now - lastsend) < 2000)
|
||||||
|
return;
|
||||||
|
|
||||||
|
lastsend = now;
|
||||||
|
int r = rand();
|
||||||
|
currentValue = (r * 1.0) / (RAND_MAX * 1.0);
|
||||||
|
currentValue *= 100 * 100;
|
||||||
|
|
||||||
|
goCurrent.value(currentValue);
|
||||||
|
|
||||||
|
if (currentValue > maxValue) {
|
||||||
|
maxValue = currentValue;
|
||||||
|
goMax.value(maxValue);
|
||||||
|
}
|
||||||
|
if (currentValue < minValue) {
|
||||||
|
minValue = currentValue;
|
||||||
|
goMin.value(minValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void app_main(void) {
|
||||||
|
// Initialize NVS
|
||||||
|
esp_err_t ret = nvs_flash_init();
|
||||||
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||||
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||||
|
ret = nvs_flash_init();
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK(ret);
|
||||||
|
|
||||||
|
// Initialize TCP/IP and WiFi
|
||||||
|
ESP_ERROR_CHECK(esp_netif_init());
|
||||||
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||||
|
s_wifi_netif = esp_netif_create_default_wifi_sta();
|
||||||
|
|
||||||
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||||
|
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL, NULL));
|
||||||
|
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &wifi_event_handler, NULL, NULL));
|
||||||
|
|
||||||
|
wifi_config_t wifi_config = {};
|
||||||
|
strcpy((char*)wifi_config.sta.ssid, WIFI_SSID);
|
||||||
|
strcpy((char*)wifi_config.sta.password, WIFI_PASS);
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_start());
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "WiFi initialization finished.");
|
||||||
|
|
||||||
|
// Set UART pins (example: RX=16, TX=17)
|
||||||
|
knxPlatform.knxUartPins(16, 17);
|
||||||
|
knxPlatform.setupUart();
|
||||||
|
|
||||||
|
// Set button ISR
|
||||||
|
knx.setButtonISRFunction(myButtonPressed);
|
||||||
|
|
||||||
|
// Read KNX memory (address table, etc.)
|
||||||
|
knx.readMemory();
|
||||||
|
|
||||||
|
// Register group object callbacks and types if configured
|
||||||
|
if (knx.configured()) {
|
||||||
|
goReset.callback(resetCallback);
|
||||||
|
goReset.dataPointType(DPT_Trigger);
|
||||||
|
goCurrent.dataPointType(DPT_Value_Temp);
|
||||||
|
goMin.dataPointType(DPT_Value_Temp);
|
||||||
|
goMax.dataPointType(DPT_Value_Temp);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Timeout: %d", knx.paramByte(0));
|
||||||
|
ESP_LOGI(TAG, "Cyclic send: %d", knx.paramByte(1));
|
||||||
|
ESP_LOGI(TAG, "Min/Max send: %d", knx.paramByte(2));
|
||||||
|
ESP_LOGI(TAG, "Send on change: %d", knx.paramByte(3));
|
||||||
|
ESP_LOGI(TAG, "Alignment: %d", knx.paramByte(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start KNX stack
|
||||||
|
knx.start();
|
||||||
|
|
||||||
|
// Main loop
|
||||||
|
while (1) {
|
||||||
|
knx.loop();
|
||||||
|
if (knx.configured()) {
|
||||||
|
measureTemp();
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
}
|
||||||
|
}
|
5
examples/knx-demo/.gitignore
vendored
Normal file
5
examples/knx-demo/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
@ -1,3 +1,5 @@
|
|||||||
|
#ifdef ARDUINO
|
||||||
|
|
||||||
#include "arduino_platform.h"
|
#include "arduino_platform.h"
|
||||||
#include "knx/bits.h"
|
#include "knx/bits.h"
|
||||||
|
|
||||||
@ -309,3 +311,5 @@ void println(void)
|
|||||||
ArduinoPlatform::SerialDebug->println();
|
ArduinoPlatform::SerialDebug->println();
|
||||||
}
|
}
|
||||||
#endif // KNX_NO_PRINT
|
#endif // KNX_NO_PRINT
|
||||||
|
|
||||||
|
#endif // ARDUINO
|
@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef ARDUINO
|
||||||
|
|
||||||
#include "knx/platform.h"
|
#include "knx/platform.h"
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
@ -42,3 +44,4 @@ class ArduinoPlatform : public Platform
|
|||||||
protected:
|
protected:
|
||||||
HardwareSerial* _knxSerial;
|
HardwareSerial* _knxSerial;
|
||||||
};
|
};
|
||||||
|
#endif // ARDUINO
|
436
src/esp32_idf_platform.cpp
Normal file
436
src/esp32_idf_platform.cpp
Normal file
@ -0,0 +1,436 @@
|
|||||||
|
#ifndef ARDUINO
|
||||||
|
#ifdef ESP_PLATFORM
|
||||||
|
// esp32_idf_platform.cpp
|
||||||
|
#include <esp_system.h>
|
||||||
|
#include <esp_mac.h>
|
||||||
|
#include "esp32_idf_platform.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "knx/bits.h"
|
||||||
|
#include "nvs.h"
|
||||||
|
#include <esp_timer.h>
|
||||||
|
|
||||||
|
static const char* KTAG = "KNX_LIB";
|
||||||
|
|
||||||
|
Esp32IdfPlatform::Esp32IdfPlatform(uart_port_t uart_num)
|
||||||
|
: _uart_num(uart_num)
|
||||||
|
{
|
||||||
|
// Set the memory type to use our NVS-based EEPROM emulation
|
||||||
|
_memoryType = Eeprom;
|
||||||
|
}
|
||||||
|
|
||||||
|
Esp32IdfPlatform::~Esp32IdfPlatform()
|
||||||
|
{
|
||||||
|
if (_sock != -1)
|
||||||
|
{
|
||||||
|
closeMultiCast();
|
||||||
|
}
|
||||||
|
if (_uart_installed)
|
||||||
|
{
|
||||||
|
closeUart();
|
||||||
|
}
|
||||||
|
if (_eeprom_buffer)
|
||||||
|
{
|
||||||
|
free(_eeprom_buffer);
|
||||||
|
}
|
||||||
|
if (_nvs_handle)
|
||||||
|
{
|
||||||
|
nvs_close(_nvs_handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp32IdfPlatform::knxUartPins(int8_t rxPin, int8_t txPin)
|
||||||
|
{
|
||||||
|
_rxPin = rxPin;
|
||||||
|
_txPin = txPin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp32IdfPlatform::setNetif(esp_netif_t* netif)
|
||||||
|
{
|
||||||
|
_netif = netif;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp32IdfPlatform::fatalError()
|
||||||
|
{
|
||||||
|
ESP_LOGE(KTAG, "FATAL ERROR. System halted.");
|
||||||
|
// Loop forever to halt the system
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ESP specific uart handling with pins
|
||||||
|
void Esp32IdfPlatform::setupUart()
|
||||||
|
{
|
||||||
|
if (_uart_installed)
|
||||||
|
return;
|
||||||
|
uart_config_t uart_config;
|
||||||
|
memset(&uart_config, 0, sizeof(uart_config));
|
||||||
|
uart_config.baud_rate = 19200;
|
||||||
|
uart_config.data_bits = UART_DATA_8_BITS;
|
||||||
|
uart_config.parity = UART_PARITY_EVEN;
|
||||||
|
uart_config.stop_bits = UART_STOP_BITS_1;
|
||||||
|
uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
|
||||||
|
uart_config.source_clk = UART_SCLK_DEFAULT;
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(uart_driver_install(_uart_num, 256 * 2, 0, 0, NULL, 0));
|
||||||
|
ESP_ERROR_CHECK(uart_param_config(_uart_num, &uart_config));
|
||||||
|
ESP_ERROR_CHECK(uart_set_pin(_uart_num, _txPin, _rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
|
||||||
|
_uart_installed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp32IdfPlatform::closeUart()
|
||||||
|
{
|
||||||
|
if (!_uart_installed)
|
||||||
|
return;
|
||||||
|
uart_driver_delete(_uart_num);
|
||||||
|
_uart_installed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Esp32IdfPlatform::uartAvailable()
|
||||||
|
{
|
||||||
|
if (!_uart_installed)
|
||||||
|
return 0;
|
||||||
|
size_t length = 0;
|
||||||
|
ESP_ERROR_CHECK(uart_get_buffered_data_len(_uart_num, &length));
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Esp32IdfPlatform::writeUart(const uint8_t data)
|
||||||
|
{
|
||||||
|
if (!_uart_installed)
|
||||||
|
return 0;
|
||||||
|
return uart_write_bytes(_uart_num, &data, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Esp32IdfPlatform::writeUart(const uint8_t* buffer, size_t size)
|
||||||
|
{
|
||||||
|
if (!_uart_installed)
|
||||||
|
return 0;
|
||||||
|
return uart_write_bytes(_uart_num, buffer, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Esp32IdfPlatform::readUart()
|
||||||
|
{
|
||||||
|
if (!_uart_installed)
|
||||||
|
return -1;
|
||||||
|
uint8_t data;
|
||||||
|
if (uart_read_bytes(_uart_num, &data, 1, pdMS_TO_TICKS(20)) > 0)
|
||||||
|
{
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Esp32IdfPlatform::readBytesUart(uint8_t* buffer, size_t length)
|
||||||
|
{
|
||||||
|
if (!_uart_installed)
|
||||||
|
return 0;
|
||||||
|
return uart_read_bytes(_uart_num, buffer, length, pdMS_TO_TICKS(100));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp32IdfPlatform::flushUart()
|
||||||
|
{
|
||||||
|
if (!_uart_installed)
|
||||||
|
return;
|
||||||
|
ESP_ERROR_CHECK(uart_flush(_uart_num));
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Esp32IdfPlatform::currentIpAddress()
|
||||||
|
{
|
||||||
|
if (!_netif)
|
||||||
|
return 0;
|
||||||
|
esp_netif_ip_info_t ip_info;
|
||||||
|
esp_netif_get_ip_info(_netif, &ip_info);
|
||||||
|
return ip_info.ip.addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Esp32IdfPlatform::currentSubnetMask()
|
||||||
|
{
|
||||||
|
if (!_netif)
|
||||||
|
return 0;
|
||||||
|
esp_netif_ip_info_t ip_info;
|
||||||
|
esp_netif_get_ip_info(_netif, &ip_info);
|
||||||
|
return ip_info.netmask.addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Esp32IdfPlatform::currentDefaultGateway()
|
||||||
|
{
|
||||||
|
if (!_netif)
|
||||||
|
return 0;
|
||||||
|
esp_netif_ip_info_t ip_info;
|
||||||
|
esp_netif_get_ip_info(_netif, &ip_info);
|
||||||
|
return ip_info.gw.addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp32IdfPlatform::macAddress(uint8_t* addr)
|
||||||
|
{
|
||||||
|
if (!_netif)
|
||||||
|
return;
|
||||||
|
esp_netif_get_mac(_netif, addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Esp32IdfPlatform::uniqueSerialNumber()
|
||||||
|
{
|
||||||
|
uint8_t mac[6];
|
||||||
|
esp_efuse_mac_get_default(mac);
|
||||||
|
uint64_t chipid = 0;
|
||||||
|
for (int i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
chipid |= ((uint64_t)mac[i] << (i * 8));
|
||||||
|
}
|
||||||
|
uint32_t upperId = (chipid >> 32) & 0xFFFFFFFF;
|
||||||
|
uint32_t lowerId = (chipid & 0xFFFFFFFF);
|
||||||
|
return (upperId ^ lowerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp32IdfPlatform::restart()
|
||||||
|
{
|
||||||
|
ESP_LOGI(KTAG, "Restarting system...");
|
||||||
|
esp_restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp32IdfPlatform::setupMultiCast(uint32_t addr, uint16_t port)
|
||||||
|
{
|
||||||
|
_multicast_addr = addr;
|
||||||
|
_multicast_port = port;
|
||||||
|
|
||||||
|
_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
|
||||||
|
if (_sock < 0)
|
||||||
|
{
|
||||||
|
ESP_LOGE(KTAG, "Failed to create socket. Errno: %d", errno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sockaddr_in saddr;
|
||||||
|
memset(&saddr, 0, sizeof(saddr));
|
||||||
|
saddr.sin_family = AF_INET;
|
||||||
|
saddr.sin_port = htons(port);
|
||||||
|
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
|
if (bind(_sock, (struct sockaddr*)&saddr, sizeof(struct sockaddr_in)) < 0)
|
||||||
|
{
|
||||||
|
ESP_LOGE(KTAG, "Failed to bind socket. Errno: %d", errno);
|
||||||
|
close(_sock);
|
||||||
|
_sock = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ip_mreq imreq;
|
||||||
|
memset(&imreq, 0, sizeof(imreq));
|
||||||
|
imreq.imr_interface.s_addr = IPADDR_ANY;
|
||||||
|
imreq.imr_multiaddr.s_addr = addr;
|
||||||
|
if (setsockopt(_sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &imreq, sizeof(struct ip_mreq)) < 0)
|
||||||
|
{
|
||||||
|
ESP_LOGE(KTAG, "Failed to join multicast group. Errno: %d", errno);
|
||||||
|
close(_sock);
|
||||||
|
_sock = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGI(KTAG, "Successfully joined multicast group on port %d", port);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp32IdfPlatform::closeMultiCast()
|
||||||
|
{
|
||||||
|
if (_sock != -1)
|
||||||
|
{
|
||||||
|
close(_sock);
|
||||||
|
_sock = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Esp32IdfPlatform::sendBytesMultiCast(uint8_t* buffer, uint16_t len)
|
||||||
|
{
|
||||||
|
if (_sock < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
struct sockaddr_in dest_addr = {};
|
||||||
|
dest_addr.sin_family = AF_INET;
|
||||||
|
dest_addr.sin_port = htons(_multicast_port);
|
||||||
|
dest_addr.sin_addr.s_addr = _multicast_addr;
|
||||||
|
|
||||||
|
int sent_len = sendto(_sock, buffer, len, 0, (struct sockaddr*)&dest_addr, sizeof(dest_addr));
|
||||||
|
if (sent_len < 0)
|
||||||
|
{
|
||||||
|
ESP_LOGE(KTAG, "sendBytesMultiCast failed. Errno: %d", errno);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return sent_len == len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Esp32IdfPlatform::readBytesMultiCast(uint8_t* buffer, uint16_t maxLen, uint32_t& src_addr, uint16_t& src_port)
|
||||||
|
{
|
||||||
|
if (_sock < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
socklen_t socklen = sizeof(_remote_addr);
|
||||||
|
int len = recvfrom(_sock, buffer, maxLen, 0, (struct sockaddr*)&_remote_addr, &socklen);
|
||||||
|
|
||||||
|
if (len <= 0)
|
||||||
|
{
|
||||||
|
return 0; // No data or error
|
||||||
|
}
|
||||||
|
|
||||||
|
src_addr = _remote_addr.sin_addr.s_addr;
|
||||||
|
src_port = ntohs(_remote_addr.sin_port);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Esp32IdfPlatform::sendBytesUniCast(uint32_t addr, uint16_t port, uint8_t* buffer, uint16_t len)
|
||||||
|
{
|
||||||
|
if (_sock < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
struct sockaddr_in dest_addr;
|
||||||
|
dest_addr.sin_family = AF_INET;
|
||||||
|
|
||||||
|
if (addr == 0)
|
||||||
|
{ // If address is 0, use the address from the last received packet
|
||||||
|
dest_addr.sin_addr.s_addr = _remote_addr.sin_addr.s_addr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dest_addr.sin_addr.s_addr = addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (port == 0)
|
||||||
|
{ // If port is 0, use the port from the last received packet
|
||||||
|
dest_addr.sin_port = _remote_addr.sin_port;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dest_addr.sin_port = htons(port);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sendto(_sock, buffer, len, 0, (struct sockaddr*)&dest_addr, sizeof(dest_addr)) < 0)
|
||||||
|
{
|
||||||
|
ESP_LOGE(KTAG, "sendBytesUniCast failed. Errno: %d", errno);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t* Esp32IdfPlatform::getEepromBuffer(uint32_t size)
|
||||||
|
{
|
||||||
|
if (_eeprom_buffer && _eeprom_size == size)
|
||||||
|
{
|
||||||
|
return _eeprom_buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_eeprom_buffer)
|
||||||
|
{
|
||||||
|
free(_eeprom_buffer);
|
||||||
|
_eeprom_buffer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
_eeprom_size = size;
|
||||||
|
_eeprom_buffer = (uint8_t*)malloc(size);
|
||||||
|
if (!_eeprom_buffer)
|
||||||
|
{
|
||||||
|
ESP_LOGE(KTAG, "Failed to allocate EEPROM buffer");
|
||||||
|
fatalError();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t err = nvs_flash_init();
|
||||||
|
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND)
|
||||||
|
{
|
||||||
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||||
|
err = nvs_flash_init();
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK(err);
|
||||||
|
|
||||||
|
err = nvs_open(_nvs_namespace, NVS_READWRITE, &_nvs_handle);
|
||||||
|
if (err != ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGE(KTAG, "Error opening NVS handle: %s", esp_err_to_name(err));
|
||||||
|
free(_eeprom_buffer);
|
||||||
|
_eeprom_buffer = nullptr;
|
||||||
|
fatalError();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t required_size = size;
|
||||||
|
err = nvs_get_blob(_nvs_handle, _nvs_key, _eeprom_buffer, &required_size);
|
||||||
|
if (err != ESP_OK || required_size != size)
|
||||||
|
{
|
||||||
|
if (err == ESP_ERR_NVS_NOT_FOUND)
|
||||||
|
{
|
||||||
|
ESP_LOGI(KTAG, "No previous EEPROM data found in NVS. Initializing fresh buffer.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGW(KTAG, "NVS get blob failed (%s) or size mismatch. Initializing fresh buffer.", esp_err_to_name(err));
|
||||||
|
}
|
||||||
|
memset(_eeprom_buffer, 0xFF, size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGI(KTAG, "Successfully loaded %d bytes from NVS into EEPROM buffer.", required_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _eeprom_buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp32IdfPlatform::commitToEeprom()
|
||||||
|
{
|
||||||
|
if (!_eeprom_buffer || !_nvs_handle)
|
||||||
|
{
|
||||||
|
ESP_LOGE(KTAG, "EEPROM not initialized, cannot commit.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t err = nvs_set_blob(_nvs_handle, _nvs_key, _eeprom_buffer, _eeprom_size);
|
||||||
|
if (err != ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGE(KTAG, "Failed to set NVS blob: %s", esp_err_to_name(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = nvs_commit(_nvs_handle);
|
||||||
|
if (err != ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGE(KTAG, "Failed to commit NVS: %s", esp_err_to_name(err));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGI(KTAG, "Committed %" PRIu32 " bytes to NVS.", _eeprom_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t millis()
|
||||||
|
{
|
||||||
|
// esp_timer_get_time() returns microseconds, so we divide by 1000 for milliseconds.
|
||||||
|
// Cast to uint32_t to match the Arduino function signature.
|
||||||
|
return (uint32_t)(esp_timer_get_time() / 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Internal wrapper function to bridge Arduino-style ISR to ESP-IDF
|
||||||
|
static void IRAM_ATTR isr_wrapper(void* arg)
|
||||||
|
{
|
||||||
|
IsrFuncPtr fn = (IsrFuncPtr)arg;
|
||||||
|
fn(); // call the original ISR
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implement attachInterrupt arduino like in ESP IDF
|
||||||
|
void attachInterrupt(uint32_t pin, IsrFuncPtr callback, uint32_t mode)
|
||||||
|
{
|
||||||
|
gpio_config_t io_conf = {
|
||||||
|
.pin_bit_mask = (1ULL << pin),
|
||||||
|
.mode = GPIO_MODE_INPUT,
|
||||||
|
.pull_up_en = GPIO_PULLUP_ENABLE,
|
||||||
|
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||||
|
.intr_type = (gpio_int_type_t)mode
|
||||||
|
};
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(gpio_config(&io_conf));
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(gpio_install_isr_service(0));
|
||||||
|
// Add ISR using the wrapper and pass original function as argument
|
||||||
|
ESP_ERROR_CHECK(gpio_isr_handler_add((gpio_num_t)pin, isr_wrapper, (void*)callback));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ESP_PLATFORM
|
||||||
|
#endif // !ARDUINO
|
87
src/esp32_idf_platform.h
Normal file
87
src/esp32_idf_platform.h
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#ifndef ARDUINO
|
||||||
|
#ifdef ESP_PLATFORM
|
||||||
|
// esp_idf_platform.h
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "driver/uart.h"
|
||||||
|
#include "esp_netif.h"
|
||||||
|
#include "esp_system.h"
|
||||||
|
#include "lwip/sockets.h"
|
||||||
|
#include "nvs_flash.h"
|
||||||
|
#include "knx/platform.h"// Include the provided base class
|
||||||
|
|
||||||
|
class Esp32IdfPlatform : public Platform
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Esp32IdfPlatform(uart_port_t uart_num = UART_NUM_1);
|
||||||
|
~Esp32IdfPlatform();
|
||||||
|
|
||||||
|
// uart
|
||||||
|
void knxUartPins(int8_t rxPin, int8_t txPin);
|
||||||
|
|
||||||
|
// Call this after WiFi/Ethernet has started and received an IP.
|
||||||
|
void setNetif(esp_netif_t* netif);
|
||||||
|
|
||||||
|
// --- Overridden Virtual Functions ---
|
||||||
|
|
||||||
|
// ip stuff
|
||||||
|
uint32_t currentIpAddress() override;
|
||||||
|
uint32_t currentSubnetMask() override;
|
||||||
|
uint32_t currentDefaultGateway() override;
|
||||||
|
void macAddress(uint8_t* addr) override;
|
||||||
|
|
||||||
|
// unique serial number
|
||||||
|
uint32_t uniqueSerialNumber() override;
|
||||||
|
|
||||||
|
// basic stuff (pure virtual in base)
|
||||||
|
void restart() override;
|
||||||
|
void fatalError() override;
|
||||||
|
|
||||||
|
// multicast
|
||||||
|
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, 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;
|
||||||
|
|
||||||
|
// UART
|
||||||
|
void setupUart() override;
|
||||||
|
void closeUart() override;
|
||||||
|
int uartAvailable() override;
|
||||||
|
size_t writeUart(const uint8_t data) override;
|
||||||
|
size_t writeUart(const uint8_t* buffer, size_t size) override;
|
||||||
|
int readUart() override;
|
||||||
|
size_t readBytesUart(uint8_t* buffer, size_t length) override;
|
||||||
|
void flushUart() override;
|
||||||
|
|
||||||
|
// Memory (EEPROM emulation via NVS)
|
||||||
|
// We override these two functions to provide the low-level storage mechanism.
|
||||||
|
// The base Platform class will use them when _memoryType is Eeprom.
|
||||||
|
uint8_t* getEepromBuffer(uint32_t size) override;
|
||||||
|
void commitToEeprom() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Network
|
||||||
|
esp_netif_t* _netif = nullptr;
|
||||||
|
int _sock = -1;
|
||||||
|
struct sockaddr_in _remote_addr;
|
||||||
|
uint32_t _multicast_addr = 0;
|
||||||
|
uint16_t _multicast_port = 0;
|
||||||
|
|
||||||
|
// UART
|
||||||
|
uart_port_t _uart_num;
|
||||||
|
int8_t _rxPin = -1;
|
||||||
|
int8_t _txPin = -1;
|
||||||
|
bool _uart_installed = false;
|
||||||
|
|
||||||
|
// NVS (for EEPROM emulation)
|
||||||
|
nvs_handle_t _nvs_handle;
|
||||||
|
uint8_t* _eeprom_buffer = nullptr;
|
||||||
|
uint32_t _eeprom_size = 0;
|
||||||
|
const char* _nvs_namespace = "eeprom";
|
||||||
|
const char* _nvs_key = "eeprom";
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
#endif
|
@ -247,7 +247,7 @@ void ApplicationLayer::dataSystemBroadcastIndication(HopCountType hopType, Prior
|
|||||||
popWord(propertyId, data + 3);
|
popWord(propertyId, data + 3);
|
||||||
popByte(testInfo[0], data + 4);
|
popByte(testInfo[0], data + 4);
|
||||||
popByte(testInfo[1], data + 5);
|
popByte(testInfo[1], data + 5);
|
||||||
propertyId = (propertyId >> 4) & 0x0FFF;;
|
propertyId = (propertyId >> 4) & 0x0FFF;
|
||||||
testInfo[0] &= 0x0F;
|
testInfo[0] &= 0x0F;
|
||||||
_bau.systemNetworkParameterReadIndication(priority, hopType, secCtrl, objectType, propertyId, testInfo, sizeof(testInfo));
|
_bau.systemNetworkParameterReadIndication(priority, hopType, secCtrl, objectType, propertyId, testInfo, sizeof(testInfo));
|
||||||
break;
|
break;
|
||||||
@ -296,7 +296,7 @@ void ApplicationLayer::dataSystemBroadcastConfirm(HopCountType hopType, Priority
|
|||||||
popWord(propertyId, data + 3);
|
popWord(propertyId, data + 3);
|
||||||
popByte(testInfo[0], data + 4);
|
popByte(testInfo[0], data + 4);
|
||||||
popByte(testInfo[1], data + 5);
|
popByte(testInfo[1], data + 5);
|
||||||
propertyId = (propertyId >> 4) & 0x0FFF;;
|
propertyId = (propertyId >> 4) & 0x0FFF;
|
||||||
testInfo[0] &= 0x0F;
|
testInfo[0] &= 0x0F;
|
||||||
_bau.systemNetworkParameterReadLocalConfirm(priority, hopType, secCtrl, objectType, propertyId, testInfo, sizeof(testInfo), status);
|
_bau.systemNetworkParameterReadLocalConfirm(priority, hopType, secCtrl, objectType, propertyId, testInfo, sizeof(testInfo), status);
|
||||||
break;
|
break;
|
||||||
|
@ -49,6 +49,7 @@ void BauSystemBDevice::loop()
|
|||||||
#ifdef USE_DATASECURE
|
#ifdef USE_DATASECURE
|
||||||
_appLayer.loop();
|
_appLayer.loop();
|
||||||
#endif
|
#endif
|
||||||
|
_memory.loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BauSystemBDevice::sendNextGroupTelegram()
|
void BauSystemBDevice::sendNextGroupTelegram()
|
||||||
|
186
src/knx/bits.cpp
186
src/knx/bits.cpp
@ -176,3 +176,189 @@ uint16_t crc16Dnp(uint8_t* input, uint16_t length)
|
|||||||
|
|
||||||
return (~crc) & 0xffff;
|
return (~crc) & 0xffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Produce Arduino print and println in ESP IDF for ESP32 family using printf().
|
||||||
|
#ifndef ARDUINO
|
||||||
|
#ifdef ESP_PLATFORM
|
||||||
|
// Helper function to print a number in binary format
|
||||||
|
static void print_binary(unsigned long long n)
|
||||||
|
{
|
||||||
|
if (n == 0)
|
||||||
|
{
|
||||||
|
printf("0");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Buffer for the maximum possible bits in an unsigned long long
|
||||||
|
char binary_string[65];
|
||||||
|
int i = 0;
|
||||||
|
while (n > 0)
|
||||||
|
{
|
||||||
|
binary_string[i++] = (n % 2) + '0';
|
||||||
|
n /= 2;
|
||||||
|
}
|
||||||
|
binary_string[i] = '\0';
|
||||||
|
|
||||||
|
// Reverse the string to get the correct binary representation
|
||||||
|
for (int j = 0; j < i / 2; ++j)
|
||||||
|
{
|
||||||
|
char temp = binary_string[j];
|
||||||
|
binary_string[j] = binary_string[i - j - 1];
|
||||||
|
binary_string[i - j - 1] = temp;
|
||||||
|
}
|
||||||
|
printf("%s", binary_string);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- print function implementations ---
|
||||||
|
|
||||||
|
void print(const char str[]) {
|
||||||
|
printf("%s", str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print(char c) {
|
||||||
|
printf("%c", c);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print(unsigned char b, int base) {
|
||||||
|
if (base == BIN) {
|
||||||
|
print_binary(b);
|
||||||
|
} else if (base == DEC) {
|
||||||
|
printf("%u", (unsigned int)b);
|
||||||
|
} else if (base == HEX) {
|
||||||
|
printf("%x", (unsigned int)b);
|
||||||
|
} else if (base == OCT) {
|
||||||
|
printf("%o", (unsigned int)b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print(int n, int base) {
|
||||||
|
if (base == BIN) {
|
||||||
|
print_binary(n);
|
||||||
|
} else if (base == DEC) {
|
||||||
|
printf("%d", n);
|
||||||
|
} else if (base == HEX) {
|
||||||
|
printf("%x", n);
|
||||||
|
} else if (base == OCT) {
|
||||||
|
printf("%o", n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print(unsigned int n, int base) {
|
||||||
|
if (base == BIN) {
|
||||||
|
print_binary(n);
|
||||||
|
} else if (base == DEC) {
|
||||||
|
printf("%u", n);
|
||||||
|
} else if (base == HEX) {
|
||||||
|
printf("%x", n);
|
||||||
|
} else if (base == OCT) {
|
||||||
|
printf("%o", n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print(long n, int base) {
|
||||||
|
if (base == BIN) {
|
||||||
|
print_binary(n);
|
||||||
|
} else if (base == DEC) {
|
||||||
|
printf("%ld", n);
|
||||||
|
} else if (base == HEX) {
|
||||||
|
printf("%lx", n);
|
||||||
|
} else if (base == OCT) {
|
||||||
|
printf("%lo", n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print(unsigned long n, int base) {
|
||||||
|
if (base == BIN) {
|
||||||
|
print_binary(n);
|
||||||
|
} else if (base == DEC) {
|
||||||
|
printf("%lu", n);
|
||||||
|
} else if (base == HEX) {
|
||||||
|
printf("%lx", n);
|
||||||
|
} else if (base == OCT) {
|
||||||
|
printf("%lo", n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print(long long n, int base) {
|
||||||
|
if (base == BIN) {
|
||||||
|
print_binary(n);
|
||||||
|
} else if (base == DEC) {
|
||||||
|
printf("%lld", n);
|
||||||
|
} else if (base == HEX) {
|
||||||
|
printf("%llx", n);
|
||||||
|
} else if (base == OCT) {
|
||||||
|
printf("%llo", n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print(unsigned long long n, int base) {
|
||||||
|
if (base == BIN) {
|
||||||
|
print_binary(n);
|
||||||
|
} else if (base == DEC) {
|
||||||
|
printf("%llu", n);
|
||||||
|
} else if (base == HEX) {
|
||||||
|
printf("%llx", n);
|
||||||
|
} else if (base == OCT) {
|
||||||
|
printf("%llo", n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print(double n) {
|
||||||
|
printf("%f", n);
|
||||||
|
}
|
||||||
|
|
||||||
|
void println(void) {
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void println(const char c[]) {
|
||||||
|
print(c);
|
||||||
|
println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void println(char c) {
|
||||||
|
print(c);
|
||||||
|
println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void println(unsigned char b, int base) {
|
||||||
|
print(b, base);
|
||||||
|
println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void println(int num, int base) {
|
||||||
|
print(num, base);
|
||||||
|
println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void println(unsigned int num, int base) {
|
||||||
|
print(num, base);
|
||||||
|
println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void println(long num, int base) {
|
||||||
|
print(num, base);
|
||||||
|
println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void println(unsigned long num, int base) {
|
||||||
|
print(num, base);
|
||||||
|
println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void println(long long num, int base) {
|
||||||
|
print(num, base);
|
||||||
|
println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void println(unsigned long long num, int base) {
|
||||||
|
print(num, base);
|
||||||
|
println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void println(double num) {
|
||||||
|
print(num);
|
||||||
|
println();
|
||||||
|
}
|
||||||
|
#endif // ESP_PLATFORM
|
||||||
|
#endif // !ARDUINO
|
||||||
|
@ -25,6 +25,28 @@
|
|||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <esp_wifi.h>
|
#include <esp_wifi.h>
|
||||||
|
#elif defined(ESP_PLATFORM)
|
||||||
|
#include <lwip/inet.h>
|
||||||
|
#include <driver/gpio.h>
|
||||||
|
// // Define Arduino-like macros if needed for compatibility
|
||||||
|
|
||||||
|
#define lowByte(val) ((val)&255)
|
||||||
|
#define highByte(val) (((val) >> ((sizeof(val) - 1) << 3)) & 255)
|
||||||
|
#define bitRead(val, bitno) (((val) >> (bitno)) & 1)
|
||||||
|
#define DEC 10
|
||||||
|
#define HEX 16
|
||||||
|
#define OCT 8
|
||||||
|
#define BIN 2
|
||||||
|
#define LOW 0
|
||||||
|
#define HIGH 1
|
||||||
|
#define CHANGE GPIO_INTR_ANYEDGE
|
||||||
|
#define FALLING GPIO_INTR_NEGEDGE
|
||||||
|
#define RISING GPIO_INTR_POSEDGE
|
||||||
|
// Implement or map Arduino-like functions if needed
|
||||||
|
uint32_t millis();
|
||||||
|
typedef void (*IsrFuncPtr)(void); // Arduino-style
|
||||||
|
typedef void (*EspIsrFuncPtr)(void*); // ESP-IDF-style
|
||||||
|
void attachInterrupt(uint32_t pin, IsrFuncPtr callback, uint32_t mode);
|
||||||
#else // Non-Arduino platforms
|
#else // Non-Arduino platforms
|
||||||
#define lowByte(val) ((val)&255)
|
#define lowByte(val) ((val)&255)
|
||||||
#define highByte(val) (((val) >> ((sizeof(val) - 1) << 3)) & 255)
|
#define highByte(val) (((val) >> ((sizeof(val) - 1) << 3)) & 255)
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#define ENSURE_PAYLOAD(x)
|
#define ENSURE_PAYLOAD(x)
|
||||||
|
|
||||||
|
|
||||||
int KNX_Decode_Value(uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool KNX_Decode_Value(uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
if (payload_length > 0)
|
if (payload_length > 0)
|
||||||
{
|
{
|
||||||
@ -106,6 +106,10 @@ int KNX_Decode_Value(uint8_t* payload, size_t payload_length, const Dpt& datatyp
|
|||||||
if (datatype.mainGroup == 19 && datatype.subGroup == 1 && (datatype.index <= 3 || datatype.index == 9 || datatype.index == 10))
|
if (datatype.mainGroup == 19 && datatype.subGroup == 1 && (datatype.index <= 3 || datatype.index == 9 || datatype.index == 10))
|
||||||
return busValueToDateTime(payload, payload_length, datatype, value);
|
return busValueToDateTime(payload, payload_length, datatype, value);
|
||||||
|
|
||||||
|
// DPT 20.* - HVAC Control mode Unsigned 8 Bit Integer
|
||||||
|
if (datatype.mainGroup == 20 && !datatype.index)
|
||||||
|
return busValueToUnsigned8(payload, payload_length, datatype, value);
|
||||||
|
|
||||||
// DPT 26.* - Scene Info
|
// DPT 26.* - Scene Info
|
||||||
if (datatype.mainGroup == 26 && datatype.subGroup == 1 && datatype.index <= 1)
|
if (datatype.mainGroup == 26 && datatype.subGroup == 1 && datatype.index <= 1)
|
||||||
return busValueToSceneInfo(payload, payload_length, datatype, value);
|
return busValueToSceneInfo(payload, payload_length, datatype, value);
|
||||||
@ -174,7 +178,7 @@ int KNX_Decode_Value(uint8_t* payload, size_t payload_length, const Dpt& datatyp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
if (datatype.mainGroup == 1 && datatype.subGroup >= 1 && datatype.subGroup <= 23 && datatype.subGroup != 20 && !datatype.index)
|
if (datatype.mainGroup == 1 && datatype.subGroup >= 1 && datatype.subGroup <= 23 && datatype.subGroup != 20 && !datatype.index)
|
||||||
return valueToBusValueBinary(value, payload, payload_length, datatype);
|
return valueToBusValueBinary(value, payload, payload_length, datatype);
|
||||||
@ -267,6 +271,10 @@ int KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_len
|
|||||||
if (datatype.mainGroup == 19 && datatype.subGroup == 1 && (datatype.index <= 3 || datatype.index == 9 || datatype.index == 10))
|
if (datatype.mainGroup == 19 && datatype.subGroup == 1 && (datatype.index <= 3 || datatype.index == 9 || datatype.index == 10))
|
||||||
return valueToBusValueDateTime(value, payload, payload_length, datatype);
|
return valueToBusValueDateTime(value, payload, payload_length, datatype);
|
||||||
|
|
||||||
|
// DPT 20.* - HVAC Control mode Unsigned 8 Bit Integer
|
||||||
|
if (datatype.mainGroup == 20 && !datatype.index)
|
||||||
|
return valueToBusValueUnsigned8(value, payload, payload_length, datatype);
|
||||||
|
|
||||||
// DPT 26.* - Scene Info
|
// DPT 26.* - Scene Info
|
||||||
if (datatype.mainGroup == 26 && datatype.subGroup == 1 && datatype.index <= 1)
|
if (datatype.mainGroup == 26 && datatype.subGroup == 1 && datatype.index <= 1)
|
||||||
return valueToBusValueSceneInfo(value, payload, payload_length, datatype);
|
return valueToBusValueSceneInfo(value, payload, payload_length, datatype);
|
||||||
@ -334,27 +342,27 @@ int KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_len
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToBinary(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToBinary(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(1);
|
ASSERT_PAYLOAD(1);
|
||||||
value = bitFromPayload(payload, 7);
|
value = bitFromPayload(payload, 7);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToBinaryControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToBinaryControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(1);
|
ASSERT_PAYLOAD(1);
|
||||||
value = (uint8_t)(unsigned8FromPayload(payload, 0) & 0x03);
|
value = (uint8_t)(unsigned8FromPayload(payload, 0) & 0x03);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToStepControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToStepControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(1);
|
ASSERT_PAYLOAD(1);
|
||||||
value = (uint8_t)(unsigned8FromPayload(payload, 0) & 0x0F);
|
value = (uint8_t)(unsigned8FromPayload(payload, 0) & 0x0F);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
int busValueToCharacter(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToCharacter(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(1);
|
ASSERT_PAYLOAD(1);
|
||||||
int8_t charValue = signed8FromPayload(payload, 0);
|
int8_t charValue = signed8FromPayload(payload, 0);
|
||||||
@ -372,7 +380,7 @@ int busValueToCharacter(const uint8_t* payload, size_t payload_length, const Dpt
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToUnsigned8(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToUnsigned8(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(1);
|
ASSERT_PAYLOAD(1);
|
||||||
|
|
||||||
@ -402,14 +410,14 @@ int busValueToUnsigned8(const uint8_t* payload, size_t payload_length, const Dpt
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToSigned8(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToSigned8(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(1);
|
ASSERT_PAYLOAD(1);
|
||||||
value = (uint8_t)(unsigned8FromPayload(payload, 0));
|
value = (uint8_t)(unsigned8FromPayload(payload, 0));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToStatusAndMode(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToStatusAndMode(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(1);
|
ASSERT_PAYLOAD(1);
|
||||||
|
|
||||||
@ -427,14 +435,14 @@ int busValueToStatusAndMode(const uint8_t* payload, size_t payload_length, const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToUnsigned16(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToUnsigned16(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(2);
|
ASSERT_PAYLOAD(2);
|
||||||
value = unsigned16FromPayload(payload, 0);
|
value = unsigned16FromPayload(payload, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToTimePeriod(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToTimePeriod(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(2);
|
ASSERT_PAYLOAD(2);
|
||||||
|
|
||||||
@ -443,7 +451,7 @@ int busValueToTimePeriod(const uint8_t* payload, size_t payload_length, const Dp
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToSigned16(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToSigned16(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(2);
|
ASSERT_PAYLOAD(2);
|
||||||
|
|
||||||
@ -457,7 +465,7 @@ int busValueToSigned16(const uint8_t* payload, size_t payload_length, const Dpt&
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToTimeDelta(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToTimeDelta(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(2);
|
ASSERT_PAYLOAD(2);
|
||||||
|
|
||||||
@ -466,7 +474,7 @@ int busValueToTimeDelta(const uint8_t* payload, size_t payload_length, const Dpt
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToFloat16(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToFloat16(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(2);
|
ASSERT_PAYLOAD(2);
|
||||||
|
|
||||||
@ -477,7 +485,7 @@ int busValueToFloat16(const uint8_t* payload, size_t payload_length, const Dpt&
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToTime(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToTime(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(3);
|
ASSERT_PAYLOAD(3);
|
||||||
|
|
||||||
@ -497,7 +505,8 @@ int busValueToTime(const uint8_t* payload, size_t payload_length, const Dpt& dat
|
|||||||
if (hours > 23 || minutes > 59 || seconds > 59)
|
if (hours > 23 || minutes > 59 || seconds > 59)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
struct tm tmp = {0};
|
struct tm tmp;
|
||||||
|
memset(&tmp, 0, sizeof(tmp));
|
||||||
tmp.tm_hour = hours;
|
tmp.tm_hour = hours;
|
||||||
tmp.tm_wday = weekDay;
|
tmp.tm_wday = weekDay;
|
||||||
tmp.tm_min = minutes;
|
tmp.tm_min = minutes;
|
||||||
@ -510,7 +519,7 @@ int busValueToTime(const uint8_t* payload, size_t payload_length, const Dpt& dat
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToDate(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToDate(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(3);
|
ASSERT_PAYLOAD(3);
|
||||||
unsigned short year = unsigned8FromPayload(payload, 2) & 0x7F;
|
unsigned short year = unsigned8FromPayload(payload, 2) & 0x7F;
|
||||||
@ -520,7 +529,8 @@ int busValueToDate(const uint8_t* payload, size_t payload_length, const Dpt& dat
|
|||||||
if (year > 99 || month < 1 || month > 12 || day < 1)
|
if (year > 99 || month < 1 || month > 12 || day < 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
struct tm tmp = {0};
|
struct tm tmp;
|
||||||
|
memset(&tmp, 0, sizeof(tmp));
|
||||||
year += year >= 90 ? 1900 : 2000;
|
year += year >= 90 ? 1900 : 2000;
|
||||||
tmp.tm_mday = day;
|
tmp.tm_mday = day;
|
||||||
tmp.tm_year = year;
|
tmp.tm_year = year;
|
||||||
@ -529,35 +539,35 @@ int busValueToDate(const uint8_t* payload, size_t payload_length, const Dpt& dat
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToUnsigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToUnsigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(4);
|
ASSERT_PAYLOAD(4);
|
||||||
value = unsigned32FromPayload(payload, 0);
|
value = unsigned32FromPayload(payload, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToSigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToSigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(4);
|
ASSERT_PAYLOAD(4);
|
||||||
value = signed32FromPayload(payload, 0);
|
value = signed32FromPayload(payload, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToLongTimePeriod(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToLongTimePeriod(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(4);
|
ASSERT_PAYLOAD(4);
|
||||||
value = signed32FromPayload(payload, 0);
|
value = signed32FromPayload(payload, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToFloat32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToFloat32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(4);
|
ASSERT_PAYLOAD(4);
|
||||||
value = float32FromPayload(payload, 0);
|
value = float32FromPayload(payload, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToAccess(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToAccess(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(4);
|
ASSERT_PAYLOAD(4);
|
||||||
|
|
||||||
@ -596,7 +606,7 @@ int busValueToAccess(const uint8_t* payload, size_t payload_length, const Dpt& d
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToString(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToString(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(14);
|
ASSERT_PAYLOAD(14);
|
||||||
|
|
||||||
@ -612,14 +622,14 @@ int busValueToString(const uint8_t* payload, size_t payload_length, const Dpt& d
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToScene(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToScene(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(1);
|
ASSERT_PAYLOAD(1);
|
||||||
value = (uint8_t)(unsigned8FromPayload(payload, 0) & 0x3F);
|
value = (uint8_t)(unsigned8FromPayload(payload, 0) & 0x3F);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToSceneControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToSceneControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(1);
|
ASSERT_PAYLOAD(1);
|
||||||
|
|
||||||
@ -641,7 +651,7 @@ int busValueToSceneControl(const uint8_t* payload, size_t payload_length, const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToSceneInfo(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToSceneInfo(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(1);
|
ASSERT_PAYLOAD(1);
|
||||||
|
|
||||||
@ -663,7 +673,7 @@ int busValueToSceneInfo(const uint8_t* payload, size_t payload_length, const Dpt
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToSceneConfig(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToSceneConfig(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(1);
|
ASSERT_PAYLOAD(1);
|
||||||
|
|
||||||
@ -686,7 +696,7 @@ int busValueToSceneConfig(const uint8_t* payload, size_t payload_length, const D
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToDateTime(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToDateTime(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(8);
|
ASSERT_PAYLOAD(8);
|
||||||
|
|
||||||
@ -718,7 +728,8 @@ int busValueToDateTime(const uint8_t* payload, size_t payload_length, const Dpt&
|
|||||||
if ((hours > 24 || minutes > 59 || seconds > 59))
|
if ((hours > 24 || minutes > 59 || seconds > 59))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
struct tm tmp = {0};
|
struct tm tmp;
|
||||||
|
memset(&tmp, 0, sizeof(tmp));
|
||||||
tmp.tm_sec = seconds;
|
tmp.tm_sec = seconds;
|
||||||
tmp.tm_min = minutes;
|
tmp.tm_min = minutes;
|
||||||
tmp.tm_hour = hours;
|
tmp.tm_hour = hours;
|
||||||
@ -764,20 +775,20 @@ int busValueToDateTime(const uint8_t* payload, size_t payload_length, const Dpt&
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToUnicode(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToUnicode(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
//TODO
|
//TODO
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToSigned64(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToSigned64(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(8);
|
ASSERT_PAYLOAD(8);
|
||||||
value = signed64FromPayload(payload, 0);
|
value = signed64FromPayload(payload, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToAlarmInfo(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToAlarmInfo(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(6);
|
ASSERT_PAYLOAD(6);
|
||||||
|
|
||||||
@ -817,7 +828,7 @@ int busValueToAlarmInfo(const uint8_t* payload, size_t payload_length, const Dpt
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToSerialNumber(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToSerialNumber(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(6);
|
ASSERT_PAYLOAD(6);
|
||||||
|
|
||||||
@ -835,7 +846,7 @@ int busValueToSerialNumber(const uint8_t* payload, size_t payload_length, const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToVersion(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToVersion(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(2);
|
ASSERT_PAYLOAD(2);
|
||||||
|
|
||||||
@ -857,7 +868,7 @@ int busValueToVersion(const uint8_t* payload, size_t payload_length, const Dpt&
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToScaling(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToScaling(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(3);
|
ASSERT_PAYLOAD(3);
|
||||||
|
|
||||||
@ -875,7 +886,7 @@ int busValueToScaling(const uint8_t* payload, size_t payload_length, const Dpt&
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToTariff(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToTariff(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(3);
|
ASSERT_PAYLOAD(3);
|
||||||
|
|
||||||
@ -900,7 +911,7 @@ int busValueToTariff(const uint8_t* payload, size_t payload_length, const Dpt& d
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToLocale(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToLocale(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(datatype.mainGroup == 231 ? 4 : 2);
|
ASSERT_PAYLOAD(datatype.mainGroup == 231 ? 4 : 2);
|
||||||
|
|
||||||
@ -916,15 +927,15 @@ int busValueToLocale(const uint8_t* payload, size_t payload_length, const Dpt& d
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToRGB(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToRGB(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(3);
|
ASSERT_PAYLOAD(3);
|
||||||
uint32_t rgb = unsigned16FromPayload(payload, 0) * 256 + unsigned8FromPayload(payload, 2);
|
uint32_t rgb = (unsigned16FromPayload(payload, 0) << 8) | unsigned8FromPayload(payload, 2);
|
||||||
value = rgb;
|
value = rgb;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToRGBW(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToRGBW(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(6);
|
ASSERT_PAYLOAD(6);
|
||||||
|
|
||||||
@ -934,19 +945,19 @@ int busValueToRGBW(const uint8_t* payload, size_t payload_length, const Dpt& dat
|
|||||||
{
|
{
|
||||||
uint32_t rgbw = unsigned32FromPayload(payload, 0);
|
uint32_t rgbw = unsigned32FromPayload(payload, 0);
|
||||||
value = rgbw;
|
value = rgbw;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
case 1: // The mask bits only
|
case 1: // The mask bits only
|
||||||
|
{
|
||||||
value = unsigned8FromPayload(payload, 5);
|
value = unsigned8FromPayload(payload, 5);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToFlaggedScaling(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToFlaggedScaling(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(2);
|
ASSERT_PAYLOAD(2);
|
||||||
|
|
||||||
@ -964,7 +975,7 @@ int busValueToFlaggedScaling(const uint8_t* payload, size_t payload_length, cons
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int busValueToActiveEnergy(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
bool busValueToActiveEnergy(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(6);
|
ASSERT_PAYLOAD(6);
|
||||||
|
|
||||||
@ -989,25 +1000,25 @@ int busValueToActiveEnergy(const uint8_t* payload, size_t payload_length, const
|
|||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
int valueToBusValueBinary(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueBinary(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
bitToPayload(payload, payload_length, 7, value);
|
bitToPayload(payload, payload_length, 7, value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueBinaryControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueBinaryControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
unsigned8ToPayload(payload, payload_length, 0, (uint64_t)value, 0x03);
|
unsigned8ToPayload(payload, payload_length, 0, (uint64_t)value, 0x03);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueStepControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueStepControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
unsigned8ToPayload(payload, payload_length, 0, (uint64_t)value, 0x0F);
|
unsigned8ToPayload(payload, payload_length, 0, (uint64_t)value, 0x0F);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueCharacter(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueCharacter(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
if ((uint64_t)value > INT64_C(255) || (datatype.subGroup == 1 && (uint64_t)value > INT64_C(127)))
|
if ((uint64_t)value > INT64_C(255) || (datatype.subGroup == 1 && (uint64_t)value > INT64_C(127)))
|
||||||
return false;
|
return false;
|
||||||
@ -1016,7 +1027,7 @@ int valueToBusValueCharacter(const KNXValue& value, uint8_t* payload, size_t pay
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueUnsigned8(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueUnsigned8(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
if ((int64_t)value < INT64_C(0))
|
if ((int64_t)value < INT64_C(0))
|
||||||
return false;
|
return false;
|
||||||
@ -1062,7 +1073,7 @@ int valueToBusValueUnsigned8(const KNXValue& value, uint8_t* payload, size_t pay
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueSigned8(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueSigned8(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
if ((int64_t)value < INT64_C(-128) || (int64_t)value > INT64_C(127))
|
if ((int64_t)value < INT64_C(-128) || (int64_t)value > INT64_C(127))
|
||||||
return false;
|
return false;
|
||||||
@ -1071,7 +1082,7 @@ int valueToBusValueSigned8(const KNXValue& value, uint8_t* payload, size_t paylo
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueStatusAndMode(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueStatusAndMode(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
if (datatype.index < 5)
|
if (datatype.index < 5)
|
||||||
bitToPayload(payload, payload_length, datatype.index, value);
|
bitToPayload(payload, payload_length, datatype.index, value);
|
||||||
@ -1088,7 +1099,7 @@ int valueToBusValueStatusAndMode(const KNXValue& value, uint8_t* payload, size_t
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueUnsigned16(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueUnsigned16(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
if ((int64_t)value < INT64_C(0) || (int64_t)value > INT64_C(65535))
|
if ((int64_t)value < INT64_C(0) || (int64_t)value > INT64_C(65535))
|
||||||
return false;
|
return false;
|
||||||
@ -1097,7 +1108,7 @@ int valueToBusValueUnsigned16(const KNXValue& value, uint8_t* payload, size_t pa
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueTimePeriod(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueTimePeriod(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
struct tm tmp = value;
|
struct tm tmp = value;
|
||||||
time_t timeSinceEpoch = mktime(&tmp);
|
time_t timeSinceEpoch = mktime(&tmp);
|
||||||
@ -1109,7 +1120,7 @@ int valueToBusValueTimePeriod(const KNXValue& value, uint8_t* payload, size_t pa
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueSigned16(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueSigned16(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
if ((int64_t)value < INT64_C(-32768) || (int64_t)value > INT64_C(32767))
|
if ((int64_t)value < INT64_C(-32768) || (int64_t)value > INT64_C(32767))
|
||||||
return false;
|
return false;
|
||||||
@ -1127,7 +1138,7 @@ int valueToBusValueSigned16(const KNXValue& value, uint8_t* payload, size_t payl
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueTimeDelta(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueTimeDelta(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
struct tm tmp = value;
|
struct tm tmp = value;
|
||||||
time_t timeSinceEpoch = mktime(&tmp);
|
time_t timeSinceEpoch = mktime(&tmp);
|
||||||
@ -1139,7 +1150,7 @@ int valueToBusValueTimeDelta(const KNXValue& value, uint8_t* payload, size_t pay
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueFloat16(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueFloat16(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
double numValue = value;
|
double numValue = value;
|
||||||
|
|
||||||
@ -1196,7 +1207,7 @@ int valueToBusValueFloat16(const KNXValue& value, uint8_t* payload, size_t paylo
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueTime(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueTime(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
switch (datatype.index)
|
switch (datatype.index)
|
||||||
{
|
{
|
||||||
@ -1226,7 +1237,7 @@ int valueToBusValueTime(const KNXValue& value, uint8_t* payload, size_t payload_
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueDate(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueDate(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
struct tm tmp = value;
|
struct tm tmp = value;
|
||||||
|
|
||||||
@ -1239,7 +1250,7 @@ int valueToBusValueDate(const KNXValue& value, uint8_t* payload, size_t payload_
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueUnsigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueUnsigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
if ((int64_t)value < INT64_C(0) || (int64_t)value > INT64_C(4294967295))
|
if ((int64_t)value < INT64_C(0) || (int64_t)value > INT64_C(4294967295))
|
||||||
return false;
|
return false;
|
||||||
@ -1248,7 +1259,7 @@ int valueToBusValueUnsigned32(const KNXValue& value, uint8_t* payload, size_t pa
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueSigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueSigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
if ((int64_t)value < INT64_C(-2147483648) || (int64_t)value > INT64_C(2147483647))
|
if ((int64_t)value < INT64_C(-2147483648) || (int64_t)value > INT64_C(2147483647))
|
||||||
return false;
|
return false;
|
||||||
@ -1257,7 +1268,7 @@ int valueToBusValueSigned32(const KNXValue& value, uint8_t* payload, size_t payl
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueLongTimePeriod(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueLongTimePeriod(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
if ((int64_t)value < INT64_C(-2147483648) || (int64_t)value > INT64_C(2147483647))
|
if ((int64_t)value < INT64_C(-2147483648) || (int64_t)value > INT64_C(2147483647))
|
||||||
return false;
|
return false;
|
||||||
@ -1266,7 +1277,7 @@ int valueToBusValueLongTimePeriod(const KNXValue& value, uint8_t* payload, size_
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueFloat32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueFloat32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
double numValue = value;
|
double numValue = value;
|
||||||
|
|
||||||
@ -1277,7 +1288,7 @@ int valueToBusValueFloat32(const KNXValue& value, uint8_t* payload, size_t paylo
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueAccess(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueAccess(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
switch (datatype.index)
|
switch (datatype.index)
|
||||||
{
|
{
|
||||||
@ -1317,7 +1328,7 @@ int valueToBusValueAccess(const KNXValue& value, uint8_t* payload, size_t payloa
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueString(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueString(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
const char* strValue = value;
|
const char* strValue = value;
|
||||||
uint8_t val = strValue[0];
|
uint8_t val = strValue[0];
|
||||||
@ -1333,7 +1344,7 @@ int valueToBusValueString(const KNXValue& value, uint8_t* payload, size_t payloa
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueScene(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueScene(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
if ((int64_t)value < INT64_C(0) || (int64_t)value > INT64_C(63))
|
if ((int64_t)value < INT64_C(0) || (int64_t)value > INT64_C(63))
|
||||||
return false;
|
return false;
|
||||||
@ -1342,7 +1353,7 @@ int valueToBusValueScene(const KNXValue& value, uint8_t* payload, size_t payload
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueSceneControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueSceneControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
switch (datatype.index)
|
switch (datatype.index)
|
||||||
{
|
{
|
||||||
@ -1366,7 +1377,7 @@ int valueToBusValueSceneControl(const KNXValue& value, uint8_t* payload, size_t
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueSceneInfo(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueSceneInfo(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
switch (datatype.index)
|
switch (datatype.index)
|
||||||
{
|
{
|
||||||
@ -1390,7 +1401,7 @@ int valueToBusValueSceneInfo(const KNXValue& value, uint8_t* payload, size_t pay
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueSceneConfig(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueSceneConfig(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
switch (datatype.index)
|
switch (datatype.index)
|
||||||
{
|
{
|
||||||
@ -1415,7 +1426,7 @@ int valueToBusValueSceneConfig(const KNXValue& value, uint8_t* payload, size_t p
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueDateTime(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueDateTime(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
switch (datatype.index)
|
switch (datatype.index)
|
||||||
{
|
{
|
||||||
@ -1492,19 +1503,19 @@ int valueToBusValueDateTime(const KNXValue& value, uint8_t* payload, size_t payl
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueUnicode(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueUnicode(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
//TODO
|
//TODO
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueSigned64(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueSigned64(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
signed64ToPayload(payload, payload_length, 0, (int64_t)value, UINT64_C(0xFFFFFFFFFFFFFFFF));
|
signed64ToPayload(payload, payload_length, 0, (int64_t)value, UINT64_C(0xFFFFFFFFFFFFFFFF));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueAlarmInfo(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueAlarmInfo(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
switch (datatype.index)
|
switch (datatype.index)
|
||||||
{
|
{
|
||||||
@ -1556,7 +1567,7 @@ int valueToBusValueAlarmInfo(const KNXValue& value, uint8_t* payload, size_t pay
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueSerialNumber(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueSerialNumber(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
switch (datatype.index)
|
switch (datatype.index)
|
||||||
{
|
{
|
||||||
@ -1587,7 +1598,7 @@ int valueToBusValueSerialNumber(const KNXValue& value, uint8_t* payload, size_t
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueVersion(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueVersion(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
switch (datatype.index)
|
switch (datatype.index)
|
||||||
{
|
{
|
||||||
@ -1626,7 +1637,7 @@ int valueToBusValueVersion(const KNXValue& value, uint8_t* payload, size_t paylo
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueScaling(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueScaling(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
switch (datatype.index)
|
switch (datatype.index)
|
||||||
{
|
{
|
||||||
@ -1655,7 +1666,7 @@ int valueToBusValueScaling(const KNXValue& value, uint8_t* payload, size_t paylo
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueTariff(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueTariff(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
switch (datatype.index)
|
switch (datatype.index)
|
||||||
{
|
{
|
||||||
@ -1684,7 +1695,7 @@ int valueToBusValueTariff(const KNXValue& value, uint8_t* payload, size_t payloa
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueLocale(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueLocale(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
int strl = strlen(value);
|
int strl = strlen(value);
|
||||||
|
|
||||||
@ -1702,19 +1713,19 @@ int valueToBusValueLocale(const KNXValue& value, uint8_t* payload, size_t payloa
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueRGB(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueRGB(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
if ((int64_t)value < INT64_C(0) || (int64_t)value > INT64_C(16777215))
|
if ((int64_t)value < INT64_C(0) || (int64_t)value > INT64_C(0xffffff))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
unsigned int rgb = (int64_t)value;
|
unsigned int rgb = (int64_t)value;
|
||||||
|
|
||||||
unsigned16ToPayload(payload, payload_length, 0, rgb / 256, 0xffff);
|
unsigned16ToPayload(payload, payload_length, 0, rgb >> 8, 0xffff);
|
||||||
unsigned8ToPayload(payload, payload_length, 2, rgb % 256, 0xff);
|
unsigned8ToPayload(payload, payload_length, 2, rgb & 0xff, 0xff);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueRGBW(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueRGBW(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
switch (datatype.index)
|
switch (datatype.index)
|
||||||
{
|
{
|
||||||
@ -1722,18 +1733,19 @@ int valueToBusValueRGBW(const KNXValue& value, uint8_t* payload, size_t payload_
|
|||||||
{
|
{
|
||||||
uint32_t rgbw = (uint32_t)value;
|
uint32_t rgbw = (uint32_t)value;
|
||||||
unsigned32ToPayload(payload, payload_length, 0, rgbw, 0xffffffff); // RGBW
|
unsigned32ToPayload(payload, payload_length, 0, rgbw, 0xffffffff); // RGBW
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 1: // Mask bits
|
case 1: // Mask bits
|
||||||
|
{
|
||||||
unsigned8ToPayload(payload, payload_length, 5, (uint8_t)value, 0x0f);
|
unsigned8ToPayload(payload, payload_length, 5, (uint8_t)value, 0x0f);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueFlaggedScaling(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueFlaggedScaling(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
switch (datatype.index)
|
switch (datatype.index)
|
||||||
{
|
{
|
||||||
@ -1758,7 +1770,7 @@ int valueToBusValueFlaggedScaling(const KNXValue& value, uint8_t* payload, size_
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToBusValueActiveEnergy(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
bool valueToBusValueActiveEnergy(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
switch (datatype.index)
|
switch (datatype.index)
|
||||||
{
|
{
|
||||||
|
@ -36,90 +36,90 @@
|
|||||||
/**
|
/**
|
||||||
* Converts the KNX Payload given by the specific DPT and puts the value in the KNXValue struc
|
* Converts the KNX Payload given by the specific DPT and puts the value in the KNXValue struc
|
||||||
*/
|
*/
|
||||||
int KNX_Decode_Value(uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool KNX_Decode_Value(uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the KNXValue struct to the KNX Payload as the specific DPT
|
* Converts the KNXValue struct to the KNX Payload as the specific DPT
|
||||||
*/
|
*/
|
||||||
int KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
|
|
||||||
//KNX to internal
|
//KNX to internal
|
||||||
int busValueToBinary(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToBinary(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToBinaryControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToBinaryControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToStepControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToStepControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToCharacter(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToCharacter(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToUnsigned8(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToUnsigned8(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToSigned8(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToSigned8(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToStatusAndMode(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToStatusAndMode(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToUnsigned16(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToUnsigned16(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToTimePeriod(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToTimePeriod(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToSigned16(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToSigned16(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToTimeDelta(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToTimeDelta(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToFloat16(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToFloat16(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToTime(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToTime(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToDate(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToDate(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToUnsigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToUnsigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToSigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToSigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToLongTimePeriod(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToLongTimePeriod(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToFloat32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToFloat32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToAccess(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToAccess(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToString(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToString(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToScene(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToScene(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToSceneControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToSceneControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToSceneInfo(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToSceneInfo(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToSceneConfig(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToSceneConfig(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToDateTime(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToDateTime(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToUnicode(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToUnicode(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToSigned64(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToSigned64(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToAlarmInfo(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToAlarmInfo(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToSerialNumber(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToSerialNumber(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToVersion(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToVersion(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToScaling(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToScaling(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToTariff(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToTariff(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToLocale(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToLocale(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToRGB(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToRGB(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToRGBW(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToRGBW(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToFlaggedScaling(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToFlaggedScaling(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
int busValueToActiveEnergy(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
bool busValueToActiveEnergy(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||||
|
|
||||||
//Internal to KNX
|
//Internal to KNX
|
||||||
int valueToBusValueBinary(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueBinary(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueBinaryControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueBinaryControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueStepControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueStepControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueCharacter(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueCharacter(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueUnsigned8(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueUnsigned8(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueSigned8(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueSigned8(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueStatusAndMode(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueStatusAndMode(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueUnsigned16(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueUnsigned16(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueTimePeriod(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueTimePeriod(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueSigned16(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueSigned16(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueTimeDelta(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueTimeDelta(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueFloat16(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueFloat16(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueTime(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueTime(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueDate(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueDate(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueUnsigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueUnsigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueSigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueSigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueLongTimePeriod(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueLongTimePeriod(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueFloat32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueFloat32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueAccess(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueAccess(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueString(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueString(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueScene(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueScene(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueSceneControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueSceneControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueSceneInfo(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueSceneInfo(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueSceneConfig(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueSceneConfig(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueDateTime(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueDateTime(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueUnicode(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueUnicode(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueSigned64(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueSigned64(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueAlarmInfo(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueAlarmInfo(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueSerialNumber(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueSerialNumber(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueVersion(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueVersion(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueScaling(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueScaling(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueTariff(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueTariff(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueLocale(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueLocale(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueRGB(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueRGB(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueRGBW(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueRGBW(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueFlaggedScaling(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueFlaggedScaling(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
int valueToBusValueActiveEnergy(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
bool valueToBusValueActiveEnergy(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||||
|
|
||||||
//Payload manipulation
|
//Payload manipulation
|
||||||
bool bitFromPayload(const uint8_t* payload, int index);
|
bool bitFromPayload(const uint8_t* payload, int index);
|
||||||
|
@ -21,7 +21,7 @@ enum ComFlag : uint8_t
|
|||||||
class GroupObject;
|
class GroupObject;
|
||||||
|
|
||||||
#ifndef HAS_FUNCTIONAL
|
#ifndef HAS_FUNCTIONAL
|
||||||
#if defined(__linux__) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_STM32) || defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_RP2040) || defined(LIBRETINY)
|
#if defined(__linux__) || defined(ARDUINO_ARCH_ESP32) || defined(ESP_PLATFORM) || defined(ARDUINO_ARCH_STM32) || defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_RP2040) || defined(LIBRETINY)
|
||||||
#define HAS_FUNCTIONAL 1
|
#define HAS_FUNCTIONAL 1
|
||||||
#else
|
#else
|
||||||
#define HAS_FUNCTIONAL 0
|
#define HAS_FUNCTIONAL 0
|
||||||
|
@ -122,7 +122,7 @@ void InterfaceObject::command(PropertyID id, uint8_t* data, uint8_t length, uint
|
|||||||
if (prop == nullptr)
|
if (prop == nullptr)
|
||||||
{
|
{
|
||||||
resultLength = 0;
|
resultLength = 0;
|
||||||
return;;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
prop->command(data, length, resultData, resultLength);
|
prop->command(data, length, resultData, resultLength);
|
||||||
@ -135,7 +135,7 @@ void InterfaceObject::state(PropertyID id, uint8_t* data, uint8_t length, uint8_
|
|||||||
if (prop == nullptr)
|
if (prop == nullptr)
|
||||||
{
|
{
|
||||||
resultLength = 0;
|
resultLength = 0;
|
||||||
return;;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
prop->state(data, length, resultData, resultLength);
|
prop->state(data, length, resultData, resultLength);
|
||||||
|
@ -601,7 +601,8 @@ struct tm KNXValue::timeValue() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tm tmp = {0};
|
struct tm tmp;
|
||||||
|
memset(&tmp, 0, sizeof(tmp));
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
@ -301,10 +301,15 @@ void Memory::freeMemory(uint8_t* ptr)
|
|||||||
|
|
||||||
removeFromUsedList(block);
|
removeFromUsedList(block);
|
||||||
addToFreeList(block);
|
addToFreeList(block);
|
||||||
|
_saveTimeout = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Memory::writeMemory(uint32_t relativeAddress, size_t size, uint8_t* data)
|
void Memory::writeMemory(uint32_t relativeAddress, size_t size, uint8_t* data)
|
||||||
{
|
{
|
||||||
|
if(_saveTimeout != 0)
|
||||||
|
{
|
||||||
|
_saveTimeout = millis();
|
||||||
|
}
|
||||||
_platform.writeNonVolatileMemory(relativeAddress, data, size);
|
_platform.writeNonVolatileMemory(relativeAddress, data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,3 +546,13 @@ VersionCheckCallback Memory::versionCheckCallback()
|
|||||||
{
|
{
|
||||||
return _versionCheckCallback;
|
return _versionCheckCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Memory::loop()
|
||||||
|
{
|
||||||
|
if(_saveTimeout != 0 && millis() - _saveTimeout > 5000)
|
||||||
|
{
|
||||||
|
println("saveMemory timeout");
|
||||||
|
_saveTimeout = 0;
|
||||||
|
writeMemory();
|
||||||
|
}
|
||||||
|
}
|
@ -46,6 +46,7 @@ class Memory
|
|||||||
void clearMemory();
|
void clearMemory();
|
||||||
void addSaveRestore(SaveRestore* obj);
|
void addSaveRestore(SaveRestore* obj);
|
||||||
void addSaveRestore(TableObject* obj);
|
void addSaveRestore(TableObject* obj);
|
||||||
|
void loop();
|
||||||
|
|
||||||
uint8_t* allocMemory(size_t size);
|
uint8_t* allocMemory(size_t size);
|
||||||
void freeMemory(uint8_t* ptr);
|
void freeMemory(uint8_t* ptr);
|
||||||
@ -82,4 +83,5 @@ class Memory
|
|||||||
MemoryBlock* _freeList = nullptr;
|
MemoryBlock* _freeList = nullptr;
|
||||||
MemoryBlock* _usedList = nullptr;
|
MemoryBlock* _usedList = nullptr;
|
||||||
uint16_t _metadataSize = 6 + LEN_HARDWARE_TYPE; // accounting for 3x pushWord and pushByteArray of length LEN_HARDWARE_TYPE
|
uint16_t _metadataSize = 6 + LEN_HARDWARE_TYPE; // accounting for 3x pushWord and pushByteArray of length LEN_HARDWARE_TYPE
|
||||||
|
unsigned long _saveTimeout = 0;
|
||||||
};
|
};
|
||||||
|
@ -106,6 +106,17 @@ IRAM_ATTR void buttonEvent()
|
|||||||
KnxFacade<LibretinyPlatform, Bau091A> knx(buttonEvent);
|
KnxFacade<LibretinyPlatform, Bau091A> knx(buttonEvent);
|
||||||
#else
|
#else
|
||||||
#error "Mask version not supported on LIBRETINY"
|
#error "Mask version not supported on LIBRETINY"
|
||||||
|
|
||||||
|
#elif defined(ESP_PLATFORM)
|
||||||
|
// predefined global instance for TP or IP or TP/IP coupler
|
||||||
|
#if MASK_VERSION == 0x07B0
|
||||||
|
KnxFacade<Esp32IdfPlatform, Bau07B0> knx(buttonEvent);
|
||||||
|
#elif MASK_VERSION == 0x57B0
|
||||||
|
KnxFacade<Esp32IdfPlatform, Bau57B0> knx(buttonEvent);
|
||||||
|
#elif MASK_VERSION == 0x091A
|
||||||
|
KnxFacade<Esp32IdfPlatform, Bau091A> knx(buttonEvent);
|
||||||
|
#else
|
||||||
|
#error "Mask version not supported on ESP_IDF_ESP32"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(ARDUINO_ARCH_STM32)
|
#elif defined(ARDUINO_ARCH_STM32)
|
||||||
|
@ -34,6 +34,8 @@
|
|||||||
#endif
|
#endif
|
||||||
#elif defined(LIBRETINY)
|
#elif defined(LIBRETINY)
|
||||||
#include "libretiny_platform.h"
|
#include "libretiny_platform.h"
|
||||||
|
#elif defined(ESP_PLATFORM)
|
||||||
|
#include "esp32_idf_platform.h"
|
||||||
#ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE
|
#ifndef KNX_NO_AUTOMATIC_GLOBAL_INSTANCE
|
||||||
void buttonUp();
|
void buttonUp();
|
||||||
#endif
|
#endif
|
||||||
@ -265,13 +267,27 @@ template <class P, class B> class KnxFacade : private SaveRestore
|
|||||||
|
|
||||||
void start()
|
void start()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (_ledPin >= 0)
|
if (_ledPin >= 0)
|
||||||
|
{
|
||||||
|
#if defined(ESP_PLATFORM)
|
||||||
|
gpio_reset_pin((gpio_num_t)ledPin());
|
||||||
|
gpio_set_direction((gpio_num_t)ledPin(), GPIO_MODE_OUTPUT);
|
||||||
|
#else
|
||||||
pinMode(_ledPin, OUTPUT);
|
pinMode(_ledPin, OUTPUT);
|
||||||
|
#endif // ESP_PLATFORM
|
||||||
|
}
|
||||||
|
|
||||||
progLedOff();
|
progLedOff();
|
||||||
|
|
||||||
if(_buttonPin >= 0)
|
if(_buttonPin >= 0)
|
||||||
{
|
{
|
||||||
|
#if defined(ESP_PLATFORM)
|
||||||
|
if (_progButtonISRFuncPtr)
|
||||||
|
{
|
||||||
|
attachInterrupt(_buttonPin, _progButtonISRFuncPtr, CHANGE);
|
||||||
|
}
|
||||||
|
#else
|
||||||
pinMode(_buttonPin, INPUT_PULLUP);
|
pinMode(_buttonPin, INPUT_PULLUP);
|
||||||
|
|
||||||
if (_progButtonISRFuncPtr)
|
if (_progButtonISRFuncPtr)
|
||||||
@ -281,8 +297,9 @@ template <class P, class B> class KnxFacade : private SaveRestore
|
|||||||
attachInterrupt(_buttonPin, _progButtonISRFuncPtr, (PinStatus)CHANGE);
|
attachInterrupt(_buttonPin, _progButtonISRFuncPtr, (PinStatus)CHANGE);
|
||||||
#else
|
#else
|
||||||
attachInterrupt(_buttonPin, _progButtonISRFuncPtr, CHANGE);
|
attachInterrupt(_buttonPin, _progButtonISRFuncPtr, CHANGE);
|
||||||
#endif
|
#endif // ARDUINO_API_VERSION
|
||||||
}
|
}
|
||||||
|
#endif // ESP_PLATFORM
|
||||||
}
|
}
|
||||||
|
|
||||||
enabled(true);
|
enabled(true);
|
||||||
@ -461,7 +478,13 @@ template <class P, class B> class KnxFacade : private SaveRestore
|
|||||||
void progLedOn()
|
void progLedOn()
|
||||||
{
|
{
|
||||||
if (_ledPin >= 0)
|
if (_ledPin >= 0)
|
||||||
|
{
|
||||||
|
#if defined(ESP_PLATFORM)
|
||||||
|
gpio_set_level((gpio_num_t)ledPin(), _ledPinActiveOn);
|
||||||
|
#else
|
||||||
digitalWrite(_ledPin, _ledPinActiveOn);
|
digitalWrite(_ledPin, _ledPinActiveOn);
|
||||||
|
#endif // ESP_PLATFORM
|
||||||
|
}
|
||||||
|
|
||||||
if (_progLedOffCallback != 0)
|
if (_progLedOffCallback != 0)
|
||||||
_progLedOnCallback();
|
_progLedOnCallback();
|
||||||
@ -470,7 +493,13 @@ template <class P, class B> class KnxFacade : private SaveRestore
|
|||||||
void progLedOff()
|
void progLedOff()
|
||||||
{
|
{
|
||||||
if (_ledPin >= 0)
|
if (_ledPin >= 0)
|
||||||
|
{
|
||||||
|
#if defined(ESP_PLATFORM)
|
||||||
|
gpio_set_level((gpio_num_t)ledPin(), 1 - _ledPinActiveOn);
|
||||||
|
#else
|
||||||
digitalWrite(_ledPin, HIGH - _ledPinActiveOn);
|
digitalWrite(_ledPin, HIGH - _ledPinActiveOn);
|
||||||
|
#endif // ESP_PLATFORM
|
||||||
|
}
|
||||||
|
|
||||||
if (_progLedOffCallback != 0)
|
if (_progLedOffCallback != 0)
|
||||||
_progLedOffCallback();
|
_progLedOffCallback();
|
||||||
@ -536,6 +565,16 @@ template <class P, class B> class KnxFacade : private SaveRestore
|
|||||||
extern KnxFacade<LibretinyPlatform, Bau091A> knx;
|
extern KnxFacade<LibretinyPlatform, Bau091A> knx;
|
||||||
#else
|
#else
|
||||||
#error "Mask version not supported on LIBRETINY"
|
#error "Mask version not supported on LIBRETINY"
|
||||||
|
#elif defined(ESP_PLATFORM)
|
||||||
|
// predefined global instance for TP or IP or TP/IP coupler
|
||||||
|
#if MASK_VERSION == 0x07B0
|
||||||
|
extern KnxFacade<Esp32IdfPlatform, Bau07B0> knx;
|
||||||
|
#elif MASK_VERSION == 0x57B0
|
||||||
|
extern KnxFacade<Esp32IdfPlatform, Bau57B0> knx;
|
||||||
|
#elif MASK_VERSION == 0x091A
|
||||||
|
extern KnxFacade<Esp32IdfPlatform, Bau091A> knx;
|
||||||
|
#else
|
||||||
|
#error "Mask version not supported on ESP_PLATFORM"
|
||||||
#endif
|
#endif
|
||||||
#elif defined(ARDUINO_ARCH_STM32)
|
#elif defined(ARDUINO_ARCH_STM32)
|
||||||
// predefined global instance for TP only
|
// predefined global instance for TP only
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#ifdef ARDUINO
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "arduino_platform.h"
|
#include "arduino_platform.h"
|
||||||
@ -153,3 +154,4 @@ class RP2040ArduinoPlatform : public ArduinoPlatform
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif // ARDUINO
|
@ -1,3 +1,4 @@
|
|||||||
|
#ifdef ARDUINO
|
||||||
#include "arduino_platform.h"
|
#include "arduino_platform.h"
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
@ -53,3 +54,4 @@ class SamdPlatform : public ArduinoPlatform
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif // ARDUINO
|
Loading…
Reference in New Issue
Block a user