33 #if defined(PIOS_INCLUDE_OMNIP)
35 #define PIOS_OMNIP_DEV_MAGIC 0x506e6d4f
44 char line_buffer[RX_BUF_LEN];
55 static void PIOS_OMNIP_ProcessMessage(
omnip_dev_t dev)
59 dev->rf_data.
velocity = strtof(dev->line_buffer, &endptr);
61 if (endptr == dev->line_buffer) {
65 dev->rf_data.velocity_status =
true;
66 dev->rf_data.range_status =
false;
75 dev->rf_data.range = strtof(begin, &endptr);
77 if (endptr == begin) {
81 dev->rf_data.range_status =
true;
88 printf(
"Passing on ranging data; vel=[%0.3f]%s range=[%0.3f]%s\n",
89 dev->rf_data.velocity,
90 dev->rf_data.velocity_status ?
"" :
"(INVALID)",
92 dev->rf_data.range_status ?
"" :
"(INVALID)");
99 if (dev->num_received > 2) {
112 static void PIOS_OMNIP_UpdateState(
omnip_dev_t dev, uint8_t c)
117 if ((dev->line_pos > 0) && (dev->line_pos < RX_BUF_LEN)) {
118 dev->line_buffer[dev->line_pos] = 0;
120 PIOS_OMNIP_ProcessMessage(dev);
126 }
else if (c ==
'\n') {
132 if (dev->line_pos != 0) {
133 dev->line_pos = RX_BUF_LEN;
136 if (dev->line_pos < RX_BUF_LEN) {
137 dev->line_buffer[dev->line_pos] = (char) c;
144 static uint16_t PIOS_OMNIP_RxInCallback(uintptr_t context,
155 for (uint8_t
i = 0;
i < buf_len;
i++) {
156 PIOS_OMNIP_UpdateState(dev, buf[
i]);
181 **dev = (
struct omnip_dev_s) {
182 .magic = PIOS_OMNIP_DEV_MAGIC,
188 if (!(*dev)->queue) {
197 (driver->
bind_rx_cb)(lower_id, PIOS_OMNIP_RxInCallback, (uintptr_t) *dev);
struct pios_queue * PIOS_Queue_Create(size_t queue_length, size_t item_size)
Main PiOS header to include all the compiled in PiOS options.
bool PIOS_Queue_Send(struct pios_queue *queuep, const void *itemp, uint32_t timeout_ms)
void * PIOS_malloc_no_dma(size_t size)
Pios sensor structure for generic rangefinder data.
int32_t PIOS_SENSORS_Register(enum pios_sensor_type type, struct pios_queue *queue)
Register a queue-based sensor with the PIOS_SENSORS interface.
int32_t PIOS_OMNIP_Init(omnip_dev_t *dev, const struct pios_com_driver *driver, uintptr_t lower_id)
Allocate and initialise OMNIP device.
struct omnip_dev_s * omnip_dev_t
int printf(const char *format,...)
static struct pios_queue * queue
void(* bind_rx_cb)(uintptr_t id, pios_com_callback rx_in_cb, uintptr_t context)
Generic interface for sensors.
#define PIOS_Assert(test)