""" gps_event.py Periodically read data from Magellan Meridian Gold GPS connected on COM 1. Format GPS data into XML/JSON/... and send to a EP/CEP server or service BUS or ... """ # select service: none, aws, rc, tweet, email, gtalk, coral8, wp, blog use_service = 'coral8' # define sampling delay in seconds sample_delay = 5 # map templates to services format_list ={'none':'json', 'aws':'xml', 'rc': 'rcxml', 'tweet':'tweet', 'email':'email', 'coral8':'coral8', 'gtalk':'gtalk','wp':'wp', 'blog':'wp'} import time, sys import gps_devices service = __import__('gps_service_%s' % use_service) template = __import__('gps_template_%s' % format_list[use_service]) msg_cnt = 1 max_msg = 10 # 0 for infinite loop simulate_gps = False def gps_main(): """Read GPS every 'sample_delay' seconds, send to ... """ gps = gps_devices.MeridianGold(entity='DS_GPS_1', simulate=simulate_gps) try: while 1: if gps.read_gps(): st = make_output_string(gps.data) send(st) if max_msg > 0: if msg_cnt > max_msg: break time.sleep(sample_delay) finally: gps.close_port() return '*** ABORTING gps_event.py ***' def make_output_string(dic, pretty = True): """Make xml, json ...""" st = template.template(pretty) for (k,v) in dic.items(): st = st.replace('$%s_here$'%(k,), v) return st def send(xst): """Send data to...""" global msg_cnt r = service.send(xst) print 'Send result: %s; msg %d' % (r, msg_cnt) if r: print xst msg_cnt += 1 if __name__ == "__main__": print gps_main()