first commit

This commit is contained in:
2025-06-14 11:22:44 +07:00
parent 6010ce956c
commit 0c748cbac1
29 changed files with 242 additions and 1 deletions

View File

@@ -0,0 +1,21 @@
<component name="libraryTable">
<library name="digitalpetri.modbus.master.tcp" type="repository">
<properties maven-id="com.digitalpetri.modbus:modbus-master-tcp:1.2.2" />
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/modbus-master-tcp-1.2.2.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/modbus-codec-1.2.2.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/modbus-core-1.2.2.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/netty-buffer-4.1.105.Final.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/netty-codec-4.1.105.Final.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/netty-common-4.1.105.Final.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/netty-transport-4.1.105.Final.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/netty-resolver-4.1.105.Final.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/netty-channel-fsm-0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/strict-machine-0.7.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/metrics-core-3.1.5.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/slf4j-api-1.7.7.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

11
.idea/libraries/google_code_gson.xml generated Normal file
View File

@@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="google.code.gson" type="repository">
<properties maven-id="com.google.code.gson:gson:2.13.1" />
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/gson-2.13.1.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/error_prone_annotations-2.38.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

39
.idea/libraries/io_javalin.xml generated Normal file
View File

@@ -0,0 +1,39 @@
<component name="libraryTable">
<library name="io.javalin" type="repository">
<properties maven-id="io.javalin:javalin:5.4.2" />
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/javalin-5.4.2.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/slf4j-api-2.0.6.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jetty-server-11.0.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jetty-jakarta-servlet-api-5.0.2.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jetty-http-11.0.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jetty-util-11.0.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jetty-io-11.0.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jetty-webapp-11.0.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jetty-servlet-11.0.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jetty-security-11.0.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jetty-xml-11.0.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/websocket-jetty-server-11.0.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/websocket-jetty-common-11.0.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/websocket-core-common-11.0.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/websocket-servlet-11.0.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/websocket-core-server-11.0.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jetty-annotations-11.0.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jetty-plus-11.0.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jakarta.transaction-api-2.0.0.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jetty-jndi-11.0.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/jakarta.annotation-api-2.1.1.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/asm-9.4.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/asm-commons-9.4.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/asm-tree-9.4.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/websocket-jetty-api-11.0.14.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/kotlin-stdlib-jdk8-1.7.10.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/kotlin-stdlib-1.7.10.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/kotlin-stdlib-common-1.7.10.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/annotations-13.0.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/kotlin-stdlib-jdk7-1.7.10.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

10
.idea/libraries/projectlombok_lombok.xml generated Normal file
View File

@@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="projectlombok.lombok" type="repository">
<properties maven-id="org.projectlombok:lombok:1.18.34" />
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/lombok-1.18.34.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

10
.idea/libraries/tinylog_api.xml generated Normal file
View File

@@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="tinylog.api" type="repository">
<properties maven-id="org.tinylog:tinylog-api:2.7.0" />
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/tinylog-api-2.7.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

11
.idea/libraries/tinylog_impl.xml generated Normal file
View File

@@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="tinylog.impl" type="repository">
<properties maven-id="org.tinylog:tinylog-impl:2.7.0" />
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/tinylog-impl-2.7.0.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/tinylog-api-2.7.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

4
.idea/vcs.xml generated
View File

@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings" defaultProject="true" />
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -7,5 +7,11 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="io.javalin" level="project" />
<orderEntry type="library" name="digitalpetri.modbus.master.tcp" level="project" />
<orderEntry type="library" name="projectlombok.lombok" level="project" />
<orderEntry type="library" name="google.code.gson" level="project" />
<orderEntry type="library" name="tinylog.impl" level="project" />
<orderEntry type="library" name="tinylog.api" level="project" />
</component>
</module>

Binary file not shown.

BIN
lib/gson-2.13.1.jar Normal file

Binary file not shown.

BIN
lib/lombok-1.18.34.jar Normal file

Binary file not shown.

BIN
lib/metrics-core-3.1.5.jar Normal file

Binary file not shown.

BIN
lib/modbus-codec-1.2.2.jar Normal file

Binary file not shown.

BIN
lib/modbus-core-1.2.2.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
lib/slf4j-api-1.7.7.jar Normal file

Binary file not shown.

BIN
lib/strict-machine-0.7.jar Normal file

Binary file not shown.

BIN
lib/tinylog-api-2.6.2.jar Normal file

Binary file not shown.

BIN
lib/tinylog-api-2.7.0.jar Normal file

Binary file not shown.

BIN
lib/tinylog-impl-2.7.0.jar Normal file

Binary file not shown.

7
src/Somecodes.java Normal file
View File

@@ -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();
}

122
src/config.java Normal file
View File

@@ -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;
}
}

2
src/tinylog.properties Normal file
View File

@@ -0,0 +1,2 @@
writer = console
writer.format = {date: HH:mm:ss.SSS} {level}: {message}