@@ -14,19 +14,19 @@ import io.runtime.mcumgr.exception.McuMgrException
1414import java.io.IOException
1515
1616val UpgradeModes =
17- mapOf (
18- 1 to FirmwareUpgradeManager .Mode .TEST_AND_CONFIRM ,
19- 2 to FirmwareUpgradeManager .Mode .CONFIRM_ONLY ,
20- 3 to FirmwareUpgradeManager .Mode .TEST_ONLY
21- )
17+ mapOf (
18+ 1 to FirmwareUpgradeManager .Mode .TEST_AND_CONFIRM ,
19+ 2 to FirmwareUpgradeManager .Mode .CONFIRM_ONLY ,
20+ 3 to FirmwareUpgradeManager .Mode .TEST_ONLY
21+ )
2222
2323class DeviceUpgrade (
24- private val id : String ,
25- device : BluetoothDevice ,
26- private val context : Context ,
27- private val updateFileUri : Uri ,
28- private val updateOptions : UpdateOptions ,
29- private val manager : ReactNativeMcuManagerModule
24+ private val id : String ,
25+ device : BluetoothDevice ,
26+ private val context : Context ,
27+ private val updateFileUri : Uri ,
28+ private val updateOptions : UpdateOptions ,
29+ private val manager : ReactNativeMcuManagerModule
3030) : FirmwareUpgradeCallback {
3131 private val TAG = " DeviceUpdate"
3232 private var lastNotification = - 1
@@ -54,13 +54,7 @@ class DeviceUpgrade(
5454 disconnectDevice()
5555 Log .v(this .TAG , " Cancel" )
5656 withSafePromise { promise ->
57- promise.reject(
58- CodedException (
59- " UPGRADE_CANCELLED" ,
60- " Upgrade cancelled" ,
61- null
62- )
63- )
57+ promise.reject(CodedException (" UPGRADE_CANCELLED" , " Upgrade cancelled" , null ))
6458 }
6559 }
6660
@@ -93,20 +87,16 @@ class DeviceUpgrade(
9387 disconnectDevice()
9488 Log .v(this .TAG , " mcu exception" )
9589 withSafePromise { promise ->
96- promise.reject(
97- ReactNativeMcuMgrException .fromMcuMgrException(
98- e
99- )
100- )
90+ promise.reject(ReactNativeMcuMgrException .fromMcuMgrException(e))
10191 }
10292 }
10393 }
10494
10595 override fun onUpgradeStarted (controller : FirmwareUpgradeController ) {}
10696
10797 override fun onStateChanged (
108- prevState : FirmwareUpgradeManager .State ,
109- newState : FirmwareUpgradeManager .State
98+ prevState : FirmwareUpgradeManager .State ,
99+ newState : FirmwareUpgradeManager .State
110100 ) {
111101 val stateMap: Map <String , Any ?> = mapOf (" id" to id, " state" to newState.name)
112102 manager.upgradeStateCB(stateMap)
@@ -120,24 +110,14 @@ class DeviceUpgrade(
120110 override fun onUpgradeFailed (state : FirmwareUpgradeManager .State , error : McuMgrException ) {
121111 disconnectDevice()
122112 withSafePromise { promise ->
123- promise.reject(
124- ReactNativeMcuMgrException .fromMcuMgrException(
125- error
126- )
127- )
113+ promise.reject(ReactNativeMcuMgrException .fromMcuMgrException(error))
128114 }
129115 }
130116
131117 override fun onUpgradeCanceled (state : FirmwareUpgradeManager .State ) {
132118 disconnectDevice()
133119 withSafePromise { promise ->
134- promise.reject(
135- CodedException (
136- " UPGRADE_CANCELLED" ,
137- " Upgrade cancelled" ,
138- null
139- )
140- )
120+ promise.reject(CodedException (" UPGRADE_CANCELLED" , " Upgrade cancelled" , null ))
141121 }
142122 }
143123
0 commit comments