Subversion Repositories HomeAutomation

Rev

Rev 1673 | Rev 1889 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1673 Rev 1887
1
 
1
 
2
Node_ResetNodeId = null;
2
Node_ResetNodeId = null;
3
Node_ResetClientId = null;
3
Node_ResetClientId = null;
4
 
4
 
5
Node_ProgramNodeId = null;
5
Node_ProgramNodeId = null;
6
Node_ProgramClientId = null;
6
Node_ProgramClientId = null;
7
 
7
 
8
Node_WaitClientId = null;
8
Node_WaitClientId = null;
-
 
9
 
-
 
10
Node_HexData = "";
9
 
11
 
10
function Node_OnChange(node_id, available)
12
function Node_OnChange(node_id, available)
11
{
13
{
12
    if (node_id == Node_ResetNodeId && available)
14
    if (node_id == Node_ResetNodeId && available)
13
    {
15
    {
14
        Console_LogToClient(Node_ResetClientId, "\033[32m" + Node_ResetNodeId + " started okay.\033[0m\n");
16
        Console_LogToClient(Node_ResetClientId, "\033[32m" + Node_ResetNodeId + " started okay.\033[0m\n");
15
        Node_ResetNodeId = null;
17
        Node_ResetNodeId = null;
16
        Node_ResetClientId = null;
18
        Node_ResetClientId = null;
17
        Console_SetDefaultPrompt();
19
        Console_SetDefaultPrompt();
18
    }
20
    }
19
   
21
   
20
    if (node_id == Node_ProgramNodeId && available)
22
    if (node_id == Node_ProgramNodeId && available)
21
    {
23
    {
22
        Console_LogToClient(Node_ProgramClientId, "\033[32m" + Node_ProgramNodeId + " started okay.\033[0m\n");
24
        Console_LogToClient(Node_ProgramClientId, "\033[32m" + Node_ProgramNodeId + " started okay.\033[0m\n");
23
        Node_ProgramNodeId = null;
25
        Node_ProgramNodeId = null;
24
        Node_ProgramClientId = null;
26
        Node_ProgramClientId = null;
25
        Console_SetDefaultPrompt();
27
        Console_SetDefaultPrompt();
26
    }
28
    }
27
   
29
   
28
    if (Node_WaitClientId != null && available)
30
    if (Node_WaitClientId != null && available)
29
    {    
31
    {    
30
        var result = NodeExport_GetNodeInformation(node_id);
32
        var result = NodeExport_GetNodeInformation(node_id);
31
   
33
   
32
        if (!result)
34
        if (!result)
33
        {
35
        {
34
            Console_LogToClient(Node_WaitClientId, "\033[31mNo node with id " + node_id + " found.\033[0m\n");
36
            Console_LogToClient(Node_WaitClientId, "\033[31mNo node with id " + node_id + " found.\033[0m\n");
35
            return false;
37
            return false;
36
        }
38
        }
37
       
39
       
38
        var date = new Date(result["LastActive"] * 1000);
40
        var date = new Date(result["LastActive"] * 1000);
39
       
41
       
40
        Console_LogToClient(Node_WaitClientId, "Id: " + result["Id"] + "\n");
42
        Console_LogToClient(Node_WaitClientId, "Id: " + result["Id"] + "\n");
41
        Console_LogToClient(Node_WaitClientId, "Valid: " + result["Valid"] + "\n");
43
        Console_LogToClient(Node_WaitClientId, "Valid: " + result["Valid"] + "\n");
42
        Console_LogToClient(Node_WaitClientId, "Bios Version: " + result["BiosVersion"] + "\n");
44
        Console_LogToClient(Node_WaitClientId, "Bios Version: " + result["BiosVersion"] + "\n");
43
        Console_LogToClient(Node_WaitClientId, "Device Type: " + result["DeviceType"] + "\n");
45
        Console_LogToClient(Node_WaitClientId, "Device Type: " + result["DeviceType"] + "\n");
44
        Console_LogToClient(Node_WaitClientId, "Has Application: " + result["HasApplication"] + "\n");
46
        Console_LogToClient(Node_WaitClientId, "Has Application: " + result["HasApplication"] + "\n");
45
        Console_LogToClient(Node_WaitClientId, "Last Active: " + date.toString() + "\n");
47
        Console_LogToClient(Node_WaitClientId, "Last Active: " + date.toString() + "\n");
46
       
48
       
47
        Node_WaitClientId = null;
49
        Node_WaitClientId = null;
48
        Console_SetDefaultPrompt();
50
        Console_SetDefaultPrompt();
49
    }
51
    }
50
}
52
}
51
 
53
 
52
function Node_GetAvailableIds()
54
function Node_GetAvailableIds()
53
{
55
{
54
    var result_list = [];
56
    var result_list = [];
55
    var available_nodes = NodeExport_GetAvailableNodes();
57
    var available_nodes = NodeExport_GetAvailableNodes();
56
   
58
   
57
    for (var n in available_nodes)
59
    for (var n in available_nodes)
58
    {
60
    {
59
        var id_parts = available_nodes[n].split(",", 2);
61
        var id_parts = available_nodes[n].split(",", 2);
60
       
62
       
61
        result_list.push(id_parts[0]);
63
        result_list.push(id_parts[0]);
62
    }
64
    }
63
   
65
   
64
    return result_list;
66
    return result_list;
65
}
67
}
66
 
