Rev 1846 | Rev 1849 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1846 | Rev 1848 | ||
|---|---|---|---|
| Line 111... | Line 111... | ||
| 111 | volatile uint32_t sns_irTransceive_LastPronto=0; |
111 | volatile uint32_t sns_irTransceive_LastPronto=0; |
| 112 | static uint8_t activeChannel = 0; |
112 | static uint8_t activeChannel = 0; |
| 113 | #define sns_irTransceive_MAXTIMING (16*1000) |
113 | #define sns_irTransceive_MAXTIMING (16*1000) |
| 114 | 114 | ||
| 115 | static void send_pronto(uint16_t *buffer, uint8_t len, uint8_t channel, uint16_t modfreq) { |
115 | static void send_pronto(uint16_t *buffer, uint8_t len, uint8_t channel, uint16_t modfreq) { |
| - | 116 | return; |
|
| - | 117 | ||
| 116 | StdCan_Msg_t msg; |
118 | StdCan_Msg_t msg; |
| 117 | 119 | ||
| 118 | StdCan_Set_class(msg.Header, CAN_MODULE_CLASS_SNS); |
120 | StdCan_Set_class(msg.Header, CAN_MODULE_CLASS_SNS); |
| 119 | StdCan_Set_direction(msg.Header, DIRECTIONFLAG_FROM_OWNER); |
121 | StdCan_Set_direction(msg.Header, DIRECTIONFLAG_FROM_OWNER); |
| 120 | msg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE; |
122 | msg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE; |
| Line 131... | Line 133... | ||
| 131 | msg.Data[0] = ((channel<<4)|0xf); |
133 | msg.Data[0] = ((channel<<4)|0xf); |
| 132 | msg.Data[1] = 0x10; |
134 | msg.Data[1] = 0x10; |
| 133 | msg.Data[2] = (((currentTime-sns_irTransceive_LastPronto)*1000)>>16)&0xff; |
135 | msg.Data[2] = (((currentTime-sns_irTransceive_LastPronto)*1000)>>16)&0xff; |
| 134 | msg.Data[3] = (((currentTime-sns_irTransceive_LastPronto)*1000)>>8)&0xff; |
136 | msg.Data[3] = (((currentTime-sns_irTransceive_LastPronto)*1000)>>8)&0xff; |
| 135 | msg.Data[4] = ((currentTime-sns_irTransceive_LastPronto)*1000)&0xff; |
137 | msg.Data[4] = ((currentTime-sns_irTransceive_LastPronto)*1000)&0xff; |
| 136 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
138 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
| 137 | _delay_ms(1); |
139 | _delay_ms(1); |
| 138 | } |
140 | } |
| 139 | sns_irTransceive_LastPronto=currentTime; |
141 | sns_irTransceive_LastPronto=currentTime; |
| 140 | 142 | ||
| 141 | // calculate frequency divider |
143 | // calculate frequency divider |
| 142 | uint16_t divider = (uint16_t)(sns_irTransceive_BaseFrq / (1000*(uint32_t)modfreq)); |
144 | uint16_t divider = (uint16_t)(sns_irTransceive_BaseFrq / (1000*(uint32_t)modfreq)); |
| Line 197... | Line 199... | ||
| 197 | _delay_ms(1); |
199 | _delay_ms(1); |
| 198 | j=0; |
200 | j=0; |
| 199 | seqNr = (seqNr + 1) % 16; |
201 | seqNr = (seqNr + 1) % 16; |
| 200 | msg.Header.Command = CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA1 + seqNr; |
202 | msg.Header.Command = CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA1 + seqNr; |
| 201 | } |
203 | } |
| 202 | /* Set complementary burst pair to 0 to indicate 16bit transmission */ |
204 | /* Set complementary burst pair to 0 to indicate 16bit transmission */ |
| 203 | msg.Data[j] = 0; |
205 | msg.Data[j] = 0; |
| 204 | } |
- | |
| 205 | else |
- | |
| 206 | { |
- | |
| 207 | msg.Data[j] = data&0xff; |
- | |
| 208 | } |
- | |
| 209 | - | ||
| 210 | i++; |
- | |
| 211 | } |
- | |
| 212 | - | ||
| 213 | j++; |
- | |
| 214 | if (j==8) |
- | |
| 215 | { |
- | |
| 216 | /* If send buffer is full, send frame */ |
- | |
| 217 | /* can buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
- | |
| 218 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
- | |
| 219 | _delay_ms(1); |
- | |
| 220 | j=0; |
- | |
| 221 | seqNr = (seqNr + 1) % 16; |
- | |
| 222 | msg.Header.Command = CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA1 + seqNr; |
- | |
| 223 | } |
- | |
| 224 | } |
206 | } |
| - | 207 | else |
|
| - | 208 | { |
|
| - | 209 | msg.Data[j] = data&0xff; |
|
| - | 210 | } |
|
| - | 211 | ||
| - | 212 | i++; |
|
| - | 213 | } |
|
| - | 214 | ||
| - | 215 | j++; |
|
| - | 216 | if (j==8) |
|
| - | 217 | { |
|
| - | 218 | /* If send buffer is full, send frame */ |
|
| - | 219 | /* can buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
|
| - | 220 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
|
| - | 221 | _delay_ms(1); |
|
| - | 222 | j=0; |
|
| - | 223 | seqNr = (seqNr + 1) % 16; |
|
| - | 224 | msg.Header.Command = CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA1 + seqNr; |
|
| - | 225 | } |
|
| - | 226 | } |
|
| 225 | 227 | ||
| 226 | /* End with max pulse TODO fix uglyness */ |
228 | /* End with max pulse TODO fix uglyness */ |
| 227 | msg.Data[j] = ((IR_MAX_PULSE_WIDTH/((1000000ULL*109)/sns_irTransceive_BaseFrq))>>8) & 0xFF; |
229 | msg.Data[j] = ((IR_MAX_PULSE_WIDTH/((1000000ULL*109)/sns_irTransceive_BaseFrq))>>8) & 0xFF; |
| 228 | j++; |
230 | j++; |
| 229 | if (j==8) |
231 | if (j==8) |
| 230 | { |
232 | { |
| 231 | /* If send buffer is full, send frame */ |
233 | /* If send buffer is full, send frame */ |
| 232 | /* can buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
234 | /* can buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
| Line 262... | Line 264... | ||
| 262 | 264 | ||
| 263 | 265 | ||
| 264 | static int decodeProntoData(int channel, uint8_t data) |
266 | static int decodeProntoData(int channel, uint8_t data) |
| 265 | { |
267 | { |
| 266 | static uint8_t waitingForLSB = FALSE; |
268 | static uint8_t waitingForLSB = FALSE; |
| - | 269 | static uint8_t previousValueWas16bit = FALSE; |
|
| 267 | 270 | ||
| 268 | if (irTxChannel[channel].txlen >= MAX_NR_TIMES) { |
271 | if (irTxChannel[channel].txlen >= MAX_NR_TIMES) { |
| 269 | // max length exceeded |
272 | // max length exceeded |
| 270 | return -1; |
273 | return -1; |
| 271 | } |
274 | } |
| Line 277... | Line 280... | ||
| 277 | return -2; |
280 | return -2; |
| 278 | } |
281 | } |
| 279 | } |
282 | } |
| 280 | 283 | ||
| 281 | // 0x00 means that previously received time is MSB of 16bit value, and that next byte will be LSB |
284 | // 0x00 means that previously received time is MSB of 16bit value, and that next byte will be LSB |
| 282 | if (data == 0 && !waitingForLSB) { |
285 | if (data == 0 && !waitingForLSB && previousValueWas16bit==FALSE) { |
| 283 | // convert previous time to MSB of the 16bit value. next received byte will become LSB |
286 | // convert previous time to MSB of the 16bit value. next received byte will become LSB |
| 284 | irTxChannel[channel].txbuf[irTxChannel[channel].txlen - 1] <<= 8; |
287 | irTxChannel[channel].txbuf[irTxChannel[channel].txlen - 1] <<= 8; |
| 285 | 288 | ||
| 286 | // flag that next received byte is LSB rather than a new timing value |
289 | // flag that next received byte is LSB rather than a new timing value |
| 287 | waitingForLSB = TRUE; |
290 | waitingForLSB = TRUE; |
| Line 292... | Line 295... | ||
| 292 | // let this byte be LSB of previous 16bit value |
295 | // let this byte be LSB of previous 16bit value |
| 293 | irTxChannel[channel].txbuf[irTxChannel[channel].txlen - 1] |= data; |
296 | irTxChannel[channel].txbuf[irTxChannel[channel].txlen - 1] |= data; |
| 294 | 297 | ||
| 295 | // we've now completed reception of the 16bit value |
298 | // we've now completed reception of the 16bit value |
| 296 | waitingForLSB = FALSE; |
299 | waitingForLSB = FALSE; |
| - | 300 | ||
| - | 301 | previousValueWas16bit = TRUE; |
|
| 297 | } |
302 | } |
| 298 | 303 | ||
| 299 | // non-zero value! simply new 8bit value |
304 | // non-zero value! simply new 8bit value |
| 300 | else { |
305 | else { |
| 301 | // check if we're already done |
306 | // check if we're already done |
| 302 | if (irTxChannel[ |
307 | if (irTxChannel[channel].txlen >= (((uint16_t)irTxChannel[channel].onceSeqLen + (uint16_t)irTxChannel[channel].repSeqLen))) { |
| 303 | // too much data received, not necessarily a problem in case frames are padded |
308 | // too much data received, not necessarily a problem in case frames are padded |
| 304 | return 2; |
309 | return 2; |
| 305 | } |
310 | } |
| 306 | 311 | ||
| 307 | irTxChannel[channel].txbuf[irTxChannel[channel].txlen] = data; |
312 | irTxChannel[channel].txbuf[irTxChannel[channel].txlen] = data; |
| - | 313 | ||
| - | 314 | previousValueWas16bit = FALSE; |
|
| 308 | 315 | ||
| 309 | irTxChannel[channel].txlen++; |
316 | irTxChannel[channel].txlen++; |
| 310 | } |
317 | } |
| 311 | 318 | ||
| 312 | return 1; |
319 | return 1; |
| Line 431... | Line 438... | ||
| 431 | Pca95xx_set_out(sns_irTransceive_TX2_PWRh); |
438 | Pca95xx_set_out(sns_irTransceive_TX2_PWRh); |
| 432 | if (power&0x1) |
439 | if (power&0x1) |
| 433 | { |
440 | { |
| 434 | Pca95xx_set_in(sns_irTransceive_TX2_PWRl); |
441 | Pca95xx_set_in(sns_irTransceive_TX2_PWRl); |
| 435 | } |
442 | } |
| 436 | if (power&0x2) |
443 | if (power&0x2) |
| 437 | { |
444 | { |
| 438 | Pca95xx_set_in(sns_irTransceive_TX2_PWRh); |
445 | Pca95xx_set_in(sns_irTransceive_TX2_PWRh); |
| 439 | } |
446 | } |
| 440 | #endif |
447 | #endif |
| 441 | break; |
448 | break; |
| 442 | } |
449 | } |
| 443 | irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE; |
450 | irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE; |
| 444 | } |
451 | } |
| 445 | #endif |
452 | #endif |
| 446 | } |
453 | } |
| 447 | } |
454 | } |
| 448 | 455 | ||
| 449 | 456 | ||
| Line 651... | Line 658... | ||
| 651 | irTxMsg.Data[5] = irRxChannel[channel].proto.data&0xff; |
658 | irTxMsg.Data[5] = irRxChannel[channel].proto.data&0xff; |
| 652 | 659 | ||
| 653 | StdCan_Put(&irTxMsg); |
660 | StdCan_Put(&irTxMsg); |
| 654 | } |
661 | } |
| 655 | irRxChannel[channel].state = sns_irTransceive_STATE_IDLE; |
662 | irRxChannel[channel].state = sns_irTransceive_STATE_IDLE; |
| 656 | break; |
663 | break; |
| 657 | 664 | ||
| 658 | default: |
665 | default: |
| 659 | break; |
666 | break; |
| 660 | } |
667 | } |
| 661 | #endif |
668 | #endif |
| 662 | 669 | ||
| 663 | #if IR_TX_ENABLE==1 |
670 | #if IR_TX_ENABLE==1 |
| 664 | switch (irTxChannel[channel].state) |
671 | switch (irTxChannel[channel].state) |
| 665 | { |
672 | { |
| 666 | case sns_irTransceive_STATE_IDLE: |
673 | case sns_irTransceive_STATE_IDLE: |
| 667 | /* transmission is started when a command is received on can */ |
674 | /* transmission is started when a command is received on can */ |
| 668 | break; |
675 | break; |
| 669 | 676 | ||
| 670 | case sns_irTransceive_STATE_START_TRANSMIT: |
677 | case sns_irTransceive_STATE_START_TRANSMIT: |
| 671 | { |
678 | { |
| 672 | if (expandProtocol(irTxChannel[channel].txbuf, &irTxChannel[channel].txlen, &irTxChannel[channel].proto) == IR_OK) { |
679 | if (expandProtocol(irTxChannel[channel].txbuf, &irTxChannel[channel].txlen, &irTxChannel[channel].proto) == IR_OK) { |
| 673 | IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, 0, irTxChannel[channel].txlen); |
680 | IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, 0, irTxChannel[channel].txlen); |
| 674 | irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMITTING; |
681 | irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMITTING; |
| 675 | } |
682 | } |
| 676 | else { |
683 | else { |
| 677 | irTxChannel[channel].state = sns_irTransceive_STATE_IDLE; |
684 | irTxChannel[channel].state = sns_irTransceive_STATE_IDLE; |
| 678 | } |
685 | } |
| 679 | break; |
686 | break; |
| 680 | } |
687 | } |
| Line 697... | Line 704... | ||
| 697 | irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE; |
704 | irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE; |
| 698 | break; |
705 | break; |
| 699 | } |
706 | } |
| 700 | 707 | ||
| 701 | if (irTxChannel[channel].repeatCount < 255) { |
708 | if (irTxChannel[channel].repeatCount < 255) { |
| 702 | irTxChannel[channel].repeatCount++; |
709 | irTxChannel[channel].repeatCount++; |
| 703 | } |
710 | } |
| 704 | 711 | ||
| 705 | // repeat sequence exists? |
712 | // repeat sequence exists? |
| 706 | if (irTxChannel[channel].repSeqLen != 0) { |
713 | if (irTxChannel[channel].repSeqLen != 0) { |
| 707 | // use repeat seq |
714 | // use repeat seq |
| Line 724... | Line 731... | ||
| 724 | cli(); |
731 | cli(); |
| 725 | irTxChannel[channel].sendComplete = FALSE; |
732 | irTxChannel[channel].sendComplete = FALSE; |
| 726 | sei(); |
733 | sei(); |
| 727 | 734 | ||
| 728 | if (irTxChannel[channel].sendingPronto) |
735 | if (irTxChannel[channel].sendingPronto) |
| 729 | { |
736 | { |
| - | 737 | // first repeat, or no repeat sequence defined => use last passive time in once seq |
|
| 730 | if(irTxChannel[channel].repeatCount == 0 || irTxChannel[channel].repSeqLen == 0) |
738 | if(irTxChannel[channel].repeatCount == 0 || irTxChannel[channel].repSeqLen == 0) |
| 731 | { |
739 | { |
| 732 | // use last passive time as timeout |
740 | // use last passive time as timeout |
| 733 | uint16_t lastPasTime = irTxChannel[channel].txbuf[irTxChannel[channel].onceSeqLen - 1] / 1000; |
741 | uint16_t lastPasTime = irTxChannel[channel].txbuf[irTxChannel[channel].onceSeqLen - 1] / 1000; |
| 734 | Timer_SetTimeout(irTxChannel[channel].timerNum, lastPasTime==0 ? 1 : lastPasTime, TimerTypeOneShot, 0); |
742 | Timer_SetTimeout(irTxChannel[channel].timerNum, lastPasTime==0 ? 1 : lastPasTime, TimerTypeOneShot, 0); |
| 735 | } |
743 | } |
| - | 744 | // second, or later repeat => use last passive time in repeat seq |
|
| 736 | else |
745 | else |
| 737 | { |
746 | { |
| 738 | // use last passive time as timeout |
747 | // use last passive time as timeout |
| 739 | uint16_t lastPasTime = irTxChannel[channel].txbuf[irTxChannel[channel].txlen - 1] / 1000; |
748 | uint16_t lastPasTime = irTxChannel[channel].txbuf[irTxChannel[channel].txlen - 1] / 1000; |
| 740 | Timer_SetTimeout(irTxChannel[channel].timerNum, lastPasTime==0 ? 1 : lastPasTime, TimerTypeOneShot, 0); |
749 | Timer_SetTimeout(irTxChannel[channel].timerNum, lastPasTime==0 ? 1 : lastPasTime, TimerTypeOneShot, 0); |
| 741 | } |
750 | } |
| 742 | irTxChannel[channel].state = sns_irTransceive_STATE_PAUSING; |
751 | irTxChannel[channel].state = sns_irTransceive_STATE_PAUSING; |
| 743 | } |
752 | } |
| 744 | else |
753 | else |
| 745 | { |
754 | { |
| 746 | irTxChannel[channel].state = sns_irTransceive_STATE_START_PAUSE; |
755 | irTxChannel[channel].state = sns_irTransceive_STATE_START_PAUSE; |
| 747 | } |
756 | } |
| 748 | } |
757 | } |
| Line 762... | Line 771... | ||
| 762 | { |
771 | { |
| 763 | irTxChannel[channel].proto.framecnt++; |
772 | irTxChannel[channel].proto.framecnt++; |
| 764 | } |
773 | } |
| 765 | 774 | ||
| 766 | irTxChannel[channel].state = sns_irTransceive_STATE_PAUSING; |
775 | irTxChannel[channel].state = sns_irTransceive_STATE_PAUSING; |
| 767 | break; |
776 | break; |
| 768 | } |
777 | } |
| 769 | 778 | ||
| 770 | case sns_irTransceive_STATE_PAUSING: |
779 | case sns_irTransceive_STATE_PAUSING: |
| 771 | { |
780 | { |
| 772 | if (irTxChannel[channel].sendingPronto) |
781 | if (irTxChannel[channel].sendingPronto) |
| 773 | { |
782 | { |
| 774 | if (Timer_Expired(irTxChannel[channel].timerNum)) |
783 | if (Timer_Expired(irTxChannel[channel].timerNum)) |
| 775 | { |
784 | { |
| 776 | irTxChannel[channel].state = sns_irTransceive_STATE_PRONTO_REPEAT; |
785 | irTxChannel[channel].state = sns_irTransceive_STATE_PRONTO_REPEAT; |
| 777 | } |
786 | } |
| 778 | break; |
787 | break; |
| 779 | } |
788 | } |
| 780 | 789 | ||
| 781 | if (Timer_Expired(irTxChannel[channel].timerNum)) |
790 | if (Timer_Expired(irTxChannel[channel].timerNum)) |
| 782 | { |
791 | { |
| 783 | irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT; |
792 | irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT; |
| 784 | } |
793 | } |
| 785 | 794 | ||
| 786 | /* transmission is stopped when such command is recevied on can */ |
795 | /* transmission is stopped when such command is recevied on can */ |
| 787 | if (irTxChannel[channel].stopSend == TRUE && irTxChannel[channel].repeatCount >= irTxChannel[channel].proto.repeats) |
796 | if (irTxChannel[channel].stopSend == TRUE && irTxChannel[channel].repeatCount >= irTxChannel[channel].proto.repeats) |
| 788 | { |
797 | { |
| Line 803... | Line 812... | ||
| 803 | default: |
812 | default: |
| 804 | break; |
813 | break; |
| 805 | } |
814 | } |
| 806 | #endif |
815 | #endif |
| 807 | 816 | ||
| 808 | } |
817 | } |
| 809 | } |
818 | } |
| 810 | 819 | ||
| 811 | 820 | ||
| 812 | /* Handle incoming CAN data */ |
821 | /* Handle incoming CAN data */ |
| 813 | void sns_irTransceive_HandleMessage(StdCan_Msg_t *rxMsg) |
822 | void sns_irTransceive_HandleMessage(StdCan_Msg_t *rxMsg) |
| 814 | { |
823 | { |
| 815 | /* Sanity check. */ |
824 | /* Sanity check. */ |
| 816 | if (StdCan_Ret_class(rxMsg->Header) != CAN_MODULE_CLASS_SNS || |
825 | if (StdCan_Ret_class(rxMsg->Header) != CAN_MODULE_CLASS_SNS || |
| Line 833... | Line 842... | ||
| 833 | irTxChannel[channel].proto.protocol = rxMsg->Data[1]; |
842 | irTxChannel[channel].proto.protocol = rxMsg->Data[1]; |
| 834 | 843 | ||
| 835 | irTxChannel[channel].proto.data = rxMsg->Data[2]; |
844 | irTxChannel[channel].proto.data = rxMsg->Data[2]; |
| 836 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
845 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
| 837 | irTxChannel[channel].proto.data |= rxMsg->Data[3]; |
846 | irTxChannel[channel].proto.data |= rxMsg->Data[3]; |
| 838 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
847 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
| 839 | irTxChannel[channel].proto.data |= rxMsg->Data[4]; |
848 | irTxChannel[channel].proto.data |= rxMsg->Data[4]; |
| 840 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
849 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
| 841 | irTxChannel[channel].proto.data |= rxMsg->Data[5]; |
850 | irTxChannel[channel].proto.data |= rxMsg->Data[5]; |
| 842 | 851 | ||
| 843 | irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT; |
852 | irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT; |
| 844 | } |
853 | } |
| 845 | } |
854 | } |
| 846 | else if ((0xf&rxMsg->Data[0]) == CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_RELEASED && channel < IR_SUPPORTED_NUM_CHANNELS) |
855 | else if ((0xf&rxMsg->Data[0]) == CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_RELEASED && channel < IR_SUPPORTED_NUM_CHANNELS) |
| 847 | { |
856 | { |
| 848 | if (irTxChannel[channel].state != sns_irTransceive_STATE_IDLE) |
857 | if (irTxChannel[channel].state != sns_irTransceive_STATE_IDLE) |
| 849 | { |
858 | { |
| 850 | irTxChannel[channel].stopSend = TRUE; |
859 | irTxChannel[channel].stopSend = TRUE; |
| 851 | } |
860 | } |
| 852 | } |
861 | } |
| 853 | break; |
862 | break; |
| 854 | } |
863 | } |
| 855 | 864 | ||
| 856 | #if sns_irTransceive_PRONTO_SUPPORT==1 |
865 | #if sns_irTransceive_PRONTO_SUPPORT==1 |
| 857 | /* TODO: add struct which stores pronto info: |
866 | /* TODO: add struct which stores pronto info: |
| Line 873... | Line 882... | ||
| 873 | break; |
882 | break; |
| 874 | } |
883 | } |
| 875 | uint32_t freqkHz = (sns_irTransceive_BaseFrq / (divider*1000)); |
884 | uint32_t freqkHz = (sns_irTransceive_BaseFrq / (divider*1000)); |
| 876 | if (freqkHz == 0) { |
885 | if (freqkHz == 0) { |
| 877 | // invalid modfreq |
886 | // invalid modfreq |
| 878 | break; |
887 | break; |
| 879 | } |
888 | } |
| 880 | irTxChannel[channel].proto.modfreq = freqkHz; |
889 | irTxChannel[channel].proto.modfreq = freqkHz; |
| 881 | //printf("FRQ%05u", irTxChannel[channel].proto.modfreq); |
890 | //printf("FRQ%05u", irTxChannel[channel].proto.modfreq); |
| 882 | 891 | ||
| 883 | // TODO: reconfigure with new modfreq, if no other channels sending pronto |
892 | // TODO: reconfigure with new modfreq, if no other channels sending pronto |
| Line 899... | Line 908... | ||
| 899 | /* TODO: Send response frame */ |
908 | /* TODO: Send response frame */ |
| 900 | break; |
909 | break; |
| 901 | } |
910 | } |
| 902 | 911 | ||
| 903 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOSTOP: |
912 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOSTOP: |
| 904 | /* TODO: stop sending IR */ |
913 | /* TODO: stop sending IR */ |
| 905 | 914 | ||
| 906 | /* TODO: Send response frame */ |
915 | /* TODO: Send response frame */ |
| 907 | break; |
916 | break; |
| 908 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOCONTINUE: |
917 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOCONTINUE: |
| 909 | /* TODO: reset timeout to continue sending repeat sequences */ |
918 | /* TODO: reset timeout to continue sending repeat sequences */ |
| Line 925... | Line 934... | ||
| 925 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA12: /* Fall through */ |
934 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA12: /* Fall through */ |
| 926 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA13: /* Fall through */ |
935 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA13: /* Fall through */ |
| 927 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA14: /* Fall through */ |
936 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA14: /* Fall through */ |
| 928 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA15: /* Fall through */ |
937 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA15: /* Fall through */ |
| 929 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA16: |
938 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA16: |
| 930 | { |
939 | { |
| 931 | // unexpected CAN msg, out of order |
940 | // unexpected CAN msg, out of order |
| 932 | if (irTxChannel[activeChannel].state != sns_irTransceive_STATE_PREPARING_PRONTO) { |
941 | if (irTxChannel[activeChannel].state != sns_irTransceive_STATE_PREPARING_PRONTO) { |
| 933 | break; |
942 | break; |
| 934 | } |
943 | } |
| 935 | 944 | ||
| 936 | // unexpected CAN msg, out of order |
945 | // unexpected CAN msg, out of order |
| 937 | if ((rxMsg->Header.Command - CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA1) != (irTxChannel[activeChannel].expectedSeqNr % 16)) { |
946 | if ((rxMsg->Header.Command - CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA1) != (irTxChannel[activeChannel].expectedSeqNr % 16)) { |
| 938 | printf("SEQERROR"); |
947 | printf("SEQERROR"); |
| 939 | irTxChannel[ |
948 | irTxChannel[activeChannel].state = sns_irTransceive_STATE_START_IDLE; |
| 940 | break; |
949 | break; |
| 941 | } |
950 | } |
| 942 | 951 | ||
| 943 | // decode pronto data |
952 | // decode pronto data |
| 944 | for (uint8_t i = 0; i < rxMsg->Length; i++) { |
953 | for (uint8_t i = 0; i < rxMsg->Length; i++) { |
| 945 | int res; |
- | |
| 946 | if ( |
954 | if (decodeProntoData(activeChannel, rxMsg->Data[i]) != 1) { |
| 947 | irTxChannel[ |
955 | irTxChannel[activeChannel].state = sns_irTransceive_STATE_START_IDLE; |
| 948 | printf(" |
956 | printf("DECERROR"); |
| 949 | return; |
957 | return; |
| 950 | } |
958 | } |
| 951 | } |
959 | } |
| 952 | 960 | ||
| 953 | irTxChannel[activeChannel].expectedSeqNr++; |
961 | irTxChannel[activeChannel].expectedSeqNr++; |
| Line 969... | Line 977... | ||
| 969 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND14: /* Fall through */ |
977 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND14: /* Fall through */ |
| 970 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND15: /* Fall through */ |
978 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND15: /* Fall through */ |
| 971 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND16: /* Fall through */ |
979 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND16: /* Fall through */ |
| 972 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND17: |
980 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND17: |
| 973 | { |
981 | { |
| 974 | // unexpected CAN msg, out of order |
982 | // unexpected CAN msg, out of order |
| 975 | if (irTxChannel[activeChannel].state != sns_irTransceive_STATE_PREPARING_PRONTO) { |
983 | if (irTxChannel[activeChannel].state != sns_irTransceive_STATE_PREPARING_PRONTO) { |
| 976 | break; |
984 | break; |
| 977 | } |
985 | } |
| 978 | 986 | ||
| 979 | // unexpected CAN msg, out of order |
987 | // unexpected CAN msg, out of order |
| 980 | if (((rxMsg->Header.Command - CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND1) % 16) != (irTxChannel[activeChannel].expectedSeqNr % 16)) { |
988 | if (((rxMsg->Header.Command - CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND1) % 16) != (irTxChannel[activeChannel].expectedSeqNr % 16)) { |
| 981 | printf("SEQERROR"); |
989 | printf("SEQERROR"); |
| 982 | irTxChannel[ |
990 | irTxChannel[activeChannel].state = sns_irTransceive_STATE_START_IDLE; |
| 983 | break; |
991 | break; |
| 984 | } |
992 | } |
| 985 | 993 | ||
| 986 | // decode remaining pronto data (if any) |
994 | // decode remaining pronto data (if any). -1 because last byte is repeat count |
| 987 | for (uint16_t i = 0; i < rxMsg->Length - 1; i++) { |
995 | for (uint16_t i = 0; i < rxMsg->Length - 1; i++) { |
| 988 | if (decodeProntoData(activeChannel, rxMsg->Data[i]) < 0) { |
996 | if (decodeProntoData(activeChannel, rxMsg->Data[i]) < 0) { |
| 989 | printf("DECERROR"); |
997 | printf("DECERROR"); |
| 990 | irTxChannel[ |
998 | irTxChannel[activeChannel].state = sns_irTransceive_STATE_START_IDLE; |
| 991 | return; |
999 | return; |
| 992 | } |
1000 | } |
| 993 | } |
1001 | } |
| 994 | 1002 | ||
| 995 | // sanity check |
1003 | // sanity check |
| Line 1004... | Line 1012... | ||
| 1004 | irTxChannel[activeChannel].proto.timeout = 1; // TODO: timer is buggy and doesn't support timeout 0, so we're forced to use 1ms extra between repeats |
1012 | irTxChannel[activeChannel].proto.timeout = 1; // TODO: timer is buggy and doesn't support timeout 0, so we're forced to use 1ms extra between repeats |
| 1005 | 1013 | ||
| 1006 | // convert pronto data to us |
1014 | // convert pronto data to us |
| 1007 | // TODO: calculate value |
1015 | // TODO: calculate value |
| 1008 | for (uint16_t i=0; i < irTxChannel[activeChannel].txlen; i++) { |
1016 | for (uint16_t i = 0; i < irTxChannel[activeChannel].txlen; i++) { |
| 1009 | uint32_t newVal = ((uint32_t)irTxChannel[activeChannel].txbuf[i]) * |
1017 | uint32_t newVal = ((uint32_t)irTxChannel[activeChannel].txbuf[i]) * 27UL; |
| 1010 | if (newVal > |
1018 | if (newVal > 0xFFFFUL) { |
| 1011 | newVal = |
1019 | newVal = 0xFFFFUL; |
| 1012 | } |
1020 | } |
| 1013 | irTxChannel[activeChannel].txbuf[i] = (uint16_t)newVal; |
1021 | irTxChannel[activeChannel].txbuf[i] = (uint16_t)newVal; |
| 1014 | } |
1022 | } |
| 1015 | 1023 | ||
| 1016 | // send |
1024 | // send |