Skip to content

Commit

Permalink
PreFlight 1
Browse files Browse the repository at this point in the history
  • Loading branch information
vaclavstepan committed Jan 1, 2000
1 parent 3a57d56 commit 043d972
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 125 deletions.
12 changes: 12 additions & 0 deletions scripts/clean_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
data_dir=/data/balon
echo -n Remove all logs and img dir in: ${data_dir} [y/n]?\
read r
if [ x$r == "xy" ]; then
cd $data_dir || exit 1
rm -v data_*.csv monitor.log
rm -vrf img
else
echo Ok, not removing anything.
fi

2 changes: 1 addition & 1 deletion scripts/m_gps.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def run(self):
data['GPS_Alt']=gpsd.fix.altitude
data['GPS_Lat']=gpsd.fix.latitude
data['GPS_Lon']=gpsd.fix.longitude
data['GPS_Speed']=gpsd.fix.speed
data['GPS_Speed']=0.514444*gpsd.fix.speed
data['GPS_Track']=gpsd.fix.track
data['GPS_epx']=gpsd.fix.epx # Position error [m]
data['GPS_epv']=gpsd.fix.epv # Altitude error [m]
Expand Down
98 changes: 60 additions & 38 deletions scripts/m_gsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

modem=None
ppp_requested = False
sms_enabled = True
modem_failure = False
beat = 0

# TESTING
Expand Down Expand Up @@ -98,7 +100,10 @@ def send_position_via_sms(destination):
logging.warn('SMS text length {0}'.format(len(smstext)))
logging.warn('SMS: {0}'.format(smstext))

sms = modem.sendSms(destination, smstext, waitForDeliveryReport=False)
if sms_enabled:
sms = modem.sendSms(destination, smstext, waitForDeliveryReport=False)
else:
logging.warn('SMS dispatch disabled.')
except TimeoutException:
logging.warn('Failed to send message to {0}: the send operation timed out'.format(destination))
else:
Expand Down Expand Up @@ -152,10 +157,16 @@ def handleSms(sms):
global sms_queue
logging.info('SMS From {0} at {1}:{2}'.format(sms.number, sms.time, sms.text))
if sms.text.lower() == 'pos':
logging.info('SMS: Position request')
logging.warn('SMS: Position request')
sms_queue.append('position')
elif sms.text.lower() == 'smsoff':
logging.warn('SMS messaging OFF')
sms_enabled = False
elif sms.text.lower() == 'smson':
logging.warn('SMS messaging ON')
sms_enabled = False
elif sms.text.lower() == 'ppp':
logging.info('SMS: GSM uplink requested')
logging.warn('SMS: GSM uplink requested')
sms_queue.append('Activating PPP uplink')
ppp_requested = True
else:
Expand Down Expand Up @@ -190,6 +201,8 @@ def shutdown(self):
self.do_shutdown = True

def get_status_string(self):
if modem_failure:
return("GSM: FAIL ")
if self.signalStrength < 100:
return("GSM: %d @ %s Cell: %s " % (self.signalStrength,self.networkName, self.cellInfo))
else:
Expand All @@ -210,13 +223,19 @@ def run(self):
global ppp_requested
global sms_queue
global beat
global modem_failure

rxListenLength = 5
init_count = 0

while self.running:
beat += 1
while self.running and not ppp_requested and init_count > -1:
if (init_count > 10):
# Let's exit after 10 fails
self.running = False
modem_failure = True
return(1)
try:
init_count = init_count + 1
modem = GsmModem(PORT, BAUDRATE, incomingCallCallbackFunc=handleIncomingCall, smsReceivedCallbackFunc=handleSms)
Expand Down Expand Up @@ -256,18 +275,19 @@ def run(self):
#time.sleep(rxListenLength)
if (self.signalStrength > 5):
sent_position = 0
while (len(sms_queue) > 0):
text=sms_queue.pop()
if (text == 'position') and sent_position:
logging.info('Not resending position in the same interval')
elif (text == 'position'):
send_position_via_sms(default_destination)
sent_position = 1
else:
try:
modem.sendSms(default_destination, text, waitForDeliveryReport=False)
except (CommandError, TimeoutException):
sms_queue.append(text)
if sms_enabled:
while (len(sms_queue) > 0):
text=sms_queue.pop()
if (text == 'position') and sent_position:
logging.info('Not resending position in the same interval')
elif (text == 'position'):
send_position_via_sms(default_destination)
sent_position = 1
else:
try:
modem.sendSms(default_destination, text, waitForDeliveryReport=False)
except (CommandError, TimeoutException):
sms_queue.append(text)
else:
logging.info('Waiting for better network coverage')

