Polaris ADS-B Client Library

The Polaris client library provides remote access to the receiver using functions that wrap CSP protocol messages.

Frame Store

Each received ADS-B message is tagged with a 32-bit sequence number and stored in SDRAM with estimated signal strength in dBFS and a 64-bit timestamp (number of nanoseconds since midnight on January 1st, 1970). The store is a ring buffer and wraps around every 1048576 messages.

Frames can be selectively downloaded by their sequence number through the store CSP service, and provides access to the full ADS-B message and metadata.

Received frames are passed to a callback function matching sl_polaris_adsb_frame_cb_t() prototype.

The example below shows a simple frame callback function that just prints the length and first byte of received frames, and a request_frames() function that requests the last 8 frames from the CSP node on address 23. Error handling has been left out for brevity.

static int frameprint_cb(sl_polaris_adsb_store_frame_t *frame, void *arg)
{
    printf("Got a %u byte frame and the first byte is %02hhx\n",
           frame->length, frame->data[0]);
    return 0;
}

void request_frames(void)
{
     // Prepare bitmap for 8 frames
     uint8_t bitmap[SL_POLARIS_ADSB_STORE_BITMAP_SIZE] = {0xff};
     // Request from CSP node 23, call callback for each frame
     sl_polaris_adsb_store_read(23, 1000, 0, bitmap, frameprint_cb, NULL);
}

Typedefs

typedef int (*sl_polaris_adsb_frame_cb_t)(sl_polaris_adsb_store_frame_t *frame, void *arg)

Frame callback function prototype.

Callback function prototype used by store read function.

Return

0 to continue iteration over received frames, or a non-zero value to abort the iteration.

Parameters
  • frame: Pointer to structure with frame data. The structure data has been converted to host byte order.

  • arg: Arbitrary data pointer passed from the mirror/read function call. Can be used to pass any additional data required by the callback function.

Functions

int sl_polaris_adsb_store_read(uint8_t node, uint32_t timeout, uint32_t start, uint8_t *bitmap, sl_polaris_adsb_frame_cb_t cb, void *arg)

Request ADS-B frames from store.

This function requests a number of received ADS-B frames from the store. Frames are selected using a starting sequence number and a bitmap. The last sequence number to be received can be read using the store.seq property or start=0 can be used to request the most recent frames.

Frames are requested backwards from start, i.e. the start fields selects the maximum sequence number to request.

The bitmap field is used to request selected messages backwards from the start sequence number. If bit n is set, the receiver will send the message with sequence number start - n, i.e. bit 0 must be set to request the message with sequence number start. Bit 0 is the bit immediately after the start field and bit 255 is the last bit in the packet.

E.g. to request messages with sequence number 10, 9, 8, 7, 2 and 1 set:

start = 10, bitmap = [0xf0, 0xc0, 0x00, 0x00, …, 0x00]

The bitmap argument must be SL_POLARIS_ADSB_STORE_BITMAP_SIZE bytes (currently 32, allowing up to 256 frames per request).

Return

0 on success, and a negative error code on error.

Parameters
  • node: CSP address of the Polaris node.

  • timeout: Timeout of the command in milliseconds.

  • start: Start frame request number. Use 0 to request from most recent frame.

  • bitmap: Bitmap of frames from start to request.

  • cb: Frame callback function.

  • arg: Pointer argument passed to callback function.

Sample Buffer

This file provides functions to is used to read raw sample data from the Polaris sample buffer via CSP. The source can currently only be short (fixed length) bursts of full spectrum data.

The number of captured samples must be 8192 for SL_POLARIS_ADSB_SAMPLEBUF_SOURCE_RAW source.

Samples are 32-bit words consisting of 16-bit IQ channels.

Note

The sample commands write data into external SDRAM, which is automatically enabled and kept powered on after sampling. This results in a higher power consumption after the first sample request is received.

Functions

int sl_polaris_adsb_sample_read(uint8_t node, uint32_t timeout, uint8_t source, uint32_t *out, size_t outlen)

