Example #1
0
int main(int argc,char **argv){
	char s[4];
	byte port=0;		// ↓お手持ちのXBeeモジュールのIEEEアドレスに変更する
	byte dev_gpio[]   = {0x00,0x13,0xA2,0x00,0x40,0x30,0xC1,0x6F};	// PIO デバイス
	
	// 初期化処理
	if( argc==2 ) port = (byte)(argv[1][0]-'0');
	xbee_init( port );					// XBee用COMポートの初期化(引数はポート番号)
	xbee_atnj( 0xFF );					// デバイスを常に参加受け入れ(テスト用)
	
	// メイン処理
	while(1){							// 永久に受信する
		printf("input[0-2]:");
		fgets(s, 4, stdin);
		switch( s[0] ){
			case '0':
				xbee_gpo(dev_gpio,12,1);		// GPOポート12をHレベル(3.3V)へ
				xbee_gpo(dev_gpio,11,1);		// GPOポート11をHレベル(3.3V)へ
				break;
			case '1':
				xbee_gpo(dev_gpio,12,0);		// GPOポート12をLレベル(0V)へ
				break;
			case '2':
				xbee_gpo(dev_gpio,11,0);		// GPOポート11をLレベル(0V)へ
				break;
		}
	}
}
Example #2
0
void downlink_init(void)
{
  downlink.nb_ovrn = 0;
  downlink.nb_bytes = 0;
  downlink.nb_msgs = 0;

#if defined DATALINK
#if DATALINK == PPRZ || DATALINK == SUPERBITRF || DATALINK == W5100
  pprz_transport_init(&pprz_tp);
#endif
#if DATALINK == XBEE
  xbee_init();
#endif
#if DATALINK == W5100
  w5100_init();
#endif
#endif

#if USE_PPRZLOG
  pprzlog_transport_init();
#endif

#if SITL
  ivy_transport_init();
#endif

#if PERIODIC_TELEMETRY
  register_periodic_telemetry(DefaultPeriodic, "DATALINK_REPORT", send_downlink);
#endif
}
int main(int argc,char **argv){

    char s[32];                                 // 文字入力用
    byte com=0;                                 // シリアルCOMポート番号
    byte dev[]={0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF};
                                                // 宛先XBeeアドレス(ブロードキャスト)

    if(argc==2) com=(byte)atoi(argv[1]);        // 引数があれば変数comに代入する
    xbee_init( com );                           // XBee用COMポートの初期化
    printf("Waiting for XBee Commissoning\n");  // 待ち受け中の表示
    if(xbee_atnj(30) != 0){                     // デバイスの参加受け入れを開始
        printf("Found a Device\n");             // XBee子機デバイスの発見表示
        xbee_from( dev );                       // 見つけた子機のアドレスを変数devへ
        xbee_ratnj(dev,0);                      // 子機に対して孫機の受け入れ制限を設定
    }else{                                      // 子機が見つからなかった場合
        printf("no Devices\n");                 // 見つからなかったことを表示
        exit(-1);                               // 異常終了
    }
    
    while(1){
        /* データ送信 */
        printf("TX-> ");                        // 文字入力欄の表示
        gets( s );                              // 入力文字を変数sに代入
        xbee_uart( dev , s );                   // 変数sの文字を送信
    }
}
int main(int argc,char **argv){

    byte com=0;                                 // シリアルCOMポート番号
    byte value;                                 // 受信値
    byte trig=0;                                // 子機へデータ要求するタイミング調整用
    XBEE_RESULT xbee_result;                    // 受信データ(詳細)

    if(argc==2) com=(byte)atoi(argv[1]);        // 引数があれば変数comに代入する
    xbee_init( com );                           // XBee用COMポートの初期化
    xbee_atnj( 0xFF );                          // 親機XBeeを常にジョイン許可状態にする
    xbee_gpio_config(dev,1,DIN);                // 子機XBeeのポート1をデジタル入力に
   
    while(1){
        /* データ送信 */
        if( trig == 0){
            xbee_force( dev );                  // 子機へデータ要求を送信
            trig = FORCE_INTERVAL;
        }
        trig--;

        /* データ受信(待ち受けて受信する) */
        xbee_rx_call( &xbee_result );           // データを受信
        if( xbee_result.MODE == MODE_RESP){     // xbee_forceに対する応答の時
            value = xbee_result.GPI.PORT.D1;    // D1ポートの値を変数valueに代入
            printf("Value =%d\n",value);        // 変数valueの値を表示
        }
    }
}
int main(int argc,char **argv){

    byte com=0;                                 // シリアルCOMポート番号
    byte dev[8];                                // XBee子機デバイスのアドレス
    float value;                                // 受信データの代入用
    XBEE_RESULT xbee_result;                    // 受信データ(詳細)

    if(argc==2) com=(byte)atoi(argv[1]);        // 引数があれば変数comに代入する
    xbee_init( com );                           // XBee用COMポートの初期化
    xbee_atnj( 0xFF );                          // 子機XBeeデバイスを常に参加受け入れ
    printf("Waiting for XBee Commissoning\n");  // 待ち受け中の表示

    while(1){
        /* データ受信(待ち受けて受信する) */
        xbee_rx_call( &xbee_result );               // データを受信
        switch( xbee_result.MODE ){                 // 受信したデータの内容に応じて
            case MODE_GPIN:                         // 子機XBeeの自動送信の受信
                // 照度測定結果をvalueに代入してprintfで表示する
                value = (float)xbee_result.ADCIN[1] * 3.55;
                printf("%.1f Lux\n" , value );
                break;
            case MODE_IDNT:                         // 新しいデバイスを発見
                printf("Found a New Device\n");
                xbee_atnj(0);                       // 子機XBeeデバイスの参加を不許可へ
                bytecpy(dev, xbee_result.FROM, 8);  // 発見したアドレスをdevにコピーする
                set_ports( dev );                   // 子機のGPIOポートの設定
                break;
        }
    }
}
Example #6
0
/********** INIT *************************************************************/
void init_rctx( void ) {
  hw_init();
  sys_time_init();
#ifdef LED
  led_init();
#endif
#ifdef USE_UART1
    Uart1Init();
#endif
#ifdef ADC
  adc_init();
  adc_buf_channel(ADC_CHANNEL_VSUPPLY, &vsupply_adc_buf, DEFAULT_AV_NB_SAMPLE);
#endif
#ifdef RADIO_CONTROL
  ppm_init();
#endif
  int_enable();

  /** - wait 0.5s (for modem init ?) */
  uint8_t init_cpt = 30;
  while (init_cpt) {
    if (sys_time_periodic())
      init_cpt--;
  }

#if defined DATALINK
#if DATALINK == XBEE
  xbee_init();
#endif
#endif /* DATALINK */
}
Example #7
0
STATIC_INLINE void main_init( void ) {

  mcu_init();

  electrical_init();

  stateInit();

  actuators_init();
#if USE_MOTOR_MIXING
  motor_mixing_init();
#endif

  radio_control_init();

  air_data_init();
#if USE_BARO_BOARD
  baro_init();
#endif
  imu_init();
#if USE_IMU_FLOAT
  imu_float_init();
#endif
  ahrs_aligner_init();
  ahrs_init();

  ins_init();

#if USE_GPS
  gps_init();
#endif

  autopilot_init();

  modules_init();

  settings_init();

  mcu_int_enable();

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

#if DATALINK == UDP
  udp_init();
#endif

  // register the timers for the periodic functions
  main_periodic_tid = sys_time_register_timer((1./PERIODIC_FREQUENCY), NULL);
  modules_tid = sys_time_register_timer(1./MODULES_FREQUENCY, NULL);
  radio_control_tid = sys_time_register_timer((1./60.), NULL);
  failsafe_tid = sys_time_register_timer(0.05, NULL);
  electrical_tid = sys_time_register_timer(0.1, NULL);
  telemetry_tid = sys_time_register_timer((1./TELEMETRY_FREQUENCY), NULL);
#if USE_BARO_BOARD
  baro_tid = sys_time_register_timer(1./BARO_PERIODIC_FREQUENCY, NULL);
#endif
}
Example #8
0
/*
 * main.c
 */
