示例#1
0
def main(name):
    context = zmq.Context()
    zmq_socket = context.socket(zmq.PUB)
    zmq_socket.bind('tcp://*:5555')
    socket = generate_map(name)['blackbox']
    prefix = user_data_dir + sep + 'log' + sep
    try:
        now = datetime.today().isoformat().replace(':', '')
        symlink_file = prefix + 'blackbox_last.msgpack'
        try:
            unlink(symlink_file)
        except:
            pass
        if len(argv) > 1:
            new_file = prefix + 'blackbox_%s_%s.msgpack' % (now, argv[1])
        else:
            new_file = prefix + 'blackbox_%s.msgpack' % now
        symlink(new_file, symlink_file)
        f = open(new_file, "wb")
        rt = RateTimer(20)
        while True:
            data = socket.recv()
            f.write(data)
            if rt.expired():
                zmq_socket.send(data)
    finally:
        try:
            f.close()
        except:
            pass
示例#2
0
def main(name):
   context = zmq.Context()
   zmq_socket = context.socket(zmq.PUB)
   zmq_socket.bind('tcp://*:5555')
   socket = generate_map(name)['blackbox']
   prefix = user_data_dir + sep + 'log' + sep
   try:
      now = datetime.today().isoformat().replace(':', '')
      symlink_file = prefix + 'blackbox_last.msgpack'
      try:
         unlink(symlink_file)
      except:
         pass
      if len(argv) > 1:
         new_file = prefix + 'blackbox_%s_%s.msgpack' % (now, argv[1])
      else:
         new_file = prefix + 'blackbox_%s.msgpack' % now
      symlink(new_file, symlink_file)
      f = open(new_file, "wb")
      rt = RateTimer(20)
      while True:
         data = socket.recv()
         f.write(data)
         if rt.expired():
            zmq_socket.send(data)
   finally:
      try:
         f.close()
      except:
         pass
示例#3
0
def gps_reader():
   global gps
   socket = socket_map['gps']
   rt = RateTimer(1)
   while True:
      data = socket.recv()
      if rt.expired():
         gps = loads(data)
示例#4
0
def gps_reader():
   global gps
   socket = socket_map['gps']
   rt = RateTimer(1)
   while True:
      data = socket.recv()
      if rt.expired():
         gps = loads(data)
示例#5
0
def remote_reader():
   s = socket_map['rc_cal']
   global channels
   rt = RateTimer(5)
   while True:
      raw = s.recv()
      if spinning:
         continue
      if rt.expired():
         channels = loads(raw)
示例#6
0
def sats_reader():
   global sats
   socket = socket_map['sats']
   rt = RateTimer(1)
   while True:
      raw = socket.recv()
      if spinning:
         continue
      if rt.expired():
         sats = loads(raw)
示例#7
0
def main(name):
   elev_map = SrtmElevMap()
   socket_map = generate_map(name)
   gps_socket = socket_map['gps']
   elev_socket = socket_map['elev']
   rt = RateTimer(1.0)
   while True:
      raw = gps_socket.recv()
      if rt.expired():
         try:
            gps = loads(gps_socket.recv())
            elev = elev_map.lookup((gps[LON], gps[LAT]))
            elev_socket.send(dumps([elev]))
         except:
            pass
示例#8
0
def main(name):
    elev_map = SrtmElevMap()
    socket_map = generate_map(name)
    gps_socket = socket_map['gps']
    elev_socket = socket_map['elev']
    rt = RateTimer(1.0)
    while True:
        raw = gps_socket.recv()
        if rt.expired():
            try:
                gps = loads(gps_socket.recv())
                elev = elev_map.lookup((gps[LON], gps[LAT]))
                elev_socket.send(dumps([elev]))
            except:
                pass
示例#9
0
def main(name):
    script_path = os.path.dirname(os.path.abspath(__file__))
    gm = GeoMag(script_path + os.sep + 'geomag' + os.sep + 'WMM.COF')
    socket_map = generate_map(name)
    gps_socket = socket_map['gps']
    decl_socket = socket_map['decl']
    rt = RateTimer(1)
    while True:
        raw = gps_socket.recv()
        if rt.expired():
            gps = loads(raw)
            try:
                date = datetime.strptime(gps[TIME], '%Y-%m-%d %H:%M:%S').date()
                decl = gm.GeoMag(gps[LAT], gps[LON], time=date).dec
                decl_socket.send('%f' % decl)
            except:
                pass
示例#10
0
def main(name):
   script_path = os.path.dirname(os.path.abspath(__file__))
   gm = GeoMag(script_path + os.sep + 'geomag' + os.sep + 'WMM.COF')
   socket_map = generate_map(name)
   gps_socket = socket_map['gps']
   decl_socket = socket_map['decl']
   rt = RateTimer(1)
   while True:
      raw = gps_socket.recv()
      if rt.expired():
         gps = loads(raw)
         try:
            date = datetime.strptime(gps[TIME], '%Y-%m-%d %H:%M:%S').date()
            decl = gm.GeoMag(gps[LAT], gps[LON], time = date).dec
            decl_socket.send('%f' % decl)
         except:
            pass
示例#11
0
def main(name):
   elev_map = SrtmElevMap()
   socket_map = generate_map(name)
   gps_socket = socket_map['gps']
   elev_socket = socket_map['elev']
   rt = RateTimer(1)
   start_elev = None
   while True:
      raw = gps_socket.recv()
      if rt.expired():
         gps = loads(raw)
         try:
            elev = int(elev_map.lookup((gps[LON], gps[LAT])))
            if not start_elev:
               start_elev = elev
            elev_socket.send(dumps([elev, start_elev]))
         except:
            pass
示例#12
0
 t.start()
 sleep(3)
 state = 0
 ud = 'up', 'down'
 rl = 'right', 'left'
 fb = 'forward', 'backward'
 specs = [('gas', ud),
          ('yaw', rl),
          ('pitch', ud),
          ('roll', rl),
          ('two_state', fb),
          ('three_state', fb)]
 detectors = [ ChannelDetector(spec) for spec in specs ]
 channel_map = [ None ] * len(specs)
 states = range(len(specs))
 rt = RateTimer(0.2)
 while not killed:
    if not channels_valid:
       if rt.expired():
          print 'please enable your remote control'
    else:
       result = detectors[state].run(channels, channels_prev)
       if result is not None:
          if result in channel_map:
             print 'channel already used, please try again'
             detectors[state].reset()
          else:
             channel_map[state] = result
             state += 1
       if state == len(specs):
          print channel_map
示例#13
0
 def run(self):
    rt = RateTimer(1)
    while True:
       raw = self.socket.recv()
       if rt.expired():
          self.data = loads(raw)
示例#14
0
 def run(self):
     rt = RateTimer(1)
     while True:
         raw = self.socket.recv()
         if rt.expired():
             self.data = loads(raw)
示例#15
0
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details. """

from scl import generate_map
from msgpack import loads
from misc import RateTimer

try:
    socket_map = generate_map('rc_cal_dump')
    s = socket_map['rc_cal']
    rt = RateTimer(2.0)
    while True:
        data = loads(s.recv())
        valid = bool(data[0])
        c = data[1:]
        if valid:
            print 'pitch: %.1f\troll: %.1f\tyaw: %.1f\tgas: %.1f\ttwo_state: %.1f\tthree_state: %.1f' % (
                c[0], c[1], c[2], c[3], c[4], c[5])
        elif rt.expired():
            print 'signal invalid'
except:
    print 'canceled by user'