add PUMP CONNECT and PUMP DISCONNECT commands

This commit is contained in:
Lexsus 2020-05-26 12:48:21 +03:00
parent b9806d0ea9
commit 11f768636e
2 changed files with 76 additions and 15 deletions

View file

@ -85,7 +85,7 @@ class SmsCommunicatorPlugin @Inject constructor(
"LOOP" to "LOOP STOP/DISABLE/START/ENABLE/RESUME/STATUS\nLOOP SUSPEND 20", "LOOP" to "LOOP STOP/DISABLE/START/ENABLE/RESUME/STATUS\nLOOP SUSPEND 20",
"TREATMENTS" to "TREATMENTS REFRESH", "TREATMENTS" to "TREATMENTS REFRESH",
"NSCLIENT" to "NSCLIENT RESTART", "NSCLIENT" to "NSCLIENT RESTART",
"PUMP" to "PUMP", "PUMP" to "PUMP\nPUMP CONNECT\nPUMP DISCONNECT 30\n",
"BASAL" to "BASAL STOP/CANCEL\nBASAL 0.3\nBASAL 0.3 20\nBASAL 30%\nBASAL 30% 20\n", "BASAL" to "BASAL STOP/CANCEL\nBASAL 0.3\nBASAL 0.3 20\nBASAL 30%\nBASAL 30% 20\n",
"BOLUS" to "BOLUS 1.2\nBOLUS 1.2 MEAL", "BOLUS" to "BOLUS 1.2\nBOLUS 1.2 MEAL",
"EXTENDED" to "EXTENDED STOP/CANCEL\nEXTENDED 2 120", "EXTENDED" to "EXTENDED STOP/CANCEL\nEXTENDED 2 120",
@ -227,8 +227,9 @@ class SmsCommunicatorPlugin @Inject constructor(
"NSCLIENT" -> "NSCLIENT" ->
if (splitted.size == 2) processNSCLIENT(splitted, receivedSms) if (splitted.size == 2) processNSCLIENT(splitted, receivedSms)
else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat))) else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat)))
"PUMP" -> "PUMP" ->//TODO remoteCommandsAllowed
if (splitted.size == 1) processPUMP(receivedSms) if (!remoteCommandsAllowed) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_remotecommandnotallowed)))
else if (splitted.size <=3) processPUMP(splitted,receivedSms)
else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat))) else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat)))
"PROFILE" -> "PROFILE" ->
if (!remoteCommandsAllowed) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_remotecommandnotallowed))) if (!remoteCommandsAllowed) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_remotecommandnotallowed)))
@ -441,20 +442,77 @@ class SmsCommunicatorPlugin @Inject constructor(
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat))) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat)))
} }
private fun processPUMP(receivedSms: Sms) { private fun processPUMP(splitted: Array<String>,receivedSms: Sms) {
commandQueue.readStatus("SMS", object : Callback() { if (splitted.size == 1) {
override fun run() { commandQueue.readStatus("SMS", object : Callback() {
val pump = activePlugin.activePump override fun run() {
if (result.success) { val pump = activePlugin.activePump
val reply = pump.shortStatus(true) if (result.success) {
sendSMS(Sms(receivedSms.phoneNumber, reply)) val reply = pump.shortStatus(true)
} else { sendSMS(Sms(receivedSms.phoneNumber, reply))
val reply = resourceHelper.gs(R.string.readstatusfailed) } else {
sendSMS(Sms(receivedSms.phoneNumber, reply)) val reply = resourceHelper.gs(R.string.readstatusfailed)
sendSMS(Sms(receivedSms.phoneNumber, reply))
}
} }
})
receivedSms.processed = true
}
else if ((splitted.size == 2) && (splitted[1].equals("CONNECT", ignoreCase = true)))
{
val passCode = generatePasscode()
val reply = String.format(resourceHelper.gs(R.string.smscommunicator_pumpconnect),passCode)
receivedSms.processed = true
messageToConfirm = AuthRequest(injector,receivedSms,reply,passCode,object : SmsAction(){
override fun run() {
commandQueue.cancelTempBasal(true, object : Callback() {
override fun run() {
if (!result.success) {
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_pumpconnectfail)))
}
else
{
loopPlugin.suspendTo(0L)
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.reconnect)))
rxBus.send(EventRefreshOverview("SMS_PUMP_START"))
//rxBus.send(EventRefreshOverview("SMS_PUMP_CONNECT"))
sp.putBoolean(R.string.key_objectiveusereconnect, true)
loopPlugin.createOfflineEvent(0)
}
}
})
}
})
}
else if (splitted.size == 3)
{
if (splitted[1].equals("DISCONNECT", ignoreCase = true)){
val minutes = SafeParse.stringToInt(splitted[2])
val passCode = generatePasscode()
val reply = String.format(resourceHelper.gs(R.string.smscommunicator_pumpdisconnect),minutes,passCode)
receivedSms.processed = true
messageToConfirm = AuthRequest(injector,receivedSms,reply,passCode,object : SmsAction(){
override fun run() {
val profile = profileFunction.getProfile()
loopPlugin.disconnectPump(minutes, profile)
rxBus.send(EventRefreshOverview("SMS_PUMP_DISCONNECT"))
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.pumpsuspended)))
//rxBus.send(EventRefreshOverview("suspendmenu"))
}
})
} }
}) else{
receivedSms.processed = true sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat)))
return
}
}
} }
private fun processPROFILE(splitted: Array<String>, receivedSms: Sms) { // load profiles private fun processPROFILE(splitted: Array<String>, receivedSms: Sms) { // load profiles

View file

@ -300,6 +300,9 @@
<string name="smscommunicator_loopisenabled">Loop is enabled</string> <string name="smscommunicator_loopisenabled">Loop is enabled</string>
<string name="valuelimitedto">%1$.2f limited to %2$.2f</string> <string name="valuelimitedto">%1$.2f limited to %2$.2f</string>
<string name="valueoutofrange">Value %1$s is out of hard limits</string> <string name="valueoutofrange">Value %1$s is out of hard limits</string>
<string name="smscommunicator_pumpconnect">To connect pump reply with code %1$s</string>
<string name="smscommunicator_pumpdisconnect">To disconnect pump to %1d minutes reply with code %2$s</string>
<string name="smscommunicator_pumpconnectfail">To connect pump failed</string>
<string name="smscommunicator_remotecommandnotallowed">Remote command is not allowed</string> <string name="smscommunicator_remotecommandnotallowed">Remote command is not allowed</string>
<string name="smscommunicator_remotebolusnotallowed">Remote bolus not available. Try again later.</string> <string name="smscommunicator_remotebolusnotallowed">Remote bolus not available. Try again later.</string>
<string name="smscommunicator_basalreplywithcode">To start basal %1$.2fU/h for %2$d min reply with code %3$s</string> <string name="smscommunicator_basalreplywithcode">To start basal %1$.2fU/h for %2$d min reply with code %3$s</string>