rt-thread AT設備EC20獲取GNSS信息

EC20的某些版本,如EC20CEFILG-128-SGNS是具有GPS定位功能的,參照手冊有對應的AT指令集可以讀取,通過at_exec_cmd可以很方便的執行。

#include <rtthread.h>

#define DBG_TAG "main"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>


#include <at.h>

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章