Subversion Repositories HomeAutomation

Rev

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

Rev 2083 Rev 2160
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_Native_Reset = false;
-
 
11
Node_Native_Program = false;
-
 
12
//Node_Native_WaitNodeId = null;
9
 
13
 
10
Node_HexData = "";
14
Node_HexData = "";
11
Node_HexNumLines = 0;
15
Node_HexNumLines = 0;
12
 
16
 
13
function Node_OnChange(node_id, available)
17
function Node_OnChange(node_id, available)
14
{
18
{
-
 
19
Log("Node_OnChange "+Node_ResetNodeId+" "+Node_ProgramNodeId+" "+node_id+" "+available+"\n");
15
    if (node_id == Node_ResetNodeId && available)
20
    if (node_id == Node_ResetNodeId && available)
16
    {
21
    {
-
 
22
Log("ResetNodeId "+Node_Native_Reset+"\n");
17
        Console_LogToClient(Node_ResetClientId, "\033[32m" + Node_ResetNodeId + " started okay.\033[0m\n");
23
        Console_LogToClient(Node_ResetClientId, "\033[32m" + Node_ResetNodeId + " started okay.\033[0m\n");
18
 
24
 
19
    Console_NewConnection(Node_ResetClientId); // This is a ugly hack for a bad design for multiusers
25
        Console_NewConnection(Node_ResetClientId); // This is a ugly hack for a bad design for multiusers
20
    Node_ResetNodeId = null;
26
        Node_ResetNodeId = null;
21
    Node_ResetClientId = null;
27
        Node_ResetClientId = null;
-
 
28
       
-
 
29
        Node_Native_Reset = true;
22
    }
30
    }
23
 
31
 
24
    if (node_id == Node_ProgramNodeId && available)
32
    if (node_id == Node_ProgramNodeId && available)
25
    {
33
    {
-
 
34
Log("ProgramNodeId "+Node_Native_Program+"\n");
26
        Console_LogToClient(Node_ProgramClientId, "\033[32m" + Node_ProgramNodeId + " started okay.\033[0m\n");
35
        Console_LogToClient(Node_ProgramClientId, "\033[32m" + Node_ProgramNodeId + " started okay.\033[0m\n");
27
 
36
 
28
        Console_NewConnection(Node_ProgramClientId); // This is a ugly hack for a bad design for multiusers
37
        Console_NewConnection(Node_ProgramClientId); // This is a ugly hack for a bad design for multiusers
29
        Node_ProgramNodeId = null;
38
        Node_ProgramNodeId = null;
30
        Node_ProgramClientId = null;
39
        Node_ProgramClientId = null;
-
 
40
       
-
 
41
        Node_Native_Program = true;
31
    }
42
    }
32
 
43
 
33
    if (Node_WaitClientId != null && available)
44
    if (Node_WaitClientId != null && available)
34
    {
45
    {
35
        var result = NodeExport_GetNodeInformation(node_id);
46
        var result = NodeExport_GetNodeInformation(node_id);
36
 
47
 
37
        if (!result)
48
        if (!result)
38
        {
49
        {
39
            Console_LogToClient(Node_WaitClientId, "\033[31mNo node with id " + node_id + " found.\033[0m\n");
50
            Console_LogToClient(Node_WaitClientId, "\033[31mNo node with id " + node_id + " found.\033[0m\n");
40
            return false;
51
            return false;
41
        }
52
        }
42
 
53
 
43
        var date = new Date(result["LastActive"] * 1000);
54
        var date = new Date(result["LastActive"] * 1000);
44
 
55
 
45
        Console_LogToClient(Node_WaitClientId, "Id: " + result["Id"] + "\n");
56
        Console_LogToClient(Node_WaitClientId, "Id: " + result["Id"] + "\n");
46
        Console_LogToClient(Node_WaitClientId, "Valid: " + result["Valid"] + "\n");
57
        Console_LogToClient(Node_WaitClientId, "Valid: " + result["Valid"] + "\n");
47
        Console_LogToClient(Node_WaitClientId, "Bios Version: " + result["BiosVersion"] + "\n");
58
        Console_LogToClient(Node_WaitClientId, "Bios Version: " + result["BiosVersion"] + "\n");
48
        Console_LogToClient(Node_WaitClientId, "Device Type: " + result["DeviceType"] + "\n");
59
        Console_LogToClient(Node_WaitClientId, "Device Type: " + result["DeviceType"] + "\n");
49
        Console_LogToClient(Node_WaitClientId, "Has Application: " + result["HasApplication"] + "\n");
60
        Console_LogToClient(Node_WaitClientId, "Has Application: " + result["HasApplication"] + "\n");
50
        Console_LogToClient(Node_WaitClientId, "Last Active: " + date.toString() + "\n");
61
        Console_LogToClient(Node_WaitClientId, "Last Active: " + date.toString() + "\n");
51
 
62
 
52
        Console_NewConnection(Node_WaitClientId); // This is a ugly hack for a bad design for multiusers
63
        Console_NewConnection(Node_WaitClientId); // This is a ugly hack for a bad design for multiusers
53
        Node_WaitClientId = null;
64
        Node_WaitClientId = null;
54
    }
65
    }
55
}
66
}
56
 
