Subversion Repositories HomeAutomation

Rev

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