A module that contains logging event callbacks for an ANT::Channel.
Refs: * 9.5.6.1 Channel
Response / Event (0x40) [ANT Message Protocol and Usage, Rev 5.1]
The mask of the channel number in buffer data
Mapping of response message IDs to handler methods
The mask of the sequence number in buffer data
Log the channel event by default.
# File lib/ant/channel/event_callbacks.rb, line 67
def self::log_event_callback( channel_num, handler_method, event_id, data )
self.log.debug "Event on channel %d: %#0x (%s): %s" % [
channel_num,
event_id,
handler_method,
Ant::DataUtilities.hexdump( data[ 0..3 ] )
]
end
Default callback hook – handles event callbacks.
# File lib/ant/channel/event_callbacks.rb, line 54
def handle_event_callback( channel_num, event_id, data )
handler_method = HANDLER_METHODS[ event_id ] or
raise "Unhandled channel event %p" % [ event_id ]
if self.respond_to?( handler_method )
self.public_send( handler_method, channel_num, data )
else
Ant::Channel::EventCallbacks.log_event_callback( channel_num, handler_method, event_id, data )
end
end
Handle a CHANNEL_CLOSED event.
# File lib/ant/channel/event_callbacks.rb, line 118
def on_event_channel_closed( channel_num, * )
self.log.warn "Channel %d was closed." % [ channel_num ]
end
Handle a CHANNEL_COLLISION event.
# File lib/ant/channel/event_callbacks.rb, line 130
def on_event_channel_collision( channel_num, * )
self.log.warn "Channel collision on channel %d." % [ channel_num ]
end
Handle an RX_BROADCAST event.
# File lib/ant/channel/event_callbacks.rb, line 190
def on_event_rx_broadcast( channel_num, data )
self.log.info "Broadcast: Rx:\n%s" % [ hexdump(data[1..8]) ]
end
Handle an RX_BURST_PACKET event.
# File lib/ant/channel/event_callbacks.rb, line 181
def on_event_rx_burst_packet( channel_num, data )
channel = (data.bytes[0] & CHANNEL_NUMBER_MASK) >> 5
sequence_num = data.bytes[0] & SEQUENCE_NUMBER_MASK
self.log.info "Burst (0x%02x): Rx: %d:\n%s" % [ channel, sequence_num, hexdump(data[1..8]) ]
end
Handle a RX_FAIL event.
# File lib/ant/channel/event_callbacks.rb, line 94
def on_event_rx_fail( channel_num, * )
self.log.warn "Receive failed on channel %d." % [ channel_num ]
end
Handle a RX_FAIL_GO_TO_SEARCH event.
# File lib/ant/channel/event_callbacks.rb, line 124
def on_event_rx_fail_go_to_search( channel_num, * )
self.log.warn "Channel %d dropped; resume search." % [ channel_num ]
end
Handle an RX_FLAG_BROADCAST event.
# File lib/ant/channel/event_callbacks.rb, line 161
def on_event_rx_flag_broadcast( channel_num, data )
flags = data.bytes[ 9 ]
if flags & Ant::ANT_EXT_MESG_BITFIELD_DEVICE_ID
usDeviceNumber = data.bytes[10] | (data.bytes[11] << 8)
ucDeviceType = data.bytes[12]
ucTransmissionType = data.bytes[13]
self.log.info "Got a broadcast on Chan ID(%d/%d/%d)" %
[usDeviceNumber, ucDeviceType, ucTransmissionType]
end
self.on_event_rx_broadcast( channel_num, data )
end
Handle an RX_FLAG_BURST_PACKET event.
# File lib/ant/channel/event_callbacks.rb, line 146
def on_event_rx_flag_burst_packet( channel_num, data )
flags = data.bytes[ 9 ]
if flags & Ant::ANT_EXT_MESG_BITFIELD_DEVICE_ID
usDeviceNumber = data.bytes[10] | (data.bytes[11] << 8)
ucDeviceType = data.bytes[12]
ucTransmissionType = data.bytes[13]
self.log.info "Got a burst on Chan ID(%d/%d/%d)" %
[usDeviceNumber, ucDeviceType, ucTransmissionType]
end
self.on_event_rx_burst_packet( channel_num, data )
end
Handle a RX_SEARCH_TIMEOUT event.
# File lib/ant/channel/event_callbacks.rb, line 88
def on_event_rx_search_timeout( channel_num, * )
self.log.warn "Search timeout on channel %d." % [ channel_num ]
end
Handle a TRANSFER_RX_FAILED event.
# File lib/ant/channel/event_callbacks.rb, line 100
def on_event_transfer_rx_failed( channel_num, * )
self.log.warn "Receive failed on channel %d." % [ channel_num ]
end
Handle a TRANSFER_TX_COMPLETED event.
# File lib/ant/channel/event_callbacks.rb, line 106
def on_event_transfer_tx_completed( channel_num, * )
self.log.warn "Transfer completed on channel %d." % [ channel_num ]
end
Handle a TRANSFER_TX_FAILED event.
# File lib/ant/channel/event_callbacks.rb, line 112
def on_event_transfer_tx_failed( channel_num, * )
self.log.warn "Transfer failed on channel %d." % [ channel_num ]
end
Handle a TRANSFER_TX_START event.
# File lib/ant/channel/event_callbacks.rb, line 136
def on_event_transfer_tx_start( channel_num, * )
self.log.warn "Burst transfer started on channel %d." % [ channel_num ]
end
Handle an TX event.
# File lib/ant/channel/event_callbacks.rb, line 78
def on_event_tx( channel_num, data )
# self.log.info "Broadcast message on channel %d was transmitted." % [ channel_num ]
# data = SecureRandom.bytes( 8 )
# self.log.debug "Sending our own broadcast data: %p." % [ data ]
# self.send_broadcast_data( data )
end