Read data from sample buffer.

The Polaris device will send the samples via CSP to the requesting node address immediately after request.

Return

0 on success, and a negative error code on error.

Parameters
  • node: CSP address of the Polaris node.

  • timeout: Timeout of the command in milliseconds.

  • source: Sample source identifier. Must be: SL_POLARIS_ADSB_SAMPLEBUF_SOURCE_RAW

  • out: Pointer to output data array.

  • outlen: Size of the output array in bytes (must be 4x number of samples).

int sl_polaris_adsb_sample_store(uint8_t node, uint32_t timeout, uint8_t source, uint8_t dest, size_t samples, uint32_t id)

Save sample buffer data.

This function is used to store raw sample data on the Polaris device for later download using BTP.

Return

0 on success, and a negative error code on error.

Parameters
  • node: CSP address of the Polaris node.

  • timeout: Timeout of the command in milliseconds.

  • source: Sample source identifier. Must be: SL_POLARIS_ADSB_SAMPLEBUF_SOURCE_RAW

  • dest: Destination identifier. Must be one of: SL_POLARIS_ADSB_SAMPLEBUF_DEST_CSP SL_POLARIS_ADSB_SAMPLEBUF_DEST_MEM SL_POLARIS_ADSB_SAMPLEBUF_DEST_SDCARD

  • samples: Number of samples to store.

  • id: Identification number of sample. Samples stored to the SD-card will be named s<id>.bin, e.g. s1000.bin for sample ID 1000.

Bootloader

This file contains functions to configure the boot process on a Polaris system.

The system is delivered with a factory firmware flashed in the first half of internal flash. An alternate image can be flashed on orbit in the alternate partion in the second half of internal flash. An alternate firmware image (ending in “-alt.bin”) must be transferred to the SD-card using BTP and can then be flashed to the alternate partition using the sl_polaris_adsb_bootloader_flash_alternate function.

Functions

int sl_polaris_adsb_bootloader_set_alternate(uint8_t node, uint32_t timeout, uint8_t boots)

Request boot of the alternate image.

The boots argument can be set 0 to boot the factory firmware. Note that a system reset, e.g. using CSP reboot or external power cycle, is required after this command to actually boot the image.

After boots boot cycles, the system will return to the factory firmware.

Return

0 on success, negative error code otherwise.

Parameters
  • node: CSP address of the property node.

  • timeout: Timeout of the command in milliseconds.

  • boots: Number of boots to boot the alternate image.

int sl_polaris_adsb_bootloader_flash_alternate(uint8_t node, uint32_t timeout, const char *filename, uint32_t *crc)

Flash image file from SD-card to alternate partition.

This function flashes a firmware file from the SD-card to the alternate flash partion. It is not necessary to erase the partition first.

The system calculates the checksum of the file and verifies the contents of the flash after programming. The calculated checksum is returned in the crc argument and can be used to verify the value on ground.

Flashing and verifying a firmware image typically takes 15-30 seconds, so ensure that the timeout is set sufficiently high.

It is not possible to flash an image when the alternate image is running. It must be performed from the factory image.

Warning

The firmware file must be an “-alt” variant binary.

Return

0 on success, negative error code otherwise.

Parameters
  • node: CSP address of the property node.

  • timeout: Timeout of the command in milliseconds.

  • filename: Filename of the remote file to flash.

  • crc: Returned CRC32C checksum of flashed file.

int sl_polaris_adsb_bootloader_erase_alternate(uint8_t node, uint32_t timeout)

Erase alternate image partition.

Erase the contents of the alternate firmware partition.

Erasing the alternate firmware partition typically takes 10-15 seconds, so ensure that the timeout is set sufficiently high.

It is not possible to erase the alternate image partition when the alternate image is running. It must be performed from the factory image.

Return

0 on success, negative error code otherwise.

Parameters
  • node: CSP address of the property node.

  • timeout: Timeout of the command in milliseconds.

