commit 05/02/2026
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package barix
|
||||
|
||||
import codes.Somecodes.Companion.LitteEndianToInt
|
||||
import codes.Somecodes.Companion.ValidString
|
||||
import kotlinx.coroutines.*
|
||||
import org.tinylog.Logger
|
||||
@@ -15,7 +16,7 @@ class TCP_Barix_Command_Server {
|
||||
lateinit var job: Job
|
||||
private val socketMap = mutableMapOf<String, Socket>()
|
||||
|
||||
private val regex = """STATUSBARIX;(\d+);(\d+);?(\d)?"""
|
||||
private val regex = """STATUSBARIX;(\d+);(\d+)(;(\d+))?"""
|
||||
private val pattern = Regex(regex)
|
||||
|
||||
/**
|
||||
@@ -43,15 +44,25 @@ class TCP_Barix_Command_Server {
|
||||
|
||||
val din = DataInputStream(socket.getInputStream())
|
||||
while (isActive) {
|
||||
val length = ByteArray(4)
|
||||
din.readFully(length)
|
||||
val readlength = ByteBuffer.wrap(length).getInt()
|
||||
//println("Read Length : $readlength")
|
||||
val bb = ByteArray(readlength)
|
||||
din.readFully(bb)
|
||||
// B4A format, 4 bytes di depan adalah size
|
||||
val str = String(bb)
|
||||
//println("Received from $key : $str")
|
||||
|
||||
val bb = ByteArray(128)
|
||||
val readbytes = din.read(bb)
|
||||
if (readbytes == -1) {
|
||||
Logger.info { "Connection closed by Streamer Output with IP $key" }
|
||||
break
|
||||
}
|
||||
if (readbytes == 0) continue
|
||||
var stringlength = 0
|
||||
try{
|
||||
stringlength = LitteEndianToInt(bb[0], bb[1], bb[2], bb[3])
|
||||
if (stringlength<1 || stringlength>bb.size-4) throw Exception("Invalid string length $stringlength")
|
||||
} catch (ex:Exception){
|
||||
Logger.error { "Error reading length from Streamer Output with IP $key, Message : ${ex.message}" }
|
||||
continue
|
||||
}
|
||||
val str = String(bb,4, stringlength).trim()
|
||||
if (str.isBlank()) continue
|
||||
if (!str.startsWith("STATUSBARIX")) continue
|
||||
if (ValidString(str)) {
|
||||
// Valid command from Barix is in format $"STATUSBARIX;VU;BuffRemain;StatusData"$
|
||||
pattern.find(str)?.let { matchResult ->
|
||||
@@ -60,7 +71,8 @@ class TCP_Barix_Command_Server {
|
||||
socket.inetAddress.hostAddress,
|
||||
vu.toInt(),
|
||||
buffremain.toInt(),
|
||||
statusdata.toIntOrNull() ?: 0
|
||||
statusdata.toIntOrNull() ?: 0,
|
||||
statusdata.isNullOrEmpty() // barix tidak ada statusdata , Q-AG1 ada
|
||||
)
|
||||
//Logger.info { "Received valid command from $key : $status" }
|
||||
cb.accept(status)
|
||||
|
||||
Reference in New Issue
Block a user