Adding in a ping test

master
Dan 2018-07-25 21:26:03 -06:00
parent 84a65e837f
commit 805a182d89
1 changed files with 34 additions and 0 deletions

34
ping_test/ping.py 100755
View File

@ -0,0 +1,34 @@
#!/usr/bin/python
import socket
import time
import serial
import sys, os
import subprocess
#import pynmea2
ser = serial.Serial('/dev/ttyACM0',9600)
#UDP_IP = "10.0.0.2"
UDP_IP = "localhost"
UDP_PORT = 5005
outfile = open("./results_ping.txt", 'w')
last_gps = ''
while True:
p = subprocess.Popen(['ping -c 1 -W 10 ' + UDP_IP], shell=True, stdout=subprocess.PIPE)
while p.poll() == None:
data = ser.readline()
if (data.startswith("$GNGGA")):
last_gps = data
o, e = p.communicate()
print o
data = o
output_str = "********\nReceived Message:" + data + '/' + last_gps
print "********\nreceived message:", data, '/', last_gps
outfile.write(output_str)
outfile.flush()
os.system('play system-ready.ogg -q -V0')
# last_gps = pynmea2.parse(data)