Ejemplo n.º 1
0
    def testSendData(self):
        logger.debug('\n\ttestSendData')
        
        eradio_array = self.find_eradios()
        
        #add eradios to array
        for i in range(len(eradio_array)):
            eradios.append(Elkaradio(eradio_array[i]))
        
        #use default radio channels & radio addresses
        #set data rate to 250 Kbps
        for i in range(len(eradios)):
            eradios[i].set_data_rate(0)
        
        #set second eradio found to PRX mode
        if len(eradios) > 2:
            eradios[1].set_radio_mode(Elkaradio.MODE_PRX)
        
        for h in range(10):
            toSend = []
            for i in range(26):
                toSend.append(0x00 + h)
            data = DataPacket(0, toSend)
            assert (data.datal == toSend)

            log_outputs.debug('Packet: {0}'.format(data.datat))
            
            ack = None
            if len(eradios) > 2:
                ack = eradios[0].send_packet(data.data)
            if ack is not None:
                logger.debug('Received ack {0}'.format(ack))
            
        if len(eradios) > 2:
            eradios[1].close()
Ejemplo n.º 2
0
 def testInstantiateTXeradio(self):
     logger.debug('\n\ttestInstantiateTXeradio')
     
     eradio_array = self.find_eradios()
     
     sRepr = ''
     
     for i in range(len(eradio_array)): 
         eradios.append(Elkaradio(eradio_array[i]))
         if sRepr != '':
             sRepr += '\n'
         sRepr += str(eradios[i]) + '\n\t' \
         + 'Serial Number: ' + str(eradios[i].dev.serial_number)
     logger.debug('\nElkaradio identifiers:\n' + sRepr + '\n')
Ejemplo n.º 3
0
    def test_send_data(self):
        logger.debug("Test: send_data")
        log_outputs.info('Test: send_data')

        eradio_array = self.find_eradios()
        
        #add eradios to array
        for i in range(len(eradio_array)):
            eradios.append(Elkaradio(eradio_array[i]))
            #FIXME make sure that eradios are starting correctly
            logger.debug('Elkaradio {0}: {1}'.format(i, eradios[i]))
        
        #use default radio channels & radio addresses
        #set data rate to 250 Kbps
        for i in range(len(eradios)):
            eradios[i].set_data_rate(0)
        
        #set second eradio found to PRX mode
        if len(eradios) > 2:
            #FIXME make sure that one radio is set to PRX mode
            eradios[1].set_radio_mode(Elkaradio.MODE_PRX)
        
        for h in range(10):
            toSend = []
            for i in range(26):
                toSend.append(0x00 + h)
            #FIXME make sure that outputs are being formed correctly
            data = DataPacket.output()

            log_outputs.info('Packet {0}: {1}'.format(h, data.data))
        
            ack = None
            if len(eradios) > 1:
                ack = eradios[0].send_packet(data.data)

            if ack is not None:
                log_acks.info('Ack {0}: {1}'.format(h, ack))
            else:
                log_acks.info('Ack {0}: No ack received'.format(h))
            
        if len(eradios) > 2:
            eradios[1].close()
Ejemplo n.º 4
0
def main():
  global logger
  sp = False
  base = None
  options = ('\nHelp <help>\n'
               'Exit program <exit>\n'
               'Run ElkaControl with Elka <run elka>\n' 'Run ElkaControl with two ElkaRadios <run radios>\n'
              'Parse log files <parse>')
  while not sp:
    try:
      print '\nMain:\nWhat would you like to do?'
      print options
      
      r_cmd = raw_input('< ')
      cmd = parse_raw_cmd(r_cmd)

      """ main option tree """
      if cmd[0] == 'exit':
        sp = True
      elif cmd[0] == 'help':
          #FIXME print options
          pass
      elif cmd[0] == 'run' and cmd[1] == 'elka':
        run_elka_control()
      elif cmd[0] == 'run' and cmd[1] == 'radios':
        # mainly for debugging
        i = 0
        erads = []
        rx = [] # array of receive nodes
        for e in _find_devices():
          erads.append(e)
          if i != 0:
            rx.append(Elkaradio(erads[i]))
          i += 1
        run_elka_control(rx=rx) 
      elif cmd[0] == 'parse':
        parse_logs()
      else:
        raise InvalidCommand('Invalid command for menu Main.')

    except JoystickNotFound as e:
      print "Joystick not found: ", e
      logger.exception(e)
    except KeyboardInterrupt as e:
      print "Keyboard Interrupt: ", e
      logger.exception(e)
    except ElkaradioNotFound as e:
      print "Elkaradio not found: ", e
      logger.exception(e)
    except LinkException as e:
      print "Exception in comm link: ", e
      logger.exception(e)
    except JoystickThreadFinished as e:
      print 'Joystick thread has stopped: ', e
      logger.exception(e)
    except InvalidCommand as e:
      print "Invalid command:", e
      logger.exception(e)
    except Exception as e:
      print "Exception: ", e
      logger.exception(e)
    finally:
      logger.debug(traceback.format_exc())
      # should only show main thread as alive
      logger.debug(threading.enumerate()) 
Ejemplo n.º 5
0
import traceback, os, sys, usb, usb.core, usb.util, logging, logging.config

sys.path.append(os.getcwd())

from ETP.elkaDriver import ElkaDriver
from Elkaradio.elkaradioTRX import Elkaradio
from Utils.exceptions import *

open('./Logging/testCtrl.log', 'w').close()
logging.config.fileConfig('./Logging/logging.conf',
                          disable_existing_loggers=False)
logger = logging.getLogger('testCtrl')

base = None

try:
    base = Elkaradio()

    pk = [0, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5]

    logger.debug('pk: {}'.format(pk))
    ack = base.send_packet(pk)

    logger.debug('ack: {0}'.format(ack))
except Exception as e:
    logger.debug('exit via exception')
finally:
    base.close()
    logger.debug('{}'.format(traceback.format_exc()))