![]() |
SCAMP-5c SPI Interface
1.0.0
SCAMP-5c is connected to the flight computer via a SPI interface
|
the SPI interface hosting class More...
#include <Scamp5cHost.hpp>
Public Member Functions | |
void | SetupSpi (scamp5c_spi_ht *spi_class) |
assign the SPI interface class to operate upon More... | |
void | Open () |
open the spi interface and initialize the host | |
void | Close () |
close the spi interface and terminate the host | |
void | Process () |
process any present packet More... | |
void | RegisterStandardOutputCallback (int type, std::function< void(Scamp5cHost *)> func) |
register a function to be called when a type of standard packet is received More... | |
void | RegisterGenericPacketCallback (std::function< void(Scamp5cHost *)> func) |
register a function to be called when a generic packet is received More... | |
uint32_t | GetDataDim (int d) |
this function can only be used within a packet callback function to get the dimension of the data More... | |
uint8_t * | GetData () |
this function can only be used within a packet callback function to get the data More... | |
scamp5c_spi::packet * | GetPacket () |
get the orgininal packet class received (can be used only in packet callback) More... | |
void | SetInputPort (int i, uint8_t u) |
set the value of SPI_RX_* port on the IPU | |
uint32_t | GetPacketCount () |
double | GetPacketRate () |
uint32_t | GetLoopCounter () |
uint32_t | GetLoopCounterError () |
void | RegisterErrorCallback (std::function< void(Scamp5cHost *)> func) |
void | ResetCounters () |
int | SaveFrameBMP (const char *filepath) |
scamp5c_spi_ht * | GetSpiClass (void) |
Protected Member Functions | |
uint8_t & | data (size_t r, size_t c) |
void | format_data_buffer (size_t r, size_t c) |
void | update_loop_counter (uint32_t new_lc) |
void | update_packet_rate (uint32_t n) |
void | process_std_loopc (scamp5c_spi::packet *pkt) |
void | process_std_aout (scamp5c_spi::packet *pkt) |
void | process_std_dout (scamp5c_spi::packet *pkt) |
void | process_std_target (scamp5c_spi::packet *pkt) |
void | process_std_events (scamp5c_spi::packet *pkt) |
void | process_std_appinfo (scamp5c_spi::packet *pkt) |
Static Protected Member Functions | |
static int | save_bmp24 (const char *filename, uint32_t width, uint32_t height, const uint8_t *data) |
Protected Attributes | |
scamp5c_spi_ht * | Scamp5spi |
jcStopwatch | PacketStopwatch |
double | host_packet_rate |
double | host_packet_rate_e |
uint32_t | host_packet_count |
scamp5c_spi::packet * | original_packet |
int | data_type |
uint16_t | data_dim_r |
uint16_t | data_dim_c |
uint8_t * | data_ptr |
uint8_t * | data_buffer |
uint32_t | loop_counter |
int | loop_counter_error |
std::function< void(Scamp5cHost *)> | standard_output_callback [8] |
std::function< void(Scamp5cHost *)> | generic_packet_callback |
std::function< void(Scamp5cHost *)> | error_callback |
the SPI interface hosting class
This class handles the packets received from a SPI interface class so that standard packets are recognized and handled differently, while still maintaining the capability for user to deal with arbitart data packet.
void Scamp5cHost::SetupSpi | ( | scamp5c_spi_ht * | spi_class | ) |
assign the SPI interface class to operate upon
Before using Scamp5cHost::Open to start the hosting class, a spi interface class must be created and assigned to the hosting class using this function.
For example, a typical initialization procedure:
void Scamp5cHost::Process | ( | ) |
process any present packet
This function process packets in queue and calling the registered callback functions. It shall be called routinely within the main loop of a application.
Note, the spi interface mechanism is processed in a seperate thread while the callback functions regestered for this hosting class are called internally by this function and hence in the same thread calling this function.
void Scamp5cHost::RegisterStandardOutputCallback | ( | int | type, |
std::function< void(Scamp5cHost *)> | func | ||
) |
register a function to be called when a type of standard packet is received
func | a function which takes a pointer to Scamp5cHost and returns void |
Valid types:
type | spi macro |
---|---|
S5C_SPI_LOOPC | spi.send_loop_counter |
S5C_SPI_AOUT | spi.aout, spi.aout64 |
S5C_SPI_DOUT | spi.dout |
S5C_SPI_TARGET | spi.scan_target |
S5C_SPI_EVENTS | spi.scan_events |
void Scamp5cHost::RegisterGenericPacketCallback | ( | std::function< void(Scamp5cHost *)> | func | ) |
register a function to be called when a generic packet is received
func | a function which takes a pointer to Scamp5cHost and returns void |
|
inline |
this function can only be used within a packet callback function to get the dimension of the data
d | dimension option |
In general, data in standard packet are two-dimensional which means they are organized into rows and columns. For different packet callbacks, the definition of the dimensions are different. The following chart manifest the definition:
type | d = 0 | d = 1 |
---|---|---|
S5C_SPI_LOOPC | constant: 1 | constant: 4 |
S5C_SPI_AOUT | frame height | frame width |
S5C_SPI_DOUT | frame height | frame width |
S5C_SPI_TARGET | constant: 2 | constant: 2 |
S5C_SPI_EVENTS | points count | constant: 2 |
|
inline |
this function can only be used within a packet callback function to get the data
For different types of standard packet, the interpretation of the data is different:
type | interpretation |
---|---|
S5C_SPI_LOOPC | a 32-bit unsigned integer |
S5C_SPI_AOUT | row-major bitmap, one byte per pixel |
S5C_SPI_DOUT | row-major bitmap, one byte per pixel |
S5C_SPI_TARGET | two 2-D coordinates pair: x0, y0; x1, y1; |
S5C_SPI_EVENTS | N 2-D coordinates pair: x0, y0; x1, y1; ... |
|
inline |
get the orgininal packet class received (can be used only in packet callback)
This is usually used to process data from a generic packet.
See scamp5c_spi::packet for more details.