Expand All @@ -290,18 +310,19 @@ def run(self):
try:
self.signalStrength = 101
logging.info('Launching PPP session.')
while (len(sms_queue) > 0):
logging.info('==== Sending PPP activation SMS =====')
text=sms_queue.pop()
try:
modem.sendSms(default_destination, text, waitForDeliveryReport=False)
time.sleep(1)
except (CommandError, TimeoutException):
sms_queue.append(text)
if sms_enabled:
while (len(sms_queue) > 0):
logging.info('==== Sending PPP activation SMS =====')
text=sms_queue.pop()
try:
modem.sendSms(default_destination, text, waitForDeliveryReport=False)
time.sleep(1)
except (CommandError, TimeoutException):
sms_queue.append(text)
#waitForNetworkCoverage()
modem.close()
logging.info("Modem interface closed.")
rc = subprocess.check_output(['/usr/bin/timeout','360','/usr/bin/pon'], stderr=subprocess.STDOUT)
rc = subprocess.check_output(['/usr/bin/timeout','250','/usr/bin/pon'], stderr=subprocess.STDOUT)
logging.info('PPP ended: %s' % s)
except subprocess.CalledProcessError as e:
logging.info('PPP ended: %s' % e)
Expand All @@ -314,7 +335,7 @@ def run(self):
#### main ####
if __name__ == '__main__':
# Logging
logging.basicConfig(level=logging.DEBUG,
logging.basicConfig(level=logging.INFO,
format='%(asctime)s [%(levelname)s] (%(threadName)-10s) %(message)s',
)
try:
Expand All @@ -327,23 +348,24 @@ def run(self):
gsmpart = ModemHandler()
gsmpart.start()
while gsmpart.running:
#sms_queue.append('position')
# GSM module data
logging.info(gsmpart.get_status_string())
#i2c = m_i2c.get_i2c_data()
time.sleep(10)
logging.info(gsmpart.get_status_string())
time.sleep(10)
logging.info(gsmpart.get_status_string())
time.sleep(10)
gsmpart.shutdown()
while gsmpart.isAlive():
print "waiting for modem shutdown"
time.sleep(1)
print "Modem radio disabled and modem is down."
time.sleep(10)
gsmpart = ModemHandler()
gsmpart.start()

logging.info(gsmpart.get_status_string())
time.sleep(10)

gsmpart.shutdown()
while gsmpart.isAlive():
print "waiting for modem shutdown"
time.sleep(1)
print "Modem radio disabled and modem is down."
time.sleep(10)

gsmpart = ModemHandler()
gsmpart.start()

print "GSM part finished."
raise(SystemExit)
Expand Down
2 changes: 1 addition & 1 deletion scripts/m_pcrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def channels_summary(channels):
#### PCRD poller ####
class PCRD_poller(threading.Thread):
# Default data dir
data_dir = './'
data_dir = '/data/balon/'
def __init__(self):
logging.info("PCRD poller thread is initializing.")
threading.Thread.__init__(self)
Expand Down
23 changes: 19 additions & 4 deletions scripts/m_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,31 @@
data_dir = '/data/balon/'
image_dir = data_dir + 'img/'

round_beat = 5
round_beat = 10

# This is for testing, triggers lpm when external power source is disconnected
print "======================= SET REAL U LIMITS ====================="
U_lpm = [8350, 8430] # Threshold to enter and exit the low power mode, in mV
#print "======================= SET REAL U LIMITS ====================="
#U_lpm = [8350, 8430] # Threshold to enter and exit the low power mode, in mV

# Flight thresholds:
#U_lpm = [7000,7300]
U_lpm = [7000,7300]

# Modem
default_destination = "+420777642401"

#default_destination = "+420775268014"

# Testing, lower edge of interval
alt_threshold = 280
alt_hyst = 5

alt_step = 20

# Start mode
start_timeout = 30
morituri_timeout = 30

# FAILSAFE MODE
failsafe_timeout = 7200 # s
sos_interval = 600 # s

4 changes: 3 additions & 1 deletion scripts/m_webcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import pygame
import pygame.camera

import m_sequence

#### Settings #####
data_dir="/data/balon/"
imagedir=data_dir+"img/"
Expand Down Expand Up @@ -61,7 +63,7 @@ def make_selfie():
return(2)

# Construct file name
savefname=imagedir+('cam%d-' % (device_number))+time.strftime('%F_%T.jpg', time.gmtime())
savefname=imagedir+str(m_sequence.get_next_image_fname())
logging.info("Capturing {0}x{1} frame to {2}.".format(resolutionx,resolutiony,savefname))
try:
ensure_dir(savefname)
Expand Down
Loading

0 comments on commit 043d972

Please sign in to comment.