testGnss.lua 1.6 KB

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