Subversion Repositories HomeAutomation

Rev

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

Rev 2198 Rev 2199
Line 14... Line 14...
14
 
14
 
15
//#include <drivers/mcu/gpio.h>
15
//#include <drivers/mcu/gpio.h>
16
 
16
 
17
 
17
 
18
 
18
 
19
int8_t parseProtocol(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
19
int8_t parseProtocol(const uint16_t *buf, uint8_t len, uint8_t index, Ir_Protocol_Data_t *proto) {
20
    proto->protocol=IR_PROTO_UNKNOWN;
20
    proto->protocol=IR_PROTO_UNKNOWN;
21
    proto->data=0;
21
    proto->data=0;
22
    proto->timeout=1;
22
    proto->timeout=1;
23
    /* Try all protocols in order. */
23
    /* Try all protocols in order. */
24
#if (IR_PROTOCOLS_USE_SIRC)
24
#if (IR_PROTOCOLS_USE_SIRC)
Line 43... Line 43...
43
    if (parsePanasonic(buf, len, proto)==IR_OK) return IR_OK;
43
    if (parsePanasonic(buf, len, proto)==IR_OK) return IR_OK;
44
#endif
44
#endif
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
 
-
 
49
 
-
 
50
/* RF protocols needs index parameter */
48
#if (IR_PROTOCOLS_USE_NEXA2)
51
#if (IR_PROTOCOLS_USE_NEXA2)
49
    if (parseNexa2(buf, len, proto)==IR_OK) return IR_OK;
52
    if (parseNexa2(buf, len, index, proto)==IR_OK) return IR_OK;
50
#endif
53
#endif
51
#if (IR_PROTOCOLS_USE_NEXA1)
54
#if (IR_PROTOCOLS_USE_NEXA1)
52
    if (parseNexa1(buf, len, proto)==IR_OK) return IR_OK;
55
    if (parseNexa1(buf, len, index, proto)==IR_OK) return IR_OK;
53
#endif
56
#endif
54
    /* No protocol matched. */
57
    /* No protocol matched. */
55
    proto->protocol = IR_PROTO_UNKNOWN;
58
    proto->protocol = IR_PROTO_UNKNOWN;
56
    return IR_NOT_CORRECT_DATA;
59
    return IR_NOT_CORRECT_DATA;
57
}
60
}
Line 141... Line 144...
141
                /* do nothing, a zero is already in rawbits */
144
                /* do nothing, a zero is already in rawbits */
142
            } else {
145
            } else {
143
                return IR_NOT_CORRECT_DATA;
146
                return IR_NOT_CORRECT_DATA;
144
            }
147
            }
145
        }
148
        }
146
    }
149
    }
147
   
150
   
148
    proto->protocol = IR_PROTO_SIRC;
151
    proto->protocol = IR_PROTO_SIRC;
149
    proto->timeout = IR_SIRC_TIMEOUT;
152
    proto->timeout = IR_SIRC_TIMEOUT;
150
    proto->data = rawbits;
153
    proto->data = rawbits;
151
   
154
   
152
    return IR_OK;
155
    return IR_OK;
Line 154... Line 157...
154
#endif
157
#endif
155
 
158
 
156
/**
159
/**
157
 * Expand data from SIRC protocol
160
 * Expand data from SIRC protocol
158
 * http://www.sbprojects.com/knowledge/ir/sirc.htm
161
 * http://www.sbprojects.com/knowledge/ir/sirc.htm
159
 *
162
 *
160
 * @param buf
163
 * @param buf
161
 *      Pointer to buffer to store the expanded data
164
 *      Pointer to buffer to store the expanded data
162
 * @param len
165
 * @param len
163
 *      Pointer to length of the data
166
 *      Pointer to length of the data
164
 * @param proto
167
 * @param proto
165
 *      Pointer to protocol information
168
 *      Pointer to protocol information
166
 * @return
169
 * @return
167
 *      IR_OK if data expanded successfully, one of several errormessages if not
170
 *      IR_OK if data expanded successfully, one of several errormessages if not
168
 */
