Subversion Repositories HomeAutomation

Rev

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

Rev 1666 Rev 1669
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
 
-
 
8
Node_WaitClientId = null;
7
 
9
 
8
function Node_OnChange(node_id, available)
10
function Node_OnChange(node_id, available)
9
{
11
{
10
    if (node_id == Node_ResetNodeId && available)
12
    if (node_id == Node_ResetNodeId && available)
11
    {
13
    {
12
        Console_LogToClient(Node_ResetClientId, "\033[32m" + Node_ResetNodeId + " started okay.\033[0m\n");
14
        Console_LogToClient(Node_ResetClientId, "\033[32m" + Node_ResetNodeId + " started okay.\033[0m\n");
13
        Node_ResetNodeId = null;
15
        Node_ResetNodeId = null;
14
        Node_ResetClientId = null;
16
        Node_ResetClientId = null;
15
        Console_SetDefaultPrompt();
17
        Console_SetDefaultPrompt();
16
    }
18
    }
17
   
19
   
18
    if (node_id == Node_ProgramNodeId && available)
20
    if (node_id == Node_ProgramNodeId && available)
19
    {
21
    {
20
        Console_LogToClient(Node_ProgramClientId, "\033[32m" + Node_ProgramNodeId + " started okay.\033[0m\n");
22
        Console_LogToClient(Node_ProgramClientId, "\033[32m" + Node_ProgramNodeId + " started okay.\033[0m\n");
21
        Node_ProgramNodeId = null;
23
        Node_ProgramNodeId = null;
22
        Node_ProgramClientId = null;
24
        Node_ProgramClientId = null;
23
        Console_SetDefaultPrompt();
25
        Console_SetDefaultPrompt();
-
 
26
    }
-
 
27
   
-
 
28
    if (Node_WaitClientId != null && available)
-
 
29
    {    
-
 
30
        var result = NodeExport_GetNodeInformation(node_id);
-
 
31
   
-
 
32
        if (!result)
-
 
33
        {
-
 
34
            Console_LogToClient(Node_WaitClientId, "\033[31mNo node with id " + node_id + " found.\033[0m\n");
-
 
35
            return false;
-
 
36
        }
-
 
37
       
-
 
38
        var date = new Date(result["LastActive"] * 1000);
-
 
39
       
-
 
40
        Console_LogToClient(Node_WaitClientId, "Id: " + result["Id"] + "\n");
-
 
41
        Console_LogToClient(Node_WaitClientId, "Valid: " + result["Valid"] + "\n");
-
 
42
        Console_LogToClient(Node_WaitClientId, "Bios Version: " + result["BiosVersion"] + "\n");
-
 
43
        Console_LogToClient(Node_WaitClientId, "Device Type: " + result["DeviceType"] + "\n");
-
 
44
        Console_LogToClient(Node_WaitClientId, "Has Application: " + result["HasApplication"] + "\n");
-
 
45
        Console_LogToClient(Node_WaitClientId, "Last Active: " + date.toString() + "\n");
-
 
46
       
-
 
47
        Node_WaitClientId = null;
-
 
48
        Console_SetDefaultPrompt();
24
    }
49
    }
25
}
50
}
26
 
51
 
27
function Node_GetAvailableIds()
52
function Node_GetAvailableIds()
28
{
53
{
29
    var result_list = [];
54
    var result_list = [];
30
    var available_nodes = NodeExport_GetAvailableNodes();
55
    var available_nodes = NodeExport_GetAvailableNodes();
31
   
56
   
32
    for (var n in available_nodes)
57
    for (var n in available_nodes)
33
    {
58
    {
34
        var id_parts = available_nodes[n].split(",", 2);
59
        var id_parts = available_nodes[n].split(",", 2);
35
       
60
       
36
        result_list.push(id_parts[0]);
61
        result_list.push(id_parts[0]);
37
    }
62
    }
38
   
63
   
39
    return result_list;
64
    return result_list;
40
}
65
}
41
 
66
 
42
function Node_ListAvailable()
67
function Node_ListAvailable()
43
{
68
{
44
    var available_nodes = NodeExport_GetAvailableNodes();
69
    var available_nodes = NodeExport_GetAvailableNodes();
45
   
70
   
46
    var lines = [["Id", "Modules"]];
71
    var lines = [["Id", "Modules"]];
47
   
72
   
48
    for (var n in available_nodes)
73
    for (var n in available_nodes)
49
    {
74
    {
50
        var parts = available_nodes[n].split(",");
75
        var parts = available_nodes[n].split(",");
51
        var id = parts.shift();
76
        var id = parts.shift();
52
        var modules = "<none>";
77
        var modules = "<none>";
53
       
78
       
54
        if (parts.length > 0)
79
        if (parts.length > 0)
55
        {
80
        {
56
            modules = parts.join(", ");
81
            modules = parts.join(", ");
57
        }
82
        }
58
       
83
       
59
        lines.push([id, modules]);
84
        lines.push([id, modules]);
60
    }
85
    }
61
   
86
   
62
    var table_lines = create_table(lines);
87
    var table_lines = create_table(lines);
63
   
88
   
64
    Log("\033[29;1m" + table_lines[0] + "\033[0m\n");
89
    Log("\033[29;1m" + table_lines[0] + "\033[0m\n");
65
   
90
   
66
    for (var n = 1; n < table_lines.length; n++)
91
    for (var n = 1; n < table_lines.length; n++)
67
    {
92
    {
68
        Log(table_lines[n] + "\n");
93
        Log(table_lines[n] + "\n");
69
    }
94
    }
70
   
95
   
71
    return true;
96
    return true;
72
}
97
}
73
Console_RegisterCommand(Node_ListAvailable);
98
Console_RegisterCommand(Node_ListAvailable);
74
 
