Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mute1='mute,1,1'
- function net_send(msg)
- local tmp = {}
- for i = 1, #msg do
- tmp[i-1] = msg[i]
- end
- uart_send_data(tmp)
- end
- inmut = {0, 0, 0, 0, 0, 0, 0, 0}
- outmut = {0, 0, 0, 0, 0, 0, 0, 0}
- local wificom = 0
- local mode = 1
- local server_port = '5557'
- local server_ip = '10.0.255.199'
- local dhcp = 0
- local ipaddr = '10.0.255.123'
- local netmask = '255.255.255.0'
- local gateway = '10.0.255.1'
- local dns = '10.0.255.1'
- function on_init()
- start_timer(1, 1000, 1, 0)
- set_network_cfg(dhcp, ipaddr, netmask, gateway, dns)
- --set_network_service_cfg(wificom, mode, server_port, server_ip)
- save_network_cfg()
- sockfd=udp_create(12345)
- print('init_ok')
- end
- function on_timer(timer_id)
- print('timer')
- if timer_id ==1 then
- if inmute[1] ==1 then set_value(0,17,1) end
- if inmute[1] ==1 then set_value(0,17,0) end
- end
- end
- function on_control_notify(screen,control,value)
- if screen == 0 then
- if control ==17 and value==1 then
- byte_cmd(mute1)
- end
- end
- end
- function byte_cmd (cmd)
- local cmd_loc = {}
- for i = 1, cmd:len() do
- cmd_loc[i-1] = cmd:byte(i)
- end
- udp_sendto(sockfd, server_ip, server_port, cmd_loc)
- rcudp(sockfd)
- end
- function rcudp(sockfd)
- local ret,ip,port,packet = udp_recvfrom(sockfd)
- local packet_str = ""
- for _, ch in ipairs(packet) do
- packet_str = packet_str .. string.char(ch)
- end
- local _,_,i,v= packet_str:find("MUTE,(%d+),(%d+)")
- print(packet_str)
- if i ~= nil then
- inmut[tonumber(i)] = tonumber(v)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment