Subversion Repositories HomeAutomation

Rev

Rev 1066 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
999 runge 1
 
2
function quit()
3
{
4
    if (ClientId)
5
    {
6
        _quit(ClientId);
7
    }
8
}
9
 
10
function print(text)
11
{
12
    if (ClientId)
13
    {
14
        _print(ClientId, text);
15
    }
16
    else
17
    {
18
        log(text);
19
    }
20
}
21
 
1008 runge 22
function printTo(clientId, text)
23
{
1009 runge 24
    _print(clientId, text);
1008 runge 25
}
26
 
999 runge 27
function services()
28
{
29
    var list = new Array();
30
 
31
    var row = new Array();
32
 
33
    row[row.length] = "Type";
34
    row[row.length] = "Name";
35
    row[row.length] = "Id";
36
    row[row.length] = "Online";
37
 
38
    list[list.length] = row;
39
 
40
    for (var n in ServiceManager.Services)
41
    {
42
        var row = new Array();
43
 
44
        row[row.length] = ServiceManager.Services[n].getType();
45
        row[row.length] = ServiceManager.Services[n].getName();
46
        row[row.length] = ServiceManager.Services[n].getId();
1008 runge 47
        if (ServiceManager.Services[n].getType() == "Can")
1007 runge 48
        {
49
            row[row.length] = ServiceManager.Services[n].isOnline();
50
        }
51
        else
52
        {
53
            row[row.length] = "";
54
        }
999 runge 55
 
56
        list[list.length] = row;
57
    }
58
 
59
    var lines = TextTable.create(list);
60
 
61
    for (var n in lines)
62
    {
63
        print(lines[n] + "\n");
64
    }
65
}
66
 
67
function getService(id, name)
68
{
69
    var fullId = name + id;
70
 
71
    if (!ServiceManager.Services[fullId])
72
    {
73
        print("No such service found.\n");
74
    }
75
 
76
    return ServiceManager.Services[fullId];
77
}
1008 runge 78
 
1040 runge 79
function ethStart()
80
{
81
    var canMessage = new CanNMTMessage("nmt", "Time");
82
    canMessage.send();
83
}
84
 
1028 arune 85
function resetNode(hardwareId)
86
{
87
    ProgrammingClientId = ClientId;
88
 
89
    if (hardwareId.length > 2)
90
    {
91
        if (hardwareId.substr(0,2)=="0x")
92
        {
93
            hardwareId = hex2uint(hardwareId.substring(2,hardwareId.length));
94
        }
95
    }
96
 
97
    var node = CanNodes[hardwareId];
98
 
99
    if (!node)
100
    {
1067 arune 101
        //printTo(ProgrammingClientId, "STOP: Failed. No node is online that has that hardware id, " + hardwareId + "\n");
102
        //log("A can node with hardware id " + uint2hex(canMessage.getData("HardwareId"), 32) + " was not found, starting.\n");
103
 
104
        /* As a node with this hardware id has not been seen it could just be that it was started before atom and has no application installed */
105
        node = new CanNode(hardwareId, null);
106
        CanNodes[hardwareId] = node;
107
        //return;
1028 arune 108
    }
1040 runge 109
 
110
    node.reset( function(status)
111
            {
112
                if (status)
113
                {
1066 arune 114
                    printTo(ProgrammingClientId, "STOP: Success: Node reset and bios started okay.\n");
1040 runge 115
                }
116
                else
117
                {
1066 arune 118
                    printTo(ProgrammingClientId, "STOP: Failed. Node did not respond failed.\n");
1040 runge 119
                }
120
            });
1028 arune 121
}
122
 
1008 runge 123
var ProgrammingClientId = null;
124
 
1034 arune 125
function programNodeCallback(status, event, text, raw)
1008 runge 126
{
1034 arune 127
    if (raw)
128
    {
129
        printTo(ProgrammingClientId, text);
130
    }
131
    else
132
    {
133
        printTo(ProgrammingClientId, event + ": " + text + "\n");
134
    }
1008 runge 135
}
136
 
137
function programNode(hardwareId, hexData, bios)
138
{
139
    ProgrammingClientId = ClientId;
140
 
1013 arune 141
    if (hardwareId.length > 2)
142
    {
143
        if (hardwareId.substr(0,2)=="0x")
144
        {
145
            hardwareId = hex2uint(hardwareId.substring(2,hardwareId.length));
146
        }
147
    }
148
 
1008 runge 149
    var node = CanNodes[hardwareId];
1013 arune 150
 
1008 runge 151
    if (!node)
152
    {
1067 arune 153
        //print("STOP: Failed. No node is online that has that hardware id, " + hardwareId + "\n");
154
        //return;
155
        /* As a node with this hardware id has not been seen it could just be that it was started before atom and has no application installed */
156
        node = new CanNode(hardwareId, null);
157
        CanNodes[hardwareId] = node;
1008 runge 158
    }
1013 arune 159
 
1008 runge 160
    hexData = unescape(hexData);
1013 arune 161
 
1008 runge 162
    if (hexData)
163
    {
164
        var hexLinesOrg = hexData.split('\n');
165
        var hexLines = new Array();
1013 arune 166
 
1008 runge 167
        for (var n = 0; n < hexLinesOrg.length; n++)
168
        {
169
            var line = hexLinesOrg[n].trim(' ');
1013 arune 170
 
1008 runge 171
            if (line != "")
172
            {
173
                hexLines[hexLines.length] = line;
174
            }
175
        }
1013 arune 176
 
177
        var hexObj = new IntelHex(hexLines);
178
        if (hexObj.isValid()) {
179
            node.startProgramming(hexObj, programNodeCallback, bios);
180
        }
1063 arune 181
        else
182
        {
1066 arune 183
            print("STOP: Failed. Invalid hexfile\n");
1063 arune 184
        }
1008 runge 185
    }
186
    else
187
    {
1013 arune 188
        //print("File was not found, " + hexFilename + "\n");
1008 runge 189
    }
190
}
1060 runge 191
 
1061 runge 192
function p(time, button)
1060 runge 193
{
194
    var t = ServiceManager.getService("CAN", "irTransmit", 1);
1061 runge 195
    t.sendClick('KiSS_DP-1500_Remote', button, time);
1060 runge 196
}