-add magic number to memory

-add debug output to esp_platform
-add more fine granular startup to Bau57B0
This commit is contained in:
Thomas Kunze 2018-03-17 00:08:14 +01:00
parent a7a48b4a7b
commit 649d831f7f
5 changed files with 70 additions and 24 deletions

View File

@ -39,7 +39,7 @@ void ApplicationLayer::dataGroupIndication(HopCountType hopType, Priority priori
len -= 1;
}
for (uint16_t i; i < entries; i++)
for (uint16_t i = 0; i < entries; i++)
{
uint16_t entry = _assocTable[i];
if (highByte(entry) == tsap)

View File

@ -2,6 +2,7 @@
#include <string.h>
#include <stdio.h>
using namespace std;
Bau57B0::Bau57B0(Platform& platform): _memoryReference((uint8_t*)&_deviceObj), _memory(platform), _addrTable(_memoryReference),
@ -19,8 +20,6 @@ Bau57B0::Bau57B0(Platform& platform): _memoryReference((uint8_t*)&_deviceObj), _
_memory.addSaveRestore(&_addrTable);
_memory.addSaveRestore(&_assocTable);
_memory.addSaveRestore(&_groupObjTable);
_memory.readMemory();
_dlLayer.enabled(true);
}
void Bau57B0::loop()
@ -82,6 +81,11 @@ void Bau57B0::updateGroupObject(GroupObject & go, uint8_t * data, uint8_t length
go.commFlag(cfUpdate);
if (go.updateHandler)
go.updateHandler(go);
}
void Bau57B0::readMemory()
{
_memory.readMemory();
}
DeviceObject& Bau57B0::deviceObject()
@ -105,6 +109,16 @@ bool Bau57B0::configured()
&& _addrTable.loadState() == LS_LOADED
&& _assocTable.loadState() == LS_LOADED
&& _appProgram.loadState() == LS_LOADED;
}
bool Bau57B0::enabled()
{
return _dlLayer.enabled();
}
void Bau57B0::enabled(bool value)
{
_dlLayer.enabled(value);
}
void Bau57B0::memoryWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t number,

View File

@ -24,6 +24,9 @@ public:
GroupObjectTableObject& groupObjectTable();
ApplicationProgramObject& parameters();
bool configured();
bool enabled();
void enabled(bool value);
void readMemory();
protected:
void memoryWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t number,
uint16_t memoryAddress, uint8_t* data) override;

View File

@ -29,7 +29,7 @@ void EspPlatform::macAddress(uint8_t * addr)
uint32_t EspPlatform::millis()
{
return millis();
return ::millis();
}
void EspPlatform::mdelay(uint32_t millis)
@ -39,6 +39,7 @@ void EspPlatform::mdelay(uint32_t millis)
void EspPlatform::restart()
{
Serial.println("restart");
ESP.restart();
}
@ -58,7 +59,12 @@ void EspPlatform::setupMultiCast(uint32_t addr, uint16_t port)
{
_mulitcastAddr = addr;
_mulitcastPort = port;
_udp.beginMulticast(WiFi.localIP(), addr, port);
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());
uint8 result = _udp.beginMulticast(WiFi.localIP(), mcastaddr, port);
Serial.printf("result %d\n", result);
}
void EspPlatform::closeMultiCast()
@ -66,11 +72,24 @@ void EspPlatform::closeMultiCast()
_udp.stop();
}
void printHex(const char* suffix, uint8_t *data, uint8_t length)
{
Serial.print(suffix);
for (int i = 0; i<length; i++) {
if (data[i]<0x10) { Serial.print("0"); }
Serial.print(data[i], HEX);
Serial.print(" ");
}
Serial.print("\n");
}
bool EspPlatform::sendBytes(uint8_t * buffer, uint16_t len)
{
_udp.beginPacketMulticast(_mulitcastAddr, _mulitcastPort, WiFi.localIP());
_udp.write(buffer, len);
_udp.endPacket();
printHex("-> ",buffer, len);
int result = 0;
result = _udp.beginPacketMulticast(_mulitcastAddr, _mulitcastPort, WiFi.localIP());
result = _udp.write(buffer, len);
result = _udp.endPacket();
return true;
}
@ -82,11 +101,12 @@ int EspPlatform::readBytes(uint8_t * buffer, uint16_t maxLen)
if (len > maxLen)
{
printf("udp buffer to small. was %d, needed %d\n", maxLen, len);
Serial.printf("udp buffer to small. was %d, needed %d\n", maxLen, len);
fatalError();
}
_udp.read(buffer, len);
printHex("<- ", buffer, len);
return len;
}

View File

@ -16,25 +16,34 @@ bool Memory::isMemoryModified()
void Memory::readMemory()
{
//_data = _platform.getEepromBuffer(512);
//uint8_t* buffer = _data;
//int size = _saveCount;
//for (int i = 0; i < size; i++)
//{
// buffer = _saveRestores[i]->restore(buffer);
//}
_data = _platform.getEepromBuffer(512);
if (_data[0] != 0xDE || _data[1] != 0xAD || _data[2] != 0xAF || _data[3] != 0xFE)
return;
uint8_t* buffer = _data + 4;
int size = _saveCount;
for (int i = 0; i < size; i++)
{
buffer = _saveRestores[i]->restore(buffer);
}
}
void Memory::writeMemory()
{
//uint8_t* buffer = _data;
//int size = _saveCount;
//for (int i = 0; i < size; i++)
//{
// buffer = _saveRestores[i]->save(buffer);
//}
//_platform.commitToEeprom();
//_modified = false;
_data[0] = 0xDE;
_data[1] = 0xAD;
_data[2] = 0xAF;
_data[3] = 0xFE;
uint8_t* buffer = _data + 4;
int size = _saveCount;
for (int i = 0; i < size; i++)
{
buffer = _saveRestores[i]->save(buffer);
}
_platform.commitToEeprom();
_modified = false;
}
void Memory::addSaveRestore(SaveRestore * obj)