Subversion Repositories HomeAutomation

Rev

Rev 2260 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 2260 Rev 2297
Line 59... Line 59...
59
#if (IR_PROTOCOLS_USE_NEXA1)
59
#if (IR_PROTOCOLS_USE_NEXA1)
60
    if (parseNexa1(buf, len, index, proto)==IR_OK) return IR_OK;
60
    if (parseNexa1(buf, len, index, proto)==IR_OK) return IR_OK;
61
#endif
61
#endif
62
#if (IR_PROTOCOLS_USE_VIKING)
62
#if (IR_PROTOCOLS_USE_VIKING)
63
    if (parseViking(buf, len, index, proto)==IR_OK) return IR_OK;
63
    if (parseViking(buf, len, index, proto)==IR_OK) return IR_OK;
-
 
64
#endif
-
 
65
#if (IR_PROTOCOLS_USE_VIKING_T3)
-
 
66
    if (parseVikingT3(buf, len, index, proto)==IR_OK) return IR_OK;
64
#endif
67
#endif
65
#if (IR_PROTOCOLS_USE_VIKING_STEAK)
68
#if (IR_PROTOCOLS_USE_VIKING_STEAK)
66
    res = parseVikingSteak(buf, len, index, proto);
69
    res = parseVikingSteak(buf, len, index, proto);
67
    if (res!=IR_NOT_CORRECT_DATA) return res;
70
    if (res!=IR_NOT_CORRECT_DATA) return res;
68
#endif
71
#endif
69
#if (IR_PROTOCOLS_USE_RUBICSON)
72
#if (IR_PROTOCOLS_USE_RUBICSON)
70
    res = parseRubicson(buf, len, index, proto);
73
    res = parseRubicson(buf, len, index, proto);
71
    if (res!=IR_NOT_CORRECT_DATA) return res;
74
    if (res!=IR_NOT_CORRECT_DATA) return res;
72
#endif
75
#endif
73
#if (IR_PROTOCOLS_USE_OREGON)
76
#if (IR_PROTOCOLS_USE_OREGON)
74
   
77
   
75
    res = parseOregon(buf, len, index, proto);
78
    res = parseOregon(buf, len, index, proto);
76
    gpio_clr_pin(EXP_K);
79
    gpio_clr_pin(EXP_K);
77
    gpio_clr_pin(EXP_L);
80
    gpio_clr_pin(EXP_L);
78
    gpio_clr_pin(EXP_M);
81
    gpio_clr_pin(EXP_M);
79
    gpio_clr_pin(EXP_N);
82
    gpio_clr_pin(EXP_N);
80
    if (res!=IR_NOT_CORRECT_DATA) return res;
83
    if (res!=IR_NOT_CORRECT_DATA) return res;
81
#endif      
84
#endif      
82
   
85
   
83
    /* No protocol matched. */
86
    /* No protocol matched. */
84
    proto->protocol = IR_PROTO_UNKNOWN;
87
    proto->protocol = IR_PROTO_UNKNOWN;
85
    return IR_NOT_CORRECT_DATA;
88
    return IR_NOT_CORRECT_DATA;
86
}
89
}
87
 
90
 
88
int8_t parseHash(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
91
int8_t parseHash(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
89
    //TODO: Transform the buffer in some clever way to a 32 bit word. */
92
    //TODO: Transform the buffer in some clever way to a 32 bit word. */
90
    proto->protocol = IR_PROTO_HASH;
93
    proto->protocol = IR_PROTO_HASH;
Line 185... Line 188...
185
#endif
188
#endif
186
 
189
 
187
/**
190
/**
188
 * Expand data from SIRC protocol
191
 * Expand data from SIRC protocol
189
 * http://www.sbprojects.com/knowledge/ir/sirc.htm
192
 * http://www.sbprojects.com/knowledge/ir/sirc.htm
190
 *
193
 *
191
 * @param buf
194
 * @param buf
192
 *      Pointer to buffer to store the expanded data
195
 *      Pointer to buffer to store the expanded data
193
 * @param len
196
 * @param len
194
 *      Pointer to length of the data
197
 *      Pointer to length of the data
195
 * @param proto
198
 * @param proto
Line 228... Line 231...
228
 
231
 
229
 
232
 
230
#if (IR_PROTOCOLS_USE_RC5)
233
#if (IR_PROTOCOLS_USE_RC5)
231
/**
234
/**
232
 * Test data on RC5 protocol
235
 * Test data on RC5 protocol
233
 * http://www.sbprojects.com/knowledge/ir/rc5.htm
236
 * http://www.sbprojects.com/knowledge/ir/rc5.htm
234
 *
237
 *
235
 * @param buf
238
 * @param buf
236
 *      Pointer to buffer to where to data to parse is stored
239
 *      Pointer to buffer to where to data to parse is stored
237
 * @param len
240
 * @param len
238
 *      Length of the data
241
 *      Length of the data
239
 * @param proto
242
 * @param proto
240
 *      Pointer to protocol information
243
 *      Pointer to protocol information
241
 * @return
244
 * @return
242
 *      IR_OK if data parsed successfully, one of several errormessages if not
245
 *      IR_OK if data parsed successfully, one of several errormessages if not
243
 */
246
 */
244
int8_t parseRC5(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
247
int8_t parseRC5(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
245
    uint8_t halfbitscnt = 1;
248
    uint8_t halfbitscnt = 1;
246
    uint16_t rawbits = 0;
249
    uint16_t rawbits = 0;
247
   
250
   
248
    for (uint8_t i = 0; i<len; i++) {
251
    for (uint8_t i = 0; i<len; i++) {
249
        //halfbitscnt&1==1 in the middle of bits
252
        //halfbitscnt&1==1 in the middle of bits
250
        //i&1==0 positive flank
253
        //i&1==0 positive flank
251
 
254
 
252
        if ((halfbitscnt&1)==1 && (i&1)==0) {       /* in the middle of bit AND a positve flank */
255
        if ((halfbitscnt&1)==1 && (i&1)==0) {       /* in the middle of bit AND a positve flank */
253
            rawbits |= (1<<(13-(halfbitscnt>>1)));
256
            rawbits |= (1<<(13-(halfbitscnt>>1)));
254
        }
257
        }
255
       
258
       
256
        if (buf[i] > IR_RC5_HALF_BIT - IR_RC5_HALF_BIT/IR_RC5_TOL_DIV && buf[i] < IR_RC5_HALF_BIT + IR_RC5_HALF_BIT/IR_RC5_TOL_DIV) {
259
        if (buf[i] > IR_RC5_HALF_BIT - IR_RC5_HALF_BIT/IR_RC5_TOL_DIV && buf[i] < IR_RC5_HALF_BIT + IR_RC5_HALF_BIT/IR_RC5_TOL_DIV) {
257
            halfbitscnt += 1;
260
            halfbitscnt += 1;
258
        } else if (buf[i] > IR_RC5_BIT - IR_RC5_BIT/IR_RC5_TOL_DIV && buf[i] < IR_RC5_BIT + IR_RC5_BIT/IR_RC5_TOL_DIV) {
261
        } else if (buf[i] > IR_RC5_BIT - IR_RC5_BIT/IR_RC5_TOL_DIV && buf[i] < IR_RC5_BIT + IR_RC5_BIT/IR_RC5_TOL_DIV) {
259
            halfbitscnt += 2;
262
            halfbitscnt += 2;
260
        } else {
263
        } else {
261
            return IR_NOT_CORRECT_DATA;
264
            return IR_NOT_CORRECT_DATA;
262
        }
265
        }
263
       
266
       
264
    }
267
    }
265
 
268
 
266
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_RC5;
269
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_RC5;
267
    proto->timeout=IR_RC5_TIMEOUT;
270
    proto->timeout=IR_RC5_TIMEOUT;
268
    //support RC5-extended keeping second startbit 
271
    //support RC5-extended keeping second startbit 
269
    //remove togglebit
272
    //remove togglebit
270
    proto->data = rawbits&0x37ff; //This seems to be wrong? Does not invert second start bit and keeps first start bit
273
    proto->data = rawbits&0x37ff; //This seems to be wrong? Does not invert second start bit and keeps first start bit
Line 326... Line 329...
326
        *len = 4;
329
        *len = 4;
327
        previousBit = 0; //Toggled from last startbit
330
        previousBit = 0; //Toggled from last startbit
328
    }
331
    }
329
    //Invert the toggle for next time
332
    //Invert the toggle for next time
330
    rc5_toggle=!rc5_toggle & 1;
333
    rc5_toggle=!rc5_toggle & 1;
331
   
334
   
332
    //Decode the message
335
    //Decode the message
333
    //We know that RC5 messages are 14 bits long
336
    //We know that RC5 messages are 14 bits long
334
    for(uint8_t pos=11;pos>0;pos--)
337
    for(uint8_t pos=11;pos>0;pos--)
335
    {      
338
    {      
336
        // Check the current bit
339
        // Check the current bit
Line 411... Line 414...
411
        }
414
        }
412
    }
415
    }
413
   
416
   
414
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_SHARP;
417
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_SHARP;
415
    proto->timeout=IR_SHARP_TIMEOUT;
418
    proto->timeout=IR_SHARP_TIMEOUT;
416
    proto->data=rawbits;
419
    proto->data=rawbits;
417
    return IR_OK;
420
    return IR_OK;
418
}
421
}
419
#endif
422
#endif
420
 
423
 
421
/**
424
/**
422
 * Expand data from Sharp protocol
425
 * Expand data from Sharp protocol
423
 * http://www.sbprojects.com/knowledge/ir/sharp.htm
426
 * http://www.sbprojects.com/knowledge/ir/sharp.htm
424
 *
427
 *
Line 431... Line 434...
431
 * @return
434
 * @return
432
 *      IR_OK if data expanded successfully, one of several errormessages if not
435
 *      IR_OK if data expanded successfully, one of several errormessages if not
433
 */
436
 */
434
int8_t expandSharp(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
437
int8_t expandSharp(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
435
    //TODO: Implement this function.
438
    //TODO: Implement this function.
436
    return IR_NOT_CORRECT_DATA;
439
    return IR_NOT_CORRECT_DATA;
437
}
440
}
438
 
441
 
439
 
442
 
440
#if (IR_PROTOCOLS_USE_NEC)
443
#if (IR_PROTOCOLS_USE_NEC)
441
/**
444
/**
442
 * Test data on NEC protocol
445
 * Test data on NEC protocol
443
 * http://www.sbprojects.com/knowledge/ir/nec.htm
446
 * http://www.sbprojects.com/knowledge/ir/nec.htm
Line 450... Line 453...
450
 *      Pointer to protocol information
453
 *      Pointer to protocol information
451
 * @return
454
 * @return
452
 *      IR_OK if data parsed successfully, one of several errormessages if not
455
 *      IR_OK if data parsed successfully, one of several errormessages if not
453
 */
456
 */
454
int8_t parseNEC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
457
int8_t parseNEC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
455
    /* parse buf[], max is len */
458
    /* parse buf[], max is len */
456
 
459
 
457
    /* check if we have correct amount of data */
460
    /* check if we have correct amount of data */
458
    if (len != 67) {
461
    if (len != 67) {
459
        return IR_NOT_CORRECT_DATA;
462
        return IR_NOT_CORRECT_DATA;
460
    }
463
    }
461
   
464
   
462
    /* check startbit */
465
    /* check startbit */
463
    if (buf[0] > IR_NEC_ST_BIT + IR_NEC_ST_BIT/IR_NEC_TOL_DIV || buf[0] < IR_NEC_ST_BIT - IR_NEC_ST_BIT/IR_NEC_TOL_DIV) {
466
    if (buf[0] > IR_NEC_ST_BIT + IR_NEC_ST_BIT/IR_NEC_TOL_DIV || buf[0] < IR_NEC_ST_BIT - IR_NEC_ST_BIT/IR_NEC_TOL_DIV) {
464
        return IR_NOT_CORRECT_DATA;
467
        return IR_NOT_CORRECT_DATA;
465
    }
468
    }
466
 
469
 
467
    /* check pause after startbit */
470
    /* check pause after startbit */
468
    if (buf[1] > IR_NEC_ST_PAUSE + IR_NEC_ST_PAUSE/IR_NEC_TOL_DIV || buf[1] < IR_NEC_ST_PAUSE - IR_NEC_ST_PAUSE/IR_NEC_TOL_DIV) {
471
    if (buf[1] > IR_NEC_ST_PAUSE + IR_NEC_ST_PAUSE/IR_NEC_TOL_DIV || buf[1] < IR_NEC_ST_PAUSE - IR_NEC_ST_PAUSE/IR_NEC_TOL_DIV) {
469
        return IR_NOT_CORRECT_DATA;
472
        return IR_NOT_CORRECT_DATA;
470
    }
473
    }
471
 
474
 
Line 473... Line 476...
473
 
476
 
