rt-thread AT设备EC20获取GNSS信息

EC20的某些版本,如EC20CEFILG-128-SGNS是具有GPS定位功能的,参照手册有对应的AT指令集可以读取,通过at_exec_cmd可以很方便的执行。

#include 

#define DBG_TAG "main"
#define DBG_LVL DBG_LOG
#include 


#include 

static void show_information()
{
    at_response_t resp = RT_NULL;
    resp = at_create_resp(512, 0, rt_tick_from_millisecond(5000));
    at_exec_cmd(resp, "AT+QGPSGNMEA=\"RMC\"");
    LOG_D("resp->line_counts:%d", resp->line_counts);
    for (int i = 0; i < (int) resp->line_counts; i++)
    {
        LOG_D("%s", at_resp_get_line(resp, i + 1));
    }
    at_delete_resp(resp);
}

int main(void)
{
    int count = 1;
    int i = 0;  //用于保存是否已经开启GPS
    LOG_D("Hello RT-Thread!");
    rt_thread_mdelay(5000);
    LOG_D("Hello RT-Thread!");

    at_response_t resp = RT_NULL;
    resp = at_create_resp(512, 0, rt_tick_from_millisecond(5000));

    at_exec_cmd(resp, "AT+QGPS?");
    LOG_D("resp->line_counts:%d", resp->line_counts);
    LOG_D("at_resp_get_line_by_kw:%s", at_resp_get_line_by_kw(resp, "+QGPS:"));
    at_resp_parse_line_args_by_kw(resp, "+QGPS:", "+QGPS:%d", &i);
    if (i == 0)
    {
        at_exec_cmd(resp, "AT+QGPS=1");
    }
    LOG_D("at_resp_parse_line_args_by_kw:%d", i);
    for (int i = 0; i < (int) resp->line_counts; i++)
    {
        LOG_D("%s", at_resp_get_line(resp, i + 1));
    }


    at_exec_cmd(resp, "AT+QGPSCFG=?");

    at_delete_resp(resp);

    while (count++)
    {
        show_information();
        rt_thread_mdelay(1000);
    }
    return RT_EOK;
}

你可能感兴趣的:(单片机模块,rt-thread)