diff --git a/.idea/libraries/digitalpetri_modbus_master_tcp.xml b/.idea/libraries/digitalpetri_modbus_master_tcp.xml new file mode 100644 index 0000000..067876d --- /dev/null +++ b/.idea/libraries/digitalpetri_modbus_master_tcp.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/google_code_gson.xml b/.idea/libraries/google_code_gson.xml new file mode 100644 index 0000000..8348c9d --- /dev/null +++ b/.idea/libraries/google_code_gson.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/io_javalin.xml b/.idea/libraries/io_javalin.xml new file mode 100644 index 0000000..6ad104d --- /dev/null +++ b/.idea/libraries/io_javalin.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/projectlombok_lombok.xml b/.idea/libraries/projectlombok_lombok.xml new file mode 100644 index 0000000..3ac4141 --- /dev/null +++ b/.idea/libraries/projectlombok_lombok.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/tinylog_api.xml b/.idea/libraries/tinylog_api.xml new file mode 100644 index 0000000..7d7e94f --- /dev/null +++ b/.idea/libraries/tinylog_api.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/tinylog_impl.xml b/.idea/libraries/tinylog_impl.xml new file mode 100644 index 0000000..7683aa1 --- /dev/null +++ b/.idea/libraries/tinylog_impl.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index d843f34..94a25f7 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,4 +1,6 @@ - + + + \ No newline at end of file diff --git a/FA_Gateway_Java.iml b/FA_Gateway_Java.iml index c90834f..0a81566 100644 --- a/FA_Gateway_Java.iml +++ b/FA_Gateway_Java.iml @@ -7,5 +7,11 @@ + + + + + + \ No newline at end of file diff --git a/lib/error_prone_annotations-2.38.0.jar b/lib/error_prone_annotations-2.38.0.jar new file mode 100644 index 0000000..b21cbdd Binary files /dev/null and b/lib/error_prone_annotations-2.38.0.jar differ diff --git a/lib/gson-2.13.1.jar b/lib/gson-2.13.1.jar new file mode 100644 index 0000000..159b930 Binary files /dev/null and b/lib/gson-2.13.1.jar differ diff --git a/lib/lombok-1.18.34.jar b/lib/lombok-1.18.34.jar new file mode 100644 index 0000000..ea0ba78 Binary files /dev/null and b/lib/lombok-1.18.34.jar differ diff --git a/lib/metrics-core-3.1.5.jar b/lib/metrics-core-3.1.5.jar new file mode 100644 index 0000000..5e6aed8 Binary files /dev/null and b/lib/metrics-core-3.1.5.jar differ diff --git a/lib/modbus-codec-1.2.2.jar b/lib/modbus-codec-1.2.2.jar new file mode 100644 index 0000000..22e696f Binary files /dev/null and b/lib/modbus-codec-1.2.2.jar differ diff --git a/lib/modbus-core-1.2.2.jar b/lib/modbus-core-1.2.2.jar new file mode 100644 index 0000000..551b945 Binary files /dev/null and b/lib/modbus-core-1.2.2.jar differ diff --git a/lib/modbus-master-tcp-1.2.2.jar b/lib/modbus-master-tcp-1.2.2.jar new file mode 100644 index 0000000..709703e Binary files /dev/null and b/lib/modbus-master-tcp-1.2.2.jar differ diff --git a/lib/netty-buffer-4.1.105.Final.jar b/lib/netty-buffer-4.1.105.Final.jar new file mode 100644 index 0000000..09b4d82 Binary files /dev/null and b/lib/netty-buffer-4.1.105.Final.jar differ diff --git a/lib/netty-channel-fsm-0.9.jar b/lib/netty-channel-fsm-0.9.jar new file mode 100644 index 0000000..bc8e00a Binary files /dev/null and b/lib/netty-channel-fsm-0.9.jar differ diff --git a/lib/netty-codec-4.1.105.Final.jar b/lib/netty-codec-4.1.105.Final.jar new file mode 100644 index 0000000..53cc624 Binary files /dev/null and b/lib/netty-codec-4.1.105.Final.jar differ diff --git a/lib/netty-common-4.1.105.Final.jar b/lib/netty-common-4.1.105.Final.jar new file mode 100644 index 0000000..1286e4c Binary files /dev/null and b/lib/netty-common-4.1.105.Final.jar differ diff --git a/lib/netty-resolver-4.1.105.Final.jar b/lib/netty-resolver-4.1.105.Final.jar new file mode 100644 index 0000000..18c7aa3 Binary files /dev/null and b/lib/netty-resolver-4.1.105.Final.jar differ diff --git a/lib/netty-transport-4.1.105.Final.jar b/lib/netty-transport-4.1.105.Final.jar new file mode 100644 index 0000000..dac1539 Binary files /dev/null and b/lib/netty-transport-4.1.105.Final.jar differ diff --git a/lib/slf4j-api-1.7.7.jar b/lib/slf4j-api-1.7.7.jar new file mode 100644 index 0000000..bebabd9 Binary files /dev/null and b/lib/slf4j-api-1.7.7.jar differ diff --git a/lib/strict-machine-0.7.jar b/lib/strict-machine-0.7.jar new file mode 100644 index 0000000..7ba991a Binary files /dev/null and b/lib/strict-machine-0.7.jar differ diff --git a/lib/tinylog-api-2.6.2.jar b/lib/tinylog-api-2.6.2.jar new file mode 100644 index 0000000..e098dd5 Binary files /dev/null and b/lib/tinylog-api-2.6.2.jar differ diff --git a/lib/tinylog-api-2.7.0.jar b/lib/tinylog-api-2.7.0.jar new file mode 100644 index 0000000..94c2bdc Binary files /dev/null and b/lib/tinylog-api-2.7.0.jar differ diff --git a/lib/tinylog-impl-2.7.0.jar b/lib/tinylog-impl-2.7.0.jar new file mode 100644 index 0000000..3daf689 Binary files /dev/null and b/lib/tinylog-impl-2.7.0.jar differ diff --git a/src/Somecodes.java b/src/Somecodes.java new file mode 100644 index 0000000..454659c --- /dev/null +++ b/src/Somecodes.java @@ -0,0 +1,7 @@ +import com.google.gson.Gson; + +public class Somecodes { + + public static String currentdirectory = System.getProperty("user.dir"); + public static Gson gson = new Gson(); +} diff --git a/src/config.java b/src/config.java new file mode 100644 index 0000000..dd55083 --- /dev/null +++ b/src/config.java @@ -0,0 +1,122 @@ +import lombok.Getter; +import lombok.Setter; +import org.tinylog.Logger; + +import java.nio.file.Files; +import java.nio.file.Path; + +public class config { + private @Getter @Setter String VX3KTargetIP; + private @Getter @Setter int VX3KTargetPort; + private @Getter @Setter String Email_SMTPServer; + private @Getter @Setter int Email_SMTPPort; + private @Getter @Setter boolean Email_SMTPSSL; + private @Getter @Setter String Email_SMTPUsername; + private @Getter @Setter String Email_SMTPPassword; + private @Getter @Setter String Email_SMTPFrom ; + private @Getter @Setter String Email_SenderName; + private @Getter @Setter String Email_Subject; + private @Getter @Setter String MQTT_Broker; + private @Getter @Setter int MQTT_Port; + private @Getter @Setter String MQTT_Topic ; + private @Getter @Setter String MQTT_ClientID; + private @Getter @Setter String MQTT_Username; + private @Getter @Setter String MQTT_Password ; + + + public config(){ + Load(); + } + + /** + * Load configuration from file. + * If the file does not exist, create default configuration. + */ + private void Load(){ + Path configPath = Path.of(Somecodes.currentdirectory, "config.json"); + if (Files.exists(configPath)){ + // Read the configuration from the file + // and if not complete, create defaults + try{ + String configContent = Files.readString(configPath); + config loadedConfig = Somecodes.gson.fromJson(configContent, config.class); + if (loadedConfig != null) { + // Copy values from loadedConfig to this instance + this.VX3KTargetIP = loadedConfig.VX3KTargetIP; + this.VX3KTargetPort = loadedConfig.VX3KTargetPort; + this.Email_SMTPServer = loadedConfig.Email_SMTPServer; + this.Email_SMTPPort = loadedConfig.Email_SMTPPort; + this.Email_SMTPSSL = loadedConfig.Email_SMTPSSL; + this.Email_SMTPUsername = loadedConfig.Email_SMTPUsername; + this.Email_SMTPPassword = loadedConfig.Email_SMTPPassword; + this.Email_SMTPFrom = loadedConfig.Email_SMTPFrom; + this.Email_SenderName = loadedConfig.Email_SenderName; + this.Email_Subject = loadedConfig.Email_Subject; + this.MQTT_Broker = loadedConfig.MQTT_Broker; + this.MQTT_Port = loadedConfig.MQTT_Port; + this.MQTT_Topic = loadedConfig.MQTT_Topic; + this.MQTT_ClientID = loadedConfig.MQTT_ClientID; + this.MQTT_Username = loadedConfig.MQTT_Username; + this.MQTT_Password = loadedConfig.MQTT_Password; + + Logger.info("Loaded config from {}", configPath.toAbsolutePath()); + } else { + Logger.error("Loaded config is null, creating Default Config"); + MakeDefaults(); + } + } catch (Exception e){ + Logger.error("Failed to read config file: {}, creating Default Config", e.getMessage()); + MakeDefaults(); + } + } else { + Logger.error("Config file not found at {}, creating Default Config", configPath.toAbsolutePath()); + MakeDefaults(); + } + } + + /** + * Create default configuration values. + * This method sets default values for all configuration fields. + */ + private void MakeDefaults() { + // Set default values if needed + + VX3KTargetIP = "192.168.14.1"; + VX3KTargetPort = 5000; + Email_SMTPServer = "mail.galva.co.id"; + Email_SMTPPort = 587; + Email_SMTPSSL = true; + Email_SMTPUsername = "admin"; + Email_SMTPPassword = "admin"; + Email_SMTPFrom = "fa@galva.co.id"; + Email_SenderName = "Fire Alarm Gateway"; + Email_Subject = "Fire Alarm Gateway Notification"; + MQTT_Broker = "34.101.202.96"; + MQTT_Port = 1883; + MQTT_Topic = "FA_Gateway/status"; + MQTT_ClientID = "Pekojan"; + MQTT_Username = "gtcdev"; + MQTT_Password = "gtcdev2025"; + + Save(); + + } + + /** + * Save the current configuration to a file. + * This method serializes the configuration object to JSON and writes it to a file. + * @return true if the save operation was successful, false otherwise. + */ + public boolean Save(){ + Path configPath = Path.of(Somecodes.currentdirectory, "config.json"); + String gs = Somecodes.gson.toJson(this); + try { + Files.writeString(configPath, gs); + Logger.info("Default config written to {}", configPath.toAbsolutePath()); + return true; + } catch (Exception e) { + Logger.error("Failed to write default config: {}", e.getMessage()); + } + return false; + } +} diff --git a/src/tinylog.properties b/src/tinylog.properties new file mode 100644 index 0000000..9d3d900 --- /dev/null +++ b/src/tinylog.properties @@ -0,0 +1,2 @@ +writer = console +writer.format = {date: HH:mm:ss.SSS} {level}: {message} \ No newline at end of file