From f20539bf17d3de8e0ab56d834f665eeea4813988 Mon Sep 17 00:00:00 2001 From: Robin Krens Date: Sun, 11 Feb 2024 14:31:50 +0100 Subject: [PATCH] RAPacker: minor directory restructering --- src/Packer.py | 143 ---------------------------------------------------- src/RAFlasher.py | 2 +- src/RAPacker.py | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/test_parse.py | 2 +- 4 files changed, 145 insertions(+), 145 deletions(-) delete mode 100644 src/Packer.py create mode 100644 src/RAPacker.py diff --git a/src/Packer.py b/src/Packer.py deleted file mode 100644 index 8480267..0000000 --- a/src/Packer.py +++ /dev/null @@ -1,143 +0,0 @@ -# Copyright (C) Robin Krens - 2024 -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# - -import struct - -# Commands send to boot firmware -INQ_CMD = 0x00 -ERA_CMD = 0x12 -WRI_CMD = 0x13 -REA_CMD = 0x15 -IDA_CMD = 0x30 -BAU_CMD = 0x34 -SIG_CMD = 0x3A -ARE_CMD = 0x3B - -# These are combined with send command, for example -# STATUS_OK | ERA_CMD == 0x12 -# STATUS_ERR | ERA_CMD = 0x92 -STATUS_OK = 0x00 -STATUS_ERR = 0x80 - -# Error codes -error_codes = { - 0xC: "ERR_UNSU", - 0xC1: "ERR_PCKT", - 0xC2: "ERR_CHKS", - 0xC3: "ERR_FLOW", - 0xD0: "ERR_ADDR", - 0xD4: "ERR_BAUD", - 0xDA: "ERR_PROT", - 0xDB: "ERR_ID", - 0xDC: "ERR_SERI", - 0xE1: "ERR_ERA", - 0xE2: "ERR_WRI", - 0xE7: "ERR_SEQ" -} - -# used for init sequence -LOW_PULSE = 0x00 -GENERIC_CODE = 0x55 -BOOT_CODE = 0xC3 - -TESTID = [ - "0xF0", "0xF1", "0xF2", "0xF3", - "0xE4", "0xE5", "0xE6", "0xE7", - "0xD8", "0xD9", "0xDA", "0xDB", - "0xCC", "0xCD", "0xCE", "0xCF" -] - -def calc_sum(cmd, data): - data_len = len(data) - lnh = data_len + 1 & 0xFF00 - lnl = data_len + 1 & 0x00FF - res = lnh + lnl + cmd - for i in range(data_len): - if isinstance(data[i], str): - res += int(data[i], 16) - elif isinstance(data[i], int): - res += data[i] - else: - res += ord(data[i]) - res = ~(res - 1) & 0xFF # two's complement - return (lnh, lnl, res) - - -# format of data packet is [SOD|LNH|LNL|COM|byte_data|SUM|ETX] -def pack_command(cmd, data): - SOD = 0x01 - COM = cmd - - if isinstance(data, str): - byte_data = bytes(data.encode('utf-8')) - else: - byte_data = bytes([int(x, 16) for x in data]) - - LNH, LNL, SUM = calc_sum(int(cmd), data) - ETX = 0x03 - fmt_header = '= 1024): - raise Exception(f'Data packet too large, data length is {DATA_LEN} (>1024)') - LNH, LNL, SUM = calc_sum(int(res), data) - if not isinstance(data, bytes): - DAT = bytes([int(x, 16) for x in data]) - else: - DAT = data - RES = res - ETX = 0x03 - fmt_header = '= 1024): + raise Exception(f'Data packet too large, data length is {DATA_LEN} (>1024)') + LNH, LNL, SUM = calc_sum(int(res), data) + if not isinstance(data, bytes): + DAT = bytes([int(x, 16) for x in data]) + else: + DAT = data + RES = res + ETX = 0x03 + fmt_header = '