mirror of
https://github.com/Ai-Thinker-Open/Ai-Thinker-Open_RTL8710BX_ALIOS_SDK.git
synced 2026-07-13 21:45:38 +00:00
rel_1.6.0 init
This commit is contained in:
commit
27b3e2883d
19359 changed files with 8093121 additions and 0 deletions
425
Living_SDK/device/gps/drv/drv_sim868/gps_drv_simcom_sim868.c
Normal file
425
Living_SDK/device/gps/drv/drv_sim868/gps_drv_simcom_sim868.c
Normal file
|
|
@ -0,0 +1,425 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "gps_hal.h"
|
||||
|
||||
#define SIM868_AT_CMD_SUCCESS_RSP "OK"
|
||||
#define SIM868_AT_CMD_FAIL_RSP "ERROR"
|
||||
|
||||
#define SIM868_AT_CMD_GPS_POWER_OFF "AT+CGNSPWR=0"
|
||||
#define SIM868_AT_CMD_GPS_POWER_ON "AT+CGNSPWR=1"
|
||||
#define SIM868_AT_CMD_GPS_POWER_CHECK "AT+CGNSPWR?"
|
||||
|
||||
#define SIM868_AT_CMD_GPS_LASTPARSE_SET "AT+CGNSSEQ=\"RMC\""
|
||||
#define SIM868_AT_CMD_GPS_LASTPARSE_CHECK "AT+CGNSSEQ?"
|
||||
|
||||
#define SIM868_AT_CMD_GPS_POSITION_GET "AT+CGNSINF"
|
||||
|
||||
#define SIM868_AT_CMD_GPS_INTERVAL_SET "AT+CGNSURC=100"
|
||||
#define SIM868_AT_CMD_GPS_INTERVAL_CLOSE "AT+CGNSURC=0"
|
||||
#define SIM868_AT_CMD_GPS_INTERVAL_CHECK "AT+CGNSURC?"
|
||||
|
||||
#define SIM868_AT_CMD_GPS_SEND_MODE_SET "AT+CGNSTST=0"
|
||||
#define SIM868_AT_CMD_GPS_SEND_MODE_CHECK "AT+CGNSTST?"
|
||||
|
||||
#define SIM868_GPS_HEAD_LOOP "\n+UGNSINF:"
|
||||
#define SIM868_GPS_TAIL_LOOP "\r\n"
|
||||
|
||||
#define SIM868_GPS_HEAD_POLL "\n+CGNSINF:"
|
||||
#define SIM868_GPS_TAIL_POLL "\r\n"
|
||||
|
||||
#define SIM868_GPS_DEFAULT_CMD_LEN (64)
|
||||
#define SIM868_GPS_DEFAULT_RSP_LEN (256)
|
||||
|
||||
|
||||
static char g_gps_sim868_addr[GPS_RCV_DATA_LEN];
|
||||
static gps_data_t g_gps_sim868_data;
|
||||
|
||||
static int gps_simcom_sim868_power_on(work_mode_e mode)
|
||||
{
|
||||
int ret = 0;
|
||||
char rsp[SIM868_GPS_DEFAULT_RSP_LEN] = {0};
|
||||
|
||||
if((DEV_DATA_READY != mode ) && (DEV_POLLING != mode)){
|
||||
LOG("func:%s line: %d para: %d error\n",__func__, __LINE__,mode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(rsp, 0, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
ret = at.send_raw(SIM868_AT_CMD_GPS_POWER_ON, rsp, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
if ((0 != ret) || (strstr(rsp, SIM868_AT_CMD_SUCCESS_RSP) == NULL)) {
|
||||
LOG("%s %d failed rsp %s errno %d\r\n", __func__, __LINE__, rsp,ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(rsp, 0, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
ret = at.send_raw(SIM868_AT_CMD_GPS_LASTPARSE_SET, rsp, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
if ((0 != ret) || (strstr(rsp, SIM868_AT_CMD_SUCCESS_RSP) == NULL)) {
|
||||
LOG("%s %d failed rsp %s errno %d\r\n", __func__, __LINE__, rsp,ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(rsp, 0, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
if(DEV_POLLING == mode){
|
||||
ret = at.send_raw(SIM868_AT_CMD_GPS_INTERVAL_CLOSE, rsp, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
}
|
||||
else{
|
||||
ret = at.send_raw(SIM868_AT_CMD_GPS_INTERVAL_SET, rsp, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
}
|
||||
|
||||
if ((0 != ret) || (strstr(rsp, SIM868_AT_CMD_SUCCESS_RSP) == NULL)) {
|
||||
LOG("%s %d failed rsp %s errno %d\r\n", __func__, __LINE__, rsp,ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(rsp, 0, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
ret = at.send_raw(SIM868_AT_CMD_GPS_SEND_MODE_SET, rsp, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
if ((0 != ret) || (strstr(rsp, SIM868_AT_CMD_SUCCESS_RSP) == NULL)) {
|
||||
LOG("%s %d failed rsp %s errno %d\r\n", __func__, __LINE__, rsp,ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gps_simcom_sim868_power_off()
|
||||
{
|
||||
int ret = 0;
|
||||
char rsp[SIM868_GPS_DEFAULT_RSP_LEN] = {0};
|
||||
|
||||
memset(rsp, 0, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
ret = at.send_raw(SIM868_AT_CMD_GPS_POWER_OFF, rsp, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
if ((0 != ret) || (strstr(rsp, SIM868_AT_CMD_SUCCESS_RSP) == NULL)) {
|
||||
LOG("%s %d failed rsp %s errno %d\r\n", __func__, __LINE__, rsp,ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gps_simcom_sim868_check(void)
|
||||
{
|
||||
int ret = 0;
|
||||
char rsp[SIM868_GPS_DEFAULT_RSP_LEN] = {0};
|
||||
|
||||
memset(rsp, 0, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
ret = at.send_raw(SIM868_AT_CMD_GPS_POWER_CHECK, rsp, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
if ((0 != ret) || (strstr(rsp, SIM868_AT_CMD_SUCCESS_RSP) == NULL)) {
|
||||
LOG("%s %d failed rsp %s errno %d\r\n", __func__, __LINE__, rsp,ret);
|
||||
return -1;
|
||||
}
|
||||
LOG("GPS power check %s \r\n", rsp);
|
||||
|
||||
memset(rsp, 0, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
ret = at.send_raw(SIM868_AT_CMD_GPS_LASTPARSE_CHECK, rsp, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
if ((0 != ret) || (strstr(rsp, SIM868_AT_CMD_SUCCESS_RSP) == NULL)) {
|
||||
LOG("%s %d failed rsp %s errno %d\r\n", __func__, __LINE__, rsp,ret);
|
||||
return -1;
|
||||
}
|
||||
LOG("GPS LAST PARSE %s \r\n", rsp);
|
||||
|
||||
memset(rsp, 0, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
ret = at.send_raw(SIM868_AT_CMD_GPS_POSITION_GET, rsp, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
if ((0 != ret) || (strstr(rsp, SIM868_AT_CMD_SUCCESS_RSP) == NULL)) {
|
||||
LOG("%s %d failed rsp %s errno %d\r\n", __func__, __LINE__, rsp,ret);
|
||||
return -1;
|
||||
}
|
||||
LOG("GPS POSITION %s \r\n", rsp);
|
||||
|
||||
memset(rsp, 0, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
ret = at.send_raw(SIM868_AT_CMD_GPS_INTERVAL_CHECK, rsp, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
if ((0 != ret) || (strstr(rsp, SIM868_AT_CMD_SUCCESS_RSP) == NULL)) {
|
||||
LOG("%s %d failed rsp %s errno %d\r\n", __func__, __LINE__, rsp,ret);
|
||||
return -1;
|
||||
}
|
||||
LOG("GPS INVERVAL %s \r\n", rsp);
|
||||
|
||||
|
||||
memset(rsp, 0, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
ret = at.send_raw(SIM868_AT_CMD_GPS_SEND_MODE_CHECK, rsp, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
if ((0 != ret) || (strstr(rsp, SIM868_AT_CMD_SUCCESS_RSP) == NULL)) {
|
||||
LOG("%s %d failed rsp %s errno %d\r\n", __func__, __LINE__, rsp,ret);
|
||||
return -1;
|
||||
}
|
||||
LOG("GPS send mode %s \r\n", rsp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int gps_simcom_sim868_config(work_mode_e mode)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = gps_simcom_sim868_power_off(mode);
|
||||
if(0 != ret)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = gps_simcom_sim868_power_on(mode);
|
||||
if(0 != ret)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
return gps_simcom_sim868_check();
|
||||
}
|
||||
|
||||
|
||||
static int gps_simcom_sim868_poll_read(char* rsp)
|
||||
{
|
||||
int ret = 0;
|
||||
memset(rsp, 0, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
ret = at.send_raw(SIM868_AT_CMD_GPS_POSITION_GET, rsp, SIM868_GPS_DEFAULT_RSP_LEN);
|
||||
if (strstr(rsp, SIM868_AT_CMD_SUCCESS_RSP) == NULL) {
|
||||
LOG("%s %d failed rsp %s\r\n", __func__, __LINE__, rsp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (int)strlen(rsp);
|
||||
}
|
||||
|
||||
static void gps_simcom_sim868_dispatcher(input_event_t *event, void *priv_data)
|
||||
{
|
||||
int ret = 0;
|
||||
int len = 0;
|
||||
char* str;
|
||||
|
||||
if ((event == NULL)||(event->type != GPS_EV_UDATA)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch(event->code){
|
||||
case GPS_DEV_READ:{
|
||||
str = (char*)(void*)(event->value);
|
||||
if(NULL == str){
|
||||
return;
|
||||
}
|
||||
ret = gps_simcom_sim868_proc(str,&g_gps_sim868_data);
|
||||
if(0 != ret){
|
||||
return;
|
||||
}
|
||||
|
||||
}break;
|
||||
|
||||
case GPS_DEV_SEND:{
|
||||
|
||||
}break;
|
||||
|
||||
default:break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static int gps_simcom_sim868_data_proc_init(work_mode_e mode)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if(DEV_DATA_READY == mode){
|
||||
ret = aos_register_event_filter(GPS_EV_UDATA, gps_simcom_sim868_dispatcher, NULL);
|
||||
if(unlikely(ret)){
|
||||
return -1;
|
||||
}
|
||||
LOG(" %s successfully \n", __func__);
|
||||
}
|
||||
else{
|
||||
LOG("func : %s no need\n",__func__);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void gps_simcom_sim868_ood_cb(void *arg, void* buf, int size)
|
||||
{
|
||||
int ret;
|
||||
char* str;
|
||||
if((NULL == buf) || (0 == size) || (size >= GPS_RCV_DATA_LEN)){
|
||||
return;
|
||||
}
|
||||
|
||||
str = &g_gps_sim868_addr[0];
|
||||
memcpy(str,buf,size);
|
||||
str[size] = '\0';
|
||||
|
||||
ret = aos_post_event(GPS_EV_UDATA, GPS_DEV_READ, (unsigned long)str);
|
||||
if(ret < 0){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static int gps_simcom_sim868_ood_cb_reg(work_mode_e mode)
|
||||
{
|
||||
|
||||
if(DEV_DATA_READY == mode){
|
||||
at.oob(SIM868_GPS_HEAD_LOOP, SIM868_GPS_TAIL_LOOP,GPS_RCV_DATA_LEN-1, gps_simcom_sim868_ood_cb, NULL);
|
||||
}
|
||||
else{
|
||||
LOG("func : %s no need\n",__func__);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gps_simcom_sim868_cb_unreg(void)
|
||||
{
|
||||
/*unreg uart callback, ref to at.oob*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gps_simcom_sim868_open(void)
|
||||
{
|
||||
int ret;
|
||||
work_mode_e mode;
|
||||
|
||||
mode = gps_mode_get();
|
||||
ret = gps_simcom_sim868_data_proc_init(mode);
|
||||
if(0 != ret){
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = gps_simcom_sim868_ood_cb_reg(mode);
|
||||
if(0 != ret){
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = gps_simcom_sim868_config(mode);
|
||||
if(0 != ret){
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gps_simcom_sim868_close(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = gps_simcom_sim868_power_off();
|
||||
if(0 != ret){
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = gps_simcom_sim868_cb_unreg();
|
||||
if(0 != ret){
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gps_simcom_sim868_data_get()
|
||||
{
|
||||
int ret = 0;
|
||||
char rsp[SIM868_GPS_DEFAULT_RSP_LEN] ={0};
|
||||
|
||||
ret = gps_simcom_sim868_poll_read(rsp);
|
||||
if((ret <= 0) || (ret >= SIM868_GPS_DEFAULT_RSP_LEN))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
ret = gps_simcom_sim868_proc(rsp,&g_gps_sim868_data);
|
||||
if(0 != ret){
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gps_simcom_sim868_read(void *buf, size_t len)
|
||||
{
|
||||
int ret;
|
||||
size_t size = 0;
|
||||
gps_data_t* gps = buf;
|
||||
|
||||
if(0 == buf){
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = sizeof(gps_data_t);
|
||||
if(len < size){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(DEV_POLLING == gps_mode_get()){
|
||||
ret = gps_simcom_sim868_data_get();
|
||||
if(0 != ret){
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(&(gps->utc),&(g_gps_sim868_data.utc),sizeof(g_gps_sim868_data.utc));
|
||||
|
||||
gps->lat = g_gps_sim868_data.lat;
|
||||
gps->lon = g_gps_sim868_data.lon;
|
||||
gps->elv = g_gps_sim868_data.elv;
|
||||
gps->timestamp = aos_now_ms();
|
||||
|
||||
return (int)size;
|
||||
}
|
||||
|
||||
static void gps_simcom_sim868_irq_handle(void)
|
||||
{
|
||||
/* no handle so far */
|
||||
}
|
||||
|
||||
static int gps_simcom_sim868_ioctl(int cmd, unsigned long arg)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int gps_simcom_sim868_env_init()
|
||||
{
|
||||
int ret = 0;
|
||||
#if AOS_ATCMD
|
||||
|
||||
ret = at.init(AT_RECV_PREFIX, AT_RECV_SUCCESS_POSTFIX,
|
||||
AT_RECV_FAIL_POSTFIX, AT_SEND_DELIMITER, 10000);
|
||||
if(0 != ret){
|
||||
LOG("%s : line %d ret %d\n",__func__,__LINE__,ret);
|
||||
ret -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int gps_simcom_sim868_init(void)
|
||||
{
|
||||
int ret = 0;
|
||||
sensor_obj_t gpsobj;
|
||||
|
||||
ret = gps_simcom_sim868_env_init();
|
||||
if(unlikely(ret)){
|
||||
return -1;
|
||||
}
|
||||
/* fill the gps obj parameters here */
|
||||
gpsobj.io_port = UART_PORT;
|
||||
gpsobj.tag = TAG_DEV_GPS;
|
||||
gpsobj.path = dev_gps_path;
|
||||
gpsobj.mode = DEV_POLLING;
|
||||
gpsobj.open = gps_simcom_sim868_open;
|
||||
gpsobj.close = gps_simcom_sim868_close;
|
||||
gpsobj.read = gps_simcom_sim868_read;
|
||||
gpsobj.write = NULL;
|
||||
gpsobj.ioctl = gps_simcom_sim868_ioctl;
|
||||
gpsobj.irq_handle = gps_simcom_sim868_irq_handle;
|
||||
|
||||
ret = gps_create_obj(&gpsobj);
|
||||
if(unlikely(ret)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOG("%s %s successfully \n", GPS_STR, __func__);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
274
Living_SDK/device/gps/drv/drv_sim868/gps_parse_simcom_sim868.c
Normal file
274
Living_SDK/device/gps/drv/drv_sim868/gps_parse_simcom_sim868.c
Normal file
|
|
@ -0,0 +1,274 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "gps_hal.h"
|
||||
#include "gps_parse.h"
|
||||
|
||||
typedef enum{
|
||||
NONINF = 0x0000,
|
||||
UGNSINF = 0x0001,
|
||||
CGNSINF = 0x0002
|
||||
}en_gnsinf_type;
|
||||
|
||||
|
||||
typedef struct _gps_sim868
|
||||
{
|
||||
char name[GPS_TYPE_NAME_LEN];
|
||||
int run_stat;
|
||||
int fix_stat;
|
||||
gps_time_t utc;
|
||||
float lat;
|
||||
float lon;
|
||||
float elv;
|
||||
float speed;
|
||||
float course;
|
||||
int fix_mode;
|
||||
int rev1;
|
||||
|
||||
float HDOP;
|
||||
float PDOP;
|
||||
float VDOP;
|
||||
int rev2;
|
||||
|
||||
int gps_sat_num;
|
||||
int gnss_sat_num;
|
||||
int glo_sat_num;
|
||||
int rev3;
|
||||
|
||||
int cn0_max;
|
||||
float HPA;
|
||||
float VPA;
|
||||
|
||||
} gps_sim868_t;
|
||||
|
||||
#define GPS_SIM868_T_PARA_NUM (22)
|
||||
|
||||
typedef struct sim868_inernel_data_stu{
|
||||
gps_sim868_t data_sim868;
|
||||
|
||||
}sim868_inernel_data_t;
|
||||
|
||||
static sim868_inernel_data_t g_sim868value;
|
||||
static int g_sim868typebitmap = CGNSINF;
|
||||
|
||||
static void gps_simcom_sim868_para_set(test_gps_data_t sim868_index[], gps_sim868_t* sim868_para)
|
||||
{
|
||||
sim868_index[0].type = GPS_TYPE_STR;
|
||||
sim868_index[0].addr = &(sim868_para->name[0]);
|
||||
|
||||
sim868_index[1].type = GPS_TYPE_INT32;
|
||||
sim868_index[1].addr = &(sim868_para->run_stat);
|
||||
|
||||
sim868_index[2].type = GPS_TYPE_INT32;
|
||||
sim868_index[2].addr = &(sim868_para->fix_stat);
|
||||
|
||||
sim868_index[3].type = GPS_TYPE_UTC;
|
||||
sim868_index[3].addr = &(sim868_para->utc);
|
||||
|
||||
sim868_index[4].type = GPS_TYPE_FLOAT;
|
||||
sim868_index[4].addr = &(sim868_para->lat);
|
||||
sim868_index[5].type = GPS_TYPE_FLOAT;
|
||||
sim868_index[5].addr = &(sim868_para->lon);
|
||||
sim868_index[6].type = GPS_TYPE_FLOAT;
|
||||
sim868_index[6].addr = &(sim868_para->elv);
|
||||
|
||||
|
||||
sim868_index[7].type = GPS_TYPE_FLOAT;
|
||||
sim868_index[7].addr = &(sim868_para->speed);
|
||||
sim868_index[8].type = GPS_TYPE_FLOAT;
|
||||
sim868_index[8].addr = &(sim868_para->course);
|
||||
sim868_index[9].type = GPS_TYPE_INT32;
|
||||
sim868_index[9].addr = &(sim868_para->fix_mode);
|
||||
|
||||
sim868_index[10].type = GPS_TYPE_INT32;
|
||||
sim868_index[10].addr = &(sim868_para->rev1);
|
||||
|
||||
|
||||
sim868_index[11].type = GPS_TYPE_FLOAT;
|
||||
sim868_index[11].addr = &(sim868_para->HDOP);
|
||||
sim868_index[12].type = GPS_TYPE_FLOAT;
|
||||
sim868_index[12].addr = &(sim868_para->PDOP);
|
||||
sim868_index[13].type = GPS_TYPE_FLOAT;
|
||||
sim868_index[13].addr = &(sim868_para->VDOP);
|
||||
|
||||
|
||||
sim868_index[14].type = GPS_TYPE_INT32;
|
||||
sim868_index[14].addr = &(sim868_para->rev2);
|
||||
|
||||
|
||||
sim868_index[15].type = GPS_TYPE_INT32;
|
||||
sim868_index[15].addr = &(sim868_para->gps_sat_num);
|
||||
sim868_index[16].type = GPS_TYPE_INT32;
|
||||
sim868_index[16].addr = &(sim868_para->gnss_sat_num);
|
||||
sim868_index[17].type = GPS_TYPE_INT32;
|
||||
sim868_index[17].addr = &(sim868_para->glo_sat_num);
|
||||
|
||||
sim868_index[18].type = GPS_TYPE_INT32;
|
||||
sim868_index[18].addr = &(sim868_para->rev3);
|
||||
|
||||
sim868_index[19].type = GPS_TYPE_INT32;
|
||||
sim868_index[19].addr = &(sim868_para->cn0_max);
|
||||
|
||||
sim868_index[20].type = GPS_TYPE_FLOAT;
|
||||
sim868_index[20].addr = &(sim868_para->HPA);
|
||||
sim868_index[21].type = GPS_TYPE_FLOAT;
|
||||
sim868_index[21].addr = &(sim868_para->VPA);
|
||||
|
||||
}
|
||||
|
||||
static int gps_simcom_sim868_data_parse(char *str, int len, gps_sim868_t *result)
|
||||
{
|
||||
int i = 0;
|
||||
int ret;
|
||||
char data[GPS_RCV_DATA_LEN];
|
||||
char* prt0;
|
||||
char* prt1 = &data[0];
|
||||
test_gps_data_t index[GPS_SIM868_T_PARA_NUM];
|
||||
|
||||
if((NULL == str) || (0 == result)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(data,str,len);
|
||||
data[len] = '\0';
|
||||
|
||||
memset(result, 0, sizeof(gps_sim868_t));
|
||||
gps_simcom_sim868_para_set(index,result);
|
||||
|
||||
prt0 = gps_strtok(prt1,&prt1,':',strlen(prt1));
|
||||
gps_data_conv(prt0,strlen(prt0),index[i].addr,index[i].type);
|
||||
i++;
|
||||
|
||||
for(; (i < 22) &&(NULL!=prt0); i++){
|
||||
prt0 = gps_strtok(prt1,&prt1,',',strlen(prt1));
|
||||
gps_data_conv(prt0,strlen(prt0),index[i].addr,index[i].type);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int gps_simcom_sim868_data_get(gps_sim868_t *result,gps_data_t* pgpsdata)
|
||||
{
|
||||
|
||||
if((NULL == result) || (0 == pgpsdata)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
pgpsdata->utc.year = result->utc.year;
|
||||
pgpsdata->utc.mon = result->utc.mon;
|
||||
pgpsdata->utc.day = result->utc.day;
|
||||
pgpsdata->utc.hour = result->utc.hour;
|
||||
pgpsdata->utc.min = result->utc.min;
|
||||
pgpsdata->utc.sec = result->utc.sec;
|
||||
pgpsdata->utc.hsec = result->utc.hsec;
|
||||
|
||||
pgpsdata->lat = result->lat;
|
||||
pgpsdata->lon = result->lon;
|
||||
pgpsdata->elv = result->elv;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int gps_simcom_sim868_type_get(const char *buf, int size)
|
||||
{
|
||||
static const char *pheads[] = {
|
||||
"\n+UGNSINF",
|
||||
"\n+CGNSINF"
|
||||
};
|
||||
|
||||
if(0 == buf){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(size < 8)
|
||||
return NONINF;
|
||||
else if(0 == memcmp(buf, pheads[0], 5))
|
||||
return UGNSINF;
|
||||
else if(0 == memcmp(buf, pheads[1], 5))
|
||||
return CGNSINF;
|
||||
|
||||
return NONINF;
|
||||
}
|
||||
|
||||
static bool gps_simcom_sim868_type_filter(const char *buf, int size)
|
||||
{
|
||||
int ret = gps_simcom_sim868_type_get(buf,size);
|
||||
|
||||
return (g_sim868typebitmap&ret) ? 1:0;
|
||||
}
|
||||
|
||||
|
||||
static int gps_simcom_sim868_parse(char* str, int len, gps_data_t* pgpsdata)
|
||||
{
|
||||
int ret;
|
||||
int ptype;
|
||||
|
||||
ptype = gps_simcom_sim868_type_get(str,len);
|
||||
|
||||
switch(ptype){
|
||||
case UGNSINF:
|
||||
case CGNSINF:{
|
||||
ret = gps_simcom_sim868_data_parse(str, len,&(g_sim868value.data_sim868));
|
||||
if(0 != ret){
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = gps_simcom_sim868_data_get(&(g_sim868value.data_sim868), pgpsdata);
|
||||
if(0 != ret){
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gps_simcom_sim868_proc(const char* str, gps_data_t* pgpsdata)
|
||||
{
|
||||
int ret;
|
||||
int len;
|
||||
int ptype;
|
||||
char gpsdata[GPS_CALC_BUF_LEN];
|
||||
|
||||
if(0 == str){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(0 == pgpsdata){
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = strlen(str);
|
||||
if(len >= GPS_RCV_DATA_LEN){
|
||||
return -1;
|
||||
}
|
||||
#if 0
|
||||
if(!(gps_gp_type_filter((str+1), len-1))){
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
memcpy(&gpsdata[0], str, len);
|
||||
gpsdata[len] = '\0';
|
||||
|
||||
ret = gps_simcom_sim868_parse(&gpsdata[0],len, pgpsdata);
|
||||
if(0 != ret){
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
24
Living_SDK/device/gps/gps.mk
Normal file
24
Living_SDK/device/gps/gps.mk
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
NAME := gps
|
||||
|
||||
$(NAME)_TYPE := kernel
|
||||
$(NAME)_COMPONENTS += sal atparser
|
||||
|
||||
$(NAME)_SOURCES += hal/gps_hal.c \
|
||||
parse/gps_parse.c
|
||||
|
||||
|
||||
ifeq (gps.sim868,$(module))
|
||||
$(NAME)_COMPONENTS += sal.gprs.sim800
|
||||
GLOBAL_DEFINES += AOS_GPS_SIM868
|
||||
|
||||
$(NAME)_SOURCES += drv/drv_sim868/gps_drv_simcom_sim868.c
|
||||
$(NAME)_SOURCES += drv/drv_sim868/gps_parse_simcom_sim868.c
|
||||
endif
|
||||
|
||||
GLOBAL_DEFINES += AOS_GPS
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
$(NAME)_INCLUDES := ../../utility/iotx-utils/sdk-impl ../../framework/atparser
|
||||
$(NAME)_INCLUDES += ./hal ./parse
|
||||
GLOBAL_INCLUDES += .
|
||||
|
||||
267
Living_SDK/device/gps/hal/gps_hal.c
Normal file
267
Living_SDK/device/gps/hal/gps_hal.c
Normal file
|
|
@ -0,0 +1,267 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "gps_hal.h"
|
||||
|
||||
static gps_obj_t *g_gps_obj;
|
||||
static uint32_t g_gps_sensor_cnt = 0;
|
||||
static int g_gps_init_flag = 0;
|
||||
|
||||
static int gps_hal_get_dev_list(void* buf)
|
||||
{
|
||||
sensor_list_t* list = buf;
|
||||
if(buf == NULL)
|
||||
return -1;
|
||||
|
||||
if (list->cnt >= TAG_DEV_SENSOR_NUM_MAX){
|
||||
LOG("list->cnt == %d %d\n",list->cnt,TAG_DEV_SENSOR_NUM_MAX);
|
||||
return -1;
|
||||
}
|
||||
|
||||
list->list[list->cnt] = g_gps_obj->tag;
|
||||
|
||||
list->cnt ++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int gps_open(inode_t *node, file_t *file)
|
||||
{
|
||||
if((node == NULL)||(file == NULL)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* just open the /dev/nodegps node here */
|
||||
if(strncmp(gps_node_path, node->i_name, strlen(node->i_name)) == 0){
|
||||
return 0;
|
||||
}
|
||||
if( g_gps_obj->open == NULL){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(g_gps_obj->ref == 0){
|
||||
g_gps_obj->open();
|
||||
}
|
||||
g_gps_obj->ref++;
|
||||
|
||||
LOG("%s %s successfully\n", GPS_STR, __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int gps_close(file_t *file)
|
||||
{
|
||||
if(strncmp(gps_node_path, (file->node->i_name), strlen(file->node->i_name)) == 0){
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( g_gps_obj->close == NULL){
|
||||
return -1;
|
||||
}
|
||||
//if the ref counter is less than 2, then close the sensor
|
||||
if(g_gps_obj->ref < 2){
|
||||
g_gps_obj->close();
|
||||
}
|
||||
|
||||
if(g_gps_obj->ref > 0){
|
||||
g_gps_obj->ref--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static ssize_t gps_read(file_t *f, void *buf, size_t len)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if(f == NULL){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( g_gps_obj->read == NULL){
|
||||
goto error;
|
||||
}
|
||||
|
||||
if(buf == NULL){
|
||||
goto error;
|
||||
}
|
||||
|
||||
ret = g_gps_obj->read(buf, len);
|
||||
if(ret < 0){
|
||||
goto error;
|
||||
}
|
||||
|
||||
LOG("%s %s successfully\n", GPS_STR, __func__);
|
||||
return ret;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static ssize_t gps_write(file_t *f, const void *buf, size_t len)
|
||||
{
|
||||
/* no need this functionality recently */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int gps_ioctl(file_t *f, int cmd, unsigned long arg)
|
||||
{
|
||||
int ret = 0;
|
||||
int index = 0;
|
||||
|
||||
if(f == NULL){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(cmd == SENSOR_IOCTL_GET_SENSOR_LIST){
|
||||
ret = gps_hal_get_dev_list(arg);
|
||||
if(ret != 0){
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(g_gps_obj->ioctl == NULL){
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = g_gps_obj->ioctl(cmd, arg);
|
||||
if(ret != 0){
|
||||
return -1;
|
||||
}
|
||||
LOG("%s %s successfully\n", GPS_STR, __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gps_register_irq(void)
|
||||
{
|
||||
// will implement later
|
||||
return 0;
|
||||
}
|
||||
|
||||
file_ops_t gps_fops = {
|
||||
.open = gps_open,
|
||||
.close = gps_close,
|
||||
.read = gps_read,
|
||||
.write = gps_write,
|
||||
.ioctl = gps_ioctl,
|
||||
};
|
||||
|
||||
|
||||
static int gps_obj_register( )
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if((g_gps_obj->mode == DEV_INT)){
|
||||
ret = gps_register_irq();
|
||||
if (ret != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
ret = aos_register_driver(g_gps_obj->path, &gps_fops, NULL);
|
||||
if (ret != 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gps_create_obj(gps_obj_t* gpsobj)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
g_gps_obj = (gps_obj_t*)aos_malloc(sizeof(gps_obj_t));
|
||||
if(g_gps_obj == NULL){
|
||||
return -1;
|
||||
}
|
||||
memset(g_gps_obj, 0, sizeof(gps_obj_t));
|
||||
|
||||
/* install the phy sensor info into the sensor object datebase here */
|
||||
g_gps_obj->io_port = gpsobj->io_port;
|
||||
g_gps_obj->path = gpsobj->path;
|
||||
g_gps_obj->tag = gpsobj->tag;
|
||||
g_gps_obj->open = gpsobj->open;
|
||||
g_gps_obj->close = gpsobj->close;
|
||||
g_gps_obj->ioctl = gpsobj->ioctl;
|
||||
g_gps_obj->read = gpsobj->read;
|
||||
g_gps_obj->write = gpsobj->write;
|
||||
g_gps_obj->irq_handle = gpsobj->irq_handle;
|
||||
g_gps_obj->mode = gpsobj->mode;
|
||||
g_gps_obj->power = DEV_POWER_OFF; // will update the status later
|
||||
g_gps_obj->ref = 0; // count the ref of this sensor
|
||||
/* register the sensor object into the irq list and vfs */
|
||||
ret = gps_obj_register();
|
||||
if (ret != 0) {
|
||||
goto error;
|
||||
}
|
||||
LOG("%s %s successfully \n", GPS_STR, __func__);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
free(g_gps_obj);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static int gps_hal_register(void)
|
||||
{
|
||||
int ret = 0;
|
||||
ret = aos_register_driver(gps_node_path, &gps_fops, NULL);
|
||||
if (ret != 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
work_mode_e gps_mode_get(void)
|
||||
{
|
||||
if(0 == g_gps_init_flag){
|
||||
LOG("%s : %d\n",__func__,__LINE__);
|
||||
return DEV_MODE_INV;
|
||||
}
|
||||
|
||||
if(NULL == g_gps_obj){
|
||||
LOG("%s : %d\n",__func__,__LINE__);
|
||||
return DEV_MODE_INV;
|
||||
}
|
||||
|
||||
if(g_gps_obj->mode >= DEV_MODE_INV){
|
||||
LOG("%s : %d\n",__func__,__LINE__);
|
||||
return DEV_MODE_INV;
|
||||
}
|
||||
|
||||
return g_gps_obj->mode;
|
||||
}
|
||||
|
||||
int gps_init(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
#ifdef AOS_GPS_SIM868
|
||||
ret = gps_simcom_sim868_init();
|
||||
if(ret != 0){
|
||||
LOG("%s %s fail \n", GPS_STR, __func__);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = gps_hal_register();
|
||||
if(ret != 0){
|
||||
|
||||
LOG("%s %s fail \n", GPS_STR, __func__);
|
||||
return -1;
|
||||
}
|
||||
g_gps_init_flag = 1;
|
||||
|
||||
LOG("%s %s successfully\n", GPS_STR, __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
63
Living_SDK/device/gps/hal/gps_hal.h
Normal file
63
Living_SDK/device/gps/hal/gps_hal.h
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef GPS_HAL_H
|
||||
#define GPS_HAL_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <aos/aos.h>
|
||||
#include <vfs_conf.h>
|
||||
#include <vfs_err.h>
|
||||
#include <vfs_register.h>
|
||||
#include <hal/base.h>
|
||||
#include "common.h"
|
||||
#include "hal/sensor.h"
|
||||
|
||||
#ifdef AOS_ATCMD
|
||||
#include <atparser.h>
|
||||
#endif
|
||||
|
||||
#define GPS_EV_UDATA (0x40)
|
||||
#define GPS_DEV_READ (1)
|
||||
#define GPS_DEV_PROC (2)
|
||||
#define GPS_DEV_SEND (3)
|
||||
|
||||
#define GPS_RCV_DATA_LEN (256)
|
||||
|
||||
typedef struct _gps_obj_t {
|
||||
char* path;
|
||||
sensor_tag_e tag;
|
||||
dev_io_port_e io_port;
|
||||
work_mode_e mode;
|
||||
dev_power_mode_e power;
|
||||
gpio_dev_t gpio;
|
||||
dev_sensor_full_info_t info;
|
||||
uint8_t ref;
|
||||
int (*open)(void);
|
||||
int (*close)(void);
|
||||
int (*read)(void *, size_t);
|
||||
int (*write)(const void *buf, size_t len);
|
||||
int (*ioctl)(int cmd, unsigned long arg);
|
||||
void(*irq_handle)(void);
|
||||
}gps_obj_t;
|
||||
|
||||
extern int gps_simcom_sim868_init(void);
|
||||
extern int gps_simcom_sim868_proc(const char* str, gps_data_t* pgpsdata);
|
||||
extern int gps_gp_proc(const char* str, gps_data_t* pgpsdata);
|
||||
extern work_mode_e gps_mode_get(void);
|
||||
extern int gps_create_obj(gps_obj_t* gpsobj);
|
||||
|
||||
|
||||
#endif /* GPS_HAL_H */
|
||||
|
||||
|
||||
301
Living_SDK/device/gps/parse/gps_parse.c
Normal file
301
Living_SDK/device/gps/parse/gps_parse.c
Normal file
|
|
@ -0,0 +1,301 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <aos/aos.h>
|
||||
#include <atparser.h>
|
||||
#include <hal/sensor.h>
|
||||
#include "gps_hal.h"
|
||||
#include "gps_parse.h"
|
||||
|
||||
|
||||
typedef enum{
|
||||
GPNON = 0x0000,
|
||||
GPGGA = 0x0001,
|
||||
GPGSA = 0x0002,
|
||||
GPGSV = 0x0004,
|
||||
GPRMC = 0x0008,
|
||||
GPVTG = 0x0010
|
||||
}en_gps_type;
|
||||
|
||||
|
||||
typedef struct _gps_gpgga
|
||||
{
|
||||
char name[GPS_TYPE_NAME_LEN];
|
||||
gps_time_t utc;
|
||||
float lat;
|
||||
char ns;
|
||||
float lon;
|
||||
char ew;
|
||||
int sig;
|
||||
int satinuse;
|
||||
float HDOP;
|
||||
float elv;
|
||||
char elv_units;
|
||||
float diff;
|
||||
char diff_units;
|
||||
float dgps_age;
|
||||
int dgps_sid;
|
||||
} gps_gpgga_t;
|
||||
|
||||
#define GPS_GPGGA_T_PARA_NUM (15)
|
||||
typedef struct gps_inernel_data_stu{
|
||||
gps_gpgga_t data_gga;
|
||||
|
||||
}gps_inernel_data_t;
|
||||
|
||||
|
||||
gps_inernel_data_t g_gpsvalue;
|
||||
int g_gpstypebitmap = GPGGA;
|
||||
|
||||
static void gps_gpgga_para_set(test_gps_data_t gpgga_index[], gps_gpgga_t* gpgga_para)
|
||||
{
|
||||
gpgga_index[0].type = GPS_TYPE_STR;
|
||||
gpgga_index[0].addr = &(gpgga_para->name[0]);
|
||||
gpgga_index[1].type = GPS_TYPE_UTC;
|
||||
gpgga_index[1].addr = &(gpgga_para->utc);
|
||||
|
||||
gpgga_index[2].type = GPS_TYPE_FLOAT;
|
||||
gpgga_index[2].addr = &(gpgga_para->lat);
|
||||
gpgga_index[3].type = GPS_TYPE_UINT8;
|
||||
gpgga_index[3].addr = &(gpgga_para->ns);
|
||||
gpgga_index[4].type = GPS_TYPE_FLOAT;
|
||||
gpgga_index[4].addr = &(gpgga_para->lon);
|
||||
gpgga_index[5].type = GPS_TYPE_UINT8;
|
||||
gpgga_index[5].addr = &(gpgga_para->ew);
|
||||
|
||||
gpgga_index[6].type = GPS_TYPE_INT32;
|
||||
gpgga_index[6].addr = &(gpgga_para->sig);
|
||||
gpgga_index[7].type = GPS_TYPE_INT32;
|
||||
gpgga_index[7].addr = &(gpgga_para->satinuse);
|
||||
gpgga_index[8].type = GPS_TYPE_FLOAT;
|
||||
gpgga_index[8].addr = &(gpgga_para->HDOP);
|
||||
gpgga_index[9].type = GPS_TYPE_FLOAT;
|
||||
gpgga_index[9].addr = &(gpgga_para->elv);
|
||||
|
||||
gpgga_index[10].type = GPS_TYPE_UINT8;
|
||||
gpgga_index[10].addr = &(gpgga_para->elv_units);
|
||||
gpgga_index[11].type = GPS_TYPE_FLOAT;
|
||||
gpgga_index[11].addr = &(gpgga_para->diff);
|
||||
gpgga_index[12].type = GPS_TYPE_UINT8;
|
||||
gpgga_index[12].addr = &(gpgga_para->diff_units);
|
||||
gpgga_index[13].type = GPS_TYPE_FLOAT;
|
||||
gpgga_index[13].addr = &(gpgga_para->dgps_age);
|
||||
|
||||
gpgga_index[14].type = GPS_TYPE_INT32;
|
||||
gpgga_index[14].addr = &(gpgga_para->dgps_sid);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static int gps_gpgga_data_parse(char *str, int len, gps_gpgga_t *result)
|
||||
{
|
||||
int i = 0;
|
||||
char data[GPS_RCV_DATA_LEN];
|
||||
char* prt0;
|
||||
char* prt1 = &data[0];
|
||||
test_gps_data_t gga_idx[GPS_GPGGA_T_PARA_NUM];
|
||||
|
||||
if((NULL == str) || (0 == result)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(data,str,len);
|
||||
data[len] = '\0';
|
||||
|
||||
memset(result, 0, sizeof(gps_gpgga_t));
|
||||
gps_gpgga_para_set(gga_idx,result);
|
||||
|
||||
for( i = 0; (i < 13) &&(NULL!=prt0); i++){
|
||||
//printf("strlen(prt1) == %d\n",strlen(prt1));
|
||||
|
||||
prt0 = gps_strtok(prt1,&prt1,',',strlen(prt1));
|
||||
//printf("prt0 == %s\n",prt0);
|
||||
|
||||
gps_data_conv(prt0,strlen(prt0),gga_idx[i].addr,gga_idx[i].type);
|
||||
//printf("index %d\n\n",i);
|
||||
}
|
||||
|
||||
prt0 = gps_strtok(prt1,&prt1,',',strlen(prt1));
|
||||
gps_data_conv(prt0,strlen(prt0),gga_idx[i].addr,gga_idx[i].type);
|
||||
i++;
|
||||
//printf("index %d\n\n\n",i);
|
||||
|
||||
prt0 = gps_strtok(prt1,&prt1,'*',strlen(prt1));
|
||||
gps_data_conv(prt0,strlen(prt0),gga_idx[i].addr,gga_idx[i].type);
|
||||
//printf("index %d\n\n\n",i);
|
||||
|
||||
//printf("time %2d:%2d:%2d.%d\n",result->utc.hour,result->utc.min,result->utc.sec,result->utc.hsec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int gps_gpgga_data_get(gps_gpgga_t *result,gps_data_t* pgpsdata)
|
||||
{
|
||||
|
||||
if((NULL == result) || (0 == pgpsdata)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
pgpsdata->utc.year = result->utc.year;
|
||||
pgpsdata->utc.mon = result->utc.mon;
|
||||
pgpsdata->utc.day = result->utc.day;
|
||||
pgpsdata->utc.hour = result->utc.hour;
|
||||
pgpsdata->utc.min = result->utc.min;
|
||||
pgpsdata->utc.sec = result->utc.sec;
|
||||
pgpsdata->utc.hsec = result->utc.hsec;
|
||||
|
||||
pgpsdata->lat = ('N' == result->ns)? result->lat : -(result->lat);
|
||||
pgpsdata->lat = pgpsdata->lat/100;
|
||||
pgpsdata->lon = ('E' == result->ew)? result->lon : -(result->lon);
|
||||
pgpsdata->lon = pgpsdata->lon/100;
|
||||
pgpsdata->elv = result->elv;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int gps_gp_type_get(const char *buf, int size)
|
||||
{
|
||||
static const char *pheads[] = {
|
||||
"GPGGA",
|
||||
"GPGSA",
|
||||
"GPGSV",
|
||||
"GPRMC",
|
||||
"GPVTG"
|
||||
};
|
||||
|
||||
if(0 == buf){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(size < 5)
|
||||
return GPNON;
|
||||
else if(0 == memcmp(buf, pheads[0], 5))
|
||||
return GPGGA;
|
||||
else if(0 == memcmp(buf, pheads[1], 5))
|
||||
return GPGSA;
|
||||
else if(0 == memcmp(buf, pheads[2], 5))
|
||||
return GPGSV;
|
||||
else if(0 == memcmp(buf, pheads[3], 5))
|
||||
return GPRMC;
|
||||
else if(0 == memcmp(buf, pheads[4], 5))
|
||||
return GPVTG;
|
||||
|
||||
return GPNON;
|
||||
}
|
||||
|
||||
bool gps_gp_type_filter(const char *buf, int size)
|
||||
{
|
||||
int ret = gps_gp_type_get(buf,size);
|
||||
|
||||
return (g_gpstypebitmap&ret) ? 1:0;
|
||||
}
|
||||
|
||||
|
||||
static int gps_gp_parse(char* str, int len, gps_data_t* pgpsdata)
|
||||
{
|
||||
int ret;
|
||||
int ptype;
|
||||
|
||||
ptype = gps_gp_type_get(str+1,len-1);
|
||||
|
||||
switch(ptype){
|
||||
case GPGGA:{
|
||||
ret = gps_gpgga_data_parse(str, len,&(g_gpsvalue.data_gga));
|
||||
if(0 != ret){
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = gps_gpgga_data_get(&(g_gpsvalue.data_gga), pgpsdata);
|
||||
if(0 != ret){
|
||||
return -1;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gps_gp_check(const char* str, int len)
|
||||
{
|
||||
int i;
|
||||
int crc_calc = 0;
|
||||
int crc = 0;
|
||||
char* str_tmp = str;
|
||||
|
||||
if(str_tmp[0] != '$'){
|
||||
return -1;
|
||||
}
|
||||
|
||||
str_tmp++;
|
||||
|
||||
for(i = 1; (i < len) && (*str_tmp != '*'); i++,str_tmp++){
|
||||
crc_calc ^= (int)(*str_tmp);
|
||||
}
|
||||
|
||||
crc = gps_atoi(&str_tmp[1],2,16);
|
||||
if(crc != crc_calc){
|
||||
LOG("crc_origin == 0x%08x, crc_calc == 0x%08x\n",crc,crc_calc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gps_gp_proc(const char* str, gps_data_t* pgpsdata)
|
||||
{
|
||||
int ret;
|
||||
int len;
|
||||
int ptype;
|
||||
char gpsdata[GPS_CALC_BUF_LEN];
|
||||
|
||||
if(0 == str){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(0 == pgpsdata){
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = strlen(str);
|
||||
if(len >= GPS_RCV_DATA_LEN){
|
||||
return -1;
|
||||
}
|
||||
#if 0
|
||||
if(!(gps_gp_type_filter((str+1), len-1))){
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
memcpy(&gpsdata[0], str, len);
|
||||
gpsdata[len] = '\0';
|
||||
|
||||
|
||||
ret = gps_gp_check(&gpsdata[0],len);
|
||||
if(0 != ret){
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = gps_gp_parse(&gpsdata[0],len, pgpsdata);
|
||||
if(0 != ret){
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
168
Living_SDK/device/gps/parse/gps_parse.h
Normal file
168
Living_SDK/device/gps/parse/gps_parse.h
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef GPS_PARSE_H
|
||||
#define GPS_PARSE_H
|
||||
|
||||
#include "gps_hal.h"
|
||||
|
||||
|
||||
#define GPS_CONV_DATA_LEN (64)
|
||||
#define GPS_CALC_BUF_LEN (256)
|
||||
#define GPS_CALC_STR_LEN (GPS_CALC_BUF_LEN-1)
|
||||
#define GPS_TYPE_NAME_LEN (16)
|
||||
|
||||
#define GPS_UTC_YEAR_LEN (4)
|
||||
#define GPS_UTC_MON_LEN (2)
|
||||
#define GPS_UTC_DAY_LEN (2)
|
||||
|
||||
#define GPS_UTC_HOUR_LEN (2)
|
||||
#define GPS_UTC_MIN_LEN (2)
|
||||
#define GPS_UTC_SEC_LEN (2)
|
||||
#define GPS_UTC_HSEC_LEN (3)
|
||||
#define GPS_UTC_POINT_LEN (1)
|
||||
|
||||
|
||||
typedef enum{
|
||||
GPS_TYPE_UINT8 = 0,
|
||||
GPS_TYPE_INT32,
|
||||
GPS_TYPE_FLOAT,
|
||||
GPS_TYPE_STR,
|
||||
GPS_TYPE_UTC
|
||||
}gps_data_type;
|
||||
|
||||
|
||||
typedef struct test_gps_data_t{
|
||||
int type;
|
||||
void* addr;
|
||||
}test_gps_data_t;
|
||||
|
||||
static inline int gps_atoi(const char *str, int size, int radix)
|
||||
{
|
||||
int ret = 0;
|
||||
char *str_tmp = NULL;
|
||||
char buff[GPS_CONV_DATA_LEN];
|
||||
|
||||
if(size < GPS_CONV_DATA_LEN){
|
||||
memcpy(&buff[0], str, size);
|
||||
buff[size] = '\0';
|
||||
ret = strtol(&buff[0], &str_tmp, radix);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline float gps_atof(const char *str, int len)
|
||||
{
|
||||
double ret = 0;
|
||||
char *str_tmp = NULL;
|
||||
char buff[GPS_CONV_DATA_LEN];
|
||||
|
||||
if(len < GPS_CONV_DATA_LEN){
|
||||
memcpy(&buff[0], str, len);
|
||||
buff[len] = '\0';
|
||||
ret = strtod(&buff[0], &str_tmp);
|
||||
}
|
||||
|
||||
return (float)ret;
|
||||
}
|
||||
|
||||
static inline char* gps_strtok(char* src, char** ret, char c,int len)
|
||||
{
|
||||
int i;
|
||||
char* str_tmp = src;
|
||||
|
||||
for(i = 0; i < len; i++,str_tmp++){
|
||||
if(c == *str_tmp){
|
||||
str_tmp[0] = '\0';
|
||||
*ret = str_tmp+1;
|
||||
return src;
|
||||
}
|
||||
}
|
||||
|
||||
*ret = str_tmp;
|
||||
return src;
|
||||
}
|
||||
|
||||
static inline int gps_utc_get(const char *str, int len, gps_time_t* res)
|
||||
{
|
||||
int success = 0;
|
||||
char* str_tmp = NULL;
|
||||
|
||||
switch(len){
|
||||
case (sizeof("YYYYMMDDhhmmss.sss") - 1):
|
||||
str_tmp = str;
|
||||
res->year = gps_atoi(str_tmp,GPS_UTC_YEAR_LEN,10);
|
||||
str_tmp += GPS_UTC_YEAR_LEN;
|
||||
res->mon = gps_atoi(str_tmp,GPS_UTC_MON_LEN,10);
|
||||
str_tmp += GPS_UTC_MON_LEN;
|
||||
res->day = gps_atoi(str_tmp,GPS_UTC_DAY_LEN,10);
|
||||
str_tmp += GPS_UTC_DAY_LEN;
|
||||
|
||||
res->hour = gps_atoi(str_tmp,GPS_UTC_HOUR_LEN,10);
|
||||
str_tmp += GPS_UTC_HOUR_LEN;
|
||||
res->min = gps_atoi(str_tmp,GPS_UTC_MIN_LEN,10);
|
||||
str_tmp += GPS_UTC_MIN_LEN;
|
||||
res->sec = gps_atoi(str_tmp,GPS_UTC_SEC_LEN,10);
|
||||
str_tmp += (GPS_UTC_SEC_LEN + GPS_UTC_POINT_LEN);
|
||||
res->hsec = gps_atoi(str_tmp,3,10);
|
||||
break;
|
||||
|
||||
case (sizeof("hhmmss.sss") - 1):
|
||||
|
||||
str_tmp = str;
|
||||
res->hour = gps_atoi(str_tmp,GPS_UTC_HOUR_LEN,10);
|
||||
str_tmp += GPS_UTC_HOUR_LEN;
|
||||
res->min = gps_atoi(str_tmp,GPS_UTC_MIN_LEN,10);
|
||||
str_tmp += GPS_UTC_MIN_LEN;
|
||||
res->sec = gps_atoi(str_tmp,GPS_UTC_SEC_LEN,10);
|
||||
str_tmp += (GPS_UTC_SEC_LEN + GPS_UTC_POINT_LEN);
|
||||
res->hsec = gps_atoi(str_tmp,3,10);
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG("Parse of UTC fail (format error)!");
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static inline void gps_data_conv(void* str, int len,void* addr,int type)
|
||||
{
|
||||
switch(type){
|
||||
case GPS_TYPE_FLOAT:
|
||||
*(float*)(addr) = (float)gps_atof(str,len);
|
||||
//printf("f == %f\n",*(float*)(addr));
|
||||
break;
|
||||
case GPS_TYPE_INT32:
|
||||
*(int*)(addr) = (int)gps_atoi(str,len,10);
|
||||
//printf("d == %d\n",*(int*)(addr) );
|
||||
break;
|
||||
|
||||
case GPS_TYPE_UINT8:
|
||||
*(char*)(addr) = *(char*)str;
|
||||
//printf("c == %c\n",*(char*)(addr) );
|
||||
break;
|
||||
|
||||
case GPS_TYPE_STR:
|
||||
memcpy(addr, str, len);
|
||||
((char *)addr)[len] = '\0';
|
||||
//printf("S == %s\n",(char*)(addr) );
|
||||
break;
|
||||
|
||||
case GPS_TYPE_UTC:
|
||||
gps_utc_get(str,len,addr);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif /* GPS_PARSE_H */
|
||||
|
||||
52
Living_SDK/device/gps/ucube.py
Normal file
52
Living_SDK/device/gps/ucube.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
src =Split('''
|
||||
hal/gps_hal.c
|
||||
parse/gps_parse.c
|
||||
''')
|
||||
component =aos_component('gps', src)
|
||||
|
||||
dependencis =Split('''
|
||||
device/sal
|
||||
framework/atparser
|
||||
''')
|
||||
for i in dependencis:
|
||||
component.add_comp_deps(i)
|
||||
|
||||
global_includes =Split('''
|
||||
.
|
||||
''')
|
||||
for i in global_includes:
|
||||
component.add_global_includes(i)
|
||||
|
||||
global_macros =Split('''
|
||||
AOS_GPS
|
||||
''')
|
||||
for i in global_macros:
|
||||
component.add_global_macros(i)
|
||||
|
||||
includes =Split('''
|
||||
../../utility/iotx-utils/sdk-impl
|
||||
../../framework/atparser
|
||||
./hal
|
||||
./parse
|
||||
''')
|
||||
for i in includes:
|
||||
component.add_includes(i)
|
||||
|
||||
|
||||
cflags =Split('''
|
||||
-Wall
|
||||
-Werror
|
||||
''')
|
||||
for i in cflags:
|
||||
component.add_cflags(i)
|
||||
|
||||
module = aos_global_config.get('module')
|
||||
if module == 'gps.sim868':
|
||||
component.add_comp_deps('device/sal/gprs/sim800')
|
||||
component.add_global_macros('AOS_GPS_SIM868')
|
||||
src.add_sources('drv/drv_sim868/gps_drv_simcom_sim868.c')
|
||||
src.add_sources('drv/drv_sim868/gps_parse_simcom_sim868.c')
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue