Subversion Repositories HomeAutomation

Rev

Rev 1904 | Rev 1922 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1904 Rev 1906
Line 45... Line 45...
45
#if (IR_PROTOCOLS_USE_SKY)
45
#if (IR_PROTOCOLS_USE_SKY)
46
    if (parseSky(buf, len, proto)==IR_OK) return IR_OK;
46
    if (parseSky(buf, len, proto)==IR_OK) return IR_OK;
47
#endif
47
#endif
48
#if (IR_PROTOCOLS_USE_NEXA2)
48
#if (IR_PROTOCOLS_USE_NEXA2)
49
    if (parseNexa2(buf, len, proto)==IR_OK) return IR_OK;
49
    if (parseNexa2(buf, len, proto)==IR_OK) return IR_OK;
-
 
50
#endif
-
 
51
#if (IR_PROTOCOLS_USE_NEXA1)
-
 
52
    if (parseNexa1(buf, len, proto)==IR_OK) return IR_OK;
50
#endif
53
#endif
51
    /* No protocol matched. */
54
    /* No protocol matched. */
52
    proto->protocol = IR_PROTO_UNKNOWN;
55
    proto->protocol = IR_PROTO_UNKNOWN;
53
    return IR_NOT_CORRECT_DATA;
56
    return IR_NOT_CORRECT_DATA;
54
}
57
}
Line 81... Line 84...
81
        return expandPanasonic(buf, len, proto);
84
        return expandPanasonic(buf, len, proto);
82
    case IR_PROTO_SKY:
85
    case IR_PROTO_SKY:
83
        return expandSky(buf, len, proto);
86
        return expandSky(buf, len, proto);
84
    case IR_PROTO_NEXA2:
87
    case IR_PROTO_NEXA2:
85
        return expandNexa2(buf, len, proto);
88
        return expandNexa2(buf, len, proto);
-
 
89
    case IR_PROTO_NEXA1:
-
 
90
        return expandNexa1(buf, len, proto);
86
    }
91
    }
87
    /* Invalid protocol specified. */
92
    /* Invalid protocol specified. */
88
    return IR_NOT_CORRECT_DATA;
93
    return IR_NOT_CORRECT_DATA;
89
}
94
}
90
 
95
 
Line 124... Line 129...
124
   
129
   
125
    for (uint8_t i = 1; i < len; i++) {
130
    for (uint8_t i = 1; i < len; i++) {
126
        if ((i&1) == 1) {       /* if odd, ir-pause */
131
        if ((i&1) == 1) {       /* if odd, ir-pause */
127
            /* check length of pause between bits */
132
            /* check length of pause between bits */
128
            if (buf[i] > IR_SIRC_LOW + IR_SIRC_LOW/IR_SIRC_TOL_DIV || buf[i] < IR_SIRC_LOW - IR_SIRC_LOW/IR_SIRC_TOL_DIV) {
133
            if (buf[i] > IR_SIRC_LOW + IR_SIRC_LOW/IR_SIRC_TOL_DIV || buf[i] < IR_SIRC_LOW - IR_SIRC_LOW/IR_SIRC_TOL_DIV) {
129
                return IR_NOT_CORRECT_DATA;
134
                return IR_NOT_CORRECT_DATA;
130
            }
135
            }
131
        } else {            /* if even, ir-bit */
136
        } else {            /* if even, ir-bit */
132
            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) {
137
            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) {
133
                /* write a one */
138
                /* write a one */
134
                rawbits |= 1<<((i-2)>>1);
139
                rawbits |= 1<<((i-2)>>1);
135
            } 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) {
140
            } 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) {
Line 141... Line 146...
141
    }
146
    }
142
   
147
   
143
    proto->protocol = IR_PROTO_SIRC;
148
    proto->protocol = IR_PROTO_SIRC;
144
    proto->timeout = IR_SIRC_TIMEOUT;
149
    proto->timeout = IR_SIRC_TIMEOUT;
145
    proto->data = rawbits;
150
    proto->data = rawbits;
146
   
151
   
147
    return IR_OK;
152
    return IR_OK;
148
}
153
}
149
#endif
154
#endif
150
 
155
 
151
/**
156
/**
Line 172... Line 177...
172
          *len = 31;
177
          *len = 31;
173
        }
178
        }
174
        for (uint8_t i = 0; i < *len-2; i++) {
179
        for (uint8_t i = 0; i < *len-2; i++) {
175
          if ((i&1) == 1) {     /* if odd, ir-pause */
