Reading sensor values and controlling the MSP using IPC

From University of Washington - Ubicomp Research Page
Revision as of 21:15, 24 August 2007 by Karl Koscher (talk | contribs)

Jump to: navigation, search

Introduction

[CMU's IPC package] is a collection of software that facilities message passing between programs, including those on different hosts. It supports both publish/subscribe and request/response semantics. The msb-server and lsb-server can publish the sensor readings they receive from the sensor boards over IPC. You can easily develop your own applications to receive these sensor messages. Applications can either be message-driven or periodically poll for new sensor readings.

IPC application requirements

All IPC applications must call msp_ipc_initialize(argc, argv) before using any other IPC functions. Most IPC applications then subscribe to various messages by using the functions defined in msb_interface.h and lsb_interface.h (e.g. msb_subscribe_accel_message). When subscribing to a message, you must pass a pointer to a structure used to store the message, the function to be called that will handle the message, and if multiple messages are received between IPC polls, whether you want all messages (MSP_SUBSCRIBE_ALL) or just the latest (MSB_SUBSCRIBE_LATEST). You can also specify MSB_UNSUBSCRIBE to stop receiving messages.

IPC message handlers receive data in structures specific to the message type. These structures are defined in msb_messages.h and lsb_messages.h.

A simple IPC example

This simple example shows the bare minimum required to receive sensor readings from the MSB. It displays accelerometer readings along with their timestamps.

msb-ipc-demo.c:

  1. include <stdio.h>
  2. include <msp/msp.h>

void msb_accel_handler(msb_accel_message *data) { int i;

for (i = 0; i < data->num_samples; i++) { printf("Accel data received: X: %f, Y: %f, Z: %f, Timestamp: %d %d\n", data->sample[i].accel[0], data->sample[i].accel[1], data->sample[i].accel[2], data->sample[i].time_counter, data->sample[i].interrupt_counter); } }

int main(int argc, char *argv[]) { msb_accel_message data;

msp_ipc_initialize(argc, argv);

msb_subscribe_accel_message(&data, (msp_handler_t)msb_accel_handler, MSP_SUBSCRIBE_ALL);

IPC_dispatch();

return 0; }

Makefile:

include ../Makefile.conf

MODULE_NAME = "MSB-IPC-DEMO"
MODULE_COMMENT = "MSB/IPC Demo"

CFLAGS +=
IFLAGS +=
LFLAGS +=  -lmsb_interface -lglobal -lipc

SOURCES = msb-ipc-demo.c

PUBLIC_INCLUDES = 
PUBLIC_LIBRARIES = 
PUBLIC_BINARIES = msb-ipc-demo
MAN_PAGES =

TARGETS = msb-ipc-demo

msb-ipc-demo:    msb-ipc-demo.o

# rules

include ../Makefile.rules