67
 
57
function Node_GetAvailableIds()
68
function Node_GetAvailableIds()
58
{
69
{
59
    var result_list = [];
70
    var result_list = [];
60
    var available_nodes = NodeExport_GetAvailableNodes();
71
    var available_nodes = NodeExport_GetAvailableNodes();
61
 
72
 
62
    for (var n in available_nodes)
73
    for (var n in available_nodes)
63
    {
74
    {
64
        var id_parts = available_nodes[n].split(",", 2);
75
        var id_parts = available_nodes[n].split(",", 2);
65
 
76
 
66
        result_list.push(id_parts[0]);
77
        result_list.push(id_parts[0]);
67
    }
78
    }
68
 
79
 
69
    return result_list;
80
    return result_list;
70
}
81
}
71
 
82
 
72
function Node_ListAvailable()
83
function Node_ListAvailable()
73
{
84
{
74
    var available_nodes = NodeExport_GetAvailableNodes();
85
    var available_nodes = NodeExport_GetAvailableNodes();
75
 
86
 
76
    var lines = [["Id", "Modules"]];
87
    var lines = [["Id", "Modules"]];
77
 
88
 
78
    for (var n in available_nodes)
89
    for (var n in available_nodes)
79
    {
90
    {
80
        var parts = available_nodes[n].split(",");
91
        var parts = available_nodes[n].split(",");
81
        var id = parts.shift();
92
        var id = parts.shift();
82
        var modules = "<none>";
93
        var modules = "<none>";
83
 
94
 
84
        if (parts.length > 0)
95
        if (parts.length > 0)
85
        {
96
        {
86
            modules = parts.join(", ");
97
            modules = parts.join(", ");
87
        }
98
        }
88
 
99
 
89
        lines.push([id, modules]);
100
        lines.push([id, modules]);
90
    }
101
    }
91
 
102
 
92
    var table_lines = create_table(lines);
103
    var table_lines = create_table(lines);
93
 
104
 
94
    Log("\033[29;1m" + table_lines[0] + "\033[0m\n");
105
    Log("\033[29;1m" + table_lines[0] + "\033[0m\n");
95
 
106
 
96
    for (var n = 1; n < table_lines.length; n++)
107
    for (var n = 1; n < table_lines.length; n++)
97
    {
108
    {
98
        Log(table_lines[n] + "\n");
109
        Log(table_lines[n] + "\n");
99
    }
110
    }
100
 
111
 
101
    return true;
112
    return true;
102
}
113
}
103
Console_RegisterCommand(Node_ListAvailable);
114
Console_RegisterCommand(Node_ListAvailable);
104
 
115
 
-
 
116
function Node_ResetPollNative()
-
 
117
{
-
 
118
    return Node_Native_Reset;
-
 
119
}
-
 
120
 
