testGnss.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. -- libgnss库初始化
  2. libgnss.clear() -- 清空数据,兼初始化
  3. -- LED和ADC初始化
  4. LED_GNSS = 24
  5. gpio.setup(LED_GNSS, 0) -- GNSS定位成功灯
  6. local hdgnss = require("hdgnss")
  7. sys.taskInit(function()
  8. log.debug("提醒", "室内无GNSS信号,定位不会成功, 要到空旷的室外,起码要看得到天空")
  9. hdgnss.setup({
  10. uart_id=2,
  11. uart_forward = uart.VUART_0, -- 转发到虚拟串口,方便对接GnssToolKit3
  12. debug=true
  13. })
  14. hdgnss.start()
  15. end)
  16. sys.taskInit(function()
  17. while 1 do
  18. sys.wait(5000)
  19. -- log.info("RMC", json.encode(libgnss.getRmc(2) or {}, "7f"))
  20. -- log.info("INT", libgnss.getIntLocation())
  21. -- log.info("GGA", libgnss.getGga(3))
  22. -- log.info("GLL", json.encode(libgnss.getGll(2) or {}, "7f"))
  23. -- log.info("GSA", json.encode(libgnss.getGsa(1) or {}, "7f"))
  24. -- log.info("GSV", json.encode(libgnss.getGsv(2) or {}, "7f"))
  25. -- log.info("VTG", json.encode(libgnss.getVtg(2) or {}, "7f"))
  26. -- log.info("ZDA", json.encode(libgnss.getZda(2) or {}, "7f"))
  27. -- log.info("date", os.date())
  28. -- log.info("sys", rtos.meminfo("sys"))
  29. -- log.info("lua", rtos.meminfo("lua"))
  30. end
  31. end)
  32. -- 订阅GNSS状态编码
  33. sys.subscribe("GNSS_STATE", function(event, ticks)
  34. -- event取值有
  35. -- FIXED 定位成功
  36. -- LOSE 定位丢失
  37. -- ticks是事件发生的时间,一般可以忽略
  38. local onoff = libgnss.isFix() and 1 or 0
  39. log.info("GNSS", "LED", onoff)
  40. gpio.set(LED_GNSS, onoff)
  41. end)