Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

nees-adxl.c File Reference

Read from the Crossbow ADXL 2-axis accelerometer board and stream it. More...

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#include <signal.h>
#include <time.h>
#include <pthread.h>
#include <getopt.h>
#include <sys/termios.h>
#include <fcntl.h>
#include "nsds_util.h"
#include "flog.h"
#include "adxl_util.h"

Go to the source code of this file.

Data Structures

struct  thread_params_t
 Struct passed to data thread - holds TCP port descriptor and serial port. More...


Functions

int data_active_count (void)
 Return number of active channels.

bool data_channel_enabled (const int channel_id)
 Is a channel subscribed?

int data_channel_flag (const int channel_id, const bool subscribe)
 Mark a channel as subscribed or unsubscribed.

void * daq_thread_main (void *arg)
 Data handling thread.

int daq_do_work (const int control_socket, const int data_socket, const thread_params_t *thread_params)
 Main worker routine: read / parse / respond.

void daq_main_loop (const int daq_port, const char *serial_portname, const int sample_delay)
 Open network socket, loop doing work until control-c.

int main (int argc, char *argv[])
 Init the network, talk to all.


Variables

const int DAQ_PORT = 55050
 Default TCP port to listen on.

bool streaming_active
 Semaphore boolean.

const int TCP_Q_LEN = 1
 Depth of TCP queue.

struct {
   pthread_mutex_t   mutex
   bool   active [NUM_ADXL_CHANNELS]
   int   num_active
chan_struct
 Shared structure for subscribed data channels.


Detailed Description

Read from the Crossbow ADXL 2-axis accelerometer board and stream it.

Note:
Requires the flog messaging library, nsds_util lib as well
Based on fake_daq.c

Date:
4/30/03
Author:
Paul Hubbard

Definition in file nees-adxl.c.


Function Documentation

int daq_do_work const int  control_socket,
const int  data_socket,
const thread_params_t thread_params
 

Main worker routine: read / parse / respond.

Date:
9/5/02
Author:
Paul Hubbard
Return values:
0 OK, != 0 means error
Parameters:
control_socket FD of control connection
data_socket FD of data connection
thread_params Bundle of params for data thread, passed through Read commands, respond as required. Starts data thread upon receiving the first data subscription, and closes it when no more channels are streaming.

Definition at line 375 of file nees-adxl.c.

References daq_thread_main(), data_active_count(), data_channel_flag(), NUM_ADXL_CHANNELS, and streaming_active.

Referenced by daq_main_loop().

void daq_main_loop const int  daq_port,
const char *  serial_portname,
const int  sample_delay
 

Open network socket, loop doing work until control-c.

Date:
9/5/02
Note:
Opens server socket
This handles the dropped connections and other TCP errors, mostly by restarting the connects. Also kills data thread if connections die.

Parameters:
daq_port TCP port number of main server socket
serial_portname ADXL serial port, passed to data thread
sample_delay If non-zero, inter-sample delay in microseconds

Definition at line 624 of file nees-adxl.c.

References control_break, daq_do_work(), thread_params_t::delay_usec, thread_params_t::serial_port, thread_params_t::socket_fd, streaming_active, and TCP_Q_LEN.

Referenced by main().

void* daq_thread_main void *  arg  ) 
 

Data handling thread.

Transient thread to send data out the data channel. Dead simple.

Note:
Opens and closes the ADXL at thread startup and shutdown

based on fake_daq and nees-di

Parameters:
arg Ptr to thread_params_t struct
Return values:
Null always

Definition at line 245 of file nees-adxl.c.

References adxl_close(), ADXL_DATUM_LEN, adxl_open(), adxl_read(), control_break, data_active_count(), data_channel_enabled(), thread_params_t::delay_usec, adxl_reading_t::G, NUM_ADXL_CHANNELS, thread_params_t::serial_port, thread_params_t::socket_fd, and streaming_active.

Referenced by daq_do_work().

int data_active_count void   ) 
 

Return number of active channels.

Return values:
Number active, <0 if error
Note:
Common with nees-di code, roll into library?
Date:
9/27/02

Definition at line 74 of file nees-adxl.c.

References chan_struct.

Referenced by daq_do_work(), and daq_thread_main().

bool data_channel_enabled const int  channel_id  ) 
 

Is a channel subscribed?

Locks mutex and checks array to see if a channel is subscribed.

Parameters:
channel_id Channel ID to check
Return values:
True or false, false if error
Note:
uses mutex lock on chan_struct

Common with nees-di code, roll into library?

Date:
9/24/02

Definition at line 112 of file nees-adxl.c.

References chan_struct, and NUM_ADXL_CHANNELS.

Referenced by daq_thread_main().

int data_channel_flag const int  channel_id,
const bool  subscribe
 

Mark a channel as subscribed or unsubscribed.

Lock the mutex, set the bit, report if it changed.

Note:
Idempotent - call multiple times w/no harm done.
Parameters:
channel_id Channel ID in question
subscribe if true, subscribe, if false un-sub
Return values:
0 if OK, non-zero if error
Note:
Uses chan_struct and mutex therein

Common with nees-di code, roll into library?

Date:
9/24/02

Definition at line 159 of file nees-adxl.c.

References chan_struct, and NUM_ADXL_CHANNELS.

Referenced by daq_do_work().

int main int  argc,
char *  argv[]
 

Init the network, talk to all.

Parse options, installs signal handler, calls worker routine.

Note:
Driver port passed on command line

Ditto w/sample rate

Parameters:
argc Argc as passed by shell
argv Argv as passed by shell
Returns:
0 All is good

Non-zero All is not good

Definition at line 719 of file nees-adxl.c.

References ADXL_MAX_RATE_HZ, adxl_sighandler(), control_break, daq_main_loop(), DAQ_PORT, and NUM_ADXL_CHANNELS.


Variable Documentation

bool active[NUM_ADXL_CHANNELS]
 

R/W mutex for struct.

Definition at line 54 of file nees-adxl.c.

struct { ... } chan_struct
 

Shared structure for subscribed data channels.

Referenced by data_active_count(), data_channel_enabled(), and data_channel_flag().

const int DAQ_PORT = 55050
 

Default TCP port to listen on.

Definition at line 42 of file nees-adxl.c.

Referenced by main().

pthread_mutex_t mutex
 

Definition at line 53 of file nees-adxl.c.

int num_active
 

Definition at line 55 of file nees-adxl.c.

bool streaming_active
 

Semaphore boolean.

Definition at line 45 of file nees-adxl.c.

Referenced by daq_do_work(), daq_main_loop(), and daq_thread_main().

const int TCP_Q_LEN = 1
 

Depth of TCP queue.

Definition at line 48 of file nees-adxl.c.

Referenced by daq_main_loop().


Generated on Fri May 2 15:13:15 2003 for ADXL202-NEESgrid driver by doxygen1.3