Fix C3 casts

This commit is contained in:
Robert Strouse 2024-04-09 19:08:38 -07:00
parent 5a8c09ee9f
commit c4d6a1008f
9 changed files with 74 additions and 62 deletions

View file

@ -313,7 +313,7 @@ void MQTTSettings::toJSON(JsonResponse &json) {
json.addElem("pubDisco", this->pubDisco);
json.addElem("protocol", this->protocol);
json.addElem("hostname", this->hostname);
json.addElem("port", this->port);
json.addElem("port", (uint32_t)this->port);
json.addElem("username", this->username);
json.addElem("password", this->password);
json.addElem("rootTopic", this->rootTopic);

View file

@ -83,7 +83,9 @@ bool GitRelease::toJSON(JsonObject &obj) {
}
void GitRelease::toJSON(JsonResponse &json) {
Timestamp ts;
json.addElem("id", this->id);
char buff[20];
sprintf(buff, "%llu", this->id);
json.addElem("id", buff);
json.addElem("name", this->name);
json.addElem("date", ts.getISOTime(this->releaseDate));
json.addElem("draft", this->draft);
@ -334,7 +336,7 @@ void GitUpdater::setCurrentRelease(GitRepo &repo) {
void GitUpdater::toJSON(JsonResponse &json) {
json.addElem("available", this->updateAvailable);
json.addElem("status", this->status);
json.addElem("error", this->error);
json.addElem("error", (int32_t)this->error);
json.addElem("cancelled", this->cancelled);
json.addElem("checkForUpdate", settings.checkForUpdate);
json.addElem("inetAvailable", this->inetAvailable);
@ -368,7 +370,7 @@ void GitUpdater::emitUpdateCheck(uint8_t num) {
json->beginObject();
json->addElem("available", this->updateAvailable);
json->addElem("status", this->status);
json->addElem("error", this->error);
json->addElem("error", (int32_t)this->error);
json->addElem("cancelled", this->cancelled);
json->addElem("checkForUpdate", settings.checkForUpdate);
json->addElem("inetAvailable", this->inetAvailable);
@ -427,11 +429,11 @@ void GitUpdater::emitDownloadProgress(uint8_t num, size_t total, size_t loaded,
JsonSockEvent *json = sockEmit.beginEmit(evt);
json->beginObject();
json->addElem("ver", this->targetRelease);
json->addElem("part", (int16_t)this->partition);
json->addElem("part", (int32_t)this->partition);
json->addElem("file", this->currentFile);
json->addElem("total", (uint32_t)total);
json->addElem("loaded", (uint32_t)loaded);
json->addElem("error", this->error);
json->addElem("error", (uint32_t)this->error);
json->endObject();
sockEmit.endEmit(num);
/*

View file

@ -175,8 +175,8 @@ void Network::emitSockets(uint8_t num) {
JsonSockEvent *json = sockEmit.beginEmit("wifiStrength");
json->beginObject();
json->addElem("ssid", WiFi.SSID().c_str());
json->addElem("strength", WiFi.RSSI());
json->addElem("channel", this->channel);
json->addElem("strength", (uint32_t)WiFi.RSSI());
json->addElem("channel", (uint32_t)this->channel);
json->endObject();
sockEmit.endEmit(num);
/*
@ -193,15 +193,15 @@ void Network::emitSockets(uint8_t num) {
JsonSockEvent *json = sockEmit.beginEmit("wifiStrength");
json->beginObject();
json->addElem("ssid", "");
json->addElem("strength", -100);
json->addElem("channel", -1);
json->addElem("strength", (int8_t)-100);
json->addElem("channel", (int8_t)-1);
json->endObject();
sockEmit.endEmit(num);
json = sockEmit.beginEmit("ethernet");
json->beginObject();
json->addElem("connected", false);
json->addElem("speed", 0);
json->addElem("speed", (uint8_t)0);
json->addElem("fullduplex", false);
json->endObject();
sockEmit.endEmit(num);
@ -709,7 +709,7 @@ void Network::networkEvent(WiFiEvent_t event) {
JsonSockEvent *json = sockEmit.beginEmit("ethernet");
json->beginObject();
json->addElem("connected", false);
json->addElem("speed", 0);
json->addElem("speed", (uint8_t)0);
json->addElem("fullduplex", false);
json->endObject();
sockEmit.endEmit();

View file

@ -1825,7 +1825,7 @@ void SomfyShade::emitState(uint8_t num, const char *evt) {
json->beginObject();
json->addElem("shadeId", this->shadeId);
json->addElem("type", static_cast<uint8_t>(this->shadeType));
json->addElem("remoteAddress", this->getRemoteAddress());
json->addElem("remoteAddress", (uint32_t)this->getRemoteAddress());
json->addElem("name", this->name);
json->addElem("direction", this->direction);
json->addElem("position", this->transformPosition(this->currentPos));
@ -1868,11 +1868,11 @@ void SomfyShade::emitCommand(uint8_t num, somfy_commands cmd, const char *source
JsonSockEvent *json = sockEmit.beginEmit(evt);
json->beginObject();
json->addElem("shadeId", this->shadeId);
json->addElem("remoteAddress", this->getRemoteAddress());
json->addElem("remoteAddress", (uint32_t)this->getRemoteAddress());
json->addElem("cmd", translateSomfyCommand(cmd).c_str());
json->addElem("source", source);
json->addElem("rcode", this->lastRollingCode);
json->addElem("sourceAddress", sourceAddress);
json->addElem("rcode", (uint32_t)this->lastRollingCode);
json->addElem("sourceAddress", (uint32_t)sourceAddress);
json->endObject();
sockEmit.endEmit(num);
/*
@ -1928,7 +1928,7 @@ void SomfyGroup::emitState(uint8_t num, const char *evt) {
JsonSockEvent *json = sockEmit.beginEmit(evt);
json->beginObject();
json->addElem("groupId", this->groupId);
json->addElem("remoteAddress", this->getRemoteAddress());
json->addElem("remoteAddress", (uint32_t)this->getRemoteAddress());
json->addElem("name", this->name);
json->addElem("sunSensor", this->hasSunSensor());
json->beginArray("shades");
@ -3199,7 +3199,7 @@ void SomfyShade::toJSONRef(JsonResponse &json) {
json.addElem("shadeId", this->getShadeId());
json.addElem("roomId", this->roomId);
json.addElem("name", this->name);
json.addElem("remoteAddress", this->m_remoteAddress);
json.addElem("remoteAddress", (uint32_t)this->m_remoteAddress);
json.addElem("paired", this->paired);
json.addElem("shadeType", static_cast<uint8_t>(this->shadeType));
json.addElem("bitLength", this->bitLength);
@ -3215,17 +3215,17 @@ void SomfyShade::toJSON(JsonResponse &json) {
json.addElem("shadeId", this->getShadeId());
json.addElem("roomId", this->roomId);
json.addElem("name", this->name);
json.addElem("remoteAddress", this->m_remoteAddress);
json.addElem("upTime", this->upTime);
json.addElem("downTime", this->downTime);
json.addElem("remoteAddress", (uint32_t)this->m_remoteAddress);
json.addElem("upTime", (uint32_t)this->upTime);
json.addElem("downTime", (uint32_t)this->downTime);
json.addElem("paired", this->paired);
json.addElem("lastRollingCode", this->lastRollingCode);
json.addElem("lastRollingCode", (uint32_t)this->lastRollingCode);
json.addElem("position", this->transformPosition(this->currentPos));
json.addElem("tiltType", static_cast<uint8_t>(this->tiltType));
json.addElem("tiltPosition", this->transformPosition(this->currentTiltPos));
json.addElem("tiltDirection", this->tiltDirection);
json.addElem("tiltTime", this->tiltTime);
json.addElem("stepSize", this->stepSize);
json.addElem("tiltTime", (uint32_t)this->tiltTime);
json.addElem("stepSize", (uint32_t)this->stepSize);
json.addElem("tiltTarget", this->transformPosition(this->tiltTarget));
json.addElem("target", this->transformPosition(this->target));
json.addElem("myPos", this->transformPosition(this->myPos));
@ -3353,8 +3353,8 @@ void SomfyGroup::toJSON(JsonResponse &json) {
json.addElem("groupId", this->getGroupId());
json.addElem("roomId", this->roomId);
json.addElem("name", this->name);
json.addElem("remoteAddress", this->m_remoteAddress);
json.addElem("lastRollingCode", this->lastRollingCode);
json.addElem("remoteAddress", (uint32_t)this->m_remoteAddress);
json.addElem("lastRollingCode", (uint32_t)this->lastRollingCode);
json.addElem("bitLength", this->bitLength);
json.addElem("proto", static_cast<uint8_t>(this->proto));
json.addElem("sunSensor", this->hasSunSensor());
@ -3381,8 +3381,8 @@ void SomfyGroup::toJSONRef(JsonResponse &json) {
json.addElem("groupId", this->getGroupId());
json.addElem("roomId", this->roomId);
json.addElem("name", this->name);
json.addElem("remoteAddress", this->m_remoteAddress);
json.addElem("lastRollingCode", this->lastRollingCode);
json.addElem("remoteAddress", (uint32_t)this->m_remoteAddress);
json.addElem("lastRollingCode", (uint32_t)this->lastRollingCode);
json.addElem("bitLength", this->bitLength);
json.addElem("proto", static_cast<uint8_t>(this->proto));
json.addElem("sunSensor", this->hasSunSensor());
@ -3423,8 +3423,8 @@ bool SomfyGroup::toJSON(JsonObject &obj) {
}
*/
void SomfyRemote::toJSON(JsonResponse &json) {
json.addElem("remoteAddress", this->getRemoteAddress());
json.addElem("lastRollingCode", this->lastRollingCode);
json.addElem("remoteAddress", (uint32_t)this->getRemoteAddress());
json.addElem("lastRollingCode", (uint32_t)this->lastRollingCode);
}
bool SomfyRemote::toJSON(JsonObject &obj) {
//obj["remotePrefId"] = this->getRemotePrefId();
@ -4080,7 +4080,7 @@ void SomfyShadeController::toJSONGroups(JsonResponse &json) {
}
void SomfyShadeController::toJSONRepeaters(JsonResponse &json) {
for(uint8_t i = 0; i < SOMFY_MAX_REPEATERS; i++) {
if(somfy.repeaters[i] != 0) json.addElem(somfy.repeaters[i]);
if(somfy.repeaters[i] != 0) json.addElem((uint8_t)somfy.repeaters[i]);
}
}
bool SomfyShadeController::toJSONRepeaters(JsonArray &arr) {
@ -4464,9 +4464,9 @@ void Transceiver::emitFrequencyScan(uint8_t num) {
json->beginObject();
json->addElem("scanning", rxmode == 3);
json->addElem("testFreq", currFreq);
json->addElem("testRSSI", currRSSI);
json->addElem("testRSSI", (int32_t)currRSSI);
json->addElem("frequency", markFreq);
json->addElem("RSSI", markRSSI);
json->addElem("RSSI", (int32_t)markRSSI);
json->endObject();
sockEmit.endEmit(num);
/*
@ -4492,10 +4492,10 @@ void Transceiver::emitFrame(somfy_frame_t *frame, somfy_rx_t *rx) {
JsonSockEvent *json = sockEmit.beginEmit("remoteFrame");
json->beginObject();
json->addElem("encKey", frame->encKey);
json->addElem("address", frame->remoteAddress);
json->addElem("rcode", frame->rollingCode);
json->addElem("address", (uint32_t)frame->remoteAddress);
json->addElem("rcode", (uint32_t)frame->rollingCode);
json->addElem("command", translateSomfyCommand(frame->cmd).c_str());
json->addElem("rssi", frame->rssi);
json->addElem("rssi", (uint32_t)frame->rssi);
json->addElem("bits", rx->bit_length);
json->addElem("proto", static_cast<uint8_t>(frame->proto));
json->addElem("valid", frame->valid);
@ -4503,7 +4503,7 @@ void Transceiver::emitFrame(somfy_frame_t *frame, somfy_rx_t *rx) {
json->beginArray("pulses");
if(rx) {
for(uint16_t i = 0; i < rx->pulseCount; i++) {
json->addElem(rx->pulses[i]);
json->addElem((uint32_t)rx->pulses[i]);
}
}
json->endArray();

Binary file not shown.

Binary file not shown.

View file

@ -107,23 +107,29 @@ void JsonFormatter::addElem(const char *val) { this->addElem(nullptr, val); }
void JsonFormatter::addElem(float fval) { sprintf(this->_numbuff, "%.4f", fval); this->_appendNumber(nullptr); }
void JsonFormatter::addElem(int8_t nval) { sprintf(this->_numbuff, "%d", nval); this->_appendNumber(nullptr); }
void JsonFormatter::addElem(uint8_t nval) { sprintf(this->_numbuff, "%u", nval); this->_appendNumber(nullptr); }
void JsonFormatter::addElem(int32_t nval) { sprintf(this->_numbuff, "%ld", (long)nval); this->_appendNumber(nullptr); }
void JsonFormatter::addElem(uint32_t nval) { sprintf(this->_numbuff, "%lu", (unsigned long)nval); this->_appendNumber(nullptr); }
/*
void JsonFormatter::addElem(int16_t nval) { sprintf(this->_numbuff, "%d", nval); this->_appendNumber(nullptr); }
void JsonFormatter::addElem(uint16_t nval) { sprintf(this->_numbuff, "%u", nval); this->_appendNumber(nullptr); }
void JsonFormatter::addElem(int nval) { sprintf(this->_numbuff, "%ld", (long)nval); this->_appendNumber(nullptr); }
void JsonFormatter::addElem(uint32_t nval) { sprintf(this->_numbuff, "%lu", (unsigned long)nval); this->_appendNumber(nullptr); }
void JsonFormatter::addElem(int64_t lval) { sprintf(this->_numbuff, "%lld", (long long)lval); this->_appendNumber(nullptr); }
void JsonFormatter::addElem(uint64_t lval) { sprintf(this->_numbuff, "%llu", (unsigned long long)lval); this->_appendNumber(nullptr); }
*/
void JsonFormatter::addElem(bool bval) { strcpy(this->_numbuff, bval ? "true" : "false"); this->_appendNumber(nullptr); }
void JsonFormatter::addElem(const char *name, float fval) { sprintf(this->_numbuff, "%.4f", fval); this->_appendNumber(name); }
void JsonFormatter::addElem(const char *name, int8_t nval) { sprintf(this->_numbuff, "%d", nval); this->_appendNumber(name); }
void JsonFormatter::addElem(const char *name, uint8_t nval) { sprintf(this->_numbuff, "%u", nval); this->_appendNumber(name); }
void JsonFormatter::addElem(const char *name, int32_t nval) { sprintf(this->_numbuff, "%ld", (long)nval); this->_appendNumber(name); }
void JsonFormatter::addElem(const char *name, uint32_t nval) { sprintf(this->_numbuff, "%lu", (unsigned long)nval); this->_appendNumber(name); }
/*
void JsonFormatter::addElem(const char *name, int16_t nval) { sprintf(this->_numbuff, "%d", nval); this->_appendNumber(name); }
void JsonFormatter::addElem(const char *name, uint16_t nval) { sprintf(this->_numbuff, "%u", nval); this->_appendNumber(name); }
void JsonFormatter::addElem(const char *name, int nval) { sprintf(this->_numbuff, "%ld", (long)nval); this->_appendNumber(name); }
void JsonFormatter::addElem(const char *name, uint32_t nval) { sprintf(this->_numbuff, "%lu", (unsigned long)nval); this->_appendNumber(name); }
void JsonFormatter::addElem(const char *name, int64_t lval) { sprintf(this->_numbuff, "%lld", (long long)lval); this->_appendNumber(name); }
void JsonFormatter::addElem(const char *name, uint64_t lval) { sprintf(this->_numbuff, "%llu", (unsigned long long)lval); this->_appendNumber(name); }
*/
void JsonFormatter::addElem(const char *name, bool bval) { strcpy(this->_numbuff, bval ? "true" : "false"); this->_appendNumber(name); }
void JsonFormatter::_safecat(const char *val, bool escape) {

20
WResp.h
View file

@ -24,25 +24,29 @@ class JsonFormatter {
void addElem(const char* val);
void addElem(float fval);
void addElem(int nval);
void addElem(int8_t nval);
void addElem(uint8_t nval);
/*
void addElem(int32_t nval);
void addElem(int16_t nval);
void addElem(uint16_t nval);
void addElem(uint32_t nval);
void addElem(int64_t lval);
void addElem(uint64_t lval);
void addElem(unsigned int nval);
*/
void addElem(int32_t lval);
void addElem(uint32_t lval);
void addElem(bool bval);
void addElem(const char* name, float fval);
void addElem(const char* name, int nval);
void addElem(const char* name, int8_t nval);
void addElem(const char* name, uint8_t nval);
/*
void addElem(const char* name, int nval);
void addElem(const char* name, int16_t nval);
void addElem(const char* name, uint16_t nval);
void addElem(const char* name, uint32_t nval);
void addElem(const char* name, int64_t lval);
void addElem(const char* name, uint64_t lval);
void addElem(const char* name, unsigned int nval);
*/
void addElem(const char* name, int32_t lval);
void addElem(const char* name, uint32_t lval);
void addElem(const char* name, bool bval);
void addElem(const char *name, const char *val);
};

26
Web.cpp
View file

@ -272,12 +272,12 @@ void Web::handleController(WebServer &server) {
JsonResponse resp;
resp.beginResponse(&server, g_content, sizeof(g_content));
resp.beginObject();
resp.addElem("maxRooms", SOMFY_MAX_ROOMS);
resp.addElem("maxShades", SOMFY_MAX_SHADES);
resp.addElem("maxGroups", SOMFY_MAX_GROUPS);
resp.addElem("maxGroupedShades", SOMFY_MAX_GROUPED_SHADES);
resp.addElem("maxLinkedRemotes", SOMFY_MAX_LINKED_REMOTES);
resp.addElem("startingAddress", somfy.startingAddress);
resp.addElem("maxRooms", (uint8_t)SOMFY_MAX_ROOMS);
resp.addElem("maxShades", (uint8_t)SOMFY_MAX_SHADES);
resp.addElem("maxGroups", (uint8_t)SOMFY_MAX_GROUPS);
resp.addElem("maxGroupedShades", (uint8_t)SOMFY_MAX_GROUPED_SHADES);
resp.addElem("maxLinkedRemotes", (uint8_t)SOMFY_MAX_LINKED_REMOTES);
resp.addElem("startingAddress", (uint32_t)somfy.startingAddress);
resp.beginObject("transceiver");
somfy.transceiver.toJSON(resp);
resp.endObject();
@ -1224,9 +1224,9 @@ void Web::begin() {
resp.beginResponse(&server, g_content, sizeof(g_content));
resp.beginObject();
resp.addElem("shadeId", shadeId);
resp.addElem("remoteAddress", somfy.getNextRemoteAddress(shadeId));
resp.addElem("remoteAddress", (uint32_t)somfy.getNextRemoteAddress(shadeId));
resp.addElem("bitLength", somfy.transceiver.config.type);
resp.addElem("stepSize", 100);
resp.addElem("stepSize", (uint8_t)100);
resp.addElem("proto", static_cast<uint8_t>(somfy.transceiver.config.proto));
resp.endObject();
resp.endResponse();
@ -1238,7 +1238,7 @@ void Web::begin() {
resp.beginResponse(&server, g_content, sizeof(g_content));
resp.beginObject();
resp.addElem("groupId", groupId);
resp.addElem("remoteAddress", somfy.getNextRemoteAddress(groupId));
resp.addElem("remoteAddress", (uint32_t)somfy.getNextRemoteAddress(groupId));
resp.addElem("bitLength", somfy.transceiver.config.type);
resp.addElem("proto", static_cast<uint8_t>(somfy.transceiver.config.proto));
resp.endObject();
@ -2189,16 +2189,16 @@ void Web::begin() {
resp.beginObject("connected");
resp.addElem("name", settings.WIFI.ssid);
resp.addElem("passphrase", settings.WIFI.passphrase);
resp.addElem("strength", WiFi.RSSI());
resp.addElem("channel", WiFi.channel());
resp.addElem("strength", (int32_t)WiFi.RSSI());
resp.addElem("channel", (int32_t)WiFi.channel());
resp.endObject();
resp.beginArray("accessPoints");
for(int i = 0; i < n; ++i) {
if(WiFi.SSID(i).length() == 0 || WiFi.RSSI(i) < -95) continue; // Ignore hidden and weak networks that we cannot connect to anyway.
resp.beginObject();
resp.addElem("name", WiFi.SSID(i).c_str());
resp.addElem("channel", WiFi.channel(i));
resp.addElem("strength", WiFi.RSSI(i));
resp.addElem("channel", (int32_t)WiFi.channel(i));
resp.addElem("strength", (int32_t)WiFi.RSSI(i));
resp.addElem("macAddress", WiFi.BSSIDstr(i).c_str());
resp.endObject();
}