CGM Simulator  0.1.3
A CGM simulator to demonstrate the BLE CGM profile v1.1
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
cgm.c File Reference

This file contains the CGM sensor simulator application for use with the CC2540 Bluetooth Low Energy Protocol Stack. More...

#include "bcomdef.h"
#include "OSAL.h"
#include "OSAL_PwrMgr.h"
#include "OnBoard.h"
#include "hal_adc.h"
#include "hal_led.h"
#include "hal_key.h"
#include "gatt.h"
#include "hci.h"
#include "gapgattserver.h"
#include "gattservapp.h"
#include "gatt_profile_uuid.h"
#include "linkdb.h"
#include "peripheral.h"
#include "gapbondmgr.h"
#include "cgmservice.h"
#include "devinfoservice.h"
#include "cgm.h"
#include "OSAL_Clock.h"
#include "battservice.h"
#include "cgmsimdata.h"
#include "crc.h"
Include dependency graph for cgm.c:

Data Structures

struct  cgmMeasC_t
 Container for CGM measurement result data. More...
 
struct  cgmFeature_t
 Container for the CGM support feature characteristic. More...
 
struct  cgmStatus_t
 Container for the CGM sensor status characteristic. More...
 
struct  cgmSessionStartTime_t
 Container for the CGM session start time characteristic. More...
 
struct  cgmCtlPntMsg_t
 The container for receiving CGMCP data message from the CGM service layer. More...
 
struct  cgmRACPMsg_t
 The container for receiving RACP data message from the CGM service layer. More...
 

Macros

#define SFLOAT   uint16
 Using a unsigned 16bit integer to store a SFLOAT. More...
 
#define FEATURE_GLUCOSE_CALIBRATION   0
 The glucose calibration feature. More...
 
#define FEATURE_GLUCOSE_PATIENTHIGHLOW   0
 The patient set high/low alert feature. More...
 
#define FEATURE_GLUCOSE_HYPERALERT   0
 The hyperglycemia alert feature. More...
 
#define FEATURE_GLUCOSE_HYPOALERT   0
 The hypoglycemia alert feature. More...
 
#define FEATURE_GLUCOSE_RATEALERT   0
 The rate of increase/decrease alert feature. More...
 
#define FEATURE_GLUCOSE_QUALITY   0
 The CGM supports quality indication. More...
 
#define FEATURE_GLUCOSE_CRC   1
 The E2E-CRC support. More...
 
#define FEATURE_GLUCOSE_DEVICE_ALERT   1
 The device alert support. More...
 
#define FEATURE_GLUCOSE_TREND   1
 
#define DEFAULT_FAST_ADV_INTERVAL   32
 Fast advertising interval in 625us units. More...
 
#define DEFAULT_FAST_ADV_DURATION   30
 Duration of fast advertising duration in sec. More...
 
#define DEFAULT_SLOW_ADV_INTERVAL   1600
 Slow advertising interval in 625us units. More...
 
#define DEFAULT_SLOW_ADV_DURATION   30
 Duration of slow advertising duration in sec. More...
 
#define DEFAULT_ENABLE_UPDATE_REQUEST   TRUE
 Whether to enable automatic parameter update request when a connection is formed. More...
 
#define DEFAULT_DESIRED_MIN_CONN_INTERVAL   200
 Minimum connection interval (units of 1.25ms) if automatic parameter update request is enabled. More...
 
#define DEFAULT_DESIRED_MAX_CONN_INTERVAL   1600
 Maximum connection interval (units of 1.25ms) if automatic parameter update request is enabled. More...
 
#define DEFAULT_DESIRED_SLAVE_LATENCY   1
 Slave latency to use if automatic parameter update request is enabled. More...
 
#define DEFAULT_DESIRED_CONN_TIMEOUT   1000
 
#define DEFAULT_PASSCODE   19655
 Default passcode. More...
 
#define DEFAULT_PAIRING_MODE   GAPBOND_PAIRING_MODE_NO_PAIRING
 
