Subversion Repositories HomeAutomation

Rev

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

Rev 2254 Rev 2259
Line 7... Line 7...
7
 *  
7
 *  
8
 */
8
 */
9
 
9
 
10
#include "protocols.h"
10
#include "protocols.h"
11
#include <bios.h>
11
#include <bios.h>
-
 
12
#include <drivers/mcu/gpio.h>
12
 
13
 
13
#include <drivers/can/moduleid.h>
14
#include <drivers/can/moduleid.h>
14
 
15
 
15
//#include <drivers/mcu/gpio.h>
16
//#include <drivers/mcu/gpio.h>
16
 
17
 
Line 68... Line 69...
68
#if (IR_PROTOCOLS_USE_RUBICSON)
69
#if (IR_PROTOCOLS_USE_RUBICSON)
69
    res = parseRubicson(buf, len, index, proto);
70
    res = parseRubicson(buf, len, index, proto);
70
    if (res!=IR_NOT_CORRECT_DATA) return res;
71
    if (res!=IR_NOT_CORRECT_DATA) return res;
71
#endif
72
#endif
72
#if (IR_PROTOCOLS_USE_OREGON)
73
#if (IR_PROTOCOLS_USE_OREGON)
-
 
74
   
73
    res = parseOregon(buf, len, index, proto);
75
    res = parseOregon(buf, len, index, proto);
-
 
76
    gpio_clr_pin(EXP_K);
-
 
77
    gpio_clr_pin(EXP_L);
-
 
78
    gpio_clr_pin(EXP_M);
-
 
79
    gpio_clr_pin(EXP_N);
74
    if (res!=IR_NOT_CORRECT_DATA) return res;
80
    if (res!=IR_NOT_CORRECT_DATA) return res;
75
#endif      
81
#endif      
76
   
82
   
77
    /* No protocol matched. */
83
    /* No protocol matched. */
78
    proto->protocol = IR_PROTO_UNKNOWN;
84
    proto->protocol = IR_PROTO_UNKNOWN;
Line 119... Line 125...
119
}
125
}
120
 
126
 
121
#if (IR_PROTOCOLS_USE_SIRC)
127
#if (IR_PROTOCOLS_USE_SIRC)
122
/**
128
/**
123
 * Test data on SIRC protocol, 12-bit version
129
 * Test data on SIRC protocol, 12-bit version
124
 * http://www.sbprojects.com/knowledge/ir/sirc.htm
130
 * http://www.sbprojects.com/knowledge/ir/sirc.htm
125
 * http://picprojects.org.uk/projects/sirc/sonysirc.pdf
131
 * http://picprojects.org.uk/projects/sirc/sonysirc.pdf
126
 *
132
 *
127
 * @param buf
133
 * @param buf
128
 *      Pointer to buffer to where to data to parse is stored
134
 *      Pointer to buffer to where to data to parse is stored
129
 * @param len
135
 * @param len
Line 140... Line 146...
140
           supporting two versions of SIRC:
146
           supporting two versions of SIRC:
141
           12 bit = 25, 15 bit = 31
147
           12 bit = 25, 15 bit = 31
142
           there is also a 20 bit protocol, but we don't support it
148
           there is also a 20 bit protocol, but we don't support it
143
         */
149
         */
144
    if (len != 25 && len != 31) {
150
    if (len != 25 && len != 31) {
145
        return IR_NOT_CORRECT_DATA;
151
        return IR_NOT_CORRECT_DATA;
146
    }
152
    }
147
   
153
   
148
    /* check startbit */
154
    /* check startbit */
149
    if (buf[0] > IR_SIRC_ST_BIT + IR_SIRC_ST_BIT/IR_SIRC_TOL_DIV || buf[0] < IR_SIRC_ST_BIT - IR_SIRC_ST_BIT/IR_SIRC_TOL_DIV) {
155
    if (buf[0] > IR_SIRC_ST_BIT + IR_SIRC_ST_BIT/IR_SIRC_TOL_DIV || buf[0] < IR_SIRC_ST_BIT - IR_SIRC_ST_BIT/IR_SIRC_TOL_DIV) {
150
        return IR_NOT_CORRECT_DATA;
156
        return IR_NOT_CORRECT_DATA;
151
    }
157
    }
152
   
158
   
153
    uint16_t rawbits=0;
159
    uint16_t rawbits=0;
154
   
160
   
155
    for (uint8_t i = 1; i < len; i++) {
161
    for (uint8_t i = 1; i < len; i++) {
156
        if ((i&1) == 1) {       /* if odd, ir-pause */
162
        if ((i&1) == 1) {       /* if odd, ir-pause */
157
            /* check length of pause between bits */
163
            /* check length of pause between bits */
Line 169... Line 175...
169
            }
175
            }
170
        }
176
        }
171
    }
177
    }
172
   
178
   
173
    proto->protocol = CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_SIRC;
179
    proto->protocol = CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_SIRC;
174
    proto->timeout = IR_SIRC_TIMEOUT;
180
    proto->timeout = IR_SIRC_TIMEOUT;
175
    proto->data = rawbits;
181
    proto->data = rawbits;
176
   
182
   
177
    return IR_OK;
183
    return IR_OK;
178
}
184
}
179
#endif
185
#endif
180
 
186
 
181
/**
187
/**
Line 275... Line 281...
275
int8_t rc5_toggle=0;
281
int8_t rc5_toggle=0;
276
 
282
 
277
/**
283
/**
278
 * Expand data from RC5 protocol
284
 * Expand data from RC5 protocol
279
 * http://www.sbprojects.com/knowledge/ir/rc5.htm
285
 * http://www.sbprojects.com/knowledge/ir/rc5.htm
280
 *
286
 *
281
 * One is defined as low then high
287
 * One is defined as low then high
282
 * Zero is defined as high then low
288
 * Zero is defined as high then low
283
 *
289
 *
284
 * @param buf
290
 * @param buf
285
 *      Pointer to buffer to store the expanded data
291
 *      Pointer to buffer to store the expanded data
Line 293... Line 299...
293
int8_t expandRC5(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
299
int8_t expandRC5(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
294
 
300
 
295
    //This is the raw message that we should create the IR times for
301
    //This is the raw message that we should create the IR times for
296
    //Lets copy the data locally to ensure that no interups will modify the vector.
302
    //Lets copy the data locally to ensure that no interups will modify the vector.
297
    uint16_t rawMessage=proto->data & 0x3fff;
303
    uint16_t rawMessage=proto->data & 0x3fff;
298
   
304
   
299
    uint8_t previousBit;
305
    uint8_t previousBit;
300
    /* Set up startbit */
306
    /* Set up startbit */
301
    //Bit = 0
307
    //Bit = 0
302
    //We start with a low signal since the diode 
308
    //We start with a low signal since the diode 
303
    //isn't active before we send anything,
309
    //isn't active before we send anything,
304
    buf[0] = IR_RC5_HALF_BIT;//first start bit
310
    buf[0] = IR_RC5_HALF_BIT;//first start bit
305
   
311
   
306
    // Bit = 1
312
    // Bit = 1
307
    buf[1] = IR_RC5_HALF_BIT;
313
    buf[1] = IR_RC5_HALF_BIT;
308
    buf[2] = IR_RC5_HALF_BIT;//second start bit
314
    buf[2] = IR_RC5_HALF_BIT;//second start bit
309
 
315
 
310
    if (rc5_toggle==0){
316
    if (rc5_toggle==0){
Line 352... Line 358...
352
    if(previousBit == 0)
358
    if(previousBit == 0)
353
    {
359
    {
354
        //We have to remove the last time since that would bring us to a high signal again.
360
        //We have to remove the last time since that would bring us to a high signal again.
355
        *len=*len-1;
361
        *len=*len-1;
356
        buf[*len]=0;
362
        buf[*len]=0;
357
    }
363
    }
358
   
364
   
359
    proto->modfreq=IR_RC5_F_MOD;
365
    proto->modfreq=IR_RC5_F_MOD;
360
    proto->timeout=IR_RC5_TIMEOUT;
366
    proto->timeout=IR_RC5_TIMEOUT;
361
    proto->repeats=IR_RC5_REPS;
367
    proto->repeats=IR_RC5_REPS;
362
    return IR_OK;
368
    return IR_OK;
Line 376... Line 382...
376
 *      Pointer to protocol information
382
 *      Pointer to protocol information
377
 * @return
383
 * @return
378
 *      IR_OK if data parsed successfully, one of several errormessages if not
384
 *      IR_OK if data parsed successfully, one of several errormessages if not
379
 */
385
 */
380
int8_t parseSharp(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
386
int8_t parseSharp(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
381
    /* parse buf[], max is len */
387
    /* parse buf[], max is len */
382
 
388
 
383
    /* check if we have correct amount of data */
389
    /* check if we have correct amount of data */
384
    if (len != 31) {
390
    if (len != 31) {
385
        return IR_NOT_CORRECT_DATA;
391
        return IR_NOT_CORRECT_DATA;
386
    }
392
    }
387
   
393
   
388
    uint16_t rawbits=0;
394
    uint16_t rawbits=0;
Line 482... Line 488...
482
            }
488
            }
483
        }
489
        }
484
    }
490
    }
485
 
491
 
486
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_NEC;
492
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_NEC;
487
    proto->timeout=IR_NEC_TIMEOUT;
493
    proto->timeout=IR_NEC_TIMEOUT;
488
    proto->data=rawbits;   
494
    proto->data=rawbits;   
489
    return IR_OK;
495
    return IR_OK;
490
}
496
}
491
#endif
497
#endif
492
 
498
 
493
/**
499
/**
Line 529... Line 535...
529
        proto->timeout=IR_NEC_ST_TIMEOUT;
535
        proto->timeout=IR_NEC_ST_TIMEOUT;
530
        *len = 3;
536
        *len = 3;
531
    }
537
    }
532
    proto->modfreq=IR_NEC_F_MOD;
538
    proto->modfreq=IR_NEC_F_MOD;
533
    proto->repeats=IR_NEC_REPS;
539
    proto->repeats=IR_NEC_REPS;
534
    return IR_OK;
540
    return IR_OK;
535
}
541
}
536
 
542
 
537
 
543
 
538
#if (IR_PROTOCOLS_USE_SAMSUNG)
544
#if (IR_PROTOCOLS_USE_SAMSUNG)
539
/**
545
/**
540
 * Test data on Samsung protocol
546
 * Test data on Samsung protocol
541
 * Very much like NEC, different start bit/pause lengths etc.
547
 * Very much like NEC, different start bit/pause lengths etc.
Line 576... Line 582...
576
            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) {
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) {
577
                /* write a one */
583
                /* write a one */
