42 #include <sys/types.h>
50 #define ICSC_BROADCAST 0x00
51 #define ICSC_CMD_SYS 0x1F
52 #define ICSC_SYS_PING 0x05
53 #define ICSC_SYS_PONG 0x06
54 #define ICSC_SYS_QSTAT 0x07
55 #define ICSC_SYS_RSTAT 0x08
56 #define ICSC_SYS_RELAY 0x09
70 #define ICSC_SOH_START_COUNT 1
80 command_ptr commandList;
97 int readThreadRunning;
98 pthread_mutex_t uartMutex;
102 typedef void(*callbackFunction)(icsc_ptr,
unsigned char, char,
unsigned char,
char *);
107 callbackFunction callback;
119 #define ICSC_GPIO_OUTPUT 0
120 #define ICSC_GPIO_INPUT 1
207 #define ICSC_CATCH_ALL 0xFF
239 extern icsc_ptr
icsc_init_de(
const char *uart,
unsigned long baud, uint8_t station,
int de);
248 extern icsc_ptr
icsc_init(
const char *uart,
unsigned long baud, uint8_t station);
272 extern int icsc_send_array(icsc_ptr icsc, uint8_t station,
char command, uint8_t len,
const char *data);
281 extern int icsc_send_string(icsc_ptr icsc, uint8_t station,
char command,
const char *str);
290 extern int icsc_send_long(icsc_ptr icsc, uint8_t station,
char command, int32_t data);
299 extern int icsc_send_int(icsc_ptr icsc, uint8_t station,
char command, int16_t data);
308 extern int icsc_send_char(icsc_ptr icsc, uint8_t station,
char command, int8_t data);
int icsc_serial_read(int fd)
Read a byte from the serial port.
Definition: serial.c:166
void icsc_serial_flush(int fd)
Wait until all data sent to the serial port has been delivered to the wire.
Definition: serial.c:176
int icsc_broadcast_int(icsc_ptr icsc, char command, int16_t data)
Send a 16-bit integer to all remote stations.
Definition: icsc.c:406
icsc_ptr icsc_init(const char *uart, unsigned long baud, uint8_t station)
Create a new ICSC context, initialize the hardware, and start listening for messages.
Definition: icsc.c:362
int icsc_close(icsc_ptr icsc)
Close an ICSC instance freeing the memory. Terminates all communication.
Definition: icsc.c:415
int icsc_broadcast_array(icsc_ptr icsc, char command, uint8_t len, const char *data)
Send an array of data (or struct as if it were an array) to all stations.
Definition: icsc.c:391
int icsc_broadcast_long(icsc_ptr icsc, char command, int32_t data)
Send a 32-bit integer to all remote stations.
Definition: icsc.c:400
int icsc_send_long(icsc_ptr icsc, uint8_t station, char command, int32_t data)
Send a 32-bit integer to a remote station.
Definition: icsc.c:375
int icsc_gpio_write(int num, int level)
Set a GPIO to high or low.
Definition: gpio.c:82
int icsc_serial_write(int fd, uint8_t c)
Write a byte to a serial port.
Definition: serial.c:183
icsc_ptr icsc_init_de(const char *uart, unsigned long baud, uint8_t station, int de)
Create a new ICSC context, initialize the hardware, and start listening for messages.
Definition: icsc.c:289
int icsc_unregister_command(icsc_ptr icsc, char command)
Unregister an old command character.
Definition: icsc.c:259
int icsc_send_char(icsc_ptr icsc, uint8_t station, char command, int8_t data)
Send an 8-bit integer to a remote station.
Definition: icsc.c:386
void icsc_serial_close(int fd)
Close the serial port.
Definition: serial.c:192
void icsc_enable_debug()
Enable debug messages.
Definition: icsc.c:14
int icsc_send_array(icsc_ptr icsc, uint8_t station, char command, uint8_t len, const char *data)
Send an array of data (or struct as if it were an array) to a remote station.
Definition: icsc.c:366
void icsc_debug(const char *fmt,...)
Display a debug message to stderr.
Definition: icsc.c:17
void icsc_error(const char *fmt,...)
Display an error message to stderr.
Definition: icsc.c:28
int icsc_serial_open(const char *path, unsigned long baud)
Open a serial device at a specific baud rate.
Definition: serial.c:24
int icsc_gpio_open(int num, int mode)
Open a GPIO device in either input or output mode. Exports the GPIO node.
Definition: gpio.c:11
int icsc_gpio_close(int num)
Close a GPIO. Unexports the GPIO node.
Definition: gpio.c:99
void icsc_disable_debug()
Disable debug messages.
Definition: icsc.c:15
int icsc_send_string(icsc_ptr icsc, uint8_t station, char command, const char *str)
Send a text string to a remote station.
Definition: icsc.c:370
int icsc_broadcast_char(icsc_ptr icsc, char command, int8_t data)
Send an 8-bit integer to all remote stations.
Definition: icsc.c:411
int icsc_send_int(icsc_ptr icsc, uint8_t station, char command, int16_t data)
Send a 16-bit integer to a remote station.
Definition: icsc.c:381
int icsc_serial_available(int fd)
Look to see if serial data is available.
Definition: serial.c:162
int icsc_serial_wait_available(int fd, unsigned long timeout)
Wait for serial data to arrive up until the timeout expires.
Definition: serial.c:143
int icsc_gpio_read(int num)
Read the value of a GPIO.
Definition: gpio.c:60
int icsc_broadcast_string(icsc_ptr icsc, char command, const char *str)
Send a text string to all remote stations.
Definition: icsc.c:395
int icsc_register_command(icsc_ptr icsc, char command, callbackFunction func)
Register a new command callback.
Definition: icsc.c:231