feat: initial commit
This commit is contained in:
commit
272cfd47e3
5 changed files with 167 additions and 0 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
@ -0,0 +1 @@
|
|||
use flake
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
.direnv/
|
80
big-sign.py
Normal file
80
big-sign.py
Normal file
|
@ -0,0 +1,80 @@
|
|||
import serial
|
||||
import sys
|
||||
import time
|
||||
|
||||
PACKET_HEADER = b'\0\0\0\0\0\x01'
|
||||
SIGN_TYPE = b'Z'
|
||||
SIGN_ADDRESS = b'00'
|
||||
VALID_NAMES = b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
|
||||
def encode_packet(command_code, data):
|
||||
return PACKET_HEADER + SIGN_TYPE + SIGN_ADDRESS + b'\x02' + command_code + data + b'\x04'
|
||||
|
||||
def generate_memory_config(files: list[tuple[bytes, int]]):
|
||||
data = b'$'
|
||||
for name, size in files:
|
||||
if len(name) != 1:
|
||||
raise ValueError()
|
||||
if name not in VALID_NAMES:
|
||||
raise ValueError()
|
||||
data += name
|
||||
data += b'AU'
|
||||
data += hex(size).upper()[2:].encode().rjust(4, b'0')
|
||||
# data += b'00FF'
|
||||
data += b'FFFF'
|
||||
return encode_packet(b'E', data)
|
||||
|
||||
def generate_run_order(files: list[bytes]):
|
||||
data = b'.TU'
|
||||
for name in files:
|
||||
if len(name) != 1:
|
||||
raise ValueError()
|
||||
if name not in VALID_NAMES:
|
||||
raise ValueError()
|
||||
data += name
|
||||
return encode_packet(b'E', data)
|
||||
|
||||
def generate_write_text_file(name: bytes, content: bytes):
|
||||
return encode_packet(b'A', name + content)
|
||||
|
||||
def main(args: list[str]):
|
||||
if len(args) < 3:
|
||||
print(f'Usage: {args[0]} <file> <serial>')
|
||||
exit(1)
|
||||
file_name = args[1]
|
||||
serial_port = args[2]
|
||||
with open(file_name) as f:
|
||||
lines = f.readlines()
|
||||
if len(lines) > len(VALID_NAMES):
|
||||
print('Too many lines! I dont have enough files!')
|
||||
exit(1)
|
||||
|
||||
run_order = []
|
||||
files = []
|
||||
text_packets = []
|
||||
|
||||
for file_name, line in zip(VALID_NAMES, lines):
|
||||
file_name = bytes([file_name])
|
||||
data = line.strip().encode()
|
||||
length = len(data)
|
||||
run_order.append(file_name)
|
||||
files.append((file_name, length))
|
||||
text_packets.append(generate_write_text_file(file_name, data))
|
||||
|
||||
with serial.Serial(serial_port, 9600) as ser:
|
||||
print('Config memory')
|
||||
ser.write(generate_memory_config(files))
|
||||
print('+', generate_memory_config(files).hex())
|
||||
time.sleep(1)
|
||||
print('Send files')
|
||||
for tp in text_packets:
|
||||
ser.write(tp)
|
||||
print('+', tp.hex())
|
||||
time.sleep(1)
|
||||
print('Send run order')
|
||||
ser.write(generate_run_order(run_order))
|
||||
print('+', generate_run_order(run_order).hex())
|
||||
print('Done!')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv)
|
61
flake.lock
Normal file
61
flake.lock
Normal file
|
@ -0,0 +1,61 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1694529238,
|
||||
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1696261572,
|
||||
"narHash": "sha256-s8TtSYJ1LBpuITXjbPLUPyxzAKw35LhETcajJjCS5f0=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "0c7ffbc66e6d78c50c38e717ec91a2a14e0622fb",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
24
flake.nix
Normal file
24
flake.nix
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = github:NixOS/nixpkgs/nixpkgs-unstable;
|
||||
flake-utils.url = github:numtide/flake-utils;
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
};
|
||||
dependencies= ps: with ps; [
|
||||
pyserial
|
||||
];
|
||||
in
|
||||
{
|
||||
devShells.default = pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [
|
||||
(python311.withPackages dependencies)
|
||||
];
|
||||
};
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue