forked from M-Labs/humpback-dds
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
import argparse
|
|
import struct
|
|
|
|
|
|
def get_argparser():
|
|
parser = argparse.ArgumentParser(description="MQTT-controlled 4-channel DDS signal generator")
|
|
|
|
parser.add_argument("cidr", nargs=1,
|
|
metavar=("Client_CIDR"),
|
|
help="IPv4 Address of Humpback-DDS in CIDR notation")
|
|
parser.add_argument("mac_addr", nargs=1,
|
|
metavar=("Client_MAC"),
|
|
help="MAC Address of Humpback-DDS")
|
|
parser.add_argument("broker_ip", nargs=1,
|
|
metavar=("Broker_IP"),
|
|
help="IP address of MQTT broker")
|
|
parser.add_argument("name", nargs=1,
|
|
metavar=("Name"),
|
|
help="Device name of Humpback-DDS")
|
|
|
|
return parser
|
|
|
|
|
|
def write_record(f, key, value):
|
|
key_size = len(key) + 1
|
|
value_size = len(value)
|
|
record_size = key_size + value_size + 4
|
|
f.write(struct.pack(">l", record_size))
|
|
f.write(key.encode())
|
|
f.write(b"\x00")
|
|
f.write(value)
|
|
|
|
|
|
def write_end_marker(f):
|
|
f.write(b"\xff\xff\xff\xff")
|
|
|
|
|
|
def main():
|
|
args = get_argparser().parse_args()
|
|
with open("flash_config.bin", "wb") as fo:
|
|
write_record(fo, "CIDR", args.cidr[0].encode())
|
|
write_record(fo, "MAC", args.mac_addr[0].encode())
|
|
write_record(fo, "BrokerIP", args.broker_ip[0].encode())
|
|
write_record(fo, "Name", args.name[0].encode())
|
|
write_end_marker(fo)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |