예제 #1
0
파일: manager.py 프로젝트: La0/GFrun
    def __init__(self):

        self._queue = Queue.Queue()
        self._beacons = Queue.Queue()

        self._node = Node(0x0fcf, 0x1008)

        print "Request basic information..."
        m = self._node.request_message(Message.ID.RESPONSE_VERSION)
        print "  ANT version:  ", struct.unpack("<10sx", m[2])[0]
        m = self._node.request_message(Message.ID.RESPONSE_CAPABILITIES)
        print "  Capabilities: ", m[2]
        m = self._node.request_message(Message.ID.RESPONSE_SERIAL_NUMBER)
        print "  Serial number:", struct.unpack("<I", m[2])[0]

        print "Starting system..."

        NETWORK_KEY = [0xa8, 0xa4, 0x23, 0xb9, 0xf5, 0x5e, 0x63, 0xc1]

        self._node.reset_system()
        self._node.set_network_key(0x00, NETWORK_KEY)

        self._channel = self._node.new_channel(
            Channel.Type.BIDIRECTIONAL_RECEIVE)
        self._channel.on_broadcast_data = self._on_data
        self._channel.on_burst_data = self._on_data

        self.setup_channel(self._channel)

        self._worker_thread = threading.Thread(target=self._worker,
                                               name="ant.fs")
        self._worker_thread.start()
예제 #2
0
def main():
    fan.gearOff()
    logging.info("Setting:")
    i = 0
    while i < len(fan.pinlist):
        info = "*  gear " + str(i + 1) + " if heartrate greater " + str(
            myHeartrateLevel[i])
        i += 1
        logging.info(info)
    # ant device
    node = Node()
    node.set_network_key(0x00, NETWORK_KEY)
    channel = node.new_channel(Channel.Type.BIDIRECTIONAL_RECEIVE)
    # define the callback
    channel.on_broadcast_data = on_data
    channel.on_burst_data = on_data
    #
    channel.set_period(8070)
    channel.set_search_timeout(12)
    channel.set_rf_freq(57)
    channel.set_id(0, 120, 0)

    try:
        channel.open()
        node.start()
    finally:
        fan.gearOff()
        node.stop()
        GPIO.cleanup()
예제 #3
0
def main():
    # logging.basicConfig()

    monitor = Monitor()

    node = Node()
    node.set_network_key(0x00, NETWORK_KEY)

    channel = node.new_channel(Channel.Type.BIDIRECTIONAL_RECEIVE)

    channel.on_broadcast_data = monitor.on_data_heartrate
    channel.on_burst_data = monitor.on_data_heartrate

    channel.set_period(8070)
    channel.set_search_timeout(12)
    channel.set_rf_freq(57)
    channel.set_id(0, 120, 0)

    channel_cadence_speed = node.new_channel(
        Channel.Type.BIDIRECTIONAL_RECEIVE)

    channel_cadence_speed.on_broadcast_data = monitor.on_data_cadence_speed
    channel_cadence_speed.on_burst_data = monitor.on_data_cadence_speed

    channel_cadence_speed.set_period(8085)
    channel_cadence_speed.set_search_timeout(30)
    channel_cadence_speed.set_rf_freq(57)
    channel_cadence_speed.set_id(0, 121, 0)

    try:
        channel.open()
        channel_cadence_speed.open()
        node.start()
    finally:
        node.stop()
예제 #4
0
    def _open_and_start(self):
        """Open ant+ channel, if no error, start broadcast immediately"""

        # todo: add the try, catch, maybe Node not available, or network key error, or channel can't acquire

        # initialize the ant device, a node represent an ant USB device.
        self.node = Node()
        # set network key at net#0, only net#0 is used.
        self.node.set_network_key(0x00, self.network_key)

        # try get a new TX channel
        self.channel = self.node.new_channel(
            Channel.Type.BIDIRECTIONAL_TRANSMIT)
        # set the callback function for TX tick, each TX tick, this function will be called.
        self.channel.on_TX_event = self.on_tx_event

        # set the channel configurations
        self.channel.set_period(self.channel_period)
        self.channel.set_rf_freq(self.RF_frequency)
        # channel id is defined as <device num, device type, transmission type>
        self.channel.set_id(self.device_number, self.device_type,
                            self.transmission_type)

        # try open channel,
        # once opened, the channel could be found by other devices, but No data sending yet.
        try:
            self.channel.open()
            # start the message loop on the ant device.
            # once started, the messages will be dispatched to callback functions of each channel.
            self.node.start()
        finally:
            self.node.stop()
예제 #5
0
def main():
    print("ANT+ Open Rx Scan Mode Demo")
    logging.basicConfig(filename="example.log", level=logging.DEBUG)

    TimeProgramStart = time.time()  # get start time

    node = Node()
    node.set_network_key(0x00, NETWORK_KEY)  # 1. Set Network Key
    # CHANNEL CONFIGURATION
    channel = node.new_channel(Channel.Type.BIDIRECTIONAL_RECEIVE, 0x00,
                               0x00)  # 2. Assign channel

    channel.on_broadcast_data = on_data_scan
    channel.on_burst_data = on_data_scan
    channel.on_acknowledge = on_data_scan
    channel.on_acknowledge_data = on_data_ack_scan  # von mir

    channel.set_id(0, 0, 0)  # 3. Set Channel ID
    channel.set_period(0)  # 4. Set Channel Period
    channel.set_rf_freq(57)  # 5. Set RadioFrequenzy
    channel.enable_extended_messages(
        1)  # 6. Enable Extended Messages, needed for OpenRxScanMode

    try:
        channel.open_rx_scan_mode()  #  7. OpenRxScanMode
        node.start()
    except KeyboardInterrupt:
        print("Closing ANT+ Channel")
        channel.close()
        node.stop()
    finally:
        node.stop()
        logging.shutdown()  # Shutdown Logger
예제 #6
0
    def OpenChannel(self):

        self.node = Node()  # initialize the ANT+ device as node

        # CHANNEL CONFIGURATION
        self.node.set_network_key(0x00, NETWORK_KEY)  # set network key
        self.channel = self.node.new_channel(
            Channel.Type.BIDIRECTIONAL_TRANSMIT, 0x00,
            0x00)  # Set Channel, Master TX
        self.channel.set_id(
            Device_Number, Device_Type, 5
        )  # set channel id as <Device Number, Device Type, Transmission Type>
        self.channel.set_period(Channel_Period)  # set Channel Period
        self.channel.set_rf_freq(Channel_Frequency)  # set Channel Frequency

        # Callback function for each TX event
        self.channel.on_broadcast_tx_data = self.on_event_tx

        try:
            self.channel.open(
            )  # Open the ANT-Channel with given configuration
            self.node.start()
        except KeyboardInterrupt:
            print("Closing ANT+ Channel...")
            self.channel.close()
            self.node.stop()
        finally:
            print("Final checking...")
예제 #7
0
    def __init__(self):
        self.count = 0

        logging.basicConfig(filename="example.log", level=logging.DEBUG)

        node = Node()
        node.set_network_key(0x00, NETWORK_KEY)

        # Master channel configuration for Generic Control Device
        self.channel = node.new_channel(Channel.Type.BIDIRECTIONAL_TRANSMIT)
        self.channel.set_id(1, 16, 5)
        self.channel.set_period(8192)
        self.channel.set_rf_freq(57)

        # Callbacks
        self.channel.on_broadcast_tx_data = self.on_tx_data
        self.channel.on_acknowledge_data = self.on_acknowledge_data
        self.channel.on_broadcast_data = self.on_broadcast_data

        try:
            print("Opening ANT+ Channel ...")
            self.channel.open()
            node.start()
        except KeyboardInterrupt:
            print("Closing ANT+ Channel ...")
            self.channel.close()
            node.stop()
        finally:
            logging.shutdown()
예제 #8
0
    def sensor_init(self):

        if not self.config.G_ANT['STATUS']:
            global _SENSOR_ANT
            _SENSOR_ANT = False

        if _SENSOR_ANT:
            self.node = Node()
            self.node.set_network_key(self.NETWORK_NUM, self.NETWORK_KEY)

        #initialize scan channel (reserve ch0)
        self.scanner = ANT_Device_MultiScan(self.node, self.config)
        self.searcher = ANT_Device_Search(self.node, self.config, self.values)
        self.scanner.setMainAntDevice(self.device)

        #auto connect ANT+ sensor from setting.conf
        if _SENSOR_ANT and not self.config.G_DUMMY_OUTPUT:
            for key in ['HR', 'SPD', 'CDC', 'PWR']:
                if self.config.G_ANT['USE'][key]:
                    antID = self.config.G_ANT['ID'][key]
                    antType = self.config.G_ANT['TYPE'][key]
                    self.connectAntSensor(key, antID, antType, False)
            return
        #otherwise, initialize
        else:
            for key in ['HR', 'SPD', 'CDC', 'PWR']:
                self.config.G_ANT['USE'][key] = False
                self.config.G_ANT['ID'][key] = 0
                self.config.G_ANT['TYPE'][key] = 0

        #for dummy output
        if not _SENSOR_ANT and self.config.G_DUMMY_OUTPUT:
            #need to set dummy ANT+ device id 0
            self.config.G_ANT['USE'] = {
                'HR': True,
                'SPD': True,
                'CDC': True,  #same as SPD
                'PWR': True,
            }
            self.config.G_ANT['ID_TYPE'] = {
                'HR': struct.pack('<HB', 0, 0x78),
                'SPD': struct.pack('<HB', 0, 0x79),
                'CDC': struct.pack('<HB', 0, 0x79),  #same as SPD
                'PWR': struct.pack('<HB', 0, 0x0B),
            }
            self.config.G_ANT['TYPE'] = {
                'HR': 0x78,
                'SPD': 0x79,
                'CDC': 0x79,  #same as SPD
                'PWR': 0x0B,
            }
            ac = self.config.G_ANT['ID_TYPE']
            self.values[ac['HR']] = {}
            self.values[ac['SPD']] = {'distance': 0}
            self.values[ac['PWR']] = {}
            for key in [0x10, 0x11, 0x12]:
                self.values[ac['PWR']][key] = {'accumulated_power': 0}

        self.reset()
예제 #9
0
파일: scan.py 프로젝트: rdeterre/openant
def main():
    #logging.basicConfig(filename='example.log',level=logging.DEBUG)

    node = Node()
    node.set_network_key(0x00, NETWORK_KEY)

    channel_scan = node.new_channel(Channel.Type.BIDIRECTIONAL_RECEIVE,0x00,0x01)

    channel_scan.on_broadcast_data = scan_data
    channel_scan.on_burst_data = scan_data
    channel_scan.on_acknowledge = scan_data

    channel_scan.set_id(0, 120, 0)
    channel_scan.enable_extended_messages(1)
    channel_scan.set_search_timeout(0xFF)
    channel_scan.set_period(8070)
    channel_scan.set_rf_freq(57)


    channel_hrm = node.new_channel(Channel.Type.BIDIRECTIONAL_RECEIVE)

    channel_hrm.on_broadcast_data = hrm_data
    channel_hrm.on_burst_data = hrm_data
    channel_hrm.on_acknowledge = hrm_data

    channel_hrm.set_id(49024, 120, 0)
    channel_hrm.enable_extended_messages(1)
    channel_hrm.set_search_timeout(0xFF)
    channel_hrm.set_period(32280)
    channel_hrm.set_rf_freq(57)

    channel_hrm2 = node.new_channel(Channel.Type.BIDIRECTIONAL_RECEIVE)

    channel_hrm2.on_broadcast_data = hrm_data
    channel_hrm2.on_burst_data = hrm_data
    channel_hrm2.on_acknowledge = hrm_data

    channel_hrm2.set_id(25170, 120, 0)
    channel_hrm2.enable_extended_messages(1)
    channel_hrm2.set_search_timeout(0xFF)
    channel_hrm2.set_period(32280)
    channel_hrm2.set_rf_freq(57)
    try:
        channel_scan.open()
        time.sleep(10)
        channel_scan.close()
        channel_scan._unassign()
        channel_hrm.open()
        channel_hrm2.open()
        #channel_scan.open()
        node.start()
    finally:
        channel_hrm.close()
        channel_hrm._unassign()
        channel_hrm2.close()
        channel_hrm2._unassign()
        node.stop()
