Subversion Repositories HomeAutomation

Rev

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

Rev 1484 Rev 1487
Line 17... Line 17...
17
    uint8_t             state;
17
    uint8_t             state;
18
    uint8_t             sendComplete;
18
    uint8_t             sendComplete;
19
    uint16_t            *txbuf;
19
    uint16_t            *txbuf;
20
    uint8_t             txlen;
20
    uint8_t             txlen;
21
    uint8_t             timerNum;
21
    uint8_t             timerNum;
-
 
22
    uint8_t             repeatCount;
-
 
23
    uint8_t             stopSend;
22
    Ir_Protocol_Data_t  proto;
24
    Ir_Protocol_Data_t  proto;
23
} irTxChannel[sns_irTransceive_SUPPORTED_NUM_CHANNELS];
25
} irTxChannel[sns_irTransceive_SUPPORTED_NUM_CHANNELS];
24
#endif
26
#endif
25
 
27
 
26
uint16_t    buf0[MAX_NR_TIMES];
28
uint16_t    buf0[MAX_NR_TIMES];
Line 115... Line 117...
115
#endif
117
#endif
116
 
118
 
117
#if IR_TX_ENABLE==1
119
#if IR_TX_ENABLE==1
118
        irTxChannel[i].state = sns_irTransceive_STATE_IDLE;
120
        irTxChannel[i].state = sns_irTransceive_STATE_IDLE;
119
        irTxChannel[i].sendComplete = FALSE;
121
        irTxChannel[i].sendComplete = FALSE;
-
 
122
        irTxChannel[i].repeatCount = 0;
120
        irTxChannel[i].txlen = 0;
123
        irTxChannel[i].txlen = 0;
121
        irTxChannel[i].proto.timeout=0;
-
 
122
        irTxChannel[i].proto.data=0;
124
        irTxChannel[i].proto.data=0;
123
        irTxChannel[i].proto.repeats=0;
125
        irTxChannel[i].proto.repeats=0;
-
 
126
        irTxChannel[i].proto.framecnt=0;
124
        irTxChannel[i].proto.protocol=0;
127
        irTxChannel[i].proto.protocol=0;
125
#endif
128
#endif
126
    }
129
    }
127
   
130
   
128
#if IR_RX_ENABLE==1
131
#if IR_RX_ENABLE==1
Line 143... Line 146...
143
    irRxChannel[0].rxbuf = buf0;
146
    irRxChannel[0].rxbuf = buf0;
144
    IrTransceiver_InitRxChannel(0, irRxChannel[0].rxbuf, sns_irTransceive_RX_done_callback, sns_irTransceive_RX0_PCINT, sns_irTransceive_RX0_PIN);
147
    IrTransceiver_InitRxChannel(0, irRxChannel[0].rxbuf, sns_irTransceive_RX_done_callback, sns_irTransceive_RX0_PCINT, sns_irTransceive_RX0_PIN);
145
#endif
148
#endif
146
 
149
 
147
#if IR_TX_ENABLE==1
150
#if IR_TX_ENABLE==1
-
 
151
    irTxChannel[0].txbuf = buf1;
148
    IrTransceiver_InitTxChannel(0, sns_irTransceive_TX_done_callback, sns_irTransceive_TX0_PIN);
152
    IrTransceiver_InitTxChannel(0, sns_irTransceive_TX_done_callback, sns_irTransceive_TX0_PIN);
149
#endif
153
#endif
150
 
154
 
151
}
155
}
152
 
156
 
Line 247... Line 251...
247
 
251
 
248
#if IR_TX_ENABLE==1
252
#if IR_TX_ENABLE==1
249
        switch (irTxChannel[channel].state)
253
        switch (irTxChannel[channel].state)