180
          if ((i&1) == 1) {     /* if odd, ir-pause */
176
            buf[i+2] = IR_SIRC_LOW;
181
            buf[i+2] = IR_SIRC_LOW;
177
          } else {          /* if even, ir-bit */
182
          } else {          /* if even, ir-bit */
178
            if ((proto->data>>(i>>1))&1) {
183
            if ((proto->data>>(i>>1))&1) {
179
              buf[i+2] = IR_SIRC_HIGH_ONE;
184
              buf[i+2] = IR_SIRC_HIGH_ONE;
180
            } else {
185
            } else {
181
              buf[i+2] = IR_SIRC_HIGH_ZERO;
186
              buf[i+2] = IR_SIRC_HIGH_ZERO;
182
            }
187
            }
Line 414... Line 419...
414
 *      Pointer to protocol information
419
 *      Pointer to protocol information
415
 * @return
420
 * @return
416
 *      IR_OK if data parsed successfully, one of several errormessages if not
421
 *      IR_OK if data parsed successfully, one of several errormessages if not
417
 */
422
 */
418
int8_t parseNEC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
423
int8_t parseNEC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
419
    /* parse buf[], max is len */
424
    /* parse buf[], max is len */
420
 
425
 
421
    /* check if we have correct amount of data */
426
    /* check if we have correct amount of data */
422
    if (len != 67) {
427
    if (len != 67) {
423
        return IR_NOT_CORRECT_DATA;
428
        return IR_NOT_CORRECT_DATA;
424
    }
429
    }
425
   
430
   
426
    /* check startbit */
431
    /* check startbit */
427
    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) {
432
    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) {
428
        return IR_NOT_CORRECT_DATA;
433
        return IR_NOT_CORRECT_DATA;
429
    }
434
    }
430
 
435
 
431
    /* check pause after startbit */
436
    /* check pause after startbit */
432
    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) {
437
    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) {
433
        return IR_NOT_CORRECT_DATA;
438
        return IR_NOT_CORRECT_DATA;
434
    }
439
    }
435
 
440
 
436
    uint32_t rawbits = 0;
441
    uint32_t rawbits = 0;
437
 
442
 
438
    for (uint8_t i = 3; i < len; i++) {
443
    for (uint8_t i = 3; i < len; i++) {
439
        if ((i&1) == 1) {       /* if odd, ir-pause */
444
        if ((i&1) == 1) {       /* if odd, ir-pause */
440
            /* check length of pause between bits */
445
            /* check length of pause between bits */
441
            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) {
446
            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) {
442
                /* write a one */
447
                /* write a one */
443
                rawbits |= 1UL<<((i-3)>>1);
448
                rawbits |= 1UL<<((i-3)>>1);
444
            } 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) {
449
            } 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) {
445
                /* do nothing, a zero is already in place */
450
                /* do nothing, a zero is already in place */
446
            } else {
451
            } else {
447
                return IR_NOT_CORRECT_DATA;
452
                return IR_NOT_CORRECT_DATA;
448
            }
453
            }
449
        } else {            /* if even, ir-bit */
454
        } else {            /* if even, ir-bit */
450
            if (buf[i] > IR_NEC_HIGH + IR_NEC_HIGH/IR_NEC_TOL_DIV || buf[i] < IR_NEC_HIGH - IR_NEC_HIGH/IR_NEC_TOL_DIV) {
455
            if (buf[i] > IR_NEC_HIGH + IR_NEC_HIGH/IR_NEC_TOL_DIV || buf[i] < IR_NEC_HIGH - IR_NEC_HIGH/IR_NEC_TOL_DIV) {
451
                return IR_NOT_CORRECT_DATA;
456
                return IR_NOT_CORRECT_DATA;
452
            }
457
            }
453
        }
458
        }
454
    }
459
    }
455
 
460
 
456
    proto->protocol=IR_PROTO_NEC;
461
    proto->protocol=IR_PROTO_NEC;
457
    proto->timeout=IR_NEC_TIMEOUT;
462
    proto->timeout=IR_NEC_TIMEOUT;
458
    proto->data=rawbits;   
463
    proto->data=rawbits;   
459
    return IR_OK;
464
    return IR_OK;
460
}
465
}
461
#endif
466
#endif
462
 
467
 
463
/**
468
/**
464
 * Expand data from NEC protocol
469
 * Expand data from NEC protocol
465
 * http://www.sbprojects.com/knowledge/ir/nec.htm
470
 * http://www.sbprojects.com/knowledge/ir/nec.htm
466
 *
471
 *
467
 * @param buf
472
 * @param buf
468
 *      Pointer to buffer to store the expanded data
473
 *      Pointer to buffer to store the expanded data
Line 474... Line 479...
474
 *      IR_OK if data expanded successfully, one of several errormessages if not
479
 *      IR_OK if data expanded successfully, one of several errormessages if not
475
 */
