From d4f2fc0d259c4992d081b82c591553ec5a2bc599 Mon Sep 17 00:00:00 2001 From: Hoan Hoang Date: Fri, 20 Jan 2017 10:07:54 -0500 Subject: [PATCH 1/2] Add reset function --- include/serialintrf.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/serialintrf.h b/include/serialintrf.h index 0d3116af..7f80cc42 100755 --- a/include/serialintrf.h +++ b/include/serialintrf.h @@ -245,6 +245,18 @@ struct _serialintrf_dev { * @return None */ void (*StopTx)(SERINTRFDEV *pSerDev); + + /** + * @brief - Reset + * This function perform a reset of interface. Must provide empty + * function of not used. + * + * @param + * pSerDev : Pointer to an instance of the Serial Interface + * + * @return None + */ + void (*Reset)(SERINTRFDEV *pSerDev); }; #pragma pack(pop) @@ -304,6 +316,10 @@ static inline void SerialIntrfStopTx(SERINTRFDEV *pDev) { pDev->StopTx(pDev); } +static inline void SerialIntrfReset(SERINTRFDEV *pDev) { + if (pDev->Reset) + pDev->Reset(pDev); +} #ifdef __cplusplus /* @@ -346,7 +362,10 @@ class SerialIntrf { virtual int TxData(uint8_t *pData, int DataLen) = 0; // Stop transmit virtual void StopTx(void) = 0; + // + virtual void Reset(void) { SerialIntrfReset(*this); } }; + #endif #endif // __SERIALINTRF_H__ From 586a9a7a4108b85b4d485641f0022606172785be Mon Sep 17 00:00:00 2001 From: Nguyen Hoan Hoang Date: Sun, 22 Jan 2017 23:08:12 -0500 Subject: [PATCH 2/2] more device info modif run sequence --- ARM/Nordic/include/ble_periph_app.h | 16 ++++-- .../nRF52/exemples/LmxBlue/src/main.cpp | 12 +++++ ARM/Nordic/src/ble_periph_app.cpp | 50 ++++++++++++++----- 3 files changed, 61 insertions(+), 17 deletions(-) diff --git a/ARM/Nordic/include/ble_periph_app.h b/ARM/Nordic/include/ble_periph_app.h index ddd0e1d1..f131b7ec 100644 --- a/ARM/Nordic/include/ble_periph_app.h +++ b/ARM/Nordic/include/ble_periph_app.h @@ -58,7 +58,7 @@ typedef enum { #define BLEAPP_SECEXCHG_OOB (1<<2) #define BLEAPP_DEVNAME_MAX_SIZE 10 -#define BLEAPP_NAME_MAX_SIZE 20 +#define BLEAPP_INFOSTR_MAX_SIZE 20 typedef void (*PRIVINITCB)(); @@ -66,10 +66,14 @@ typedef void (*PRIVINITCB)(); typedef struct _BleAppConfig { BLEAPP_MODE AppMode; - const char DevName[BLEAPP_DEVNAME_MAX_SIZE]; - const char ModelName[BLEAPP_NAME_MAX_SIZE]; - const char ManName[BLEAPP_NAME_MAX_SIZE]; - uint16_t CompanyID; // Bluetooth company id + const char *pDevName; // Device name + const char *pModelName; // Model name + const char *pManufName; // Manufacturer name + const char *pSerialNoStr; // Serial number string + const char *pFwVerStr; // Firmware version string + const char *pHwVerStr; // Hardware version string + uint16_t VendorID; // PnP Bluetooth/USB vendor id + uint16_t ProductId; // PnP Product ID const uint8_t *pManData; // Manufacture specific data to advertise int ManDataLen; // Length of manufacture specific data BLEAPP_SECTYPE SecType; // Secure connection type @@ -94,6 +98,7 @@ extern "C" { // *** // Require implementations per app // +void BlePeriphAppInitUserData(); void BlePeriphAppInitServices(); void BlePeriphAppSrvcEvtDispatch(ble_evt_t * p_ble_evt); @@ -103,6 +108,7 @@ void BlePeriphAppSrvcEvtDispatch(ble_evt_t * p_ble_evt); bool BlePeriphAppInit(const BLEAPP_CFG *pBleAppCfg, bool bEraseBond); void BlePeriphAppProcessEvt(); void BlePeriphAppEnterDfu(); +void BlePeriphAppStart(); #ifdef __cplusplus } diff --git a/ARM/Nordic/nRF52/exemples/LmxBlue/src/main.cpp b/ARM/Nordic/nRF52/exemples/LmxBlue/src/main.cpp index 3f46396b..8c5abc50 100644 --- a/ARM/Nordic/nRF52/exemples/LmxBlue/src/main.cpp +++ b/ARM/Nordic/nRF52/exemples/LmxBlue/src/main.cpp @@ -81,7 +81,11 @@ const BLEAPP_CFG s_BleAppCfg = { "LMXBLUE", "IBB-LMXBLUE", "I-SYST inc.", + "", + "0.0", + "0.0", ISYST_BLUETOOTH_ID, + 1, g_ManData, sizeof(g_ManData), BLEAPP_SECTYPE_NONE, @@ -90,6 +94,7 @@ const BLEAPP_CFG s_BleAppCfg = { 0,//sizeof(s_AdvUuids) / sizeof(ble_uuid_t), APP_ADV_INTERVAL, APP_ADV_TIMEOUT_IN_SECONDS, + 0, BLUEIO_CONNECT_LED_PORT, BLUEIO_CONNECT_LED_PIN, NULL @@ -165,6 +170,11 @@ void HardwareInit() //LedMxPrintLeft(&g_LmxDev, "IBB-LMXBLUE Blutooth LED matrix demo"); } +void BlePeriphAppInitUserData() +{ + +} + // // Print a greeting message on standard output and exit. // @@ -184,6 +194,8 @@ int main() BlePeriphAppInit(&s_BleAppCfg, true); + BlePeriphAppStart(); + while(1) { BlePeriphAppProcessEvt(); diff --git a/ARM/Nordic/src/ble_periph_app.cpp b/ARM/Nordic/src/ble_periph_app.cpp index afc396dc..1af92aad 100644 --- a/ARM/Nordic/src/ble_periph_app.cpp +++ b/ARM/Nordic/src/ble_periph_app.cpp @@ -201,8 +201,8 @@ static void gap_params_init(const BLEAPP_CFG *pBleAppCfg) } err_code = sd_ble_gap_device_name_set(&sec_mode, - (const uint8_t *) pBleAppCfg->DevName, - strlen(pBleAppCfg->DevName)); + (const uint8_t *) pBleAppCfg->pDevName, + strlen(pBleAppCfg->pDevName)); APP_ERROR_CHECK(err_code); memset(&gap_conn_params, 0, sizeof(gap_conn_params)); @@ -686,7 +686,7 @@ void BlePeriphAppAdvInit(const BLEAPP_CFG *pCfg) ble_adv_modes_config_t options; ble_advdata_manuf_data_t mdata; - mdata.company_identifier = pCfg->CompanyID; + mdata.company_identifier = pCfg->VendorID; mdata.data.p_data = (uint8_t*)pCfg->pManData; mdata.data.size = pCfg->ManDataLen; @@ -707,7 +707,7 @@ void BlePeriphAppAdvInit(const BLEAPP_CFG *pCfg) options.ble_adv_fast_interval = pCfg->AdvInterval; options.ble_adv_fast_timeout = pCfg->AdvTimeout; - if (pCfg->AdvSlowInterval > 0) + // if (pCfg->AdvSlowInterval > 0) { options.ble_adv_slow_enabled = true; options.ble_adv_slow_interval = pCfg->AdvSlowInterval; @@ -784,20 +784,43 @@ bool BlePeriphAppInit(const BLEAPP_CFG *pBleAppCfg, bool bEraseBond) gap_params_init(pBleAppCfg); + BlePeriphAppInitUserData(); + BlePeriphAppInitServices(); ble_dis_init_t dis_init; - ble_dis_sys_id_t sys_id; + ble_dis_pnp_id_t pnp_id; // Initialize Device Information Service. memset(&dis_init, 0, sizeof(dis_init)); - ble_srv_ascii_to_utf8(&dis_init.manufact_name_str, (char*)pBleAppCfg->ManName); - ble_srv_ascii_to_utf8(&dis_init.model_num_str, (char*)pBleAppCfg->ModelName); + if (pBleAppCfg->pManufName) + { + ble_srv_ascii_to_utf8(&dis_init.manufact_name_str, (char*)pBleAppCfg->pManufName); + } + + if (pBleAppCfg->pModelName) + { + ble_srv_ascii_to_utf8(&dis_init.model_num_str, (char*)pBleAppCfg->pModelName); + } - sys_id.manufacturer_id = pBleAppCfg->CompanyID; - sys_id.organizationally_unique_id = pBleAppCfg->CompanyID; - dis_init.p_sys_id = &sys_id; + if (pBleAppCfg->pSerialNoStr) + { + ble_srv_ascii_to_utf8(&dis_init.serial_num_str, (char*)pBleAppCfg->pSerialNoStr); + } + + if (pBleAppCfg->pFwVerStr) + { + ble_srv_ascii_to_utf8(&dis_init.fw_rev_str, (char*)pBleAppCfg->pFwVerStr); + } + + if (pBleAppCfg->pHwVerStr) + { + ble_srv_ascii_to_utf8(&dis_init.hw_rev_str, (char*)pBleAppCfg->pHwVerStr); + } + + pnp_id.vendor_id = pBleAppCfg->VendorID; + dis_init.p_pnp_id = &pnp_id; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&dis_init.dis_attr_md.read_perm); BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&dis_init.dis_attr_md.write_perm); @@ -812,12 +835,15 @@ bool BlePeriphAppInit(const BLEAPP_CFG *pBleAppCfg, bool bEraseBond) return true; } -void BlePeriphAppProcessEvt() +void BlePeriphAppStart() { - uint32_t err_code = ble_advertising_start(BLE_ADV_MODE_FAST); + uint32_t err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); +} +void BlePeriphAppProcessEvt() +{ if (g_BleAppData.AppMode == BLEAPP_MODE_RTOS) { intern_softdevice_events_execute();