Subversion Repositories HomeAutomation

Rev

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

Rev 2241 Rev 2244
Line 8... Line 8...
8
 */
8
 */
9
 
9
 
10
#include "protocols.h"
10
#include "protocols.h"
11
#include <bios.h>
11
#include <bios.h>
12
 
12
 
13
 
-
 
-
 
13
#include <drivers/can/moduleid.h>
14
 
14
 
15
//#include <drivers/mcu/gpio.h>
15
//#include <drivers/mcu/gpio.h>
16
 
16
 
17
 
17
 
18
 
18
 
Line 43... Line 43...
43
#if (IR_PROTOCOLS_USE_PANASONIC)
43
#if (IR_PROTOCOLS_USE_PANASONIC)
44
    if (parsePanasonic(buf, len, proto)==IR_OK) return IR_OK;
44
    if (parsePanasonic(buf, len, proto)==IR_OK) return IR_OK;
45
#endif
45
#endif
46
#if (IR_PROTOCOLS_USE_SKY)
46
#if (IR_PROTOCOLS_USE_SKY)
47
    if (parseSky(buf, len, proto)==IR_OK) return IR_OK;
47
    if (parseSky(buf, len, proto)==IR_OK) return IR_OK;
-
 
48
#endif
-
 
49
#if (IR_PROTOCOLS_USE_IROBOT)
-
 
50
    if (parseiRobot(buf, len, proto)==IR_OK) return IR_OK;
48
#endif
51
#endif
49
 
52
 
50
 
53
 
51
/* RF protocols needs index parameter */
54
/* RF protocols needs index parameter */
52
#if (IR_PROTOCOLS_USE_NEXA2)
55
#if (IR_PROTOCOLS_USE_NEXA2)
Line 83... Line 86...
83
}
86
}
84
 
87
 
85
int8_t expandProtocol(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
88
int8_t expandProtocol(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
86
    /* Call the expand function for the specified protocol. */
89
    /* Call the expand function for the specified protocol. */
87
    switch (proto->protocol) {
90
    switch (proto->protocol) {
88
    case IR_PROTO_SIRC:
91
    case CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_SIRC:
89
        return expandSIRC(buf, len, proto);
92
        return expandSIRC(buf, len, proto);
90
    case IR_PROTO_RC5:
93
    case CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_RC5:
91
        return expandRC5(buf, len, proto);
94
        return expandRC5(buf, len, proto);
92
    case IR_PROTO_SHARP:
95
    case CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_SHARP:
93
        return expandSharp(buf, len, proto);
96
        return expandSharp(buf, len, proto);
94
    case IR_PROTO_NEC:
97
    case CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_NEC:
95
        return expandNEC(buf, len, proto);
98
        return expandNEC(buf, len, proto);
96
    case IR_PROTO_SAMS:
99
    case CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_SAMSUNG:
97
        return expandSamsung(buf, len, proto);
100
        return expandSamsung(buf, len, proto);
98
    case IR_PROTO_MARANTZ:
101
    case CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_MARANTZ:
99
        return expandMarantz(buf, len, proto);
102
        return expandMarantz(buf, len, proto);
100
    case IR_PROTO_PANASONIC:
103
    case CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_PANASONIC:
101
        return expandPanasonic(buf, len, proto);
104
        return expandPanasonic(buf, len, proto);
102
    case IR_PROTO_SKY:
105
    case CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_SKY:
103
        return expandSky(buf, len, proto);
106
        return expandSky(buf, len, proto);
-
 
107
    case CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_IROBOT:
-
 
108
        return expandiRobot(buf, len, proto);
104
    case IR_PROTO_NEXA2:
109
    case CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_NEXA2:
105
        return expandNexa2(buf, len, proto);
110
        return expandNexa2(buf, len, proto);
106
    case IR_PROTO_NEXA1:
111
    case CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_NEXA:
107
        return expandNexa1(buf, len, proto);
112
        return expandNexa1(buf, len, proto);
108
    }
113
    }
109
    /* Invalid protocol specified. */
114
    /* Invalid protocol specified. */
110
    return IR_NOT_CORRECT_DATA;
115
    return IR_NOT_CORRECT_DATA;
111
}
116
}
112
 
117
 
113
#if (IR_PROTOCOLS_USE_SIRC)
118
#if (IR_PROTOCOLS_USE_SIRC)
114
/**
119
/**
115
 * Test data on SIRC protocol, 12-bit version
120
 * Test data on SIRC protocol, 12-bit version
116
 * http://www.sbprojects.com/knowledge/ir/sirc.htm
121
 * http://www.sbprojects.com/knowledge/ir/sirc.htm
117
 * http://picprojects.org.uk/projects/sirc/sonysirc.pdf
122
 * http://picprojects.org.uk/projects/sirc/sonysirc.pdf
Line 122... Line 127...
122
 *      Length of the data
127
 *      Length of the data
123
 * @param proto
128
 * @param proto
124
 *      Pointer to protocol information
129
 *      Pointer to protocol information
125
 * @return
130
 * @return
126
 *      IR_OK if data parsed successfully, one of several errormessages if not
131
 *      IR_OK if data parsed successfully, one of several errormessages if not
127
 */