예제 #10
0
def main():
    def on_data(data):
        heartrate = data[7]
        string = "Heartrate: " + str(heartrate) + " [BPM]"
        
        sys.stdout.write(string)
        sys.stdout.flush()
        sys.stdout.write("\b" * len(string))
        if len(data) > 8:
            print(data)
            deviceNumberLSB = data[9]
            deviceNumberMSB = data[10]
            deviceNumber = "{}".format(deviceNumberLSB + (deviceNumberMSB << 8))
            deviceType = "{}".format(data[11])
            print("New Device Found: %s of type %s" % (deviceNumber, deviceType))
            result.append(deviceNumber)

    logging.basicConfig(filename="example.log", level=logging.DEBUG)

    result = []

    node = Node()
    node.set_network_key(0x00, NETWORK_KEY)

    print(node.ant._driver._out)

    channel = node.new_channel(Channel.Type.BIDIRECTIONAL_RECEIVE, 0x00, 0x01)

    channel.on_broadcast_data = on_data
    channel.on_burst_data = on_data
    channel.on_acknowledge = on_data

    channel.set_id(0, 120, 0)
    channel.enable_extended_messages(1)
    channel.set_search_timeout(0xFF)
    channel.set_period(8070)
    channel.set_rf_freq(57)

    try:
        node.start()
        channel.open()
        time.sleep(10)
        channel.close()
        time.sleep(0.5) #just to give the event handler to treat incoming message before unassigning it
        channel._unassign()
        result = list(set(result))
        result.sort()
        print("New Devices Found: \n %s " % (result))
    finally:
        node.stop()
예제 #11
0
파일: test.py 프로젝트: pirower/test1
    def test_search(self):

        try:
            logger = logging.getLogger("ant")
            logger.setLevel(logging.DEBUG)
            handler = logging.StreamHandler()
            handler.setFormatter(
                logging.Formatter(
                    fmt="%(asctime)s  %(name)-15s  %(levelname)-8s  %(message)s"
                ))
            logger.addHandler(handler)

            self.node = Node()
            print("Request basic information...")
            m = self.node.request_message(Message.ID.RESPONSE_ANT_VERSION)
            print("  ANT version:  ", struct.unpack("<10sx", m[2])[0])
            m = self.node.request_message(Message.ID.RESPONSE_CAPABILITIES)
            print("  Capabilities: ", m[2])
            m = self.node.request_message(Message.ID.RESPONSE_SERIAL_NUMBER)
            print("  Serial number:", struct.unpack("<I", m[2])[0])

            print("Starting system...")

            NETWORK_KEY = [0xA8, 0xA4, 0x23, 0xB9, 0xF5, 0x5E, 0x63, 0xC1]

            # self.node.reset_system()
            self.node.set_network_key(0x00, NETWORK_KEY)

            c = self.node.new_channel(Channel.Type.BIDIRECTIONAL_RECEIVE)

            c.set_period(4096)
            c.set_search_timeout(255)
            c.set_rf_freq(50)
            c.set_search_waveform([0x53, 0x00])
            c.set_id(0, 0x01, 0)

            print("Open channel...")
            c.open()
            c.request_message(Message.ID.RESPONSE_CHANNEL_STATUS)

            print("Searching...")

            self.node.start()

            print("Done")
        except KeyboardInterrupt:
            print("Interrupted")
            self.node.stop()
            sys.exit(1)
예제 #12
0
def create_node():
    node = Node()

    def thread_func():
        node.set_network_key(0x00, NETWORK_KEY)
        channel = node.new_channel(Channel.Type.BIDIRECTIONAL_RECEIVE)

        channel.on_broadcast_data = on_data
        channel.on_burst_data = on_data
        channel.set_period(8070)
        channel.set_search_timeout(12)
        channel.set_rf_freq(57)
        channel.set_id(0, 120, 0)
        channel.open()
        node.start()

    node_thread = threading.Thread(target=thread_func)
    node_thread.start()
    return node, node_thread
예제 #13
0
파일: manager.py 프로젝트: pirower/test1
    def __init__(self):

        self._queue = queue.Queue()
        self._beacons = queue.Queue()

        self._node = Node()

        try:
            NETWORK_KEY = [0xA8, 0xA4, 0x23, 0xB9, 0xF5, 0x5E, 0x63, 0xC1]
            self._node.set_network_key(0x00, NETWORK_KEY)

            print("Request basic information...")

            m = self._node.request_message(Message.ID.RESPONSE_CAPABILITIES)
            print("  Capabilities: ", m[2])

            # m = self._node.request_message(Message.ID.RESPONSE_ANT_VERSION)
            # print "  ANT version:  ", struct.unpack("<10sx", m[2])[0]

            # m = self._node.request_message(Message.ID.RESPONSE_SERIAL_NUMBER)
            # print "  Serial number:", struct.unpack("<I", m[2])[0]

            print("Starting system...")

            # NETWORK_KEY= [0xa8, 0xa4, 0x23, 0xb9, 0xf5, 0x5e, 0x63, 0xc1]
            # self._node.set_network_key(0x00, NETWORK_KEY)

            print("Key done...")

            self._channel = self._node.new_channel(
                Channel.Type.BIDIRECTIONAL_RECEIVE)
            self._channel.on_broadcast_data = self._on_data
            self._channel.on_burst_data = self._on_data

            self.setup_channel(self._channel)

            self._worker_thread = threading.Thread(target=self._worker,
                                                   name="ant.fs")
            self._worker_thread.start()
        except Exception as e:
            self.stop()
            raise e
예제 #14
0
def main():
    # logging.basicConfig()

    node = Node()
    node.set_network_key(0x00, NETWORK_KEY)

    channel = node.new_channel(Channel.Type.BIDIRECTIONAL_RECEIVE)

    channel.on_broadcast_data = on_data
    channel.on_burst_data = on_data

    channel.set_period(8070)
    channel.set_search_timeout(12)
    channel.set_rf_freq(57)
    channel.set_id(0, 120, 0)

    try:
        channel.open()
        node.start()
    finally:
        node.stop()
예제 #15
0
def main():
    node = Node()
    node.set_network_key(0x00, NETWORK_KEY)

    channel = node.new_channel(Channel.Type.BIDIRECTIONAL_RECEIVE)

    channel.on_broadcast_data = on_data
    channel.on_burst_data = on_data

    channel.set_period(8070)
    channel.set_search_timeout(12)
    channel.set_rf_freq(57)
    channel.set_id(0, 120, 0)

    try:
        channel.open()
        node.start()

    finally:
        node.stop()
        GPIO.cleanup()
        colorWipe(strip, Color(0, 0, 0), 10)
예제 #16
0
파일: scan.py 프로젝트: pwithnall/openant
def main():
    logging.basicConfig(filename='example.log', level=logging.DEBUG)

    node = Node()
    node.set_network_key(0x00, NETWORK_KEY)

    channel = node.new_channel(Channel.Type.BIDIRECTIONAL_RECEIVE, 0x00, 0x01)

    channel.on_broadcast_data = on_data
    channel.on_burst_data = on_data
    channel.on_acknowledge = on_data

    channel.set_id(0, 120, 0)
    channel.enable_extended_messages(1)
    channel.set_search_timeout(0xFF)
    channel.set_period(8070)
    channel.set_rf_freq(57)

    try:
        channel.open()
        node.start()
    finally:
        node.stop()
예제 #17
0
 def __init__(self, network_key):
     self.node = Node()
     self.node.set_network_key(0x00, network_key)
     self.ant_device_id = 1
예제 #18
0
 def __init__(self, network_key):
     self.node = Node()
     self.node.set_network_key(0x00, network_key)
        channel.set_period(8070)
        channel.set_search_timeout(255)
        channel.set_rf_freq(57)
        channel.set_id(0, 120, 0)

        return channel

    def on_data(self, data):
        self.write_file(data[7])

    def write_file(self, heartrate):
        f = file('/tmp/messages/heartrate', 'w')
        f.write('Heartrate: ' + str(heartrate))
        f.close()


logging.basicConfig()
logging.disable(logging.ERROR)

node = Node()
node.set_network_key(0x00, NETWORK_KEY)
heartrate = HeartRate()

channel_heart = heartrate.setup_channel(node)

try:
    channel_heart.open()
    node.start()
finally:
    node.stop()