2018-03-16 00:48:39 +01:00
|
|
|
#include "esp_platform.h"
|
2018-11-07 00:32:36 +01:00
|
|
|
|
|
|
|
#ifdef ARDUINO_ARCH_ESP8266
|
2018-03-16 00:48:39 +01:00
|
|
|
#include <user_interface.h>
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include <EEPROM.h>
|
|
|
|
|
2018-08-16 23:58:57 +02:00
|
|
|
#include "knx/bits.h"
|
|
|
|
|
2019-09-09 18:19:09 +02:00
|
|
|
EspPlatform::EspPlatform() : ArduinoPlatform(&Serial)
|
2018-03-16 00:48:39 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-09-09 18:19:09 +02:00
|
|
|
EspPlatform::EspPlatform( HardwareSerial* s) : ArduinoPlatform(s)
|
2019-09-01 20:49:28 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-03-16 00:48:39 +01:00
|
|
|
uint32_t EspPlatform::currentIpAddress()
|
|
|
|
{
|
|
|
|
return WiFi.localIP();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t EspPlatform::currentSubnetMask()
|
|
|
|
{
|
|
|
|
return WiFi.subnetMask();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t EspPlatform::currentDefaultGateway()
|
|
|
|
{
|
|
|
|
return WiFi.gatewayIP();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EspPlatform::macAddress(uint8_t * addr)
|
|
|
|
{
|
|
|
|
wifi_get_macaddr(STATION_IF, addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EspPlatform::restart()
|
|
|
|
{
|
2019-09-09 20:10:56 +02:00
|
|
|
println("restart");
|
2018-03-20 23:56:42 +01:00
|
|
|
ESP.reset();
|
2018-03-16 00:48:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EspPlatform::setupMultiCast(uint32_t addr, uint16_t port)
|
|
|
|
{
|
2018-03-20 22:04:11 +01:00
|
|
|
_mulitcastAddr = htonl(addr);
|
2018-03-16 00:48:39 +01:00
|
|
|
_mulitcastPort = port;
|
2018-03-20 22:04:11 +01:00
|
|
|
IPAddress mcastaddr(_mulitcastAddr);
|
2018-03-17 00:08:14 +01:00
|
|
|
|
|
|
|
Serial.printf("setup multicast addr: %s port: %d ip: %s\n", mcastaddr.toString().c_str(), port,
|
|
|
|
WiFi.localIP().toString().c_str());
|
|
|
|
uint8 result = _udp.beginMulticast(WiFi.localIP(), mcastaddr, port);
|
|
|
|
Serial.printf("result %d\n", result);
|
2018-03-16 00:48:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EspPlatform::closeMultiCast()
|
|
|
|
{
|
|
|
|
_udp.stop();
|
|
|
|
}
|
|
|
|
|
2019-12-10 22:29:14 +01:00
|
|
|
bool EspPlatform::sendBytesMultiCast(uint8_t * buffer, uint16_t len)
|
2018-03-16 00:48:39 +01:00
|
|
|
{
|
2018-09-15 00:22:30 +02:00
|
|
|
//printHex("<- ",buffer, len);
|
2018-03-17 00:08:14 +01:00
|
|
|
int result = 0;
|
|
|
|
result = _udp.beginPacketMulticast(_mulitcastAddr, _mulitcastPort, WiFi.localIP());
|
|
|
|
result = _udp.write(buffer, len);
|
|
|
|
result = _udp.endPacket();
|
2018-03-16 00:48:39 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-12-10 22:29:14 +01:00
|
|
|
int EspPlatform::readBytesMultiCast(uint8_t * buffer, uint16_t maxLen)
|
2018-03-16 00:48:39 +01:00
|
|
|
{
|
|
|
|
int len = _udp.parsePacket();
|
|
|
|
if (len == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (len > maxLen)
|
|
|
|
{
|
2018-03-17 00:08:14 +01:00
|
|
|
Serial.printf("udp buffer to small. was %d, needed %d\n", maxLen, len);
|
2018-03-16 00:48:39 +01:00
|
|
|
fatalError();
|
|
|
|
}
|
|
|
|
|
|
|
|
_udp.read(buffer, len);
|
2018-09-15 00:22:30 +02:00
|
|
|
//printHex("-> ", buffer, len);
|
2018-03-16 00:48:39 +01:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t * EspPlatform::getEepromBuffer(uint16_t size)
|
|
|
|
{
|
|
|
|
EEPROM.begin(size);
|
|
|
|
return EEPROM.getDataPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EspPlatform::commitToEeprom()
|
|
|
|
{
|
|
|
|
EEPROM.commit();
|
|
|
|
}
|
2018-12-12 23:17:42 +01:00
|
|
|
#endif
|