132
 */
128
int8_t parseSIRC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
133
int8_t parseSIRC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
129
    /* parse buf[], max is len */
134
    /* parse buf[], max is len */
130
 
135
 
131
    /* check if we have correct amount of data.
136
    /* check if we have correct amount of data.
132
           supporting two versions of SIRC:
137
           supporting two versions of SIRC:
Line 137... Line 142...
137
        return IR_NOT_CORRECT_DATA;
142
        return IR_NOT_CORRECT_DATA;
138
    }
143
    }
139
   
144
   
140
    /* check startbit */
145
    /* check startbit */
141
    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) {
146
    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) {
142
        return IR_NOT_CORRECT_DATA;
147
        return IR_NOT_CORRECT_DATA;
143
    }
148
    }
144
   
149
   
145
    uint16_t rawbits=0;
150
    uint16_t rawbits=0;
146
   
151
   
147
    for (uint8_t i = 1; i < len; i++) {
152
    for (uint8_t i = 1; i < len; i++) {
Line 154... Line 159...
154
            if (buf[i] > IR_SIRC_HIGH_ONE - IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV && buf[i] < IR_SIRC_HIGH_ONE + IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV) {
159
            if (buf[i] > IR_SIRC_HIGH_ONE - IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV && buf[i] < IR_SIRC_HIGH_ONE + IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV) {
155
                /* write a one */
160
                /* write a one */
156
                rawbits |= 1<<((i-2)>>1);
161
                rawbits |= 1<<((i-2)>>1);
157
            } else if (buf[i] > IR_SIRC_HIGH_ZERO - IR_SIRC_HIGH_ZERO/IR_SIRC_TOL_DIV && buf[i] < IR_SIRC_HIGH_ZERO + IR_SIRC_HIGH_ZERO/IR_SIRC_TOL_DIV) {
162
            } else if (buf[i] > IR_SIRC_HIGH_ZERO - IR_SIRC_HIGH_ZERO/IR_SIRC_TOL_DIV && buf[i] < IR_SIRC_HIGH_ZERO + IR_SIRC_HIGH_ZERO/IR_SIRC_TOL_DIV) {
158
                /* do nothing, a zero is already in rawbits */
163
                /* do nothing, a zero is already in rawbits */
159
            } else {
164
            } else {
160
                return IR_NOT_CORRECT_DATA;
165
                return IR_NOT_CORRECT_DATA;
161
            }
166
            }
162
        }
167
        }
163
    }
168
    }
164
   
169
   
165
    proto->protocol = IR_PROTO_SIRC;
170
    proto->protocol = CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_SIRC;
166
    proto->timeout = IR_SIRC_TIMEOUT;
171
    proto->timeout = IR_SIRC_TIMEOUT;
167
    proto->data = rawbits;
172
    proto->data = rawbits;
168
   
173
   
169
    return IR_OK;
174
    return IR_OK;
170
}
175
}
171
#endif
176
#endif
172
 
177
 
173
/**
178
/**
174
 * Expand data from SIRC protocol
179
 * Expand data from SIRC protocol
175
 * http://www.sbprojects.com/knowledge/ir/sirc.htm
180
 * http://www.sbprojects.com/knowledge/ir/sirc.htm
176
 *
181
 *
Line 180... Line 185...
180
 *      Pointer to length of the data
185
 *      Pointer to length of the data
181
 * @param proto
186
 * @param proto
182
 *      Pointer to protocol information
187
 *      Pointer to protocol information
183
 * @return
188
 * @return
184
 *      IR_OK if data expanded successfully, one of several errormessages if not
189
 *      IR_OK if data expanded successfully, one of several errormessages if not
185
 */
190
 */
186
int8_t expandSIRC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
191
int8_t expandSIRC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
187
    buf[0] = IR_SIRC_ST_BIT;
192
    buf[0] = IR_SIRC_ST_BIT;
188
    buf[1] = IR_SIRC_LOW; //start pulse finished
193
    buf[1] = IR_SIRC_LOW; //start pulse finished
189
 
194
 
190
        /* Assume 12 bit protocol */
195
        /* Assume 12 bit protocol */
Line 206... Line 211...
206
        }  
211
        }  
207
 
212
 
208
    proto->modfreq=IR_SIRC_F_MOD;
