Esempio n. 1
0
class ADS1x15_ADC:

   def __init__(self, adc_id):
      self.adc = ADS1x15(ic = 0)
      result = self.adc.startContinuousConversion(0, 6144)

   def read(self):
      return self.adc.getLastConversionResults()


def main(name):
   map = generate_map(name)
   socket = map['power']
   opcd = OPCD_Interface(map['opcd_ctrl'], 'pi_quad')
   voltage_adc = ADS1x15_ADC(opcd.get('voltage_channel'))
   #current_adc = ADS1x15_ADC(opcd.get('current_channel'))
   voltage_lambda = eval(opcd.get('adc_to_voltage'))
   #current_lambda = eval(opcd.get('adc_to_current'))
   while True:
      sleep(0.2)
      voltage = voltage_lambda(voltage_adc.read())  
      #current = current_lambda(current_adc.read())
      state = [voltage,  # 0 [V]
               0.4]      # 1 [A]
      socket.send(dumps(state))


daemonize('ads1x15', main)

Esempio n. 2
0
   def __init__(self, socket):
      Thread.__init__(self)
      self.daemon = True
      self.socket = socket

   def run(self):
      rt = RateTimer(1)
      while True:
         raw = self.socket.recv()
         if rt.expired():
            self.data = loads(raw)


def main(name):
   map = generate_map(name)
   gps_reader = GPS_Reader(map['gps'])
   gps_reader.start()
   wifi_socket = map['networks']
   f = file("/tmp/wifi.log", "w")
   while True:
      try:
         measure = loads(wifi_socket.recv())
         gps = gps_reader.data
         f.write('%f %f %s %d\n' % (gps[LAT], gps[LON], measure[0], measure[1]))
         f.flush()
      except:
         pass

daemonize('wifi_loc', main)

Esempio n. 3
0
  
 Log Proxy Service

 Copyright (C) 2014 Tobias Simon, Integrated Communication Systems Group, TU Ilmenau

 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 misc import daemonize


def main(name):
   map = generate_map(name)
   socket_in = map['log_data']
   socket_out = map['log_data_pub']
   while True:
      data = socket_in.recv()
      socket_out.send(data)

daemonize('log_proxy', main)

Esempio n. 4
0
 Copyright (C) 2014 Tobias Simon, Integrated Communication Systems Group, TU Ilmenau

 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 os import sep
from scl import generate_map
from misc import daemonize, user_data_dir


def main(name):
    map = generate_map(name)
    socket = map['log_data_pub']
    prefix = user_data_dir + sep + 'log' + sep
    new_file = prefix + 'session.log'
    f = open(new_file, "wb")
    while True:
        data = socket_in.recv()
        f.write(data)
        f.flush()


daemonize('file_logger', main)
Esempio n. 5
0
   def run(self):
      while True:
         data = Measurement()
         raw_data = self.socket.recv()
         data.ParseFromString(raw_data)
         self.data = data
         self.event.set()


def main(name):
   map = generate_map(name)
   mon_reader = MonReader(map['mon'])
   networks_reader = NetworksReader(map['networks'])
   mon_reader.start()
   networks_reader.start()
   
   netfile = open('/tmp/netfile.txt', 'w')
   mon_reader.event.wait()
   while True:
      networks_reader.event.wait()
      networks_reader.event.clear()
      measure = networks_reader.data
      tstamp = time()
      netfile.write('%f; %f; %f; %f; %s; %s\n' % (tstamp, mon_reader.data.x, mon_reader.data.y, mon_reader.data.z, measure.mac, measure.rssi))
      netfile.flush()


main('wifi_logger')
daemonize('wifi_logger', main)

