Skip to content

Commit f8b3bc4

Browse files
author
Robert Strouse
committed
Fix byte alignments #273
1 parent 25c8a66 commit f8b3bc4

14 files changed

+109
-56
lines changed

ConfigFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ bool ShadeConfigFile::validate() {
483483
if(this->header.version >= 21) {
484484
recs = 0;
485485
while(recs < this->header.repeaterRecords) {
486-
uint32_t pos = this->file.position();
486+
//uint32_t pos = this->file.position();
487487
if(!this->seekChar(CFG_REC_END)) {
488488
Serial.printf("Failed to find the repeater record end %d\n", recs);
489489
}
@@ -757,7 +757,7 @@ bool ShadeConfigFile::readGroupRecord(SomfyGroup *group) {
757757
bool ShadeConfigFile::readRepeaterRecord(SomfyShadeController *s) {
758758
uint32_t startPos = this->file.position();
759759

760-
for(uint8_t i; i < SOMFY_MAX_REPEATERS; i++) {
760+
for(uint8_t i = 0; i < SOMFY_MAX_REPEATERS; i++) {
761761
s->linkRepeater(this->readUInt32(0));
762762
}
763763
if(this->file.position() != startPos + this->header.repeaterRecordSize) {

Network.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extern rebootDelay_t rebootDelay;
1717
extern Network net;
1818

1919
static bool _apScanning = false;
20+
static uint32_t _lastHeap = 0;
2021
int connectRetries = 0;
2122
void Network::end() {
2223
sockEmit.end();
@@ -147,6 +148,7 @@ bool Network::changeAP(const uint8_t *bssid, const int32_t channel) {
147148
return false;
148149
}
149150
void Network::emitSockets() {
151+
this->emitHeap();
150152
if(this->needsBroadcast ||
151153
(this->connType == conn_types::wifi && (abs(abs(WiFi.RSSI()) - abs(this->lastRSSI)) > 1 || WiFi.channel() != this->lastChannel))) {
152154
this->emitSockets(255);
@@ -222,6 +224,7 @@ void Network::emitSockets(uint8_t num) {
222224
this->lastChannel = -1;
223225
}
224226
}
227+
this->emitHeap(num);
225228
}
226229
void Network::setConnected(conn_types connType) {
227230
this->connType = connType;
@@ -331,7 +334,7 @@ void Network::setConnected(conn_types connType) {
331334
if(strlen(settings.chipModel) == 0) SSDP.setModelNumber(0, "ESP32");
332335
else {
333336
char sModel[20] = "";
334-
snprintf(sModel, sizeof(sModel), "ESP32-%S", settings.chipModel);
337+
snprintf(sModel, sizeof(sModel), "ESP32-%s", settings.chipModel);
335338
SSDP.setModelNumber(0, sModel);
336339
}
337340
SSDP.setModelURL(0, "https://github.com/rstrouse/ESPSomfy-RTS");
@@ -744,3 +747,15 @@ void Network::networkEvent(WiFiEvent_t event) {
744747
break;
745748
}
746749
}
750+
void Network::emitHeap(uint8_t num) {
751+
if(num != 255 || this->needsBroadcast || ESP.getMaxAllocHeap() != _lastHeap) {
752+
_lastHeap = ESP.getMaxAllocHeap();
753+
JsonSockEvent *json = sockEmit.beginEmit("memStatus");
754+
json->beginObject();
755+
json->addElem("max", _lastHeap);
756+
json->addElem("free", ESP.getFreeHeap());
757+
json->addElem("min", ESP.getMinFreeHeap());
758+
json->endObject();
759+
sockEmit.endEmit(num);
760+
}
761+
}

Network.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Network {
3939
void end();
4040
void emitSockets();
4141
void emitSockets(uint8_t num);
42+
void emitHeap(uint8_t num = 255);
4243
uint32_t getChipId();
4344
static void networkEvent(WiFiEvent_t event);
4445
};

SSDP.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static const char _ssdp_bye_template[] PROGMEM =
3232
"NTS: ssdp:byebye\r\n"
3333
"NT: %s\r\n"
3434
"USN: %s\r\n"
35-
"BOOTID.UPNP.ORG: %ul\r\n"
35+
"BOOTID.UPNP.ORG: %lu\r\n"
3636
"CONFIGID.UPNP.ORG: %d\r\n"
3737
"\r\n";
3838
static const char _ssdp_packet_template[] PROGMEM =
@@ -42,7 +42,7 @@ static const char _ssdp_packet_template[] PROGMEM =
4242
"USN: %s\r\n" // _uuid
4343
"%s: %s\r\n" // "NT" or "ST", _deviceType
4444
"LOCATION: http://%u.%u.%u.%u:%u/%s\r\n" // WiFi.localIP(), _port, _schemaURL
45-
"BOOTID.UPNP.ORG: %ul\r\n"
45+
"BOOTID.UPNP.ORG: %lu\r\n"
4646
"CONFIGID.UPNP.ORG: %d\r\n"
4747
"\r\n";
4848
static const char _ssdp_device_schema_template[] PROGMEM =
@@ -160,7 +160,7 @@ void UPNPDeviceType::setChipId(uint32_t chipId) {
160160
(uint16_t)((chipId >> 8) & 0xff),
161161
(uint16_t)chipId & 0xff);
162162
}
163-
SSDPClass::SSDPClass():sendQueue{false, INADDR_NONE, 0, nullptr, false, 0, ""} {}
163+
SSDPClass::SSDPClass():sendQueue{false, INADDR_NONE, 0, nullptr, false, 0, "", response_types_t::root} {}
164164
SSDPClass::~SSDPClass() { end(); }
165165
bool SSDPClass::begin() {
166166
for(int i = 0; i < SSDP_QUEUE_SIZE; i++) {
@@ -407,7 +407,7 @@ void SSDPClass::_sendResponse(IPAddress addr, uint16_t port, UPNPDeviceType *d,
407407
strcpy_P(pbuff, _ssdp_response_template);
408408

409409
// Don't use ip.toString as this fragments the heap like no tomorrow.
410-
int len = snprintf_P(buffer, sizeof(buffer)-1,
410+
snprintf_P(buffer, sizeof(buffer)-1,
411411
_ssdp_packet_template,
412412
pbuff,
413413
this->_interval,

Sockets.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ JsonSockEvent *SocketEmitter::beginEmit(const char *evt) {
175175
this->json.beginEvent(&sockServer, evt, g_response, sizeof(g_response));
176176
return &this->json;
177177
}
178-
void SocketEmitter::endEmit(uint8_t num) { this->json.endEvent(num); }
178+
void SocketEmitter::endEmit(uint8_t num) { sockServer.loop(); this->json.endEvent(num); }
179179
void SocketEmitter::endEmitRoom(uint8_t room) {
180180
if(room < SOCK_MAX_ROOMS) {
181181
room_t *r = &this->rooms[room];

Somfy.cpp

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,6 +3258,7 @@ void SomfyShade::toJSON(JsonResponse &json) {
32583258
json.endArray();
32593259
}
32603260

3261+
/*
32613262
bool SomfyShade::toJSON(JsonObject &obj) {
32623263
//Serial.print("Serializing Shade:");
32633264
//Serial.print(this->getShadeId());
@@ -3310,17 +3311,20 @@ bool SomfyShade::toJSON(JsonObject &obj) {
33103311
}
33113312
return true;
33123313
}
3314+
*/
33133315
bool SomfyRoom::fromJSON(JsonObject &obj) {
33143316
if(obj.containsKey("name")) strlcpy(this->name, obj["name"], sizeof(this->name));
33153317
if(obj.containsKey("sortOrder")) this->sortOrder = obj["sortOrder"];
33163318
return true;
33173319
}
3320+
/*
33183321
bool SomfyRoom::toJSON(JsonObject &obj) {
33193322
obj["roomId"] = this->roomId;
33203323
obj["name"] = this->name;
33213324
obj["sortOrder"] = this->sortOrder;
33223325
return true;
33233326
}
3327+
*/
33243328
void SomfyRoom::toJSON(JsonResponse &json) {
33253329
json.addElem("roomId", this->roomId);
33263330
json.addElem("name", this->name);
@@ -3422,16 +3426,19 @@ bool SomfyGroup::toJSON(JsonObject &obj) {
34223426
return true;
34233427
}
34243428
*/
3429+
34253430
void SomfyRemote::toJSON(JsonResponse &json) {
34263431
json.addElem("remoteAddress", (uint32_t)this->getRemoteAddress());
34273432
json.addElem("lastRollingCode", (uint32_t)this->lastRollingCode);
34283433
}
3434+
/*
34293435
bool SomfyRemote::toJSON(JsonObject &obj) {
34303436
//obj["remotePrefId"] = this->getRemotePrefId();
34313437
obj["remoteAddress"] = this->getRemoteAddress();
34323438
obj["lastRollingCode"] = this->lastRollingCode;
34333439
return true;
34343440
}
3441+
*/
34353442
void SomfyRemote::setRemoteAddress(uint32_t address) { this->m_remoteAddress = address; snprintf(this->m_remotePrefId, sizeof(this->m_remotePrefId), "_%lu", (unsigned long)this->m_remoteAddress); }
34363443
uint32_t SomfyRemote::getRemoteAddress() { return this->m_remoteAddress; }
34373444
void SomfyShadeController::processFrame(somfy_frame_t &frame, bool internal) {
@@ -4571,13 +4578,14 @@ void Transceiver::toJSON(JsonResponse& json) {
45714578
this->config.toJSON(json);
45724579
json.endObject();
45734580
}
4574-
4581+
/*
45754582
bool Transceiver::toJSON(JsonObject& obj) {
45764583
//Serial.println("Setting Transceiver Json");
45774584
JsonObject objConfig = obj.createNestedObject("config");
45784585
this->config.toJSON(objConfig);
45794586
return true;
45804587
}
4588+
*/
45814589
bool Transceiver::fromJSON(JsonObject& obj) {
45824590
if (obj.containsKey("config")) {
45834591
JsonObject objConfig = obj["config"];
@@ -4664,6 +4672,7 @@ void transceiver_config_t::toJSON(JsonResponse &json) {
46644672
json.addElem("enabled", this->enabled);
46654673
json.addElem("radioInit", this->radioInit);
46664674
}
4675+
/*
46674676
void transceiver_config_t::toJSON(JsonObject& obj) {
46684677
obj["type"] = this->type;
46694678
obj["TXPin"] = this->TXPin;
@@ -4677,36 +4686,35 @@ void transceiver_config_t::toJSON(JsonObject& obj) {
46774686
obj["deviation"] = this->deviation; // float
46784687
obj["txPower"] = this->txPower;
46794688
obj["proto"] = static_cast<uint8_t>(this->proto);
4680-
/*
4681-
obj["internalCCMode"] = this->internalCCMode;
4682-
obj["modulationMode"] = this->modulationMode;
4683-
obj["channel"] = this->channel;
4684-
obj["channelSpacing"] = this->channelSpacing; // float
4685-
obj["dataRate"] = this->dataRate; // float
4686-
obj["syncMode"] = this->syncMode;
4687-
obj["syncWordHigh"] = this->syncWordHigh;
4688-
obj["syncWordLow"] = this->syncWordLow;
4689-
obj["addrCheckMode"] = this->addrCheckMode;
4690-
obj["checkAddr"] = this->checkAddr;
4691-
obj["dataWhitening"] = this->dataWhitening;
4692-
obj["pktFormat"] = this->pktFormat;
4693-
obj["pktLengthMode"] = this->pktLengthMode;
4694-
obj["pktLength"] = this->pktLength;
4695-
obj["useCRC"] = this->useCRC;
4696-
obj["autoFlushCRC"] = this->autoFlushCRC;
4697-
obj["disableDCFilter"] = this->disableDCFilter;
4698-
obj["enableManchester"] = this->enableManchester;
4699-
obj["enableFEC"] = this->enableFEC;
4700-
obj["minPreambleBytes"] = this->minPreambleBytes;
4701-
obj["pqtThreshold"] = this->pqtThreshold;
4702-
obj["appendStatus"] = this->appendStatus;
4703-
obj["printBuffer"] = somfy.transceiver.printBuffer;
4704-
*/
4689+
//obj["internalCCMode"] = this->internalCCMode;
4690+
//obj["modulationMode"] = this->modulationMode;
4691+
//obj["channel"] = this->channel;
4692+
//obj["channelSpacing"] = this->channelSpacing; // float
4693+
//obj["dataRate"] = this->dataRate; // float
4694+
//obj["syncMode"] = this->syncMode;
4695+
//obj["syncWordHigh"] = this->syncWordHigh;
4696+
//obj["syncWordLow"] = this->syncWordLow;
4697+
//obj["addrCheckMode"] = this->addrCheckMode;
4698+
//obj["checkAddr"] = this->checkAddr;
4699+
//obj["dataWhitening"] = this->dataWhitening;
4700+
//obj["pktFormat"] = this->pktFormat;
4701+
//obj["pktLengthMode"] = this->pktLengthMode;
4702+
//obj["pktLength"] = this->pktLength;
4703+
//obj["useCRC"] = this->useCRC;
4704+
//obj["autoFlushCRC"] = this->autoFlushCRC;
4705+
//obj["disableDCFilter"] = this->disableDCFilter;
4706+
//obj["enableManchester"] = this->enableManchester;
4707+
//obj["enableFEC"] = this->enableFEC;
4708+
//obj["minPreambleBytes"] = this->minPreambleBytes;
4709+
//obj["pqtThreshold"] = this->pqtThreshold;
4710+
//obj["appendStatus"] = this->appendStatus;
4711+
//obj["printBuffer"] = somfy.transceiver.printBuffer;
47054712
obj["enabled"] = this->enabled;
47064713
obj["radioInit"] = this->radioInit;
47074714
//Serial.print("Serialize Radio JSON ");
47084715
//Serial.printf("SCK:%u MISO:%u MOSI:%u CSN:%u RX:%u TX:%u\n", this->SCKPin, this->MISOPin, this->MOSIPin, this->CSNPin, this->RXPin, this->TXPin);
47094716
}
4717+
*/
47104718
void transceiver_config_t::save() {
47114719
pref.begin("CC1101");
47124720
pref.clear();

Somfy.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class SomfyRoom {
197197
void clear();
198198
bool save();
199199
bool fromJSON(JsonObject &obj);
200-
bool toJSON(JsonObject &obj);
200+
//bool toJSON(JsonObject &obj);
201201
void toJSON(JsonResponse &json);
202202
void emitState(const char *evt = "roomState");
203203
void emitState(uint8_t num, const char *evt = "roomState");
@@ -228,7 +228,7 @@ class SomfyRemote {
228228
uint8_t repeats = 1;
229229
virtual bool isLastCommand(somfy_commands cmd);
230230
char *getRemotePrefId() {return m_remotePrefId;}
231-
virtual bool toJSON(JsonObject &obj);
231+
//virtual bool toJSON(JsonObject &obj);
232232
virtual void toJSON(JsonResponse &json);
233233
virtual void setRemoteAddress(uint32_t address);
234234
virtual uint32_t getRemoteAddress();
@@ -297,7 +297,7 @@ class SomfyShade : public SomfyRemote {
297297
//bool toJSONRef(JsonObject &obj);
298298
void toJSONRef(JsonResponse &json);
299299
int8_t fromJSON(JsonObject &obj);
300-
bool toJSON(JsonObject &obj) override;
300+
//bool toJSON(JsonObject &obj) override;
301301
void toJSON(JsonResponse &json) override;
302302

303303
char name[21] = "";
@@ -475,7 +475,7 @@ struct transceiver_config_t {
475475
bool appendStatus = false; // Appends the RSSI and LQI values to the TX packed as well as the CRC.
476476
*/
477477
void fromJSON(JsonObject& obj);
478-
void toJSON(JsonObject& obj);
478+
//void toJSON(JsonObject& obj);
479479
void toJSON(JsonResponse& json);
480480
void save();
481481
void load();
@@ -490,7 +490,7 @@ class Transceiver {
490490
public:
491491
transceiver_config_t config;
492492
bool printBuffer = false;
493-
bool toJSON(JsonObject& obj);
493+
//bool toJSON(JsonObject& obj);
494494
void toJSON(JsonResponse& json);
495495
bool fromJSON(JsonObject& obj);
496496
bool save();

SomfyController.ino.esp32.bin

-1.39 KB
Binary file not shown.

SomfyController.ino.esp32s3.bin

10.1 KB
Binary file not shown.

SomfyController.littlefs.bin

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)