213
    proto->modfreq=IR_SIRC_F_MOD;
209
    proto->timeout=IR_SIRC_TIMEOUT;
214
    proto->timeout=IR_SIRC_TIMEOUT;
210
    proto->repeats=IR_SIRC_REPS;
215
    proto->repeats=IR_SIRC_REPS;
211
       
216
       
212
    return IR_OK;
217
    return IR_OK;
213
}
218
}
214
 
219
 
215
 
220
 
216
#if (IR_PROTOCOLS_USE_RC5)
221
#if (IR_PROTOCOLS_USE_RC5)
217
/**
222
/**
218
 * Test data on RC5 protocol
223
 * Test data on RC5 protocol
Line 235... Line 240...
235
        //halfbitscnt&1==1 in the middle of bits
240
        //halfbitscnt&1==1 in the middle of bits
236
        //i&1==0 positive flank
241
        //i&1==0 positive flank
237
 
242
 
238
        if ((halfbitscnt&1)==1 && (i&1)==0) {       /* in the middle of bit AND a positve flank */
243
        if ((halfbitscnt&1)==1 && (i&1)==0) {       /* in the middle of bit AND a positve flank */
239
            rawbits |= (1<<(13-(halfbitscnt>>1)));
244
            rawbits |= (1<<(13-(halfbitscnt>>1)));
240
        }
245
        }
241
       
246
       
242
        if (buf[i] > IR_RC5_HALF_BIT - IR_RC5_HALF_BIT/IR_RC5_TOL_DIV && buf[i] < IR_RC5_HALF_BIT + IR_RC5_HALF_BIT/IR_RC5_TOL_DIV) {
247
        if (buf[i] > IR_RC5_HALF_BIT - IR_RC5_HALF_BIT/IR_RC5_TOL_DIV && buf[i] < IR_RC5_HALF_BIT + IR_RC5_HALF_BIT/IR_RC5_TOL_DIV) {
243
            halfbitscnt += 1;
248
            halfbitscnt += 1;
244
        } else if (buf[i] > IR_RC5_BIT - IR_RC5_BIT/IR_RC5_TOL_DIV && buf[i] < IR_RC5_BIT + IR_RC5_BIT/IR_RC5_TOL_DIV) {
249
        } else if (buf[i] > IR_RC5_BIT - IR_RC5_BIT/IR_RC5_TOL_DIV && buf[i] < IR_RC5_BIT + IR_RC5_BIT/IR_RC5_TOL_DIV) {
245
            halfbitscnt += 2;
250
            halfbitscnt += 2;
246
        } else {
251
        } else {
247
            return IR_NOT_CORRECT_DATA;
252
            return IR_NOT_CORRECT_DATA;
248
        }
253
        }
249
       
254
       
250
    }
255
    }
251
 
256
 
252
    proto->protocol=IR_PROTO_RC5;
257
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_RC5;
253
    proto->timeout=IR_RC5_TIMEOUT;
258
    proto->timeout=IR_RC5_TIMEOUT;
254
    //support RC5-extended keeping second startbit 
259
    //support RC5-extended keeping second startbit 
255
    //remove togglebit
260
    //remove togglebit
256
    proto->data = rawbits&0x37ff; //This seems to be wrong? Does not invert second start bit and keeps first start bit
261
    proto->data = rawbits&0x37ff; //This seems to be wrong? Does not invert second start bit and keeps first start bit
257
    //proto->data = (rawbits&0x07ff) | ((~rawbits)&0x0100);
262
    //proto->data = (rawbits&0x07ff) | ((~rawbits)&0x0100);
258
 
263
 
259
   
264
   
260
    return IR_OK;
265
    return IR_OK;
261
}
266
}
262
#endif
267
#endif
263
 
268
 
264
/**
269
/**
265
 * Used by the expandRC5 to ensure that we toggle the signal with each button press.
270
 * Used by the expandRC5 to ensure that we toggle the signal with each button press.
266
 */
271
 */
267
int8_t rc5_toggle=0;
272
int8_t rc5_toggle=0;
Line 316... Line 321...
316
    rc5_toggle=!rc5_toggle & 1;
321
    rc5_toggle=!rc5_toggle & 1;
317
   
322
   
318
    //Decode the message
323
    //Decode the message
319
    //We know that RC5 messages are 14 bits long
324
    //We know that RC5 messages are 14 bits long
320
    for(uint8_t pos=11;pos>0;pos--)
325
    for(uint8_t pos=11;pos>0;pos--)
