[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c: In function 'gps_init':
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:115:5: error: unknown type name 'hi_uart_attribute'; did you mean '__has_attribute'?
[OHOS ERROR] hi_uart_attribute config = {
[OHOS ERROR] ^~~~~~~~~~~~~~~~~
[OHOS ERROR] __has_attribute
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:116:9: error: field name not in record or union initializer
[OHOS ERROR] .baud_rate = 9600, // NEO-6M默认波特率
[OHOS ERROR] ^
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:116:9: note: (near initialization for 'config')
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:117:9: error: field name not in record or union initializer
[OHOS ERROR] .data_bits = HI_UART_DATA_BIT_8, // 8位数据位
[OHOS ERROR] ^
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:117:9: note: (near initialization for 'config')
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:117:22: error: 'HI_UART_DATA_BIT_8' undeclared (first use in this function); did you mean 'HI_ERR_DMA_BUSY'?
[OHOS ERROR] .data_bits = HI_UART_DATA_BIT_8, // 8位数据位
[OHOS ERROR] ^~~~~~~~~~~~~~~~~~
[OHOS ERROR] HI_ERR_DMA_BUSY
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:117:22: note: each undeclared identifier is reported only once for each function it appears in
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:117:22: warning: excess elements in scalar initializer
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:117:22: note: (near initialization for 'config')
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:118:9: error: field name not in record or union initializer
[OHOS ERROR] .stop_bits = HI_UART_STOP_BIT_1, // 1位停止位
[OHOS ERROR] ^
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:118:9: note: (near initialization for 'config')
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:118:22: error: 'HI_UART_STOP_BIT_1' undeclared (first use in this function); did you mean 'HI_UART_DATA_BIT_8'?
[OHOS ERROR] .stop_bits = HI_UART_STOP_BIT_1, // 1位停止位
[OHOS ERROR] ^~~~~~~~~~~~~~~~~~
[OHOS ERROR] HI_UART_DATA_BIT_8
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:118:22: warning: excess elements in scalar initializer
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:118:22: note: (near initialization for 'config')
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:119:9: error: field name not in record or union initializer
[OHOS ERROR] .parity = HI_UART_PARITY_NONE, // 无校验
[OHOS ERROR] ^
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:119:9: note: (near initialization for 'config')
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:119:19: error: 'HI_UART_PARITY_NONE' undeclared (first use in this function); did you mean 'HI_UART_DATA_BIT_8'?
[OHOS ERROR] .parity = HI_UART_PARITY_NONE, // 无校验
[OHOS ERROR] ^~~~~~~~~~~~~~~~~~~
[OHOS ERROR] HI_UART_DATA_BIT_8
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:119:19: warning: excess elements in scalar initializer
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:119:19: note: (near initialization for 'config')
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:120:9: error: field name not in record or union initializer
[OHOS ERROR] .fifo_enable = HI_TRUE // 启用FIFO
[OHOS ERROR] ^
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:120:9: note: (near initialization for 'config')
[OHOS ERROR] In file included from ../../../device/hisilicon/hispark_pegasus/sdk_liteos/include/hi_io.h:26:0,
[OHOS ERROR] from ../../../vendor/pzkj/pz_hi3861/common/bsp/include/bsp_gps.h:6,
[OHOS ERROR] from ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:1:
[OHOS ERROR] ../../../device/hisilicon/hispark_pegasus/sdk_liteos/include/hi_types_base.h:284:26: warning: excess elements in scalar initializer
[OHOS ERROR] #define HI_TRUE 1
[OHOS ERROR] ^
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:120:24: note: in expansion of macro 'HI_TRUE'
[OHOS ERROR] .fifo_enable = HI_TRUE // 启用FIFO
[OHOS ERROR] ^~~~~~~
[OHOS ERROR] ../../../device/hisilicon/hispark_pegasus/sdk_liteos/include/hi_types_base.h:284:26: note: (near initialization for 'config')
[OHOS ERROR] #define HI_TRUE 1
[OHOS ERROR] ^
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:120:24: note: in expansion of macro 'HI_TRUE'
[OHOS ERROR] .fifo_enable = HI_TRUE // 启用FIFO
[OHOS ERROR] ^~~~~~~
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:124:18: warning: implicit declaration of function 'hi_uart_init'; did you mean 'uart0_init'? [-Wimplicit-function-declaration]
[OHOS ERROR] hi_u32 ret = hi_uart_init(HI_UART_IDX_2, &config);
[OHOS ERROR] ^~~~~~~~~~~~
[OHOS ERROR] uart0_init
[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:124:31: error: 'HI_UART_IDX_2' undeclared (first use in this function); did you mean 'HI_GPIO_IDX_2'?
[OHOS ERROR] hi_u32 ret = hi_uart_init(HI_UART_IDX_2, &config);
[OHOS ERROR] ^~~~~~~~~~~~~
[OHOS ERROR] HI_GPIO_IDX_2
[OHOS ERROR] you can check build log in D:\hi3861\hi3861_hdu_iot_application\src\out\hispark_pegasus\wifiiot_hispark_pegasus\build.log
[OHOS ERROR] command: "D:\hi3861\hi3861_hdu_iot_application\src\prebuilts\build-tools\win64-x64\bin\ninja.exe -w dupbuild=warn -C D:\hi3861\hi3861_hdu_iot_application\src\out\hispark_pegasus\wifiiot_hispark_pegasus" failed
[OHOS ERROR] return code: 1
[OHOS ERROR] execution path: D:\hi3861\hi3861_hdu_iot_application\src
scons: *** [src\out\hispark_pegasus\wifiiot_hispark_pegasus\target.elf] Error -1请根据该错误对VSCODE以下代码进行修改#ifndef BSP__GPS_H__
#define BSP__GPS_H__
#include "cmsis_os2.h"
#include "hi_io.h"
#include "hi_gpio.h"
#include <stdio.h>
#include <string.h>
#include "bsp_uart.h"
#include "hi_errno.h"
// GPS 数据结构定义
typedef struct {
float longitude; // 经度 (度)
float latitude; // 纬度 (度)
char nshemi; // 北纬/南纬 (N/S)
char ewhemi; // 东经/西经 (E/W)
struct {
uint8_t hour; // UTC 小时
uint8_t min; // UTC 分钟
uint8_t sec; // UTC 秒
} utc;
uint8_t fixmode; // 定位模式
uint8_t posslnum; // 参与定位的卫星数
float altitude; // 海拔高度 (米)
} nmea_msg;
// 定义UART2引脚配置
#define GPS_UART_IDX HI_UART_IDX_2
#define GPS_BAUDRATE 9600 // NEO-6M默认波特率
// 函数声明
void gps_init(void);
void gps_parse_nmea(nmea_msg *gps, const char *buf);
void gps_show_data(const nmea_msg *gps);
#endif#include "bsp_gps.h"
#include <stdlib.h>
#include "bsp_uart.h" // 添加必要的UART头文件
// 查找逗号位置
// 计算m的n次方
static uint32_t NMEA_Pow(uint8_t m, uint8_t n) {
uint32_t result = 1;
while (n--) result *= m;
return result;
}
// 查找逗号位置(修改为接受const指针)
uint8_t nmea_comma_pos(const uint8_t *buf, uint8_t cx) {
const uint8_t *p = buf;
while (cx) {
if (*buf == '*' || *buf < ' ' || *buf > 'z')
return 0xFF; // 错误终止符
if (*buf == ',') cx--;
buf++;
}
return buf - p;
}
// 字符串转数字(修改为接受const指针)
int nmea_str2num(const uint8_t *buf, uint8_t *dx) {
const uint8_t *p = buf;
uint32_t ires = 0, fres = 0;
uint8_t ilen = 0, flen = 0, i;
uint8_t mask = 0;
int res;
while (1) {
if (*p == '-') { mask |= 0x02; p++; } // 负数标记
if (*p == ',' || *p == '*') break; // 结束符
if (*p == '.') { mask |= 0x01; p++; } // 小数点
else if (*p > '9' || *p < '0') { // 非法字符
ilen = 0; flen = 0; break;
}
if (mask & 0x01) flen++;
else ilen++;
p++;
}
if (mask & 0x02) buf++; // 跳过负号
for (i = 0; i < ilen; i++) // 整数部分
ires += NMEA_Pow(10, ilen - 1 - i) * (buf[i] - '0');
if (flen > 5) flen = 5; // 最多5位小数
if (dx) *dx = flen; // 安全处理空指针
for (i = 0; i < flen; i++) // 小数部分
fres += NMEA_Pow(10, flen - 1 - i) * (buf[ilen + 1 + i] - '0');
res = ires * NMEA_Pow(10, flen) + fres;
if (mask & 0x02) res = -res;
return res;
}
// 解析 GPRMC 语句
static void parse_gprmc(nmea_msg *gps, const char *buf) {
const char *p = strstr(buf, "GPRMC");
if (!p) return;
// 显式类型转换解决警告(函数参数已改为const uint8_t*)
uint8_t pos = nmea_comma_pos((const uint8_t *)p, 1); // UTC 时间
if (pos != 0xFF) {
uint32_t time = nmea_str2num((const uint8_t *)(p + pos), NULL);
gps->utc.hour = time / 10000;
gps->utc.min = (time % 10000) / 100;
gps->utc.sec = time % 100;
}
pos = nmea_comma_pos((const uint8_t *)p, 3); // 纬度
if (pos != 0xFF) {
float lat = nmea_str2num((const uint8_t *)(p + pos), NULL) / 100000.0f;
gps->latitude = (int)(lat / 100) + (lat - (int)(lat / 100) * 100) / 60.0f;
}
pos = nmea_comma_pos((const uint8_t *)p, 4); // 纬度半球
if (pos != 0xFF) gps->nshemi = *(p + pos);
pos = nmea_comma_pos((const uint8_t *)p, 5); // 经度
if (pos != 0xFF) {
float lon = nmea_str2num((const uint8_t *)(p + pos), NULL) / 100000.0f;
gps->longitude = (int)(lon / 100) + (lon - (int)(lon / 100) * 100) / 60.0f;
}
pos = nmea_comma_pos((const uint8_t *)p, 6); // 经度半球
if (pos != 0xFF) gps->ewhemi = *(p + pos);
}
// 主解析函数
void gps_parse_nmea(nmea_msg *gps, const char *buf) {
if (strstr(buf, "$GPRMC")) parse_gprmc(gps, buf); // 修正:移除多余空格
// 可扩展其他语句解析 (如GPGGA, GPGSA等)
}
void gps_init(void) {
// 初始化GPIO子系统 (必须首先调用)
hi_gpio_init();
// ===== 配置TX引脚 (GPIO11 - 输出) =====
hi_io_set_pull(HI_IO_NAME_GPIO_11, HI_IO_PULL_UP); // 上拉模式
hi_io_set_func(HI_IO_NAME_GPIO_11, HI_IO_FUNC_GPIO_11_UART2_TXD); // UART TX功能
hi_gpio_set_dir(HI_IO_NAME_GPIO_11, HI_GPIO_DIR_OUT); // 输出方向
// ===== 配置RX引脚 (GPIO12 - 输入) =====
hi_io_set_pull(HI_IO_NAME_GPIO_12, HI_IO_PULL_NONE); // 浮空模式(推荐)
hi_io_set_func(HI_IO_NAME_GPIO_12, HI_IO_FUNC_GPIO_12_UART2_RXD); // UART RX功能
hi_gpio_set_dir(HI_IO_NAME_GPIO_12, HI_GPIO_DIR_IN); // 输入方向
// ===== UART参数配置 =====
hi_uart_attribute config = {
.baud_rate = 9600, // NEO-6M默认波特率
.data_bits = HI_UART_DATA_BIT_8, // 8位数据位
.stop_bits = HI_UART_STOP_BIT_1, // 1位停止位
.parity = HI_UART_PARITY_NONE, // 无校验
.fifo_enable = HI_TRUE // 启用FIFO
};
// 初始化UART2
hi_u32 ret = hi_uart_init(HI_UART_IDX_2, &config);
if (ret != HI_ERR_SUCCESS) {
printf("GPS UART init failed! Error: 0x%X\n", ret);
}
}
// 显示GPS数据
void gps_show_data(const nmea_msg *gps) {
printf("Longitude: %.5f%c\n", gps->longitude, gps->ewhemi);
printf("Latitude: %.5f%c\n", gps->latitude, gps->nshemi);
printf("UTC Time: %02d:%02d:%02d\n", gps->utc.hour, gps->utc.min, gps->utc.sec);
printf("Satellites: %d\n", gps->posslnum);
printf("Altitude: %.1fm\n", gps->altitude);
}
最新发布