19 #define CHANNEL_OF_FRAME(i) ((((frame_buf[2*i]<<8) + frame_buf[2*i+1])&0x03FF)-512)
24 GIOCondition condition,
33 if ((
sp_fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
34 printf(
"opening %s (%s)\n", device, strerror(errno));
37 struct termios termios;
40 termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
41 | ICRNL |
IUCLC | IXON | IXANY | IXOFF | IMAXBEL);
42 termios.c_iflag |= IGNPAR;
46 termios.c_cflag &= ~(CSIZE | PARENB | CRTSCTS | PARODD | HUPCL);
47 termios.c_cflag |= CREAD | CS8 | CSTOPB | CLOCAL;
51 termios.c_lflag &= ~(ISIG | ICANON | IEXTEN | ECHO | FLUSHO | PENDIN);
52 termios.c_lflag |= NOFLSH;
56 if (cfsetispeed(&termios, speed)) {
57 printf(
"setting term speed (%s)\n", strerror(errno));
60 if (tcsetattr(
sp_fd, TCSADRAIN, &termios)) {
61 printf(
"setting term attributes (%s)\n", strerror(errno));
65 g_io_channel_set_encoding(channel, NULL, NULL);
74 GIOCondition condition __attribute__((unused)),
75 gpointer data __attribute__((unused)))
80 GIOStatus st = g_io_channel_read_chars(source, buf, 255, &bytes_read, &_err);
82 if (st == G_IO_STATUS_NORMAL) {
86 printf(
"error reading serial: %s\n", _err->message);
97 #define STA_GOT_SYNC_1 1
98 #define STA_GOT_SYNC_2 2
109 for (i = 0; i < len; i++) {
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)