68
 
67
function Node_ListAvailable()
69
function Node_ListAvailable()
68
{
70
{
69
    var available_nodes = NodeExport_GetAvailableNodes();
71
    var available_nodes = NodeExport_GetAvailableNodes();
70
   
72
   
71
    var lines = [["Id", "Modules"]];
73
    var lines = [["Id", "Modules"]];
72
   
74
   
73
    for (var n in available_nodes)
75
    for (var n in available_nodes)
74
    {
76
    {
75
        var parts = available_nodes[n].split(",");
77
        var parts = available_nodes[n].split(",");
76
        var id = parts.shift();
78
        var id = parts.shift();
77
        var modules = "<none>";
79
        var modules = "<none>";
78
       
80
       
79
        if (parts.length > 0)
81
        if (parts.length > 0)
80
        {
82
        {
81
            modules = parts.join(", ");
83
            modules = parts.join(", ");
82
        }
84
        }
83
       
85
       
84
        lines.push([id, modules]);
86
        lines.push([id, modules]);
85
    }
87
    }
86
   
88
   
87
    var table_lines = create_table(lines);
89
    var table_lines = create_table(lines);
88
   
90
   
89
    Log("\033[29;1m" + table_lines[0] + "\033[0m\n");
91
    Log("\033[29;1m" + table_lines[0] + "\033[0m\n");
90
   
92
   
91
    for (var n = 1; n < table_lines.length; n++)
93
    for (var n = 1; n < table_lines.length; n++)
92
    {
94
    {
93
        Log(table_lines[n] + "\n");
95
        Log(table_lines[n] + "\n");
94
    }
96
    }
95
   
97
   
96
    return true;
98
    return true;
97
}
99
}
98
Console_RegisterCommand(Node_ListAvailable);
100
Console_RegisterCommand(Node_ListAvailable);
99
 
101
 
100
function Node_Reset(node_id)
102
function Node_Reset(node_id)
101
{
103
{
102
    if (arguments.length < 1)
104
    if (arguments.length < 1)
103
    {
105
    {
104
        Log("\033[31mNot enough parameters given.\033[0m\n");
106
        Log("\033[31mNot enough parameters given.\033[0m\n");
105
        return false;
107
        return false;
106
    }
108
    }
107
   
109
   
108
    Log("Sending reset to " + node_id + "...\n");
110
    Log("Sending reset to " + node_id + "...\n");
109
   
111
   
110
    if (!NodeExport_ResetNode(node_id))
112
    if (!NodeExport_ResetNode(node_id))
111
    {
113
    {
112
        Log("\033[31mFailed to send reset.\033[0m\n");
114
        Log("\033[31mFailed to send reset.\033[0m\n");
113
        return false;
115
        return false;
114
    }
116
    }
115
   
117
   
116
    Node_ProgramClientId = Console_GetClientId();
118
    Node_ProgramClientId = Console_GetClientId();
117
    Node_ProgramNodeId = node_id;
119
    Node_ProgramNodeId = node_id;
118
    Console_PreventDefaultPrompt();
120
    Console_PreventDefaultPrompt();
119
 
121
 
120
    return true;
122
    return true;
121
}
123
}
122
Console_RegisterCommand(Node_Reset, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
124
Console_RegisterCommand(Node_Reset, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
123
 
125
 
124
function Node_Program(node_id, bios, filename)
126
function Node_Program(node_id, bios, filename)
125
{
127
{
126
    if (arguments.length < 3)
128
    if (arguments.length < 3)
127
    {
129
    {
128
        Log("\033[31mNot enough parameters given.\033[0m\n");
130
        Log("\033[31mNot enough parameters given.\033[0m\n");
129
        return false;
131
        return false;
130
    }
132
    }
131
   
133
   
132
    Log("Initiating programming of " + node_id + "...\n");
134
    Log("Initiating programming of " + node_id + "...\n");
133
   
135
   
134
    if (!NodeExport_ProgramNode(node_id, bios > 0, filename))
136
    if (!NodeExport_ProgramNode(node_id, bios > 0, filename))
135
    {
137
    {
136
        Log("\033[31mFailed to start programming.\033[0m\n");
138
        Log("\033[31mFailed to start programming.\033[0m\n");
137
        return false;
139
        return false;
-
 
140
    }
-
 
141
   
-
 
142
    Node_ResetClientId = Console_GetClientId();
-
 
143
    Node_ResetNodeId = node_id;
-
 
144
    Console_PreventDefaultPrompt();
-
 
145
   
-
 
146
    return true;
-
 
147
}
-
 
148
Console_RegisterCommand(Node_Program, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds(), [0, 1]); });
-
 
149
 
-
 
150
function Node_ProgramHex(node_id, bios)
-
 
151
{
-
 
152
    if (arguments.length < 2)
-
 
153
    {
-
 
154
        Log("\033[31mNot enough parameters given.\033[0m\n");
-
 
155
        return false;
-
 
156
    }
-
 
157
   
-
 
158
    Log("Initiating programming of " + node_id + "...\n");
-
 
159
   
-
 
160
    if (!NodeExport_ProgramNodeHex(node_id, bios > 0, Node_HexData))
-
 
161
    {
-
 
162
        Log("\033[31mFailed to start programming.\033[0m\n");
-
 
163
        return false;
138
    }
164
    }
139
   
165
   
140
    Node_ResetClientId = Console_GetClientId();
166
    Node_ResetClientId = Console_GetClientId();
141
    Node_ResetNodeId = node_id;
167
    Node_ResetNodeId = node_id;
142
    Console_PreventDefaultPrompt();
168
    Console_PreventDefaultPrompt();
-
 
169
 
-
 
170
    Node_HexData = "";
-
 
171
 
-
 
172
    return true;
-
 
173
}
-
 
174
Console_RegisterCommand(Node_ProgramHex, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds(), [0, 1]); });
-
 