480
 */
476
int8_t expandNEC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
481
int8_t expandNEC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
477
    /* Set up startbit */
482
    /* Set up startbit */
478
    buf[0] = IR_NEC_ST_BIT;
483
    buf[0] = IR_NEC_ST_BIT;
479
   
484
   
480
    if (proto->framecnt == 0) {
485
    if (proto->framecnt == 0) {
481
        buf[1] = IR_NEC_ST_PAUSE;
486
        buf[1] = IR_NEC_ST_PAUSE;
482
   
487
   
483
        *len = 67;
488
        *len = 67;
484
        for (uint8_t i = 0; i < 65; i++) {
489
        for (uint8_t i = 0; i < 65; i++) {
Line 545... Line 550...
545
            /* check length of pause between bits */
550
            /* check length of pause between bits */
546
            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) {
551
            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) {
547
                /* write a one */
552
                /* write a one */
548
                rawbits |= 1UL<<((i-3)>>1);
553
                rawbits |= 1UL<<((i-3)>>1);
549
            } 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) {
554
            } 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) {
550
                /* do nothing, a zero is already in rawbits */
555
                /* do nothing, a zero is already in rawbits */
551
            } else {
556
            } else {
552
                return IR_NOT_CORRECT_DATA;
557
                return IR_NOT_CORRECT_DATA;
553
            }
558
            }
554
        } else {            /* if even, ir-bit */
559
        } else {            /* if even, ir-bit */
555
            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) {
560
            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) {
556
                return IR_NOT_CORRECT_DATA;
561
                return IR_NOT_CORRECT_DATA;
557
            }
562
            }
558
        }
563
        }
559
    }
564
    }
560
   
565
   
561
    proto->protocol=IR_PROTO_SAMS;
566
    proto->protocol=IR_PROTO_SAMS;
562
    proto->timeout=IR_SAMS_TIMEOUT;
567
    proto->timeout=IR_SAMS_TIMEOUT;
563
    proto->data=rawbits;   
568
    proto->data=rawbits;   
564
    return IR_OK;
569
    return IR_OK;
565
}
570
}
Line 567... Line 572...
567
 
572
 
568
/**
573
/**
569
 * Expand data from Samsung protocol
574
 * Expand data from Samsung protocol
570
 * Very much like NEC, different start bit/pause lengths etc.
575
 * Very much like NEC, different start bit/pause lengths etc.
571
 * http://www.sbprojects.com/knowledge/ir/nec.htm
576
 * http://www.sbprojects.com/knowledge/ir/nec.htm
572
 *
577
 *
573
 * @param buf
578
 * @param buf
574
 *      Pointer to buffer to store the expanded data
579
 *      Pointer to buffer to store the expanded data
575
 * @param len
580
 * @param len
576
 *      Pointer to length of the data
581
 *      Pointer to length of the data
577
 * @param proto
582
 * @param proto
578
 *      Pointer to protocol information
583
 *      Pointer to protocol information
579
 * @return
584
 * @return
Line 599... Line 604...
599
    *len = 67;
604
    *len = 67;
600
   
605
   
601
    proto->modfreq=IR_SAMS_F_MOD;
606
    proto->modfreq=IR_SAMS_F_MOD;
602
    proto->timeout=IR_SAMS_TIMEOUT;
607
    proto->timeout=IR_SAMS_TIMEOUT;
603
    proto->repeats=IR_SAMS_REPS;
608
    proto->repeats=IR_SAMS_REPS;
604
    return IR_OK;
609
    return IR_OK;
605
}
610
}
606
 
611
 
607
#if (IR_PROTOCOLS_USE_MARANTZ)
612
#if (IR_PROTOCOLS_USE_MARANTZ)
608
/**
613
/**
609
 * Test data on Marantz protocol
614
 * Test data on Marantz protocol
610
 * Reverse-Engineered by Noddan, very similar to RC-5.
615
 * Reverse-Engineered by Noddan, very similar to RC-5.
611
 * Not tested with odd adresses since I have no remote that sends them.
616
 * Not tested with odd adresses since I have no remote that sends them.
Line 617... Line 622...
617
 *      Length of the data
622
 *      Length of the data
618
 * @param proto
623
 * @param proto
619
 *      Pointer to protocol information
624
 *      Pointer to protocol information
620
 * @return
625
 * @return
621
 *      IR_OK if data parsed successfully, one of several errormessages if not
626
 *      IR_OK if data parsed successfully, one of several errormessages if not
622
 */
627
 */
623
int8_t parseMarantz(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
628
int8_t parseMarantz(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
624
    uint8_t halfbitscnt = 1;
629
    uint8_t halfbitscnt = 1;
625
    uint32_t rawbits = 0;
630
    uint32_t rawbits = 0;
626
   
631
   
627
    for (uint8_t i = 0; i<len; i++) {
632
    for (uint8_t i = 0; i<len; i++) {
Line 649... Line 654...
649
    proto->data = rawbits&0x0001ffff;
654
    proto->data = rawbits&0x0001ffff;
650
   
655
   
651
    return IR_OK;
656
    return IR_OK;
652
}
657
}
653
#endif
658
#endif
654
 
659
 
655
/**
660
/**
656
 * Expand data from Marantz. Written by Martin Nordin
661
 * Expand data from Marantz. Written by Martin Nordin
657
 *
662
 *
658
 * @param buf
663
 * @param buf
659
 *      Pointer to buffer to store the expanded data
664
 *      Pointer to buffer to store the expanded data
Line 665... Line 670...
665
 *      IR_OK if data expanded successfully, one of several errormessages if not
670
 *      IR_OK if data expanded successfully, one of several errormessages if not
666
 */
671
 */
667
int8_t expandMarantz(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
672
int8_t expandMarantz(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
668
    uint8_t previousBit;
673
    uint8_t previousBit;
669
    uint32_t tempdata;
674
    uint32_t tempdata;
670
   
675
   
671
    /* Set up startbits */
676
    /* Set up startbits */
672
    buf[0] = IR_MARANTZ_HALF_BIT;//first start bit
677
    buf[0] = IR_MARANTZ_HALF_BIT;//first start bit
673
    buf[1] = IR_MARANTZ_HALF_BIT;
678
    buf[1] = IR_MARANTZ_HALF_BIT;
674
    buf[2] = IR_MARANTZ_HALF_BIT;//second start bit
679
    buf[2] = IR_MARANTZ_HALF_BIT;//second start bit
675
    //TODO: Toggle bit should be better, not hard-coded
680
    //TODO: Toggle bit should be better, not hard-coded
676
    buf[3] = IR_MARANTZ_HALF_BIT;
681
    buf[3] = IR_MARANTZ_HALF_BIT;
677
    buf[4] = IR_MARANTZ_HALF_BIT;//toggle bit
682
    buf[4] = IR_MARANTZ_HALF_BIT;//toggle bit
678
    *len=5;
683
    *len=5;
679
    previousBit = 1;
684
    previousBit = 1;
680
   
685
   
681
    tempdata = (uint32_t)(proto->data)<<14;
686
    tempdata = (uint32_t)(proto->data)<<14;
682
       
687
       
683
    for(uint8_t i = 0; i < 17; i++) {
688
    for(uint8_t i = 0; i < 17; i++) {
684
        tempdata = (uint32_t)tempdata<<1;
689
        tempdata = (uint32_t)tempdata<<1;
685
 
690
 
686
        if (((uint32_t)tempdata>>31)==1){
691
        if (((uint32_t)tempdata>>31)==1){
687
            if (previousBit == 1){//11
692
            if (previousBit == 1){//11
688
                buf[*len] = IR_MARANTZ_HALF_BIT;
693
                buf[*len] = IR_MARANTZ_HALF_BIT;
689
                buf[*len+1] = IR_MARANTZ_HALF_BIT;
694
                buf[*len+1] = IR_MARANTZ_HALF_BIT;
690
                *len = *len + 2;
695
                *len = *len + 2;
691
            } else {//01
696
            } else {//01
692
                buf[*len-1] = IR_MARANTZ_BIT;
697
                buf[*len-1] = IR_MARANTZ_BIT;
693
                buf[*len] = IR_MARANTZ_HALF_BIT;
698
                buf[*len] = IR_MARANTZ_HALF_BIT;
694
                *len = *len + 1;
699
                *len = *len + 1;
695
            }
700
            }
696
            previousBit = 1;
701
            previousBit = 1;
697
        } else {
702
        } else {
698
            if (previousBit == 1){//10
703
            if (previousBit == 1){//10
699
                buf[*len-1] = IR_MARANTZ_BIT;
704
                buf[*len-1] = IR_MARANTZ_BIT;
700
                buf[*len] = IR_MARANTZ_HALF_BIT;
705
                buf[*len] = IR_MARANTZ_HALF_BIT;
701
                *len = *len + 1;
706
                *len = *len + 1;
702
            } else {//00
707
            } else {//00
703
                buf[*len] = IR_MARANTZ_HALF_BIT;
708
                buf[*len] = IR_MARANTZ_HALF_BIT;
704
                if (i==4){
709
                if (i==4){
705
                    buf[*len+1] = IR_MARANTZ_HALF_BIT*5;
710
                    buf[*len+1] = IR_MARANTZ_HALF_BIT*5;
Line 806... Line 811...
806
            if ((staticBits>>(i>>1))&1) {
811
            if ((staticBits>>(i>>1))&1) {
807
                buf[i+2] = IR_PANA_LOW_ONE;
812
                buf[i+2] = IR_PANA_LOW_ONE;
808
            } else {
813
            } else {
809
                buf[i+2] = IR_PANA_LOW_ZERO;
814
                buf[i+2] = IR_PANA_LOW_ZERO;
810
            }
815
            }
811
        } else {                /* if even, ir-bit */
816
        } else {                /* if even, ir-bit */
812
            buf[i+2] = IR_PANA_HIGH;
817
            buf[i+2] = IR_PANA_HIGH;
813
        }
818
        }
814
    }
819
    }
815
   
820
   
816
    /* then add the value bits */
821
    /* then add the value bits */
817
    for (uint8_t i = 0; i < 65; i++) {
822
    for (uint8_t i = 0; i < 65; i++) {
818
        if ((i&1) == 1) {       /* if odd, ir-pause */
823
        if ((i&1) == 1) {       /* if odd, ir-pause */
Line 822... Line 827...
822
                buf[i+2+32] = IR_PANA_LOW_ZERO;
827
                buf[i+2+32] = IR_PANA_LOW_ZERO;
823
            }
828
            }
824
        } else {                /* if even, ir-bit */
829
        } else {                /* if even, ir-bit */
825
            buf[i+2+32] = IR_PANA_HIGH;
830
            buf[i+2+32] = IR_PANA_HIGH;
826
        }
831
        }
827
    }
832
    }
828
   
833
   
829
    *len = 99;
834
    *len = 99;
830
   
835
   
831
    proto->modfreq=IR_PANA_F_MOD;
836
    proto->modfreq=IR_PANA_F_MOD;
832
    proto->timeout=IR_PANA_TIMEOUT;
837
    proto->timeout=IR_PANA_TIMEOUT;
833
    proto->repeats=IR_PANA_REPS;
838
    proto->repeats=IR_PANA_REPS;
Line 835... Line 840...
835
}
840
}
836
 
841
 
837
#if (IR_PROTOCOLS_USE_SKY)
842
#if (IR_PROTOCOLS_USE_SKY)
838
/**
843
/**
839
 * Test data on Sky protocol
844
 * Test data on Sky protocol
840
 *
845
 *
841
 *
846
 *
842
 * @param buf
847
 * @param buf
843
 *      Pointer to buffer to where to data to parse is stored
848
 *      Pointer to buffer to where to data to parse is stored
844
 * @param len
849
 * @param len
845
 *      Length of the data
850
 *      Length of the data
846
 * @param proto
851
 * @param proto
847
 *      Pointer to protocol information
852
 *      Pointer to protocol information
Line 851... Line 856...
851
int8_t parseSky(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
856
int8_t parseSky(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
852
    /* parse buf[], max is len */
857
    /* parse buf[], max is len */
853
 
858
 
854
    /* check startbit */
859
    /* check startbit */
855
    if (buf[0] > IR_SKY_ST_BIT + IR_SKY_ST_BIT/IR_SKY_TOL_DIV || buf[0] < IR_SKY_ST_BIT - IR_SKY_ST_BIT/IR_SKY_TOL_DIV) {
860
    if (buf[0] > IR_SKY_ST_BIT + IR_SKY_ST_BIT/IR_SKY_TOL_DIV || buf[0] < IR_SKY_ST_BIT - IR_SKY_ST_BIT/IR_SKY_TOL_DIV) {
856
        return IR_NOT_CORRECT_DATA;
861
        return IR_NOT_CORRECT_DATA;
857
    }
862
    }
858
   
863
   
859
    uint32_t rawbits=0;
864
    uint32_t rawbits=0;
860
    uint8_t current=0;
865
    uint8_t current=0;
861
    uint8_t previous=0;
866
    uint8_t previous=0;
862
    uint8_t cnt=0;
867
    uint8_t cnt=0;
Line 864... Line 869...
864
#define SKYSHORT 1
869
#define SKYSHORT 1
865
    for (uint8_t i = 1; i < len; i++)
870
    for (uint8_t i = 1; i < len; i++)
866
    {
871
    {
867
        if (buf[i] > IR_SKY_SHORT - IR_SKY_SHORT/IR_SKY_TOL_DIV && buf[i] < IR_SKY_SHORT + IR_SKY_SHORT/IR_SKY_TOL_DIV) {
872
        if (buf[i] > IR_SKY_SHORT - IR_SKY_SHORT/IR_SKY_TOL_DIV && buf[i] < IR_SKY_SHORT + IR_SKY_SHORT/IR_SKY_TOL_DIV) {
868
            current = SKYSHORT;
873
            current = SKYSHORT;
869
        }
874
        }
870
        else if (buf[i] > IR_SKY_LONG - IR_SKY_LONG/IR_SKY_TOL_DIV && buf[i] < IR_SKY_LONG + IR_SKY_LONG/IR_SKY_TOL_DIV) {
875
        else if (buf[i] > IR_SKY_LONG - IR_SKY_LONG/IR_SKY_TOL_DIV && buf[i] < IR_SKY_LONG + IR_SKY_LONG/IR_SKY_TOL_DIV) {
871
            current = SKYLONG;
876
            current = SKYLONG;
872
        }
877
        }
873
        else {
878
        else {
874
            return IR_NOT_CORRECT_DATA;
879
            return IR_NOT_CORRECT_DATA;
875
        }
880
        }
876
       
881
       
877
        /* if level is low */
882
        /* if level is low */
878
        if ((rawbits&1)==0) {
883
        if ((rawbits&1)==0) {
879
            /* and there is a long pulse */
884
            /* and there is a long pulse */
880
            if (current == SKYLONG) {
885
            if (current == SKYLONG) {
881
                /* push a one */
886
                /* push a one */
882
                rawbits = rawbits<<1;
887
                rawbits = rawbits<<1;
883
                rawbits |= 1;
888
                rawbits |= 1;
884
                cnt = 0;
889
                cnt = 0;
885
            }
890
            }
886
            else if (cnt == 0) {
891
            else if (cnt == 0) {
887
                cnt=1;
892
                cnt=1;
888
                /* push a zero */
893
                /* push a zero */
889
                rawbits = rawbits<<1;
894
                rawbits = rawbits<<1;
890
               
895
               
891
            }
896
            }
892
            else {
897
            else {
893
                cnt = 0;
898
                cnt = 0;
894
            }
899
            }
Line 914... Line 919...
914
                rawbits = rawbits<<1;
919
                rawbits = rawbits<<1;
915
                rawbits |= 1;
920
                rawbits |= 1;
916
            }
921
            }
917
            else {
922
            else {
918
                cnt = 0;
923
                cnt = 0;
919
            }
924
            }
920
        }
925
        }
921
       
926
       
922
        previous=current;
927
        previous=current;
923
       
928
       
924
    }
929
    }
925
   
930
   
926
    proto->protocol = IR_PROTO_SKY;
931
    proto->protocol = IR_PROTO_SKY;
927
    proto->timeout = IR_SKY_TIMEOUT;
932
    proto->timeout = IR_SKY_TIMEOUT;
928
    proto->data = rawbits;
933
    proto->data = rawbits;
929
   
934
   
Line 931... Line 936...
931
}
936
}
932
#endif
937
#endif
933
 
