您能帮我理解这个班级的构造函数吗? (adafruit_atparser)

发布于 2025-02-07 17:55:16 字数 3283 浏览 3 评论 0 原文

我正在为我的研究团队建造一个设备。简而言之,该设备使用连接到Arduino的电动机和负载传感器将旋转力施加到玉米茎上并记录茎的电阻。我们正在将蓝牙构建到设备中。我们正在使用此BT模块。 我们有一个BLE GATT服务,具有2个用于存储数据的特征和1个用于持有命令的特征,该命令将由设备读取并进行操作。阅读命令特征是我们遇到问题的地方。

void get_input(){
     uint16_t bufSize = 15;
     char inputBuffer[bufSize];
     bleParse = Adafruit_ATParser();    // Throws error: bleParse was not declared in this scope
     bleParse.atcommandStrReply("AT+GATTCHAR=3",&inputBuffer,bufSize,1000); 
     Serial.print("input:");
     Serial.println(inputBuffer);
}

我要使用的功能在 for Module in adarfruit_atparser.cpp

/******************************************************************************/
/*!
    @brief Constructor
*/
/******************************************************************************/
Adafruit_ATParser::Adafruit_ATParser(void)
{
  _mode    = BLUEFRUIT_MODE_COMMAND;
  _verbose = false;
}


******************************************************************************/
/*!
    @brief Send an AT command and get multiline string response into
           user-provided buffer.
    @param[in] cmd Command
    @param[in] buf Provided buffer
    @param[in] bufsize buffer size
    @param[in] timeout timeout in milliseconds
*/
/******************************************************************************/
uint16_t Adafruit_ATParser::atcommandStrReply(const char cmd[], char* buf, uint16_t bufsize, uint16_t timeout)
{
  uint16_t result_bytes;
  uint8_t current_mode = _mode;
  // switch mode if necessary to execute command
  if ( current_mode == BLUEFRUIT_MODE_DATA ) setMode(BLUEFRUIT_MODE_COMMAND);

  // Execute command with parameter and get response
  println(cmd);
  result_bytes = this->readline(buf, bufsize, timeout, true);

  // switch back if necessary
  if ( current_mode == BLUEFRUIT_MODE_DATA ) setMode(BLUEFRUIT_MODE_DATA);

  return result_bytes;
}

in图书馆中的示例使用此。他们都创建了自己的解析器。例如,neopixel_picker示例草图具有一个名为我相信从BT模块检索该特定草图的数据,但它永远不会包括或使用 adafruit_atparser。。在任何地方都没有此构造函数的示例,我不知道如何使用它。我尝试了这些方法:
bleparse = adafruit_atparser();
adafruit_atparser bleparse();
adafruit_atparser();
ble.adafruit_atparser bleparse();
注意:BLE是一个对象,表示Arduino和BT创建的BT之间的串行连接:

SoftwareSerial bluefruitSS = SoftwareSerial(BLUEFRUIT_SWUART_TXD_PIN, BLUEFRUIT_SWUART_RXD_PIN);
Adafruit_BluefruitLE_UART ble(bluefruitSS, BLUEFRUIT_UART_MODE_PIN,BLUEFRUIT_UART_CTS_PIN, BLUEFRUIT_UART_RTS_PIN);

谁能给我一个有关如何使用 adafruit_atparser() structionor的线索吗?另外,如果构造函数没有对BLE对象的引用,则它如何通过命令传递到BT模块?

我知道这是一个很大的要求,感谢您可以给我的任何意见。

I am building a device for my research team. To briefly describe it, this device uses a motor and load sensor connected to an Arduino to apply a rotational force to a corn stalk and record the resistance of the stalk. We are in the process of building Bluetooth into the device. We are using this BT module.
We have a BLE GATT Service with 2 characteristics for storing DATA and 1 for holding the command which is an integer that will be read by the device and acted on. Reading the command characteristic is where we encounter our problem.

void get_input(){
     uint16_t bufSize = 15;
     char inputBuffer[bufSize];
     bleParse = Adafruit_ATParser();    // Throws error: bleParse was not declared in this scope
     bleParse.atcommandStrReply("AT+GATTCHAR=3",&inputBuffer,bufSize,1000); 
     Serial.print("input:");
     Serial.println(inputBuffer);
}

The functions I am trying to use are found in the library for the module in Adarfruit_ATParser.cpp

/******************************************************************************/
/*!
    @brief Constructor
*/
/******************************************************************************/
Adafruit_ATParser::Adafruit_ATParser(void)
{
  _mode    = BLUEFRUIT_MODE_COMMAND;
  _verbose = false;
}


