initial commit
This commit is contained in:
Vendored
+101
@@ -0,0 +1,101 @@
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \file
|
||||
*
|
||||
* \brief Medical sensor sample application interface.
|
||||
*
|
||||
* Copyright (c) 2012-2018 Arm Ltd.
|
||||
*
|
||||
* Copyright (c) 2019 Packetcraft, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
#ifndef MEDS_API_H
|
||||
#define MEDS_API_H
|
||||
|
||||
#include "wsf_os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
Macros
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! Profile identifier used for MedsSetProfile() */
|
||||
enum
|
||||
{
|
||||
MEDS_ID_BLP, /*! Blood pressure profile */
|
||||
MEDS_ID_WSP, /*! Weight scale profile */
|
||||
MEDS_ID_HTP, /*! Health thermometer profile */
|
||||
MEDS_ID_PLX, /*! Pulse Oximeter profile */
|
||||
MEDS_ID_GLP /*! Glucose profile */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Function Declarations
|
||||
**************************************************************************************************/
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void MedsStart(void);
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Application handler init function called during system initialization.
|
||||
*
|
||||
* \param handlerID WSF handler ID for App.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void MedsHandlerInit(wsfHandlerId_t handlerId);
|
||||
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief WSF event handler for the application.
|
||||
*
|
||||
* \param event WSF event mask.
|
||||
* \param pMsg WSF message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void MedsHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg);
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Set the profile to be used by the application. This function is called internally
|
||||
* by MedsHandlerInit() with a default value. It may also be called by the system
|
||||
* to configure the profile after executing MedsHandlerInit() and before executing
|
||||
* MedsStart().
|
||||
*
|
||||
* \param profile Profile identifier.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void MedsSetProfile(uint8_t profile);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* MEDS_API_H */
|
||||
Vendored
+322
@@ -0,0 +1,322 @@
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \file
|
||||
*
|
||||
* \brief Medical sensor sample, blood pressure profile
|
||||
*
|
||||
* Copyright (c) 2012-2019 Arm Ltd.
|
||||
*
|
||||
* Copyright (c) 2019 Packetcraft, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include "wsf_types.h"
|
||||
#include "util/bstream.h"
|
||||
#include "wsf_msg.h"
|
||||
#include "wsf_trace.h"
|
||||
#include "hci_api.h"
|
||||
#include "dm_api.h"
|
||||
#include "att_api.h"
|
||||
#include "app_api.h"
|
||||
#include "app_ui.h"
|
||||
#include "svc_ch.h"
|
||||
#include "svc_bps.h"
|
||||
#include "svc_dis.h"
|
||||
#include "svc_core.h"
|
||||
#include "blps/blps_api.h"
|
||||
#include "gatt/gatt_api.h"
|
||||
#include "meds/meds_main.h"
|
||||
|
||||
/**************************************************************************************************
|
||||
Macros
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! enumeration of client characteristic configuration descriptors */
|
||||
enum
|
||||
{
|
||||
MEDS_BLP_GATT_SC_CCC_IDX, /*! GATT service, service changed characteristic */
|
||||
MEDS_BLP_BPS_BPM_CCC_IDX, /*! Blood pressure service, blood pressure measurement characteristic */
|
||||
MEDS_BLP_BPS_ICP_CCC_IDX, /*! Blood pressure service, intermediate cuff pressure characteristic */
|
||||
MEDS_BLP_NUM_CCC_IDX
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Configurable Parameters
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! blood pressure measurement configuration */
|
||||
static const blpsCfg_t medsBlpsCfg =
|
||||
{
|
||||
2000 /*! Measurement timer expiration period in ms */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Advertising Data
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! Service UUID list */
|
||||
static const uint8_t medsSvcUuidList[] =
|
||||
{
|
||||
UINT16_TO_BYTES(ATT_UUID_BLOOD_PRESSURE_SERVICE),
|
||||
UINT16_TO_BYTES(ATT_UUID_DEVICE_INFO_SERVICE)
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Client Characteristic Configuration Descriptors
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! client characteristic configuration descriptors settings, indexed by above enumeration */
|
||||
static const attsCccSet_t medsBlpCccSet[MEDS_BLP_NUM_CCC_IDX] =
|
||||
{
|
||||
/* cccd handle value range security level */
|
||||
{GATT_SC_CH_CCC_HDL, ATT_CLIENT_CFG_INDICATE, DM_SEC_LEVEL_ENC}, /* MEDS_BLP_GATT_SC_CCC_IDX */
|
||||
{BPS_BPM_CH_CCC_HDL, ATT_CLIENT_CFG_INDICATE, DM_SEC_LEVEL_ENC}, /* MEDS_BLP_BPS_BPM_CCC_IDX */
|
||||
{BPS_ICP_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_ENC} /* MEDS_BLP_BPS_ICP_CCC_IDX */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Local Functions
|
||||
**************************************************************************************************/
|
||||
|
||||
static void medsBlpStart(void);
|
||||
static void medsBlpProcMsg(wsfMsgHdr_t *pMsg);
|
||||
static void medsBlpBtn(dmConnId_t connId, uint8_t btn);
|
||||
|
||||
/**************************************************************************************************
|
||||
Global Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! profile interface pointer */
|
||||
medsIf_t medsBlpIf =
|
||||
{
|
||||
NULL,
|
||||
medsBlpStart,
|
||||
medsBlpProcMsg,
|
||||
medsBlpBtn
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Local Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! application control block */
|
||||
static struct
|
||||
{
|
||||
bool_t measuring;
|
||||
bool_t storedMeasurement;
|
||||
} medsBlpCb;
|
||||
|
||||
static uint8_t medsBpmFlags = CH_BPM_FLAG_UNITS_MMHG | CH_BPM_FLAG_TIMESTAMP |
|
||||
CH_BPM_FLAG_PULSE_RATE | CH_BPM_FLAG_MEAS_STATUS;
|
||||
static uint8_t medsIcpFlags = CH_BPM_FLAG_UNITS_MMHG | CH_BPM_FLAG_PULSE_RATE |
|
||||
CH_BPM_FLAG_MEAS_STATUS;
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Perform UI actions on connection close.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsBlpClose(wsfMsgHdr_t *pMsg)
|
||||
{
|
||||
/* stop blood pressure measurement */
|
||||
BlpsMeasStop();
|
||||
medsBlpCb.measuring = FALSE;
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsBlpStart(void)
|
||||
{
|
||||
/* set up CCCD table and callback */
|
||||
AttsCccRegister(MEDS_BLP_NUM_CCC_IDX, (attsCccSet_t *) medsBlpCccSet, medsCccCback);
|
||||
|
||||
/* add blood pressure service */
|
||||
SvcBpsAddGroup();
|
||||
|
||||
/* Set Service Changed CCCD index. */
|
||||
GattSetSvcChangedIdx(MEDS_BLP_GATT_SC_CCC_IDX);
|
||||
|
||||
/* initialize blood pressure profile sensor */
|
||||
BlpsInit(medsCb.handlerId, (blpsCfg_t *) &medsBlpsCfg);
|
||||
BlpsSetBpmFlags(medsBpmFlags);
|
||||
BlpsSetIcpFlags(medsIcpFlags);
|
||||
|
||||
/* set advertising data */
|
||||
AppAdvSetAdValue(APP_ADV_DATA_DISCOVERABLE, DM_ADV_TYPE_16_UUID, sizeof(medsSvcUuidList),
|
||||
(uint8_t *) medsSvcUuidList);
|
||||
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Send stored blood pressure measurement.
|
||||
*
|
||||
* \param connId Connection ID to send stored measurement to.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsBlpSendStoredMeasurement(dmConnId_t connId)
|
||||
{
|
||||
medsBlpCb.storedMeasurement = FALSE;
|
||||
|
||||
BlpsMeasComplete((dmConnId_t)connId, MEDS_BLP_BPS_BPM_CCC_IDX);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Process messages from the event handler.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsBlpProcMsg(wsfMsgHdr_t *pMsg)
|
||||
{
|
||||
switch(pMsg->event)
|
||||
{
|
||||
case MEDS_TIMER_IND:
|
||||
BlpsProcMsg(pMsg);
|
||||
break;
|
||||
|
||||
case ATTS_CCC_STATE_IND:
|
||||
/* Check if stored measurement exists and indications on measurements enabled */
|
||||
if (medsBlpCb.storedMeasurement &&
|
||||
AttsCccEnabled((dmConnId_t)pMsg->param, MEDS_BLP_BPS_BPM_CCC_IDX))
|
||||
{
|
||||
medsBlpSendStoredMeasurement((dmConnId_t)pMsg->param);
|
||||
}
|
||||
break;
|
||||
|
||||
case DM_CONN_CLOSE_IND:
|
||||
medsBlpClose(pMsg);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Button press callback.
|
||||
*
|
||||
* \param connId Connection identifier.
|
||||
* \param btn Button press.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsBlpBtn(dmConnId_t connId, uint8_t btn)
|
||||
{
|
||||
/* button actions when connected */
|
||||
if (connId != DM_CONN_ID_NONE)
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
case APP_UI_BTN_1_SHORT:
|
||||
/* start or complete measurement */
|
||||
if (!medsBlpCb.measuring)
|
||||
{
|
||||
BlpsMeasStart(connId, MEDS_TIMER_IND, MEDS_BLP_BPS_ICP_CCC_IDX);
|
||||
medsBlpCb.measuring = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
BlpsMeasComplete(connId, MEDS_BLP_BPS_BPM_CCC_IDX);
|
||||
medsBlpCb.measuring = FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else /* if not connected */
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
case APP_UI_BTN_1_EX_LONG:
|
||||
/* Toggle flags in service for testing purposes */
|
||||
SvcBpsToggleFeatureFlags(CH_BPF_FLAG_MULTI_BOND);
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_2_SHORT:
|
||||
/* Toggle flags in measurements for testing purposes */
|
||||
if (!(medsBpmFlags & CH_BPM_FLAG_USER_ID))
|
||||
{
|
||||
medsBpmFlags |= CH_BPM_FLAG_USER_ID;
|
||||
}
|
||||
else
|
||||
{
|
||||
medsBpmFlags &= ~CH_BPM_FLAG_USER_ID;
|
||||
}
|
||||
|
||||
BlpsSetBpmFlags(medsBpmFlags);
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_2_MED:
|
||||
/* Toggle flags in intermediate measurements for testing purposes */
|
||||
if (!(medsIcpFlags & CH_BPM_FLAG_USER_ID))
|
||||
{
|
||||
medsIcpFlags |= CH_BPM_FLAG_USER_ID;
|
||||
}
|
||||
else
|
||||
{
|
||||
medsIcpFlags &= ~CH_BPM_FLAG_USER_ID;
|
||||
}
|
||||
|
||||
BlpsSetIcpFlags(medsIcpFlags);
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_2_LONG:
|
||||
/* Toggle flags in intermediate measurements for testing purposes */
|
||||
if (!(medsIcpFlags & CH_BPM_FLAG_TIMESTAMP))
|
||||
{
|
||||
medsIcpFlags |= CH_BPM_FLAG_TIMESTAMP;
|
||||
}
|
||||
else
|
||||
{
|
||||
medsIcpFlags &= ~CH_BPM_FLAG_TIMESTAMP;
|
||||
}
|
||||
|
||||
BlpsSetIcpFlags(medsIcpFlags);
|
||||
break;
|
||||
|
||||
|
||||
case APP_UI_BTN_2_EX_LONG:
|
||||
if (connId == DM_CONN_ID_NONE)
|
||||
{
|
||||
/* Store a measurement to be sent when connected */
|
||||
medsBlpCb.storedMeasurement = TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+166
@@ -0,0 +1,166 @@
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \file
|
||||
*
|
||||
* \brief Medical sensor sample, glucose profile
|
||||
*
|
||||
* Copyright (c) 2016-2019 Arm Ltd.
|
||||
*
|
||||
* Copyright (c) 2019 Packetcraft, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include "wsf_types.h"
|
||||
#include "util/bstream.h"
|
||||
#include "wsf_msg.h"
|
||||
#include "wsf_trace.h"
|
||||
#include "hci_api.h"
|
||||
#include "dm_api.h"
|
||||
#include "att_api.h"
|
||||
#include "app_api.h"
|
||||
#include "app_ui.h"
|
||||
#include "app_hw.h"
|
||||
#include "svc_ch.h"
|
||||
#include "svc_gls.h"
|
||||
#include "svc_dis.h"
|
||||
#include "svc_core.h"
|
||||
#include "gatt/gatt_api.h"
|
||||
#include "glps/glps_api.h"
|
||||
#include "meds/meds_main.h"
|
||||
|
||||
/**************************************************************************************************
|
||||
Macros
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! enumeration of client characteristic configuration descriptors */
|
||||
enum
|
||||
{
|
||||
MEDS_GLS_GATT_SC_CCC_IDX, /*! GATT service, service changed characteristic */
|
||||
MEDS_GLS_GLS_GLM_CCC_IDX, /*! Glucose measurement characteristic */
|
||||
MEDS_GLS_GLS_GLMC_CCC_IDX, /*! Glucose measurement context characteristic */
|
||||
MEDS_GLS_GLS_RACP_CCC_IDX, /*! Glucose record access control point characteristic */
|
||||
MEDS_GLS_NUM_CCC_IDX
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Advertising Data
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! Service UUID list */
|
||||
static const uint8_t medsSvcUuidList[] =
|
||||
{
|
||||
UINT16_TO_BYTES(ATT_UUID_GLUCOSE_SERVICE),
|
||||
UINT16_TO_BYTES(ATT_UUID_DEVICE_INFO_SERVICE)
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Client Characteristic Configuration Descriptors
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! client characteristic configuration descriptors settings, indexed by above enumeration */
|
||||
static const attsCccSet_t medsGlpCccSet[MEDS_GLS_NUM_CCC_IDX] =
|
||||
{
|
||||
/* cccd handle value range security level */
|
||||
{GATT_SC_CH_CCC_HDL, ATT_CLIENT_CFG_INDICATE, DM_SEC_LEVEL_NONE}, /* MEDS_GLS_GATT_SC_CCC_IDX */
|
||||
{GLS_GLM_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* MEDS_GLS_GLS_GLM_CCC_IDX */
|
||||
{GLS_GLMC_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* MEDS_GLS_GLS_GLMC_CCC_IDX */
|
||||
{GLS_RACP_CH_CCC_HDL, ATT_CLIENT_CFG_INDICATE, DM_SEC_LEVEL_NONE} /* MEDS_GLS_GLS_RACP_CCC_IDX */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Local Functions
|
||||
**************************************************************************************************/
|
||||
|
||||
static void medsGlpStart(void);
|
||||
static void medsGlpProcMsg(wsfMsgHdr_t *pMsg);
|
||||
static void medsGlpBtn(dmConnId_t connId, uint8_t btn);
|
||||
|
||||
/**************************************************************************************************
|
||||
Global Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! profile interface pointer */
|
||||
medsIf_t medsGlpIf =
|
||||
{
|
||||
NULL,
|
||||
medsGlpStart,
|
||||
medsGlpProcMsg,
|
||||
medsGlpBtn
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Local Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsGlpStart(void)
|
||||
{
|
||||
/* set up CCCD table and callback */
|
||||
AttsCccRegister(MEDS_GLS_NUM_CCC_IDX, (attsCccSet_t *) medsGlpCccSet, medsCccCback);
|
||||
|
||||
/* add glucose service */
|
||||
SvcGlsAddGroup();
|
||||
SvcGlsCbackRegister(NULL, GlpsRacpWriteCback);
|
||||
|
||||
/* Set Service Changed CCCD index. */
|
||||
GattSetSvcChangedIdx(MEDS_GLS_GATT_SC_CCC_IDX);
|
||||
|
||||
/* initialize glucose profile sensor */
|
||||
GlpsInit();
|
||||
GlpsSetCccIdx(MEDS_GLS_GLS_GLM_CCC_IDX, MEDS_GLS_GLS_GLMC_CCC_IDX, MEDS_GLS_GLS_RACP_CCC_IDX);
|
||||
|
||||
/* TODO: Define glucose features */
|
||||
GlpsSetFeature(GLP_ALL_SUPPORTED_FEATURES);
|
||||
|
||||
/* set advertising data */
|
||||
AppAdvSetAdValue(APP_ADV_DATA_DISCOVERABLE, DM_ADV_TYPE_16_UUID, sizeof(medsSvcUuidList),
|
||||
(uint8_t *) medsSvcUuidList);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Process messages from the event handler.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsGlpProcMsg(wsfMsgHdr_t *pMsg)
|
||||
{
|
||||
GlpsProcMsg(pMsg);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Button press callback.
|
||||
*
|
||||
* \param connId Connection identifier.
|
||||
* \param btn Button press.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsGlpBtn(dmConnId_t connId, uint8_t btn)
|
||||
{
|
||||
GlpsBtn(connId, btn);
|
||||
}
|
||||
Vendored
+293
@@ -0,0 +1,293 @@
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \file
|
||||
*
|
||||
* \brief Medical sensor sample, health thermometer profile
|
||||
*
|
||||
* Copyright (c) 2012-2019 Arm Ltd.
|
||||
*
|
||||
* Copyright (c) 2019 Packetcraft, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include "wsf_types.h"
|
||||
#include "util/bstream.h"
|
||||
#include "wsf_msg.h"
|
||||
#include "wsf_trace.h"
|
||||
#include "hci_api.h"
|
||||
#include "dm_api.h"
|
||||
#include "att_api.h"
|
||||
#include "app_api.h"
|
||||
#include "app_hw.h"
|
||||
#include "app_ui.h"
|
||||
#include "svc_ch.h"
|
||||
#include "svc_hts.h"
|
||||
#include "svc_dis.h"
|
||||
#include "svc_core.h"
|
||||
#include "gatt/gatt_api.h"
|
||||
#include "htps/htps_api.h"
|
||||
#include "meds/meds_main.h"
|
||||
|
||||
/**************************************************************************************************
|
||||
Macros
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! enumeration of client characteristic configuration descriptors */
|
||||
enum
|
||||
{
|
||||
MEDS_HTP_GATT_SC_CCC_IDX, /*! GATT service, service changed characteristic */
|
||||
MEDS_HTP_HTS_TM_CCC_IDX, /*! Health thermometer service, temperature measurement characteristic */
|
||||
MEDS_HTP_HTS_IT_CCC_IDX, /*! Health thermometer service, intermediate temperature characteristic */
|
||||
MEDS_HTP_NUM_CCC_IDX
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Configurable Parameters
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! health thermometer measurement configuration */
|
||||
static const htpsCfg_t medsHtpsCfg =
|
||||
{
|
||||
2000 /*! Measurement timer expiration period in ms */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Advertising Data
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! Service UUID list */
|
||||
static const uint8_t medsSvcUuidList[] =
|
||||
{
|
||||
UINT16_TO_BYTES(ATT_UUID_HEALTH_THERM_SERVICE),
|
||||
UINT16_TO_BYTES(ATT_UUID_DEVICE_INFO_SERVICE)
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Client Characteristic Configuration Descriptors
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! client characteristic configuration descriptors settings, indexed by above enumeration */
|
||||
static const attsCccSet_t medsHtpCccSet[MEDS_HTP_NUM_CCC_IDX] =
|
||||
{
|
||||
/* cccd handle value range security level */
|
||||
{GATT_SC_CH_CCC_HDL, ATT_CLIENT_CFG_INDICATE, DM_SEC_LEVEL_ENC}, /* MEDS_HTP_GATT_SC_CCC_IDX */
|
||||
{HTS_TM_CH_CCC_HDL, ATT_CLIENT_CFG_INDICATE, DM_SEC_LEVEL_NONE}, /* MEDS_HTP_HTS_TM_CCC_IDX */
|
||||
{HTS_IT_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_ENC} /* MEDS_HTP_HTS_IT_CCC_IDX */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Local Functions
|
||||
**************************************************************************************************/
|
||||
|
||||
static void medsHtpStart(void);
|
||||
static void medsHtpProcMsg(wsfMsgHdr_t *pMsg);
|
||||
static void medsHtpBtn(dmConnId_t connId, uint8_t btn);
|
||||
|
||||
/**************************************************************************************************
|
||||
Global Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! profile interface pointer */
|
||||
medsIf_t medsHtpIf =
|
||||
{
|
||||
NULL,
|
||||
medsHtpStart,
|
||||
medsHtpProcMsg,
|
||||
medsHtpBtn
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Local Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! application control block */
|
||||
static struct
|
||||
{
|
||||
bool_t measuring;
|
||||
bool_t storedMeasurement;
|
||||
} medsHtpCb;
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Set temperature measurement units.
|
||||
*
|
||||
* \param units CH_TM_FLAG_UNITS_C or CH_TM_FLAG_UNITS_F.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsHtpSetUnits(uint8_t units)
|
||||
{
|
||||
HtpsSetTmFlags(units | CH_TM_FLAG_TIMESTAMP);
|
||||
HtpsSetItFlags(units);
|
||||
AppHwTmSetUnits(units);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Perform UI actions on connection close.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsHtpClose(wsfMsgHdr_t *pMsg)
|
||||
{
|
||||
/* stop health thermometer measurement */
|
||||
HtpsMeasStop();
|
||||
medsHtpCb.measuring = FALSE;
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsHtpStart(void)
|
||||
{
|
||||
/* set up CCCD table and callback */
|
||||
AttsCccRegister(MEDS_HTP_NUM_CCC_IDX, (attsCccSet_t *) medsHtpCccSet, medsCccCback);
|
||||
|
||||
/* add health thermometer service */
|
||||
SvcHtsAddGroup();
|
||||
|
||||
/* Set Service Changed CCCD index. */
|
||||
GattSetSvcChangedIdx(MEDS_HTP_GATT_SC_CCC_IDX);
|
||||
|
||||
/* initialize health thermometer profile sensor */
|
||||
HtpsInit(medsCb.handlerId, (htpsCfg_t *) &medsHtpsCfg);
|
||||
medsHtpSetUnits(CH_TM_FLAG_UNITS_C);
|
||||
|
||||
/* set advertising data */
|
||||
AppAdvSetAdValue(APP_ADV_DATA_DISCOVERABLE, DM_ADV_TYPE_16_UUID, sizeof(medsSvcUuidList),
|
||||
(uint8_t *) medsSvcUuidList);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Send stored temperature measurement.
|
||||
*
|
||||
* \param connId connection ID to send stored measurement to.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsHtpSendStoredMeasurement(dmConnId_t connId)
|
||||
{
|
||||
medsHtpCb.storedMeasurement = FALSE;
|
||||
|
||||
HtpsMeasComplete((dmConnId_t)connId, MEDS_HTP_HTS_TM_CCC_IDX);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Process messages from the event handler.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsHtpProcMsg(wsfMsgHdr_t *pMsg)
|
||||
{
|
||||
switch(pMsg->event)
|
||||
{
|
||||
case MEDS_TIMER_IND:
|
||||
HtpsProcMsg(pMsg);
|
||||
break;
|
||||
|
||||
case ATTS_CCC_STATE_IND:
|
||||
/* Check if stored measurement exists and indications on temperature measurement enabled */
|
||||
if (medsHtpCb.storedMeasurement && AttsCccEnabled((dmConnId_t)pMsg->param, MEDS_HTP_HTS_TM_CCC_IDX))
|
||||
{
|
||||
medsHtpSendStoredMeasurement((dmConnId_t)pMsg->param);
|
||||
}
|
||||
break;
|
||||
|
||||
case DM_CONN_CLOSE_IND:
|
||||
medsHtpClose(pMsg);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Button press callback.
|
||||
*
|
||||
* \param connId Connection identifier.
|
||||
* \param btn Button press.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsHtpBtn(dmConnId_t connId, uint8_t btn)
|
||||
{
|
||||
static bool_t advNonconn = FALSE;
|
||||
|
||||
switch (btn)
|
||||
{
|
||||
case APP_UI_BTN_1_SHORT:
|
||||
/* if connected */
|
||||
if (connId != DM_CONN_ID_NONE)
|
||||
{
|
||||
/* start or complete measurement */
|
||||
if (!medsHtpCb.measuring)
|
||||
{
|
||||
HtpsMeasStart(connId, MEDS_TIMER_IND, MEDS_HTP_HTS_IT_CCC_IDX);
|
||||
medsHtpCb.measuring = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
HtpsMeasComplete(connId, MEDS_HTP_HTS_TM_CCC_IDX);
|
||||
medsHtpCb.measuring = FALSE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_2_SHORT:
|
||||
/* set units */
|
||||
medsHtpSetUnits(CH_TM_FLAG_UNITS_F);
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_2_MED:
|
||||
/* set units */
|
||||
medsHtpSetUnits(CH_TM_FLAG_UNITS_C);
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_2_LONG:
|
||||
/* set new advertising type */
|
||||
advNonconn = !advNonconn;
|
||||
AppSetAdvType(advNonconn ? DM_ADV_NONCONN_UNDIRECT : DM_ADV_CONN_UNDIRECT);
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_2_EX_LONG:
|
||||
if (connId == DM_CONN_ID_NONE)
|
||||
{
|
||||
/* Store a temperature measurement to be sent when connected */
|
||||
medsHtpCb.storedMeasurement = TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
Vendored
+542
@@ -0,0 +1,542 @@
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \file
|
||||
*
|
||||
* \brief Medical sensor sample application for the following profiles:
|
||||
* Blood Pressure profile sensor
|
||||
* Weight Scale profile sensor
|
||||
* Health Thermometer profile sensor
|
||||
*
|
||||
* Copyright (c) 2012-2019 Arm Ltd.
|
||||
*
|
||||
* Copyright (c) 2019 Packetcraft, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include "wsf_types.h"
|
||||
#include "util/bstream.h"
|
||||
#include "wsf_msg.h"
|
||||
#include "wsf_trace.h"
|
||||
#include "hci_api.h"
|
||||
#include "dm_api.h"
|
||||
#include "att_api.h"
|
||||
#include "app_api.h"
|
||||
#include "app_db.h"
|
||||
#include "app_ui.h"
|
||||
#include "app_hw.h"
|
||||
#include "app_main.h"
|
||||
#include "svc_ch.h"
|
||||
#include "svc_core.h"
|
||||
#include "svc_dis.h"
|
||||
#include "gatt/gatt_api.h"
|
||||
#include "meds/meds_api.h"
|
||||
#include "meds/meds_main.h"
|
||||
|
||||
/**************************************************************************************************
|
||||
Profile Configuration
|
||||
**************************************************************************************************/
|
||||
|
||||
/* Blood pressure profile included */
|
||||
#ifndef MEDS_BLP_INCLUDED
|
||||
#define MEDS_BLP_INCLUDED TRUE
|
||||
#endif
|
||||
|
||||
/* Weight scale profile included */
|
||||
#ifndef MEDS_WSP_INCLUDED
|
||||
#define MEDS_WSP_INCLUDED TRUE
|
||||
#endif
|
||||
|
||||
/* Health thermometer profile included */
|
||||
#ifndef MEDS_HTP_INCLUDED
|
||||
#define MEDS_HTP_INCLUDED TRUE
|
||||
#endif
|
||||
|
||||
/* Pulse Oximeter profile included */
|
||||
#ifndef MEDS_PLX_INCLUDED
|
||||
#define MEDS_PLX_INCLUDED TRUE
|
||||
#endif
|
||||
|
||||
/* Glucose profile included */
|
||||
#ifndef MEDS_GLP_INCLUDED
|
||||
#define MEDS_GLP_INCLUDED TRUE
|
||||
#endif
|
||||
|
||||
/* Default profile to use */
|
||||
#ifndef MEDS_PROFILE
|
||||
#define MEDS_PROFILE MEDS_ID_BLP
|
||||
#endif
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
Configurable Parameters
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! configurable parameters for advertising */
|
||||
static const appAdvCfg_t medsAdvCfg =
|
||||
{
|
||||
{60000, 30000, 0}, /*! Advertising durations in ms */
|
||||
{ 48, 1600, 0} /*! Advertising intervals in 0.625 ms units */
|
||||
};
|
||||
|
||||
/*! configurable parameters for slave */
|
||||
static const appSlaveCfg_t medsSlaveCfg =
|
||||
{
|
||||
1, /*! Maximum connections */
|
||||
};
|
||||
|
||||
/*! configurable parameters for security */
|
||||
static const appSecCfg_t medsSecCfg =
|
||||
{
|
||||
DM_AUTH_BOND_FLAG, /*! Authentication and bonding flags */
|
||||
0, /*! Initiator key distribution flags */
|
||||
DM_KEY_DIST_LTK, /*! Responder key distribution flags */
|
||||
FALSE, /*! TRUE if Out-of-band pairing data is present */
|
||||
TRUE /*! TRUE to initiate security upon connection */
|
||||
};
|
||||
|
||||
/*! configurable parameters for connection parameter update */
|
||||
static const appUpdateCfg_t medsUpdateCfg =
|
||||
{
|
||||
0, /*! Connection idle period in ms before attempting
|
||||
connection parameter update; set to zero to disable */
|
||||
640, /*! Minimum connection interval in 1.25ms units */
|
||||
800, /*! Maximum connection interval in 1.25ms units */
|
||||
0, /*! Connection latency */
|
||||
600, /*! Supervision timeout in 10ms units */
|
||||
5 /*! Number of update attempts before giving up */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Advertising Data
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! advertising data flags */
|
||||
static const uint8_t medsAdvDataFlags[] =
|
||||
{
|
||||
DM_FLAG_LE_LIMITED_DISC |
|
||||
DM_FLAG_LE_BREDR_NOT_SUP
|
||||
};
|
||||
|
||||
/*! advertising data buffer (value is set in medsSetup) */
|
||||
static uint8_t medsAdvDataDisc[HCI_ADV_DATA_LEN];
|
||||
|
||||
/*! scan data, discoverable mode */
|
||||
static const uint8_t medsScanDataDisc[] =
|
||||
{
|
||||
/*! device name */
|
||||
11, /*! length */
|
||||
DM_ADV_TYPE_LOCAL_NAME, /*! AD type */
|
||||
'M',
|
||||
'e',
|
||||
'd',
|
||||
' ',
|
||||
'S',
|
||||
'e',
|
||||
'n',
|
||||
's',
|
||||
'o',
|
||||
'r'
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Global Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! application control block */
|
||||
medsCb_t medsCb;
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Application DM callback.
|
||||
*
|
||||
* \param pDmEvt DM callback event
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsDmCback(dmEvt_t *pDmEvt)
|
||||
{
|
||||
dmEvt_t *pMsg;
|
||||
uint16_t len;
|
||||
|
||||
len = DmSizeOfEvt(pDmEvt);
|
||||
|
||||
if ((pMsg = WsfMsgAlloc(len)) != NULL)
|
||||
{
|
||||
memcpy(pMsg, pDmEvt, len);
|
||||
WsfMsgSend(medsCb.handlerId, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Application ATT callback.
|
||||
*
|
||||
* \param pEvt ATT callback event
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsAttCback(attEvt_t *pEvt)
|
||||
{
|
||||
medsCb.pIf->procMsg((wsfMsgHdr_t*) pEvt);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Application ATTS client characteristic configuration callback.
|
||||
*
|
||||
* \param pDmEvt DM callback event
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void medsCccCback(attsCccEvt_t *pEvt)
|
||||
{
|
||||
attsCccEvt_t *pMsg;
|
||||
appDbHdl_t dbHdl;
|
||||
|
||||
/* If CCC not set from initialization and there's a device record and currently bonded */
|
||||
if ((pEvt->handle != ATT_HANDLE_NONE) &&
|
||||
((dbHdl = AppDbGetHdl((dmConnId_t) pEvt->hdr.param)) != APP_DB_HDL_NONE) &&
|
||||
AppCheckBonded((dmConnId_t)pEvt->hdr.param))
|
||||
{
|
||||
/* Store value in device database. */
|
||||
AppDbSetCccTblValue(dbHdl, pEvt->idx, pEvt->value);
|
||||
}
|
||||
|
||||
if ((pMsg = WsfMsgAlloc(sizeof(attsCccEvt_t))) != NULL)
|
||||
{
|
||||
memcpy(pMsg, pEvt, sizeof(attsCccEvt_t));
|
||||
WsfMsgSend(medsCb.handlerId, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Set up advertising and other procedures that need to be performed after
|
||||
* device reset.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsSetup(wsfMsgHdr_t *pMsg)
|
||||
{
|
||||
/* start advertising; automatically set connectable/discoverable mode and bondable mode */
|
||||
AppAdvStart(APP_MODE_AUTO_INIT);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Button press callback.
|
||||
*
|
||||
* \param btn Button press.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsBtnCback(uint8_t btn)
|
||||
{
|
||||
dmConnId_t connId;
|
||||
|
||||
/* button actions when connected */
|
||||
if ((connId = AppConnIsOpen()) != DM_CONN_ID_NONE)
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
case APP_UI_BTN_1_LONG:
|
||||
AppConnClose(connId);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* all other button presses-- send to profile */
|
||||
medsCb.pIf->btn(connId, btn);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* button actions when not connected */
|
||||
else
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
case APP_UI_BTN_1_SHORT:
|
||||
/* start or restart advertising */
|
||||
AppAdvStart(APP_MODE_AUTO_INIT);
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_1_MED:
|
||||
/* enter discoverable and bondable mode mode */
|
||||
AppSetBondable(TRUE);
|
||||
AppAdvStart(APP_MODE_DISCOVERABLE);
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_1_LONG:
|
||||
/* clear all bonding info */
|
||||
AppSlaveClearAllBondingInfo();
|
||||
|
||||
/* restart advertising */
|
||||
AppAdvStart(APP_MODE_AUTO_INIT);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* all other button presses-- send to profile */
|
||||
medsCb.pIf->btn(connId, btn);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Process messages from the event handler.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsProcMsg(wsfMsgHdr_t *pMsg)
|
||||
{
|
||||
uint8_t uiEvent = APP_UI_NONE;
|
||||
|
||||
switch(pMsg->event)
|
||||
{
|
||||
case MEDS_TIMER_IND:
|
||||
break;
|
||||
|
||||
case ATT_MTU_UPDATE_IND:
|
||||
APP_TRACE_INFO1("Negotiated MTU %d", ((attEvt_t *)pMsg)->mtu);
|
||||
break;
|
||||
|
||||
case DM_RESET_CMPL_IND:
|
||||
AttsCalculateDbHash();
|
||||
medsSetup(pMsg);
|
||||
uiEvent = APP_UI_RESET_CMPL;
|
||||
break;
|
||||
|
||||
case DM_ADV_START_IND:
|
||||
uiEvent = APP_UI_ADV_START;
|
||||
break;
|
||||
|
||||
case DM_ADV_STOP_IND:
|
||||
uiEvent = APP_UI_ADV_STOP;
|
||||
break;
|
||||
|
||||
case DM_CONN_OPEN_IND:
|
||||
uiEvent = APP_UI_CONN_OPEN;
|
||||
break;
|
||||
|
||||
case DM_CONN_CLOSE_IND:
|
||||
uiEvent = APP_UI_CONN_CLOSE;
|
||||
break;
|
||||
|
||||
case DM_SEC_PAIR_CMPL_IND:
|
||||
uiEvent = APP_UI_SEC_PAIR_CMPL;
|
||||
break;
|
||||
|
||||
case DM_SEC_PAIR_FAIL_IND:
|
||||
uiEvent = APP_UI_SEC_PAIR_FAIL;
|
||||
break;
|
||||
|
||||
case DM_SEC_ENCRYPT_IND:
|
||||
uiEvent = APP_UI_SEC_ENCRYPT;
|
||||
break;
|
||||
|
||||
case DM_SEC_ENCRYPT_FAIL_IND:
|
||||
uiEvent = APP_UI_SEC_ENCRYPT_FAIL;
|
||||
break;
|
||||
|
||||
case DM_SEC_AUTH_REQ_IND:
|
||||
AppHandlePasskey(&((dmEvt_t *)pMsg)->authReq);
|
||||
break;
|
||||
|
||||
case DM_PRIV_CLEAR_RES_LIST_IND:
|
||||
APP_TRACE_INFO1("Clear resolving list status 0x%02x", pMsg->status);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
medsCb.pIf->procMsg(pMsg);
|
||||
|
||||
if (uiEvent != APP_UI_NONE)
|
||||
{
|
||||
AppUiAction(uiEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Application handler init function called during system initialization.
|
||||
*
|
||||
* \param handlerID WSF handler ID.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void MedsHandlerInit(wsfHandlerId_t handlerId)
|
||||
{
|
||||
APP_TRACE_INFO0("MedsHandlerInit");
|
||||
|
||||
/* store handler ID */
|
||||
medsCb.handlerId = handlerId;
|
||||
|
||||
/* Set configuration pointers */
|
||||
pAppSlaveCfg = (appSlaveCfg_t *) &medsSlaveCfg;
|
||||
pAppAdvCfg = (appAdvCfg_t *) &medsAdvCfg;
|
||||
pAppSecCfg = (appSecCfg_t *) &medsSecCfg;
|
||||
pAppUpdateCfg = (appUpdateCfg_t *) &medsUpdateCfg;
|
||||
|
||||
/* Initialize application framework */
|
||||
AppSlaveInit();
|
||||
AppServerInit();
|
||||
|
||||
/* Set default profile to use */
|
||||
MedsSetProfile(MEDS_PROFILE);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief WSF event handler for application.
|
||||
*
|
||||
* \param event WSF event mask.
|
||||
* \param pMsg WSF message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void MedsHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg)
|
||||
{
|
||||
if (pMsg != NULL)
|
||||
{
|
||||
APP_TRACE_INFO1("Meds got evt %d", pMsg->event);
|
||||
|
||||
/* process ATT messages */
|
||||
if (pMsg->event >= ATT_CBACK_START && pMsg->event <= ATT_CBACK_END)
|
||||
{
|
||||
/* process server-related ATT messages */
|
||||
AppServerProcAttMsg(pMsg);
|
||||
}
|
||||
/* process DM messages */
|
||||
else if (pMsg->event >= DM_CBACK_START && pMsg->event <= DM_CBACK_END)
|
||||
{
|
||||
/* process advertising and connection-related messages */
|
||||
AppSlaveProcDmMsg((dmEvt_t *) pMsg);
|
||||
|
||||
/* process security-related messages */
|
||||
AppSlaveSecProcDmMsg((dmEvt_t *) pMsg);
|
||||
}
|
||||
|
||||
/* perform profile and user interface-related operations */
|
||||
medsProcMsg(pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void MedsStart(void)
|
||||
{
|
||||
/* Register for stack callbacks */
|
||||
DmRegister(medsDmCback);
|
||||
DmConnRegister(DM_CLIENT_ID_APP, medsDmCback);
|
||||
AttRegister(medsAttCback);
|
||||
AttConnRegister(AppServerConnCback);
|
||||
|
||||
/* Register for app framework callbacks */
|
||||
AppUiBtnRegister(medsBtnCback);
|
||||
|
||||
/* Initialize attribute server database */
|
||||
SvcCoreGattCbackRegister(GattReadCback, GattWriteCback);
|
||||
SvcCoreAddGroup();
|
||||
SvcDisAddGroup();
|
||||
|
||||
/* set advertising and scan response data for discoverable mode */
|
||||
AppAdvSetData(APP_ADV_DATA_DISCOVERABLE, 0, (uint8_t *) medsAdvDataDisc);
|
||||
AppAdvSetAdValue(APP_ADV_DATA_DISCOVERABLE, DM_ADV_TYPE_FLAGS, sizeof(medsAdvDataFlags),
|
||||
(uint8_t *) medsAdvDataFlags);
|
||||
AppAdvSetData(APP_SCAN_DATA_DISCOVERABLE, sizeof(medsScanDataDisc), (uint8_t *) medsScanDataDisc);
|
||||
|
||||
/* set advertising and scan response data for connectable mode */
|
||||
AppAdvSetData(APP_ADV_DATA_CONNECTABLE, 0, NULL);
|
||||
AppAdvSetData(APP_SCAN_DATA_CONNECTABLE, 0, NULL);
|
||||
|
||||
/* call profile start function */
|
||||
medsCb.pIf->start();
|
||||
|
||||
/* Reset the device */
|
||||
DmDevReset();
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Set the profile to be used by the application. This function is called internally
|
||||
* by MedsHandlerInit() with a default value. It may also be called by the system
|
||||
* to configure the profile after executing MedsHandlerInit() and before executing
|
||||
* MedsStart().
|
||||
*
|
||||
* \param profile Profile identifier.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void MedsSetProfile(uint8_t profile)
|
||||
{
|
||||
switch (profile)
|
||||
{
|
||||
#if MEDS_BLP_INCLUDED == TRUE
|
||||
case MEDS_ID_BLP:
|
||||
medsCb.pIf = &medsBlpIf;
|
||||
break;
|
||||
#endif
|
||||
#if MEDS_WSP_INCLUDED == TRUE
|
||||
case MEDS_ID_WSP:
|
||||
medsCb.pIf = &medsWspIf;
|
||||
break;
|
||||
#endif
|
||||
#if MEDS_HTP_INCLUDED == TRUE
|
||||
case MEDS_ID_HTP:
|
||||
medsCb.pIf = &medsHtpIf;
|
||||
break;
|
||||
#endif
|
||||
#if MEDS_PLX_INCLUDED == TRUE
|
||||
case MEDS_ID_PLX:
|
||||
medsCb.pIf = &medsPlxIf;
|
||||
break;
|
||||
#endif
|
||||
#if MEDS_GLP_INCLUDED == TRUE
|
||||
case MEDS_ID_GLP:
|
||||
medsCb.pIf = &medsGlpIf;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
APP_TRACE_WARN1("MedsSetProfile invalid profile:%d", profile);
|
||||
medsCb.pIf = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((medsCb.pIf != NULL) && (medsCb.pIf->init != NULL))
|
||||
{
|
||||
medsCb.pIf->init();
|
||||
}
|
||||
}
|
||||
Vendored
+96
@@ -0,0 +1,96 @@
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \file
|
||||
*
|
||||
* \brief Health/medical sensor sample application interface file.
|
||||
*
|
||||
* Copyright (c) 2012-2018 Arm Ltd.
|
||||
*
|
||||
* Copyright (c) 2019 Packetcraft, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
|
||||
#ifndef MEDS_MAIN_H
|
||||
#define MEDS_MAIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
Macros
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! WSF message event starting value */
|
||||
#define MEDS_MSG_START 0xA0
|
||||
|
||||
/*! WSF message event enumeration */
|
||||
enum
|
||||
{
|
||||
MEDS_TIMER_IND = MEDS_MSG_START, /*! Timer expired */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Data Types
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! profile interface callback functions */
|
||||
typedef void (*medsInitCback_t)(void);
|
||||
typedef void (*medsStartCback_t)(void);
|
||||
typedef void (*medsProcMsgCback_t)(wsfMsgHdr_t *pMsg);
|
||||
typedef void (*medsBtnCback_t)(dmConnId_t connId, uint8_t btn);
|
||||
|
||||
/*! profile interface structure */
|
||||
typedef struct
|
||||
{
|
||||
medsInitCback_t init;
|
||||
medsStartCback_t start;
|
||||
medsProcMsgCback_t procMsg;
|
||||
medsBtnCback_t btn;
|
||||
} medsIf_t;
|
||||
|
||||
/*! application control block */
|
||||
typedef struct
|
||||
{
|
||||
medsIf_t *pIf; /*! Profile interface */
|
||||
wsfHandlerId_t handlerId; /*! WSF hander ID */
|
||||
} medsCb_t;
|
||||
|
||||
/**************************************************************************************************
|
||||
Global Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! application control block */
|
||||
extern medsCb_t medsCb;
|
||||
|
||||
/*! profile interface pointers */
|
||||
extern medsIf_t medsBlpIf; /* blood pressure profile */
|
||||
extern medsIf_t medsWspIf; /* weight scale profile */
|
||||
extern medsIf_t medsHtpIf; /* health thermometer profile */
|
||||
extern medsIf_t medsPlxIf; /* pulse oximeter profile */
|
||||
extern medsIf_t medsGlpIf; /* glucose profile */
|
||||
|
||||
/**************************************************************************************************
|
||||
Function Declarations
|
||||
**************************************************************************************************/
|
||||
|
||||
void medsCccCback(attsCccEvt_t *pEvt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* MEDS_MAIN_H */
|
||||
|
||||
Vendored
+263
@@ -0,0 +1,263 @@
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \file
|
||||
*
|
||||
* \brief Medical sensor sample, pulse oximeter profile
|
||||
*
|
||||
* Copyright (c) 2016-2019 Arm Ltd.
|
||||
*
|
||||
* Copyright (c) 2019 Packetcraft, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include "wsf_types.h"
|
||||
#include "util/bstream.h"
|
||||
#include "wsf_msg.h"
|
||||
#include "wsf_trace.h"
|
||||
#include "hci_api.h"
|
||||
#include "dm_api.h"
|
||||
#include "att_api.h"
|
||||
#include "app_api.h"
|
||||
#include "app_ui.h"
|
||||
#include "app_hw.h"
|
||||
#include "svc_ch.h"
|
||||
#include "svc_plxs.h"
|
||||
#include "svc_dis.h"
|
||||
#include "svc_core.h"
|
||||
#include "gatt/gatt_api.h"
|
||||
#include "plxps/plxps_api.h"
|
||||
#include "plxps/plxps_main.h"
|
||||
#include "meds/meds_main.h"
|
||||
|
||||
/**************************************************************************************************
|
||||
Macros
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! enumeration of client characteristic configuration descriptors */
|
||||
enum
|
||||
{
|
||||
MEDS_PLX_GATT_SC_CCC_IDX, /*! GATT service, service changed characteristic */
|
||||
MEDS_PLX_PLX_SCM_CCC_IDX, /*! Pulse Oximeter Spot Check measurement characteristic */
|
||||
MEDS_PLX_PLX_CM_CCC_IDX, /*! Pulse Oximeter Continuous characteristic */
|
||||
MEDS_PLX_PLX_RACP_CCC_IDX, /*! Pulse Oximeter record access control point characteristic */
|
||||
MEDS_PLX_NUM_CCC_IDX
|
||||
};
|
||||
|
||||
/* Default MTU */
|
||||
#define MEDS_PLX_DEFAULT_MTU 50
|
||||
|
||||
/**************************************************************************************************
|
||||
Configurable Parameters
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! Pulse Oximeter Continuous measurement configuration */
|
||||
static const plxpsCfg_t medsPlxpsCfg =
|
||||
{
|
||||
2000 /*! Measurement timer expiration period in ms */
|
||||
};
|
||||
|
||||
/*! ATT configurable parameters (increase MTU) */
|
||||
static const attCfg_t medsPlxAttCfg =
|
||||
{
|
||||
15, /* ATT server service discovery connection idle timeout in seconds */
|
||||
MEDS_PLX_DEFAULT_MTU, /* desired ATT MTU */
|
||||
ATT_MAX_TRANS_TIMEOUT, /* transcation timeout in seconds */
|
||||
4 /* number of queued prepare writes supported by server */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Advertising Data
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! Service UUID list */
|
||||
static const uint8_t medsSvcUuidList[] =
|
||||
{
|
||||
UINT16_TO_BYTES(ATT_UUID_PULSE_OXIMITER_SERVICE),
|
||||
UINT16_TO_BYTES(ATT_UUID_DEVICE_INFO_SERVICE)
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Client Characteristic Configuration Descriptors
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! client characteristic configuration descriptors settings, indexed by above enumeration */
|
||||
static const attsCccSet_t medsPlxCccSet[MEDS_PLX_NUM_CCC_IDX] =
|
||||
{
|
||||
/* cccd handle value range security level */
|
||||
{GATT_SC_CH_CCC_HDL, ATT_CLIENT_CFG_INDICATE, DM_SEC_LEVEL_NONE}, /* MEDS_PLX_GATT_SC_CCC_IDX */
|
||||
{PLXS_SPOT_CHECK_CH_CCC_HDL, ATT_CLIENT_CFG_INDICATE, DM_SEC_LEVEL_NONE}, /* MEDS_PLX_PLX_SCM_CCC_IDX */
|
||||
{PLXS_CONTINUOUS_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* MEDS_PLX_PLX_CM_CCC_IDX */
|
||||
{PLXS_RECORD_ACCESS_CH_CCC_HDL, ATT_CLIENT_CFG_INDICATE, DM_SEC_LEVEL_NONE} /* MEDS_PLX_PLX_RACP_CCC_IDX */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Local Functions
|
||||
**************************************************************************************************/
|
||||
|
||||
static void medsPlxInit(void);
|
||||
static void medsPlxStart(void);
|
||||
static void medsPlxProcMsg(wsfMsgHdr_t *pMsg);
|
||||
static void medsPlxBtn(dmConnId_t connId, uint8_t btn);
|
||||
|
||||
/**************************************************************************************************
|
||||
Global Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! profile interface pointer */
|
||||
medsIf_t medsPlxIf =
|
||||
{
|
||||
medsPlxInit,
|
||||
medsPlxStart,
|
||||
medsPlxProcMsg,
|
||||
medsPlxBtn
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Local Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! application control block */
|
||||
static struct
|
||||
{
|
||||
bool_t measuring;
|
||||
} medsPlxCb;
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Perform actions on connection close.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsPlxClose(wsfMsgHdr_t *pMsg)
|
||||
{
|
||||
/* Reset control information */
|
||||
medsPlxCb.measuring = FALSE;
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsPlxStart(void)
|
||||
{
|
||||
/* set up CCCD table and callback */
|
||||
AttsCccRegister(MEDS_PLX_NUM_CCC_IDX, (attsCccSet_t *) medsPlxCccSet, medsCccCback);
|
||||
|
||||
/* add pulse oximeter service */
|
||||
SvcPlxsAddGroup();
|
||||
SvcPlxsCbackRegister(NULL, PlxpsWriteCback);
|
||||
|
||||
/* Set Service Changed CCCD index. */
|
||||
GattSetSvcChangedIdx(MEDS_PLX_GATT_SC_CCC_IDX);
|
||||
|
||||
/* initialize pulse oximeter profile sensor */
|
||||
PlxpsInit(medsCb.handlerId, (plxpsCfg_t *) &medsPlxpsCfg);
|
||||
PlxpsSetCccIdx(MEDS_PLX_PLX_SCM_CCC_IDX, MEDS_PLX_PLX_CM_CCC_IDX, MEDS_PLX_PLX_RACP_CCC_IDX);
|
||||
|
||||
/* TODO: Define pulse oximeter features */
|
||||
PlxpsSetFeature(CH_PLF_FLAG_SENSOR_STATUS_SUP, 0, 0);
|
||||
|
||||
/* set advertising data */
|
||||
AppAdvSetAdValue(APP_ADV_DATA_DISCOVERABLE, DM_ADV_TYPE_16_UUID, sizeof(medsSvcUuidList),
|
||||
(uint8_t *) medsSvcUuidList);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Process messages from the event handler.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsPlxProcMsg(wsfMsgHdr_t *pMsg)
|
||||
{
|
||||
if (pMsg->event == DM_CONN_CLOSE_IND)
|
||||
{
|
||||
medsPlxClose(pMsg);
|
||||
}
|
||||
|
||||
PlxpsProcMsg(pMsg);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Profile initialization function.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsPlxInit(void)
|
||||
{
|
||||
/* Set configuration pointers */
|
||||
pAttCfg = (attCfg_t *) &medsPlxAttCfg;
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Button press callback.
|
||||
*
|
||||
* \param connId Connection identifier.
|
||||
* \param btn Button press.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsPlxBtn(dmConnId_t connId, uint8_t btn)
|
||||
{
|
||||
appPlxCm_t record;
|
||||
|
||||
/* button actions when connected */
|
||||
if (connId != DM_CONN_ID_NONE)
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
case APP_UI_BTN_2_SHORT:
|
||||
AppHwPlxcmRead(&record);
|
||||
record.flags = CH_PLXC_FLAG_PULSE_AMP_INDX;
|
||||
plxpsSendContinuousMeas(connId, &record);
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_2_MED:
|
||||
plxpsDbDeleteRecords(CH_RACP_OPERATOR_ALL);
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_1_SHORT:
|
||||
/* start or complete measurement */
|
||||
if (!medsPlxCb.measuring)
|
||||
{
|
||||
PlxpsMeasStart(connId, MEDS_TIMER_IND, MEDS_PLX_PLX_CM_CCC_IDX);
|
||||
medsPlxCb.measuring = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
PlxpsMeasStop();
|
||||
medsPlxCb.measuring = FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+165
@@ -0,0 +1,165 @@
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \file
|
||||
*
|
||||
* \brief Medical sensor sample, weight scale profile
|
||||
*
|
||||
* Copyright (c) 2012-2019 Arm Ltd.
|
||||
*
|
||||
* Copyright (c) 2019 Packetcraft, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include "wsf_types.h"
|
||||
#include "util/bstream.h"
|
||||
#include "wsf_msg.h"
|
||||
#include "wsf_trace.h"
|
||||
#include "hci_api.h"
|
||||
#include "dm_api.h"
|
||||
#include "att_api.h"
|
||||
#include "app_api.h"
|
||||
#include "app_ui.h"
|
||||
#include "svc_ch.h"
|
||||
#include "svc_wss.h"
|
||||
#include "svc_dis.h"
|
||||
#include "svc_core.h"
|
||||
#include "gatt/gatt_api.h"
|
||||
#include "wsps/wsps_api.h"
|
||||
#include "meds/meds_main.h"
|
||||
|
||||
/**************************************************************************************************
|
||||
Macros
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! enumeration of client characteristic configuration descriptors */
|
||||
enum
|
||||
{
|
||||
MEDS_WSP_GATT_SC_CCC_IDX, /*! GATT service, service changed characteristic */
|
||||
MEDS_WSP_WSS_WSM_CCC_IDX, /*! Weight scale service, weight scale measurement characteristic */
|
||||
MEDS_WSP_NUM_CCC_IDX
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Advertising Data
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! Service UUID list */
|
||||
static const uint8_t medsSvcUuidList[] =
|
||||
{
|
||||
UINT16_TO_BYTES(ATT_UUID_WEIGHT_SCALE_SERVICE),
|
||||
UINT16_TO_BYTES(ATT_UUID_DEVICE_INFO_SERVICE)
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Client Characteristic Configuration Descriptors
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! client characteristic configuration descriptors settings, indexed by above enumeration */
|
||||
static const attsCccSet_t medsWspCccSet[MEDS_WSP_NUM_CCC_IDX] =
|
||||
{
|
||||
/* cccd handle value range security level */
|
||||
{GATT_SC_CH_CCC_HDL, ATT_CLIENT_CFG_INDICATE, DM_SEC_LEVEL_ENC}, /* MEDS_WSP_GATT_SC_CCC_IDX */
|
||||
{WSS_WM_CH_CCC_HDL, ATT_CLIENT_CFG_INDICATE, DM_SEC_LEVEL_ENC} /* MEDS_WSP_WSS_WSM_CCC_IDX */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Local Functions
|
||||
**************************************************************************************************/
|
||||
|
||||
static void medsWspStart(void);
|
||||
static void medsWspProcMsg(wsfMsgHdr_t *pMsg);
|
||||
static void medsWspBtn(dmConnId_t connId, uint8_t btn);
|
||||
|
||||
/**************************************************************************************************
|
||||
Global Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! profile interface pointer */
|
||||
medsIf_t medsWspIf =
|
||||
{
|
||||
NULL,
|
||||
medsWspStart,
|
||||
medsWspProcMsg,
|
||||
medsWspBtn
|
||||
};
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsWspStart(void)
|
||||
{
|
||||
/* set up CCCD table and callback */
|
||||
AttsCccRegister(MEDS_WSP_NUM_CCC_IDX, (attsCccSet_t *) medsWspCccSet, medsCccCback);
|
||||
|
||||
/* add weight scale service */
|
||||
SvcWssAddGroup();
|
||||
|
||||
/* Set Service Changed CCCD index. */
|
||||
GattSetSvcChangedIdx(MEDS_WSP_GATT_SC_CCC_IDX);
|
||||
|
||||
/* initialize weight scale profile sensor */
|
||||
WspsSetWsmFlags(CH_WSM_FLAG_UNITS_LBS | CH_WSM_FLAG_TIMESTAMP);
|
||||
|
||||
/* set advertising data */
|
||||
AppAdvSetAdValue(APP_ADV_DATA_DISCOVERABLE, DM_ADV_TYPE_16_UUID, sizeof(medsSvcUuidList),
|
||||
(uint8_t *) medsSvcUuidList);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Process messages from the event handler.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsWspProcMsg(wsfMsgHdr_t *pMsg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \brief Button press callback.
|
||||
*
|
||||
* \param connId Connection identifier.
|
||||
* \param btn Button press.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void medsWspBtn(dmConnId_t connId, uint8_t btn)
|
||||
{
|
||||
/* button actions when connected */
|
||||
if (connId != DM_CONN_ID_NONE)
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
case APP_UI_BTN_1_SHORT:
|
||||
/* send measurement */
|
||||
WspsMeasComplete(connId, MEDS_WSP_WSS_WSM_CCC_IDX);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user