Skip to content

Conversation

@efidoman
Copy link
Contributor

This PR adds the ability to inject custom script(s) to run synchronously at the end of every oref0-pump-loop. Any script files with executable flag set will be run as follows:

If the script file is placed in the plugins/every folder then the script runs at the end of every loop.
If the script file is placed in the plugins/once folder then the script once at the end of the current loop.

Script files placed in the plugins/once folder will be removed once run. This allows for a use case such as the following:

Logger and Lookout both call a pump utility called fakemeter that helps out users in offline mode by sending the current CGM (Dexcom) glucose value as a meter glucose value. This shows the glucose on the pump every 5 minutes and allows you to quickly see the current glucose value on the pump. Since this script requires communication with the pump, it will collide with oref0 pump communications on occasion. This oref0-pump-loop plugin capability will allow Logger and Lookout to run fakemeter synchronously at the end of the pump loop and avoid any radio collisions.

@scottleibrand
Copy link
Contributor

Code looks good. If someone can post test results, I think we can merge this.

@efidoman
Copy link
Contributor Author

needs a quick review again. I found an issue while testing where the plugins didn't run upon any loop failure. The intention is for plugins to run at the end of every pump loop regardless of pass or fail. Also, I updated the comments and logging a bit.

@efidoman
Copy link
Contributor Author

efidoman commented Feb 27, 2019

Here's my latest test results that include the Logger PR to leverage this new plugin capability for running fakemeter:

Completed oref0-pump-loop at Wed Feb 27 08:28:30 EST 2019

Running plugin script (plugins/once/run_fakemeter.sh)... 
2019/02/27 08:28:31 connected to CC111x radio on /dev/spidev5.1
2019/02/27 08:28:31 setting frequency to 916.650
2019/02/27 08:28:31 model 522 pump
2019/02/27 08:28:34 disconnecting CC111x radio on /dev/spidev5.1
Completed plugin script (plugins/once/run_fakemeter.sh). 
Running plugin script (plugins/every/plugins.sh)... 
Plugins Starting - Wed Feb 27 08:28:34 EST 2019
Completed plugin script (plugins/every/plugins.sh). 
Running plugin script (plugins/every/yo.sh)... 
/root/myopenaps
Completed plugin script (plugins/every/yo.sh). 

Starting oref0-pump-loop at Wed Feb 27 08:29:03 EST 2019 with 1 second wait_for_silence:

# pump-loop errored out for some reason
fail "$@"
fi
run_plugins
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving it here won't help make it run on failures, as the fail function calls exit 1. You'll instead need to add run_plugins after update_display there as well as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I was not aware. I have updated run_plugins to run in both places so it runs either way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tweaked the placement to be more consistent between the two cases. LMK if you don't think that will do the right thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

efidoman and others added 2 commits February 27, 2019 12:53
When a loop fails, we should do the various reason-for-failure checks (and display their output) before moving on to run_plugins.  Since we're doing run_plugins after update_display in the success case, we should do the same in the fail function.
Copy link
Contributor

@scottleibrand scottleibrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything else before we merge?

@efidoman
Copy link
Contributor Author

It's ready. I've been watching the logs and testing - works great.

@scottleibrand scottleibrand merged commit 82508cc into openaps:dev Mar 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants