Rev 1588 | Rev 1837 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1588 | Rev 1715 | ||
|---|---|---|---|
| Line 82... | Line 82... | ||
| 82 | 82 | ||
| 83 | #if (IR_PROTOCOLS_USE_SIRC) |
83 | #if (IR_PROTOCOLS_USE_SIRC) |
| 84 | /** |
84 | /** |
| 85 | * Test data on SIRC protocol, 12-bit version |
85 | * Test data on SIRC protocol, 12-bit version |
| 86 | * http://www.sbprojects.com/knowledge/ir/sirc.htm |
86 | * http://www.sbprojects.com/knowledge/ir/sirc.htm |
| - | 87 | * http://picprojects.org.uk/projects/sirc/sonysirc.pdf |
|
| 87 | * |
88 | * |
| 88 | * @param buf |
89 | * @param buf |
| 89 | * Pointer to buffer to where to data to parse is stored |
90 | * Pointer to buffer to where to data to parse is stored |
| 90 | * @param len |
91 | * @param len |
| 91 | * Length of the data |
92 | * Length of the data |
| Line 95... | Line 96... | ||
| 95 | * IR_OK if data parsed successfully, one of several errormessages if not |
96 | * IR_OK if data parsed successfully, one of several errormessages if not |
| 96 | */ |
97 | */ |
| 97 | int8_t parseSIRC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) { |
98 | int8_t parseSIRC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) { |
| 98 | /* parse buf[], max is len */ |
99 | /* parse buf[], max is len */ |
| 99 | 100 | ||
| 100 | /* check if we have correct amount of data |
101 | /* check if we have correct amount of data. |
| - | 102 | supporting two versions of SIRC: |
|
| - | 103 | 12 bit = 25, 15 bit = 31 |
|
| - | 104 | there is also a 20 bit protocol, but we don't support it |
|
| - | 105 | */ |
|
| 101 | if (len != 25) { |
106 | if (len != 25 && len != 31) { |
| 102 | return IR_NOT_CORRECT_DATA; |
107 | return IR_NOT_CORRECT_DATA; |
| 103 | } |
108 | } |
| 104 | 109 | ||
| 105 | /* check startbit */ |
110 | /* check startbit */ |
| 106 | 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) { |
111 | 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) { |
| 107 | return IR_NOT_CORRECT_DATA; |
112 | return IR_NOT_CORRECT_DATA; |
| 108 | } |
113 | } |
| 109 | 114 | ||
| 110 | uint16_t rawbits=0; |
115 | uint16_t rawbits=0; |
| 111 | 116 | ||
| 112 | for (uint8_t i = 1; i < len; i++) { |
117 | for (uint8_t i = 1; i < len; i++) { |
| 113 | if ((i&1) == 1) { /* if odd, ir-pause */ |
118 | if ((i&1) == 1) { /* if odd, ir-pause */ |
| Line 121... | Line 126... | ||
| 121 | rawbits |= 1<<((i-2)>>1); |
126 | rawbits |= 1<<((i-2)>>1); |
| 122 | } 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) { |
127 | } 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) { |
| 123 | /* do nothing, a zero is already in rawbits */ |
128 | /* do nothing, a zero is already in rawbits */ |
| 124 | } else { |
129 | } else { |
| 125 | return IR_NOT_CORRECT_DATA; |
130 | return IR_NOT_CORRECT_DATA; |
| 126 | } |
131 | } |
| 127 | } |
132 | } |
| 128 | } |
133 | } |
| 129 | 134 | ||
| 130 | proto->protocol = IR_PROTO_SIRC; |
135 | proto->protocol = IR_PROTO_SIRC; |
| 131 | proto->timeout = IR_SIRC_TIMEOUT; |
136 | proto->timeout = IR_SIRC_TIMEOUT; |
| 132 | proto->data = rawbits; |
137 | proto->data = rawbits; |
| 133 | 138 | ||
| 134 | return IR_OK; |
139 | return IR_OK; |
| 135 | } |
140 | } |
| 136 | #endif |
141 | #endif |
| 137 | 142 | ||
| 138 | /** |
143 | /** |
| 139 | * Expand data from SIRC protocol |
144 | * Expand data from SIRC protocol |
| 140 | * http://www.sbprojects.com/knowledge/ir/sirc.htm |
145 | * http://www.sbprojects.com/knowledge/ir/sirc.htm |
| 141 | * |
146 | * |
| 142 | * @param buf |
147 | * @param buf |
| Line 147... | Line 152... | ||
| 147 | * Pointer to protocol information |
152 | * Pointer to protocol information |
| 148 | * @return |
153 | * @return |
| 149 | * IR_OK if data expanded successfully, one of several errormessages if not |
154 | * IR_OK if data expanded successfully, one of several errormessages if not |
| 150 | */ |
155 | */ |
| 151 | int8_t expandSIRC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) { |
156 | int8_t expandSIRC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) { |
| 152 | //TODO: Implement this function. |
- | |
| 153 | buf[0] = IR_SIRC_ST_BIT; |
157 | buf[0] = IR_SIRC_ST_BIT; |
| 154 | buf[1] = IR_SIRC_LOW;//start pulse finished |
158 | buf[1] = IR_SIRC_LOW; //start pulse finished |
| 155 | 159 | ||
| - | 160 | /* Assume 12 bit protocol */ |
|
| - | 161 | *len = 25; |
|
| - | 162 | /* If data to big, use 15 bit protocol */ |
|
| - | 163 | if (proto->data > (1<<11)) { // cannot be represented by 12 bits |
|
| - | 164 | *len = 31; |
|
| - | 165 | } |
|
| - | 166 | for (uint8_t i = 0; i < *len-2; i++) { |
|
| - | 167 | if ((i&1) == 1) { /* if odd, ir-pause */ |
|
| - | 168 | buf[i+2] = IR_SIRC_LOW; |
|
| - | 169 | } else { /* if even, ir-bit */ |
|
| - | 170 | if ((proto->data>>(i>>1))&1) { |
|
| - | 171 | buf[i+2] = IR_SIRC_HIGH_ONE; |
|
| - | 172 | } else { |
|
| - | 173 | buf[i+2] = IR_SIRC_HIGH_ZERO; |
|
| - | 174 | } |
|
| - | 175 | } |
|
| - | 176 | } |
|
| 156 | 177 | ||
| - | 178 | proto->modfreq=IR_SIRC_F_MOD; |
|
| - | 179 | proto->timeout=IR_SIRC_TIMEOUT; |
|
| - | 180 | proto->repeats=IR_SIRC_REPS; |
|
| 157 | 181 | ||
| 158 | return |
182 | return IR_OK; |
| 159 | } |
183 | } |
| 160 | 184 | ||
| 161 | 185 | ||
| 162 | #if (IR_PROTOCOLS_USE_RC5) |
186 | #if (IR_PROTOCOLS_USE_RC5) |
| 163 | /** |
187 | /** |