22 GIOCondition condition,
31 if ((
sp_fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
32 printf(
"opening %s (%s)\n", device, strerror(errno));
35 struct termios termios;
38 termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
39 | ICRNL |
IUCLC | IXON | IXANY | IXOFF | IMAXBEL);
40 termios.c_iflag |= IGNPAR;
44 termios.c_cflag &= ~(CSIZE | PARENB | CRTSCTS | PARODD | HUPCL);
45 termios.c_cflag |= CREAD | CS8 | CSTOPB | CLOCAL;
49 termios.c_lflag &= ~(ISIG | ICANON | IEXTEN | ECHO | FLUSHO | PENDIN);
50 termios.c_lflag |= NOFLSH;
54 if (cfsetispeed(&termios, speed)) {
55 printf(
"setting term speed (%s)\n", strerror(errno));
58 if (tcsetattr(
sp_fd, TCSADRAIN, &termios)) {
59 printf(
"setting term attributes (%s)\n", strerror(errno));
63 g_io_channel_set_encoding(channel, NULL, NULL);
72 GIOCondition condition __attribute__((unused)),
73 gpointer data __attribute__((unused)))
78 GIOStatus st = g_io_channel_read_chars(source, buf, 255, &bytes_read, &_err);
80 if (st == G_IO_STATUS_NORMAL) {
84 printf(
"error reading serial: %s\n", _err->message);
95 #define STA_GOT_SYNC_1 1
96 #define STA_GOT_SYNC_2 2
107 for (i = 0; i < len; i++) {
136 #define CHANNEL_OF_FRAME(i) ((((frame_buf[2*i]<<8) + frame_buf[2*i+1])&0x03FF)-512)
static gboolean on_serial_data_received(GIOChannel *source, GIOCondition condition, gpointer data)
#define CHANNEL_OF_FRAME(i)
int nps_radio_control_spektrum_init(const char *device)
struct NpsRadioControl nps_radio_control
static void handle_frame(void)
static uint8_t frame_buf[FRAME_LEN]
static void parse_data(char *buf, int len)