mirror of
https://github.com/thelsing/knx.git
synced 2026-02-23 13:50:35 +01:00
first real working version of knxPython
This commit is contained in:
@@ -83,8 +83,9 @@ void BauSystemB::updateGroupObject(GroupObject & go, uint8_t * data, uint8_t len
|
||||
memcpy(goData, data, length);
|
||||
|
||||
go.commFlag(cfUpdate);
|
||||
if (go.updateHandler)
|
||||
go.updateHandler(go);
|
||||
GroupObjectUpdatedHandler handler = go.callback();
|
||||
if (handler)
|
||||
handler(go);
|
||||
}
|
||||
|
||||
void BauSystemB::readMemory()
|
||||
|
||||
@@ -43,7 +43,7 @@ private:
|
||||
uint8_t _routingCount;
|
||||
uint8_t _prgMode;
|
||||
uint16_t _ownAddress;
|
||||
uint16_t _manufacturerId;
|
||||
uint16_t _manufacturerId = 0xfa; //Default to KNXA
|
||||
uint32_t _bauNumber;
|
||||
char _orderNumber[10];
|
||||
uint8_t _hardwareType[6];
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
GroupObject::GroupObject(uint8_t size)
|
||||
{
|
||||
_data = new uint8_t[size];
|
||||
memset(_data, 0, size);
|
||||
_commFlag = Ok;
|
||||
_table = 0;
|
||||
_dataLength = size;
|
||||
updateHandler = 0;
|
||||
_updateHandler = 0;
|
||||
}
|
||||
|
||||
GroupObject::GroupObject(const GroupObject& other)
|
||||
@@ -20,7 +21,7 @@ GroupObject::GroupObject(const GroupObject& other)
|
||||
_table = other._table;
|
||||
_dataLength = other._dataLength;
|
||||
_asap = other._asap;
|
||||
updateHandler = other.updateHandler;
|
||||
_updateHandler = other._updateHandler;
|
||||
memcpy(_data, other._data, _dataLength);
|
||||
}
|
||||
|
||||
@@ -252,3 +253,15 @@ void GroupObject::objectWrite(float value)
|
||||
uint32_t tmp = value * 100;
|
||||
objectWriteFloatDpt9(tmp);
|
||||
}
|
||||
|
||||
|
||||
void GroupObject::callback(GroupObjectUpdatedHandler handler)
|
||||
{
|
||||
_updateHandler = handler;
|
||||
}
|
||||
|
||||
|
||||
GroupObjectUpdatedHandler GroupObject::callback()
|
||||
{
|
||||
return _updateHandler;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <stdint.h>
|
||||
#include "knx_types.h"
|
||||
|
||||
|
||||
class GroupObjectTableObject;
|
||||
|
||||
enum ComFlag
|
||||
@@ -17,7 +18,14 @@ enum ComFlag
|
||||
};
|
||||
|
||||
class GroupObject;
|
||||
typedef void (*GroupObjectUpdatedHandler)(GroupObject& go);
|
||||
|
||||
#ifdef __linux__
|
||||
#include <functional>
|
||||
typedef std::function<void(GroupObject&)> GroupObjectUpdatedHandler;
|
||||
#else
|
||||
typedef void(*GroupObjectUpdatedHandler)(GroupObject& go);
|
||||
#endif
|
||||
|
||||
|
||||
class GroupObject
|
||||
{
|
||||
@@ -109,8 +117,10 @@ public:
|
||||
size_t sizeInTelegram();
|
||||
uint8_t* valueRef();
|
||||
uint16_t asap();
|
||||
GroupObjectUpdatedHandler updateHandler;
|
||||
void callback(GroupObjectUpdatedHandler hanlder);
|
||||
GroupObjectUpdatedHandler callback();
|
||||
private:
|
||||
GroupObjectUpdatedHandler _updateHandler;
|
||||
size_t goSize();
|
||||
uint16_t _asap;
|
||||
ComFlag _commFlag;
|
||||
|
||||
@@ -218,7 +218,7 @@ void LinuxPlatform::doMemoryMapping()
|
||||
_fd = open("flash.bin", O_RDWR | O_CREAT, S_IRWXU | S_IRGRP | S_IROTH);
|
||||
if (_fd < 0)
|
||||
{
|
||||
perror("Error in file opening");
|
||||
puts("Error in file opening");
|
||||
//exit(-1);
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ void LinuxPlatform::doMemoryMapping()
|
||||
uint32_t ret = fstat(_fd, &st);
|
||||
if (ret < 0)
|
||||
{
|
||||
perror("Error in fstat");
|
||||
puts("Error in fstat");
|
||||
//exit(-1);
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ void LinuxPlatform::doMemoryMapping()
|
||||
{
|
||||
if (ftruncate(_fd, FLASHSIZE) != 0)
|
||||
{
|
||||
perror("Error extending file");
|
||||
puts("Error extending file");
|
||||
//exit(-1);
|
||||
}
|
||||
len_file = FLASHSIZE;
|
||||
@@ -250,7 +250,7 @@ void LinuxPlatform::doMemoryMapping()
|
||||
|
||||
if (addr == MAP_FAILED)
|
||||
{
|
||||
perror("Error in mmap");
|
||||
puts("Error in mmap");
|
||||
//exit(-1);
|
||||
}
|
||||
_mappedFile = addr;
|
||||
@@ -308,9 +308,10 @@ uint8_t* LinuxPlatform::allocMemory(size_t size)
|
||||
throw std::overflow_error("MAX_MEM was to small");
|
||||
return addr;
|
||||
}
|
||||
#endif
|
||||
|
||||
void LinuxPlatform::freeMemory(uint8_t* ptr)
|
||||
{
|
||||
/* do nothing. Memory is freed on restart()*/
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
10
src/main.cpp
10
src/main.cpp
@@ -75,18 +75,10 @@ void setup()
|
||||
srand((unsigned int)time(NULL));
|
||||
bau.readMemory();
|
||||
|
||||
uint8_t hwType[] = { 0x0, 0x0, 0x8, 0x0, 0x0, 0x2 };
|
||||
GroupObjectTableObject& got(bau.groupObjectTable());
|
||||
got.groupObjects(groupObjects, 4);
|
||||
|
||||
DeviceObject& devObj(bau.deviceObject());
|
||||
devObj.manufacturerId(0xfa);
|
||||
devObj.bauNumber(0xdeadbeef);
|
||||
devObj.orderNumber("Coolstuff");
|
||||
devObj.hardwareType(hwType);
|
||||
devObj.version(0x0020);
|
||||
|
||||
RESET.updateHandler = resetCallback;
|
||||
RESET.callback(resetCallback);
|
||||
|
||||
if (bau.deviceObject().induvidualAddress() == 0)
|
||||
bau.deviceObject().progMode(true);
|
||||
|
||||
Reference in New Issue
Block a user