#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <sys/errno.h>
#include <sys/times.h>
#include <sys/termios.h>
#include <fcntl.h>
#include <stdint.h>
#include <time.h>
#include <signal.h>
#include <stdbool.h>
Go to the source code of this file.
Data Structures | |
| struct | daq_reading_t |
Defines | |
| #define | SERIAL_NUM_LEN 10 |
| Length of DI-194's internal serial number, in characters. | |
Typedefs | |
| typedef uint8_t | daq_buf_t [8] |
| Typedef for serial buffering. | |
Enumerations | |
| enum | di_rate_t { DI_RATE_INVALID, DI_RATE_60HZ, DI_RATE_120HZ, DI_RATE_240HZ, DI_RATE_UNKNOWN } |
Functions | |
| int | di_serial_init (const char *COMPORT_FILE) |
| Open port and configure control lines, etc. | |
| int | min (const int A, const int B) |
| Hardwired min fn. | |
| void | hex_print_byte (const uint8_t in_byte) |
| Super-quick hack to hex-print a character, with ASCII if printable. | |
| int | di_serial_read (const int COMM_FD, const uint8_t *buf, const int READ_LEN, const time_t TIMEOUT) |
| Read with timeout from a file descriptor. | |
| void | di_cmd_print (const uint8_t *cmd, const int CMD_LEN) |
| Debug routine to print a command to stderr. | |
| bool | is_reset_cmd (const uint8_t *cmd, const int CMD_LEN) |
| Function to compare an input command to the reset command. | |
| int | di_daq_sync (const int COMM_FD) |
| Function to re-sync with the incoming stream of samples. | |
| int | di_cmd_send (const int COMM_FD, const uint8_t *cmd, const int CMD_LEN) |
| Send a command to the unit and get the reply. | |
| int | di_initialize (const int COMM_FD, int *num_bits) |
| Function to init comms with a DI-194 once the port is setup. | |
| int | di_configure (const int COMM_FD) |
| Program DI-194 for continuous DAQ. | |
| int | di_buf_decode (const daq_buf_t buf, daq_reading_t *result, const int NUM_BITS) |
| Convert from raw data into float, raw and bit format. | |
| int | di_buf_validate (const daq_buf_t buf) |
| Check that a buffer matches the expected structure. | |
| char * | di_byte_print (const uint8_t in_byte) |
| Nasty hack to print a byte as bits. | |
| int | di_open (const char *COMPORT_FILE, int *num_bits) |
| User-called routine to open the port, program DI194. | |
| int | di_close (const int COMM_FD) |
| Shut down DI194. | |
| int | di_read (const int COMM_FD, daq_reading_t *data, const int NUM_BITS) |
| User-called routine to read one data point. Or something like 1. | |
| int | di_start (const int COMM_FD) |
| int | di_stop (const int COMM_FD) |
| int | di_reset (const int COMM_FD) |
| int | di_serial_num (const int COMM_FD, char *ser_buf) |
| int | di_read_single (const int COMM_FD, daq_reading_t *data, const int NUM_BITS) |
| User-called routine to read one data point. Assumes unit stopped. | |
Include file for Di-194 DAQ code, moved here by phubbard 3/11/02 to cleanup evolving code.
Original code by:
Author: Anthony Hanson and Mike Hage Date: April 1st, 2001
I've cleaned it up and rewritten almost all of it, so I'm taking credit.
Definition in file di194.h.
|
|
Length of DI-194's internal serial number, in characters.
Definition at line 67 of file di194.h. Referenced by di_initialize(), di_serial_num(), and user_loop(). |
|
|
Typedef for serial buffering.
Definition at line 63 of file di194.h. Referenced by di_daq_sync(), and di_read(). |
|
|
List of sample rates, only use 240Hz for now |
|
||||||||||||||||
|
Convert from raw data into float, raw and bit format. Function to decode a block of eight bytes encoded from a DATAQ DI-194 as explained in the app note, which should have been included with this file. Expects 8-byte input buffer, zero terminated Data in 194 format (make some checks) Result buffer ready to fill Returns Struct filled in, with bit set if OK, otherwise return non-zero Notes Neither overly paranoid nor overly optimized.
Definition at line 818 of file di194.c. References daq_reading_t::analog, di_buf_validate(), daq_reading_t::digital, hex_print_byte(), daq_reading_t::is_valid, and daq_reading_t::raw. Referenced by di_read(). |
|
|
Check that a buffer matches the expected structure. Function to check the first couple of bytes for the signature that should be there if they are a valid DI-194 reading. See the Dataq sheet for details; there are some bits hardwired to zero that we check for. Note that random data can easily confuse this into returning valid on bad data; this is _not_ robust. Assumes Can check up the whole buffer Returns 0 if valid, nonzero if invalid
Definition at line 770 of file di194.c. Referenced by di_buf_decode(), and di_daq_sync(). |
|
|
Nasty hack to print a byte as bits.
|
|
|
Shut down DI194.
Definition at line 988 of file di194.c. References di_serial_close(). Referenced by daq_loop(), main(), and user_loop(). |
|
||||||||||||
|
Debug routine to print a command to stderr.
|
|
||||||||||||||||
|
Send a command to the unit and get the reply. Function to send a command to the DI-194, and discard the echod response. The DI seems to echo the non-zero characters sent, but with some exceptions. Most annoying. More exactly: it never echos the leading zero a rejected / unknown command echos 0xFF back arguments are echod verbatim unless the command is reset a reset command echos one extra byte back to the sender All of this was determined experimentally and may therefore be wrong.
Definition at line 502 of file di194.c. References di_serial_read(), and serial_timeout. Referenced by di_configure(), di_initialize(), di_reset(), di_serial_num(), di_start(), and di_stop(). |
|
|
Program DI-194 for continuous DAQ.
Assumes Port opened and init'd OK
Definition at line 676 of file di194.c. References all_chan, di_cmd_send(), and dig_chan. Referenced by di_open(), and user_loop(). |
|
|
Function to re-sync with the incoming stream of samples. We may be off by up to seven bytes due to sync errors, so read two buffers' worth and look for the signature as spec'd in the DATAQ web page. Kind of a hack until I grok more about the protocol. Assumes DI-194 is streaming data to the given port
Definition at line 417 of file di194.c. References daq_buf_t, di_buf_validate(), di_serial_read(), and serial_timeout. Referenced by daq_loop(), main(), and user_loop(). |
|
||||||||||||
|
Function to init comms with a DI-194 once the port is setup. Does a reset, downloads the key, and requests the serial number from the unit - should make a good test. Assumes Port open, 194 connected to same
Definition at line 589 of file di194.c. References di_cmd_send(), di_enable_key, di_serial_num(), di_stop(), key_cmd, odd_cmd, and SERIAL_NUM_LEN. Referenced by di_open(). |
|
||||||||||||
|
User-called routine to open the port, program DI194.
To do: -p port parsing, will need for USB serial. getopt!
Definition at line 914 of file di194.c. References di_configure(), di_initialize(), and di_serial_init(). Referenced by daq_loop(), and main(). |
|
||||||||||||||||
|
User-called routine to read one data point. Or something like 1.
Definition at line 1021 of file di194.c. References daq_buf_t, di_buf_decode(), di_serial_read(), and serial_timeout. Referenced by daq_loop(), di_read_single(), main(), and user_loop(). |
|
||||||||||||||||
|
User-called routine to read one data point. Assumes unit stopped.
Definition at line 1077 of file di194.c. References di_read(), di_start(), and di_stop(). Referenced by user_loop(). |
|
|
Definition at line 205 of file di194.c. References di_cmd_send(), and rst_cmd. Referenced by user_loop(). |
|
|
Open port and configure control lines, etc. Function to open the serial port and set up the rather peculiar comms requirements of the DI-194: 4800 baud, N81 No flow control (?) Controlled by DTR?
Definition at line 82 of file di194.c. References serial_timeout. Referenced by di_open(). |
|
||||||||||||
|
Definition at line 210 of file di194.c. References di_cmd_send(), di_serial_read(), SERIAL_NUM_LEN, serial_timeout, and sn_cmd. Referenced by di_initialize(), and user_loop(). |
|
||||||||||||||||||||
|
Read with timeout from a file descriptor.
Definition at line 266 of file di194.c. Referenced by di_cmd_send(), di_daq_sync(), di_read(), and di_serial_num(). |
|
|
Definition at line 200 of file di194.c. References di_cmd_send(), and start_cmd. Referenced by daq_loop(), di_read_single(), main(), and user_loop(). |
|
|
Definition at line 194 of file di194.c. References di_cmd_send(), and stop_cmd. Referenced by di_initialize(), di_read_single(), and user_loop(). |
|
|
Super-quick hack to hex-print a character, with ASCII if printable.
Definition at line 187 of file di194.c. Referenced by di_buf_decode(). |
|
||||||||||||
|
Function to compare an input command to the reset command. Just an inline cleanup Assumes CMD and len match Returns true if matches rst_cmd, false otherwise or if NULL
Definition at line 375 of file di194.c. References rst_cmd. |
|
||||||||||||
|
Hardwired min fn. Here and I thought min(int, int) was part of C9X now. Hmm.
|
1.3