da221gnss.lua 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. --[[
  2. @module da221gnss
  3. @summary 利用加速度传感器da221实现中断触发gnss定位
  4. @version 1.0
  5. @date 2025.08.01
  6. @author 李源龙
  7. @usage
  8. 使用Air8000利用内置的da221加速度传感器实现中断触发gnss定位
  9. ]]
  10. gnss=require("gnss")
  11. tcp=require("tcp")
  12. da221=require("da221")
  13. local intPin=gpio.WAKEUP2
  14. local tid
  15. local function mode1_cb(tag)
  16. log.info("TAGmode1_cb+++++++++",tag)
  17. local rmc=gnss.getRmc(0)
  18. log.info("nmea", "rmc", json.encode(gnss.getRmc(0)))
  19. tcp.latlngfnc(rmc.lat,rmc.lng)
  20. end
  21. local function timer1()
  22. log.info("timer1")
  23. gnss.close(gnss.DEFAULT,{tag="MODE1"})
  24. sys.timerStop(tid)
  25. end
  26. local function ind()
  27. log.info("int", gpio.get(intPin))
  28. if gpio.get(intPin) == 1 then
  29. sys.timerStart(timer1,10000)
  30. local x,y,z = da221.read_xyz() --读取x,y,z轴的数据
  31. log.info("x", x..'g', "y", y..'g', "z", z..'g')
  32. if gnss.openres()~=true then
  33. log.info("nmea", "openres", "false")
  34. gnss.open(gnss.DEFAULT,{tag="MODE1",cb=mode1_cb})
  35. tid=sys.timerLoopStart(mode1_cb, 5000)
  36. else
  37. log.info("nmea", "openres", "true")
  38. end
  39. end
  40. end
  41. local function gnss_fnc()
  42. log.info("gnss_fnc111")
  43. local gnssotps={
  44. gnssmode=1, --1为卫星全定位,2为单北斗
  45. agps_enable=true, --是否使用AGPS,开启AGPS后定位速度更快,会访问服务器下载星历,星历时效性为北斗1小时,GPS4小时,默认下载星历的时间为1小时,即一小时内只会下载一次
  46. debug=true, --是否输出调试信息
  47. -- uart=2, --使用的串口,780EGH和8000默认串口2
  48. -- uartbaud=115200, --串口波特率,780EGH和8000默认115200
  49. -- bind=1, --绑定uart端口进行GNSS数据读取,是否设置串口转发,指定串口号
  50. -- rtc=false --定位成功后自动设置RTC true开启,flase关闭
  51. }
  52. gnss.setup(gnssotps)
  53. --1、静态/微动检测,使用场景:微振动检测、手势识别;
  54. --2、常规运动监测,使用场景:运动监测、车载设备;
  55. --3、高动态冲击检测,使用场景:碰撞检测、工业冲击
  56. da221.open(1)
  57. gpio.debounce(intPin, 100)
  58. gpio.setup(intPin, ind)
  59. end
  60. sys.taskInit(gnss_fnc)