First commit

This commit is contained in:
2024-11-15 10:58:51 +07:00
parent 2d647fd470
commit 240a7357b6
7 changed files with 167 additions and 0 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

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

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

50
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectInspectionProfilesVisibleTreeState">
<entry key="Project Default">
<profile-state>
<expanded-state>
<State />
<State>
<id>Android</id>
</State>
<State>
<id>CodePlugin DevKit</id>
</State>
<State>
<id>ComplianceLintAndroid</id>
</State>
<State>
<id>CorrectnessLintAndroid</id>
</State>
<State>
<id>Java</id>
</State>
<State>
<id>Java language level migration aidsJava</id>
</State>
<State>
<id>LintAndroid</id>
</State>
<State>
<id>PerformanceLintAndroid</id>
</State>
<State>
<id>Plugin DevKit</id>
</State>
<State>
<id>UsabilityLintAndroid</id>
</State>
</expanded-state>
<selected-state>
<State>
<id>Android</id>
</State>
</selected-state>
</profile-state>
</entry>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/ProtegeToAASMini.iml" filepath="$PROJECT_DIR$/ProtegeToAASMini.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

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

21
ProtegeToAASMini.iml Normal file
View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://C:/apache-cxf/3.5.9/lib/cxf-manifest.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="tinylog" level="project" />
</component>
</module>

View File

@@ -5,6 +5,7 @@ import org.pmw.tinylog.Logger;
import java.net.InetAddress;
import java.net.Socket;
@SuppressWarnings("unused")
public class AASMini {
private final String targetIP;
private final int targetPort;
@@ -20,6 +21,14 @@ public class AASMini {
this.targetPort = port;
}
/**
* Check if the AAS Mini is connected
* @return true if connected, false otherwise
*/
public boolean IsConnected(){
return socket != null && socket.isConnected();
}
/**
* Connect to AAS Mini
* @return true if connected, false otherwise
@@ -42,6 +51,61 @@ public class AASMini {
return false;
}
/**
* Disconnect from AAS Mini
*/
public void Disconnect(){
try{
if (socket != null && socket.isConnected()){
socket.close();
Logger.info("Disconnected from {}:{}", targetIP, targetPort);
}
} catch (Exception e){
Logger.error("Failed to disconnect from {}:{}, Error : {}", targetIP, targetPort, e.getMessage());
}
socket = null;
}
//TODO protocol untuk kirim data ke AAS Mini
/**
* Send data to AAS Mini and receive response
* @param data Data to be sent
* @return byte array of response or null if failed
*/
private byte[] SendAndReceive(byte[] data){
if (IsConnected()){
if (data!=null && data.length>0){
try{
socket.getOutputStream().write(data);
byte[] buffer = new byte[1024];
int read = socket.getInputStream().read(buffer);
if (read>0){
byte[] result = new byte[read];
System.arraycopy(buffer, 0, result, 0, read);
return result;
}
} catch (Exception e){
Logger.error("Failed to send data to {}:{}, Error : {}", targetIP, targetPort, e.getMessage());
}
}
}
return null;
}
/**
* Send data to AAS Mini
* @param data Data to be sent
*/
private void SendData(byte[] data){
if (IsConnected()){
if (data!=null && data.length>0){
try{
socket.getOutputStream().write(data);
} catch (Exception e){
Logger.error("Failed to send data to {}:{}, Error : {}", targetIP, targetPort, e.getMessage());
}
}
}
}
}