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