<FileType>1</FileType>
<FilePath>..\user\user_filter.c</FilePath>
</File>
- <File>
- <FileName>user_temperture.c</FileName>
- <FileType>1</FileType>
- <FilePath>..\user\user_temperture.c</FilePath>
- </File>
<File>
<FileName>user_lora.c</FileName>
<FileType>1</FileType>
<FileType>1</FileType>
<FilePath>..\user\user_alarm_sound.c</FilePath>
</File>
+ <File>
+ <FileName>user_wind_sensor.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>..\user\user_wind_sensor.c</FilePath>
+ </File>
</Files>
</Group>
<Group>
#define SW_VER_MAJOR 1
#define SW_VER_MINOR 0
+#define USER_SHELL_USE_UART1 0
+#define WIND_SENSOR_USE_UART1 1
+
typedef osMutexId_t user_lock_t;
int8_t state;
float db;
}noise_t;
+
+typedef struct{
+ int8_t state; //0:normal, 1:strength err 2:direction err
+ float strength;
+ float direction;
+}wind_t;
+
typedef struct{
int8_t state;
float freq;
}sound_t;
+
typedef struct{
bd_state_t state;
float lat;
noise_t noise;
sound_t sound;
position_t pos;
+ wind_t wind;
}sensor_info_t;
typedef struct{
//
void user_noise_info_update( float db, int8_t state );
+void user_wind_info_update( float strength, float direction, int8_t state );
void user_sound_info_update( float freq, int8_t state );
void user_position_update( float lat, float lon, bd_state_t state );
void user_sensor_info_read( sensor_info_t *info );
extern UART_HandleTypeDef huart1;
extern int g_adc_debug;
-static uint16_t freq_list[1024];
-static uint16_t amp_list[1024];
-static uint32_t num = 0;
+//static uint16_t freq_list[1024];
+//static uint16_t amp_list[1024];
+//static uint32_t num = 0;
extern int alarm_data_add( uint16_t in_freq, uint16_t in_amp );
extern int DetectAlarm( void );
int adc_debug( int enable )
{
g_adc_debug = enable;
+ return 0;
}
extern void init_fft(void);
extern void user_noise_task_start( void );
extern void user_bd_task_start( void );
extern void user_lora_task_start( void );
+extern void user_wind_task_start( void );
extern void bd_rx_cb( void );
extern void shell_uart_rx_cb( void );
extern void lora_rx_cb( void );
+extern void user_rs485_rx_cb( void );
extern uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len);
extern uint32_t adc_finished;
{
if( huart->Instance == USART1 ){
//USART1 debug shell
+#if USER_SHELL_USE_UART1
shell_uart_rx_cb();
+#elif WIND_SENSOR_USE_UART1
+ user_rs485_rx_cb();
+#endif
}else if( huart->Instance == USART2 ){
//USART2 BD Tx/Rx
int fputc( int ch, FILE *fd )
{
+#if USER_SHELL_USE_UART1
+
+#elif WIND_SENSOR_USE_UART1
+
+#else
HAL_UART_Transmit( &huart1, (uint8_t*)&ch, 1, 100 );
+#endif
return 0;
}
user_unlock( g_dev.lock );
}
+void user_wind_info_update( float strength, float direction, int8_t state )
+{
+ user_lock( g_dev.lock );
+ g_dev.sensor.wind.strength = strength;
+ g_dev.sensor.wind.direction = direction;
+ g_dev.sensor.wind.state = state;
+ user_unlock( g_dev.lock );
+}
+
void user_sound_info_update( float freq, int8_t state )
{
user_lock( g_dev.lock );
HAL_GPIO_WritePin( PB15_ETH_RESET_GPIO_Port, PB15_ETH_RESET_Pin, GPIO_PIN_RESET );
osDelay( 100 );
HAL_GPIO_WritePin( PB15_ETH_RESET_GPIO_Port, PB15_ETH_RESET_Pin, GPIO_PIN_SET );
-
+
MX_LWIP_Init();
Tcp_Server_Init();
user_sound_task_start();
user_lora_task_start();
user_bd_task_start();
+ user_wind_task_start();
delay_ticks = xTaskGetTickCount();
for(;;)
#define BLOCK_SIZE 1 /* µ÷ÓÃÒ»´Îarm_fir_f32´¦ÀíµÄ²ÉÑùµã¸öÊý */
#define NUM_TAPS 21 /* Â˲¨Æ÷ϵÊý¸öÊý */
-static float32_t testInput[TEST_LENGTH_SAMPLES]; /* ²ÉÑùµã */
-static float32_t testOutput[TEST_LENGTH_SAMPLES]; /* Â˲¨ºóµÄÊä³ö */
+//static float32_t testInput[TEST_LENGTH_SAMPLES]; /* ²ÉÑùµã */
+//static float32_t testOutput[TEST_LENGTH_SAMPLES]; /* Â˲¨ºóµÄÊä³ö */
static float32_t firStateF32[BLOCK_SIZE + NUM_TAPS - 1]; /* ״̬»º´æ£¬´óСnumTaps + blockSize - 1*/
{
uint32_t i;
arm_fir_instance_f32 S;
- float32_t *inputF32, *outputF32;
+// float32_t *inputF32, *outputF32;
/* ³õʼ»¯ÊäÈëÊä³ö»º´æÖ¸Õë */
- inputF32 = &testInput[0];
- outputF32 = &testOutput[0];
+// inputF32 = &testInput[0];
+// outputF32 = &testOutput[0];
/* ³õʼ»¯½á¹¹ÌåS */
arm_fir_init_f32(&S,
{
bd_log_flag = on;
printf( "bd log out %s\n", on?"enable":"disable" );
+ return 0;
}
void bd_parse( void )
#include <main.h>
#include "user.h"
-extern void user_noise_update( float noise, int8_t state );
-
-static float noise_value = 0;
static int8_t noise_state = 0;
static uint8_t recv_byte;
if( tcp_connected_pcb ){
for( int i=0; i<5; i++ ){
- err = tcp_write( tcp_connected_pcb, data, data_sz, 0); //TCP_WRITE_FLAG_COPY
+ err = (err_enum_t)tcp_write( tcp_connected_pcb, data, data_sz, 0); //TCP_WRITE_FLAG_COPY
if( err == ERR_OK ){
ret = 0;
tcp_output( tcp_connected_pcb );
55AA 0002 0001 0008 XX... XXXX
CMD:
0001: query LEN 0 query period:5s
- 0002: resp LEN 8 , DATA: noise + alarm
+ 0002: resp LEN 32 , DATA: noise + alarm + pos + wind
1001: Lora Tx
1002: Lora Rx
2001: BD Tx
resp_data[10] = sensor.pos.state;
memcpy( &resp_data[11], &sensor.pos.lat, 4 );
memcpy( &resp_data[15], &sensor.pos.lon, 4 );
- memset( &resp_data[19], 0, 13 );
+ resp_data[19] = sensor.wind.state;
+ memcpy( &resp_data[20], &sensor.wind.strength, 4 );
+ memcpy( &resp_data[24], &sensor.wind.direction, 4 );
+ memset( &resp_data[28], 0, 4 );
resp_sz = wrap_pkt( resp, rx_pkt_sn, 0x0101, resp_data, 32 );
break;
case 0x0003: //lora transmit
+++ /dev/null
-
-#include "user.h"
-
-#if 0
-
-/*
-ÅäÖÃTIM3µÄCOUNTER À´×ö¼ÆÊ± µ¥Î»us¡£
-GPIO PE3 ÅäÖÃΪÖжϴ¥·¢£¬ÖжϺ¯ÊýÖмǼ¸ßµçƽ±£³Öʱ¼ä
-
-¶ÁȡָÁ ·¢ËÍÆô¶¯Ö¸ÁÆô¶¯TIM3 Æô¶¯IOÖжϣ¬ÖжÏÖжÁÈ¡TIM3µÄcounter¼Ä´æÆ÷£¬¼Ç¼¸ßµçƽ±£³Öʱ¼ä
-¶ÁȡָÁîºóÑÓ³Ù10ms £¬¼ì²é¼Ç¼Êý¾Ý£¬½âÎöζÈÄ£¿éµÄ»ØÓ¦±¨ÎÄÀ´»ñÈ¡ÎÂʪ¶ÈÊý¾Ý
-*/
-
-extern TIM_HandleTypeDef htim3;
-
-int user_temperature_read( float *tem, float * hum );
-
-static void temp_read_start( void );
-static void temp_read_stop( void );
-
-static float s_tem;
-static float s_hum;
-
-struct tem_bit{
- uint8_t h_us;
-};
-
-struct tem_bit tem_bit_data[ 50 ]; //ack + bit x 40 + end
-int tem_bit_count;
-
-
-void tem_int_cb( void )
-{
- int us;
- int level;
-
- level = HAL_GPIO_ReadPin( DQ_IN_GPIO_Port, DQ_IN_Pin )==GPIO_PIN_SET?1:0;
- us = __HAL_TIM_GET_COUNTER( &htim3 );
-
- if( tem_bit_count > 42 )
- return;
-
- if( level==0 ){
- tem_bit_data[tem_bit_count].h_us = us;
- }else{
- tem_bit_count++;
- }
-
- __HAL_TIM_SET_COUNTER( &htim3, 0 );
-}
-
-void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
-{
- if( GPIO_Pin==DQ_IN_Pin ){
- tem_int_cb();
- }
-}
-
-void tem_pin_cfg_out( int level )
-{
- GPIO_InitTypeDef GPIO_InitStruct = {0};
-
- HAL_NVIC_DisableIRQ(EXTI3_IRQn);
- HAL_GPIO_WritePin(SYS_LED_GPIO_Port, SYS_LED_Pin, GPIO_PIN_RESET);
-
- /*Configure GPIO pin : DQ_IN_Pin */
- GPIO_InitStruct.Pin = DQ_IN_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(DQ_IN_GPIO_Port, &GPIO_InitStruct);
-
-
-}
-
-void tem_pin_cfg_input( void )
-{
- GPIO_InitTypeDef GPIO_InitStruct = {0};
-
- /*Configure GPIO pin : DQ_IN_Pin */
- GPIO_InitStruct.Pin = DQ_IN_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(DQ_IN_GPIO_Port, &GPIO_InitStruct);
- __HAL_GPIO_EXTI_CLEAR_IT(DQ_IN_Pin);
-
-}
-
-void temp_read_start( void )
-{
- tem_pin_cfg_out( 0 );
- osDelay(20);
- tem_pin_cfg_input();
-
- tem_bit_count = 0;
- __HAL_TIM_SET_COUNTER( &htim3, 0 );
- HAL_TIM_Base_Start( &htim3 );
-
- HAL_NVIC_SetPriority(EXTI3_IRQn, 5, 0);
- HAL_NVIC_EnableIRQ(EXTI3_IRQn);
-}
-
-void temp_read_stop( void )
-{
- HAL_NVIC_DisableIRQ(EXTI3_IRQn);
- HAL_TIM_Base_Stop( &htim3 );
- __HAL_TIM_SET_COUNTER( &htim3, 0 );
-
-}
-
-int user_temperature_read( float *tem, float * hum )
-{
- temp_read_start();
- osDelay(10*100);
- temp_read_stop();
-
- if( tem_bit_count > 42 ){
-
- *tem = s_tem;
- *hum = s_hum;
- return 0;
- }
- return -1;
-}
-
-#endif
--- /dev/null
+
+#include "user.h"
+
+extern UART_HandleTypeDef huart1;
+
+#define WIND_STRENGTH_ADDR 1
+#define WIND_DIRECTION_ADDR 2
+#define WIND_SENSOR_BAUD 9600
+
+/******************************************************************************************
+·çËÙ/·çÏò´«¸ÐÆ÷ĬÈϲÎÊý µØÖ·1 ²¨ÌØÂÊ 4800
+
+д«¸ÐÆ÷ͨ¹ýPC¹¤¾ßÅäÖòÎÊý
+1. ·çËÙ´«¸ÐÆ÷ µØÖ· 1 ²¨ÌØÂÊ 9600
+2. ·çÏò´«¸ÐÆ÷ µØÖ· 2 ²¨ÌØÂÊ 9600
+
+·çËÙ´«¸ÐÆ÷ ¼Ä´æÆ÷0 µ¥Î» 0.1 m/s
+·çÏò´«¸ÐÆ÷ ¼Ä´æÆ÷0 µ¥Î» 0.1 ¶È
+******************************************************************************************/
+
+static void wind_sensor_uart_init( void )
+{
+ huart1.Instance = USART1;
+ huart1.Init.BaudRate = WIND_SENSOR_BAUD;
+ huart1.Init.WordLength = UART_WORDLENGTH_8B;
+ huart1.Init.StopBits = UART_STOPBITS_1;
+ huart1.Init.Parity = UART_PARITY_NONE;
+ huart1.Init.Mode = UART_MODE_TX_RX;
+ huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
+ huart1.Init.OverSampling = UART_OVERSAMPLING_16;
+ if (HAL_UART_Init(&huart1) != HAL_OK)
+ {
+ Error_Handler();
+ }
+
+}
+
+static int32_t rs485_rx_flag = 0;
+void user_rs485_rx_cb( void )
+{
+ rs485_rx_flag = 1;
+}
+
+int32_t rs485_tx( uint8_t *data, uint16_t sz )
+{
+ uint8_t dummy;
+
+ while( HAL_UART_Receive( &huart1, &dummy, 1, 0 ) == HAL_OK){
+ };
+
+ HAL_UART_Transmit( &huart1, data, sz, 100 );
+
+ return 0;
+}
+
+int32_t rs485_rx( uint8_t *rx_data, uint8_t rx_n, uint32_t timeout_ms )
+{
+ uint32_t tick;
+ rs485_rx_flag = 0;
+ tick = xTaskGetTickCount();
+
+ if( HAL_UART_Receive_IT( &huart1, rx_data, rx_n ) != HAL_OK){
+ return -1;
+ };
+ while( xTaskGetTickCount() - tick < timeout_ms && !rs485_rx_flag){
+ osDelay(2);
+ }
+ if( !rs485_rx_flag ){
+ HAL_UART_AbortReceive_IT(&huart1);
+ }
+ return rs485_rx_flag?0:-1;
+}
+
+int32_t mb_master_write_reg( uint8_t device_addr, uint16_t reg, uint16_t reg_value )
+{
+ uint8_t cmd[16];
+ uint16_t crc;
+ uint16_t n = 0;
+ //int32_t rx_n;
+
+ cmd[n++] = device_addr;
+ cmd[n++] = 0x06;
+ cmd[n++] = (reg>>8)&0xff;
+ cmd[n++] = reg &0xff;
+ cmd[n++] = (reg_value>>8)&0xff;
+ cmd[n++] = reg_value &0xff;
+ crc = usMBCRC16( cmd, n );
+ cmd[n++] = crc &0xff;
+ cmd[n++] = (crc>>8)&0xff;
+
+ uint8_t rx_data[50];
+ rs485_tx( cmd, n );
+ if( rs485_rx( rx_data, 8, 200 ) == 0 ){
+ }else{
+ //printf( "rx err!\n" );
+ }
+ return 0;
+}
+
+
+int32_t mb_master_read_regs( uint8_t device_addr, uint16_t reg, uint16_t* reg_values, uint16_t reg_nr )
+{
+ uint8_t cmd[16];
+ uint16_t crc;
+ uint16_t n = 0;
+ int32_t rx_n;
+
+ cmd[n++] = device_addr;
+ cmd[n++] = 0x03;
+ cmd[n++] = (reg>>8)&0xff;
+ cmd[n++] = reg &0xff;
+ cmd[n++] = (reg_nr>>8)&0xff;
+ cmd[n++] = reg_nr &0xff;
+ crc = usMBCRC16( cmd, n );
+ cmd[n++] = crc &0xff;
+ cmd[n++] = (crc>>8)&0xff;
+
+ uint8_t rx_data[50];
+ memset( rx_data, 0x55, 20 );
+ rs485_tx( cmd, n );
+ rx_n = reg_nr*2+5;
+ if( rs485_rx( rx_data, rx_n, 200 ) == 0 ){
+ if( rx_data[0] == device_addr && rx_data[1] == 3 && rx_data[2] == reg_nr*2 ){
+ //check modbus-crc
+ if( usMBCRC16( rx_data, rx_n-2 ) == rx_data[rx_n-2]| ( rx_data[rx_n-1]<<8) ){
+ for( int i=0; i<reg_nr; i++ ){
+ reg_values[i] = (rx_data[i*2+3]<<8)|rx_data[i*2+4];
+ }
+ return 0;
+ }
+ }
+ }else{
+ //printf( "rx err!\n" );
+ }
+ return -1;
+}
+
+void user_wind_sensor_init( void )
+{
+ wind_sensor_uart_init();
+}
+
+int32_t user_wind_strength_read( float *strength )
+{
+ uint16_t reg_value;
+ if( mb_master_read_regs( 1, 0, ®_value, 1 ) == 0 ){
+ if( strength )
+ *strength = reg_value/10.0f;
+ return 0;
+ }else{
+ return -1;
+ }
+}
+
+int32_t user_wind_direction_read( float *direction )
+{
+ uint16_t reg_value;
+ if( mb_master_read_regs( 2, 0, ®_value, 1 ) == 0 ){
+ if( direction )
+ *direction = reg_value/10.0f;
+ return 0;
+ }else{
+ return -1;
+ }
+}
+
+static void user_wind_task(void *argument)
+{
+ float strength;
+ float direction;
+ int32_t strength_err=0;
+ int32_t direction_err=0;
+ int8_t wind_state = 0;
+
+ user_wind_sensor_init();
+
+ while(1){
+
+ osDelay(2000);
+ strength = 0;
+ direction = 0;
+
+ if( user_wind_strength_read( &strength ) == 0 ){
+ strength_err = 0;
+ //user_noise_info_update( noise, noise_state );
+ //printf( "noise db:%.1f ...\n", noise );
+ }else{
+ strength_err++;
+ }
+ osDelay(2000);
+ //printf( "wind direction read ...\n" );
+ if( user_wind_direction_read( &direction ) == 0 ){
+ direction_err = 0;
+ //user_noise_info_update( noise, noise_state );
+ //printf( "noise db:%.1f ...\n", noise );
+ }else{
+ direction_err++;
+ }
+
+ wind_state = 0;
+ wind_state = ( strength_err > 10 )?1:0;
+ wind_state = ( strength_err > 10 )?2:0;
+ user_wind_info_update( strength, direction, wind_state );
+ }
+}
+
+/* Definitions for defaultTask */
+osThreadId_t windTaskHandle;
+const osThreadAttr_t windTask_attributes = {
+ .name = "windTask",
+ .stack_size = 1024,
+ .priority = (osPriority_t) osPriorityNormal,
+};
+
+void user_wind_task_start( void )
+{
+ windTaskHandle = osThreadNew(user_wind_task, NULL, &windTask_attributes);
+}
+
#include "user.h"
#include "shell.h"
-#define SW_VER_MAJOR 1
-#define SW_VER_MINOR 2
-
extern UART_HandleTypeDef huart1;
#define huart_shell huart1
static uint32_t shell_rx_rd;
static uint8_t shell_rx_byte;
-static uint8_t uart_rx_flag;
void shell_uart_rx_start( void )
{
void user_shell_start( void )
{
+#if USER_SHELL_USE_UART1
shellTaskHandle = osThreadNew(user_shell_task, NULL, &shellTask_attributes);
+#endif
}