171
 */
169
int8_t expandSIRC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
172
int8_t expandSIRC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
170
    buf[0] = IR_SIRC_ST_BIT;
173
    buf[0] = IR_SIRC_ST_BIT;
171
    buf[1] = IR_SIRC_LOW; //start pulse finished
174
    buf[1] = IR_SIRC_LOW; //start pulse finished
172
 
175
 
Line 511... Line 514...
511
 
514
 
512
 
515
 
513
#if (IR_PROTOCOLS_USE_SAMSUNG)
516
#if (IR_PROTOCOLS_USE_SAMSUNG)
514
/**
517
/**
515
 * Test data on Samsung protocol
518
 * Test data on Samsung protocol
516
 * Very much like NEC, different start bit/pause lengths etc.
519
 * Very much like NEC, different start bit/pause lengths etc.
517
 * http://www.sbprojects.com/knowledge/ir/nec.htm
520
 * http://www.sbprojects.com/knowledge/ir/nec.htm
518
 *
521
 *
519
 * @param buf
522
 * @param buf
520
 *      Pointer to buffer to where to data to parse is stored
523
 *      Pointer to buffer to where to data to parse is stored
521
 * @param len
524
 * @param len
522
 *      Length of the data
525
 *      Length of the data
523
 * @param proto
526
 * @param proto
524
 *      Pointer to protocol information
527
 *      Pointer to protocol information
525
 * @return
528
 * @return
Line 528... Line 531...
528
int8_t parseSamsung(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
531
int8_t parseSamsung(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
529
    /* parse buf[], max is len */
532
    /* parse buf[], max is len */
530
 
533
 
531
    /* check if we have correct amount of data */
534
    /* check if we have correct amount of data */
532
    if (len != 67) {
535
    if (len != 67) {
533
        return IR_NOT_CORRECT_DATA;
536
        return IR_NOT_CORRECT_DATA;
534
    }
537
    }
535
   
538
   
536
    /* check startbit */
539
    /* check startbit */
537
    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) {
540
    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) {
538
        return IR_NOT_CORRECT_DATA;
541
        return IR_NOT_CORRECT_DATA;
539
    }
542
    }
540
 
543
 
Line 557... Line 560...
557
                return IR_NOT_CORRECT_DATA;
560
                return IR_NOT_CORRECT_DATA;
558
            }
561
            }
559
        } else {            /* if even, ir-bit */
562
        } else {            /* if even, ir-bit */
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) {
563
            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) {
561
                return IR_NOT_CORRECT_DATA;
564
                return IR_NOT_CORRECT_DATA;
562
            }
565
            }
563
        }
566
        }
564
    }
567
    }
565
   
568
   
566
    proto->protocol=IR_PROTO_SAMS;
569
    proto->protocol=IR_PROTO_SAMS;
567
    proto->timeout=IR_SAMS_TIMEOUT;
570
    proto->timeout=IR_SAMS_TIMEOUT;
568
    proto->data=rawbits;   
571
    proto->data=rawbits;   
569
    return IR_OK;
572
    return IR_OK;
570
}
573
}
Line 633... Line 636...
633
        //halfbitscnt&1==1 in the middle of bits
636
        //halfbitscnt&1==1 in the middle of bits
634
        //i&1==0 positive flank
637
        //i&1==0 positive flank
635
 
638
 
636
        if ((halfbitscnt&1)==1 && (i&1)==0) {       /* in the middle of bit AND a positve flank */
639
        if ((halfbitscnt&1)==1 && (i&1)==0) {       /* in the middle of bit AND a positve flank */
637
            rawbits |= (uint32_t)1<<(19-(halfbitscnt>>1));
640
            rawbits |= (uint32_t)1<<(19-(halfbitscnt>>1));
638
        }
641
        }
