knx/examples/knx-linux/main.cpp

170 lines
3.9 KiB
C++
Raw Normal View History

2019-05-18 21:04:49 +02:00
#include "knx_facade.h"
2019-10-28 18:26:24 +01:00
#include "knx/bau57B0.h"
2019-10-27 14:10:05 +01:00
#include "knx/bau27B0.h"
#include "knx/bau07B0.h"
2019-05-15 21:25:04 +02:00
#include "knx/group_object_table_object.h"
#include "knx/bits.h"
2019-05-15 21:25:04 +02:00
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
2019-10-28 20:42:51 +01:00
#include <string.h>
#include <signal.h>
2019-10-28 20:42:51 +01:00
#include <sched.h>
#include <sys/mman.h>
Add support for KNX data secure (#66) * initial comic * save work * Handle SystemBroadcast and Broadcast for TP and IP * Rework * Fix comment * save work * save work * save work * save work * save work * Restore old broadcast structure * Readd systembroadcast methods * Make sure that services from SystemBroadcast are also available from Broadcast on closed media * save work * Save work * save work * Save work * save work * save work * save work * save work * save work * Change maximum number of elements for the key tables, etc. * save work * First working seqno sync with ETS * save work * save work * save work * save work * save work * save work * Remove magic value and add comment * save work * Extend restart and masterreset for factory reset * save work * First working secure broadcast mode with IA programming * Add FunctionPropertyExt* AL services * Fix FunctionPropertyExt*. Working T_DATA_CONNECTED with FunctionPropertyExt*. * Add PropertyValueExt* AL services. Handle master reset in AL service RESTART. * Fix FunctionPropertyExtStateRead, fix restart. MILESTONE: Working physical programming of IA and toolkey with confirmed restart. Reading deviceinfos working. * Handle PDT_CONTROL in FunctionPropertyExt* * Fix FunctionPropertyExt* and FunctionProperty for PDT_CONTROL * Change comment. * save work * save work * Add group object security handling * Move map to own file * use simple_map * Include simple_map.h in CmakeFile * Move code from header to source file * Remove obsolete code * MILESTONE: working programming of secure device with IA and tables * cleanup * bugfix * flashSize must be big enough. Security IF object contains a lot more data. * Merge master into feat_datasecure * Revert "Merge master into feat_datasecure" This reverts commit 0c8358692aab13456196dc3a9ce5383bc1a2dec9. * Revert "Revert "Merge master into feat_datasecure"" This reverts commit aa5925378591eb32ea6d89dcb778ab02388a710f. * Bugfixes * cleanup * cleanup * Add printing of uint64_t * Don't compile secapplayer if data secure not enabled * pin platform for ESP8266 to specific version * SecIfObject: save/restore required for persisting STATE. Bugfix: use correct PID for group key table * Cleanup comment and debug output * Further cleanup. * Refactor master reset * Remove unused IP data link layer test code * Only reset TOOL kkey to FDSK on factory reset * Modify .gitignore and remove vscode config file * Correct comment * Handle SBC flag (systembroadcast) in SCF field. Couplers between open and closed media need this. * Remove code that slipped in.
2020-07-06 19:16:54 +02:00
#include "fdsk.h"
volatile sig_atomic_t loopActive = 1;
void signalHandler(int sig)
{
(void)sig;
// can be called asynchronously
loopActive = 0;
}
2019-05-15 21:25:04 +02:00
bool sendHidReport(uint8_t* data, uint16_t length)
{
return false;
}
bool isSendHidReportPossible()
{
return false;
}
Add coupler support (#79) * save work. * save work * save work * save work * save work * Remember which interface received the cemi frame * save work * save work * save work * Use default value from PID_ROUTING_COUNT * Add simple alternative to std::function without smart pointers or move semantics * Remove include * Add more comments about cleanup * save work * Remove forgotten code. * Move crc16Ccitt to bits.c as it also used for PID_MCB * save work * move comment * save work * save work * save work * save work * save work * save work * save work * derive from TableObject instead of InterfaceObject * save work * save work * Fix wrong pointer arithmetic in TableObject * Filter table setting/clearing * move comment * save work * save work * save work * handle SBC on closed media * save work * move coupler example to different dir * Restore device example for linux * save work * Remove MEDIUM_TYPE and use MASK_VERSION * save work * save work * save work * save work * save work * save work * save work * save work * save work * save work * save work * save work * save work * save work * Replace MEDIUM_TYPE by MASK_VERSION * Remove adafruit/travis-ci tests * Disable travis ci cache for platformio * Fix missing changes * Fix cemi server and add missing MASK_VERSION definitions * Enable platformio caching on travis ci again * Handle device address update for routing decision * source address is set in network layer and not in data link layer * Add remaining APCI types that are used with system broadcast * Add debug print for routing * Remove simple_functional * Fix CMakLists.txt * Use MASK_VERSION to conditionally compile code. * Remove fixed version reuqirement from platform esp8266 * Add demo-coupler for MCUs * Remove simple_functional.h from demo knx-linux * Enable CI for coupler demos * Correct path for knx-linux-coupler * Fix knx_facade.h * Refactor NetworkLayer to use getInterface() for devices and getPrimaryInterface(), getSecondaryInterface() for couplers * Add platformio configs for other currently possible mask/platform combinations * Add class diagrams and remove obsolete includes * Add some minimal docs
2020-09-06 21:41:34 +02:00
#if MASK_VERSION == 0x57B0
2019-10-28 18:26:24 +01:00
KnxFacade<LinuxPlatform, Bau57B0> knx;
Add coupler support (#79) * save work. * save work * save work * save work * save work * Remember which interface received the cemi frame * save work * save work * save work * Use default value from PID_ROUTING_COUNT * Add simple alternative to std::function without smart pointers or move semantics * Remove include * Add more comments about cleanup * save work * Remove forgotten code. * Move crc16Ccitt to bits.c as it also used for PID_MCB * save work * move comment * save work * save work * save work * save work * save work * save work * save work * derive from TableObject instead of InterfaceObject * save work * save work * Fix wrong pointer arithmetic in TableObject * Filter table setting/clearing * move comment * save work * save work * save work * handle SBC on closed media * save work * move coupler example to different dir * Restore device example for linux * save work * Remove MEDIUM_TYPE and use MASK_VERSION * save work * save work * save work * save work * save work * save work * save work * save work * save work * save work * save work * save work * save work * save work * Replace MEDIUM_TYPE by MASK_VERSION * Remove adafruit/travis-ci tests * Disable travis ci cache for platformio * Fix missing changes * Fix cemi server and add missing MASK_VERSION definitions * Enable platformio caching on travis ci again * Handle device address update for routing decision * source address is set in network layer and not in data link layer * Add remaining APCI types that are used with system broadcast * Add debug print for routing * Remove simple_functional * Fix CMakLists.txt * Use MASK_VERSION to conditionally compile code. * Remove fixed version reuqirement from platform esp8266 * Add demo-coupler for MCUs * Remove simple_functional.h from demo knx-linux * Enable CI for coupler demos * Correct path for knx-linux-coupler * Fix knx_facade.h * Refactor NetworkLayer to use getInterface() for devices and getPrimaryInterface(), getSecondaryInterface() for couplers * Add platformio configs for other currently possible mask/platform combinations * Add class diagrams and remove obsolete includes * Add some minimal docs
2020-09-06 21:41:34 +02:00
#elif MASK_VERSION == 0x27B0
2019-10-27 14:10:05 +01:00
KnxFacade<LinuxPlatform, Bau27B0> knx;
#elif MASK_VERSION == 0x07B0
KnxFacade<LinuxPlatform, Bau07B0> knx;
2019-10-28 18:26:24 +01:00
#else
Add coupler support (#79) * save work. * save work * save work * save work * save work * Remember which interface received the cemi frame * save work * save work * save work * Use default value from PID_ROUTING_COUNT * Add simple alternative to std::function without smart pointers or move semantics * Remove include * Add more comments about cleanup * save work * Remove forgotten code. * Move crc16Ccitt to bits.c as it also used for PID_MCB * save work * move comment * save work * save work * save work * save work * save work * save work * save work * derive from TableObject instead of InterfaceObject * save work * save work * Fix wrong pointer arithmetic in TableObject * Filter table setting/clearing * move comment * save work * save work * save work * handle SBC on closed media * save work * move coupler example to different dir * Restore device example for linux * save work * Remove MEDIUM_TYPE and use MASK_VERSION * save work * save work * save work * save work * save work * save work * save work * save work * save work * save work * save work * save work * save work * save work * Replace MEDIUM_TYPE by MASK_VERSION * Remove adafruit/travis-ci tests * Disable travis ci cache for platformio * Fix missing changes * Fix cemi server and add missing MASK_VERSION definitions * Enable platformio caching on travis ci again * Handle device address update for routing decision * source address is set in network layer and not in data link layer * Add remaining APCI types that are used with system broadcast * Add debug print for routing * Remove simple_functional * Fix CMakLists.txt * Use MASK_VERSION to conditionally compile code. * Remove fixed version reuqirement from platform esp8266 * Add demo-coupler for MCUs * Remove simple_functional.h from demo knx-linux * Enable CI for coupler demos * Correct path for knx-linux-coupler * Fix knx_facade.h * Refactor NetworkLayer to use getInterface() for devices and getPrimaryInterface(), getSecondaryInterface() for couplers * Add platformio configs for other currently possible mask/platform combinations * Add class diagrams and remove obsolete includes * Add some minimal docs
2020-09-06 21:41:34 +02:00
#error Mask version not supported yet!
2019-10-28 18:26:24 +01:00
#endif
2019-05-15 21:25:04 +02:00
long lastsend = 0;
2019-08-22 22:57:35 +02:00
#define CURR knx.getGroupObject(1)
#define MAX knx.getGroupObject(2)
#define MIN knx.getGroupObject(3)
#define RESET knx.getGroupObject(4)
2019-05-15 21:25:04 +02:00
void measureTemp()
{
2019-08-22 21:31:02 +02:00
long now = millis();
if ((now - lastsend) < 10000)
2019-05-15 21:25:04 +02:00
return;
lastsend = now;
int r = rand();
double currentValue = (r * 1.0) / (RAND_MAX * 1.0);
2019-07-15 21:32:00 +02:00
currentValue *= 100;
currentValue -= 50;
// currentValue *= (670433.28 + 273);
// currentValue -= 273;
println(currentValue);
CURR.value(currentValue);
2019-05-15 21:25:04 +02:00
double max = MAX.value();
if (currentValue > max)
MAX.value(currentValue);
2019-05-15 21:25:04 +02:00
if (currentValue < (double)MIN.value())
MIN.value(currentValue);
2019-05-15 21:25:04 +02:00
}
void resetCallback(GroupObject& go)
{
if (go.value())
2019-05-15 21:25:04 +02:00
{
MAX.valueNoSend(-273.0);
MIN.valueNoSend(670433.28);
2019-05-15 21:25:04 +02:00
}
}
void appLoop()
{
2019-08-22 22:57:35 +02:00
if (!knx.configured())
2019-05-15 21:25:04 +02:00
return;
measureTemp();
}
void setup()
{
srand((unsigned int)time(NULL));
2019-08-22 22:57:35 +02:00
knx.readMemory();
2019-05-15 21:25:04 +02:00
if (knx.individualAddress() == 0)
2019-08-22 22:57:35 +02:00
knx.progMode(true);
2019-05-15 21:25:04 +02:00
2019-08-22 22:57:35 +02:00
if (knx.configured())
2019-05-15 21:25:04 +02:00
{
CURR.dataPointType(Dpt(9, 1));
MIN.dataPointType(Dpt(9, 1));
MIN.value(670433.28);
MAX.dataPointType(Dpt(9, 1));
MAX.valueNoSend(-273.0);
RESET.dataPointType(Dpt(1, 15));
2019-05-18 21:04:49 +02:00
RESET.callback(resetCallback);
2019-08-22 22:57:35 +02:00
printf("Timeout: %d\n", knx.paramWord(0));
printf("Zykl. senden: %d\n", knx.paramByte(2));
printf("Min/Max senden: %d\n", knx.paramByte(3));
printf("Aenderung senden: %d\n", knx.paramByte(4));
printf("Abgleich %d\n", knx.paramByte(5));
2019-05-15 21:25:04 +02:00
}
2019-12-09 23:19:13 +01:00
else
println("not configured");
2019-08-22 22:57:35 +02:00
knx.start();
2019-05-15 21:25:04 +02:00
}
int main(int argc, char **argv)
{
printf("main() start.\n");
Add support for KNX data secure (#66) * initial comic * save work * Handle SystemBroadcast and Broadcast for TP and IP * Rework * Fix comment * save work * save work * save work * save work * save work * Restore old broadcast structure * Readd systembroadcast methods * Make sure that services from SystemBroadcast are also available from Broadcast on closed media * save work * Save work * save work * Save work * save work * save work * save work * save work * save work * Change maximum number of elements for the key tables, etc. * save work * First working seqno sync with ETS * save work * save work * save work * save work * save work * save work * Remove magic value and add comment * save work * Extend restart and masterreset for factory reset * save work * First working secure broadcast mode with IA programming * Add FunctionPropertyExt* AL services * Fix FunctionPropertyExt*. Working T_DATA_CONNECTED with FunctionPropertyExt*. * Add PropertyValueExt* AL services. Handle master reset in AL service RESTART. * Fix FunctionPropertyExtStateRead, fix restart. MILESTONE: Working physical programming of IA and toolkey with confirmed restart. Reading deviceinfos working. * Handle PDT_CONTROL in FunctionPropertyExt* * Fix FunctionPropertyExt* and FunctionProperty for PDT_CONTROL * Change comment. * save work * save work * Add group object security handling * Move map to own file * use simple_map * Include simple_map.h in CmakeFile * Move code from header to source file * Remove obsolete code * MILESTONE: working programming of secure device with IA and tables * cleanup * bugfix * flashSize must be big enough. Security IF object contains a lot more data. * Merge master into feat_datasecure * Revert "Merge master into feat_datasecure" This reverts commit 0c8358692aab13456196dc3a9ce5383bc1a2dec9. * Revert "Revert "Merge master into feat_datasecure"" This reverts commit aa5925378591eb32ea6d89dcb778ab02388a710f. * Bugfixes * cleanup * cleanup * Add printing of uint64_t * Don't compile secapplayer if data secure not enabled * pin platform for ESP8266 to specific version * SecIfObject: save/restore required for persisting STATE. Bugfix: use correct PID for group key table * Cleanup comment and debug output * Further cleanup. * Refactor master reset * Remove unused IP data link layer test code * Only reset TOOL kkey to FDSK on factory reset * Modify .gitignore and remove vscode config file * Correct comment * Handle SBC flag (systembroadcast) in SCF field. Couplers between open and closed media need this. * Remove code that slipped in.
2020-07-06 19:16:54 +02:00
uint8_t serialNumber[] = { 0x00, 0xFA, 0x01, 0x02, 0x03, 0x04};
uint8_t key[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
FdskCalculator calc;
char fdskString[42]; // 6 * 6 chars + 5 dashes + nullbyte = 42
calc.snprintFdsk(fdskString, sizeof(fdskString), serialNumber, key);
printf("FDSK: %s\n", fdskString);
2019-10-28 20:42:51 +01:00
// Prevent swapping of this process
struct sched_param sp;
memset(&sp, 0, sizeof(sp));
sp.sched_priority = sched_get_priority_max(SCHED_FIFO);
sched_setscheduler(0, SCHED_FIFO, &sp);
mlockall(MCL_CURRENT | MCL_FUTURE);
// Register signals
signal(SIGINT, signalHandler);
signal(SIGTERM, signalHandler);
2019-08-22 22:57:35 +02:00
knx.platform().cmdLineArgs(argc, argv);
2019-05-15 21:25:04 +02:00
setup();
while (loopActive)
2019-05-15 21:25:04 +02:00
{
2019-08-22 22:57:35 +02:00
knx.loop();
if(knx.configured())
2019-05-18 21:04:49 +02:00
appLoop();
2019-10-28 18:26:24 +01:00
delayMicroseconds(100);
2019-05-15 21:25:04 +02:00
}
// pinMode() will automatically export GPIO pin in sysfs
// Read or writing the GPIO pin for the first time automatically
// opens the "value" sysfs file to read or write the GPIO pin value.
// The following calls will close the "value" sysfs fiel for the pin
// and unexport the GPIO pin.
#ifdef USE_RF
gpio_unexport(SPI_SS_PIN);
gpio_unexport(GPIO_GDO2_PIN);
gpio_unexport(GPIO_GDO0_PIN);
#endif
printf("main() exit.\n");
2019-10-28 18:26:24 +01:00
}