Rev 1833 | Rev 1835 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1833 | Rev 1834 | ||
|---|---|---|---|
| Line 42... | Line 42... | ||
| 42 | uint8_t repeatCount; |
42 | uint8_t repeatCount; |
| 43 | Ir_Protocol_Data_t proto; |
43 | Ir_Protocol_Data_t proto; |
| 44 | uint8_t stopSend; |
44 | uint8_t stopSend; |
| 45 | uint8_t sendComplete; |
45 | uint8_t sendComplete; |
| 46 | // pronto params |
46 | // pronto params |
| - | 47 | uint8_t sendingPronto; |
|
| 47 | uint8_t onceSeqLen; |
48 | uint8_t onceSeqLen; |
| 48 | uint8_t repSeqLen; |
49 | uint8_t repSeqLen; |
| 49 | uint8_t numberOfRepeats; |
50 | uint8_t numberOfRepeats; |
| 50 | } irTxChannel[IR_SUPPORTED_NUM_CHANNELS]; |
51 | } irTxChannel[IR_SUPPORTED_NUM_CHANNELS]; |
| 51 | #endif |
52 | #endif |
| Line 607... | Line 608... | ||
| 607 | { |
608 | { |
| 608 | irTxChannel[channel].state = sns_irTransceive_STATE_IDLE; |
609 | irTxChannel[channel].state = sns_irTransceive_STATE_IDLE; |
| 609 | } |
610 | } |
| 610 | break; |
611 | break; |
| 611 | 612 | ||
| 612 | case |
613 | case sns_irTransceive_STATE_START_TRANSMIT_PRONTO: |
| 613 | IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, 0, irTxChannel[channel].txlen); |
614 | IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, 0, irTxChannel[channel].txlen); |
| 614 | irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMITTING; |
615 | irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMITTING; |
| - | 616 | irTxChannel[channel].sendingPronto = TRUE; |
|
| 615 | break; |
617 | break; |
| 616 | 618 | ||
| 617 | case sns_irTransceive_STATE_TRANSMITTING: |
619 | case sns_irTransceive_STATE_TRANSMITTING: |
| 618 | if (irTxChannel[channel].sendComplete == TRUE) |
620 | if (irTxChannel[channel].sendComplete == TRUE) |
| 619 | { |
621 | { |
| Line 641... | Line 643... | ||
| 641 | break; |
643 | break; |
| 642 | 644 | ||
| 643 | case sns_irTransceive_STATE_PAUSING: |
645 | case sns_irTransceive_STATE_PAUSING: |
| 644 | if (Timer_Expired(irTxChannel[channel].timerNum)) |
646 | if (Timer_Expired(irTxChannel[channel].timerNum)) |
| 645 | { |
647 | { |
| - | 648 | if (irTxChannel[channel].sendingPronto) { |
|
| 646 | irTxChannel[channel].state = |
649 | irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT_PRONTO; |
| 647 | } |
650 | } |
| - | 651 | else { |
|
| - | 652 | irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT; |
|
| - | 653 | } |
|
| - | 654 | } |
|
| 648 | 655 | ||
| 649 | /* transmission is stopped when such command is recevied on can */ |
656 | /* transmission is stopped when such command is recevied on can */ |
| 650 | if (irTxChannel[channel].stopSend == TRUE && irTxChannel[channel].repeatCount >= irTxChannel[channel].proto.repeats) |
657 | if (irTxChannel[channel].stopSend == TRUE && irTxChannel[channel].repeatCount >= irTxChannel[channel].proto.repeats) |
| 651 | { |
658 | { |
| 652 | //TODO maybe send message on can for status? to confirm stopped sending, ready for new command |
659 | //TODO maybe send message on can for status? to confirm stopped sending, ready for new command |
| 653 | irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE; |
660 | irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE; |
| 654 | } |
661 | } |
| - | 662 | ||
| - | 663 | if (irTxChannel[channel].sendingPronto && irTxChannel[channel].repeatCount >= irTxChannel[channel].proto.repeats) |
|
| - | 664 | { |
|
| - | 665 | irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE; |
|
| - | 666 | } |
|
| - | 667 | ||
| 655 | break; |
668 | break; |
| 656 | 669 | ||
| 657 | case sns_irTransceive_STATE_START_IDLE: |
670 | case sns_irTransceive_STATE_START_IDLE: |
| 658 | irTxChannel[channel].stopSend = FALSE; |
671 | irTxChannel[channel].stopSend = FALSE; |
| 659 | irTxChannel[channel].repeatCount = 0; |
672 | irTxChannel[channel].repeatCount = 0; |
| 660 | irTxChannel[channel].proto.framecnt = 0; |
673 | irTxChannel[channel].proto.framecnt = 0; |
| - | 674 | irTxChannel[channel].sendingPronto = FALSE; |
|
| 661 | 675 | ||
| 662 | irTxChannel[channel].state = sns_irTransceive_STATE_IDLE; |
676 | irTxChannel[channel].state = sns_irTransceive_STATE_IDLE; |
| 663 | break; |
677 | break; |
| 664 | 678 | ||
| 665 | default: |
679 | default: |
| Line 677... | Line 691... | ||
| 677 | if ( StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS && |
691 | if ( StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS && |
| 678 | StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER && |
692 | StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER && |
| 679 | rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_IRTRANSCEIVE && |
693 | rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_IRTRANSCEIVE && |
| 680 | rxMsg->Header.ModuleId == sns_irTransceive_ID) |
694 | rxMsg->Header.ModuleId == sns_irTransceive_ID) |
| 681 | { |
695 | { |
| 682 | //printf("CMD= %u\n", rxMsg->Header.Command); |
- | |
| 683 | switch (rxMsg->Header.Command) |
696 | switch (rxMsg->Header.Command) |
| 684 | { |
697 | { |
| 685 | #if IR_TX_ENABLE==1 |
698 | #if IR_TX_ENABLE==1 |
| 686 | case CAN_MODULE_CMD_PHYSICAL_IR: { |
699 | case CAN_MODULE_CMD_PHYSICAL_IR: { |
| 687 | uint8_t channel = rxMsg->Data[0]>>4; |
700 | uint8_t channel = rxMsg->Data[0]>>4; |
| Line 690... | Line 703... | ||
| 690 | if (irTxChannel[channel].state == sns_irTransceive_STATE_IDLE) |
703 | if (irTxChannel[channel].state == sns_irTransceive_STATE_IDLE) |
| 691 | { |
704 | { |
| 692 | irTxChannel[channel].proto.protocol = rxMsg->Data[1]; |
705 | irTxChannel[channel].proto.protocol = rxMsg->Data[1]; |
| 693 | 706 | ||
| 694 | irTxChannel[channel].proto.data = rxMsg->Data[2]; |
707 | irTxChannel[channel].proto.data = rxMsg->Data[2]; |
| 695 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
708 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
| 696 | irTxChannel[channel].proto.data |= rxMsg->Data[3]; |
709 | irTxChannel[channel].proto.data |= rxMsg->Data[3]; |
| 697 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
710 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
| 698 | irTxChannel[channel].proto.data |= rxMsg->Data[4]; |
711 | irTxChannel[channel].proto.data |= rxMsg->Data[4]; |
| 699 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
712 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
| 700 | irTxChannel[channel].proto.data |= rxMsg->Data[5]; |
713 | irTxChannel[channel].proto.data |= rxMsg->Data[5]; |
| Line 720... | Line 733... | ||
| 720 | uint8_t channel = rxMsg->Data[0]>>4; |
733 | uint8_t channel = rxMsg->Data[0]>>4; |
| 721 | if (channel >= IR_SUPPORTED_NUM_CHANNELS) { |
734 | if (channel >= IR_SUPPORTED_NUM_CHANNELS) { |
| 722 | // invalid channel |
735 | // invalid channel |
| 723 | break; |
736 | break; |
| 724 | } |
737 | } |
| - | 738 | ||
| - | 739 | printf("TxSt=%03d", irTxChannel[channel].state); |
|
| 725 | 740 | ||
| 726 | if (irTxChannel[channel].state != sns_irTransceive_STATE_IDLE) { |
741 | if (irTxChannel[channel].state != sns_irTransceive_STATE_IDLE) { |
| 727 | // busy |
742 | // busy |
| 728 | break; |
743 | break; |
| 729 | } |
744 | } |
| Line 733... | Line 748... | ||
| 733 | if (format != 0) { |
748 | if (format != 0) { |
| 734 | // unsupported format |
749 | // unsupported format |
| 735 | break; |
750 | break; |
| 736 | } |
751 | } |
| 737 | 752 | ||
| 738 | irTxChannel[channel].state = |
753 | irTxChannel[channel].state = sns_irTransceive_STATE_PREPARING_PRONTO; |
| 739 | irTxChannel[channel].txlen = 0; |
754 | irTxChannel[channel].txlen = 0; |
| 740 | 755 | ||
| 741 | //irTxChannel[channel].modfreq = rxMsg->Data[2]; |
756 | //irTxChannel[channel].modfreq = rxMsg->Data[2]; |
| 742 | irTxChannel[channel].modfreq = (((F_CPU/2000)/IR_NEC_F_MOD) -1); // for testing |
757 | irTxChannel[channel].modfreq = (((F_CPU/2000)/IR_NEC_F_MOD) -1); // for testing |
| 743 | irTxChannel[channel].proto.modfreq = (((F_CPU/2000)/IR_NEC_F_MOD) -1); |
758 | irTxChannel[channel].proto.modfreq = (((F_CPU/2000)/IR_NEC_F_MOD) -1); |
| 744 | irTxChannel[channel].proto.timeout = |
759 | irTxChannel[channel].proto.timeout = 100; |
| 745 | irTxChannel[channel].proto.repeats = |
760 | irTxChannel[channel].proto.repeats = 2; |
| 746 | 761 | ||
| 747 | irTxChannel[channel].onceSeqLen = rxMsg->Data[3]; |
762 | irTxChannel[channel].onceSeqLen = rxMsg->Data[3]; |
| 748 | irTxChannel[channel].repSeqLen = rxMsg->Data[4]; |
763 | irTxChannel[channel].repSeqLen = rxMsg->Data[4]; |
| 749 | 764 | ||
| 750 | activeChannel = channel; |
765 | activeChannel = channel; |
| Line 781... | Line 796... | ||
| 781 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA15: /* Fall through */ |
796 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA15: /* Fall through */ |
| 782 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA16: { |
797 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA16: { |
| 783 | if (activeChannel>=IR_SUPPORTED_NUM_CHANNELS) { |
798 | if (activeChannel>=IR_SUPPORTED_NUM_CHANNELS) { |
| 784 | break; |
799 | break; |
| 785 | } |
800 | } |
| 786 | if (irTxChannel[activeChannel].state!= |
801 | if (irTxChannel[activeChannel].state!=sns_irTransceive_STATE_PREPARING_PRONTO) { |
| 787 | // invalid state |
802 | // invalid state |
| 788 | break; |
803 | break; |
| 789 | } |
804 | } |
| 790 | if ((uint16_t)irTxChannel[activeChannel].txlen+(uint16_t)rxMsg->Length >= MAX_NR_TIMES) { |
805 | if ((uint16_t)irTxChannel[activeChannel].txlen+(uint16_t)rxMsg->Length >= MAX_NR_TIMES) { |
| 791 | // too long |
806 | // too long |
| Line 816... | Line 831... | ||
| 816 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND16: /* Fall through */ |
831 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND16: /* Fall through */ |
| 817 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND17: { |
832 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND17: { |
| 818 | if (activeChannel>=IR_SUPPORTED_NUM_CHANNELS) { |
833 | if (activeChannel>=IR_SUPPORTED_NUM_CHANNELS) { |
| 819 | break; |
834 | break; |
| 820 | } |
835 | } |
| 821 | if (irTxChannel[activeChannel].state!= |
836 | if (irTxChannel[activeChannel].state!=sns_irTransceive_STATE_PREPARING_PRONTO) { |
| 822 | // invalid state |
837 | // invalid state |
| 823 | break; |
838 | break; |
| 824 | } |
839 | } |
| 825 | if ((uint16_t)irTxChannel[activeChannel].txlen + (uint16_t)(rxMsg->Length-1) >= MAX_NR_TIMES) { |
840 | if ((uint16_t)irTxChannel[activeChannel].txlen + (uint16_t)(rxMsg->Length-1) >= MAX_NR_TIMES) { |
| 826 | // too long |
841 | // too long |
| Line 833... | Line 848... | ||
| 833 | } |
848 | } |
| 834 | // last byte tells what to do with IR data (nr of repeats) |
849 | // last byte tells what to do with IR data (nr of repeats) |
| 835 | irTxChannel[activeChannel].numberOfRepeats = rxMsg->Data[rxMsg->Length-1]; |
850 | irTxChannel[activeChannel].numberOfRepeats = rxMsg->Data[rxMsg->Length-1]; |
| 836 | 851 | ||
| 837 | // send |
852 | // send |
| 838 | //IrTransceiver_Transmit(activeChannel, irTxChannel[activeChannel].txbuf, 0, irTxChannel[activeChannel].txlen); |
- | |
| 839 | irTxChannel[activeChannel].state = |
853 | irTxChannel[activeChannel].state = sns_irTransceive_STATE_START_TRANSMIT_PRONTO; |
| 840 | 854 | ||
| 841 |
|
855 | irTxChannel[activeChannel].sendingPronto = TRUE; |
| 842 | 856 | ||
| 843 | /* TODO: Send response frame */ |
857 | /* TODO: Send response frame */ |
| 844 | 858 | ||
| 845 | break; |
859 | break; |
| 846 | } |
860 | } |