639
       
642
       
640
        if (buf[i] > IR_MARANTZ_HALF_BIT - IR_MARANTZ_HALF_BIT/IR_MARANTZ_TOL_DIV && buf[i] < IR_MARANTZ_HALF_BIT + IR_MARANTZ_HALF_BIT/IR_MARANTZ_TOL_DIV) {
643
        if (buf[i] > IR_MARANTZ_HALF_BIT - IR_MARANTZ_HALF_BIT/IR_MARANTZ_TOL_DIV && buf[i] < IR_MARANTZ_HALF_BIT + IR_MARANTZ_HALF_BIT/IR_MARANTZ_TOL_DIV) {
641
            halfbitscnt += 1;
644
            halfbitscnt += 1;
642
        } else if (buf[i] > IR_MARANTZ_BIT - IR_MARANTZ_BIT/IR_MARANTZ_TOL_DIV && buf[i] < IR_MARANTZ_BIT + IR_MARANTZ_BIT/IR_MARANTZ_TOL_DIV) {
645
        } else if (buf[i] > IR_MARANTZ_BIT - IR_MARANTZ_BIT/IR_MARANTZ_TOL_DIV && buf[i] < IR_MARANTZ_BIT + IR_MARANTZ_BIT/IR_MARANTZ_TOL_DIV) {
643
            halfbitscnt += 2;
646
            halfbitscnt += 2;
644
        } else if (buf[i] > IR_MARANTZ_BIT - IR_MARANTZ_BIT/IR_MARANTZ_TOL_DIV && buf[i] < 5*IR_MARANTZ_HALF_BIT + IR_MARANTZ_BIT/IR_MARANTZ_TOL_DIV) {
647
        } else if (buf[i] > IR_MARANTZ_BIT - IR_MARANTZ_BIT/IR_MARANTZ_TOL_DIV && buf[i] < 5*IR_MARANTZ_HALF_BIT + IR_MARANTZ_BIT/IR_MARANTZ_TOL_DIV) {
645
            halfbitscnt += 1; //It seems to work, not entirely sure of the purpose of this long zero though.
648
            halfbitscnt += 1; //It seems to work, not entirely sure of the purpose of this long zero though.
646
        } else {
649
        } else {
647
            return IR_NOT_CORRECT_DATA;
650
            return IR_NOT_CORRECT_DATA;
648
        }
651
        }
649
       
652
       
650
    }
653
    }
651
   
654
   
652
    proto->protocol=IR_PROTO_MARANTZ;
655
    proto->protocol=IR_PROTO_MARANTZ;
653
    proto->timeout=IR_MARANTZ_TIMEOUT;
656
    proto->timeout=IR_MARANTZ_TIMEOUT;
654
    proto->data = rawbits&0x0001ffff;
657
    proto->data = rawbits&0x0001ffff;
655
   
658
   
656
    return IR_OK;
659
    return IR_OK;
657
}
660
}
658
#endif
661
#endif
659
 
662
 
