Subversion Repositories HomeAutomation

Rev

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

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