578
                rawbits |= 1UL<<((i-3)>>1);
584
                rawbits |= 1UL<<((i-3)>>1);
579
            } 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) {
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) {
580
                /* do nothing, a zero is already in rawbits */
586
                /* do nothing, a zero is already in rawbits */
581
            } else {
587
            } else {
582
                return IR_NOT_CORRECT_DATA;
588
                return IR_NOT_CORRECT_DATA;
583
            }
589
            }
584
        } else {            /* if even, ir-bit */
590
        } else {            /* if even, ir-bit */
585
            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) {
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) {
586
                return IR_NOT_CORRECT_DATA;
592
                return IR_NOT_CORRECT_DATA;
587
            }
593
            }
588
        }
594
        }
589
    }
595
    }
590
   
596
   
591
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_SAMSUNG;
597
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_SAMSUNG;
592
    proto->timeout=IR_SAMS_TIMEOUT;
598
    proto->timeout=IR_SAMS_TIMEOUT;
593
    proto->data=rawbits;   
599
    proto->data=rawbits;   
Line 597... Line 603...
597
 
603
 
598
/**
604
/**
599
 * Expand data from Samsung protocol
605
 * Expand data from Samsung protocol
600
 * Very much like NEC, different start bit/pause lengths etc.
606
 * Very much like NEC, different start bit/pause lengths etc.
601
 * http://www.sbprojects.com/knowledge/ir/nec.htm
607
 * http://www.sbprojects.com/knowledge/ir/nec.htm
602
 *
608
 *
603
 * @param buf
609
 * @param buf
604
 *      Pointer to buffer to store the expanded data
610
 *      Pointer to buffer to store the expanded data
605
 * @param len
611
 * @param len
606
 *      Pointer to length of the data
612
 *      Pointer to length of the data
607
 * @param proto
613
 * @param proto
608
 *      Pointer to protocol information
614
 *      Pointer to protocol information
609
 * @return
615
 * @return
610
 *      IR_OK if data expanded successfully, one of several errormessages if not
616
 *      IR_OK if data expanded successfully, one of several errormessages if not
611
 */
617
 */
612
int8_t expandSamsung(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
618
int8_t expandSamsung(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
613
    /* Set up startbit */
619
    /* Set up startbit */
614
    buf[0] = IR_SAMS_ST_BIT;
620
    buf[0] = IR_SAMS_ST_BIT;
615
    buf[1] = IR_SAMS_ST_PAUSE;
621
    buf[1] = IR_SAMS_ST_PAUSE;
616
   
622
   
Line 622... Line 628...
622
                buf[i+2] = IR_SAMS_LOW_ZERO;
628
                buf[i+2] = IR_SAMS_LOW_ZERO;
623
            }
629
            }
624
        } else {                /* if even, ir-bit */
630
        } else {                /* if even, ir-bit */
625
            buf[i+2] = IR_SAMS_HIGH;
631
            buf[i+2] = IR_SAMS_HIGH;
626
        }
632
        }
627
    }
633
    }
628
   
634
   
629
    *len = 67;
635
    *len = 67;
630
   
636
   
631
    proto->modfreq=IR_SAMS_F_MOD;
637
    proto->modfreq=IR_SAMS_F_MOD;
632
    proto->timeout=IR_SAMS_TIMEOUT;
638
    proto->timeout=IR_SAMS_TIMEOUT;
633
    proto->repeats=IR_SAMS_REPS;
639
    proto->repeats=IR_SAMS_REPS;
634
    return IR_OK;
640
    return IR_OK;
635
}
641
}
636
 
642
 
637
#if (IR_PROTOCOLS_USE_MARANTZ)
643
#if (IR_PROTOCOLS_USE_MARANTZ)
638
/**
644
/**
639
 * Test data on Marantz protocol
645
 * Test data on Marantz protocol
640
 * Reverse-Engineered by Noddan, very similar to RC-5.
646
 * Reverse-Engineered by Noddan, very similar to RC-5.
641
 * Not tested with odd adresses since I have no remote that sends them.
647
 * Not tested with odd adresses since I have no remote that sends them.
Line 682... Line 688...
682
}
688
}
683
#endif
689
#endif
684
 
690
 
685
/**
691
/**
686
 * Expand data from Marantz. Written by Martin Nordin
692
 * Expand data from Marantz. Written by Martin Nordin
687
 *
693
 *
688
 * @param buf
694
 * @param buf
689
 *      Pointer to buffer to store the expanded data
695
 *      Pointer to buffer to store the expanded data
690
 * @param len
696
 * @param len
691
 *      Pointer to length of the data
697
 *      Pointer to length of the data
692
 * @param proto
698
 * @param proto
693
 *      Pointer to protocol information
699
 *      Pointer to protocol information
694
 * @return
700
 * @return
695
 *      IR_OK if data expanded successfully, one of several errormessages if not
701
 *      IR_OK if data expanded successfully, one of several errormessages if not
696
 */
702
 */
697
int8_t expandMarantz(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
703
int8_t expandMarantz(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
698
    uint8_t previousBit;
704
    uint8_t previousBit;
699
    uint32_t tempdata;
705
    uint32_t tempdata;
700
   
706
   
701
    /* Set up startbits */
707
    /* Set up startbits */
702
    buf[0] = IR_MARANTZ_HALF_BIT;//first start bit
708
    buf[0] = IR_MARANTZ_HALF_BIT;//first start bit
703
    buf[1] = IR_MARANTZ_HALF_BIT;
709
    buf[1] = IR_MARANTZ_HALF_BIT;
704
    buf[2] = IR_MARANTZ_HALF_BIT;//second start bit
710
    buf[2] = IR_MARANTZ_HALF_BIT;//second start bit
705
    //TODO: Toggle bit should be better, not hard-coded
711
    //TODO: Toggle bit should be better, not hard-coded
Line 717... Line 723...
717
            if (previousBit == 1){//11
723
            if (previousBit == 1){//11
718
                buf[*len] = IR_MARANTZ_HALF_BIT;
724
                buf[*len] = IR_MARANTZ_HALF_BIT;
719
                buf[*len+1] = IR_MARANTZ_HALF_BIT;
725
                buf[*len+1] = IR_MARANTZ_HALF_BIT;
720
                *len = *len + 2;
726
                *len = *len + 2;
721
            } else {//01
727
            } else {//01
722
                buf[*len-1] = IR_MARANTZ_BIT;
728
                buf[*len-1] = IR_MARANTZ_BIT;
723
                buf[*len] = IR_MARANTZ_HALF_BIT;
729
                buf[*len] = IR_MARANTZ_HALF_BIT;
724
                *len = *len + 1;
730
                *len = *len + 1;
725
            }
731
            }
726
            previousBit = 1;
732
            previousBit = 1;
727
        } else {
733
        } else {
Line 743... Line 749...
743
        }
749
        }
744
    }
750
    }
745
    //make sure that we finish high by removing the last zero if needed
751
    //make sure that we finish high by removing the last zero if needed
746
    if (*len%2 == 0){
752
    if (*len%2 == 0){
747
        *len = *len - 1;
753
        *len = *len - 1;
748
    }
754
    }
749
 
755
 
750
    proto->modfreq=IR_MARANTZ_F_MOD;
756
    proto->modfreq=IR_MARANTZ_F_MOD;
751
    proto->timeout=IR_MARANTZ_TIMEOUT;
757
    proto->timeout=IR_MARANTZ_TIMEOUT;
752
    proto->repeats=IR_MARANTZ_REPS;
758
    proto->repeats=IR_MARANTZ_REPS;
753
    return IR_OK;
759
    return IR_OK;
754
}
760
}
755
 
761
 
756
#if (IR_PROTOCOLS_USE_PANASONIC)
762
#if (IR_PROTOCOLS_USE_PANASONIC)
757
/**
763
/**
758
 * Test data on Panasonic protocol
764
 * Test data on Panasonic protocol
759
 *
765
 *
760
 * @param buf
766
 * @param buf
Line 769... Line 775...
769
int8_t parsePanasonic(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
775
int8_t parsePanasonic(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
770
    /* parse buf[], max is len */
776
    /* parse buf[], max is len */
771
 
777
 
772
    /* check if we have correct amount of data */
778
    /* check if we have correct amount of data */
773
    if (len != 99) {
779
    if (len != 99) {
774
        return IR_NOT_CORRECT_DATA;
780
        return IR_NOT_CORRECT_DATA;
775
    }
781
    }
776
   
782
   
777
    /* check startbit */
783
    /* check startbit */
778
    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) {
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) {
779
        return IR_NOT_CORRECT_DATA;
785
        return IR_NOT_CORRECT_DATA;
780
    }
786
    }
781
 
787
 
782
    /* check pause after startbit */
788
    /* check pause after startbit */
783
    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) {
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) {
784
        return IR_NOT_CORRECT_DATA;
790
        return IR_NOT_CORRECT_DATA;
785
    }
791
    }
786
 
792
 
787
    uint32_t rawbits = 0;
793
    uint32_t rawbits = 0;
788
   
794
   
789
    /* skip start bit, start bit pause and first 16 bits (32 values) */
795
    /* skip start bit, start bit pause and first 16 bits (32 values) */
790
    for (uint8_t i = (3+16*2); i < len; i++) {
796
    for (uint8_t i = (3+16*2); i < len; i++) {
Line 793... Line 799...
793
            if (buf[i] > IR_PANA_LOW_ONE - IR_PANA_LOW_ONE/IR_PANA_TOL_DIV && buf[i] < IR_PANA_LOW_ONE + IR_PANA_LOW_ONE/IR_PANA_TOL_DIV) {
799
            if (buf[i] > IR_PANA_LOW_ONE - IR_PANA_LOW_ONE/IR_PANA_TOL_DIV && buf[i] < IR_PANA_LOW_ONE + IR_PANA_LOW_ONE/IR_PANA_TOL_DIV) {
794
                /* write a one */
800
                /* write a one */
795
                rawbits |= 1UL<<((i-(3+16*2))>>1);
801
                rawbits |= 1UL<<((i-(3+16*2))>>1);
796
            } else if (buf[i] > IR_PANA_LOW_ZERO - IR_PANA_LOW_ZERO/IR_PANA_TOL_DIV && buf[i] < IR_PANA_LOW_ZERO + IR_PANA_LOW_ZERO/IR_PANA_TOL_DIV) {
802
            } else if (buf[i] > IR_PANA_LOW_ZERO - IR_PANA_LOW_ZERO/IR_PANA_TOL_DIV && buf[i] < IR_PANA_LOW_ZERO + IR_PANA_LOW_ZERO/IR_PANA_TOL_DIV) {
797
                /* do nothing, a zero is already in rawbits */
803
                /* do nothing, a zero is already in rawbits */
798
            } else {
804
            } else {
799
                return IR_NOT_CORRECT_DATA;
805
                return IR_NOT_CORRECT_DATA;
800
            }
806
            }
801
        } else {            /* if even, ir-bit */
807
        } else {            /* if even, ir-bit */
802
            if (buf[i] > IR_PANA_HIGH + IR_PANA_HIGH/IR_PANA_TOL_DIV || buf[i] < IR_PANA_HIGH - IR_PANA_HIGH/IR_PANA_TOL_DIV) {
808
            if (buf[i] > IR_PANA_HIGH + IR_PANA_HIGH/IR_PANA_TOL_DIV || buf[i] < IR_PANA_HIGH - IR_PANA_HIGH/IR_PANA_TOL_DIV) {
803
                return IR_NOT_CORRECT_DATA;
809
                return IR_NOT_CORRECT_DATA;
804
            }
810
            }
805
        }
811
        }