175
 
-
 
176
function Node_ClearHex()
-
 
177
{
-
 
178
    Log("Clearing hexdata...\n");
-
 
179
   
-
 
180
    Node_HexData = "";
-
 
181
   
-
 
182
    return true;
-
 
183
}
-
 
184
Console_RegisterCommand(Node_ClearHex);
-
 
185
 
-
 
186
function Node_AppendHex(hexrow)
-
 
187
{
-
 
188
    if (arguments.length < 1)
-
 
189
    {
-
 
190
        Log("\033[31mNot enough parameters given.\033[0m\n");
-
 
191
        return false;
-
 
192
    }
-
 
193
   
-
 
194
    Log("Appending hexrow...\n");
-
 
195
   
-
 
196
    Node_HexData = Node_HexData + hexrow + "\n";
143
   
197
   
144
    return true;
198
    return true;
145
}
199
}
146
Console_RegisterCommand(Node_Program, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds(), [0, 1]); });
200
Console_RegisterCommand(Node_AppendHex);
147
 
201
 
148
function Node_GetInformation(node_id)
202
function Node_GetInformation(node_id)
149
{
203
{
150
    if (arguments.length < 1)
204
    if (arguments.length < 1)
151
    {
205
    {
152
        Log("\033[31mNot enough parameters given.\033[0m\n");
206
        Log("\033[31mNot enough parameters given.\033[0m\n");
153
        return false;
207
        return false;
154
    }
208
    }
155
   
209
   
156
    var result = NodeExport_GetNodeInformation(node_id);
210
    var result = NodeExport_GetNodeInformation(node_id);
157
   
211
   
158
    if (!result)
212
    if (!result)
159
    {
213
    {
160
        Log("\033[31mNo node with id " + node_id + " found.\033[0m\n");
214
        Log("\033[31mNo node with id " + node_id + " found.\033[0m\n");
161
        return false;
215
        return false;
162
    }
216
    }
163
   
217
   
164
    var date = new Date(result["LastActive"] * 1000);
218
    var date = new Date(result["LastActive"] * 1000);
165
 
219
 
166
    Log("\033[96mId: \033[0;1m" + result["Id"] + "\033[0m\n");
220
    Log("\033[96mId: \033[0;1m" + result["Id"] + "\033[0m\n");
167
    Log("\033[96mValid: \033[0;1m" + result["Valid"] + "\033[0m\n");
221
    Log("\033[96mValid: \033[0;1m" + result["Valid"] + "\033[0m\n");
168
    Log("\033[96mBios Version: \033[0;1m" + result["BiosVersion"] + "\033[0m\n");
222
    Log("\033[96mBios Version: \033[0;1m" + result["BiosVersion"] + "\033[0m\n");
169
    Log("\033[96mDevice Type: \033[0;1m" + result["DeviceType"] + "\033[0m\n");
223
    Log("\033[96mDevice Type: \033[0;1m" + result["DeviceType"] + "\033[0m\n");
170
    Log("\033[96mHas Application: \033[0;1m" + result["HasApplication"] + "\033[0m\n");
224
    Log("\033[96mHas Application: \033[0;1m" + result["HasApplication"] + "\033[0m\n");
171
    Log("\033[96mLast Active: \033[0;1m" + date.toString() + "\033[0m\n");
225
    Log("\033[96mLast Active: \033[0;1m" + date.toString() + "\033[0m\n");
172
   
226
   
173
    return true;
227
    return true;
174
}
228
}
175
Console_RegisterCommand(Node_GetInformation, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
229
Console_RegisterCommand(Node_GetInformation, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
176
 
230
 
177
function Node_WaitForInformation()
231
function Node_WaitForInformation()
178
{
232
{
179
    Node_WaitClientId = Console_GetClientId();
233
    Node_WaitClientId = Console_GetClientId();
180
    Console_PreventDefaultPrompt();
234
    Console_PreventDefaultPrompt();
181
   
235
   
182
    return true;
236
    return true;
183
}
237
}
184
Console_RegisterCommand(Node_WaitForInformation);
238
Console_RegisterCommand(Node_WaitForInformation);
185
 
239