cembeddedheader-filesquectel

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


I am new with Embedded firmware development and first time working with MC60. I have to write my own header files and libraries for all the features I'll be using in MC60, be it UART, BLE, GSM, GPS, etc. I want to know how can I write a header file in C, that can send an AT command to MC60 from the MCU and just fetch the response. The MCU to be used is still not decided however, for reference I want a script in C that can just customize the AT commands of MC60 like we have for Arduino LCD commands by using library LiquidCrystal.h, If anyone can tell me how to write one or two commands of the BLE module in a header file then that can act as reference for me to write other commands all by myself.

I am following this PDF document of AT commands for BLE and it consists of all the commands that I want to customize in my header file. https://github.com/nkolban/esp32-snippets/files/2105752/Quectel_MC60_BLE_AT_Commands_Manual_V1.1.pdf


Solution

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

    From 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.

    From wikipedia source code:

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

    You can't write a header file that will do an action. The source code does the "work" of the computer, header file serves as a dictionary.

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

    There are plenty tutorials on how to write header files in C over the net. The tutorial on tutorialspoint is one of them.

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

    Opinion: rule of a thumb - google "github I want this" and you will get code samples.

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

    Stackoverflow is not a coding service.

    Start your way up or down. Create an abstraction. Create API and write libraries that support your abstraction. Work way up (or down) and create all relevant source files.

    Arduino has many libraries you can use. AT commands are plain data you send through communication link - mostly through an universal asynchronous receive-transmitted (UART), but not only. The documentation you linked is exact - it lists all available AT commands you can use with your device. Read it.

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

    All the serial communications on arduino is described in Serial. You can get many examples of serial communications on arduino online. Note that arduino libraries are in C++, not in C. You can write your own abstraction for the uart communication (or have no abstraction at all). Download the datasheet/reference manual for your device, read it and start implementing the needed functionality in your program.

    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();
    }
    

    Above I have customized the command to power up or down the device. With simple snprintf you can use all the family printf format modifiers, including "%d".

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