Ejemplo n.º 1
0
def process_incoming_raw_data():
    # for non-Windows; Windows has windows_raw_encrypted_data_handler()
    global g_os_decryption
    global g_device
    global g_raw_decrypted_packets
    global g_raw_encryped_packets
    global g_packet_timestamps

    #this_packet = 'xxx'
    #while this_packet != '':
    if g_os_decryption:
        this_packet = g_device.read(32)
        this_timestamp = time.time()
        if this_packet != '':
            g_raw_decrypted_packets.append(this_packet)
            g_packet_timestamps.append(this_timestamp)
    else:
        this_packet = hidapi.hid_read(g_device, 34)
        this_timestamp = time.time()
        if len(this_packet) == 32:
            this_packet.insert(0, 0)
        if this_packet != '':
            this_packet = ''.join(map(chr, this_packet[1:]))
            g_raw_encryped_packets.append(this_packet)
            g_packet_timestamps.append(this_timestamp)
Ejemplo n.º 2
0
 def readFirmwareVersion(self):
     self.sn = self.sn + 1
     if self.sn > 255:
         self.sn = 1
     data = struct.pack('BBBBBBBBBB', 0xAA, HASSEB_READ_FIRMWARE_VERSION,
                        self.sn, 0, 0, 0, 0, 0, 0, 0)
     hidapi.hid_write(self.device, data)
     data = hidapi.hid_read(self.device, 10)
     for i in range(0, 100):
         if len(data) == 10:
             if data[1] != HASSEB_READ_FIRMWARE_VERSION:
                 data = hidapi.hid_read(self.device, 10)
             else:
                 return f"{data[3]}.{data[4]}"
         else:
             data = hidapi.hid_read(self.device, 10)
     return f"VERSION_ERROR"
Ejemplo n.º 3
0
 def setup_not_windows(self):
     """
     Setup for headset on a non-windows platform.
     Receives packets from headset and sends them to a Queue to be processed
     by the crypto greenlet.
     """
     _os_decryption = False
     if os.path.exists('/dev/eeg/raw'):
         # The decryption is handled by the Linux epoc daemon. We don't need to handle it.
         _os_decryption = True
         hidraw = open("/dev/eeg/raw")
     path, serial_number = hid_enumerate()
     if len(path) == 0:
         print("Could not find device.")
         print_hid_enumerate()
         sys.exit()
     self.serial_number = serial_number
     device = hidapi.hid_open_path(path)
     crypto = gevent.spawn(self.setup_crypto, self.serial_number)
     gevent.sleep(DEVICE_POLL_INTERVAL)
     console_updater = gevent.spawn(self.update_console)
     while self.running:
         try:
             if _os_decryption:
                 data = hidraw.read(32)
                 if data != "":
                     self.packets.put_nowait(
                         EmotivPacket(data, self.sensors, self.old_model))
             else:
                 # Doesn't seem to matter how big we make the buffer 32 returned every time, 33 for other platforms
                 data = hidapi.hid_read(device, 34)
                 if len(data) == 32:
                     # Most of the time the 0 is truncated? That's ok we'll add it... Could probably not do this...
                     data.insert(0, 0)
                 if data != "":
                     if _os_decryption:
                         self.packets.put_nowait(
                             EmotivPacket(data, self.sensors,
                                          self.old_model))
                     else:
                         # Queue it!
                         if self.write and self.write_raw:
                             self.write_data(data)
                         tasks.put_nowait(''.join(map(chr, data[1:])))
                         self.packets_received += 1
             gevent.sleep(DEVICE_POLL_INTERVAL)
         except KeyboardInterrupt:
             self.running = False
         except Exception, ex:
             print("Setup emotiv.py(line=710): %s" % ex.message)
             self.running = False
         gevent.sleep(DEVICE_POLL_INTERVAL)
Ejemplo n.º 4
0
 def receive(self):
     data = hidapi.hid_read(self.device, 10)
     frame = self.extract(data)
     if isinstance(frame, HassebDALIUSBNoDataAvailable):
         return
     elif isinstance(frame, BackwardFrame) or isinstance(frame, HassebDALIUSBNoAnswer):
         if self._pending and isinstance(frame, BackwardFrame):
             self._response_message = data
             self._pending = None
         elif self._pending and isinstance(frame, HassebDALIUSBNoAnswer):
             self._response_message = None
             self._pending = None
     return data
