diff --git a/knx-linux/CMakeLists.txt b/knx-linux/CMakeLists.txt
index 064e7a8..ee4e468 100644
--- a/knx-linux/CMakeLists.txt
+++ b/knx-linux/CMakeLists.txt
@@ -52,6 +52,7 @@ add_executable(knx-linux
../src/knx/network_layer.h
../src/knx/npdu.cpp
../src/knx/npdu.h
+ ../src/knx/platform.cpp
../src/knx/platform.h
../src/knx/rf_data_link_layer.cpp
../src/knx/rf_data_link_layer.h
diff --git a/knx-linux/knx-linux.vcxproj b/knx-linux/knx-linux.vcxproj
index c0b62f8..0d59f71 100644
--- a/knx-linux/knx-linux.vcxproj
+++ b/knx-linux/knx-linux.vcxproj
@@ -145,6 +145,7 @@
+
diff --git a/knx-linux/knx-linux.vcxproj.filters b/knx-linux/knx-linux.vcxproj.filters
index f26dfd5..52f7e53 100644
--- a/knx-linux/knx-linux.vcxproj.filters
+++ b/knx-linux/knx-linux.vcxproj.filters
@@ -262,5 +262,8 @@
Source files\knx
+
+ Source files\knx
+
\ No newline at end of file
diff --git a/src/arduino_platform.cpp b/src/arduino_platform.cpp
index 58d9986..5ae6db5 100644
--- a/src/arduino_platform.cpp
+++ b/src/arduino_platform.cpp
@@ -10,30 +10,6 @@ ArduinoPlatform::ArduinoPlatform(HardwareSerial* knxSerial) : _knxSerial(knxSeri
{
}
-uint32_t ArduinoPlatform::currentIpAddress()
-{
- // not needed
- return 0;
-}
-
-uint32_t ArduinoPlatform::currentSubnetMask()
-{
- // not needed
- return 0;
-}
-
-uint32_t ArduinoPlatform::currentDefaultGateway()
-{
- // not needed
- return 0;
-}
-
-void ArduinoPlatform::macAddress(uint8_t * addr)
-{
- // not needed
-}
-
-
void ArduinoPlatform::fatalError()
{
const int period = 200;
@@ -48,28 +24,6 @@ void ArduinoPlatform::fatalError()
}
}
-void ArduinoPlatform::setupMultiCast(uint32_t addr, uint16_t port)
-{
- //not needed
-}
-
-void ArduinoPlatform::closeMultiCast()
-{
- //not needed
-}
-
-bool ArduinoPlatform::sendBytes(uint8_t * buffer, uint16_t len)
-{
- //not needed
- return false;
-}
-
-int ArduinoPlatform::readBytes(uint8_t * buffer, uint16_t maxLen)
-{
- //not needed
- return 0;
-}
-
void ArduinoPlatform::knxUart( HardwareSerial* serial )
{
closeUart();
diff --git a/src/arduino_platform.h b/src/arduino_platform.h
index d7b6f69..10c10e6 100644
--- a/src/arduino_platform.h
+++ b/src/arduino_platform.h
@@ -9,21 +9,9 @@ class ArduinoPlatform : public Platform
public:
ArduinoPlatform(HardwareSerial* knxSerial);
- // ip stuff
- uint32_t currentIpAddress();
- uint32_t currentSubnetMask();
- uint32_t currentDefaultGateway();
- void macAddress(uint8_t* addr);
-
// basic stuff
void fatalError();
- //multicast
- void setupMultiCast(uint32_t addr, uint16_t port);
- void closeMultiCast();
- bool sendBytes(uint8_t* buffer, uint16_t len);
- int readBytes(uint8_t* buffer, uint16_t maxLen);
-
//uart
virtual void knxUart( HardwareSerial* serial);
virtual HardwareSerial* knxUart();
@@ -43,7 +31,5 @@ class ArduinoPlatform : public Platform
static Stream* SerialDebug;
protected:
- uint32_t _mulitcastAddr;
- uint16_t _mulitcastPort;
HardwareSerial* _knxSerial;
};
diff --git a/src/esp32_platform.cpp b/src/esp32_platform.cpp
index 4dd9a6b..f290cf7 100644
--- a/src/esp32_platform.cpp
+++ b/src/esp32_platform.cpp
@@ -42,9 +42,7 @@ void Esp32Platform::restart()
void Esp32Platform::setupMultiCast(uint32_t addr, uint16_t port)
{
- _mulitcastAddr = htonl(addr);
- _mulitcastPort = port;
- IPAddress mcastaddr(_mulitcastAddr);
+ IPAddress mcastaddr(htonl(addr));
Serial.printf("setup multicast addr: %s port: %d ip: %s\n", mcastaddr.toString().c_str(), port,
WiFi.localIP().toString().c_str());
diff --git a/src/esp_platform.h b/src/esp_platform.h
index 372ff32..e48084c 100644
--- a/src/esp_platform.h
+++ b/src/esp_platform.h
@@ -33,6 +33,8 @@ class EspPlatform : public ArduinoPlatform
void commitToEeprom();
private:
WiFiUDP _udp;
+ uint32_t _mulitcastAddr;
+ uint16_t _mulitcastPort;
};
#endif
diff --git a/src/knx/platform.cpp b/src/knx/platform.cpp
new file mode 100644
index 0000000..59e15df
--- /dev/null
+++ b/src/knx/platform.cpp
@@ -0,0 +1,89 @@
+#include "platform.h"
+
+
+NvMemoryType Platform::NonVolatileMemoryType()
+{
+ return _memoryType;
+}
+
+
+void Platform::NonVolatileMemoryType(NvMemoryType type)
+{
+ _memoryType = type;
+}
+
+void Platform::setupSpi()
+{}
+
+void Platform::closeSpi()
+{}
+
+int Platform::readWriteSpi(uint8_t *data, size_t len)
+{
+ return 0;
+}
+
+size_t Platform::readBytesUart(uint8_t *buffer, size_t length)
+{
+ return 0;
+}
+
+int Platform::readUart()
+{
+ return -1;
+}
+
+size_t Platform::writeUart(const uint8_t *buffer, size_t size)
+{
+ return 0;
+}
+
+size_t Platform::writeUart(const uint8_t data)
+{
+ return 0;
+}
+
+int Platform::uartAvailable()
+{
+ return 0;
+}
+
+void Platform::closeUart()
+{}
+
+void Platform::setupUart()
+{}
+
+uint32_t Platform::currentIpAddress()
+{
+ return 0;
+}
+
+uint32_t Platform::currentSubnetMask()
+{
+ return 0;
+}
+
+uint32_t Platform::currentDefaultGateway()
+{
+ return 0;
+}
+
+void Platform::macAddress(uint8_t *data)
+{}
+
+void Platform::setupMultiCast(uint32_t addr, uint16_t port)
+{}
+
+void Platform::closeMultiCast()
+{}
+
+bool Platform::sendBytes(uint8_t *buffer, uint16_t len)
+{
+ return false;
+}
+
+int Platform::readBytes(uint8_t *buffer, uint16_t maxLen)
+{
+ return 0;
+}
\ No newline at end of file
diff --git a/src/knx/platform.h b/src/knx/platform.h
index dbf5790..b6d682b 100644
--- a/src/knx/platform.h
+++ b/src/knx/platform.h
@@ -4,38 +4,45 @@
#include
#include "save_restore.h"
+enum NvMemoryType
+{
+ Eeprom,
+ Flash
+};
+
class Platform
{
public:
+ virtual ~Platform() {}
// ip config
- virtual uint32_t currentIpAddress() = 0;
- virtual uint32_t currentSubnetMask() = 0;
- virtual uint32_t currentDefaultGateway() = 0;
- virtual void macAddress(uint8_t* data) = 0;
+ virtual uint32_t currentIpAddress();
+ virtual uint32_t currentSubnetMask();
+ virtual uint32_t currentDefaultGateway();
+ virtual void macAddress(uint8_t* data);
// basic stuff
virtual void restart() = 0;
virtual void fatalError() = 0;
//multicast socket
- virtual void setupMultiCast(uint32_t addr, uint16_t port) = 0;
- virtual void closeMultiCast() = 0;
- virtual bool sendBytes(uint8_t* buffer, uint16_t len) = 0;
- virtual int readBytes(uint8_t* buffer, uint16_t maxLen) = 0;
+ virtual void setupMultiCast(uint32_t addr, uint16_t port);
+ virtual void closeMultiCast();
+ virtual bool sendBytes(uint8_t* buffer, uint16_t len);
+ virtual int readBytes(uint8_t* buffer, uint16_t maxLen);
//UART
- virtual void setupUart() = 0;
- virtual void closeUart() = 0;
- virtual int uartAvailable() = 0;
- virtual size_t writeUart(const uint8_t data) = 0;
- virtual size_t writeUart(const uint8_t* buffer, size_t size) = 0;
- virtual int readUart() = 0;
- virtual size_t readBytesUart(uint8_t* buffer, size_t length) = 0;
+ virtual void setupUart();
+ virtual void closeUart();
+ virtual int uartAvailable();
+ virtual size_t writeUart(const uint8_t data);
+ virtual size_t writeUart(const uint8_t* buffer, size_t size);
+ virtual int readUart();
+ virtual size_t readBytesUart(uint8_t* buffer, size_t length);
// SPI
- virtual void setupSpi() = 0;
- virtual void closeSpi() = 0;
- virtual int readWriteSpi (uint8_t *data, size_t len) = 0;
+ virtual void setupSpi();
+ virtual void closeSpi();
+ virtual int readWriteSpi(uint8_t *data, size_t len);
#if 0
// Flash memory
virtual size_t flashEraseBlockSize(); // in pages
@@ -47,4 +54,10 @@ class Platform
#endif
virtual uint8_t* getEepromBuffer(uint16_t size) = 0;
virtual void commitToEeprom() = 0;
+
+ NvMemoryType NonVolatileMemoryType();
+ void NonVolatileMemoryType(NvMemoryType type);
+
+ protected:
+ NvMemoryType _memoryType = Eeprom;
};
\ No newline at end of file
diff --git a/src/linux_platform.cpp b/src/linux_platform.cpp
index 4f86ba8..64510cf 100644
--- a/src/linux_platform.cpp
+++ b/src/linux_platform.cpp
@@ -42,20 +42,6 @@ LinuxPlatform::~LinuxPlatform()
delete[] _args;
}
-uint32_t LinuxPlatform::currentIpAddress()
-{
- return 0;
-}
-
-uint32_t LinuxPlatform::currentSubnetMask()
-{
- return 0;
-}
-
-uint32_t LinuxPlatform::currentDefaultGateway()
-{
- return 0;
-}
uint32_t millis()
{
@@ -73,16 +59,7 @@ void delay(uint32_t millis)
nanosleep(&ts, NULL);
}
-void LinuxPlatform::macAddress(uint8_t* data)
-{
- // hardcode some address
- data[0] = 0x08;
- data[1] = 0x00;
- data[2] = 0x27;
- data[3] = 0x6c;
- data[4] = 0xa8;
- data[5] = 0x2a;
-}
+
void LinuxPlatform::restart()
{
@@ -262,45 +239,6 @@ void LinuxPlatform::doMemoryMapping()
_mappedFile = addr;
}
-size_t LinuxPlatform::readBytesUart(uint8_t *buffer, size_t length)
-{
- return 0;
-}
-
-
-int LinuxPlatform::readUart()
-{
- return -1;
-}
-
-
-size_t LinuxPlatform::writeUart(const uint8_t *buffer, size_t size)
-{
- return 0;
-}
-
-
-size_t LinuxPlatform::writeUart(const uint8_t data)
-{
- return 0;
-}
-
-
-int LinuxPlatform::uartAvailable()
-{
- return 0;
-}
-
-
-void LinuxPlatform::closeUart()
-{
-}
-
-
-void LinuxPlatform::setupUart()
-{
-}
-
void LinuxPlatform::closeSpi()
{
close(_spiFd);
diff --git a/src/linux_platform.h b/src/linux_platform.h
index 46380ba..1121e66 100644
--- a/src/linux_platform.h
+++ b/src/linux_platform.h
@@ -22,12 +22,6 @@ public:
std::string flashFilePath();
void flashFilePath(const std::string path);
- // ip stuff
- uint32_t currentIpAddress() override;
- uint32_t currentSubnetMask() override;
- uint32_t currentDefaultGateway() override;
- void macAddress(uint8_t* addr) override;
-
// basic stuff
void restart() override;
void fatalError() override;
@@ -38,15 +32,6 @@ public:
bool sendBytes(uint8_t* buffer, uint16_t len) override;
int readBytes(uint8_t* buffer, uint16_t maxLen) 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;
-
//spi
void setupSpi() override;
void closeSpi() override;