Esempio n. 6
0
    signal(SIGINT, term_sig_handler)
    signal(SIGQUIT, term_sig_handler)

    parser = argparse.ArgumentParser(description='gateway service')
    parser.add_argument('-p',
                        action="store",
                        default=6752,
                        type=int,
                        dest='port',
                        help='port default 6752')
    parser.add_argument('-debug',
                        action="store",
                        default=True,
                        type=bool,
                        dest='debug',
                        help='debug default true')
    parser.add_argument('-daemon',
                        action="store",
                        default=False,
                        type=bool,
                        dest='daemon',
                        help='daemon default false')
    p = parser.parse_args()

    if p.daemon:
        daemonize()

    print "http://{}:{}".format("localhost", p.port)

    AppManager().start(p)
Esempio n. 7
0
    def run(self):
        i = 0
        while True:
            data = self.socket.recv()
            if i == 5:
                i = 0
                gps = GpsData()
                gps.ParseFromString(data)
                self.data = gps
            i += 1


def main(name):
    map = generate_map(name)
    gps_reader = GPS_Reader(map['gps'])
    gps_reader.start()
    wifi_socket = map['wifi']
    f = file("/tmp/wifi.log", "w")
    while True:
        try:
            measure = loads(wifi_socket.recv())
            gps = gps_reader.data
            f.write('%f %f %s %d\n' %
                    (gps.lat, gps.lon, measure[0], measure[1]))
            f.flush()
        except:
            pass


daemonize('wifi_loc', main)
Esempio n. 8
0
            val = int(file.read())
        except:
            val = 17.0
        file.close()
        return val


def main(name):
    map = generate_map(name)
    socket = map['power']
    opcd = OPCD_Interface(map['opcd_ctrl'], 'overo_quad')
    voltage_adc = TWL4030_MADC(opcd.get('voltage_channel'))
    current_adc = TWL4030_MADC(opcd.get('current_channel'))
    voltage_lambda = eval(opcd.get('adc_to_voltage'))
    current_lambda = eval(opcd.get('adc_to_current'))
    while True:
        try:
            sleep(0.2)
            voltage = voltage_lambda(voltage_adc.read())
            current = current_lambda(current_adc.read())
            state = [
                voltage,  # 0 [V]
                current
            ]  # 1 [A]
            socket.send(dumps(state))
        except:
            pass


daemonize('twl4030_madc', main)
Esempio n. 9
0
 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 os import sep
from scl import generate_map
from misc import daemonize, user_data_dir
from msgpack import loads
from datetime import datetime


def main(name):
    map = generate_map(name)
    gps_socket = map['gps']
    ts_socket = map['time_set']
    while not loads(ts_socket.recv()):
        pass
    now = datetime.today().isoformat().replace(':', '')
    prefix = user_data_dir + sep + 'log' + sep
    new_file = prefix + 'gps_' + now + '.log'
    f = open(new_file, "wb")
    while True:
        data = gps_socket.recv()
        f.write(data)
        f.flush()


daemonize('gps_logger', main)
Esempio n. 10
0
        self.yaw_setpoint = self.mon_data.yaw
        self.activity = TakeoffActivity(self.fsm, self)
        self.activity.start()

    def _land_activity(self):
        log_info("landing")
        self.activity.cancel_and_join()
        self.activity = LandActivity(self)
        self.activity.start()

    def _move_activity(self):
        log_info("moving")
        self.activity.cancel_and_join()
        self.activity = MoveActivity(self)
        self.activity.start()

    def _stop_activity(self):
        log_info("stopping")
        self.activity.cancel_and_join()
        self.activity = StopActivity(self)
        self.activity.start()


def main(name):
    sockets = generate_map(name)
    ICARUS(sockets)
    await_signal()


daemonize("icarus", main)
Esempio n. 11
0
 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 time import sleep, time
from scl import generate_map
from misc import daemonize
from msgpack import loads
from aircomm_shared import BCAST, HEARTBEAT


def main(name):
   global socket_map, gps_lock, font, caution_written
   socket_map = generate_map('aircomm_app')
   socket = socket_map['in']
   while True:
      data = loads(socket.recv())
      if data[0] == 'js':
         print map(lambda x : x * 1.0 / (2 ** 15), data[1:])