938
 
934
/**
939
/**
935
 * Expand data from Sky protocol
940
 * Expand data from Sky protocol
936
 *
941
 *
937
 *
942
 *
938
 * @param buf
943
 * @param buf
939
 *      Pointer to buffer to store the expanded data
944
 *      Pointer to buffer to store the expanded data
940
 * @param len
945
 * @param len
941
 *      Pointer to length of the data
946
 *      Pointer to length of the data
942
 * @param proto
947
 * @param proto
943
 *      Pointer to protocol information
948
 *      Pointer to protocol information
944
 * @return
949
 * @return
Line 946... Line 951...
946
 */
951
 */
947
int8_t expandSky(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
952
int8_t expandSky(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
948
    //TODO: Implement this function.
953
    //TODO: Implement this function.
949
    buf[0] = IR_SKY_ST_BIT;
954
    buf[0] = IR_SKY_ST_BIT;
950
    buf[1] = IR_SKY_LONG;   //
955
    buf[1] = IR_SKY_LONG;   //
951
   
956
   
952
   
957
   
953
    return IR_NOT_CORRECT_DATA;
958
    return IR_NOT_CORRECT_DATA;
954
}
959
}
955
 
960
 
956
#if (IR_PROTOCOLS_USE_NEXA2)
961
#if (IR_PROTOCOLS_USE_NEXA2)
957
/**
962
/**
958
 * Test data on NEXA protocol
963
 * Test data on NEXA protocol
959
 * http://elektronikforumet.com/wiki/index.php?title=RF_Protokoll_-_Nexa_sj%C3%A4lvl%C3%A4rande
964
 * http://elektronikforumet.com/wiki/index.php?title=RF_Protokoll_-_Nexa_sj%C3%A4lvl%C3%A4rande
960
 *
965
 *
Line 966... Line 971...
966
 *      Pointer to protocol information
971
 *      Pointer to protocol information
967
 * @return
972
 * @return
968
 *      IR_OK if data parsed successfully, one of several errormessages if not
973
 *      IR_OK if data parsed successfully, one of several errormessages if not
969
 */