321
    {      
326
    {      
322
        // Check the current bit
327
        // Check the current bit
323
        if(previousBit == ((rawMessage>>(pos-1)) & 1))
328
        if(previousBit == ((rawMessage>>(pos-1)) & 1))
324
        {
329
        {
325
            buf[*len]=IR_RC5_HALF_BIT;
330
            buf[*len]=IR_RC5_HALF_BIT;
326
            buf[*len+1]=IR_RC5_HALF_BIT;
331
            buf[*len+1]=IR_RC5_HALF_BIT;
Line 372... Line 377...
372
int8_t parseSharp(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
377
int8_t parseSharp(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
373
    /* parse buf[], max is len */
378
    /* parse buf[], max is len */
374
 
379
 
375
    /* check if we have correct amount of data */
380
    /* check if we have correct amount of data */
376
    if (len != 31) {
381
    if (len != 31) {
377
        return IR_NOT_CORRECT_DATA;
382
        return IR_NOT_CORRECT_DATA;
378
    }
383
    }
379
   
384
   
380
    uint16_t rawbits=0;
385
    uint16_t rawbits=0;
381
   
386
   
382
    for (uint8_t i = 1; i < len; i++) {
387
    for (uint8_t i = 1; i < len; i++) {
383
        if ((i&1) == 1) {       /* if odd, ir-pause */
388
        if ((i&1) == 1) {       /* if odd, ir-pause */
384
            /* check length of pause between bits */
389
            /* check length of pause between bits */
385
            if (buf[i] > IR_SHARP_LOW_ONE - IR_SHARP_LOW_ONE/IR_SHARP_TOL_DIV && buf[i] < IR_SHARP_LOW_ONE + IR_SHARP_LOW_ONE/IR_SHARP_TOL_DIV) {
390
            if (buf[i] > IR_SHARP_LOW_ONE - IR_SHARP_LOW_ONE/IR_SHARP_TOL_DIV && buf[i] < IR_SHARP_LOW_ONE + IR_SHARP_LOW_ONE/IR_SHARP_TOL_DIV) {
Line 395... Line 400...
395
                return IR_NOT_CORRECT_DATA;
400
                return IR_NOT_CORRECT_DATA;
396
            }
401
            }
397
        }
402
        }
398
    }
403
    }
399
   
404
   
400
    proto->protocol=IR_PROTO_SHARP;
405
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_SHARP;
401
    proto->timeout=IR_SHARP_TIMEOUT;
406
    proto->timeout=IR_SHARP_TIMEOUT;
402
    proto->data=rawbits;
407
    proto->data=rawbits;
403
    return IR_OK;
408
    return IR_OK;
404
}
409
}
405
#endif
410
#endif
Line 473... Line 478...
473
                return IR_NOT_CORRECT_DATA;
478
                return IR_NOT_CORRECT_DATA;
474
            }
479
            }
475
        }
480
        }
476
    }
481
    }
477
 
482
 
478
    proto->protocol=IR_PROTO_NEC;
483
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_NEC;
479
    proto->timeout=IR_NEC_TIMEOUT;
484
    proto->timeout=IR_NEC_TIMEOUT;
480
    proto->data=rawbits;   
485
    proto->data=rawbits;   
481
    return IR_OK;
486
    return IR_OK;
482
}
487
}
483
#endif
488
#endif
Line 578... Line 583...
578
                return IR_NOT_CORRECT_DATA;
583
                return IR_NOT_CORRECT_DATA;
579
            }
584
            }
580
        }
585
        }
581
    }
586
    }
582
   
587
   
583
    proto->protocol=IR_PROTO_SAMS;
588
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_SAMSUNG;
584
    proto->timeout=IR_SAMS_TIMEOUT;
589
    proto->timeout=IR_SAMS_TIMEOUT;
585
    proto->data=rawbits;   
590
    proto->data=rawbits;   
586
    return IR_OK;
591
    return IR_OK;
587
}
592
}
588
#endif
593
#endif
Line 610... Line 615...
610
        if ((i&1) == 1) {       /* if odd, ir-pause */
615
        if ((i&1) == 1) {       /* if odd, ir-pause */
611
            if ((proto->data>>(i>>1))&1) {
616
            if ((proto->data>>(i>>1))&1) {
612
                buf[i+2] = IR_SAMS_LOW_ONE;
617
                buf[i+2] = IR_SAMS_LOW_ONE;
613
            } else {
618
            } else {
614
                buf[i+2] = IR_SAMS_LOW_ZERO;
619
                buf[i+2] = IR_SAMS_LOW_ZERO;
615
            }
620
            }
616
        } else {                /* if even, ir-bit */
621
        } else {                /* if even, ir-bit */
617
            buf[i+2] = IR_SAMS_HIGH;
622
            buf[i+2] = IR_SAMS_HIGH;
618
        }
623
        }
619
    }
624
    }
620
   
625
   
621
    *len = 67;
626
    *len = 67;
622
   
627
   
