Rev 2200 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2200 | Rev 2236 | ||
|---|---|---|---|
| Line 91... | Line 91... | ||
| 91 | #endif |
91 | #endif |
| 92 | } |
92 | } |
| 93 | 93 | ||
| 94 | 94 | ||
| 95 | ///////////// DEBUG!!!! |
95 | ///////////// DEBUG!!!! |
| 96 | #if |
96 | #if (sns_rfTransceive_SEND_DEBUG==1) |
| 97 | StdCan_Msg_t irTxMsg; |
97 | StdCan_Msg_t irTxMsg; |
| 98 | void send_debug(uint16_t *buffer, uint8_t |
98 | void send_debug(uint16_t *buffer, uint8_t startindex, uint8_t endindex) { |
| 99 | 99 | ||
| 100 | /* the protocol is unknown so the raw ir-data is sent, makes it easier to develop a new protocol */ |
100 | /* the protocol is unknown so the raw ir-data is sent, makes it easier to develop a new protocol */ |
| 101 | 101 | ||
| 102 | StdCan_Set_class(irTxMsg.Header, CAN_MODULE_CLASS_SNS); |
102 | StdCan_Set_class(irTxMsg.Header, CAN_MODULE_CLASS_SNS); |
| 103 | StdCan_Set_direction(irTxMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
103 | StdCan_Set_direction(irTxMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
| 104 | irTxMsg.Length = 8; |
104 | irTxMsg.Length = 8; |
| 105 | irTxMsg.Header.ModuleType = |
105 | irTxMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_RFTRANSCEIVE; |
| 106 | irTxMsg.Header.ModuleId = 0; |
106 | irTxMsg.Header.ModuleId = 0; |
| 107 | irTxMsg.Header.Command = CAN_MODULE_CMD_IRRECEIVE_IRRAW; |
107 | irTxMsg.Header.Command = CAN_MODULE_CMD_IRRECEIVE_IRRAW; |
| 108 |
|
108 | while (StdCan_Put(&irTxMsg) != StdCan_Ret_OK) {} |
| - | 109 | _delay_ms(1); |
|
| - | 110 | //_------------------ |
|
| 109 |
|
111 | uint8_t i= startindex; |
| 110 | - | ||
| - | 112 | while(i != endindex) { |
|
| - | 113 | irTxMsg.Length = 2; |
|
| 111 |
|
114 | irTxMsg.Data[0] = (buffer[i]>>8)&0xff; |
| 112 |
|
115 | irTxMsg.Data[1] = (buffer[i]>>0)&0xff; |
| - | 116 | i++; |
|
| - | 117 | if (i == MAX_NR_TIMES) { |
|
| - | 118 | i=0; |
|
| - | 119 | } |
|
| - | 120 | if(i != endindex) { |
|
| - | 121 | irTxMsg.Length = 4; |
|
| 113 | irTxMsg.Data[2] = (buffer[ |
122 | irTxMsg.Data[2] = (buffer[i]>>8)&0xff; |
| 114 | irTxMsg.Data[3] = (buffer[ |
123 | irTxMsg.Data[3] = (buffer[i]>>0)&0xff; |
| - | 124 | i++; |
|
| - | 125 | if (i == MAX_NR_TIMES) { |
|
| - | 126 | i=0; |
|
| - | 127 | } |
|
| - | 128 | if(i != endindex) { |
|
| - | 129 | irTxMsg.Length = 6; |
|
| 115 | irTxMsg.Data |
130 | irTxMsg.Data[4] = (buffer[i]>>8)&0xff; |
| 116 | irTxMsg.Data |
131 | irTxMsg.Data[5] = (buffer[i]>>0)&0xff; |
| - | 132 | i++; |
|
| - | 133 | if (i == MAX_NR_TIMES) { |
|
| - | 134 | i=0; |
|
| - | 135 | } |
|
| - | 136 | if(i != endindex) { |
|
| - | 137 | irTxMsg.Length = 8; |
|
| 117 | irTxMsg.Data[6] = (buffer[ |
138 | irTxMsg.Data[6] = (buffer[i]>>8)&0xff; |
| 118 | irTxMsg.Data[7] = (buffer[ |
139 | irTxMsg.Data[7] = (buffer[i]>>0)&0xff; |
| - | 140 | i++; |
|
| - | 141 | if (i == MAX_NR_TIMES) { |
|
| - | 142 | i=0; |
|
| 119 | 143 | } |
|
| - | 144 | } |
|
| - | 145 | } |
|
| - | 146 | } |
|
| 120 | /* buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
147 | /* buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
| 121 | while (StdCan_Put(&irTxMsg) != StdCan_Ret_OK) {} |
148 | while (StdCan_Put(&irTxMsg) != StdCan_Ret_OK) {} |
| 122 | _delay_ms(1); |
149 | _delay_ms(1); |
| 123 | } |
150 | } |
| 124 | - | ||
| 125 | uint8_t lastpacketcnt = len&0x03; |
- | |
| 126 | if (lastpacketcnt > 0) { |
- | |
| 127 | irTxMsg.Length = lastpacketcnt<<1; |
- | |
| 128 | for (uint8_t i = 0; i < lastpacketcnt; i++) { |
- | |
| 129 | irTxMsg.Data[i<<1] = (buffer[(len&0xfc)|i]>>8)&0xff; |
- | |
| 130 | irTxMsg.Data[(i<<1)+1] = (buffer[(len&0xfc)|i]>>0)&0xff; |
- | |
| 131 | } |
- | |
| 132 | /* buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
- | |
| 133 | while (StdCan_Put(&irTxMsg) != StdCan_Ret_OK) {} |
- | |
| 134 | _delay_ms(1); |
- | |
| 135 | } |
- | |
| 136 | - | ||
| 137 | } |
151 | } |
| 138 | #endif |
152 | #endif |
| 139 | 153 | ||
| 140 | void sns_rfTransceive_Process(void) |
154 | void sns_rfTransceive_Process(void) |
| 141 | { |
155 | { |
| 142 | #if IR_RX_ENABLE==1 |
156 | #if IR_RX_ENABLE==1 |
| 143 | switch (rfRxChannel_state) |
157 | switch (rfRxChannel_state) |
| Line 156... | Line 170... | ||
| 156 | rfRxChannel_state = sns_rfTransceive_STATE_START_RECEIVE; |
170 | rfRxChannel_state = sns_rfTransceive_STATE_START_RECEIVE; |
| 157 | break; |
171 | break; |
| 158 | } |
172 | } |
| 159 | 173 | ||
| 160 | case sns_rfTransceive_STATE_START_RECEIVE: |
174 | case sns_rfTransceive_STATE_START_RECEIVE: |
| 161 | cli(); |
175 | cli(); |
| 162 | rfRxChannel_newData = FALSE; |
176 | rfRxChannel_newData = FALSE; |
| 163 | sei(); |
177 | sei(); |
| 164 | rfRxChannel_state = sns_rfTransceive_STATE_RECEIVING; |
178 | rfRxChannel_state = sns_rfTransceive_STATE_RECEIVING; |
| 165 | 179 | ||
| 166 | break; |
180 | break; |
| Line 179... | Line 193... | ||
| 179 | /* If timeout is 0, protocol is burst protocol */ |
193 | /* If timeout is 0, protocol is burst protocol */ |
| 180 | if (rfRxChannel_proto.timeout > 0) |
194 | if (rfRxChannel_proto.timeout > 0) |
| 181 | { |
195 | { |
| 182 | rfTxMsg.Data[0] = CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED; |
196 | rfTxMsg.Data[0] = CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED; |
| 183 | rfRxChannel_state = sns_rfTransceive_STATE_START_PAUSE; |
197 | rfRxChannel_state = sns_rfTransceive_STATE_START_PAUSE; |
| 184 | } |
198 | } |
| 185 | else |
199 | else |
| 186 | { |
200 | { |
| 187 | rfTxMsg.Data[0] = CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_BURST; |
201 | rfTxMsg.Data[0] = CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_BURST; |
| 188 | rfRxChannel_state = sns_rfTransceive_STATE_START_RECEIVE; |
202 | rfRxChannel_state = sns_rfTransceive_STATE_START_RECEIVE; |
| 189 | } |
203 | } |
| Line 203... | Line 217... | ||
| 203 | //send_debug(rfRxChannel_buf, rfRxChannel_len); |
217 | //send_debug(rfRxChannel_buf, rfRxChannel_len); |
| 204 | //rfRxChannel_proto.timeout=300; |
218 | //rfRxChannel_proto.timeout=300; |
| 205 | #endif |
219 | #endif |
| 206 | rfRxChannel_state = sns_rfTransceive_STATE_START_RECEIVE; |
220 | rfRxChannel_state = sns_rfTransceive_STATE_START_RECEIVE; |
| 207 | } |
221 | } |
| - | 222 | #if (sns_rfTransceive_SEND_DEBUG==1) |
|
| - | 223 | else if (res2 == IR_SEND_DEBUG) |
|
| - | 224 | { |
|
| - | 225 | send_debug(rfRxChannel_buf, rfRxChannel_proto.data & 0xFFu, rfRxChannel_index); |
|
| - | 226 | rfRxChannel_state = sns_rfTransceive_STATE_START_RECEIVE; |
|
| - | 227 | } |
|
| - | 228 | #endif |
|
| 208 | } |
229 | } |
| 209 | break; |
230 | break; |
| 210 | 231 | ||
| 211 | case sns_rfTransceive_STATE_START_PAUSE: |
232 | case sns_rfTransceive_STATE_START_PAUSE: |
| 212 | /* set a timer so we can send release button event when no new RF is arriving */ |
233 | /* set a timer so we can send release button event when no new RF is arriving */ |