You are on page 1of 1

There are several variables used throughout this program.

The
DEVICE_TYPE is the type of device with ANT+ technology we’re
working with, and the PERIOD refers to how often the sensor is
expected to send new data. The other variables relate to the con‐
figuration of the radio, and the data received from it (the data
variable).

This class represents the value from the sensor that we’re inter‐
ested in: the current temperature.

The data from the sensor comes back as data pages. This class
reads through each page, parsing the payload contained in the
page, and extracts the current temperature from it. The parse()
function calls the parseCurrentTemp() function and stores the
value it gets from it into the currentTemp field of the TempeData
variable, data.

This function receives the ANT message and extracts the cur‐
rent temperature from it. The ANT message comes in as an
array of bytes; elements 6 and 7 are the least significant and
most significant byte that, when combined, give us a two-byte
integer that contains the temperature.
The range of numbers that can be represented in two bytes is 0
to 65,535. Divided by 100, that gives us a range of 0 to 655.35
degrees, in .01 degree increments. However, temperatures can
be negative, so the values 0 to 32767 represent 0 to 327.67
degrees, while the values 32768 to 65535 represent the range
-327.67 to 0 degrees. Technically, 0 represents positive 0 and
65535 represents negative 0, but they are numerically equiva‐
lent.

This function assigns a radio channel for the ANT network,


then configures the device to communicate with the tempe sen‐
sor. It then creates a new TempeData object and stores it in the
data variable.

The open() function reopens the ANT communications chan‐


nel.

This closeSensor() function closes the ANT communications


channel.

Read Data from a Sensor | 49

You might also like