| | |
| | | |
| | | import java.io.File; |
| | | import java.util.List; |
| | | |
| | | import dialog.Dingshidialog; |
| | | import dialog.Errlog; |
| | | import home.MachineConfig; |
| | | |
| | | /** |
| | |
| | | initialize(DEFAULT_CONFIG_PATH); |
| | | |
| | | // 移除自动启动轮询的逻辑,由Homein统一管理 |
| | | System.out.println("系统配置初始化完成,轮询将由主启动类统一管理"); |
| | | ////System.out.println("系统配置初始化完成,轮询将由主启动类统一管理"); |
| | | |
| | | return true; |
| | | } catch (Exception e) { |
| | | System.err.println("系统初始化异常: " + e.getMessage()); |
| | | Errlog.logOperation("系统初始化异常: " + e.getMessage()); |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | |
| | | // 停止轮询查询 |
| | | if (lunxun.isPolling()) { |
| | | lunxun.stopPolling(); |
| | | System.out.println("系统关闭:轮询查询已停止"); |
| | | ////System.out.println("系统关闭:轮询查询已停止"); |
| | | } |
| | | } catch (Exception e) { |
| | | System.err.println("系统关闭异常: " + e.getMessage()); |
| | | Errlog.logOperation("系统关闭异常: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | |
| | | // 检查配置文件是否存在 |
| | | File configFile = new File(configFilePath); |
| | | if (!configFile.exists()) { |
| | | System.err.println("配置文件不存在: " + configFilePath); |
| | | Errlog.logOperation("配置文件不存在: " + configFilePath); |
| | | return false; |
| | | } |
| | | |
| | |
| | | // 标记初始化完成 |
| | | initialized = true; |
| | | |
| | | System.out.println("系统初始化完成,配置已加载"); |
| | | System.out.println("设备编号: " + machineConfig.getMachineId()); |
| | | System.out.println("服务器地址: " + machineConfig.getServerAddress() + ":" + machineConfig.getServerPort()); |
| | | System.out.println("卡槽总数: " + machineConfig.getTotalSlots()); |
| | | System.out.println("轮询间隔: " + machineConfig.getPollingInterval() + "ms"); |
| | | System.out.println("波特率: " + machineConfig.getBaudrate()); |
| | | ////System.out.println("系统初始化完成,配置已加载"); |
| | | ////System.out.println("设备编号: " + machineConfig.getMachineId()); |
| | | ////System.out.println("服务器地址: " + machineConfig.getServerAddress() + ":" + machineConfig.getServerPort()); |
| | | ////System.out.println("卡槽总数: " + machineConfig.getTotalSlots()); |
| | | ////System.out.println("轮询间隔: " + machineConfig.getPollingInterval() + "ms"); |
| | | ////System.out.println("波特率: " + machineConfig.getBaudrate()); |
| | | |
| | | return true; |
| | | |
| | | } catch (Exception e) { |
| | | System.err.println("系统初始化失败: " + e.getMessage()); |
| | | Errlog.logOperation("系统初始化失败: " + e.getMessage()); |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | |
| | | */ |
| | | public boolean saveConfig(String configFilePath) { |
| | | if (machineConfig == null) { |
| | | System.err.println("配置未加载,无法保存"); |
| | | Errlog.logOperation("配置未加载,无法保存"); |
| | | return false; |
| | | } |
| | | |
| | | try { |
| | | machineConfig.saveToFile(configFilePath); |
| | | System.out.println("配置已保存到: " + configFilePath); |
| | | ////System.out.println("配置已保存到: " + configFilePath); |
| | | return true; |
| | | } catch (Exception e) { |
| | | System.err.println("保存配置失败: " + e.getMessage()); |
| | | Errlog.logOperation("保存配置失败: " + e.getMessage()); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | */ |
| | | public MachineConfig getMachineConfig() { |
| | | if (!initialized) { |
| | | throw new IllegalStateException("系统未初始化,请先调用initialize()方法"); |
| | | Dingshidialog.showTimedDialog(null,10,"系统未初始化成功"); |
| | | } |
| | | return machineConfig; |
| | | } |