2019-01-26 22:18:25 +00:00
|
|
|
#include <delay.h>
|
|
|
|
#include <LedConfig.h>
|
2017-08-20 12:41:17 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stm32f10x_rcc.h>
|
2019-01-23 21:18:05 +00:00
|
|
|
#include <stm32f10x.h>
|
2017-08-20 12:41:17 +00:00
|
|
|
|
|
|
|
#include "main.h"
|
2019-01-27 13:23:20 +00:00
|
|
|
#include "packet_tx_handler.h"
|
2017-08-20 12:41:17 +00:00
|
|
|
#include "station_config.h"
|
|
|
|
|
|
|
|
#include "diag/Trace.h"
|
|
|
|
#include "antilib_adc.h"
|
|
|
|
#include "afsk_pr.h"
|
|
|
|
#include "drivers/serial.h"
|
|
|
|
#include "TimerConfig.h"
|
|
|
|
#include "PathConfig.h"
|
|
|
|
|
2019-01-27 13:23:20 +00:00
|
|
|
#include "it_handlers.h"
|
|
|
|
|
2017-08-20 12:41:17 +00:00
|
|
|
#include "aprs/digi.h"
|
|
|
|
#include "aprs/telemetry.h"
|
|
|
|
#include "aprs/dac.h"
|
|
|
|
#include "aprs/beacon.h"
|
|
|
|
|
2019-04-03 09:41:37 +00:00
|
|
|
#ifdef _VICTRON
|
|
|
|
#include "ve_direct_protocol/parser.h"
|
|
|
|
#endif
|
|
|
|
|
2019-01-26 22:18:25 +00:00
|
|
|
#include "rte_wx.h"
|
2019-04-03 09:41:37 +00:00
|
|
|
#include "rte_pv.h"
|
2019-04-16 21:33:41 +00:00
|
|
|
#include "rte_main.h"
|
2017-08-20 12:41:17 +00:00
|
|
|
|
|
|
|
#ifdef _METEO
|
2019-01-26 22:18:25 +00:00
|
|
|
#include <wx_handler.h>
|
2017-08-20 12:41:17 +00:00
|
|
|
#include "drivers/dallas.h"
|
|
|
|
#include "drivers/ms5611.h"
|
|
|
|
#include "drivers/i2c.h"
|
|
|
|
#include "drivers/tx20.h"
|
2019-12-26 19:55:47 +00:00
|
|
|
#include "drivers/analog_anemometer.h"
|
2017-08-20 12:41:17 +00:00
|
|
|
#include "aprs/wx.h"
|
2020-04-04 21:09:00 +00:00
|
|
|
#include "drivers/gpio_conf.h"
|
2020-03-21 16:46:16 +00:00
|
|
|
|
|
|
|
#ifdef _UMB_MASTER
|
|
|
|
#include "umb_master/umb_master.h"
|
|
|
|
#include "umb_master/umb_channel_pool.h"
|
|
|
|
#include "umb_master/umb_0x26_status.h"
|
|
|
|
#endif
|
|
|
|
|
2017-08-20 12:41:17 +00:00
|
|
|
#endif
|
|
|
|
|
2018-05-11 19:54:27 +00:00
|
|
|
#ifdef _DALLAS_AS_TELEM
|
|
|
|
#include "drivers/dallas.h"
|
|
|
|
#endif
|
|
|
|
|
2017-08-20 12:41:17 +00:00
|
|
|
#include "KissCommunication.h"
|
|
|
|
|
2020-02-23 17:22:37 +00:00
|
|
|
#define SOH 0x01
|
|
|
|
|
2020-03-18 20:56:02 +00:00
|
|
|
//#define SERIAL_TX_TEST_MODE
|
2017-08-20 12:41:17 +00:00
|
|
|
|
|
|
|
// Niebieska dioda -> DCD
|
|
|
|
// Zielona dioda -> anemometr albo TX
|
|
|
|
|
2019-04-16 21:33:41 +00:00
|
|
|
// backup registers
|
|
|
|
// 2 -> 4bit hard-faults | 4bit boot-counter
|
|
|
|
// 3 -> hard fault PC LSB
|
|
|
|
// 4 -> hard fault PC MSB
|
|
|
|
// 5 -> hard fault LR LSB
|
|
|
|
// 6 -> hard fault LR MSB
|
|
|
|
|
2017-08-20 12:41:17 +00:00
|
|
|
// ----- main() ---------------------------------------------------------------
|
|
|
|
|
|
|
|
// Sample pragmas to cope with warnings. Please note the related line at
|
|
|
|
// the end of this function, used to pop the compiler diagnostics status.
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
|
|
|
#pragma GCC diagnostic ignored "-Wmissing-declarations"
|
|
|
|
#pragma GCC diagnostic ignored "-Wreturn-type"
|
|
|
|
#pragma GCC diagnostic ignored "-Wempty-body"
|
|
|
|
|
2019-01-13 20:55:09 +00:00
|
|
|
|
2019-01-23 21:18:05 +00:00
|
|
|
// global variable incremented by the SysTick handler to measure time in miliseconds
|
2019-01-13 20:55:09 +00:00
|
|
|
uint32_t master_time = 0;
|
|
|
|
|
2019-01-26 17:02:19 +00:00
|
|
|
// global variable used as a timer to trigger meteo sensors mesurements
|
2019-01-27 13:23:20 +00:00
|
|
|
int32_t main_wx_sensors_pool_timer = 65500;
|
2019-01-26 22:18:25 +00:00
|
|
|
|
|
|
|
// global variable used as a timer to trigger packet sending
|
2019-01-27 13:23:20 +00:00
|
|
|
int32_t main_packet_tx_pool_timer = 60000;
|
2019-01-26 17:02:19 +00:00
|
|
|
|
2020-02-01 22:20:17 +00:00
|
|
|
// one second pool interval
|
|
|
|
int32_t main_one_second_pool_timer = 1000;
|
|
|
|
|
2019-12-16 21:40:42 +00:00
|
|
|
// two second pool interval
|
|
|
|
int32_t main_two_second_pool_timer = 2000;
|
|
|
|
|
2020-01-04 13:15:33 +00:00
|
|
|
// ten second pool interval
|
|
|
|
int32_t main_ten_second_pool_timer = 10000;
|
|
|
|
|
2019-01-13 20:55:09 +00:00
|
|
|
// global variables represending the AX25/APRS stack
|
2019-01-26 22:18:25 +00:00
|
|
|
AX25Ctx main_ax25;
|
|
|
|
Afsk main_afsk;
|
2017-08-20 12:41:17 +00:00
|
|
|
|
2019-01-13 14:57:59 +00:00
|
|
|
|
2019-01-27 11:34:43 +00:00
|
|
|
AX25Call main_own_path[3];
|
|
|
|
uint8_t main_own_path_ln = 0;
|
|
|
|
uint8_t main_own_aprs_msg_len;
|
2019-01-26 22:18:25 +00:00
|
|
|
char main_own_aprs_msg[160];
|
2017-08-20 12:41:17 +00:00
|
|
|
|
2019-01-13 20:55:09 +00:00
|
|
|
// global variable used to store return value from various functions
|
|
|
|
volatile uint8_t retval = 100;
|
|
|
|
|
2019-04-03 09:41:37 +00:00
|
|
|
uint16_t buffer_len = 0;
|
|
|
|
#ifdef _VICTRON
|
|
|
|
#endif
|
|
|
|
|
2020-02-23 17:22:37 +00:00
|
|
|
#ifdef _UMB_MASTER
|
|
|
|
// return value from UMB related functions
|
|
|
|
umb_retval_t main_umb_retval = UMB_UNINITIALIZED;
|
|
|
|
#endif
|
|
|
|
|
2017-08-20 12:41:17 +00:00
|
|
|
char after_tx_lock;
|
|
|
|
|
2018-05-11 19:54:27 +00:00
|
|
|
unsigned short rx10m = 0, tx10m = 0, digi10m = 0, kiss10m = 0;
|
2017-08-20 12:41:17 +00:00
|
|
|
|
2018-04-17 22:05:02 +00:00
|
|
|
|
2017-08-20 12:41:17 +00:00
|
|
|
static void message_callback(struct AX25Msg *msg) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
// Send a greeting to the trace device (skipped on Release).
|
|
|
|
// trace_puts("Hello ARM World!");
|
|
|
|
|
2019-01-13 14:57:59 +00:00
|
|
|
int32_t ln = 0;
|
2017-08-20 12:41:17 +00:00
|
|
|
|
2019-01-27 13:23:20 +00:00
|
|
|
uint8_t button_inhibit = 0;
|
|
|
|
|
2017-08-20 12:41:17 +00:00
|
|
|
RCC->APB1ENR |= (RCC_APB1ENR_TIM2EN | RCC_APB1ENR_TIM3EN | RCC_APB1ENR_TIM7EN | RCC_APB1ENR_TIM4EN);
|
|
|
|
RCC->APB2ENR |= (RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_IOPDEN | RCC_APB2ENR_AFIOEN | RCC_APB2ENR_TIM1EN);
|
|
|
|
|
2019-01-26 22:18:25 +00:00
|
|
|
memset(main_own_aprs_msg, 0x00, 128);
|
2017-08-20 12:41:17 +00:00
|
|
|
|
2019-01-27 11:34:43 +00:00
|
|
|
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
|
|
|
|
|
2019-01-13 20:55:09 +00:00
|
|
|
// choosing the signal source for the SysTick timer.
|
|
|
|
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
|
|
|
|
|
|
|
|
// Configuring the SysTick timer to generate interrupt 100x per second (one interrupt = 10ms)
|
2019-01-27 11:34:43 +00:00
|
|
|
SysTick_Config(SystemCoreClock / SYSTICK_TICKS_PER_SECONDS);
|
2019-01-13 20:55:09 +00:00
|
|
|
|
2019-01-27 12:14:36 +00:00
|
|
|
// setting an Systick interrupt priority
|
|
|
|
NVIC_SetPriority(SysTick_IRQn, 5);
|
|
|
|
|
2019-04-16 21:33:41 +00:00
|
|
|
// enable access to BKP registers
|
|
|
|
RCC->APB1ENR |= (RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN);
|
|
|
|
PWR->CR |= PWR_CR_DBP;
|
|
|
|
|
2019-05-05 07:48:51 +00:00
|
|
|
rte_main_reboot_req = 0;
|
|
|
|
|
2019-04-16 21:33:41 +00:00
|
|
|
// read current number of boot cycles
|
|
|
|
rte_main_boot_cycles = (uint8_t)(BKP->DR2 & 0xFF);
|
|
|
|
|
|
|
|
// read current number of hard faults
|
2019-05-05 12:25:48 +00:00
|
|
|
rte_main_hard_faults = (uint8_t)((BKP->DR2 & 0xFF00) >> 8);
|
2019-04-16 21:33:41 +00:00
|
|
|
|
|
|
|
// increase boot cycles count
|
|
|
|
rte_main_boot_cycles++;
|
|
|
|
|
|
|
|
// erasing old value from backup registers
|
|
|
|
BKP->DR2 &= (0xFFFF ^ 0xFF);
|
|
|
|
|
|
|
|
// storing increased value
|
|
|
|
BKP->DR2 |= rte_main_boot_cycles;
|
|
|
|
|
|
|
|
rte_main_hardfault_pc = (BKP->DR3 | (BKP->DR4 << 16));
|
|
|
|
rte_main_hardfault_lr = (BKP->DR5 | (BKP->DR6 << 16));
|
|
|
|
|
|
|
|
BKP->DR3 = 0;
|
|
|
|
BKP->DR4 = 0;
|
|
|
|
BKP->DR5 = 0;
|
|
|
|
BKP->DR6 = 0;
|
|
|
|
|
|
|
|
// disabling access to BKP registers
|
|
|
|
RCC->APB1ENR &= (0xFFFFFFFF ^ (RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN));
|
|
|
|
PWR->CR &= (0xFFFFFFFF ^ PWR_CR_DBP);
|
|
|
|
|
2019-01-26 17:02:19 +00:00
|
|
|
#if defined _RANDOM_DELAY
|
|
|
|
// configuring a default delay value
|
|
|
|
delay_set(_DELAY_BASE, 1);
|
|
|
|
#elif !defined _RANDOM_DELAY
|
|
|
|
delay_set(_DELAY_BASE, 0);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// configuring an APRS path used to transmit own packets (telemetry, wx, beacons)
|
2019-01-27 11:34:43 +00:00
|
|
|
main_own_path_ln = ConfigPath(main_own_path);
|
2017-08-20 12:41:17 +00:00
|
|
|
|
|
|
|
#ifdef _METEO
|
2020-01-04 13:15:33 +00:00
|
|
|
// initialize i2c controller
|
2017-08-20 12:41:17 +00:00
|
|
|
i2cConfigure();
|
|
|
|
#endif
|
2020-01-04 13:15:33 +00:00
|
|
|
|
|
|
|
// initialize GPIO pins leds are connecting to
|
|
|
|
led_init();
|
|
|
|
|
|
|
|
// initialize AX25 & APRS stuff
|
2019-01-26 22:18:25 +00:00
|
|
|
AFSK_Init(&main_afsk);
|
|
|
|
ax25_init(&main_ax25, &main_afsk, 0, 0x00);
|
2017-08-20 12:41:17 +00:00
|
|
|
DA_Init();
|
|
|
|
|
2020-04-04 21:09:00 +00:00
|
|
|
// initialize Watchdog output
|
|
|
|
Configure_GPIO(GPIOA,12,GPPP_OUTPUT_50MHZ);
|
|
|
|
|
2020-01-04 13:15:33 +00:00
|
|
|
// initialize variables & arrays in rte_wx
|
|
|
|
rte_wx_init();
|
|
|
|
|
2017-08-20 12:41:17 +00:00
|
|
|
#ifdef _METEO
|
2019-12-16 21:40:42 +00:00
|
|
|
// initialize sensor power control and switch off supply voltage
|
|
|
|
wx_pwr_init();
|
|
|
|
|
|
|
|
// call periodic handle to wait for 1 second and then switch on voltage
|
|
|
|
wx_pwr_periodic_handle();
|
|
|
|
|
|
|
|
// initialize humidity sensor
|
2018-04-17 22:05:02 +00:00
|
|
|
dht22_init();
|
2019-09-10 20:34:08 +00:00
|
|
|
#ifndef _DALLAS_SPLIT_PIN
|
2019-10-27 19:50:01 +00:00
|
|
|
dallas_init(GPIOC, GPIO_Pin_6, GPIO_PinSource6, &rte_wx_dallas_average);
|
2019-09-10 20:34:08 +00:00
|
|
|
#else
|
2019-10-27 19:50:01 +00:00
|
|
|
dallas_init(GPIOC, GPIO_Pin_11, GPIO_PinSource11, &rte_wx_dallas_average);
|
2019-09-10 20:34:08 +00:00
|
|
|
#endif
|
2019-12-26 19:55:47 +00:00
|
|
|
|
2020-02-23 17:22:37 +00:00
|
|
|
#if defined(_UMB_MASTER)
|
|
|
|
// UMB client cannot be used in the same time with TX20 or analogue anemometer
|
|
|
|
#undef _ANEMOMETER_TX20
|
|
|
|
#undef _ANEMOMETER_ANALOGUE
|
|
|
|
|
|
|
|
// client initialization
|
2020-03-18 20:56:02 +00:00
|
|
|
umb_master_init(&rte_wx_umb_context);
|
2020-02-23 17:22:37 +00:00
|
|
|
#endif
|
|
|
|
|
2019-12-26 19:55:47 +00:00
|
|
|
#ifdef _ANEMOMETER_TX20
|
2020-03-03 21:12:15 +00:00
|
|
|
tx20_init();
|
2019-12-26 19:55:47 +00:00
|
|
|
#endif
|
|
|
|
#ifdef _ANEMOMETER_ANALOGUE
|
2020-02-29 21:12:08 +00:00
|
|
|
analog_anemometer_init(10, 10, 100, 1);
|
2019-12-26 19:55:47 +00:00
|
|
|
#endif
|
|
|
|
|
2018-05-11 19:54:27 +00:00
|
|
|
#endif
|
|
|
|
#ifdef _DALLAS_AS_TELEM
|
2019-09-10 20:34:08 +00:00
|
|
|
#ifndef _DALLAS_SPLIT_PIN
|
2019-10-27 19:50:01 +00:00
|
|
|
dallas_init(GPIOC, GPIO_Pin_6, GPIO_PinSource6, &rte_wx_dallas_average);
|
2019-09-10 20:34:08 +00:00
|
|
|
#else
|
2019-10-27 19:50:01 +00:00
|
|
|
dallas_init(GPIOC, GPIO_Pin_11, GPIO_PinSource11, &rte_wx_dallas_average);
|
2019-09-10 20:34:08 +00:00
|
|
|
#endif
|
2017-08-20 12:41:17 +00:00
|
|
|
#endif
|
|
|
|
|
2019-01-26 22:18:25 +00:00
|
|
|
// initializing UART drvier
|
|
|
|
srl_init();
|
2017-08-20 12:41:17 +00:00
|
|
|
|
2019-01-27 12:14:36 +00:00
|
|
|
// configuring interrupt priorities
|
|
|
|
it_handlers_set_priorities();
|
|
|
|
|
2017-08-20 12:41:17 +00:00
|
|
|
#ifdef _METEO
|
2019-01-26 17:02:19 +00:00
|
|
|
ms5611_reset(&rte_wx_ms5611_qf);
|
|
|
|
ms5611_read_calibration(SensorCalData, &rte_wx_ms5611_qf);
|
|
|
|
ms5611_trigger_measure(0, 0);
|
2017-08-20 12:41:17 +00:00
|
|
|
#endif
|
|
|
|
|
2019-01-12 13:44:16 +00:00
|
|
|
// preparing initial beacon which will be sent to host PC using KISS protocol via UART
|
2019-01-27 11:34:43 +00:00
|
|
|
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);
|
2019-01-12 13:44:16 +00:00
|
|
|
|
|
|
|
// terminating the aprs message
|
2019-01-27 11:34:43 +00:00
|
|
|
main_own_aprs_msg[main_own_aprs_msg_len] = 0;
|
2019-01-12 13:44:16 +00:00
|
|
|
|
|
|
|
// 'sending' the message which will only encapsulate it inside AX25 protocol (ax25_starttx is not called here)
|
2019-05-05 07:48:51 +00:00
|
|
|
//ax25_sendVia(&main_ax25, main_own_path, (sizeof(main_own_path) / sizeof(*(main_own_path))), main_own_aprs_msg, main_own_aprs_msg_len);
|
|
|
|
ln = ax25_sendVia_toBuffer(main_own_path, (sizeof(main_own_path) / sizeof(*(main_own_path))), main_own_aprs_msg, main_own_aprs_msg_len, srl_tx_buffer, TX_BUFFER_LN);
|
2019-01-12 13:44:16 +00:00
|
|
|
|
|
|
|
// SendKISSToHost function cleares the output buffer hence routine need to wait till the UART will be ready for next transmission.
|
|
|
|
// Here this could be omitted because UART isn't used before but general idea
|
2019-01-13 14:57:59 +00:00
|
|
|
while(srl_tx_state != SRL_TX_IDLE && srl_tx_state != SRL_TX_ERROR);
|
2019-01-12 13:44:16 +00:00
|
|
|
|
|
|
|
// converting AX25 with beacon to KISS format
|
2019-05-05 07:48:51 +00:00
|
|
|
//ln = SendKISSToHost(main_afsk.tx_buf + 1, main_afsk.tx_fifo.tail - main_afsk.tx_fifo.head - 4, srl_tx_buffer, TX_BUFFER_LN);
|
2019-01-12 13:44:16 +00:00
|
|
|
|
|
|
|
// checking if KISS-framing was done correctly
|
|
|
|
if (ln != KISS_TOO_LONG_FRM) {
|
|
|
|
#ifdef SERIAL_TX_TEST_MODE
|
|
|
|
// infinite loop for testing UART transmission
|
|
|
|
for (;;) {
|
|
|
|
|
2019-01-13 14:57:59 +00:00
|
|
|
retval = srl_receive_data(100, FEND, FEND, 0, 0, 0);
|
|
|
|
#endif
|
|
|
|
retval = srl_start_tx(ln);
|
2019-01-12 13:44:16 +00:00
|
|
|
|
|
|
|
#ifdef SERIAL_TX_TEST_MODE
|
2019-01-13 14:57:59 +00:00
|
|
|
while(srl_tx_state != SRL_TX_IDLE);
|
2020-03-17 21:52:10 +00:00
|
|
|
// while(srl_rx_state != SRL_RX_DONE);
|
2019-01-13 14:57:59 +00:00
|
|
|
|
2019-03-13 18:54:01 +00:00
|
|
|
GPIOC->ODR = (GPIOC->ODR ^ GPIO_Pin_9);
|
|
|
|
|
2019-01-13 14:57:59 +00:00
|
|
|
if (srl_rx_state == SRL_RX_DONE) {
|
2019-03-13 18:54:01 +00:00
|
|
|
GPIOC->ODR = (GPIOC->ODR ^ GPIO_Pin_8);
|
|
|
|
|
2019-01-13 14:57:59 +00:00
|
|
|
retval = 200;
|
|
|
|
}
|
2019-01-12 13:44:16 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// reinitializing AFSK and AX25 driver
|
2019-01-26 22:18:25 +00:00
|
|
|
AFSK_Init(&main_afsk);
|
2017-08-20 12:41:17 +00:00
|
|
|
|
|
|
|
ADCStartConfig();
|
|
|
|
DACStartConfig();
|
2019-01-26 22:18:25 +00:00
|
|
|
AFSK_Init(&main_afsk);
|
|
|
|
ax25_init(&main_ax25, &main_afsk, 0, message_callback);
|
2017-08-20 12:41:17 +00:00
|
|
|
|
2019-01-26 17:02:19 +00:00
|
|
|
// getting all meteo measuremenets to be sure that WX frames want be sent with zeros
|
|
|
|
wx_get_all_measurements();
|
2017-08-20 12:41:17 +00:00
|
|
|
|
2020-02-23 17:22:37 +00:00
|
|
|
#if defined _VICTRON && !defined _UMB_MASTER
|
2019-04-03 09:41:37 +00:00
|
|
|
// initializing protocol parser
|
|
|
|
ve_direct_parser_init(&rte_pv_struct, &rte_pv_average);
|
|
|
|
|
|
|
|
// enabling timeout handling for serial port. This is required because VE protocol frame may vary in lenght
|
|
|
|
// and serial port driver could finish reception only either on stop character or when declared number of bytes
|
|
|
|
// has been received.
|
|
|
|
srl_switch_timeout(1, 100);
|
|
|
|
|
|
|
|
// switching UART to receive mode to be ready for data from charging controller
|
|
|
|
srl_receive_data(VE_DIRECT_MAX_FRAME_LN, 0x0D, 0, 0, 0, 0);
|
2020-02-23 17:22:37 +00:00
|
|
|
|
|
|
|
#elif !defined _VICTRON && defined _UMB_MASTER
|
|
|
|
|
2020-03-18 20:56:02 +00:00
|
|
|
// srl_receive_data(8, SOH, 0x00, 0, 6, 12);
|
2020-02-23 17:22:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
#elif ! defined _VICTRON && !defined _UMB_MASTER
|
2019-01-26 22:18:25 +00:00
|
|
|
// switching UART to receive mode to be ready for KISS frames from host
|
2019-01-26 17:02:19 +00:00
|
|
|
srl_receive_data(100, FEND, FEND, 0, 0, 0);
|
2019-04-03 09:41:37 +00:00
|
|
|
#endif
|
2017-08-20 12:41:17 +00:00
|
|
|
|
|
|
|
GPIO_ResetBits(GPIOC, GPIO_Pin_8 | GPIO_Pin_9);
|
|
|
|
|
2019-01-26 22:18:25 +00:00
|
|
|
// configuting system timers
|
2018-04-20 21:23:50 +00:00
|
|
|
TimerConfig();
|
|
|
|
|
2017-08-20 12:41:17 +00:00
|
|
|
#ifdef _BCN_ON_STARTUP
|
2019-04-16 21:33:41 +00:00
|
|
|
SendStartup();
|
2017-08-20 12:41:17 +00:00
|
|
|
#endif
|
|
|
|
|
2020-03-21 16:46:16 +00:00
|
|
|
#if defined(_UMB_MASTER)
|
2020-03-17 21:52:10 +00:00
|
|
|
umb_0x26_status_request(&rte_wx_umb, &rte_wx_umb_context);
|
2020-03-21 16:46:16 +00:00
|
|
|
#endif
|
2020-03-17 21:52:10 +00:00
|
|
|
|
2017-08-20 12:41:17 +00:00
|
|
|
// Infinite loop
|
|
|
|
while (1)
|
|
|
|
{
|
2019-05-05 07:48:51 +00:00
|
|
|
if (rte_main_reboot_req == 1)
|
|
|
|
NVIC_SystemReset();
|
|
|
|
|
2017-08-20 12:41:17 +00:00
|
|
|
if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)) {
|
2019-01-27 13:23:20 +00:00
|
|
|
|
|
|
|
if (main_afsk.sending == false && button_inhibit == 0) {
|
|
|
|
|
|
|
|
while(main_ax25.dcd == true);
|
|
|
|
|
2019-09-11 21:30:29 +00:00
|
|
|
#ifndef _METEO
|
2019-01-27 13:23:20 +00:00
|
|
|
//telemetry_send_values(rx10m, tx10m, digi10m, kiss10m, rte_wx_temperature_dallas_valid, rte_wx_dallas_qf, rte_wx_ms5611_qf, rte_wx_dht.qf);
|
|
|
|
SendOwnBeacon();
|
2019-09-11 21:30:29 +00:00
|
|
|
#else
|
2020-01-04 13:15:33 +00:00
|
|
|
|
|
|
|
SendWXFrame(rte_wx_average_windspeed, rte_wx_max_windspeed, rte_wx_average_winddirection, rte_wx_temperature_dallas_valid, rte_wx_pressure_valid);
|
|
|
|
|
|
|
|
#endif // #ifndef _METEO
|
2019-01-27 13:23:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
button_inhibit = 1;
|
2017-08-20 12:41:17 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-01-27 13:23:20 +00:00
|
|
|
button_inhibit = 0;
|
2017-08-20 12:41:17 +00:00
|
|
|
}
|
|
|
|
|
2019-01-26 22:18:25 +00:00
|
|
|
// if new packet has been received from radio channel
|
2019-03-18 20:12:05 +00:00
|
|
|
if(ax25_new_msg_rx_flag == 1) {
|
2019-01-02 07:20:19 +00:00
|
|
|
memset(srl_tx_buffer, 0x00, sizeof(srl_tx_buffer));
|
2019-01-26 22:18:25 +00:00
|
|
|
|
|
|
|
// convert message to kiss format and send it to host
|
2019-03-18 20:12:05 +00:00
|
|
|
srl_start_tx(SendKISSToHost(ax25_rxed_frame.raw_data, (ax25_rxed_frame.raw_msg_len - 2), srl_tx_buffer, TX_BUFFER_LN));
|
2018-04-20 21:23:50 +00:00
|
|
|
|
2019-01-26 22:18:25 +00:00
|
|
|
main_ax25.dcd = false;
|
2017-08-20 12:41:17 +00:00
|
|
|
#ifdef _DBG_TRACE
|
2019-03-18 20:12:05 +00:00
|
|
|
trace_printf("APRS-RF:RadioPacketFrom=%.6s-%d,FirstPathEl=%.6s-%d\r\n", ax25_rxed_frame.src.call, ax25_rxed_frame.src.ssid, ax25_rxed_frame.rpt_lst[0].call, ax25_rxed_frame.rpt_lst[0].ssid);
|
2017-08-20 12:41:17 +00:00
|
|
|
#endif
|
|
|
|
#ifdef _DIGI
|
2019-01-26 22:18:25 +00:00
|
|
|
// check if this packet needs to be repeated (digipeated) and do it if it is neccessary
|
2019-03-18 20:12:05 +00:00
|
|
|
Digi(&ax25_rxed_frame);
|
2017-08-20 12:41:17 +00:00
|
|
|
#endif
|
2019-03-18 20:12:05 +00:00
|
|
|
ax25_new_msg_rx_flag = 0;
|
2017-08-20 12:41:17 +00:00
|
|
|
rx10m++;
|
|
|
|
}
|
|
|
|
|
2020-02-23 17:22:37 +00:00
|
|
|
#if defined _VICTRON
|
2019-01-26 22:18:25 +00:00
|
|
|
// if new KISS message has been received from the host
|
2019-04-03 09:41:37 +00:00
|
|
|
if (srl_rx_state == SRL_RX_DONE || srl_rx_state == SRL_RX_ERROR) {
|
2019-01-26 22:18:25 +00:00
|
|
|
|
2019-04-03 09:41:37 +00:00
|
|
|
// cutting received string to Checksum, everything after will be skipped
|
|
|
|
ve_direct_cut_to_checksum(srl_get_rx_buffer(), RX_BUFFER_LN, &buffer_len);
|
2019-02-10 16:16:37 +00:00
|
|
|
|
2019-04-03 09:41:37 +00:00
|
|
|
// checking if this frame is ok
|
|
|
|
ve_direct_validate_checksum(srl_get_rx_buffer(), buffer_len, &retval);
|
|
|
|
|
|
|
|
if (retval == 1) {
|
|
|
|
// parsing data from input serial buffer to
|
|
|
|
retval = ve_direct_parse_to_raw_struct(srl_get_rx_buffer(), buffer_len, &rte_pv_struct);
|
|
|
|
|
|
|
|
if (retval == 0) {
|
|
|
|
ve_direct_add_to_average(&rte_pv_struct, &rte_pv_average);
|
|
|
|
|
|
|
|
ve_direct_get_averages(&rte_pv_average, &rte_pv_battery_current, &rte_pv_battery_voltage, &rte_pv_cell_voltage, &rte_pv_load_current);
|
|
|
|
|
|
|
|
ve_direct_set_sys_voltage(&rte_pv_struct, &rte_pv_sys_voltage);
|
2019-04-04 17:57:21 +00:00
|
|
|
|
|
|
|
ve_direct_store_errors(&rte_pv_struct, &rte_pv_last_error);
|
2019-04-03 09:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
srl_receive_data(VE_DIRECT_MAX_FRAME_LN, 0x0D, 0, 0, 0, 0);
|
|
|
|
}
|
2020-02-23 17:22:37 +00:00
|
|
|
#elif defined _UMB_MASTER
|
|
|
|
// if some UMB data have been received
|
|
|
|
if (srl_rx_state == SRL_RX_DONE) {
|
2020-03-29 07:12:23 +00:00
|
|
|
umb_pooling_handler(&rte_wx_umb_context, REASON_RECEIVE_IDLE, master_time);
|
2020-02-23 17:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if there were an error during receiving frame from host, restart rxing once again
|
|
|
|
if (srl_rx_state == SRL_RX_ERROR) {
|
2020-03-29 07:12:23 +00:00
|
|
|
umb_pooling_handler(&rte_wx_umb_context, REASON_RECEIVE_ERROR, master_time);
|
2020-03-07 18:13:24 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 21:52:10 +00:00
|
|
|
if (srl_tx_state == SRL_TX_IDLE) {
|
2020-03-29 07:12:23 +00:00
|
|
|
umb_pooling_handler(&rte_wx_umb_context, REASON_TRANSMIT_IDLE, master_time);
|
2020-02-23 17:22:37 +00:00
|
|
|
}
|
2019-04-03 09:41:37 +00:00
|
|
|
#else
|
|
|
|
// if new KISS message has been received from the host
|
|
|
|
if (srl_rx_state == SRL_RX_DONE) {
|
2019-01-26 22:18:25 +00:00
|
|
|
// parse incoming data and then transmit on radio freq
|
2019-02-10 16:16:37 +00:00
|
|
|
short res = ParseReceivedKISS(srl_get_rx_buffer(), srl_get_num_bytes_rxed(), &main_ax25, &main_afsk);
|
2018-05-11 19:54:27 +00:00
|
|
|
if (res == 0)
|
2019-01-26 22:18:25 +00:00
|
|
|
kiss10m++; // increase kiss messages counter
|
2018-05-11 19:54:27 +00:00
|
|
|
|
2019-01-26 22:18:25 +00:00
|
|
|
// restart KISS receiving to be ready for next frame
|
2019-01-02 07:20:19 +00:00
|
|
|
srl_receive_data(120, FEND, FEND, 0, 0, 0);
|
2017-08-20 12:41:17 +00:00
|
|
|
}
|
2019-01-26 22:18:25 +00:00
|
|
|
|
2019-02-10 16:16:37 +00:00
|
|
|
// if there were an error during receiving frame from host, restart rxing once again
|
|
|
|
if (srl_rx_state == SRL_RX_ERROR) {
|
|
|
|
srl_receive_data(120, FEND, FEND, 0, 0, 0);
|
|
|
|
}
|
2019-04-03 09:41:37 +00:00
|
|
|
#endif
|
2019-02-10 16:16:37 +00:00
|
|
|
|
2019-01-26 22:18:25 +00:00
|
|
|
// 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) {
|
2019-01-12 13:44:16 +00:00
|
|
|
|
2019-01-26 17:02:19 +00:00
|
|
|
wx_get_all_measurements();
|
|
|
|
|
2019-01-26 22:18:25 +00:00
|
|
|
main_wx_sensors_pool_timer = 65500;
|
2018-04-18 23:00:44 +00:00
|
|
|
}
|
2019-01-26 17:02:19 +00:00
|
|
|
|
2019-01-27 13:23:20 +00:00
|
|
|
if (main_packet_tx_pool_timer < 10) {
|
|
|
|
|
|
|
|
packet_tx_handler();
|
|
|
|
|
|
|
|
main_packet_tx_pool_timer = 60000;
|
|
|
|
}
|
|
|
|
|
2020-02-01 22:20:17 +00:00
|
|
|
if (main_one_second_pool_timer < 10) {
|
|
|
|
|
2020-02-23 06:50:22 +00:00
|
|
|
#ifdef _ANEMOMETER_ANALOGUE
|
2020-02-01 22:20:17 +00:00
|
|
|
analog_anemometer_direction_handler();
|
2020-02-23 06:50:22 +00:00
|
|
|
#endif
|
2020-02-01 22:20:17 +00:00
|
|
|
|
|
|
|
main_one_second_pool_timer = 1000;
|
|
|
|
}
|
|
|
|
else if (main_one_second_pool_timer < -10) {
|
|
|
|
|
2020-02-23 06:50:22 +00:00
|
|
|
#ifdef _ANEMOMETER_ANALOGUE
|
2020-02-01 22:20:17 +00:00
|
|
|
analog_anemometer_direction_reset();
|
2020-02-23 06:50:22 +00:00
|
|
|
#endif
|
2020-02-01 22:20:17 +00:00
|
|
|
|
|
|
|
main_one_second_pool_timer = 1000;
|
|
|
|
}
|
|
|
|
|
2019-12-16 21:40:42 +00:00
|
|
|
if (main_two_second_pool_timer < 10) {
|
|
|
|
|
|
|
|
wx_pwr_periodic_handle();
|
|
|
|
|
|
|
|
main_two_second_pool_timer = 2000;
|
|
|
|
}
|
|
|
|
|
2020-01-04 13:15:33 +00:00
|
|
|
if (main_ten_second_pool_timer < 10) {
|
|
|
|
|
2020-03-21 16:46:16 +00:00
|
|
|
#if defined(_UMB_MASTER)
|
2020-03-23 20:41:01 +00:00
|
|
|
umb_channel_pool(&rte_wx_umb, &rte_wx_umb_context);
|
|
|
|
rte_wx_umb_qf = umb_get_current_qf(&rte_wx_umb_context, master_time);
|
2020-03-21 16:46:16 +00:00
|
|
|
#endif
|
|
|
|
|
2020-03-23 20:41:01 +00:00
|
|
|
wx_pool_anemometer();
|
2020-01-04 13:15:33 +00:00
|
|
|
|
|
|
|
main_ten_second_pool_timer = 10000;
|
2020-04-04 21:09:00 +00:00
|
|
|
|
|
|
|
GPIOA->ODR = (GPIOA->ODR ^ GPIO_Pin_12);
|
2020-01-04 13:15:33 +00:00
|
|
|
}
|
|
|
|
|
2019-01-26 22:18:25 +00:00
|
|
|
#ifdef _METEO
|
2019-01-26 17:02:19 +00:00
|
|
|
// dht22 sensor communication pooling
|
|
|
|
wx_pool_dht22();
|
2019-01-12 13:44:16 +00:00
|
|
|
#endif
|
2017-08-20 12:41:17 +00:00
|
|
|
}
|
|
|
|
// Infinite loop, never return.
|
|
|
|
}
|
|
|
|
|
2019-01-23 21:18:05 +00:00
|
|
|
uint16_t main_get_adc_sample(void) {
|
|
|
|
return (uint16_t) ADC1->DR;
|
|
|
|
}
|
|
|
|
|
2019-01-27 13:23:20 +00:00
|
|
|
|
2019-12-16 21:40:42 +00:00
|
|
|
|
2017-08-20 12:41:17 +00:00
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|