MX_UART4_Init();
MX_OCTOSPI1_Init();
MX_TIM1_Init();
- //MX_IWDG1_Init();
+ MX_IWDG1_Init();
MX_TIM3_Init();
/* USER CODE BEGIN 2 */
}
/* USER CODE BEGIN Callback 1 */
else if( htim->Instance == TIM3 ){
- extern void flow_total_update( uint32_t ms );
-#if 1
- flow_total_update( 1000 ); //1秒定时器触发
-#else
- static uint32_t cnt_1s = 0;
- cnts++; //1 毫秒定时器触发
- if( cnt_1s >= 1000 ){ //1000ms 计算一次累计流量
- flow_total_update( cnt );
- cnt_1s = 0;
- }
-#endif
+ osEventFlagsSet( g_dev.ev_group, EVENT_TIMER_1S );
}
/* USER CODE END Callback 1 */
}
#include "usart.h"
#include "usb_device.h"
#include "gpio.h"
+#include "user_lfs.h"
//#include "fmc.h"
//--------------------
#define APP_VER_MAJOR 3
#define EVENT_ADC1_UPDATE ( 1<<4) //ADC1 DMA采集完成
#define EVENT_ADC2_UPDATE ( 1<<5) //ADC2 DMA采集完成
#define EVENT_ADC3_UPDATE ( 1<<6) //ADC3 DMA采集完成
+#define EVENT_TIMER_1S ( 1<<7) //1秒定时器信息,用于保存累计流量和计算离线时间
//SPI FLASH 空间分配, 一共4M
//APP存储分区
char serial_number[32];
alarm_t alarm;
uint32_t hw_ver; //2 or 3
+ uint32_t has_bypass;
+
+ uint32_t offline_secs; //offline time;
}dev_info_t;
extern TIM_HandleTypeDef htim2; //htim2 用于触发DMA ADC采集
extern void debug_task_start( void );
extern void wifi_task_start( void );
extern void eth_task_start( void );
+
+extern void flow_total_update( uint32_t ms );
+extern void offline_time_update( uint32_t add_secs );
+
void ui_task_start_h3( void );
int32_t lcd_init_h3( void );
void beep_init( void );
dev_cfg_load( &g_dev.cfg );
dev_cfg_v2_load( &g_dev.cfg2 );
- lfs_load_device_serial( g_dev.serial_number, sizeof( g_dev.serial_number ) );
+ lfs_load_device_serial( g_dev.serial_number, sizeof( g_dev.serial_number ) );
+ g_dev.offline_secs = lfs_load_offline_time();
g_dev.ev_group = xEventGroupCreate();
- if( lcd_init_h3() == 0 )
+ if( lcd_init_h3() == 0 ){
g_dev.hw_ver = 3;
- else
+ g_dev.has_bypass = 0;
+ g_dev.cfg.bypass = 0;
+ g_dev.cfg.bypass_save = 0;
+ }else{
g_dev.hw_ver = 2;
+ g_dev.has_bypass = 1;
+ }
DBG_PRINTF( "WeldingController V%d.%d\n", APP_VER_MAJOR, APP_VER_MINOR );
adcTaskHandle = osThreadNew(user_adc_task, NULL, &adcTask_attributes);
void ui_task_start_h3( void );
ui_task_start_h3();
}else{
- g_dev.hw_ver = 2;
uiTaskHandle = osThreadNew(user_ui_task, NULL, &uiTask_attributes);
}
+ HAL_TIM_Base_Start_IT( &htim3 );
+ EventBits_t uxBits;
while(1){
- HAL_IWDG_Refresh( &hiwdg1 ); //4s iwdg
- osDelay(1000);
+ uxBits = xEventGroupWaitBits(
+ g_dev.ev_group, /* The event group being tested. */
+ EVENT_TIMER_1S, /* The bits within the event group to wait for. */
+ pdTRUE, /* BIT_x should be cleared before returning. */
+ pdFALSE, /* Don't wait for all bits, either bit will do. */
+ osWaitForever );/* Wait a maximum of xxx ms for either bit to be set. */
+
+ if( uxBits & EVENT_TIMER_1S ){
+ //debug_printf( "offline time:%d\n", g_dev.offline_secs );
+ flow_total_update( 1000 ); //1秒定时器触发
+ offline_time_update( 1 ); //离线更新,加1秒
+
+ HAL_IWDG_Refresh( &hiwdg1 ); //4s iwdg
+ }
}
}
uint32_t coeff = get_u32_big( &pkt->pdata[16] );
uint32_t bypass_save = get_u32_big( &pkt->pdata[20] );
uint32_t bypass = get_u32_big( &pkt->pdata[24] );
-
+
+ if( !g_dev.has_bypass ){
+ bypass = 0;
+ }
+
if( factor >=2 && factor <= 30 )
g_dev.cfg.save_gas_factor = factor;
if( method <3 )
resp[0] = 1;
tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 1 );
break;
-#if 0
- case 0xC2: //气路读取 1B 0:bypass_off, 1:bypass_on
- resp[0] = g_dev.cfg.bypass;
- tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 1 );
- break;
- case 0xC3: //气路选择 1B 0:bypass_off, 1:bypass_on
- if( pkt->pdata[0] == 1 || pkt->pdata[0] == 0 ){
- g_dev.cfg.bypass = pkt->pdata[0];
- dev_cfg_store( &g_dev.cfg );
- resp[0] = 1;
- lcd_update_cfg();
- }else{
- resp[0] = 0;
- }
- tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 1 );
- break;
-#endif
#endif
}
tick = xTaskGetTickCount();
while( client->connected==0 && xTaskGetTickCount() - tick < 5*1000 ){
+ osDelay(100);
}
if( client->connected > 0 ){
client->pcb = tpcb;
void flow_total_update( uint32_t ms )
{
- if( g_dev.flowmeter.flow_speed > 0 ){
- //debug_printf( "------ update flow total %0.1f -> ", g_flow_total );
+ if( g_dev.flowmeter.id == FLOWMETER_SMC && g_dev.flowmeter.flow_speed > 0 ){
g_flow_total += g_dev.flowmeter.flow_speed*ms/(60*1000.0f);
- //debug_printf( " %0.1f \n", g_flow_total );
}
}
float flow_comp;
float save_flow_total = 0;
- osDelay( 100 );
- save_flow_total = lfs_load_flow_total();
-
//检查流量计类型
g_dev.flowmeter.id = g_dev.cfg2.flowmeter;
debug_printf( "flowmeter task start, flowmeter:%d ...\n", g_dev.flowmeter );
if( g_dev.flowmeter.id== FLOWMETER_SMC ){
- //load flow_total
- g_flow_total = lfs_load_flow_total();
- g_dev.flowmeter.flow_total = g_flow_total;
-
- HAL_TIM_Base_Start_IT( &htim3 );
- }
-#if 0
- if( g_dev.flowmeter.id== FLOWMETER_AFM0750 ){
- //测试软件计算累计流量
+ //load flow_total from lfs
g_flow_total = lfs_load_flow_total();
g_dev.flowmeter.flow_total = g_flow_total;
- HAL_TIM_Base_Start_IT( &htim3 );
}
-#endif
if( g_dev.flowmeter.id == FLOWMETER_MF4008 ){
//MF4008 检查修正系数, 只开机检查, 如果通过上位机修改参数,需要重启系统。
g_dev.flowmeter.tem = reg_values[3]/10.0f;
g_dev.flowmeter.state = reg_values[4];
flow_err = 0;
-#if 0
- total_raw = g_flow_total; //for test
-#endif
+
}else{
flow_err ++; //读取失败, 故障计数到10次报错
}
g_dev.flowmeter.flow_speed = flow_raw;
g_dev.flowmeter.flow_total = total_raw;
- if( g_dev.flowmeter.id == FLOWMETER_SMC || g_dev.flowmeter.id == FLOWMETER_AFM0750 ){
+ if( g_dev.flowmeter.id == FLOWMETER_SMC ){
static int n = 0;
if( n++ >= 100 ){ //10秒 保存一次
n = 0;
{
return user_lfs_write( DEVICE_SN_PATH, (uint8_t*)sn, strlen( sn ) ) == strlen(sn)?0:-1;
}
+
+uint32_t lfs_load_offline_time( void )
+{
+ uint32_t secs = 0;
+
+ if( user_lfs_read( OFFLINE_TIME_PATH, (uint8_t*)&secs, sizeof( secs ) ) == sizeof( secs ) ){
+
+ }
+ return secs;
+}
+
+int32_t lfs_store_offline_time( uint32_t secs )
+{
+ int32_t ret = -1;
+
+ if( user_lfs_write( OFFLINE_TIME_PATH, (uint8_t*)&secs, sizeof( secs ) ) == sizeof( secs ) ){
+ ret = 0;
+ }
+ return ret;
+}
\ No newline at end of file
#include "lfs.h"
-#define FLOW_TOTAL_PATH "flowmeter_total"
+#define FLOW_TOTAL_PATH "flow_total"
+#define OFFLINE_TIME_PATH "offline_time"
#define DEVICE_SN_PATH "device_serial"
#define DEVICE_CONFIG_PATH "device_config"
#define DEVICE_CONFIG_V2_PATH "device_config_v2"
int32_t lfs_store_flow_total( float total );
int32_t lfs_load_device_serial( char *read_buffer, uint32_t buffer_size );
int32_t lfs_store_device_serial( char *sn );
-
+uint32_t lfs_load_offline_time( void );
+int32_t lfs_store_offline_time( uint32_t secs );
#endif //__USER_LFS_H__
#endif
+void offline_time_update( uint32_t add_secs )
+ {
+ static uint32_t n = 0;
+ if( g_dev.wifi_connected == 2 || g_dev.eth_connected == 2 ){
+ //在线
+ if( g_dev.offline_secs != 0 ){
+ g_dev.offline_secs = 0;
+ lfs_store_offline_time( 0 );
+ }
+ n = 0;
+ return;
+ }else{
+ //离线,更新离线时间
+ g_dev.offline_secs += add_secs;
+ if( n++ > 60 ){ //1分钟保存一次
+ n = 0;
+ //这个timer中断中调用,不能调用文件系统读写操作
+ lfs_store_offline_time( g_dev.offline_secs );
+ }
+ }
+}
+
static void mac_str_init( void )
{
uint8_t mac[6];
}else if( ctrl_addr == lcd_valve_bypass_addr ){//比例阀旁路
uint8_t bypass = ctrl_value;
//g_dev.ui_bypass = bypass;
+ if( !g_dev.has_bypass )
+ bypass = 0;
g_dev.cfg.bypass = bypass;
dev_cfg_store( &g_dev.cfg );
}else if( ctrl_addr == lcd_wifi_config_addr ){ //点击配置按钮
void lcd_power_on( void )
{
- if( g_dev.hw_ver != 3 ){
+ if( g_dev.hw_ver == 2 ){
HAL_GPIO_WritePin( LCM_EN_GPIO_Port, LCM_EN_Pin, GPIO_PIN_SET );
}
}
void lcd_power_off( void )
{
- if( g_dev.hw_ver != 3 ){
+ if( g_dev.hw_ver == 2 ){
HAL_GPIO_WritePin( LCM_EN_GPIO_Port, LCM_EN_Pin, GPIO_PIN_RESET );
}
}
// welding_data_store( g_dev.welding_time/100 );
}
- if( g_dev.cfg.bypass || tem_err_state ){
- //屏上点击旁路或温度故障,开启旁路
- valve_bypass( 1 ); //旁路电磁阀开启
- g_dev.valve_curr_out = 0; //比例电磁阀关闭
- }else if( !g_dev.cfg.bypass && !tem_err_state ){
- //恢复正常,关闭旁路
- valve_bypass( 0 ); //旁路电磁阀关闭
- }
+ if( g_dev.has_bypass){
+ if( g_dev.cfg.bypass || tem_err_state ){
+ //屏上点击旁路或温度故障,开启旁路
+ valve_bypass( 1 ); //旁路电磁阀开启
+ g_dev.valve_curr_out = 0; //比例电磁阀关闭
+ }else{
+ //恢复正常,关闭旁路
+ valve_bypass( 0 ); //旁路电磁阀关闭
+ }
+ }
//更新比例阀驱动电流
user_valve_set_current( g_dev.valve_curr_out );
if( now - alarm_start > 10*1000 ){
//计时到10秒,开直通阀
alarm = 3;
- if( g_dev.cfg.bypass == 0 ){
+ if( g_dev.cfg.bypass == 0 && g_dev.has_bypass ){
g_dev.cfg.bypass = 1;
ui_cfg_remote_update(); //刷新lcd
}