105
function Node_Reset(node_id)
121
function Node_ResetNative(node_id)
106
{
122
{
107
    if (arguments.length < 1)
123
    if (arguments.length < 1)
108
    {
124
    {
-
 
125
        return "\033[31mError: Not enough parameters given.\033[0m";
-
 
126
    }
-
 
127
 
-
 
128
    Node_Native_Reset = false;
-
 
129
    if (!NodeExport_ResetNode(node_id))
-
 
130
    {
-
 
131
        return "\033[31mError: Failed to send reset, this can happen if node only contains bios and it was connected before atom was started/restarted.\033[0m";
-
 
132
    }
-
 
133
 
-
 
134
    Node_ResetClientId = Console_GetClientId();
-
 
135
    Node_ResetNodeId = node_id;
-
 
136
 
-
 
137
    return "Reset command sent successfully";
-
 
138
}
-
 
139
 
-
 
140
function Node_Reset(node_id)
-
 
141
{
-
 
142
    if (arguments.length < 1)
-
 
143
    {
109
        Log("\033[31mNot enough parameters given.\033[0m\n");
144
        Log("\033[31mNot enough parameters given.\033[0m\n");
110
        return false;
145
        return false;
111
    }
146
    }
112
 
147
 
113
    Log("Sending reset to " + node_id + "...\n");
148
    Log("Sending reset to " + node_id + "...\n");
114
 
149
 
115
    if (!NodeExport_ResetNode(node_id))
150
    if (!NodeExport_ResetNode(node_id))
116
    {
151
    {
117
        Log("\033[31mFailed to send reset.\033[0m\n");
152
        Log("\033[31mFailed to send reset, this can happen if node only contains bios and it was connected before atom was started/restarted.\033[0m\n");
118
        return false;
153
        return false;
119
    }
154
    }
120
 
155
 
121
    Node_ProgramClientId = Console_GetClientId();
156
    Node_ResetClientId = Console_GetClientId();
122
    Node_ProgramNodeId = node_id;
157
    Node_ResetNodeId = node_id;
123
    Console_PreventDefaultPrompt();
158
    Console_PreventDefaultPrompt();
124
 
159
 
125
    return true;
160
    return true;
126
}
161
}
127
Console_RegisterCommand(Node_Reset, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
162
Console_RegisterCommand(Node_Reset, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
-
 
163
 
-
 
164
function Node_ProgramPollNative()
-
 
165
{
-
 
166
    return Node_Native_Program;
-
 
167
}
-
 
168
 
-
 
169
function Node_AppendHexNative(hexrow)
-
 
170
{
-
 
171
    if (arguments.length < 1)
-
 
172
    {
-
 
173
        return "\033[31mError: Not enough parameters given.\033[0m";
-
 
174
    }
-
 
175
 
-
 
176
    Node_HexData = Node_HexData + hexrow + "\n";
-
 
177
    Node_HexNumLines += 1;
-
 
178
 
-
 
179
    return true;
-
 
180
}
-
 
181
 
-
 
182
function Node_ProgramNative(node_id, bios, hexnumlines)
-
 
183
{
-
 
184
    if (arguments.length < 3)
-
 
185
    {
-
 
186
        return "\033[31mError: Not enough parameters given.\033[0m";
-
 
187
    }
-
 
188
    if (Node_HexNumLines != hexnumlines)
-
 
189
    {
-
 
190
        return "\033[31mError: Number of hex lines does not match received (" + Node_HexNumLines + " received, should be " + hexnumlines + ").\033[0m";
-
 
191
    }
-
 
192
   
-
 
193
    Node_Native_Program = false;
-
 
194
    if (!NodeExport_ProgramNodeHex(node_id, bios > 0, Node_HexData))
-
 
195
    {
-
 
196
        return "\033[31mError: Failed to start programming, this can happen if node only contains bios and it was connected before atom was started/restarted.\033[0m";
-
 
197
    }
-
 
198
 
-
 
199
    Node_ProgramClientId = Console_GetClientId();
-
 
200
    Node_ProgramNodeId = node_id;
-
 
201
    Node_HexData = "";
-
 
202
    Node_HexNumLines = 0;
-
 
203
 
-
 
204
    return "Program command sent successfully";
-
 
205
}
128
 
206
 
129
function Node_Program(node_id, bios, filename)
207
function Node_Program(node_id, bios, filename)
130
{
208
{
131
    if (arguments.length < 3)
209
    if (arguments.length < 3)
132
    {
210
    {
133
        Log("\033[31mNot enough parameters given.\033[0m\n");
211
        Log("\033[31mNot enough parameters given.\033[0m\n");
134
        return false;
212
        return false;
135
    }
213
    }
136
 
214
 
137
    Log("Initiating programming of " + node_id + "...\n");
215
    Log("Initiating programming of " + node_id + "...\n");
138
 
216
 
139
    if (!NodeExport_ProgramNode(node_id, bios > 0, filename))
217
    if (!NodeExport_ProgramNode(node_id, bios > 0, filename))
140
    {
218
    {
141
        Log("\033[31mFailed to start programming.\033[0m\n");
219
        Log("\033[31mFailed to start programming, this can happen if node only contains bios and it was connected before atom was started/restarted.\033[0m\n");
142
        return false;
220
        return false;
143
    }
221
    }
144
 
222
 
145
    Node_ResetClientId = Console_GetClientId();
223
    Node_ProgramClientId = Console_GetClientId();
146
    Node_ResetNodeId = node_id;
224
    Node_ProgramNodeId = node_id;
147
    Console_PreventDefaultPrompt();
225
    Console_PreventDefaultPrompt();
148
 
226
 
149
    return true;
227
    return true;
150
}
228
}
151
Console_RegisterCommand(Node_Program, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds(), [0, 1]); });
229
Console_RegisterCommand(Node_Program, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds(), [0, 1]); });
152
 
