Skip to content

Commit

Permalink
20240510
Browse files Browse the repository at this point in the history
        - NVRAM Erase tool, showing logs in real time
- Add translation for button NVRAM Erase
- Correct Olimex typo #6 Thanks @mihsu81 🚀
  • Loading branch information
xyzroe committed May 10, 2024
1 parent a1a2561 commit 92dcdf7
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 94 deletions.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions lib/CCTools/src/CCTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ bool CCTools::ledToggle()
return false;
}

bool CCTools::nvram_reset(void (*logFunction)(String))
bool CCTools::nvram_reset(void (*logFunction)(const String&))
{
bool success = true;

Expand Down Expand Up @@ -965,7 +965,7 @@ bool CCTools::nvram_reset(void (*logFunction)(String))
}
}

logFunction("NVRAM erase finish. Restarting...");
logFunction("NVRAM erase finish. Restart CC2652");

restart();

Expand Down
2 changes: 1 addition & 1 deletion lib/CCTools/src/CCTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ class CCTools : public CommandInterface
void processFlash(byte *data, int size);
bool checkFirmwareVersion();
bool ledToggle();
bool nvram_reset(void (*logFunction)(String));
bool nvram_reset(void (*logFunction)(const String&));
};

#endif // CCTools_DETECT_H
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// AUTO GENERATED FILE
#ifndef VERSION
#define VERSION "20240509"
#define VERSION "20240510"
#endif
102 changes: 25 additions & 77 deletions src/web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,71 +498,6 @@ void handleApi()
const uint8_t action = serverWeb.arg(action).toInt();
switch (action)
{
/*case API_FLASH_ZB:
{
vars.zbFlashing = 1;
const char *fwurlArg = "fwurl";
const uint8_t eventLen = 11;
const char *tagZB_FW_info = "ZB_FW_info";
const char *tagZB_FW_err = "ZB_FW_err";
const char *tagZB_FW_progress = "ZB_FW_prgs";
if (serverWeb.hasArg(fwurlArg))
{
String fwUrl = serverWeb.arg(fwurlArg);
serverWeb.send(HTTP_CODE_OK, contTypeText, ok);
uint8_t evWaitCount = 0;
while (!eventsClient.connected() && evWaitCount < 200)
{ // wait for events
webServerHandleClient();
delay(25);
evWaitCount++;
}
// sendEvent(eventLen, String("FW Url: ") + fwUrl);
// setClock();
HTTPClient https;
WiFiClientSecure client;
client.setInsecure();
https.begin(client, fwUrl); // https://raw.githubusercontent.com/Tarik2142/devHost/main/coordinator_20211217.bin
https.addHeader("Content-Type", "application/octet-stream");
const int16_t httpsCode = https.GET();
// sendEvent(eventLen, String("REQ result: ") + httpsCode);
if (httpsCode == HTTP_CODE_OK)
{
const uint32_t fwSize = https.getSize();
DEBUG_PRINTLN(F("[start] Downloading firmware..."));
sendEvent(tagZB_FW_info, eventLen, "[start]");
sendEvent(tagZB_FW_info, eventLen, "Downloading firmware...");
const char *tempFile2 = "/config/coordinator.bin";
LittleFS.remove(tempFile2);
File fwFile = LittleFS.open(tempFile2, "w", 1);
uint8_t buff[4];
uint32_t downloaded = 0;
while (client.readBytes(buff, sizeof(buff)))
{
downloaded += fwFile.write(buff, sizeof(buff));
if (!(downloaded % 8192))
{
const uint8_t d = ((float)downloaded / fwSize) * 100;
sendEvent(tagZB_FW_progress, eventLen, String(d));
}
}
fwFile.close();
// in development
}
else
{
LOGD("REQ error: http_code " + String(httpsCode));
serverWeb.send(HTTP_CODE_BAD_REQUEST, contTypeText, String(httpsCode));
sendEvent(tagZB_FW_err, eventLen, "REQ error: http_code " + String(httpsCode));
}
}
else
{
serverWeb.send(HTTP_CODE_BAD_REQUEST, contTypeText, "missing arg 1");
}
vars.zbFlashing = 0;
}
break;*/
case API_GET_LOG:
{
String result;
Expand Down Expand Up @@ -1003,30 +938,24 @@ void handleSaveParams()

void printEachKeyValuePair(const String &jsonString)
{
DynamicJsonDocument doc(1024); // Создаём JSON документ с достаточным размером буфера

// Десериализация JSON строки в JSON объект
DynamicJsonDocument doc(1024);
DeserializationError error = deserializeJson(doc, jsonString);

// Проверяем на ошибки десериализации
if (error)
{
// Serial.print(F("deserializeJson() failed with code "));
// Serial.println(error.c_str());

return;
}

const uint8_t eventLen = 100;
// Перебираем все ключи и значения в корневом объекте

for (JsonPair kv : doc.as<JsonObject>())
{
DynamicJsonDocument pairDoc(256); // Создаем маленький JSON документ для каждой пары
pairDoc[kv.key().c_str()] = kv.value(); // Добавляем текущую пару в новый документ
DynamicJsonDocument pairDoc(256);
pairDoc[kv.key().c_str()] = kv.value();

// Сериализуем новый JSON документ и печатаем его
String output;
serializeJson(pairDoc, output); // Сериализуем пару в строку
// Serial.println(output);
serializeJson(pairDoc, output);

sendEvent("root_update", eventLen, String(output));
}
Expand Down Expand Up @@ -1691,6 +1620,25 @@ void printLogMsg(String msg)
LOGI("%s", msg.c_str());
}

void progressNvRamFunc(unsigned int progress, unsigned int total)
{

const char *tagESP_FW_progress = "ESP_FW_prgs";
const uint8_t eventLen = 11;

float percent = ((float)progress / total) * 100.0;

sendEvent(tagESP_FW_progress, eventLen, String(percent));
// printLogMsg(String(percent));

#ifdef DEBUG
if (int(percent) % 5 == 0)
{
LOGD("Update ESP32 progress: %s of %s | %s%", String(progress), String(total), String(percent));
}
#endif
};

void progressFunc(unsigned int progress, unsigned int total)
{

Expand Down
9 changes: 8 additions & 1 deletion src/websrc/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1305,11 +1305,18 @@ function updateRootEvents(callback) {
});

source.addEventListener('ZB_FW_prgs', function (e) {
//console.log(val);
//console.log(e.data);
$('#zbFlshPgsTxt').html(i18next.t('md.esp.fu.prgs', { per: e.data }));
$("#zbFlshPrgs").css("width", e.data + '%');
}, false);

source.addEventListener('NV', function (e) {
//console.log(e.data);
let currentContent = $("#console").val();
let newContent = currentContent + "\n" + e.data;
$("#console").val(newContent);
}, false);

source.addEventListener('ZB_FW_info', function (e) {
let data = e.data.replaceAll("`", "<br>");
console.log(data);
Expand Down
3 changes: 2 additions & 1 deletion src/websrc/json/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@
"saf": "Verfügbare Firmwares anzeigen",
"clzv": "Überprüfen Sie die neuesten Zigbee-Firmwares",
"zgu": "Git CC2652-Update",
"sri": "Version auswählen"
"sri": "Version auswählen",
"eznr": "NVRAM löschen"
},
"vp": {
"hn": {
Expand Down
3 changes: 2 additions & 1 deletion src/websrc/json/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@
"saf": "Mostrar firmwares disponibles",
"clzv": "Verifique los últimos firmwares de Zigbee",
"zgu": "Actualización de Git CC2652",
"sri": "Seleccionar versión"
"sri": "Seleccionar versión",
"eznr": "Borrar NVRAM"
},
"vp": {
"hn": {
Expand Down
3 changes: 2 additions & 1 deletion src/websrc/json/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@
"saf": "Afficher les firmwares disponibles",
"clzv": "Vérifiez les derniers firmwares Zigbee",
"zgu": "Mise à jour Git CC2652",
"sri": "Sélectionnez la version"
"sri": "Sélectionnez la version",
"eznr": "Effacer la NVRAM"
},
"vp": {
"hn": {
Expand Down
3 changes: 2 additions & 1 deletion src/websrc/json/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@
"saf": "Mostra i firmware disponibili",
"clzv": "Controlla gli ultimi firmware Zigbee",
"zgu": "Aggiornamento Git CC2652",
"sri": "Seleziona la versione"
"sri": "Seleziona la versione",
"eznr": "Cancella NVRAM"
},
"vp": {
"hn": {
Expand Down
3 changes: 2 additions & 1 deletion src/websrc/json/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@
"saf": "利用可能なファームウェアを表示する",
"clzv": "最新の Zigbee ファームウェアを確認する",
"zgu": "Git CC2652 アップデート",
"sri": "バージョンの選択"
"sri": "バージョンの選択",
"eznr": "NVRAMの消去"
},
"vp": {
"hn": {
Expand Down
3 changes: 2 additions & 1 deletion src/websrc/json/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@
"saf": "Pokaż dostępne oprogramowanie sprzętowe",
"clzv": "Sprawdź najnowsze oprogramowanie sprzętowe Zigbee",
"zgu": "Aktualizacja Gita CC2652",
"sri": "Wybierz wersję"
"sri": "Wybierz wersję",
"eznr": "Wymaż NVRAM"
},
"vp": {
"hn": {
Expand Down
3 changes: 2 additions & 1 deletion src/websrc/json/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@
"saf": "Mostrar firmwares disponíveis",
"clzv": "Verifique os firmwares Zigbee mais recentes",
"zgu": "Atualização do Git CC2652",
"sri": "Selecione a versão"
"sri": "Selecione a versão",
"eznr": "Apagar NVRAM"
},
"vp": {
"hn": {
Expand Down
3 changes: 2 additions & 1 deletion src/websrc/json/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@
"saf": "Показать доступную прошивку",
"clzv": "Проверить последнюю версию прошивки Zigbee",
"zgu": "Обновление Git CC2652",
"sri": "Выберите версию"
"sri": "Выберите версию",
"eznr": "Стереть NVRAM"
},
"vp": {
"hn": {
Expand Down
3 changes: 2 additions & 1 deletion src/websrc/json/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@
"saf": "Mevcut ürün yazılımlarını göster",
"clzv": "En yeni Zigbee yazılımlarını kontrol edin",
"zgu": "Git CC2652 güncellemesi",
"sri": "Sürümü seçin"
"sri": "Sürümü seçin",
"eznr": "NVRAM'ı sil"
},
"vp": {
"hn": {
Expand Down
3 changes: 2 additions & 1 deletion src/websrc/json/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@
"clzv": "Перевірити останню прошивку Zigbee",
"saf": "Показати доступну прошивку",
"zgu": "Оновлення Git CC2652",
"ls": "запуск..."
"ls": "запуск...",
"eznr": "Очистити NVRAM"
},
"lo": {
"pt": "Логін - XZG",
Expand Down
3 changes: 2 additions & 1 deletion src/websrc/json/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@
"saf": "显示可用固件",
"clzv": "检查最新的 Zigbee 固件",
"zgu": "Git CC2652 更新",
"sri": "选择版本"
"sri": "选择版本",
"eznr": "擦除NVRAM"
},
"vp": {
"hn": {
Expand Down
16 changes: 15 additions & 1 deletion src/zb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,24 @@ bool zigbeeErase()
}
return false;
}
void nvPrgs(const String &inputMsg)
{
const char *tagZB_NV_progress = "NV";
const uint8_t eventLen = 30;
String msg = inputMsg;
if (msg.length() > 25)
{
msg = msg.substring(0, 25);
}
sendEvent(tagZB_NV_progress, eventLen, msg);
LOGD("%s", msg.c_str());
}

void zbEraseNV(void *pvParameters)
{
CCTool.nvram_reset(printLogMsg);
CCTool.nvram_reset(nvPrgs);
logClear();
printLogMsg("NVRAM erase finish! Restart CC2652!");
vTaskDelete(NULL);
}

Expand Down
1 change: 1 addition & 0 deletions src/zb.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ bool zbFwCheck();
void zbHwCheck();
bool zbLedToggle();
bool zigbeeErase();
void nvPrgs(const String &inputMsg);
void zbEraseNV(void *pvParameters);
void flashZbUrl(String url);
bool eraseWriteZbUrl(const char *url, std::function<void(float)> progressShow, CCTools &CCTool);
Expand Down

0 comments on commit 92dcdf7

Please sign in to comment.