kopia lustrzana https://github.com/SP8EBC/ParaTNC
davis vantage LOOP packet parser improved
rodzic
99009503b0
commit
10a7fafe30
|
@ -13,8 +13,7 @@ C_SRCS += \
|
|||
../system/src/drivers/i2c.c \
|
||||
../system/src/drivers/ms5611.c \
|
||||
../system/src/drivers/serial.c \
|
||||
../system/src/drivers/tx20.c \
|
||||
../system/src/drivers/user_interf.c
|
||||
../system/src/drivers/tx20.c
|
||||
|
||||
OBJS += \
|
||||
./system/src/drivers/_dht22.o \
|
||||
|
@ -26,8 +25,7 @@ OBJS += \
|
|||
./system/src/drivers/i2c.o \
|
||||
./system/src/drivers/ms5611.o \
|
||||
./system/src/drivers/serial.o \
|
||||
./system/src/drivers/tx20.o \
|
||||
./system/src/drivers/user_interf.o
|
||||
./system/src/drivers/tx20.o
|
||||
|
||||
C_DEPS += \
|
||||
./system/src/drivers/_dht22.d \
|
||||
|
@ -39,8 +37,7 @@ C_DEPS += \
|
|||
./system/src/drivers/i2c.d \
|
||||
./system/src/drivers/ms5611.d \
|
||||
./system/src/drivers/serial.d \
|
||||
./system/src/drivers/tx20.d \
|
||||
./system/src/drivers/user_interf.d
|
||||
./system/src/drivers/tx20.d
|
||||
|
||||
|
||||
# Each subdirectory must supply rules for building sources it contributes
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
#include "aprs/ax25.h"
|
||||
#include "drivers/serial.h"
|
||||
|
||||
#define SW_VER "DF06"
|
||||
#define SW_DATE "02092020"
|
||||
#define SW_VER "DF07"
|
||||
#define SW_DATE "03092020"
|
||||
|
||||
#define SYSTICK_TICKS_PER_SECONDS 100
|
||||
#define SYSTICK_TICKS_PERIOD 10
|
||||
|
|
|
@ -10,17 +10,19 @@
|
|||
#include "drivers/_dht22.h"
|
||||
#include "drivers/dallas.h"
|
||||
#include "drivers/analog_anemometer.h"
|
||||
#include "davis_vantage/davis_qf_t.h"
|
||||
#include "davis_vantage/davis_loop_t.h"
|
||||
#include "umb_master/umb_master.h"
|
||||
#include "umb_master/umb_qf_t.h"
|
||||
|
||||
|
||||
//#ifdef _SENSOR_MS5611
|
||||
#ifdef _SENSOR_MS5611
|
||||
#include "drivers/ms5611.h"
|
||||
//#endif
|
||||
#endif
|
||||
|
||||
//#ifdef _SENSOR_BME280
|
||||
#ifdef _SENSOR_BME280
|
||||
#include "drivers/bme280.h"
|
||||
//#endif
|
||||
#endif
|
||||
|
||||
#ifndef RTE_WX_H_
|
||||
#define RTE_WX_H_
|
||||
|
@ -57,18 +59,16 @@ extern int8_t rte_wx_humidity, rte_wx_humidity_valid;
|
|||
extern uint8_t rte_wx_tx20_excessive_slew_rate;
|
||||
|
||||
extern dht22Values rte_wx_dht, rte_wx_dht_valid;
|
||||
|
||||
extern dallas_qf_t rte_wx_current_dallas_qf, rte_wx_error_dallas_qf;
|
||||
extern dallas_average_t rte_wx_dallas_average;
|
||||
extern analog_wind_qf_t rte_wx_wind_qf;
|
||||
|
||||
//#ifdef _SENSOR_MS5611
|
||||
#ifdef _SENSOR_MS5611
|
||||
extern ms5611_qf_t rte_wx_ms5611_qf;
|
||||
//#endif
|
||||
|
||||
#endif
|
||||
#ifdef _SENSOR_BME280
|
||||
extern bme280_qf_t rte_wx_bme280_qf;
|
||||
#endif
|
||||
extern analog_wind_qf_t rte_wx_wind_qf;
|
||||
|
||||
|
||||
#ifdef _UMB_MASTER
|
||||
|
||||
|
@ -80,6 +80,10 @@ extern int16_t rte_wx_umb_channel_values[UMB_CHANNELS_STORAGE_CAPAC][2];
|
|||
#endif
|
||||
extern umb_qf_t rte_wx_umb_qf;
|
||||
|
||||
extern uint8_t rte_wx_davis_station_avaliable;
|
||||
extern uint8_t rte_wx_davis_loop_packet_avaliable;
|
||||
extern davis_loop_t rte_wx_davis_loop_content;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
|
|
101
src/main.c
101
src/main.c
|
@ -62,7 +62,7 @@
|
|||
#include "umb_master/umb_0x26_status.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif // _METEO
|
||||
|
||||
#ifdef _DALLAS_AS_TELEM
|
||||
#include "drivers/dallas.h"
|
||||
|
@ -133,6 +133,12 @@ uint32_t main_target_kiss_baudrate;
|
|||
// target USART2 (wx) baudrate
|
||||
uint32_t main_target_wx_baudrate;
|
||||
|
||||
// controls if the KISS modem is enabled
|
||||
uint8_t main_kiss_enabled = 1;
|
||||
|
||||
// controls if DAVIS serialprotocol client is enabled by the configuration
|
||||
uint8_t main_davis_serial_enabled = 0;
|
||||
|
||||
// global variables represending the AX25/APRS stack
|
||||
AX25Ctx main_ax25;
|
||||
Afsk main_afsk;
|
||||
|
@ -293,23 +299,54 @@ int main(int argc, char* argv[]){
|
|||
main_wx_srl_ctx_ptr->te_port = GPIOA;
|
||||
#endif
|
||||
|
||||
//#if (defined(PARATNC_HWREV_B) || defined(PARATNC_HWREV_C)) && defined(_DAVIS_SERIAL)
|
||||
// // reinitialize the KISS serial port temporary to davis baudrate
|
||||
// main_target_kiss_baudrate = DAVIS_DEFAULT_BAUDRATE;
|
||||
//
|
||||
// // reset RX state to allow reinitialization with changed baudrate
|
||||
// main_kiss_srl_ctx_ptr->srl_rx_state = SRL_RX_NOT_CONFIG;
|
||||
//
|
||||
// // reinitializing serial hardware
|
||||
// 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);
|
||||
//
|
||||
// srl_switch_timeout(main_kiss_srl_ctx_ptr, SRL_TIMEOUT_ENABLE, 1500);
|
||||
//
|
||||
// davis_init(main_kiss_srl_ctx_ptr);
|
||||
//
|
||||
// davis_wake_up(1);
|
||||
//
|
||||
//#endif
|
||||
#if (defined(PARATNC_HWREV_B) || defined(PARATNC_HWREV_C)) && defined(_DAVIS_SERIAL)
|
||||
// reinitialize the KISS serial port temporary to davis baudrate
|
||||
main_target_kiss_baudrate = DAVIS_DEFAULT_BAUDRATE;
|
||||
|
||||
// reset RX state to allow reinitialization with changed baudrate
|
||||
main_kiss_srl_ctx_ptr->srl_rx_state = SRL_RX_NOT_CONFIG;
|
||||
|
||||
// reinitializing serial hardware to wake up Davis wx station
|
||||
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);
|
||||
|
||||
srl_switch_timeout(main_kiss_srl_ctx_ptr, SRL_TIMEOUT_ENABLE, 3000);
|
||||
|
||||
davis_init(main_kiss_srl_ctx_ptr);
|
||||
|
||||
// try to wake up the davis base
|
||||
rte_wx_davis_station_avaliable = (davis_wake_up(DAVIS_BLOCKING_IO) == 0 ? 1 : 0);
|
||||
|
||||
// if davis weather stations is connected to SERIAL port
|
||||
if (rte_wx_davis_station_avaliable == 1) {
|
||||
// turn LCD backlight on..
|
||||
davis_control_backlight(1);
|
||||
|
||||
// wait for a while
|
||||
delay_fixed(1000);
|
||||
|
||||
// and then off to let the user know that communication is working
|
||||
davis_control_backlight(0);
|
||||
|
||||
// disable the KISS modem as the UART will be used for DAVIS wx station
|
||||
main_kiss_enabled = 0;
|
||||
|
||||
// enable the davis serial protocol client to allow pooling callbacks to be called in main loop.
|
||||
// This only controls the callback it doesn't mean that the station itself is responding to
|
||||
// communication. It stays set to one event if Davis station
|
||||
main_davis_serial_enabled = 1;
|
||||
|
||||
davis_trigger_loop_packet();
|
||||
|
||||
}
|
||||
else {
|
||||
// if not revert back to KISS configuration
|
||||
main_target_kiss_baudrate = 9600u;
|
||||
main_kiss_srl_ctx_ptr->srl_rx_state = SRL_RX_NOT_CONFIG;
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// configuring an APRS path used to transmit own packets (telemetry, wx, beacons)
|
||||
|
@ -545,8 +582,10 @@ int main(int argc, char* argv[]){
|
|||
if(ax25_new_msg_rx_flag == 1) {
|
||||
memset(srl_usart1_tx_buffer, 0x00, sizeof(srl_usart1_tx_buffer));
|
||||
|
||||
// convert message to kiss format and send it to host
|
||||
srl_start_tx(main_kiss_srl_ctx_ptr, SendKISSToHost(ax25_rxed_frame.raw_data, (ax25_rxed_frame.raw_msg_len - 2), srl_usart1_tx_buffer, TX_BUFFER_1_LN));
|
||||
if (main_kiss_enabled == 1) {
|
||||
// convert message to kiss format and send it to host
|
||||
srl_start_tx(main_kiss_srl_ctx_ptr, SendKISSToHost(ax25_rxed_frame.raw_data, (ax25_rxed_frame.raw_msg_len - 2), srl_usart1_tx_buffer, TX_BUFFER_1_LN));
|
||||
}
|
||||
|
||||
main_ax25.dcd = false;
|
||||
#ifdef _DBG_TRACE
|
||||
|
@ -605,7 +644,7 @@ int main(int argc, char* argv[]){
|
|||
}
|
||||
#else
|
||||
// if new KISS message has been received from the host
|
||||
if (main_kiss_srl_ctx_ptr->srl_rx_state == SRL_RX_DONE) {
|
||||
if (main_kiss_srl_ctx_ptr->srl_rx_state == SRL_RX_DONE && main_kiss_enabled == 1) {
|
||||
// parse incoming data and then transmit on radio freq
|
||||
short res = ParseReceivedKISS(srl_get_rx_buffer(main_kiss_srl_ctx_ptr), srl_get_num_bytes_rxed(main_kiss_srl_ctx_ptr), &main_ax25, &main_afsk);
|
||||
if (res == 0)
|
||||
|
@ -616,11 +655,18 @@ int main(int argc, char* argv[]){
|
|||
}
|
||||
|
||||
// if there were an error during receiving frame from host, restart rxing once again
|
||||
if (main_kiss_srl_ctx_ptr->srl_rx_state == SRL_RX_ERROR) {
|
||||
if (main_kiss_srl_ctx_ptr->srl_rx_state == SRL_RX_ERROR && main_kiss_enabled == 1) {
|
||||
srl_receive_data(main_kiss_srl_ctx_ptr, 120, FEND, FEND, 0, 0, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
// if Davis wx station is enabled and it is alive
|
||||
if (main_davis_serial_enabled == 1) {
|
||||
|
||||
// pool the Davis wx station driver for LOOP packet
|
||||
davis_loop_packet_pooler(&rte_wx_davis_loop_packet_avaliable);
|
||||
}
|
||||
|
||||
// get all meteo measuremenets each 65 seconds. some values may not be
|
||||
// downloaded from sensors if _METEO and/or _DALLAS_AS_TELEM aren't defined
|
||||
if (main_wx_sensors_pool_timer < 10) {
|
||||
|
@ -683,6 +729,17 @@ int main(int argc, char* argv[]){
|
|||
|
||||
wx_pool_anemometer();
|
||||
|
||||
if (main_davis_serial_enabled == 1) {
|
||||
|
||||
// if previous LOOP packet is ready for processing
|
||||
if (rte_wx_davis_loop_packet_avaliable == 1) {
|
||||
davis_parsers_loop(main_kiss_srl_ctx_ptr->srl_rx_buf_pointer, main_kiss_srl_ctx_ptr->srl_rx_buf_ln, &rte_wx_davis_loop_content);
|
||||
}
|
||||
|
||||
// trigger consecutive LOOP packet
|
||||
davis_trigger_loop_packet();
|
||||
}
|
||||
|
||||
main_ten_second_pool_timer = 10000;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#include "packet_tx_handler.h"
|
||||
#include "station_config.h"
|
||||
#include "rte_wx.h"
|
||||
#include "rte_pv.h"
|
||||
|
@ -143,6 +142,7 @@ void packet_tx_handler(void) {
|
|||
rte_wx_current_dallas_qf = DALLAS_QF_UNKNOWN;
|
||||
}
|
||||
|
||||
#if defined(_SENSOR_MS5611) // some metaprogramming to save RAM
|
||||
// pressure sensors quality factors
|
||||
if (rte_wx_ms5611_qf == MS5611_QF_UNKNOWN) {
|
||||
// use BME280 is used instead
|
||||
|
@ -165,6 +165,7 @@ void packet_tx_handler(void) {
|
|||
}
|
||||
}
|
||||
|
||||
#elif defined(_SENSOR_BME280)
|
||||
// humidity sensors quality factors
|
||||
if (rte_wx_bme280_qf == BME280_QF_UKNOWN) {
|
||||
// use DHT22
|
||||
|
@ -186,6 +187,10 @@ void packet_tx_handler(void) {
|
|||
case BME280_QF_GEN_DEGRADED: humidity_qf = HUMIDITY_QF_DEGRADATED; break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
pressure_qf = PRESSURE_QF_NOT_AVALIABLE;
|
||||
humidity_qf = HUMIDITY_QF_NOT_AVALIABLE;
|
||||
#endif
|
||||
|
||||
// wind quality factor
|
||||
if (rte_wx_wind_qf == AN_WIND_QF_UNKNOWN) {
|
||||
|
|
|
@ -36,10 +36,19 @@ uint8_t rte_wx_tx20_excessive_slew_rate = 0;
|
|||
dht22Values rte_wx_dht, rte_wx_dht_valid; // quality factor inside this structure
|
||||
dallas_qf_t rte_wx_current_dallas_qf, rte_wx_error_dallas_qf = DALLAS_QF_UNKNOWN;
|
||||
dallas_average_t rte_wx_dallas_average;
|
||||
#ifdef _SENSOR_MS5611
|
||||
ms5611_qf_t rte_wx_ms5611_qf = MS5611_QF_UNKNOWN;
|
||||
#endif
|
||||
#ifdef _SENSOR_BME280
|
||||
bme280_qf_t rte_wx_bme280_qf = BME280_QF_UKNOWN;
|
||||
#endif
|
||||
analog_wind_qf_t rte_wx_wind_qf = AN_WIND_QF_UNKNOWN;
|
||||
|
||||
uint8_t rte_wx_davis_station_avaliable = 0;
|
||||
uint8_t rte_wx_davis_loop_packet_avaliable = 0;
|
||||
davis_loop_t rte_wx_davis_loop_content;
|
||||
|
||||
|
||||
#ifdef _UMB_MASTER
|
||||
umb_frame_t rte_wx_umb;
|
||||
umb_context_t rte_wx_umb_context;
|
||||
|
|
|
@ -10,14 +10,22 @@
|
|||
|
||||
#include "drivers/serial.h"
|
||||
|
||||
#include "davis_retval_def.h"
|
||||
#include <davis_vantage/davis_retval_def.h>
|
||||
#include <davis_vantage/davis_qf_t.h>
|
||||
|
||||
|
||||
#define DAVIS_DEFAULT_BAUDRATE 19200u
|
||||
|
||||
#define DAVIS_BLOCKING_IO 1
|
||||
|
||||
extern davis_qf_t davis_quality_factor;
|
||||
extern uint8_t davis_avaliable;
|
||||
|
||||
uint32_t davis_init(srl_context_t* srl_port);
|
||||
uint32_t davis_wake_up(uint8_t is_io_blocking);
|
||||
uint32_t davis_do_test(void);
|
||||
uint32_t davis_query_for_loop_packet(void);
|
||||
uint32_t davis_loop_packet_pooler(uint8_t* loop_avaliable_flag);
|
||||
uint32_t davis_trigger_loop_packet(void);
|
||||
uint32_t davis_leave_receiving_screen(void);
|
||||
uint32_t davis_control_backlight(uint8_t state);
|
||||
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
|
||||
#include "davis_loop_t.h"
|
||||
|
||||
#define DAVIS_PARSERS_OK 0
|
||||
#define DAVIS_PARSERS_TOO_SHORT_FRAME -1
|
||||
#define DAVIS_PARSERS_CORRUPTED_CRC -2
|
||||
#define DAVIS_PARSERS_WRONG_CONTENT -3
|
||||
|
||||
uint32_t davis_parsers_loop(uint8_t* input, uint16_t input_ln, davis_loop_t* output);
|
||||
uint32_t davis_parsers_check_crc(uint8_t* input, uint16_t input_ln);
|
||||
|
|
|
@ -96,9 +96,6 @@ typedef struct srl_context_t {
|
|||
#define SRL_WRONG_PARAMS_COMBINATION 4
|
||||
#define SRL_TIMEOUT 5
|
||||
|
||||
//extern srl_rx_state_t srl_rx_state;
|
||||
//extern srl_tx_state_t srl_tx_state;
|
||||
//extern uint8_t srl_usart1_tx_buffer[TX_BUFFER_1_LN];
|
||||
#ifdef SEPARATE_TX_BUFF
|
||||
extern uint8_t srl_usart1_tx_buffer[TX_BUFFER_1_LN];
|
||||
#endif
|
||||
|
|
|
@ -1,104 +0,0 @@
|
|||
#ifndef __USER_INTERF_H
|
||||
#define __USER_INTERF_H
|
||||
|
||||
#ifndef __USER_INTERF
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stm32f10x.h>
|
||||
#include "locale.h"
|
||||
|
||||
int ascii[] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39 };
|
||||
int key;
|
||||
|
||||
int FlightStatsC = 8;
|
||||
int MainMenuC = 2;
|
||||
|
||||
|
||||
// definicje napis<69>w wy<77>wietlacza
|
||||
char* AirTimeLine = "AIRTIME: s";
|
||||
char* Alti1Line = "ALTI1: m";
|
||||
char* Alti2Line = "ALTI2: m";
|
||||
char* VarioLine = "VARIO: m/s";
|
||||
char* MaxClimbingLine = "MAX CLMB: ";
|
||||
char* MaxDescendingLine = "MAX DSCND: ";
|
||||
char* VarioAvgLine = "VARIO AVG: ";
|
||||
char* VarioGraphLine = " ";
|
||||
char* MaxAltGain = "MxAltS: m";
|
||||
char* NullLineS = " ";
|
||||
|
||||
char* testing1 = "TEMP: oC"; // 11
|
||||
char* testing2 = "BARO: hPa"; // 13
|
||||
char* testing3 = "ALTI: m"; // 13
|
||||
char* testing4 = "VARIO: m/s"; // 13
|
||||
|
||||
|
||||
// definicje tablic char<61>w kt<6B>re zawieraj<61> wzorki u<>o<EFBFBD>one z kratek do wy<77>wietlania
|
||||
// jako bargraf wariometru
|
||||
char* Bargraph1h = "# ";
|
||||
char* Bargraph2h = "## ";
|
||||
char* Bargraph3h = "### ";
|
||||
char* Bargraph4h = "#### ";
|
||||
char* Bargraph5h = "##### ";
|
||||
char* Bargraph6h = "###### ";
|
||||
char* Bargraph7h = "####### ";
|
||||
char* Bargraph8h = "########";
|
||||
char* Bargraph9h = " #######";
|
||||
char* Bargraph10h= " ######";
|
||||
char* Bargraph11h= " #####";
|
||||
char* Bargraph12h= " ####";
|
||||
char* Bargraph13h= " ###";
|
||||
char* Bargraph14h= " ##";
|
||||
char* Bargraph15h= " #";
|
||||
char* Bargraph16h= " ";
|
||||
|
||||
char* Bargraphc= "-";
|
||||
|
||||
int j = 0; // do cel<65>w testowych
|
||||
|
||||
struct FlightData {
|
||||
// definicja struktury u<>ywanej do zapisu parametr<74>w lotu do pami<6D>ci flash
|
||||
float MaxSink;
|
||||
float MaxClimbing;
|
||||
float MaxAltiGain;
|
||||
float BestThermalHeigh;
|
||||
int FlightTime;
|
||||
float StartAltitude;
|
||||
float LandingAltitude;
|
||||
};
|
||||
|
||||
|
||||
void Delay1ms(void);
|
||||
void Delay10ms(void);
|
||||
void FixString(char* input, int len);
|
||||
|
||||
#define __SERIAL
|
||||
#include "drivers/serial.h"
|
||||
//extern void SrlSendData(char* data);
|
||||
//extern int SrlTXing;
|
||||
|
||||
//#define __FLASH
|
||||
//#include "drivers/flash.h"
|
||||
|
||||
//void FlightStats(struct FlightData lot);
|
||||
|
||||
char sss[10];
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __USER_INTERF
|
||||
|
||||
extern int GetCodeFromDigit(int input);
|
||||
extern void int2string(int input, char* output);
|
||||
extern void float2string(float input, char* output, int accur);
|
||||
extern void MainScreen(float vario, float alti, int fltime, int settings);
|
||||
extern void TableCpy(int* copy_from, int* copy_to);
|
||||
extern void Delay1ms(void);
|
||||
extern void Delay10ms(void);
|
||||
extern void FixString(char* input, int len);
|
||||
extern void FlightStats(struct FlightData lot);
|
||||
extern void MainMenu(void);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#define DAVIS_ACK 0x06
|
||||
|
||||
#define LOOP_PACKET_LN 99
|
||||
#define LOOP_PACKET_LN 100
|
||||
|
||||
/**
|
||||
* Serial port context to be used for communication
|
||||
|
@ -41,12 +41,6 @@ davis_qf_t davis_quality_factor;
|
|||
*/
|
||||
uint8_t davis_avaliable;
|
||||
|
||||
/**
|
||||
* Set to one if new loop packet is available for parsing. Cleared
|
||||
* to zero after the 'davis_parsers_loop' is called
|
||||
*
|
||||
*/
|
||||
uint8_t davis_loop_avaliable;
|
||||
|
||||
static const char line_feed = '\n';
|
||||
static const char line_feed_return[] = {'\n', '\r'};
|
||||
|
@ -68,8 +62,6 @@ uint32_t davis_init(srl_context_t* srl_port) {
|
|||
|
||||
davis_avaliable = 0;
|
||||
|
||||
davis_loop_avaliable = 0;
|
||||
|
||||
// set the timeout according to davis vantage documentation
|
||||
srl_switch_timeout(srl_port, 1, 1200);
|
||||
|
||||
|
@ -138,6 +130,8 @@ uint32_t davis_wake_up(uint8_t is_io_blocking) {
|
|||
else {
|
||||
// if not the station is dead an
|
||||
davis_quality_factor = DAVIS_QF_NOT_AVALIABLE;
|
||||
|
||||
retval = DAVIS_NOT_AVALIABLE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,7 +208,7 @@ uint32_t davis_do_test(void) {
|
|||
return retval;
|
||||
}
|
||||
|
||||
uint32_t davis_query_for_loop_packet(void) {
|
||||
uint32_t davis_loop_packet_pooler(uint8_t* loop_avaliable_flag) {
|
||||
|
||||
uint32_t retval = DAVIS_OK;
|
||||
|
||||
|
@ -232,6 +226,8 @@ uint32_t davis_query_for_loop_packet(void) {
|
|||
// send the LOOP query
|
||||
srl_send_data(davis_serial_context, (uint8_t*)loop_command, 1, 7, 0);
|
||||
|
||||
*loop_avaliable_flag = 0;
|
||||
|
||||
davis_loop_state = DAVIS_QUERY_SENDING_QUERY;
|
||||
}
|
||||
|
||||
|
@ -242,10 +238,10 @@ uint32_t davis_query_for_loop_packet(void) {
|
|||
// if transmission was successful
|
||||
if (davis_serial_context->srl_tx_state == SRL_TX_IDLE) {
|
||||
// trigger the reception of ACK message
|
||||
srl_receive_data(davis_serial_context, 1, 0, 0, 0, 0, 0);
|
||||
srl_receive_data(davis_serial_context, LOOP_PACKET_LN, 0, 0, 0, 0, 0);
|
||||
|
||||
// switching the internal state
|
||||
davis_loop_state = DAVIS_QUERY_RECEIVING_ACK;
|
||||
davis_loop_state = DAVIS_QUERY_RECEIVING;
|
||||
}
|
||||
|
||||
if (davis_serial_context->srl_tx_state == SRL_TX_ERROR) {
|
||||
|
@ -254,32 +250,10 @@ uint32_t davis_query_for_loop_packet(void) {
|
|||
|
||||
break;
|
||||
}
|
||||
case DAVIS_QUERY_RECEIVING_ACK: {
|
||||
|
||||
if (davis_serial_context->srl_rx_state == SRL_RX_DONE) {
|
||||
|
||||
// if the davis station responded with an ACK
|
||||
if (davis_serial_context->srl_rx_buf_pointer[0] == DAVIS_ACK) {
|
||||
// trigger the reception of target LOOP packet
|
||||
srl_receive_data(davis_serial_context, LOOP_PACKET_LN, 0, 0, 0, 0, 0);
|
||||
|
||||
// and switch the state machine
|
||||
davis_loop_state = DAVIS_QUERY_RECEIVING;
|
||||
}
|
||||
else {
|
||||
davis_loop_state = DAVIS_QUERY_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
else if (davis_serial_context->srl_rx_state == SRL_RX_ERROR) {
|
||||
davis_loop_state = DAVIS_QUERY_ERROR;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case DAVIS_QUERY_RECEIVING: {
|
||||
if (davis_serial_context->srl_rx_state == SRL_RX_DONE) {
|
||||
davis_loop_avaliable = 0;
|
||||
// parse the loop packet
|
||||
*loop_avaliable_flag = 1;
|
||||
}
|
||||
else if (davis_serial_context->srl_rx_state == SRL_RX_ERROR) {
|
||||
davis_loop_state = DAVIS_QUERY_ERROR;
|
||||
|
@ -292,13 +266,31 @@ uint32_t davis_query_for_loop_packet(void) {
|
|||
break;
|
||||
}
|
||||
case DAVIS_QUERY_ERROR: {
|
||||
// clear data availability flag
|
||||
*loop_avaliable_flag = 0;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
davis_loop_state = DAVIS_QUERY_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/** This function will be called from the for(;;) loop in main.c every
|
||||
* ten seconds to trigger the pooler to query for next 'LOOP' packet
|
||||
*
|
||||
*/
|
||||
uint32_t davis_trigger_loop_packet(void) {
|
||||
|
||||
uint32_t retval = DAVIS_OK;
|
||||
|
||||
davis_loop_state = DAVIS_QUERY_IDLE;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
uint32_t davis_leave_receiving_screen(void) {
|
||||
|
||||
uint32_t retval = DAVIS_OK;
|
||||
|
|
|
@ -36,7 +36,7 @@ const uint16_t crc_table [] = {
|
|||
0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
|
||||
0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x8e1, 0x3882, 0x28a3,
|
||||
0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
|
||||
0x4a75, 0x5a54, 0x6a37, 0x7a16, 0xaf1, 0x1ad0, 0x2ab3, 0x3a92,
|
||||
0x4a75, 0x5a54, 0x6a37, 0x7a16, 0xaf1, 0x1ad0, 0x2ab3, 0x3a92,
|
||||
0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
|
||||
0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0xcc1,
|
||||
0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
|
||||
|
@ -45,7 +45,7 @@ const uint16_t crc_table [] = {
|
|||
|
||||
#define LOOP_PACAKET_LN 99
|
||||
|
||||
#define LOOP_CRC_OFFSET 97
|
||||
#define LOOP_CRC_OFFSET 0x61
|
||||
#define LOOP_BAROMETER_OFFSET 7
|
||||
#define LOOP_INSIDE_TEMPERATURE_OFFSET 9
|
||||
#define LOOP_OUTSIDE_TEMPERATURE 12
|
||||
|
@ -57,7 +57,7 @@ const uint16_t crc_table [] = {
|
|||
|
||||
uint32_t davis_parsers_loop(uint8_t* input, uint16_t input_ln, davis_loop_t* output) {
|
||||
|
||||
uint32_t retval = 0;
|
||||
uint32_t retval = DAVIS_PARSERS_OK;
|
||||
|
||||
// crc stored in the frame
|
||||
uint16_t crc_from_frame = 0;
|
||||
|
@ -72,37 +72,55 @@ uint32_t davis_parsers_loop(uint8_t* input, uint16_t input_ln, davis_loop_t* out
|
|||
retval = DAVIS_PARSERS_TOO_SHORT_FRAME;
|
||||
}
|
||||
else {
|
||||
// retrieve the CRC value from the frame content
|
||||
crc_from_frame = *(input + LOOP_CRC_OFFSET) | *(input + LOOP_CRC_OFFSET + 1);
|
||||
|
||||
// calculate the CRC locally excluding the last 2 bytes which consists the CRC value
|
||||
calculated_crc = davis_parsers_check_crc(input, LOOP_PACAKET_LN - 2);
|
||||
|
||||
// check if calculated CRC is the same as recevied from the sation
|
||||
if (calculated_crc == crc_from_frame) {
|
||||
// continue only if both CRC matches
|
||||
|
||||
// fetch the pressure
|
||||
output->barometer = *(input + LOOP_BAROMETER_OFFSET) | *(input + LOOP_BAROMETER_OFFSET + 1);
|
||||
|
||||
output->inside_temperature = *(input + LOOP_INSIDE_TEMPERATURE_OFFSET) | *(input + LOOP_INSIDE_TEMPERATURE_OFFSET + 1);
|
||||
|
||||
output->outside_temperature = *(input + LOOP_INSIDE_TEMPERATURE_OFFSET) | *(input + LOOP_INSIDE_TEMPERATURE_OFFSET + 1);
|
||||
|
||||
output->wind_speed = *(input + LOOP_WINDSPEED_OFFSET);
|
||||
|
||||
output->wind_speed_10min_average = *(input + LOOP_TEN_MIN_WINDSPEED_OFFSET);
|
||||
|
||||
output->wind_direction = *(input + LOOP_WIND_DIRECTION_OFFSET);
|
||||
|
||||
output->outside_humidity = *(input + LOOP_OUTSIDE_HUMIDITY);
|
||||
|
||||
output->day_rain = *(input + LOOP_DAY_RAIN_OFFSET);
|
||||
|
||||
// check if first character in the buffer is ACK (0x06) send for the LOOP packet
|
||||
if (*input == 0x06) {
|
||||
// if yes rewind the buffer to the next character
|
||||
input += 1;
|
||||
}
|
||||
else if (*input == 'L') {
|
||||
retval = DAVIS_PARSERS_OK;
|
||||
}
|
||||
else {
|
||||
// if CRCs differs treat the frame as corrupted and
|
||||
retval = DAVIS_PARSERS_CORRUPTED_CRC;
|
||||
// correct LOOP packet shall start from either 0x06 (if it is glued
|
||||
// to ACK) or 'L'. If it starts from something else it means that
|
||||
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);
|
||||
|
||||
// check if calculated CRC is the same as recevied from the sation
|
||||
if (calculated_crc == crc_from_frame) {
|
||||
// continue only if both CRC matches
|
||||
|
||||
// fetch the pressure
|
||||
output->barometer = *(input + LOOP_BAROMETER_OFFSET) | *(input + LOOP_BAROMETER_OFFSET + 1);
|
||||
|
||||
output->inside_temperature = *(input + LOOP_INSIDE_TEMPERATURE_OFFSET) | *(input + LOOP_INSIDE_TEMPERATURE_OFFSET + 1);
|
||||
|
||||
output->outside_temperature = *(input + LOOP_INSIDE_TEMPERATURE_OFFSET) | *(input + LOOP_INSIDE_TEMPERATURE_OFFSET + 1);
|
||||
|
||||
output->wind_speed = *(input + LOOP_WINDSPEED_OFFSET);
|
||||
|
||||
output->wind_speed_10min_average = *(input + LOOP_TEN_MIN_WINDSPEED_OFFSET);
|
||||
|
||||
output->wind_direction = *(input + LOOP_WIND_DIRECTION_OFFSET);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -273,6 +273,7 @@ uint8_t srl_receive_data(srl_context_t *ctx, int num, char start, char stop, cha
|
|||
}
|
||||
else {
|
||||
ctx->srl_triggered_start = 0;
|
||||
ctx->srl_start_trigger = 0;
|
||||
}
|
||||
|
||||
if (stop != 0x00) {
|
||||
|
@ -281,6 +282,7 @@ uint8_t srl_receive_data(srl_context_t *ctx, int num, char start, char stop, cha
|
|||
}
|
||||
else {
|
||||
ctx->srl_triggered_stop = 0;
|
||||
ctx->srl_stop_trigger = 0;
|
||||
}
|
||||
|
||||
if (ctx->srl_triggered_start == 1 || ctx->srl_triggered_stop == 1) {
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
#include "drivers/user_interf.h"
|
||||
|
||||
|
||||
//void FixString(char* input, int len) {
|
||||
// // funkcja ma usuwa<77> zb<7A>dne znaczniki ko<6B>ca ci<63>gu powsta<74>e po funkcji strcpy
|
||||
// // zamienia wszystkie naporkane przed ko<6B>cem znaki /0 na spacj<63>
|
||||
// int i = 1;
|
||||
// for(i; (i<32 && i<len); i++) {
|
||||
// if(*(input+i) == '\0' && i != (len+1) )
|
||||
// *(input+i) = 0x20;
|
||||
// *(input+len) = '\0';
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
void Delay1ms(void) {
|
||||
int i;
|
||||
for (i = 0; i<0x3E5; i++);
|
||||
}
|
||||
|
||||
void Delay10ms(void) {
|
||||
int i;
|
||||
for (i = 0; i<0x3E50; i++);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Ładowanie…
Reference in New Issue