Message delimeter simplified
This commit is contained in:
@@ -55,6 +55,9 @@ class BluetoothViewModel(
|
|||||||
private val deviceStateMessageAdapter = moshi.adapter(DeviceState::class.java)
|
private val deviceStateMessageAdapter = moshi.adapter(DeviceState::class.java)
|
||||||
private val pidSittingsMessageAdapter = moshi.adapter(PidSettings::class.java)
|
private val pidSittingsMessageAdapter = moshi.adapter(PidSettings::class.java)
|
||||||
private val pidSittingsRequiredMessageAdapter = moshi.adapter(PidSettingRequiredMessage::class.java)
|
private val pidSittingsRequiredMessageAdapter = moshi.adapter(PidSettingRequiredMessage::class.java)
|
||||||
|
companion object {
|
||||||
|
const val messageDelimeter = "\n"
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
bluetoothController.isConnected.onEach { isConnected ->
|
bluetoothController.isConnected.onEach { isConnected ->
|
||||||
@@ -203,20 +206,11 @@ class BluetoothViewModel(
|
|||||||
super.onCleared()
|
super.onCleared()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sendHelloWorld() {
|
|
||||||
viewModelScope.launch {
|
|
||||||
bluetoothController.trySendMessage(
|
|
||||||
"{\"p1\": {\"p\": 1.5, \"i\": 1.5, \"d\": 1.5}}\n\r".toByteArray()
|
|
||||||
//"{\"p1\": [1.5, 1.5, 1.5]}\n\r".toByteArray()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun startImuCalibration() {
|
fun startImuCalibration() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val message = statusMessageAdapter.toJson(
|
val message = statusMessageAdapter.toJson(
|
||||||
ChangedDeviceStatus(DeviceStatus.IsImuCalibration)
|
ChangedDeviceStatus(DeviceStatus.IsImuCalibration)
|
||||||
) + "\n\r"
|
) + messageDelimeter
|
||||||
val isSuccess = bluetoothController.trySendMessage(
|
val isSuccess = bluetoothController.trySendMessage(
|
||||||
message.toByteArray()
|
message.toByteArray()
|
||||||
)
|
)
|
||||||
@@ -234,7 +228,7 @@ class BluetoothViewModel(
|
|||||||
|
|
||||||
fun requestPidSettings() {
|
fun requestPidSettings() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val message = pidSittingsRequiredMessageAdapter.toJson(PidSettingRequiredMessage(true)) + "\n\r"
|
val message = pidSittingsRequiredMessageAdapter.toJson(PidSettingRequiredMessage(true)) + messageDelimeter
|
||||||
Log.i("BluetoothVM", "Requested PID settings: $message")
|
Log.i("BluetoothVM", "Requested PID settings: $message")
|
||||||
val isSuccess = bluetoothController.trySendMessage(
|
val isSuccess = bluetoothController.trySendMessage(
|
||||||
message.toByteArray()
|
message.toByteArray()
|
||||||
@@ -247,7 +241,7 @@ class BluetoothViewModel(
|
|||||||
|
|
||||||
fun applyPidSettings(pidSettings: PidSettings) {
|
fun applyPidSettings(pidSettings: PidSettings) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val message = pidSittingsMessageAdapter.toJson(pidSettings) + "\n\r"
|
val message = pidSittingsMessageAdapter.toJson(pidSettings) + messageDelimeter
|
||||||
val isSuccess = bluetoothController.trySendMessage(message.toByteArray())
|
val isSuccess = bluetoothController.trySendMessage(message.toByteArray())
|
||||||
if(!isSuccess) {
|
if(!isSuccess) {
|
||||||
Log.e("BluetoothVM", "Failed to request PID settings: $message")
|
Log.e("BluetoothVM", "Failed to request PID settings: $message")
|
||||||
|
|||||||
Reference in New Issue
Block a user