Rev 617 | Rev 732 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 617 | Rev 727 | ||
|---|---|---|---|
| Line 4... | Line 4... | ||
| 4 | * @date 2006-12-10 |
4 | * @date 2006-12-10 |
| 5 | * |
5 | * |
| 6 | * @author Anders Runeson, Andreas Fritiofson |
6 | * @author Anders Runeson, Andreas Fritiofson |
| 7 | * |
7 | * |
| 8 | */ |
8 | */ |
| - | 9 | ||
| - | 10 | #include <bios.h> //FIXME: Ta bort mig, jag finns bara fr debug av noddans RC6 |
|
| 9 | 11 | ||
| 10 | #include "protocols.h" |
12 | #include "protocols.h" |
| 11 | 13 | ||
| 12 | int8_t parseProtocol(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) { |
14 | int8_t parseProtocol(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) { |
| 13 | proto->protocol=IR_PROTO_UNKNOWN; |
15 | proto->protocol=IR_PROTO_UNKNOWN; |
| Line 100... | Line 102... | ||
| 100 | if (buf[i] > IR_SIRC_HIGH_ONE - IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV && buf[i] < IR_SIRC_HIGH_ONE + IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV) { |
102 | if (buf[i] > IR_SIRC_HIGH_ONE - IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV && buf[i] < IR_SIRC_HIGH_ONE + IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV) { |
| 101 | /* write a one */ |
103 | /* write a one */ |
| 102 | rawbits |= 1<<((i-2)>>1); |
104 | rawbits |= 1<<((i-2)>>1); |
| 103 | } else if (buf[i] > IR_SIRC_HIGH_ZERO - IR_SIRC_HIGH_ZERO/IR_SIRC_TOL_DIV && buf[i] < IR_SIRC_HIGH_ZERO + IR_SIRC_HIGH_ZERO/IR_SIRC_TOL_DIV) { |
105 | } else if (buf[i] > IR_SIRC_HIGH_ZERO - IR_SIRC_HIGH_ZERO/IR_SIRC_TOL_DIV && buf[i] < IR_SIRC_HIGH_ZERO + IR_SIRC_HIGH_ZERO/IR_SIRC_TOL_DIV) { |
| 104 | /* do nothing, a zero is already in rawbits */ |
106 | /* do nothing, a zero is already in rawbits */ |
| 105 | } else { |
107 | } else { |
| 106 | return IR_NOT_CORRECT_DATA; |
108 | return IR_NOT_CORRECT_DATA; |
| 107 | } |
109 | } |
| 108 | } |
110 | } |
| 109 | } |
111 | } |
| 110 | 112 | ||
| 111 | proto->protocol = IR_PROTO_SIRC; |
113 | proto->protocol = IR_PROTO_SIRC; |
| 112 | proto->timeout = IR_SIRC_TIMEOUT; |
114 | proto->timeout = IR_SIRC_TIMEOUT; |
| Line 117... | Line 119... | ||
| 117 | #endif |
119 | #endif |
| 118 | 120 | ||
| 119 | /** |
121 | /** |
| 120 | * Expand data from SIRC protocol |
122 | * Expand data from SIRC protocol |
| 121 | * http://www.sbprojects.com/knowledge/ir/sirc.htm |
123 | * http://www.sbprojects.com/knowledge/ir/sirc.htm |
| 122 | * |
124 | * |
| 123 | * @param buf |
125 | * @param buf |
| 124 | * Pointer to buffer to store the expanded data |
126 | * Pointer to buffer to store the expanded data |
| 125 | * @param len |
127 | * @param len |
| 126 | * Pointer to length of the data |
128 | * Pointer to length of the data |
| 127 | * @param proto |
129 | * @param proto |
| 128 | * Pointer to protocol information |
130 | * Pointer to protocol information |
| 129 | * @return |
131 | * @return |
| 130 | * IR_OK if data expanded successfully, one of several errormessages if not |
132 | * IR_OK if data expanded successfully, one of several errormessages if not |
| 131 | */ |
133 | */ |
| 132 | int8_t expandSIRC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) { |
134 | int8_t expandSIRC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) { |
| 133 | //TODO: Implement this function. |
135 | //TODO: Implement this function. |
| 134 | return IR_NOT_CORRECT_DATA; |
136 | return IR_NOT_CORRECT_DATA; |
| Line 194... | Line 196... | ||
| 194 | * Pointer to protocol information |
196 | * Pointer to protocol information |
| 195 | * @return |
197 | * @return |
| 196 | * IR_OK if data expanded successfully, one of several errormessages if not |
198 | * IR_OK if data expanded successfully, one of several errormessages if not |
| 197 | */ |
199 | */ |
| 198 | int8_t expandRC5(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) { |
200 | int8_t expandRC5(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) { |
| - | 201 | uint8_t tempadress; |
|
| - | 202 | uint8_t tempcommand; |
|
| - | 203 | uint8_t previousBit; |
|
| - | 204 | ||
| 199 | //TODO: Implement this function. |
205 | //TODO: Implement this function. Martin testar! |
| - | 206 | /* Set up startbit */ |
|
| - | 207 | buf[0] = 0; // no start-one |
|
| - | 208 | buf[1] = IR_RC5_HALF_BIT; |
|
| - | 209 | buf[2] = IR_RC5_HALF_BIT;//first start bit |
|
| - | 210 | buf[3] = IR_RC5_HALF_BIT; |
|
| - | 211 | buf[4] = IR_RC5_HALF_BIT;//second start bit |
|
| - | 212 | ||
| - | 213 | #define Toggle 0 //TODO: Fix toggle in some proper way |
|
| - | 214 | if (Toggle==0){ |
|
| - | 215 | buf[5] = IR_RC5_HALF_BIT; |
|
| - | 216 | buf[6] = IR_RC5_HALF_BIT; //toggle bit (yes i know it should not be hardcoded) |
|
| - | 217 | *len = 7; |
|
| - | 218 | } else { |
|
| - | 219 | buf[4] = IR_RC5_BIT; |
|
| - | 220 | buf[5] = IR_RC5_HALF_BIT; |
|
| - | 221 | *len = 6; |
|
| - | 222 | } |
|
| - | 223 | ||
| - | 224 | ||
| - | 225 | previousBit = 1; |
|
| - | 226 | ||
| - | 227 | //let's start with the adress bits.. |
|
| - | 228 | tempadress = (proto->data>>8)&(0b00011111); |
|
| - | 229 | tempcommand = proto->data&(0b00111111); |
|
| - | 230 | ||
| - | 231 | ||
| - | 232 | Can_Message_t txMsg; |
|
| - | 233 | txMsg.Id = (CAN_NMT_APP_START << CAN_SHIFT_NMT_TYPE) | (NODE_ID << CAN_SHIFT_NMT_SID); |
|
| - | 234 | txMsg.DataLength = 5; |
|
| - | 235 | txMsg.RemoteFlag = 0; |
|
| - | 236 | txMsg.ExtendedFlag = 1; |
|
| - | 237 | txMsg.Data.words[0] = tempadress; |
|
| - | 238 | //txMsg.Data.words[1] = tempcommand; |
|
| - | 239 | //txMsg.Data.words[2] = *len+3; |
|
| - | 240 | //BIOS_CanSend(&txMsg); |
|
| - | 241 | ||
| - | 242 | tempadress = tempadress<<2; |
|
| - | 243 | ||
| - | 244 | for(uint8_t i = 0; i < 5; i++) { |
|
| - | 245 | tempadress = tempadress<<1; |
|
| - | 246 | //temptemp = tempadress&0xA0; |
|
| - | 247 | if (((tempadress&(0xA0))>>7)==1){ |
|
| - | 248 | if (previousBit == 1){//11 |
|
| - | 249 | buf[*len] = IR_RC5_HALF_BIT; |
|
| - | 250 | buf[*len+1] = IR_RC5_HALF_BIT; |
|
| - | 251 | *len = *len + 2; |
|
| - | 252 | } else {//01 |
|
| - | 253 | buf[*len-1] = IR_RC5_BIT; |
|
| - | 254 | buf[*len] = IR_RC5_HALF_BIT; |
|
| - | 255 | *len = *len + 1; |
|
| - | 256 | } |
|
| - | 257 | previousBit = 1; |
|
| - | 258 | } else {//10 |
|
| - | 259 | if (previousBit == 1){ |
|
| - | 260 | buf[*len-1] = IR_RC5_BIT; |
|
| - | 261 | buf[*len] = IR_RC5_HALF_BIT; |
|
| - | 262 | *len = *len + 1; |
|
| - | 263 | } else {//00 |
|
| - | 264 | buf[*len] = IR_RC5_HALF_BIT; |
|
| - | 265 | buf[*len+1] = IR_RC5_HALF_BIT; |
|
| - | 266 | *len = *len + 2; |
|
| - | 267 | } |
|
| - | 268 | previousBit = 0; |
|
| - | 269 | } |
|
| - | 270 | } |
|
| - | 271 | ||
| - | 272 | txMsg.DataLength = 6; |
|
| - | 273 | ||
| - | 274 | tempcommand = tempcommand << 1; |
|
| - | 275 | ||
| - | 276 | for(uint8_t i = 0; i < 6; i++) { |
|
| - | 277 | tempcommand = tempcommand<<1; |
|
| - | 278 | //temptemp = tempadress&0xA0; |
|
| - | 279 | if (((tempcommand&(0xA0))>>7)==1){ |
|
| - | 280 | if (previousBit == 1){//11 |
|
| - | 281 | buf[*len] = IR_RC5_HALF_BIT; |
|
| - | 282 | buf[*len+1] = IR_RC5_HALF_BIT; |
|
| - | 283 | *len = *len + 2; |
|
| - | 284 | } else {//01 |
|
| - | 285 | buf[*len-1] = IR_RC5_BIT; |
|
| - | 286 | buf[*len] = IR_RC5_HALF_BIT; |
|
| - | 287 | *len = *len + 1; |
|
| - | 288 | } |
|
| - | 289 | previousBit = 1; |
|
| - | 290 | } else {//10 |
|
| - | 291 | if (previousBit == 1){ |
|
| - | 292 | buf[*len-1] = IR_RC5_BIT; |
|
| - | 293 | buf[*len] = IR_RC5_HALF_BIT; |
|
| - | 294 | *len = *len + 1; |
|
| - | 295 | } else {//00 |
|
| - | 296 | buf[*len] = IR_RC5_HALF_BIT; |
|
| - | 297 | buf[*len+1] = IR_RC5_HALF_BIT; |
|
| - | 298 | *len = *len + 2; |
|
| - | 299 | } |
|
| - | 300 | previousBit = 0; |
|
| - | 301 | } |
|
| - | 302 | } |
|
| - | 303 | ||
| - | 304 | /* |
|
| - | 305 | //time for the command then! |
|
| - | 306 | for(uint8_t i = 0; i < 6; i++) { |
|
| - | 307 | tempcommand = tempcommand << 1; |
|
| - | 308 | if (((tempcommand&0xA0)>>7)==1){ |
|
| - | 309 | buf[*len] = 3; //zero at the start |
|
| - | 310 | buf[*len+1] = IR_RC5_HALF_BIT; //keep it low |
|
| - | 311 | buf[*len+2] = IR_RC5_HALF_BIT; //and then, make it high |
|
| - | 312 | buf[*len+3] = 3; //and then we waste another cycle low to get in sync |
|
| - | 313 | *len = *len + 4; |
|
| - | 314 | } else { |
|
| - | 315 | buf[*len] = IR_RC5_HALF_BIT; |
|
| - | 316 | buf[*len+1] = IR_RC5_HALF_BIT; |
|
| - | 317 | *len = *len + 2; |
|
| - | 318 | } |
|
| - | 319 | |
|
| - | 320 | } |
|
| - | 321 | */ |
|
| - | 322 | proto->modfreq=(((F_CPU/2000)/IR_RC5_F_MOD) -1); |
|
| - | 323 | proto->timeout=IR_RC5_TIMEOUT; |
|
| - | 324 | proto->repeats=IR_RC5_REPS; |
|
| - | 325 | return IR_OK; |
|
| 200 |
|
326 | //return IR_NOT_CORRECT_DATA; |
| 201 | } |
327 | } |
| 202 | 328 | ||
| 203 | 329 | ||
| 204 | #if (IR_PROTOCOLS_USE_SHARP) |
330 | #if (IR_PROTOCOLS_USE_SHARP) |
| 205 | /** |
331 | /** |