Packets

A 'packet' in JSLogo is a list used when reading data from the microcontroller. This list takes the following form:

[type time count adc0 adc1 adc2 adc3 adc4 adc5 checksum]

This format matches the table found in the "data" view.

Type is an arbitrary number that can be used to define the type of data in a packet.

The checksum is made up of all ADC values in that packet added together, which makes for an easy validation method when reading saved data. From the "data" view all recorded packets can be exported as a .csv file or imported from a previous save.

NameArgumentsDescription
receive-packetnoneReads all ADC values from the Arduino and constructs a packet list; adds to data table if cofigured.
set-packet-savetrue or falseConfigures receive-packet behavior to write data to the data table or not; default is false
set-packet-countnumberSet number of ADC pins (starting at 0) to read
get-packet-datanoneReturns the current data in the data tab as an array of arrays
get-packet-colstring*Returns an array of all values in the named column

*String must be a column title - 'type', 'time', 'count', 'adc0', etc.

JSLogo uses a series of system variables starting with underscores to handle data, including packets. In this case, :_last-packet will always hold the value of the most recent packet received.

The function receive-packet is defined in the standard JSLogo library:

 to receive-packet
        if (is-defined '_packet-length') = false
        [
            make '_packet-length' 6
        ]

        make '_checksum' 0

        make '_packet-type' 'T1'
        ;always T1 right now because these aren't defined yet

        let "i 0
        make '_last-packet' :_packet-type
        make "_last-packet se :_last-packet now
        make "_last-packet se :_last-packet :_packet-length

        repeat ( :_packet-length ) [
            let "_adc-holder readADC :i
            make "_last-packet se :_last-packet ( :_adc-holder )
            let 'i' :i + 1
            make "_checksum :_checksum + (:_adc-holder)
        ]

        make "_last-packet se :_last-packet :_checksum

        if (is-defined '_packet-log') = false 
        [
            make '_packet-log' false
        ]

       if (:_packet-log = true)[
            logData :_last-packet
        ]

    end

Packets can be viewed and worked with in the "data" tab of the LbyM web app. In addition to displaying data in a table, users can import and export this data as a .csv file. You can download an example file from https://lbym.sonoma.edu/ws2.csv (opens in a new tab). After downloading, import the file by clicking 'import' in the data tab and selecting the file.

Last updated on December 22, 2022