Subversion Repositories HomeAutomation

Rev

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

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