474
    for (uint8_t i = 3; i < len; i++) {
477
    for (uint8_t i = 3; i < len; i++) {
475
        if ((i&1) == 1) {       /* if odd, ir-pause */
478
        if ((i&1) == 1) {       /* if odd, ir-pause */
476
            /* check length of pause between bits */
479
            /* check length of pause between bits */
477
            if (buf[i] > IR_NEC_LOW_ONE - IR_NEC_LOW_ONE/IR_NEC_TOL_DIV && buf[i] < IR_NEC_LOW_ONE + IR_NEC_LOW_ONE/IR_NEC_TOL_DIV) {
480
            if (buf[i] > IR_NEC_LOW_ONE - IR_NEC_LOW_ONE/IR_NEC_TOL_DIV && buf[i] < IR_NEC_LOW_ONE + IR_NEC_LOW_ONE/IR_NEC_TOL_DIV) {
478
                /* write a one */
481
                /* write a one */
479
                rawbits |= 1UL<<((i-3)>>1);
482
                rawbits |= 1UL<<((i-3)>>1);
480
            } else if (buf[i] > IR_NEC_LOW_ZERO - IR_NEC_LOW_ZERO/IR_NEC_TOL_DIV && buf[i] < IR_NEC_LOW_ZERO + IR_NEC_LOW_ZERO/IR_NEC_TOL_DIV) {
483
            } else if (buf[i] > IR_NEC_LOW_ZERO - IR_NEC_LOW_ZERO/IR_NEC_TOL_DIV && buf[i] < IR_NEC_LOW_ZERO + IR_NEC_LOW_ZERO/IR_NEC_TOL_DIV) {
481
                /* do nothing, a zero is already in place */
484
                /* do nothing, a zero is already in place */
482
            } else {
485
            } else {
483
                return IR_NOT_CORRECT_DATA;
486
                return IR_NOT_CORRECT_DATA;
484
            }
487
            }
Line 536... Line 539...
536
        *len = 3;
539
        *len = 3;
537
    }
540
    }
538
    proto->modfreq=IR_NEC_F_MOD;
541
    proto->modfreq=IR_NEC_F_MOD;
539
    proto->repeats=IR_NEC_REPS;
542
    proto->repeats=IR_NEC_REPS;
540
    return IR_OK;
543
    return IR_OK;
541
}
544
}
542
 
545
 
543
 
546
 
544
#if (IR_PROTOCOLS_USE_SAMSUNG)
547
#if (IR_PROTOCOLS_USE_SAMSUNG)
545
/**
548
/**
546
 * Test data on Samsung protocol
549
 * Test data on Samsung protocol
547
 * Very much like NEC, different start bit/pause lengths etc.
550
 * Very much like NEC, different start bit/pause lengths etc.
548
 * http://www.sbprojects.com/knowledge/ir/nec.htm
551
 * http://www.sbprojects.com/knowledge/ir/nec.htm
Line 559... Line 562...
559
int8_t parseSamsung(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
562
int8_t parseSamsung(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
560
    /* parse buf[], max is len */
563
    /* parse buf[], max is len */
561
 
564
 
562
    /* check if we have correct amount of data */
565
    /* check if we have correct amount of data */
563
    if (len != 67) {
566
    if (len != 67) {
564
        return IR_NOT_CORRECT_DATA;
567
        return IR_NOT_CORRECT_DATA;
565
    }
568
    }
566
   
569
   
567
    /* check startbit */
570
    /* check startbit */
568
    if (buf[0] > IR_SAMS_ST_BIT + IR_SAMS_ST_BIT/IR_SAMS_TOL_DIV || buf[0] < IR_SAMS_ST_BIT - IR_SAMS_ST_BIT/IR_SAMS_TOL_DIV) {
571
    if (buf[0] > IR_SAMS_ST_BIT + IR_SAMS_ST_BIT/IR_SAMS_TOL_DIV || buf[0] < IR_SAMS_ST_BIT - IR_SAMS_ST_BIT/IR_SAMS_TOL_DIV) {
569
        return IR_NOT_CORRECT_DATA;
572
        return IR_NOT_CORRECT_DATA;
570
    }
573
    }
571
 
574
 
572
    /* check pause after startbit */
575
    /* check pause after startbit */
573
    if (buf[1] > IR_SAMS_ST_PAUSE + IR_SAMS_ST_PAUSE/IR_SAMS_TOL_DIV || buf[1] < IR_SAMS_ST_PAUSE - IR_SAMS_ST_PAUSE/IR_SAMS_TOL_DIV) {
576
    if (buf[1] > IR_SAMS_ST_PAUSE + IR_SAMS_ST_PAUSE/IR_SAMS_TOL_DIV || buf[1] < IR_SAMS_ST_PAUSE - IR_SAMS_ST_PAUSE/IR_SAMS_TOL_DIV) {
574
        return IR_NOT_CORRECT_DATA;
577
        return IR_NOT_CORRECT_DATA;
575
    }
578
    }
576
 
579
 
577
    uint32_t rawbits = 0;
580
    uint32_t rawbits = 0;
578
   
581
   
579
    for (uint8_t i = 3; i < len; i++) {
582
    for (uint8_t i = 3; i < len; i++) {
580
        if ((i&1) == 1) {       /* if odd, ir-pause */
583
        if ((i&1) == 1) {       /* if odd, ir-pause */
581
            /* check length of pause between bits */
584
            /* check length of pause between bits */
582
            if (buf[i] > IR_SAMS_LOW_ONE - IR_SAMS_LOW_ONE/IR_SAMS_TOL_DIV && buf[i] < IR_SAMS_LOW_ONE + IR_SAMS_LOW_ONE/IR_SAMS_TOL_DIV) {
585
            if (buf[i] > IR_SAMS_LOW_ONE - IR_SAMS_LOW_ONE/IR_SAMS_TOL_DIV && buf[i] < IR_SAMS_LOW_ONE + IR_SAMS_LOW_ONE/IR_SAMS_TOL_DIV) {
583
                /* write a one */
586
                /* write a one */
584
                rawbits |= 1UL<<((i-3)>>1);
587
                rawbits |= 1UL<<((i-3)>>1);
585
            } else if (buf[i] > IR_SAMS_LOW_ZERO - IR_SAMS_LOW_ZERO/IR_SAMS_TOL_DIV && buf[i] < IR_SAMS_LOW_ZERO + IR_SAMS_LOW_ZERO/IR_SAMS_TOL_DIV) {
588
            } else if (buf[i] > IR_SAMS_LOW_ZERO - IR_SAMS_LOW_ZERO/IR_SAMS_TOL_DIV && buf[i] < IR_SAMS_LOW_ZERO + IR_SAMS_LOW_ZERO/IR_SAMS_TOL_DIV) {
586
                /* do nothing, a zero is already in rawbits */
589
                /* do nothing, a zero is already in rawbits */
587
            } else {
590
            } else {
588
                return IR_NOT_CORRECT_DATA;
591
                return IR_NOT_CORRECT_DATA;
589
            }
592
            }
590
        } else {            /* if even, ir-bit */
593
        } else {            /* if even, ir-bit */
591
            if (buf[i] > IR_SAMS_HIGH + IR_SAMS_HIGH/IR_SAMS_TOL_DIV || buf[i] < IR_SAMS_HIGH - IR_SAMS_HIGH/IR_SAMS_TOL_DIV) {
594
            if (buf[i] > IR_SAMS_HIGH + IR_SAMS_HIGH/IR_SAMS_TOL_DIV || buf[i] < IR_SAMS_HIGH - IR_SAMS_HIGH/IR_SAMS_TOL_DIV) {
592
                return IR_NOT_CORRECT_DATA;
595
                return IR_NOT_CORRECT_DATA;
593
            }
596
            }
594
        }
597
        }
595
    }
598
    }
