Skip to content

Commit 56a4036

Browse files
committed
Code rework, cleanup
Zigbee HEX file validation speedup x4.5 (Zigbee flashing still in work) Zigbee file validation progress indication with BSL config in console (Zigbee flashing still in work) Add ability to flash ESP32 OTA from custom URL http://IP_ADDRESS/api?action=8&cmd=9&url=LINK_TO_BIN_FILE.bin Add timezone selection on system control tab (for NTP need for WG and OTA) **Announcement** Cause typofix mqttPublishAvail() in 0.2.5 topic **/avty** will be changed to **/avail** . It you use AutoDiscovery don't keep mind.
1 parent 7ba7a0a commit 56a4036

34 files changed

+1226
-536
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.vscode
44
.gcc-flags.json
55
.clang_complete
6-
commit
6+
commit*
77
test.html
88
gzipped
99
webh

README.md

+9-17
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ This repository contains the latest firmware for the ESP32 peripheral module of
2020
- ESP32 (peripheral) and CC2652P (Zigbee) OTA updates, ESP32 and CC2652P restart;
2121
- Switch CC2652P (Zigbee) to flash mode;
2222
- Pairing mode for the adapter in router mode;
23-
- Firewall for incoming connections to secure your network;
23+
- Filter IP addresses for incoming connections to secure your network;
2424
- Fully responsive web interface based on the latest Bootstrap 5.3.
25+
- WireGuard VPN
26+
- MQTT client for gateway monitoring and control
2527

