Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1728 cougar 1
 
2
function counter(type, name, id)
3
{
4
    this.CanService(type, name, id);
5
 
6
    this.myLastValue = new Array();
7
}
8
 
9
extend(counter, CanService);
10
 
11
counter.prototype.myReportInterval = null;
12
counter.prototype.myLastValue = null;
13
 
14
counter.prototype.canMessageHandler = function(canMessage)
15
{
16
    if (canMessage.getDirectionFlag() == "From_Owner")
17
    {
18
        switch (canMessage.getCommandName())
19
        {
20
        case "Counter":
21
        //log(this.myName + ":" + this.myId + "> PinId : " + canMessage.getData("PinId") + " New value: " + canMessage.getData("Count") + "\n");
22
        this.myLastValue[canMessage.getData("PinId")] = canMessage.getData("Count");
23
        this.callEvent("newValue");
24
        break;
25
 
26
        case "Report_Interval":
27
        //log(this.myName + ":" + this.myId + "> PinId : " + canMessage.getData("PinId") + " New report interval: " + canMessage.getData("Time") + "\n");
28
        this.myReportInterval = canMessage.getData("Time");
29
        break;
30
 
31
        case "setCounter":
32
        //log(this.myName + ":" + this.myId + "> PinId : " + canMessage.getData("PinId") + " New count stored: " + canMessage.getData("Count") + "\n");
33
        break;
34
        }
35
    }
36
 
37
    this.CanService.prototype.canMessageHandler.call(this, canMessage);
38
}
39
 
40
counter.prototype.getCount = function()
41
{
42
    return this.myLastValueCount;
43
}
44
counter.prototype.setCount = function(id, count)
45
{
46
    var canMessage = new CanMessage("sns", "To_Owner", this.myName, this.myId, "setCounter");
47
    canMessage.setData("PinId", id);
48
    canMessage.setData("Count", count);
49
    sendMessage(canMessage);
50
}
51
 
52
counter.prototype.setReportInterval = function(time)
53
{
54
    var canMessage = new CanMessage("sns", "To_Owner", this.myName, this.myId, "Report_Interval");
55
    canMessage.setData("Time", time);
56
    sendMessage(canMessage);
57
}