Subversion Repositories HomeAutomation

Rev

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

Rev Author Line No. Line
1927 arune 1
 
2
 
3
function rfTransceive(type, name, id)
4
{
5
    this.CanService(type, name, id);
6
}
7
 
8
extend(rfTransceive, CanService);
9
 
10
rfTransceive.prototype.canMessageHandler = function(canMessage)
11
{
12
    /*if (canMessage.getDirectionFlag() == "From_Owner")
13
    {
14
        switch (canMessage.getCommandName())
15
        {
16
        case "IR":
17
        break;
18
        }
19
    }*/
20
 
21
    this.CanService.prototype.canMessageHandler.call(this, canMessage);
22
}
23
 
24
rfTransceive.prototype.sendClick = function(channel, remoteName, buttonName, time)
25
{
26
    this.sendButton(channel, remoteName, buttonName, true);
27
 
28
    if (time)
29
    {
30
        sleep(time);
31
    }
32
    else
33
    {
34
        sleep(50000);
35
    }
36
 
37
    this.sendButton(channel, remoteName, buttonName, false);
38
}
39
 
40
rfTransceive.prototype.sendButton = function(channel, remoteName, buttonName, down)
41
{
42
    var remotesStore = DataStore.getStore("IRRemotes");
43
 
44
    if (remotesStore)
45
    {
46
        for (var n = 0; n < remotesStore['remotes'].length; n++)
47
        {
48
            if (remotesStore['remotes'][n]['name'] == remoteName)
49
            {
50
                for (var code in remotesStore['remotes'][n]['codes'])
51
                {
52
                    if (remotesStore['remotes'][n]['codes'][code] == buttonName)
53
                    {
54
                        this.sendData(channel, remotesStore['remotes'][n]['protocol'], code, down ? "Pressed" : "Released");
55
                        return;
56
                    }
57
                }
58
            }
59
        }
60
    }
61
}
62
 
63
rfTransceive.prototype.sendData = function(channel, protocol, data, status)
64
{
65
    if (status == "Pressed")
66
    {
67
        var canMessage = new CanMessage("sns", "To_Owner", this.myName, this.myId, "DataStart");
68
        canMessage.setData("Channel", channel);
69
        canMessage.setData("Protocol", protocol);
70
        canMessage.setData("Data", data);
71
        sendMessage(canMessage);
72
    }
73
    else if (status == "Released")
74
    {
75
        var canMessage = new CanMessage("sns", "To_Owner", this.myName, this.myId, "DataStop");
76
        canMessage.setData("Channel", channel);
77
        canMessage.setData("Protocol", protocol);
78
        canMessage.setData("Data", data);
79
        sendMessage(canMessage);
80
    }
81
    else if (status == "Burst")
82
    {
83
        var canMessage = new CanMessage("sns", "To_Owner", this.myName, this.myId, "DataBurst");
84
        canMessage.setData("Channel", channel);
85
        canMessage.setData("Protocol", protocol);
86
        canMessage.setData("Data", data);
87
        sendMessage(canMessage);
88
    }
89
}
90