623
    proto->modfreq=IR_SAMS_F_MOD;
628
    proto->modfreq=IR_SAMS_F_MOD;
624
    proto->timeout=IR_SAMS_TIMEOUT;
629
    proto->timeout=IR_SAMS_TIMEOUT;
Line 664... Line 669...
664
            return IR_NOT_CORRECT_DATA;
669
            return IR_NOT_CORRECT_DATA;
665
        }
670
        }
666
       
671
       
667
    }
672
    }
668
   
673
   
669
    proto->protocol=IR_PROTO_MARANTZ;
674
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_MARANTZ;
670
    proto->timeout=IR_MARANTZ_TIMEOUT;
675
    proto->timeout=IR_MARANTZ_TIMEOUT;
671
    proto->data = rawbits&0x0001ffff;
676
    proto->data = rawbits&0x0001ffff;
672
   
677
   
673
    return IR_OK;
678
    return IR_OK;
674
}
679
}
Line 795... Line 800...
795
                return IR_NOT_CORRECT_DATA;
800
                return IR_NOT_CORRECT_DATA;
796
            }
801
            }
797
        }
802
        }
798
    }
803
    }
799
   
804
   
800
    proto->protocol=IR_PROTO_PANASONIC;
805
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_PANASONIC;
801
    proto->timeout=IR_PANA_TIMEOUT;
806
    proto->timeout=IR_PANA_TIMEOUT;
802
    proto->data=rawbits;   
807
    proto->data=rawbits;   
803
    return IR_OK;
808
    return IR_OK;
804
}
809
}
805
#endif
810
#endif
Line 851... Line 856...
851
    *len = 99;
856
    *len = 99;
852
   
857
   
853
    proto->modfreq=IR_PANA_F_MOD;
858
    proto->modfreq=IR_PANA_F_MOD;
854
    proto->timeout=IR_PANA_TIMEOUT;
859
    proto->timeout=IR_PANA_TIMEOUT;
855
    proto->repeats=IR_PANA_REPS;
860
    proto->repeats=IR_PANA_REPS;
856
    return IR_OK;
861
    return IR_OK;
857
}
862
}
858
 
863
 
859
#if (IR_PROTOCOLS_USE_SKY)
864
#if (IR_PROTOCOLS_USE_SKY)
860
/**
865
/**
861
 * Test data on Sky protocol
866
 * Test data on Sky protocol
862
 *
867
 *
863
 *
868
 *
864
 * @param buf
869
 * @param buf
865
 *      Pointer to buffer to where to data to parse is stored
870
 *      Pointer to buffer to where to data to parse is stored
866
 * @param len
871
 * @param len
867
 *      Length of the data
872
 *      Length of the data
868
 * @param proto
873
 * @param proto
869
 *      Pointer to protocol information
874
 *      Pointer to protocol information
870
 * @return
875
 * @return
871
 *      IR_OK if data parsed successfully, one of several errormessages if not
876
 *      IR_OK if data parsed successfully, one of several errormessages if not
872
 */
877
 */
