Rev 2259 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2259 | Rev 2260 | ||
|---|---|---|---|
| Line 2121... | Line 2121... | ||
| 2121 | default: |
2121 | default: |
| 2122 | return IR_NOT_CORRECT_DATA; |
2122 | return IR_NOT_CORRECT_DATA; |
| 2123 | } |
2123 | } |
| 2124 | 2124 | ||
| 2125 | 2125 | ||
| 2126 | #else |
- | |
| 2127 | return IR_NOT_CORRECT_DATA; |
- | |
| 2128 | #endif |
- | |
| 2129 | } |
- | |
| 2130 | #endif |
- | |
| 2131 | - | ||
| 2132 | /** |
- | |
| 2133 | * Test data on OREGON weather sensor protocol |
- | |
| 2134 | * |
- | |
| 2135 | * |
- | |
| 2136 | * |
- | |
| 2137 | * @param buf |
- | |
| 2138 | * Pointer to buffer to where to data to parse is stored |
- | |
| 2139 | * @param len |
- | |
| 2140 | * Length of the data |
- | |
| 2141 | * @param proto |
- | |
| 2142 | * Pointer to protocol information |
- | |
| 2143 | * @return |
- | |
| 2144 | * IR_OK if data parsed successfully, one of several errormessages if not |
- | |
| 2145 | */ |
- | |
| 2146 | - | ||
| 2147 | int8_t parseOregon(const uint16_t *buf, uint8_t len, uint8_t index, Ir_Protocol_Data_t *proto) |
- | |
| 2148 | { |
- | |
| 2149 | #if IR_RX_CONTINUOUS_MODE==1 |
- | |
| 2150 | /* check if we have correct amount of data */ |
- | |
| 2151 | if (len < 74) { //Ändra till vettigt värde |
- | |
| 2152 | return IR_NOT_CORRECT_DATA; |
- | |
| 2153 | } |
- | |
| 2154 | uint8_t data[IR_OREGON_DATASIZE]; //Verifiera minsta möjliga storlek |
- | |
| 2155 | uint8_t i2 = 0; |
- | |
| 2156 | uint8_t b_i; |
- | |
| 2157 | uint8_t currentBit = 0; |
- | |
| 2158 | uint8_t done = 0; |
- | |
| 2159 | uint8_t invert = 0; |
- | |
| 2160 | uint8_t shift = 0; |
- | |
| 2161 | uint8_t i = index; |
- | |
| 2162 | uint64_t rawbitsTemp = 0;//0xffffffffffffffff; |
- | |
| 2163 | - | ||
| 2164 | /* Check stop condition */ |
- | |
| 2165 | if (buf[i] < IR_OREGON_END) |
- | |
| 2166 | { |
- | |
| 2167 | return IR_NOT_CORRECT_DATA; |
- | |
| 2168 | } |
- | |
| 2169 | i--; //set index to last bit |
- | |
| 2170 | len--; //Store remaining length |
- | |
| 2171 | printf("End\n"); |
- | |
| 2172 | //loop to store data |
- | |
| 2173 | while (done == 0) { //Wait for sync pulse and preamble, loop for all bytes |
- | |
| 2174 | data[i2] = 00; |
- | |
| 2175 | for (b_i = 0;b_i<8;b_i++) { //loop for each bit |
- | |
| 2176 | if (((buf[i] < IR_OREGON_SHORT_L) && (buf[i] > IR_OREGON_SHORT_S)) ) { |
- | |
| 2177 | i--; |
- | |
| 2178 | if (i > MAX_NR_TIMES) i = MAX_NR_TIMES - 1; |
- | |
| 2179 | if (((buf[i] < IR_OREGON_SHORT_L) && (buf[i] > IR_OREGON_SHORT_S))) { |
- | |
| 2180 | //Keep previous bit value |
- | |
| 2181 | data[i2] = data[b_i] << 1; |
- | |
| 2182 | data[i2] += currentBit; |
- | |
| 2183 | i--; |
- | |
| 2184 | if (i > MAX_NR_TIMES) i = MAX_NR_TIMES - 1; |
- | |
| 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;} |
- | |
| 2186 | } |
- | |
| 2187 | else if (((buf[i] < IR_OREGON_LONG_L) && (buf[i] > IR_OREGON_LONG_S))) { |
- | |
| 2188 | //Invert previous bit value |
- | |
| 2189 | if (currentBit) |
- | |
| 2190 | currentBit = 0; |
- | |
| 2191 | else |
- | |
| 2192 | currentBit = 1; |
- | |
| 2193 | data[i2] = data[b_i] << 1; |
- | |
| 2194 | data[i2] += currentBit; |
- | |
| 2195 | i--; |
- | |
| 2196 | if (i > MAX_NR_TIMES) i = MAX_NR_TIMES - 1; |
- | |
| 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 | - | ||
| 2203 | return IR_NOT_CORRECT_DATA; |
- | |
| 2204 | } |
- | |
| 2205 | printf("8 bits\n"); |
- | |
| 2206 | } |
- | |
| 2207 | //swap nibbles to make parsing easier |
- | |
| 2208 | uint8_t temp = data[i2] << 4; |
- | |
| 2209 | data[i2] = (data[i2] >> 4) + temp; |
- | |
| 2210 | //check for end condition |
- | |
| 2211 | if (i2 > 6) { // TODO check what value to use here |
- | |
| 2212 | if (data[i2] == 0xFFu && data[i2-1] == 0xFAu) { |
- | |
| 2213 | done = 1; |
- | |
| 2214 | } |
- | |
| 2215 | if (data[i2] == 0x00u && data[i2-1] == 0x05u) { |
- | |
| 2216 | done = 1; |
- | |
| 2217 | invert = 1; |
- | |
| 2218 | } |
- | |
| 2219 | if (data[i2] == 0xFFu && (data[i2-1]&0xF0u) == 0xA0u) { |
- | |
| 2220 | shift = 1; |
- | |
| 2221 | done = 1; |
- | |
| 2222 | } |
- | |
| 2223 | if (data[i2] == 0x00u && (data[i2-1]&0xF0u) == 0x50u) { |
- | |
| 2224 | shift = 1; |
- | |
| 2225 | done = 1; |
- | |
| 2226 | invert = 1; |
- | |
| 2227 | } |
- | |
| 2228 | } |
- | |
| 2229 | i2++; |
- | |
| 2230 | if (i2 >= IR_OREGON_DATASIZE) |
- | |
| 2231 | { |
- | |
| 2232 | printf("Ovr\n"); |
- | |
| 2233 | return IR_NOT_CORRECT_DATA; |
- | |
| 2234 | } |
- | |
| 2235 | } |
- | |
| 2236 | printf("Found\n"); |
- | |
| 2237 | i2--; //restore index |
- | |
| 2238 | if (invert == 1) { |
- | |
| 2239 | for (b_i = 0;b_i<=i2;b_i++) { //loop for each byte |
- | |
| 2240 | data[b_i] ^= 0xFFu; |
- | |
| 2241 | } |
- | |
| 2242 | } |
- | |
| 2243 | if (shift == 1) { |
- | |
| 2244 | for (b_i = i2;b_i>0;b_i--) { //loop for each byte |
- | |
| 2245 | data[b_i] = (data[b_i] << 4) + (data[(b_i - 1)] & 0x0Fu); |
- | |
| 2246 | } |
- | |
| 2247 | data[0] = data[0] << 4; |
- | |
| 2248 | i2--; //remove sync byte |
- | |
| 2249 | } else { |
- | |
| 2250 | i2--; //remove sync byte |
- | |
| 2251 | i2--; //remove sync byte |
- | |
| 2252 | } |
- | |
| 2253 | - | ||
| 2254 | - | ||
| 2255 | switch (data[i2]) { |
- | |
| 2256 | case 0x19u: |
- | |
| 2257 | if (data[i2-1] == 0x84 || data[i2-1] == 0x94 ) { //Anemometer |
- | |
| 2258 | i2-=2; //Remove Sensor id |
- | |
| 2259 | rawbitsTemp = 0x100000000000uL; //Anemometer id |
- | |
| 2260 | rawbitsTemp |= ((uint64_t)(data[i2]&0xF0u)) << 36; //store channel as MSB |
- | |
| 2261 | i2--; |
- | |
| 2262 | if (data[i2] == 0x4u) |
- | |
| 2263 | rawbitsTemp |= 0x080000000000uL; //Bat Low flag |
- | |
| 2264 | i2--; |
- | |
| 2265 | rawbitsTemp |= ((uint64_t)(data[i2]&0xF0u)) << 28; //store wind direction 0x0->0xF |
- | |
| 2266 | i2--; |
- | |
| 2267 | rawbitsTemp |= ((uint64_t)(data[i2]&0x0Fu)) << 24; //store current wind speed |
- | |
| 2268 | i2--; |
- | |
| 2269 | rawbitsTemp |= ((uint64_t)(data[i2])) << 16; //store current wind speed |
- | |
| 2270 | i2--; |
- | |
| 2271 | rawbitsTemp |= ((uint64_t)(data[i2])) << 8; //store average wind speed |
- | |
| 2272 | i2--; |
- | |
| 2273 | rawbitsTemp |= ((uint64_t)(data[i2]&0xF0u)) << 0; //store current wind speed |
- | |
| 2274 | } else { |
- | |
| 2275 | return IR_NOT_CORRECT_DATA; |
- | |
| 2276 | } |
- | |
| 2277 | break; |
- | |
| 2278 | case 0x1Du: |
- | |
| 2279 | case 0xF8u: |
- | |
| 2280 | if (data[i2-1] == 0x20 || data[i2-1] == 0x24 || data[i2-1] == 0xB4 ) { //Temperature/humidity |
- | |
| 2281 | i2-=2; //Remove Sensor id |
- | |
| 2282 | rawbitsTemp = 0x200000000000uL; //Temp/humidity id |
- | |
| 2283 | rawbitsTemp |= ((uint64_t)(data[i2]&0xF0u)) << 36; //store channel as MSB |
- | |
| 2284 | i2--; |
- | |
| 2285 | if (data[i2] == 0x4u) |
- | |
| 2286 | rawbitsTemp |= 0x080000000000uL; //Bat Low flag |
- | |
| 2287 | i2--; |
- | |
| 2288 | rawbitsTemp |= ((uint64_t)(data[i2])) << 16; //store temp |
- | |
| 2289 | i2--; |
- | |
| 2290 | rawbitsTemp |= ((uint64_t)(data[i2])) << 8; //store temp and temp sign |
- | |
| 2291 | i2--; |
- | |
| 2292 | rawbitsTemp |= ((uint64_t)(data[i2])) << 0; //store humidity |
- | |
| 2293 | } else { |
- | |
| 2294 | return IR_NOT_CORRECT_DATA; |
- | |
| 2295 | } |
- | |
| 2296 | break; |
- | |
| 2297 | case 0x29u: |
- | |
| 2298 | if (data[i2-1] == 0x14) { //Rain Gauge (inches) |
- | |
| 2299 | i2-=2; //Remove Sensor id |
- | |
| 2300 | rawbitsTemp = 0x300000000000uL; //Rain inches id |
- | |
| 2301 | rawbitsTemp |= ((uint64_t)(data[i2]&0xF0u)) << 36; //store channel as MSB |
- | |
| 2302 | i2--; |
- | |
| 2303 | if (data[i2] == 0x4u) |
- | |
| 2304 | rawbitsTemp |= 0x080000000000uL; //Bat Low flag |
- | |
| 2305 | i2--; |
- | |
| 2306 | rawbitsTemp |= ((uint64_t)(data[i2])) << 32; //Rain per hour |
- | |
| 2307 | i2--; |
- | |
| 2308 | rawbitsTemp |= ((uint64_t)(data[i2])) << 24; //Rain per hour |
- | |
| 2309 | i2--; |
- | |
| 2310 | rawbitsTemp |= ((uint64_t)(data[i2])) << 16; //store total rain |
- | |
| 2311 | i2--; |
- | |
| 2312 | rawbitsTemp |= ((uint64_t)(data[i2])) << 8; //store total rain |
- | |
| 2313 | i2--; |
- | |
| 2314 | rawbitsTemp |= ((uint64_t)(data[i2])) << 0; //store total rain |
- | |
| 2315 | } else { |
- | |
| 2316 | return IR_NOT_CORRECT_DATA; |
- | |
| 2317 | } |
- | |
| 2318 | break; |
- | |
| 2319 | case 0x2Du: |
- | |
| 2320 | if (data[i2-1] == 0x10) { //Rain Gauge (mm) |
- | |
| 2321 | i2-=2; //Remove Sensor id |
- | |
| 2322 | rawbitsTemp = 0x400000000000uL; //Rain mm id |
- | |
| 2323 | rawbitsTemp |= ((uint64_t)(data[i2]&0xF0u)) << 36; //store channel as MSB |
- | |
| 2324 | i2--; |
- | |
| 2325 | if (data[i2] == 0x4u) |
- | |
| 2326 | rawbitsTemp |= 0x080000000000uL; //Bat Low flag |
- | |
| 2327 | i2--; |
- | |
| 2328 | rawbitsTemp |= ((uint64_t)(data[i2])) << 32; //Rain per hour |
- | |
| 2329 | i2--; |
- | |
| 2330 | rawbitsTemp |= ((uint64_t)(data[i2])) << 24; //Rain per hour |
- | |
| 2331 | i2--; |
- | |
| 2332 | rawbitsTemp |= ((uint64_t)(data[i2])) << 16; //store total rain |
- | |
| 2333 | i2--; |
- | |
| 2334 | rawbitsTemp |= ((uint64_t)(data[i2])) << 8; //store total rain |
- | |
| 2335 | i2--; |
- | |
| 2336 | rawbitsTemp |= ((uint64_t)(data[i2])) << 0; //store total rain |
- | |
| 2337 | } else { |
- | |
| 2338 | return IR_NOT_CORRECT_DATA; |
- | |
| 2339 | } |
- | |
| 2340 | break; |
- | |
| 2341 | default: |
- | |
| 2342 | return IR_NOT_CORRECT_DATA; |
- | |
| 2343 | break; |
- | |
| 2344 | } |
- | |
| 2345 | - | ||
| 2346 | proto->protocol=CAN_MODULE_ENUM_PHYSICAL_IR_PROTOCOL_OREGON; |
- | |
| 2347 | proto->timeout=IR_OREGON_TIMEOUT; |
- | |
| 2348 | proto->data=rawbitsTemp; |
- | |
| 2349 | - | ||
| 2350 | return IR_OK; |
- | |
| 2351 | #else |
2126 | #else |
| 2352 | return IR_NOT_CORRECT_DATA; |
2127 | return IR_NOT_CORRECT_DATA; |
| 2353 | #endif |
2128 | #endif |
| 2354 | } |
2129 | } |
| 2355 | #endif |
2130 | #endif |