diff --git a/firmware/firmware.ino b/firmware/firmware.ino index ef7d7d8..a087c7d 100644 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -47,9 +47,9 @@ void setup() si5351.output_enable(SI5351_CLK0, 1); // enable clock output 0 si5351.drive_strength(SI5351_CLK0, SI5351_DRIVE_2MA); // 2 4 6 8ma */ - delay(500); + //delay(500); - Serial.println("SWR Meter firmware v0.1 by Kai Lauterbach (me@klaute.de)"); + //Serial.println("SWR Meter firmware v0.1 by Kai Lauterbach (me@klaute.de)"); } void loop() diff --git a/tools/meas.py b/tools/meas.py index 1ce599d..84c6564 100644 --- a/tools/meas.py +++ b/tools/meas.py @@ -29,7 +29,7 @@ parser.add_argument("-o", "--output_file", type=str, help="") # show graphical results parser.add_argument("-g", "--show_graph", default=False, help="", action='store_true') # get config -parser.add_argument("-c", "--get_config", default=False, help="", action='store_true') +#parser.add_argument("-c", "--get_config", default=False, help="", action='store_true') ############################################################################### @@ -60,7 +60,7 @@ CC_CMD_GET_CONFIG = 0x10 ############################################################################### -TIMEOUT_CNT_MAX = 50 +TIMEOUT_CNT_MAX = 150 MAIN_LOOP_DELAY_S = 0.05 THREAD_LOOP_DELAY_S = 0.01 @@ -157,7 +157,7 @@ def cc_dataReceiverThread(): #print bytesToRead # TODO incoming = list(ser.read(64)) - print incoming # TODO + #print incoming # TODO # 2. process the received data for c in incoming: @@ -292,28 +292,31 @@ def openSerialDevice(d): # Why 115200? Because the host defines the baudrate for the USB serial connection. try: - #ser = serial.Serial(d, 115200, timeout=0) + ser = serial.Serial(d) + except: + print "ERROR: Can't open the serial device " + device + exit(1) + + # Toggle DTR to reset Arduino + ser.setDTR(False) + time.sleep(1) + # toss any data already received, see + # http://pyserial.sourceforge.net/pyserial_api.html#serial.Serial.flushInput + ser.flushInput() + ser.setDTR(True) + + try: ser = serial.Serial( port=d,\ baudrate=115200,\ parity=serial.PARITY_NONE,\ stopbits=serial.STOPBITS_ONE,\ bytesize=serial.EIGHTBITS,\ + rtscts=0,\ timeout=0) except: print "ERROR: Can't open the serial device " + device - exit(1) - - time.sleep(2) - - #ser.write(bytearray([0x00])) - #ser.write(bytearray([0x00])) - #ser.write(bytearray([0x00])) - #ser.write(bytearray([0x00])) - #ser.write(bytearray([0x00])) - - ser.flush() - ser.read(1000) + exit(2) ##### def closeSerialDevice(): @@ -340,6 +343,12 @@ def sendSerialData(data): if __name__ == "__main__": + start_freq = 0 + end_freq = 0 + step_freq = 0 + + config_read = False + cc_init() # parse the commandline arguments @@ -357,11 +366,13 @@ if __name__ == "__main__": # 2. start thread to poll cc_dataReceiverThread() cc_startReceiverThread() + time.sleep(1.5) + # 3. get and process the commandline arguments/parameter - if args.get_config == True: - print "Send: GET_CONFIG" - sendSerialData([CC_CMD_GET_CONFIG]) - dataSend = dataSend + 1 + #if args.get_config == True and args.start_meas == False: + # print "Send: GET_CONFIG" + # sendSerialData([CC_CMD_GET_CONFIG]) + # dataSend = dataSend + 1 if args.start_freq != None: print "Send: SET_START_FREQ" @@ -436,6 +447,9 @@ if __name__ == "__main__": a0 += e[3][5] a1 = e[3][6] << 8 a1 += e[3][7] + print "freq: " + str(freq) + print "a0: " + str(a0) + print "a1: " + str(a1) elif e[1] == MSG_TYPE_CONFIG: print "recv: CONFIG" @@ -454,12 +468,17 @@ if __name__ == "__main__": intervall = e[3][12] << 8 intervall += e[3][13] drive_str = e[3][14] + print "start_freq = " + str(start_freq) print "end_freq = " + str(end_freq) print "step_freq = " + str(step_freq) print "intervall = " + str(intervall) print "drive_str = " + str(drive_str) + if args.start_meas == True and config_read == False: + dataSend = dataSend + 1 + ((end_freq - start_freq) / step_freq) + config_read = True + elif e[1] == MSG_TYPE_MEAS_END_INFO: print "recv: END INFO"