main('joystick')
daemonize('joystick', main)

Esempio n. 12
0
def main(name):
   global socket_map
   socket_map = generate_map(name)

   t2 = Thread(target = pm_reader)
   t2.daemon = True
   t2.start()

   t3 = Thread(target = gps_reader)
   t3.daemon = True
   t3.start()
   
   ser = serialport_t()
   CSTOPB = 0000100
   serial_open(ser, "/dev/ttyO0", 100000, os.O_WRONLY, CSTOPB)
   while True:
      try:
         serial_write_str(ser, "H %d %d\n" % (int(current * 100), int(voltage * 100)))
         if fix(gps) >= 2:
            serial_write_str(ser, "G2 %d %d %d\n" % (int(gps[LAT] * 10000000.0), int(gps[LON] * 10000000.0), int(gps[SPEED] * 10.0)))
         if fix(gps) == 3:
            serial_write_str(ser, "G3 %d %d\n" % (int(gps[ALT] * 1000), 0))
      except:
         pass
      sleep(0.1)

#main('teensy_taranis')
daemonize('teensy_taranis', main)

Esempio n. 13
0
   t1.daemon = True
   t1.start()

   t2 = Thread(target = pmreader)
   t2.daemon = True
   t2.start()

   t3 = Thread(target = gps)
   t3.daemon = True
   t3.start()

   socket = generate_map('aircomm_app')['out']
   packer = Packer(use_single_float = True)
   while True:
      try:
         data = [BCAST_NOFW, HEARTBEAT, int(voltage * 10), int(current * 10), int(load), mem_used(), critical]
         with gps_lock:
            try:
               if gps_data.fix >= 2:
                  data += [gps_data.lon, gps_data.lat]
            except:
               pass
         socket.send(packer.pack(data))
      except Exception, e:
         pass
      sleep(1.0)


daemonize('heartbeat', main)

Esempio n. 14
0
 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 misc import daemonize, RateTimer
from gps_msgpack import *
from msgpack import loads, dumps
from srtm import SrtmElevMap


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


daemonize('elevmap', main)
Esempio n. 15
0
      file = open(self.path)
      try:
         val = int(file.read())
      except:
         val = 17.0
      file.close()
      return val


def main(name):
   map = generate_map(name)
   socket = map['power']
   opcd = OPCD_Interface(map['opcd_ctrl'], 'overo_quad')
   voltage_adc = TWL4030_MADC(opcd.get('voltage_channel'))
   current_adc = TWL4030_MADC(opcd.get('current_channel'))
   voltage_lambda = eval(opcd.get('adc_to_voltage'))
   current_lambda = eval(opcd.get('adc_to_current'))
   while True:
      try:
         sleep(0.2)
         voltage = voltage_lambda(voltage_adc.read())  
         current = current_lambda(current_adc.read())
         state = [voltage,  # 0 [V]
                  current]  # 1 [A]
         socket.send(dumps(state))
      except:
         pass

daemonize('twl4030_madc', main)

Esempio n. 16
0
 |___________________________________________________|
  
 Log Proxy Service

 Copyright (C) 2014 Tobias Simon, Ilmenau University of Technology

 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 misc import daemonize


def main(name):
    map = generate_map(name)
    socket_in = map['log_data']
    socket_out = map['log_data_pub']
    while True:
        data = socket_in.recv()
        socket_out.send(data)


daemonize('log_proxy', main)
Esempio n. 17
0
   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

daemonize('blackbox', main)

Esempio n. 18
0
 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 misc import daemonize, RateTimer
from gps_msgpack import *
from msgpack import loads, dumps
from srtm import SrtmElevMap


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


daemonize('elevmap', main)
Esempio n. 19
0
 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 os import sep
from scl import generate_map
from misc import daemonize, user_data_dir
from msgpack import loads
from datetime import datetime