873
int8_t parseSky(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
878
int8_t parseSky(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
874
    /* parse buf[], max is len */
879
    /* parse buf[], max is len */
875
 
880
 
876
    /* check startbit */
881
    /* check startbit */
877
    if (buf[0] > IR_SKY_ST_BIT + IR_SKY_ST_BIT/IR_SKY_TOL_DIV || buf[0] < IR_SKY_ST_BIT - IR_SKY_ST_BIT/IR_SKY_TOL_DIV) {
882
    if (buf[0] > IR_SKY_ST_BIT + IR_SKY_ST_BIT/IR_SKY_TOL_DIV || buf[0] < IR_SKY_ST_BIT - IR_SKY_ST_BIT/IR_SKY_TOL_DIV) {
Line 898... Line 903...
898
       
903
       
899
        /* if level is low */
904
        /* if level is low */
900
        if ((rawbits&1)==0) {
905
        if ((rawbits&1)==0) {
901
            /* and there is a long pulse */
906
            /* and there is a long pulse */
902
            if (current == SKYLONG) {
907
            if (current == SKYLONG) {
903
                /* push a one */
908
                /* push a one */
904
                rawbits = rawbits<<1;
909
                rawbits = rawbits<<1;
905
                rawbits |= 1;
910
                rawbits |= 1;
906
                cnt = 0;
911
                cnt = 0;
907
            }
912
            }
908
            else if (cnt == 0) {
913
            else if (cnt == 0) {
909
                cnt=1;
914
                cnt=1;
910
                /* push a zero */
915
                /* push a zero */
911
                rawbits = rawbits<<1;
916
                rawbits = rawbits<<1;
912
               
917
               
913
            }
918
            }
914
            else {
919
            else {
915
                cnt = 0;
920
                cnt = 0;
-
 
921
            }
-
 
922
        }
-
 
923
       
-
 
924
        /* if level is high */
-
 
925
        if ((rawbits&1)==1) {
-
 
926
            /* and there is a long pulse */
-
 
927
            if (current == SKYLONG) {
-
 
928
                /* push a zero */
-
 
929
                rawbits = rawbits<<1;
-
 
930
               
-
 
931
                if (previous == SKYLONG) {
-
 
932
                    cnt = 1;
-
 
933
                }
-
 
934
                else {
-
 
935
                    cnt = 0;
-
 
936
                }
916
            }
937
            }
-
 
938
            else if (cnt == 0) {
-
 
939
                cnt=1;
-
 
940
                /* push a one */
-
 
941
                rawbits = rawbits<<1;
-
 
942
                rawbits |= 1;
-
 
943
            }
-
 
944
            else {
-
 
945
                cnt = 0;
-
 
946
            }
-
 
947
        }
-
 
948
       
-
 
949
        previous=current;
-
 
950
       
-
 
951
    }
-
 
952
   
-
 
953
    proto->protocol = CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_SKY;
-
 
954
    proto->timeout = IR_SKY_TIMEOUT;
-
 
955
    proto->data = rawbits;
-
 
956
   
-
 
957
    return IR_OK;
-
 
958
}
-
 
959
#endif
-
 
960
 
-
 
961
/**
-
 
962
 * Expand data from Sky protocol
-
 
963
 *
-
 
964
 *
-
 
965
 * @param buf
-
 
966
 *      Pointer to buffer to store the expanded data
-
 
967
 * @param len
-
 
968
 *      Pointer to length of the data
-
 
969
 * @param proto
-
 
970
 *      Pointer to protocol information
-
 
971
 * @return
-
 
972
 *      IR_OK if data expanded successfully, one of several errormessages if not
-
 
973
 */
-
 
974
int8_t expandSky(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
-
 
975
    //TODO: Implement this function.
-
 
976
    buf[0] = IR_SKY_ST_BIT;
-
 
977
    buf[1] = IR_SKY_LONG;   //
-
 
978
   
-
 
979
   
-
 
980
    return IR_NOT_CORRECT_DATA;
-
 
981
}
-
 
982
 
-
 
983
#if (IR_PROTOCOLS_USE_IROBOT)
-
 
984
/**
-
 
985
 * Test data on iRobot protocol
-
 
986
 *
-
 
987
 *
-
 
988
 * @param buf
-
 
989
 *      Pointer to buffer to where to data to parse is stored
-
 
990
 * @param len
-
 
991
 *      Length of the data
-
 
992
 * @param proto
-
 
993
 *      Pointer to protocol information
-
 
994
 * @return
-
 
995
 *      IR_OK if data parsed successfully, one of several errormessages if not
-
 
996
 */
-
 
997
int8_t parseiRobot(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
-
 
998
    /* parse buf[], max is len */  
-
 
999
    uint32_t rawbits=0;
-
 
1000
    uint8_t current=0;
-
 
1001
    uint8_t previous=0;
-
 
1002
    uint8_t cnt=0;
-
 
1003
#define IROBOTLONG 0
-
 
1004
#define IROBOTSHORT 1
-
 
1005
 
-
 
1006
    /* check if we have correct amount of data */
-
 
1007
    if (len != 16) {
-
 
1008
        return IR_NOT_CORRECT_DATA;
-
 
1009
    }
-
 
1010
   
-
 
1011
 
-
 
1012
    for (uint8_t i = 0; i < len; i++)
-
 
1013
    {
-
 
1014
        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) {
-
 
1015
            current = IROBOTSHORT;
-
 
1016
        }
-
 
1017
        else if (buf[i] > IR_IROBOT_LONG - IR_IROBOT_LONG/IR_IROBOT_TOL_DIV && buf[i] < IR_IROBOT_LONG + IR_IROBOT_LONG/IR_IROBOT_TOL_DIV) {
-
 
1018
            current = IROBOTLONG;
-
 
1019
        }
-
 
1020
        else {
-
 
1021
            return IR_NOT_CORRECT_DATA;
-
 
1022
        }
-
 
1023
       
-
 
1024
        /* if level is low */
-
 
1025
        if ((rawbits&1)==0) {
-
 
1026
            /* and there is a long pulse */
-
 
1027
            if (current == IROBOTLONG) {
-
 
1028
                /* push a one */
-
 
1029
                rawbits = rawbits<<1;
-
 
1030
                rawbits |= 1;
-
 
1031
                cnt = 0;
-
 
1032
            }
-
 
1033
            else if (cnt == 0) {
-
 
1034
                cnt=1;
-
 
1035
                /* push a zero */
-
 
1036
                rawbits = rawbits<<1;
-
 
1037
               
-
 
1038
            }
-
 
1039
            else {
-
 
1040
                cnt = 0;
-
 
1041
            }
917
        }
1042
        }
918
       
1043
       
919
        /* if level is high */
1044
        /* if level is high */
920
        if ((rawbits&1)==1) {
1045
        if ((rawbits&1)==1) {
921
            /* and there is a long pulse */
1046
            /* and there is a long pulse */
922
            if (current == SKYLONG) {
1047
            if (current == IROBOTLONG) {
923
                /* push a zero */
1048
                /* push a zero */
924
                rawbits = rawbits<<1;
1049
                rawbits = rawbits<<1;
925
               
1050
               
926
                if (previous == SKYLONG) {
1051
                if (previous == IROBOTLONG) {
927
                    cnt = 1;
1052
                    cnt = 1;
928
                }
1053
                }
929
                else {
1054
                else {
930
                    cnt = 0;
1055
                    cnt = 0;
931
                }
1056
                }
932
            }
1057
            }
933
            else if (cnt == 0) {
1058
            else if (cnt == 0) {
934
                cnt=1;
1059
                cnt=1;
935
                /* push a one */
1060
                /* push a one */
936
                rawbits = rawbits<<1;
1061
                rawbits = rawbits<<1;
937
                rawbits |= 1;
1062
                rawbits |= 1;
938
            }
1063
            }
939
            else {
1064
            else {
940
                cnt = 0;
1065
                cnt = 0;
941
            }
1066
            }
942
        }
1067
        }
943
       
1068
       
944
        previous=current;
1069
        previous=current;
945
       
1070
       
946
    }
1071
    }
947
   
1072
   
948
    proto->protocol = IR_PROTO_SKY;
1073
    proto->protocol = CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_IROBOT;
949
    proto->timeout = IR_SKY_TIMEOUT;
1074
    proto->timeout = IR_IROBOT_TIMEOUT;
950
    proto->data = rawbits;
1075
    proto->data = rawbits;
951
   
1076
   
952
    return IR_OK;
1077
    return IR_OK;
953
}
1078
}
954
#endif
1079
#endif
955
 