int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

    if (CALBC1_1MHZ==0xFF)					// If calibration constant erased
    {
      while(1);                               // do not load, trap CPU!!
    }

	lcdinit();
	uart_init();

	__bis_SR_register(GIE);

//	uint8_t str[8] = {'+','+','+',0x00};
//
//	uart_send_frame(str);
//
//	while( !rx_ok ); // Wait until we have received OK from xbee
//	str[0] = 'A';
//	str[1] = 'T';
//	str[2] = 'A';
//	str[3] = 'P';
//	str[4] = ' ';
//	str[5] = '1';
//	str[6] = 0x0D;
//	str[7] = 0x00;
//	rx_ok = 0;
//	uart_send_frame(str);
//
//	while( !rx_ok );
//	str[2] = 'C';
//	str[3] = 'N';
//	str[4] = ' ';
//	rx_ok = 0;
//	uart_send_frame(str);
//
//	while( !rx_ok );
//
//	// Should be in API mode now
//	uint8_t buf[22] = {0x7E, 0x00, 0x04, 0x08, 0x07, 'W', 'R', 0x00};
//
//	__delay_cycles(10000000);
//	buf[7] = calculate_checksum(buf+3,4);
//
//	uart_send_frame(buf);


	xbee_init("128");
//
//	packet_rx_handler( print_packet );
//
//	xbee_tx_packet( 100, "Hi!", 3 );


	while(1);

	return 0;
}
Example #9
0
STATIC_INLINE void main_init( void ) {

  mcu_init();

  electrical_init();

  stateInit();

  actuators_init();
#if USE_MOTOR_MIXING
 // motor_mixing_init();
 // servo_mixing_init();
  set_servo_init();
#endif

  radio_control_init();

  baro_init();
  imu_init();
  autopilot_init();
  nav_init();
  guidance_h_init();
  guidance_v_init();
  stabilization_init();

  ahrs_aligner_init();
  ahrs_init();

  ins_init();

#if USE_GPS
  gps_init();
#endif

  modules_init();

  settings_init();

  mcu_int_enable();

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

#if DATALINK == UDP
  udp_init();
#endif

  // register the timers for the periodic functions
  main_periodic_tid = sys_time_register_timer((1./PERIODIC_FREQUENCY), NULL);
  modules_tid = sys_time_register_timer(1./MODULES_FREQUENCY, NULL);
  radio_control_tid = sys_time_register_timer((1./60.), NULL);
  failsafe_tid = sys_time_register_timer(0.05, NULL);
  electrical_tid = sys_time_register_timer(0.1, NULL);
  baro_tid = sys_time_register_timer(1./BARO_PERIODIC_FREQUENCY, NULL);
  telemetry_tid = sys_time_register_timer((1./TELEMETRY_FREQUENCY), NULL);
}
Example #10
0
/**
 * Initialize the peripherals and state for this task.
 */