230
 
153
function Node_ProgramHex(node_id, bios, hexnumlines)
231
function Node_ProgramHex(node_id, bios, hexnumlines)
154
{
232
{
155
    if (arguments.length < 2)
233
    if (arguments.length < 2)
156
    {
234
    {
157
        Log("\033[31mNot enough parameters given.\033[0m\n");
235
        Log("\033[31mNot enough parameters given.\033[0m\n");
158
        return false;
236
        return false;
159
    }
237
    }
160
    if (Node_HexNumLines != hexnumlines)
238
    if (Node_HexNumLines != hexnumlines)
161
    {
239
    {
162
        Log("\033[31mNumber of hex lines does not match received (" + Node_HexNumLines + " received, should be " + hexnumlines + ").\033[0m\n");
240
        Log("\033[31mNumber of hex lines does not match received (" + Node_HexNumLines + " received, should be " + hexnumlines + ").\033[0m\n");
163
        return false;
241
        return false;
164
    }
242
    }
165
 
243
 
166
    Log("Initiating programming of " + node_id + "...\n");
244
    Log("Initiating programming of " + node_id + "...\n");
167
 
245
 
168
    if (!NodeExport_ProgramNodeHex(node_id, bios > 0, Node_HexData))
246
    if (!NodeExport_ProgramNodeHex(node_id, bios > 0, Node_HexData))
169
    {
247
    {
170
        Log("\033[31mFailed to start programming.\033[0m\n");
248
        Log("\033[31mFailed to start programming, this can happen if node only contains bios and it was connected before atom was started/restarted.\033[0m\n");
171
        return false;
249
        return false;
172
    }
250
    }
173
 
251
 
174
    Node_ResetClientId = Console_GetClientId();
252
    Node_ProgramClientId = Console_GetClientId();
175
    Node_ResetNodeId = node_id;
253
    Node_ProgramNodeId = node_id;
176
    Console_PreventDefaultPrompt();
254
    Console_PreventDefaultPrompt();
177
 
255
 
178
    Node_HexData = "";
256
    Node_HexData = "";
179
    Node_HexNumLines = 0;
257
    Node_HexNumLines = 0;
180
 
258
 
181
 
259
 
182
    return true;
260
    return true;
183
}
261
}
184
Console_RegisterCommand(Node_ProgramHex, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds(), [0, 1]); });
262
Console_RegisterCommand(Node_ProgramHex, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds(), [0, 1]); });
185
 
263
 
186
function Node_ClearHex()
264
function Node_ClearHex()
187
{
265
{
188
//    Log("Clearing hexdata...\n");
266
//    Log("Clearing hexdata...\n");
189
 
267
 
190
    Node_HexData = "";
268
    Node_HexData = "";
191
    Node_HexNumLines = 0;
269
    Node_HexNumLines = 0;
192
 
270
 
193
    return true;
271
    return true;
194
}
272
}
195
Console_RegisterCommand(Node_ClearHex);
273
Console_RegisterCommand(Node_ClearHex);
196
 