250
        {
254
        {
251
        case sns_irTransceive_STATE_IDLE:
255
        case sns_irTransceive_STATE_IDLE:
-
 
256
            /* transmission is started when a command is received on can */
252
            break;
257
            break;
253
 
258
 
254
        case sns_irTransceive_STATE_START_TRANSMIT:
259
        case sns_irTransceive_STATE_START_TRANSMIT:
255
            if (expandProtocol(irTxChannel[channel].txbuf, &irTxChannel[channel].txlen, &irTxChannel[channel].proto) == IR_OK)
260
            if (expandProtocol(irTxChannel[channel].txbuf, &irTxChannel[channel].txlen, &irTxChannel[channel].proto) == IR_OK)
256
            {
261
            {
Line 272... Line 277...
272
                irTxChannel[channel].state = sns_irTransceive_STATE_START_PAUSE;
277
                irTxChannel[channel].state = sns_irTransceive_STATE_START_PAUSE;
273
            }
278
            }
274
            break;
279
            break;
275
 
280
 
276
        case sns_irTransceive_STATE_START_PAUSE:
281
        case sns_irTransceive_STATE_START_PAUSE:
-
 
282
            if (irTxChannel[channel].repeatCount < irTxChannel[channel].proto.repeats)
-
 
283
            {
-
 
284
                irTxChannel[channel].repeatCount++;
-
 
285
            }
-
 
286
           
-
 
287
            Timer_SetTimeout(irTxChannel[channel].timerNum, irTxChannel[channel].proto.timeout, TimerTypeOneShot, 0);
-
 
288
 
-
 
289
            if (irTxChannel[channel].proto.framecnt != 255)
-
 
290
            {
-
 
291
                irTxChannel[channel].proto.framecnt++;
-
 
292
            }
-
 
293
           
-
 
294
            irTxChannel[channel].state = sns_irTransceive_STATE_PAUSING;
277
            break;
295
            break;
278
 
296
 
279
        case sns_irTransceive_STATE_PAUSING:
297
        case sns_irTransceive_STATE_PAUSING:
-
 
298
            if (Timer_Expired(irTxChannel[channel].timerNum))
-
 
299
            {
-
 
300
                irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT;
-
 
301
            }
-
 
302
           
-
 
303
            /* transmission is stopped when such command is recevied on can */
-
 
304
            if (irTxChannel[channel].stopSend == TRUE && irTxChannel[channel].repeatCount >= irTxChannel[channel].proto.repeats)
-
 
305
            {
-
 
306
                //TODO maybe send message on can for status? to confirm stopped sending, ready for new command
-
 
307
                irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE;
-
 
308
            }
280
            break;
309
            break;
281
 
310
 
282
        case sns_irTransceive_STATE_START_IDLE:
311
        case sns_irTransceive_STATE_START_IDLE:
-
 
312
            irTxChannel[channel].stopSend = FALSE;
-
 
313
            irTxChannel[channel].repeatCount = 0;
-
 
314
            irTxChannel[channel].proto.framecnt = 0;
283
       
315
           
284
            irTxChannel[channel].state = sns_irTransceive_STATE_IDLE;
316
            irTxChannel[channel].state = sns_irTransceive_STATE_IDLE;
285
            break;
317
            break;
286
        }
318
        }
287
#endif
319
#endif
288
 
320
 
289
    }
321
    }
290
}
322
}
291
 
323
 
292
void sns_irTransceive_HandleMessage(StdCan_Msg_t *rxMsg)
324
void sns_irTransceive_HandleMessage(StdCan_Msg_t *rxMsg)
293
{
325
{
294
    /*if (  StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS &&
326
    if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS &&
295
        StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_FROM_OWNER &&
327
        StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
296
        rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_IRTRANSCEIVE &&
328
        rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_IRTRANSCEIVE &&
297
        rxMsg->Header.ModuleId == sns_irTransceive_ID)
329
        rxMsg->Header.ModuleId == sns_irTransceive_ID)
298
    {
330
    {
-
 
331
        uint8_t channel;
299
        switch (rxMsg->Header.Command)
332
        switch (rxMsg->Header.Command)
300
        {
333
        {
301
        case CAN_CMD_MODULE_DUMMY:
334
        case CAN_MODULE_CMD_PHYSICAL_IR:
302
        ///TODO: Do something dummy
335
            channel = rxMsg->Data[0]>>4;
-
 
336
            if ((0xf&rxMsg->Data[0]) == CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED && channel < sns_irTransceive_SUPPORTED_NUM_CHANNELS)
-
 
337
            {
-
 
338
                if (irTxChannel[channel].state == sns_irTransceive_STATE_IDLE)
-
 
339
                {
-
 
340
                    irTxChannel[channel].proto.protocol = rxMsg->Data[1];
-
 
341
 
-
 
342
                    irTxChannel[channel].proto.data = rxMsg->Data[2];
-
 
343
                    irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8;
-
 
344
                    irTxChannel[channel].proto.data |= rxMsg->Data[3];
-
 
345
                    irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8;
-
 
346
                    irTxChannel[channel].proto.data |= rxMsg->Data[4];
-
 
347
                    irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8;
-
 
348
                    irTxChannel[channel].proto.data |= rxMsg->Data[5];
-
 
349
 
-
 
350
                    irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT;
-
 
351
                }
-
 
352
            }
-
 
353
            else if ((0xf&rxMsg->Data[0]) == CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_RELEASED && channel < sns_irTransceive_SUPPORTED_NUM_CHANNELS)
-
 
354
            {
-
 
355
                if (irTxChannel[channel].state != sns_irTransceive_STATE_IDLE)
-
 
356
                {
-
 
357
                    irTxChannel[channel].stopSend = TRUE;
-
 
358
                }
-
 
359
            }
303
        break;
360
            break;
304
        }
361
        }
305
    }*/
362
    }
306
}
363
}
307
 
364
 
308
void sns_irTransceive_List(uint8_t ModuleSequenceNumber)
365
void sns_irTransceive_List(uint8_t ModuleSequenceNumber)
309
{
366
{
310
    StdCan_Msg_t txMsg;
367
    StdCan_Msg_t txMsg;