Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import java.nio.ByteBuffer
import java.nio.charset.StandardCharsets
import java.util.concurrent.CopyOnWriteArrayList
import java.util.stream.Stream
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi
import kotlin.streams.asSequence
import kotlin.streams.asStream
import dev.slimevr.serial.SerialPort as SlimeSerialPort
Expand Down Expand Up @@ -279,10 +281,13 @@ class AndroidSerialHandler(val activity: AppCompatActivity) :
currentPort?.port?.write(buff, 0)
}

@OptIn(ExperimentalEncodingApi::class)
@Synchronized
override fun setWifi(ssid: String, passwd: String) {
writeSerial("SET WIFI \"${ssid}\" \"${passwd}\"")
addLog("-> SET WIFI \"$ssid\" \"${passwd.replace(".".toRegex(), "*")}\"\n")
val b64ssid = Base64.encode(ssid.encodeToByteArray())
val b64passwd = Base64.encode(passwd.encodeToByteArray())
writeSerial("SET BWIFI $b64ssid $b64passwd")
addLog("-> SET BWIFI $b64ssid ${"*".repeat(b64passwd.length)}\n")
}

override fun getCurrentPort(): SlimeSerialPort? = this.currentPort
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import java.util.*
import java.util.concurrent.CopyOnWriteArrayList
import java.util.stream.Stream
import kotlin.concurrent.timerTask
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi
import kotlin.streams.asSequence
import kotlin.streams.asStream
import dev.slimevr.serial.SerialPort as SlimeSerialPort
Expand Down Expand Up @@ -194,14 +196,17 @@ class DesktopSerialHandler :
currentPort?.outputStream?.write(buff)
}

@OptIn(ExperimentalEncodingApi::class)
@Synchronized
override fun setWifi(ssid: String, passwd: String) {
val os = currentPort?.outputStream ?: return
val writer = OutputStreamWriter(os)
try {
writer.append("SET WIFI \"").append(ssid).append("\" \"").append(passwd).append("\"\n")
val b64ssid = Base64.encode(ssid.encodeToByteArray())
val b64passwd = Base64.encode(passwd.encodeToByteArray())
writer.append("SET BWIFI ").append(b64ssid).append(" ").append(b64passwd).append("\n")
writer.flush()
addLog("-> SET WIFI \"$ssid\" \"${passwd.replace(".".toRegex(), "*")}\"\n")
addLog("-> SET BWIFI $b64ssid ${"*".repeat(b64passwd.length)}\n")
} catch (e: IOException) {
addLog("$e\n")
LogManager.warning("[SerialHandler] Serial port write error", e)
Expand Down