2628
## Installation and Configuration
2729
Please refer to the installation and configuration articles in our [documentation](https://uzg.zig-star.com).
@@ -31,20 +33,11 @@ Please follow this link for web-flasher - just plug-and-flash: [ZigStar WebFlash
3133

3234
If you made changes to the code and want to compile you own firmware, please do the following:
3335

34-
### You did not change web-interface appearance
3536
- Download repository;
3637
- Install Microsoft Visual Code (MVC);
3738
- Install PlatformIO extension to MVC;
3839
- Press "PlatformIO: Build" and wait until firmware.bin is generated;
3940

40-
### You made changes to web-interface
41-
42-
In such case - you have to rebuild web-interface fisrt before building the firmware.
43-
- Go to the folder tools/webfilesbuilder;
44-
- Run: npm install
45-
- Run: npx gulp
46-
47-
4841
## Contribute
4942

5043
You can contribute to UZG-01 Firmware by
@@ -55,25 +48,24 @@ You can contribute to UZG-01 Firmware by
5548
## Credits
5649

5750
People helping to keep the show on the road - **developers and contributors**:
58-
- [@smlight-dev](https://github.com/smlight-dev/) - for improvement and refactoring of [ZigStarGW-FW](https://github.com/xyzroe/ZigStarGW-FW)
59-
- [@Tarik2142](https://github.com/Tarik2142) for refactoring, code optimizations done under [smlight-dev](https://github.com/mercenaruss/uzg-firmware)
60-
- [@xyzroe](https://github.com/xyzroe/) for initial firmware released for ZigStar devices
51+
52+
- [@xyzroe](https://github.com/xyzroe/) for initial firmware released for ZigStar devices and all work being doing till now
53+
- [@Tarik2142](https://github.com/Tarik2142) for refactoring, code optimizations done under [smlight-dev](https://github.com/smlight-dev/)
54+
6155

6256
Special thanks goes also to all authors of 3rd party libraries which are used in this project:
6357

6458
- [bblanchon / arduinojson](https://github.com/bblanchon/ArduinoJson),
65-
- [esp8266 / arduino](https://github.com/esp8266/Arduino),
6659
- [espressif / arduino-esp32](https://github.com/espressif/arduino-esp32),
6760
- [esprfid / esp-rfid](https://github.com/esprfid/esp-rfid),
6861
- [fairecasoimeme / zigate-ethernet](https://github.com/fairecasoimeme/ZiGate-Ethernet),
6962
- [rlogiacco / circularbuffer](https://github.com/rlogiacco/CircularBuffer),
7063
- [sstaub / ticker](https://github.com/sstaub/Ticker),
71-
- [vurtun / lib](https://github.com/vurtun/lib)
64+
- [vurtun / lib](https://github.com/vurtun/lib),
65+
- [ciniml / WireGuard-ESP32-Arduino] (https://github.com/ciniml/WireGuard-ESP32-Arduino)
7266

7367
## License and attribution
7468

75-
UZG-01-Firmware is a fork of [smlight-dev](https://github.com/mercenaruss/uzg-firmware),what was refactored from our original firmware[ZigStarGW-FW](https://github.com/xyzroe/ZigStarGW-FW)
76-
7769
UZG-01-Firmware is licensed under GNU General Public License v3.
7870
3rd party libraries that are used by this project are licensed under different license schemes, please check them out as well.
7971
Copyright (c) 2023 ZigStar.

bin/UZG-01.bin

29.4 KB
Binary file not shown.

bin/UZG-01_v0.2.3.full.bin

-1.02 MB
Binary file not shown.

bin/UZG-01_v0.2.4.full.bin

1.05 MB
Binary file not shown.

lib/CC26XX/library.properties

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name=CC26XX-ESP32
2+
version=0.0.1
3+
author=xyzroe
4+
maintainer=xyzroe
5+
sentence=TI CC26XX dev tools on ESP32
6+
paragraph=
7+
includes=CC26XX.h
8+
architectures=esp32

lib/CC26XX/src/CC26XX.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ void CommandInterface::_sendNAck()
146146
_stream.write(cmd2);
147147
}
148148

149+
void CommandInterface::_eraseFlash() {
150+
const u_int32_t cmd1 = 0x2C;
151+
_stream.write(cmd1);
152+
}
153+
154+
bool CommandInterface::_ping() {
155+
const u_int32_t cmd1 = 0x20;
156+
_stream.write(cmd1);
157+
return _wait_for_ack(1);
158+
}
159+
149160
byte *CommandInterface::_cmdMemRead(uint32_t address)
150161
{
151162
const u_int32_t cmd = 0x2A;
@@ -355,3 +366,11 @@ String CC26XX_detect::detectChipInfo()
355366
return chip_str;
356367
}
357368

369+
370+
bool CC26XX_detect::eraseFlash()
371+
{
372+
_ping();
373+
_eraseFlash();
374+
375+
return true;
376+
}

lib/CC26XX/src/CC26XX.h

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class CommandInterface
9494
bool _checkLastCmd();
9595
void _sendAck();
9696
void _sendNAck();
97+
void _eraseFlash();
98+
bool _ping();
9799
void _encodeAddr(unsigned long addr, byte encodedAddr[4]);
98100
unsigned long _decodeAddr(byte byte0, byte byte1, byte byte2, byte byte3);
99101
byte _calcChecks(byte cmd, unsigned long addr, unsigned long size);
@@ -110,6 +112,8 @@ class CC26XX_detect : public CommandInterface
110112
public:
111113
CC26XX_detect(Stream &serial);
112114
bool begin(int CC_RST_PIN, int CC_BSL_PIN, int BSL_MODE = 0);
115+
bool eraseFlash();
116+
bool ping();
113117
String detectChipInfo();
114118
};
115119

lib/intelhex/library.properties

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name=IntelHEX-ESP32
2+
version=0.0.2
3+
author="OpenAI's ChatGPT with contributions from xyzroe"
4+
maintainer=xyzroe
5+
sentence=IntelHEX file actions on ESP32
6+
paragraph=
7+
includes=intelhex.h
8+
architectures=esp32

lib/intelhex/src/intelhex.cpp

+147-27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "intelhex.h"
2+
#include <esp_task_wdt.h>
3+
24
/*
35
* IntelHex Arduino Library
46
*
@@ -15,15 +17,8 @@
1517
1618
If you want library to control LittleFS you need to uncomment some lines.
1719
18-
19-
TO-DO List
20-
21-
1. Line length check
22-
2. Error if not IntelHEX line after start till end
23-
2420
*/
2521

26-
2722
#ifndef DEBUG_PRINT
2823
#ifdef DEBUG
2924
#define DEBUG_PRINT(x) Serial.print(String(x))
@@ -34,9 +29,6 @@ TO-DO List
3429
#endif
3530
#endif
3631

37-
38-
39-
4032
IntelHex::IntelHex(const char *filename) : _filename(filename) {}
4133

4234
IntelHex::~IntelHex()
@@ -63,13 +55,16 @@ void IntelHex::close()
6355
// LittleFS.end();
6456
}
6557

66-
bool IntelHex::parse(void (*preCallback)(), void (*parseCallback)(uint32_t address, uint8_t len, uint8_t *data), void (*postCallback)())
58+
bool IntelHex::parse(void (*preCallback)(), void (*parseCallback)(uint32_t address, uint8_t len, uint8_t *data, size_t currentPosition, size_t totalSize), void (*postCallback)())
6759
{
6860
if (!open())
6961
{
7062
return false;
7163
}
7264

65+
_totalSize = _file.size();
66+
DEBUG_PRINTLN(String("_file.size() = ") + String(_totalSize));
67+
7368
preCallback();
7469

7570
bool status = true;
@@ -96,8 +91,115 @@ bool IntelHex::parse(void (*preCallback)(), void (*parseCallback)(uint32_t addre
9691
return status;
9792
}
9893

99-
bool IntelHex::_munchLine(void (*parseCallback)(uint32_t address, uint8_t len, uint8_t *data))
94+
/*
95+
bool IntelHex::validateChecksum()
96+
{
97+
DEBUG_PRINTLN("Starting checksum validation");
98+
99+
if (!open())
100+
{
101+
DEBUG_PRINTLN("Failed to open file");
102+
return false;
103+
}
104+
105+
String line;
106+
while (_file.available())
107+
{
108+
line = _file.readStringUntil('\n');
109+
line.trim();
110+
111+
if (line.length() < 11 || line[0] != ':')
112+
{
113+
DEBUG_PRINTLN("Skipping non-data line or line too short");
114+
continue;
115+
}
116+
117+
// Проверяем на строку окончания файла Intel HEX
118+
if (line == ":00000001FF")
119+
{
120+
DEBUG_PRINTLN("Intel HEX file end line found, checksum validation passed");
121+
close();
122+
return true;
123+
}
124+
125+
uint8_t sum = 0;
126+
// Считаем сумму всех байтов строки, за исключением начального ':'
127+
for (int i = 1; i < line.length(); i += 2)
128+
{
129+
uint8_t byteValue = strtol(line.substring(i, i + 2).c_str(), nullptr, 16);
130+
sum += byteValue;
131+
}
132+
133+
// Проверка контрольной суммы
134+
if (sum != 0)
135+
{
136+
DEBUG_PRINTLN("Checksum validation failed");
137+
close();
138+
return false;
139+
}
140+
}
141+
142+
DEBUG_PRINTLN("Checksum validation passed, but no end line found - file might be incomplete");
143+
close();
144+
return false; // Если мы достигли этой точки, значит, строка окончания файла не была найдена.
145+
}
146+
*/
147+
148+
/*
149+
bool IntelHex::checkBSLConfiguration() {
150+
DEBUG_PRINTLN("checkBSLConfiguration: Starting BSL configuration check");
151+
152+
if (!open()) {
153+
DEBUG_PRINTLN("checkBSLConfiguration: Failed to open file");
154+
return false;
155+
}
156+
157+
const uint32_t addresses[] = {ALL_CHIP_ADDRESS, P7_CHIP_ADDRESS};
158+
bool foundBSL = false;
159+
160+
for (auto address : addresses) {
161+
DEBUG_PRINT("checkBSLConfiguration: Checking address: ");
162+
DEBUG_PRINTLN(String(address, HEX));
163+
164+
// Предполагаем, что BSL конфигурация начинается непосредственно с этого адреса.
165+
// Важно отметить, что в файле Intel Hex адреса не обязательно идут последовательно и могут быть разбросаны.
166+
// Это может потребовать специфической логики для перемещения по файлу.
167+
168+
// Чтение данных из файла, предполагая, что они могут находиться по этому адресу.
169+
_file.seek(address, SeekSet);
170+
uint8_t data[4]; // Предполагаем, что для проверки BSL конфигурации достаточно 4 байтов.
171+
if (_file.read(data, 4) != 4) {
172+
DEBUG_PRINTLN("checkBSLConfiguration: Failed to read data");
173+
continue; // Если не удается прочитать 4 байта, переходим к следующему адресу.
174+
}
175+
176+
// Добавляем логирование прочитанных данных, чтобы увидеть, что было считано.
177+
DEBUG_PRINT("checkBSLConfiguration: Read data: ");
178+
for (int i = 0; i < 4; ++i) {
179+
DEBUG_PRINT(String(data[i], HEX));
180+
DEBUG_PRINT(" ");
181+
}
182+
DEBUG_PRINTLN();
183+
184+
foundBSL = _checkBSLconfig(address, 4, data);
185+
if (foundBSL) {
186+
DEBUG_PRINTLN("checkBSLConfiguration: BSL configuration found and valid");
187+
break; // Если нашли и проверили конфигурацию BSL, прерываем цикл.
188+
}
189+
}
190+
191+
if (!foundBSL) {
192+
DEBUG_PRINTLN("checkBSLConfiguration: BSL configuration not found or invalid");
193+
}
194+
195+
close();
196+
return foundBSL;
197+
}
198+
*/
199+
200+
bool IntelHex::_munchLine(void (*parseCallback)(uint32_t address, uint8_t len, uint8_t *data, size_t currentPosition, size_t totalSize))
100201
{
202+
101203
String line = _file.readStringUntil('\n');
102204
line.trim();
103205

@@ -135,11 +237,6 @@ bool IntelHex::_munchLine(void (*parseCallback)(uint32_t address, uint8_t len, u
135237
// DEBUG_PRINTLN("Record Type: " + String(recordType, HEX) + ", Offset Low: " + String(offset_low, HEX) + ", Length: " + String(len, HEX)); // Print record info
136238

137239
uint8_t data[255];
138-
for (uint8_t i = 0; i < len; i++)
139-
{
140-
data[i] = strtol(line.substring(9 + i * 2, 11 + i * 2).c_str(), nullptr, 16);
141-
}
142-
143240
uint32_t address = offset_low;
144241
// https://jimmywongiot.com/2021/04/20/format-of-intelhex/
145242
if (recordType == 4)
@@ -153,28 +250,51 @@ bool IntelHex::_munchLine(void (*parseCallback)(uint32_t address, uint8_t len, u
153250

154251
address += _offset_high;
155252

156-
if (!_bsl_valid)
253+
esp_task_wdt_reset();
254+
//#ifdef DEBUG
255+
// delay(5); // to avoid reboot
256+
//#endif
257+
258+
for (int i = 0; i < ELEMENTCOUNT(CCFG_ADDRESS); i++)
157259
{
158-
_bsl_valid = _checkBSLconfig(address, len, data);
260+
// DEBUG_PRINT(CCFG_ADDRESS[i]);
261+
// DEBUG_PRINT(" ");
262+
if (address <= CCFG_ADDRESS[i] && address + len > CCFG_ADDRESS[i] + 4)
263+
{
264+
//DEBUG_PRINTLN(" ");
265+
//DEBUG_PRINTLN("CCFG_ADDRESS[" + String(i) + "] in range");
266+
267+
268+
for (uint8_t i = 0; i < len; i++)
269+
{
270+
data[i] = strtol(line.substring(9 + i * 2, 11 + i * 2).c_str(), nullptr, 16);
271+
}
272+
273+
if (!_bsl_valid)
274+
{
275+
_bsl_valid = _checkBSLconfig(address, len, data);
276+
}
277+
}
159278
}
160-
parseCallback(address, len, data);
279+
280+
size_t currentPosition = _file.position();
281+
282+
parseCallback(address, len, data, currentPosition, _totalSize);
161283

162284
return true;
163285
}
164286

165287
bool IntelHex::_checkBSLconfig(uint32_t address, uint8_t len, uint8_t *data)
166288
{
167289
// Check if CCFG is within the buffer
168-
//DEBUG_PRINTLN(" ");
169-
//DEBUG_PRINT(ELEMENTCOUNT(CCFG_ADDRESS));
170-
//DEBUG_PRINT(" ");
290+
// DEBUG_PRINTLN(" ");
291+
// DEBUG_PRINT(ELEMENTCOUNT(CCFG_ADDRESS));
292+
// DEBUG_PRINT(" ");
171293

172-
// DEBUG_PRINTLN(ESP.getFreeHeap() / 1024);
173-
delay(5);
174294
for (int i = 0; i < ELEMENTCOUNT(CCFG_ADDRESS); i++)
175295
{
176-
//DEBUG_PRINT(CCFG_ADDRESS[i]);
177-
//DEBUG_PRINT(" ");
296+
// DEBUG_PRINT(CCFG_ADDRESS[i]);
297+
// DEBUG_PRINT(" ");
178298
if (address <= CCFG_ADDRESS[i] && address + len > CCFG_ADDRESS[i] + 4)
179299
{
180300
DEBUG_PRINTLN(" ");

0 commit comments

Comments
 (0)