Ejemplo n.º 5
0
 def setup_not_windows(self):
     """
     Setup for headset on a non-windows platform.
     Receives packets from headset and sends them to a Queue to be processed
     by the crypto greenlet.
     """
     _os_decryption = False
     if os.path.exists('/dev/eeg/raw'):
         # The decryption is handled by the Linux epoc daemon. We don't need to handle it.
         _os_decryption = True
         hidraw = open("/dev/eeg/raw")
     path, serial_number = hid_enumerate()
     if len(path) == 0:
         print("Could not find device.")
         print_hid_enumerate()
         sys.exit()
     self.serial_number = serial_number
     device = hidapi.hid_open_path(path)
     crypto = gevent.spawn(self.setup_crypto, self.serial_number)
     gevent.sleep(DEVICE_POLL_INTERVAL)
     console_updater = gevent.spawn(self.update_console)
     while self.running:
         try:
             if _os_decryption:
                 data = hidraw.read(32)
                 if data != "":
                     self.packets.put_nowait(EmotivPacket(data, self.sensors, self.old_model))
             else:
                 # Doesn't seem to matter how big we make the buffer 32 returned every time, 33 for other platforms
                 data = hidapi.hid_read(device, 34)
                 if len(data) == 32:
                     # Most of the time the 0 is truncated? That's ok we'll add it... Could probably not do this...
                     data.insert(0, 0)
                 if data != "":
                     if _os_decryption:
                         self.packets.put_nowait(EmotivPacket(data, self.sensors, self.old_model))
                     else:
                         # Queue it!
                         if self.write and self.write_raw:
                             self.write_data(data)
                         tasks.put_nowait(''.join(map(chr, data[1:])))
                         self.packets_received += 1
             gevent.sleep(DEVICE_POLL_INTERVAL)
         except KeyboardInterrupt:
             self.running = False
         except Exception, ex:
             print("Setup emotiv.py(line=710): %s" % ex.message)
             self.running = False
         gevent.sleep(DEVICE_POLL_INTERVAL)
Ejemplo n.º 6
0
    def cor(self) -> bool:
        """
        [RX] Detects if there's a signal from the Radio.

        Blocks until a signal is received from the Radio.
        """
        cor_status: bool = False

        hid_read = hidapi.hid_read(self.hid_device, roip.READ_SIZE)
        self._logger.debug('read="%s"', hid_read)

        if roip.COR_START in hid_read:
            cor_status = True
        elif roip.COR_STOP in hid_read:
            cor_status = False

        self._logger.debug('cor_status="%s"', cor_status)
        return cor_status
Ejemplo n.º 7
0
#!/usr/bin/env python

import hidapi
import binascii
import time

hidapi.hid_init()
    
print 'Loaded hidapi library from: {:s}\n'.format(hidapi.hid_lib_path())

devices = hidapi.hid_enumerate(0x0483, 0x5750)
if len(devices) == 0:
    print "No dev attached"
    exit(1)

device = hidapi.hid_open(0x0483, 0x5750)


import random
while True:
    result = hidapi.hid_read(device, 4)
    state = binascii.hexlify(result)
    print "#%d: %s"  % (len(result), state)

hidapi.hid_close(device)
Ejemplo n.º 8
0
import base64
import binascii

__author__ = 'matt'

import hidapi

hidapi.hid_init()

# for dev in hidapi.hid_enumerate():
#     print '------------------------------------------------------------'
#     print dev.description()

dev = hidapi.hid_open(0x1430, 0x0150)
arr = hidapi.hid_read(dev, 1024)
report = ''.join(chr(x) for x in [0x00, 0x00, 0x00, 0x00, 0x08, 0x00])
# num = hidapi.hid_write(dev, report)
print "i don't think we'll get here"
# val = 0
# while (True):
#     arr = hidapi.hid_read(dev, 1024)
#     new_val = arr[1]
#     if new_val is not val:
#         test_one = new_val
#         test_two = hidapi.hid_read(dev, 1024)[1]
#         while test_one is not test_two:
#             test_one = test_two
#             test_two = hidapi.hid_read(dev, 1024)[1]
#         print "Got {}".format(test_two)
#         val = test_two
#         print binascii.hexlify(arr)