806
    }
812
    }
807
   
813
   
808
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_PANASONIC;
814
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_PANASONIC;
809
    proto->timeout=IR_PANA_TIMEOUT;
815
    proto->timeout=IR_PANA_TIMEOUT;
810
    proto->data=rawbits;   
816
    proto->data=rawbits;   
811
    return IR_OK;
817
    return IR_OK;
812
}
818
}
Line 821... Line 827...
821
 *      Pointer to length of the data
827
 *      Pointer to length of the data
822
 * @param proto
828
 * @param proto
823
 *      Pointer to protocol information
829
 *      Pointer to protocol information
824
 * @return
830
 * @return
825
 *      IR_OK if data expanded successfully, one of several errormessages if not
831
 *      IR_OK if data expanded successfully, one of several errormessages if not
826
 */
832
 */
827
int8_t expandPanasonic(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
833
int8_t expandPanasonic(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
828
    /* Set up startbit */
834
    /* Set up startbit */
829
    buf[0] = IR_PANA_ST_BIT;
835
    buf[0] = IR_PANA_ST_BIT;
830
    buf[1] = IR_PANA_ST_PAUSE;
836
    buf[1] = IR_PANA_ST_PAUSE;
831
   
837
   
Line 896... Line 902...
896
    {
902
    {
897
        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) {
903
        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) {
898
            current = SKYSHORT;
904
            current = SKYSHORT;
899
        }
905
        }
900
        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) {
906
        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) {
901
            current = SKYLONG;
907
            current = SKYLONG;
902
        }
-
 
903
        else {
-
 
904
            return IR_NOT_CORRECT_DATA;
-
 
905
        }
908
        }
906
       
-
 
907
        /* if level is low */
-
 
908
        if ((rawbits&1)==0) {
-
 
909
            /* and there is a long pulse */
-
 
910
            if (current == SKYLONG) {
-
 
911
                /* push a one */
-
 
912
                rawbits = rawbits<<1;
-
 
913
                rawbits |= 1;
-
 
914
                cnt = 0;
-
 
915
            }
-
 
916
            else if (cnt == 0) {
-
 
917
                cnt=1;
-
 
918
                /* push a zero */
-
 
919
                rawbits = rawbits<<1;
-
 
920
               
-
 
921
            }
-
 
922
            else {
909
        else {
923
                cnt = 0;
910
            return IR_NOT_CORRECT_DATA;
924
            }
-
 
925
        }
911
        }
926
       
912
       
-
 
913
        /* if level is low */
-
 
914
        if ((rawbits&1)==0) {
-
 
915
            /* and there is a long pulse */
-
 
916
            if (current == SKYLONG) {
-
 
917
                /* push a one */
-
 
918
                rawbits = rawbits<<1;
-
 
919
                rawbits |= 1;
-
 
920
                cnt = 0;
-
 
921
            }
-
 
922
            else if (cnt == 0) {
-
 
923
                cnt=1;
-
 
924
                /* push a zero */
-
 
925
                rawbits = rawbits<<1;
-
 
926
               
-
 
927
            }
-
 
928
            else {
-
 
929
                cnt = 0;
-
 
930
            }
-
 
931
        }
-
 
932
       
927
        /* if level is high */
933
        /* if level is high */
928
        if ((rawbits&1)==1) {
934
        if ((rawbits&1)==1) {
929
            /* and there is a long pulse */
935
            /* and there is a long pulse */
930
            if (current == SKYLONG) {
936
            if (current == SKYLONG) {
931
                /* push a zero */
937
                /* push a zero */
932
                rawbits = rawbits<<1;
938
                rawbits = rawbits<<1;
933
               
939
               
Line 975... Line 981...
975
 *      IR_OK if data expanded successfully, one of several errormessages if not
981
 *      IR_OK if data expanded successfully, one of several errormessages if not
976
 */
982
 */
977
int8_t expandSky(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
983
int8_t expandSky(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
978
    //TODO: Implement this function.
984
    //TODO: Implement this function.
979
    buf[0] = IR_SKY_ST_BIT;
985
    buf[0] = IR_SKY_ST_BIT;
980
    buf[1] = IR_SKY_LONG;   //
986
    buf[1] = IR_SKY_LONG;   //
981
   
987
   
982
   
988
   
983
    return IR_NOT_CORRECT_DATA;
989
    return IR_NOT_CORRECT_DATA;
984
}
990
}
985
 
991
 
986
#if (IR_PROTOCOLS_USE_IROBOT)
992
#if (IR_PROTOCOLS_USE_IROBOT)
987
/**
993
/**
988
 * Test data on iRobot protocol
994
 * Test data on iRobot protocol
989
 *
995
 *
990
 *
996
 *
991
 * @param buf
997
 * @param buf
992
 *      Pointer to buffer to where to data to parse is stored
998
 *      Pointer to buffer to where to data to parse is stored
993
 * @param len
999
 * @param len
994
 *      Length of the data
1000
 *      Length of the data
995
 * @param proto
1001
 * @param proto
Line 1003... Line 1009...
1003
    uint8_t current=0;
1009
    uint8_t current=0;
1004
    uint8_t previous=0;
1010
    uint8_t previous=0;
1005
    uint8_t cnt=0;
1011
    uint8_t cnt=0;
1006
#define IROBOTLONG 0
1012
#define IROBOTLONG 0
1007
#define IROBOTSHORT 1
1013
#define IROBOTSHORT 1
1008
 
1014
 
1009
    /* check if we have correct amount of data */
1015
    /* check if we have correct amount of data */
1010
    if (len != 16) {
1016
    if (len != 16) {
1011
        return IR_NOT_CORRECT_DATA;
1017
        return IR_NOT_CORRECT_DATA;
1012
    }
1018
    }
1013
   
1019
   
1014
 
1020
 
1015
    for (uint8_t i = 0; i < len; i++)
1021
    for (uint8_t i = 0; i < len; i++)
1016
    {
1022
    {
1017
        if (buf[i] > IR_IROBOT_SHORT - IR_IROBOT_SHORT/IR_IROBOT_TOL_DIV && buf[i] < IR_IROBOT_SHORT + IR_IROBOT_SHORT/IR_IROBOT_TOL_DIV) {
1023
        if (buf[i] > IR_IROBOT_SHORT - IR_IROBOT_SHORT/IR_IROBOT_TOL_DIV && buf[i] < IR_IROBOT_SHORT + IR_IROBOT_SHORT/IR_IROBOT_TOL_DIV) {
1018
            current = IROBOTSHORT;
1024
            current = IROBOTSHORT;
Line 1024... Line 1030...
1024
            return IR_NOT_CORRECT_DATA;
1030
            return IR_NOT_CORRECT_DATA;
1025
        }
1031
        }
1026
       
1032
       
1027
        /* if level is low */
1033
        /* if level is low */
1028
        if ((rawbits&1)==0) {
1034
        if ((rawbits&1)==0) {
1029
            /* and there is a long pulse */
1035
            /* and there is a long pulse */
1030
            if (current == IROBOTLONG) {
1036
            if (current == IROBOTLONG) {
1031
                /* push a one */
1037
                /* push a one */
1032
                rawbits = rawbits<<1;
1038
                rawbits = rawbits<<1;
1033
                rawbits |= 1;
1039
                rawbits |= 1;
1034
                cnt = 0;
1040
                cnt = 0;
1035
            }
1041
            }
1036
            else if (cnt == 0) {
1042
            else if (cnt == 0) {
1037
                cnt=1;
1043
                cnt=1;
1038
                /* push a zero */
1044
                /* push a zero */
1039
                rawbits = rawbits<<1;
1045
                rawbits = rawbits<<1;
1040
               
1046
               
1041
            }
1047
            }
1042
            else {
1048
            else {
1043
                cnt = 0;
1049
                cnt = 0;
1044
            }
1050
            }
1045
        }
1051
        }
1046
       
1052
       
1047
        /* if level is high */
1053
        /* if level is high */
1048
        if ((rawbits&1)==1) {
1054
        if ((rawbits&1)==1) {
1049
            /* and there is a long pulse */
1055
            /* and there is a long pulse */
1050
            if (current == IROBOTLONG) {
1056
            if (current == IROBOTLONG) {
1051
                /* push a zero */
1057
                /* push a zero */
1052
                rawbits = rawbits<<1;
1058
                rawbits = rawbits<<1;
1053
               
1059
               
1054
                if (previous == IROBOTLONG) {
1060
                if (previous == IROBOTLONG) {
1055
                    cnt = 1;
1061
                    cnt = 1;
1056
                }
1062
                }
1057
                else {
1063
                else {
1058
                    cnt = 0;
1064
                    cnt = 0;
1059
                }
1065
                }
1060
            }
1066
            }
1061
            else if (cnt == 0) {
1067
            else if (cnt == 0) {
1062
                cnt=1;
1068
                cnt=1;
1063
                /* push a one */
1069
                /* push a one */
1064
                rawbits = rawbits<<1;
1070
                rawbits = rawbits<<1;
1065
                rawbits |= 1;
1071
                rawbits |= 1;
1066
            }
1072
            }
1067
            else {
1073
            else {
1068
                cnt = 0;
1074
                cnt = 0;
1069
            }
1075
            }
1070
        }
1076
        }
1071
       
1077
       
1072
        previous=current;
1078
        previous=current;
1073
       
1079
       
1074
    }
1080
    }
1075
   
1081
   
1076
    proto->protocol = CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_IROBOT;
1082
    proto->protocol = CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_IROBOT;
1077
    proto->timeout = IR_IROBOT_TIMEOUT;
1083
    proto->timeout = IR_IROBOT_TIMEOUT;
1078
    proto->data = rawbits;
1084
    proto->data = rawbits;
1079
   
1085
   
Line 1082... Line 1088...
1082
#endif
1088
#endif
1083
 
1089
 
1084
/**
1090
/**
1085
 * Expand data from iRobot protocol
1091
 * Expand data from iRobot protocol
1086
 *
1092
 *
1087
 *
1093
 *
1088
 * @param buf
1094
 * @param buf
1089
 *      Pointer to buffer to store the expanded data
1095
 *      Pointer to buffer to store the expanded data
1090
 * @param len
1096
 * @param len
1091
 *      Pointer to length of the data
1097
 *      Pointer to length of the data
1092
 * @param proto
1098
 * @param proto
Line 1106... Line 1112...
1106
    proto->data = temp;
1112
    proto->data = temp;
1107
    //proto->data = temp << 8;
1113
    //proto->data = temp << 8;
1108
    //proto->data += 0x52;
1114
    //proto->data += 0x52;
1109
    for (uint8_t i = 0; i < 16; i++) {
1115
    for (uint8_t i = 0; i < 16; i++) {
1110
        if ((proto->data>>(i>>1))&1) {
1116
        if ((proto->data>>(i>>1))&1) {
1111
            buf[i] = IR_IROBOT_LONG;
1117
            buf[i] = IR_IROBOT_LONG;
1112
            i++;
1118
            i++;
1113
            buf[i] = IR_IROBOT_SHORT;  
1119
            buf[i] = IR_IROBOT_SHORT;  
1114
        } else {
1120
        } else {
1115
            buf[i] = IR_IROBOT_SHORT;
1121
            buf[i] = IR_IROBOT_SHORT;
1116
            i++;
1122
            i++;
1117
            buf[i] = IR_IROBOT_LONG;
1123
            buf[i] = IR_IROBOT_LONG;
1118
        }
1124
        }
1119
    }
1125
    }
1120
   
1126
   
1121
    *len = 15;
1127
    *len = 15;
1122
    proto->modfreq=IR_IROBOT_F_MOD;
1128
    proto->modfreq=IR_IROBOT_F_MOD;
1123
    proto->timeout=IR_IROBOT_TIMEOUT;
1129
    proto->timeout=IR_IROBOT_TIMEOUT;
1124
    proto->repeats=IR_IROBOT_REPS;
1130
    proto->repeats=IR_IROBOT_REPS;
1125
    return IR_OK;
1131
    return IR_OK;
1126
}
1132
}
1127
 
1133
 
1128
 
1134
 
1129
#if (IR_PROTOCOLS_USE_NEXA2)
1135
#if (IR_PROTOCOLS_USE_NEXA2)
1130
/**
1136
/**
1131
 * Test data on NEXA protocol
1137
 * Test data on NEXA protocol
Line 1147... Line 1153...
1147
    /* check if we have correct amount of data */
1153
    /* check if we have correct amount of data */
1148
    if (len < 132) {
1154
    if (len < 132) {
1149
        return IR_NOT_CORRECT_DATA;
1155
        return IR_NOT_CORRECT_DATA;
1150
    }
1156
    }
1151
    uint8_t i;
1157
    uint8_t i;
1152
#if IR_RX_CONTINUOUS_MODE==0
1158
#if IR_RX_CONTINUOUS_MODE==0
1153
    i = 0;
1159
    i = 0;
1154
#else
1160
#else
1155
    i=index-132;
1161
    i=index-132;
1156
    if (i>index)
1162
    if (i>index)
1157
        i+=MAX_NR_TIMES;
1163
        i+=MAX_NR_TIMES;
Line 1173... Line 1179...
1173
    i = 2;
1179
    i = 2;
1174
#else
1180
#else
1175
    i=index-130;
1181
    i=index-130;
1176
    if (i>index)
1182
    if (i>index)
1177
        i+=MAX_NR_TIMES;
1183
        i+=MAX_NR_TIMES;
1178
#endif
1184
#endif
1179
    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
1185
    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
1180
        return IR_NOT_CORRECT_DATA;
1186
        return IR_NOT_CORRECT_DATA;
1181
    }
1187
    }
1182
 
1188
 
1183
    /* Incoming data could actually be longer than 32bits when a dimming command is received */
1189
    /* Incoming data could actually be longer than 32bits when a dimming command is received */
Line 1199... Line 1205...
1199
                rawbitsTemp |= (1UL)<<(bitCounter++);
1205
                rawbitsTemp |= (1UL)<<(bitCounter++);
1200
            } 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)) {
1206
            } 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)) {
1201
                /* do nothing, a zero is already in rawbits */
1207
                /* do nothing, a zero is already in rawbits */
1202
                bitCounter++;
1208
                bitCounter++;
1203
            } else {
1209
            } else {
1204
                return IR_NOT_CORRECT_DATA;
1210
                return IR_NOT_CORRECT_DATA;
1205
            }
