Subversion Repositories HomeAutomation

Rev

Rev 2162 | Rev 2170 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

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