kopia lustrzana https://github.com/ge0rg/aprsdroid
add parseHostPort utility function
rodzic
9dfb374096
commit
8fef181969
|
@ -76,4 +76,12 @@ object AprsPacket {
|
|||
def formatLogin(callsign : String, ssid : String, passcode : String) : String = {
|
||||
"user " + formatCallSsid(callsign, ssid) + " pass " + passcode + " vers APRSdroid 0.1"
|
||||
}
|
||||
|
||||
def parseHostPort(hostport : String, defaultport : Int) : (String, Int) = {
|
||||
val splits = hostport.split(":")
|
||||
if (splits.length == 2)
|
||||
return (splits(0), splits(1).toInt)
|
||||
else
|
||||
return (splits(0), defaultport)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,10 @@ class UdpUploader extends AprsIsUploader {
|
|||
}
|
||||
|
||||
def update(host : String, login : String, packet : String) : String = {
|
||||
val addr = InetAddress.getByName(host)
|
||||
val (h, port) = AprsPacket.parseHostPort(host, 8080)
|
||||
val addr = InetAddress.getByName(h)
|
||||
val pbytes = (login + "\r\n" + packet + "\r\n").getBytes()
|
||||
socket.send(new DatagramPacket(pbytes, pbytes.length, addr, 8080))
|
||||
socket.send(new DatagramPacket(pbytes, pbytes.length, addr, port))
|
||||
Log.d(TAG, "update(): sent '" + packet + "' to " + host)
|
||||
"UDP OK"
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue