00001 /* 00002 * Copyright (C) 2005, 2007, 2009 Austin Robot Technology 00003 * 00004 * License: Modified BSD Software License Agreement 00005 * 00006 * $Id: dev8x.h 2 2010-01-17 01:54:03Z jack.oquin $ 00007 */ 00008 00016 #ifndef _DEV8X_H_ 00017 #define _DEV8X_H_ 00018 00019 #define IOADR_MAX_INPUTS 8 00020 #define IOADR_MAX_OUTPUTS 8 00021 00022 #include <stdio.h> 00023 #include <stdint.h> 00024 00025 #define DBG(format,args...) ROS_DEBUG(format, ## args) 00026 00027 #define BUFSIZE 8 // dev8x port buffer size 00028 00029 // One per IOADR8x hardware device. 00030 class dev8x 00031 { 00032 public: 00033 00034 dev8x(const char *pn); 00035 ~dev8x() {}; 00036 00037 int query_relays(uint8_t *relays); 00038 int read_8bit_port(int ch, int *data); 00039 int read_10bit_port(int ch, int *data); 00040 bool relays_busy(void); 00041 int set_relays(uint8_t bitmask); 00042 int setup(); 00043 int shutdown(); 00044 uint16_t sim_sawtooth(int ch, uint16_t limit); 00045 00046 private: 00047 int configure_port(int cflags, int iflags); 00048 00049 // device state: 00050 enum {UNREADY, READY, RELAY_WAIT} state; 00051 00052 double relay_wait_time; // time we last set relays 00053 //#define MIN_RELAY_WAIT 0.16 // minimum wait in seconds 00054 #define MIN_RELAY_WAIT 0.08 // minimum wait in seconds 00055 00056 // device I/O control 00057 char port_name[FILENAME_MAX]; // serial port name 00058 bool have_tty; // have real tty, not /dev/null 00059 uint8_t buffer[BUFSIZE]; // IOADR8x device buffer 00060 int fd; // file descriptor 00061 00062 // simulated analog ports and relays (when have_tty == false) 00063 uint16_t sim_port[IOADR_MAX_OUTPUTS]; 00064 uint8_t sim_relays; 00065 }; 00066 00067 #endif // _DEV8X_H_