testy w polarisie

pull/2/head
Mateusz Lubecki 2020-09-20 18:01:29 +02:00
rodzic 3c67678367
commit 6b0fbcdf31
8 zmienionych plików z 238 dodań i 4 usunięć

49
davis_loop.txt 100644
Wyświetl plik

@ -0,0 +1,49 @@
srl_usart1_rx_buffer : 0x2000030C <ASCII>
Address 0 1 2 3 4 5 6 7 8 9 A B C D E F
20000300              L O O
20000310 Ä  ú  v ´  5 §    S  ÿ
20000320 ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ < ÿ
20000330 ÿ ÿ ÿ ÿ ÿ ÿ    "    ÿ ÿ 
20000340    % 
   .  ÿ ÿ ÿ ÿ ÿ
20000350 ÿ ÿ              
20000360     ¥   s  4 
 -
20000370                
20000380                
20000390                
200003A0                
200003B0                
200003C0                
200003D0                
200003E0                
200003F0                
20000400                
20000410                
20000420                
20000430                
srl_usart1_rx_buffer : 0x2000030C <Hex>
Address 0 1 2 3 4 5 6 7 8 9 A B C D E F
20000300 00 00 00 00 00 00 00 00 00 00 00 00 06 4C 4F 4F
20000310 C4 00 FA 08 0D 76 B4 02 35 A7 02 00 01 53 01 FF
20000320 FF FF FF FF FF FF FF FF FF FF FF FF FF FF 3C FF
20000330 FF FF FF FF FF FF 00 00 07 22 01 00 00 FF FF 00
20000340 00 00 00 25 0F 0A 00 00 00 2E 07 FF FF FF FF FF
20000350 FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000360 00 00 00 00 A5 02 06 0C 73 02 34 07 0A 0D 14 2D
20000370 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000380 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000390 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000400 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000420 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000430 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

80
davis_loop2.txt 100644
Wyświetl plik

@ -0,0 +1,80 @@
srl_usart1_rx_buffer : 0x2000030C <Hex>
Address 0 1 2 3 4 5 6 7 8 9 A B C D E F
20000300 00 00 00 00 00 00 00 00 00 00 00 00 06 4C 4F 4F
20000310 C4 01 FF 7F 07 76 8A 02 40 82 02 00 FF 20 01 08
20000320 00 0E 00 03 00 24 01 FF 7F FF 7F 37 00 FF 47 FF
20000330 40 00 40 00 40 00 00 00 00 3C 00 00 00 FF FF 00
20000340 00 00 00 00 00 0A 00 00 00 02 00 00 0E 00 3E 6D
20000350 3E 6D 53 76 FF 01 02 0A 12 0D 09 0E 15 0D 01 01
20000360 FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F 0A 0D 99 67
20000370 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000380 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000390 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000400 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000420 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000430 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
srl_usart1_rx_buffer : 0x2000030C <ASCII>
Address 0 1 2 3 4 5 6 7 8 9 A B C D E F
20000300              L O O
20000310 Ä  ÿ   v Š  @   ÿ  
20000320      $  ÿ  ÿ  7  ÿ G ÿ
20000330 @  @  @     <    ÿ ÿ 
20000340     
        > m
20000350 > m S v ÿ  
    
20000360 ÿ  ÿ  ÿ  ÿ  ÿ  ÿ 
™ g
20000370                
20000380                
20000390                
200003A0                
200003B0                
200003C0                
200003D0                
200003E0                
200003F0                
20000400                
20000410                
20000420                
20000430                
/////
srl_usart1_rx_buffer : 0x2000030C <Hex>
Address 0 1 2 3 4 5 6 7 8 9 A B C D E F
20000300 00 00 00 00 00 00 00 00 00 00 00 00 06 4C 4F 4F
20000310 C4 01 FF 7F 07 76 7F 02 42 78 02 01 FF 18 01 0A
20000320 00 0B 00 03 00 24 01 FF 7F FF 7F 36 00 FF 49 FF
20000330 3F 00 3F 00 3F 00 00 00 00 41 00 00 00 FF FF 00
20000340 00 00 00 00 00 0A 00 00 00 02 00 00 0E 00 3E 6D
20000350 3E 6D 53 76 FF 07 02 0B 12 0D 0F 0E 1B 0D 01 01
20000360 FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F 0A 0D 6A BE
20000370 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000380 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000390 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200003F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000400 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000420 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20000430 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Details:{barometer = 30215, inside_temperature = 639, outside_temperature = 632, wind_speed = 11, wind_speed_10min_average = 10, wind_gusts = 3, wind_direction = 280, outside_humidity = 73 'I', day_rain = 0, crc = 0}

