|
大家好,
由于个人原因需要使用C语音对NXT进行编程,经过查阅一些资料最终选择了nxtOSEK(http://lejos-osek.sourceforge.net/zh-cn/index.htm)。
而这两天在尝试对NXT和NXT之间的蓝牙连接时一直没有成功,在此请教各位。
依照nxtOSEK主页的蓝牙教程http://lejos-osek.sourceforge.net/zh-cn/nxt2nxt.htm
“当程序在NXT上执行后,我们会在LCD屏幕的左上角看到蓝牙设备的地址。这些信息必需在 主NXT 上的代码运行实现。如果 从NXT 获取蓝牙设备地址失败,"BD_ADDR:Failed..."信息将代替地址信息出现。在这种情况下,需要重启从NXT。”
然而在我运行了nxtOSEK提供的样例程序btslave.c之后,并没有有关我NXT设备的蓝牙地址在屏幕上显示,然而也没有任何出错信息。
问题是在他提供的程序中我没有找到任何有关显示我的蓝牙设备地址的代码,不知是什么问题或者是否还有其他方法获取从设备的蓝牙地址。
先谢谢大家了!
注:本人使用的nxtOSEK firmware为1.07版本,操作系统是vista。
程序代码如下:
/* btslave.c */
#include "kernel.h"
#include "kernel_id.h"
#include "ecrobot_interface.h"
/* OSEK declarations */
DeclareCounter(SysTimerCnt);
DeclareTask(EventDispatcher);
DeclareTask(EventHandler);
DeclareTask(IdleTask);
DeclareEvent(TouchSensorOnEvent);
DeclareEvent(TouchSensorOffEvent);
/* below macro enables run-time Bluetooth connection */
#define RUNTIME_CONNECTION
/* nxtOSEK hooks */
void ecrobot_device_initialize()
{
#ifndef RUNTIME_CONNECTION
ecrobot_init_bt_slave("LEJOS-OSEK");
#endif
}
void ecrobot_device_terminate()
{
ecrobot_term_bt_connection();
}
/* EventDispatcher executed every 5ms */
TASK(EventDispatcher)
{
static U8 bt_receive_buf[32];
static U8 TouchSensorStatus_old = 0;
U8 TouchSensorStatus;
/* read packet data from the master device */
ecrobot_read_bt_packet(bt_receive_buf, 32);
if (bt_receive_buf[0] == 1)
{
ecrobot_set_motor_speed(NXT_PORT_B, 100);
}
else
{
ecrobot_set_motor_speed(NXT_PORT_B, 0);
}
TouchSensorStatus = ecrobot_get_touch_sensor(NXT_PORT_S4);
if (TouchSensorStatus == 1 && TouchSensorStatus_old == 0)
{
/* Send a Touch Sensor ON Event to the Handler */
SetEvent(EventHandler, TouchSensorOnEvent);
}
else if (TouchSensorStatus == 0 && TouchSensorStatus_old == 1)
{
/* Send a Touch Sensor OFF Event to the Handler */
SetEvent(EventHandler, TouchSensorOffEvent);
}
TouchSensorStatus_old = TouchSensorStatus;
TerminateTask();
}
/* EventHandler executed by OSEK Events */
TASK(EventHandler)
{
static U8 bt_send_buf[32];
while(1)
{
WaitEvent(TouchSensorOnEvent); /* Task is in waiting status until the Event comes */
ClearEvent(TouchSensorOnEvent);
/* send packet data to the master device */
bt_send_buf[0] = 1;
ecrobot_send_bt_packet(bt_send_buf, 32);
WaitEvent(TouchSensorOffEvent); /* Task is in waiting status until the Event comes */
ClearEvent(TouchSensorOffEvent);
/* send packet data to the master device */
bt_send_buf[0] = 0;
ecrobot_send_bt_packet(bt_send_buf, 32);
}
TerminateTask();
}
/* IdleTask */
TASK(IdleTask)
{
static SINT bt_status = BT_NO_INIT;
while(1)
{
#ifdef RUNTIME_CONNECTION
ecrobot_init_bt_slave("LEJOS-OSEK");
#endif
if (ecrobot_get_bt_status() == BT_STREAM && bt_status != BT_STREAM)
{
display_clear(0);
display_goto_xy(0, 0);
display_string("[BT]");
display_update();
}
bt_status = ecrobot_get_bt_status();
}
} |
|