Polaris Client Library¶
The Polaris client library provides remote access to the receiver using functions that wrap CSP protocol messages.
Frame Store¶
Each received AIS message is tagged with a 32-bit sequence number and stored in NOR-flash with reception metadata (estimated center frequency offset, signal level) and a 64-bit timestamp (number of nanoseconds since midnight on January 1st, 1970).
All 1-5 slot messages are stored in the same store, and consumes 256 bytes of NOR flash, including metadata, independent on the number of slots in the message. The store is a ring buffer and wraps around every 261120 messages.
Frames can be selectively downloaded by their sequence number through the store CSP service, and provides access to the full AIS messages and metadata.
If an external store is preferred, the mirror mode can be used to forward all received frames to another CSP node. Refer to sl_polaris_store_mirror() for this functionality.
Both the normal frame request and mirror frames pass received frames to a callback function matching sl_polaris_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 20. Error handling has been left out for brevity.
static int frameprint_cb(sl_polaris_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_STORE_BITMAP_SIZE] = {0xff};
// Request from CSP node 20, call callback for each frame
sl_polaris_store_read(20, 1000, 0, bitmap, frameprint_cb, NULL);
}
Typedefs
-
typedef int (*
sl_polaris_frame_cb_t
)(sl_polaris_store_frame_t *frame, void *arg)¶ Frame callback function prototype.
Callback function prototype used by store mirror and read functions.
- 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_store_mirror
(uint8_t node, uint32_t timeout, uint8_t dest_node, uint8_t dest_port, uint32_t time_ms)¶ Request store frame mirroring.
This function requests the Polaris to mirror received frames to another CSP system.
The
time_ms
specifies the amount of time the system should keep sending frames. This ensures that the receiver will eventually stop sending frames if the mirror client no longer waits for frames. A client can extend the mirror period by sending a new mirror request before the timeout expires.- 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.dest_node
: Destination CSP address.dest_port
: Destination CSP port.time_ms
: Milliseconds the system should mirror frames for.
-
int
sl_polaris_store_mirror_recv
(uint8_t node, uint32_t timeout, sl_polaris_frame_cb_t cb, void *arg)¶ Receive mirror frames from device.
This function requests frame mirroring and calls the
cb
function for each received frame. It automatically refreshes the mirror timeout every 60 seconds.- 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.cb
: Frame callback function.arg
: Pointer argument passed to callback function.
-
int
sl_polaris_store_read
(uint8_t node, uint32_t timeout, uint32_t start, uint8_t *bitmap, sl_polaris_frame_cb_t cb, void *arg)¶ Request AIS frames from store.
This function requests a number of received AIS 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_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 or store sample data from the Polaris sample buffer via CSP.
The source can be either short (fixed length) bursts of full spectrum data or variable length samples from one of the 4 AIS channels.
The number of captured samples must be 8192 for SL_POLARIS_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_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 one of: SL_POLARIS_SAMPLEBUF_SOURCE_RAW SL_POLARIS_SAMPLEBUF_SOURCE_CH1 SL_POLARIS_SAMPLEBUF_SOURCE_CH2 SL_POLARIS_SAMPLEBUF_SOURCE_CH3 SL_POLARIS_SAMPLEBUF_SOURCE_CH4out
: Pointer to output data array.outlen
: Size of the output array in bytes (must be 4x number of samples).
-
int
sl_polaris_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 one of: SL_POLARIS_SAMPLEBUF_SOURCE_RAW SL_POLARIS_SAMPLEBUF_SOURCE_CH1 SL_POLARIS_SAMPLEBUF_SOURCE_CH2 SL_POLARIS_SAMPLEBUF_SOURCE_CH3 SL_POLARIS_SAMPLEBUF_SOURCE_CH4dest
: Destination identifier. Must be one of: SL_POLARIS_SAMPLEBUF_DEST_CSP SL_POLARIS_SAMPLEBUF_DEST_MEM SL_POLARIS_SAMPLEBUF_DEST_SDCARDsamples
: 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_bootloader_flash_alternate function.
Functions
-
int
sl_polaris_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_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_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_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_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_DEFAULT_ADDRESS
¶ Default CSP address.
-
SL_POLARIS_PORT_SAMPLEBUF
¶ CSP ports.
-
SL_POLARIS_PORT_STORE
¶
-
SL_POLARIS_PORT_BOOTLOADER
¶
-
SL_POLARIS_PORT_SHELL
¶
-
SL_POLARIS_PORT_STORE_MIRROR_RECV
¶ Default mirror frame receive port.
-
SL_POLARIS_ERR_NONE
¶ Error codes.
-
SL_POLARIS_ERR_INVAL
¶
-
SL_POLARIS_ERR_IO
¶
-
SL_POLARIS_ERR_NOMEM
¶
-
SL_POLARIS_ERR_BUSY
¶
-
SL_POLARIS_SAMPLEBUF_READ_REQ
¶
-
SL_POLARIS_SAMPLEBUF_READ_REP
¶
-
SL_POLARIS_SAMPLEBUF_READ_CHUNK
¶
-
SL_POLARIS_SAMPLEBUF_FREE
¶
-
SL_POLARIS_SAMPLEBUF_SOURCE_RAW
¶
-
SL_POLARIS_SAMPLEBUF_SOURCE_CH1
¶
-
SL_POLARIS_SAMPLEBUF_SOURCE_CH2
¶
-
SL_POLARIS_SAMPLEBUF_SOURCE_CH3
¶
-
SL_POLARIS_SAMPLEBUF_SOURCE_CH4
¶
-
SL_POLARIS_SAMPLEBUF_DEST_CSP
¶
-
SL_POLARIS_SAMPLEBUF_DEST_MEM
¶
-
SL_POLARIS_SAMPLEBUF_DEST_SDCARD
¶
-
SL_POLARIS_SAMPLEBUF_FL_FORCE_INTRAM
¶
-
SL_POLARIS_SAMPLEBUF_READ_CHUNK_SAMPLES
¶
-
SL_POLARIS_STORE_FRAME
¶
-
SL_POLARIS_STORE_MIRROR_REQ
¶
-
SL_POLARIS_STORE_MIRROR_REP
¶
-
SL_POLARIS_STORE_READ_REQ
¶
-
SL_POLARIS_STORE_READ_REP
¶
-
SL_POLARIS_STORE_MAX_DATALEN
¶
-
SL_POLARIS_STORE_FRAME_OVERHEAD
¶
-
SL_POLARIS_STORE_BITMAP_SIZE
¶
-
SL_POLARIS_BOOTLOADER_SET_REQ
¶
-
SL_POLARIS_BOOTLOADER_SET_REP
¶
-
SL_POLARIS_BOOTLOADER_FLASH_REQ
¶
-
SL_POLARIS_BOOTLOADER_FLASH_REP
¶
-
SL_POLARIS_BOOTLOADER_ERASE_REQ
¶
-
SL_POLARIS_BOOTLOADER_ERASE_REP
¶
-
SL_POLARIS_BOOTLOADER_CHECKSUM_REQ
¶
-
SL_POLARIS_BOOTLOADER_CHECKSUM_REP
¶
-
SL_POLARIS_BOOTLOADER_SET_KEY
¶
-
SL_POLARIS_BOOTLOADER_FLASH_KEY
¶
-
SL_POLARIS_BOOTLOADER_ERASE_KEY
¶
-
SL_POLARIS_BOOTLOADER_FILENAME_MAX
¶
-
SL_POLARIS_SHELL_RUN_REQ
¶
-
SL_POLARIS_SHELL_RUN_REP
¶
-
SL_POLARIS_SHELL_RUN_KEY
¶
-
SL_POLARIS_SHELL_RUN_MAX
¶
-
struct
sl_polaris_rep_t
¶
-
struct
sl_polaris_samplebuf_read_req_t
¶
-
struct
sl_polaris_samplebuf_read_rep_t
¶
-
struct
sl_polaris_samplebuf_read_chunk_t
¶
-
struct
sl_polaris_samplebuf_free_req_t
¶
-
struct
sl_polaris_samplebuf_free_rep_t
¶
-
struct
sl_polaris_store_frame_t
¶ Public Members
-
uint8_t
type
¶ Must be SL_POLARIS_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)
-
uint8_t
channel
¶ AIS channel this message was received on.
-
uint16_t
scale
¶ Signal scale.
-
int16_t
mean
¶ Estimated frequency offset.
-
uint8_t
length
¶ Number of bytes in data field.
-
uint8_t
data
[135]¶ Raw AIS message, excludes flag bytes, includes FCS.
-
uint8_t
-
struct
sl_polaris_store_mirror_req_t
¶
-
struct
sl_polaris_store_mirror_rep_t
¶
-
struct
sl_polaris_store_read_req_t
¶
-
struct
sl_polaris_store_read_rep_t
¶
-
struct
sl_polaris_bootloader_set_req_t
¶
-
struct
sl_polaris_bootloader_set_rep_t
¶
-
struct
sl_polaris_bootloader_flash_req_t
¶
-
struct
sl_polaris_bootloader_flash_rep_t
¶
-
struct
sl_polaris_bootloader_erase_req_t
¶
-
struct
sl_polaris_bootloader_erase_rep_t
¶
-
struct
sl_polaris_bootloader_checksum_req_t
¶
-
struct
sl_polaris_bootloader_checksum_rep_t
¶
-
struct
sl_polaris_shell_run_req_t
¶
-
struct
sl_polaris_shell_run_rep_t
¶