patch 06/12/2024
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
WebUsername=admin
|
||||
WebPassword=admin
|
||||
WebListenPort = 8080
|
||||
SipServer=rdkartono.ddns.me
|
||||
SipServer=192.168.10.2
|
||||
SipPort=5060
|
||||
SipUsername=101
|
||||
SipPassword=password101
|
||||
@@ -153,6 +153,7 @@ public class BassSoundManager extends AbstractSoundManager {
|
||||
int rs;
|
||||
Pointer buf = new Memory(read_size);
|
||||
while(true) {
|
||||
if (recordhandle==0) break;
|
||||
if (BASS.BASS_ChannelIsActive(recordhandle)!=Bass.BASS_ACTIVE_PLAYING) break;
|
||||
rs = BASS.BASS_ChannelGetData(recordhandle, buf, read_size);
|
||||
if (rs<0) {
|
||||
@@ -165,7 +166,7 @@ public class BassSoundManager extends AbstractSoundManager {
|
||||
if (bsml!=null) bsml.ReadToRTP(rs, result);
|
||||
return result;
|
||||
} else {
|
||||
// nol
|
||||
// nol, tunggu bentar
|
||||
try {
|
||||
Thread.sleep(2);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
108
src/Main.java
108
src/Main.java
@@ -41,15 +41,46 @@ public class Main {
|
||||
private static NetworkTransmitReceiveInfo[] previousNetworkInfo;
|
||||
private static final Map<String, String> networkTX = new HashMap<>();
|
||||
private static final Map<String, String> networkRX = new HashMap<>();
|
||||
private static Properties config;
|
||||
|
||||
public static void main(String[] args) {
|
||||
common.ExtractProperties(currentDir,"config.properties", false);
|
||||
Properties config = common.LoadProperties(currentDir,"config.properties");
|
||||
config = common.LoadProperties(currentDir,"config.properties");
|
||||
|
||||
// Timer Section
|
||||
timer = new Timer();
|
||||
|
||||
// SIP Section
|
||||
SIPClient_Section();
|
||||
|
||||
// Web Server Section
|
||||
WebServer_Section();
|
||||
|
||||
// GPIO Section
|
||||
GPIO_Section();
|
||||
|
||||
// Start System monitoring
|
||||
init_system_monitoring();
|
||||
|
||||
// Shutdown Hook
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
Logger.info("Shutting down SIPIntercom");
|
||||
if (client!=null) client.Disconnect();
|
||||
if (webserver!=null) webserver.Stop();
|
||||
if (socketioserver!=null) socketioserver.Stop();
|
||||
if (callButton!=null && callButton.isInitialized()) callButton.Close();
|
||||
if (hangupButton!=null && hangupButton.isInitialized()) hangupButton.Close();
|
||||
if (pilotLight!=null && pilotLight.isInitialized()) pilotLight.Close();
|
||||
if (networkLight!=null && networkLight.isInitialized()) networkLight.Close();
|
||||
if (callLight!=null && callLight.isInitialized()) callLight.Close();
|
||||
if (timer!=null) timer.cancel();
|
||||
if (system_monitoring_timer!=null) system_monitoring_timer.cancel();
|
||||
}));
|
||||
}
|
||||
|
||||
private static void SIPClient_Section(){
|
||||
// initialize pakai thread, biar cepat
|
||||
new Thread(()->{
|
||||
client = new jSIPClient(config);
|
||||
// event dari sisi Bass Sound Manager
|
||||
client.SetBassSoundManagerEvent(new BassSoundManagerEvent() {
|
||||
@@ -151,15 +182,19 @@ public class Main {
|
||||
|
||||
@Override
|
||||
public void CalleePickup(SIP_Response resp) {
|
||||
Logger.info("Callee Pickup, Response: {}",resp);
|
||||
oncallResponse = resp;
|
||||
SipStatus = "Communication with "+resp.CallID;
|
||||
Logger.info("Callee Pickup, Response: {}",oncallResponse);
|
||||
SipStatus = "Communication with "+oncallResponse.CallID;
|
||||
}
|
||||
});
|
||||
client.Connect();
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
// Web Server Section
|
||||
private static void WebServer_Section(){
|
||||
// initialize pakai thread, biar cepat
|
||||
new Thread(()->{
|
||||
webserver = new WebServer(config);
|
||||
webserver.Start();
|
||||
socketioserver = new SocketioServer("0.0.0.0", 9092);
|
||||
@@ -214,15 +249,8 @@ public class Main {
|
||||
resp = new SocketioResponse("success", SipStatus);
|
||||
break;
|
||||
case "hangup":
|
||||
if (incomingRequest!=null || incomingResponse!=null){
|
||||
resp = new SocketioResponse("success", "Reject Incoming Call from "+incomingRequest.CallID);
|
||||
hangupCall();
|
||||
} else if (oncallRequest!=null || oncallResponse!=null){
|
||||
resp = new SocketioResponse("success", "Hangup Call to "+oncallRequest.CallID);
|
||||
hangupCall();
|
||||
} else {
|
||||
resp = new SocketioResponse("error", "No Call to Hangup");
|
||||
}
|
||||
resp = new SocketioResponse("success", "Hangup Call");
|
||||
break;
|
||||
case "getRamInfo":
|
||||
if (ramInformation!=null){
|
||||
@@ -264,12 +292,22 @@ public class Main {
|
||||
}
|
||||
return resp;
|
||||
});
|
||||
}).start();
|
||||
|
||||
// GPIO Section
|
||||
// talk button = pin12
|
||||
// hangup button = pin14
|
||||
// Call light = pin 22
|
||||
// Network light = pin 20
|
||||
}
|
||||
|
||||
/**
|
||||
* GPIO Section
|
||||
* talk button = pin12
|
||||
* hangup button = pin14
|
||||
* Call light = pin 22
|
||||
* Network light = pin 20
|
||||
* Pilot light = pin 16
|
||||
* Buzzer = pin 18
|
||||
*/
|
||||
private static void GPIO_Section(){
|
||||
// initialize pakai thread, biar cepat
|
||||
new Thread(()->{
|
||||
callButton = new GpioInput(NanopiDuo2.Pin12.gpionumber, true);
|
||||
if (callButton.isInitialized()){
|
||||
callButton.setOnLongPress(vv->{
|
||||
@@ -294,7 +332,7 @@ public class Main {
|
||||
});
|
||||
} else Logger.error("Failed to initialize Hangup Button");
|
||||
|
||||
// belum ada pinout nya di PCB demo (04/12/2024)
|
||||
|
||||
pilotLight = new GpioOutput(NanopiDuo2.Pin16.gpionumber, true);
|
||||
if (pilotLight.isInitialized()){
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@@ -308,41 +346,25 @@ public class Main {
|
||||
networkLight = new GpioOutput(NanopiDuo2.Pin20.gpionumber, true);
|
||||
callLight = new GpioOutput(NanopiDuo2.Pin22.gpionumber, true);
|
||||
|
||||
// belum ada pinout nya di PCB demo (04/12/2024)
|
||||
|
||||
Buzzer = new GpioOutput(NanopiDuo2.Pin18.gpionumber, true);
|
||||
}).start();
|
||||
|
||||
// Start System monitoring
|
||||
init_system_monitoring();
|
||||
|
||||
// Shutdown Hook
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
Logger.info("Shutting down SIPIntercom");
|
||||
if (client!=null) client.Disconnect();
|
||||
if (webserver!=null) webserver.Stop();
|
||||
if (socketioserver!=null) socketioserver.Stop();
|
||||
if (callButton!=null && callButton.isInitialized()) callButton.Close();
|
||||
if (hangupButton!=null && hangupButton.isInitialized()) hangupButton.Close();
|
||||
if (pilotLight!=null && pilotLight.isInitialized()) pilotLight.Close();
|
||||
if (networkLight!=null && networkLight.isInitialized()) networkLight.Close();
|
||||
if (callLight!=null && callLight.isInitialized()) callLight.Close();
|
||||
if (timer!=null) timer.cancel();
|
||||
if (system_monitoring_timer!=null) system_monitoring_timer.cancel();
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Hangup call
|
||||
*/
|
||||
private static void hangupCall() {
|
||||
if (oncallRequest!=null || oncallResponse!=null){
|
||||
if (incomingRequest!=null || incomingResponse!=null){
|
||||
client.RejectIncomingCall(incomingRequest);
|
||||
} else {
|
||||
client.HangUp();
|
||||
}
|
||||
incomingResponse = null;
|
||||
incomingRequest = null;
|
||||
oncallResponse = null;
|
||||
oncallRequest = null;
|
||||
} else if (incomingRequest!=null || incomingResponse!=null){
|
||||
client.RejectIncomingCall(incomingRequest);
|
||||
incomingRequest = null;
|
||||
incomingResponse = null;
|
||||
}
|
||||
callLight_Idle();
|
||||
Buzzer_Off();
|
||||
SipStatus = "Idle";
|
||||
@@ -392,6 +414,7 @@ public class Main {
|
||||
File ff = new File(currentDir, filename);
|
||||
if (ff.isFile()){
|
||||
String callnumber = MessageFormat.format("sip:{0}@{1}", extension, client.getServerAddress());
|
||||
|
||||
if (client.StreamFile(callnumber, ff.getAbsolutePath())){
|
||||
Logger.info("Stream to {} is successful",callnumber);
|
||||
try{
|
||||
@@ -519,6 +542,7 @@ public class Main {
|
||||
|
||||
private static void init_system_monitoring(){
|
||||
TimerTask tt = new TimerTask() {
|
||||
@SuppressWarnings("IfStatementWithIdenticalBranches")
|
||||
@Override
|
||||
public void run() {
|
||||
cpuTemperature = SystemInformation.getCPUTemperature();
|
||||
|
||||
@@ -6,13 +6,11 @@ import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static code.common.*;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Getter
|
||||
public class GpioInput {
|
||||
private boolean initialized = false;
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.nio.file.Path;
|
||||
|
||||
import static code.common.*;
|
||||
|
||||
@SuppressWarnings({"unused", "UnusedReturnValue"})
|
||||
@SuppressWarnings({"unused","UnusedReturnValue"})
|
||||
@Getter
|
||||
public class GpioOutput {
|
||||
private boolean initialized = false;
|
||||
|
||||
@@ -379,6 +379,7 @@ public class jSIPClient {
|
||||
DialogManager dialogManager = user_agent.getDialogManager();
|
||||
Dialog dialog = dialogManager.getDialog(callId);
|
||||
user_agent.acceptCall(req, dialog);
|
||||
sip_request = req;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user