找回密码
 马上注册

QQ登录

只需一步,快速开始

查看: 8333|回复: 5

使用nxtOSEK进行NXT与NXT之间的蓝牙连接问题

[复制链接]
发表于 2010-3-5 20:07:52 | 显示全部楼层 |阅读模式
大家好,

由于个人原因需要使用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();
      }
    }
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
 楼主| 发表于 2010-3-5 20:39:29 | 显示全部楼层
刚刚发现。。好像发错版了。。汗。。
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

发表于 2010-3-5 21:16:28 | 显示全部楼层
看不懂程序
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

 楼主| 发表于 2010-3-6 17:52:06 | 显示全部楼层
哎 看来nxtOSEK真是太小众了
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

发表于 2010-4-25 23:47:43 | 显示全部楼层
一个字:顶
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

发表于 2012-4-11 00:51:13 | 显示全部楼层
与BricxCC比有什么不同的优势???
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|中文乐高 ( 桂ICP备13001575号-7 )

GMT+8, 2024-5-29 04:04 , Processed in 0.073933 second(s), 18 queries .

Powered by Discuz! X3.5

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表