pull/2/head
Mateusz Lubecki 2020-08-09 21:43:38 +02:00
rodzic 96232c3873
commit 962ee06687
6 zmienionych plików z 208 dodań i 11 usunięć

Wyświetl plik

@ -8,6 +8,7 @@ C_SRCS += \
../system/src/drivers/analog_anemometer.c \
../system/src/drivers/bme280.c \
../system/src/drivers/dallas.c \
../system/src/drivers/davis_vantage.c \
../system/src/drivers/dma_helper_functions.c \
../system/src/drivers/gpio_conf.c \
../system/src/drivers/i2c.c \
@ -21,6 +22,7 @@ OBJS += \
./system/src/drivers/analog_anemometer.o \
./system/src/drivers/bme280.o \
./system/src/drivers/dallas.o \
./system/src/drivers/davis_vantage.o \
./system/src/drivers/dma_helper_functions.o \
./system/src/drivers/gpio_conf.o \
./system/src/drivers/i2c.o \
@ -34,6 +36,7 @@ C_DEPS += \
./system/src/drivers/analog_anemometer.d \
./system/src/drivers/bme280.d \
./system/src/drivers/dallas.d \
./system/src/drivers/davis_vantage.d \
./system/src/drivers/dma_helper_functions.d \
./system/src/drivers/gpio_conf.d \
./system/src/drivers/i2c.d \

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -12,16 +12,17 @@
#define DAVIS_OK 0
typedef enum davis_loop_query_state {
DAVIS_LOOP_IDLE,
DAVIS_LOOP_SENDING_QUERY,
DAVIS_LOOP_RECEIVING,
DAVIS_LOOP_OK,
DAVIS_LOOP_ERROR
}davis_loop_query_state_t;
typedef enum davis_qf_t {
DAVIS_QF_UNINITIALIZED,
DAVIS_QF_NOT_AVALIABLE,
DAVIS_QF_DEGRADED_COMM_BASE,
DAVIS_QF_DEGRADED_COMM_ODU,
DAVIS_QF_DEGRADED_BATTERY,
DAVIS_QF_FULL
} davis_qf_t;
uint32_t davis_init(srl_context_t* srl_port);
uint32_t davis_wake_up(void);
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_leave_receiving_screen(void);

Wyświetl plik