660
/**
663
/**
661
 * Expand data from Marantz. Written by Martin Nordin
664
 * Expand data from Marantz. Written by Martin Nordin
662
 *
665
 *
663
 * @param buf
666
 * @param buf
664
 *      Pointer to buffer to store the expanded data
667
 *      Pointer to buffer to store the expanded data
665
 * @param len
668
 * @param len
666
 *      Pointer to length of the data
669
 *      Pointer to length of the data
667
 * @param proto
670
 * @param proto
668
 *      Pointer to protocol information
671
 *      Pointer to protocol information
669
 * @return
672
 * @return
670
 *      IR_OK if data expanded successfully, one of several errormessages if not
673
 *      IR_OK if data expanded successfully, one of several errormessages if not
Line 688... Line 691...
688
    for(uint8_t i = 0; i < 17; i++) {
691
    for(uint8_t i = 0; i < 17; i++) {
689
        tempdata = (uint32_t)tempdata<<1;
692
        tempdata = (uint32_t)tempdata<<1;
690
 
693
 
691
        if (((uint32_t)tempdata>>31)==1){
694
        if (((uint32_t)tempdata>>31)==1){
692
            if (previousBit == 1){//11
695
            if (previousBit == 1){//11
693
                buf[*len] = IR_MARANTZ_HALF_BIT;
696
                buf[*len] = IR_MARANTZ_HALF_BIT;
694
                buf[*len+1] = IR_MARANTZ_HALF_BIT;
697
                buf[*len+1] = IR_MARANTZ_HALF_BIT;
695
                *len = *len + 2;
698
                *len = *len + 2;
696
            } else {//01
699
            } else {//01
697
                buf[*len-1] = IR_MARANTZ_BIT;
700
                buf[*len-1] = IR_MARANTZ_BIT;
698
                buf[*len] = IR_MARANTZ_HALF_BIT;
701
                buf[*len] = IR_MARANTZ_HALF_BIT;
Line 744... Line 747...
744
int8_t parsePanasonic(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
747
int8_t parsePanasonic(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
745
    /* parse buf[], max is len */
748
    /* parse buf[], max is len */
746
 
749
 
747
    /* check if we have correct amount of data */
750
    /* check if we have correct amount of data */
748
    if (len != 99) {
751
    if (len != 99) {
749
        return IR_NOT_CORRECT_DATA;
752
        return IR_NOT_CORRECT_DATA;
750
    }
753
    }
751
   
754
   
752
    /* check startbit */
755
    /* check startbit */
753
    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) {
756
    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) {
754
        return IR_NOT_CORRECT_DATA;
757
        return IR_NOT_CORRECT_DATA;
755
    }
758
    }
756
 
759
 
757
    /* check pause after startbit */
760
    /* check pause after startbit */
758
    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) {
761
    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) {
759
        return IR_NOT_CORRECT_DATA;
762
        return IR_NOT_CORRECT_DATA;
760
    }
763
    }
761
 
764
 
Line 781... Line 784...
781
    }
784
    }
782
   
785
   
783
    proto->protocol=IR_PROTO_PANASONIC;
786
    proto->protocol=IR_PROTO_PANASONIC;
784
    proto->timeout=IR_PANA_TIMEOUT;
787
    proto->timeout=IR_PANA_TIMEOUT;
785
    proto->data=rawbits;   
788
    proto->data=rawbits;   
786
    return IR_OK;
789
    return IR_OK;
787
}
790
}
788
#endif
791
#endif
789
 
792
 
790
/**
793
/**
791
 * Expand data from Panasonic protocol
794
 * Expand data from Panasonic protocol
Line 796... Line 799...
796
 *      Pointer to length of the data
799
 *      Pointer to length of the data
797
 * @param proto
800
 * @param proto
798
 *      Pointer to protocol information
801
 *      Pointer to protocol information
799
 * @return
802
 * @return
800
 *      IR_OK if data expanded successfully, one of several errormessages if not
803
 *      IR_OK if data expanded successfully, one of several errormessages if not
801
 */
804
 */
802
int8_t expandPanasonic(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
805
int8_t expandPanasonic(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
803
    /* Set up startbit */
806
    /* Set up startbit */
804
    buf[0] = IR_PANA_ST_BIT;
807
    buf[0] = IR_PANA_ST_BIT;
805
    buf[1] = IR_PANA_ST_PAUSE;
808
    buf[1] = IR_PANA_ST_PAUSE;
806
   
809
   
Line 810... Line 813...
810
        if ((i&1) == 1) {       /* if odd, ir-pause */
813
        if ((i&1) == 1) {       /* if odd, ir-pause */
811
            if ((staticBits>>(i>>1))&1) {
814
            if ((staticBits>>(i>>1))&1) {
812
                buf[i+2] = IR_PANA_LOW_ONE;
815
                buf[i+2] = IR_PANA_LOW_ONE;
813
            } else {
816
            } else {
814
                buf[i+2] = IR_PANA_LOW_ZERO;
817
                buf[i+2] = IR_PANA_LOW_ZERO;
815
            }
818
            }
816
        } else {                /* if even, ir-bit */
819
        } else {                /* if even, ir-bit */
817
            buf[i+2] = IR_PANA_HIGH;
820
            buf[i+2] = IR_PANA_HIGH;
818
        }
821
        }
819
    }
822
    }
