kopia lustrzana https://github.com/SP8EBC/ParaTNC
dust sensor sketch
rodzic
f9df2f7cf0
commit
bd8b738ff8
|
@ -43,6 +43,9 @@ typedef struct __attribute__((aligned (4))) config_data_mode_t {
|
|||
|
||||
#define WX_MODBUS_DEBUG (1 << 1)
|
||||
|
||||
#define WX_DUST_SDS011_PWM (1 << 1)
|
||||
#define WX_DUST_SDS011_SERIAL (1 << 2)
|
||||
|
||||
uint8_t digi;
|
||||
|
||||
uint8_t wx;
|
||||
|
@ -57,6 +60,8 @@ typedef struct __attribute__((aligned (4))) config_data_mode_t {
|
|||
|
||||
uint8_t wx_anemometer_pulses_constant; // #define _ANEMOMETER_PULSES_IN_10SEC_PER_ONE_MS_OF_WINDSPEED 10
|
||||
|
||||
uint8_t wx_dust_sensor;
|
||||
|
||||
uint8_t victron;
|
||||
|
||||
uint8_t digi_viscous;
|
||||
|
|
|
@ -19,7 +19,7 @@ typedef enum configuration_handler_region_t {
|
|||
typedef enum configuration_erase_startup_t {
|
||||
ERASE_STARTUP_IDLE = 0xAA,
|
||||
ERASE_STARTUP_PENDING = 0xAB,
|
||||
ERASE_STARTUP_ERASED = 0xAC,
|
||||
ERASE_STARTUP_DONE = 0xAC,
|
||||
ERASE_STARTUP_ERROR = 0xAD
|
||||
}configuration_erase_startup_t;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "config_data.h"
|
||||
|
||||
#define SW_VER "EA16"
|
||||
#define SW_DATE "20082022"
|
||||
#define SW_DATE "17092022"
|
||||
#define SW_KISS_PROTO "A"
|
||||
|
||||
#define SYSTICK_TICKS_PER_SECONDS 100
|
||||
|
|
|
@ -670,7 +670,7 @@ configuration_erase_startup_t configuration_handler_erase_startup(void) {
|
|||
FLASH_Lock();
|
||||
|
||||
if (flash_status == FLASH_COMPLETE) {
|
||||
return ERASE_STARTUP_ERASED;
|
||||
return ERASE_STARTUP_DONE;
|
||||
}
|
||||
else {
|
||||
return ERASE_STARTUP_ERROR;
|
||||
|
@ -714,13 +714,13 @@ configuration_erase_startup_t configuration_handler_program_startup(uint8_t * da
|
|||
comparision_result = memcmp((const void * )target, (const void * )source, dataln);
|
||||
|
||||
if (comparision_result == 0) {
|
||||
return ERASE_STARTUP_ERASED;
|
||||
return ERASE_STARTUP_DONE;
|
||||
}
|
||||
else {
|
||||
return ERASE_STARTUP_ERROR;
|
||||
}
|
||||
|
||||
return ERASE_STARTUP_ERASED;
|
||||
return ERASE_STARTUP_DONE;
|
||||
}
|
||||
else {
|
||||
return ERASE_STARTUP_ERROR;
|
||||
|
|
44
src/main.c
44
src/main.c
|
@ -664,9 +664,18 @@ int main(int argc, char* argv[]){
|
|||
rtu_serial_start();
|
||||
}
|
||||
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);
|
||||
if ((main_config_data_mode->wx_dust_sensor & WX_DUST_SDS011_SERIAL) > 0) {
|
||||
srl_init(main_kiss_srl_ctx_ptr, USART1, srl_usart1_rx_buffer, RX_BUFFER_1_LN, srl_usart1_tx_buffer, TX_BUFFER_1_LN, 9600u, 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);
|
||||
|
||||
// disable kiss as UART will be now used for dust sensor
|
||||
main_kiss_enabled = 0;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(STM32F10X_MD_VL)
|
||||
|
@ -850,8 +859,13 @@ int main(int argc, char* argv[]){
|
|||
srl_receive_data(main_kiss_srl_ctx_ptr, 100, FEND, FEND, 0, 0, 0);
|
||||
}
|
||||
#else
|
||||
// switching UART to receive mode to be ready for KISS frames from host
|
||||
srl_receive_data(main_kiss_srl_ctx_ptr, 100, FEND, FEND, 0, 0, 0);
|
||||
if (main_kiss_enabled == 1) {
|
||||
// switching UART to receive mode to be ready for KISS frames from host
|
||||
srl_receive_data(main_kiss_srl_ctx_ptr, 100, FEND, FEND, 0, 0, 0);
|
||||
}
|
||||
else {
|
||||
srl_receive_data(main_kiss_srl_ctx_ptr, 10, 0xAA, 0, 0, 0, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
io_oc_output_low();
|
||||
|
@ -928,9 +942,11 @@ int main(int argc, char* argv[]){
|
|||
}
|
||||
}
|
||||
|
||||
pwm_input_io_init();
|
||||
if ((main_config_data_mode->wx_dust_sensor & WX_DUST_SDS011_PWM) > 0) {
|
||||
pwm_input_io_init();
|
||||
|
||||
pwm_input_init(1);
|
||||
pwm_input_init(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (main_config_data_basic-> beacon_at_bootup == 1) {
|
||||
|
@ -1010,7 +1026,7 @@ int main(int argc, char* argv[]){
|
|||
}
|
||||
|
||||
// reinitialize APRS radio modem to clear all possible intermittent state caused by
|
||||
// switching power state in the middle of reception APRS packet
|
||||
// switching power state in the middle of APRS packet reception
|
||||
ax25_new_msg_rx_flag = 0;
|
||||
main_ax25.dcd = false;
|
||||
|
||||
|
@ -1110,6 +1126,14 @@ int main(int argc, char* argv[]){
|
|||
}
|
||||
#endif
|
||||
}
|
||||
else if ((main_config_data_mode & WX_DUST_SDS011_SERIAL) > 0) {
|
||||
if (main_kiss_srl_ctx_ptr->srl_rx_state == SRL_RX_DONE) {
|
||||
|
||||
// restart reception
|
||||
srl_receive_data(main_kiss_srl_ctx_ptr, 10, 0xAA, 0, 0, 0, 0);
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
// if new KISS message has been received from the host
|
||||
if (main_kiss_srl_ctx_ptr->srl_rx_state == SRL_RX_DONE && main_kiss_enabled == 1) {
|
||||
|
@ -1361,7 +1385,9 @@ int main(int argc, char* argv[]){
|
|||
pwr_save_pooling_handler(main_config_data_mode, main_config_data_basic, packet_tx_get_minutes_to_next_wx(), rte_main_average_battery_voltage);
|
||||
}
|
||||
|
||||
pwm_input_pool();
|
||||
if (main_config_data_mode->wx_dust_sensor & WX_DUST_SDS011_PWM > 0) {
|
||||
pwm_input_pool();
|
||||
}
|
||||
|
||||
if (pwm_first_channel != 0) {
|
||||
rte_wx_pm2_5 = pwm_first_channel;
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* sds011.h
|
||||
*
|
||||
* Created on: Sep 16, 2022
|
||||
* Author: mateusz
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_DUST_SENSOR_SDS011_H_
|
||||
#define INCLUDE_DUST_SENSOR_SDS011_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
int sds011_get_pms(uint8_t * data, uint16_t data_ln, uint16_t * pm_10, uint16_t * pm_2_5);
|
||||
|
||||
#endif /* INCLUDE_DUST_SENSOR_SDS011_H_ */
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* sds011.c
|
||||
*
|
||||
* Created on: Sep 16, 2022
|
||||
* Author: mateusz
|
||||
*/
|
||||
|
||||
#include "dust_sensor/sds011.h"
|
||||
|
||||
int sds011_get_pms(uint8_t * data, uint16_t data_ln, uint16_t * pm_10, uint16_t * pm_2_5) {
|
||||
|
||||
if (pm_10 == 0 || pm_2_5 == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint16_t local_checksum = 0;
|
||||
|
||||
// values received from sensor
|
||||
uint8_t head = *(data + 0);
|
||||
uint8_t command_id = *(data + 1);
|
||||
uint8_t checksum = *(data + 9);
|
||||
|
||||
// calculate checksum
|
||||
for (int i = 2; i < 9; i++) {
|
||||
local_checksum += *(data + i);
|
||||
}
|
||||
|
||||
if ((local_checksum & 0xFF) != checksum) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
local_checksum = *(data + 1) | (*(data + 2) << 8);
|
||||
*pm_2_5 = local_checksum;
|
||||
|
||||
local_checksum = *(data + 4) | (*(data + 5) << 8);
|
||||
*pm_10 = local_checksum;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
Ładowanie…
Reference in New Issue