airlan.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. local airlan = {}
  2. dnsproxy = require("dnsproxy")
  3. dhcpsrv = require("dhcpsrv")
  4. httpplus = require("httpplus")
  5. local run_state = false
  6. local lan_state = false
  7. local number = 0
  8. local bytes = ""
  9. local ms_duration = ""
  10. local bandwidth = ""
  11. local lan_net_state = "未打开"
  12. local event = ""
  13. local function start_lan()
  14. sys.wait(500)
  15. log.info("ch390", "打开LDO供电")
  16. lan_net_state = "打开LDO供电"
  17. gpio.setup(140, 1, gpio.PULLUP) --打开ch390供电
  18. sys.wait(2000)
  19. local result = spi.setup(
  20. 1,--spi_id
  21. nil,
  22. 0,--CPHA
  23. 0,--CPOL
  24. 8,--数据宽度
  25. 25600000--,--频率
  26. -- spi.MSB,--高低位顺序 可选,默认高位在前
  27. -- spi.master,--主模式 可选,默认主
  28. -- spi.full--全双工 可选,默认全双工
  29. )
  30. log.info("main", "open",result)
  31. if result ~= 0 then--返回值为0,表示打开成功
  32. log.info("main", "spi open error",result)
  33. return
  34. end
  35. -- 初始化指定netdrv设备,
  36. -- socket.LWIP_ETH 网络适配器编号
  37. -- netdrv.CH390外挂CH390
  38. -- SPI ID 1, 片选 GPIO12
  39. netdrv.setup(socket.LWIP_ETH, netdrv.CH390, {spi=1,cs=12})
  40. sys.wait(3000)
  41. local ipv4,mark, gw = netdrv.ipv4(socket.LWIP_ETH, "192.168.4.1", "255.255.255.0", "192.168.4.1")
  42. log.info("ipv4", ipv4,mark, gw)
  43. while netdrv.link(socket.LWIP_ETH) ~= true do
  44. sys.wait(100)
  45. end
  46. while netdrv.link(socket.LWIP_GP) ~= true do
  47. sys.wait(100)
  48. end
  49. sys.wait(2000)
  50. dhcpsrv.create({adapter=socket.LWIP_ETH})
  51. dnsproxy.setup(socket.LWIP_ETH, socket.LWIP_GP)
  52. netdrv.napt(socket.LWIP_GP)
  53. log.info("启动iperf服务器端")
  54. lan_net_state = "以太网服务创建成功,启动iperf服务器端"
  55. iperf.server(socket.LWIP_ETH)
  56. end
  57. local function stop_lan()
  58. end
  59. sys.subscribe("IPERF_REPORT", function(bytes, ms_duration, bandwidth)
  60. log.info("iperf", bytes, ms_duration, bandwidth)
  61. end)
  62. function airlan.run()
  63. log.info("airlan.run")
  64. lcd.setFont(lcd.font_opposansm12_chinese) -- 具体取值可参考api文档的常量表
  65. run_state = true
  66. while true do
  67. sys.wait(10)
  68. -- airlink.statistics()
  69. lcd.clear(_G.bkcolor)
  70. lcd.drawStr(0,80,"以太网LAN状态:"..lan_net_state )
  71. if lan_state then
  72. lcd.drawStr(0,120,"bytes:" .. bytes )
  73. lcd.drawStr(0,140,"ms_duration:" .. ms_duration )
  74. lcd.drawStr(0,160,"bandwidth:" .. bandwidth )
  75. lcd.drawStr(0,180,"空间 LUA:" .. rtos.meminfo() .. ",SYS:" .. rtos.meminfo("sys") )
  76. lcd.drawStr(0,200, event)
  77. end
  78. lcd.showImage(20,360,"/luadb/back.jpg")
  79. if lan_state then
  80. lcd.showImage(130,370,"/luadb/stop.jpg")
  81. else
  82. lcd.showImage(130,370,"/luadb/start.jpg")
  83. end
  84. lcd.showImage(0,448,"/luadb/Lbottom.jpg")
  85. lcd.flush()
  86. if not run_state then -- 等待结束
  87. return true
  88. end
  89. end
  90. end
  91. local function start_lan_task()
  92. lan_state = true
  93. start_lan()
  94. end
  95. local function stop_lan_task()
  96. -- stop_lan()
  97. lan_state = false
  98. end
  99. function airlan.start_lan()
  100. start_lan()
  101. end
  102. function airlan.tp_handal(x,y,event) -- 判断是否需要停止播放
  103. if x > 20 and x < 100 and y > 360 and y < 440 then
  104. run_state = false
  105. elseif x > 130 and x < 230 and y > 370 and y < 417 then
  106. if lan_state then
  107. sysplus.taskInitEx(stop_lan_task, "stop_lan_task")
  108. else
  109. sysplus.taskInitEx(start_lan_task , "start_lan_task")
  110. end
  111. end
  112. end
  113. return airlan