Merge pull request #1043 from avereha/logs

Dash: improve logging
This commit is contained in:
Milos Kozak 2021-12-07 09:57:48 +01:00 committed by GitHub
commit 540050f484
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View file

@ -43,7 +43,12 @@ class ServiceDiscoverer(
} }
logger.debug(LTag.PUMPBTCOMM, "Services discovered") logger.debug(LTag.PUMPBTCOMM, "Services discovered")
val service = gatt.getService(SERVICE_UUID.toUuid()) val service = gatt.getService(SERVICE_UUID.toUuid())
?: throw ConnectException("Service not found: $SERVICE_UUID") ?: run {
for (service in gatt.services) {
logger.debug(LTag.PUMPBTCOMM, "Found service: ${service.uuid}")
}
throw ConnectException("Service not found: $SERVICE_UUID")
}
val cmdChar = service.getCharacteristic(CharacteristicType.CMD.uuid) val cmdChar = service.getCharacteristic(CharacteristicType.CMD.uuid)
?: throw ConnectException("Characteristic not found: ${CharacteristicType.CMD.value}") ?: throw ConnectException("Characteristic not found: ${CharacteristicType.CMD.value}")
val dataChar = service.getCharacteristic(CharacteristicType.DATA.uuid) val dataChar = service.getCharacteristic(CharacteristicType.DATA.uuid)

View file

@ -394,7 +394,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
if (activeCommand == null) { if (activeCommand == null) {
Completable.complete() Completable.complete()
} else { } else {
logger.warn(LTag.PUMP, "Active command already existing: $activeCommand") logger.warn(LTag.PUMPCOMM, "Active command already existing: $activeCommand")
Completable.error( Completable.error(
java.lang.IllegalStateException( java.lang.IllegalStateException(
"Trying to send a command " + "Trying to send a command " +
@ -432,7 +432,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
override fun updateActiveCommand() = Maybe.create<CommandConfirmed> { source -> override fun updateActiveCommand() = Maybe.create<CommandConfirmed> { source ->
val activeCommand = podState.activeCommand val activeCommand = podState.activeCommand
if (activeCommand == null) { if (activeCommand == null) {
logger.error("No active command to update") logger.error(LTag.PUMPCOMM, "No active command to update")
source.onComplete() source.onComplete()
return@create return@create
} }
@ -502,6 +502,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
override fun getCommandConfirmationFromState(): CommandConfirmationFromState { override fun getCommandConfirmationFromState(): CommandConfirmationFromState {
return podState.activeCommand?.run { return podState.activeCommand?.run {
logger.debug( logger.debug(
LTag.PUMPCOMM,
"Getting command state with parameters: $activeCommand " + "Getting command state with parameters: $activeCommand " +
"lastResponse=$lastStatusResponseReceived " + "lastResponse=$lastStatusResponseReceived " +
"$sequenceNumberOfLastProgrammingCommand $historyId" "$sequenceNumberOfLastProgrammingCommand $historyId"
@ -634,7 +635,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
override fun updateFromAlarmStatusResponse(response: AlarmStatusResponse) { override fun updateFromAlarmStatusResponse(response: AlarmStatusResponse) {
logger.info( logger.info(
LTag.PUMP, LTag.PUMPCOMM,
"Received AlarmStatusResponse: $response" "Received AlarmStatusResponse: $response"
) )
podState.deliveryStatus = response.deliveryStatus podState.deliveryStatus = response.deliveryStatus
@ -678,12 +679,12 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
private fun store() { private fun store() {
try { try {
val cleanPodState = podState.copy(ltk = byteArrayOf()) // do not log ltk val cleanPodState = podState.copy(ltk = byteArrayOf()) // do not log ltk
logger.debug(LTag.PUMP, "Storing Pod state: ${Gson().toJson(cleanPodState)}") logger.debug(LTag.PUMPCOMM, "Storing Pod state: ${Gson().toJson(cleanPodState)}")
val serialized = Gson().toJson(podState) val serialized = Gson().toJson(podState)
sharedPreferences.putString(R.string.key_omnipod_dash_pod_state, serialized) sharedPreferences.putString(R.string.key_omnipod_dash_pod_state, serialized)
} catch (ex: Exception) { } catch (ex: Exception) {
logger.error(LTag.PUMP, "Failed to store Pod state", ex) logger.error(LTag.PUMPCOMM, "Failed to store Pod state", ex)
} }
} }
@ -695,7 +696,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
PodState::class.java PodState::class.java
) )
} catch (ex: Exception) { } catch (ex: Exception) {
logger.error(LTag.PUMP, "Failed to deserialize Pod state", ex) logger.error(LTag.PUMPCOMM, "Failed to deserialize Pod state", ex)
} }
} }
return PodState() return PodState()