20 #define CHANNEL_OF_FRAME(i) ((((frame_buf[2*i]<<8) + frame_buf[2*i+1])&0x03FF)-512)
25 GIOCondition condition,
34 if ((
sp_fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
35 printf(
"opening %s (%s)\n", device, strerror(errno));
38 struct termios termios;
41 termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
42 | ICRNL |
IUCLC | IXON | IXANY | IXOFF | IMAXBEL);
43 termios.c_iflag |= IGNPAR;
47 termios.c_cflag &= ~(CSIZE | PARENB | CRTSCTS | PARODD | HUPCL);
48 termios.c_cflag |= CREAD | CS8 | CSTOPB | CLOCAL;
52 termios.c_lflag &= ~(ISIG | ICANON | IEXTEN | ECHO | FLUSHO | PENDIN);
53 termios.c_lflag |= NOFLSH;
57 if (cfsetispeed(&termios, speed)) {
58 printf(
"setting term speed (%s)\n", strerror(errno));
61 if (tcsetattr(
sp_fd, TCSADRAIN, &termios)) {
62 printf(
"setting term attributes (%s)\n", strerror(errno));
65 GIOChannel *channel = g_io_channel_unix_new(
sp_fd);
66 g_io_channel_set_encoding(channel, NULL, NULL);
75 GIOCondition condition __attribute__((unused)),
76 gpointer data __attribute__((unused)))
81 GIOStatus st = g_io_channel_read_chars(source, buf, 255, &bytes_read, &_err);
83 if (st == G_IO_STATUS_NORMAL) {
87 printf(
"error reading serial: %s\n", _err->message);
98 #define STA_GOT_SYNC_1 1
99 #define STA_GOT_SYNC_2 2
110 for (i = 0; i < len; i++) {
struct NpsRadioControl nps_radio_control
#define CHANNEL_OF_FRAME(i)
static void handle_frame(void)
int nps_radio_control_spektrum_init(const char *device)
static uint8_t frame_buf[FRAME_LEN]
static gboolean on_serial_data_received(GIOChannel *source, GIOCondition condition, gpointer data)
static void parse_data(char *buf, int len)
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.