示例#1
0
void ffs_init_sockets(int* rfile_sock_fd, int* wfile_sock_fd)
{
    printf("Setting up %s with rfile=%s and wfile=%s\n", ffs_host_ip, ffs_rfile_port, ffs_wfile_port);
    setup_port(ffs_host_ip, rfile_sock_fd, ffs_rfile_port);
    setup_port(ffs_host_ip, wfile_sock_fd, ffs_wfile_port);

    // Reap all dead processes
    struct sigaction sa;
    sa.sa_handler = sigchld_handler; 
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_RESTART;
    if (sigaction(SIGCHLD, &sa, NULL) == -1) 
        { perror("sigaction"); exit(1); }
}
示例#2
0
void serial_raw::transmit(Bit8u byte)
{
#ifdef WIN32
  DWORD DErr, Len2;
  OVERLAPPED tx_ovl;
#endif

  BX_DEBUG (("transmit %d", byte));
  if (present) {
#ifdef WIN32
    if (DCBchanged) {
      setup_port();
    } else {
      ClearCommError(hCOM, &DErr, NULL);
    }
    memset(&tx_ovl, 0, sizeof(OVERLAPPED));
    tx_ovl.hEvent = CreateEvent(NULL,TRUE,TRUE,"transmit");
    if (!WriteFile(hCOM, &byte, 1, &Len2, &tx_ovl)) {
      if (GetLastError() == ERROR_IO_PENDING) {
        if (WaitForSingleObject(tx_ovl.hEvent, 100) == WAIT_OBJECT_0) {
          GetOverlappedResult(hCOM, &tx_ovl, &Len2, FALSE);
        }
      }
    }
    if (Len2 != 1) BX_ERROR(("transmit failed: len = %d", Len2));
    ClearCommError(hCOM, &DErr, NULL);
    CloseHandle(tx_ovl.hEvent);
#endif
  }
}
示例#3
0
int main(int argc, char **argv) {
	// install quit handler
	signal(SIGINT, catch_quit);
	signal(SIGQUIT, catch_quit);
	
	#ifndef TESTMODE
	if (argc < 4) {
        fprintf(stdout, "Usage: %s /dev/your_serial_device PORT_BAUD BALLOON_ID\n", argv[0]);
        return 1;
	}
	
	// init serial port
	if ((serial_port = setup_port(argv[1], atoi(argv[2]))) == -1) {
		perror("setup_port");
		return 1;
	}
    balloon_id = atoi(argv[3]);
    #else
    balloon_id = 6;
    #endif
	printf("Will spawn IO loops\n");
	packet_loop();

	return 0;
}
示例#4
0
void main(){
  port = "/dev/ttyUSB0";
  open_port();
  setup_port();
  streaming();
  // return;
}
示例#5
0
SerialPort::SerialPort ( char *name, ArchSerialInfo port_info ) : CharacterDevice( name )
{
  this->port_info_ = port_info;

  WriteLock = 0;
  SerialLock = 0;
  
  setup_port( BR_9600, DATA_8, STOP_ONE, NO_PARITY );
};
示例#6
0
int serial_raw::receive()
{
#ifdef WIN32
  int data;
#endif

  if (present) {
#ifdef WIN32
    if (DCBchanged) {
      setup_port();
    }
    data = rxdata_buffer[0];
    if (rxdata_count > 0) {
      memcpy(&rxdata_buffer[0], &rxdata_buffer[1], sizeof(Bit16s)*(RX_BUFSIZE-1));
      rxdata_count--;
    }
    if (data < 0) {
      switch (data) {
        case RAW_EVENT_CTS_ON:
          MSR_value |= 0x10;
          break;
        case RAW_EVENT_CTS_OFF:
          MSR_value &= ~0x10;
          break;
        case RAW_EVENT_DSR_ON:
          MSR_value |= 0x20;
          break;
        case RAW_EVENT_DSR_OFF:
          MSR_value &= ~0x20;
          break;
        case RAW_EVENT_RING_ON:
          MSR_value |= 0x40;
          break;
        case RAW_EVENT_RING_OFF:
          MSR_value &= ~0x40;
          break;
        case RAW_EVENT_RLSD_ON:
          MSR_value |= 0x80;
          break;
        case RAW_EVENT_RLSD_OFF:
          MSR_value &= ~0x80;
          break;
      }
    }
    return data;
#else
    BX_DEBUG (("receive returning 'A'"));
    return (int)'A';
#endif
  } else {
    BX_DEBUG (("receive returning 'A'"));
    return (int)'A';
  }
}
示例#7
0
int main(){

  srand(time(NULL));

  data_item_header  ignition_angle  = {"Ignition angle",  Real32_Type,  Degrees};
  data_item_header  engine_torque   = {"Engine torque",   Real32_Type,  Newton_Metres};
  data_item_header  engine_speed    = {"Engine speed",    UInt32_Type,   Revolutions_Per_Second};

  int ignition_angle_port = -1;
  int engine_torque_port  = -1;
  int engine_speed_port   = -1;

  unsigned int  ignition_angle_port_size = sizeof(data_item_header)+4;
  unsigned int  engine_torque_port_size  = sizeof(data_item_header)+4;
  unsigned int  engine_speed_port_size   = sizeof(data_item_header)+4;

  ignition_angle_data = setup_port(port_ignition_angle_btdc, &ignition_angle_port, ignition_angle_port_size);
  engine_torque_data  = setup_port(port_engine_torque, &engine_torque_port, engine_torque_port_size);
  engine_speed_data   = setup_port(port_engine_speed, &engine_speed_port, engine_speed_port_size);

  initialize_simulation();

  sleep(5);

  memcpy(ignition_angle_data, &ignition_angle, sizeof(data_item_header) );
  memcpy(engine_torque_data, &engine_torque, sizeof(data_item_header) );
  memcpy(engine_speed_data, &engine_speed, sizeof(data_item_header) );

  int i = 0;
  for(; i < 1000000000; i++){
    update_rpm();
    update_ignition_angle();
    update_torque();
  }

  sleep(5);

  close_port(port_ignition_angle_btdc, ignition_angle_data, ignition_angle_port_size);
  close_port(port_engine_torque, engine_torque_data, engine_torque_port_size);
  close_port(port_engine_speed, engine_speed_data, engine_speed_port_size);
}
void GRPCServer::run()
{
    grpc::ServerBuilder builder;
    setup_port(builder);

    builder.RegisterService(&_core);
    builder.RegisterService(&_action_service);
    builder.RegisterService(&_camera_service);
    builder.RegisterService(&_mission_service);
    builder.RegisterService(&_telemetry_service);

    _server = builder.BuildAndStart();
    LogInfo() << "Server started";
}
示例#9
0
int main(int argc, char **argv) {
    // install quit handler
    signal(SIGINT, catch_quit);
    signal(SIGQUIT, catch_quit);

    // init serial port
    #ifndef TESTMODE
    if ((serial_port = setup_port("/dev/ttyMSM2")) == -1) {
        perror("setup_port");
        return 1;
    }
    #endif

    printf("Will spawn IO loops\n");
    packet_loop();

    return 0;
}
示例#10
0
文件: message.c 项目: jtyr/neclcd
void send_message(char *str, char **replay_msg) {
	int fd, w;

	/* open port */
	fd = open_port();

	/* setup port */
	setup_port(&fd);

	/* write port */
	w = write_port(&fd, str);

	/* read replay */
	if (w > 0) read_port(&fd, replay_msg);

	/* close port */
	close(fd);
}
示例#11
0
bool ofxMavlink::connect(string uart_name) {
    //char *uart_name = (char*)"/dev/ttyUSB0";
    int baudrate = 57600;
    bool bSuccess = false;

    ofLogNotice("ofxMavlink") << "Trying to connect to " << uart_name;

    fd = open_port(uart_name.c_str());
    if (fd == -1)
    {
        ofLogError("ofxMavlink") << "failure, could not open port.";
        //exit(EXIT_FAILURE);
    }
    else
    {
        ofLogNotice("ofxMavlink") << "success.";
    }
    ofLogNotice("ofxMavlink") << "Trying to configure " << uart_name;

    bool setup = setup_port(fd, baudrate, 8, 1, false, false);
    if (!setup)
    {
        ofLogError("ofxMavlink") << "failure, could not configure port.";
        //exit(EXIT_FAILURE);
    }
    else
    {
        ofLogNotice("ofxMavlink") << "success.";
    }

    if (fd == -1 || fd == 0)
    {
        ofLogNotice("ofxMavlink") << "Connection attempt to port " << uart_name <<  " with " << baudrate << " baud, 8N1 failed, exiting.";
        //std::exit(1);
    }
    else
    {
        bSuccess = true;
        ofLogNotice("ofxMavlink") << "Connected to" << uart_name <<  " with " << baudrate << " baud, 8 data bits, no parity, 1 stop bit (8N1)";
    }

    return bSuccess;
}
示例#12
0
void SerialPort::begin_serial(const char* &uart_name, const int &baudrate) {
	// display status as needed
	LOG_DEBUG("Trying to connect to %s.. ", uart_name);
	fflush(stdout);

	// attempt to open the com port
	open_port(uart_name);

	// check for success, display comments as needed
	if (fd == -1) {
		LOG_DEBUG("failure, could not open port.");
		throw EXIT_FAILURE;
	} else {
		LOG_DEBUG("success.\n");
	}

	// display status as needed
	LOG_DEBUG("Trying to configure %s.. ", uart_name);

	// attempt to setup the com port
	bool setup = setup_port(baudrate, 8, 1, false, false);

	// check success, display comments as needed
	if (!setup) {
		LOG_DEBUG("failure, could not configure port.");
		throw EXIT_FAILURE;
	} else {
		LOG_DEBUG("success.\n");
	}

	// error checking, display comments as needed
	if (fd <= 0) {
		LOG_ERROR("Connection attempt to port %s with %d baud, 8N1 failed, exiting.", uart_name, baudrate);
		throw EXIT_FAILURE;
	} else {
		LOG_STATUS("\nConnected to %s with %d baud, 8 data bits, no parity, 1 stop bit (8N1)", uart_name, baudrate);
	}

	// final status update to display as needed
	LOG_DEBUG("\nREADY, waiting for heartbeat.\n");
}
示例#13
0
int open_tap(char *dev) {
	struct ifreq ifr;
	int fd, err;

	if ((fd = open("/dev/net/tun", O_RDWR)) < 0) {
		perror("Failed to open /dev/net/tun");
		return (-1);
	}
	memset(&ifr, 0, sizeof(ifr));
	ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
	strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name) - 1);
	if (ioctl(fd, TUNSETIFF, (void *) &ifr) < 0) {
		perror("TUNSETIFF failed");
		close(fd);
		return (-1);
	}
	err = setup_port(fd, send_tap, NULL, 0);
	if (err)
		return (err);
	return (fd);
}
示例#14
0
int setupPort(int* fd, char* uart_name, int baudrate) {
    // SETUP SERIAL PORT

    // Exit if opening port failed
    // Open the serial port.
    if (!silent) printf("Trying to connect to %s.. ", uart_name);
    fflush(stdout);
    *fd = open_port(uart_name);
    if (*fd == -1) {
        if (!silent) printf("failure, could not open port.\n");
        return (EXIT_FAILURE);
    } else {
        if (!silent) printf("success.\n");
    }
    if (!silent) printf("Trying to configure %s.. ", uart_name);
    bool setup = setup_port(*fd, baudrate, 8, 1, false, false);
    if (!setup) {
        if (!silent) printf("failure, could not configure port.\n");
        return (EXIT_FAILURE);
    } else {
        if (!silent) printf("success.\n");
    }

    int noErrors = 0;
    if (*fd == -1 || *fd == 0) {
        if (!silent) fprintf(stderr, "Connection attempt to port %s with %d baud, 8N1 failed, exiting.\n", uart_name, baudrate);
        return (EXIT_FAILURE);
    } else {
        if (!silent) fprintf(stderr, "\nConnected to %s with %d baud, 8 data bits, no parity, 1 stop bit (8N1)\n", uart_name, baudrate);
    }

    if (*fd < 0) {
        return (noErrors);
    }
    return 2;
}
示例#15
0
G_MODULE_EXPORT gboolean load_firmware (GtkButton *button)
{
	GtkWidget *widget = NULL;
	gchar *port;
	gchar *filename = NULL;
	gint port_fd = 0;
	gint file_fd = 0;
	FirmwareType type = MS1;

	widget = GTK_WIDGET(gtk_builder_get_object((GtkBuilder *)DATA_GET(global_data,"builder"), "port_entry"));
	port = (gchar *)gtk_entry_get_text(GTK_ENTRY(widget));
	widget = GTK_WIDGET(gtk_builder_get_object ((GtkBuilder *)DATA_GET(global_data,"builder"), "filechooser_button"));
	filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget));

	if (g_utf8_strlen(port, -1) == 0)
		return FALSE;
	if (filename == NULL)
		return FALSE;

	/* If we got this far, all is good argument wise */
	if (!lock_port(port))
	{
		output((gchar *)"Could NOT LOCK Serial Port,\nYou should check for other programs using the serial port\n",FALSE);
		return FALSE;
	}
	port_fd = open_port(port);
	if (port_fd > 0)
		output((gchar *)"Port successfully opened\n",FALSE);
	else
	{
		output((gchar *)"Could NOT open Port, You should check perms\n",FALSE);
		unlock_port();
		return FALSE;
	}
