Subversion Repositories HomeAutomation

Rev

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