Wyświetl plik

@ -693,7 +693,9 @@ int main(int argc, char* argv[]){
// if modbus rtu master is enabled
if (main_modbus_rtu_master_enabled == 1) {
#ifdef _MODBUS_RTU
rtu_serial_pool(&main_rtu_pool_queue, main_wx_srl_ctx_ptr);
#endif
}
// get all meteo measuremenets each 65 seconds. some values may not be

Wyświetl plik

@ -29,12 +29,15 @@ typedef struct davis_loop {
uint16_t outside_temperature;
// wind speed in US land miles per hour. Value od '1' means 1mph
uint8_t wind_speed;
uint16_t wind_speed;
// the same scaling as for wind_speed. There is no clear explanation
// what are the differences between wind_speed and it's 10 minutes
// average. Presumably wind_speed is just a current value
uint8_t wind_speed_10min_average;
uint16_t wind_speed_10min_average;
// only in loop2
uint16_t wind_gusts_10min;
// Wind direction in degrees. It is scaled +1 from real value.
// Value of 0 means that no data is available

Wyświetl plik

@ -25,6 +25,7 @@ inline static uint8_t is_digit(char c) {
}
uint32_t davis_parsers_loop(uint8_t* input, uint16_t input_ln, davis_loop_t* output);
uint32_t davis_parsers_loop2(uint8_t* input, uint16_t input_ln, davis_loop_t* output);
uint32_t davis_parsers_check_crc(uint8_t* input, uint16_t input_ln);
uint32_t davis_parsers_rxcheck( uint8_t* input,
uint16_t input_ln,

Wyświetl plik

@ -21,6 +21,8 @@
#define RX_CHECK_LN_WITH_ACK 32
#define RX_CHECK_MIN_LN_WITH_ACK 16
#define DAVIS_QUERY_ABOUT_LOOP2
/**
* Serial port context to be used for communication
*/
@ -72,11 +74,16 @@ uint32_t davis_last_good_rxcheck = 0;
static const char line_feed = '\n';
static const char line_feed_return[] = {'\n', '\r'};
static const char loop_command[] = "LOOP 1\n";
static const char lamps_off[] = "LAMPS 0\n";
static const char lamps_on[] = "LAMPS 1\n";
static const char leave_rx_screen[] = "RXTEST\n"; // it also resets
static const char rx_check[] = "RXCHECK\n";
#ifdef DAVIS_QUERY_ABOUT_LOOP2
static const char loop_command[] = "LPS 2 1\n";
#else
static const char loop_command[] = "LOOP 1\n";
#endif
uint32_t davis_init(srl_context_t* srl_port) {
@ -380,7 +387,7 @@ uint32_t davis_loop_packet_pooler(uint8_t* loop_avaliable_flag) {
}
else {
// send the LOOP query
srl_send_data(davis_serial_context, (uint8_t*)loop_command, 1, 7, 0);
srl_send_data(davis_serial_context, (uint8_t*)loop_command, 1, strlen(loop_command), 0);
*loop_avaliable_flag = 0;

Wyświetl plik

@ -10,6 +10,8 @@
#include <string.h>
#include <stdio.h>
#define DAVIS_QUERY_ABOUT_LOOP2
const uint16_t crc_table [] = {
0x0, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
@ -59,10 +61,19 @@ const uint16_t crc_table [] = {
#define LOOP_OUTSIDE_HUMIDITY 33
#define LOOP_DAY_RAIN_OFFSET 50
#define LOOP2_CRC_OFFSET 0x61
#define LOOP2_WIND_DIRECTION 16
#define LOOP2_TEN_MINUTES_AVG_WINDSPEED 18
#define LOOP2_TWO_MINUTES_AVG_WINDSPEED 20
#define LOOP2_TEN_MINUTES_GUST 22
uint32_t davis_parsers_loop(uint8_t* input, uint16_t input_ln, davis_loop_t* output) {
uint32_t retval = DAVIS_PARSERS_OK;
#ifdef DAVIS_QUERY_ABOUT_LOOP2
retval = davis_parsers_loop2(input, input_ln, output);
#else
// crc stored in the frame
uint16_t crc_from_frame = 0;
@ -127,10 +138,86 @@ uint32_t davis_parsers_loop(uint8_t* input, uint16_t input_ln, davis_loop_t* out
}
}
}
#endif
return retval;
}
uint32_t davis_parsers_loop2(uint8_t* input, uint16_t input_ln, davis_loop_t* output) {
uint32_t retval = DAVIS_PARSERS_OK;
// crc stored in the frame
uint16_t crc_from_frame = 0;
// calculated crc checksum
uint16_t calculated_crc = 0;
// check if input buffer consist at least as many characters as the LOOP packet has
if (input_ln < LOOP_PACAKET_LN) {
// return with an error state, don't consider consecutive content of a frame
// as it is for sure incorrect
retval = DAVIS_PARSERS_TOO_SHORT_FRAME;
}
else {
if (*input == 0x06 && *(input + 1) == 'L') {
// if yes rewind the buffer to the next character
input += 1;
retval = DAVIS_PARSERS_OK;
}
else if (*input == 'L') {
retval = DAVIS_PARSERS_OK;
}
else {
retval = DAVIS_PARSERS_WRONG_CONTENT;
}
if (retval == DAVIS_PARSERS_OK) {
// retrieve the CRC value from the frame content (sent in MSB, totally opposite from the rest of the frame)
crc_from_frame = *(input + LOOP_CRC_OFFSET + 1) | (*(input + LOOP_CRC_OFFSET)) << 8;
// calculate the CRC locally excluding the last 2 bytes which consists the CRC value.
// the another way of performing this calculation is to include the last 2 bytes (CRC itself)
// and check if the result equals '0' what indicates that data is not corrupted.
calculated_crc = davis_parsers_check_crc(input, LOOP_PACAKET_LN - 2);
if (calculated_crc == crc_from_frame) {
// fetch the pressure
output->barometer = *(input + LOOP_BAROMETER_OFFSET) | *(input + LOOP_BAROMETER_OFFSET + 1) << 8;
output->inside_temperature = *(input + LOOP_INSIDE_TEMPERATURE_OFFSET) | *(input + LOOP_INSIDE_TEMPERATURE_OFFSET + 1) << 8;
output->outside_temperature = *(input + LOOP_OUTSIDE_TEMPERATURE_OFFSET) | *(input + LOOP_OUTSIDE_TEMPERATURE_OFFSET + 1) << 8;
output->wind_speed = *(input + LOOP2_TWO_MINUTES_AVG_WINDSPEED) | *(input + LOOP2_TWO_MINUTES_AVG_WINDSPEED + 1) << 8;
output->wind_speed_10min_average = *(input + LOOP2_TEN_MINUTES_AVG_WINDSPEED) | *(input + LOOP2_TEN_MINUTES_AVG_WINDSPEED + 1) << 8;
output->wind_gusts_10min = *(input + LOOP2_TEN_MINUTES_GUST) | *(input + LOOP2_TEN_MINUTES_GUST + 1) << 8;
output->wind_direction = *(input + LOOP_WIND_DIRECTION_OFFSET) | *(input + LOOP_WIND_DIRECTION_OFFSET + 1) << 8;
output->outside_humidity = *(input + LOOP_OUTSIDE_HUMIDITY);
output->day_rain = *(input + LOOP_DAY_RAIN_OFFSET);
}
else {
// if CRCs differs treat the frame as corrupted and
retval = DAVIS_PARSERS_CORRUPTED_CRC;
}
}
}
return retval;
}
uint32_t davis_parsers_check_crc(uint8_t* input, uint16_t input_ln) {
//uint32_t retval = 0;

Wyświetl plik

@ -73,6 +73,9 @@ int32_t rtu_serial_init(rtu_pool_queue_t* queue) {
// zeroing the content of the structure
memset(queue, 0x00, sizeof(rtu_pool_queue_t));
#ifdef _MODBUS_RTU
#ifdef _RTU_SLAVE_ID_1
queue->function_id[0] =_RTU_SLAVE_FUNC_1;
queue->function_parameter[0] = &rte_wx_modbus_rtu_f1;
@ -107,6 +110,8 @@ int32_t rtu_serial_init(rtu_pool_queue_t* queue) {
rte_wx_modbus_rtu_f4.slave_address = _RTU_SLAVE_ID_4;
rte_wx_modbus_rtu_f4.base_address = _RTU_SLAVE_ADDR_4;
rte_wx_modbus_rtu_f4.number_of_registers = 1;
#endif
#endif
return retval;