Skip to content

Commit

Permalink
Merge pull request #5 from I-SYST/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
hnhoan authored Jan 23, 2017
2 parents 6d4c473 + 586a9a7 commit b753f27
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 17 deletions.
16 changes: 11 additions & 5 deletions ARM/Nordic/include/ble_periph_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,22 @@ 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)();

#pragma pack(push, 4)

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
Expand All @@ -94,6 +98,7 @@ extern "C" {
// ***
// Require implementations per app
//
void BlePeriphAppInitUserData();
void BlePeriphAppInitServices();
void BlePeriphAppSrvcEvtDispatch(ble_evt_t * p_ble_evt);

Expand All @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions ARM/Nordic/nRF52/exemples/LmxBlue/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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.
//
Expand All @@ -184,6 +194,8 @@ int main()

BlePeriphAppInit(&s_BleAppCfg, true);

BlePeriphAppStart();

while(1)
{
BlePeriphAppProcessEvt();
Expand Down
50 changes: 38 additions & 12 deletions ARM/Nordic/src/ble_periph_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down
19 changes: 19 additions & 0 deletions include/serialintrf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
/*
Expand Down Expand Up @@ -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__

0 comments on commit b753f27

Please sign in to comment.