596
   
599
   
597
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_SAMSUNG;
600
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_SAMSUNG;
598
    proto->timeout=IR_SAMS_TIMEOUT;
601
    proto->timeout=IR_SAMS_TIMEOUT;
599
    proto->data=rawbits;   
602
    proto->data=rawbits;   
600
    return IR_OK;
603
    return IR_OK;
601
}
604
}
Line 635... Line 638...
635
    *len = 67;
638
    *len = 67;
636
   
639
   
637
    proto->modfreq=IR_SAMS_F_MOD;
640
    proto->modfreq=IR_SAMS_F_MOD;
638
    proto->timeout=IR_SAMS_TIMEOUT;
641
    proto->timeout=IR_SAMS_TIMEOUT;
639
    proto->repeats=IR_SAMS_REPS;
642
    proto->repeats=IR_SAMS_REPS;
640
    return IR_OK;
643
    return IR_OK;
641
}
644
}
642
 
645
 
643
#if (IR_PROTOCOLS_USE_MARANTZ)
646
#if (IR_PROTOCOLS_USE_MARANTZ)
644
/**
647
/**
645
 * Test data on Marantz protocol
648
 * Test data on Marantz protocol
646
 * Reverse-Engineered by Noddan, very similar to RC-5.
649
 * Reverse-Engineered by Noddan, very similar to RC-5.
Line 723... Line 726...
723
            if (previousBit == 1){//11
726
            if (previousBit == 1){//11
724
                buf[*len] = IR_MARANTZ_HALF_BIT;
727
                buf[*len] = IR_MARANTZ_HALF_BIT;
725
                buf[*len+1] = IR_MARANTZ_HALF_BIT;
728
                buf[*len+1] = IR_MARANTZ_HALF_BIT;
726
                *len = *len + 2;
729
                *len = *len + 2;
727
            } else {//01
730
            } else {//01
728
                buf[*len-1] = IR_MARANTZ_BIT;
731
                buf[*len-1] = IR_MARANTZ_BIT;
729
                buf[*len] = IR_MARANTZ_HALF_BIT;
732
                buf[*len] = IR_MARANTZ_HALF_BIT;
730
                *len = *len + 1;
733
                *len = *len + 1;
731
            }
734
            }
732
            previousBit = 1;
735
            previousBit = 1;
733
        } else {
736
        } else {
734
            if (previousBit == 1){//10
737
            if (previousBit == 1){//10
Line 760... Line 763...
760
}
763
}
761
 
764
 
762
#if (IR_PROTOCOLS_USE_PANASONIC)
765
#if (IR_PROTOCOLS_USE_PANASONIC)
763
/**
766
/**
764
 * Test data on Panasonic protocol
767
 * Test data on Panasonic protocol
765
 *
768
 *
766
 * @param buf
769
 * @param buf
767
 *      Pointer to buffer to where to data to parse is stored
770
 *      Pointer to buffer to where to data to parse is stored
768
 * @param len
771
 * @param len
769
 *      Length of the data
772
 *      Length of the data
770
 * @param proto
773
 * @param proto
771
 *      Pointer to protocol information
774
 *      Pointer to protocol information
772
 * @return
775
 * @return
773
 *      IR_OK if data parsed successfully, one of several errormessages if not
776
 *      IR_OK if data parsed successfully, one of several errormessages if not
774
 */
777
 */