974
 */
970
int8_t parseNexa2(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
975
int8_t parseNexa2(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
971
    /* parse buf[], max is len */
976
    /* parse buf[], max is len */
972
 
977
   
973
    /* check if we have correct amount of data */
978
    /* check if we have correct amount of data */
974
    if (len != 148 && len != 132) {
979
    if (len != 148 && len != 132) {
975
        return IR_NOT_CORRECT_DATA;
980
        return IR_NOT_CORRECT_DATA;
976
    }
981
    }
977
 
982
 
978
    if (buf[0] < IR_NEXA2_START1 - IR_NEXA2_START1/IR_NEXA2_TOL_DIV && buf[0] > IR_NEXA2_START1 + IR_NEXA2_START1/IR_NEXA2_TOL_DIV) { //check start bit
983
    if (buf[0] < IR_NEXA2_START1 - IR_NEXA2_START1/IR_NEXA2_TOL_DIV && buf[0] > IR_NEXA2_START1 + IR_NEXA2_START1/IR_NEXA2_TOL_DIV) { //check start bit
979
        return IR_NOT_CORRECT_DATA;
984
        return IR_NOT_CORRECT_DATA;
980
    }
985
    }
981
    if (buf[1] < IR_NEXA2_HIGH - IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV && buf[1] > IR_NEXA2_HIGH + IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV) { //check start bit
986
    if (buf[1] < IR_NEXA2_HIGH - IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV && buf[1] > IR_NEXA2_HIGH + IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV) { //check start bit
982
        return IR_NOT_CORRECT_DATA;
987
        return IR_NOT_CORRECT_DATA;
983
    }
988
    }
984
    if (buf[2] < IR_NEXA2_START2 - IR_NEXA2_START2/IR_NEXA2_TOL_DIV && buf[2] > IR_NEXA2_START2 + IR_NEXA2_START2/IR_NEXA2_TOL_DIV) { //check start bit
989
    if (buf[2] < IR_NEXA2_START2 - IR_NEXA2_START2/IR_NEXA2_TOL_DIV && buf[2] > IR_NEXA2_START2 + IR_NEXA2_START2/IR_NEXA2_TOL_DIV) { //check start bit
985
        return IR_NOT_CORRECT_DATA;
990
        return IR_NOT_CORRECT_DATA;
986
    }
991
    }
987
 
992
 
988
    /* Incoming data could actually be longer than 32bits when a dimming command is received */
993
    /* Incoming data could actually be longer than 32bits when a dimming command is received */
989
    uint32_t rawbitsTemp = 0;
994
    uint32_t rawbitsTemp = 0;
990
    uint8_t bitCounter = 0;
995
    uint8_t bitCounter = 0;
991
    for (uint8_t i = 3; i < len; i++) {
996
    for (uint8_t i = 3; i < len; i++) {
992
        if ((i&1) == 0) {       /* if even, data */
997
        if ((i&1) == 0) {       /* if even, data */
Line 1005... Line 1010...
1005
            if (buf[i] < IR_NEXA2_HIGH - IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV && buf[i] > IR_NEXA2_HIGH + IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV) {
1010
            if (buf[i] < IR_NEXA2_HIGH - IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV && buf[i] > IR_NEXA2_HIGH + IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV) {
1006
                return IR_NOT_CORRECT_DATA;
1011
                return IR_NOT_CORRECT_DATA;
1007
            }
1012
            }
1008
        }
1013
        }
1009
    }
1014
    }
1010
   
-
 
1011
//gpio_set_pin(EXP_H);
-
 
1012
   
1015
   
1013
    proto->protocol=IR_PROTO_NEXA2;
1016
    proto->protocol=IR_PROTO_NEXA2;
1014
    proto->timeout=IR_NEXA2_TIMEOUT;
1017
    proto->timeout=IR_NEXA2_TIMEOUT;
1015
    proto->data=rawbitsTemp;
1018
    proto->data=rawbitsTemp;
1016
    return IR_OK;
1019
    return IR_OK;
Line 1056... Line 1059...
1056
 * @return
1059
 * @return
1057
 *      IR_OK if data parsed successfully, one of several errormessages if not
1060
 *      IR_OK if data parsed successfully, one of several errormessages if not
1058
 */
1061
 */
1059
int8_t parseNexa1(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
1062
int8_t parseNexa1(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
1060
    /* parse buf[], max is len */
1063
    /* parse buf[], max is len */
-
 
1064
 
-
 
1065
//gpio_set_pin(EXP_H);
1061
 
1066
 
1062
    /* check if we have correct amount of data */
1067
    /* check if we have correct amount of data */
1063
    if (len != 50) {
1068
    if (len != 50) {
1064
        return IR_NOT_CORRECT_DATA;
1069
        return IR_NOT_CORRECT_DATA;
1065
    }
1070
    }
-
 
1071
    if (buf[0] < IR_NEXA1_START - IR_NEXA1_START/IR_NEXA1_TOL_DIV && buf[0] > IR_NEXA1_START + IR_NEXA1_START/IR_NEXA1_TOL_DIV) { //check start bit
-
 
1072
        return IR_NOT_CORRECT_DATA;
-
 
1073
    }
-
 
1074
 
1066
    uint32_t rawbitsTemp = 0;
1075
    uint32_t rawbitsTemp = 0;
-
 
1076
    uint8_t bitCounter = 0;
-
 
1077
 
-
 
1078
    for (uint8_t i = 1; i < len; i+=4) {
-
 
1079
        /* Check if '0' bit */
-
 
1080
        if (
-
 
1081
            (buf[i+0] > IR_NEXA1_SHORT - IR_NEXA1_SHORT/IR_NEXA1_TOL_DIV && buf[i+0] < IR_NEXA1_SHORT + IR_NEXA1_SHORT/IR_NEXA1_TOL_DIV) &&
-
 
1082
            (buf[i+1] > IR_NEXA1_LONG - IR_NEXA1_LONG/IR_NEXA1_TOL_DIV && buf[i+1] < IR_NEXA1_LONG + IR_NEXA1_LONG/IR_NEXA1_TOL_DIV) &&
-
 
1083
            (buf[i+2] > IR_NEXA1_SHORT - IR_NEXA1_SHORT/IR_NEXA1_TOL_DIV && buf[i+2] < IR_NEXA1_SHORT + IR_NEXA1_SHORT/IR_NEXA1_TOL_DIV) &&
-
 
1084
            (buf[i+3] > IR_NEXA1_LONG - IR_NEXA1_LONG/IR_NEXA1_TOL_DIV && buf[i+3] < IR_NEXA1_LONG + IR_NEXA1_LONG/IR_NEXA1_TOL_DIV))
-
 
1085
        {
-
 
1086
            /* write a one */
-
 
1087
            rawbitsTemp |= (1UL)<<(bitCounter++);
-
 
1088
        }
-
 
1089
        /* Check if 'X' bit */
-
 
1090
        else if (
-
 
1091
            (buf[i+0] > IR_NEXA1_SHORT - IR_NEXA1_SHORT/IR_NEXA1_TOL_DIV && buf[i+0] < IR_NEXA1_SHORT + IR_NEXA1_SHORT/IR_NEXA1_TOL_DIV) &&
-
 
1092
            (buf[i+1] > IR_NEXA1_LONG - IR_NEXA1_LONG/IR_NEXA1_TOL_DIV && buf[i+1] < IR_NEXA1_LONG + IR_NEXA1_LONG/IR_NEXA1_TOL_DIV) &&
-
 
1093
            (buf[i+2] > IR_NEXA1_LONG - IR_NEXA1_LONG/IR_NEXA1_TOL_DIV && buf[i+2] < IR_NEXA1_LONG + IR_NEXA1_LONG/IR_NEXA1_TOL_DIV) &&
-
 
1094
            (buf[i+3] > IR_NEXA1_SHORT - IR_NEXA1_SHORT/IR_NEXA1_TOL_DIV && buf[i+3] < IR_NEXA1_SHORT + IR_NEXA1_SHORT/IR_NEXA1_TOL_DIV))
-
 
1095
        {
-
 
1096
            /* do nothing, a zero is already in rawbits */
-
 
1097
            bitCounter++;
-
 
1098
        }
-
 
1099
    }
1067
 
1100
   
1068
    proto->protocol=IR_PROTO_NEXA1;
1101
    proto->protocol=IR_PROTO_NEXA1;
1069
    proto->timeout=IR_NEXA1_TIMEOUT;
1102
    proto->timeout=IR_NEXA1_TIMEOUT;
1070
    proto->data=rawbitsTemp;
1103
    proto->data=rawbitsTemp;
1071
    return IR_OK;
1104
    return IR_OK;