******************************************************************************/
/*!
    @brief Send an AT command and get multiline string response into
           user-provided buffer.
    @param[in] cmd Command
    @param[in] buf Provided buffer
    @param[in] bufsize buffer size
    @param[in] timeout timeout in milliseconds
*/
/******************************************************************************/
uint16_t Adafruit_ATParser::atcommandStrReply(const char cmd[], char* buf, uint16_t bufsize, uint16_t timeout)
{
  uint16_t result_bytes;
  uint8_t current_mode = _mode;
  // switch mode if necessary to execute command
  if ( current_mode == BLUEFRUIT_MODE_DATA ) setMode(BLUEFRUIT_MODE_COMMAND);

  // Execute command with parameter and get response
  println(cmd);
  result_bytes = this->readline(buf, bufsize, timeout, true);

  // switch back if necessary
  if ( current_mode == BLUEFRUIT_MODE_DATA ) setMode(BLUEFRUIT_MODE_DATA);

  return result_bytes;
}

None of the examples in the library use this. They all create their own parsers. For example, the neopixel_picker example sketch has a file called packetParser.cpp which I believe retrieves data from the BT module for that specific sketch, but it never includes or uses Adafruit_ATParser.. There are no examples of this constructor anywhere and I cannot figure out how to use it. I have tried these ways:
bleParse = Adafruit_ATParser();
Adafruit_ATParser bleParse();
Adafruit_ATParser();
ble.Adafruit_ATParser bleParse();
note: ble is an object that signifies a Serial connection between arduino and BT created with:

SoftwareSerial bluefruitSS = SoftwareSerial(BLUEFRUIT_SWUART_TXD_PIN, BLUEFRUIT_SWUART_RXD_PIN);
Adafruit_BluefruitLE_UART ble(bluefruitSS, BLUEFRUIT_UART_MODE_PIN,BLUEFRUIT_UART_CTS_PIN, BLUEFRUIT_UART_RTS_PIN);

Can anyone give me a clue on how to use the Adafruit_ATParser() constructor? Also, if the constructor has no reference to the ble object, how does it pass AT commands to the BT module?

I know this is a big ask, I appreciate any input you can give me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Saygoodbye 2025-02-14 17:55:16

像这样,

Adafruit_ATParser bleParse;

您最接近此 adafruit_atparser bleparse(); 。这是一个常见的初学者错误,因为它看起来正确。不幸的是,它声明了一个函数 bleparse ,它没有参数并返回 adafruit_atparser 对象。

我无法回答第二个问题。

编辑

我已经花了一些时间来查看代码。这就是我发现的

class Adafruit_BluefruitLE_UART : public Adafruit_BLE
{

class Adafruit_BLE : public Adafruit_ATParser
{

这意味着 adafruit_bluefruitle_uart class是从 adafruit_ble_ble 类派生的, class又是从 adafruit_atparser class派生的。 。派生意味着 Adafruit_ble 中的任何公共方法也可以在 adafruit_bluefruitle_uart 对象上使用。您已经有一个 adafruit_bluefruitle_uart 对象(您称其为 ble ),因此您可以只使用要在该对象上使用的方法。

SoftwareSerial bluefruitSS = SoftwareSerial(BLUEFRUIT_SWUART_TXD_PIN, BLUEFRUIT_SWUART_RXD_PIN);
Adafruit_BluefruitLE_UART ble(bluefruitSS, BLUEFRUIT_UART_MODE_PIN,BLUEFRUIT_UART_CTS_PIN, BLUEFRUIT_UART_RTS_PIN);
ble.atcommandStrReply( ... );

Like this

Adafruit_ATParser bleParse;

You were closest with this one Adafruit_ATParser bleParse();. This is a common beginner mistake because it looks right. Unfortunately it declares a function bleParse which takes no arguments and returns a Adafruit_ATParser object.

I can't answer the second question.

EDIT

I've taken the time to have a look at the code. This is what I found

class Adafruit_BluefruitLE_UART : public Adafruit_BLE
{

and

class Adafruit_BLE : public Adafruit_ATParser
{

what this means is that the Adafruit_BluefruitLE_UART class is derived from the Adafruit_BLE class which in turn is derived from the Adafruit_ATParser class. Derivation means that any public methods in Adafruit_BLE can also be used on a Adafruit_BluefruitLE_UART object. You already have an Adafruit_BluefruitLE_UART object (you called it ble) so you can just use the method you want to use on that object.

SoftwareSerial bluefruitSS = SoftwareSerial(BLUEFRUIT_SWUART_TXD_PIN, BLUEFRUIT_SWUART_RXD_PIN);
Adafruit_BluefruitLE_UART ble(bluefruitSS, BLUEFRUIT_UART_MODE_PIN,BLUEFRUIT_UART_CTS_PIN, BLUEFRUIT_UART_RTS_PIN);
ble.atcommandStrReply( ... );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文