#ifdef __WIN32__
	file_fd = open(filename, O_RDWR | O_BINARY );
#else
	file_fd = g_open(filename,O_RDONLY,S_IRUSR);
#endif
	if (file_fd > 0 )
		output((gchar *)"Firmware file successfully opened\n",FALSE);
	else
	{
		output((gchar *)"Could NOT open firmware file, check permissions/paths\n",FALSE);
		close_port(port_fd);
		unlock_port();
		return FALSE;
	}
	lock_buttons();
	if ((GINT)DATA_GET(global_data,"persona") == MS1)
	{
		setup_port(port_fd, 9600);
		do_ms1_load(port_fd,file_fd);
	}
	else if ((GINT)DATA_GET(global_data,"persona") == MS2)
	{
		setup_port(port_fd, 115200);
		do_ms2_load(port_fd,file_fd);
	}
	else if ((GINT)DATA_GET(global_data,"persona") == FREEEMS)
	{
		setup_port(port_fd, 115200);
		do_freeems_load(port_fd,file_fd);
	}
	unlock_buttons();
	close_port(port_fd);
	unlock_port();
	return TRUE;
}
示例#16
0
int start_middleware_frontend(char *database) {
  int sock;
  char address[ARG_SIZE];
  int reallen;
  struct sockaddr_in real;
  char db[TABLENAMELEN];
  char *p;

  if (myname[0] != '\0') {
    debug_out(2, "Already registered!\n");
    exit(1);
  }

  if (strncmp(database, MWPREFIX, strlen(MWPREFIX)) != 0) {
    debug_out(2, "Bogus database '%s'\n", database);
    return FALSE;
  }

  {
    char *q;			/* temporary pointer */

    p = q = database + strlen(MWPREFIX);

    while (*p && *p >= '0' && *p <= '9') p++;

    /* 12 characters are needed for a text representation of a 32-bit integer */

    /* If a (non-null) character at p, or no digits detected, or name too long */
    if (*p || p == q || strlen(database) > (TABLENAMELEN - 12)) {
      debug_out(2, "Bogus database '%s'\n", database);
      exit(1);
    }
  }

  sprintf(db, "%d%s", getuid(), database);

  strcpy(myname, db);

  sock = setup_port(0, TCP, FALSE);
  if (sock < 0) {
    debug_out(2,"Error setting up port\n");
    exit(1);
  }

  reallen = sizeof(struct sockaddr_in);
  if (getsockname(sock, (struct sockaddr *) &real, &reallen) < 0) {
    my_perror(2,"getsockname");
    exit(1);
  }
      
  if (reallen != sizeof(struct sockaddr_in)) {
    debug_out(2, "Length mismatch in getsockname()\n");
    exit(1);
  }

  sprintf(address, "%s:%d", get_host_name(), ntohs(real.sin_port));

  if (!replace_entry(address , "nameserver", db)) {
    debug_out(2, "Failed to enter data into nameserver\n");
    exit(1);
  }

  return sock;
}
示例#17
0
int op_entry(request req, char *str, char *database, char *entry) {
  int sock;			/* Socket */
  char tmpstr[DATALEN] = "";
  char *p;
  char db[TABLENAMELEN];
  int status;

  if (strncmp(database, DBPREFIX, strlen(DBPREFIX)) != 0 &&
      strcmp(database, MANAGEMENT) != 0 &&
      strcmp(database, NSDB) != 0) {
    debug_out(2, "Bogus database '%s'\n", database);
    return FALSE;
  }

  if (strcmp(database, MANAGEMENT) != 0 &&
      strcmp(database, NSDB) != 0) { /* Not management or nameserver */
    char *q;			/* temporary pointer */

    p = q = database + strlen(DBPREFIX);

    while (*p && *p >= '0' && *p <= '9') p++;

    /* 12 characters are needed for a text representation of a 32-bit integer */

    /* If a (non-null) character at p, or no digits detected, or name too long */
    if (*p || p == q || strlen(database) > (TABLENAMELEN - 12)) {
      debug_out(2, "Bogus database *'%s'\n", database);
      return FALSE;
    }
  }

  if (strcmp(database, NSDB) != 0) {
    sprintf(db, "%d%s", getuid(), database);
  } else {
    sprintf(db, "%s", database);
  }

  if (io_delay) {
    debug_out(0, "Sleeping for %d seconds\n", io_delay);
    sleep(io_delay); /* Go to sleep for a while */
  }

  sock = setup_port(0, UDP, FALSE);
  if (sock < 0) {
    debug_out(2, "Failed to open port.\n");
    exit(1);
  }
  switch (req) {
  case GET:
    status = do_get(sock, db, entry, tmpstr, NULL);
    if (status == EXISTS) {
      strncpy(str, tmpstr, ARG_SIZE);
      str[ARG_SIZE - 1] = 0;
      close(sock);
      return TRUE;
    }
    break;
  case DEL:
    status = do_del(sock, db, entry, tmpstr, NULL);
    if (status == EXISTS) {
      strncpy(str, tmpstr, ARG_SIZE);
      str[ARG_SIZE - 1] = 0;
      close(sock);
      return TRUE;
    }
    break;
  case PUT:
    strncpy(tmpstr, str, ARG_SIZE);
    status = do_put(sock, db, entry, tmpstr, NULL);
    if (status == NONEXISTENT) {
      strncpy(str, tmpstr, ARG_SIZE);
      str[ARG_SIZE - 1] = 0;
      close(sock);
      return TRUE;
    }
    break;
  case RPL:
    strncpy(tmpstr, str, ARG_SIZE);
    status = do_rpl(sock, db, entry, tmpstr, NULL);
    if (status == REPLACED) {
      strncpy(str, tmpstr, ARG_SIZE);
      str[ARG_SIZE - 1] = 0;
      close(sock);
      return TRUE;
    }
    break;
  }
  close(sock);
  return FALSE;
}
示例#18
0
int unibo_filtertest_thread_main(int argc, char *argv[])
{
	warnx("main thread started");
	thread_running = true;
	int unibo_ref_pub_fd;
	int unibo_param_pub_fd;
	int unibo_opti_pub_fd;
	/* default values for arguments */

	// use (ttyS2) for UART5 in px4fum_v1
	char *uart_name = (char*)"/dev/ttyS6";      //(ttyS2)--> UART5,
	int baudrate = 115200;
	const char *commandline_usage = "\tusage: %s -d <devicename> -b <baudrate> [-v/--verbose] [--debug]\n\t\tdefault: -d %s -b %i\n";

	/* read program arguments */
			int i;

			for (i = 1; i < argc; i++) { /* argv[0] is "start/stop/status" */
				if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
					warnx(commandline_usage, argv[0], uart_name, baudrate);
					thread_should_exit = true;
					return 0;
				}

				/* UART device ID */
				if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--device") == 0) {
					if (argc > i + 1) {
						uart_name = argv[i + 1];

					} else {
						warnx(commandline_usage, argv[0], uart_name, baudrate);
						thread_should_exit = true;
						return 0;
					}
				}

				/* baud rate */
				if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "--baud") == 0) {
					if (argc > i + 1) {
						baudrate = atoi(argv[i + 1]);

					} else {
						warnx(commandline_usage, argv[0], uart_name, baudrate);
						thread_should_exit = true;
						return 0;
					}
				}

			}

			// SETUP SERIAL PORT

			// Exit if opening port failed
			// Open the serial port.
			if (!silent) warnx("Trying to connect to %s.. ", uart_name);
			fflush(stdout);

			fd = open_port(uart_name);
			if (fd == -1)
			{
				warnx("failure, could not open port.\n");
				exit(EXIT_FAILURE);
			}
			else
			{
				warnx("success.\n");
			}
			warnx("Trying to configure %s.. ", uart_name);
			bool setup = setup_port(fd, baudrate, 8, 1, false, false);
			if (!setup)
			{
				warnx("failure, could not configure port.\n");
				//exit(EXIT_FAILURE);
			}
			else
			{
				warnx("success.\n");
			}

			int noErrors = 0;
			if (fd == -1 || fd == 0)
			{
				fprintf(stderr, "Connection attempt to port %s with %d baud, 8N1 failed, exiting.\n", uart_name, baudrate);
				//exit(EXIT_FAILURE);
			}
			else
			{
				fprintf(stderr, "\nConnected to %s with %d baud, 8 data bits, no parity, 1 stop bit (8N1)\n", uart_name, baudrate);
			}

			if(fd < 0)
			{
				//exit(noErrors);
			}


	// Round Buffer for REF packet
	static char round_buffer_PACK[LENGTH*4];
	static char packet_PACK[LENGTH];
	int pos_PACK=0;
	int start_PACK=0;
	int lastSidx_PACK = -1;
	bool PACK_ready = false;
	bool updated;

	//Topics advertise

	// subscribe to sensor_combined topic

	int sensor_sub_fd = orb_subscribe(ORB_ID(sensor_combined));
	orb_set_interval(sensor_sub_fd, 10);
	int gps_sub_fd = orb_subscribe(ORB_ID(vehicle_gps_position));
	orb_set_interval(gps_sub_fd, 200);
	int att_sub_fd = orb_subscribe(ORB_ID(vehicle_attitude));
	orb_set_interval(att_sub_fd, 10);

	// Run indefinitely while the serial loop handles data
	warnx("\nREADY, waiting for serial data.\n");

	/* Main loop*/
	while (!thread_should_exit) {

		orb_check(sensor_sub_fd, &updated);
				if (updated){
					struct sensor_combined_s sens;
					orb_copy(ORB_ID(sensor_combined),sensor_sub_fd,&sens);
					struct vehicle_attitude_s att;
					orb_copy(ORB_ID(vehicle_attitude),att_sub_fd,&att);
					struct vehicle_gps_position_s gps;
					orb_copy(ORB_ID(vehicle_gps_position),gps_sub_fd,&gps);
					serial_write(fd, sens,att,gps);


				}




		//usleep(20000);

	}

	close_port(fd);
	thread_running = false;

	return 0;
}
示例#19
0
/*!
 \brief main() is the typical main function in a C program, it performs
 all core initialization, loading of all main parameters, initializing handlers
 and entering gtk_main to process events until program close
 \param argc (gint) count of command line arguments
 \param argv (char **) array of command line args
 \returns TRUE
 */