274
 
197
function Node_AppendHex(hexrow)
275
function Node_AppendHex(hexrow)
198
{
276
{
199
    if (arguments.length < 1)
277
    if (arguments.length < 1)
200
    {
278
    {
201
        Log("\033[31mNot enough parameters given.\033[0m\n");
279
        Log("\033[31mNot enough parameters given.\033[0m\n");
202
        return false;
280
        return false;
203
    }
281
    }
204
 
282
 
205
//    Log("Appending hexrow...\n");
283
//    Log("Appending hexrow...\n");
206
 
284
 
207
    Node_HexData = Node_HexData + hexrow + "\n";
285
    Node_HexData = Node_HexData + hexrow + "\n";
208
    Node_HexNumLines += 1;
286
    Node_HexNumLines += 1;
209
 
287
 
210
    return true;
288
    return true;
211
}
289
}
212
Console_RegisterCommand(Node_AppendHex);
290
Console_RegisterCommand(Node_AppendHex);
213
 
291
 
214
function Node_GetInformation(node_id)
292
function Node_GetInformation(node_id)
215
{
293
{
216
    if (arguments.length < 1)
294
    if (arguments.length < 1)
217
    {
295
    {
218
        Log("\033[31mNot enough parameters given.\033[0m\n");
296
        Log("\033[31mNot enough parameters given.\033[0m\n");
219
        return false;
297
        return false;
220
    }
298
    }
221
 
299
 
222
    var result = NodeExport_GetNodeInformation(node_id);
300
    var result = NodeExport_GetNodeInformation(node_id);
223
 
301
 
224
    if (!result)
302
    if (!result)
225
    {
303
    {
226
        Log("\033[31mNo node with id " + node_id + " found.\033[0m\n");
304
        Log("\033[31mNo node with id " + node_id + " found.\033[0m\n");
227
        return false;
305
        return false;
228
    }
306
    }
229
 
307
 
230
    var date = new Date(result["LastActive"] * 1000);
308
    var date = new Date(result["LastActive"] * 1000);
231
 
309
 
232
    Log("\033[96mId: \033[0;1m" + result["Id"] + "\033[0m\n");
310
    Log("\033[96mId: \033[0;1m" + result["Id"] + "\033[0m\n");
233
    Log("\033[96mValid: \033[0;1m" + result["Valid"] + "\033[0m\n");
311
    Log("\033[96mValid: \033[0;1m" + result["Valid"] + "\033[0m\n");
234
    Log("\033[96mBios Version: \033[0;1m" + result["BiosVersion"] + "\033[0m\n");
312
    Log("\033[96mBios Version: \033[0;1m" + result["BiosVersion"] + "\033[0m\n");
235
    Log("\033[96mDevice Type: \033[0;1m" + result["DeviceType"] + "\033[0m\n");
313
    Log("\033[96mDevice Type: \033[0;1m" + result["DeviceType"] + "\033[0m\n");
236
    Log("\033[96mHas Application: \033[0;1m" + result["HasApplication"] + "\033[0m\n");
314
    Log("\033[96mHas Application: \033[0;1m" + result["HasApplication"] + "\033[0m\n");
237
    Log("\033[96mLast Active: \033[0;1m" + date.toString() + "\033[0m\n");
315
    Log("\033[96mLast Active: \033[0;1m" + date.toString() + "\033[0m\n");
238
 
316
 
239
    return true;
317
    return true;
240
}
318
}
241
Console_RegisterCommand(Node_GetInformation, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
319
Console_RegisterCommand(Node_GetInformation, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
242
 
320
 
243
function Node_WaitForInformation()
321
function Node_WaitForInformation()
244
{
322
{
245
    Node_WaitClientId = Console_GetClientId();
323
    Node_WaitClientId = Console_GetClientId();
246
    Console_PreventDefaultPrompt();
324
    Console_PreventDefaultPrompt();
247
 
325
 
248
    return true;
326
    return true;
249
}
327
}
250
Console_RegisterCommand(Node_WaitForInformation);
328
Console_RegisterCommand(Node_WaitForInformation);
251
 
329