Rev 1856 | Rev 1861 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1856 | Rev 1858 | ||
|---|---|---|---|
| Line 717... | Line 717... | ||
| 717 | /* Start IR transmission. */ |
717 | /* Start IR transmission. */ |
| 718 | IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, 0, irTxChannel[channel].onceSeqLen - 1); |
718 | IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, 0, irTxChannel[channel].onceSeqLen - 1); |
| 719 | 719 | ||
| 720 | /* Enter transmitting state. */ |
720 | /* Enter transmitting state. */ |
| 721 | irTxChannel[channel].sendingPronto = TRUE; |
721 | irTxChannel[channel].sendingPronto = TRUE; |
| - | 722 | irTxChannel[channel].stopSend = FALSE; |
|
| 722 | irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMITTING; |
723 | irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMITTING; |
| 723 | break; |
724 | break; |
| 724 | } |
725 | } |
| 725 | 726 | ||
| 726 | case sns_irTransceive_STATE_PRONTO_REPEAT: |
727 | case sns_irTransceive_STATE_PRONTO_REPEAT: |
| 727 | { |
728 | { |
| 728 | /* Check if done. */ |
729 | /* Check if done. */ |
| 729 | if ((irTxChannel[channel].repeatCount >= irTxChannel[channel].proto.repeats && irTxChannel[channel].proto.repeats != 0xFF) || irTxChannel[channel].stopSend) { |
730 | if ((irTxChannel[channel].repeatCount >= irTxChannel[channel].proto.repeats && irTxChannel[channel].proto.repeats != 0xFF) || irTxChannel[channel].stopSend) { |
| 730 | /* Pronto transmission was stopped/completed */ |
731 | /* Pronto transmission was stopped/completed */ |
| Line 748... | Line 749... | ||
| 748 | /* Use once seq */ |
749 | /* Use once seq */ |
| 749 | /* Don't transmit last passive. last passive handled by timer */ |
750 | /* Don't transmit last passive. last passive handled by timer */ |
| 750 | IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, 0, irTxChannel[channel].txlen - 1); |
751 | IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, 0, irTxChannel[channel].txlen - 1); |
| 751 | } |
752 | } |
| 752 | irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMITTING; |
753 | irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMITTING; |
| 753 | } |
754 | } |
| 754 | 755 | ||
| 755 | case sns_irTransceive_STATE_TRANSMITTING: |
756 | case sns_irTransceive_STATE_TRANSMITTING: |
| 756 | { |
757 | { |
| 757 | if (irTxChannel[channel].sendComplete == TRUE) |
758 | if (irTxChannel[channel].sendComplete == TRUE) |
| 758 | { |
759 | { |
| Line 768... | Line 769... | ||
| 768 | /* Use last passive time as timeout */ |
769 | /* Use last passive time as timeout */ |
| 769 | uint16_t lastPasTime = irTxChannel[channel].txbuf[irTxChannel[channel].onceSeqLen - 1] / 1000; |
770 | uint16_t lastPasTime = irTxChannel[channel].txbuf[irTxChannel[channel].onceSeqLen - 1] / 1000; |
| 770 | Timer_SetTimeout(irTxChannel[channel].timerNum, lastPasTime==0 ? 1 : lastPasTime, TimerTypeOneShot, 0); |
771 | Timer_SetTimeout(irTxChannel[channel].timerNum, lastPasTime==0 ? 1 : lastPasTime, TimerTypeOneShot, 0); |
| 771 | } |
772 | } |
| 772 | /* Second, or later repeat => use last passive time in repeat seq */ |
773 | /* Second, or later repeat => use last passive time in repeat seq */ |
| 773 | else |
774 | else |
| 774 | { |
775 | { |
| 775 | /* Use last passive time as timeout */ |
776 | /* Use last passive time as timeout */ |
| 776 | uint16_t lastPasTime = irTxChannel[channel].txbuf[irTxChannel[channel].txlen - 1] / 1000; |
777 | uint16_t lastPasTime = irTxChannel[channel].txbuf[irTxChannel[channel].txlen - 1] / 1000; |
| 777 | Timer_SetTimeout(irTxChannel[channel].timerNum, lastPasTime==0 ? 1 : lastPasTime, TimerTypeOneShot, 0); |
778 | Timer_SetTimeout(irTxChannel[channel].timerNum, lastPasTime==0 ? 1 : lastPasTime, TimerTypeOneShot, 0); |
| 778 | } |
779 | } |
| Line 780... | Line 781... | ||
| 780 | } |
781 | } |
| 781 | else |
782 | else |
| 782 | { |
783 | { |
| 783 | irTxChannel[channel].state = sns_irTransceive_STATE_START_PAUSE; |
784 | irTxChannel[channel].state = sns_irTransceive_STATE_START_PAUSE; |
| 784 | } |
785 | } |
| 785 | } |
786 | } |
| 786 | break; |
787 | break; |
| 787 | } |
788 | } |
| 788 | 789 | ||
| 789 | case sns_irTransceive_STATE_START_PAUSE: |
790 | case sns_irTransceive_STATE_START_PAUSE: |
| 790 | { |
791 | { |
| 791 | if (irTxChannel[channel].repeatCount < irTxChannel[channel].proto.repeats) |
792 | if (irTxChannel[channel].repeatCount < irTxChannel[channel].proto.repeats) |
| 792 | { |
793 | { |
| 793 | irTxChannel[channel].repeatCount++; |
794 | irTxChannel[channel].repeatCount++; |
| 794 | } |
795 | } |
| 795 | 796 | ||
| 796 | Timer_SetTimeout(irTxChannel[channel].timerNum, irTxChannel[channel].proto.timeout, TimerTypeOneShot, 0); |
797 | Timer_SetTimeout(irTxChannel[channel].timerNum, irTxChannel[channel].proto.timeout, TimerTypeOneShot, 0); |
| 797 | 798 | ||
| 798 | if (irTxChannel[channel].proto.framecnt != 255) |
799 | if (irTxChannel[channel].proto.framecnt != 255) |
| 799 | { |
800 | { |
| 800 | irTxChannel[channel].proto.framecnt++; |
801 | irTxChannel[channel].proto.framecnt++; |
| 801 | } |
802 | } |
| 802 | 803 | ||
| 803 | irTxChannel[channel].state = sns_irTransceive_STATE_PAUSING; |
804 | irTxChannel[channel].state = sns_irTransceive_STATE_PAUSING; |
| 804 | break; |
805 | break; |
| 805 | } |
806 | } |
| 806 | 807 | ||
| 807 | case sns_irTransceive_STATE_PAUSING: |
808 | case sns_irTransceive_STATE_PAUSING: |
| 808 | { |
809 | { |
| 809 | if (irTxChannel[channel].sendingPronto) |
810 | if (irTxChannel[channel].sendingPronto) |
| 810 | { |
811 | { |
| 811 | if (Timer_Expired(irTxChannel[channel].timerNum)) |
812 | if (Timer_Expired(irTxChannel[channel].timerNum)) |
| 812 | { |
813 | { |
| 813 | irTxChannel[channel].state = sns_irTransceive_STATE_PRONTO_REPEAT; |
814 | irTxChannel[channel].state = sns_irTransceive_STATE_PRONTO_REPEAT; |
| 814 | } |
815 | } |
| 815 | break; |
816 | break; |
| 816 | } |
817 | } |
| 817 | 818 | ||
| 818 | if (Timer_Expired(irTxChannel[channel].timerNum)) |
819 | if (Timer_Expired(irTxChannel[channel].timerNum)) |
| 819 | { |
820 | { |
| 820 | irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT; |
821 | irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT; |
| 821 | } |
822 | } |
| Line 827... | Line 828... | ||
| 827 | /* TODO: Not sure we want this response when sending non-pronto data, but probably doesn't hurt? /jm */ |
828 | /* TODO: Not sure we want this response when sending non-pronto data, but probably doesn't hurt? /jm */ |
| 828 | pronto_sendResponse(channel, CAN_MODULE_ENUM_IRTRANSCEIVE_IRPRONTORESPONSE_RESPONSE_STOPPED); |
829 | pronto_sendResponse(channel, CAN_MODULE_ENUM_IRTRANSCEIVE_IRPRONTORESPONSE_RESPONSE_STOPPED); |
| 829 | 830 | ||
| 830 | irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE; |
831 | irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE; |
| 831 | } |
832 | } |
| 832 | break; |
833 | break; |
| 833 | } |
834 | } |
| 834 | 835 | ||
| 835 | case sns_irTransceive_STATE_START_IDLE: |
836 | case sns_irTransceive_STATE_START_IDLE: |
| 836 | irTxChannel[channel].stopSend = FALSE; |
837 | irTxChannel[channel].stopSend = FALSE; |
| 837 | irTxChannel[channel].repeatCount = 0; |
838 | irTxChannel[channel].repeatCount = 0; |
| 838 | irTxChannel[channel].proto.framecnt = 0; |
839 | irTxChannel[channel].proto.framecnt = 0; |
| Line 842... | Line 843... | ||
| 842 | 843 | ||
| 843 | default: |
844 | default: |
| 844 | break; |
845 | break; |
| 845 | } |
846 | } |
| 846 | #endif |
847 | #endif |
| 847 | 848 | ||
| 848 | } |
- | |
| 849 | } |
849 | } |
| - | 850 | } |
|
| 850 | 851 | ||
| 851 | 852 | ||
| 852 | /* Handle incoming CAN data */ |
853 | /* Handle incoming CAN data */ |
| 853 | void sns_irTransceive_HandleMessage(StdCan_Msg_t *rxMsg) |
854 | void sns_irTransceive_HandleMessage(StdCan_Msg_t *rxMsg) |
| 854 | { |
855 | { |
| 855 | /* Sanity check. */ |
856 | /* Sanity check. */ |
| 856 | if (StdCan_Ret_class(rxMsg->Header) != CAN_MODULE_CLASS_SNS || |
857 | if (StdCan_Ret_class(rxMsg->Header) != CAN_MODULE_CLASS_SNS || |
| 857 | StdCan_Ret_direction(rxMsg->Header) != DIRECTIONFLAG_TO_OWNER || |
858 | StdCan_Ret_direction(rxMsg->Header) != DIRECTIONFLAG_TO_OWNER || |
| 858 | rxMsg->Header.ModuleType != CAN_MODULE_TYPE_SNS_IRTRANSCEIVE || |
859 | rxMsg->Header.ModuleType != CAN_MODULE_TYPE_SNS_IRTRANSCEIVE || |
| 859 | rxMsg->Header.ModuleId != sns_irTransceive_ID) return; |
860 | rxMsg->Header.ModuleId != sns_irTransceive_ID) return; |
| 860 | 861 | ||
| 861 | switch (rxMsg->Header.Command) |
862 | switch (rxMsg->Header.Command) |
| 862 | { |
863 | { |
| 863 | #if IR_TX_ENABLE==1 |
864 | #if IR_TX_ENABLE==1 |
| 864 | case CAN_MODULE_CMD_PHYSICAL_IR: |
865 | case CAN_MODULE_CMD_PHYSICAL_IR: |
| 865 | { |
866 | { |
| 866 | /* Get IR channel. */ |
867 | /* Get IR channel. */ |
| 867 | uint8_t channel = rxMsg->Data[0] >> 4; |
868 | uint8_t channel = rxMsg->Data[0] >> 4; |
| 868 | 869 | ||
| 869 | /* Sanity check. */ |
870 | /* Sanity check. */ |
| 870 | if (channel >= IR_SUPPORTED_NUM_CHANNELS) { |
871 | if (channel >= IR_SUPPORTED_NUM_CHANNELS) { |
| 871 | /* Invalid channel */ |
872 | /* Invalid channel */ |
| 872 | break; |
873 | break; |
| 873 | } |
874 | } |
| 874 | 875 | ||
| 875 | if ((0xf&rxMsg->Data[0]) == CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED) |
876 | if ((0xf&rxMsg->Data[0]) == CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED) |
| 876 | { |
877 | { |
| 877 | if (irTxChannel[channel].state == sns_irTransceive_STATE_IDLE) |
878 | if (irTxChannel[channel].state == sns_irTransceive_STATE_IDLE) |
| 878 | { |
879 | { |
| 879 | irTxChannel[channel].proto.protocol = rxMsg->Data[1]; |
880 | irTxChannel[channel].proto.protocol = rxMsg->Data[1]; |
| 880 | 881 | ||
| 881 | irTxChannel[channel].proto.data = rxMsg->Data[2]; |
882 | irTxChannel[channel].proto.data = rxMsg->Data[2]; |
| 882 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
883 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
| 883 | irTxChannel[channel].proto.data |= rxMsg->Data[3]; |
884 | irTxChannel[channel].proto.data |= rxMsg->Data[3]; |
| 884 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
885 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
| 885 | irTxChannel[channel].proto.data |= rxMsg->Data[4]; |
886 | irTxChannel[channel].proto.data |= rxMsg->Data[4]; |
| 886 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
887 | irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8; |
| 887 | irTxChannel[channel].proto.data |= rxMsg->Data[5]; |
888 | irTxChannel[channel].proto.data |= rxMsg->Data[5]; |
| 888 | 889 | ||
| 889 | irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT; |
890 | irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT; |
| 890 | } |
891 | } |
| 891 | } |
892 | } |
| 892 | else if ((0xf&rxMsg->Data[0]) == CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_RELEASED) |
893 | else if ((0xf&rxMsg->Data[0]) == CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_RELEASED) |
| 893 | { |
894 | { |
| 894 | if (irTxChannel[channel].state != sns_irTransceive_STATE_IDLE) |
895 | if (irTxChannel[channel].state != sns_irTransceive_STATE_IDLE) |
| 895 | { |
896 | { |
| 896 | irTxChannel[channel].stopSend = TRUE; |
897 | irTxChannel[channel].stopSend = TRUE; |
| 897 | } |
898 | } |
| 898 | } |
899 | } |
| 899 | break; |
900 | break; |
| 900 | } |
901 | } |
| 901 | 902 | ||
| 902 | #if sns_irTransceive_PRONTO_SUPPORT==1 |
903 | #if sns_irTransceive_PRONTO_SUPPORT==1 |
| 903 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOSTART: |
904 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOSTART: |
| 904 | { |
905 | { |
| 905 | /* Get IR channel. */ |
906 | /* Get IR channel. */ |
| 906 | uint8_t channel = rxMsg->Data[0] >> 4; |
907 | uint8_t channel = rxMsg->Data[0] >> 4; |
| 907 | 908 | ||
| 908 | /* Sanity check. */ |
909 | /* Sanity check. */ |
| 909 | if (channel >= IR_SUPPORTED_NUM_CHANNELS) { |
910 | if (channel >= IR_SUPPORTED_NUM_CHANNELS) { |
| 910 | /* Invalid channel */ |
911 | /* Invalid channel */ |
| 911 | pronto_sendResponse(channel, CAN_MODULE_ENUM_IRTRANSCEIVE_IRPRONTORESPONSE_RESPONSE_ERROR); |
912 | pronto_sendResponse(channel, CAN_MODULE_ENUM_IRTRANSCEIVE_IRPRONTORESPONSE_RESPONSE_ERROR); |
| 912 | break; |
913 | break; |
| 913 | } |
914 | } |
| 914 | if (irTxChannel[channel].state != sns_irTransceive_STATE_IDLE) { |
915 | if (irTxChannel[channel].state != sns_irTransceive_STATE_IDLE) { |
| 915 | /* We're already transmitting on this channel */ |
916 | /* We're already transmitting on this channel */ |
| Line 968... | Line 969... | ||
| 968 | pronto_sendResponse(channel, CAN_MODULE_ENUM_IRTRANSCEIVE_IRPRONTORESPONSE_RESPONSE_ERROR); |
969 | pronto_sendResponse(channel, CAN_MODULE_ENUM_IRTRANSCEIVE_IRPRONTORESPONSE_RESPONSE_ERROR); |
| 969 | break; |
970 | break; |
| 970 | } |
971 | } |
| 971 | 972 | ||
| 972 | irTxChannel[channel].stopSend = TRUE; |
973 | irTxChannel[channel].stopSend = TRUE; |
| - | 974 | ||
| - | 975 | /* State check. If we're not currently transmitting anything, the STOPPED reponse will never occur. */ |
|
| - | 976 | /* TODO: better way to check this? /jm */ |
|
| - | 977 | if (irTxChannel[activeChannel].state != sns_irTransceive_STATE_START_TRANSMIT_PRONTO && |
|
| - | 978 | irTxChannel[activeChannel].state != sns_irTransceive_STATE_TRANSMITTING && |
|
| - | 979 | irTxChannel[activeChannel].state != sns_irTransceive_STATE_PRONTO_REPEAT && |
|
| - | 980 | irTxChannel[activeChannel].state != sns_irTransceive_STATE_PAUSING && |
|
| - | 981 | irTxChannel[activeChannel].state != sns_irTransceive_STATE_START_PAUSE) |
|
| - | 982 | { |
|
| - | 983 | /* Nothing to stop. Not in TX state. Respond that we're already stopped */ |
|
| - | 984 | pronto_sendResponse(activeChannel, CAN_MODULE_ENUM_IRTRANSCEIVE_IRPRONTORESPONSE_RESPONSE_ALREADYSTOPPED); |
|
| - | 985 | break; |
|
| - | 986 | } |
|
| 973 | 987 | ||
| 974 | /* Response will be sent when transmission has been completed (i.e. stopped) */ |
988 | /* Response will be sent when transmission has been completed (i.e. stopped) */ |
| 975 | break; |
989 | break; |
| 976 | } |
990 | } |
| 977 | 991 | ||