knx/src/esp_platform.cpp

99 lines
2.1 KiB
C++
Raw Normal View History

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"
EspPlatform::EspPlatform() : ArduinoPlatform(&Serial)
2018-03-16 00:48:39 +01:00
{
}
EspPlatform::EspPlatform( HardwareSerial* s) : ArduinoPlatform(s)
{
}
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()
{
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);
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();
}
bool EspPlatform::sendBytesMultiCast(uint8_t * buffer, uint16_t len)
2018-03-16 00:48:39 +01:00
{
//printHex("<- ",buffer, len);
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;
}
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)
{
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);
//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();
}
#endif