Documentation ¶
Overview ¶
Package dexcom provides functions to access a Dexcom G4 Share CGM receiver over a BLE or USB connection.
Based on the Python version at github.com/bewest/decoding-dexcom
Index ¶
- Constants
- Variables
- func IsSpecial(glucose uint16) bool
- func NightscoutEntries(records Records) nightscout.Entries
- type CGM
- func (cgm *CGM) Cmd(cmd Command, params ...byte) []byte
- func (cgm *CGM) Error() error
- func (cgm *CGM) IterRecords(pageType PageType, firstPage, lastPage int, recordFn RecordFunc)
- func (cgm *CGM) ReadCount(pageType PageType, count int) Records
- func (cgm *CGM) ReadDisplayTime() time.Time
- func (cgm *CGM) ReadFirmwareHeader() XMLInfo
- func (cgm *CGM) ReadHistory(pageType PageType, since time.Time) Records
- func (cgm *CGM) ReadPage(pageType PageType, pageNumber int) []byte
- func (cgm *CGM) ReadPageRange(pageType PageType) (int, int)
- func (cgm *CGM) ReadRawRecords(pageType PageType, pageNumber int) [][]byte
- func (cgm *CGM) ReadRecords(pageType PageType, pageNumber int) Records
- func (cgm *CGM) ReadXMLRecord(pageType PageType) Record
- func (cgm *CGM) SetDisplayTime(t time.Time)
- func (cgm *CGM) SetError(err error)
- type CRCError
- type CalibrationInfo
- type CalibrationRecord
- type Command
- type Connection
- type EGVInfo
- type InsertionInfo
- type MeterInfo
- type PageInfo
- type PageType
- type Record
- type RecordFunc
- type Records
- type SensorChange
- type SensorInfo
- type SpecialGlucose
- type Timestamp
- type Trend
- type XMLInfo
Constants ¶
const ( EGVDisplayOnly = 1 << 15 EGVValueMask = 0x3FF EGVNoiseMask = 0x70 EGVTrendMask = 0xF )
Constants used to extract EGV, noise, and trend.
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" )
Variables ¶
var IterationDone = errors.New("iteration done") // nolint
IterationDone can be returned by a RecordFunc to indicate that iteration is complete and no further records need to be processed.
Functions ¶
func NightscoutEntries ¶
func NightscoutEntries(records Records) nightscout.Entries
NightscoutEntries converts records (in reverse-chronological order) into a Nightscout entries. Neighboring Sensor and EGV records are merged.
Types ¶
type CGM ¶
type CGM struct { Connection // contains filtered or unexported fields }
CGM represents a CGM connection.
func Open ¶
func Open() *CGM
Open first attempts to open a USB connection; if that fails it tries a BLE connection.
func (*CGM) Cmd ¶
Cmd creates a Dexcom packet with the given command and parameters, sends it to the device, and returns the response.
func (*CGM) IterRecords ¶
func (cgm *CGM) IterRecords(pageType PageType, firstPage, lastPage int, recordFn RecordFunc)
IterRecords reads the specified page range and applies recordFn to each record in each page. Pages are visited in reverse order to facilitate scanning for recent records.
func (*CGM) ReadDisplayTime ¶
ReadDisplayTime returns the Dexcom receiver's display time.
SystemTime = RTC + SystemTimeOffset DisplayTime = SystemTime + DisplayTimeOffset
func (*CGM) ReadFirmwareHeader ¶
ReadFirmwareHeader gets the firmware header from the Dexcom CGM receiver and returns it as XMLInfo.
func (*CGM) ReadHistory ¶
ReadHistory returns records since the specified time.
func (*CGM) ReadPageRange ¶
ReadPageRange returns the starting and ending page for a given PageType. The page numbers can be -1 if there are no entries (for example, USER_EVENT_DATA).
func (*CGM) ReadRawRecords ¶
ReadRawRecords reads the specified page and returns its records as raw byte slices.
func (*CGM) ReadRecords ¶
ReadRecords reads the specified page and returns its records.
func (*CGM) ReadXMLRecord ¶
ReadXMLRecord gets the given XML record type from the Dexcom CGM receiver.
func (*CGM) SetDisplayTime ¶
SetDisplayTime sets the Dexcom receiver's display time.
type CRCError ¶
type CRCError struct { Kind string Received, Computed uint16 PageType PageType PageNumber int Data []byte }
CRCError indicates that a CRC error was detected.
type CalibrationInfo ¶
type CalibrationInfo struct { Slope float64 Intercept float64 Scale float64 Decay float64 Data []CalibrationRecord }
CalibrationInfo represents a calibration event.
type CalibrationRecord ¶
type CalibrationRecord struct { TimeEntered time.Time Glucose int32 Raw int32 TimeApplied time.Time }
CalibrationRecord represents a calibration data point.
type Command ¶
type Command byte
Command represents a Dexcom CGM receiver command.
const ( Null Command = 0 Ack Command = 1 Nak Command = 2 InvalidCommand Command = 3 InvalidParam Command = 4 IncompletePacketReceived Command = 5 ReceiverError Command = 6 InvalidMode Command = 7 Ping Command = 10 ReadFirmwareHeader Command = 11 ReadDatabasePartitionInfo Command = 15 ReadDatabasePageRange Command = 16 ReadDatabasePages Command = 17 ReadDatabasePageHeader Command = 18 ReadTransmitterID Command = 25 WriteTransmitterID Command = 26 ReadLanguage Command = 27 WriteLanguage Command = 28 ReadDisplayTimeOffset Command = 29 WriteDisplayTimeOffset Command = 30 ReadRTC Command = 31 ResetReceiver Command = 32 ReadBatteryLevel Command = 33 ReadSystemTime Command = 34 ReadSystemTimeOffset Command = 35 WriteSystemTime Command = 36 ReadGlucoseUnits Command = 37 WriteGlucoseUnits Command = 38 ReadBlindMode Command = 39 WriteBlindMode Command = 40 ReadClockMode Command = 41 WriteClockMode Command = 42 ReadDeviceMode Command = 43 EraseDatabase Command = 45 ShutdownReceiver Command = 46 WriteSoftwareParameters Command = 47 ReadBatteryState Command = 48 ReadHardwareID Command = 49 ReadFirmwareSettings Command = 54 ReadEnableSetupWizardFlag Command = 55 ReadSetupWizardState Command = 57 ReadChargerCurrentSetting Command = 59 WriteChargerCurrentSetting Command = 60 )
Dexcom G4 receiver commands.
type Connection ¶
Connection is the interface satisfied by a CGM connection.
func OpenBLE ¶
func OpenBLE() (Connection, error)
OpenBLE makes a BLE connection to a Dexcom G4 Share receiver.
func OpenUSB ¶
func OpenUSB() (Connection, error)
OpenUSB opens the USB serial device for a Dexcom G4 receiver.
type InsertionInfo ¶
type InsertionInfo struct { SystemTime time.Time Event SensorChange }
InsertionInfo represents a sensor change event.
type PageInfo ¶
PageInfo represents a page of raw records.
func UnmarshalPage ¶
UnmarshalPage validates the CRC of the given page data and uses the page type to slice the data into raw records.
type PageType ¶
type PageType byte
PageType specifies a record page type stored by the Dexcom G4 receiver.
const ( ManufacturingData PageType = 0 FirmwareData PageType = 1 SoftwareData PageType = 2 SensorData PageType = 3 EGVData PageType = 4 CalibrationData PageType = 5 DeviationData PageType = 6 InsertionTimeData PageType = 7 ReceiverLogData PageType = 8 ReceiverErrorData PageType = 9 MeterData PageType = 10 UserEventData PageType = 11 UserSettingData PageType = 12 FirstPageType = ManufacturingData LastPageType = UserSettingData InvalidPage PageType = 0xFF )
Types of CGM records stored by the Dexcom G4 receiver.
type Record ¶
type Record struct { Timestamp Timestamp XML XMLInfo `json:",omitempty"` Sensor *SensorInfo `json:",omitempty"` EGV *EGVInfo `json:",omitempty"` Calibration *CalibrationInfo `json:",omitempty"` Insertion *InsertionInfo `json:",omitempty"` Meter *MeterInfo `json:",omitempty"` }
Record represents a time-stamped Dexcom receiver record.
type RecordFunc ¶
RecordFunc represents a function that IterRecords applies to each record.
type Records ¶
type Records []Record
Records represents a sequence of records.
func MergeHistory ¶
MergeHistory merges slices of records that are already in reverse chronological order into a single ordered slice.
func UnmarshalRecords ¶
UnmarshalRecords unmarshals raw records into records of the appropriate type.
type SensorChange ¶
type SensorChange byte
SensorChange represents a sensor change.
const ( Stopped SensorChange = 1 Started SensorChange = 7 )
Sensor change values.
func (SensorChange) String ¶
func (i SensorChange) String() string
type SensorInfo ¶
SensorInfo represents a sensor reading.
type SpecialGlucose ¶
type SpecialGlucose uint16
SpecialGlucose represents a glucose value that indicates an exceptional condition.
const ( SensorNotActive SpecialGlucose = 1 MinimalDeviation SpecialGlucose = 2 NoAntenna SpecialGlucose = 3 SensorNotCalibrated SpecialGlucose = 5 CountDeviation SpecialGlucose = 6 AbsoluteDeviation SpecialGlucose = 9 PowerDeviation SpecialGlucose = 10 BadRF SpecialGlucose = 12 )
Exceptional conditions.
func (SpecialGlucose) String ¶
func (i SpecialGlucose) String() string
type Trend ¶
type Trend byte
Trend represents a directional arrow displayed by the Dexcom CGM receiver.
type XMLInfo ¶
XMLInfo maps attribute names to values. The Dexcom CGM receiver represents its system data as single XML nodes with multiple attributes, so a tree structure is not required.
func (*XMLInfo) UnmarshalXML ¶
UnmarshalXML is called by xml.Unmarshal.