Subversion Repositories HomeAutomation

Rev

Rev 2083 | Rev 2162 | 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;
12
//Node_Native_WaitNodeId = null;
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
{
2160 arune 19
Log("Node_OnChange "+Node_ResetNodeId+" "+Node_ProgramNodeId+" "+node_id+" "+available+"\n");
1657 runge 20
    if (node_id == Node_ResetNodeId && available)
21
    {
2160 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
    {
2160 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);
2083 runge 47
 
1669 runge 48
        if (!result)
49
        {
50
            Console_LogToClient(Node_WaitClientId, "\033[31mNo node with id " + node_id + " found.\033[0m\n");
51
            return false;
52
        }
2083 runge 53
 
1669 runge 54
        var date = new Date(result["LastActive"] * 1000);
2083 runge 55
 
1669 runge 56
        Console_LogToClient(Node_WaitClientId, "Id: " + result["Id"] + "\n");
57
        Console_LogToClient(Node_WaitClientId, "Valid: " + result["Valid"] + "\n");
58
        Console_LogToClient(Node_WaitClientId, "Bios Version: " + result["BiosVersion"] + "\n");
59
        Console_LogToClient(Node_WaitClientId, "Device Type: " + result["DeviceType"] + "\n");
60
        Console_LogToClient(Node_WaitClientId, "Has Application: " + result["HasApplication"] + "\n");
61
        Console_LogToClient(Node_WaitClientId, "Last Active: " + date.toString() + "\n");
2083 runge 62
 
63
        Console_NewConnection(Node_WaitClientId); // This is a ugly hack for a bad design for multiusers
1669 runge 64
        Node_WaitClientId = null;
65
    }
1657 runge 66
}
67
 
68
function Node_GetAvailableIds()
69
{
70
    var result_list = [];
71
    var available_nodes = NodeExport_GetAvailableNodes();
2083 runge 72
 
1657 runge 73
    for (var n in available_nodes)
74
    {
75
        var id_parts = available_nodes[n].split(",", 2);
2083 runge 76
 
1657 runge 77
        result_list.push(id_parts[0]);
78
    }
2083 runge 79
 
1657 runge 80
    return result_list;
81
}
82
 
83
function Node_ListAvailable()
84
{
85
    var available_nodes = NodeExport_GetAvailableNodes();
2083 runge 86
 
1660 runge 87
    var lines = [["Id", "Modules"]];
2083 runge 88
 
1657 runge 89
    for (var n in available_nodes)
90
    {
1660 runge 91
        var parts = available_nodes[n].split(",");
92
        var id = parts.shift();
93
        var modules = "<none>";
2083 runge 94
 
1660 runge 95
        if (parts.length > 0)
1657 runge 96
        {
1660 runge 97
            modules = parts.join(", ");
1657 runge 98
        }
2083 runge 99
 
1660 runge 100
        lines.push([id, modules]);
1657 runge 101
    }
2083 runge 102
 
1660 runge 103
    var table_lines = create_table(lines);
2083 runge 104
 
1660 runge 105
    Log("\033[29;1m" + table_lines[0] + "\033[0m\n");
2083 runge 106
 
1660 runge 107
    for (var n = 1; n < table_lines.length; n++)
108
    {
109
        Log(table_lines[n] + "\n");
110
    }
2083 runge 111
 
1657 runge 112
    return true;
113
}
114
Console_RegisterCommand(Node_ListAvailable);
115
 
2160 arune 116
function Node_ResetPollNative()
117
{
118
    return Node_Native_Reset;
119
}
120
 
121
function Node_ResetNative(node_id)
122
{
123
    if (arguments.length < 1)
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
 
1657 runge 140
function Node_Reset(node_id)
141
{
142
    if (arguments.length < 1)
143
    {
144
        Log("\033[31mNot enough parameters given.\033[0m\n");
145
        return false;
146
    }
2083 runge 147
 
1665 runge 148
    Log("Sending reset to " + node_id + "...\n");
2083 runge 149
 
1657 runge 150
    if (!NodeExport_ResetNode(node_id))
151
    {
2160 arune 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");
1657 runge 153
        return false;
154
    }
2083 runge 155
 
2160 arune 156
    Node_ResetClientId = Console_GetClientId();
157
    Node_ResetNodeId = node_id;
1657 runge 158
    Console_PreventDefaultPrompt();
159
 
160
    return true;
161
}
162
Console_RegisterCommand(Node_Reset, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
1665 runge 163
 
2160 arune 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
}
206
 
1666 runge 207
function Node_Program(node_id, bios, filename)
208
{
209
    if (arguments.length < 3)
210
    {
211
        Log("\033[31mNot enough parameters given.\033[0m\n");
212
        return false;
213
    }
2083 runge 214
 
1666 runge 215
    Log("Initiating programming of " + node_id + "...\n");
2083 runge 216
 
1666 runge 217
    if (!NodeExport_ProgramNode(node_id, bios > 0, filename))
218
    {
2160 arune 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");
1666 runge 220
        return false;
221
    }
2083 runge 222
 
2160 arune 223
    Node_ProgramClientId = Console_GetClientId();
224
    Node_ProgramNodeId = node_id;
1666 runge 225
    Console_PreventDefaultPrompt();
2083 runge 226
 
1666 runge 227
    return true;
228
}
229
Console_RegisterCommand(Node_Program, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds(), [0, 1]); });
230
 
