Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
360 | f9daq | 1 | /* |
2 | * Red Pitaya TCPSOCKET service manager |
||
3 | * |
||
4 | * Author: Artem Kokos <a.kokos@integrasources.eu> |
||
5 | * |
||
6 | * (c) Red Pitaya http://www.redpitaya.com |
||
7 | * |
||
8 | */ |
||
9 | |||
10 | function parseIP(msg) { |
||
11 | |||
12 | var res = msg.responseText.split(";"); |
||
13 | var ethIP = res[0].match(/inet([\s\S]*?)brd/); |
||
14 | var wlanIP = res[1].match(/inet([\s\S]*?)brd/); |
||
15 | |||
16 | if (ethIP != null){ |
||
17 | ethIP = ethIP[0].split(" ")[1].split("/")[0]; |
||
18 | $('#ip-addr').text(ethIP); |
||
19 | } |
||
20 | else if (wlanIP != null){ |
||
21 | wlanIP = wlanIP[0].split(" ")[1].split("/")[0]; |
||
22 | $('#ip-addr').text(wlanIP); |
||
23 | } |
||
24 | else $('#ip-addr').text( window.location.host ); |
||
25 | |||
26 | |||
27 | } |
||
28 | |||
29 | |||
30 | (function(TCPSOCKET, $, undefined) { |
||
31 | TCPSOCKET.CheckServerStatus = function() { |
||
32 | $.ajax({ |
||
33 | url: '/get_tcpsocket_status', |
||
34 | type: 'GET', |
||
35 | timeout: 1500 |
||
36 | }) |
||
37 | .fail(function(msg) { |
||
38 | if (msg.responseText.split('\n')[0] == "active") { |
||
39 | $('#TCPSOCKET_RUN').hide(); |
||
40 | $('#TCPSOCKET_STOP').css('display', 'block'); |
||
41 | $('#label-is-runnung').hide(); |
||
42 | $('#label-is-not-runnung').show(); |
||
43 | } else { |
||
44 | $('#TCPSOCKET_STOP').hide(); |
||
45 | $('#TCPSOCKET_RUN').css('display', 'block'); |
||
46 | $('#label-is-not-runnung').hide(); |
||
47 | $('#label-is-runnung').show(); |
||
48 | } |
||
49 | }) |
||
50 | } |
||
51 | |||
52 | TCPSOCKET.StartServer = function() { |
||
53 | $.ajax({ |
||
54 | url: '/start_tcpsocket_manager', |
||
55 | type: 'GET', |
||
56 | timeout: 2500 |
||
57 | }) |
||
58 | .fail(function(msg) { |
||
59 | if (msg.responseText) {} else {} |
||
60 | }) |
||
61 | } |
||
62 | |||
63 | TCPSOCKET.StopServer = function() { |
||
64 | $.ajax({ |
||
65 | url: '/stop_tcpsocket_manager', |
||
66 | type: 'GET', |
||
67 | timeout: 2500 |
||
68 | }) |
||
69 | .fail(function(msg) { |
||
70 | if (msg.responseText) {} else {} |
||
71 | }) |
||
72 | } |
||
73 | |||
74 | TCPSOCKET.GetIP = function() { |
||
75 | $.ajax({ |
||
76 | url: '/get_rpip', |
||
77 | type: 'GET', |
||
78 | }).fail( parseIP ).done( parseIP ) |
||
79 | } |
||
80 | |||
81 | }(window.TCPSOCKET = window.TCPSOCKET || {}, jQuery)); |
||
82 | |||
83 | |||
84 | |||
85 | |||
86 | // Page onload event handler |
||
87 | $(function() { |
||
88 | |||
89 | // Init help |
||
90 | Help.init(helpListTCPSOCKET); |
||
91 | Help.setState("idle"); |
||
92 | |||
93 | TCPSOCKET.CheckServerStatus(); |
||
94 | setInterval(TCPSOCKET.GetIP, 3000); |
||
95 | setInterval(TCPSOCKET.CheckServerStatus, 3333); |
||
96 | |||
97 | $('#TCPSOCKET_RUN').click(TCPSOCKET.StartServer); |
||
98 | |||
99 | $('#TCPSOCKET_STOP').click(TCPSOCKET.StopServer); |
||
100 | |||
101 | $('#TCPSOCKET_EXAMPLES').click(function(){ |
||
102 | window.open('http://redpitaya.com/examples-new/','_blank'); |
||
103 | }); |
||
104 | }); |