775
int8_t parsePanasonic(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
778
int8_t parsePanasonic(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
776
    /* parse buf[], max is len */
779
    /* parse buf[], max is len */
777
 
780
 
778
    /* check if we have correct amount of data */
781
    /* check if we have correct amount of data */
779
    if (len != 99) {
782
    if (len != 99) {
780
        return IR_NOT_CORRECT_DATA;
783
        return IR_NOT_CORRECT_DATA;
781
    }
784
    }
782
   
785
   
783
    /* check startbit */
786
    /* check startbit */
784
    if (buf[0] > IR_PANA_ST_BIT + IR_PANA_ST_BIT/IR_PANA_TOL_DIV || buf[0] < IR_PANA_ST_BIT - IR_PANA_ST_BIT/IR_PANA_TOL_DIV) {
787
    if (buf[0] > IR_PANA_ST_BIT + IR_PANA_ST_BIT/IR_PANA_TOL_DIV || buf[0] < IR_PANA_ST_BIT - IR_PANA_ST_BIT/IR_PANA_TOL_DIV) {
785
        return IR_NOT_CORRECT_DATA;
788
        return IR_NOT_CORRECT_DATA;
786
    }
789
    }
787
 
790
 
788
    /* check pause after startbit */
791
    /* check pause after startbit */
789
    if (buf[1] > IR_PANA_ST_PAUSE + IR_PANA_ST_PAUSE/IR_PANA_TOL_DIV || buf[1] < IR_PANA_ST_PAUSE - IR_PANA_ST_PAUSE/IR_PANA_TOL_DIV) {
792
    if (buf[1] > IR_PANA_ST_PAUSE + IR_PANA_ST_PAUSE/IR_PANA_TOL_DIV || buf[1] < IR_PANA_ST_PAUSE - IR_PANA_ST_PAUSE/IR_PANA_TOL_DIV) {
790
        return IR_NOT_CORRECT_DATA;
793
        return IR_NOT_CORRECT_DATA;
791
    }
794
    }
Line 823... Line 826...
823
 *
826
 *
824
 * @param buf
827
 * @param buf
825
 *      Pointer to buffer to store the expanded data
828
 *      Pointer to buffer to store the expanded data
826
 * @param len
829
 * @param len
827
 *      Pointer to length of the data
830
 *      Pointer to length of the data
828
 * @param proto
831
 * @param proto
829
 *      Pointer to protocol information
832
 *      Pointer to protocol information
830
 * @return
833
 * @return
831
 *      IR_OK if data expanded successfully, one of several errormessages if not
834
 *      IR_OK if data expanded successfully, one of several errormessages if not
832
 */
835
 */
833
int8_t expandPanasonic(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
836
int8_t expandPanasonic(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
834
    /* Set up startbit */
837
    /* Set up startbit */
835
    buf[0] = IR_PANA_ST_BIT;
838
    buf[0] = IR_PANA_ST_BIT;
Line 910... Line 913...
910
            return IR_NOT_CORRECT_DATA;
913
            return IR_NOT_CORRECT_DATA;
911
        }
914
        }
912
       
915
       
913
        /* if level is low */
916
        /* if level is low */
914
        if ((rawbits&1)==0) {
917
        if ((rawbits&1)==0) {
915
            /* and there is a long pulse */
918
            /* and there is a long pulse */
916
            if (current == SKYLONG) {
919
            if (current == SKYLONG) {
917
                /* push a one */
920
                /* push a one */
918
                rawbits = rawbits<<1;
921
                rawbits = rawbits<<1;
919
                rawbits |= 1;
922
                rawbits |= 1;
920
                cnt = 0;
923
                cnt = 0;
921
            }
924
            }
922
            else if (cnt == 0) {
925
            else if (cnt == 0) {
923
                cnt=1;
926
                cnt=1;
924
                /* push a zero */
927
                /* push a zero */
925
                rawbits = rawbits<<1;
928
                rawbits = rawbits<<1;
926
               
929
               
927
            }
930
            }
928
            else {
931
            else {
929
                cnt = 0;
932
                cnt = 0;
930
            }
933
            }
931
        }
934
        }
932
       
935
       
933
        /* if level is high */
936
        /* if level is high */
934
        if ((rawbits&1)==1) {
937
        if ((rawbits&1)==1) {
935
            /* and there is a long pulse */
938
            /* and there is a long pulse */
936
            if (current == SKYLONG) {
939
            if (current == SKYLONG) {
937
                /* push a zero */
940
                /* push a zero */
938
                rawbits = rawbits<<1;
941
                rawbits = rawbits<<1;
939
               
942
               
940
                if (previous == SKYLONG) {
943
                if (previous == SKYLONG) {
941
                    cnt = 1;
944
                    cnt = 1;
942
                }
945
                }
943
                else {
946
                else {
944
                    cnt = 0;
947
                    cnt = 0;
945
                }
948
                }
946
            }
949
            }
947
            else if (cnt == 0) {
950
            else if (cnt == 0) {
948
                cnt=1;
951
                cnt=1;
949
                /* push a one */
952
                /* push a one */
950
                rawbits = rawbits<<1;
953
                rawbits = rawbits<<1;
951
                rawbits |= 1;
954
                rawbits |= 1;
952
            }
955
            }
953
            else {
956
            else {
954
                cnt = 0;
957
                cnt = 0;
955
            }
958
            }
Line 1298... Line 1301...
1298
    /* parse buf[], max is len */
1301
    /* parse buf[], max is len */
1299
 
1302
 
1300
    uint8_t i;
1303
    uint8_t i;
1301
    /* check if we have correct amount of data */
1304
    /* check if we have correct amount of data */
1302
    if (len < 50) {
1305
    if (len < 50) {
1303
        return IR_NOT_CORRECT_DATA;
1306
        return IR_NOT_CORRECT_DATA;
1304
    }
1307
    }
1305
#if IR_RX_CONTINUOUS_MODE==0
1308
#if IR_RX_CONTINUOUS_MODE==0
1306
    i = 0;
1309
    i = 0;
1307
#else
1310
#else
1308
    i=index-50;
1311
    i=index-50;
1309
    if (i>index)
1312
    if (i>index)
1310
        i+=MAX_NR_TIMES;
1313
        i+=MAX_NR_TIMES;
1311
#endif
1314
#endif
1312
    if (buf[i] < IR_NEXA1_START - IR_NEXA1_START/IR_NEXA1_TOL_DIV || buf[i] > IR_NEXA1_START + IR_NEXA1_START/IR_NEXA1_TOL_DIV) { //check start bit
1315
    if (buf[i] < IR_NEXA1_START - IR_NEXA1_START/IR_NEXA1_TOL_DIV || buf[i] > IR_NEXA1_START + IR_NEXA1_START/IR_NEXA1_TOL_DIV) { //check start bit
Line 1321... Line 1324...
1321
        uint8_t i2;
1324
        uint8_t i2;
1322
#if IR_RX_CONTINUOUS_MODE==0
1325
#if IR_RX_CONTINUOUS_MODE==0
1323
        i2 = i;
1326
        i2 = i;
1324
#else
1327
#else
1325
        i2=index-(50-i);
1328
        i2=index-(50-i);
1326
        if (i2>index)
1329
        if (i2>index)
1327
            i2+=MAX_NR_TIMES;
1330
            i2+=MAX_NR_TIMES;
1328
#endif
1331
#endif
1329
        /* Check if '0' bit */
1332
        /* Check if '0' bit */
1330
        if (
1333
        if (
1331
            (buf[i2+0] > IR_NEXA1_SHORT - IR_NEXA1_SHORT/IR_NEXA1_TOL_DIV) && (buf[i2+0] < IR_NEXA1_SHORT + IR_NEXA1_SHORT/IR_NEXA1_TOL_DIV) &&
1334
            (buf[i2+0] > IR_NEXA1_SHORT - IR_NEXA1_SHORT/IR_NEXA1_TOL_DIV) && (buf[i2+0] < IR_NEXA1_SHORT + IR_NEXA1_SHORT/IR_NEXA1_TOL_DIV) &&
1332
            (buf[i2+1] > IR_NEXA1_LONG  - IR_NEXA1_LONG /IR_NEXA1_TOL_DIV) && (buf[i2+1] < IR_NEXA1_LONG  + IR_NEXA1_LONG /IR_NEXA1_TOL_DIV) &&
1335
            (buf[i2+1] > IR_NEXA1_LONG  - IR_NEXA1_LONG /IR_NEXA1_TOL_DIV) && (buf[i2+1] < IR_NEXA1_LONG  + IR_NEXA1_LONG /IR_NEXA1_TOL_DIV) &&
Line 1344... Line 1347...
1344
            (buf[i2+3] > IR_NEXA1_SHORT - IR_NEXA1_SHORT/IR_NEXA1_TOL_DIV) && (buf[i2+3] < IR_NEXA1_SHORT + IR_NEXA1_SHORT/IR_NEXA1_TOL_DIV) )
1347
            (buf[i2+3] > IR_NEXA1_SHORT - IR_NEXA1_SHORT/IR_NEXA1_TOL_DIV) && (buf[i2+3] < IR_NEXA1_SHORT + IR_NEXA1_SHORT/IR_NEXA1_TOL_DIV) )
1345
        {
1348
        {
1346
            /* do nothing, a zero is already in rawbits */
1349
            /* do nothing, a zero is already in rawbits */
1347
            bitCounter++;
1350
            bitCounter++;
1348
        }
1351
        }
1349
        else
1352
        else
1350
        {
1353
        {
1351
            return IR_NOT_CORRECT_DATA;
1354
            return IR_NOT_CORRECT_DATA;
1352
        }
1355
        }
1353
    }
1356
    }
1354
 
1357
 
1355
    if (rawbitsTemp==0)
1358
    if (rawbitsTemp==0)
1356
    {
1359
    {
1357
        /* Bogus RF data */
1360
        /* Bogus RF data */
1358
        return IR_NOT_CORRECT_DATA;
1361
        return IR_NOT_CORRECT_DATA;
1359
    }
1362
    }
1360
   
1363
   
1361
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_NEXA;
1364
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_NEXA;
1362
    proto->timeout=IR_NEXA1_TIMEOUT;
1365
    proto->timeout=IR_NEXA1_TIMEOUT;
1363
    proto->data=rawbitsTemp;
1366
    proto->data=rawbitsTemp;
1364
    return IR_OK;
1367
    return IR_OK;
1365
}
1368
}
1366
 
1369
 
1367
#endif
1370
#endif
1368
 
1371
 
1369
/**
1372
/**
1370
 * Expand data from Nexa1 protocol
1373
 * Expand data from Nexa1 protocol
1371
 *
1374
 *
1372
 *
1375
 *
1373
 * @param buf
1376
 * @param buf
1374
 *      Pointer to buffer to store the expanded data
1377
 *      Pointer to buffer to store the expanded data
1375
 * @param len
1378
 * @param len
1376
 *      Pointer to length of the data
1379
 *      Pointer to length of the data
1377
 * @param proto
1380
 * @param proto
Line 1388... Line 1391...
1388
    /* encode data bits */
1391
    /* encode data bits */
1389
    for (uint8_t i = 0; i < 45; i += 4)
1392
    for (uint8_t i = 0; i < 45; i += 4)
1390
    {
1393
    {
1391
        if (tempshift & 1) {
1394
        if (tempshift & 1) {
1392
            /* encode 0 bit */
1395
            /* encode 0 bit */
1393
            buf[i+0] = IR_NEXA1_SHORT;
1396
            buf[i+0] = IR_NEXA1_SHORT;
1394
            buf[i+1] = IR_NEXA1_LONG;
1397
            buf[i+1] = IR_NEXA1_LONG;
1395
            buf[i+2] = IR_NEXA1_SHORT;
1398
            buf[i+2] = IR_NEXA1_SHORT;
1396
            buf[i+3] = IR_NEXA1_LONG;
1399
            buf[i+3] = IR_NEXA1_LONG;
1397
        } else {
1400
        } else {
1398
            /* encode X bit */
1401
            /* encode X bit */
Line 1400... Line 1403...
1400
            buf[i+1] = IR_NEXA1_LONG;
1403
            buf[i+1] = IR_NEXA1_LONG;
1401
            buf[i+2] = IR_NEXA1_LONG;
1404
            buf[i+2] = IR_NEXA1_LONG;
1402
            buf[i+3] = IR_NEXA1_SHORT;
1405
            buf[i+3] = IR_NEXA1_SHORT;
1403
        }
1406
        }
1404
        tempshift = tempshift>>1;
1407
        tempshift = tempshift>>1;
1405
    }
1408
    }
1406
 
1409
 
1407
    /* encode stop/sync bit */
1410
    /* encode stop/sync bit */
1408
    buf[48] = IR_NEXA1_SHORT;
1411
    buf[48] = IR_NEXA1_SHORT;
1409
   
1412
   
1410
    proto->modfreq = IR_NEXA1_F_MOD;
1413
    proto->modfreq = IR_NEXA1_F_MOD;
1411
    proto->timeout = IR_NEXA1_START/1000;
1414
    proto->timeout = IR_NEXA1_START/1000;
1412
    proto->repeats = IR_NEXA1_REPS;
1415
    proto->repeats = IR_NEXA1_REPS;
1413
    return IR_OK;  
1416
    return IR_OK;  
1414
}
1417
}
1415
 
1418
 
1416
 
1419
 
1417
#if (IR_PROTOCOLS_USE_VIKING)
1420
#if (IR_PROTOCOLS_USE_VIKING)
1418
/**
1421
/**
1419
 * Test data on Viking temperature sensor protocol
1422
 * Test data on Viking sensor protocol
-
 
1423
 * This is protocol type 4 (temperature with sign and one more byte)
-
 
1424
 *
1420
 *
1425
 *
-
 
1426
 * @param buf
-
 
1427
 *      Pointer to buffer to where to data to parse is stored
-
 
1428
 * @param len
-
 
1429
 *      Length of the data
-
 
1430
 * @param proto
-
 
1431
 *      Pointer to protocol information
-
 
1432
 * @return
-
 
1433
 *      IR_OK if data parsed successfully, one of several errormessages if not
-
 
1434
 */
-
 
1435
 
-
 
1436
int8_t parseViking(const uint16_t *buf, uint8_t len, uint8_t index, Ir_Protocol_Data_t *proto)
-
 
1437
{
-
 
1438
#if IR_RX_CONTINUOUS_MODE==1
-
 
1439
    /* check if we have correct amount of data */
-
 
1440
    if (len < 90) {
-
 
1441
        return IR_NOT_CORRECT_DATA;
-
 
1442
    }
-
 
1443
    uint8_t i, i2;
-
 
1444
    uint64_t rawbitsTemp = 0;//0xffffffffffffffff;
-
 
1445
   
-
 
1446
    for (i = 90; i > 0; i--)
-
 
1447
    {
-
 
1448
        i2=index-i;
-
 
1449
        if (i2>index)
-
 
1450
            i2+=MAX_NR_TIMES;
-
 
1451
 
-
 
1452
        /* Check if correct amount of data have been received */
-
 
1453
        if ((i == 78) && (rawbitsTemp != 0b00001))
-
 
1454
            return IR_NOT_CORRECT_DATA;
-
 
1455
 
-
 
1456
/* Only check type if we have separate support for type 3 */
-
 
1457
#if (IR_PROTOCOLS_USE_VIKING_T3)
-
 
1458
        /* Check type, only allow type=4 (3 inverted) */
-
 
1459
        if ((i == 72) && (rawbitsTemp != 0b00001011))
-
 
1460
            return IR_NOT_CORRECT_DATA;
-
 
1461
#endif
-
 
1462
 
-
 
1463
        if ((i&1) == 0)
-
 
1464
        {       /* if even, no data */
-
 
1465
            if ((buf[i2] < IR_VIKING_LOW - IR_VIKING_LOW/IR_VIKING_TOL_DIV) || (buf[i2] > IR_VIKING_LOW + IR_VIKING_LOW/IR_VIKING_TOL_DIV))
-
 
1466
            {
-
 
1467
                return IR_NOT_CORRECT_DATA;
-
 
1468
            }
-
 
1469
        }
-
 
1470
        else
-
 
1471
        {           /* if odd, data */
-
 
1472
            /* check length of transmit pulse */
-
 
1473
            if ((buf[i2] > IR_VIKING_HIGH_ONE - IR_VIKING_HIGH_ONE/IR_VIKING_TOL_DIV) && (buf[i2] < IR_VIKING_HIGH_ONE + IR_VIKING_HIGH_ONE/IR_VIKING_TOL_DIV))
-
 
1474
            {
-
 
1475
                /* write a one */
-
 
1476
                rawbitsTemp = rawbitsTemp<<1;
-
 
1477
                rawbitsTemp |= 1;
-
 
1478
            }
-
 
1479
            else if ((buf[i2] > IR_VIKING_HIGH_ZERO - IR_VIKING_HIGH_ZERO/IR_VIKING_TOL_DIV) && (buf[i2] < IR_VIKING_HIGH_ZERO + IR_VIKING_HIGH_ZERO/IR_VIKING_TOL_DIV))
-
 
1480
            {
-
 
1481
                /* do nothing, a zero is already in rawbits */
-
 
1482
                rawbitsTemp = rawbitsTemp<<1;
-
 
1483
            }
-
 
1484
            else
-
 
1485
            {
-
 
1486
                return IR_NOT_CORRECT_DATA;
-
 
1487
            }
-
 
1488
        }
-
 
1489
    }
-
 
1490
   
-
 
1491
    rawbitsTemp = ~rawbitsTemp;
-
 
1492
    rawbitsTemp = rawbitsTemp&0xFFFFFFFFFF;
-
 
1493
   
-
 
1494
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_VIKING;
-
 
1495
    proto->timeout=0;
-
 
1496
    proto->data=rawbitsTemp;
-
 
1497
 
-
 
1498
    return IR_OK;
-
 
1499
#else
-
 
1500
    return IR_NOT_CORRECT_DATA;
-
 
1501
#endif
-
 
1502
}
-
 