uint8_t
beacon_task_setup() {
	/* Create an IPC queue to receive updates from the Skywire task. */
	xSLUpdatesQueue = xQueueCreate( 10, sizeof(SLUpdate));

	/* Initialize the UART to communicate with the XBee radio. */
	xbee_init();

	return 1; // OK
}
Example #11
0
int main(int argc,char **argv){
	byte trig=0;
	byte dev_en = 0;	// センサー発見の有無(0:未発見)
	XBEE_RESULT xbee_result;
	float value;
	byte port=0;
	byte dev_sens[8];	// センサデバイス
	
	// 初期化処理
	if( argc==2 ) port = (byte)(argv[1][0]-'0');
	xbee_init( port );					// COMポート初期化(引数はポート番号)
	
	// デバイス探索
	printf("Searching:SENSOR\n");
	if( xbee_atnj(10) ){				// 10秒間の参加受け入れ
		dev_en = 1;						// sensor発見済
		set_sensor_adc(dev_sens);
	}else printf("Failed:no devices\n");
	
	// メイン処理
	printf("Receiving\n");
	while(1){							// 永久に受信する
		if( dev_en && trig == 0){
			xbee_force( dev_sens );		// デバイスdev_sensへデータ要求
			trig = 250;
		}
		trig--;

		/* データ受信(待ち受けて受信する) */
		xbee_rx_call( &xbee_result );	// データを受信します。
		switch( xbee_result.MODE ){		// 受信したデータの内容(MODE値)に応じて
			case MODE_RESP:				// sensorからの応答の場合に照度と温度を表示
				if( bytecmp( dev_sens , xbee_result.FROM ,8 ) == 0 &&
				xbee_result.STATUS == STATUS_OK ){
					// 照度測定結果
					value = xbee_sensor_result( &xbee_result,LIGHT);
					printf("%.0f Lux, ",value);
					// 温度測定結果
					value = xbee_sensor_result( &xbee_result,TEMP);
					printf("%.1f degC, ",value);
					//
					printf("%d\n",xbee_result.GPI.PORT.D11);
				}
				break;
			case MODE_IDNT:				// 新しいデバイスを発見
				dev_en = 1;				// sensor発見済
				set_sensor_adc(dev_sens);
				break;
		}
	}
}
Example #12
0
File: main.c Project: wuwx/simba
static int test_init(struct harness_t *harness_p)
{
    BTASSERT(xbee_module_init() == 0);
    BTASSERT(xbee_module_init() == 0);

    BTASSERT(queue_init(&queue, &queue_buf[0], sizeof(queue_buf)) == 0);
    BTASSERT(chan_init(&transport,
                       chan_read_null,
                       chan_write_null,
                       chan_size_null) == 0);
    BTASSERT(xbee_init(&xbee, &transport, &transport) == 0);

    return (0);
}
int main(int argc,char **argv){
	char lcd1[]="ボクニモワカル";				// 液晶1行目(8文字)
	char lcd2[]=" XBee ZB";				// 液晶2行目(8文字)
	byte data[2];
	byte i;	// ↓お手持ちのXBeeモジュールのIEEEアドレスに変更する
	byte dev[]   = {0x00,0x13,0xA2,0x00,0x40,0x30,0xC1,0x6F};	// PIO デバイス

	byte port=0;
	
	// 初期化処理
	if( argc==2 ) port = (byte)(argv[1][0]-'0');
	xbee_init( port );					// XBee用COMポートの初期化(引数はポート番号)
	xbee_atnj( 0xFF );					// デバイスを常に参加受け入れ(テスト用)
	xbee_i2c_init(dev);					// I2Cインタフェースの初期化
	
	// メイン処理
	
	print_timer();printf("LCD Init\n");
//	data[0]=0x00; data[1]=0x38; xbee_i2c_write(dev,0x7C,data,2);	// IS=0
	data[0]=0x00; data[1]=0x39; xbee_i2c_write(dev,0x7C,data,2);	// IS=1
//	data[0]=0x00; data[1]=0x14; xbee_i2c_write(dev,0x7C,data,2);	// OSC Freq.	4
	data[0]=0x00; data[1]=0x7E; xbee_i2c_write(dev,0x7C,data,2);	// コントラスト	E
	data[0]=0x00; data[1]=0x5D; xbee_i2c_write(dev,0x7C,data,2);	// Power/Cont	D
	data[0]=0x00; data[1]=0x6C; xbee_i2c_write(dev,0x7C,data,2);	// FollowerCtrl	C
	delay(200);
	data[0]=0x00; data[1]=0x38; xbee_i2c_write(dev,0x7C,data,2);	// IS=0
	data[0]=0x00; data[1]=0x0C; xbee_i2c_write(dev,0x7C,data,2);	// DisplayON	C
//	data[0]=0x00; data[1]=0x01; xbee_i2c_write(dev,0x7C,data,2);	// ClearDisplay
//	data[0]=0x00; data[1]=0x06; xbee_i2c_write(dev,0x7C,data,2);	// EntryMode	6
	
	print_timer();printf("LCD Data 1\n");
	data[0]=0x00; data[1]=0x80; xbee_i2c_write(dev,0x7C,data,2);	// 1行目
	for(i=0;i<8;i++){
		data[0]=0x40;
		data[1]=(byte)lcd1[i];
		xbee_i2c_write(dev,0x7C,data,2);
	}
	
	print_timer();printf("LCD Data 2\n");
	data[0]=0x00; data[1]=0xC0; xbee_i2c_write(dev,0x7C,data,2);	// 2行目
	for(i=0;i<8;i++){
		data[0]=0x40;
		data[1]=(byte)lcd2[i];
		xbee_i2c_write(dev,0x7C,data,2);
	}
	
	print_timer();printf("Done\n");
	return(0);
}
Example #14
0
int main(int argc,char **argv){
    byte com=0;                         // シリアルCOMポート番号
    unsigned int  value;                // リモート子機からの入力値
    
    if(argc==2) com=(byte)atoi(argv[1]);// 引数があれば変数comに代入する
    xbee_init( com );                   // XBee用COMポートの初期化
    xbee_atnj( 0xFF );                  // 親機XBeeを常にジョイン許可状態にする

    while(1){                           // 繰り返し処理
        /* XBee通信 */
        value = xbee_adc(dev,1);        // リモート子機のポート1からアナログ値を入力
        printf("Value =%d\n",value);    // 変数valueの値を表示する
        delay( 1000 );                  // 1000ms(1秒間)の待ち
    }
}
Example #15
0
int main(void){
    xbee_init( 0 );                     // XBeeの初期化
    printf("Example 66 RSSI (Any key to Exit)\n");
    while( xbee_ping(dev)==00 ){        // 繰り返し処理
        xbee_rat(dev,"ATP005");         // リモートATコマンドATP0(DIO10設定)=05(出力'H')
        xbee_rat(dev,"ATD405");         // リモートATコマンドATD4(DIO 4設定)=05(出力'H')
        delay( 1000 );                  // 約1000ms(1秒間)の待ち
        xbee_rat(dev,"ATP004");         // リモートATコマンドATP0(DIO10設定)=04(出力'L')
        xbee_rat(dev,"ATD404");         // リモートATコマンドATD4(DIO 4設定)=04(出力'L')
        delay( 1000 );                  // 約1000ms(1秒間)の待ち
        if( kbhit() ) break;            // キーが押されていた時にwhileループを抜ける
    }
    printf("\ndone\n");
    return(0);
}
Example #16
0
STATIC_INLINE void main_init( void ) {

#ifndef NO_FUCKING_STARTUP_DELAY
#ifndef RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT
  /* IF THIS IS NEEDED SOME PERHIPHERAL THEN PLEASE MOVE IT THERE */
  for (uint32_t startup_counter=0; startup_counter<2000000; startup_counter++){
    __asm("nop");
  }
#endif
#endif

  mcu_init();

  sys_time_init();
  electrical_init();

  actuators_init();
  radio_control_init();

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

  baro_init();
  imu_init();
  autopilot_init();
  nav_init();
  guidance_h_init();
  guidance_v_init();
  stabilization_init();

  ahrs_aligner_init();
  ahrs_init();

  ins_init();

#ifdef USE_GPS
  gps_init();
#endif

  modules_init();

  settings_init();

  mcu_int_enable();

}
Example #17
0
int main(int argc,char **argv){

    byte com=0;                                     // シリアルCOMポート番号
    byte dev[8];                                    // XBee子機デバイスのアドレス
    byte id=0;                                      // パケット送信番号
    byte trig=0xFF;                                 // データ要求するタイミング調整用
    float value;                                    // 受信データの代入用
    XBEE_RESULT xbee_result;                        // 受信データ(詳細)

    if(argc==2) com=(byte)atoi(argv[1]);            // 引数があれば変数comに代入する
    xbee_init( com );                               // XBee用COMポートの初期化
    xbee_atnj( 0xFF );                              // 親機に子機のジョイン許可を設定
    printf("Waiting for XBee Commissoning\n");      // 待ち受け中の表示
    
    while(1){
        /* データ送信 */
        if( trig == 0){
            id = xbee_force( dev );                 // 子機へデータ要求を送信
            trig = FORCE_INTERVAL;
        }
        if( trig != 0xFF ) trig--;                  // 変数trigが0xFF以外の時に値を1減算

        /* データ受信(待ち受けて受信する) */
        xbee_rx_call( &xbee_result );               // データを受信
        switch( xbee_result.MODE ){                 // 受信したデータの内容に応じて
            case MODE_RESP:                         // xbee_forceに対する応答の時
                if( id == xbee_result.ID ){         // 送信パケットIDが一致
                    // 照度測定結果をvalueに代入してprintfで表示する
                    value = xbee_sensor_result( &xbee_result, LIGHT);
                    printf("%.1f Lux, " , value );
                    // 温度測定結果をvalueに代入してprintfで表示する
                    value = xbee_sensor_result( &xbee_result, TEMP);
                    value -= TEMP_OFFSET;
                    printf("%.1f degC\n" , value );
                }
                break;
            case MODE_IDNT:                         // 新しいデバイスを発見
                printf("Found a New Device\n");
                bytecpy(dev, xbee_result.FROM, 8);  // 発見したアドレスをdevにコピーする
                xbee_atnj(0);                       // 親機XBeeに子機の受け入れ制限
                xbee_ratnj(dev,0);                  // 子機に対して孫機の受け入れを制限
                set_ports( dev );                   // 子機のGPIOポートの設定
                trig = 0;                           // 子機へデータ要求を開始
                break;
        }
    }
}
Example #18
0
STATIC_INLINE void main_init( void ) {

  mcu_init();

  electrical_init();

  actuators_init();
  radio_control_init();

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

  
  imu_init();
  autopilot_init();
  nav_init();
  guidance_h_init();
  guidance_v_init();
  stabilization_init();

  ahrs_aligner_init();
  ahrs_init();
baro_init();
  ins_init();

#if USE_GPS
  gps_init();
#endif

  modules_init();

  settings_init();

  mcu_int_enable();

  // register the timers for the periodic functions
  main_periodic_tid = sys_time_register_timer((1./PERIODIC_FREQUENCY), NULL);
  radio_control_tid = sys_time_register_timer((1./60.), NULL);
  failsafe_tid = sys_time_register_timer(0.05, NULL);
  electrical_tid = sys_time_register_timer(0.1, NULL);
  baro_tid = sys_time_register_timer(0.02, NULL);
  telemetry_tid = sys_time_register_timer((1./60.), NULL);
}
int main(int argc,char **argv){
    
    byte com=0;                             	// シリアルCOMポート番号
    byte dev_bell[8];                       	// XBee子機(ベル)デバイスのアドレス
    byte dev_sw[8];                         	// XBee子機(スイッチ)デバイスのアドレス
    byte trig=0;                                // 子機へデータ要求するタイミング調整用
    XBEE_RESULT xbee_result;                	// 受信データ(詳細)

    if(argc==2) com=(byte)atoi(argv[1]);    	// 引数があれば変数comに代入する
    xbee_init( com );                       	// XBee用COMポートの初期化
    printf("Waiting for XBee Bell\n");
    xbee_atnj(60);                          	// デバイスの参加受け入れ
    xbee_from( dev_bell );                  	// 見つけた子機のアドレスを変数devへ
    bell(dev_bell,3);							// ベルを3回鳴らす
    xbee_end_device(dev_bell, 1, 0, 0);      	// 起動間隔1秒,自動測定OFF,SLEEP端子無効
    printf("Waiting for XBee Switch\n");
    xbee_atnj(60);                          	// デバイスの参加受け入れ
    xbee_from( dev_sw );                    	// 見つけた子機のアドレスを変数devへ
    bell(dev_bell,3);							// ベルを3回鳴らす
    xbee_gpio_init( dev_sw );               	// 子機のDIOにIO設定を行う
    xbee_end_device(dev_sw, 3, 0, 1);     		// 起動間隔3秒,自動送信OFF,SLEEP端子有効
    printf("done\n");

    while(1){
        if( trig == 0){
            xbee_force( dev_sw );                  		// 子機へデータ要求を送信
            trig = FORCE_INTERVAL;
        }
        trig--;
        xbee_rx_call( &xbee_result );                   // データを受信
        switch( xbee_result.MODE ){                     // 受信したデータの内容に応じて
            case MODE_RESP:
            case MODE_GPIN:                             // 子機XBeeの自動送信の受信
                if(xbee_result.GPI.PORT.D1 == 0){
	                printf("D1=0 Ring\n");
	                bell(dev_bell,3);					// ベルを3回鳴らす
	            }else printf("D1=1\n");
                bell(dev_bell,0);						// ベル音を消す
                break;
        }
    }
}
Example #20
0
int main(void) {
    char s[3];                          // 入力用(2文字まで)
    byte port=4;                        // リモート機のポート番号(初期値=4)
    byte value=1;                       // リモート機への設定値(初期値=1)

    xbee_init( 0 );                     // XBeeの初期化
    printf("Example 67 LED ('q' to Exit)\n");
    while( xbee_ping(dev)==00 ) {       // 繰り返し処理
        xbee_gpo(dev,port,value);       // リモート機ポート(port)に制御値(value)を設定
        printf("Port  =");              // ポート番号入力のための表示
        gets( s );                      // キーボードからの入力
        if( s[0] == 'q' ) break;        // [q]が入力された時にwhileを抜ける
        port = atoi( s );               // 入力文字を数字に変換してportに代入
        printf("Value =");              // 値の入力のための表示
        gets( s );                      // キーボードからの入力
        value = atoi( s );              // 入力文字を数字に変換してvalueに代入
    }
    printf("done\n");
    return(0);
}
Example #21
0
void auto_init_ng_netif(void)
{
    int res;
    kernel_pid_t iface;

    /* setup Xbee device */
    printf("Initializing the Xbee S1 device UART_%i... \n", XBEE_UART);
    res = xbee_init(&dev, XBEE_UART, XBEE_BAUDRATE, GPIO_NUMOF, GPIO_NUMOF);
    if (res < 0) {
        puts("Error initializing xbee device driver");
        return;
    }
    /* start MAC layer */
    iface = ng_nomac_init(nomac_stack, sizeof(nomac_stack), PRIO, "xbee",
                          (ng_netdev_t *)(&dev));
    if (iface <= KERNEL_PID_UNDEF) {
        puts("Error initializing MAC layer");
        return;
    }
}
Example #22
0
void auto_init_xbee(void)
{
    for (int i = 0; i < XBEE_NUM; i++) {
        const xbee_params_t *p = &xbee_params[i];
        DEBUG("Initializing XBee radio at UART_%i\n", p->uart);
        int res = xbee_init(&xbee_devs[i],
                p->uart,
                p->baudrate,
                p->sleep_pin,
                p->status_pin);

        if (res < 0) {
            DEBUG("Error initializing XBee radio device!");
        }
        else {
            ng_nomac_init(_nomac_stacks[i],
                    XBEE_MAC_STACKSIZE, XBEE_MAC_PRIO, "xbee",
                    (ng_netdev_t *)&xbee_devs[i]);
        }
    }
}
Example #23
0
int main(void) {
  avr_init();
  avr_adc_init();

  xbee_init();
  xbee_wait_for_association();

  avr_clear_bit(LIGHT_SENSOR_PORT, LIGHT_SENSOR_PIN);

  union {
    uint16_t reading;
    uint8_t  bytes[2];
  } light;

  while(TRUE) {
    light.reading = avr_adc_read(LIGHT_SENSOR_PIN);
    xbee_send_bytes(light.bytes, 2);
    _delay_ms(60000L);
  }

  return(0);
}
Example #24
0
int main(int argc,char **argv) {

    byte port=0;                                // シリアルCOMポート番号
    byte ret=0;

    if( argc==2 ) {
        if( atoi(argv[1]) < 0 ) {
            port = 0x9F + (byte)(-atoi(argv[1])) ;
        } else  if( ( argv[1][0]=='b' || argv[1][0]=='B' )&& argv[1][1]!='\0' ) {
            port = 0xB0 + ( argv[1][1] - '0');
        } else  if( ( argv[1][0]=='a' || argv[1][0]=='A' )&& argv[1][1]!='\0' ) {
            port = 0xA0 + ( argv[1][1] - '0');
        } else port = (byte)(atoi(argv[1]));
    }
    xbee_init( port );                          // XBee用COMポートの初期化
    printf("Disabling Encryption\n");
    ret = xbee_atee_off();
    if( ret <= 1 ) {                            // 暗号化をオフにする
        printf("SUCCESS\n");                    // 表示
    } else printf("Error(%02X)\n",ret);          // エラー表示
    return( ret );
}
Example #25
0
int main(void){
    byte value;                                     // 受信値
    XBEE_RESULT xbee_result;                        // 受信データ(詳細)

    xbee_init( 0 );                                 // XBeeの初期化
    printf("Example 68 SW_R (Any key to Exit)\n");
    if( xbee_ping(dev_gpio)==00 ){
        xbee_myaddress(dev_my);                     // 自分のアドレスを設定する
        xbee_gpio_init(dev_gpio);                   // デバイスdev_gpioにIO設定を行う
        while(1){
            xbee_rx_call( &xbee_result );           // データを受信
            if( xbee_result.MODE == MODE_GPIN){     // 子機XBeeのDIO入力
                value = xbee_result.GPI.PORT.D1;    // D1ポートの値を変数valueに代入
                printf("Value =%d\n",value);        // 変数valueの値を表示
                xbee_gpo(dev_gpio,4,value);         // 子機XBeeのDIOポート4へ出力
            }
            if( kbhit() ) break;                    // PCのキー押下時にwhileを抜ける
        }
    }
    printf("\ndone\n");
    return(0);
}
Example #26
0
int main() {
    board_init();
    uart_init();
    esc_init();
    rgbled_init();
    rgbled_set(0xFF8000, 100);
    spektrum_init();
    rgbled_set(0xFF8000, 100);
    xbee_init();
    i2c_init();
    alt_init();
    mag_init();
    mpu_init();
    sonar_init();
    ins_init();
    inscomp_init();
    altitude_init();
    controller_init();
    basestation_init();
    flight_init();

    controlpanel_run();
}
int main(int argc,char **argv){
    byte com=0;                         // シリアルCOMポート番号
    char s[3];                          // 入力用(2文字まで)
    byte port;                          // リモート子機のポート番号
    byte value;                         // リモート子機への設定値
    
    if(argc==2) com=(byte)atoi(argv[1]);// 引数があれば変数comに代入する
    xbee_init( com );                   // XBee用COMポートの初期化
    xbee_atnj( 0xFF );                  // 親機XBeeを常にジョイン許可状態にする

    while(1){                           // 繰り返し処理
    
        /* 子機のポート番号と制御値の入力 */
        printf("Port  =");              // ポート番号入力のための表示
        gets( s );                      // キーボードからの入力
        port = atoi( s );               // 入力文字を数字に変換してportに代入
        printf("Value =");              // 値の入力のための表示
        gets( s );                      // キーボードからの入力
        value = atoi( s );              // 入力文字を数字に変換してvalueに代入

        /* XBee通信 */
        xbee_gpo(dev,port,value);       // リモート子機ポート(port)に制御値(value)を設定
    }
}
Example #28
0
void init_ap( void ) 
{
#ifndef SINGLE_MCU /** init done in main_fbw in single MCU */
  mcu_init();
#endif /* SINGLE_MCU */

  /************* Sensors initialization ***************/
#if USE_GPS
  gps_init();
#endif

#ifdef USE_GPIO
  GpioInit();
#endif

#if USE_IMU
  imu_init();
#endif

#if USE_AHRS_ALIGNER
  ahrs_aligner_init();
#endif

#if USE_AHRS
  ahrs_init();
#endif

#if USE_BAROMETER
  baro_init();
#endif

  ins_init();

  stateInit();

  /************* Links initialization ***************/
#if defined MCU_SPI_LINK || defined MCU_UART_LINK
  link_mcu_init();
#endif
#if USE_AUDIO_TELEMETRY
  audio_telemetry_init();
#endif

  /************ Internal status ***************/
  autopilot_init();
  h_ctl_init();
  v_ctl_init();
  nav_init();

  modules_init();

  settings_init();

  /**** start timers for periodic functions *****/
  sensors_tid = sys_time_register_timer(1./PERIODIC_FREQUENCY, NULL);
  navigation_tid = sys_time_register_timer(1./NAVIGATION_FREQUENCY, NULL);
  attitude_tid = sys_time_register_timer(1./CONTROL_FREQUENCY, NULL);
  modules_tid = sys_time_register_timer(1./MODULES_FREQUENCY, NULL);
  telemetry_tid = sys_time_register_timer(1./60, NULL);
  monitor_tid = sys_time_register_timer(1.0, NULL);

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

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

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

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

#ifdef TRAFFIC_INFO
  traffic_info_init();
#endif
}
Example #29
0
/* Init kmsg input */
int in_xbee_init(struct flb_config *config)
{
    int ret;
    int opt_baudrate = 9600;
    char *tmp;
    char *opt_device = FLB_XBEE_DEFAULT_DEVICE;
    struct stat dev_st;
	struct xbee *xbee;
	struct xbee_con *con;
	struct xbee_conAddress address;
    struct flb_in_xbee_config *ctx;

    /* Check an optional baudrate */
    tmp = getenv("FLB_XBEE_BAUDRATE");
    if (tmp) {
        opt_baudrate = atoi(tmp);
    }

    /* Get the target device entry */
    tmp = getenv("FLB_XBEE_DEVICE");
    if (tmp) {
        opt_device = strdup(tmp);
    }
    flb_info("XBee device=%s, baudrate=%i", opt_device, opt_baudrate);

    ret = stat(opt_device, &dev_st);
    if (ret < 0) {
        printf("Error: could not open %s device\n", opt_device);
        exit(EXIT_FAILURE);
    }

    if (!S_ISCHR(dev_st.st_mode)) {
        printf("Error: invalid device %s \n", opt_device);
        exit(EXIT_FAILURE);
    }

    if (access(opt_device, R_OK | W_OK) == -1) {
        printf("Error: cannot open the device %s (permission denied ?)\n",
               opt_device);
        exit(EXIT_FAILURE);
    }

    /* Init library */
    xbee_init();

	ret = xbee_setup(&xbee, "xbeeZB", opt_device, opt_baudrate);
    if (ret != XBEE_ENONE) {
        flb_utils_error_c("xbee_setup");
		return ret;
	}

    /* FIXME: just a built-in example */
	memset(&address, 0, sizeof(address));
	address.addr64_enabled = 1;
	address.addr64[0] = 0x00;
	address.addr64[1] = 0x13;
	address.addr64[2] = 0xA2;
	address.addr64[3] = 0x00;
    address.addr64[4] = 0x40;
    address.addr64[5] = 0xB7;
    address.addr64[6] = 0xB1;
    address.addr64[7] = 0xEB;

    /* Prepare a connection with the peer XBee */
	if ((ret = xbee_conNew(xbee, &con, "Data", &address)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conNew() returned: %d (%s)", ret, xbee_errorToStr(ret));
		return ret;
	}

    /* Prepare the configuration context */
    ctx = calloc(1, sizeof(struct flb_in_xbee_config));
    if (!ctx) {
        perror("calloc");
        return -1;
    }
    ctx->device     = opt_device;
    ctx->baudrate   = opt_baudrate;
    ctx->con        = con;
    ctx->buffer_len = 0;

	if ((ret = xbee_conDataSet(con, ctx, NULL)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conDataSet() returned: %d", ret);
		return ret;
	}


	if ((ret = xbee_conCallbackSet(con, in_xbee_cb, NULL)) != XBEE_ENONE) {
		xbee_log(xbee, -1, "xbee_conCallbackSet() returned: %d", ret);
		return ret;
	}


    /* Set the context */
    ret = flb_input_set_context("xbee", ctx, config);
    if (ret == -1) {
        flb_utils_error_c("Could not set configuration for xbee input plugin");
    }

    /*
     * Set our collector based on time. We will trigger a collection at certain
     * intervals. For now it works but it's not the ideal implementation. I am
     * talking with libxbee maintainer to check possible workarounds and use
     * proper events mechanism.
     */
    ret = flb_input_set_collector_time("xbee",
                                       in_xbee_collect,
                                       IN_XBEE_COLLECT_SEC,
                                       IN_XBEE_COLLECT_NSEC,
                                       config);
    if (ret == -1) {
        flb_utils_error_c("Could not set collector for xbee input plugin");
    }

    return 0;
}
Example #30
0
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
}