820
   
823
   
Line 841... Line 844...
841
 
844
 
842
#if (IR_PROTOCOLS_USE_SKY)
845
#if (IR_PROTOCOLS_USE_SKY)
843
/**
846
/**
844
 * Test data on Sky protocol
847
 * Test data on Sky protocol
845
 *
848
 *
846
 *
849
 *
847
 * @param buf
850
 * @param buf
848
 *      Pointer to buffer to where to data to parse is stored
851
 *      Pointer to buffer to where to data to parse is stored
849
 * @param len
852
 * @param len
850
 *      Length of the data
853
 *      Length of the data
851
 * @param proto
854
 * @param proto
Line 869... Line 872...
869
#define SKYSHORT 1
872
#define SKYSHORT 1
870
    for (uint8_t i = 1; i < len; i++)
873
    for (uint8_t i = 1; i < len; i++)
871
    {
874
    {
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) {
875
        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) {
873
            current = SKYSHORT;
876
            current = SKYSHORT;
874
        }
877
        }
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) {
878
        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) {
876
            current = SKYLONG;
879
            current = SKYLONG;
877
        }
880
        }
878
        else {
881
        else {
879
            return IR_NOT_CORRECT_DATA;
882
            return IR_NOT_CORRECT_DATA;
880
        }
883
        }
881
       
884
       
882
        /* if level is low */
885
        /* if level is low */