1211
            }
1206
            i+=2;   // skip every other bit, implement check here in the future
1212
            i+=2;   // skip every other bit, implement check here in the future
1207
        } else {            /* if odd, no data */
1213
        } else {            /* if odd, no data */
1208
            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)) {
1214
            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)) {
1209
                return IR_NOT_CORRECT_DATA;
1215
                return IR_NOT_CORRECT_DATA;
Line 1212... Line 1218...
1212
    }
1218
    }
1213
   
1219
   
1214
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_NEXA2;
1220
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_NEXA2;
1215
    proto->timeout=IR_NEXA2_TIMEOUT;
1221
    proto->timeout=IR_NEXA2_TIMEOUT;
1216
    proto->data=rawbitsTemp;
1222
    proto->data=rawbitsTemp;
1217
 
-
 
1218
    return IR_OK;
1223
    return IR_OK;
1219
}
1224
}
1220
#endif
1225
#endif
1221
 
1226
 
1222
/**
1227
/**
Line 1520... Line 1525...
1520
        i2+=MAX_NR_TIMES;
1525
        i2+=MAX_NR_TIMES;
1521
 
1526
 
1522
    proto->data=i2;     /*Store startindex for debug output */
1527
    proto->data=i2;     /*Store startindex for debug output */
1523
   
1528
   
1524
    if ((buf[i2] < IR_VIKING_STEAK_LOW_START - IR_VIKING_STEAK_LOW_START/IR_VIKING_STEAK_TOL_DIV) || (buf[i2] > IR_VIKING_STEAK_LOW_START + IR_VIKING_STEAK_LOW_START/IR_VIKING_STEAK_TOL_DIV))
1529
    if ((buf[i2] < IR_VIKING_STEAK_LOW_START - IR_VIKING_STEAK_LOW_START/IR_VIKING_STEAK_TOL_DIV) || (buf[i2] > IR_VIKING_STEAK_LOW_START + IR_VIKING_STEAK_LOW_START/IR_VIKING_STEAK_TOL_DIV))
1525
    {
1530
    {
1526
        return IR_NOT_CORRECT_DATA;
1531
        return IR_NOT_CORRECT_DATA;
1527
    }
1532
    }
1528
   
1533
   
1529
    for (i = 73; i > 0; i--)
1534
    for (i = 73; i > 0; i--)
1530
    {
1535
    {
1531
        i2=index-i;
1536
        i2=index-i;
1532
        if (i2>index)
1537
        if (i2>index)
1533
            i2+=MAX_NR_TIMES;
1538
            i2+=MAX_NR_TIMES;
1534
 
1539
 
1535
        /* Check if correct amount of data have been received */
1540
        /* Check if correct amount of data have been received */
1536
        //if ((i == 78) && (rawbitsTemp != 0b00001))
1541
        //if ((i == 78) && (rawbitsTemp != 0b00001))
1537
        //  return IR_NOT_CORRECT_DATA;
1542
        //  return IR_NOT_CORRECT_DATA;
1538
 
1543
 
1539
        if ((i&1) != 0)
1544
        if ((i&1) != 0)
Line 1545... Line 1550...
1545
        }
1550
        }
1546
        else
1551
        else
1547
        {           /* if even, data */
1552
        {           /* if even, data */
1548
            /* check length of transmit pulse */
1553
            /* check length of transmit pulse */
1549
            if ((buf[i2] > IR_VIKING_STEAK_LOW_ONE - IR_VIKING_STEAK_LOW_ONE/IR_VIKING_STEAK_TOL_DIV) && (buf[i2] < IR_VIKING_STEAK_LOW_ONE + IR_VIKING_STEAK_LOW_ONE/IR_VIKING_STEAK_TOL_DIV))
1554
            if ((buf[i2] > IR_VIKING_STEAK_LOW_ONE - IR_VIKING_STEAK_LOW_ONE/IR_VIKING_STEAK_TOL_DIV) && (buf[i2] < IR_VIKING_STEAK_LOW_ONE + IR_VIKING_STEAK_LOW_ONE/IR_VIKING_STEAK_TOL_DIV))
1550
            {
1555
            {
1551
                /* write a one */
1556
                /* write a one */
1552
                rawbitsTemp = rawbitsTemp<<1;
1557
                rawbitsTemp = rawbitsTemp<<1;
1553
                rawbitsTemp |= 1;
1558
                rawbitsTemp |= 1;
1554
            }
1559
            }
1555
            else if ((buf[i2] > IR_VIKING_STEAK_LOW_ZERO - IR_VIKING_STEAK_LOW_ZERO/IR_VIKING_STEAK_TOL_DIV) && (buf[i2] < IR_VIKING_STEAK_LOW_ZERO + IR_VIKING_STEAK_LOW_ZERO/IR_VIKING_STEAK_TOL_DIV))
1560
            else if ((buf[i2] > IR_VIKING_STEAK_LOW_ZERO - IR_VIKING_STEAK_LOW_ZERO/IR_VIKING_STEAK_TOL_DIV) && (buf[i2] < IR_VIKING_STEAK_LOW_ZERO + IR_VIKING_STEAK_LOW_ZERO/IR_VIKING_STEAK_TOL_DIV))
1556
            {
1561
            {
1557
                /* do nothing, a zero is already in rawbits */
1562
                /* do nothing, a zero is already in rawbits */
1558
                rawbitsTemp = rawbitsTemp<<1;
1563
                rawbitsTemp = rawbitsTemp<<1;
1559
            }
1564
            }
1560
            else
1565
            else
1561
            {
1566
            {
1562
                return IR_NOT_CORRECT_DATA;
1567
                return IR_NOT_CORRECT_DATA;
1563
            }
1568
            }
-
 
1569
        }
1564
        }
1570
    }
1565
    }
-
 
1566
   
1571
   
1567
    //rawbitsTemp = ~rawbitsTemp;
1572
    //rawbitsTemp = ~rawbitsTemp;
1568
    //rawbitsTemp = rawbitsTemp&0xFFFFFFFFFF;
