@@ -14,19 +14,19 @@ import io.runtime.mcumgr.exception.McuMgrException
14
14
import java.io.IOException
15
15
16
16
val 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
+ )
22
22
23
23
class 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
30
30
) : FirmwareUpgradeCallback {
31
31
private val TAG = " DeviceUpdate"
32
32
private var lastNotification = - 1
@@ -54,13 +54,7 @@ class DeviceUpgrade(
54
54
disconnectDevice()
55
55
Log .v(this .TAG , " Cancel" )
56
56
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 ))
64
58
}
65
59
}
66
60
@@ -93,20 +87,16 @@ class DeviceUpgrade(
93
87
disconnectDevice()
94
88
Log .v(this .TAG , " mcu exception" )
95
89
withSafePromise { promise ->
96
- promise.reject(
97
- ReactNativeMcuMgrException .fromMcuMgrException(
98
- e
99
- )
100
- )
90
+ promise.reject(ReactNativeMcuMgrException .fromMcuMgrException(e))
101
91
}
102
92
}
103
93
}
104
94
105
95
override fun onUpgradeStarted (controller : FirmwareUpgradeController ) {}
106
96
107
97
override fun onStateChanged (
108
- prevState : FirmwareUpgradeManager .State ,
109
- newState : FirmwareUpgradeManager .State
98
+ prevState : FirmwareUpgradeManager .State ,
99
+ newState : FirmwareUpgradeManager .State
110
100
) {
111
101
val stateMap: Map <String , Any ?> = mapOf (" id" to id, " state" to newState.name)
112
102
manager.upgradeStateCB(stateMap)
@@ -120,24 +110,14 @@ class DeviceUpgrade(
120
110
override fun onUpgradeFailed (state : FirmwareUpgradeManager .State , error : McuMgrException ) {
121
111
disconnectDevice()
122
112
withSafePromise { promise ->
123
- promise.reject(
124
- ReactNativeMcuMgrException .fromMcuMgrException(
125
- error
126
- )
127
- )
113
+ promise.reject(ReactNativeMcuMgrException .fromMcuMgrException(error))
128
114
}
129
115
}
130
116
131
117
override fun onUpgradeCanceled (state : FirmwareUpgradeManager .State ) {
132
118
disconnectDevice()
133
119
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 ))
141
121
}
142
122
}
143
123
0 commit comments