883
        if ((rawbits&1)==0) {
886
        if ((rawbits&1)==0) {
884
            /* and there is a long pulse */
887
            /* and there is a long pulse */
885
            if (current == SKYLONG) {
888
            if (current == SKYLONG) {
886
                /* push a one */
889
                /* push a one */
887
                rawbits = rawbits<<1;
890
                rawbits = rawbits<<1;
888
                rawbits |= 1;
891
                rawbits |= 1;
889
                cnt = 0;
892
                cnt = 0;
890
            }
893
            }
891
            else if (cnt == 0) {
894
            else if (cnt == 0) {
892
                cnt=1;
895
                cnt=1;
893
                /* push a zero */
896
                /* push a zero */
894
                rawbits = rawbits<<1;
897
                rawbits = rawbits<<1;
Line 942... Line 945...
942
 *
945
 *
943
 * @param buf
946
 * @param buf
944
 *      Pointer to buffer to store the expanded data
947
 *      Pointer to buffer to store the expanded data
945
 * @param len
948
 * @param len
946
 *      Pointer to length of the data
949
 *      Pointer to length of the data
947
 * @param proto
950
 * @param proto
948
 *      Pointer to protocol information
951
 *      Pointer to protocol information
949
 * @return
952
 * @return
950
 *      IR_OK if data expanded successfully, one of several errormessages if not
953
 *      IR_OK if data expanded successfully, one of several errormessages if not
951
 */
954
 */
952
int8_t expandSky(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
955
int8_t expandSky(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
953
    //TODO: Implement this function.
956
    //TODO: Implement this function.
Line 972... Line 975...
972
 *      Pointer to protocol information
975
 *      Pointer to protocol information
973
 * @return
976
 * @return
974
 *      IR_OK if data parsed successfully, one of several errormessages if not
977
 *      IR_OK if data parsed successfully, one of several errormessages if not
975
 */
978
 */
976
 
979
 
977
int8_t parseNexa2(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
980
int8_t parseNexa2(const uint16_t *buf, uint8_t len, uint8_t index, Ir_Protocol_Data_t *proto)
-
 
981
{
978
    /* check if we have correct amount of data */
982
    /* check if we have correct amount of data */
979
    if (len < 132) {
983
    if (len < 132) {
980
        return IR_NOT_CORRECT_DATA;
984
        return IR_NOT_CORRECT_DATA;
981
    }
985
    }
-
 
986
    uint8_t i;
-
 
987
#if IR_RX_CONTINUOUS_MODE==0
-
 
988
    i = 0;
982
 
989
#else
-
 
990
    i=index-132;
-
 
991
    if (i>index)
-
 
992
        i+=MAX_NR_TIMES;
-
 
993
#endif
983
    if ((buf[len-132] < IR_NEXA2_START1 - IR_NEXA2_START1/IR_NEXA2_TOL_DIV) || (buf[len-132] > IR_NEXA2_START1 + IR_NEXA2_START1/IR_NEXA2_TOL_DIV)) { //check start bit
994
    if ((buf[i] < IR_NEXA2_START1 - IR_NEXA2_START1/IR_NEXA2_TOL_DIV) || (buf[i] > IR_NEXA2_START1 + IR_NEXA2_START1/IR_NEXA2_TOL_DIV)) { //check start bit
984
        return IR_NOT_CORRECT_DATA;
995
        return IR_NOT_CORRECT_DATA;
985
    }
996
    }
-
 
997
#if IR_RX_CONTINUOUS_MODE==0
-
 
998
    i = 1;
-
 
999
#else
-
 
1000
    i=index-131;
-
 
1001
    if (i>index)
-
 
1002
        i+=MAX_NR_TIMES;
-
 
1003
#endif
986
    if ((buf[len-131] < IR_NEXA2_HIGH - IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV) || (buf[len-131] > IR_NEXA2_HIGH + IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV)) { //check start bit
1004
    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)) { //check start bit
987
        return IR_NOT_CORRECT_DATA;
1005
        return IR_NOT_CORRECT_DATA;
988
    }
1006
    }
-
 
1007
#if IR_RX_CONTINUOUS_MODE==0
-
 
1008
    i = 2;
-
 
1009
#else
-
 
1010
    i=index-130;
-
 
1011
    if (i>index)
-
 
1012
        i+=MAX_NR_TIMES;
-
 
1013
#endif
989
    if ((buf[len-130] < IR_NEXA2_START2 - IR_NEXA2_START2/IR_NEXA2_TOL_DIV) || (buf[len-130] > IR_NEXA2_START2 + IR_NEXA2_START2/IR_NEXA2_TOL_DIV)) { //check start bit
1014
    if ((buf[i] < IR_NEXA2_START2 - IR_NEXA2_START2/IR_NEXA2_TOL_DIV) || (buf[i] > IR_NEXA2_START2 + IR_NEXA2_START2/IR_NEXA2_TOL_DIV)) { //check start bit
990
        return IR_NOT_CORRECT_DATA;
1015
        return IR_NOT_CORRECT_DATA;
991
    }
1016
    }
992
 
1017
 
993
    /* Incoming data could actually be longer than 32bits when a dimming command is received */
1018
    /* Incoming data could actually be longer than 32bits when a dimming command is received */
994
    uint64_t rawbitsTemp = 0;
1019
    uint64_t rawbitsTemp = 0;
995
    uint8_t bitCounter = 0;
1020
    uint8_t bitCounter = 0;
-
 
1021
    uint8_t i2;
996
    for (uint8_t i = len-129; i < len; i++) {
1022
    for (i = 3; i < 132; i++) {
-
 
1023
#if IR_RX_CONTINUOUS_MODE==0
-
 
1024
        i2 = i;
-
 
1025
#else
-
 
1026
        i2=index-(132-i);
-
 
1027
        if (i2>index)
-
 
1028
            i2+=MAX_NR_TIMES;
-
 
1029
#endif
997
        if ((i&1) == 0) {       /* if even, data */
1030
        if ((i&1) == 0) {       /* if even, data */
998
            /* check length of transmit pulse */
1031
            /* check length of transmit pulse */
999
            if (buf[i] > IR_NEXA2_LOW_ONE - IR_NEXA2_LOW_ONE/IR_NEXA2_TOL_DIV && buf[i] < IR_NEXA2_LOW_ONE + IR_NEXA2_LOW_ONE/IR_NEXA2_TOL_DIV) {
1032
            if ((buf[i2] > IR_NEXA2_LOW_ONE - IR_NEXA2_LOW_ONE/IR_NEXA2_TOL_DIV) && (buf[i2] < IR_NEXA2_LOW_ONE + IR_NEXA2_LOW_ONE/IR_NEXA2_TOL_DIV)) {
1000
                /* write a one */
1033
                /* write a one */
1001
                rawbitsTemp |= (1UL)<<(bitCounter++);
1034
                rawbitsTemp |= (1UL)<<(bitCounter++);
1002
            } else if (buf[i] > IR_NEXA2_LOW_ZERO - IR_NEXA2_LOW_ZERO/IR_NEXA2_TOL_DIV && buf[i] < IR_NEXA2_LOW_ZERO + IR_NEXA2_LOW_ZERO/IR_NEXA2_TOL_DIV) {
1035
            } else if ((buf[i2] > IR_NEXA2_LOW_ZERO - IR_NEXA2_LOW_ZERO/IR_NEXA2_TOL_DIV) && (buf[i2] < IR_NEXA2_LOW_ZERO + IR_NEXA2_LOW_ZERO/IR_NEXA2_TOL_DIV)) {
1003
                /* do nothing, a zero is already in rawbits */
1036
                /* do nothing, a zero is already in rawbits */
1004
                bitCounter++;
1037
                bitCounter++;
1005
            } else {
1038
            } else {
1006
                return IR_NOT_CORRECT_DATA;
1039
                return IR_NOT_CORRECT_DATA;
1007
            }
1040
            }
1008
            i+=2;   // skip every other bit, implement check here in the future
1041
            i+=2;   // skip every other bit, implement check here in the future
1009
        } else {            /* if odd, no data */
1042
        } else {            /* if odd, no data */
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) {
1043
            if ((buf[i2] < IR_NEXA2_HIGH - IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV) && (buf[i2] > IR_NEXA2_HIGH + IR_NEXA2_HIGH/IR_NEXA2_TOL_DIV)) {
1011
                return IR_NOT_CORRECT_DATA;
1044
                return IR_NOT_CORRECT_DATA;
1012
            }
1045
            }
1013
        }
1046
        }
1014
    }
1047
    }
1015
   
1048
   
Line 1090... Line 1123...
1090
 * @param proto
1123
 * @param proto
1091
 *      Pointer to protocol information
1124
 *      Pointer to protocol information
1092
 * @return
1125
 * @return
1093
 *      IR_OK if data parsed successfully, one of several errormessages if not
1126
 *      IR_OK if data parsed successfully, one of several errormessages if not
1094
 */
1127
 */
1095
int8_t parseNexa1(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
1128
int8_t parseNexa1(const uint16_t *buf, uint8_t len, uint8_t index, Ir_Protocol_Data_t *proto) {
1096
    /* parse buf[], max is len */
1129
    /* parse buf[], max is len */
1097
 
1130
 
1098
    /* check if we have correct amount of data */
1131
    /* check if we have correct amount of data */
1099
    if (len != 50) {
1132
    if (len != 50) {
1100
        return IR_NOT_CORRECT_DATA;
1133
        return IR_NOT_CORRECT_DATA;