1573
    //rawbitsTemp = rawbitsTemp&0xFFFFFFFFFF;
1569
   
1574
   
1570
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_VIKINGSTEAK;
1575
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_VIKINGSTEAK;
1571
    proto->timeout=IR_VIKING_STEAK_TIMEOUT;
1576
    proto->timeout=IR_VIKING_STEAK_TIMEOUT;
1572
    proto->data=rawbitsTemp;
1577
    proto->data=rawbitsTemp;
1573
 
1578
 
1574
    return IR_OK;
1579
    return IR_OK;
1575
#else
1580
#else
1576
    return IR_NOT_CORRECT_DATA;
1581
    return IR_NOT_CORRECT_DATA;
1577
#endif
1582
#endif
1578
}
1583
}
1579
#endif
1584
#endif
1580
 
1585
 
1581
#if (IR_PROTOCOLS_USE_RUBICSON)
1586
#if (IR_PROTOCOLS_USE_RUBICSON)
1582
/**
1587
/**
1583
 * Test data on Rubicson temperature sensor protocol
1588
 * Test data on Rubicson temperature sensor protocol
1584
 *
1589
 *
1585
 *
1590
 *
1586
 *
1591
 *
1587
 * @param buf
1592
 * @param buf
1588
 *      Pointer to buffer to where to data to parse is stored
1593
 *      Pointer to buffer to where to data to parse is stored
1589
 * @param len
1594
 * @param len
1590
 *      Length of the data
1595
 *      Length of the data
1591
 * @param proto
1596
 * @param proto
Line 1600... Line 1605...
1600
    /* check if we have correct amount of data */
1605
    /* check if we have correct amount of data */
1601
    if (len < 74) {
1606
    if (len < 74) {
1602
        return IR_NOT_CORRECT_DATA;
1607
        return IR_NOT_CORRECT_DATA;
1603
    }
1608
    }
1604
    uint8_t i, i2;
1609
    uint8_t i, i2;
1605
    uint64_t rawbitsTemp = 0;//0xffffffffffffffff;
1610
    uint64_t rawbitsTemp = 0;//0xffffffffffffffff;
1606
   
1611
   
1607
    /* Check start bit condition */
1612
    /* Check start bit condition */
1608
    i2=index-74;
1613
    i2=index-74;
1609
    if (i2>index)
1614
    if (i2>index)
1610
        i2+=MAX_NR_TIMES;
1615
        i2+=MAX_NR_TIMES;
1611
 
1616
 
1612
    proto->data=i2;     /*Store startindex for debug output */
1617
    proto->data=i2;     /*Store startindex for debug output */
1613
   
1618
   
1614
    if ((buf[i2] < IR_RUBICSON_LOW_START - IR_RUBICSON_LOW_START/IR_RUBICSON_TOL_DIV) || (buf[i2] > IR_RUBICSON_LOW_START + IR_RUBICSON_LOW_START/IR_RUBICSON_TOL_DIV))
1619
    if ((buf[i2] < IR_RUBICSON_LOW_START - IR_RUBICSON_LOW_START/IR_RUBICSON_TOL_DIV) || (buf[i2] > IR_RUBICSON_LOW_START + IR_RUBICSON_LOW_START/IR_RUBICSON_TOL_DIV))
1615
    {
1620
    {
1616
        return IR_NOT_CORRECT_DATA;
1621
        return IR_NOT_CORRECT_DATA;
1617
    }
1622
    }
1618
   
1623
   
Line 1627... Line 1632...
1627
        //  return IR_NOT_CORRECT_DATA;
1632
        //  return IR_NOT_CORRECT_DATA;
1628
 
1633
 
1629
        if ((i&1) != 0)
1634
        if ((i&1) != 0)
1630
        {       /* if odd, no data */
1635
        {       /* if odd, no data */
1631
            if ((buf[i2] < IR_RUBICSON_HIGH - IR_RUBICSON_HIGH/IR_RUBICSON_TOL_DIV) || (buf[i2] > IR_RUBICSON_HIGH + IR_RUBICSON_HIGH/IR_RUBICSON_TOL_DIV))
1636
            if ((buf[i2] < IR_RUBICSON_HIGH - IR_RUBICSON_HIGH/IR_RUBICSON_TOL_DIV) || (buf[i2] > IR_RUBICSON_HIGH + IR_RUBICSON_HIGH/IR_RUBICSON_TOL_DIV))
1632
            {
1637
            {
1633
                return IR_NOT_CORRECT_DATA;
1638
                return IR_NOT_CORRECT_DATA;
1634
            }
1639
            }
1635
        }
1640
        }
1636
        else
1641
        else
1637
        {           /* if even, data */
1642
        {           /* if even, data */
1638
            /* check length of transmit pulse */
1643
            /* check length of transmit pulse */
1639
            if ((buf[i2] > IR_RUBICSON_LOW_ONE - IR_RUBICSON_LOW_ONE/IR_RUBICSON_TOL_DIV) && (buf[i2] < IR_RUBICSON_LOW_ONE + IR_RUBICSON_LOW_ONE/IR_RUBICSON_TOL_DIV))
1644
            if ((buf[i2] > IR_RUBICSON_LOW_ONE - IR_RUBICSON_LOW_ONE/IR_RUBICSON_TOL_DIV) && (buf[i2] < IR_RUBICSON_LOW_ONE + IR_RUBICSON_LOW_ONE/IR_RUBICSON_TOL_DIV))
1640
            {
1645
            {
1641
                /* write a one */
1646
                /* write a one */
1642
                rawbitsTemp = rawbitsTemp<<1;
1647
                rawbitsTemp = rawbitsTemp<<1;
1643
                rawbitsTemp |= 1;
1648
                rawbitsTemp |= 1;
1644
            }
1649
            }
1645
            else if ((buf[i2] > IR_RUBICSON_LOW_ZERO - IR_RUBICSON_LOW_ZERO/IR_RUBICSON_TOL_DIV) && (buf[i2] < IR_RUBICSON_LOW_ZERO + IR_RUBICSON_LOW_ZERO/IR_RUBICSON_TOL_DIV))
1650
            else if ((buf[i2] > IR_RUBICSON_LOW_ZERO - IR_RUBICSON_LOW_ZERO/IR_RUBICSON_TOL_DIV) && (buf[i2] < IR_RUBICSON_LOW_ZERO + IR_RUBICSON_LOW_ZERO/IR_RUBICSON_TOL_DIV))
1646
            {
1651
            {
1647
                /* do nothing, a zero is already in rawbits */
1652
                /* do nothing, a zero is already in rawbits */
1648
                rawbitsTemp = rawbitsTemp<<1;
1653
                rawbitsTemp = rawbitsTemp<<1;
1649
            }
1654
            }
1650
            else
1655
            else
1651
            {
1656
            {
1652
                return IR_NOT_CORRECT_DATA;
1657
                return IR_NOT_CORRECT_DATA;
1653
            }
1658
            }
1654
        }
1659
        }
1655
    }
1660
    }
1656
   
1661
   
1657
    //rawbitsTemp = ~rawbitsTemp;
1662
    //rawbitsTemp = ~rawbitsTemp;
1658
    //rawbitsTemp = rawbitsTemp&0xFFFFFFFFFF;
1663
    //rawbitsTemp = rawbitsTemp&0xFFFFFFFFFF;
1659
   
1664
   
1660
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_RUBICSON;
1665
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_RUBICSON;
1661
    proto->timeout=IR_RUBICSON_TIMEOUT;
1666
    proto->timeout=IR_RUBICSON_TIMEOUT;
1662
    proto->data=rawbitsTemp;
1667
    proto->data=rawbitsTemp;
1663
 
1668
 
Line 1666... Line 1671...
1666
    return IR_NOT_CORRECT_DATA;
1671
    return IR_NOT_CORRECT_DATA;
1667
#endif
1672
#endif
1668
}
1673
}
1669
#endif
1674
#endif
1670
 
1675
 
1671
 
1676
 
1672
 
1677
 
1673
#if (IR_PROTOCOLS_USE_OREGON)
1678
#if (IR_PROTOCOLS_USE_OREGON)
-
 
1679
/**
-
 
1680
 * Test data on OREGON weather sensor protocol
-
 
1681
 *
-
 
1682
 *
-
 
1683
 *
-
 
1684
 * @param buf
-
 
1685
 *      Pointer to buffer to where to data to parse is stored
-
 
1686
 * @param len
-
 
1687
 *      Length of the data
-
 
1688
 * @param proto
-
 
1689
 *      Pointer to protocol information
-
 
1690
 * @return
-
 
1691
 *      IR_OK if data parsed successfully, one of several errormessages if not
-
 
1692
 */
-
 
1693
 
-
 
1694
int8_t parseOregon(const uint16_t *buf, uint8_t len, uint8_t index, Ir_Protocol_Data_t *proto)
-
 
