Reading sensor values and controlling the MSP using IPC

From University of Washington - Ubicomp Research Page
Revision as of 20:58, 24 August 2007 by Karl Koscher (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to 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.

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:

#include <stdio.h>
#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