package module
v0.0.0-...-721237c Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 15 Imported by: 0



The medtronic package provides functions for communicating with Medtronic insulin pumps using SPI-connected radio modules.

Decoding of messages to and from the pump is derived primarily from Ben West's pioneering "Decoding Carelink" work, along with Pete Schwamb's code for RileyLink.

Radio configuration

The medtronic package and any programs that use it must be built with the appropriate Go build tag for the radio. Currently supported radios:

The default is the CC111x driver if no tags are specified.

Utility programs

The cmd directory contains a number of command-line applications:

  • mdt is a "Swiss army knife" application (analogous to the the openaps use pump ... commands)
  • mmtune scans for the best frequency to communicate with the pump
  • pumphistory retrieves pump history records and prints them
  • fakemeter sends a glucose value to the pump, as if from a connected glucometer
  • setbasals sets the pump's basal rate schedule from the command line
  • listen waits for a packet or a timeout, for use in scripts
  • sniff listens for pump communications and prints the packets it receives




View Source
const (
	// MaxHistoryPages is the maximum number of pump history pages.
	MaxHistoryPages = 36

	// Max512HistoryPages is the maximum number of pump history pages for model x12 pumps.
	Max512HistoryPages = 32
View Source
const (
	// JSONTimeLayout specifies the format for JSON time values.
	JSONTimeLayout = time.RFC3339
	// UserTimeLayout specifies a consistent, human-readable format for local time.
	UserTimeLayout = "2006-01-02 15:04:05"
View Source
const (
	// MaxGlucosePages is the maximum number of glucose history pages.
	MaxGlucosePages = 32


View Source
var ErrorNeedsTimestamp = fmt.Errorf("CGM history needs timestamp")

ErrorNeedsTimestamp indicates that no initial timestamp was found.


func DeviceAddress

func DeviceAddress(id string) ([]byte, error)

DeviceAddress returns the encoded form of a device ID.

func NightscoutEntries

func NightscoutEntries(records CGMHistory) nightscout.Entries

NightscoutEntries converts certain CGM history records into records that can be uploaded as Nightscout entries. The nightscout.Trend calculation assumes that the records are in reverse chronological order.

func ParseFrequency

func ParseFrequency(s string) (uint32, error)

ParseFrequency interprets the given string as a frequency and returns its value in Hertz.

func PumpAddress

func PumpAddress() []byte

PumpAddress returns the encoded form of the pump ID.

func ReverseCGMHistory

func ReverseCGMHistory(a CGMHistory)

ReverseCGMHistory reverses a slice of CGM history records.

func ReverseHistory

func ReverseHistory(a History)

ReverseHistory reverses a slice of history records.

func Treatments

func Treatments(records History) []nightscout.Treatment

Treatments converts certain pump history records into records that can be uploaded as Nightscout treatments. History records must be in chronological order.


type AlarmCode

type AlarmCode byte

AlarmCode represents a pump alarm code.

const (
	BatteryOutLimitExceeded AlarmCode = 0x03
	NoDelivery              AlarmCode = 0x04
	BatteryDepleted         AlarmCode = 0x05
	AutoOff                 AlarmCode = 0x06
	DeviceReset             AlarmCode = 0x10
	ReprogramError          AlarmCode = 0x3D
	EmptyReservoir          AlarmCode = 0x3E

func (AlarmCode) String

func (i AlarmCode) String() string

type BadResponseError

type BadResponseError struct {
	Command Command
	Data    []byte

BadResponseError indicates an unexpected response to a command.

func (BadResponseError) Error

func (e BadResponseError) Error() string

type BasalProfileStartRecord

type BasalProfileStartRecord struct {
	ProfileIndex int
	BasalRate    BasalRate

type BasalRate

type BasalRate struct {
	Start TimeOfDay
	Rate  Insulin

BasalRate represents an entry in a basal rate schedule.

type BasalRateSchedule

type BasalRateSchedule []BasalRate

BasalRateSchedule represents a basal rate schedule.

func (BasalRateSchedule) BasalRateAt

func (s BasalRateSchedule) BasalRateAt(t time.Time) int

BasalRateAt returns the index of the basal rate in effect at the given time.

func (BasalRateSchedule) NextChange

func (s BasalRateSchedule) NextChange(t time.Time) time.Time

NextChange returns the time when the next scheduled rate will take effect (strictly after t).

func (BasalRateSchedule) NightscoutSchedule

func (sched BasalRateSchedule) NightscoutSchedule() nightscout.Schedule

NightscoutSchedule converts a BasalRateSchedule to a nightscout.Schedule.

type BatteryInfo

type BatteryInfo struct {
	Voltage    Voltage
	LowBattery bool

BatteryInfo represents the pump's battery voltage and low-battery state.

type BolusRecord

type BolusRecord struct {
	Programmed Insulin
	Amount     Insulin
	Unabsorbed Insulin
	Duration   Duration // non-zero for square wave bolus

type BolusWizardConfig

type BolusWizardConfig struct {
	Ratios        CarbRatioSchedule
	Sensitivities InsulinSensitivitySchedule
	Targets       GlucoseTargetSchedule
	InsulinAction Duration

type BolusWizardRecord

type BolusWizardRecord struct {
	GlucoseInput Glucose
	CarbInput    Carbs
	GlucoseUnits GlucoseUnitsType
	CarbUnits    CarbUnitsType
	TargetLow    Glucose
	TargetHigh   Glucose
	Sensitivity  Glucose // glucose reduction per insulin unit
	CarbRatio    Ratio   // 10x grams/unit or 1000x units/exchange
	Correction   Insulin
	Food         Insulin
	Unabsorbed   Insulin
	Bolus        Insulin

func (BolusWizardRecord) MarshalJSON

func (r BolusWizardRecord) MarshalJSON() ([]byte, error)

MarshalJSON marshals BolusWizardRecord values.

func (*BolusWizardRecord) UnmarshalJSON

func (r *BolusWizardRecord) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals BolusWizardRecord values.

type BolusWizardSetupRecord

type BolusWizardSetupRecord struct {
	Before BolusWizardConfig
	After  BolusWizardConfig

type CGMHistory

type CGMHistory []CGMRecord

CGMHistory represents a sequence of CGM records.

func DecodeCGMHistory

func DecodeCGMHistory(data []byte, t time.Time) (CGMHistory, time.Time, error)

DecodeCGMHistory decodes the records in a page of CGM data and returns them in reverse chronological order (most recent first). If a non-zero time is given, it is used as the initial timestamp.

type CGMRecord

type CGMRecord struct {
	Type    CGMRecordType
	Data    []byte
	Time    time.Time
	Glucose int    `json:",omitempty"`
	Value   string `json:",omitempty"`

CGMRecord represents a CGM record.

func DecodeCGMRecord

func DecodeCGMRecord(data []byte) (CGMRecord, error)

DecodeCGMRecord decodes a CGM history record based on its type.

func (CGMRecord) MarshalJSON

func (r CGMRecord) MarshalJSON() ([]byte, error)

MarshalJSON marshals CGMRecord values.

func (*CGMRecord) UnmarshalJSON

func (r *CGMRecord) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals CGMRecord values.

type CGMRecordType

type CGMRecordType byte

CGMRecordType represents a CGM record type.

const (
	CGMDataEnd       CGMRecordType = 0x01
	CGMWeakSignal    CGMRecordType = 0x02
	CGMCal           CGMRecordType = 0x03
	CGMPacket        CGMRecordType = 0x04
	CGMError         CGMRecordType = 0x05
	CGMDataLow       CGMRecordType = 0x06
	CGMDataHigh      CGMRecordType = 0x07
	CGMTimestamp     CGMRecordType = 0x08
	CGMBatteryChange CGMRecordType = 0x0A
	CGMStatus        CGMRecordType = 0x0B
	CGMTimeChange    CGMRecordType = 0x0C
	CGMSync          CGMRecordType = 0x0D
	CGMCalBG         CGMRecordType = 0x0E
	CGMCalFactor     CGMRecordType = 0x0F
	CGMEvent10       CGMRecordType = 0x10
	CGMEvent13       CGMRecordType = 0x13

	// Synthetic record type.
	// Single bytes with this value or greater represent glucose readings.
	CGMGlucose CGMRecordType = 0x20

Events stored in the pump's CGM history pages.

func (CGMRecordType) String

func (i CGMRecordType) String() string

type CarbRatio

type CarbRatio struct {
	Start TimeOfDay
	Ratio Ratio
	Units CarbUnitsType

CarbRatio represents an entry in a carb ratio schedule.

func (CarbRatio) MarshalJSON

func (r CarbRatio) MarshalJSON() ([]byte, error)

MarshalJSON marshals CarbRatio values.

func (*CarbRatio) UnmarshalJSON

func (r *CarbRatio) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals CarbRatio values.

type CarbRatioSchedule

type CarbRatioSchedule []CarbRatio

CarbRatioSchedule represents a carb ratio schedule.

func (CarbRatioSchedule) CarbRatioAt

func (s CarbRatioSchedule) CarbRatioAt(t time.Time) CarbRatio

CarbRatioAt returns the carb ratio in effect at the given time.

func (CarbRatioSchedule) NightscoutSchedule

func (sched CarbRatioSchedule) NightscoutSchedule() nightscout.Schedule

NightscoutSchedule converts a CarbRatioSchedule to a nightscout.Schedule.

type CarbRecord

type CarbRecord struct {
	Units CarbUnitsType
	Carbs Carbs

type CarbUnitsType

type CarbUnitsType byte

CarbUnitsType represents the pump's carb unit type (grams or exchanges).

const (
	// Grams represents the pump's use of grams for carb units.
	Grams CarbUnitsType = 1
	// Exchanges represents the pump's use of exchanges for carb units.
	Exchanges CarbUnitsType = 2

func (CarbUnitsType) MarshalJSON

func (r CarbUnitsType) MarshalJSON() ([]byte, error)

MarshalJSON marshals CarbUnitsType values.

func (CarbUnitsType) String

func (i CarbUnitsType) String() string

func (*CarbUnitsType) UnmarshalJSON

func (r *CarbUnitsType) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals CarbUnitsType values.

type Carbs

type Carbs int

Carbs represents a carb value as either grams or 10x exchanges.

type Command

type Command byte

Command represents a pump command.

func (Command) String

func (i Command) String() string

type Duration

type Duration time.Duration

Duration allows custom JSON marshaling for time.Duration values.

func (Duration) MarshalJSON

func (r Duration) MarshalJSON() ([]byte, error)

MarshalJSON marshals Duration values.

func (Duration) TimeOfDay

func (d Duration) TimeOfDay() TimeOfDay

TimeOfDay converts a duration to a time of day.

func (*Duration) UnmarshalJSON

func (r *Duration) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals Duration values.

type Family

type Family int8

Family represents a pump family. Use int8 so the compiler will warn about accidental uses of 523 instead of 23, etc.

type Glucose

type Glucose int

Glucose represents a glucose value as either mg/dL or μmol/L, so all conversions must include a GlucoseUnitsType parameter.

func (Glucose) NightscoutGlucose

func (r Glucose) NightscoutGlucose() nightscout.Glucose

NightscoutGlucose converts a Glucose value to a nightscout.Glucose value.

type GlucoseRecord

type GlucoseRecord struct {
	Units   GlucoseUnitsType
	Glucose Glucose
	MeterID string `json:",omitempty"`

type GlucoseTarget

type GlucoseTarget struct {
	Start TimeOfDay
	Low   Glucose
	High  Glucose
	Units GlucoseUnitsType

GlucoseTarget represents an entry in a glucose target schedule.

type GlucoseTargetSchedule

type GlucoseTargetSchedule []GlucoseTarget

GlucoseTargetSchedule represents a glucose target schedule.

func (GlucoseTargetSchedule) GlucoseTargetAt

func (s GlucoseTargetSchedule) GlucoseTargetAt(t time.Time) GlucoseTarget

GlucoseTargetAt returns the glucose target in effect at the given time.

func (GlucoseTargetSchedule) NightscoutSchedule

func (sched GlucoseTargetSchedule) NightscoutSchedule() (nightscout.Schedule, nightscout.Schedule)

NightscoutSchedule converts a GlucoseTargetSchedule to a nightscout.Schedule.

type GlucoseUnitsType

type GlucoseUnitsType byte

GlucoseUnitsType represents the pump's glucose unit type (mg/dL or mmol/L).

const (
	// MgPerDeciLiter represents the pump's use of mg/dL for glucose units.
	MgPerDeciLiter GlucoseUnitsType = 1
	// MMolPerLiter represents the pump's use of mmol/L for glucose units.
	MMolPerLiter GlucoseUnitsType = 2

func (GlucoseUnitsType) MarshalJSON

func (r GlucoseUnitsType) MarshalJSON() ([]byte, error)

MarshalJSON marshals GlucoseUnitsType values.

func (GlucoseUnitsType) String

func (u GlucoseUnitsType) String() string

func (*GlucoseUnitsType) UnmarshalJSON

func (r *GlucoseUnitsType) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals GlucoseUnitsType values.

type History

type History []HistoryRecord

func DecodeHistory

func DecodeHistory(data []byte, family Family) (History, error)

DecodeHistory decodes the records in a page of data and returns them in reverse chronological order (most recent first), to match the order of the history pages themselves.

type HistoryRecord

type HistoryRecord struct {
	Data []byte
	Time time.Time
	Info interface{} `json:",omitempty"`

func DecodeHistoryRecord

func DecodeHistoryRecord(data []byte, family Family) (HistoryRecord, error)

DecodeHistoryRecord decodes a history record based on its type.

func (HistoryRecord) MarshalJSON

func (r HistoryRecord) MarshalJSON() ([]byte, error)

MarshalJSON marshals HistoryRecord values.

func (HistoryRecord) Type

Type returns the history record type.

func (*HistoryRecord) UnmarshalJSON

func (r *HistoryRecord) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals HistoryRecord values.

type HistoryRecordType

type HistoryRecordType byte

HistoryRecordType represents a history record type.

const (
	Bolus                   HistoryRecordType = 0x01
	Prime                   HistoryRecordType = 0x03
	Alarm                   HistoryRecordType = 0x06
	DailyTotal              HistoryRecordType = 0x07
	BasalProfileBefore      HistoryRecordType = 0x08
	BasalProfileAfter       HistoryRecordType = 0x09
	BGCapture               HistoryRecordType = 0x0A
	SensorAlarm             HistoryRecordType = 0x0B
	ClearAlarm              HistoryRecordType = 0x0C
	ChangeBasalPattern      HistoryRecordType = 0x14
	TempBasalDuration       HistoryRecordType = 0x16
	ChangeTime              HistoryRecordType = 0x17
	NewTime                 HistoryRecordType = 0x18
	LowBattery              HistoryRecordType = 0x19
	BatteryChange           HistoryRecordType = 0x1A
	SetAutoOff              HistoryRecordType = 0x1B
	PrepareInsulinChange    HistoryRecordType = 0x1C
	SuspendPump             HistoryRecordType = 0x1E
	ResumePump              HistoryRecordType = 0x1F
	SelfTest                HistoryRecordType = 0x20
	Rewind                  HistoryRecordType = 0x21
	ClearSettings           HistoryRecordType = 0x22
	EnableChildBlock        HistoryRecordType = 0x23
	MaxBolus                HistoryRecordType = 0x24
	EnableRemote            HistoryRecordType = 0x26
	MaxBasal                HistoryRecordType = 0x2C
	EnableBolusWizard       HistoryRecordType = 0x2D
	Unknown2E               HistoryRecordType = 0x2E
	BolusWizard512          HistoryRecordType = 0x2F
	UnabsorbedInsulin512    HistoryRecordType = 0x30
	ChangeBGReminder        HistoryRecordType = 0x31
	SetAlarmClockTime       HistoryRecordType = 0x32
	TempBasalRate           HistoryRecordType = 0x33
	LowReservoir            HistoryRecordType = 0x34
	AlarmClock              HistoryRecordType = 0x35
	ChangeMeterID           HistoryRecordType = 0x36
	BGReceived512           HistoryRecordType = 0x39
	ConfirmInsulinChange    HistoryRecordType = 0x3A
	SensorStatus            HistoryRecordType = 0x3B
	EnableMeter             HistoryRecordType = 0x3C
	BGReceived              HistoryRecordType = 0x3F
	MealMarker              HistoryRecordType = 0x40
	ExerciseMarker          HistoryRecordType = 0x41
	InsulinMarker           HistoryRecordType = 0x42
	OtherMarker             HistoryRecordType = 0x43
	EnableSensorAutoCal     HistoryRecordType = 0x44
	ChangeBolusWizardSetup  HistoryRecordType = 0x4F
	SensorSetup             HistoryRecordType = 0x50
	Sensor51                HistoryRecordType = 0x51
	Sensor52                HistoryRecordType = 0x52
	ChangeSensorAlarm       HistoryRecordType = 0x53
	Sensor54                HistoryRecordType = 0x54
	Sensor55                HistoryRecordType = 0x55
	ChangeSensorAlert       HistoryRecordType = 0x56
	ChangeBolusStep         HistoryRecordType = 0x57
	BolusWizardSetup        HistoryRecordType = 0x5A
	BolusWizard             HistoryRecordType = 0x5B
	UnabsorbedInsulin       HistoryRecordType = 0x5C
	SaveSettings            HistoryRecordType = 0x5D
	EnableVariableBolus     HistoryRecordType = 0x5E
	ChangeEasyBolus         HistoryRecordType = 0x5F
	EnableBGReminder        HistoryRecordType = 0x60
	EnableAlarmClock        HistoryRecordType = 0x61
	ChangeTempBasalType     HistoryRecordType = 0x62
	ChangeAlarmType         HistoryRecordType = 0x63
	ChangeTimeFormat        HistoryRecordType = 0x64
	ChangeReservoirWarning  HistoryRecordType = 0x65
	EnableBolusReminder     HistoryRecordType = 0x66
	SetBolusReminderTime    HistoryRecordType = 0x67
	DeleteBolusReminderTime HistoryRecordType = 0x68
	BolusReminder           HistoryRecordType = 0x69
	DeleteAlarmClockTime    HistoryRecordType = 0x6A
	DailyTotal515           HistoryRecordType = 0x6C
	DailyTotal522           HistoryRecordType = 0x6D
	DailyTotal523           HistoryRecordType = 0x6E
	ChangeCarbUnits         HistoryRecordType = 0x6F
	BasalProfileStart       HistoryRecordType = 0x7B
	ConnectOtherDevices     HistoryRecordType = 0x7C
	ChangeOtherDevice       HistoryRecordType = 0x7D
	ChangeMarriage          HistoryRecordType = 0x81
	DeleteOtherDevice       HistoryRecordType = 0x82
	EnableCaptureEvent      HistoryRecordType = 0x83

Events stored in the pump's history pages.

func (HistoryRecordType) String

func (i HistoryRecordType) String() string

type Insulin

type Insulin int

Insulin represents quantities and rates of insulin delivery, in milliunits.

func (Insulin) MarshalJSON

func (r Insulin) MarshalJSON() ([]byte, error)

MarshalJSON marshals Insulin values.

func (Insulin) NightscoutInsulin

func (r Insulin) NightscoutInsulin() nightscout.Insulin

NightscoutInsulin converts an Insulin value to a nightscout.Insulin value.

func (Insulin) String

func (r Insulin) String() string

func (*Insulin) UnmarshalJSON

func (r *Insulin) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals Insulin values.

type InsulinSensitivity

type InsulinSensitivity struct {
	Start       TimeOfDay
	Sensitivity Glucose // glucose reduction per insulin unit
	Units       GlucoseUnitsType

InsulinSensitivity represents an entry in an insulin sensitivity schedule.

type InsulinSensitivitySchedule

type InsulinSensitivitySchedule []InsulinSensitivity

InsulinSensitivitySchedule represents an insulin sensitivity schedule.

func (InsulinSensitivitySchedule) InsulinSensitivityAt

func (s InsulinSensitivitySchedule) InsulinSensitivityAt(t time.Time) InsulinSensitivity

InsulinSensitivityAt returns the insulin sensitivity in effect at the given time.

func (InsulinSensitivitySchedule) NightscoutSchedule

func (sched InsulinSensitivitySchedule) NightscoutSchedule() nightscout.Schedule

NightscoutSchedule converts an InsulinSensitivitySchedule to a nightscout.Schedule.

type InvalidCommandError

type InvalidCommandError struct {
	Command   Command
	PumpError PumpError

InvalidCommandError indicates that the pump rejected a command as invalid.

func (InvalidCommandError) Error

func (e InvalidCommandError) Error() string

type NoResponseError

type NoResponseError Command

NoResponseError indicates that no response to a command was received.

func (NoResponseError) Error

func (e NoResponseError) Error() string

type PrimeRecord

type PrimeRecord struct {
	Fixed  Insulin
	Manual Insulin

type Pump

type Pump struct {
	Radio radio.Interface
	// contains filtered or unexported fields

Pump represents a Medtronic insulin pump.

func Open

func Open() *Pump

Open opens radio communication with a pump.

func (*Pump) BadResponse

func (pump *Pump) BadResponse(cmd Command, data []byte)

BadResponse sets the pump's error state to a BadResponseError.

func (*Pump) BasalPatternA

func (pump *Pump) BasalPatternA() BasalRateSchedule

BasalPatternA returns the pump's basal pattern A.

func (*Pump) BasalPatternB

func (pump *Pump) BasalPatternB() BasalRateSchedule

BasalPatternB returns the pump's basal pattern B.

func (*Pump) BasalRates

func (pump *Pump) BasalRates() BasalRateSchedule

BasalRates returns the pump's basal rate schedule.

func (*Pump) Battery

func (pump *Pump) Battery() BatteryInfo

Battery returns the pump's battery information.

func (*Pump) Bolus

func (pump *Pump) Bolus(amount Insulin)

Bolus delivers the given amount of insulin as a bolus.

func (*Pump) Button

func (pump *Pump) Button(b PumpButton)

Button sends the button-press to the pump.

func (*Pump) CGMCurrentGlucosePage

func (pump *Pump) CGMCurrentGlucosePage() int

CGMCurrentGlucosePage returns the current CGM glucose page number.

func (*Pump) CGMHistory

func (pump *Pump) CGMHistory(since time.Time) CGMHistory

CGMHistory returns the CGM records since the specified time.

func (*Pump) CGMWriteTimestamp

func (pump *Pump) CGMWriteTimestamp()

CGMWriteTimestamp writes a new sensor timestamp to the CGM history.

func (*Pump) CalibrationFactor

func (pump *Pump) CalibrationFactor() int

CalibrationFactor returns the CGM calibration factor.

func (*Pump) CarbRatios

func (pump *Pump) CarbRatios() CarbRatioSchedule

CarbRatios returns the pump's carb ratio schedule..

func (*Pump) CarbUnits

func (pump *Pump) CarbUnits() CarbUnitsType

CarbUnits returns the pump's carb units.

func (*Pump) Clock

func (pump *Pump) Clock() time.Time

Clock returns the time according to the pump's clock.

func (*Pump) Close

func (pump *Pump) Close()

Close closes communication with the pump.

func (*Pump) Download

func (pump *Pump) Download(cmd Command, page int) []byte

Download requests the given history page from the pump.

func (*Pump) Error

func (pump *Pump) Error() error

Error returns the error state of the pump.

func (*Pump) Execute

func (pump *Pump) Execute(cmd Command, params ...byte) []byte

Execute sends a command and parameters to the pump and returns its response. Commands with parameters require an initial exchange with no parameters, followed by an exchange with the actual arguments.

func (*Pump) ExtendedRequest

func (pump *Pump) ExtendedRequest(cmd Command, params ...byte) []byte

ExtendedRequest sends a command and a sequence of parameter packets to the pump and returns its response.

func (*Pump) ExtendedResponse

func (pump *Pump) ExtendedResponse(cmd Command, params ...byte) []byte

ExtendedResponse sends a command and parameters to the pump and collects the sequence of packets that make up its response.

func (*Pump) Family

func (pump *Pump) Family() Family

Family returns 22 for 522/722 pumps, 23 for 523/723 pumps, etc., and returns -1 for an unrecognized model. It calls Model once and caches the result.

func (*Pump) FirmwareVersion

func (pump *Pump) FirmwareVersion() string

FirmwareVersion returns the pump's firmware version.

func (*Pump) GlucosePage

func (pump *Pump) GlucosePage(page int) []byte

GlucosePage downloads the given glucose page.

func (*Pump) GlucoseTargets

func (pump *Pump) GlucoseTargets() GlucoseTargetSchedule

GlucoseTargets returns the pump's glucose target schedule.

func (*Pump) GlucoseUnits

func (pump *Pump) GlucoseUnits() GlucoseUnitsType

GlucoseUnits returns the pump's glucose units.

func (*Pump) History

func (pump *Pump) History(since time.Time) History

History returns the history records since the specified time. Note that the results may include records with a zero timestamp or an earlier timestamp than the cutoff (in the case of DailyTotal records).

func (*Pump) HistoryFrom

func (pump *Pump) HistoryFrom(id []byte) (History, bool)

HistoryFrom returns the history records since the specified record ID along with a bool indicating whether it was found. If the record ID was not found, the result will contain the entire pump history.

func (*Pump) HistoryPage

func (pump *Pump) HistoryPage(page int) []byte

HistoryPage downloads the given history page.

func (*Pump) ISIGPage

func (pump *Pump) ISIGPage(page int) []byte

ISIGPage downloads the given ISIG page.

func (*Pump) InsulinSensitivities

func (pump *Pump) InsulinSensitivities() InsulinSensitivitySchedule

InsulinSensitivities returns the pump's insulin sensitivity schedule.

func (*Pump) LastHistoryPage

func (pump *Pump) LastHistoryPage() int

LastHistoryPage returns the pump's last (oldest) history page number.

func (*Pump) Model

func (pump *Pump) Model() string

Model requests the model number from the pump and returns it, caching the pump family as a side effect. Use Family to avoid contacting the pump more than once.

func (*Pump) NoResponse

func (pump *Pump) NoResponse() bool

NoResponse checks whether the pump has a NoResponseError.

func (*Pump) PumpID

func (pump *Pump) PumpID() string

PumpID returns the pump's ID.

func (*Pump) RSSI

func (pump *Pump) RSSI() int

RSSI returns the RSSI received with the most recent packet from the pump.

func (*Pump) Reservoir

func (pump *Pump) Reservoir() Insulin

Reservoir returns the amount of insulin remaining.

func (*Pump) Retries

func (pump *Pump) Retries() int

Retries returns the number of retries used for pump communications.

func (*Pump) SetAbsoluteTempBasal

func (pump *Pump) SetAbsoluteTempBasal(duration time.Duration, rate Insulin)

SetAbsoluteTempBasal sets a temporary basal with the given absolute rate and duration.

func (*Pump) SetBasalPatternA

func (pump *Pump) SetBasalPatternA(s BasalRateSchedule)

SetBasalPatternA sets the pump's basal pattern A.

func (*Pump) SetBasalPatternB

func (pump *Pump) SetBasalPatternB(s BasalRateSchedule)

SetBasalPatternB sets the pump's basal pattern B.

func (*Pump) SetBasalRates

func (pump *Pump) SetBasalRates(s BasalRateSchedule)

SetBasalRates sets the pump's basal rate schedule.

func (*Pump) SetClock

func (pump *Pump) SetClock(t time.Time)

SetClock sets the pump's clock to the given time.

func (*Pump) SetError

func (pump *Pump) SetError(err error)

SetError sets the error state of the pump.

func (*Pump) SetMaxBasal

func (pump *Pump) SetMaxBasal(rate Insulin)

SetMaxBasal sets the pump's maximum basal rate.

func (*Pump) SetMaxBolus

func (pump *Pump) SetMaxBolus(amount Insulin)

SetMaxBolus sets the pump's maximum bolus.

func (*Pump) SetPercentTempBasal

func (pump *Pump) SetPercentTempBasal(duration time.Duration, percent int)

SetPercentTempBasal sets a temporary basal with the given percent rate and duration.

func (*Pump) SetRetries

func (pump *Pump) SetRetries(n int)

SetRetries sets the number of retries used for pump communications. For safety, state-changing commands are only tried once.

func (*Pump) SetTimeout

func (pump *Pump) SetTimeout(t time.Duration)

SetTimeout sets the timeout used for pump communications.

func (*Pump) Settings

func (pump *Pump) Settings() SettingsInfo

Settings returns the pump's settings.

func (*Pump) Status

func (pump *Pump) Status() StatusInfo

Status returns the pump's status.

func (*Pump) Suspend

func (pump *Pump) Suspend(yes bool)

Suspend suspends or resumes the pump.

func (*Pump) TempBasal

func (pump *Pump) TempBasal() TempBasalInfo

TempBasal returns the pump's current temporary basal setting. If none is in effect, it will have a Duration of 0.

func (*Pump) Timeout

func (pump *Pump) Timeout() time.Duration

Timeout returns the timeout used for pump communications.

func (*Pump) VcntrPage

func (pump *Pump) VcntrPage(page int) []byte

VcntrPage downloads the given vcntr page.

func (*Pump) Wakeup

func (pump *Pump) Wakeup()

Wakeup wakes up the pump. It first attempts a model command, which will succeed quickly if the pump is already awake. If that times out, it will repeatedly send wakeup commands.

type PumpButton

type PumpButton byte

PumpButton represents a key on the pump keypad.

const (
	BolusButton PumpButton = 0
	EscButton   PumpButton = 1
	ActButton   PumpButton = 2
	UpButton    PumpButton = 3
	DownButton  PumpButton = 4

Pump button codes.

func (PumpButton) String

func (i PumpButton) String() string

type PumpError

type PumpError byte

PumpError represents an error response from the pump.

const (
	CommandRefused           PumpError = 0x08
	SettingOutOfRange        PumpError = 0x09
	BolusInProgress          PumpError = 0x0C
	InvalidHistoryPageNumber PumpError = 0x0D

Pump error codes.

func (PumpError) String

func (i PumpError) String() string

type Ratio

type Ratio int

Ratio represents a carb ratio using the higher resolution: 10x grams/unit or 1000x units/exchange.

func (Ratio) MarshalJSON

func (r Ratio) MarshalJSON() ([]byte, error)

MarshalJSON panics because Ratios must be marshaled together with carb units.

func (*Ratio) UnmarshalJSON

func (r *Ratio) UnmarshalJSON([]byte) error

UnmarshalJSON panics because Ratios must be unmarshaled together with carb units.

type SettingsInfo

type SettingsInfo struct {
	AutoOff              time.Duration
	InsulinAction        time.Duration
	InsulinConcentration int // 50 or 100
	MaxBolus             Insulin
	MaxBasal             Insulin
	RFEnabled            bool
	TempBasalType        TempBasalType
	SelectedPattern      int

SettingsInfo represents the pump's settings.

func (SettingsInfo) MarshalJSON

func (r SettingsInfo) MarshalJSON() ([]byte, error)

MarshalJSON marshals SettingsInfo values.

func (*SettingsInfo) UnmarshalJSON

func (r *SettingsInfo) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals SettingsInfo values.

type StatusInfo

type StatusInfo struct {
	Code      byte
	Bolusing  bool
	Suspended bool

StatusInfo represents the pump's status.

func (StatusInfo) Normal

func (s StatusInfo) Normal() bool

Normal returns true if the status code indicates normal pump operation. Observed values:

0: rewinding
1: preparing to prime
2: priming
3: normal

type TempBasalInfo

type TempBasalInfo struct {
	Duration time.Duration
	Type     TempBasalType
	Rate     *Insulin `json:",omitempty"`
	Percent  *uint8   `json:",omitempty"`

TempBasalInfo represents a temporary basal setting.

func (TempBasalInfo) MarshalJSON

func (r TempBasalInfo) MarshalJSON() ([]byte, error)

MarshalJSON marshals TempBasalInfo values.

func (*TempBasalInfo) UnmarshalJSON

func (r *TempBasalInfo) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals TempBasalInfo values.

type TempBasalRecord

type TempBasalRecord struct {
	Type  TempBasalType
	Value interface{}

type TempBasalType

type TempBasalType byte

TempBasalType represents the temp basal type.

const (
	// Absolute represents the pump's use of absolute rates for temporary basals.
	Absolute TempBasalType = 0
	// Percent represents the pump's use of percentage rates for temporary basals.
	Percent TempBasalType = 1

func (TempBasalType) MarshalJSON

func (r TempBasalType) MarshalJSON() ([]byte, error)

MarshalJSON marshals TempBasalType values.

func (TempBasalType) String

func (i TempBasalType) String() string

func (*TempBasalType) UnmarshalJSON

func (r *TempBasalType) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals TempBasalType values.

type TimeOfDay

type TimeOfDay time.Duration

TimeOfDay represents a value between 0 and 24 hours.

func ParseTimeOfDay

func ParseTimeOfDay(s string) (TimeOfDay, error)

ParseTimeOfDay parses a string of the form HH:MM into a time of day.

func SinceMidnight

func SinceMidnight(t time.Time) TimeOfDay

SinceMidnight converts a time to a time of day.

func (TimeOfDay) HalfHours

func (t TimeOfDay) HalfHours() uint8

HalfHours convert a time of day into half-hours.

func (TimeOfDay) MarshalJSON

func (r TimeOfDay) MarshalJSON() ([]byte, error)

MarshalJSON marshals TimeOfDay values.

func (TimeOfDay) String

func (t TimeOfDay) String() string

Convert a time of day to a string of the form HH:MM.

func (*TimeOfDay) UnmarshalJSON

func (r *TimeOfDay) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals TimeOfDay values.

type UnabsorbedBolus

type UnabsorbedBolus struct {
	Bolus Insulin
	Age   Duration

type UnabsorbedBolusHistory

type UnabsorbedBolusHistory []UnabsorbedBolus

type UnknownRecordTypeError

type UnknownRecordTypeError struct {
	Data []byte

func (UnknownRecordTypeError) Error

func (e UnknownRecordTypeError) Error() string

type Voltage

type Voltage int

Voltage represents the battery voltage in milliVolts.

func (Voltage) MarshalJSON

func (r Voltage) MarshalJSON() ([]byte, error)

MarshalJSON marshals Voltage values.

func (Voltage) NightscoutVoltage

func (r Voltage) NightscoutVoltage() nightscout.Voltage

NightscoutVoltage converts a Voltage value to a nightscout.Voltage value.

func (Voltage) String

func (r Voltage) String() string

func (*Voltage) UnmarshalJSON

func (r *Voltage) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals Voltage values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL