kopia lustrzana https://github.com/SP8EBC/ParaTNC
conditional compilation removed from wx_pool_anemometer
rodzic
9a7131fc3c
commit
bfe4bfb86b
|
@ -17,6 +17,9 @@
|
|||
|
||||
typedef struct config_data_mode_t {
|
||||
|
||||
#define WX_ENABLED (1)
|
||||
#define WX_INTERNAL_AS_BACKUP (1 << 1)
|
||||
|
||||
uint8_t digi;
|
||||
|
||||
uint8_t wx;
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
#include "drivers/serial.h"
|
||||
#include "config_data.h"
|
||||
|
||||
#define SW_VER "DF14"
|
||||
#define SW_DATE "22032021"
|
||||
#define SW_VER "EA00"
|
||||
#define SW_DATE "13052021"
|
||||
|
||||
#define SYSTICK_TICKS_PER_SECONDS 100
|
||||
#define SYSTICK_TICKS_PERIOD 10
|
||||
|
@ -38,6 +38,12 @@ extern uint8_t main_own_path_ln;
|
|||
extern uint8_t main_own_aprs_msg_len;
|
||||
extern char main_own_aprs_msg[OWN_APRS_MSG_LN];
|
||||
|
||||
extern char main_string_latitude[9];
|
||||
extern char main_string_longitude[9];
|
||||
|
||||
extern char main_symbol_f;
|
||||
extern char main_symbol_s;
|
||||
|
||||
extern srl_context_t* main_kiss_srl_ctx_ptr;
|
||||
extern srl_context_t* main_wx_srl_ctx_ptr;
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ extern uint8_t rte_wx_winddirection_it;
|
|||
extern uint16_t rte_wx_winddirection_last;
|
||||
extern uint16_t rte_wx_average_windspeed;
|
||||
extern uint16_t rte_wx_max_windspeed;
|
||||
extern int16_t rte_wx_average_winddirection;
|
||||
extern uint16_t rte_wx_average_winddirection;
|
||||
|
||||
extern int8_t rte_wx_humidity, rte_wx_humidity_valid;
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ typedef enum wx_pwr_state_t {
|
|||
void wx_get_all_measurements(const config_data_wx_sources_t * const config_sources, const config_data_mode_t * const config_mode, const config_data_umb_t * const config_umb, const config_data_rtu_t * const config_rtu);
|
||||
int32_t wx_get_bme280_temperature_pressure_humidity(float * const temperature, float * const pressure, int8_t * const humidity);
|
||||
|
||||
void wx_pool_anemometer(void);
|
||||
void wx_pool_anemometer(const config_data_wx_sources_t * const config_sources, const config_data_mode_t * const config_mode, const config_data_umb_t * const config_umb, const config_data_rtu_t * const config_rtu);
|
||||
void wx_pwr_init(void);
|
||||
void wx_pwr_periodic_handle(void);
|
||||
void wx_pwr_disable_12v_sw(void);
|
||||
|
|
|
@ -385,5 +385,5 @@ void configuration_handler_load_configuration(configuration_handler_region_t reg
|
|||
}
|
||||
|
||||
uint32_t configuration_handler_program(uint8_t* data, uint16_t data_ln, uint8_t config_idx) {
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
|
29
src/main.c
29
src/main.c
|
@ -404,11 +404,10 @@ int main(int argc, char* argv[]){
|
|||
// Configure I/O pins for USART1 (Kiss modem)
|
||||
Configure_GPIO(GPIOA,10,PUD_INPUT); // RX
|
||||
Configure_GPIO(GPIOA,9,AFPP_OUTPUT_2MHZ); // TX
|
||||
#if defined(PARATNC_HWREV_B) || defined(PARATNC_HWREV_C)
|
||||
|
||||
// Configure I/O pins for USART2 (wx meteo comm)
|
||||
Configure_GPIO(GPIOA,3,PUD_INPUT); // RX
|
||||
Configure_GPIO(GPIOA,2,AFPP_OUTPUT_2MHZ); // TX
|
||||
#endif
|
||||
|
||||
#if defined(PARATNC_HWREV_A) || defined(PARATNC_HWREV_B)
|
||||
Configure_GPIO(GPIOA,7,GPPP_OUTPUT_2MHZ); // re/te
|
||||
|
@ -423,28 +422,11 @@ int main(int argc, char* argv[]){
|
|||
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
|
||||
RCC->APB1ENR |= RCC_APB1ENR_USART2EN;
|
||||
|
||||
#if defined(PARATNC_HWREV_A)
|
||||
main_kiss_srl_ctx_ptr = &main_kiss_srl_ctx;
|
||||
main_wx_srl_ctx_ptr = &main_kiss_srl_ctx;
|
||||
|
||||
main_target_kiss_baudrate = 9600u;
|
||||
#if defined(_UMB_MASTER)
|
||||
main_target_kiss_baudrate = _SERIAL_BAUDRATE;
|
||||
#endif
|
||||
#endif
|
||||
#if defined(PARATNC_HWREV_B) || defined(PARATNC_HWREV_C)
|
||||
main_kiss_srl_ctx_ptr = &main_kiss_srl_ctx;
|
||||
main_wx_srl_ctx_ptr = &main_wx_srl_ctx;
|
||||
|
||||
main_target_kiss_baudrate = 9600u;
|
||||
main_target_wx_baudrate = _SERIAL_BAUDRATE;
|
||||
#endif
|
||||
#if !defined(PARATNC_HWREV_A) && !defined(PARATNC_HWREV_B) && !defined(PARATNC_HWREV_C)
|
||||
main_kiss_srl_ctx_ptr = &main_kiss_srl_ctx;
|
||||
main_wx_srl_ctx_ptr = &main_kiss_srl_ctx;
|
||||
|
||||
main_target_kiss_baudrate = _SERIAL_BAUDRATE;
|
||||
#endif
|
||||
|
||||
// if Victron VE-direct protocol is enabled set the baudrate to the 19200u
|
||||
if (main_config_data_mode->victron == 1) {
|
||||
|
@ -506,7 +488,6 @@ int main(int argc, char* argv[]){
|
|||
|
||||
}
|
||||
#endif
|
||||
//#elif (defined(PARATNC_HWREV_B) || defined(PARATNC_HWREV_C)) && defined(_MODBUS_RTU)
|
||||
if (main_config_data_mode->wx_modbus == 1) {
|
||||
|
||||
rtu_serial_init(&rte_rtu_pool_queue, 1, main_wx_srl_ctx_ptr, main_config_data_rtu);
|
||||
|
@ -524,15 +505,11 @@ int main(int argc, char* argv[]){
|
|||
rtu_serial_start();
|
||||
}
|
||||
else {
|
||||
//#else
|
||||
// initializing UART drvier
|
||||
srl_init(main_kiss_srl_ctx_ptr, USART1, srl_usart1_rx_buffer, RX_BUFFER_1_LN, srl_usart1_tx_buffer, TX_BUFFER_1_LN, main_target_kiss_baudrate, 1);
|
||||
srl_init(main_wx_srl_ctx_ptr, USART2, srl_usart2_rx_buffer, RX_BUFFER_2_LN, srl_usart2_tx_buffer, TX_BUFFER_2_LN, main_target_wx_baudrate, 1);
|
||||
}
|
||||
|
||||
//#endif
|
||||
|
||||
|
||||
#if defined(PARATNC_HWREV_A) || defined(PARATNC_HWREV_B)
|
||||
main_wx_srl_ctx_ptr->te_pin = GPIO_Pin_7;
|
||||
main_wx_srl_ctx_ptr->te_port = GPIOA;
|
||||
|
@ -902,7 +879,7 @@ int main(int argc, char* argv[]){
|
|||
rtu_serial_start();
|
||||
}
|
||||
|
||||
if (main_config_data_mode->wx == 1) {
|
||||
if (main_config_data_mode->wx > 0) {
|
||||
wx_get_all_measurements(main_config_data_wx_sources, main_config_data_mode, main_config_data_umb, main_config_data_rtu);
|
||||
}
|
||||
|
||||
|
@ -984,7 +961,7 @@ int main(int argc, char* argv[]){
|
|||
}
|
||||
//#endif
|
||||
|
||||
wx_pool_anemometer();
|
||||
wx_pool_anemometer(main_config_data_wx_sources, main_config_data_mode, main_config_data_umb, main_config_data_rtu);
|
||||
|
||||
if (main_davis_serial_enabled == 1) {
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ uint8_t rte_wx_winddirection_it = 0;
|
|||
uint16_t rte_wx_winddirection_last = 0;
|
||||
uint16_t rte_wx_average_windspeed = 0;
|
||||
uint16_t rte_wx_max_windspeed = 0;
|
||||
int16_t rte_wx_average_winddirection = 0;
|
||||
uint16_t rte_wx_average_winddirection = 0;
|
||||
|
||||
int8_t rte_wx_humidity = 0, rte_wx_humidity_valid = 0;
|
||||
|
||||
|
|
243
src/wx_handler.c
243
src/wx_handler.c
|
@ -100,7 +100,6 @@ void wx_get_all_measurements(const config_data_wx_sources_t * const config_sourc
|
|||
|
||||
int32_t wx_get_bme280_temperature_pressure_humidity(float * const temperature, float * const pressure, int8_t * const humidity) {
|
||||
|
||||
int i = 0, j = 0;
|
||||
int32_t return_value = 0;
|
||||
|
||||
// reading raw values from BME280 sensor
|
||||
|
@ -130,7 +129,7 @@ int32_t wx_get_bme280_temperature_pressure_humidity(float * const temperature, f
|
|||
}
|
||||
|
||||
|
||||
void wx_pool_anemometer(void) {
|
||||
void wx_pool_anemometer(const config_data_wx_sources_t * const config_sources, const config_data_mode_t * const config_mode, const config_data_umb_t * const config_umb, const config_data_rtu_t * const config_rtu) {
|
||||
|
||||
// locals
|
||||
uint32_t average_windspeed = 0;
|
||||
|
@ -143,167 +142,165 @@ void wx_pool_anemometer(void) {
|
|||
short i = 0;
|
||||
uint8_t average_ln;
|
||||
|
||||
#ifdef _MODBUS_RTU
|
||||
int32_t modbus_retval;
|
||||
#endif
|
||||
|
||||
wx_wind_pool_call_counter++;
|
||||
|
||||
uint16_t scaled_windspeed = 0;
|
||||
|
||||
// internal sensors
|
||||
#if defined(_ANEMOMETER_ANALOGUE) && !defined(_UMB_MASTER) && !defined(_MODBUS_RTU) || (!defined(_RTU_SLAVE_WIND_DIRECTION_SORUCE) && !defined(_RTU_SLAVE_WIND_SPEED_SOURCE) && defined(_ANEMOMETER_ANALOGUE))
|
||||
// this windspeed is scaled * 10. Example: 0.2 meters per second is stored as 2
|
||||
scaled_windspeed = analog_anemometer_get_ms_from_pulse(rte_wx_windspeed_pulses);
|
||||
#endif
|
||||
|
||||
#if defined(_UMB_MASTER)
|
||||
rte_wx_average_winddirection = umb_get_winddirection();
|
||||
rte_wx_average_windspeed = umb_get_windspeed();
|
||||
rte_wx_max_windspeed = umb_get_windgusts();
|
||||
#else
|
||||
|
||||
#if defined(_MODBUS_RTU) && defined(_RTU_SLAVE_WIND_DIRECTION_SORUCE) && defined(_RTU_SLAVE_WIND_SPEED_SOURCE) && !defined(_RTU_SLAVE_FULL_WIND_DATA)
|
||||
// get the value from modbus registers
|
||||
modbus_retval = rtu_get_wind_speed(&scaled_windspeed);
|
||||
|
||||
// check if this value has been processed w/o errors
|
||||
if (modbus_retval == MODBUS_RET_OK) {
|
||||
// if yes continue to further processing
|
||||
modbus_retval = rtu_get_wind_direction(&rte_wx_winddirection_last);
|
||||
|
||||
if (config_sources->wind == WX_SOURCE_INTERNAL) {
|
||||
// this windspeed is scaled * 10. Example: 0.2 meters per second is stored as 2
|
||||
scaled_windspeed = analog_anemometer_get_ms_from_pulse(rte_wx_windspeed_pulses);
|
||||
}
|
||||
|
||||
// the second IF to check if the return value was the same for wind direction
|
||||
if (modbus_retval == MODBUS_RET_OK || modbus_retval == MODBUS_RET_DEGRADED) {
|
||||
// if the value is not available (like modbus is not configured as a source
|
||||
// for wind data) get the value from internal sensors..
|
||||
#ifdef _INTERNAL_AS_BACKUP
|
||||
// .. if they are configured
|
||||
scaled_windspeed = analog_anemometer_get_ms_from_pulse(rte_wx_windspeed_pulses);
|
||||
#endif
|
||||
else if (config_sources->wind == WX_SOURCE_UMB) {
|
||||
rte_wx_average_winddirection = umb_get_winddirection(config_umb);
|
||||
rte_wx_average_windspeed = umb_get_windspeed(config_umb);
|
||||
rte_wx_max_windspeed = umb_get_windgusts(config_umb);
|
||||
}
|
||||
#elif defined(_MODBUS_RTU) && defined(_RTU_SLAVE_WIND_DIRECTION_SORUCE) && defined(_RTU_SLAVE_WIND_SPEED_SOURCE) && defined(_RTU_SLAVE_FULL_WIND_DATA)
|
||||
// get the value from modbus registers
|
||||
modbus_retval = rtu_get_wind_direction(&rte_wx_average_winddirection);
|
||||
|
||||
// check if this value has been processed w/o errors
|
||||
if (modbus_retval == MODBUS_RET_OK || modbus_retval == MODBUS_RET_DEGRADED) {
|
||||
// if yes continue to further processing
|
||||
modbus_retval = rtu_get_wind_gusts(&rte_wx_max_windspeed);
|
||||
modbus_retval = rtu_get_wind_speed(&rte_wx_winddirection_last);
|
||||
else if (config_sources->wind == WX_SOURCE_RTU) {
|
||||
// get the value from modbus registers
|
||||
modbus_retval = rtu_get_wind_speed(&scaled_windspeed, config_rtu);
|
||||
|
||||
// check if this value has been processed w/o errors
|
||||
if (modbus_retval == MODBUS_RET_OK) {
|
||||
// if yes continue to further processing
|
||||
modbus_retval = rtu_get_wind_direction(&rte_wx_winddirection_last, config_rtu);
|
||||
|
||||
}
|
||||
|
||||
// the second IF to check if the return value was the same for wind direction
|
||||
if (modbus_retval == MODBUS_RET_OK || modbus_retval == MODBUS_RET_DEGRADED) {
|
||||
// if the value is not available (like modbus is not configured as a source
|
||||
// for wind data) get the value from internal sensors..
|
||||
#ifdef _INTERNAL_AS_BACKUP
|
||||
// .. if they are configured
|
||||
scaled_windspeed = analog_anemometer_get_ms_from_pulse(rte_wx_windspeed_pulses);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#else
|
||||
//rte_wx_reset_last_measuremenet_timers(RTE_WX_MEASUREMENT_WIND);
|
||||
#endif
|
||||
|
||||
else if (config_sources->wind == WX_SOURCE_FULL_RTU) {
|
||||
// get the value from modbus registers
|
||||
modbus_retval = rtu_get_wind_direction(&rte_wx_average_winddirection, config_rtu);
|
||||
|
||||
#ifndef _RTU_SLAVE_FULL_WIND_DATA
|
||||
// check how many times before the pool function was called
|
||||
if (wx_wind_pool_call_counter < WIND_AVERAGE_LEN) {
|
||||
// if it was called less time than a length of buffers, the average length
|
||||
// needs to be shortened to handle the underrun properly
|
||||
average_ln = (uint8_t)wx_wind_pool_call_counter;
|
||||
// check if this value has been processed w/o errors
|
||||
if (modbus_retval == MODBUS_RET_OK || modbus_retval == MODBUS_RET_DEGRADED) {
|
||||
// if yes continue to further processing
|
||||
modbus_retval = rtu_get_wind_gusts(&rte_wx_max_windspeed, config_rtu);
|
||||
modbus_retval = rtu_get_wind_speed(&rte_wx_winddirection_last, config_rtu);
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
average_ln = WIND_AVERAGE_LEN;
|
||||
;
|
||||
}
|
||||
|
||||
// putting the wind speed into circular buffer
|
||||
rte_wx_windspeed[rte_wx_windspeed_it] = scaled_windspeed;
|
||||
if (config_sources->wind != WX_SOURCE_FULL_RTU) {
|
||||
// check how many times before the pool function was called
|
||||
if (wx_wind_pool_call_counter < WIND_AVERAGE_LEN) {
|
||||
// if it was called less time than a length of buffers, the average length
|
||||
// needs to be shortened to handle the underrun properly
|
||||
average_ln = (uint8_t)wx_wind_pool_call_counter;
|
||||
}
|
||||
else {
|
||||
average_ln = WIND_AVERAGE_LEN;
|
||||
}
|
||||
|
||||
// increasing the iterator to the windspeed buffer
|
||||
rte_wx_windspeed_it++;
|
||||
// putting the wind speed into circular buffer
|
||||
rte_wx_windspeed[rte_wx_windspeed_it] = scaled_windspeed;
|
||||
|
||||
// checking if iterator reached an end of the buffer
|
||||
if (rte_wx_windspeed_it >= WIND_AVERAGE_LEN) {
|
||||
rte_wx_windspeed_it = 0;
|
||||
}
|
||||
// increasing the iterator to the windspeed buffer
|
||||
rte_wx_windspeed_it++;
|
||||
|
||||
// calculating the average windspeed
|
||||
for (i = 0; i < average_ln; i++)
|
||||
average_windspeed += rte_wx_windspeed[i];
|
||||
// checking if iterator reached an end of the buffer
|
||||
if (rte_wx_windspeed_it >= WIND_AVERAGE_LEN) {
|
||||
rte_wx_windspeed_it = 0;
|
||||
}
|
||||
|
||||
average_windspeed /= average_ln;
|
||||
// calculating the average windspeed
|
||||
for (i = 0; i < average_ln; i++)
|
||||
average_windspeed += rte_wx_windspeed[i];
|
||||
|
||||
// store the value in rte
|
||||
rte_wx_average_windspeed = average_windspeed;
|
||||
average_windspeed /= average_ln;
|
||||
|
||||
// reuse the local variable to find maximum value
|
||||
average_windspeed = 0;
|
||||
// store the value in rte
|
||||
rte_wx_average_windspeed = average_windspeed;
|
||||
|
||||
// looking for gusts
|
||||
for (i = 0; i < average_ln; i++) {
|
||||
if (average_windspeed < rte_wx_windspeed[i])
|
||||
average_windspeed = rte_wx_windspeed[i];
|
||||
}
|
||||
// reuse the local variable to find maximum value
|
||||
average_windspeed = 0;
|
||||
|
||||
// storing wind gusts value in rte
|
||||
rte_wx_max_windspeed = average_windspeed;
|
||||
// looking for gusts
|
||||
for (i = 0; i < average_ln; i++) {
|
||||
if (average_windspeed < rte_wx_windspeed[i])
|
||||
average_windspeed = rte_wx_windspeed[i];
|
||||
}
|
||||
|
||||
// adding last wind direction to the buffers
|
||||
if (rte_wx_winddirection_it >= WIND_AVERAGE_LEN)
|
||||
rte_wx_winddirection_it = 0;
|
||||
// storing wind gusts value in rte
|
||||
rte_wx_max_windspeed = average_windspeed;
|
||||
|
||||
rte_wx_winddirection[rte_wx_winddirection_it++] = rte_wx_winddirection_last;
|
||||
// adding last wind direction to the buffers
|
||||
if (rte_wx_winddirection_it >= WIND_AVERAGE_LEN)
|
||||
rte_wx_winddirection_it = 0;
|
||||
|
||||
// calculating average wind direction
|
||||
for (i = 0; i < average_ln; i++) {
|
||||
rte_wx_winddirection[rte_wx_winddirection_it++] = rte_wx_winddirection_last;
|
||||
|
||||
dir_temp = (float)rte_wx_winddirection[i];
|
||||
// calculating average wind direction
|
||||
for (i = 0; i < average_ln; i++) {
|
||||
|
||||
// split the wind direction into x and y component
|
||||
wind_direction_x = (int16_t)(100.0f * cosf(dir_temp * direction_constant));
|
||||
wind_direction_y = (int16_t)(100.0f * sinf(dir_temp * direction_constant));
|
||||
dir_temp = (float)rte_wx_winddirection[i];
|
||||
|
||||
// adding components to calculate average
|
||||
wind_direction_x_avg += wind_direction_x;
|
||||
wind_direction_y_avg += wind_direction_y;
|
||||
// split the wind direction into x and y component
|
||||
wind_direction_x = (int16_t)(100.0f * cosf(dir_temp * direction_constant));
|
||||
wind_direction_y = (int16_t)(100.0f * sinf(dir_temp * direction_constant));
|
||||
|
||||
// adding components to calculate average
|
||||
wind_direction_x_avg += wind_direction_x;
|
||||
wind_direction_y_avg += wind_direction_y;
|
||||
|
||||
}
|
||||
|
||||
// dividing to get average of x and y componen
|
||||
wind_direction_x_avg /= average_ln;
|
||||
wind_direction_y_avg /= average_ln;
|
||||
|
||||
// converting x & y component of wind direction back to an angle
|
||||
arctan_value = atan2f(wind_direction_y_avg , wind_direction_x_avg);
|
||||
|
||||
rte_wx_average_winddirection = (int16_t)(arctan_value * (180.0f/M_PI));
|
||||
|
||||
if (rte_wx_average_winddirection < 0)
|
||||
rte_wx_average_winddirection += 360;
|
||||
|
||||
}
|
||||
|
||||
// dividing to get average of x and y componen
|
||||
wind_direction_x_avg /= average_ln;
|
||||
wind_direction_y_avg /= average_ln;
|
||||
|
||||
// converting x & y component of wind direction back to an angle
|
||||
arctan_value = atan2f(wind_direction_y_avg , wind_direction_x_avg);
|
||||
|
||||
rte_wx_average_winddirection = (int16_t)(arctan_value * (180.0f/M_PI));
|
||||
|
||||
if (rte_wx_average_winddirection < 0)
|
||||
rte_wx_average_winddirection += 360;
|
||||
|
||||
#endif
|
||||
|
||||
#if defined (_MODBUS_RTU) && (defined(_RTU_SLAVE_WIND_DIRECTION_SORUCE) || defined(_RTU_SLAVE_WIND_SPEED_SOURCE) || defined(_RTU_SLAVE_FULL_WIND_DATA))
|
||||
if (modbus_retval == MODBUS_RET_OK) {
|
||||
rte_wx_wind_qf = AN_WIND_QF_FULL;
|
||||
}
|
||||
else if (modbus_retval == MODBUS_RET_DEGRADED) {
|
||||
rte_wx_wind_qf = AN_WIND_QF_DEGRADED;
|
||||
}
|
||||
else if (modbus_retval == MODBUS_RET_NOT_AVALIABLE) {
|
||||
rte_wx_wind_qf = AN_WIND_QF_NOT_AVALIABLE;
|
||||
}
|
||||
else {
|
||||
#ifdef _INTERNAL_AS_BACKUP
|
||||
rte_wx_wind_qf = analog_anemometer_get_qf();
|
||||
#else
|
||||
if (config_sources->wind == WX_SOURCE_FULL_RTU || config_sources->wind != WX_SOURCE_RTU) {
|
||||
if (modbus_retval == MODBUS_RET_OK) {
|
||||
rte_wx_wind_qf = AN_WIND_QF_FULL;
|
||||
}
|
||||
else if (modbus_retval == MODBUS_RET_DEGRADED) {
|
||||
rte_wx_wind_qf = AN_WIND_QF_DEGRADED;
|
||||
}
|
||||
else if (modbus_retval == MODBUS_RET_NOT_AVALIABLE) {
|
||||
rte_wx_wind_qf = AN_WIND_QF_NOT_AVALIABLE;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
if ((config_mode->wx & WX_INTERNAL_AS_BACKUP) != 0)
|
||||
rte_wx_wind_qf = analog_anemometer_get_qf();
|
||||
else
|
||||
rte_wx_wind_qf = AN_WIND_QF_NOT_AVALIABLE;
|
||||
}
|
||||
}
|
||||
else if (config_sources->wind == WX_SOURCE_INTERNAL) {
|
||||
rte_wx_wind_qf = analog_anemometer_get_qf();
|
||||
}
|
||||
else {
|
||||
rte_wx_wind_qf = AN_WIND_QF_UNKNOWN;
|
||||
}
|
||||
#elif defined(_ANEMOMETER_ANALOGUE)
|
||||
rte_wx_wind_qf = analog_anemometer_get_qf();
|
||||
#elif defined(_ANEMOMETER_TX20)
|
||||
;
|
||||
#else
|
||||
rte_wx_wind_qf = AN_WIND_QF_UNKNOWN;
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void wx_pwr_init(void) {
|
||||
|
|
|
@ -122,8 +122,6 @@ int32_t wx_get_pressure_measurement(const config_data_wx_sources_t * const confi
|
|||
int32_t wx_get_pressure_ms5611(float * const pressure) {
|
||||
|
||||
int32_t return_value = 0;
|
||||
int i = 0, j = 0;
|
||||
float pressure_average_sum = 0.0f;
|
||||
|
||||
// quering MS5611 sensor for pressure
|
||||
return_value = ms5611_get_pressure(pressure, &rte_wx_ms5611_qf);
|
||||
|
|
|
@ -13,98 +13,6 @@ typedef struct FIFOBuffer
|
|||
} FIFOBuffer;
|
||||
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static bool fifo_isempty(const FIFOBuffer *fb) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
return fb->head == fb->tail;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static bool fifo_isfull(const FIFOBuffer *fb) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
return ((fb->head == fb->begin) && (fb->tail == fb->end)) || (fb->tail == fb->head - 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static void fifo_push(FIFOBuffer *fb, uint8_t c) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
/* Write at tail position */
|
||||
*(fb->tail) = c;
|
||||
|
||||
if (fb->tail == fb->end)
|
||||
{
|
||||
/* wrap tail around */
|
||||
fb->tail = fb->begin;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Move tail forward */
|
||||
fb->tail++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static uint8_t fifo_pop(FIFOBuffer *fb) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
if (fb->head == fb->end)
|
||||
{
|
||||
/* wrap head around */
|
||||
fb->head = fb->begin;
|
||||
return *(fb->end);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* move head forward */
|
||||
return *(fb->head++);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static void fifo_flush(FIFOBuffer *fb) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
fb->head = fb->tail;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static void fifo_init(FIFOBuffer *fb, uint8_t *buf, uint16_t size) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
fb->head = fb->tail = fb->begin = buf;
|
||||
fb->end = buf + size - 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static int16_t fifo_getc(FIFOBuffer *fb) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
if (!fifo_isempty(fb)) return fifo_pop(fb);
|
||||
else return -1;
|
||||
|
||||
}
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static void fifo_putc(uint8_t c, FIFOBuffer *fb) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
if (!fifo_isfull(fb)) fifo_push(fb, c);
|
||||
|
||||
}
|
||||
|
||||
#endif /* FIFO_H_ */
|
||||
|
|
|
@ -13,6 +13,6 @@
|
|||
|
||||
|
||||
void SendWXFrame(uint16_t windspeed, uint16_t windgusts, uint16_t winddirection, float temperatura, float cisnienie, uint8_t humidity);
|
||||
void SendWXFrameToBuffer(uint16_t windspeed, uint16_t windgusts, uint16_t winddirection, float temperatura, float cisnienie, uint8_t humidity, uint8_t* buffer, uint16_t buffer_ln, int* output_ln);
|
||||
void SendWXFrameToBuffer(uint16_t windspeed, uint16_t windgusts, uint16_t winddirection, float temperatura, float cisnienie, uint8_t humidity, uint8_t* buffer, uint16_t buffer_ln, uint16_t* output_ln);
|
||||
|
||||
#endif /* INCLUDE_APRS_WX_H_ */
|
||||
|
|
|
@ -48,6 +48,82 @@ static const uint8_t sin_table[] = {
|
|||
|
||||
};
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static bool fifo_isempty(const FIFOBuffer *fb) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
return fb->head == fb->tail;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static bool fifo_isfull(const FIFOBuffer *fb) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
return ((fb->head == fb->begin) && (fb->tail == fb->end)) || (fb->tail == fb->head - 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static void fifo_push(FIFOBuffer *fb, uint8_t c) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
/* Write at tail position */
|
||||
*(fb->tail) = c;
|
||||
|
||||
if (fb->tail == fb->end)
|
||||
{
|
||||
/* wrap tail around */
|
||||
fb->tail = fb->begin;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Move tail forward */
|
||||
fb->tail++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static uint8_t fifo_pop(FIFOBuffer *fb) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
if (fb->head == fb->end)
|
||||
{
|
||||
/* wrap head around */
|
||||
fb->head = fb->begin;
|
||||
return *(fb->end);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* move head forward */
|
||||
return *(fb->head++);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static void fifo_flush(FIFOBuffer *fb) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
fb->head = fb->tail;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static void fifo_init(FIFOBuffer *fb, uint8_t *buf, uint16_t size) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
fb->head = fb->tail = fb->begin = buf;
|
||||
fb->end = buf + size - 1;
|
||||
|
||||
}
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static uint8_t sin_sample(uint16_t idx) {
|
||||
/*********************************************************************************************************************/
|
||||
|
|
|
@ -16,6 +16,82 @@
|
|||
AX25Msg ax25_rxed_frame;
|
||||
char ax25_new_msg_rx_flag;
|
||||
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static bool fifo_isempty(const FIFOBuffer *fb) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
return fb->head == fb->tail;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static bool fifo_isfull(const FIFOBuffer *fb) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
return ((fb->head == fb->begin) && (fb->tail == fb->end)) || (fb->tail == fb->head - 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static void fifo_push(FIFOBuffer *fb, uint8_t c) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
/* Write at tail position */
|
||||
*(fb->tail) = c;
|
||||
|
||||
if (fb->tail == fb->end)
|
||||
{
|
||||
/* wrap tail around */
|
||||
fb->tail = fb->begin;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Move tail forward */
|
||||
fb->tail++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static uint8_t fifo_pop(FIFOBuffer *fb) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
if (fb->head == fb->end)
|
||||
{
|
||||
/* wrap head around */
|
||||
fb->head = fb->begin;
|
||||
return *(fb->end);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* move head forward */
|
||||
return *(fb->head++);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static int16_t fifo_getc(FIFOBuffer *fb) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
if (!fifo_isempty(fb)) return fifo_pop(fb);
|
||||
else return -1;
|
||||
|
||||
}
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static void fifo_putc(uint8_t c, FIFOBuffer *fb) {
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
if (!fifo_isfull(fb)) fifo_push(fb, c);
|
||||
|
||||
}
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
static void ax25_decode(AX25Ctx *ctx) {
|
||||
/*********************************************************************************************************************/
|
||||
|
@ -260,7 +336,6 @@ void ax25_sendVia(AX25Ctx *ctx, const AX25Call *path, uint16_t path_len, const v
|
|||
uint16_t ax25_sendVia_toBuffer(const AX25Call *path, uint16_t path_len, const void *payload, uint16_t payload_len, uint8_t* output_buf, uint16_t output_size) {
|
||||
|
||||
uint16_t i;
|
||||
uint8_t crcl,crch;
|
||||
uint16_t crc = CRC_CCITT_INIT_VAL;
|
||||
const uint8_t *buf = (const uint8_t *)payload;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
void beacon_send_own(void) {
|
||||
main_wait_for_tx_complete();
|
||||
main_own_aprs_msg_len = sprintf(main_own_aprs_msg, "=%07.2f%c%c%08.2f%c%c %s", (float)_LAT, _LATNS, _SYMBOL_F, (float)_LON, _LONWE, _SYMBOL_S, _COMMENT);
|
||||
main_own_aprs_msg_len = sprintf(main_own_aprs_msg, "=%s%c%c%s%c%c %s", main_string_latitude, main_config_data_basic->n_or_s, main_symbol_f, main_string_longitude, main_config_data_basic->e_or_w, main_symbol_s, main_config_data_basic->comment);
|
||||
main_own_aprs_msg[main_own_aprs_msg_len] = 0;
|
||||
ax25_sendVia(&main_ax25, main_own_path, main_own_path_ln, main_own_aprs_msg, main_own_aprs_msg_len);
|
||||
after_tx_lock = 1;
|
||||
|
|
|
@ -174,7 +174,7 @@ void telemetry_send_status_pv(ve_direct_average_struct* avg, ve_direct_error_rea
|
|||
ve_direct_state_to_string(state, string_buff_state, 23);
|
||||
ve_direct_error_to_string(*last_error, string_buff_err, 24);
|
||||
|
||||
main_own_aprs_msg_len = snprintf(main_own_aprs_msg, sizeof(main_own_aprs_msg), ">MT %X, MC %X, CMC %X, IMIN %d, IMAX %d, %s, %s", master_time, (uint32_t)messages_count, (uint32_t)corrupted_messages_count, avg->min_battery_current, avg->max_battery_current, string_buff_state, string_buff_err);
|
||||
main_own_aprs_msg_len = snprintf(main_own_aprs_msg, sizeof(main_own_aprs_msg), ">MT %lX, MC %lX, CMC %lX, IMIN %d, IMAX %d, %s, %s", master_time, (uint32_t)messages_count, (uint32_t)corrupted_messages_count, avg->min_battery_current, avg->max_battery_current, string_buff_state, string_buff_err);
|
||||
ax25_sendVia(&main_ax25, main_own_path, main_own_path_ln, main_own_aprs_msg, main_own_aprs_msg_len);
|
||||
afsk_txStart(&main_afsk);
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "station_config.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
void SendWXFrame(uint16_t windspeed, uint16_t windgusts, uint16_t winddirection, float temperatura, float cisnienie, uint8_t humidity) {
|
||||
|
@ -52,7 +53,8 @@ void SendWXFrame(uint16_t windspeed, uint16_t windgusts, uint16_t winddirection,
|
|||
|
||||
memset(main_own_aprs_msg, 0x00, sizeof(main_own_aprs_msg));
|
||||
|
||||
main_own_aprs_msg_len = sprintf(main_own_aprs_msg, "!%07.2f%c%c%08.2f%c%c%03d/%03dg%03dt%03dr...p...P...b%05dh%02d", _LAT, _LATNS, '/', _LON, _LONWE, '_', /* kierunek */direction, /* predkosc*/(int)wind_speed_mph, /* porywy */(short)(wind_gusts_mph), /*temperatura */(short)(temperatura*1.8+32), pressure, humidity);
|
||||
// main_own_aprs_msg_len = sprintf(main_own_aprs_msg, "=%s%c%c%s%c%c %s", main_string_latitude, main_config_data_basic->n_or_s, main_symbol_f, main_string_longitude, main_config_data_basic->e_or_w, main_symbol_s, main_config_data_basic->comment);
|
||||
main_own_aprs_msg_len = sprintf(main_own_aprs_msg, "!%s%c%c%s%c%c%03d/%03dg%03dt%03dr...p...P...b%05ldh%02d", main_string_latitude, main_config_data_basic->n_or_s, '/', main_string_longitude, main_config_data_basic->e_or_w, '_', /* kierunek */direction, /* predkosc*/(int)wind_speed_mph, /* porywy */(short)(wind_gusts_mph), /*temperatura */(short)(temperatura*1.8+32), pressure, humidity);
|
||||
main_own_aprs_msg[main_own_aprs_msg_len] = 0;
|
||||
ax25_sendVia(&main_ax25, main_own_path, main_own_path_ln, main_own_aprs_msg, main_own_aprs_msg_len);
|
||||
after_tx_lock = 1;
|
||||
|
@ -63,7 +65,7 @@ void SendWXFrame(uint16_t windspeed, uint16_t windgusts, uint16_t winddirection,
|
|||
}
|
||||
|
||||
|
||||
void SendWXFrameToBuffer(uint16_t windspeed, uint16_t windgusts, uint16_t winddirection, float temperatura, float cisnienie, uint8_t humidity, uint8_t* buffer, uint16_t buffer_ln, int* output_ln) {
|
||||
void SendWXFrameToBuffer(uint16_t windspeed, uint16_t windgusts, uint16_t winddirection, float temperatura, float cisnienie, uint8_t humidity, uint8_t* buffer, uint16_t buffer_ln, uint16_t* output_ln) {
|
||||
|
||||
uint16_t output_frame_ln = 0;
|
||||
|
||||
|
@ -95,7 +97,7 @@ void SendWXFrameToBuffer(uint16_t windspeed, uint16_t windgusts, uint16_t winddi
|
|||
|
||||
pressure = (unsigned)(cisnienie * 10);
|
||||
|
||||
main_own_aprs_msg_len = sprintf(main_own_aprs_msg, "!%07.2f%c%c%08.2f%c%c%03d/%03dg%03dt%03dr...p...P...b%05dh%02d", _LAT, _LATNS, '/', _LON, _LONWE, '_', /* kierunek */direction, /* predkosc*/(int)wind_speed_mph, /* porywy */(short)(wind_gusts_mph), /*temperatura */(short)(temperatura*1.8+32), pressure, humidity);
|
||||
main_own_aprs_msg_len = sprintf(main_own_aprs_msg, "!%s%c%c%s%c%c%03d/%03dg%03dt%03dr...p...P...b%05ldh%02d", main_string_latitude, main_config_data_basic->n_or_s, '/', main_string_longitude, main_config_data_basic->e_or_w, '_', /* kierunek */direction, /* predkosc*/(int)wind_speed_mph, /* porywy */(short)(wind_gusts_mph), /*temperatura */(short)(temperatura*1.8+32), pressure, humidity);
|
||||
main_own_aprs_msg[main_own_aprs_msg_len] = 0;
|
||||
|
||||
output_frame_ln = ax25_sendVia_toBuffer(main_own_path, main_own_path_ln, main_own_aprs_msg, main_own_aprs_msg_len, buffer, buffer_ln);
|
||||
|
|
|
@ -34,7 +34,7 @@ int32_t rtu_parser_03_04_registers(uint8_t* input, uint16_t input_ln, rtu_regist
|
|||
uint8_t slave_address_from_frame = 0;
|
||||
|
||||
// iterator through input table and registers table
|
||||
int i = 0, j = 3;
|
||||
int j = 3;
|
||||
|
||||
// rewind the input buffer if the first byte is not valid modbus rtu slave address
|
||||
if (*input < 1 || *input > 0xF7) {
|
||||
|
|
|
@ -549,7 +549,7 @@ int32_t rtu_serial_get_status_string(rtu_pool_queue_t* queue, srl_context_t* srl
|
|||
memset(out, 0x00, out_buffer_ln);
|
||||
//#ifdef _MODBUS_RTU
|
||||
|
||||
string_ln = snprintf(out, out_buffer_ln, ">MT %X, LRET %X, LSCT %X, NSSC %X, NSE %X, RXB %X, RXI %X, TXB %X",
|
||||
string_ln = snprintf(out, out_buffer_ln, ">MT %lX, LRET %lX, LSCT %lX, NSSC %X, NSE %X, RXB %lX, RXI %X, TXB %lX",
|
||||
main_get_master_time(),
|
||||
rte_rtu_last_modbus_rx_error_timestamp,
|
||||
rtu_time_of_last_successfull_comm,
|
||||
|
|
Ładowanie…
Reference in New Issue