int sl_polaris_adsb_bootloader_checksum_alternate(uint8_t node, uint32_t timeout, uint32_t size, uint32_t *crc)

Calculate checksum of alternate partition contents.

This function calculates the CRC32C checksum of the contents of the alternate partition, and returns the result in the crc argument. The calculation always starts from the beginning of the alternate partition.

Return

0 on success, negative error code otherwise.

Parameters
  • node: CSP address of the property node.

  • timeout: Timeout of the command in milliseconds.

  • size: Number of bytes to checksum.

  • crc: Returned CRC32C checksum of flashed file.

Remote Command

This file provides functions for running debug shell commands remotely. It is meant as a debugging aid and should not be required during normal operation of the device.

Functions

int sl_polaris_adsb_shell_run(uint8_t node, uint32_t timeout, const char *cmd)

Run debug shell command.

This function allows debug shell commands to be run on the Polaris system. The command is evaluated on the remote systems, and the command return value is returned. Output from the command is not available.

Return

0 on success, and a negative error code on error.

Parameters
  • node: CSP address of the property node.

  • timeout: Timeout of the command in milliseconds.

  • cmd: Command to execute

Protocol Specification

This file specifies the available CSP services and ports on the Polaris receiver. It should not be necessary for clients to use these definitions directly. Instead, use the wrapper functions from this library which handles the protocol and performs necessary byte order conversion.

Defines

SL_POLARIS_ADSB_DEFAULT_ADDRESS

Default CSP address.

SL_POLARIS_ADSB_PORT_SAMPLEBUF

CSP ports.

SL_POLARIS_ADSB_PORT_STORE
SL_POLARIS_ADSB_PORT_BOOTLOADER
SL_POLARIS_ADSB_PORT_SHELL
SL_POLARIS_ADSB_PORT_STORE_MIRROR_RECV

Default mirror frame receive port.

SL_POLARIS_ADSB_ERR_NONE

Error codes.

SL_POLARIS_ADSB_ERR_INVAL
SL_POLARIS_ADSB_ERR_IO
SL_POLARIS_ADSB_ERR_NOMEM
SL_POLARIS_ADSB_ERR_BUSY
SL_POLARIS_ADSB_SAMPLEBUF_READ_REQ
SL_POLARIS_ADSB_SAMPLEBUF_READ_REP
SL_POLARIS_ADSB_SAMPLEBUF_READ_CHUNK
SL_POLARIS_ADSB_SAMPLEBUF_FREE
SL_POLARIS_ADSB_SAMPLEBUF_SOURCE_RAW
SL_POLARIS_ADSB_SAMPLEBUF_DEST_CSP
SL_POLARIS_ADSB_SAMPLEBUF_DEST_MEM
SL_POLARIS_ADSB_SAMPLEBUF_DEST_SDCARD
SL_POLARIS_ADSB_SAMPLEBUF_FL_FORCE_INTRAM
SL_POLARIS_ADSB_SAMPLEBUF_READ_CHUNK_SAMPLES
SL_POLARIS_ADSB_STORE_FRAME
SL_POLARIS_ADSB_STORE_READ_REQ
SL_POLARIS_ADSB_STORE_READ_REP
SL_POLARIS_ADSB_STORE_BITMAP_SIZE
SL_POLARIS_ADSB_STORE_MAX_FRAMELEN
SL_POLARIS_ADSB_STORE_FLAG_CORRECTED
SL_POLARIS_ADSB_STORE_FLAG_TS_VALID
SL_POLARIS_ADSB_BOOTLOADER_SET_REQ
SL_POLARIS_ADSB_BOOTLOADER_SET_REP
SL_POLARIS_ADSB_BOOTLOADER_FLASH_REQ
SL_POLARIS_ADSB_BOOTLOADER_FLASH_REP
SL_POLARIS_ADSB_BOOTLOADER_ERASE_REQ
SL_POLARIS_ADSB_BOOTLOADER_ERASE_REP
SL_POLARIS_ADSB_BOOTLOADER_CHECKSUM_REQ
SL_POLARIS_ADSB_BOOTLOADER_CHECKSUM_REP
SL_POLARIS_ADSB_BOOTLOADER_SET_KEY
SL_POLARIS_ADSB_BOOTLOADER_FLASH_KEY
SL_POLARIS_ADSB_BOOTLOADER_ERASE_KEY
SL_POLARIS_ADSB_BOOTLOADER_FILENAME_MAX
SL_POLARIS_ADSB_SHELL_RUN_REQ
SL_POLARIS_ADSB_SHELL_RUN_REP
SL_POLARIS_ADSB_SHELL_RUN_KEY
SL_POLARIS_ADSB_SHELL_RUN_MAX
struct sl_polaris_adsb_req_t

