示例#1
0
int main( void ) 
{
  uint8_t init_cpt;
  /* init peripherals */
  timer_init(); 
  modem_init();
  adc_init();
#ifdef CTL_BRD_V1_1  
  adc_buf_channel(ADC_CHANNEL_BAT, &buf_bat);
#endif
  spi_init();
  link_fbw_init();
  gps_init();
  nav_init();
  ir_init();
  estimator_init();
#	ifdef PAPABENCH_SINGLE
		fbw_init();
#	endif

  /* start interrupt task */
  //sei(); /*Fadia*/

  /* Wait 0.5s (for modem init ?) */
  init_cpt = 30;
  _Pragma("loopbound min 31 max 31")
  while (init_cpt) {
    if (timer_periodic())
      init_cpt--;
  }

  /*  enter mainloop */
#ifndef NO_MAINLOOP
  while( 1 ) {
#endif
    if(timer_periodic()) {
      periodic_task();
#		if PAPABENCH_SINGLE
			fbw_schedule();
#		endif
	}
    if (gps_msg_received) 
    {
	/*receive_gps_data_task()*/
	parse_gps_msg();
	send_gps_pos();
        send_radIR();
        send_takeOff();
    }
    if (link_fbw_receive_complete) {
      link_fbw_receive_complete = FALSE;
      radio_control_task();
    }
#ifndef NO_MAINLOOP
  } 
#endif
  return 0;
}
示例#2
0
/**
 * Powers up the modem
 *
 * Enables the GPIO lines to the modem and then wriggles the power line in short pulses.
 */