@ -76,11 +76,13 @@ typedef struct srl_context_t {
}srl_context_t;
#define SRL_UNINITIALIZED 127
#define SRL_OK 0
#define SRL_DATA_TOO_LONG 1
#define SRL_BUSY 2
#define SRL_WRONG_BUFFER_PARAM 3
#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;
@ -111,6 +113,7 @@ void srl_init(srl_context_t *ctx, USART_TypeDef *port, uint8_t *rx_buffer, uint1
uint8_t srl_send_data(srl_context_t *ctx, uint8_t* data, uint8_t mode, uint16_t leng, uint8_t internal_external);
uint8_t srl_start_tx(srl_context_t *ctx, short leng);
void srl_wait_for_tx_completion(srl_context_t *ctx);
uint8_t srl_wait_for_rx_completion_or_timeout(srl_context_t *ctx, uint8_t* output);
void srl_irq_handler(srl_context_t *ctx);
uint8_t srl_receive_data(srl_context_t *ctx, int num, char start, char stop, char echo, char len_addr, char len_modifier);
uint16_t srl_get_num_bytes_rxed(srl_context_t *ctx);

Wyświetl plik

@ -7,23 +7,191 @@
#include "./drivers/davis_vantage.h"
/**
* This enum is private and used only internally by
*/
typedef enum davis_query_state {
DAVIS_QUERY_IDLE,
DAVIS_QUERY_SENDING_QUERY,
DAVIS_QUERY_RECEIVING,
DAVIS_QUERY_OK,
DAVIS_QUERY_ERROR
}davis_query_state_t;
/**
* Serial port context to be used for communication
*/
srl_context_t* davis_serial_context;
typedef enum davis_loop_query_state {
/**
* The internal state during loop packet retrieval
*/
davis_query_state_t davis_loop_state;
};
/**
* Internal state during waking up the station base
*/
davis_query_state_t davis_wake_up_state;
/**
*
*/
davis_qf_t davis_quality_factor;
/**
* Set to one if station was detected during bootup
*/
uint8_t davis_avaliable;
static const char line_feed[] = "\n";
static const char line_feed_return[] = {'\n', '\r'};
uint32_t davis_init(srl_context_t* srl_port) {
uint32_t retval = DAVIS_OK;
davis_serial_context = srl_port;
davis_quality_factor = DAVIS_QF_UNINITIALIZED;
davis_loop_state = DAVIS_QUERY_IDLE;
davis_wake_up_state = DAVIS_QUERY_IDLE;
davis_avaliable = 0;
// set the timeout according to davis vantage documentation
srl_switch_timeout(srl_port, 1, 1200);
return retval;
}
uint32_t davis_wake_up(void) {
/**
* This function may have blocking I/O
*/
uint32_t davis_wake_up(uint8_t is_io_blocking) {
uint32_t retval = DAVIS_OK;
int comparation_result = -1;
// sending the new line to wake up the console
srl_send_data(davis_serial_context, (uint8_t*)line_feed, 1, 1, 0);
// check if a user want to have blocking I/O
if (is_io_blocking == 1) {
// if yes wait for transmission completion and then wait for response
srl_wait_for_tx_completion(davis_serial_context);
// start waiting for console response
srl_receive_data(davis_serial_context, 2, 0, 0, 0, 0, 0);
// wait for station response or for timeout
srl_wait_for_rx_completion_or_timeout(davis_serial_context, ((uint8_t*)&retval));
// if response has been received
if (retval == SRL_OK) {
//
retval = DAVIS_OK;
// set the quality factor appropriate to signalize that the station
// is avaliable
davis_quality_factor = DAVIS_QF_FULL;
davis_avaliable = 1;
}
else {
// send the wake up command one more time
// sending the new line to wake up the console
srl_send_data(davis_serial_context, (uint8_t*)line_feed, 1, 1, 0);
// if yes wait for transmission completion and then wait for response
srl_wait_for_tx_completion(davis_serial_context);
// start waiting for console response
srl_receive_data(davis_serial_context, 2, 0, 0, 0, 0, 0);
// wait for station response or for timeout
srl_wait_for_rx_completion_or_timeout(davis_serial_context, ((uint8_t*)&retval));
// if second attempt was successful
if (retval == SRL_OK) {
retval = DAVIS_OK;
// set the quality factor appropriate to signalize that the station
// is avaliable
davis_quality_factor = DAVIS_QF_FULL;
davis_avaliable = 1;
}
else {
// if not the station is dead an
davis_quality_factor = DAVIS_QF_NOT_AVALIABLE;
}
}
}
else {
// non blocking input/output
switch (davis_wake_up_state) {
case DAVIS_QUERY_IDLE: {
// sending the new line to wake up the console
srl_send_data(davis_serial_context, (uint8_t*)line_feed, 1, 1, 0);
// switching the internal state
davis_wake_up_state = DAVIS_QUERY_SENDING_QUERY;
break;
}
case DAVIS_QUERY_SENDING_QUERY: {
// check if wakeup has been sent
if (davis_serial_context->srl_tx_state == SRL_TX_IDLE) {
// if transmission was successfull trigger the reception
srl_receive_data(davis_serial_context, 2, 0, 0, 0, 0, 0);
// switching the internal state
davis_wake_up_state = DAVIS_QUERY_RECEIVING;
}
if (davis_serial_context->srl_tx_state == SRL_TX_ERROR) {
davis_wake_up_state = DAVIS_QUERY_ERROR;
}
break;
}
case DAVIS_QUERY_RECEIVING: {
// check if receive has been successfull
if (davis_serial_context->srl_rx_state == SRL_RX_DONE) {
// check the content of what was received from the davis
comparation_result = memcmp(line_feed_return, davis_serial_context->srl_rx_buf_pointer, 2);
if (comparation_result == 0) {
// if the
}
else {
}
}
if (davis_serial_context->srl_rx_state == SRL_RX_ERROR) {
davis_wake_up_state = DAVIS_QUERY_ERROR;
}
break;
}
case DAVIS_QUERY_OK: {
break;
}
case DAVIS_QUERY_ERROR: {
break;
}
}
}
return retval;
}
uint32_t davis_do_test(void) {

Wyświetl plik

@ -268,6 +268,28 @@ void srl_wait_for_tx_completion(srl_context_t *ctx) {
while(ctx->srl_tx_state != SRL_TX_IDLE && ctx->srl_tx_state != SRL_TX_ERROR);
}
uint8_t srl_wait_for_rx_completion_or_timeout(srl_context_t *ctx, uint8_t* output) {
output = SRL_UNINITIALIZED;
// block the execution until the
while(ctx->srl_rx_state != SRL_WAITING_TO_RX && ctx->srl_rx_state != SRL_RXING && ctx->srl_rx_state != SRL_RX_ERROR);
switch (ctx->srl_rx_state) {
case SRL_RX_DONE: {
output = SRL_OK;
break;
}
case SRL_RX_ERROR: {
output = SRL_TIMEOUT;
break;
}
}
return output;
}
uint8_t srl_receive_data(srl_context_t *ctx, int num, char start, char stop, char echo, char len_addr, char len_modifier) {
if (ctx->srl_rx_state == SRL_RXING)
return SRL_BUSY;