1080
 
956
/**
1081
/**
957
 * Expand data from Sky protocol
1082
 * Expand data from iRobot protocol
958
 *
1083
 *
959
 *
1084
 *
960
 * @param buf
1085
 * @param buf
961
 *      Pointer to buffer to store the expanded data
1086
 *      Pointer to buffer to store the expanded data
962
 * @param len
1087
 * @param len
Line 964... Line 1089...
964
 * @param proto
1089
 * @param proto
965
 *      Pointer to protocol information
1090
 *      Pointer to protocol information
966
 * @return
1091
 * @return
967
 *      IR_OK if data expanded successfully, one of several errormessages if not
1092
 *      IR_OK if data expanded successfully, one of several errormessages if not
968
 */
1093
 */
969
int8_t expandSky(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
1094
int8_t expandiRobot(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
-
 
1095
    uint8_t temp;
-
 
1096
    uint8_t lookup[16] = {
-
 
1097
                   0x0, 0x8, 0x4, 0xC,
-
 
1098
                   0x2, 0xA, 0x6, 0xE,
-
 
1099
                   0x1, 0x9, 0x5, 0xD,
-
 
1100
                   0x3, 0xB, 0x7, 0xF };
970
    //TODO: Implement this function.
1101
    temp = (uint8_t)proto->data;
-
 
1102
    temp = (lookup[temp &0x0F] << 4) | lookup[temp >>4];
-
 
1103
    proto->data = temp << 8;
-
 
1104
    proto->data += 0x52;
-
 
1105
    for (uint8_t i = 0; i < 32; i++) {
-
 
1106
        if ((proto->data>>(i>>1))&1) {
-
 
1107
            buf[i] = IR_IROBOT_LONG;
-
 
1108
            i++;
-
 
1109
            buf[i] = IR_IROBOT_SHORT;  
-
 
1110
        } else {
971
    buf[0] = IR_SKY_ST_BIT;
1111
            buf[i] = IR_IROBOT_SHORT;
-
 
1112
            i++;
972
    buf[1] = IR_SKY_LONG;   //
1113
            buf[i] = IR_IROBOT_LONG;
-
 
1114
        }
973
   
1115
    }
974
   
1116
   
-
 
1117
    *len = 31;
-
 
1118
    proto->modfreq=IR_IROBOT_F_MOD;
-
 
1119
    proto->timeout=IR_IROBOT_TIMEOUT;
-
 
1120
    proto->repeats=IR_IROBOT_REPS;
975
    return IR_NOT_CORRECT_DATA;
1121
    return IR_OK;
976
}
1122
}
-
 