def main(name):
   map = generate_map(name)
   gps_socket = map['gps']
   ts_socket = map['time_set']
   while not loads(ts_socket.recv()):
      pass
   now = datetime.today().isoformat().replace(':', '')
   prefix = user_data_dir + sep + 'log' + sep
   new_file = prefix + 'gps_' + now + '.log'
   f = open(new_file, "wb")
   while True:
      data = gps_socket.recv()
      f.write(data)
      f.flush()


daemonize('gps_logger', main)

Esempio n. 20
0
   
   global THIS_SYS_ID
   THIS_SYS_ID = opcd.get('aircomm.id')
   key = opcd.get('aircomm.psk')
   crypt.init(key)
   mhist = MessageHistory(60)

   out_socket = sm['aircomm_out']
   in_socket = sm['aircomm_in']

   aci = ZMQ_Interface()
   acr = ACIReader(aci, out_socket, mhist)
   acr.start()

   # read from SCL in socket and send data via NRF
   while True:
      data = loads(in_socket.recv())
      if len(data) == 2:
         msg = [data[0], THIS_SYS_ID, data[1]]
      elif len(data) > 2:
         msg = [data[0], THIS_SYS_ID] + data[1:]
      else:
         continue
      crypt_data = crypt.encrypt(dumps(msg))
      mhist.append(crypt_data)
      aci.send(crypt_data)


daemonize('aircomm', main)

Esempio n. 21
0
            except:
                sleep(1)
                continue
            try:
                req.ParseFromString(req_data)
            except:
                rep.status = E_SYNTAX
            else:
                try:
                    timer.cancel()
                except:
                    pass
                if req.cmd == STAND_POWER:
                    timer = Timer(timeout, self.power_off)
                    timer.start()
                else:
                    if self.critical:
                        # flying command is not allowed if battery was critical:
                        rep.status = E_POWER
                    else:
                        self.gpio_mosfet.set_gpio(self.power_pin, True)
            self.ctrl_socket.send(rep.SerializeToString())


def main(name):
    PowerMan(name)
    await_signal()


daemonize('powerman', main)
Esempio n. 22
0

def main(name):
    socket = generate_map(name)['data']
    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")
        while True:
            f.write(socket.recv())
            #f.flush()
            #fsync(f.fileno())
    finally:
        try:
            f.close()
        except:
            pass


daemonize('blackbox', main)
Esempio n. 23
0
from geomag.geomag import GeoMag
from scl import generate_map
from misc import daemonize, RateTimer
import os
from time import time
from datetime import datetime
from gps_msgpack import *
from msgpack import loads


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

daemonize('geomag', main)
Esempio n. 24
0
 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 time import sleep, time
from scl import generate_map
from misc import daemonize
from msgpack import loads
from aircomm_shared import BCAST, HEARTBEAT


def main(name):
   global socket_map, gps_lock, font, caution_written
   socket_map = generate_map('aircomm_app')
   socket = socket_map['in']
   while True:
      try:
         data = loads(socket.recv())
	 if data[0] == 'EMERGENCY-KILL':
	    print 'emergency kill requested'
      except Exception, e:
         print e
      sleep(1.0)


main('emerg_kill')
daemonize('emerg_kill', main)

Esempio n. 25
0
from geomag.geomag import GeoMag
from scl import generate_map
from misc import daemonize, RateTimer
import os
from time import time
from datetime import datetime
from gps_msgpack import *
from msgpack import loads


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


daemonize('geomag', main)
Esempio n. 26
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 os import sep
from scl import generate_map
from misc import daemonize, user_data_dir


def main(name):
   map = generate_map(name)
   socket = map['log_data_pub']
   prefix = user_data_dir + sep + 'log' + sep
   new_file = prefix + 'session.log'
   f = open(new_file, "wb")
   while True:
      data = socket_in.recv()
      f.write(data)
      f.flush()

daemonize('file_logger', main)