1695
{
-
 
1696
#if IR_RX_CONTINUOUS_MODE==1
-
 
1697
    /* check if we have correct amount of data */
-
 
1698
    if (len < 160) {    //Ändra till vettigt värde
-
 
1699
        return IR_NOT_CORRECT_DATA;
-
 
1700
    }
-
 
1701
    uint8_t data[IR_OREGON_DATASIZE]; //Verifiera minsta möjliga storlek
-
 
1702
    uint8_t i2 = 0;
-
 
1703
    uint8_t b_i;
-
 
1704
    uint8_t currentBit = 1;
-
 
1705
    uint8_t done = 0;
-
 
1706
    uint8_t bits = 0;
-
 
1707
    uint8_t shift = 0;
-
 
1708
    uint16_t temperature=0;
-
 
1709
    uint8_t i = index;
-
 
1710
    uint16_t temp =0;
-
 
1711
    uint64_t rawbitsTemp = 0;//0xffffffffffffffff;
-
 
1712
    const uint8_t nibbleSwap[16] = {0x0u,0x8u,0x4u,0xCu,0x2u,0xAu,0x6u,0xEu,0x1u,0x9u,0x5u,0xDu,0x3u,0xBu,0x7u,0xFu};
-
 
1713
   
-
 
1714
    gpio_set_pin(EXP_K);
-
 
1715
    /* Check stop condition */
-
 
1716
    /*if (buf[i] < IR_OREGON_END)
-
 
1717
    {
-
 
1718
      //printf("data: %d of %d\n", buf[i], IR_OREGON_END);
-
 
1719
        return IR_NOT_CORRECT_DATA;
-
 
1720
    }
-
 
1721
    */
-
 
1722
    //gpio_set_pin(EXP_L);
-
 
1723
   
-
 
1724
    if (160 > index) {
-
 
1725
      i = MAX_NR_TIMES-160+index;
-
 
1726
    } else {
-
 
1727
      i = index - 160;
-
 
1728
    }
-
 
1729
    len= 160; //Store remaining length
-
 
1730
   
-
 
1731
   
-
 
1732
    while (len>117) {
-
 
1733
      if ((buf[i] > IR_OREGON_SHORT_L) || (buf[i] < IR_OREGON_SHORT_S)){
-
 
1734
        gpio_set_pin(EXP_L);
-
 
1735
        return IR_NOT_CORRECT_DATA;
-
 
1736
      }
-
 
1737
      i++;
-
 
1738
      if (i>= MAX_NR_TIMES){
-
 
1739
        i=0;
-
 
1740
      }
-
 
1741
      len--;
-
 
1742
    }
-
 
1743
    gpio_set_pin(EXP_M);
-
 
1744
    if ((buf[i] < IR_OREGON_LONG_L) && (buf[i] > IR_OREGON_LONG_S)){
-
 
1745
      gpio_set_pin(EXP_N);    
-
 
1746
    } else  {
-
 
1747
      return IR_NOT_CORRECT_DATA;
-
 
1748
    }
-
 
1749
    i++;
-
 
1750
    len--;
-
 
1751
    if (i>= MAX_NR_TIMES){
-
 
1752
      i=0;
-
 
1753
    }
-
 
1754
    if ((buf[i] < IR_OREGON_LONG_L) && (buf[i] > IR_OREGON_LONG_S)){
-
 
1755
      gpio_toggle_pin(EXP_N);    
-
 
1756
    } else  {
-
 
1757
      return IR_NOT_CORRECT_DATA;
-
 
1758
    }
-
 
1759
    i++;
-
 
1760
    len--;
-
 
1761
    if (i>= MAX_NR_TIMES){
-
 
1762
      i=0;
-
 
1763
    }
-
 
1764
    if ((buf[i] < IR_OREGON_LONG_L) && (buf[i] > IR_OREGON_LONG_S)){
-
 
1765
      gpio_toggle_pin(EXP_N);    
-
 
1766
    } else  {
-
 
1767
      return IR_NOT_CORRECT_DATA;
-
 
1768
    }
-
 
1769
    i++;
-
 
1770
    len--;
-
 
1771
    if (i>= MAX_NR_TIMES){
-
 
1772
      i=0;
-
 
1773
    }
-
 
1774
    if ((buf[i] < IR_OREGON_LONG_L) && (buf[i] > IR_OREGON_LONG_S)){
-
 
1775
      gpio_toggle_pin(EXP_N);    
-
 
1776
    } else  {
-
 
1777
      return IR_NOT_CORRECT_DATA;
-
 
1778
    }
-
 
1779
    i++;
-
 
1780
    len--;
-
 
1781
    if (i>= MAX_NR_TIMES){
-
 
1782
      i=0;
-
 
1783
    }
-
 
1784
    gpio_set_pin(EXP_L);
-
 
1785
    i2=i;
-
 
1786
    i2++;
-
 
1787
    if (i2>= MAX_NR_TIMES){
-
 
1788
      i2=0;
-
 
1789
    }
-
 
1790
    bits = 0;
-
 
1791
    while ( bits < 16) {
-
 
1792
        if ((buf[i] < IR_OREGON_SHORT_L) && (buf[i] > IR_OREGON_SHORT_S)){
-
 
1793
          if ((buf[i2] < IR_OREGON_SHORT_L) && (buf[i2] > IR_OREGON_SHORT_S)){
-
 
1794
          i++;
-
 
1795
          i2++;
-
 
1796
          } else {
-
 
1797
        printf("d1: %d %d %d\n", (int)(buf[i]*CYCLES_PER_US/TIMER_PRESC),(int)(buf[i2]*CYCLES_PER_US/TIMER_PRESC), len);
-
 
1798
        return IR_NOT_CORRECT_DATA;
-
 
1799
          }
-
 
1800
        } else if ((buf[i] < IR_OREGON_LONG_L) && (buf[i] > IR_OREGON_LONG_S)){
-
 
1801
          currentBit = !currentBit;
-
 
1802
        } else {
-
 
1803
          printf("d2: %d %d\n", (int)(buf[i]*CYCLES_PER_US/TIMER_PRESC), len);
-
 
1804
          return IR_NOT_CORRECT_DATA;
-
 
1805
        }
-
 
1806
        gpio_toggle_pin(EXP_M);
-
 
1807
        bits++;
-
 
1808
        if (currentBit) {
-
 
1809
          rawbitsTemp = rawbitsTemp<<1;
-
 
1810
          rawbitsTemp |= 1;
-
 
1811
        } else {
-
 
1812
          rawbitsTemp = rawbitsTemp<<1;
-
 
1813
        }
-
 
1814
        i++;
-
 
1815
        len--;
-
 
1816
        if (i>= MAX_NR_TIMES){
-
 
1817
          i=0;
-
 
1818
        }
-
 
1819
        i2++;
-
 
1820
        if (i2>= MAX_NR_TIMES){
-
 
1821
          i2=0;
-
 
1822
        }
-
 
1823
    }
-
 
1824
    bits = 0;
-
 
1825
    //inverse bitorder
-
 
1826
    while (bits < 16) {
-
 
1827
      bits++;
-
 
1828
      if (rawbitsTemp & 0x1u) {
-
 
1829
          temp |= 1u;
-
 
1830
      }
-
 
1831
      if (bits == 16) {
-
 
1832
        break;
-
 
1833
      }
-
 
1834
      temp = temp << 1;
-
 
1835
      rawbitsTemp = rawbitsTemp >> 1;
-
 
1836
    }
-
 
1837
    //restore nibbleorder
-
 
1838
    rawbitsTemp = ((temp & 0xFu) << 12)+((temp>>4 & 0xFu) << 8)+((temp>>8 & 0xFu) << 4)+((temp>>12 & 0xFu));
-
 
1839
/*
-
 
1840
    if ((rawbitsTemp != 0xf824) && (rawbitsTemp != 0x1d20) && (rawbitsTemp != 0xf8b4) ) {
-
 
1841
      printf("Found sens: %x\n", (uint16_t)rawbitsTemp);
-
 
1842
      return IR_NOT_CORRECT_DATA;
-
 
1843
    }
-
 
1844
    */
-
 
1845
    //----------------------
-
 
1846
    uint8_t bitlenght = 0;
-
 
1847
    uint16_t sensorType = (uint16_t)rawbitsTemp;
-
 
1848
    switch (sensorType)
-
 
1849
    {
-
 
1850
      case 0xf824:
-
 
1851
      case 0x1d20:
-
 
1852
      case 0xf8b4:
-
 
1853
        // Temperature and humidity
-
 
1854
        //printf("Found temp\n");
-
 
1855
        bitlenght = 40;
-
 
1856
        break;
-
 
1857
      case 0x2914:
-
 
1858
        // Rain gage inches
-
 
1859
        printf("Found rain\n");
-
 
1860
        bitlenght = 56;
-
 
1861
        break;
-
 
1862
      case 0x1984:
-
 
1863
      case 0x1994:    
-
 
1864
        // Wind speed and direction
-
 
1865
        printf("Found wind\n");
-
 
1866
        bitlenght = 52;
-
 
1867
        break;
-
 
1868
      default:
-
 
1869
        printf("Found sens: %x\n", (uint16_t)rawbitsTemp);
-
 
1870
        return IR_NOT_CORRECT_DATA;
-
 
1871
    }
-
 
1872
 
-
 
1873
   
-
 
1874
    bits = 0;
-
 
1875
    rawbitsTemp = 0;
-
 
1876
    while ( bits < bitlenght) {
-
 
1877
        if ((buf[i] < IR_OREGON_SHORT_L) && (buf[i] > IR_OREGON_SHORT_S)){
-
 
1878
          if ((buf[i2] < IR_OREGON_SHORT_L) && (buf[i2] > IR_OREGON_SHORT_S)){
-
 
1879
          i++;
-
 
1880
          i2++;
-
 
1881
          } else {
-
 
1882
        printf("x1: %d %d %d\n", (int)(buf[i]*CYCLES_PER_US/TIMER_PRESC),(int)(buf[i2]*CYCLES_PER_US/TIMER_PRESC), len);
-
 
1883
        return IR_NOT_CORRECT_DATA;
-
 
1884
          }
-
 
1885
        } else if ((buf[i] < IR_OREGON_LONG_L) && (buf[i] > IR_OREGON_LONG_S)){
-
 
1886
          currentBit = !currentBit;
-
 
1887
        } else {
-
 
1888
          printf("x2: %d %d\n", (int)(buf[i]*CYCLES_PER_US/TIMER_PRESC), len);
-
 
1889
          return IR_NOT_CORRECT_DATA;
-
 
1890
        }
-
 
1891
        gpio_toggle_pin(EXP_M);
-
 
1892
        bits++;
-
 
1893
        if (currentBit) {
-
 
1894
          rawbitsTemp = rawbitsTemp<<1;
-
 
1895
          rawbitsTemp |= 1;
-
 
1896
        } else {
-
 
1897
          rawbitsTemp = rawbitsTemp<<1;
-
 
1898
        }
-
 
1899
        i++;
-
 
1900
        len--;
-
 
1901
        if (i>= MAX_NR_TIMES){
-
 
1902
          i=0;
-
 
1903
        }
-
 
1904
        i2++;
-
 
1905
        if (i2>= MAX_NR_TIMES){
-
 
1906
          i2=0;
-
 
1907
        }
-
 
1908
    }
-
 
1909
   
-
 
1910
    proto->data = 0;
-
 
1911
    bits = 0;
-
 
1912
   
-
 
1913
    switch (sensorType)
-
 
1914
    {
-
 
1915
      case 0xf824:
-
 
1916
      case 0x1d20:
-
 
1917
      case 0xf8b4:
-
 
1918
       /* ----------- Data order rawbitsTemp ------
-
 
1919
        * aa bc cc de ef
-
 
1920
        * fe ed cc cb aa
-
 
1921
        * aa  = Humidity in BCD %
-
 
1922
        * b   = Sign for temperature (1 => -, 0 => +)
-
 
1923
        * ccc = Temperature in BCD celcius
-
 
1924
        * d   = 0x01 bat low, 0x00 bat OK
-
 
1925
        * ee  = Rolling code, random value each time batteries is inserted
-
 
1926
        * f   =  Channel
-
 
1927
        * -----------------------------*/
-
 
1928
        //printf("begi: %x %x %x %x\n", (uint16_t)(rawbitsTemp>>48), (uint16_t)(rawbitsTemp>>32), (uint16_t)(rawbitsTemp>>16), (uint16_t)rawbitsTemp);
-
 
1929
       
-
 
1930
        //Convert hunmidity to decimal from BCD
-
 
1931
        i = (uint8_t)( (rawbitsTemp & 0xFF ));
-
 
1932
        //printf("humi: %x\n", i);
-
 
1933
        i = ((uint8_t)nibbleSwap[i & 0xF]<<4) + ((uint8_t)(nibbleSwap[(i>>4) & 0xF])&0x0f);
-
 
1934
        //printf("humi: %x\n", i);
-
 
1935
        index = (i>>4)*10 + (i & 0x0Fu);
-
 
1936
        proto->data = index; // humidity
-
 
1937
       
-
 
1938
        //Convert temperature to decimal from BCD
-
 
1939
        temperature = (uint16_t)( ((rawbitsTemp >> 8) & 0x7FFF ));
-
 
1940
        //printf("temp: %x\n", temperature);
-
 
1941
        temperature = ((nibbleSwap[(temperature>>0) & 0xF]<<12)&0xf000) + ((nibbleSwap[(temperature>>4) & 0xF]<<8)&0x0f00) + ((nibbleSwap[(temperature>>8) & 0xF]<<4)&0x00f0) + ((nibbleSwap[(temperature>>12) & 0xF]<<0)&0x000f);
-
 
1942
        //printf("temp: %x\n", temperature);
-
 
1943
       
-
 
1944
        temperature = ((temperature>>12) & 0x0Fu)*1000 +((temperature>>8) & 0x0Fu)*100 +((temperature>>4) & 0x0Fu)*10 + (temperature & 0x0Fu);
-
 
1945
        //printf("temd: %d\n", temperature);
-
 
1946
       
-
 
1947
        if (rawbitsTemp & 0x0080000000 ) {
-
 
1948
          temperature = -temperature;
-
 
1949
        }
-
 
1950
        proto->data += ((temperature & 0xFFFF) << 8);
-
 
1951
 
-
 
1952
 
-
 
1953
        //Add channel information
-
 
1954
        proto->data += ((uint64_t)nibbleSwap[(uint8_t)( ((rawbitsTemp >> 36 ) & 0xF))]) << 46;
-
 
1955
        //printf("chan: %d\n", nibbleSwap[(uint8_t)( ((rawbitsTemp >> 36 ) & 0xF))]);
-
 
1956
       
-
 
1957
        //Add battery information
-
 
1958
        proto->data += ((uint64_t)(nibbleSwap[(uint8_t)( ((rawbitsTemp >> 24 ) & 0xF))])&0x1) << 45;
-
 
1959
        //printf("bat : %d\n", ((nibbleSwap[(uint8_t)( ((rawbitsTemp >> 24 ) & 0xF))])&0x1));
-
 
1960
       
-
 
1961
        //Add rolling code information
-
 
1962
        i = (uint8_t)((rawbitsTemp >> 28 ) & 0xFF);
-
 
1963
        i = (uint8_t)nibbleSwap[i & 0xF] + ((uint8_t)(nibbleSwap[(i>>4) & 0xF]<<4)&0xf0);
-
 
1964
        i = i & 0x1F;
-
 
1965
        proto->data += ((uint64_t)(i)) << 40;
-
 
1966
        //printf("roll : %d\n", i);
-
 
1967
       
-
 
1968
       
-
 
1969
        /* ----------- Data order proto-data ------
-
 
1970
        * cc 00 00 bb bb aa
-
 
1971
        * aa   = Humidity in %
-
 
1972
        * bbbb = Temperature*10 in celcius
-
 
1973
        * cc   = 0xddefffff
-
 
1974
        *   dd = Channel
-
 
1975
        *   e  = Battery low flag
-
 
1976
        *   fffff = Lower part of rolling code
-
 
1977
        * -----------------------------*/
-
 
1978
       
-
 
1979
        //printf("done: %x %x %x %x\n", (uint16_t)(proto->data>>48), (uint16_t)(proto->data>>32), (uint16_t)(proto->data>>16), (uint16_t)proto->data);
-
 
1980
        proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_OREGONTEMPHUM;
-
 
1981
        proto->timeout=IR_OREGON_TIMEOUT;
-
 
1982
        return IR_OK;
-
 
1983
        break;
-
 
1984
      case 0x2914:
-
 
1985
        // Rain gage inches
-
 
1986
        /* ----------- Data order rawbitsTemp ------
-
 
1987
        * aa aa bb bb bb de ef
-
 
1988
        * fe ed bb bb bb aa aa
-
 
1989
        * a   = Rain in 0.01 inches per hour
-
 
1990
        * b   = Total Rain in 0.001 inches
-
 
1991
        * d   = 0x01 bat low, 0x00 bat OK
-
 
1992
        * ee  = Rolling code, random value each time batteries is inserted
-
 
1993
        * f   =  Channel
-
 
1994
        * -----------------------------*/
-
 
1995
        printf("begi: %x %x %x %x\n", (uint16_t)(rawbitsTemp>>48), (uint16_t)(rawbitsTemp>>32), (uint16_t)(rawbitsTemp>>16), (uint16_t)rawbitsTemp);
-
 
1996
       
-
 
1997
        //Convert rain per hour
-
 
1998
        temp = (uint16_t)( (rawbitsTemp & 0xFFFF ));
-
 
1999
        printf("i/h : %x\n", temp);
-
 
2000
        temp = ((nibbleSwap[(temp>>0) & 0xF]<<12)&0xf000) + ((nibbleSwap[(temp>>4) & 0xF]<<8)&0x0f00) + ((nibbleSwap[(temp>>8) & 0xF]<<4)&0x00f0) + ((nibbleSwap[(temp>>12) & 0xF]<<0)&0x000f);
-
 
2001
        printf("i/h : %x\n", temp);
-
 
2002
        printf("i/h : %d\n", temp);
-
 
2003
        temp = ((temp>>12) & 0x0Fu)*1000 +((temp>>8) & 0x0Fu)*100 +((temp>>4) & 0x0Fu)*10 + (temp & 0x0Fu);
-
 
2004
        proto->data = temp; // inches per hour
-
 
2005
       
-
 
2006
        uint32_t temp32 = 0;
-
 
2007
       
-
 
2008
        //Convert temperature to decimal from BCD
-
 
2009
        temp32 = (uint32_t)( ((rawbitsTemp >> 16) & 0xFFFFFF ));
-
 
2010
        printf("temp: %x\n", temp32);
-
 
2011
        temp32 = (((uint32_t)nibbleSwap[(temp32>>0) & 0xF]<<20)&0xf00000) + (((uint32_t)nibbleSwap[(temp32>>4) & 0xF]<<16)&0x0f0000) + (((uint32_t)nibbleSwap[(temp32>>8) & 0xF]<<12)&0x00f000) + (((uint32_t)nibbleSwap[(temp32>>12) & 0xF]<<8)&0x000f00) + (((uint32_t)nibbleSwap[(temp32>>16) & 0xF]<<4)&0x0000f0) + (((uint32_t)nibbleSwap[(temp32>>20) & 0xF]<<0)&0x00000f);
-
 
2012
        //printf("temp: %x\n", temperature);
-
 
2013
       
-
 
2014
        //temperature = ((temperature>>12) & 0x0Fu)*1000 +((temperature>>8) & 0x0Fu)*100 +((temperature>>4) & 0x0Fu)*10 + (temperature & 0x0Fu);
-
 
2015
        //printf("temd: %d\n", temperature);
-
 
2016
        printf("tota: %x\n", temp32);
-
 
2017
        printf("tota: %d\n", temp32);
-
 
2018
       
-
 
2019
        proto->data += (temp32 << 16);
-
 
2020
 
-
 
2021
 
-
 
2022
        //Add channel information
-
 
2023
        proto->data += ((uint64_t)nibbleSwap[(uint8_t)( ((rawbitsTemp >> 52 ) & 0xF))]) << 46;
-
 
2024
        printf("chan: %d\n", nibbleSwap[(uint8_t)( ((rawbitsTemp >> 52 ) & 0xF))]);
-
 
2025
       
-
 
2026
        //Add battery information
-
 
2027
        proto->data += ((uint64_t)(nibbleSwap[(uint8_t)( ((rawbitsTemp >> 40 ) & 0xF))])&0x1) << 45;
-
 
2028
        printf("bat : %d\n", ((nibbleSwap[(uint8_t)( ((rawbitsTemp >> 40 ) & 0xF))])&0x1));
-
 
2029
       
-
 
2030
        //Add rolling code information
-
 
2031
        i = (uint8_t)((rawbitsTemp >> 44 ) & 0xFF);
-
 
2032
        i = (uint8_t)nibbleSwap[i & 0xF] + ((uint8_t)(nibbleSwap[(i>>4) & 0xF]<<4)&0xf0);
-
 
2033
        i = i & 0x1F;
-
 
2034
        proto->data += ((uint64_t)(i)) << 40;
-
 
2035
        printf("roll : %d\n", i);
-
 
2036
       
-
 
2037
       
-
 
2038
        /* ----------- Data order proto-data ------
-
 
2039
        * cc bb bb bb aa aa
-
 
2040
        * a   = Rain in 0.01 inches per hour
-
 
2041
        * b   = Total Rain in 0.001 inches
-
 
2042
        * cc   = 0xddefffff
-
 
2043
        *   dd = Channel
-
 
2044
        *   e  = Battery low flag
-
 
2045
        *   fffff = Lower part of rolling code
-
 
2046
        * -----------------------------*/
-
 
2047
       
-
 
2048
        printf("done: %x %x %x %x\n", (uint16_t)(proto->data>>48), (uint16_t)(proto->data>>32), (uint16_t)(proto->data>>16), (uint16_t)proto->data);
-
 
2049
        proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_OREGONRAIN;
-
 
2050
        proto->timeout=IR_OREGON_TIMEOUT;
-
 
2051
        return IR_OK;
-
 
2052
        break;
-
 
2053
       
-
 
2054
      case 0x1994:
-
 
2055
      case 0x1984:
-
 
2056
       /* ----------- Data order rawbitsTemp ------
-
 
2057
        * a? ?b bb cc cd ee f
-
 
2058
        * fe ed x? ?c cc aa a
-
 
2059
        * x   = Direction (0-F) steps of 22.5 degrees
-
 
2060
        * ccc = Temperature in BCD celcius
-
 
2061
        * ccc = Temperature in BCD celcius
-
 
2062
        * d   = 0x01 bat low, 0x00 bat OK
-
 
2063
        * ee  = Rolling code, random value each time batteries is inserted
-
 
2064
        * f   =  Channel
-
 
2065
        * -----------------------------*/
-
 
2066
        printf("begi: %x %x %x %x\n", (uint16_t)(rawbitsTemp>>48), (uint16_t)(rawbitsTemp>>32), (uint16_t)(rawbitsTemp>>16), (uint16_t)rawbitsTemp);
-
 
2067
       
-
 
2068
        //Convert average wind to decimal from BCD
-
 
2069
        temp = (uint16_t)( (rawbitsTemp & 0xFFF ));
-
 
2070
        //printf("w_av: %x\n", temp);
-
 
2071
        temp = (uint16_t)nibbleSwap[temp & 0xF] + ((uint16_t)(nibbleSwap[(temp>>4) & 0xF]<<4)&0xf0) + ((uint16_t)(nibbleSwap[(temp>>8) & 0xF]<<8)&0xf0);
-
 
2072
        //printf("humi: %x\n", temp);
-
 
2073
        temp = ((temp>>8) & 0x0Fu)*100 +((temp>>4) & 0x0Fu)*10 + (temp & 0x0Fu);
-
 
2074
        proto->data = temp; // wind average
-
 
2075
       
-
 
2076
        //Convert current wind to decimal from BCD
-
 
2077
        temp = (uint16_t)( ((rawbitsTemp >> 12) & 0xFFF ));
-
 
2078
        //printf("w_av: %x\n", temp);
-
 
2079
        temp = (uint16_t)nibbleSwap[temp & 0xF] + ((uint16_t)(nibbleSwap[(temp>>4) & 0xF]<<4)&0xf0) + ((uint16_t)(nibbleSwap[(temp>>8) & 0xF]<<8)&0xf0);
-
 
2080
        //printf("humi: %x\n", temp);
-
 
2081
        temp = ((temp>>8) & 0x0Fu)*100 +((temp>>4) & 0x0Fu)*10 + (temp & 0x0Fu);
-
 
2082
        proto->data += (temp << 12) & 0xFFF000; // wind average
-
 
2083
       
-
 
2084
        //store direction
-
 
2085
        i = (uint8_t)( ((rawbitsTemp >> 32) & 0xF ));
-
 
2086
        proto->data += (uint32_t)i << 24;
-
 
2087
 
-
 
2088
        //Add channel information
-
 
2089
        proto->data += ((uint64_t)nibbleSwap[(uint8_t)( ((rawbitsTemp >> 48 ) & 0xF))]) << 46;
-
 
2090
        //printf("chan: %d\n", nibbleSwap[(uint8_t)( ((rawbitsTemp >> 36 ) & 0xF))]);
-
 
2091
       
-
 
2092
        //Add battery information
-
 
2093
        proto->data += ((uint64_t)(nibbleSwap[(uint8_t)( ((rawbitsTemp >> 36 ) & 0xF))])&0x1) << 45;
-
 
2094
        //printf("bat : %d\n", ((nibbleSwap[(uint8_t)( ((rawbitsTemp >> 24 ) & 0xF))])&0x1));
-
 
2095
       
-
 
2096
        //Add rolling code information
-
 
2097
        i = (uint8_t)((rawbitsTemp >> 36 ) & 0xFF);
-
 
2098
        i = (uint8_t)nibbleSwap[i & 0xF] + ((uint8_t)(nibbleSwap[(i>>4) & 0xF]<<4)&0xf0);
-
 
2099
        i = i & 0x1F;
-
 
2100
        proto->data += ((uint64_t)(i)) << 40;
-
 
2101
        //printf("roll : %d\n", i);
-
 
2102
       
-
 
2103
       
-
 
2104
        /* ----------- Data order proto-data ------
-
 
2105
        * cc 00 0d bb ba aa
-
 
2106
        * aaa  = wind speed average (in 0.1m/s)
-
 
2107
        * bbb  = wind speed current (in 0.1m/s)
-
 
2108
        * d    = Direction in 22.5 degrees
-
 
2109
        * cc   = 0xddefffff
-
 
2110
        *   dd = Channel
-
 
2111
        *   e  = Battery low flag
-
 
2112
        *   fffff = Lower part of rolling code
-
 
2113
        * -----------------------------*/
-
 
2114
       
-
 
2115
        //printf("done: %x %x %x %x\n", (uint16_t)(proto->data>>48), (uint16_t)(proto->data>>32), (uint16_t)(proto->data>>16), (uint16_t)proto->data);
-
 
2116
        proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_OREGONWIND;
-
 
2117
        proto->timeout=IR_OREGON_TIMEOUT;
-
 
2118
        return IR_OK;
-
 
2119
        break;
-
 
2120
       
-
 
2121
      default:
-
 
2122
        return IR_NOT_CORRECT_DATA;
-
 
2123
    }
-
 
2124
   
-
 
2125
 
-
 
2126
#else
-
 
2127
    return IR_NOT_CORRECT_DATA;
-
 
2128
#endif
-
 
2129
}
-
 
