demoss

pannel3

May 6th, 2022
863
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | None | 0 0
  1. mute1='mute,1,1'
  2. function net_send(msg)
  3.   local tmp = {}
  4.   for i = 1, #msg do
  5.     tmp[i-1] = msg[i]
  6.   end
  7.   uart_send_data(tmp)
  8. end
  9.  
  10. inmut = {0, 0, 0, 0, 0, 0, 0, 0}
  11. outmut = {0, 0, 0, 0, 0, 0, 0, 0}
  12.  
  13. local wificom = 0
  14.             local mode = 1
  15.             local server_port = '5557'
  16.             local server_ip = '10.0.255.199'       
  17.             local dhcp    = 0
  18.             local ipaddr  = '10.0.255.123'
  19.             local netmask = '255.255.255.0'
  20.             local gateway = '10.0.255.1'
  21.             local dns     = '10.0.255.1'   
  22. function on_init() 
  23. start_timer(1, 1000, 1, 0)
  24.             set_network_cfg(dhcp, ipaddr, netmask, gateway, dns)
  25.             --set_network_service_cfg(wificom, mode, server_port, server_ip)
  26.             save_network_cfg() 
  27.         sockfd=udp_create(12345)
  28.         print('init_ok')
  29. end
  30.  
  31. function on_timer(timer_id)
  32. print('timer')
  33. if timer_id ==1 then
  34. if inmute[1] ==1 then set_value(0,17,1) end
  35. if inmute[1] ==1 then set_value(0,17,0) end
  36. end
  37. end
  38.  
  39. function on_control_notify(screen,control,value)
  40. if screen == 0 then
  41. if control ==17 and value==1 then
  42. byte_cmd(mute1)
  43. end
  44. end
  45. end
  46.  
  47. function byte_cmd (cmd)
  48. local cmd_loc = {}
  49. for i = 1, cmd:len() do
  50.   cmd_loc[i-1] = cmd:byte(i)
  51. end
  52. udp_sendto(sockfd, server_ip, server_port, cmd_loc)
  53. rcudp(sockfd)
  54. end
  55.  
  56. function rcudp(sockfd)
  57.   local ret,ip,port,packet = udp_recvfrom(sockfd)
  58.   local packet_str = ""
  59.  
  60.   for _, ch in ipairs(packet) do
  61.     packet_str = packet_str .. string.char(ch)  
  62.   end
  63.  
  64.   local _,_,i,v= packet_str:find("MUTE,(%d+),(%d+)")
  65. print(packet_str)
  66.   if i ~= nil then
  67.     inmut[tonumber(i)] = tonumber(v)
  68.   end
  69. end
Advertisement
Add Comment
Please, Sign In to add comment