Created
December 2, 2015 16:57
-
-
Save goebish/e6a486a87fba5a233c56 to your computer and use it in GitHub Desktop.
A7105 decoder
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
#!/usr/bin/env python | |
reg_map = { | |
0x00 : "00_MODE", | |
0x01 : "01_MODE_CONTROL", | |
0x02 : "02_CALC", | |
0x03 : "03_FIFOI", | |
0x04 : "04_FIFOII", | |
0x05 : "05_FIFO_DATA", | |
0x06 : "06_ID_DATA", | |
0x07 : "07_RC_OSC_I", | |
0x08 : "08_RC_OSC_II", | |
0x09 : "09_RC_OSC_III", | |
0x0A : "0A_CK0_PIN", | |
0x0B : "0B_GPIO1_PIN1", | |
0x0C : "0C_GPIO2_PIN_II", | |
0x0D : "0D_CLOCK", | |
0x0E : "0E_DATA_RATE", | |
0x0F : "0F_PLL_I", | |
0x10 : "10_PLL_II", | |
0x11 : "11_PLL_III", | |
0x12 : "12_PLL_IV", | |
0x13 : "13_PLL_V", | |
0x14 : "14_TX_I", | |
0x15 : "15_TX_II", | |
0x16 : "16_DELAY_I", | |
0x17 : "17_DELAY_II", | |
0x18 : "18_RX", | |
0x19 : "19_RX_GAIN_I", | |
0x1A : "1A_RX_GAIN_II", | |
0x1B : "1B_RX_GAIN_III", | |
0x1C : "1C_RX_GAIN_IV", | |
0x1D : "1D_RSSI_THOLD", | |
0x1E : "1E_ADC", | |
0x1F : "1F_CODE_I", | |
0x20 : "20_CODE_II", | |
0x21 : "21_CODE_III", | |
0x22 : "22_IF_CALIB_I", | |
0x23 : "23_IF_CALIB_II", | |
0x24 : "24_VCO_CURCAL", | |
0x25 : "25_VCO_SBCAL_I", | |
0x26 : "26_VCO_SBCAL_II", | |
0x27 : "27_BATTERY_DET", | |
0x28 : "28_TX_TEST", | |
0x29 : "29_RX_DEM_TEST_I", | |
0x2A : "2A_RX_DEM_TEST_I", | |
0x2B : "2B_CPC", | |
0x2C : "2C_XTAL_TEST", | |
0x2D : "2D_PLL_TEST", | |
0x2E : "2E_VCO_TEST_I", | |
0x2F : "2F_VCO_TEST_II", | |
0x30 : "30_IFAT", | |
0x31 : "31_RSCALE", | |
0x32 : "32_FILTER_TEST" | |
} | |
command_map = { | |
0x80 : "80_SLEEP", | |
0x90 : "90_IDLE", | |
0xA0 : "A0_STANDBY", | |
0xB0 : "B0_PLL", | |
0xC0 : "C0_RX", | |
0xD0 : "D0_TX", | |
0xE0 : "E0_RST_WRPTR", | |
0xF0 : "F0_RST_RDPTR" | |
} | |
def register_name(reg): | |
def_name = "%02X" % reg | |
return reg_map.get(reg, def_name) | |
def command_name(command): | |
def_name = "%02X" % command | |
return command_map.get(command, def_name) | |
def dump_command(packet_id, command, status, data): | |
if packet_id == -1: return | |
mnemonic = "UNKNOWN" | |
if (command & 0xc0) == 0x40: | |
mnemonic = "R_REGISTER(%s) " % register_name(command & ~0x40) | |
mnemonic += " ".join(map(lambda x: "%02X" % x, data)) | |
elif (command & 0xc0) == 0: | |
mnemonic = "W_REGISTER(%s) " % register_name(command) | |
mnemonic += " ".join(map(lambda x: "%02X" % x, data)) | |
elif (command >= 0x80) and ((command & 0x0f) == 0) : | |
mnemonic = "COMMAND(%s)" % command_name(command) | |
print packet_id, mnemonic | |
def process_file(f): | |
packet_id = -1 | |
# SPI exchange parameters | |
command = -1 | |
status = -1 | |
data = [] | |
count = 0 | |
for line in f: | |
line = line.strip() | |
if len(line) == 0 or line[0] == '#': continue | |
parts = line.split(',') | |
if len(parts) != 4 or parts[1] == 'Packet ID' or parts[1] == '': continue | |
if packet_id != int(parts[1]): | |
dump_command(packet_id, command, status, data) | |
command = int(parts[2], 16) | |
status = int(parts[3], 16) | |
packet_id = int(parts[1]) | |
data = [] | |
else: | |
data.append(int(parts[2], 16)) | |
dump_command(packet_id, command, status, data) | |
def main(argv): | |
for fn in argv: | |
f = file(fn) | |
process_file(f) | |
if __name__ == '__main__': | |
import sys | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment