Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
code for parsing xbee protocol in python with touch designer
#
# dat - the DAT that received the data
# rowIndex - the row number the data was placed into
# message - an ascii representation of the data
# Unprintable characters and unicode characters will
# not be preserved. Use the 'bytes' parameter to get
# the raw bytes that were sent.
# bytes - byte array of the data received
import binascii
incoming = []
def parse_packet(which_packet):
adc_start = 11
num_samples = which_packet[8]
total = 0
j = 0
address = which_packet[5] + which_packet[4] * 256
for i in range(0, num_samples):
j = i + 2
high_value = which_packet[j+adc_start]
low_value = which_packet[(j + 1) + adc_start]
print("high value ", high_value)
print("low value ", low_value)
this_sample = (high_value * 256) + low_value
total = total + this_sample
average = total / num_samples
print("average", average)
return average
def onReceive(dat, rowIndex, message, bytes):
value = ord(bytes)
if (value == 0x7E):
if (len(incoming) == 22):
parse_packet(incoming)
incoming.clear()
incoming.append(value)
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.