1503
#endif
-
 
1504
 
-
 
1505
 
-
 
1506
#if (IR_PROTOCOLS_USE_VIKING_T3)
-
 
1507
/**
-
 
1508
 * Test data on Viking sensor protocol
-
 
1509
 * This is protocol type 3 (offseted temperature with three bytes)
1421
 *
1510
 *
1422
 *
1511
 *
1423
 * @param buf
1512
 * @param buf
1424
 *      Pointer to buffer to where to data to parse is stored
1513
 *      Pointer to buffer to where to data to parse is stored
1425
 * @param len
1514
 * @param len
Line 1428... Line 1517...
1428
 *      Pointer to protocol information
1517
 *      Pointer to protocol information
1429
 * @return
1518
 * @return
1430
 *      IR_OK if data parsed successfully, one of several errormessages if not
1519
 *      IR_OK if data parsed successfully, one of several errormessages if not
1431
 */
1520
 */
1432
 
1521
 
1433
int8_t parseViking(const uint16_t *buf, uint8_t len, uint8_t index, Ir_Protocol_Data_t *proto)
1522
int8_t parseVikingT3(const uint16_t *buf, uint8_t len, uint8_t index, Ir_Protocol_Data_t *proto)
1434
{
1523
{
1435
#if IR_RX_CONTINUOUS_MODE==1
1524
#if IR_RX_CONTINUOUS_MODE==1
1436
    /* check if we have correct amount of data */
1525
    /* check if we have correct amount of data */
1437
    if (len < 90) {
1526
    if (len < 106) {
1438
        return IR_NOT_CORRECT_DATA;
1527
        return IR_NOT_CORRECT_DATA;
1439
    }
1528
    }
1440
    uint8_t i, i2;
1529
    uint8_t i, i2;
1441
    uint64_t rawbitsTemp = 0;//0xffffffffffffffff;
1530
    uint64_t rawbitsTemp = 0;//0xffffffffffffffff;
-
 
1531
    //uint8_t rawbitsTempArr[6] = {0,0,0,0,0,0};
1442
   
1532
   
-
 
1533
    for (i = 106; i > 16; i--)
-
 
1534
    {
-
 
1535
        i2=index-i;
-
 
1536
        if (i2>index)
-
 
1537
            i2+=MAX_NR_TIMES;
-
 
1538
 
-
 
1539
        /* Check if correct amount of data have been received */
-
 
1540
        if ((i == 94) && (rawbitsTemp != 0b00001))
-
 
1541
            return IR_NOT_CORRECT_DATA;
-
 
1542
 
-
 
1543
        /* Check type, only allow type=3 (4 inverted) */
-
 
1544
        if ((i == 88) && (rawbitsTemp != 0b00001100))
-
 
1545
            return IR_NOT_CORRECT_DATA;
-
 
1546
 
-
 
1547
        if ((i&1) == 0)
-
 
1548
        {       /* if even, no data */
-
 
1549
            if ((buf[i2] < IR_VIKING_LOW - IR_VIKING_LOW/IR_VIKING_TOL_DIV) || (buf[i2] > IR_VIKING_LOW + IR_VIKING_LOW/IR_VIKING_TOL_DIV))
-
 
1550
            {
-
 
1551
                return IR_NOT_CORRECT_DATA;
-
 
1552
            }
-
 
1553
        }
-
 
1554
        else
-
 
1555
        {           /* if odd, data */
-
 
1556
            /* check length of transmit pulse */
-
 
1557
            if ((buf[i2] > IR_VIKING_HIGH_ONE - IR_VIKING_HIGH_ONE/IR_VIKING_TOL_DIV) && (buf[i2] < IR_VIKING_HIGH_ONE + IR_VIKING_HIGH_ONE/IR_VIKING_TOL_DIV))
-
 
1558
            {
-
 
1559
                /* write a one */
-
 
1560
                rawbitsTemp = rawbitsTemp<<1;
-
 
1561
                rawbitsTemp |= 1;
-
 
1562
            }
-
 
1563
            else if ((buf[i2] > IR_VIKING_HIGH_ZERO - IR_VIKING_HIGH_ZERO/IR_VIKING_TOL_DIV) && (buf[i2] < IR_VIKING_HIGH_ZERO + IR_VIKING_HIGH_ZERO/IR_VIKING_TOL_DIV))
-
 
1564
            {
-
 
1565
                /* do nothing, a zero is already in rawbits */
-
 
1566
                rawbitsTemp = rawbitsTemp<<1;
-
 
1567
            }
-
 
1568
            else
-
 
1569
            {
-
 
1570
                return IR_NOT_CORRECT_DATA;
-
 
1571
            }
-
 
1572
        }
-
 
1573
    }
-
 
1574
 
-
 
1575
    uint16_t rest = 0;
1443
    for (i = 90; i > 0; i--)
1576
    for (i = 16; i > 0; i--)
1444
    {
1577
    {
1445
        i2=index-i;
1578
        i2=index-i;
1446
        if (i2>index)
1579
        if (i2>index)
1447
            i2+=MAX_NR_TIMES;
1580
            i2+=MAX_NR_TIMES;
1448
 
-
 
1449
        /* Check if correct amount of data have been received */
-
 
1450
        if ((i == 78) && (rawbitsTemp != 0b00001))
-
 
1451
            return IR_NOT_CORRECT_DATA;
-
 
1452
 
1581
 
1453
        if ((i&1) == 0)
1582
        if ((i&1) == 0)
1454
        {       /* if even, no data */
1583
        {       /* if even, no data */
1455
            if ((buf[i2] < IR_VIKING_LOW - IR_VIKING_LOW/IR_VIKING_TOL_DIV) || (buf[i2] > IR_VIKING_LOW + IR_VIKING_LOW/IR_VIKING_TOL_DIV))
1584
            if ((buf[i2] < IR_VIKING_LOW - IR_VIKING_LOW/IR_VIKING_TOL_DIV) || (buf[i2] > IR_VIKING_LOW + IR_VIKING_LOW/IR_VIKING_TOL_DIV))
1456
            {
1585
            {
1457
                return IR_NOT_CORRECT_DATA;
1586
                return IR_NOT_CORRECT_DATA;
1458
            }
1587
            }
1459
        }
1588
        }
1460
        else
1589
        else
1461
        {           /* if odd, data */
1590
        {           /* if odd, data */
1462
            /* check length of transmit pulse */
1591
            /* check length of transmit pulse */
1463
            if ((buf[i2] > IR_VIKING_HIGH_ONE - IR_VIKING_HIGH_ONE/IR_VIKING_TOL_DIV) && (buf[i2] < IR_VIKING_HIGH_ONE + IR_VIKING_HIGH_ONE/IR_VIKING_TOL_DIV))
1592
            if ((buf[i2] > IR_VIKING_HIGH_ONE - IR_VIKING_HIGH_ONE/IR_VIKING_TOL_DIV) && (buf[i2] < IR_VIKING_HIGH_ONE + IR_VIKING_HIGH_ONE/IR_VIKING_TOL_DIV))
1464
            {
1593
            {
1465
                /* write a one */
1594
                /* write a one */
1466
                rawbitsTemp = rawbitsTemp<<1;
1595
                rest = rest<<1;
1467
                rawbitsTemp |= 1;
1596
                rest |= 1;
1468
            }
1597
            }
1469
            else if ((buf[i2] > IR_VIKING_HIGH_ZERO - IR_VIKING_HIGH_ZERO/IR_VIKING_TOL_DIV) && (buf[i2] < IR_VIKING_HIGH_ZERO + IR_VIKING_HIGH_ZERO/IR_VIKING_TOL_DIV))
1598
            else if ((buf[i2] > IR_VIKING_HIGH_ZERO - IR_VIKING_HIGH_ZERO/IR_VIKING_TOL_DIV) && (buf[i2] < IR_VIKING_HIGH_ZERO + IR_VIKING_HIGH_ZERO/IR_VIKING_TOL_DIV))
1470
            {
1599
            {
1471
                /* do nothing, a zero is already in rawbits */
1600
                /* do nothing, a zero is already in rawbits */
1472
                rawbitsTemp = rawbitsTemp<<1;
1601
                rest = rest<<1;
1473
            }
1602
            }
1474
            else
1603
            else
1475
            {
1604
            {
1476
                return IR_NOT_CORRECT_DATA;
1605
                return IR_NOT_CORRECT_DATA;
1477
            }
1606
            }
1478
        }
1607
        }
1479
    }
1608
    }
-
 
1609
    rest = ~rest;
-
 
1610
    //rest = rest&0xFF;
1480
   
1611
 
1481
    rawbitsTemp = ~rawbitsTemp;
1612
    rawbitsTemp = ~rawbitsTemp;
1482
    rawbitsTemp = rawbitsTemp&0xFFFFFFFFFF;
1613
    rawbitsTemp = rawbitsTemp&0xFFFFFFFFFF;
-
 
1614
   
-
 
1615
    uint8_t crc = 0;
-
 
1616
    crc = _crc_ibutton_update(crc, 0xFF);
-
 
1617
    crc = _crc_ibutton_update(crc, rawbitsTemp&0xFF);
-
 
1618
    crc = _crc_ibutton_update(crc, (rawbitsTemp>>8)&0xFF);
-
 
1619
    crc = _crc_ibutton_update(crc, (rawbitsTemp>>16)&0xFF);
-
 
1620
    crc = _crc_ibutton_update(crc, (rawbitsTemp>>24)&0xFF);
-
 
1621
    crc = _crc_ibutton_update(crc, (rawbitsTemp>>32)&0xFF);
-
 
1622
    //crc = _crc_ibutton_update(crc, (rawbitsTemp>>40)&0xFF);
-
 
1623
   
-
 
1624
    rawbitsTemp = rawbitsTemp&0xFFFFFF0000;
-
 
1625
    rawbitsTemp |= (crc<<8)|((rest>>8)&0xFF);
1483
   
1626
   
1484
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_VIKING;
1627
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_VIKING;
1485
    proto->timeout=0;
1628
    proto->timeout=0;
1486
    proto->data=rawbitsTemp;
1629
    proto->data=rawbitsTemp;
1487
 
1630