1968 arune 231
function Node_ProgramHex(node_id, bios, hexnumlines)
1887 arune 232
{
233
    if (arguments.length < 2)
234
    {
235
        Log("\033[31mNot enough parameters given.\033[0m\n");
236
        return false;
237
    }
1968 arune 238
    if (Node_HexNumLines != hexnumlines)
239
    {
240
        Log("\033[31mNumber of hex lines does not match received (" + Node_HexNumLines + " received, should be " + hexnumlines + ").\033[0m\n");
241
        return false;
242
    }
2083 runge 243
 
1887 arune 244
    Log("Initiating programming of " + node_id + "...\n");
2083 runge 245
 
1887 arune 246
    if (!NodeExport_ProgramNodeHex(node_id, bios > 0, Node_HexData))
247
    {
2160 arune 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");
1887 arune 249
        return false;
250
    }
2083 runge 251
 
2160 arune 252
    Node_ProgramClientId = Console_GetClientId();
253
    Node_ProgramNodeId = node_id;
1887 arune 254
    Console_PreventDefaultPrompt();
255
 
256
    Node_HexData = "";
1968 arune 257
    Node_HexNumLines = 0;
1887 arune 258
 
1968 arune 259
 
1887 arune 260
    return true;
261
}
262
Console_RegisterCommand(Node_ProgramHex, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds(), [0, 1]); });
263
 
264
function Node_ClearHex()
265
{
1889 arune 266
//    Log("Clearing hexdata...\n");
2083 runge 267
 
1887 arune 268
    Node_HexData = "";
1968 arune 269
    Node_HexNumLines = 0;
1889 arune 270
 
1887 arune 271
    return true;
272
}
273
Console_RegisterCommand(Node_ClearHex);
274
 
275
function Node_AppendHex(hexrow)
276
{
277
    if (arguments.length < 1)
278
    {
279
        Log("\033[31mNot enough parameters given.\033[0m\n");
280
        return false;
281
    }
2083 runge 282
 
1889 arune 283
//    Log("Appending hexrow...\n");
2083 runge 284
 
1887 arune 285
    Node_HexData = Node_HexData + hexrow + "\n";
1968 arune 286
    Node_HexNumLines += 1;
1889 arune 287
 
1887 arune 288
    return true;
289
}
290
Console_RegisterCommand(Node_AppendHex);
291
 
1665 runge 292
function Node_GetInformation(node_id)
293
{
294
    if (arguments.length < 1)
295
    {
296
        Log("\033[31mNot enough parameters given.\033[0m\n");
297
        return false;
298
    }
2083 runge 299
 
1665 runge 300
    var result = NodeExport_GetNodeInformation(node_id);
2083 runge 301
 
1665 runge 302
    if (!result)
303
    {
304
        Log("\033[31mNo node with id " + node_id + " found.\033[0m\n");
305
        return false;
306
    }
2083 runge 307
 
1665 runge 308
    var date = new Date(result["LastActive"] * 1000);
2083 runge 309
 
1673 runge 310
    Log("\033[96mId: \033[0;1m" + result["Id"] + "\033[0m\n");
311
    Log("\033[96mValid: \033[0;1m" + result["Valid"] + "\033[0m\n");
312
    Log("\033[96mBios Version: \033[0;1m" + result["BiosVersion"] + "\033[0m\n");
313
    Log("\033[96mDevice Type: \033[0;1m" + result["DeviceType"] + "\033[0m\n");
314
    Log("\033[96mHas Application: \033[0;1m" + result["HasApplication"] + "\033[0m\n");
315
    Log("\033[96mLast Active: \033[0;1m" + date.toString() + "\033[0m\n");
2083 runge 316
 
1665 runge 317
    return true;
318
}
319
Console_RegisterCommand(Node_GetInformation, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
1669 runge 320
 
321
function Node_WaitForInformation()
322
{
323
    Node_WaitClientId = Console_GetClientId();
324
    Console_PreventDefaultPrompt();
2083 runge 325
 
1669 runge 326
    return true;
327
}
328
Console_RegisterCommand(Node_WaitForInformation);