Public Members

uint8_t type
struct sl_polaris_adsb_rep_t

Public Members

uint8_t type
uint8_t error
struct sl_polaris_adsb_samplebuf_read_req_t

Public Members

uint8_t type
uint8_t source
uint8_t dest
uint8_t flags
uint32_t id
uint32_t samples
struct sl_polaris_adsb_samplebuf_read_rep_t

Public Members

uint8_t type
uint8_t error
uint32_t id
uint32_t addr
struct sl_polaris_adsb_samplebuf_read_chunk_t

Public Members

uint8_t type
uint8_t error
uint16_t seq
uint16_t total
uint32_t data[32]
struct sl_polaris_adsb_samplebuf_free_req_t

Public Members

uint8_t type
uint8_t flags
uint32_t addr
struct sl_polaris_adsb_samplebuf_free_rep_t

Public Members

uint8_t type
uint8_t error
struct sl_polaris_adsb_store_read_req_t

Public Members

uint8_t type
uint32_t start
uint8_t bitmap[32]
struct sl_polaris_adsb_store_frame_t

Public Members

uint8_t type

Must be SL_POLARIS_ADSB_STORE_FRAME.

uint8_t error

Error code.

uint32_t seq

Sequence number of this frame.

uint64_t time

Time of reception (nanoseconds since 1/1/1970)

int16_t rssi

Signal power.

uint16_t flags

Flags.

uint8_t data[14]

Raw Mode-S message.

struct sl_polaris_adsb_bootloader_set_req_t

Public Members

uint8_t type
uint8_t flags
uint8_t boots
uint32_t key
struct sl_polaris_adsb_bootloader_set_rep_t

Public Members

uint8_t type
uint8_t error
struct sl_polaris_adsb_bootloader_flash_req_t

Public Members

uint8_t type
uint8_t flags
uint32_t key
uint8_t filename[40]
struct sl_polaris_adsb_bootloader_flash_rep_t

Public Members

uint8_t type
uint8_t error
uint32_t checksum
struct sl_polaris_adsb_bootloader_erase_req_t

Public Members

uint8_t type
uint8_t flags
uint32_t key
struct sl_polaris_adsb_bootloader_erase_rep_t

Public Members

uint8_t type
uint8_t error
struct sl_polaris_adsb_bootloader_checksum_req_t

Public Members

uint8_t type
uint8_t flags
uint32_t size
struct sl_polaris_adsb_bootloader_checksum_rep_t

Public Members

uint8_t type
uint8_t error
uint32_t checksum
struct sl_polaris_adsb_shell_run_req_t

Public Members

uint8_t type

Must be SL_POLARIS_ADSB_SHELL_RUN_REQ.

uint8_t flags

Flags, currently unused - set to zero.

uint32_t key

Must be SL_POLARIS_ADSB_SHELL_RUN_KEY.

uint8_t cmd[100]

Command to execute.

struct sl_polaris_adsb_shell_run_rep_t

Public Members

uint8_t type

Must be SL_POLARIS_ADSB_SHELL_RUN_REP.

uint8_t error

Error code.