gint main(gint argc, gchar ** argv)
{
	gint port_fd = 0;
	gint file_fd = 0;
	
	verify_args(argc, argv);

	output(g_strdup_printf("MegaTunix msloader %s\n",VERSION),TRUE);

	/* If we got this far, all is good argument wise */
	if (!lock_port(argv[2]))
	{
		output("Could NOT LOCK Serial Port\nCheck for already running serial apps using the port\n",FALSE);
		exit(-1);
	}

	port_fd = open_port(argv[2]);
	if (port_fd > 0)
		output("Port successfully opened\n",FALSE);
	else
	{
		output("Could NOT open Port check permissions\n",FALSE);
		unlock_port();
		exit(-1);
	}
#ifdef __WIN32__
	file_fd = open(argv[3], O_RDWR | O_BINARY );
#else
	file_fd = g_open(argv[3],O_RDONLY,S_IRUSR);
#endif
	if (file_fd > 0 )
		output("Firmware file successfully opened\n",FALSE);
	else
	{
		output("Could NOT open firmware file, check permissions/paths\n",FALSE);
		close_port(port_fd);
		unlock_port();
		exit(-1);
	}
	if (type == MS1)
	{
		setup_port(port_fd, 9600);
		do_ms1_load(port_fd,file_fd);
	}
	else if (type == MS2)
	{
		setup_port(port_fd,115200);
		do_ms2_load(port_fd,file_fd);
	}

	else if (type == FREEEMS)
	{
		setup_port(port_fd,115200);
		do_freeems_load(port_fd,file_fd);
	}

	flush_serial(port_fd,BOTH);
	close_port(port_fd);
	unlock_port();
	return (0) ;
}
示例#20
0
int adbd_main(int server_port) {
    umask(0);

    signal(SIGPIPE, SIG_IGN);

    init_transport_registration();

    // We need to call this even if auth isn't enabled because the file
    // descriptor will always be open.
    adbd_cloexec_auth_socket();

    // Respect ro.adb.secure in userdebug/eng builds (ALLOW_ADBD_NO_AUTH), or when the
    // device is unlocked.
    if ((ALLOW_ADBD_NO_AUTH || is_device_unlocked()) &&
        !android::base::GetBoolProperty("ro.adb.secure", false)) {
        auth_required = false;
    }

    adbd_auth_init();

    // Our external storage path may be different than apps, since
    // we aren't able to bind mount after dropping root.
    const char* adb_external_storage = getenv("ADB_EXTERNAL_STORAGE");
    if (adb_external_storage != nullptr) {
        setenv("EXTERNAL_STORAGE", adb_external_storage, 1);
    } else {
        D("Warning: ADB_EXTERNAL_STORAGE is not set.  Leaving EXTERNAL_STORAGE"
          " unchanged.\n");
    }

    drop_privileges(server_port);

    bool is_usb = false;
    if (access(USB_FFS_ADB_EP0, F_OK) == 0) {
        // Listen on USB.
        usb_init();
        is_usb = true;
    }

    // If one of these properties is set, also listen on that port.
    // If one of the properties isn't set and we couldn't listen on usb, listen
    // on the default port.
    std::string prop_port = android::base::GetProperty("service.adb.tcp.port", "");
    if (prop_port.empty()) {
        prop_port = android::base::GetProperty("persist.adb.tcp.port", "");
    }

    int port;
    if (sscanf(prop_port.c_str(), "%d", &port) == 1 && port > 0) {
        D("using port=%d", port);
        // Listen on TCP port specified by service.adb.tcp.port property.
        setup_port(port);
    } else if (!is_usb) {
        // Listen on default port.
        setup_port(DEFAULT_ADB_LOCAL_TRANSPORT_PORT);
    }

    D("adbd_main(): pre init_jdwp()");
    init_jdwp();
    D("adbd_main(): post init_jdwp()");

    D("Event loop starting");
    fdevent_loop();

    return 0;
}
示例#21
0
int main(int argc, char **argv)
{
  int opt;
  int result = 0;

  sbp_state_t s;

  if (argc <= 1) {
    usage(argv[0]);
    exit(EXIT_FAILURE);
  }

  while ((opt = getopt(argc, argv, "p:")) != -1) {
    switch (opt) {
    case 'p':
      serial_port_name = (char *)calloc(strlen(optarg) + 1, sizeof(char));
      if (!serial_port_name) {
        fprintf(stderr, "Cannot allocate memory!\n");
        exit(EXIT_FAILURE);
      }
      strcpy(serial_port_name, optarg);
      break;
    case 'h':
      usage(argv[0]);
      exit(EXIT_FAILURE);
    }
  }

  if (!serial_port_name) {
    fprintf(stderr, "Please supply the serial port path where the Piksi is " \
            "connected!\n");
    exit(EXIT_FAILURE);
  }

  result = sp_get_port_by_name(serial_port_name, &piksi_port);
  if (result != SP_OK) {
    fprintf(stderr, "Cannot find provided serial port!\n");
    exit(EXIT_FAILURE);
  }

  result = sp_open(piksi_port, SP_MODE_READ);
  if (result != SP_OK) {
    fprintf(stderr, "Cannot open %s for reading!\n", serial_port_name);
    exit(EXIT_FAILURE);
  }

  setup_port();

  sbp_state_init(&s);
  #if 0

  /* Register a node and callback, and associate them with a specific message ID. */
  sbp_register_callback(&s, SBP_MSG_HEARTBEAT, &hearbeat_callback, NULL,
                        &heartbeat_callback_node);
  sbp_register_callback(&s, SBP_MSG_GPS_TIME, &sbp_gps_time_callback,
                        NULL, &gps_time_node);
  sbp_register_callback(&s, SBP_MSG_POS_LLH, &sbp_pos_llh_callback,
                        NULL, &pos_llh_node);
  sbp_register_callback(&s, SBP_MSG_BASELINE_NED, &sbp_baseline_ned_callback,
                        NULL, &baseline_ned_node);
  sbp_register_callback(&s, SBP_MSG_VEL_NED, &sbp_vel_ned_callback,
                        NULL, &vel_ned_node);
  sbp_register_callback(&s, SBP_MSG_DOPS, &sbp_dops_callback,
                        NULL, &dops_node);

  /* Use sprintf to right justify floating point prints. */
  char rj[30];
  /* Only want 1 call to SH_SendString as semihosting is quite slow.
   * sprintf everything to this array and then print using array. */
  char str[1000];
  int str_i;
#endif
  while (1) {
    // sbp_process(&s, &piksi_port_read);

    sleep(1);
    fprintf(stdout, "hello\n");
    
    #if 0
    str_i = 0;
    memset(str, 0, sizeof(str));

    str_i += sprintf(str + str_i, "\n\n\n\n");

    /* Print GPS time. */
    str_i += sprintf(str + str_i, "GPS Time:\n");
    str_i += sprintf(str + str_i, "\tWeek\t\t: %6d\n", (int)gps_time.wn);
    sprintf(rj, "%6.2f", ((float)gps_time.tow) / 1e3);
    str_i += sprintf(str + str_i, "\tSeconds\t: %9s\n", rj);
    str_i += sprintf(str + str_i, "\n");

    /* Print absolute position. */
    str_i += sprintf(str + str_i, "Absolute Position:\n");
    sprintf(rj, "%4.10lf", pos_llh.lat);
    str_i += sprintf(str + str_i, "\tLatitude\t: %17s\n", rj);
    sprintf(rj, "%4.10lf", pos_llh.lon);
    str_i += sprintf(str + str_i, "\tLongitude\t: %17s\n", rj);
    sprintf(rj, "%4.10lf", pos_llh.height);
    str_i += sprintf(str + str_i, "\tHeight\t: %17s\n", rj);
    str_i += sprintf(str + str_i, "\tSatellites\t:     %02d\n", pos_llh.n_sats);
    str_i += sprintf(str + str_i, "\n");

    /* Print NED (North/East/Down) baseline (position vector from base to rover). */
    str_i += sprintf(str + str_i, "Baseline (mm):\n");
    str_i += sprintf(str + str_i, "\tNorth\t\t: %6d\n", (int)baseline_ned.n);
    str_i += sprintf(str + str_i, "\tEast\t\t: %6d\n", (int)baseline_ned.e);
    str_i += sprintf(str + str_i, "\tDown\t\t: %6d\n", (int)baseline_ned.d);
    str_i += sprintf(str + str_i, "\n");

    /* Print NED velocity. */
    str_i += sprintf(str + str_i, "Velocity (mm/s):\n");
    str_i += sprintf(str + str_i, "\tNorth\t\t: %6d\n", (int)vel_ned.n);
    str_i += sprintf(str + str_i, "\tEast\t\t: %6d\n", (int)vel_ned.e);
    str_i += sprintf(str + str_i, "\tDown\t\t: %6d\n", (int)vel_ned.d);
    str_i += sprintf(str + str_i, "\n");

    /* Print Dilution of Precision metrics. */
    str_i += sprintf(str + str_i, "Dilution of Precision:\n");
    sprintf(rj, "%4.2f", ((float)dops.gdop / 100));
    str_i += sprintf(str + str_i, "\tGDOP\t\t: %7s\n", rj);
    sprintf(rj, "%4.2f", ((float)dops.hdop / 100));
    str_i += sprintf(str + str_i, "\tHDOP\t\t: %7s\n", rj);
    sprintf(rj, "%4.2f", ((float)dops.pdop / 100));
    str_i += sprintf(str + str_i, "\tPDOP\t\t: %7s\n", rj);
    sprintf(rj, "%4.2f", ((float)dops.tdop / 100));
    str_i += sprintf(str + str_i, "\tTDOP\t\t: %7s\n", rj);
    sprintf(rj, "%4.2f", ((float)dops.vdop / 100));
    str_i += sprintf(str + str_i, "\tVDOP\t\t: %7s\n", rj);
    str_i += sprintf(str + str_i, "\n");
    #endif
  }

  result = sp_close(piksi_port);
  if (result != SP_OK) {
    fprintf(stderr, "Cannot close %s properly!\n", serial_port_name);
  }

  sp_free_port(piksi_port);

  free(serial_port_name);

  return 0;
}