From cb2d804031d221a9a5a1a71c5e87be902a352291 Mon Sep 17 00:00:00 2001 From: anantjoshi97 Date: Fri, 2 Sep 2016 00:09:54 +0530 Subject: [PATCH 1/3] Update Code.py --- Code.py | 77 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/Code.py b/Code.py index e2ae590..03e6fba 100644 --- a/Code.py +++ b/Code.py @@ -2,37 +2,60 @@ import serial import subprocess +def predict(s): + """ date/time in Unix format, the date and time in ASCII + (UTC), the elevation of the satellite in degrees, the azimuth of the + satellite in degrees, the orbital phase (modulo 256), the latitude (N) + and longitude (W) of the satellite's sub-satellite point, the slant + range to the satellite (in kilometers), the orbit number, and the + spacecraft's sunlight visibility information. For example: 1003611710 + Sat 20Oct01 21:01:50 11 6 164 51 72 1389 16669 * """ + + ele = '' + lat = '' + lon = '' + i = 0 #iterator + qty_count = 0 #if this variable has value i, it means the ith quantity is being accessed + + while (qty_count < 10) : + if(s[i]==' '): + i = i + 1 + continue + if(i>0 and s[i-1]==' '): + qty_count = qty_count + 1 + if(qty_count == 5): + ele = ele + s[i] + if(qty_count == 8): + lat = lat + s[i] + if(qty_count == 9): #longitude + lon = lon + s[i] + + return ele , lat , lon + . + ser = serial.Serial('/dev/ttyACM1' , 9600) -#ser = serial.Serial('/dev/tty.usbserial', 9600) -#ser = serial.Serial('/dev/ttyUSBx-1') -#ser = serial.Serial('/dev/ttySx-1') -#ser = serial.Serial('/dev/ttyCOMx') x = number after COM in Arduino IDE + + +PIPE = subprocess.PIPE while True: i = ser.inWaiting() if(i>0): - with open('test1','ab') as f: - f.write(ser.readline()) - f.write('Timestamp: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now())) - #print ser.readline() - #print('Timestamp: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now())) + with open('Timestamp: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()),'a+') as f: + + f.write('{:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()) + ' ') + + if(ser.readline() == '*'): + f.write(ser.readline() + " ") # star voltage written + if(ser.readline() == "#"): + f.write(ser.readline() + " ") # hash voltage written + + process = subprocess.Popen(["predict", "-f" , ""],stdout=PIPE, stderr=PIPE, universal_newlines=0) + stdout, stderr = process.communicate() + ele , lat , lon = predict(stdout) + f.write(ele + " ") + f.write(lat + " ") + f.write(lon + '\n') + else: continue -#first try , successful - -PIPE = subprocess.PIPE -process = subprocess.Popen(["predict", "-f" , ""],stdout=PIPE, stderr=PIPE, universal_newlines=0) -stdout, stderr = process.communicate() - -print stdout -if len(stderr)>0 : - print "error" , stderr - -#second try -""" -output = subprocess.check_output([]) -""" -#third try -""" -output = subprocess.check_output([], universal_newlines = TRUE) -""" From ba44db5fc39e56395ccc87a2dd1bd06f628a9c4b Mon Sep 17 00:00:00 2001 From: anantjoshi97 Date: Fri, 2 Sep 2016 01:35:27 +0530 Subject: [PATCH 2/3] Tested (Working) Tested Serial and Subprocess blocks individually. Both are working as required. --- Code.py | 74 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/Code.py b/Code.py index 03e6fba..928255e 100644 --- a/Code.py +++ b/Code.py @@ -2,7 +2,9 @@ import serial import subprocess -def predict(s): + + +def predict(s) : """ date/time in Unix format, the date and time in ASCII (UTC), the elevation of the satellite in degrees, the azimuth of the satellite in degrees, the orbital phase (modulo 256), the latitude (N) @@ -10,51 +12,59 @@ def predict(s): range to the satellite (in kilometers), the orbit number, and the spacecraft's sunlight visibility information. For example: 1003611710 Sat 20Oct01 21:01:50 11 6 164 51 72 1389 16669 * """ + + ele = '' + lat = '' + lon = '' + i = 0 #iterator + qty_count = 1 #if this variable has value i, it means the ith quantity is being accessed + + while (qty_count < 10) : + if(s[i]==' '): + i = i + 1 + continue + if(i>0 and s[i-1]==' ' and s[i]!=' '): + qty_count = qty_count + 1 + print i-1, s[i-1] + print i, s[i] + print i+1, s[i+1] + if(qty_count == 5): + ele = ele + s[i] + if(qty_count == 8): + lat = lat + s[i] + if(qty_count == 9): #longitude + lon = lon + s[i] + i = i + 1 + + return ele , lat , lon + - ele = '' - lat = '' - lon = '' - i = 0 #iterator - qty_count = 0 #if this variable has value i, it means the ith quantity is being accessed - - while (qty_count < 10) : - if(s[i]==' '): - i = i + 1 - continue - if(i>0 and s[i-1]==' '): - qty_count = qty_count + 1 - if(qty_count == 5): - ele = ele + s[i] - if(qty_count == 8): - lat = lat + s[i] - if(qty_count == 9): #longitude - lon = lon + s[i] - - return ele , lat , lon - . -ser = serial.Serial('/dev/ttyACM1' , 9600) +ser = serial.Serial('/dev/ttyACM2' , 9600) PIPE = subprocess.PIPE + +file_name = 'Timestamp: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()) +with open(file_name,'a+') as f: + f.write("Beginning \n") + while True: i = ser.inWaiting() + if(i>0): - with open('Timestamp: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()),'a+') as f: + with open(file_name,'a+') as f: f.write('{:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()) + ' ') - if(ser.readline() == '*'): - f.write(ser.readline() + " ") # star voltage written - if(ser.readline() == "#"): - f.write(ser.readline() + " ") # hash voltage written - + f.write(ser.readline() + " ") # star voltage written + process = subprocess.Popen(["predict", "-f" , ""],stdout=PIPE, stderr=PIPE, universal_newlines=0) stdout, stderr = process.communicate() ele , lat , lon = predict(stdout) - f.write(ele + " ") - f.write(lat + " ") - f.write(lon + '\n') + f.write(ele + " " + lat + " " + lon + '\n') + #f.write(lat + " ") + #f.write(lon + '\n') else: continue From 96f8a6947f702f95e155de546c72caef986ce865 Mon Sep 17 00:00:00 2001 From: anantjoshi97 Date: Sat, 3 Sep 2016 17:12:28 +0530 Subject: [PATCH 3/3] Print to file formatting change --- Code.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Code.py b/Code.py index 928255e..719cec0 100644 --- a/Code.py +++ b/Code.py @@ -13,7 +13,7 @@ def predict(s) : spacecraft's sunlight visibility information. For example: 1003611710 Sat 20Oct01 21:01:50 11 6 164 51 72 1389 16669 * """ - ele = '' + ele = '' #will give slant range lat = '' lon = '' i = 0 #iterator @@ -25,10 +25,8 @@ def predict(s) : continue if(i>0 and s[i-1]==' ' and s[i]!=' '): qty_count = qty_count + 1 - print i-1, s[i-1] - print i, s[i] - print i+1, s[i+1] - if(qty_count == 5): + + if(qty_count == 10): ele = ele + s[i] if(qty_count == 8): lat = lat + s[i] @@ -40,7 +38,7 @@ def predict(s) : -ser = serial.Serial('/dev/ttyACM2' , 9600) +ser = serial.Serial('/dev/ttyACM0' , 9600) PIPE = subprocess.PIPE @@ -51,15 +49,21 @@ def predict(s) : while True: i = ser.inWaiting() - + #print "i =" , i if(i>0): with open(file_name,'a+') as f: f.write('{:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()) + ' ') - f.write(ser.readline() + " ") # star voltage written + #f.write(ser.readline() + " ") # star voltage written + data = "" + string = ser.readline() + length = len(string) + for k in range(length-2): + data = data + string[k] + f.write(data + " ") - process = subprocess.Popen(["predict", "-f" , ""],stdout=PIPE, stderr=PIPE, universal_newlines=0) + process = subprocess.Popen(["predict", "-f" , "FUN"],stdout=PIPE, stderr=PIPE, universal_newlines=0) stdout, stderr = process.communicate() ele , lat , lon = predict(stdout) f.write(ele + " " + lat + " " + lon + '\n')