Skip to content

Commit

Permalink
created Python port for packagebinaries.php to create Tag_FW_Pack.bin
Browse files Browse the repository at this point in the history
  • Loading branch information
nlimper committed Oct 6, 2023
1 parent c586c9f commit c095f4c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ESP32_AP-Flasher/src/contentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ int getJsonTemplateUrl(String &filename, String URL, time_t fetched, String MAC,
void drawJsonStream(Stream &stream, String &filename, tagRecord *&taginfo, imgParam &imageParams) {
TFT_eSprite spr = TFT_eSprite(&tft);
initSprite(spr, imageParams.width, imageParams.height, imageParams);
DynamicJsonDocument doc(300);
DynamicJsonDocument doc(500);
if (stream.find("[")) {
do {
DeserializationError error = deserializeJson(doc, stream);
Expand Down
3 changes: 2 additions & 1 deletion ESP32_AP-Flasher/src/flasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ bool flasher::writeFlashFromPackOffset(fs::File *file, uint16_t length) {
}

bool flasher::writeFlashFromPack(String filename, uint8_t type) {
StaticJsonDocument<512> doc;
DynamicJsonDocument doc(1024);
fs::File readfile = contentFS->open(filename, "r");
DeserializationError err = deserializeJson(doc, readfile);
if (!err) {
Expand All @@ -466,6 +466,7 @@ bool flasher::writeFlashFromPack(String filename, uint8_t type) {
}
Serial.print("Failed to find this tag's type in the FW pack database.\n");
} else {
Serial.println(err.c_str());
Serial.print("Failed to read json header from FW pack\n");
}
readfile.close();
Expand Down
Binary file added binaries/Tag/Tag_FW_Pack.bin
Binary file not shown.
13 changes: 7 additions & 6 deletions zbs243_Tag_FW/packagebinaries.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

$types[0x00] = "Tag_FW_1.54.bin";
$types[0x01] = "Tag_FW_2.9.bin";
$types[0x00] = "SOLUM_154_SSD1619-tag-00-0022.bin";
$types[0x01] = "SOLUM_29_SSD1619-tag-01-0022";
$types[0xF0] = "Tag_FW_Segmented_UK.bin";
$types[0x02] = "Tag_FW_4.2.bin";
$types[0x11] = "Tag_FW_2.9-uc8151.bin";
$types[0x02] = "SOLUM_42_SSD1619-tag-02-0022.bin";
$types[0x11] = "SOLUM_29_UC8151-tag-11-0022.bin";

$binpath = "../binaries/";
$binpath = "../binaries/Tag";
$tocmaxsize = 512;

$toc = array();
Expand All @@ -21,6 +21,7 @@
*/
$version = 0;

// *** fixme: this should select only filenames containing the latest version. See python version of this script.
exec("ls -1 $binpath | grep 'Tag_FW' | grep -v battery | grep -v Pack | grep -v M3", $binaries);
foreach($binaries as $file){
$file = trim($file);
Expand All @@ -30,7 +31,7 @@
$type = $typeid;
}
}
if($type==-1)die("We don't recognize filetype <$file>, sorry...\n");
if($type!=-1)echo("Adding filetype <$file>\n");
$binary = file_get_contents($binpath.$file);
$length = strlen($binary);
$offset = strlen($output);
Expand Down
58 changes: 58 additions & 0 deletions zbs243_Tag_FW/packagebinaries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os
import json

version = "0022" # You can set your desired version here.

types = {
0x00: "SOLUM_154_SSD1619-tag-00-" + version + ".bin",
0x01: "SOLUM_29_SSD1619-tag-01-" + version + ".bin",
0xF0: "Tag_FW_Segmented_UK.bin",
0x02: "SOLUM_42_SSD1619-tag-02-" + version + ".bin",
0x11: "SOLUM_29_UC8151-tag-11-" + version + ".bin",
}

binpath = "../binaries/Tag"
tocmaxsize = 512

toc = []
output = b'\0' * tocmaxsize # Initialize as bytes

binaries = [file for file in os.listdir(binpath) if 'Pack' not in file and version in file]
for file in binaries:
file = file.strip()
type = -1
for typeid, typefile in types.items():
if typefile == file:
type = typeid
if type != -1:
print("Adding filetype <{}>".format(file))
with open(os.path.join(binpath, file), 'rb') as binary_file:
binary = binary_file.read()
length = len(binary)
offset = len(output)
subarr = {
'type': type,
'version': version,
'name': file,
'offset': offset,
'length': length,
}
toc.append(subarr)
output += binary

jtoc = json.dumps(toc)
jtoc = jtoc.replace("'", '"')
tocsize = len(jtoc)
if tocsize > tocmaxsize:
raise ValueError("TOC is too big! (" + str(tocsize) + "). Adjust size and try again")

# Encode jtoc as bytes
jtoc = jtoc.encode('utf-8')

# Concatenate bytes and write to the file
output = jtoc + output[len(jtoc):]
with open(os.path.join(binpath, "Tag_FW_Pack.bin"), 'wb') as output_file:
output_file.write(output)

print(toc)
print("All done.")

0 comments on commit c095f4c

Please sign in to comment.