#define DEFAULT_MITM_MODE   FALSE
 Default MITM mode (TRUE to require passcode or OOB when pairing) More...
 
#define DEFAULT_BONDING_MODE   FALSE
 Default bonding mode, TRUE to bond. More...
 
#define DEFAULT_IO_CAPABILITIES   GAPBOND_IO_CAP_DISPLAY_ONLY
 
#define DEFAULT_NOTI_PERIOD   1000
 

Functions

static void cgmPairStateCB (uint16 connHandle, uint8 state, uint8 status)
 Pairing state callback. More...
 
static void cgmPasscodeCB (uint8 *deviceAddr, uint16 connectionHandle, uint8 uiInputs, uint8 uiOutputs)
 Passcode callback. More...
 
static void cgmGapStateCB (gaprole_States_t newState)
 Notification from the profile of a state change. More...
 
static void cgm_HandleKeys (uint8 shift, uint8 keys)
 Handles all key events for this device. More...
 
static uint8 cgmVerifyTime (UTCTimeStruct *pTime)
 Verify time values are suitable for filtering. More...
 
static uint8 cgmVerifyTimeZone (int8 input)
 Verify time zone values are compliant to the standard. More...
 
static uint8 cgmVerifyDSTOffset (uint8 input)
 Verify the daylight saving time input is compliant to the standard. More...
 
static void cgmCtlPntResponse (uint8 opcode, uint8 *roperand, uint8 roperand_len)
 Send a record control point response. More...
 
static void cgmProcessCtlPntMsg (cgmCtlPntMsg_t *pMsg)
 Process Control Point messages. More...
 
static uint8 cgmSearchMeasDB (uint8 filter, uint16 operand1, uint16 operand2)
 This function implements the search function for the gluocose measurement. More...
 
static void cgmAddRecord (cgmMeasC_t *cgmCurrentMeas)
 Add record to the database. More...
 
static void cgmProcessRACPMsg (cgmRACPMsg_t *pMsg)
 Record Access Control Point messages processing. More...
 
static void cgmRACPSendNextMeas ()
 As part of the RACP operation, this function sends the set of historical measurement data to the collector APP sequencially. The resulting record would be received by the collector through the glucose measurement characteristic notification. More...
 
static void cgmResetMeasDB ()
 Reset the cgm measurement history database. More...
 
static uint8 cgmRACPClearRecord (uint8 startindx, uint8 endindx, uint16 count)
 The function to delete a block of entries from the measurement database. More...
 
static void cgmMeasSend (void)
 Send the most current record stored in cgmCurrentMeas as a GATT notification to the CGM measurement characteristic. More...
 
static void cgmNewGlucoseMeas (cgmMeasC_t *pMeas)
 Update with the lastest reading while updating the internal database. More...
 
static void cgmservice_cb (uint8 event, uint8 *valueP, uint8 *len, uint8 *result)
 The callback function in the application layer when the GATT service layer receives read/write operation to one of the CGM service characteristic. More...
 
static void cgmSimulationAppInit ()
 Initialize the CGM simulator application. Reset the historical database. More...
 
static void cgm_ProcessOSALMsg (osal_event_hdr_t *pMsg)
 Process an incoming task message. More...
 
static int8 cgmCtlPntMsgFindCRC (cgmCtlPntMsg_t *pMsg)
 This function checks the presence of the CRC field in the CGMCP command. More...
 
static int8 cgmRACPMsgFindCRC (cgmRACPMsg_t *pMsg)
 This function checks the presence of the CRC field in the RACP command. More...
 
void CGM_Init (uint8 task_id)
 Initialization function for the CGM App Task. More...
 
uint16 CGM_ProcessEvent (uint8 task_id, uint16 events)
 CGM Application Task event processor. This function is called to process all events for the task. Events include timers, messages and any other user defined events. More...
 

Variables

uint8 cgmTaskId
 The container for holding a glucose calibration structure. More...
 
