Subversion Repositories HomeAutomation

Rev

Rev 2083 | Rev 2162 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 2083 Rev 2160
Line 4... Line 4...
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);
Line 62... Line 73...
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