bool PPPCellularInterface::power_up()
{
    /* Initialize GPIO lines */
    modem_init();
    /* Give modem a little time to settle down */
    wait(0.25);

    bool success = false;

    int retry_count = 0;
    while (true) {
        modem_power_up();
        /* Modem tends to spit out noise during power up - don't confuse the parser */
        _at->flush();
        /* It is mandatory to avoid sending data to the serial port during the first 200 ms
         * of the module startup. Telit_xE910 Global form factor App note.
         * Not necessary for all types of modems however. Let's wait just to be on the safe side */
        wait_ms(200);
        _at->set_timeout(1000);
        if (_at->send("AT") && _at->recv("OK")) {
            tr_info("Modem Ready.");
            break;
        }

        if (++retry_count > 10) {
            goto failure;
        }
    }

    _at->set_timeout(8000);

    /*For more details regarding DCD and DTR circuitry, please refer to Modem AT manual */
    success = _at->send("AT"
                        "E0;" //turn off modem echoing
                        "+CMEE=2;"//turn on verbose responses
                        "&K0"//turn off RTC/CTS handshaking
                        "+IPR=115200;"//setup baud rate
                        "&C1;"//set DCD circuit(109), changes in accordance with the carrier detect status
                        "&D0")//set DTR circuit, we ignore the state change of DTR
              && _at->recv("OK");

    if (!success) {
        goto failure;
    }

    /* If everything alright, return from here with success*/
    return success;

failure:
    tr_error("Preliminary modem setup failed.");
    return false;
}
示例#3
0
int ppp_modem_init(const char *number, int blind, int *conn_rate) {
    uint64_t timeout;

    /* Initialize the modem. */
    if(!modem_init())
        return -1;

    /* Set the modem up to connect to a remote machine. */
    modem_set_mode(MODEM_MODE_REMOTE, MODEM_SPEED_V8_AUTO);

    /* If we aren't doing blind dialing, wait up to 5 seconds for a dialtone. */
    if(!blind) {
        if(modem_wait_dialtone(5000)) {
            modem_shutdown();
            return -2;
        }
    }

    /* Dial the specified phone number. */
    if(!modem_dial(number)) {
        modem_shutdown();
        return -3;
    }

    /* Give ourselves a 60 second timeout to establish a connection. */
    timeout = timer_ms_gettime64() + 60 * 1000;
    while(timer_ms_gettime64() < timeout && modem_is_connecting()) {
        thd_pass();
    }

    /* Did we connect successfully? */
    if(!modem_is_connected()) {
        modem_shutdown();
        return -4;
    }

    /* Does the user want the connection rate back? If so give it to them. */
    if(conn_rate) {
        *conn_rate = modem_get_connection_rate();
    }

    dbglog(DBG_KDEBUG, "ppp_modem: connected at %lu bps\n",
           modem_get_connection_rate());

    /* We connected to the peer successfully, set our device with libppp. */
    ppp_set_device(&modem_dev);

    return 0;
}
/* Entry point */
void main(void) {
	start_up_delay();      
	safe_op();
	gsm_uart_init();    
	gpio_port(); 
	PORTBbits.RB0 = 1; // A/B // gsm modem connected      
	gsm = ON;  
	modem_init();
	PORTAbits.RA1 = LED_ON;

	/* Keep looping until powered off */
	while(1) {
		clr_buf(); 
		clean_sim();
		PORTAbits.RA0 = LED_ON;
		wait_4_msg();       
		get_index();  
		read_msg();
		check_msg();
		PORTAbits.RA6 = LED_ON;
		if(success == 1) {  
			get_mob_no();      
			send_msg_cmd();           
			gsm = OFF;
			PORTCbits.RC0 = LED_ON; 
			gps_handler();
			PORTCbits.RC1 = LED_ON; 
			gsm = ON;
			gsm_uart_init();  
			PORTBbits.RB0 = 1;        // A/B ---> gsm modem connected  
			INTCONbits.GIEH = 1;      // Enable all unmasked interrupt           
			send_loc(); 
			PORTCbits.RC2 = LED_ON;
			for(k=60000; k>5; k--); 
			PORTAbits.RA0 = LED_OFF;
			PORTAbits.RA6 = LED_OFF;
			PORTCbits.RC0 = LED_OFF;
			PORTCbits.RC1 = LED_OFF;
			PORTCbits.RC2 = LED_OFF;  
		}else {
			PORTAbits.RA0 = LED_OFF;
			PORTAbits.RA6 = LED_OFF;
		} 
	}            	                 
}
示例#5
0
int main(void) {
  board_init(BOARD_MODE_RUN);
  board_console_init(BOARD_DEBUG_BAUD);

  SysTick_Config(BOARD_SYSTICK_100MS / 10);

  // Initialize modem
  modem_init();

  if (!modem_enable()) error("modem enable");
  if (!modem_register(60000)) error("network register");
  if (!modem_gprs_attach(CELL_APN, CELL_USER, CELL_PWD, 30000)) error("GPRS attach");

  double lat = 0.0, lon = 0.0;
  rtc_datetime_t date;
  modem_location(&lat, &lon, &date, 30000);

  PRINTF("%04hd-%02hd-%02hd %02hd:%02hd:%02hd\r\n",
         date.year, date.month, date.day, date.hour, date.minute, date.second);

  PRINTF("Location: lat=%f, lon=%f\r\n", lat, lon);

  if (!modem_tcp_connect("api.ubirch.com", 80, 5000)) error("TCP connect");

  const char *send_data = "GET / HTTP/1.1\r\n\r\n";
  if (!modem_tcp_send((const uint8_t *) send_data, (uint8_t) strlen(send_data), 30000))
    error("simulated HTTP GET");

  uint8_t buffer[8192];
  size_t received = modem_tcp_receive(buffer, 1500, 10000);
  PRINTF("received %d bytes\r\n", received);

  dbg_dump("RCV", buffer, received);

  modem_tcp_close(1000);

  modem_disable();

  while (true) {
    delay(1000);
  }
}
示例#6
0
void vPapabenchInit()
{
    mode = MODE_AUTO;
    pprz_mode = PPRZ_MODE_HOME;
    timer_init();
    modem_init();
    adc_init();
#ifdef CTL_BRD_V1_1
    adc_buf_channel(uint8_t adc_channel, struct adc_buf *s);
#endif 
    spi_init();
    link_fbw_init();
    gps_init();
    nav_init();
    ir_init();
    estimator_init();
#ifdef PAPABENCH_SINGLE
    fbw_init();
#endif
}
示例#7
0
文件: main_ap.c 项目: lxl/paparazzi
void init_ap( void ) {
#ifndef SINGLE_MCU /** init done in main_fbw in single MCU */
  mcu_init();
  sys_time_init();
#endif /* SINGLE_MCU */

  /************* Sensors initialization ***************/
#ifdef USE_INFRARED
  infrared_init();
#endif
#ifdef USE_GYRO
  gyro_init();
#endif
#ifdef USE_GPS
  gps_init();
#endif

#ifdef USE_GPIO
  GpioInit();
#endif

#ifdef USE_IMU
  imu_init();
#endif
#ifdef USE_AHRS
  ahrs_aligner_init();
  ahrs_init();
#endif

  /************* Links initialization ***************/
#if defined MCU_SPI_LINK
  link_mcu_init();
#endif
#ifdef MODEM
  modem_init();
#endif

  /************ Internal status ***************/
  h_ctl_init();
  v_ctl_init();
  estimator_init();
#ifdef ALT_KALMAN
  alt_kalman_init();
#endif
  nav_init();

  modules_init();

  settings_init();

  /** - start interrupt task */
  mcu_int_enable();

  /** wait 0.5s (historical :-) */
  sys_time_usleep(500000);

#if defined GPS_CONFIGURE
  gps_configure_uart();
#endif

#if defined DATALINK

#if DATALINK == XBEE
  xbee_init();
#endif
#endif /* DATALINK */

#if defined AEROCOMM_DATA_PIN
  IO0DIR |= _BV(AEROCOMM_DATA_PIN);
  IO0SET = _BV(AEROCOMM_DATA_PIN);
#endif

  power_switch = FALSE;

  /************ Multi-uavs status ***************/

#ifdef TRAFFIC_INFO
  traffic_info_init();
#endif
}
示例#8
0
void init_ap( void ) {
#ifndef SINGLE_MCU /** init done in main_fbw in single MCU */
  hw_init();
  sys_time_init();

#ifdef LED
  led_init();
#endif

#ifdef ADC
  adc_init();
#endif
#endif /* SINGLE_MCU */

  /************* Sensors initialization ***************/
#ifdef USE_INFRARED
  ir_init();
#endif
#ifdef USE_GYRO
  gyro_init();
#endif
#ifdef USE_GPS
  gps_init();
#endif
#ifdef USE_UART0
  Uart0Init();
#endif
#ifdef USE_UART1
  Uart1Init();
#endif
#ifdef USE_UART2
  Uart2Init();
#endif
#ifdef USE_UART3
  Uart3Init();
#endif
#ifdef USE_USB_SERIAL
  VCOM_init();
#endif

#ifdef USE_GPIO
  GpioInit();
#endif

#ifdef USE_I2C0
  i2c0_init();
#endif
#ifdef USE_I2C1
  i2c1_init();
#endif
#ifdef USE_I2C2
  i2c2_init();
#endif

  /************* Links initialization ***************/
#if defined USE_SPI
  spi_init();
#endif
#if defined MCU_SPI_LINK
  link_mcu_init();
#endif
#ifdef MODEM
  modem_init();
#endif

  /************ Internal status ***************/
  h_ctl_init();
  v_ctl_init();
  estimator_init();
#ifdef ALT_KALMAN
  alt_kalman_init();
#endif
  nav_init();

  modules_init();

  /** - start interrupt task */
  int_enable();

  /** wait 0.5s (historical :-) */
  sys_time_usleep(500000);

#if defined GPS_CONFIGURE
  gps_configure_uart();
#endif

#if defined DATALINK

#if DATALINK == XBEE
  xbee_init();
#endif
#endif /* DATALINK */

#if defined AEROCOMM_DATA_PIN
  IO0DIR |= _BV(AEROCOMM_DATA_PIN);
  IO0SET = _BV(AEROCOMM_DATA_PIN);
#endif

  power_switch = FALSE;

  /************ Multi-uavs status ***************/

#ifdef TRAFFIC_INFO
  traffic_info_init();
#endif

}
static void *SWITCH_THREAD_FUNC modem_thread(switch_thread_t *thread, void *obj)
{
	modem_t *modem = obj;
	int r, avail;
#ifdef WIN32
	DWORD readBytes;
	OVERLAPPED o;
#endif
	char buf[T31_TX_BUF_LEN], tmp[80];

	switch_mutex_lock(globals.mutex);
	modem_init(modem, control_handler);
	globals.THREADCOUNT++;
	switch_mutex_unlock(globals.mutex);

	if (switch_test_flag(modem, MODEM_FLAG_RUNNING)) {
		switch_mutex_lock(modem->cond_mutex);

		while (switch_test_flag(modem, MODEM_FLAG_RUNNING)) {

#ifndef WIN32
			r = modem_wait_sock(modem->master, -1, MODEM_POLL_READ | MODEM_POLL_ERROR);
#else
			r = modem_wait_sock(modem, -1, MODEM_POLL_READ | MODEM_POLL_ERROR);
#endif

			if (!switch_test_flag(modem, MODEM_FLAG_RUNNING)) {
				break;
			}

			if (r < 0 || !(r & MODEM_POLL_READ) || (r & MODEM_POLL_ERROR)) {
				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Bad Read on master [%s] [%d]\n", modem->devlink, r);
				break;
			}

			modem->last_event = switch_time_now();

			if (switch_test_flag(modem, MODEM_FLAG_XOFF)) {
				switch_thread_cond_wait(modem->cond, modem->cond_mutex);
				modem->last_event = switch_time_now();
			}

			avail = sizeof(buf) - modem->t31_state->tx.in_bytes + modem->t31_state->tx.out_bytes - 1;

			if (avail == 0) {
				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Buffer Full, retrying....\n");
				switch_yield(10000);
				continue;
			}

#ifndef WIN32		
			r = read(modem->master, buf, avail);
#else
			o.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

			/* Initialize the rest of the OVERLAPPED structure to zero. */
			o.Internal = 0;
			o.InternalHigh = 0;
			o.Offset = 0;
			o.OffsetHigh = 0;
			assert(o.hEvent);
			if (!ReadFile(modem->master, buf, avail, &readBytes, &o)) {
				GetOverlappedResult(modem->master,&o,&readBytes,TRUE);
			}
			CloseHandle (o.hEvent);
			r = readBytes;
#endif

			t31_at_rx(modem->t31_state, buf, r);

			memset(tmp, 0, sizeof(tmp));
			if (!strncasecmp(buf, "AT", 2)) {
				int x;
				strncpy(tmp, buf, r);
				for(x = 0; x < r; x++) {
					if(tmp[x] == '\r' || tmp[x] == '\n') {
						tmp[x] = '\0';
					}
				}

				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1,   "Command on %s [%s]\n", modem->devlink, tmp);
			}
		}

		switch_mutex_unlock(modem->cond_mutex);

		if (switch_test_flag(modem, MODEM_FLAG_RUNNING)) {
			modem_close(modem);
		}
	}

	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,   "Thread ended for %s\n", modem->devlink);

	switch_mutex_lock(globals.mutex);
	globals.THREADCOUNT--;
	switch_mutex_unlock(globals.mutex);

	return NULL;
}
/* Prepare the GSM Modem for english character based SMS send/recieve from SIM */
void modem_init(void) {
	cmd_1();
	if(gsm_buf[7]=='O' && gsm_buf[8]=='K')
		success = 1; 
	else
		success = 0; 
	if (success == 1)
	{;}
	else
		modem_init();

	cmd_2(); 
	if(gsm_buf[2]=='O' && gsm_buf[3]=='K')
		success = 1; 
	else
		success = 0; 
	if (success == 1)
	{;}
	else
		modem_init();

	cmd_3();
	if(gsm_buf[2]=='O' && gsm_buf[3]=='K')
		success = 1; 
	else
		success = 0; 
	if (success == 1)
	{;}
	else
		modem_init();

	cmd_4();
	if(gsm_buf[2]=='O' && gsm_buf[3]=='K')
		success = 1; 
	else
		success = 0; 
	if (success == 1)
	{;}
	else
		modem_init();

	cmd_5();
	if(gsm_buf[6]=='S' && gsm_buf[7]==':')
		success = 1; 
	else
		success = 0; 
	if (success == 1)
	{;}
	else
		modem_init();

	cmd_6(); 
	if(gsm_buf[2]=='O' && gsm_buf[3]=='K')
		success = 1; 
	else
		success = 0; 
	if (success == 1)
	{;}
	else
		modem_init();        
}
示例#11
0
文件: main.c 项目: grepz/modem_ctrl
int main(int argc, char *argv[])
{
    char           IMEI[15];
    modem_status_t status;
    modem_err_t    err;
    modem_ret_t    ret;

    (void)argv;
    (void)argc;

//    if (argc < 2) {
//        printf("Set device to operate.\n");
//        return EXIT_FAILURE;
//    }

    printf("Started, device '%s' used\n", argv[1]);

__modem_start:

    ret = modem_init("/dev/ttyUSB0");
    if (ret != MODEM_RET_OK) {
        printf("Error initializing modem=%d\n", ret);
        return EXIT_FAILURE;
    }

    ret = __modem_configure();
    if (ret != 0) {
        printf("Error configuring modem=%d\n", ret);
        return EXIT_FAILURE;
    }

    ret = __get_IMEI(IMEI);
    if (ret == 0)
        printf("IMEI> %s\n", IMEI);
    else {
        printf("No IMEI received: %d\n", ret);
        return EXIT_FAILURE;
    }

#if 0
    for (;;) {
        modem_get_status(&status, &err);
        printf("Status=%04X, error=%04X, auth=%d\n", status, err, __auth);
        if ((status & MODEM_STATUS_ONLINE) == 0) { /* Full restart */
            modem_destroy();
            goto __modem_start;
        }
        if ((status & MODEM_STATUS_REG) == 0) { /* No network registration */
            modem_send_cmd(MODEM_CMD_CREG_GET, NULL, NULL, NULL, 1);
            continue;
        }

       ret = modem_conn_start(BP_SERVICE_PROF);
       if (ret != MODEM_RET_OK) {
           ret = modem_conn_stop(BP_SERVICE_PROF);
           continue;
       }

       sleep(10);

        __get_bin(status);
    }
#endif

    for (;;) {
        sleep(1);

        modem_get_status(&status, &err);
        printf("Status=%04X, error=%04X, auth=%d\n", status, err, __auth);

        if ((status & MODEM_STATUS_ONLINE) == 0) { /* Full restart */
            modem_destroy();
            goto __modem_start;
        }
        if ((status & MODEM_STATUS_REG) == 0) { /* No network registration */
            modem_send_cmd(MODEM_CMD_CREG_GET, NULL, NULL, NULL, 1);
            continue;
        }
        if ((status & MODEM_STATUS_CONN) == 0) {
            ret = modem_conn_start(TCS_SERVICE_PROF);
            if (ret != MODEM_RET_OK) {
                ret = modem_conn_stop(TCS_SERVICE_PROF);
            }
            continue;
        }

        __client_auth(status);
    }

    return EXIT_SUCCESS;
}
示例#12
0
int main()
{
    int           answerMode = 0;
    unsigned char data[DATA_BUFFER_LENGTH];
    int           i;
    int           byteCount;

    if (!modem_init())
    {
       printf("modem_init failed!\n");
       return 1;
    }

    printf("\nDreamcast modem - example 1\n");
    printf("Press START to exit\n\n");

    if (answerMode)
       printf("Answer mode - Call the Dreamcast. It will pick up after one ring.\n\n");
       else
       printf("Remote mode - Connect the phone line to your computer's modem and use ATA to\n              \"answer\" the Dreamcast.\n\n");

    printf("Once the modems are connected you can send data to the Dreamcast,\n");
    printf("and the Dreamcast can send data to the remote modem by pressing the\n");
    printf("A button.\n\n");

    while (!buttonPressed(CONT_START))
    {
          modem_set_mode(answerMode ? MODEM_MODE_ANSWER :
                                      MODEM_MODE_REMOTE,
                         MODEM_SPEED_V8_AUTO);

          printf("Waiting for a connection..\n");
          while (modem_is_connecting())
          {
                if (buttonPressed(CONT_START))
                {
                   printf("Connection aborted\n");
                   return 0;
                }
          }

          if (modem_is_connected())
          {
             printf("Connected at %dbps\n", (int)modem_get_connection_rate());

             while (!buttonPressed(CONT_START) && modem_is_connected())
             {
                   /* Receive data */
                   if (modem_has_data())
                   {
                      byteCount = modem_read_data(data, DATA_BUFFER_LENGTH);
                      for (i=0; i<byteCount; i++)
                          printf("%c", (data[i] >= 32 && data[i] <= 126) ?
                                        data[i] : ' ');
                   }

                   /* Send data */
                   if (buttonPressed(CONT_A))
                   {
                      for (i=0; i<8; i++)
                          data[i] = (int)'a' + i;

                      modem_write_data(data, 8);
                   }
             }

             if (modem_is_connected())
             {
                printf("Disconnecting..\n");
                modem_disconnect();

                while (buttonPressed(CONT_START));
             } else
               printf("Disconnected\n");
          } else
            printf("Connection failed\n");
    }

    return 0;
}