Subversion Repositories HomeAutomation

Rev

Rev 2040 | Rev 2199 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 2040 Rev 2198
Line 10... Line 10...
10
uint8_t rfRxChannel_rxlen;
10
uint8_t rfRxChannel_rxlen;
11
uint8_t rfRxChannel_state;
11
uint8_t rfRxChannel_state;
12
Ir_Protocol_Data_t  rfRxChannel_proto;
12
Ir_Protocol_Data_t  rfRxChannel_proto;
13
uint16_t    rfRxChannel_buf[MAX_NR_TIMES];
13
uint16_t    rfRxChannel_buf[MAX_NR_TIMES];
14
 
14
 
-
 
15
uint16_t debugCnt1 = 0;
-
 
16
uint16_t debugCnt2 = 0;
-
 
17
uint16_t debugCnt3 = 5;
-
 
18
 
15
void sns_rfTransceive_RX_done_callback(uint8_t channel, uint16_t *buffer, uint8_t len)
19
void sns_rfTransceive_RX_done_callback(uint8_t channel, uint16_t *buffer, uint8_t len, uint8_t index)
-
 
20
{
-
 
21
#if IR_RX_CONTINUOUS_MODE==0
-
 
22
    rfRxChannel_newData = TRUE;
-
 
23
    rfRxChannel_rxlen = len;
-
 
24
#else
-
 
25
//gpio_toggle_pin(EXP_B);
-
 
26
    if (len > sns_rfTransceive_MIN_NUM_PULSES)
16
{
27
    {
17
    rfRxChannel_newData = TRUE;
28
        rfRxChannel_newData = TRUE;
18
    rfRxChannel_rxlen = len;
29
        rfRxChannel_rxlen = len;
-
 
30
       
-
 
31
///////////// DEBUG!!!!
-
 
32
//gpio_set_pin(EXP_B);
-
 
33
 
-
 
34
//debugCnt1 +=1;
-
 
35
    }
-
 
36
//debugCnt2 +=1;
-
 
37
    //check if len is > something reasonable
-
 
38
    //let process function parse protocols
-
 
39
#endif
19
}
40
}
20
#endif
41
#endif
21
 
42
 
22
 
43
 
23
#if IR_TX_ENABLE==1
44
#if IR_TX_ENABLE==1
Line 49... Line 70...
49
    rfRxChannel_rxlen = 0;
70
    rfRxChannel_rxlen = 0;
50
    rfRxChannel_proto.timeout=0;
71
    rfRxChannel_proto.timeout=0;
51
    rfRxChannel_proto.data=0;
72
    rfRxChannel_proto.data=0;
52
    rfRxChannel_proto.repeats=0;
73
    rfRxChannel_proto.repeats=0;
53
    rfRxChannel_proto.protocol=0;
74
    rfRxChannel_proto.protocol=0;
54
#endif
75
#endif
55
 
76
 
56
#if IR_TX_ENABLE==1
77
#if IR_TX_ENABLE==1
57
    rfTxChannel_sendComplete = FALSE;
78
    rfTxChannel_sendComplete = FALSE;
58
    rfTxChannel_txlen = 0;
79
    rfTxChannel_txlen = 0;
59
    rfTxChannel_proto.data=0;
80
    rfTxChannel_proto.data=0;
Line 79... Line 100...
79
   
100
   
80
#if IR_TX_ENABLE==1
101
#if IR_TX_ENABLE==1
81
    IrTransceiver_InitTxChannel(0, sns_rfTransceive_TX_done_callback, sns_rfTransceive_TX_PIN);
102
    IrTransceiver_InitTxChannel(0, sns_rfTransceive_TX_done_callback, sns_rfTransceive_TX_PIN);
82
    rfTxChannel_state = sns_rfTransceive_STATE_IDLE;
103
    rfTxChannel_state = sns_rfTransceive_STATE_IDLE;
83
#endif
104
#endif
-
 
105
 
-
 
106
///////////// DEBUG!!!!
-
 
107
gpio_set_out(EXP_A);
-
 
108
}
-
 
109
 
-
 
110
 
-
 
111
///////////// DEBUG!!!!
-
 
112
#if 0
-
 
113
StdCan_Msg_t irTxMsg;
-
 