1123
 
977
 
1124
 
978
#if (IR_PROTOCOLS_USE_NEXA2)
1125
#if (IR_PROTOCOLS_USE_NEXA2)
979
/**
1126
/**
980
 * Test data on NEXA protocol
1127
 * Test data on NEXA protocol
981
 * http://elektronikforumet.com/wiki/index.php?title=RF_Protokoll_-_Nexa_sj%C3%A4lvl%C3%A4rande
1128
 * http://elektronikforumet.com/wiki/index.php?title=RF_Protokoll_-_Nexa_sj%C3%A4lvl%C3%A4rande
Line 1058... Line 1205...
1058
                return IR_NOT_CORRECT_DATA;
1205
                return IR_NOT_CORRECT_DATA;
1059
            }
1206
            }
1060
        }
1207
        }
1061
    }
1208
    }
1062
   
1209
   
1063
    proto->protocol=IR_PROTO_NEXA2;
1210
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_NEXA2;
1064
    proto->timeout=IR_NEXA2_TIMEOUT;
1211
    proto->timeout=IR_NEXA2_TIMEOUT;
1065
    proto->data=rawbitsTemp;
1212
    proto->data=rawbitsTemp;
1066
 
1213
 
1067
    return IR_OK;
1214
    return IR_OK;
1068
}
1215
}
Line 1200... Line 1347...
1200
    {
1347
    {
1201
        /* Bogus RF data */
1348
        /* Bogus RF data */
1202
        return IR_NOT_CORRECT_DATA;
1349
        return IR_NOT_CORRECT_DATA;
1203
    }
1350
    }
1204
   
1351
   
1205
    proto->protocol=IR_PROTO_NEXA1;
1352
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_NEXA;
1206
    proto->timeout=IR_NEXA1_TIMEOUT;
1353
    proto->timeout=IR_NEXA1_TIMEOUT;
1207
    proto->data=rawbitsTemp;
1354
    proto->data=rawbitsTemp;
1208
    return IR_OK;
1355
    return IR_OK;
1209
}
1356
}
1210
 
1357
 
Line 1323... Line 1470...
1323
    }
1470
    }
1324
   
1471
   
1325
    rawbitsTemp = ~rawbitsTemp;
1472
    rawbitsTemp = ~rawbitsTemp;
1326
    rawbitsTemp = rawbitsTemp&0xFFFFFFFFFF;
1473
    rawbitsTemp = rawbitsTemp&0xFFFFFFFFFF;
1327
   
1474
   
1328
    proto->protocol=IR_PROTO_VIKING;
1475
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_VIKING;
1329
    proto->timeout=0;
1476
    proto->timeout=0;
1330
    proto->data=rawbitsTemp;
1477
    proto->data=rawbitsTemp;
1331
 
1478
 
1332
    return IR_OK;
1479
    return IR_OK;
1333
#else
1480
#else
Line 1414... Line 1561...
1414
    }
1561
    }
1415
   
1562
   
1416
    //rawbitsTemp = ~rawbitsTemp;
1563
    //rawbitsTemp = ~rawbitsTemp;
1417
    //rawbitsTemp = rawbitsTemp&0xFFFFFFFFFF;
1564
    //rawbitsTemp = rawbitsTemp&0xFFFFFFFFFF;
1418
   
1565
   
1419
    proto->protocol=IR_PROTO_VIKING_STEAK;
1566
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_VIKING_STEAK;
1420
    proto->timeout=IR_VIKING_STEAK_TIMEOUT;
1567
    proto->timeout=IR_VIKING_STEAK_TIMEOUT;
1421
    proto->data=rawbitsTemp;
1568
    proto->data=rawbitsTemp;
1422
 
1569
 
1423
    return IR_OK;
1570
    return IR_OK;
1424
#else
1571
#else
Line 1504... Line 1651...
1504
    }
1651
    }
1505
   
1652
   
1506
    //rawbitsTemp = ~rawbitsTemp;
1653
    //rawbitsTemp = ~rawbitsTemp;
1507
    //rawbitsTemp = rawbitsTemp&0xFFFFFFFFFF;
1654
    //rawbitsTemp = rawbitsTemp&0xFFFFFFFFFF;
1508
   
1655
   
1509
    proto->protocol=IR_PROTO_RUBICSON;
1656
    proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_RUBICSON;
1510
    proto->timeout=IR_RUBICSON_TIMEOUT;
1657
    proto->timeout=IR_RUBICSON_TIMEOUT;
1511
    proto->data=rawbitsTemp;
1658
    proto->data=rawbitsTemp;
1512
 
1659
 
1513
    return IR_OK;
1660
    return IR_OK;
1514
#else
1661
#else