Subversion Repositories HomeAutomation

Rev

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

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