uint16 gapConnHandle
 Local version of the GAP connection handle. More...
 
static gaprole_States_t gapProfileState = GAPROLE_INIT
 
static uint8 scanData []
 GAP Profile - Name attribute for SCAN RSP data. More...
 
static uint8 advertData []
 Define the Advertizing data. More...
 
static uint8 attDeviceName [GAP_DEVICE_NAME_LEN] = "CGM Simulator"
 The device name variable. More...
 
static bool cgmBonded = FALSE
 Local variable storing the current bonding stage of the sensor. More...
 
static uint8 cgmBondedAddr [B_ADDR_LEN]
 Local variable storing the address of the bonded peer. More...
 
static bool cgmAdvCancelled = FALSE
 
static attHandleValueInd_t cgmCtlPntRsp
 
static attHandleValueNoti_t CGMMeas
 
static attHandleValueInd_t cgmRACPRsp
 
static attHandleValueNoti_t cgmRACPRspNoti
 
static cgmFeature_t cgmFeature
 
static uint16 cgmCommInterval =1000
 
static cgmStatus_t cgmStatus ={0x1234,0x000000}
 
static cgmSessionStartTime_t cgmStartTime ={{0,0,0,0,0,2000},TIME_ZONE_UTC_M5,DST_STANDARD_TIME}
 
static cgmMeasC_t cgmCurrentMeas
 ingroup glucosemeasgrp More...
 
static UTCTime cgmCurrentTime_UTC
 The UTC format of the current system time. Appear as the number of seconds from 2000-01-01-00:00:00. More...
 
static UTCTime cgmStartTime_UTC
 The UTC format of the start time. Appear as the number of seconds from 2000-01-01-00:00:00. More...
 
static uint16 cgmTimeOffset
 The time offset from the session start time. More...
 
static uint16 cgmSessionRunTime =0x00A8
 The run time of the current sensor. Default value is 7 days. More...
 
static bool cgmSessionStartIndicator =false
 Indicate whether the sesstion has been started. More...
 
static bool cgmStartTimeConfigIndicator =false
 
static cgmMeasC_tcgmMeasDB
 Pointer to the glucose measurement history database. More...
 
static uint8 cgmMeasDBWriteIndx
 Hold the array index of the next place to write record. More...
 
static uint8 cgmMeasDBCount
 The number of records being stored into the database. More...
 
static uint8 cgmMeasDBOldestIndx
 The index pointing to the oldest record in the database. More...
 
static uint8 cgmMeasDBSearchStart
 The starting index records meeting the search criterion. More...
 
static uint8 cgmMeasDBSearchEnd
 The ending index of records meeting the search criterion. More...
 
static uint16 cgmMeasDBSearchNum
 The resulting record number that matches the criterion. More...
 
static uint8 cgmMeasDBSendIndx
 
static gapRolesCBs_t cgm_PeripheralCBs
 
static const gapBondCBs_t cgmBondCB
 Bond Manager Callbacks. More...
 

Detailed Description

This file contains the CGM sensor simulator application for use with the CC2540 Bluetooth Low Energy Protocol Stack.

Author
Harry Qiu
Version
2
Date
2015-Feb-12
Version
2

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Macro Definition Documentation

#define SFLOAT   uint16

Using a unsigned 16bit integer to store a SFLOAT.

Function Documentation

static void cgmRACPSendNextMeas ( )
static

As part of the RACP operation, this function sends the set of historical measurement data to the collector APP sequencially. The resulting record would be received by the collector through the glucose measurement characteristic notification.

Returns
none

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

gapRolesCBs_t cgm_PeripheralCBs
static
Initial value:
=
{
NULL
}
static void cgmGapStateCB(gaprole_States_t newState)
Notification from the profile of a state change.
Definition: cgm.c:1048
cgmMeasC_t cgmCurrentMeas
static

ingroup glucosemeasgrp

Local variable storing the most current glucose estimate.