|
| 1 | +import sys, getopt |
| 2 | +from galileo_has_decoder import conv |
| 3 | +from galileo_has_decoder.utils import bidict |
| 4 | +optDict = bidict({"s":"source", "t":"target", "f":"outFormat", "i":"modeIn", "o":"modeOut", "p":"port", "b":"baudrate", "v":"verbose", "m":"mute", "h":"help"}) |
| 5 | + |
| 6 | +def printHelp(): |
| 7 | + print("The HAS_Decoder.py offers easy access to most of the functionalities of the Galileo HAS Decoder. Below, available arguments are presented. For more options, please refer to the library documentation.\n") |
| 8 | + print("Usage: python3 HAS_Decoder.py -s SOURCE -t TARGET -f OUTFORMAT [-i MODEIN -o MODEOUT -p PORT -b BAUDRATE -x MESSAGES -v VERBOSELEVEL --skip SKIPPERCENT --mute]\n") |
| 9 | + print("-s arg : Source stream to decode messages from") |
| 10 | + print("-t arg : Target stream to decode messages to") |
| 11 | + print("-f opt : Format to convert HAS messages to. Options are [1:IGS, 2:RTCM3]") |
| 12 | + print("-i opt : Input mode, specifying the type of input stream. Options are :", |
| 13 | + "\n [1:SBF File, 2:BINEX File, 3:SBF Serial, 4:BINEX Serial, 5:SBF TCP, 6:BINEX TCP]") |
| 14 | + print("-o opt : Output mode, specifying the type of output stream. Options are:", |
| 15 | + "\n [1:TCP, 2:File, 3:PPPWiz File, 4:PPPWiz Stream]") |
| 16 | + print("-p arg : Optional for TCP output. If not set, uses port 6947") |
| 17 | + print("-b arg : Optional for serial input, specifying the baudrate of the stream. If not set, uses 115200") |
| 18 | + print("-v arg : Optional, specifying the verbose level for the process") |
| 19 | + print("-m : Optional, used to mute verbose-independent messages") |
| 20 | + print("-h : Displaying this help message") |
| 21 | + print("--source arg : Source stream to decode messages from") |
| 22 | + print("--target arg : Target stream to decode messages to") |
| 23 | + print("--outFormat opt : Format to convert HAS messages to. Options are [1:IGS, 2:RTCM3]") |
| 24 | + print("--modeIn opt : Input mode, specifying the type of input stream. Options are :", |
| 25 | + "\n [1:SBF File, 2:BINEX File, 3:SBF Serial, 4:BINEX Serial, 5:SBF TCP, 6:BINEX TCP]") |
| 26 | + print("--modeOut opt : Output mode, specifying the type of output stream. Options are:", |
| 27 | + "\n [1:TCP, 2:File, 3:PPPWiz File, 4:PPPWiz Stream]") |
| 28 | + print("--port arg : Optional for TCP output. If not set, uses port 6947") |
| 29 | + print("--baudrate arg : Optional for serial input, specifying the baudrate of the stream. If not set, uses 115200") |
| 30 | + print("--skip arg : Optional, used to skip some initial portion of a read file.") |
| 31 | + print("--verbose arg : Optional, specifying the verbose level for the process") |
| 32 | + print("--mute : Optional, used to mute verbose-independent messages") |
| 33 | + print("--help : Displaying this help message") |
| 34 | + exit() |
| 35 | + |
| 36 | +try: |
| 37 | + options, remainder = getopt.getopt(sys.argv[1:], 's:t:f:i:o:p:b:x:v:hm:mm:', ['source=', |
| 38 | + 'target=', |
| 39 | + 'outFormat=', |
| 40 | + 'modeIn=', |
| 41 | + 'modeOut=', |
| 42 | + 'port=', |
| 43 | + 'baudrate=', |
| 44 | + 'verbose=', |
| 45 | + 'skip=', |
| 46 | + 'help', |
| 47 | + 'mute', |
| 48 | + ]) |
| 49 | +except getopt.GetoptError: |
| 50 | + raise Exception("Options not recognized. Correct usage:\nHAS_Decoder.py -s SOURCE -t TARGET -f OUTFORMAT [-i MODEIN -o MODEOUT -p PORT -b BAUDRATE -x MESSAGES]") |
| 51 | +opts = {} |
| 52 | +adds = {} |
| 53 | +for o in options: |
| 54 | + if len(o[0]) > 2: |
| 55 | + try: |
| 56 | + opts[optDict.inverse[o[0][2:]][0]] = o[1] |
| 57 | + except KeyError: |
| 58 | + adds[o[0][2:]] = o[1] |
| 59 | + else: |
| 60 | + opts[o[0][1:]] = o[1] |
| 61 | +inputs = opts.keys() |
| 62 | +if "h" in inputs: |
| 63 | + printHelp() |
| 64 | + |
| 65 | +if "s" not in inputs or "t" not in inputs or "f" not in inputs: |
| 66 | + raise Exception("Too few options. Provide at least a source, a target and a output format. Correct usage:\nconv.py -s SOURCE -t TARGET -f OUTFORMAT [-i MODEIN -o MODEOUT -p PORT -b BAUDRATE -x MESSAGES]") |
| 67 | +args = ["s","t","f","i","o","p"] |
| 68 | +brate = opts["b"] if "b" in opts.keys() else 115200 |
| 69 | +skip = adds["skip"] if "skip" in adds.keys() else 0.0 |
| 70 | +mute = opts["m"] if "m" in opts.keys() else 0 |
| 71 | + |
| 72 | +converter = conv.HAS_Converter(*[opts[x] if x in opts.keys() else None for x in args], baudrate=brate, skip=skip, mute=mute) |
| 73 | +if 'h' in inputs or "help" in inputs: |
| 74 | + #Print help message |
| 75 | + pass |
| 76 | +if "x" in inputs: |
| 77 | + converter.convertX(int(opts["x"]), verbose=int(opts["v"]) if "v" in inputs else 0) |
| 78 | +else: |
| 79 | + converter.convertAll(verbose=int(opts["v"]) if "v" in inputs else 0) |
0 commit comments