114
void send_debug(uint16_t *buffer, uint8_t len) {
-
 
115
 
-
 
116
    /* the protocol is unknown so the raw ir-data is sent, makes it easier to develop a new protocol */
-
 
117
 
-
 
118
    StdCan_Set_class(irTxMsg.Header, CAN_MODULE_CLASS_SNS);
-
 
119
    StdCan_Set_direction(irTxMsg.Header, DIRECTIONFLAG_FROM_OWNER);
-
 
120
    irTxMsg.Length = 8;
-
 
121
    irTxMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRRECEIVE;
-
 
122
    irTxMsg.Header.ModuleId = 0;
-
 
123
    irTxMsg.Header.Command = CAN_MODULE_CMD_IRRECEIVE_IRRAW;
-
 
124
    for (uint8_t i = 0; i < len>>2; i++) {
-
 
125
        uint8_t index = i<<2;
-
 
126
 
-
 
127
        irTxMsg.Data[0] = (buffer[index]>>8)&0xff;
-
 
128
        irTxMsg.Data[1] = (buffer[index]>>0)&0xff;
-
 
129
        irTxMsg.Data[2] = (buffer[index+1]>>8)&0xff;
-
 
130
        irTxMsg.Data[3] = (buffer[index+1]>>0)&0xff;
-
 
131
        irTxMsg.Data[4] = (buffer[index+2]>>8)&0xff;
-
 
132
        irTxMsg.Data[5] = (buffer[index+2]>>0)&0xff;
-
 
133
        irTxMsg.Data[6] = (buffer[index+3]>>8)&0xff;
-
 
134
        irTxMsg.Data[7] = (buffer[index+3]>>0)&0xff;
-
 
135
               
-
 
136
        /* buffers will be filled when sending more than 2-3 messages, so retry until sent */
-
 
137
        while (StdCan_Put(&irTxMsg) != StdCan_Ret_OK) {}
-
 
138
        _delay_ms(1);
-
 
139
    }
-
 
140
   
-
 
141
    uint8_t lastpacketcnt = len&0x03;
-
 
142
    if (lastpacketcnt > 0) {
-
 
143
        irTxMsg.Length = lastpacketcnt<<1;
-
 
144
        for (uint8_t i = 0; i < lastpacketcnt; i++) {
-
 
145
            irTxMsg.Data[i<<1] = (buffer[(len&0xfc)|i]>>8)&0xff;
-
 
146
            irTxMsg.Data[(i<<1)+1] = (buffer[(len&0xfc)|i]>>0)&0xff;
-
 
147
        }
-
 
148
        /* buffers will be filled when sending more than 2-3 messages, so retry until sent */
-
 
149
        while (StdCan_Put(&irTxMsg) != StdCan_Ret_OK) {}
-
 
150
        _delay_ms(1);
-
 
151
    }
-
 
152
 
84
}
153
}
-
 
154
#endif
85
 
155
 
86
void sns_rfTransceive_Process(void)
156
void sns_rfTransceive_Process(void)
87
{
157
{
88
#if IR_RX_ENABLE==1
158
#if IR_RX_ENABLE==1
89
        switch (rfRxChannel_state)
159
        switch (rfRxChannel_state)
Line 114... Line 184...
114
        case sns_rfTransceive_STATE_RECEIVING:
184
        case sns_rfTransceive_STATE_RECEIVING:
115
            if (rfRxChannel_newData == TRUE) {
185
            if (rfRxChannel_newData == TRUE) {
116
                cli();
186
                cli();
117
                rfRxChannel_newData = FALSE;
187
                rfRxChannel_newData = FALSE;
118
                sei();
188
                sei();
-
 
189
/*
-
 
190
debugCnt3 +=1;
-
 
191
if (debugCnt3>5)
-
 
192
{
-
 
193
printf("1\n");
-
 
194
debugCnt3=0;
-
 
195
}
119
               
196
*/
120
                /* Let protocol driver parse and then send on CAN */
197
                /* Let protocol driver parse and then send on CAN */
121
                uint8_t res2 = parseProtocol(rfRxChannel_buf, rfRxChannel_rxlen, &rfRxChannel_proto);
198
                uint8_t res2 = parseProtocol(rfRxChannel_buf, rfRxChannel_rxlen, &rfRxChannel_proto);
122
                if (res2 == IR_OK && rfRxChannel_proto.protocol != IR_PROTO_UNKNOWN) {
199
                if (res2 == IR_OK && rfRxChannel_proto.protocol != IR_PROTO_UNKNOWN) {
-
 
200
gpio_clr_pin(EXP_B);
-
 
201
//send_debug(rfRxChannel_buf, rfRxChannel_rxlen);
123
                    /* If timeout is 0, protocol is burst protocol */
202
                    /* If timeout is 0, protocol is burst protocol */
124
                    if (rfRxChannel_proto.timeout > 0)
203
                    if (rfRxChannel_proto.timeout > 0)
125
                    {
204
                    {
126
                        rfTxMsg.Data[0] = CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED;
205
                        rfTxMsg.Data[0] = CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED;
127
                        rfRxChannel_state = sns_rfTransceive_STATE_START_PAUSE;
206
                        rfRxChannel_state = sns_rfTransceive_STATE_START_PAUSE;