Esempio n. 27
0
                        val = getattr(req.val, attr)
                        self.conf.set(req.id.encode('ascii'), type(val))
                        break
                  pair = Pair(id = req.id, val = req.val)
                  self.event_socket.send(pair.SerializeToString())
               except ConfigError, e:
                  log(LL_ERROR, 'key not found: %s' % req.id)
                  rep.status = CtrlRep.PARAM_UNKNOWN

            # PERSIST REQUEST:
            else:
               assert req.type == CtrlReq.PERSIST
               try:
                  self.conf.persist()
                  rep.status = CtrlRep.OK
               except Exception, e:
                  log(LL_ERROR, 'persist failed: %s' % str(e))
                  rep.status = CtrlRep.IO_ERROR
         except:
            rep.status = CtrlRep.PARAM_UNKNOWN
         # send reply:
         self.ctrl_socket.send(rep.SerializeToString())


def main(name):
   opcd = OPCD(name)
   opcd.run()

daemonize('opcd', main)

Esempio n. 28
0
 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 iwlistparse2 import parse_cells
from subprocess import Popen, PIPE
from scl import generate_map
from time import sleep
from misc import daemonize
from msgpack import dumps

def main(name):
   socket = generate_map(name)['networks']
   while True:
      pipe = Popen(['iwlist', 'wlan0', 'scan'], stdout = PIPE).stdout
      cells = parse_cells(pipe.readlines())
      for cell in cells:
         pair = [cell['Address'] + '_' + cell['Name'], int(cell['Signal'][0:-3])]
         print pair
         socket.send(dumps(pair))
      print 
      sleep(0.5)

daemonize('wifi_sensor', main)

Esempio n. 29
0
 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 iwlistparse2 import parse_cells
from subprocess import Popen, PIPE
from scl import generate_map
from time import sleep
from misc import daemonize
from msgpack import dumps


def main(name):
    socket = generate_map(name)['networks']
    while True:
        pipe = Popen(['iwlist', 'wlan0', 'scan'], stdout=PIPE).stdout
        cells = parse_cells(pipe.readlines())
        for cell in cells:
            pair = [
                cell['Address'] + '_' + cell['Name'],
                int(cell['Signal'][0:-3])
            ]
            print pair
            socket.send(dumps(pair))
        print
        sleep(0.5)


daemonize('wifi_sensor', main)
Esempio n. 30
0
                                self.conf.set(req.id.encode('ascii'),
                                              type(val))
                                break
                        pair = Pair(id=req.id, val=req.val)
                        self.event_socket.send(pair.SerializeToString())
                    except ConfigError, e:
                        log(LL_ERROR, 'key not found: %s' % req.id)
                        rep.status = CtrlRep.PARAM_UNKNOWN

                # PERSIST REQUEST:
                else:
                    assert req.type == CtrlReq.PERSIST
                    try:
                        self.conf.persist()
                        rep.status = CtrlRep.OK
                    except Exception, e:
                        log(LL_ERROR, 'persist failed: %s' % str(e))
                        rep.status = CtrlRep.IO_ERROR
            except:
                rep.status = CtrlRep.PARAM_UNKNOWN
            # send reply:
            self.ctrl_socket.send(rep.SerializeToString())


def main(name):
    opcd = OPCD(name)
    opcd.run()


daemonize('opcd', main)
Esempio n. 31
0
   
   global THIS_SYS_ID
   THIS_SYS_ID = opcd.get('aircomm.id')
   key = opcd.get('aircomm.psk')
   crypt.init(key)
   mhist = MessageHistory(60)

   out_socket = sm['aircomm_out']
   in_socket = sm['aircomm_in']

   aci = Interface(device)
   acr = ACIReader(aci, out_socket, mhist)
   acr.start()

   # read from SCL in socket and send data via NRF
   while True:
      data = loads(in_socket.recv())
      if len(data) == 2:
         msg = [data[0], THIS_SYS_ID, data[1]]
      elif len(data) > 2:
         msg = [data[0], THIS_SYS_ID] + data[1:]
      else:
         continue
      crypt_data = crypt.encrypt(dumps(msg))
      mhist.append(crypt_data)
      aci.send(crypt_data)