99
 
75
function Node_Reset(node_id)
100
function Node_Reset(node_id)
76
{
101
{
77
    if (arguments.length < 1)
102
    if (arguments.length < 1)
78
    {
103
    {
79
        Log("\033[31mNot enough parameters given.\033[0m\n");
104
        Log("\033[31mNot enough parameters given.\033[0m\n");
80
        return false;
105
        return false;
81
    }
106
    }
82
   
107
   
83
    Log("Sending reset to " + node_id + "...\n");
108
    Log("Sending reset to " + node_id + "...\n");
84
   
109
   
85
    if (!NodeExport_ResetNode(node_id))
110
    if (!NodeExport_ResetNode(node_id))
86
    {
111
    {
87
        Log("\033[31mFailed to send reset.\033[0m\n");
112
        Log("\033[31mFailed to send reset.\033[0m\n");
88
        return false;
113
        return false;
89
    }
114
    }
90
   
115
   
91
    Node_ProgramClientId = Console_GetClientId();
116
    Node_ProgramClientId = Console_GetClientId();
92
    Node_ProgramNodeId = node_id;
117
    Node_ProgramNodeId = node_id;
93
    Console_PreventDefaultPrompt();
118
    Console_PreventDefaultPrompt();
94
 
119
 
95
    return true;
120
    return true;
96
}
121
}
97
Console_RegisterCommand(Node_Reset, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
122
Console_RegisterCommand(Node_Reset, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
98
 
123
 
99
function Node_Program(node_id, bios, filename)
124
function Node_Program(node_id, bios, filename)
100
{
125
{
101
    if (arguments.length < 3)
126
    if (arguments.length < 3)
102
    {
127
    {
103
        Log("\033[31mNot enough parameters given.\033[0m\n");
128
        Log("\033[31mNot enough parameters given.\033[0m\n");
104
        return false;
129
        return false;
105
    }
130
    }
106
   
131
   
107
    Log("Initiating programming of " + node_id + "...\n");
132
    Log("Initiating programming of " + node_id + "...\n");
108
   
133
   
109
    if (!NodeExport_ProgramNode(node_id, bios > 0, filename))
134
    if (!NodeExport_ProgramNode(node_id, bios > 0, filename))
110
    {
135
    {
111
        Log("\033[31mFailed to start programming.\033[0m\n");
136
        Log("\033[31mFailed to start programming.\033[0m\n");
112
        return false;
137
        return false;
113
    }
138
    }
114
   
139
   
115
    Node_ResetClientId = Console_GetClientId();
140
    Node_ResetClientId = Console_GetClientId();
116
    Node_ResetNodeId = node_id;
141
    Node_ResetNodeId = node_id;
117
    Console_PreventDefaultPrompt();
142
    Console_PreventDefaultPrompt();
118
   
143
   
119
    return true;
144
    return true;
120
}
145
}
121
Console_RegisterCommand(Node_Program, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds(), [0, 1]); });
146
Console_RegisterCommand(Node_Program, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds(), [0, 1]); });
122
 
147
 
123
function Node_GetInformation(node_id)
148
function Node_GetInformation(node_id)
124
{
149
{
125
    if (arguments.length < 1)
150
    if (arguments.length < 1)
126
    {
151
    {
127
        Log("\033[31mNot enough parameters given.\033[0m\n");
152
        Log("\033[31mNot enough parameters given.\033[0m\n");
128
        return false;
153
        return false;
129
    }
154
    }
130
   
155
   
131
    var result = NodeExport_GetNodeInformation(node_id);
156
    var result = NodeExport_GetNodeInformation(node_id);
132
   
157
   
133
    if (!result)
158
    if (!result)
134
    {
159
    {
135
        Log("\033[31mNo node with id " + node_id + " found.\033[0m\n");
160
        Log("\033[31mNo node with id " + node_id + " found.\033[0m\n");
136
        return false;
161
        return false;
137
    }
162
    }
138
   
163
   
139
    var date = new Date(result["LastActive"] * 1000);
164
    var date = new Date(result["LastActive"] * 1000);
140
   
165
   
141
    Log("Id: " + result["Id"] + "\n");
166
    Log("Id: " + result["Id"] + "\n");
142
    Log("Valid: " + result["Valid"] + "\n");
167
    Log("Valid: " + result["Valid"] + "\n");
143
    Log("BiosVersion: " + result["BiosVersion"] + "\n");
168
    Log("Bios Version: " + result["BiosVersion"] + "\n");
144
    Log("DeviceType: " + result["DeviceType"] + "\n");
169
    Log("Device Type: " + result["DeviceType"] + "\n");
145
    Log("HasApplication: " + result["HasApplication"] + "\n");
170
    Log("Has Application: " + result["HasApplication"] + "\n");
146
    Log("LastActive: " + date.toString() + "\n");
171
    Log("Last Active: " + date.toString() + "\n");
147
   
172
   
148
    return true;
173
    return true;
149
}
174
}
150
Console_RegisterCommand(Node_GetInformation, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
175
Console_RegisterCommand(Node_GetInformation, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Node_GetAvailableIds()); });
-
 
176
 
-
 
177
function Node_WaitForInformation()
-
 
178
{
-
 
179
    Node_WaitClientId = Console_GetClientId();
-
 
180
    Console_PreventDefaultPrompt();
-
 
181
   
-
 
182
    return true;
-
 
183
}
-
 
184
Console_RegisterCommand(Node_WaitForInformation);
151
 
185