2024-08-16 22:19:48 +02:00
|
|
|
#include <knx.h>
|
2019-12-12 21:23:37 +01:00
|
|
|
|
2024-08-20 01:37:35 +02:00
|
|
|
#include "knx/ip/bau57B0.h"
|
|
|
|
#include "knx/rf/bau27B0.h"
|
|
|
|
#include "knx/tp/bau07B0.h"
|
2019-12-12 21:23:37 +01:00
|
|
|
|
2024-08-20 01:37:35 +02:00
|
|
|
#include "knx/interface_object/group_object_table_object.h"
|
2019-05-29 22:43:21 +02:00
|
|
|
#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>
|
2019-10-28 20:37:40 +01:00
|
|
|
#include <signal.h>
|
2019-10-28 20:42:51 +01:00
|
|
|
#include <sched.h>
|
|
|
|
#include <sys/mman.h>
|
2019-10-28 20:37:40 +01:00
|
|
|
|
2020-07-06 19:16:54 +02:00
|
|
|
#include "fdsk.h"
|
|
|
|
|
2024-08-17 17:27:27 +02:00
|
|
|
#define LOGGER Logger::logger("App")
|
|
|
|
|
2019-10-28 20:37:40 +01:00
|
|
|
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
|
|
|
|
2019-12-12 21:23:37 +01:00
|
|
|
bool sendHidReport(uint8_t* data, uint16_t length)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool isSendHidReportPossible()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2020-09-06 21:41:34 +02:00
|
|
|
|
|
|
|
#if MASK_VERSION == 0x57B0
|
2019-10-28 18:26:24 +01:00
|
|
|
KnxFacade<LinuxPlatform, Bau57B0> knx;
|
2020-09-06 21:41:34 +02:00
|
|
|
#elif MASK_VERSION == 0x27B0
|
2019-10-27 14:10:05 +01:00
|
|
|
KnxFacade<LinuxPlatform, Bau27B0> knx;
|
2020-09-11 13:32:29 +02:00
|
|
|
#elif MASK_VERSION == 0x07B0
|
|
|
|
KnxFacade<LinuxPlatform, Bau07B0> knx;
|
2019-10-28 18:26:24 +01:00
|
|
|
#else
|
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;
|
|
|
|
|
2021-02-08 20:54:49 +01:00
|
|
|
#define GO_CURR knx.getGroupObject(1)
|
|
|
|
#define GO_MAX knx.getGroupObject(2)
|
|
|
|
#define GO_MIN knx.getGroupObject(3)
|
|
|
|
#define GO_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();
|
2019-05-29 22:43:21 +02:00
|
|
|
if ((now - lastsend) < 10000)
|
2019-05-15 21:25:04 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
lastsend = now;
|
|
|
|
int r = rand();
|
2019-06-12 00:01:21 +02:00
|
|
|
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;
|
2024-08-19 16:25:30 +02:00
|
|
|
LOGGER.info("current value: %f",currentValue);
|
2021-02-08 20:54:49 +01:00
|
|
|
GO_CURR.value(currentValue);
|
2019-05-15 21:25:04 +02:00
|
|
|
|
2021-02-08 20:54:49 +01:00
|
|
|
double max = GO_MAX.value();
|
2019-05-29 22:43:21 +02:00
|
|
|
if (currentValue > max)
|
2021-02-08 20:54:49 +01:00
|
|
|
GO_MAX.value(currentValue);
|
2019-05-15 21:25:04 +02:00
|
|
|
|
2021-02-08 20:54:49 +01:00
|
|
|
if (currentValue < (double)GO_MIN.value())
|
|
|
|
GO_MIN.value(currentValue);
|
2019-05-15 21:25:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void resetCallback(GroupObject& go)
|
|
|
|
{
|
2019-06-12 00:01:21 +02:00
|
|
|
if (go.value())
|
2019-05-15 21:25:04 +02:00
|
|
|
{
|
2021-02-08 20:54:49 +01:00
|
|
|
GO_MAX.valueNoSend(-273.0);
|
|
|
|
GO_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));
|
2024-08-19 16:25:30 +02:00
|
|
|
|
|
|
|
Logger::logLevel("App", Logger::Info);
|
|
|
|
Logger::logLevel("ApplicationLayer", Logger::Info);
|
2019-08-22 22:57:35 +02:00
|
|
|
knx.readMemory();
|
2019-05-15 21:25:04 +02:00
|
|
|
|
2024-08-18 00:05:30 +02:00
|
|
|
if (knx.individualAddress() == 0xFFFF)
|
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
|
|
|
{
|
2021-02-08 20:54:49 +01:00
|
|
|
GO_CURR.dataPointType(Dpt(9, 1));
|
|
|
|
GO_MIN.dataPointType(Dpt(9, 1));
|
|
|
|
GO_MIN.value(670433.28);
|
|
|
|
GO_MAX.dataPointType(Dpt(9, 1));
|
|
|
|
GO_MAX.valueNoSend(-273.0);
|
|
|
|
GO_RESET.dataPointType(Dpt(1, 15));
|
2024-08-30 20:47:43 +02:00
|
|
|
//GO_RESET.callback(resetCallback);
|
2024-08-17 17:27:27 +02:00
|
|
|
LOGGER.info("Timeout: %d", knx.paramWord(0));
|
|
|
|
LOGGER.info("Zykl. senden: %d", knx.paramByte(2));
|
|
|
|
LOGGER.info("Min/Max senden: %d", knx.paramByte(3));
|
|
|
|
LOGGER.info("Aenderung senden: %d", knx.paramByte(4));
|
|
|
|
LOGGER.info("Abgleich %d", knx.paramByte(5));
|
2019-05-15 21:25:04 +02:00
|
|
|
}
|
2019-12-09 23:19:13 +01:00
|
|
|
else
|
2024-08-17 17:27:27 +02:00
|
|
|
LOGGER.info("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)
|
|
|
|
{
|
2024-08-17 17:27:27 +02:00
|
|
|
LOGGER.info("main() start.");
|
2019-10-28 20:37:40 +01:00
|
|
|
|
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);
|
2024-08-17 17:27:27 +02:00
|
|
|
LOGGER.info("FDSK: %s", fdskString);
|
2020-07-06 19:16:54 +02:00
|
|
|
|
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);
|
|
|
|
|
2019-10-28 20:37:40 +01:00
|
|
|
// 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();
|
|
|
|
|
2019-10-28 20:37:40 +01:00
|
|
|
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
|
|
|
}
|
2019-10-28 20:37:40 +01: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.
|
2024-08-17 17:27:27 +02:00
|
|
|
LOGGER.info("main() exit.");
|
2019-10-28 18:26:24 +01:00
|
|
|
}
|