kopia lustrzana https://github.com/ge0rg/aprsdroid
fixed SSID, added status feedback
rodzic
4f096319b0
commit
1d9cb344b9
|
@ -15,7 +15,7 @@ class AprsHttpPost(prefs : SharedPreferences) extends AprsIsUploader(prefs) {
|
|||
def start() {
|
||||
}
|
||||
|
||||
def doPost(urlString : String, content : String) {
|
||||
def doPost(urlString : String, content : String) : String = {
|
||||
val client = new DefaultHttpClient()
|
||||
val post = new HttpPost(urlString)
|
||||
post.setEntity(new StringEntity(content))
|
||||
|
@ -23,11 +23,12 @@ class AprsHttpPost(prefs : SharedPreferences) extends AprsIsUploader(prefs) {
|
|||
post.addHeader("Accept-Type", "text/plain");
|
||||
val response = client.execute(post)
|
||||
Log.d(TAG, "doPost(): " + response.getStatusLine())
|
||||
//return con.getInputStream()
|
||||
}
|
||||
response.getStatusLine().toString()
|
||||
}
|
||||
|
||||
def update(packet : String) {
|
||||
val login = AprsPacket.formatLogin(prefs.getString("callsign", null), prefs.getString("passcode", null))
|
||||
def update(packet : String) : String = {
|
||||
val login = AprsPacket.formatLogin(prefs.getString("callsign", null),
|
||||
prefs.getString("ssid", null), prefs.getString("passcode", null))
|
||||
var hostname = prefs.getString("host", null)
|
||||
if (hostname.indexOf(":") == -1) {
|
||||
hostname = "http://" + hostname + ":8080/"
|
||||
|
|
|
@ -6,7 +6,7 @@ import _root_.android.content.SharedPreferences
|
|||
abstract class AprsIsUploader(prefs : SharedPreferences) {
|
||||
def start()
|
||||
|
||||
def update(packet : String)
|
||||
def update(packet : String) : String
|
||||
|
||||
def stop()
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ object AprsPacket {
|
|||
formatLon(location.getLongitude) + "$ " + status
|
||||
}
|
||||
|
||||
def formatLogin(callsign : String, passcode : String) : String = {
|
||||
"user " + callsign.split("-")(0) + " pass " + passcode + " vers APRSdroid 0.1"
|
||||
def formatLogin(callsign : String, ssid : String, passcode : String) : String = {
|
||||
"user " + formatCallSsid(callsign, ssid) + " pass " + passcode + " vers APRSdroid 0.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,10 +71,13 @@ class AprsService extends Service with LocationListener {
|
|||
val packet = AprsPacket.formatLoc(callssid, status, location)
|
||||
Log.d(TAG, "packet: " + packet)
|
||||
try {
|
||||
var poster : AprsIsUploader = null
|
||||
if (prefs.getString("conntype", "udp") == "udp")
|
||||
new AprsUdp(prefs).update(packet)
|
||||
poster = new AprsUdp(prefs)
|
||||
else
|
||||
new AprsHttpPost(prefs).update(packet)
|
||||
poster = new AprsHttpPost(prefs)
|
||||
val status = poster.update(packet)
|
||||
i.putExtra(STATUS, status)
|
||||
i.putExtra(PACKET, packet)
|
||||
} catch {
|
||||
case e : Exception => i.putExtra(PACKET, e.getMessage())
|
||||
|
|
|
@ -13,13 +13,15 @@ class AprsUdp(prefs : SharedPreferences) extends AprsIsUploader(prefs) {
|
|||
def start() {
|
||||
}
|
||||
|
||||
def update(packet : String) {
|
||||
val login = AprsPacket.formatLogin(prefs.getString("callsign", null), prefs.getString("passcode", null))
|
||||
def update(packet : String) : String = {
|
||||
val login = AprsPacket.formatLogin(prefs.getString("callsign", null),
|
||||
prefs.getString("ssid", null), prefs.getString("passcode", null))
|
||||
var hostname = prefs.getString("host", null)
|
||||
val addr = InetAddress.getByName(hostname)
|
||||
val pbytes = (login + "\r\n" + packet + "\r\n").getBytes()
|
||||
socket.send(new DatagramPacket(pbytes, pbytes.length, addr, 8080))
|
||||
Log.d(TAG, "update(): sent " + packet + " to " + hostname)
|
||||
"packet sent"
|
||||
}
|
||||
|
||||
def stop() {
|
||||
|
|
Ładowanie…
Reference in New Issue