谁能建议我如何在 Quectel MC60 模块中为 BLE 编写自己的 AT 命令头文件,仅供参考?

Can anyone suggest me how to write my own header-file of AT commands for BLE in Quectel MC60 module, just for a reference?

我是嵌入式固件开发的新手,也是第一次使用 MC60。 我必须为我将在 MC60 中使用的所有功能编写自己的头文件和库,无论是 UART、BLE、GSM、GPS 等。我想知道如何用 C 编写头文件,它可以从 MCU 向 MC60 发送 AT 命令并获取响应。但是,要使用的 MCU 仍未确定,作为参考,我想要一个 C 脚本,它可以像我们使用库 LiquidCrystal.h 为 Arduino LCD 命令自定义 MC60 的 AT 命令一样,如果有人能告诉我如何把BLE模块的一两条命令写在一个头文件里,可以作为我自己写其他命令的参考

我正在关注这个 BLE AT 命令的 PDF 文档,它包含我想在我的头文件中自定义的所有命令。 https://github.com/nkolban/esp32-snippets/files/2105752/Quectel_MC60_BLE_AT_Commands_Manual_V1.1.pdf

I want to know how can I write a header file in C, that can send an AT command

来自 simplewikipedia header file:

In computer programming, a header file can be thought of as a dictionary a compiler uses if it comes across a word it does not understand.

来自 wikipedia source code:

The source code of a program is specially designed to facilitate the work of computer programmers.

您不能编写将执行操作的头文件。源代码做电脑"work",头文件作为字典。

I want to know how can I write a header file in C

网上有很多关于如何用 C 编写头文件的教程。 tutorialspoint 上的教程就是其中之一。

if anyone can tell me how to write one or two commands of the BLE module

意见:经验法则 - google "github I want this" 您将获得代码示例。

libraries for all the features I'll be using in MC60, be it UART, BLE, GSM, GPS

Whosebug 不是编码服务。

开始向上或向下。创建一个抽象。创建 API 并编写支持您的抽象的库。向上(或向下)工作并创建所有相关的源文件。

Arduino 有许多你可以使用的库。 AT 命令是您通过通信发送的纯数据 link - 主要是通过通用异步接收传输 (UART),但不仅如此。您 link 编辑的文档非常准确——它列出了您可以在您的设备上使用的所有可用 AT 命令。阅读。

can send an AT command to MC60 from the MCU and just fetch the response.

arduino 上的所有串行通信都在Serial 中进行了描述。您可以在 arduino 在线获取许多串口通信示例。请注意,arduino 库是在 C++ 中,而不是在 C 中。您可以为 uart 通信编写自己的抽象(或者根本没有抽象)。下载适用于您的设备的 datasheet/reference 手册,阅读它并开始在您的程序中实现所需的功能。

I want a script in C that can just customize the AT commands

// abstract API to send the data pointed to by pointer with ptrsize bytes through UART
void uart_send(void *ptr, size_t ptrsize);
// abstract API to read the data from uart and place it at memory pointed to by ptr
// reads as much as ptrsize bytes or until timeout_ms miliseconds timeout
void uart_read(void *ptr, size_t ptrsize, int timeout_ms);

// buffer
char buf[256];

// "customize" buf to the "Power on/off BT" at command that powers up the device
snprintf(buf, sizeof(buf), "AT+QBTPWR=1\r\n");
// power up the device
uart_send(buf, strlen(buf));

// read the response from the device with 1 second timeout
uart_read(buf, sizeof(buf), 1000);
// check the response
if (strcmp(buf, "OK\r\n") != 0) { 
    fprintf(stderr, "Device didn't repond with OK!\n");
    abort();
}


// "customize" buf to have the "Power on/off BT" at command that powers down the device
snprintf(buf, sizeof(buf), "AT+QBTPWR=0\r\n");
// power down the device
uart_send(buf, strlen(buf));

uart_read(buf, sizeof(buf), 1000);
if (strcmp(buf, "OK\r\n") != 0) { 
    fprintf(stderr, "Device didn't repond with OK!\n");
    abort();
}

以上我已经自定义了命令来打开或关闭设备。通过简单的 snprintf,您可以使用所有系列的 printf 格式修饰符,包括 "%d".

int state = 1;
snprintf(buf, sizeof(buf), "AT+QBTPWR=%d\r\n", state);