commit
27c5eddbb0
|
@ -21,6 +21,7 @@ import info.nightscout.androidaps.database.AppRepository
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry
|
import info.nightscout.androidaps.database.entities.UserEntry
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
||||||
|
import info.nightscout.androidaps.diaconn.events.EventDiaconnG8PumpLogReset
|
||||||
import info.nightscout.androidaps.events.EventAppExit
|
import info.nightscout.androidaps.events.EventAppExit
|
||||||
import info.nightscout.androidaps.interfaces.Config
|
import info.nightscout.androidaps.interfaces.Config
|
||||||
import info.nightscout.androidaps.interfaces.ImportExportPrefs
|
import info.nightscout.androidaps.interfaces.ImportExportPrefs
|
||||||
|
@ -339,6 +340,7 @@ class ImportExportPrefsImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun restartAppAfterImport(context: Context) {
|
private fun restartAppAfterImport(context: Context) {
|
||||||
|
rxBus.send(EventDiaconnG8PumpLogReset())
|
||||||
sp.putBoolean(R.string.key_setupwizard_processed, true)
|
sp.putBoolean(R.string.key_setupwizard_processed, true)
|
||||||
OKDialog.show(context, rh.gs(R.string.setting_imported), rh.gs(R.string.restartingapp)) {
|
OKDialog.show(context, rh.gs(R.string.setting_imported), rh.gs(R.string.restartingapp)) {
|
||||||
uel.log(Action.IMPORT_SETTINGS, Sources.Maintenance)
|
uel.log(Action.IMPORT_SETTINGS, Sources.Maintenance)
|
||||||
|
|
|
@ -316,7 +316,7 @@ enum class PumpType {
|
||||||
baseBasalMaxValue = 3.0,
|
baseBasalMaxValue = 3.0,
|
||||||
baseBasalStep = 0.01,
|
baseBasalStep = 0.01,
|
||||||
baseBasalSpecialSteps = null,
|
baseBasalSpecialSteps = null,
|
||||||
pumpCapability = PumpCapability.DanaWithHistoryCapabilities,
|
pumpCapability = PumpCapability.DiaconnCapabilities,
|
||||||
source = Sources.DiaconnG8,
|
source = Sources.DiaconnG8,
|
||||||
useHardwareLink = true);
|
useHardwareLink = true);
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
"formatVersion": 1,
|
"formatVersion": 1,
|
||||||
"database": {
|
"database": {
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"identityHash": "698b023da2f9efdc0351236c43eb20b6",
|
"identityHash": "d604d25c3edbdf18cc5a39121cf5a779",
|
||||||
"entities": [
|
"entities": [
|
||||||
{
|
{
|
||||||
"tableName": "diaconnHistory",
|
"tableName": "diaconnHistory",
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`timestamp` INTEGER NOT NULL, `code` INTEGER NOT NULL, `value` REAL NOT NULL, `bolusType` TEXT NOT NULL, `stringValue` TEXT NOT NULL, `duration` INTEGER NOT NULL, `dailyBasal` REAL NOT NULL, `dailyBolus` REAL NOT NULL, `alarm` TEXT NOT NULL, PRIMARY KEY(`timestamp`))",
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`timestamp` INTEGER NOT NULL, `code` INTEGER NOT NULL, `value` REAL NOT NULL, `bolusType` TEXT NOT NULL, `stringValue` TEXT NOT NULL, `duration` INTEGER NOT NULL, `dailyBasal` REAL NOT NULL, `dailyBolus` REAL NOT NULL, `alarm` TEXT NOT NULL, `lognum` INTEGER NOT NULL, `wrappingCount` INTEGER NOT NULL, `pumpUid` TEXT NOT NULL, PRIMARY KEY(`timestamp`))",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"fieldPath": "timestamp",
|
"fieldPath": "timestamp",
|
||||||
|
@ -61,6 +61,24 @@
|
||||||
"columnName": "alarm",
|
"columnName": "alarm",
|
||||||
"affinity": "TEXT",
|
"affinity": "TEXT",
|
||||||
"notNull": true
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "lognum",
|
||||||
|
"columnName": "lognum",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "wrappingCount",
|
||||||
|
"columnName": "wrappingCount",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "pumpUid",
|
||||||
|
"columnName": "pumpUid",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"primaryKey": {
|
"primaryKey": {
|
||||||
|
@ -77,6 +95,7 @@
|
||||||
"code",
|
"code",
|
||||||
"timestamp"
|
"timestamp"
|
||||||
],
|
],
|
||||||
|
"orders": [],
|
||||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_diaconnHistory_code_timestamp` ON `${TABLE_NAME}` (`code`, `timestamp`)"
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_diaconnHistory_code_timestamp` ON `${TABLE_NAME}` (`code`, `timestamp`)"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -86,7 +105,7 @@
|
||||||
"views": [],
|
"views": [],
|
||||||
"setupQueries": [
|
"setupQueries": [
|
||||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '698b023da2f9efdc0351236c43eb20b6')"
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'd604d25c3edbdf18cc5a39121cf5a779')"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -187,6 +187,13 @@ class DiaconnG8Pump @Inject constructor(
|
||||||
var lgsTime:Int = 0 // LGS Setting time (0~255 min)
|
var lgsTime:Int = 0 // LGS Setting time (0~255 min)
|
||||||
var lgsElapsedTime:Int = 0 // LGS Passed Time (0~255 min)
|
var lgsElapsedTime:Int = 0 // LGS Passed Time (0~255 min)
|
||||||
|
|
||||||
|
val pumpUid: String
|
||||||
|
get() = "$country-$productType-$makeYear-${makeMonth.toString().padStart(2,'0')}-${makeDay.toString().padStart(2, '0')}-${lotNo.toString().padStart(3,'0')}-${serialNo.toString().padStart(5,'0')}"
|
||||||
|
|
||||||
|
val pumpVersion: String
|
||||||
|
get() = "$majorVersion.$minorVersion"
|
||||||
|
|
||||||
|
|
||||||
fun buildDiaconnG8ProfileRecord(nsProfile: Profile): Array<Double> {
|
fun buildDiaconnG8ProfileRecord(nsProfile: Profile): Array<Double> {
|
||||||
val record = Array(24) { 0.0 }
|
val record = Array(24) { 0.0 }
|
||||||
for (hour in 0..23) {
|
for (hour in 0..23) {
|
||||||
|
@ -247,6 +254,7 @@ class DiaconnG8Pump @Inject constructor(
|
||||||
var apslastLogNum = 0 // 앱에서 처리한 마지막 로그 번호.
|
var apslastLogNum = 0 // 앱에서 처리한 마지막 로그 번호.
|
||||||
var apsWrappingCount = 0 // 앱에서 처리한 마지막 로그 번호.
|
var apsWrappingCount = 0 // 앱에서 처리한 마지막 로그 번호.
|
||||||
var isProgressPumpLogSync = false // 로그 동기화 진행 여부
|
var isProgressPumpLogSync = false // 로그 동기화 진행 여부
|
||||||
|
var isPlatformUploadStarted = false // 플랫폼 로그 동기화 진행 여부
|
||||||
|
|
||||||
// 6. bolus speed status.
|
// 6. bolus speed status.
|
||||||
var speed = 0 // 주입 속도(1 ~ 8)
|
var speed = 0 // 주입 속도(1 ~ 8)
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package info.nightscout.androidaps.diaconn.api
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
|
data class LastNoResponse(val ok: Boolean, val info:Info )
|
||||||
|
|
||||||
|
data class Info(val pumplog_no: Long)
|
||||||
|
|
||||||
|
data class ApiResponse(val ok: Boolean)
|
||||||
|
|
||||||
|
data class PumpLogDto(
|
||||||
|
@SerializedName("app_uid") val app_uid: String,
|
||||||
|
@SerializedName("app_version") val app_version: String,
|
||||||
|
@SerializedName("pump_uid") val pump_uid: String,
|
||||||
|
@SerializedName("pump_version") val pump_version: String,
|
||||||
|
@SerializedName("incarnation_num") val incarnation_num: Int,
|
||||||
|
@SerializedName("pumplog_info") val pumplog_info: List<PumpLog>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class PumpLog(
|
||||||
|
@SerializedName("pumplog_no") val pumplog_no: Long,
|
||||||
|
@SerializedName("pumplog_wrapping_count") val pumplog_wrapping_count: Int,
|
||||||
|
@SerializedName("pumplog_data") val pumplog_data: String,
|
||||||
|
@SerializedName("act_type") val act_type: String
|
||||||
|
)
|
|
@ -0,0 +1,24 @@
|
||||||
|
package info.nightscout.androidaps.diaconn.api
|
||||||
|
|
||||||
|
import retrofit2.Call
|
||||||
|
import retrofit2.http.Body
|
||||||
|
import retrofit2.http.GET
|
||||||
|
import retrofit2.http.Headers
|
||||||
|
import retrofit2.http.POST
|
||||||
|
import retrofit2.http.Query
|
||||||
|
|
||||||
|
interface DiaconnApiService {
|
||||||
|
|
||||||
|
@Headers("api-key: ${DiaconnLogUploader.UPLOAD_API_KEY}")
|
||||||
|
@GET("v1/pumplog/last_no")
|
||||||
|
fun getPumpLastNo(
|
||||||
|
@Query("pump_uid") pump_uid: String,
|
||||||
|
@Query("pump_version") pump_version: String,
|
||||||
|
@Query("incarnation_num") incarnation_num: Int): Call<LastNoResponse>
|
||||||
|
|
||||||
|
@Headers("api-key: ${DiaconnLogUploader.UPLOAD_API_KEY}")
|
||||||
|
@POST("v1/pumplog/save")
|
||||||
|
fun uploadPumpLogs(@Body pumpLogDto: PumpLogDto): Call<ApiResponse>
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package info.nightscout.androidaps.diaconn.api
|
||||||
|
|
||||||
|
import info.nightscout.shared.logging.AAPSLogger
|
||||||
|
import info.nightscout.shared.logging.LTag
|
||||||
|
import retrofit2.Retrofit
|
||||||
|
import retrofit2.converter.gson.GsonConverterFactory
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class DiaconnLogUploader @Inject constructor (
|
||||||
|
private val aapsLogger: AAPSLogger,
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
private const val BASE_URL = "https://api.diaconn.com/aaps/"
|
||||||
|
const val UPLOAD_API_KEY = "D7B3DA9FA8229D5253F3D75E1E2B1BA4"
|
||||||
|
}
|
||||||
|
|
||||||
|
private var retrofit: Retrofit? = null
|
||||||
|
|
||||||
|
fun getRetrofitInstance(): Retrofit? {
|
||||||
|
aapsLogger.debug(LTag.PUMPCOMM, "diaconn pump logs upload instance")
|
||||||
|
if (retrofit == null) {
|
||||||
|
retrofit = Retrofit.Builder()
|
||||||
|
.baseUrl(BASE_URL)
|
||||||
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
return retrofit
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,5 +15,8 @@ data class DiaconnHistoryRecord(
|
||||||
var duration: Int = 0,
|
var duration: Int = 0,
|
||||||
var dailyBasal: Double = 0.0,
|
var dailyBasal: Double = 0.0,
|
||||||
var dailyBolus: Double = 0.0,
|
var dailyBolus: Double = 0.0,
|
||||||
var alarm: String = ""
|
var alarm: String = "",
|
||||||
|
var lognum: Int = 0,
|
||||||
|
var wrappingCount: Int = 0,
|
||||||
|
var pumpUid: String = ""
|
||||||
)
|
)
|
||||||
|
|
|
@ -14,4 +14,7 @@ abstract class DiaconnHistoryRecordDao {
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
abstract fun createOrUpdate(diaconnHistoryRecord: DiaconnHistoryRecord)
|
abstract fun createOrUpdate(diaconnHistoryRecord: DiaconnHistoryRecord)
|
||||||
|
|
||||||
|
@Query( "SELECT * from $TABLE_DIACONN_HISTORY WHERE pumpUid = :pumpUid ORDER BY timestamp DESC LIMIT 1" )
|
||||||
|
abstract fun getLastRecord(pumpUid: String): DiaconnHistoryRecord?
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@ import dagger.Module
|
||||||
DiaconnG8ActivitiesModule::class,
|
DiaconnG8ActivitiesModule::class,
|
||||||
DiaconnG8ServiceModule::class,
|
DiaconnG8ServiceModule::class,
|
||||||
DiaconnG8PacketModule::class,
|
DiaconnG8PacketModule::class,
|
||||||
DiaconnHistoryModule::class
|
DiaconnHistoryModule::class,
|
||||||
|
DiaconnLogUploaderModule::class
|
||||||
])
|
])
|
||||||
|
|
||||||
open class DiaconnG8Module
|
open class DiaconnG8Module
|
|
@ -0,0 +1,12 @@
|
||||||
|
package info.nightscout.androidaps.diaconn.di
|
||||||
|
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.android.ContributesAndroidInjector
|
||||||
|
import info.nightscout.androidaps.diaconn.api.DiaconnLogUploader
|
||||||
|
import info.nightscout.androidaps.diaconn.service.DiaconnG8Service
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@Suppress("unused")
|
||||||
|
abstract class DiaconnLogUploaderModule {
|
||||||
|
@ContributesAndroidInjector abstract fun contributesDiaconnLogUploader(): DiaconnLogUploader
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.diaconn.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event
|
||||||
|
|
||||||
|
class EventDiaconnG8PumpLogReset : Event()
|
File diff suppressed because it is too large
Load diff
|
@ -14,7 +14,11 @@ import info.nightscout.androidaps.data.PumpEnactResult
|
||||||
import info.nightscout.androidaps.diaconn.DiaconnG8Plugin
|
import info.nightscout.androidaps.diaconn.DiaconnG8Plugin
|
||||||
import info.nightscout.androidaps.diaconn.DiaconnG8Pump
|
import info.nightscout.androidaps.diaconn.DiaconnG8Pump
|
||||||
import info.nightscout.androidaps.diaconn.R
|
import info.nightscout.androidaps.diaconn.R
|
||||||
|
import info.nightscout.androidaps.diaconn.api.DiaconnApiService
|
||||||
|
import info.nightscout.androidaps.diaconn.api.DiaconnLogUploader
|
||||||
|
import info.nightscout.androidaps.diaconn.database.DiaconnHistoryRecordDao
|
||||||
import info.nightscout.androidaps.diaconn.events.EventDiaconnG8NewStatus
|
import info.nightscout.androidaps.diaconn.events.EventDiaconnG8NewStatus
|
||||||
|
import info.nightscout.androidaps.diaconn.events.EventDiaconnG8PumpLogReset
|
||||||
import info.nightscout.androidaps.diaconn.packet.*
|
import info.nightscout.androidaps.diaconn.packet.*
|
||||||
import info.nightscout.androidaps.diaconn.pumplog.PumplogUtil
|
import info.nightscout.androidaps.diaconn.pumplog.PumplogUtil
|
||||||
import info.nightscout.androidaps.dialogs.BolusProgressDialog
|
import info.nightscout.androidaps.dialogs.BolusProgressDialog
|
||||||
|
@ -50,6 +54,7 @@ import java.util.concurrent.TimeUnit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
|
import kotlin.math.floor
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
class DiaconnG8Service : DaggerService() {
|
class DiaconnG8Service : DaggerService() {
|
||||||
|
@ -73,6 +78,8 @@ class DiaconnG8Service : DaggerService() {
|
||||||
@Inject lateinit var pumpSync: PumpSync
|
@Inject lateinit var pumpSync: PumpSync
|
||||||
@Inject lateinit var dateUtil: DateUtil
|
@Inject lateinit var dateUtil: DateUtil
|
||||||
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
||||||
|
@Inject lateinit var diaconnLogUploader: DiaconnLogUploader
|
||||||
|
@Inject lateinit var diaconnHistoryRecordDao: DiaconnHistoryRecordDao
|
||||||
|
|
||||||
private val disposable = CompositeDisposable()
|
private val disposable = CompositeDisposable()
|
||||||
private val mBinder: IBinder = LocalBinder()
|
private val mBinder: IBinder = LocalBinder()
|
||||||
|
@ -129,7 +136,7 @@ class DiaconnG8Service : DaggerService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sendMessage(message: DiaconnG8Packet) {
|
private fun sendMessage(message: DiaconnG8Packet) {
|
||||||
bleCommonService.sendMessage(message, 500)
|
bleCommonService.sendMessage(message, 2000)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun readPumpStatus() {
|
fun readPumpStatus() {
|
||||||
|
@ -232,6 +239,7 @@ class DiaconnG8Service : DaggerService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadHistory(): PumpEnactResult {
|
fun loadHistory(): PumpEnactResult {
|
||||||
|
|
||||||
if (!diaconnG8Plugin.isInitialized()) {
|
if (!diaconnG8Plugin.isInitialized()) {
|
||||||
val result = PumpEnactResult(injector).success(false)
|
val result = PumpEnactResult(injector).success(false)
|
||||||
result.comment = "pump not initialized"
|
result.comment = "pump not initialized"
|
||||||
|
@ -245,6 +253,16 @@ class DiaconnG8Service : DaggerService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val result = PumpEnactResult(injector)
|
val result = PumpEnactResult(injector)
|
||||||
|
var apsLastLogNum = 9999
|
||||||
|
var apsWrappingCount = -1
|
||||||
|
// get saved last loginfo
|
||||||
|
val diaconnHistoryRecord = diaconnHistoryRecordDao.getLastRecord(diaconnG8Pump.pumpUid)
|
||||||
|
aapsLogger.error(LTag.PUMPCOMM, "diaconnHistoryRecord :: $diaconnHistoryRecord")
|
||||||
|
|
||||||
|
if(diaconnHistoryRecord != null) {
|
||||||
|
apsLastLogNum = diaconnHistoryRecord.lognum
|
||||||
|
apsWrappingCount = diaconnHistoryRecord.wrappingCount
|
||||||
|
}
|
||||||
|
|
||||||
// pump log status
|
// pump log status
|
||||||
val pumpLastNum = diaconnG8Pump.pumpLastLogNum
|
val pumpLastNum = diaconnG8Pump.pumpLastLogNum
|
||||||
|
@ -252,74 +270,107 @@ class DiaconnG8Service : DaggerService() {
|
||||||
val apsIncarnationNum = sp.getInt(rh.gs(R.string.apsIncarnationNo), 65536)
|
val apsIncarnationNum = sp.getInt(rh.gs(R.string.apsIncarnationNo), 65536)
|
||||||
// aps last log num
|
// aps last log num
|
||||||
val pumpSerialNo = sp.getInt(rh.gs(R.string.pumpserialno), 0)
|
val pumpSerialNo = sp.getInt(rh.gs(R.string.pumpserialno), 0)
|
||||||
var apsWrappingCount = sp.getInt(rh.gs(R.string.apsWrappingCount), 0)
|
|
||||||
var apsLastLogNum = sp.getInt(rh.gs(R.string.apslastLogNum), 0)
|
|
||||||
|
|
||||||
// if first install app
|
// if first install app
|
||||||
if (apsWrappingCount == 0 && apsLastLogNum == 0) {
|
if (apsWrappingCount == -1 && apsLastLogNum == 9999 ) {
|
||||||
pumpLogDefaultSetting()
|
apsWrappingCount = pumpWrappingCount
|
||||||
|
apsLastLogNum = if (pumpLastNum - 1 < 0) 0 else pumpLastNum -2
|
||||||
}
|
}
|
||||||
|
|
||||||
// if pump reset
|
|
||||||
if (apsIncarnationNum != diaconnG8Pump.pumpIncarnationNum) {
|
|
||||||
pumpLogDefaultSetting()
|
|
||||||
sp.putInt(rh.gs(R.string.apsIncarnationNo), diaconnG8Pump.pumpIncarnationNum)
|
|
||||||
}
|
|
||||||
|
|
||||||
// if another pump
|
// if another pump
|
||||||
if (pumpSerialNo != diaconnG8Pump.serialNo) {
|
if (pumpSerialNo != diaconnG8Pump.serialNo) {
|
||||||
pumpLogDefaultSetting()
|
apsWrappingCount = pumpWrappingCount
|
||||||
|
apsLastLogNum = if (pumpLastNum - 1 < 0) 0 else pumpLastNum -2
|
||||||
sp.putInt(rh.gs(R.string.pumpserialno), diaconnG8Pump.serialNo)
|
sp.putInt(rh.gs(R.string.pumpserialno), diaconnG8Pump.serialNo)
|
||||||
}
|
}
|
||||||
|
// if pump reset
|
||||||
apsWrappingCount = sp.getInt(rh.gs(R.string.apsWrappingCount), 0)
|
if (apsIncarnationNum != diaconnG8Pump.pumpIncarnationNum) {
|
||||||
apsLastLogNum = sp.getInt(rh.gs(R.string.apslastLogNum), 0)
|
apsWrappingCount = pumpWrappingCount
|
||||||
|
apsLastLogNum = if (pumpLastNum - 1 < 0) 0 else pumpLastNum -2
|
||||||
val apsLastNum = apsWrappingCount * 10000 + apsLastLogNum
|
sp.putInt(R.string.apsIncarnationNo, apsIncarnationNum)
|
||||||
if ((pumpWrappingCount * 10000 + pumpLastNum) < apsLastLogNum) {
|
|
||||||
pumpLogDefaultSetting()
|
|
||||||
}
|
|
||||||
|
|
||||||
val start: Int? // log sync startNo
|
|
||||||
val end: Int? // log sync endNo
|
|
||||||
if (((pumpWrappingCount * 10000 + pumpLastNum) - apsLastNum) > 10000) {
|
|
||||||
start = pumpLastNum
|
|
||||||
end = 10000
|
|
||||||
} else if (pumpWrappingCount > apsWrappingCount && apsLastLogNum < 9999) {
|
|
||||||
start = apsLastLogNum + 1
|
|
||||||
end = 10000
|
|
||||||
} else if (pumpWrappingCount > apsWrappingCount && apsLastLogNum >= 9999) {
|
|
||||||
start = 0
|
|
||||||
end = pumpLastNum
|
|
||||||
} else {
|
|
||||||
start = apsLastLogNum + 1
|
|
||||||
end = pumpLastNum
|
|
||||||
}
|
}
|
||||||
|
aapsLogger.debug(LTag.PUMPCOMM, "apsWrappingCount : $apsWrappingCount, apsLastLogNum : $apsLastLogNum")
|
||||||
|
|
||||||
// pump log loop size
|
// pump log loop size
|
||||||
val pumpLogPageSize = 11
|
val pumpLogPageSize = 11
|
||||||
val loopCount: Int = ceil(((end - start) / 11.0)).toInt()
|
val (start, end, loopSize) = getLogLoopCount(apsLastLogNum, apsWrappingCount, pumpLastNum, pumpWrappingCount, false)
|
||||||
|
aapsLogger.debug(LTag.PUMPCOMM, "loopinfo start : $start, end : $end, loopSize : $loopSize")
|
||||||
// log sync start!
|
// log sync start!
|
||||||
if (loopCount > 0) {
|
if (loopSize > 0) {
|
||||||
diaconnG8Pump.isProgressPumpLogSync = true
|
for (i in 0 until loopSize) {
|
||||||
|
|
||||||
for (i in 0 until loopCount) {
|
|
||||||
val startLogNo: Int = start + i * pumpLogPageSize
|
val startLogNo: Int = start + i * pumpLogPageSize
|
||||||
val endLogNo: Int = startLogNo + min(end - startLogNo, pumpLogPageSize)
|
val endLogNo: Int = startLogNo + min(end - startLogNo, pumpLogPageSize)
|
||||||
val msg = BigLogInquirePacket(injector, startLogNo, endLogNo, 100)
|
val msg = BigLogInquirePacket(injector, startLogNo, endLogNo, 100)
|
||||||
sendMessage(msg)
|
sendMessage(msg, 500)
|
||||||
}
|
|
||||||
diaconnG8Pump.historyDoneReceived = true
|
|
||||||
while (!diaconnG8Pump.historyDoneReceived && bleCommonService.isConnected) {
|
|
||||||
SystemClock.sleep(100)
|
|
||||||
}
|
}
|
||||||
result.success(true)
|
result.success(true)
|
||||||
diaconnG8Pump.lastConnection = System.currentTimeMillis()
|
diaconnG8Pump.lastConnection = System.currentTimeMillis()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// upload pump log to Diaconn Cloud
|
||||||
|
if (sp.getBoolean(R.string.key_diaconn_g8_cloudsend, true)) {
|
||||||
|
SystemClock.sleep(1000)
|
||||||
|
try {
|
||||||
|
// getting last uploaded log number
|
||||||
|
val retrofit = diaconnLogUploader.getRetrofitInstance()
|
||||||
|
val api = retrofit?.create(DiaconnApiService::class.java)
|
||||||
|
val response = api?.getPumpLastNo(diaconnG8Pump.pumpUid, diaconnG8Pump.pumpVersion, diaconnG8Pump.pumpIncarnationNum)?.execute()
|
||||||
|
if(response?.body()?.ok == true) {
|
||||||
|
aapsLogger.debug(LTag.PUMPCOMM, "pumplog_no = ${response.body()?.info?.pumplog_no}")
|
||||||
|
val platformLastNo = response.body()?.info?.pumplog_no!!
|
||||||
|
val platformWrappingCount: Int = floor(platformLastNo / 10000.0).toInt()
|
||||||
|
val platformLogNo: Int = if (platformLastNo.toInt() == -1) {
|
||||||
|
9999
|
||||||
|
} else {
|
||||||
|
(platformLastNo % 10000).toInt()
|
||||||
|
}
|
||||||
|
aapsLogger.debug(LTag.PUMPCOMM, "platformLogNo: $platformLogNo, platformWrappingCount: $platformWrappingCount")
|
||||||
|
|
||||||
|
// 페이지 사이즈로 처리할 때 루핑 횟수 계산
|
||||||
|
val (platformStart, platformEnd, platformLoopSize) = getLogLoopCount(platformLogNo, platformWrappingCount, pumpLastNum, pumpWrappingCount, true)
|
||||||
|
if(platformLoopSize > 0) {
|
||||||
|
diaconnG8Pump.isPlatformUploadStarted = true
|
||||||
|
for (i in 0 until platformLoopSize) {
|
||||||
|
rxBus.send(EventPumpStatusChanged("클라우드동기화 진행 중 : $i / $platformLoopSize"))
|
||||||
|
val startLogNo: Int = platformStart + i * pumpLogPageSize
|
||||||
|
val endLogNo: Int = startLogNo + min(platformEnd - startLogNo, pumpLogPageSize)
|
||||||
|
val msg = BigLogInquirePacket(injector, startLogNo, endLogNo, 100)
|
||||||
|
sendMessage(msg, 500)
|
||||||
|
}
|
||||||
|
SystemClock.sleep(1000)
|
||||||
|
diaconnG8Pump.isPlatformUploadStarted = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e:Exception) {
|
||||||
|
aapsLogger.error("Unhandled exception", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getLogLoopCount(lastLogNum: Int, wrappingCount: Int, pumpLastNum: Int, pumpWrappingCount: Int, isPlatform: Boolean): Triple<Int, Int, Int> {
|
||||||
|
val start: Int// log sync start number
|
||||||
|
val end: Int // log sync end number1311
|
||||||
|
aapsLogger.debug(LTag.PUMPCOMM, "lastLogNum : $lastLogNum, wrappingCount : $wrappingCount , pumpLastNum: $pumpLastNum, pumpWrappingCount : $pumpWrappingCount")
|
||||||
|
|
||||||
|
if ((pumpWrappingCount * 10000 + pumpLastNum - lastLogNum > 10000 && isPlatform)) {
|
||||||
|
start = pumpLastNum
|
||||||
|
end = 10000
|
||||||
|
} else if (pumpWrappingCount > wrappingCount && lastLogNum < 9999) {
|
||||||
|
start = (lastLogNum + 1)
|
||||||
|
end = 10000
|
||||||
|
} else if (pumpWrappingCount > wrappingCount && lastLogNum >= 9999 && isPlatform) {
|
||||||
|
start = 0 // 처음부터 시작
|
||||||
|
end = pumpLastNum
|
||||||
|
} else {
|
||||||
|
start = (lastLogNum + 1)
|
||||||
|
end = pumpLastNum
|
||||||
|
}
|
||||||
|
val size = ceil((end - start) / 11.0).toInt()
|
||||||
|
//
|
||||||
|
return Triple(start, end, size)
|
||||||
|
}
|
||||||
|
|
||||||
fun setUserSettings(): PumpEnactResult {
|
fun setUserSettings(): PumpEnactResult {
|
||||||
val result = PumpEnactResult(injector)
|
val result = PumpEnactResult(injector)
|
||||||
|
|
||||||
|
@ -336,7 +387,7 @@ class DiaconnG8Service : DaggerService() {
|
||||||
if (diaconnG8Pump.otpNumber == 0) {
|
if (diaconnG8Pump.otpNumber == 0) {
|
||||||
aapsLogger.error(LTag.PUMPCOMM, "otp is not received yet")
|
aapsLogger.error(LTag.PUMPCOMM, "otp is not received yet")
|
||||||
result.success(false)
|
result.success(false)
|
||||||
result.comment("펌프와 연결 상태를 확인해주세요.")
|
result.comment("")
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
sendMessage(AppConfirmSettingPacket(injector, msg.msgType, diaconnG8Pump.otpNumber))
|
sendMessage(AppConfirmSettingPacket(injector, msg.msgType, diaconnG8Pump.otpNumber))
|
||||||
|
@ -348,6 +399,13 @@ class DiaconnG8Service : DaggerService() {
|
||||||
fun bolus(insulin: Double, carbs: Int, carbTime: Long, t: EventOverviewBolusProgress.Treatment): Boolean {
|
fun bolus(insulin: Double, carbs: Int, carbTime: Long, t: EventOverviewBolusProgress.Treatment): Boolean {
|
||||||
if (!isConnected) return false
|
if (!isConnected) return false
|
||||||
if (BolusProgressDialog.stopPressed) return false
|
if (BolusProgressDialog.stopPressed) return false
|
||||||
|
|
||||||
|
// Only Carbs
|
||||||
|
if (carbs > 0 && insulin == 0.0) {
|
||||||
|
pumpSync.syncCarbsWithTimestamp(carbTime, carbs.toDouble(), null, PumpType.DIACONN_G8, diaconnG8Pump.serialNo.toString())
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.startingbolus)))
|
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.startingbolus)))
|
||||||
|
|
||||||
// bolus speed setting
|
// bolus speed setting
|
||||||
|
@ -614,9 +672,9 @@ class DiaconnG8Service : DaggerService() {
|
||||||
(basalList[23] * 100).toInt()
|
(basalList[23] * 100).toInt()
|
||||||
)
|
)
|
||||||
// setting basal pattern 1,2,3,4
|
// setting basal pattern 1,2,3,4
|
||||||
sendMessage(requestReqPacket1)
|
sendMessage(requestReqPacket1, 500)
|
||||||
sendMessage(requestReqPacket2)
|
sendMessage(requestReqPacket2, 500)
|
||||||
sendMessage(requestReqPacket3)
|
sendMessage(requestReqPacket3, 500)
|
||||||
sendMessage(requestReqPacket4)
|
sendMessage(requestReqPacket4)
|
||||||
|
|
||||||
// otp process
|
// otp process
|
||||||
|
@ -634,13 +692,6 @@ class DiaconnG8Service : DaggerService() {
|
||||||
return requestReqPacket4.success()
|
return requestReqPacket4.success()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun pumpLogDefaultSetting() {
|
|
||||||
val apsWrappingCount = diaconnG8Pump.pumpWrappingCount
|
|
||||||
val apsLastLogNum = if (diaconnG8Pump.pumpLastLogNum - 1 < 0) 0 else diaconnG8Pump.pumpLastLogNum - 1
|
|
||||||
sp.putInt(rh.gs(R.string.apslastLogNum), apsLastLogNum)
|
|
||||||
sp.putInt(rh.gs(R.string.apsWrappingCount), apsWrappingCount)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun processConfirm(msgType: Byte): Boolean {
|
private fun processConfirm(msgType: Byte): Boolean {
|
||||||
// pump confirm
|
// pump confirm
|
||||||
if (diaconnG8Pump.otpNumber == 0) {
|
if (diaconnG8Pump.otpNumber == 0) {
|
||||||
|
@ -658,7 +709,7 @@ class DiaconnG8Service : DaggerService() {
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
sendMessage(AppConfirmSettingPacket(injector, msgType, diaconnG8Pump.otpNumber), 2000)
|
sendMessage(AppConfirmSettingPacket(injector, msgType, diaconnG8Pump.otpNumber))
|
||||||
diaconnG8Pump.otpNumber = 0
|
diaconnG8Pump.otpNumber = 0
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,8 @@
|
||||||
<string name="diaconn_g8_logcanulachange_title">바늘 교체</string>
|
<string name="diaconn_g8_logcanulachange_title">바늘 교체</string>
|
||||||
<string name="diaconn_g8_logcanulachange_summary">로그 동기화 시 케어포털 \"위치 교체\" 정보 자동 업로드</string>
|
<string name="diaconn_g8_logcanulachange_summary">로그 동기화 시 케어포털 \"위치 교체\" 정보 자동 업로드</string>
|
||||||
<string name="diaconn_g8_logbatterychange_summary">로그 동기화 시 케어포털 \"베터리 교체\" 정보 자동 업로드</string>
|
<string name="diaconn_g8_logbatterychange_summary">로그 동기화 시 케어포털 \"베터리 교체\" 정보 자동 업로드</string>
|
||||||
|
<string name="diaconn_g8_cloudsend_summary">펌프 로그정보를 \"디아콘 클라우드\"로 자동 업로드</string>
|
||||||
|
<string name="diaconn_g8_cloudsend_title">디아콘 클라우드 전송</string>
|
||||||
<string name="diaconn_g8_logbatterychange_title">베터리 교체</string>
|
<string name="diaconn_g8_logbatterychange_title">베터리 교체</string>
|
||||||
<string name="diaconn_g8_logsyncinprogress">로그 동기화 진행 중</string>
|
<string name="diaconn_g8_logsyncinprogress">로그 동기화 진행 중</string>
|
||||||
<string name="diaconn_g8_loginsulinshorage">인슐린 부족 경고</string>
|
<string name="diaconn_g8_loginsulinshorage">인슐린 부족 경고</string>
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
<string name="key_diaconn_g8_logbatterychange" translatable="false">diaconn_g8_logbatterychanges</string>
|
<string name="key_diaconn_g8_logbatterychange" translatable="false">diaconn_g8_logbatterychanges</string>
|
||||||
<string name="key_diaconn_g8_loginsulinchange" translatable="false">diaconn_g8_loginsulinchange</string>
|
<string name="key_diaconn_g8_loginsulinchange" translatable="false">diaconn_g8_loginsulinchange</string>
|
||||||
<string name="key_diaconn_g8_logneedlechange" translatable="false">diaconn_g8_logneedlechange</string>
|
<string name="key_diaconn_g8_logneedlechange" translatable="false">diaconn_g8_logneedlechange</string>
|
||||||
|
<string name="key_diaconn_g8_cloudsend" translatable="false">diaconn_g8_cloudsend</string>
|
||||||
|
|
||||||
<string name="resetpairing" >Reset Pairing</string>
|
<string name="resetpairing" >Reset Pairing</string>
|
||||||
<string name="diaconn_nodeviceavailable" >No Device available</string>
|
<string name="diaconn_nodeviceavailable" >No Device available</string>
|
||||||
|
@ -166,5 +167,7 @@
|
||||||
<string name="diaconn_g8_errorcode_34">LGS status is OFF, OFF Command is declined.</string>
|
<string name="diaconn_g8_errorcode_34">LGS status is OFF, OFF Command is declined.</string>
|
||||||
<string name="diaconn_g8_errorcode_35">Tempbasal start is rejected when tempbasal is running</string>
|
<string name="diaconn_g8_errorcode_35">Tempbasal start is rejected when tempbasal is running</string>
|
||||||
<string name="diaconn_g8_errorcode_36">Tempbasal stop is rejected when tempbasal is not running</string>
|
<string name="diaconn_g8_errorcode_36">Tempbasal stop is rejected when tempbasal is not running</string>
|
||||||
|
<string name="diaconn_g8_cloudsend_summary">Send pump logs to the Diaconn Cloud.</string>
|
||||||
|
<string name="diaconn_g8_cloudsend_title">Diaconn Cloud Sync</string>
|
||||||
|
<string name="key_diaconn_g8_appuid">diaconn_g8_appuid</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -45,6 +45,12 @@
|
||||||
android:summary="@string/diaconn_g8_logbatterychange_summary"
|
android:summary="@string/diaconn_g8_logbatterychange_summary"
|
||||||
android:title="@string/diaconn_g8_logbatterychange_title" />
|
android:title="@string/diaconn_g8_logbatterychange_title" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:defaultValue="true"
|
||||||
|
android:key="@string/key_diaconn_g8_cloudsend"
|
||||||
|
android:summary="@string/diaconn_g8_cloudsend_summary"
|
||||||
|
android:title="@string/diaconn_g8_cloudsend_title" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
</androidx.preference.PreferenceScreen>
|
</androidx.preference.PreferenceScreen>
|
Loading…
Reference in a new issue