daemonize('aircomm', main)

Esempio n. 32
0
   global socket_map, font, caution_written
   socket_map = generate_map(name)
   t1 = Thread(target = cpu_reader)
   t1.daemon = True
   t1.start()

   t2 = Thread(target = pm_reader)
   t2.daemon = True
   t2.start()

   t3 = Thread(target = gps_reader)
   t3.daemon = True
   t3.start()

   socket = generate_map('aircomm_app')['aircomm_in']
   while True:
      try:
         data = [BCAST_NOFW, HEARTBEAT, int(voltage * 10), int(current * 10), int(load), mem_used(), critical]
         try:
            data += [gps[LAT], gps[LON]]
         except:
            pass
         socket.send(dumps(data))
      except Exception, e:
         print e
      sleep(1.0)


daemonize('heartbeat', main)

Esempio n. 33
0
      while True:
         try:
            if not spinning:
               caution_written = False
               oled.invert(False)
               t = time()
               while time() < t + screens[screen][1]:
                  image = Image.new("1", (W, H), BLACK)
                  draw = ImageDraw.Draw(image)
                  screens[screen][0](draw)
                  show_image(image)
                  sleep(1)
                  if critical:
                     alert = Alert(1.0, 0.1, 1, batt_low, True)
                     alert.start()
                     alert.join()
            else:
               caution()
               sleep(0.2)
         except:
            sleep(1)
         screen = (screen + 1) % len(screens)
   except:
      oled.invert(False)
      oled.clear()
      oled.update()


daemonize('display', main)

Esempio n. 34
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 time import sleep, time
from scl import generate_map
from misc import daemonize
from msgpack import loads
from aircomm_shared import BCAST, HEARTBEAT


def main(name):
    global socket_map, gps_lock, font, caution_written
    socket_map = generate_map('aircomm_app')
    socket = socket_map['in']
    while True:
        data = loads(socket.recv())
        if data[0] == 'js':
            print map(lambda x: x * 1.0 / (2**15), data[1:])


main('joystick')
daemonize('joystick', main)
Esempio n. 35
0
            sleep(1)
            continue
         try:
            req.ParseFromString(req_data)
         except:
            rep.status = E_SYNTAX
         else:
            try:
               timer.cancel()
            except:
               pass
            if req.cmd == STAND_POWER:
               timer = Timer(timeout, self.power_off)
               timer.start()
            else:
               if self.critical:
                  # flying command is not allowed if battery was critical:
                  rep.status = E_POWER
               else:
                  self.gpio_mosfet.set_gpio(self.power_pin, True)
         self.ctrl_socket.send(rep.SerializeToString())



def main(name):
   PowerMan(name)
   await_signal()

daemonize('powerman', main)

Esempio n. 36
0
   for i in range(36):
      for j in range(72):
         for k in range(72):
            data[i, j, k, 0] = 0
            data[i, j, k, 1] = 0
            data[i, j, k, 2] = 9.806650
   print 'loading data'
   for line in file('/root/.PenguPilot/config/gvfa_state.txt'):
      n, e, u = map(float, line.split(' ')[3:6])
      i, j, k = map(int, line.split(' ')[0:3])
      data[i, j, k, 0] = n
      data[i, j, k, 1] = e
      data[i, j, k, 2] = u
   
   print 'starting'
   socket = generate_map(name)['gvfa']
   c = 0
   while True:
      n, e, u, i, j, k = loads(socket.recv())
      data[i, j, k, 0] = n
      data[i, j, k, 1] = e
      data[i, j, k, 2] = u
      if (c % 5000) == 0 and not writing:
         t = Thread(target = write_file)
         t.start()
      c += 1

main('gvfa')
daemonize('gvfa', main)