void init_gps(struct gps *gpsData_ptr) { // NMEA Checksums are already included unsigned char cmdNmea2BinaryMode_B9600[] = "$PSRF100,0,9600,8,1,0*0C\r\n"; unsigned char cmdNmea2BinaryMode_B38400[] = "$PSRF100,0,38400,8,1,0*3C\r\n"; unsigned char cmdNmea2BinaryMode_B57600[] = "$PSRF100,0,57600,8,1,0*37\r\n"; unsigned char cmdNmea2BinaryMode_B115200[] = "$PSRF100,0,115200,8,1,0*04\r\n"; // open serial port at default GPS baudrate 4800 gpsData_ptr->port = open_serial(gpsData_ptr->portName, B4800); if (gpsData_ptr->port < 0) return; //change GPS output to binary at given baudrate switch( gpsData_ptr->baudRate ){ case B9600: write( gpsData_ptr->port, cmdNmea2BinaryMode_B9600, sizeof(cmdNmea2BinaryMode_B9600) ); break; case B38400: write( gpsData_ptr->port, cmdNmea2BinaryMode_B38400, sizeof(cmdNmea2BinaryMode_B38400) ); break; case B57600: write( gpsData_ptr->port, cmdNmea2BinaryMode_B57600, sizeof(cmdNmea2BinaryMode_B57600) ); break; case B115200: write( gpsData_ptr->port, cmdNmea2BinaryMode_B115200, sizeof(cmdNmea2BinaryMode_B115200) ); break; } sleep(1); close(gpsData_ptr->port); // change serial port baudrate gpsData_ptr->port = open_serial( gpsData_ptr->portName, gpsData_ptr->baudRate ); }
pf_adaptor::pf_adaptor(QObject *parent) : QObject(parent), tr_tx_p(new QThread()), tr_cc_p(new QThread()), tx_p(new pf_transmitter()), controller_p(new pf_controller()) { connect(this, SIGNAL(open_serial(QString, QString, qint32)), tx_p, SLOT(open_serial(QString, QString, qint32)), Qt::BlockingQueuedConnection); connect(this, SIGNAL(close_serial(void)), tx_p, SLOT(close_port(void)), Qt::BlockingQueuedConnection); // connect(this, SIGNAL(request(QByteArray, bool)), // tx_p, SLOT(transmitt(QByteArray, bool)), Qt::BlockingQueuedConnection); connect(this, SIGNAL(request(QByteArray, bool)), controller_p, SLOT(single_request(QByteArray, bool)), Qt::BlockingQueuedConnection); connect(controller_p, SIGNAL(transmitt(QByteArray, bool)), tx_p, SLOT(transmitt(QByteArray, bool)), Qt::BlockingQueuedConnection); // connect(tx_p, SIGNAL(reply(QByteArray /*reply*/, QByteArray /*request*/, qint32 /*time*/ )), // this, SIGNAL(reply(QByteArray /*reply*/, QByteArray /*request*/, qint32 /*time*/ )), Qt::QueuedConnection); connect(tx_p, SIGNAL(reply(pf_reply)), this, SIGNAL(reply(pf_reply))); connect(tx_p ,SIGNAL(error(pf_error)), this,SIGNAL(error(pf_error)), Qt::QueuedConnection); connect(tx_p ,SIGNAL(ready()), controller_p,SLOT(next_request()), Qt::QueuedConnection); connect(this ,SIGNAL(add_cyclic(QByteArray, quint32, quint32, bool)), controller_p,SLOT(add(QByteArray, quint32, quint32, bool)), Qt::QueuedConnection); connect(this ,SIGNAL(stop_cyclic()), controller_p,SLOT(stop()), Qt::BlockingQueuedConnection); connect(this ,SIGNAL(reset_cyclic()), controller_p,SLOT(reset()), Qt::BlockingQueuedConnection); connect(this ,SIGNAL(start_cyclic()), controller_p,SLOT(start()), Qt::BlockingQueuedConnection); //TODO Can work in existing thread tx_p->moveToThread(tr_tx_p); controller_p->moveToThread(tr_cc_p); tr_tx_p->start(); tr_cc_p->start(); //tr_cc_p->setPriority(QThread::HighPriority); tr_tx_p->setPriority(QThread::TimeCriticalPriority); }
void init_gps(struct gps *gpsData_ptr) { // NMEA Checksums are already included unsigned char cmdNmea2BinaryMode_B9600[] = "$PSRF100,0,9600,8,1,0*0C\r\n"; unsigned char cmdNmea2BinaryMode_B38400[] = "$PSRF100,0,38400,8,1,0*3C\r\n"; unsigned char cmdNmea2BinaryMode_B57600[] = "$PSRF100,0,57600,8,1,0*37\r\n"; unsigned char cmdNmea2BinaryMode_B115200[] = "$PSRF100,0,115200,8,1,0*04\r\n"; unsigned char cmdSirfMsg2[] = {0xA0,0xA2,0x00,0x08,0xA6,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0xA8,0xB0,0xB3}; // command to turn off Message 2 unsigned char cmdSirfMsg4[] = {0xA0,0xA2,0x00,0x08,0xA6,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0xAA,0xB0,0xB3}; // command to turn off Message 4 unsigned char cmdSirfMsg7[] = {0xA0,0xA2,0x00,0x08,0xA6,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0xAD,0xB0,0xB3}; // command to turn off Message 7 unsigned char cmdSirfMsg9[] = {0xA0,0xA2,0x00,0x08,0xA6,0x00,0x09,0x00,0x00,0x00,0x00,0x00,0x00,0xAF,0xB0,0xB3}; // command to turn off Message 9 unsigned char cmdSirfMsg27[] = {0xA0,0xA2,0x00,0x08,0xA6,0x00,0x1B,0x00,0x00,0x00,0x00,0x00,0x00,0xC1,0xB0,0xB3}; // command to turn off Message 27 // open serial port at default GPS baudrate 4800 gpsData_ptr->port = open_serial(gpsData_ptr->portName, B4800); if (gpsData_ptr->port < 0) return; //change GPS output to binary at given baudrate switch( gpsData_ptr->baudRate ) { case B9600: write( gpsData_ptr->port, cmdNmea2BinaryMode_B9600, sizeof(cmdNmea2BinaryMode_B9600) ); break; case B38400: write( gpsData_ptr->port, cmdNmea2BinaryMode_B38400, sizeof(cmdNmea2BinaryMode_B38400) ); break; case B57600: write( gpsData_ptr->port, cmdNmea2BinaryMode_B57600, sizeof(cmdNmea2BinaryMode_B57600) ); break; case B115200: write( gpsData_ptr->port, cmdNmea2BinaryMode_B115200, sizeof(cmdNmea2BinaryMode_B115200) ); break; } close(gpsData_ptr->port); sleep(1); // change serial port baudrate gpsData_ptr->port = open_serial( gpsData_ptr->portName, gpsData_ptr->baudRate ); // Turn off messages we don't need sleep(3); write( gpsData_ptr->port, cmdSirfMsg2, sizeof(cmdSirfMsg2) ); write( gpsData_ptr->port, cmdSirfMsg4, sizeof(cmdSirfMsg4) ); write( gpsData_ptr->port, cmdSirfMsg7, sizeof(cmdSirfMsg7) ); write( gpsData_ptr->port, cmdSirfMsg9, sizeof(cmdSirfMsg9) ); write( gpsData_ptr->port, cmdSirfMsg27, sizeof(cmdSirfMsg27) ); }
int main (int argc, char** argv) { char* input; int i; packet_t* p; int fd; char slot; if(argc != 3) { printf("Usage: signpainter slotnumber message\n"); exit(1); } slot = atoi(argv[1]); input = argv[2]; printf("Checksumming: X%sX\n", input); p = build_packet(input, slot); dump_packet(p); printf("Sending out\n"); fd = open_serial("/dev/sign"); writen(fd, p->buf, p->len); printf("Sent out\n"); printf("\n"); }
int main(int argc, char *argv[]) { char ch; testmode_t mode = CONSOLE; FILE *fp; while ((ch=getopt(argc, argv, "p:r:t:b:v")) != -1) { switch(ch) { case 'p': serial_device = strdup(optarg); break; case 'b': if (!strcmp(optarg, "115200")) { port_speed = B115200; } else if (!strcmp(optarg, "38400")) { port_speed = B38400; } fprintf(stderr, "Using %s bps\n", optarg); break; default: fprintf(stderr, "Unknown option %c\n", ch); return -1; } } open_serial(); config_port(); }
int xmos_dev_open() { int fd_xmos = open_serial(SERIAL_DEV); if (fd_xmos == -1) { printf("Cannot open device\n"); return ROKID_XMOS_ERROR_DEVICE_OPEN_FAILED; } int ret; ret = set_speed(fd_xmos, 115200); if (ret == -1) { printf("Set speed failed : %d\n", ret); return ROKID_XMOS_ERROR_INIT_FAILED; } ret = set_parity(fd_xmos, 8, 1, 0); if (ret == -1) { printf("Set parity failed : %d\n", ret); return ROKID_XMOS_ERROR_INIT_FAILED; } back_led_fd = open("/dev/dm163", O_RDWR | O_NONBLOCK); if (back_led_fd < 0) { perror("open dm163 error"); } return fd_xmos; }
int do_thing(void *data) { //char *portdev = "/dev/cu.usbserial"; //char *portdev = "/dev/ttyO1"; int serial_fd; serial_t *serial = (serial_t *)data; char *port_dev = serial->port_dev; struct termios options; int nbytes; char buffer[10]; ANSI_CHECK(__FILE__, open_serial(port_dev, &serial_fd)); config_serial(&options, serial_fd); serial->fQuit = 0; while(!serial->fQuit) { nbytes = read(serial_fd, buffer, sizeof(buffer)); if(nbytes > 0) { buffer[nbytes] = '\0'; serial->on_serial_data_received(serial, buffer, nbytes); } serial->process_command(serial, serial_fd); } close(serial_fd); return 0; }
VLLA* vlla_init(char* ser1, char* ser2) { // create vlla representation VLLA* vlla = calloc(1, sizeof(VLLA)); vlla->pixels = calloc(PIXEL_COUNT, sizeof(uint32_t)); // setup communication to actual display vlla->ser1_fd = open_serial(ser1); vlla->ser2_fd = open_serial(ser2); serial_set_interface_attribs(vlla->ser1_fd, B115200, 0); serial_set_interface_attribs(vlla->ser2_fd, B115200, 0); // TODO ask display for information return vlla; }
int main(int argc, char *argv[])/*{{{*/ { char buffer[BUFFER_SIZE]; struct termios oldoptions; int fd = open_serial(&oldoptions); if (fd == -1) { printf("Unable to open port %s\n", SERIAL_DEVICE); exit(EXIT_FAILURE); } /* write a launch command of SpeechToSocketActivity */ { char tmp[] = "f"; write(fd, tmp, sizeof(tmp)); } ssize_t s; char c; int m; while (1) { m = 0; /* read until '\n' */ printf("Wainting for read\n"); while (1) { s = read(fd, &c, 1); if (s < 0) { break; } else if (s > 0) { if (c == '\n') { buffer[m] = '\0'; break; } else { buffer[m] = c; m++; if (m >= BUFFER_SIZE - 1) { buffer[m] = '\0'; break; } } } } /* print the result */ if (m > 0) { printf("%s\n", buffer); } if (s < 0) { break; } } tcsetattr(fd, TCSANOW, &oldoptions); close(fd); printf("Connection closed\n"); return 0; }/*}}}*/
VLLA* vlla_init(char* ser1, char* ser2) { VLLA* vlla = vlla_create(); // setup communication to actual display vlla->ser1_fd = open_serial(ser1); vlla->ser2_fd = open_serial(ser2); serial_set_interface_attribs(vlla->ser1_fd, B115200, 0); serial_set_interface_attribs(vlla->ser2_fd, B115200, 0); // TODO ask display for information led_data_top = calloc(SERIAL_DATA_LEN, sizeof(uint8_t)); led_data_bottom = calloc(SERIAL_DATA_LEN, sizeof(uint8_t)); return vlla; }
int main(int argc, char *argv[]) { (void)argc; port_addr fd = INVALID_HANDLE_VALUE; base_dir = argv[2]; // Open the serial device while(fd == INVALID_HANDLE_VALUE) { fd = open_serial(argv[1]); #ifndef _WIN32 if((fd == INVALID_HANDLE_VALUE) && ((errno == ENOENT) || (errno == ENODEV))) { fprintf(stderr, "Waiting for %s\n", argv[1]); sleep(1); continue; } else #endif if(fd == INVALID_HANDLE_VALUE) { fprintf(stderr, "Error opening %s\n", argv[1]); return -1; } } uint8_t buf; int breaks_read = 0; for(;;) { int bytes_read = serial_read(fd, &buf, 1); if(bytes_read > 0) { if(breaks_read == 2) { int cmd = (int)buf; do_cmd(cmd, fd); breaks_read = 0; // Pause to let the client read the message usleep(10000); } else if(buf == '\003') breaks_read++; else { breaks_read = 0; putchar(buf); } } } return 0; }
int main(int argc,char *argv[]) { int i; for(i=1;i<argc;i++) { if (!strcmp(argv[i], "-f")) { strcpy(input_file, argv[i+1]); printf("Input file: %s\n", input_file); i++; } else if (!strcmp(argv[i], "-o")) { strcpy(output_device, argv[i+1]); printf("Output device: %s\n", output_device); i++; } else if (!strcmp(argv[i], "-p")) { pause_between_block = atoi(argv[i+1]); printf("Pause between blocks: %u\n", pause_between_block); i++; } else if (!strcmp(argv[i], "-b")) { baud_rate = atoi(argv[i+1]); printf("Baud rate: %u\n", baud_rate); i++; } else if (!strcmp(argv[i], "-v")) { verbose = 1; printf("Verbose mode on\n"); } else { printf("-f: Absolute path file input\n-o: Serial output device\n-p: Pause between sysex blocks(100ms)\n-b: Baud rate(115200)\n-v: Verbose mode\n"); exit(EXIT_FAILURE); } } file_descriptor = open_serial(output_device, baud_rate); if (file_descriptor > -1) { upload_file(input_file, output_device, pause_between_block); if (close_serial(file_descriptor) > -1) exit(EXIT_SUCCESS); else { printf("Error while closing the serial line...\n"); exit(EXIT_FAILURE); } } else { printf("Aborting...\n"); exit(EXIT_FAILURE); } }
int main(int argc, char *argv[]) { int rv, len, nblocks, done = 0; char * data = NULL; if ( (rv = get_opts(&gopts, argc, argv)) != 0 ) return rv; /* register interrupt trap */ signal(SIGTERM, cleanup); /* so need global variables */ signal(SIGINT, cleanup); /* open or set input file */ if( gopts.in_fname ) { gcontr.infd = open(gopts.in_fname, O_RDONLY); if( gcontr.infd < 0 ) { fprintf(stderr,"** failed to open infile '%s'\n",gopts.in_fname); return 1; } } else gcontr.infd = 0; /* stdin */ /* allocate data block */ data = (char *)malloc(gopts.block_len * sizeof(char)); if( !data ) { fprintf(stderr,"** failed to alloc %d bytes for block\n", gopts.block_len); return 1; } if( gopts.swap == 2 ) swap_2(data, gopts.block_len/2); else if( gopts.swap == 4 ) swap_4(data, gopts.block_len/4); if( (rv = open_serial(&gopts, &gcontr)) != 0 ) return rv; nblocks = 0; while(! done && (gopts.nblocks <= 0 || nblocks < gopts.nblocks) ) { len = set_data(&gopts, &gcontr, data); if( len > 0 ) done = send_serial(&gopts, &gcontr, data, len); else done = 1; nblocks++; if( gopts.ms_sleep ) ms_sleep(gopts.ms_sleep); } free(data); close_ports(); if(gopts.debug) fprintf(stderr,"-d wrote %d blocks of data\n",nblocks); return 0; }
SerialPort::SerialPort(std::string logfile_dir, bool verbose, const char* &uart_name) : fd(-1), _verbose(verbose) { printf("calling open serial base constructor\n"); std::string output_logfile_name = logfile_dir + "serial.out"; _output_logfile = fopen(output_logfile_name.c_str(), "a"); open_serial(uart_name); }
int main(int argc, char argv[]) { //Serial Configs initialize_defaults(); open_serial(); //Write some message /*sleep(1);*/ /*set_servo(2000);*/ /*sleep(1);*/ /*set_servo(1000);*/ /*sleep(1);*/ /*set_servo(1500);*/ /*sleep(1);*/ /*release_channel();*/ /*sleep(1);*/ //Reading messages /*while (!current_messages.sysid){*/ /*read_messages(¤t_messages);*/ /*}*/ Mavlink_Messages current_messages; Mavlink_Messages output; int i ; for(i = 0; i < 1000; i++) { read_messages(&output, &output); } mavlink_servo_output_raw_t servo = output.servo_output_raw; printf("Printing Servo output raw\n"); printf("Printing Servo 1: %u \n", (unsigned int)servo.servo1_raw); printf("Printing Servo 2: %u \n", (unsigned int)servo.servo2_raw); printf("Printing Servo 3: %u \n", (unsigned int)servo.servo3_raw); printf("Printing Servo 4: %u \n", (unsigned int)servo.servo4_raw); printf("Printing Servo 5: %u \n", (unsigned int)servo.servo5_raw); printf("Printing Servo 6: %u \n", (unsigned int)servo.servo6_raw); printf("Printing Servo 7: %u \n", (unsigned int)servo.servo7_raw); printf("Printing Servo 8: %u \n", (unsigned int)servo.servo8_raw); mavlink_global_position_int_t global_position_int = output.global_position_int; printf("LAT: %u \n", (unsigned int)global_position_int.lat); /*mavlink_global_position_int_t gposint = messages.global_position_int;*/ /*printf("Lat: %u \n", (unsigned int)gposint.lat);*/ /*printf("Lat: %u \n", (unsigned int)gposint.lon);*/ /*mavlink_local_position_ned_t locpos = messages.local_position_ned;*/ /*printf("x: %u \n", (unsigned int)locpos.x);*/ /*printf("y: %u \n", (unsigned int)locpos.y);*/ /*printf("z: %u \n", (unsigned int)locpos.z);*/ //Serial Port stuff close_serial(); sleep(1); return 0; }
HANDLE SerialInit(int PortNum, int BaudRate, int dataBit, int parity, int cts, int rts, int dsr, int dtr) { char portname[80]; sprintf(portname, "/dev/ttyUSB%d", PortNum); fprintf(stderr, "Opening: %s\n", portname); return open_serial(portname, BaudRate, dataBit, parity); }
int main(int argc, char **argv) { int serfd; if (argc != 4) { fprintf(stderr, "Usage: %s <port> <device> <rate> - act as a serial forwarder on <port>\n" "(listens to serial port <device> at baud rate <rate>)\n" , argv[0]); exit(2); } if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) fprintf(stderr, "Warning: failed to ignore SIGPIPE.\n"); open_serial(argv[2], platform_baud_rate(argv[3])); serfd = serial_source_fd(src); open_server_socket(atoi(argv[1])); for (;;) { fd_set rfds; int maxfd = -1; struct timeval zero; int serial_empty; int ret; zero.tv_sec = zero.tv_usec = 0; FD_ZERO(&rfds); fd_wait(&rfds, &maxfd, serfd); fd_wait(&rfds, &maxfd, server_socket); wait_clients(&rfds, &maxfd); serial_empty = serial_source_empty(src); if (serial_empty) ret = select(maxfd + 1, &rfds, NULL, NULL, NULL); else { ret = select(maxfd + 1, &rfds, NULL, NULL, &zero); check_serial(); } if (ret >= 0) { if (FD_ISSET(serfd, &rfds)) check_serial(); if (FD_ISSET(server_socket, &rfds)) check_new_client(); check_clients(&rfds); } } }
static int attach_proto(const char *path, unsigned int proto, unsigned int speed, bool flowctl, unsigned int flags) { int fd, dev_id; fd = open_serial(path, speed, flowctl); if (fd < 0) return -1; if (ioctl(fd, HCIUARTSETFLAGS, flags) < 0) { perror("Failed to set flags"); close(fd); return -1; } if (ioctl(fd, HCIUARTSETPROTO, proto) < 0) { perror("Failed to set protocol"); close(fd); return -1; } dev_id = ioctl(fd, HCIUARTGETDEVICE); if (dev_id < 0) { perror("Failed to get device id"); close(fd); return -1; } printf("Device index %d attached\n", dev_id); if (flags & (1 << HCI_UART_RAW_DEVICE)) { unsigned int attempts = 6; struct bt_hci *hci; while (attempts-- > 0) { hci = bt_hci_new_user_channel(dev_id); if (hci) break; usleep(250 * 1000); } if (!hci) { fprintf(stderr, "Failed to open HCI user channel\n"); close(fd); return -1; } bt_hci_send(hci, BT_HCI_CMD_READ_LOCAL_VERSION, NULL, 0, local_version_callback, hci, (bt_hci_destroy_func_t) bt_hci_unref); } return fd; }
int protocol_init() { /* wiringPiSetup(); wiringPiSPISetup(0, 8000000); sleep(1); radiolink_init(26);*/ open_serial("/dev/ttyUSB0"); wait_for_sync(); return 0; }
int main(int argc, char **argv) { int cooked_baud = cook_baud(DefaultBaud); char const * serial_dev = DefaultSerialDevice; int low_port = -1, high_port = -1; int serial_fd, low_listener, high_listener; while ( --argc != 0 ) { char *p = argv[argc]; if ( *(p++) != '-' ) usage(); switch (*(p++)) { case 'b': if ( (cooked_baud = cook_baud(atoi(p))) == 0 ) { fprintf(stderr, "Bad baud rate\n"); exit(1); } break; case 'd': serial_dev = p; break; case 'l': if ((low_port = atoi(p)) <= 0) usage(); break; case 'h': if ((high_port = atoi(p)) <= 0) usage(); break; default: usage(); } } if (low_port == -1 && high_port == -1) low_port = DefaultLowPort; if (low_port == -1) low_port = high_port - 1; if (high_port == -1) high_port = low_port + 1; if ((serial_fd = open_serial(serial_dev, cooked_baud)) < 0 || (low_listener = start_listener(low_port)) < 0 || (high_listener = start_listener(high_port)) < 0) exit(1); main_loop(serial_fd, low_listener, high_listener); return 0; }
// Initialize GPS and configure it to send the desired messages void init_gps(struct gps *gpsData_ptr){ // Use this section to setup the messages on the receivers. The configuration // is saved into the flash memory, so this only needs to be done once. /******************************************************************* // open the serial port used for gps communication at the default baudrate gpsData_ptr->port = open_serial( gpsData_ptr->portName, gpsData_ptr->baudRate ); if ( gpsData_ptr->port == -1 ) { fprintf( stderr, "<gps_crescent.c>Open serial port error!\n" ); } char buf[100]; int len; // configure the gps to send the message we want strcpy(buf, "$JBIN,1,1"); buf[9] = 0x0D; buf[10] = 0x0A; len = write( gpsData_ptr->port, buf, 11 ); fprintf(stderr, "wrote %d bytes (should be 11)\n", len); cyg_thread_delay(10); strcpy(buf, "$JBIN,96,0"); buf[10] = 0x0D; buf[11] = 0x0A; len = write( gpsData_ptr->port, buf, 12 ); fprintf(stderr, "wrote %d bytes (should be 12)\n", len); cyg_thread_delay(10); // configure the baudrate strcpy(buf, "$JBAUD,115200"); buf[13] = 0x0D; buf[14] = 0x0A; len = write( gpsData_ptr->port, buf, 15 ); fprintf(stderr, "wrote %d bytes (should be 14)\n", len); cyg_thread_delay(10); strcpy(buf, "$JSAVE"); buf[6] = 0x0D; buf[7] = 0x0A; len = write( gpsData_ptr->port, buf, 8 ); fprintf(stderr, "wrote %d bytes (should be 8)\n", len); sleep(10); // wait for save to complete close(gpsData_ptr->port); sleep(1); *******************************************************************/ // Open serial port gpsData_ptr->port = open_serial( gpsData_ptr->portName, gpsData_ptr->baudRate ); }
/*!***************************************************************************** ******************************************************************************* \note init_newtonlabs_interface \date Oct 2000 \remarks initializes the interface, i.e., just a serial connection ******************************************************************************* Function Parameters: [in]=input,[out]=output none ******************************************************************************/ static int init_newtonlabs_interface(void) { serial_fd = open_serial(SERIALPORT2,BAUD115K,"ro",TRUE); if (serial_fd == FALSE) { printf("Error when opening Serial Port\n"); return FALSE; } return TRUE; }
/*!***************************************************************************** ******************************************************************************* \note init_dbvision_interface \date Oct 2000 \remarks initializes the interface, i.e., just a serial connection ******************************************************************************* Function Parameters: [in]=input,[out]=output none ******************************************************************************/ static int init_dbvision_interface(void) { serial_fd = open_serial(SERIALPORT1,BAUD115K,O_RDONLY); if (serial_fd < 0) { printf("Error when opening Serial Port\n"); return FALSE; } return TRUE; }
int main(int argc, char argv[]) { //Serial Configs initialize_defaults(); open_serial(); message_interval(100000, 33); //Serial Port stuff close_serial(); sleep(1); return 0; }
int main() { int i=0; for( i=0; i<10 ; i++) printf("%d",i); printf("I am learning git"); open_serial(); //opening serial communication send_open_message(); //when open serial com,send ack wait_for_ack(); //waiting for ack return 0; }
int main(int argc, char* argv[]) { initialize_defaults(); open_serial(); uart_name = "/dev/ttyAMA0"; baudrate = 57600; uint16_t u = 0xFFFF; sleep(1); mavlink_rc_channels_override_t rco; rco.chan1_raw = 1500; rco.chan2_raw = 1500; rco.chan3_raw = 1500; rco.chan4_raw = 2000; rco.chan5_raw = 1500; rco.chan6_raw = 1500; rco.chan7_raw = 1500; rco.chan8_raw = 1500; rco.target_system =0; rco.target_component = 0; mavlink_message_t message; /*int i;*/ /*for(i = 0; i<1; i++){*/ mavlink_msg_rc_channels_override_encode(0xff,0,&message, &rco); int len = write_message(message); /*}*/ sleep(1); mavlink_msg_rc_channels_override_pack(0xff,0, &message,0,0,u,u,u,1000,u,u,u,u ); len = write_message(message); sleep(1); mavlink_msg_rc_channels_override_pack(0xff,0, &message,0,0,u,u,u,1500,u,u,u,u ); len = write_message(message); sleep(1); mavlink_msg_rc_channels_override_pack(0xff,0, &message,0,0,0,0,0,0,0,0,0,0 ); len = write_message(message); sleep(1); close_serial(); sleep(1); pthread_mutex_destroy(&lock); return 0; }
int main (int argc, char const * argv []) { static char const * optv [] = { "cl:qv", "", "Atheros UART Device Detector", "c\tassume device is in command mode", "l f\tserial port is (f) [" SERIAL_PORT "]", "q\tquiet mode", "v\tverbose mode", (char const *) (0) }; signed c; char const *line = SERIAL_PORT; struct serial serial; struct serial_mode serial_mode; flag_t flags = 0; optind = 1; while ((c = getoptv (argc, argv, optv)) != -1) { switch ((char) (c)) { case 'c': _setbits (flags, INT6KDETECT_CMD_MODE); break; case 'l': line = optarg; break; case 'q': _setbits (flags, INT6KDETECT_QUIET); break; default: break; } } argc -= optind; argv += optind; if (open_serial (line, &serial) == -1) error (1, errno, "could not open %s", line); if (detect (&serial, &serial_mode, flags) == -1) error (1, 0, "could not detect device"); printf ("Detected the following serial mode:\n"); dump_serial_mode (&serial_mode); close_serial (&serial); return (0); }
int main(int argc, char **argv) { int serfd; if (argc != 4) { fprintf(stderr, "Usage: %s <device> <rate> <file> - act as a serial forwarder on <port>\n" "(listens to serial port <device> at baud rate <rate>)\n", argv[0]); exit(2); } if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) fprintf(stderr, "Warning: failed to ignore SIGPIPE.\n"); if (signal(SIGINT, sigproc) == SIG_ERR) fprintf(stderr, "Warning: failed to set the SIGINT interruption.\n"); srcId = -1; open_serial(argv[1], platform_baud_rate(argv[2])); serfd = serial_source_fd(src); open_file_fd(argv[3]); dup2(filefd, 1); for (;;) { fd_set rfds; int maxfd = -1; struct timeval zero; int serial_empty; int ret; zero.tv_sec = zero.tv_usec = 0; FD_ZERO(&rfds); fd_wait(&rfds, &maxfd, serfd); serial_empty = serial_source_empty(src); check_serial(); if (ret >= 0) { if (FD_ISSET(serfd, &rfds)) check_serial(); } } }
int main(int argc, char *argv[]) { optiondata opt; motparm mp; port_list * plist = &g_ports; int rv; if ( (rv = get_options(&opt, &mp, plist, argc, argv)) != 0 ) return rv; /* register interrupt trap */ signal( SIGHUP, clean_n_exit ); signal( SIGINT, clean_n_exit ); signal( SIGQUIT, clean_n_exit ); signal( SIGKILL, clean_n_exit ); signal( SIGTERM, clean_n_exit ); if ( (rv = open_incoming_socket(&opt, plist)) < 0 ) return rv; while (1) /* run until interrupt or error (consider restart?) */ { mp.nread = 0; /* reset our counter */ /* wait for AFNI to talk to us */ if ( (rv = wait_for_socket(&opt, plist, &mp)) < 0 ) { clean_n_exit(0); return rv; } if ( ! opt.no_serial ) if ( (rv = open_serial(&opt, plist)) != 0 ) return rv; /* read data while it is there */ while ( (rv = read_socket(&opt, plist, &mp)) == 0) if ( ! opt.no_serial ) send_serial(&opt, plist, &mp); close_data_ports(plist); } return 0; /* should not be reached, of course */ }
int sdp_open(sdp_t *sdp, const char *fname, int addr) #endif { SDP_F f; if (addr < SDP_DEV_ADDR_MIN || addr > SDP_DEV_ADDR_MAX) { errno = ERANGE; return SDP_ERANGE; } f = open_serial(fname); if (f == SDP_F_ERR) return SDP_EERRNO; sdp->f_in = sdp->f_out = f; sdp->addr = addr; return 0; }