-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #695 from ain101/develop
update mch2022 tools
- Loading branch information
Showing
33 changed files
with
1,835 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/resources/plugins/MCH22BToolchain/mch2022-tools/app_list.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python3 | ||
from webusb import * | ||
import argparse | ||
import sys | ||
import time | ||
|
||
def listapps(): | ||
applist = badge.app_list() | ||
if not applist == None: | ||
print("\x1b[4m{: <48}\x1b[0m \x1b[4m{: <64}\x1b[0m \x1b[4m{: <8}\x1b[0m \x1b[4m{: <10}\x1b[0m".format("Name", "Title", "Version", "Size")) | ||
for app in applist: | ||
size = str(app["size"]) + " B" | ||
if app["size"] > 1024: | ||
size = str(round(app["size"] / 1024, 2)) + " KB" | ||
print("{: <48} {: <64} {: <8} {: <10}".format(app["name"].decode("ascii", errors="ignore"), app["title"].decode("ascii", errors="ignore"), str(app["version"]), size)) | ||
else: | ||
print(location.decode("ascii") + " ** Failed to load application list **") | ||
|
||
parser = argparse.ArgumentParser(description='MCH2022 badge application list tool') | ||
args = parser.parse_args() | ||
|
||
badge = Badge() | ||
|
||
if not badge.begin(): | ||
print("Failed to connect") | ||
sys.exit(1) | ||
|
||
listapps() |
31 changes: 31 additions & 0 deletions
31
app/resources/plugins/MCH22BToolchain/mch2022-tools/app_pull.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from webusb import * | ||
import argparse | ||
import sys | ||
import time | ||
|
||
parser = argparse.ArgumentParser(description='MCH2022 badge app download tool') | ||
parser.add_argument("name", help="Remote app") | ||
parser.add_argument("target", help="Local file") | ||
args = parser.parse_args() | ||
|
||
name = args.name | ||
target = args.target | ||
|
||
badge = Badge() | ||
|
||
if not badge.begin(): | ||
print("Failed to connect") | ||
sys.exit(1) | ||
|
||
result = badge.app_read(name.encode("ascii", "ignore")) | ||
|
||
if result: | ||
with open(target, "wb") as f: | ||
f.write(result) | ||
f.truncate(len(result)) | ||
print("App downloaded succesfully") | ||
else: | ||
print("Failed to download app") | ||
sys.exit(1) |
47 changes: 47 additions & 0 deletions
47
app/resources/plugins/MCH22BToolchain/mch2022-tools/app_push.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from webusb import * | ||
import argparse | ||
import sys | ||
import time | ||
|
||
parser = argparse.ArgumentParser(description='MCH2022 badge app upload tool') | ||
parser.add_argument("file", help="Application binary") | ||
parser.add_argument("name", help="Application name") | ||
parser.add_argument("title", help="Application title") | ||
parser.add_argument("version", type=int, help="Application version") | ||
parser.add_argument('--run', '-r', '-R', action='store_true', help="Run application after uploading") | ||
args = parser.parse_args() | ||
|
||
name = args.name.encode("ascii", "ignore") | ||
title = args.title.encode("ascii", "ignore") | ||
version = args.version | ||
if version < 0: | ||
version = 0 | ||
|
||
with open(args.file, "rb") as f: | ||
data = f.read() | ||
|
||
badge = Badge() | ||
|
||
if not badge.begin(): | ||
print("Failed to connect") | ||
sys.exit(1) | ||
|
||
result = badge.app_write(name, title, version, data) | ||
|
||
if result: | ||
print("App installed succesfully") | ||
else: | ||
print("Failed to install app") | ||
sys.exit(1) | ||
|
||
if args.run: | ||
result = badge.app_run(name) | ||
|
||
if result: | ||
badge.reset(False) | ||
print("Started") | ||
else: | ||
print("Failed to start") | ||
sys.exit(1) |
26 changes: 26 additions & 0 deletions
26
app/resources/plugins/MCH22BToolchain/mch2022-tools/app_remove.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from webusb import * | ||
import argparse | ||
import sys | ||
import time | ||
|
||
parser = argparse.ArgumentParser(description='MCH2022 badge app removal tool') | ||
parser.add_argument("name", help="Name of app to be removed") | ||
args = parser.parse_args() | ||
|
||
name = args.name | ||
|
||
badge = Badge() | ||
|
||
if not badge.begin(): | ||
print("Failed to connect") | ||
sys.exit(1) | ||
|
||
result = badge.app_remove(name.encode('ascii', "ignore")) | ||
|
||
if result: | ||
print("Removed") | ||
else: | ||
print("Failed to remove") | ||
sys.exit(1) |
29 changes: 29 additions & 0 deletions
29
app/resources/plugins/MCH22BToolchain/mch2022-tools/app_run.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from webusb import * | ||
import argparse | ||
import sys | ||
import time | ||
|
||
parser = argparse.ArgumentParser(description='MCH2022 badge app run tool') | ||
parser.add_argument("name", help="Name of app to be started") | ||
parser.add_argument("--command", "-c", help="String to be stored in memory", required=False) | ||
args = parser.parse_args() | ||
|
||
name = args.name | ||
command = args.command | ||
|
||
badge = Badge() | ||
|
||
if not badge.begin(): | ||
print("Failed to connect") | ||
sys.exit(1) | ||
|
||
result = badge.app_run(name.encode('ascii', "ignore"), command.encode('ascii', "ignore") if command else None) | ||
|
||
if result: | ||
badge.reset(False) | ||
print("Started") | ||
else: | ||
print("Failed to start") | ||
sys.exit(1) |
32 changes: 32 additions & 0 deletions
32
app/resources/plugins/MCH22BToolchain/mch2022-tools/configuration_list.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python3 | ||
from webusb import * | ||
import argparse | ||
import sys | ||
import time | ||
|
||
parser = argparse.ArgumentParser(description='MCH2022 badge NVS list tool') | ||
parser.add_argument("namespace", help="Namespace", nargs='?', default=None) | ||
args = parser.parse_args() | ||
|
||
badge = Badge() | ||
|
||
if not badge.begin(): | ||
print("Failed to connect") | ||
sys.exit(1) | ||
|
||
print("\x1b[4m{: <32}\x1b[0m \x1b[4m{: <32}\x1b[0m \x1b[4m{: <8}\x1b[0m \x1b[4m{: <10}\x1b[0m \x1b[4m{: <32}\x1b[0m".format("Namespace", "Key", "Type", "Size", "Value")) | ||
badge.printGarbage = True | ||
if args.namespace: | ||
entries = badge.nvs_list(args.namespace) | ||
else: | ||
entries = badge.nvs_list() | ||
|
||
if not entries: | ||
print("Failed to read data") | ||
else: | ||
for namespace in entries: | ||
for entry in entries[namespace]: | ||
value = "(skipped)" | ||
if entry["size"] < 64 and badge.nvs_should_read(entry["type"]): | ||
value = str(badge.nvs_read(namespace, entry["key"], entry["type"])) | ||
print("{: <32} {: <32} {: <8} {:10d} {}".format(namespace, entry["key"], badge.nvs_type_to_name(entry["type"]), entry["size"], value)) |
28 changes: 28 additions & 0 deletions
28
app/resources/plugins/MCH22BToolchain/mch2022-tools/configuration_read.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python3 | ||
from webusb import * | ||
import argparse | ||
import sys | ||
import time | ||
import sys | ||
|
||
parser = argparse.ArgumentParser(description='MCH2022 badge NVS read tool') | ||
parser.add_argument("namespace", help="Namespace") | ||
parser.add_argument("key", help="Key") | ||
parser.add_argument("type", help="Type, one of u8, i8, u16, i16, u32, i32, u64, i64, string or blob") | ||
args = parser.parse_args() | ||
|
||
badge = Badge() | ||
|
||
type_name = args.type.lower() | ||
type_number = badge.nvs_name_to_type(type_name) | ||
|
||
if not badge.begin(): | ||
print("Failed to connect") | ||
sys.exit(1) | ||
|
||
value = badge.nvs_read(args.namespace, args.key, type_number) | ||
|
||
if type_name == "blob": | ||
sys.stdout.buffer.write(value) | ||
else: | ||
print(value) |
25 changes: 25 additions & 0 deletions
25
app/resources/plugins/MCH22BToolchain/mch2022-tools/configuration_remove.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env python3 | ||
from webusb import * | ||
import argparse | ||
import sys | ||
import time | ||
import sys | ||
|
||
parser = argparse.ArgumentParser(description='MCH2022 badge NVS remove tool') | ||
parser.add_argument("namespace", help="Namespace") | ||
parser.add_argument("key", help="Key") | ||
args = parser.parse_args() | ||
|
||
badge = Badge() | ||
|
||
if not badge.begin(): | ||
print("Failed to connect") | ||
sys.exit(1) | ||
|
||
result = badge.nvs_remove(args.namespace, args.key) | ||
|
||
if result: | ||
print("Entry removed") | ||
else: | ||
print("Failed to remove entry") | ||
sys.exit(1) |
Oops, something went wrong.