2130
#endif
-
 
2131
 
1674
/**
2132
/**
1675
 * Test data on OREGON weather sensor protocol
2133
 * Test data on OREGON weather sensor protocol
1676
 *
2134
 *
1677
 *
2135
 *
1678
 *
2136
 *
Line 1704... Line 2162...
1704
    uint64_t rawbitsTemp = 0;//0xffffffffffffffff;
2162
    uint64_t rawbitsTemp = 0;//0xffffffffffffffff;
1705
   
2163
   
1706
    /* Check stop condition */
2164
    /* Check stop condition */
1707
    if (buf[i] < IR_OREGON_END)
2165
    if (buf[i] < IR_OREGON_END)
1708
    {
2166
    {
1709
        return IR_NOT_CORRECT_DATA;
2167
        return IR_NOT_CORRECT_DATA;
1710
    }
2168
    }
1711
    i--; //set index to last bit
2169
    i--; //set index to last bit
1712
    len--; //Store remaining length
2170
    len--; //Store remaining length
-
 
2171
    printf("End\n");
1713
    //loop to store data
2172
    //loop to store data
1714
    while (done == 0) { //Wait for sync pulse and preamble, loop for all bytes
2173
    while (done == 0) { //Wait for sync pulse and preamble, loop for all bytes
-
 
2174
        data[i2] = 00;
1715
        for (b_i = 0;b_i<8;b_i++) { //loop for each bit
2175
        for (b_i = 0;b_i<8;b_i++) { //loop for each bit
1716
            if (((buf[i] < IR_OREGON_SHORT_L) && (buf[i] > IR_OREGON_SHORT_S)) ) {
2176
            if (((buf[i] < IR_OREGON_SHORT_L) && (buf[i] > IR_OREGON_SHORT_S)) ) {
1717
                i--;
2177
                i--;
1718
                if (i > MAX_NR_TIMES) i = MAX_NR_TIMES - 1;
2178
                if (i > MAX_NR_TIMES) i = MAX_NR_TIMES - 1;
1719
                if (((buf[i] < IR_OREGON_SHORT_L) && (buf[i] > IR_OREGON_SHORT_S))) {
2179
                if (((buf[i] < IR_OREGON_SHORT_L) && (buf[i] > IR_OREGON_SHORT_S))) {
1720
                    //Keep previous bit value
2180
                    //Keep previous bit value
1721
                    data[i2] = data[b_i] << 1;
2181
                    data[i2] = data[b_i] << 1;
1722
                    data[i2] += currentBit;
2182
                    data[i2] += currentBit;
1723
                    i--;
2183
                    i--;
1724
                    if (i > MAX_NR_TIMES) i = MAX_NR_TIMES - 1;
2184
                    if (i > MAX_NR_TIMES) i = MAX_NR_TIMES - 1;
1725
                } else { return IR_NOT_CORRECT_DATA;}  
2185
                } else { printf("1: %d, %x %x %x %x %x %x %x\n", buf[i], data[0], data[1], data[2], data[3], data[4], data[5], data[6]);  return IR_NOT_CORRECT_DATA;} 
1726
            }
2186
            }
1727
            else if (((buf[i] < IR_OREGON_LONG_L) && (buf[i] > IR_OREGON_LONG_S))) {
2187
            else if (((buf[i] < IR_OREGON_LONG_L) && (buf[i] > IR_OREGON_LONG_S))) {
1728
                //Invert previous bit value
2188
                //Invert previous bit value
1729
                if (currentBit)
2189
                if (currentBit)
1730
                    currentBit = 0;
2190
                    currentBit = 0;
Line 1733... Line 2193...
1733
                data[i2] = data[b_i] << 1;
2193
                data[i2] = data[b_i] << 1;
1734
                data[i2] += currentBit;
2194
                data[i2] += currentBit;
1735
                i--;
2195
                i--;
1736
                if (i > MAX_NR_TIMES) i = MAX_NR_TIMES - 1;
2196
                if (i > MAX_NR_TIMES) i = MAX_NR_TIMES - 1;
1737
            }
2197
            }
-
 
2198
            else {
-
 
2199
                printf("2: %d, %x %x %x %x %x %x %x\n", buf[i], data[0], data[1], data[2], data[3], data[4], data[5], data[6]);
-
 
2200
                   
-
 
2201
           
-
 
2202
           
1738
            else { return IR_NOT_CORRECT_DATA;}
2203
                return IR_NOT_CORRECT_DATA;
-
 
2204
            }
-
 
2205
            printf("8 bits\n");
1739
        }
2206
        }
1740
        //swap nibbles to make parsing easier
2207
        //swap nibbles to make parsing easier
1741
        uint8_t temp = data[i2] << 4;
2208
        uint8_t temp = data[i2] << 4;
1742
        data[i2] = (data[i2] >> 4) + temp;
2209
        data[i2] = (data[i2] >> 4) + temp;
1743
        //check for end condition
2210
        //check for end condition
Line 1760... Line 2227...
1760
            }
2227
            }
1761
        }
2228
        }
1762
        i2++;
2229
        i2++;
1763
        if (i2 >= IR_OREGON_DATASIZE)
2230
        if (i2 >= IR_OREGON_DATASIZE)
1764
        {
2231
        {
-
 
2232
            printf("Ovr\n");
1765
            return IR_NOT_CORRECT_DATA;
2233
            return IR_NOT_CORRECT_DATA;
1766
        }
2234
        }
1767
    }  
2235
    }  
-
 
2236
    printf("Found\n");
1768
    i2--; //restore index
2237
    i2--; //restore index
1769
    if (invert == 1) {
2238
    if (invert == 1) {
1770
        for (b_i = 0;b_i<=i2;b_i++) { //loop for each byte
2239
        for (b_i = 0;b_i<=i2;b_i++) { //loop for each byte
1771
            data[b_i] ^= 0xFFu;
2240
            data[b_i] ^= 0xFFu;
1772
        }
2241
        }