kopia lustrzana https://github.com/SP8EBC/ParaTNC
DB01
rodzic
a8c0005098
commit
9075327d8c
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "aprs/ax25.h"
|
||||
|
||||
#define SW_VER "DB00"
|
||||
#define SW_VER "DB02"
|
||||
#define SW_DATE "04042019"
|
||||
|
||||
#define SYSTICK_TICKS_PER_SECONDS 100
|
||||
|
|
Plik binarny nie jest wyświetlany.
|
@ -300,6 +300,8 @@ main(int argc, char* argv[])
|
|||
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);
|
||||
|
||||
ve_direct_store_errors(&rte_pv_struct, &rte_pv_last_error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -90,14 +90,22 @@ void packet_tx_handler(void) {
|
|||
if (packet_tx_telemetry_descr_counter >= packet_tx_telemetry_descr_interval) {
|
||||
#ifdef _VICTRON
|
||||
telemetry_send_chns_description_pv();
|
||||
|
||||
main_wait_for_tx_complete();
|
||||
|
||||
telemetry_send_status(&rte_pv_average, &rte_pv_last_error, rte_pv_struct.system_state);
|
||||
|
||||
main_wait_for_tx_complete();
|
||||
#else
|
||||
telemetry_send_chns_description();
|
||||
#endif
|
||||
|
||||
main_wait_for_tx_complete();
|
||||
|
||||
telemetry_send_status();
|
||||
|
||||
main_wait_for_tx_complete();
|
||||
#endif
|
||||
|
||||
|
||||
packet_tx_telemetry_descr_counter = 0;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ ve_direct_average_struct rte_pv_average;
|
|||
uint8_t rte_pv_sys_voltage;
|
||||
ve_direct_raw_struct rte_pv_struct;
|
||||
|
||||
ve_direct_error_reason rte_pv_last_error;
|
||||
|
||||
int16_t rte_pv_battery_current;
|
||||
uint16_t rte_pv_battery_voltage;
|
||||
uint16_t rte_pv_cell_voltage;
|
||||
|
|
|
@ -16,6 +16,8 @@ extern ve_direct_average_struct rte_pv_average;
|
|||
extern uint8_t rte_pv_sys_voltage;
|
||||
extern ve_direct_raw_struct rte_pv_struct;
|
||||
|
||||
extern ve_direct_error_reason rte_pv_last_error;
|
||||
|
||||
extern int16_t rte_pv_battery_current;
|
||||
extern uint16_t rte_pv_battery_voltage;
|
||||
extern uint16_t rte_pv_cell_voltage;
|
||||
|
|
|
@ -14,6 +14,10 @@
|
|||
|
||||
#include "./station_config.h"
|
||||
|
||||
#ifdef _VICTRON
|
||||
#include "ve_direct_protocol/parser.h"
|
||||
#endif
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -31,6 +35,8 @@ void telemetry_send_values_pv ( uint8_t rx_pkts,
|
|||
ms5611_qf_t ms_qf,
|
||||
dht22QF ds_qf);
|
||||
void telemetry_send_chns_description_pv(void);
|
||||
void telemetry_send_status(ve_direct_average_struct* avg, ve_direct_error_reason* last_error, ve_direct_system_state state);
|
||||
|
||||
#else
|
||||
void telemetry_send_values( uint8_t rx_pkts,
|
||||
uint8_t tx_pkts,
|
||||
|
@ -41,9 +47,10 @@ void telemetry_send_values( uint8_t rx_pkts,
|
|||
ms5611_qf_t ms_qf,
|
||||
dht22QF ds_qf);
|
||||
void telemetry_send_chns_description(void);
|
||||
#endif
|
||||
void telemetry_send_status(void);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -24,6 +24,10 @@ typedef __attribute__ ((aligned(1))) struct ve_direct_average_struct {
|
|||
|
||||
uint8_t full_buffer;
|
||||
|
||||
int16_t min_battery_current;
|
||||
|
||||
int16_t max_battery_current;
|
||||
|
||||
} ve_direct_average_struct;
|
||||
|
||||
|
||||
|
|
|
@ -28,6 +28,9 @@ int ve_direct_parse_to_raw_struct(uint8_t* input, uint16_t input_ln, ve_direct_r
|
|||
void ve_direct_add_to_average(ve_direct_raw_struct* in, ve_direct_average_struct* avg_struct);
|
||||
void ve_direct_get_averages(ve_direct_average_struct* avg_struct, int16_t* battery_current, uint16_t* battery_voltage, uint16_t* pv_voltage, uint16_t* load_current);
|
||||
void ve_direct_set_sys_voltage(ve_direct_raw_struct* in, uint8_t* sys_voltage);
|
||||
void ve_direct_store_errors(ve_direct_raw_struct* input, ve_direct_error_reason* err_reason);
|
||||
void ve_direct_error_to_string(ve_direct_error_reason input, char* output, int8_t output_ln);
|
||||
void ve_direct_state_to_string(ve_direct_system_state input, char* output, int8_t output_ln);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -10,7 +10,10 @@
|
|||
#include "station_config.h"
|
||||
#include "delay.h"
|
||||
|
||||
#include "ve_direct_protocol/parser.h"
|
||||
|
||||
#include <main.h>
|
||||
#include <stdio.h>
|
||||
|
||||
uint16_t telemetry_counter = 0;
|
||||
|
||||
|
@ -93,9 +96,9 @@ void telemetry_send_values_pv ( uint8_t rx_pkts,
|
|||
float phy_battery_voltage = 0.0f;
|
||||
float phy_pvcell_voltage = 0.0f;
|
||||
|
||||
phy_battery_current = raw_battery_current / 100;
|
||||
phy_battery_voltage = raw_battery_voltage / 100;
|
||||
phy_pvcell_voltage = raw_pv_cell_voltage / 100;
|
||||
phy_battery_current = (float)raw_battery_current / 1000.0f;
|
||||
phy_battery_voltage = (float)raw_battery_voltage / 1000.0f;
|
||||
phy_pvcell_voltage = (float)raw_pv_cell_voltage / 1000.0f;
|
||||
|
||||
scaled_battery_current = (uint8_t) roundf((phy_battery_current + 8.0f) * 14.2857f);
|
||||
scaled_battery_voltage = (uint8_t) roundf((phy_battery_voltage - 4.0f) * 14.2857f);
|
||||
|
@ -153,6 +156,21 @@ void telemetry_send_values_pv ( uint8_t rx_pkts,
|
|||
|
||||
}
|
||||
|
||||
void telemetry_send_status(ve_direct_average_struct* avg, ve_direct_error_reason* last_error, ve_direct_system_state state) {
|
||||
char string_buff_err[24], string_buff_state[23];
|
||||
|
||||
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), "> FwVersion %s BatAmpsMin %d BatAmpsMax %d %s %s", SW_VER, 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);
|
||||
|
||||
avg->max_battery_current = 0;
|
||||
avg->min_battery_current = 0;
|
||||
*last_error = ERR_UNINITIALIZED;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void telemetry_send_chns_description(void) {
|
||||
|
@ -292,8 +310,6 @@ void telemetry_send_values( uint8_t rx_pkts,
|
|||
afsk_txStart(&main_afsk);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void telemetry_send_status(void) {
|
||||
main_own_aprs_msg_len = sprintf(main_own_aprs_msg, ">ParaTNC firmware %s-%s by SP8EBC", SW_VER, SW_DATE);
|
||||
ax25_sendVia(&main_ax25, main_own_path, main_own_path_ln, main_own_aprs_msg, main_own_aprs_msg_len);
|
||||
|
@ -301,3 +317,7 @@ void telemetry_send_status(void) {
|
|||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -15,12 +15,17 @@
|
|||
#define LOWEST_PRINTABLE_CHARACTER 33
|
||||
#define HIGHEST_PRINTABLE_CHARACTER 126
|
||||
|
||||
#define VE_DIRECT_MESSAGES_TO_SKIP 2
|
||||
|
||||
#define is_non_printable_character() (*(input + i) < LOWEST_PRINTABLE_CHARACTER || *(input + i) > HIGHEST_PRINTABLE_CHARACTER)
|
||||
#define is_printable_character() (*(input + i) >= LOWEST_PRINTABLE_CHARACTER && *(input + i) <= HIGHEST_PRINTABLE_CHARACTER)
|
||||
|
||||
uint8_t key[9]; // the static array to store a key fetched from input file
|
||||
uint8_t value[12];
|
||||
|
||||
uint8_t skip_counter = 0; // counter used to skip some of VE.Direct protocol messages to spread an average over longer
|
||||
// period of time
|
||||
|
||||
//ve_direct_average_struct ve_avg;
|
||||
|
||||
static int copy_till_non_printable_char(uint8_t* input, uint16_t* input_offset, uint16_t input_ln, uint8_t* output, uint16_t output_ln) {
|
||||
|
@ -309,6 +314,13 @@ int ve_direct_parse_to_raw_struct(uint8_t* input, uint16_t input_ln, ve_direct_r
|
|||
|
||||
void ve_direct_add_to_average(ve_direct_raw_struct* in, ve_direct_average_struct* avg_struct) {
|
||||
|
||||
if (skip_counter++ < VE_DIRECT_MESSAGES_TO_SKIP) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
skip_counter = 0;
|
||||
}
|
||||
|
||||
uint16_t it = avg_struct->current_pointer;
|
||||
|
||||
avg_struct->battery_current[it] = in->battery_current;
|
||||
|
@ -328,6 +340,14 @@ void ve_direct_add_to_average(ve_direct_raw_struct* in, ve_direct_average_struct
|
|||
|
||||
avg_struct->current_pointer = it;
|
||||
|
||||
if (in->battery_current < avg_struct->min_battery_current) {
|
||||
avg_struct->min_battery_current = in->battery_current;
|
||||
}
|
||||
|
||||
if (in->battery_current > avg_struct->max_battery_current) {
|
||||
avg_struct->max_battery_current = in->battery_current;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
@ -359,3 +379,50 @@ void ve_direct_get_averages(ve_direct_average_struct* avg_struct, int16_t* batte
|
|||
void ve_direct_set_sys_voltage(ve_direct_raw_struct* in, uint8_t* sys_voltage) {
|
||||
|
||||
}
|
||||
|
||||
void ve_direct_store_errors(ve_direct_raw_struct* input, ve_direct_error_reason* err_reason) {
|
||||
if (input->error_reason != ERR_OK) {
|
||||
*err_reason = input->error_reason;
|
||||
}
|
||||
else {
|
||||
if (*err_reason == ERR_UNINITIALIZED || *err_reason == ERR_OK) {
|
||||
*err_reason = ERR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ve_direct_error_to_string(ve_direct_error_reason input, char* output, int8_t output_ln) {
|
||||
memset(output, 0x00, output_ln);
|
||||
|
||||
switch(input) {
|
||||
case ERR_UNINITIALIZED: snprintf(output, output_ln, "ERR_UNINITIALIZED"); break;
|
||||
case ERR_OK: snprintf(output, output_ln, "ERR_OK"); break;
|
||||
case ERR_EXCESIVE_BAT_VOLTAGE: snprintf(output, output_ln, "ERR_EXCESIVE_BAT_VOLTAGE"); break;
|
||||
case ERR_CHGR_TEMP_TOO_HIGH: snprintf(output, output_ln, "ERR_CHGR_TEMP_TOO_HIGH"); break;
|
||||
case ERR_CHGR_EXCESIVE_CURR: snprintf(output, output_ln, "ERR_CHGR_EXCESIVE_CURR"); break;
|
||||
case ERR_CHGR_CURR_REVERSED: snprintf(output, output_ln, "ERR_CHGR_CURR_REVERSED"); break;
|
||||
case ERR_BULK_TIME_EXCEED: snprintf(output, output_ln, "ERR_BULK_TIME_EXCEED"); break;
|
||||
case ERR_CURRENT_SENSE_FAIL: snprintf(output, output_ln, "ERR_CURRENT_SENSE_FAIL"); break;
|
||||
case ERR_EXCESIVE_TERMINAL_TEMP: snprintf(output, output_ln, "ERR_EXCESIVE_TERMINAL_TEMP"); break;
|
||||
case ERR_EXCESIVE_PV_VOLTAGE: snprintf(output, output_ln, "ERR_EXCESIVE_PV_VOLTAGE"); break;
|
||||
case ERR_EXCESIVE_PV_CURRENT: snprintf(output, output_ln, "ERR_EXCESIVE_PV_CURRENT"); break;
|
||||
case ERR_INPUT_SHUTDOWN: snprintf(output, output_ln, "ERR_INPUT_SHUTDOWN"); break;
|
||||
case ERR_TUNES_LOST: snprintf(output, output_ln, "ERR_TUNES_LOST"); break;
|
||||
}
|
||||
}
|
||||
|
||||
void ve_direct_state_to_string(ve_direct_system_state input, char* output, int8_t output_ln) {
|
||||
memset(output, 0x00, output_ln);
|
||||
|
||||
switch(input) {
|
||||
case STATE_UNINITIALIZED: snprintf(output, output_ln, "STATE_UNINITIALIZED"); break;
|
||||
case STATE_OFF: snprintf(output, output_ln, "STATE_OFF"); break;
|
||||
case STATE_LOW_PWR: snprintf(output, output_ln, "STATE_LOW_PWR"); break;
|
||||
case STATE_FAULT: snprintf(output, output_ln, "STATE_FAULT"); break;
|
||||
case STATE_BULK: snprintf(output, output_ln, "STATE_BULK"); break;
|
||||
case STATE_ABSORPTION: snprintf(output, output_ln, "STATE_ABSORPTION"); break;
|
||||
case STATE_FLOAT: snprintf(output, output_ln, "STATE_FLOAT"); break;
|
||||
case STATE_INVERTING: snprintf(output, output_ln, "STATE_INVERTING"); break;
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue