diff --git a/.cproject b/.cproject
index fcc79fc..63ababa 100644
--- a/.cproject
+++ b/.cproject
@@ -30,6 +30,7 @@
+
diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml
index c0c67e3..a98bafb 100644
--- a/.settings/language.settings.xml
+++ b/.settings/language.settings.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 95b1834..b856409 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -100,7 +100,12 @@
"fatfs.h": "c",
"stm32f4xx.h": "c",
"stm32f407xx.h": "c",
- "cstring": "cpp"
+ "cstring": "cpp",
+ "ff_gen_drv.h": "c",
+ "ff.h": "c",
+ "usbh_diskio.h": "c",
+ "ffconf.h": "c",
+ "integer.h": "c"
},
"files.autoGuessEncoding": false,
"files.encoding": "gb2312"
diff --git a/Core b/Core
index 41922cf..aaf9093 160000
--- a/Core
+++ b/Core
@@ -1 +1 @@
-Subproject commit 41922cfe8ea480cafe9b982f2f204a07ee88a9a7
+Subproject commit aaf909385c23f3ed678ad802aa9850f3be487922
diff --git a/FATFS/App/fatfs.c b/FATFS/App/fatfs.c
index 4ab4014..aa549d6 100644
--- a/FATFS/App/fatfs.c
+++ b/FATFS/App/fatfs.c
@@ -1,34 +1,33 @@
/* USER CODE BEGIN Header */
/**
- ******************************************************************************
- * @file fatfs.c
- * @brief Code for fatfs applications
- ******************************************************************************
- * @attention
- *
- * Copyright (c) 2024 STMicroelectronics.
- * All rights reserved.
- *
- * This software is licensed under terms that can be found in the LICENSE file
- * in the root directory of this software component.
- * If no LICENSE file comes with this software, it is provided AS-IS.
- *
- ******************************************************************************
- */
+ ******************************************************************************
+ * @file fatfs.c
+ * @brief Code for fatfs applications
+ ******************************************************************************
+ * @attention
+ *
+ * Copyright (c) 2024 STMicroelectronics.
+ * All rights reserved.
+ *
+ * This software is licensed under terms that can be found in the LICENSE file
+ * in the root directory of this software component.
+ * If no LICENSE file comes with this software, it is provided AS-IS.
+ *
+ ******************************************************************************
+ */
/* USER CODE END Header */
#include "fatfs.h"
-uint8_t retUSBH; /* Return value for USBH */
-char USBHPath[4]; /* USBH logical drive path */
-FATFS USBHFatFS; /* File system object for USBH logical drive */
-FIL USBHFile; /* File object for USBH */
+uint8_t retUSBH; /* Return value for USBH */
+char USBHPath[4]; /* USBH logical drive path */
+FATFS USBHFatFS; /* File system object for USBH logical drive */
+FIL USBHFile; /* File object for USBH */
/* USER CODE BEGIN Variables */
/* USER CODE END Variables */
-void MX_FATFS_Init(void)
-{
+void MX_FATFS_Init(void) {
/*## FatFS: Link the USBH driver ###########################*/
retUSBH = FATFS_LinkDriver(&USBH_Driver, USBHPath);
@@ -38,14 +37,40 @@ void MX_FATFS_Init(void)
}
/**
- * @brief Gets Time from RTC
- * @param None
- * @retval Time in DWORD
- */
-DWORD get_fattime(void)
-{
+ * @brief Gets Time from RTC
+ * @param None
+ * @retval Time in DWORD
+ */
+extern RTC_HandleTypeDef hrtc;
+
+DWORD get_fattime(void) {
/* USER CODE BEGIN get_fattime */
- return 0;
+
+ DWORD u16_dateTime;
+ uint16_t date_time[6] = {2024, 5, 20, 01, 20, 10};
+
+ RTC_DateTypeDef GetData;
+ RTC_TimeTypeDef GetTime;
+ HAL_RTC_GetTime(&hrtc, &GetTime, RTC_FORMAT_BIN);
+ HAL_RTC_GetDate(&hrtc, &GetData, RTC_FORMAT_BIN);
+
+ date_time[0] = 1900 + GetData.Year;
+ date_time[1] = GetData.Month;
+ date_time[2] = GetData.Date;
+ date_time[3] = GetTime.Hours;
+ date_time[4] = GetTime.Minutes;
+ date_time[5] = GetTime.Seconds;
+
+ u16_dateTime = date_time[0] - 1980;
+ u16_dateTime = u16_dateTime << 25;
+ u16_dateTime |= date_time[1] << 21;
+ u16_dateTime |= date_time[2] << 16;
+ u16_dateTime |= date_time[3] << 11;
+ u16_dateTime |= date_time[4] << 5;
+ u16_dateTime |= date_time[5];
+
+ return u16_dateTime;
+
/* USER CODE END get_fattime */
}
diff --git a/FATFS/Target/ffconf.h b/FATFS/Target/ffconf.h
index 63ab990..acca984 100644
--- a/FATFS/Target/ffconf.h
+++ b/FATFS/Target/ffconf.h
@@ -61,7 +61,7 @@
/* This option switches filtered directory read functions, f_findfirst() and
/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
-#define _USE_MKFS 1
+#define _USE_MKFS 0
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
#define _USE_FASTSEEK 1
diff --git a/README.md b/README.md
index bf52b6a..f1cfc6a 100644
--- a/README.md
+++ b/README.md
@@ -75,4 +75,6 @@ BUG:
3. 考虑将所有串口接收改成DMA,目前串口有点多,中断接收有点吃不消了。
2. 用户登录时检查记录是否快满或者满,给出提示或者报警
+
+ 3. 用户修改通道名称时,修改用户名时,或者,删除用户时,如果审计记录不为空,则不允许修改。
```
\ No newline at end of file
diff --git a/USB_HOST/App/usb_host.c b/USB_HOST/App/usb_host.c
index f65ccb3..cda11e8 100644
--- a/USB_HOST/App/usb_host.c
+++ b/USB_HOST/App/usb_host.c
@@ -1,30 +1,30 @@
/* USER CODE BEGIN Header */
/**
- ******************************************************************************
- * @file : usb_host.c
- * @version : v1.0_Cube
- * @brief : This file implements the USB Host
- ******************************************************************************
- * @attention
- *
- * Copyright (c) 2024 STMicroelectronics.
- * All rights reserved.
- *
- * This software is licensed under terms that can be found in the LICENSE file
- * in the root directory of this software component.
- * If no LICENSE file comes with this software, it is provided AS-IS.
- *
- ******************************************************************************
- */
+ ******************************************************************************
+ * @file : usb_host.c
+ * @version : v1.0_Cube
+ * @brief : This file implements the USB Host
+ ******************************************************************************
+ * @attention
+ *
+ * Copyright (c) 2024 STMicroelectronics.
+ * All rights reserved.
+ *
+ * This software is licensed under terms that can be found in the LICENSE file
+ * in the root directory of this software component.
+ * If no LICENSE file comes with this software, it is provided AS-IS.
+ *
+ ******************************************************************************
+ */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "usb_host.h"
-#include "usbh_core.h"
-#include "usbh_msc.h"
#include "fileoperation/file_operate.h"
+#include "usbh_core.h"
+#include "usbh_msc.h"
/* USER CODE BEGIN Includes */
@@ -64,26 +64,22 @@ static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id);
/* USER CODE END 1 */
/**
- * Init USB host library, add supported class and start the library
- * @retval None
- */
-void MX_USB_HOST_Init(void)
-{
+ * Init USB host library, add supported class and start the library
+ * @retval None
+ */
+void MX_USB_HOST_Init(void) {
/* USER CODE BEGIN USB_HOST_Init_PreTreatment */
/* USER CODE END USB_HOST_Init_PreTreatment */
/* Init host Library, add supported class and start the library. */
- if (USBH_Init(&hUsbHostFS, USBH_UserProcess, HOST_FS) != USBH_OK)
- {
+ if (USBH_Init(&hUsbHostFS, USBH_UserProcess, HOST_FS) != USBH_OK) {
Error_Handler();
}
- if (USBH_RegisterClass(&hUsbHostFS, USBH_MSC_CLASS) != USBH_OK)
- {
+ if (USBH_RegisterClass(&hUsbHostFS, USBH_MSC_CLASS) != USBH_OK) {
Error_Handler();
}
- if (USBH_Start(&hUsbHostFS) != USBH_OK)
- {
+ if (USBH_Start(&hUsbHostFS) != USBH_OK) {
Error_Handler();
}
/* USER CODE BEGIN USB_HOST_Init_PostTreatment */
@@ -94,44 +90,38 @@ void MX_USB_HOST_Init(void)
/*
* user callback definition
*/
-static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id)
-{
+static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id) {
/* USER CODE BEGIN CALL_BACK_1 */
- switch(id)
- {
- case HOST_USER_SELECT_CONFIGURATION:
- printf("+++++++++++++++++++++++++++++++++HOST_USER_SELECT_CONFIGURATION+++++++++++++++++++++++++++++\n");
- break;
-
- case HOST_USER_DISCONNECTION:
- printf("+++++++++++++++++++++++++++++++++HOST_USER_DISCONNECTION+++++++++++++++++++++++++++++\n");
- Appli_state = APPLICATION_DISCONNECT;
- break;
-
- case HOST_USER_CLASS_ACTIVE:
- printf("+++++++++++++++++++++++++++++++++HOST_USER_CLASS_ACTIVE+++++++++++++++++++++++++++++\n");
- Appli_state = APPLICATION_READY;
- Mount_FatFs();
- FatFs_GetDiskInfo();
- FatFs_WriteTXTFile("test.txt",2016,11,15);
- break;
-
- case HOST_USER_CONNECTION:
- printf("+++++++++++++++++++++++++++++++++HOST_USER_CONNECTION+++++++++++++++++++++++++++++\n");
- Appli_state = APPLICATION_START;
- break;
-
- default:
- break;
+ switch (id) {
+ case HOST_USER_SELECT_CONFIGURATION:
+ printf("+++++++++++++++++++++++++++++++++HOST_USER_SELECT_CONFIGURATION+++++++++++++++++++++++++++++\n");
+ break;
+
+ case HOST_USER_DISCONNECTION:
+ printf("+++++++++++++++++++++++++++++++++HOST_USER_DISCONNECTION+++++++++++++++++++++++++++++\n");
+ Appli_state = APPLICATION_DISCONNECT; // U盘拔出
+ break;
+
+ case HOST_USER_CLASS_ACTIVE:
+ printf("+++++++++++++++++++++++++++++++++HOST_USER_CLASS_ACTIVE+++++++++++++++++++++++++++++\n");
+ Appli_state = APPLICATION_READY; // U盘插入并准备好
+ break;
+
+ case HOST_USER_CONNECTION:
+ printf("+++++++++++++++++++++++++++++++++HOST_USER_CONNECTION+++++++++++++++++++++++++++++\n");
+ Appli_state = APPLICATION_START; // U盘插入
+ break;
+
+ default:
+ break;
}
/* USER CODE END CALL_BACK_1 */
}
/**
- * @}
- */
+ * @}
+ */
/**
- * @}
- */
-
+ * @}
+ */
diff --git a/uappbase/apphal/apphal.cpp b/uappbase/apphal/apphal.cpp
index edebc2e..f919978 100644
--- a/uappbase/apphal/apphal.cpp
+++ b/uappbase/apphal/apphal.cpp
@@ -414,7 +414,6 @@ void AppHal::rtc_init() {
// Error_Handler();
// }
}
-
void AppHal::rtc_get(zdate_t* date) {
RTC_DateTypeDef GetData;
RTC_TimeTypeDef GetTime;
@@ -423,7 +422,7 @@ void AppHal::rtc_get(zdate_t* date) {
/* Get the RTC current Date */
HAL_RTC_GetDate(&hrtc, &GetData, RTC_FORMAT_BIN);
- date->year = 2000 + GetData.Year;
+ date->year = 1900 + GetData.Year;
date->month = GetData.Month;
date->day = GetData.Date;
@@ -432,7 +431,7 @@ void AppHal::rtc_get(zdate_t* date) {
date->seconds = GetTime.Seconds;
// /* Display date Format : yy/mm/dd */
- // ZLOGI("", "%02d/%02d/%02d\r\n", 2000 + GetData.Year, GetData.Month, GetData.Date);
+ // ZLOGI("", "%02d/%02d/%02d\r\n", 1900 + GetData.Year, GetData.Month, GetData.Date);
// /* Display time Format : hh:mm:ss */
// ZLOGI("", "%02d:%02d:%02d\r\n", GetTime.Hours, GetTime.Minutes, GetTime.Seconds);
}
@@ -455,7 +454,7 @@ void AppHal::rtc_set(zdate_t* date) {
sDate.WeekDay = 0x01;
sDate.Month = date->month;
sDate.Date = date->day;
- sDate.Year = date->year - 2000;
+ sDate.Year = date->year - 1900;
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK) {
Error_Handler();
diff --git a/usrc/fileoperation/zusb_file_operator.cpp b/usrc/fileoperation/zusb_file_operator.cpp
new file mode 100644
index 0000000..3da23e1
--- /dev/null
+++ b/usrc/fileoperation/zusb_file_operator.cpp
@@ -0,0 +1,158 @@
+#include "zusb_file_operator.hpp"
+
+extern "C" {
+#include "FatFs.h"
+#include "USB_HOST\App\usb_host.h"
+#include "main.h"
+#include "stdio.h"
+#include "stm32basic\basic\zlog.h"
+}
+
+using namespace iflytop;
+
+#define TAG "ZUSBFileOperator"
+
+#define User_Sector 512 /*用户存储设备扇区字节数*/
+#define USBHFatFS USBHFatFS /*用户存储设备FatFs对象*/
+#define USBHPath USBHPath /*用户存储设备卷路径*/
+#define User_FatType FM_FAT32 /*用户存储设备初始化类型*/
+
+static char m_errorInfo[128];
+static bool m_operationSuc;
+
+static FIL m_file;
+static bool openSunc;
+
+extern "C" {
+extern ApplicationTypeDef Appli_state;
+}
+
+static const char* FRESULT_TO_STR(FRESULT result) {
+ switch (result) {
+ case FR_OK:
+ return "成功";
+ case FR_DISK_ERR:
+ return "硬件错误";
+ case FR_INT_ERR:
+ return "断言失败";
+ case FR_NOT_READY:
+ return "物理驱动器无法工作";
+ case FR_NO_FILE:
+ return "找不到文件";
+ case FR_NO_PATH:
+ return "找不到路径";
+ case FR_INVALID_NAME:
+ return "路径名格式无效";
+ case FR_DENIED:
+ return "由于禁止访问或目录已满而拒绝访问";
+ case FR_EXIST:
+ return "由于禁止访问而拒绝访问";
+ case FR_INVALID_OBJECT:
+ return "文件/目录对象无效";
+ case FR_WRITE_PROTECTED:
+ return "物理驱动器受写保护";
+ case FR_INVALID_DRIVE:
+ return "逻辑驱动器号无效";
+ case FR_NOT_ENABLED:
+ return "卷没有工作区";
+ case FR_NO_FILESYSTEM:
+ return "磁盘未格式化成FAT文件系统";
+ case FR_MKFS_ABORTED:
+ return "由于任何问题,f_mkfs()中止";
+ case FR_TIMEOUT:
+ return "无法在定义的时间段内获得访问卷的授权";
+ case FR_LOCKED:
+ return "根据文件共享策略拒绝操作";
+ case FR_NOT_ENOUGH_CORE:
+ return "无法分配LFN工作缓冲区";
+ case FR_TOO_MANY_OPEN_FILES:
+ return "打开文件数>_FS_LOCK";
+ case FR_INVALID_PARAMETER:
+ return "给定参数无效";
+ default:
+ return "未知错误";
+ }
+}
+
+static void setErrorInfo(bool suc, const char* info) {
+ memset(m_errorInfo, 0, sizeof(m_errorInfo));
+ strncpy(m_errorInfo, info, sizeof(m_errorInfo));
+}
+
+void ZUSBFileOperator::mount() {
+ if (Appli_state != APPLICATION_READY) {
+ ZLOGE(TAG, "USB not ready");
+ setErrorInfo(false, "请插入U盘");
+ return;
+ }
+
+ FRESULT retUSER = f_mount(&USBHFatFS, USBHPath, 1);
+ if (retUSER != FR_OK) {
+ ZLOGE(TAG, "file system mount fail, error code:%d(%s)", retUSER, FRESULT_TO_STR(retUSER));
+ setErrorInfo(false, FRESULT_TO_STR(retUSER));
+ return;
+ }
+ setErrorInfo(true, FRESULT_TO_STR(FR_OK));
+ ZLOGI(TAG, "file system mount success");
+ return;
+}
+void ZUSBFileOperator::unmount() {
+ FRESULT retUSER = f_mount(NULL, USBHPath, 1);
+ if (retUSER != FR_OK) {
+ ZLOGE(TAG, "file system unmount fail, error code:%d(%s)", retUSER, FRESULT_TO_STR(retUSER));
+ setErrorInfo(false, FRESULT_TO_STR(retUSER));
+ return;
+ }
+ setErrorInfo(true, FRESULT_TO_STR(FR_OK));
+ ZLOGI(TAG, "file system unmount success");
+ return;
+}
+
+void ZUSBFileOperator::openNew(const char* filename, ...) {
+ char path[128] = {0};
+ va_list args;
+ va_start(args, filename);
+ vsnprintf(path, sizeof(path), filename, args);
+ va_end(args);
+
+ ZLOGI(TAG, "openNew filename:%s", path);
+ FRESULT result = f_open(&m_file, path, FA_CREATE_ALWAYS | FA_WRITE);
+ if (result != FR_OK) {
+ ZLOGE(TAG, "open file fail, error code:%d(%s)", result, FRESULT_TO_STR(result));
+ setErrorInfo(false, FRESULT_TO_STR(result));
+ return;
+ }
+ openSunc = true;
+ setErrorInfo(true, FRESULT_TO_STR(FR_OK));
+}
+void ZUSBFileOperator::close() {
+ ZLOGI(TAG, "close");
+ if (openSunc) f_close(&m_file);
+}
+int ZUSBFileOperator::write(const char* fmt, ...) {
+ static char buf[256];
+ va_list args;
+ va_start(args, fmt);
+ vsnprintf(buf, sizeof(buf), fmt, args);
+ va_end(args);
+ return write((uint8_t*)buf, strlen(buf));
+}
+
+int ZUSBFileOperator::write(uint8_t* buf, uint32_t len) {
+ if (!openSunc) {
+ setErrorInfo(false, "file not open");
+ return -1;
+ }
+ UINT bw;
+ FRESULT result = f_write(&m_file, buf, len, &bw);
+ if (result != FR_OK) {
+ ZLOGE(TAG, "write file fail, error code:%d(%s)", result, FRESULT_TO_STR(result));
+ setErrorInfo(false, FRESULT_TO_STR(result));
+ return -1;
+ }
+ setErrorInfo(true, FRESULT_TO_STR(FR_OK));
+ return bw;
+}
+
+bool ZUSBFileOperator::getOperationStatus() { return m_operationSuc; }
+const char* ZUSBFileOperator::getErrorInfo() { return m_errorInfo; }
\ No newline at end of file
diff --git a/usrc/fileoperation/zusb_file_operator.hpp b/usrc/fileoperation/zusb_file_operator.hpp
new file mode 100644
index 0000000..a222306
--- /dev/null
+++ b/usrc/fileoperation/zusb_file_operator.hpp
@@ -0,0 +1,21 @@
+#pragma once
+#include
+#include
+namespace iflytop {
+
+class ZUSBFileOperator {
+ public:
+ static void mount();
+ static void unmount();
+
+ static void openNew(const char* filename, ...);
+ static void close();
+
+ static int write(uint8_t* buf, uint32_t len);
+ static int write(const char* fmt,...);
+
+ static bool getOperationStatus();
+ static const char* getErrorInfo();
+};
+
+} // namespace iflytop
diff --git a/usrc/project_configs.h b/usrc/project_configs.h
index 603cfc2..0e8fc1d 100644
--- a/usrc/project_configs.h
+++ b/usrc/project_configs.h
@@ -8,7 +8,7 @@
#define SDK_CFG__CFG_FLASH_ADDR 0x080C0000 // flash配置地址
#define SDK_CFG__SN_FLASH_ADDR 0x080E0004 //
-#define SDK_MAX_TASK 18 // 最大任务数量
+#define SDK_MAX_TASK 20 // 最大任务数量
/***********************************************************************************************************************
* FLASH分区 *
diff --git a/usrc/service/app_core.cpp b/usrc/service/app_core.cpp
index 7cb5b01..a261002 100644
--- a/usrc/service/app_core.cpp
+++ b/usrc/service/app_core.cpp
@@ -26,6 +26,12 @@
#include "db/dao/device_setting_dao.hpp"
#include "db/dao/user_dao.hpp"
+#include "usrc\fileoperation\zusb_file_operator.hpp"
+
+//
+#include "FATFS\App\fatfs.h"
+#include "USB_HOST\App\usb_host.h"
+
#define TAG "main"
using namespace iflytop;
static ZThread ledthread;
@@ -95,15 +101,16 @@ void AppCore::initialize() {
ZLOGI(TAG, "ID0:%d ID1:%d ID2:%d ID3:%d ID4:%d", //
id->ID0.read(), id->ID1.read(), id->ID2.read(), id->ID3.read(), id->ID4.read());
- // if (!AppHardware::ins()->isHardInitOk()) {
- // GStateMgr::ins()->initialize();
- // AppEventBus::ins()->initialize();
+ if (!AppHardware::ins()->isHardInitOk()) {
+ ZLOGE(TAG, "hardware init fail");
+ GStateMgr::ins()->initialize();
+ AppEventBus::ins()->initialize();
- // UIControler::ins()->initialize();
- // popWinPageInit();
- // UIControler::ins()->popFatalErrorWin("硬件初始化失败,请尝试掉电重启设备");
- // while (true) osDelay(30);
- // }
+ UIControler::ins()->initialize();
+ popWinPageInit();
+ UIControler::ins()->popFatalErrorWin("硬件初始化失败,请尝试掉电重启设备");
+ while (true) osDelay(30);
+ }
/***********************************************************************************************************************
* 组件初始化 *
@@ -134,12 +141,19 @@ void AppCore::initialize() {
UIControler::ins()->initialize();
UIControler::ins()->pageInitialize();
+ ZGPIO USB_PWR;
+ USB_PWR.initAsOutput(PA15, kxs_gpio_nopull, false, true);
+ MX_FATFS_Init();
+ MX_USB_HOST_Init();
+
+ ZUSBFileOperator::mount();
+
/***********************************************************************************************************************
* 开始蓝牙扫描 *
***********************************************************************************************************************/
osDelay(100);
RemoteControlerUpper::ins()->startSchedule();
- // ValveStateSyncService::ins()->startSync();
+ ValveStateSyncService::ins()->startSync();
RemoteControlerStateSyncService::ins()->startSync();
if (strlen(DeviceSettingDao::get()->bleClientName) != 0) {
diff --git a/usrc/service/valve_state_ctrl_service.cpp b/usrc/service/valve_state_ctrl_service.cpp
index 6f8f411..d9f5b97 100644
--- a/usrc/service/valve_state_ctrl_service.cpp
+++ b/usrc/service/valve_state_ctrl_service.cpp
@@ -4,6 +4,9 @@
using namespace iflytop;
#define TAG "ValveStateSyncService"
+
+static int errorCnt;
+
void ValveStateSyncService::initialize(ZCAN1* can) {
m_thread.init("ValveStateSyncService-Thread");
this->can = can;
@@ -17,7 +20,7 @@ void ValveStateSyncService::startSync() {
m_thread.start([this]() {
while (true) {
- m_thread.sleep(300);
+ m_thread.sleep(100);
{
valve_ctrl_msg_t msg = {0};
{
@@ -25,7 +28,20 @@ void ValveStateSyncService::startSync() {
msg.output0 = output0state;
msg.output1 = output1state;
msg.rgbw = rgbwstate;
- ZCAN1::ins()->txMsg(kvalve_ctrl_msg, (uint8_t*)&msg, sizeof(msg), 10);
+
+ if (errorCnt < 10) {
+ bool suc = ZCAN1::ins()->txMsg(kvalve_ctrl_msg, (uint8_t*)&msg, sizeof(msg), 10);
+ if (suc) {
+ errorCnt = 0;
+ } else {
+ ZLOGI(TAG, "txMsg fail errorCnt:%d", errorCnt);
+ errorCnt++;
+ if (errorCnt == 10) {
+ ZLOGE(TAG, "valve maybe offline,stop sync");
+ }
+ }
+ }
+
forceupdate = false;
}
}
@@ -35,7 +51,7 @@ void ValveStateSyncService::startSync() {
}
void ValveStateSyncService::setValveState(bool state) {
if (!inited) return;
- if(!started) return;
+ if (!started) return;
{
zlock_guard l(lock);
@@ -54,7 +70,7 @@ void ValveStateSyncService::setValveState(bool state) {
void ValveStateSyncService::setValveState(int valveIndex, bool state) {
if (!inited) return;
- if(!started) return;
+ if (!started) return;
if (valveIndex >= 4) {
ZLOGW(TAG, "valveIndex %d out of range", valveIndex);
@@ -75,7 +91,7 @@ void ValveStateSyncService::setValveState(int valveIndex, bool state) {
void ValveStateSyncService::setValveState(bool state0, bool state1, bool state2, bool state3) {
if (!inited) return;
- if(!started) return;
+ if (!started) return;
{
zlock_guard l(lock);
@@ -96,7 +112,7 @@ void ValveStateSyncService::setValveState(bool state0, bool state1, bool state2,
void ValveStateSyncService::setRGBState(bool r, bool g, bool b) {
if (!inited) return;
- if(!started) return;
+ if (!started) return;
{
zlock_guard l(lock);
@@ -111,7 +127,7 @@ void ValveStateSyncService::setRGBState(bool r, bool g, bool b) {
}
void ValveStateSyncService::setWarningState(bool warning) {
if (!inited) return;
- if(!started) return;
+ if (!started) return;
{
zlock_guard l(lock);
diff --git a/usrc/uicontroler/page/mupage/MuAcidDistMgrPage.cpp b/usrc/uicontroler/page/mupage/MuAcidDistMgrPage.cpp
index e251713..cf2a0be 100644
--- a/usrc/uicontroler/page/mupage/MuAcidDistMgrPage.cpp
+++ b/usrc/uicontroler/page/mupage/MuAcidDistMgrPage.cpp
@@ -12,6 +12,7 @@
#include "db/dao/device_acid_volume_dao.hpp"
#include "db/dao/device_setting_dao.hpp"
//
+#include "fileoperation\zusb_file_operator.hpp"
#include "service/pump_ctrl_service.hpp"
#include "service/remote_controler.hpp"
@@ -223,6 +224,51 @@ class MuAcidDistMgrPage : public IPageProcesser {
setText(ob_muAcidDistMgr_chId, "");
setText(ob_muAcidDistMgr_volumeVal, "");
}
+
+#define CHECK_USB_FILE_OPERATION() \
+ { \
+ if (!ZUSBFileOperator::getOperationStatus()) { \
+ UIControler::ins()->popWarningWin(ZUSBFileOperator::getErrorInfo()); \
+ return; \
+ } \
+ }
+
+ void doExportData() { //
+ zdate_t date;
+ AppHal::rtc_get(&date);
+ auto* table = AcidDistrubtRecordDao::getRecordTable();
+
+ ZUSBFileOperator::mount();
+ CHECK_USB_FILE_OPERATION();
+
+ // ZUSBFileOperator::openNew("%04d%02d%02d%02d%02d%02d_ACID_DIST_RECORD.csv", date.year, date.month, date.day, date.hours, date.minutes, date.seconds);
+ ZUSBFileOperator::openNew("ACID_DIST_RECORD.csv");
+ CHECK_USB_FILE_OPERATION();
+
+ ZUSBFileOperator::write("ID,时间,发放人,领酸人,酸液名称,容量\n");
+ CHECK_USB_FILE_OPERATION();
+
+ for (int i = 0; i < table->recordNum; i++) {
+ auto* record = &table->record[i];
+
+
+ ZUSBFileOperator::write( //
+ "%d,%d/%d/%d %02d:%02d:%02d,%s,%s,%s,%d\n", //
+ record->id, //
+ record->date.year, record->date.month, record->date.day, record->date.hours, record->date.minutes, record->date.seconds, //
+ UserDao::getUserByIdNotNull(record->distrubtAcidUsrid)->name, //
+ UserDao::getUserByIdNotNull(record->takeAcidUsrid)->name, //
+ AcidChCfgDao::getCfg(record->distribuCh)->acidChooseName, //
+ record->distribuVolume);
+ CHECK_USB_FILE_OPERATION();
+ }
+
+ ZUSBFileOperator::close();
+ CHECK_USB_FILE_OPERATION();
+
+ ZUSBFileOperator::unmount();
+ CHECK_USB_FILE_OPERATION();
+ }
};
// 实例化Page, 使其自动注册
diff --git a/usrc/uicontroler/page/mupage/muAcidUseMgr_page.cpp b/usrc/uicontroler/page/mupage/muAcidUseMgr_page.cpp
index 9e8faea..cb8874b 100644
--- a/usrc/uicontroler/page/mupage/muAcidUseMgr_page.cpp
+++ b/usrc/uicontroler/page/mupage/muAcidUseMgr_page.cpp
@@ -1,15 +1,16 @@
+#include "db/dao/acid_ch_cfg_dao.hpp"
#include "db/dao/acid_name_dao.hpp"
#include "db/dao/user_dao.hpp"
#include "uappbase/apphal/apphal.hpp"
#include "ui/ui.h"
#include "uicontroler/base/page_processer.hpp"
-#include "usrc/db/dao/acid_ch_cfg_dao.hpp"
//
#include "db/dao/acid_ch_cfg_dao.hpp"
#include "db/dao/acid_use_record_dao.hpp"
#include "db/dao/device_setting_dao.hpp"
//
+#include "fileoperation\zusb_file_operator.hpp"
#include "service/pump_ctrl_service.hpp"
#include "service/remote_controler.hpp"
@@ -78,6 +79,10 @@ class MuAcidUseMgrPage : public IPageProcesser {
}
});
}
+
+ else if (bid == ob_muAcidUseRecd_export) {
+ doExportData();
+ }
}
virtual void onInputFieldContentChange(uint8_t bid, uint8_t slecId, const char* text) override {}
@@ -94,6 +99,11 @@ class MuAcidUseMgrPage : public IPageProcesser {
AcidUseRcordPage page;
AcidUseRecordDao::getRecord(0, &page);
for (int i = 0; i < page.recordNum; i++) {
+ if (i == 0) {
+ // 最新一条记录属于当前登录用户的实时状态,不显示
+ continue;
+ }
+
setText(cfgbid_table[i + 1].val[0], "%d/%d/%d %02d:%02d:%02d", page.record[i]->date.year, page.record[i]->date.month, page.record[i]->date.day, page.record[i]->date.hours, page.record[i]->date.minutes, page.record[i]->date.seconds);
setText(cfgbid_table[i + 1].val[1], "%s(%s)", UserDao::getUserByIdNotNull(page.record[i]->usrid)->name, page.record[i]->dirty ? "*" : "");
setText(cfgbid_table[i + 1].val[2], "%.1f", page.record[i]->ch0take0p1ml / 10.0);
@@ -111,6 +121,54 @@ class MuAcidUseMgrPage : public IPageProcesser {
setText(cfgbid_table[i + 1].val[5], "");
}
}
+
+#define CHECK_USB_FILE_OPERATION() \
+ { \
+ if (!ZUSBFileOperator::getOperationStatus()) { \
+ UIControler::ins()->popWarningWin(ZUSBFileOperator::getErrorInfo()); \
+ return; \
+ } \
+ }
+
+ void doExportData() { //
+ zdate_t date;
+ AppHal::rtc_get(&date);
+ auto* table = AcidUseRecordDao::getRecordTable();
+
+ ZUSBFileOperator::mount();
+ CHECK_USB_FILE_OPERATION();
+
+ // ZUSBFileOperator::openNew("%04d%02d%02d%02d%02d%02d_ACID_USAGE_RECORD.csv", date.year, date.month, date.day, date.hours, date.minutes, date.seconds);
+ ZUSBFileOperator::openNew("ACID_USAGE_RECORD.csv", date.year, date.month, date.day, date.hours, date.minutes, date.seconds);
+ CHECK_USB_FILE_OPERATION();
+
+ ZUSBFileOperator::write("ID,时间,用户,正常退出,%s(ml),%s(ml),%s(ml),%s(ml)\n", AcidChCfgDao::getCfg(0)->acidChooseName, AcidChCfgDao::getCfg(1)->acidChooseName, AcidChCfgDao::getCfg(2)->acidChooseName, AcidChCfgDao::getCfg(3)->acidChooseName);
+ CHECK_USB_FILE_OPERATION();
+
+ for (int i = 0; i < table->recordNum; i++) {
+ auto* record = &table->record[i];
+
+ if (i + 1 == table->recordNum) {
+ // 最后一条记录属于当前登录用户的实时状态,不导出
+ break;
+ }
+
+ ZUSBFileOperator::write( //
+ "%d,%d/%d/%d %02d:%02d:%02d,%s,%s,%.2f,%.2f,%.2f,%.2f\n", //
+ record->id, //
+ record->date.year, record->date.month, record->date.day, record->date.hours, record->date.minutes, record->date.seconds, //
+ UserDao::getUserByIdNotNull(record->usrid)->name, //
+ record->dirty ? "0" : "1", //
+ record->ch0take0p1ml / 10.0, record->ch1take0p1ml / 10.0, record->ch2take0p1ml / 10.0, record->ch3take0p1ml / 10.0);
+ CHECK_USB_FILE_OPERATION();
+ }
+
+ ZUSBFileOperator::close();
+ CHECK_USB_FILE_OPERATION();
+
+ ZUSBFileOperator::unmount();
+ CHECK_USB_FILE_OPERATION();
+ }
};
// 实例化Page, 使其自动注册
diff --git a/usrc/uicontroler/page/mupage/muCHSetting_page.cpp b/usrc/uicontroler/page/mupage/muCHSetting_page.cpp
index 99f5d0a..c600743 100644
--- a/usrc/uicontroler/page/mupage/muCHSetting_page.cpp
+++ b/usrc/uicontroler/page/mupage/muCHSetting_page.cpp
@@ -7,8 +7,11 @@
#include "usrc/db/dao/acid_ch_cfg_dao.hpp"
//
#include "db/dao/acid_ch_cfg_dao.hpp"
+#include "db/dao/acid_distrubt_record_dao.hpp"
+#include "db/dao/acid_use_record_dao.hpp"
#include "db/dao/device_setting_dao.hpp"
//
+//
#include "service/pump_ctrl_service.hpp"
#include "service/remote_controler.hpp"
@@ -187,6 +190,12 @@ class MuChSetting : public IPageProcesser {
/**
* @brief 更新通道名称
*/
+
+ if (AcidDistrubtRecordDao::getRecordNum() > 0 || AcidUseRecordDao::getRecordNum() > 1) {
+ UIControler::ins()->popWarningWin("无法修改通道名,<领酸记录>或<用酸记录>不为空");
+ return;
+ }
+
AcidChCfgDao::updatekCfgAcidChooseName(m_chId, text);
setText(bid, text);
} else if (IRUN_BIND_CFG && bid == IRUN_BIND_CFG->cfgbid) {
diff --git a/usrc/uicontroler/page/mupage/muUsrMgr_page.cpp b/usrc/uicontroler/page/mupage/muUsrMgr_page.cpp
index 3185599..f2424ac 100644
--- a/usrc/uicontroler/page/mupage/muUsrMgr_page.cpp
+++ b/usrc/uicontroler/page/mupage/muUsrMgr_page.cpp
@@ -5,6 +5,8 @@
#include "uicontroler/base/page_processer.hpp"
//
#include "db/dao/acid_ch_cfg_dao.hpp"
+#include "db/dao/acid_distrubt_record_dao.hpp"
+#include "db/dao/acid_use_record_dao.hpp"
#include "db/dao/device_setting_dao.hpp"
//
#include "service/pump_ctrl_service.hpp"
@@ -85,7 +87,7 @@ class MuUsrMgr : public IPageProcesser {
/**
* @brief 返回上一页
*/
- virtual void onBackKey() { UIControler::ins()->chpage(pg_navi,true); };
+ virtual void onBackKey() { UIControler::ins()->chpage(pg_navi, true); };
virtual void onAppEvent(AppEvent* event) { return; };
@@ -149,6 +151,10 @@ class MuUsrMgr : public IPageProcesser {
} else if (bid == ob_muUsrMgr_save) {
saveUsr();
} else if (bid == ob_muUsrMgr_del) {
+ if (AcidDistrubtRecordDao::getRecordNum() > 0 || AcidUseRecordDao::getRecordNum() > 1) {
+ UIControler::ins()->popWarningWin("无法删除用户名,<领酸记录>或<用酸记录>不为空");
+ return;
+ }
delUsr();
}
}
@@ -255,6 +261,13 @@ class MuUsrMgr : public IPageProcesser {
return;
}
+ if (strcmp(m_editContext.name, user->name) != 0) {
+ if (AcidDistrubtRecordDao::getRecordNum() > 0 || AcidUseRecordDao::getRecordNum() > 1) {
+ UIControler::ins()->popWarningWin("无法修改用户名,<领酸记录>或<用酸记录>不为空.");
+ return;
+ }
+ }
+
if (m_editContext.resetPasswd) {
ZLOGI(TAG, "reset passwd");
UserDao::updateUser(user->id, m_editContext.name, DEFAULT_PASSWD, (user_role_t)m_editContext.role->val);
@@ -339,7 +352,6 @@ class MuUsrMgr : public IPageProcesser {
return;
}
-
m_editContext.usrId = m_uiUsrTable[useroff].usrId;
strcpy(m_editContext.name, m_uiUsrTable[useroff].userName);
m_editContext.role = m_uiUsrTable[useroff].role;
diff --git a/usrc/uicontroler/ui_controler.cpp b/usrc/uicontroler/ui_controler.cpp
index e283929..0795b08 100644
--- a/usrc/uicontroler/ui_controler.cpp
+++ b/usrc/uicontroler/ui_controler.cpp
@@ -12,7 +12,7 @@
using namespace iflytop;
#define TAG "UIScheduler"
-#define MODULE_DEBUG 1
+#define MODULE_DEBUG 0
#define UART_RX_OVERTIME 5
#define CMD_OVERTIME 100