├── Blinker ├── BlinkerApi.c ├── BlinkerApi.h ├── BlinkerBLE.c ├── BlinkerBLE.h ├── BlinkerConfig.h ├── BlinkerDebug.c ├── BlinkerDebug.h ├── BlinkerUtility.c ├── BlinkerUtility.h ├── ble_bts.c └── ble_bts.h ├── README.md ├── examples └── blinker_ble │ ├── app_bsp.c │ ├── ble_app_blinker_ble.eww │ ├── hex │ ├── ble_app_blinker_ble_pca10040_s132.hex │ ├── ble_app_blinker_ble_pca10040e_s112.hex │ ├── ble_app_blinker_ble_pca10056_s140.hex │ ├── ble_app_blinker_ble_pca10056e_s112.hex │ ├── ble_app_gatts_c_pca10040_s132.hex │ ├── ble_app_gatts_c_pca10040e_s112.hex │ ├── ble_app_gatts_c_pca10056_s140.hex │ ├── ble_app_gatts_c_pca10056e_s112.hex │ └── license.txt │ ├── main.c │ └── pca10040 │ └── s132 │ ├── arm4 │ ├── ble_app_blinker_ble_pca10040_s132.uvopt │ └── ble_app_blinker_ble_pca10040_s132.uvproj │ ├── arm5_no_packs │ ├── ble_app_blinker_ble_pca10040_s132.uvoptx │ └── ble_app_blinker_ble_pca10040_s132.uvprojx │ ├── armgcc │ ├── Makefile │ └── ble_app_blinker_ble_gcc_nrf52.ld │ ├── config │ └── sdk_config.h │ ├── iar │ ├── ble_app_blinker_ble_iar_nRF5x.icf │ ├── ble_app_blinker_ble_pca10040_s132.ewd │ └── ble_app_blinker_ble_pca10040_s132.ewp │ └── ses │ ├── ble_app_blinker_ble_pca10040_s132.emProject │ ├── ble_app_blinker_ble_pca10040_s132.emSession │ ├── ble_app_blinker_ble_pca10040_s132_Release.jlink │ └── flash_placement.xml └── version.json /Blinker/BlinkerApi.c: -------------------------------------------------------------------------------- 1 | #include "BlinkerApi.h" 2 | 3 | 4 | static blinker_widgets_str_t _Widgets_str[BLINKER_MAX_WIDGET_SIZE]; 5 | static blinker_widgets_rgb_t _Widgets_rgb[BLINKER_MAX_WIDGET_SIZE/2]; 6 | static blinker_widgets_int_t _Widgets_int[BLINKER_MAX_WIDGET_SIZE]; 7 | static blinker_widgets_tab_t _Widgets_tab[BLINKER_MAX_WIDGET_SIZE]; 8 | static uint8_t _wCount_str = 0; 9 | static uint8_t _wCount_rgb = 0; 10 | static uint8_t _wCount_int = 0; 11 | static uint8_t _wCount_tab = 0; 12 | 13 | static blinker_callback_with_json_arg_t blinker_data_func = NULL; 14 | 15 | static bool blinker_parsed = false; 16 | static bool blinker_auto_format = false; 17 | static uint32_t blinker_auto_format_time = 0; 18 | static char blinker_send_buf[BLINKER_MAX_SEND_SIZE] = { 0 }; 19 | static int raw_data[4] = {0,0,0,0}; 20 | static uint8_t raw_len = 0; 21 | 22 | int8_t check_string_num(const char *name, const blinker_widgets_str_t *c, uint8_t count) 23 | { 24 | for (uint8_t cNum = 0; cNum < count; cNum++) 25 | { 26 | if (strcmp(c[cNum].name, name) == 0) 27 | { 28 | // // BLINKER_LOG_ALL("check_string_num, name: %s, num: %d", name, cNum); 29 | return cNum; 30 | } 31 | } 32 | 33 | return BLINKER_OBJECT_NOT_AVAIL; 34 | } 35 | 36 | int8_t check_rgb_num(const char *name, const blinker_widgets_rgb_t *c, uint8_t count) 37 | { 38 | for (uint8_t cNum = 0; cNum < count; cNum++) 39 | { 40 | if (strcmp(c[cNum].name, name) == 0) 41 | { 42 | // // BLINKER_LOG_ALL("check_rgb_num, name: %s, num: %d", name, cNum); 43 | return cNum; 44 | } 45 | } 46 | 47 | return BLINKER_OBJECT_NOT_AVAIL; 48 | } 49 | 50 | int8_t check_int_num(const char *name, const blinker_widgets_int_t *c, uint8_t count) 51 | { 52 | for (uint8_t cNum = 0; cNum < count; cNum++) 53 | { 54 | if (strcmp(c[cNum].name, name) == 0) 55 | { 56 | // // BLINKER_LOG_ALL("check_rgb_num, name: %s, num: %d", name, cNum); 57 | return cNum; 58 | } 59 | } 60 | 61 | return BLINKER_OBJECT_NOT_AVAIL; 62 | } 63 | 64 | int8_t check_tab_num(const char *name, const blinker_widgets_tab_t *c, uint8_t count) 65 | { 66 | for (uint8_t cNum = 0; cNum < count; cNum++) 67 | { 68 | if (strcmp(c[cNum].name, name) == 0) 69 | { 70 | // // BLINKER_LOG_ALL("check_rgb_num, name: %s, num: %d", name, cNum); 71 | return cNum; 72 | } 73 | } 74 | 75 | return BLINKER_OBJECT_NOT_AVAIL; 76 | } 77 | 78 | uint8_t attach_widget_string(const char *_name, blinker_callback_with_string_arg_t _func) 79 | { 80 | int8_t num = check_string_num(_name, _Widgets_str, _wCount_str); 81 | 82 | if (num == BLINKER_OBJECT_NOT_AVAIL) 83 | { 84 | if (_wCount_str < BLINKER_MAX_WIDGET_SIZE*2) 85 | { 86 | _Widgets_str[_wCount_str].name = _name; 87 | _Widgets_str[_wCount_str].wfunc = _func; 88 | _wCount_str++; 89 | 90 | // BLINKER_LOG_ALL("new widgets: %s, _wCount_str: %d", _name, _wCount_str); 91 | return _wCount_str; 92 | } 93 | else 94 | { 95 | return 0; 96 | } 97 | } 98 | else if(num >= 0 ) 99 | { 100 | // BLINKER_ERR_LOG("widgets name > %s < has been registered, please register another name!", _name); 101 | return 0; 102 | } 103 | else 104 | { 105 | return 0; 106 | } 107 | } 108 | 109 | uint8_t attach_widget_rgb(const char *_name, blinker_callback_with_rgb_arg_t _func) 110 | { 111 | int8_t num = check_rgb_num(_name, _Widgets_rgb, _wCount_rgb); 112 | 113 | if (num == BLINKER_OBJECT_NOT_AVAIL) 114 | { 115 | if (_wCount_rgb < BLINKER_MAX_WIDGET_SIZE*2) 116 | { 117 | _Widgets_rgb[_wCount_rgb].name = _name; 118 | _Widgets_rgb[_wCount_rgb].wfunc = _func; 119 | _wCount_rgb++; 120 | 121 | // BLINKER_LOG_ALL("new widgets: %s, _wCount_rgb: %d", _name, _wCount_rgb); 122 | return _wCount_rgb; 123 | } 124 | else 125 | { 126 | return 0; 127 | } 128 | } 129 | else if(num >= 0 ) 130 | { 131 | // BLINKER_ERR_LOG("widgets name > %s < has been registered, please register another name!", _name); 132 | return 0; 133 | } 134 | else 135 | { 136 | return 0; 137 | } 138 | } 139 | 140 | uint8_t attach_widget_int(const char *_name, blinker_callback_with_int32_arg_t _func) 141 | { 142 | int8_t num = check_int_num(_name, _Widgets_int, _wCount_int); 143 | 144 | if (num == BLINKER_OBJECT_NOT_AVAIL) 145 | { 146 | if (_wCount_int < BLINKER_MAX_WIDGET_SIZE*2) 147 | { 148 | _Widgets_int[_wCount_int].name = _name; 149 | _Widgets_int[_wCount_int].wfunc = _func; 150 | _wCount_int++; 151 | 152 | // BLINKER_LOG_ALL("new widgets: %s, _wCount_int: %d", _name, _wCount_int); 153 | return _wCount_int; 154 | } 155 | else 156 | { 157 | return 0; 158 | } 159 | } 160 | else if(num >= 0 ) 161 | { 162 | // BLINKER_ERR_LOG("widgets name > %s < has been registered, please register another name!", _name); 163 | return 0; 164 | } 165 | else 166 | { 167 | return 0; 168 | } 169 | } 170 | 171 | uint8_t attach_widget_tab(const char *_name, blinker_callback_with_tab_arg_t _func, blinker_callback_t _func1) 172 | { 173 | int8_t num = check_tab_num(_name, _Widgets_tab, _wCount_tab); 174 | 175 | if (num == BLINKER_OBJECT_NOT_AVAIL) 176 | { 177 | if (_wCount_tab < BLINKER_MAX_WIDGET_SIZE*2) 178 | { 179 | _Widgets_tab[_wCount_tab].name = _name; 180 | _Widgets_tab[_wCount_tab].wfunc = _func; 181 | _Widgets_tab[_wCount_tab].wfunc1 = _func1; 182 | _wCount_tab++; 183 | 184 | // BLINKER_LOG_ALL("new widgets: %s, _wCount_tab: %d", _name, _wCount_tab); 185 | return _wCount_tab; 186 | } 187 | else 188 | { 189 | return 0; 190 | } 191 | } 192 | else if(num >= 0 ) 193 | { 194 | // BLINKER_ERR_LOG("widgets name > %s < has been registered, please register another name!", _name); 195 | return 0; 196 | } 197 | else 198 | { 199 | return 0; 200 | } 201 | } 202 | 203 | void blinker_button_print(const BlinkerButton *button, const blinker_button_config_t * config) 204 | { 205 | cJSON *pValue = cJSON_CreateObject(); 206 | // cJSON_AddStringToObject(pValue,"mac","xuhongv"); 207 | 208 | if (config->state) cJSON_AddStringToObject(pValue, BLINKER_CMD_STATE, config->state); 209 | if (config->icon) cJSON_AddStringToObject(pValue, BLINKER_CMD_ICON, config->icon); 210 | if (config->color) cJSON_AddStringToObject(pValue, BLINKER_CMD_COLOR, config->color); 211 | if (config->color) cJSON_AddStringToObject(pValue, BLINKER_CMD_COLOR_, config->color); 212 | if (config->content) cJSON_AddStringToObject(pValue, BLINKER_CMD_CONTENT, config->content); 213 | if (config->text1) cJSON_AddStringToObject(pValue, BLINKER_CMD_TEXT, config->text1); 214 | if (config->text2) cJSON_AddStringToObject(pValue, BLINKER_CMD_TEXT1, config->text2); 215 | if (config->textColor) cJSON_AddStringToObject(pValue, BLINKER_CMD_TEXTCOLOR, config->textColor); 216 | 217 | char *_data; 218 | _data = cJSON_PrintUnformatted(pValue); 219 | cJSON_Delete(pValue); 220 | 221 | blinker_print(button->name, _data, 0); 222 | 223 | free(_data); 224 | // BLINKER_LOG_ALL("blinker_button_print"); 225 | } 226 | 227 | void blinker_number_print(const BlinkerNumber *number, const blinker_number_config_t * config) 228 | { 229 | cJSON *pValue = cJSON_CreateObject(); 230 | 231 | if (config->icon) cJSON_AddStringToObject(pValue, BLINKER_CMD_ICON, config->icon); 232 | if (config->color) cJSON_AddStringToObject(pValue, BLINKER_CMD_COLOR, config->color); 233 | if (config->color) cJSON_AddStringToObject(pValue, BLINKER_CMD_COLOR_, config->color); 234 | if (config->unit) cJSON_AddStringToObject(pValue, BLINKER_CMD_UNIT, config->unit); 235 | if (config->text) cJSON_AddStringToObject(pValue, BLINKER_CMD_TEXT, config->text); 236 | // cJSON *value = cJSON_CreateNumber(config->value); 237 | // cJSON_AddItemToObject(pValue, BLINKER_CMD_VALUE, value); 238 | if (config->value) cJSON_AddStringToObject(pValue, BLINKER_CMD_VALUE, config->value); 239 | 240 | char *_data; 241 | _data = cJSON_PrintUnformatted(pValue); 242 | cJSON_Delete(pValue); 243 | 244 | blinker_print(number->name, _data, 0); 245 | 246 | free(_data); 247 | } 248 | 249 | void blinker_rgb_print(const BlinkerRGB *rgb, const blinker_rgb_config_t * config) 250 | { 251 | // cJSON *pValue = cJSON_CreateObject(); 252 | 253 | // cJSON_AddItemToObject(pValue, BLINKER_CMD_RGB, cJSON_CreateIntArray(config->rgbw, 4)); 254 | char data[24] = {0}; 255 | 256 | sprintf(data, "[%d,%d,%d,%d]", config->rgbw[0], config->rgbw[1], config->rgbw[2], config->rgbw[3]); 257 | 258 | // cJSON *pValue = cJSON_CreateObject(); 259 | 260 | // char _data[22] = {0}; 261 | 262 | // // cJSON_AddItemToObject(pValue, BLINKER_CMD_RGB, cJSON_CreateIntArray(rrgg, 4)); 263 | 264 | // sprintf(_data, "[%d, %d, %d, %d]", config->rgbw[0], config->rgbw[1], config->rgbw[2], config->rgbw[3]); 265 | 266 | // cJSON_AddRawToObject(pValue, BLINKER_CMD_RGB, data); 267 | 268 | // // BLINKER_LOG_ALL("%s", cJSON_PrintUnformatted(pValue)); 269 | 270 | // cJSON_Delete(pValue); 271 | 272 | raw_len = 4; 273 | raw_data[0] = config->rgbw[0]; 274 | raw_data[1] = config->rgbw[1]; 275 | raw_data[2] = config->rgbw[2]; 276 | raw_data[3] = config->rgbw[3]; 277 | 278 | // BLINKER_LOG_ALL("rgb: %d, %d, %d, %d", raw_data[0], raw_data[1], raw_data[2], raw_data[3]); 279 | 280 | blinker_print(rgb->name, data, 1); 281 | 282 | // cJSON_Delete(pValue); 283 | } 284 | 285 | void blinker_slider_print(const BlinkerSlider *slider, const blinker_slider_config_t * config) 286 | { 287 | cJSON *pValue = cJSON_CreateObject(); 288 | 289 | if (config->color) cJSON_AddStringToObject(pValue, BLINKER_CMD_COLOR, config->color); 290 | if (config->color) cJSON_AddStringToObject(pValue, BLINKER_CMD_COLOR_, config->color); 291 | if (config->value) cJSON_AddStringToObject(pValue, BLINKER_CMD_VALUE, config->value); 292 | 293 | char *_data; 294 | _data = cJSON_PrintUnformatted(pValue); 295 | cJSON_Delete(pValue); 296 | 297 | blinker_print(slider->name, _data, 0); 298 | 299 | free(_data); 300 | } 301 | 302 | void blinker_switch_print(const blinker_switch_config_t * config) 303 | { 304 | // cJSON *pValue = cJSON_CreateObject(); 305 | 306 | // if (config->state) cJSON_AddStringToObject(pValue, BLINKER_CMD_BUILTIN_SWITCH, config->state); 307 | 308 | // char _data[128] = {0}; 309 | // cJSON_PrintPreallocated(pValue, _data, 128, 0); 310 | blinker_print(BLINKER_CMD_BUILTIN_SWITCH, config->state, 0); 311 | 312 | // cJSON_Delete(pValue); 313 | } 314 | 315 | void blinker_tab_print(const BlinkerTab *tab, const blinker_tab_config_t * config) 316 | { 317 | cJSON *pValue = cJSON_CreateObject(); 318 | 319 | // cJSON_AddItemToObject(pValue, BLINKER_CMD_RGB, cJSON_CreateIntArray(config->rgbw, 4)); 320 | char data[24] = {0}; 321 | 322 | sprintf(data, "%d%d%d%d%d", config->tab[0], config->tab[1], config->tab[2], config->tab[3], config->tab[4]); 323 | 324 | cJSON_AddStringToObject(pValue, BLINKER_CMD_VALUE, data); 325 | 326 | // cJSON *pValue = cJSON_CreateObject(); 327 | 328 | // char _data[22] = {0}; 329 | 330 | // // cJSON_AddItemToObject(pValue, BLINKER_CMD_RGB, cJSON_CreateIntArray(rrgg, 4)); 331 | 332 | // sprintf(_data, "[%d, %d, %d, %d]", config->rgbw[0], config->rgbw[1], config->rgbw[2], config->rgbw[3]); 333 | 334 | // cJSON_AddRawToObject(pValue, BLINKER_CMD_RGB, data); 335 | 336 | // // BLINKER_LOG_ALL("%s", cJSON_PrintUnformatted(pValue)); 337 | char *_data; 338 | _data = cJSON_PrintUnformatted(pValue); 339 | cJSON_Delete(pValue); 340 | 341 | blinker_print(tab->name, _data, 0); 342 | 343 | free(_data); 344 | 345 | // cJSON_Delete(pValue); 346 | } 347 | 348 | void blinker_text_print(const BlinkerText *text, const blinker_text_config_t * config) 349 | { 350 | cJSON *pValue = cJSON_CreateObject(); 351 | 352 | if (config->icon) cJSON_AddStringToObject(pValue, BLINKER_CMD_ICON, config->icon); 353 | if (config->color) cJSON_AddStringToObject(pValue, BLINKER_CMD_COLOR, config->color); 354 | if (config->color) cJSON_AddStringToObject(pValue, BLINKER_CMD_COLOR_, config->color); 355 | if (config->text) cJSON_AddStringToObject(pValue, BLINKER_CMD_TEXT, config->text); 356 | if (config->text1) cJSON_AddStringToObject(pValue, BLINKER_CMD_VALUE, config->text1); 357 | 358 | char *_data; 359 | _data = cJSON_PrintUnformatted(pValue); 360 | cJSON_Delete(pValue); 361 | 362 | blinker_print(text->name, _data, 0); 363 | 364 | free(_data); 365 | } 366 | 367 | void blinker_button_init(BlinkerButton *button, blinker_callback_with_string_arg_t _func) 368 | { 369 | button->wNum = attach_widget_string(button->name, _func); 370 | } 371 | 372 | void blinker_rgb_init(BlinkerRGB *rgb, blinker_callback_with_rgb_arg_t _func) 373 | { 374 | rgb->wNum = attach_widget_rgb(rgb->name, _func); 375 | } 376 | 377 | void blinker_slider_init(BlinkerSlider *slider, blinker_callback_with_int32_arg_t _func) 378 | { 379 | slider->wNum = attach_widget_int(slider->name, _func); 380 | } 381 | 382 | void blinker_switch_init(blinker_callback_with_string_arg_t _func) 383 | { 384 | attach_widget_string(BLINKER_CMD_BUILTIN_SWITCH, _func); 385 | } 386 | 387 | void blinker_tab_init(BlinkerTab *tab, blinker_callback_with_tab_arg_t _func, blinker_callback_t _func1) 388 | { 389 | tab->wNum = attach_widget_tab(tab->name, _func, _func1); 390 | } 391 | 392 | void widget_string_parse(const char *_wName, cJSON *data) 393 | { 394 | // BLINKER_LOG_ALL("_Widgets_str _wName: %s", _wName); 395 | 396 | int8_t num = check_string_num(_wName, _Widgets_str, _wCount_str); 397 | 398 | if (num == BLINKER_OBJECT_NOT_AVAIL) return; 399 | 400 | cJSON *state = cJSON_GetObjectItem(data, _wName); 401 | 402 | // // BLINKER_LOG_ALL("_Widgets_str num: %d", num); 403 | 404 | // BLINKER_LOG_ALL("_Widgets_str null: %d", state->string == NULL); 405 | 406 | if (state->type == cJSON_String) 407 | { 408 | // BLINKER_LOG_ALL("widget_string_parse isParsed"); 409 | 410 | blinker_parsed = true; 411 | 412 | // BLINKER_LOG_ALL("widget_string_parse: %s", _wName); 413 | 414 | blinker_callback_with_string_arg_t nbFunc = _Widgets_str[num].wfunc; 415 | 416 | if (nbFunc) nbFunc(state->valuestring); 417 | } 418 | 419 | // cJSON_Delete(state); 420 | } 421 | 422 | void widget_rgb_parse(const char *_wName, cJSON *data) 423 | { 424 | // BLINKER_LOG_ALL("_Widgets_rgb _wName: %s", _wName); 425 | 426 | int8_t num = check_rgb_num(_wName, _Widgets_rgb, _wCount_rgb); 427 | 428 | if (num == BLINKER_OBJECT_NOT_AVAIL) return; 429 | 430 | cJSON *state = cJSON_GetObjectItem(data, _wName); 431 | 432 | // BLINKER_LOG_ALL("_Widgets_rgb num: %d", num); 433 | 434 | if (state->type == cJSON_Array) 435 | { 436 | // BLINKER_LOG_ALL("widget_rgb_parse isParsed"); 437 | 438 | blinker_parsed = true; 439 | 440 | // BLINKER_LOG_ALL("widget_rgb_parse: %s", _wName); 441 | 442 | blinker_callback_with_rgb_arg_t nbFunc = _Widgets_rgb[num].wfunc; 443 | 444 | if (nbFunc) nbFunc(cJSON_GetArrayItem(state, 0)->valueint, cJSON_GetArrayItem(state, 1)->valueint, cJSON_GetArrayItem(state, 2)->valueint, cJSON_GetArrayItem(state, 3)->valueint); 445 | } 446 | 447 | // cJSON_Delete(state); 448 | } 449 | 450 | void widget_int_parse(const char *_wName, cJSON *data) 451 | { 452 | // BLINKER_LOG_ALL("_Widgets_int _wName: %s", _wName); 453 | 454 | int8_t num = check_int_num(_wName, _Widgets_int, _wCount_int); 455 | 456 | if (num == BLINKER_OBJECT_NOT_AVAIL) return; 457 | 458 | cJSON *state = cJSON_GetObjectItem(data, _wName); 459 | 460 | // BLINKER_LOG_ALL("_Widgets_int num: %d", num); 461 | 462 | if (state->type == cJSON_Number) 463 | { 464 | // BLINKER_LOG_ALL("widget_int_parse isParsed"); 465 | 466 | blinker_parsed = true; 467 | 468 | // BLINKER_LOG_ALL("widget_int_parse: %s", _wName); 469 | 470 | blinker_callback_with_int32_arg_t nbFunc = _Widgets_int[num].wfunc; 471 | 472 | if (nbFunc) nbFunc(state->valueint); 473 | } 474 | 475 | // cJSON_Delete(state); 476 | } 477 | 478 | void widget_tab_parse(const char *_wName, cJSON *data) 479 | { 480 | // BLINKER_LOG_ALL("_Widgets_tab _wName: %s", _wName); 481 | 482 | int8_t num = check_tab_num(_wName, _Widgets_tab, _wCount_tab); 483 | 484 | if (num == BLINKER_OBJECT_NOT_AVAIL) return; 485 | 486 | cJSON *state = cJSON_GetObjectItem(data, _wName); 487 | 488 | // BLINKER_LOG_ALL("_Widgets_tab num: %d", num); 489 | 490 | if (state->type == cJSON_String) 491 | { 492 | // BLINKER_LOG_ALL("widget_tab_parse isParsed"); 493 | 494 | blinker_parsed = true; 495 | 496 | // BLINKER_LOG_ALL("widget_tab_parse: %s", _wName); 497 | 498 | blinker_callback_with_tab_arg_t nbFunc = _Widgets_tab[num].wfunc; 499 | 500 | // if (nbFunc) nbFunc(atoi(state->valuestring)); 501 | 502 | // char tab_data[10] = {0}; 503 | 504 | // cJSON_PrintPreallocated(state, tab_data, 10, 0); 505 | 506 | char *tab_data; 507 | tab_data = cJSON_PrintUnformatted(state); 508 | // cJSON_Delete(pValue); 509 | 510 | // BLINKER_LOG_ALL("tab_data: %c", tab_data[1]); 511 | 512 | if (nbFunc) 513 | { 514 | for (uint8_t num = 0; num < 5; num++) 515 | { 516 | // BLINKER_LOG_ALL("num: %c", tab_data[num + 1]); 517 | 518 | if (tab_data[num + 1] == '1') 519 | { 520 | if (nbFunc) { 521 | switch (num) 522 | { 523 | case 0: 524 | nbFunc(BLINKER_CMD_TAB_0); 525 | break; 526 | case 1: 527 | nbFunc(BLINKER_CMD_TAB_1); 528 | break; 529 | case 2: 530 | nbFunc(BLINKER_CMD_TAB_2); 531 | break; 532 | case 3: 533 | nbFunc(BLINKER_CMD_TAB_3); 534 | break; 535 | case 4: 536 | nbFunc(BLINKER_CMD_TAB_4); 537 | break; 538 | default: 539 | break; 540 | } 541 | } 542 | } 543 | } 544 | } 545 | 546 | free(tab_data); 547 | } 548 | 549 | blinker_callback_t wFunc1 = _Widgets_tab[num].wfunc1; 550 | if (wFunc1) { 551 | wFunc1(); 552 | } 553 | 554 | // cJSON_Delete(state); 555 | } 556 | 557 | void widget_parse(cJSON *data) 558 | { 559 | // BLINKER_LOG_ALL("widget_parse"); 560 | 561 | for (uint8_t wNum = 0; wNum < _wCount_str; wNum++) { 562 | if (blinker_parsed) return; 563 | widget_string_parse(_Widgets_str[wNum].name, data); 564 | } 565 | for (uint8_t wNum = 0; wNum < _wCount_rgb; wNum++) { 566 | if (blinker_parsed) return; 567 | widget_rgb_parse(_Widgets_rgb[wNum].name, data); 568 | } 569 | for (uint8_t wNum = 0; wNum < _wCount_int; wNum++) { 570 | if (blinker_parsed) return; 571 | widget_int_parse(_Widgets_int[wNum].name, data); 572 | } 573 | for (uint8_t wNum = 0; wNum < _wCount_tab; wNum++) { 574 | if (blinker_parsed) return; 575 | widget_tab_parse(_Widgets_tab[wNum].name, data); 576 | } 577 | } 578 | 579 | void blinker_attach_data(blinker_callback_with_json_arg_t func) 580 | { 581 | blinker_data_func = func; 582 | } 583 | 584 | // void blinker_check_auto_format(void) 585 | // { 586 | // if (blinker_auto_format) 587 | // { 588 | // if ((blinker_millis() - blinker_auto_format_time) >= BLINKER_MSG_AUTOFORMAT_TIMEOUT) 589 | // { 590 | // // // BLINKER_LOG_ALL("blinker_check_auto_format"); 591 | // if (strlen(blinker_send_buf)) 592 | // { 593 | // // // BLINKER_LOG_ALL("print: %s", blinker_send_buf); 594 | // uint8_t need_check = true; 595 | // if (strstr(blinker_send_buf, BLINKER_CMD_CONNECTED)) need_check = false; 596 | // blinker_ble_print(blinker_send_buf, need_check); 597 | // } 598 | // free(blinker_send_buf); 599 | // blinker_auto_format = false; 600 | // } 601 | // } 602 | // } 603 | 604 | void blinker_check_format(void) 605 | { 606 | if (!blinker_auto_format) 607 | { 608 | blinker_auto_format = true; 609 | 610 | // blinker_send_buf = (char*)malloc(BLINKER_MAX_SEND_SIZE*sizeof(char)); 611 | memset(blinker_send_buf, '\0', BLINKER_MAX_SEND_SIZE); 612 | } 613 | } 614 | 615 | void blinker_auto_format_data(const char * key, const char * value, int8_t isRaw) 616 | { 617 | // BLINKER_LOG_ALL("auto_format_data key: %s, value: %s", key, value); 618 | 619 | if (strlen(blinker_send_buf)) 620 | { 621 | cJSON *root = cJSON_Parse(blinker_send_buf); 622 | 623 | if (root != NULL) 624 | { 625 | cJSON *check_key = cJSON_GetObjectItem(root, key); 626 | if (check_key != NULL) 627 | { 628 | cJSON_DeleteItemFromObject(root, key); 629 | } 630 | } 631 | 632 | if (isJson(value) && !isRaw) 633 | { 634 | cJSON *new_item = cJSON_Parse(value); 635 | cJSON_AddItemToObject(root, key, new_item); 636 | } 637 | else 638 | { 639 | if (isRaw) 640 | { 641 | // cJSON_AddRawToObject(root, key, value); 642 | 643 | cJSON_AddItemToObject(root, key, cJSON_CreateIntArray(raw_data, raw_len)); 644 | // BLINKER_LOG_ALL("cJSON_AddRawToObject"); 645 | } 646 | else 647 | { 648 | cJSON_AddStringToObject(root, key, value); 649 | // BLINKER_LOG_ALL("cJSON_AddStringToObject"); 650 | } 651 | } 652 | 653 | char *_data = cJSON_PrintUnformatted(root); 654 | strcpy(blinker_send_buf, _data); 655 | free(_data); 656 | cJSON_Delete(root); 657 | // BLINKER_LOG_ALL("auto_format_data2: %s", blinker_send_buf); 658 | // BLINKER_LOG_ALL("auto_format_data2 end"); 659 | } 660 | else 661 | { 662 | cJSON *root = cJSON_CreateObject(); 663 | 664 | if (isJson(value) && !isRaw) 665 | { 666 | cJSON *new_item = cJSON_Parse(value); 667 | cJSON_AddItemToObject(root, key, new_item); 668 | } 669 | else 670 | { 671 | if (isRaw) 672 | { 673 | // cJSON_AddRawToObject(root, key, value); 674 | 675 | cJSON_AddItemToObject(root, key, cJSON_CreateIntArray(raw_data, raw_len)); 676 | // BLINKER_LOG_ALL("cJSON_AddRawToObject"); 677 | } 678 | else 679 | { 680 | cJSON_AddStringToObject(root, key, value); 681 | // BLINKER_LOG_ALL("cJSON_AddStringToObject"); 682 | } 683 | } 684 | 685 | char *_data = cJSON_PrintUnformatted(root); 686 | strcpy(blinker_send_buf, _data); 687 | free(_data); 688 | cJSON_Delete(root); 689 | // BLINKER_LOG_ALL("auto_format_data3: %s", blinker_send_buf); 690 | // BLINKER_LOG_ALL("auto_format_data3 end"); 691 | } 692 | 693 | // BLINKER_LOG_ALL("auto_format_data end"); 694 | } 695 | 696 | void blinker_print(const char * key, const char * value, int8_t isRaw) 697 | { 698 | blinker_check_format(); 699 | blinker_auto_format_data(key, value, isRaw); 700 | 701 | // if ((blinker_millis() - blinker_auto_format_time) >= BLINKER_MSG_AUTOFORMAT_TIMEOUT) 702 | // { 703 | // blinker_auto_format_time = blinker_millis(); 704 | // } 705 | 706 | // // BLINKER_LOG_ALL("blinker_auto_format_data end"); 707 | 708 | uint8_t need_check = true; 709 | if (strstr(blinker_send_buf, BLINKER_CMD_CONNECTED)) need_check = false; 710 | strcat(blinker_send_buf, "\r\n"); 711 | blinker_ble_print(blinker_send_buf, need_check); 712 | 713 | // free(blinker_send_buf); 714 | blinker_auto_format = false; 715 | } 716 | 717 | void blinker_heart_beat(cJSON *_data) 718 | { 719 | cJSON *_state = cJSON_GetObjectItem(_data, BLINKER_CMD_GET); 720 | // cJSON *_state = cJSON_GetObjectItem(_data, BLINKER_CMD_GET); 721 | 722 | if (_state->string != NULL) 723 | { 724 | if (strcmp(_state->valuestring, BLINKER_CMD_STATE) == 0) 725 | { 726 | // char data[512] = "{\"state\":\"online\"}"; 727 | 728 | // blinker_print(data); 729 | // blinker_print(BLINKER_CMD_STATE, BLINKER_CMD_CONNECTED, 0); 730 | 731 | blinker_parsed = true; 732 | } 733 | } 734 | 735 | // cJSON_Delete(_state); 736 | } 737 | 738 | void blinker_parse(const char * data) 739 | { 740 | // BLINKER_LOG("blinekr parse data:%s", data); 741 | 742 | blinker_parsed = false; 743 | 744 | if (!isJson(data)) 745 | { 746 | // BLINKER_ERR_LOG("not a json format data"); 747 | } 748 | else 749 | { 750 | cJSON *root = cJSON_Parse(data); 751 | cJSON *_data = cJSON_GetObjectItem(root, "data"); 752 | // cJSON *_data = cJSON_GetObjectItem(root, "data"); 753 | 754 | if (_data == NULL) 755 | { 756 | blinker_heart_beat(root); 757 | widget_parse(root); 758 | 759 | if (!blinker_parsed) 760 | { 761 | if (blinker_data_func) 762 | { 763 | blinker_data_func(root); 764 | 765 | // cJSON_Delete(root); 766 | } 767 | } 768 | 769 | // // cJSON_Delete(root); 770 | } 771 | else 772 | { 773 | // BLINKER_LOG("blinekr parse _data:%s", _data->valuestring); 774 | blinker_heart_beat(root); 775 | widget_parse(_data); 776 | 777 | if (!blinker_parsed) 778 | { 779 | if (blinker_data_func) 780 | { 781 | blinker_data_func(root); 782 | 783 | // cJSON_Delete(root); 784 | } 785 | } 786 | } 787 | 788 | // BLINKER_LOG_ALL("blinker_parse"); 789 | 790 | // cJSON_Delete(_data); 791 | cJSON_Delete(root); 792 | } 793 | 794 | blinker_ble_flush(); 795 | } 796 | 797 | void blinker_init(void) 798 | { 799 | // // BLINKER_LOG_init(); 800 | // // BLINKER_LOG("blinker v%s", BLINKER_VERSION); 801 | // // BLINKER_LOG(" To better use blinker with your IoT project!"); 802 | // // BLINKER_LOG(" Download latest blinker library here!"); 803 | // // BLINKER_LOG(" => https://github.com/blinker-iot/blinker-nRF52"); 804 | // // BLINKER_LOG("heap: %d", xPortGetFreeHeapSize()); 805 | 806 | // run(); 807 | 808 | blinker_ble_init(blinker_parse); 809 | 810 | // // BLINKER_LOG("heap: %d", xPortGetFreeHeapSize()); 811 | 812 | // const char *strings[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}; 813 | // cJSON *root; 814 | // int numbers[3]={0,0,1}; 815 | // root=cJSON_CreateObject(); 816 | // // cJSON_CreateIntArray(numbers[i],3) 817 | // // for (uint8_t i=0;i<3;i++) 818 | // cJSON_AddNumberToObject(root,"Height",600); 819 | // cJSON_AddItemToObject(root,"IDs", cJSON_CreateIntArray(numbers,3)); 820 | // char *out=cJSON_Print(root); 821 | // cJSON_Delete(root); 822 | // printf("%s\n",out); 823 | // free(out); 824 | 825 | // vTaskStartScheduler(); 826 | 827 | // // printf("run time %d,%d\r\n", app_timer_cnt_get(), app_timer_cnt_get()* ( (1 + 1 ) * 1000 ) / APP_TIMER_CLOCK_FREQ); 828 | // // // BLINKER_LOG("test"); 829 | 830 | // for (;;) 831 | // { 832 | // // idle_state_handle(); 833 | // APP_ERROR_HANDLER(NRF_ERROR_FORBIDDEN); 834 | // } 835 | } 836 | 837 | // void blinker_run(void * pv) 838 | // { 839 | // // blinker_check_auto_format(); 840 | 841 | // UNUSED_PARAMETER(pv); 842 | 843 | // while (1) 844 | // { 845 | // if (blinker_ble_avaliable()) 846 | // { 847 | // blinker_parse(blinker_ble_lastread()); 848 | // // BLINKER_LOG("heap: %d", xPortGetFreeHeapSize()); 849 | // // blinker_ble_flush(); 850 | // } 851 | // vTaskDelay(10); 852 | // } 853 | 854 | // // idle_state_handle(); 855 | // } 856 | 857 | void run(void) 858 | { 859 | // BLINKER_LOG("blinker run"); 860 | 861 | // UNUSED_VARIABLE(xTaskCreate(blinker_run, "blinker_run", 128, NULL, 2, &m_blinkr_run_thread)); 862 | } 863 | -------------------------------------------------------------------------------- /Blinker/BlinkerApi.h: -------------------------------------------------------------------------------- 1 | #ifndef BLINKER_API_H__ 2 | #define BLINKER_API_H__ 3 | 4 | #include "sdk_common.h" 5 | #if NRF_MODULE_ENABLED(BLINKER_BLE) 6 | #include "BlinkerBLE.h" 7 | #endif 8 | 9 | 10 | typedef struct 11 | { 12 | const char *name; 13 | uint8_t wNum; 14 | } BlinkerButton; 15 | 16 | typedef struct 17 | { 18 | const char *name; 19 | } BlinkerNumber; 20 | 21 | typedef struct 22 | { 23 | const char *name; 24 | uint8_t wNum; 25 | } BlinkerRGB; 26 | 27 | typedef struct 28 | { 29 | const char *name; 30 | uint8_t wNum; 31 | } BlinkerSlider; 32 | 33 | typedef struct 34 | { 35 | const char *name; 36 | uint8_t wNum; 37 | } BlinkerTab; 38 | 39 | typedef struct 40 | { 41 | const char *name; 42 | } BlinkerText; 43 | 44 | typedef struct 45 | { 46 | const char *state; 47 | const char *icon; 48 | const char *color; 49 | const char *content; 50 | const char *text1; 51 | const char *text2; 52 | const char *textColor; 53 | } blinker_button_config_t; 54 | 55 | typedef struct 56 | { 57 | const char *icon; 58 | const char *color; 59 | const char *unit; 60 | const char *text; 61 | const char *value; 62 | } blinker_number_config_t; 63 | 64 | typedef struct 65 | { 66 | uint8_t rgbw[4]; 67 | } blinker_rgb_config_t; 68 | 69 | typedef struct 70 | { 71 | const char *color; 72 | const char *value; 73 | } blinker_slider_config_t; 74 | 75 | typedef struct 76 | { 77 | const char *state; 78 | } blinker_switch_config_t; 79 | 80 | typedef struct 81 | { 82 | uint8_t tab[5]; 83 | } blinker_tab_config_t; 84 | 85 | typedef struct 86 | { 87 | const char *icon; 88 | const char *color; 89 | const char *text; 90 | const char *text1; 91 | } blinker_text_config_t; 92 | 93 | typedef struct 94 | { 95 | const char *name; 96 | blinker_callback_with_string_arg_t wfunc; 97 | } blinker_widgets_str_t; 98 | 99 | typedef struct 100 | { 101 | const char *name; 102 | blinker_callback_with_rgb_arg_t wfunc; 103 | } blinker_widgets_rgb_t; 104 | 105 | typedef struct 106 | { 107 | const char *name; 108 | blinker_callback_with_int32_arg_t wfunc; 109 | } blinker_widgets_int_t; 110 | 111 | typedef struct 112 | { 113 | const char *name; 114 | blinker_callback_with_tab_arg_t wfunc; 115 | blinker_callback_t wfunc1; 116 | } blinker_widgets_tab_t; 117 | 118 | void blinker_attach_data(blinker_callback_with_json_arg_t func); 119 | 120 | void blinker_button_print(const BlinkerButton *button, const blinker_button_config_t * config); 121 | 122 | void blinker_number_print(const BlinkerNumber *number, const blinker_number_config_t *config); 123 | 124 | void blinker_rgb_print(const BlinkerRGB *rgb, const blinker_rgb_config_t *config); 125 | 126 | void blinker_slider_print(const BlinkerSlider *slider, const blinker_slider_config_t *config); 127 | 128 | void blinker_switch_print(const blinker_switch_config_t *config); 129 | 130 | void blinker_tab_print(const BlinkerTab *tab, const blinker_tab_config_t *config); 131 | 132 | void blinker_text_print(const BlinkerText *text, const blinker_text_config_t *config); 133 | 134 | void blinker_button_init(BlinkerButton *button, blinker_callback_with_string_arg_t _func); 135 | 136 | void blinker_rgb_init(BlinkerRGB *rgb, blinker_callback_with_rgb_arg_t _func); 137 | 138 | void blinker_slider_init(BlinkerSlider *slider, blinker_callback_with_int32_arg_t _func); 139 | 140 | void blinker_switch_init(blinker_callback_with_string_arg_t _func); 141 | 142 | void blinker_tab_init(BlinkerTab *tab, blinker_callback_with_tab_arg_t _func, blinker_callback_t _func1); 143 | 144 | void blinker_print(const char * key, const char * value, int8_t isRaw); 145 | 146 | void blinker_init(void); 147 | 148 | void run(); 149 | 150 | #endif 151 | -------------------------------------------------------------------------------- /Blinker/BlinkerBLE.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Copyright (c) 2017 - 2019, Nordic Semiconductor ASA 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form, except as embedded into a Nordic 14 | * Semiconductor ASA integrated circuit in a product or a software update for 15 | * such product, must reproduce the above copyright notice, this list of 16 | * conditions and the following disclaimer in the documentation and/or other 17 | * materials provided with the distribution. 18 | * 19 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 20 | * contributors may be used to endorse or promote products derived from this 21 | * software without specific prior written permission. 22 | * 23 | * 4. This software, with or without modification, must only be used with a 24 | * Nordic Semiconductor ASA integrated circuit. 25 | * 26 | * 5. Any software provided in binary form under this license must not be reverse 27 | * engineered, decompiled, modified and/or disassembled. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 30 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 31 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 32 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 33 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 34 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 35 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 38 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | */ 41 | 42 | /** @brief GATT Service client example application main file. 43 | 44 | @details This file contains the main source code for a sample client application that uses the 45 | GATT Service. This client can be used to receive Service Changed indications. This is 46 | needed if your application interacts with GATT servers that modify, remove or add 47 | services. A typical course of action if a Service Changed indication is received is to 48 | rediscover the database on the peer device. 49 | 50 | For more information about the GATT Service, see "Defined Generic Attribute Profile Service" 51 | in Bluetooth Specification Version 5.0 Vol 3, Part G Section 7. 52 | */ 53 | 54 | #include "BlinkerBle.h" 55 | 56 | #if NRF_MODULE_ENABLED(BLINKER_BLE) 57 | 58 | // #include "app_adv.h" 59 | #include "nordic_common.h" 60 | #include "nrf.h" 61 | #include "app_error.h" 62 | #include "ble.h" 63 | #include "ble_srv_common.h" 64 | #include "ble_advdata.h" 65 | #include "ble_advertising.h" 66 | #include "nrf_sdh.h" 67 | #include "nrf_sdh_soc.h" 68 | #include "nrf_sdh_ble.h" 69 | #include "app_timer.h" 70 | #include "bsp.h" 71 | #include "bsp_btn_ble.h" 72 | #include "nrf_ble_gatts_c.h" 73 | #include "boards.h" 74 | #include "ble_gap.h" 75 | #include "nrf_ble_gatt.h" 76 | #include "nrf_ble_qwr.h" 77 | #include "peer_manager.h" 78 | #include "peer_manager_handler.h" 79 | #include "fds.h" 80 | #include "ble_conn_state.h" 81 | #include "nrf_pwr_mgmt.h" 82 | 83 | #include "app_adv.h" 84 | #include "ble_advdata.h" 85 | #include "ble_advertising.h" 86 | #include "bsp.h" 87 | #include "peer_manager.h" 88 | #include "nrf_sdh.h" 89 | #include "nrf_sdh_soc.h" 90 | #include "nrf_sdh_ble.h" 91 | #include "nrf_log.h" 92 | #include "nrf_log_ctrl.h" 93 | #include "nrf_log_default_backends.h" 94 | 95 | #define APP_BLE_OBSERVER_PRIO 3 /**< Application's BLE observer priority. You shouldn't need to modify this value. */ 96 | #define APP_BLE_CONN_CFG_TAG 1 /**< A tag identifying the SoftDevice BLE configuration. */ 97 | #define DEAD_BEEF 0xDEADBEEF /**< Value used as error code on stack dump, can be used to identify stack location on stack unwind. */ 98 | 99 | #define APP_ADV_FAST_INTERVAL 0x0028 /**< Fast advertising interval (in units of 0.625 ms. This value corresponds to 25 ms.). */ 100 | #define APP_ADV_SLOW_INTERVAL 0x0C80 /**< Slow advertising interval (in units of 0.625 ms. This value corrsponds to 2 seconds). */ 101 | 102 | #define APP_ADV_FAST_DURATION 0 /**< The advertising duration (180 seconds) in units of 10 milliseconds. */ 103 | // #define APP_ADV_SLOW_DURATION 18000 /**< The advertising duration of slow advertising in units of 10 milliseconds. */ 104 | 105 | #define MIN_CONN_INTERVAL MSEC_TO_UNITS(50, UNIT_1_25_MS) /**< Minimum acceptable connection interval (20 ms), Connection interval uses 1.25 ms units. */ 106 | #define MAX_CONN_INTERVAL MSEC_TO_UNITS(100, UNIT_1_25_MS) /**< Maximum acceptable connection interval (75 ms), Connection interval uses 1.25 ms units. */ 107 | #define SLAVE_LATENCY 0 /**< Slave latency. */ 108 | #define CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) /**< Connection supervisory timeout (4 seconds), Supervision Timeout uses 10 ms units. */ 109 | #define FIRST_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(5000) /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */ 110 | #define NEXT_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(30000) /**< Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */ 111 | #define MAX_CONN_PARAMS_UPDATE_COUNT 3 /**< Number of attempts before giving up the connection parameter negotiation. */ 112 | 113 | #define BTS_SERVICE_UUID_TYPE BLE_UUID_TYPE_VENDOR_BEGIN /**< UUID type for the Nordic UART Service (vendor specific). */ 114 | 115 | #define APP_BLE_CONN_CFG_TAG 1 /**< A tag for a BLE stack configuration .*/ 116 | #define APP_ADV_DURATION BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED /**< The advertising duration in units of 10 milliseconds. */ 117 | 118 | 119 | BLE_BTS_DEF(m_bts, NRF_SDH_BLE_TOTAL_LINK_COUNT); /**< Link Loss service instance. */ 120 | NRF_BLE_GATT_DEF(m_gatt); /**< GATT module instance. */ 121 | NRF_BLE_GATTS_C_DEF(m_gatts_c); /**< GATT Service client instance. Handles Service Changed indications from the peer. */ 122 | NRF_BLE_QWR_DEF(m_qwr); /**< Context for the Queued Write module.*/ 123 | BLE_DB_DISCOVERY_DEF(m_ble_db_discovery); /**< DB discovery module instance. */ 124 | NRF_BLE_GQ_DEF(m_ble_gatt_queue, /**< BLE GATT Queue instance. */ 125 | NRF_SDH_BLE_PERIPHERAL_LINK_COUNT, 126 | NRF_BLE_GQ_QUEUE_SIZE); 127 | BLE_ADVERTISING_DEF(m_advertising); /**< Advertising module instance. */ 128 | 129 | static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID; /**< Handle of the current connection. */ 130 | static uint16_t m_ble_bts_max_data_len = BLE_GATT_ATT_MTU_DEFAULT - 3; /**< Maximum length of data (in bytes) that can be transmitted to the peer by the Nordic UART service module. */ 131 | 132 | static bool m_erase_bonds; /**< Bool to determine if bonds should be erased before advertising starts. Based on button push upon startup. */ 133 | static ble_uuid_t m_adv_uuids[] = /**< Universally unique service identifiers. */ 134 | { 135 | {0xFFE0, BLE_UUID_TYPE_BLE}, 136 | // {BLE_UUID_IMMEDIATE_ALERT_SERVICE, BLE_UUID_TYPE_BLE}, 137 | // {BLE_UUID_BATTERY_SERVICE, BLE_UUID_TYPE_BLE}, 138 | // // {BLE_UUID_TX_POWER_SERVICE, BLE_UUID_TYPE_BLE}, 139 | // {BLE_UUID_LINK_LOSS_SERVICE, BLE_UUID_TYPE_BLE} 140 | }; 141 | 142 | static uint8_t m_pm_peer_srv_buffer[ALIGN_NUM(4, sizeof(ble_gatt_db_srv_t))] = {0}; /**< Data written to flash by peer manager must be aligned on 4 bytes. 143 | When loading and storing we will treat this byte array as a ble_gatt_db_srv_t. 144 | We use a static variable because it is written asynchronously. */ 145 | 146 | 147 | blinker_callback_with_string_arg_t blinker_parse_func = NULL; 148 | 149 | 150 | static bool ble_connect_state = false; 151 | static char ble_buf[BLINKER_MAX_READ_SIZE]; 152 | static bool ble_fresh = false; 153 | static bool ble_avail = false; 154 | static uint32_t ble_buf_len; 155 | 156 | 157 | bool blinker_ble_connect(void) { return ble_connect_state; } 158 | bool blinker_ble_connected(void) { return ble_connect_state; } 159 | void blinker_ble_disconnect(void) { advertising_start(&m_erase_bonds); } 160 | bool blinker_ble_avaliable(void) 161 | { 162 | if (ble_avail) 163 | { 164 | ble_avail = false; 165 | return true; 166 | } 167 | else 168 | { 169 | return false; 170 | } 171 | } 172 | char * blinker_ble_lastread(void) { return ble_buf;} 173 | 174 | void blinker_ble_flush(void) 175 | { 176 | if (ble_fresh) 177 | { 178 | NRF_LOG_INFO("blinker ble flush"); 179 | 180 | // free(ble_buf); 181 | ble_fresh = false; 182 | ble_avail = false; 183 | } 184 | } 185 | 186 | 187 | /**@brief Function for handling the data from the Nordic UART Service. 188 | * 189 | * @details This function will process the data received from the Nordic UART BLE Service and send 190 | * it to the UART module. 191 | * 192 | * @param[in] p_evt Nordic UART Service event. 193 | */ 194 | /**@snippet [Handling the data received over BLE] */ 195 | static void bts_data_handler(ble_bts_evt_t * p_evt) 196 | { 197 | if (p_evt->evt_type == BLE_BTS_EVT_RX_DATA) 198 | { 199 | // uint32_t err_code; 200 | 201 | if (p_evt->params.rx_data.length > 0) 202 | { 203 | // if (!ble_buf_len) 204 | // { 205 | // ble_buf = (char*)malloc((p_evt->params.rx_data.length + 1)*sizeof(char)); 206 | // } 207 | // else 208 | // { 209 | // free(ble_buf); 210 | // ble_buf = (char*)malloc((p_evt->params.rx_data.length + 1)*sizeof(char)); 211 | // } 212 | 213 | strcpy(ble_buf, p_evt->params.rx_data.p_data); 214 | ble_buf_len = p_evt->params.rx_data.length; 215 | ble_buf[ble_buf_len] = '\0'; 216 | } 217 | 218 | ble_fresh = true; 219 | ble_avail = true; 220 | 221 | if (ble_buf[ble_buf_len - 1] == '\n') ble_buf[ble_buf_len - 1] = '\0'; 222 | if (ble_buf[ble_buf_len - 2] == '\r') ble_buf[ble_buf_len - 2] = '\0'; 223 | 224 | NRF_LOG_INFO("get data: %s, len: %d", ble_buf, ble_buf_len); 225 | // NRF_LOG_INFO("get data: %s, len: %d", p_evt->params.rx_data.p_data, p_evt->params.rx_data.length); 226 | 227 | // NRF_LOG_INFO("heap: %d", xPortGetFreeHeapSize()); 228 | 229 | if (blinker_parse_func) blinker_parse_func(ble_buf); 230 | 231 | // NRF_LOG_DEBUG("Received data from BLE BTS. Writing data on UART."); 232 | // NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length); 233 | 234 | // for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++) 235 | // { 236 | // do 237 | // { 238 | // err_code = app_uart_put(p_evt->params.rx_data.p_data[i]); 239 | // if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY)) 240 | // { 241 | // NRF_LOG_ERROR("Failed receiving BTS message. Error 0x%x. ", err_code); 242 | // APP_ERROR_CHECK(err_code); 243 | // } 244 | // } while (err_code == NRF_ERROR_BUSY); 245 | // } 246 | // if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r') 247 | // { 248 | // while (app_uart_put('\n') == NRF_ERROR_BUSY); 249 | // } 250 | } 251 | 252 | // static uint8_t data_array[BLE_BTS_MAX_DATA_LEN]; 253 | // static uint8_t index; 254 | // uint32_t err_code; 255 | // static char data_buf[BLE_BTS_MAX_DATA_LEN] = { 0 }; 256 | 257 | // memcpy(data_buf, p_evt->params.rx_data.p_data, p_evt->params.rx_data.length); 258 | // strcpy(data_array, data_buf); 259 | // strcat(data_array, "\r\n"); 260 | 261 | // NRF_LOG_INFO("bts_data_handler: %s, %d", data_buf, p_evt->params.rx_data.length); 262 | 263 | // index = p_evt->params.rx_data.length + 2; 264 | 265 | // NRF_LOG_INFO("bts_data_handler end"); 266 | 267 | // if (index > 0) 268 | // { 269 | // if ((data_array[index - 1] == '\n') || 270 | // (data_array[index - 1] == '\r') || 271 | // (index >= m_ble_bts_max_data_len)) 272 | // { 273 | // if (index > 1) 274 | // { 275 | // NRF_LOG_DEBUG("Ready to send data over BLE BTS"); 276 | // NRF_LOG_HEXDUMP_DEBUG(data_array, index); 277 | 278 | // NRF_LOG_INFO("send data over BLE BTS: len: %d, %s", index, data_array); 279 | 280 | // do 281 | // { 282 | // NRF_LOG_INFO("m_conn_handle %d.", m_conn_handle); 283 | 284 | // uint16_t length = (uint16_t)index; 285 | // err_code = ble_bts_data_send(&m_bts, data_array, &length, m_conn_handle); 286 | // if ((err_code != NRF_ERROR_INVALID_STATE) && 287 | // (err_code != NRF_ERROR_RESOURCES) && 288 | // (err_code != NRF_ERROR_NOT_FOUND)) 289 | // { 290 | // APP_ERROR_CHECK(err_code); 291 | // NRF_LOG_INFO("Failed...err_code: %d", err_code); 292 | // } 293 | // // blinker_ble_print(data_array, false); 294 | // } while (err_code == NRF_ERROR_RESOURCES); 295 | // // blinker_ble_print(data_array, false); 296 | // } 297 | 298 | // index = 0; 299 | // } 300 | // } 301 | } 302 | 303 | 304 | void blinker_ble_print(char * data, bool need_check) 305 | { 306 | NRF_LOG_INFO("response: %s, len: %d", data, strlen(data)); 307 | if (ble_connect_state && strlen(data)) 308 | { 309 | uint32_t err_code; 310 | uint16_t length = (uint16_t)strlen(data); 311 | uint16_t send_len = 0; 312 | uint8_t parts = length / 20 + 1; 313 | char s_send[23] = {0}; 314 | for (uint8_t num = 0; num < parts; num++) 315 | { 316 | 317 | if ((num + 1) == parts) 318 | { 319 | blinker_substring(s_send, data, num*(20), length); 320 | send_len = length - num*(20); 321 | } 322 | else 323 | { 324 | blinker_substring(s_send, data, num*(20), (num+1)*20); 325 | send_len = 20; 326 | } 327 | 328 | do 329 | { 330 | err_code = ble_bts_data_send(&m_bts, s_send, &send_len, m_conn_handle); 331 | if ((err_code != NRF_ERROR_INVALID_STATE) && 332 | (err_code != NRF_ERROR_RESOURCES) && 333 | (err_code != NRF_ERROR_NOT_FOUND)) 334 | { 335 | APP_ERROR_CHECK(err_code); 336 | } 337 | } while (err_code == NRF_ERROR_RESOURCES); 338 | } 339 | NRF_LOG_INFO("Success..."); 340 | } 341 | else 342 | { 343 | NRF_LOG_INFO("Failed... Disconnected"); 344 | } 345 | } 346 | 347 | 348 | /**@brief Function for handling advertising events. 349 | 350 | @details This function will be called for advertising events which are passed to the application. 351 | 352 | @param[in] ble_adv_evt Advertising event. 353 | */ 354 | void on_adv_evt(ble_adv_evt_t ble_adv_evt) 355 | { 356 | ret_code_t err_code; 357 | 358 | switch (ble_adv_evt) 359 | { 360 | case BLE_ADV_EVT_FAST: 361 | NRF_LOG_INFO("Fast advertising."); 362 | err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING); 363 | APP_ERROR_CHECK(err_code); 364 | break; 365 | 366 | case BLE_ADV_EVT_IDLE: 367 | NRF_LOG_INFO("Advertising stopped."); 368 | break; 369 | 370 | default: 371 | break; 372 | } 373 | } 374 | 375 | 376 | /**@brief Function for initializing the Advertising functionality. 377 | 378 | @details Encodes the required advertising data and passes it to the stack. 379 | Also builds a structure to be passed to the stack when starting advertising. 380 | */ 381 | void advertising_init(void) 382 | { 383 | ret_code_t err_code; 384 | ble_advertising_init_t init; 385 | 386 | memset(&init, 0, sizeof(init)); 387 | 388 | ble_gap_addr_t ble_addr; 389 | sd_ble_gap_addr_get(&ble_addr); 390 | 391 | // FICR->DEVICEADDR[x] 392 | 393 | ble_advdata_manuf_data_t manuf_data; //Variable to hold manufacturer specific data 394 | // uint8_t data[] = "blinker test!"; //Our data to advertise 395 | manuf_data.company_identifier = 0x4444; //Nordics company ID 396 | manuf_data.data.p_data = ble_addr.addr;//data; 397 | manuf_data.data.size = sizeof(ble_addr.addr);//sizeof(data); 398 | init.advdata.p_manuf_specific_data = &manuf_data; 399 | 400 | init.advdata.name_type = BLE_ADVDATA_FULL_NAME; 401 | init.advdata.include_appearance = true; 402 | init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; 403 | init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]); 404 | init.advdata.uuids_complete.p_uuids = m_adv_uuids; 405 | 406 | init.config.ble_adv_fast_enabled = true; 407 | init.config.ble_adv_fast_interval = ADV_INTERVAL; 408 | init.config.ble_adv_fast_timeout = APP_ADV_DURATION; 409 | 410 | init.evt_handler = on_adv_evt; 411 | 412 | err_code = ble_advertising_init(&m_advertising, &init); 413 | APP_ERROR_CHECK(err_code); 414 | 415 | ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG); 416 | } 417 | 418 | 419 | /**@brief Function for starting advertising, or instead trigger it from peer manager (after 420 | deleting bonds). 421 | 422 | @param[in] erase_bonds Bool to determine if bonds will be deleted before advertising. 423 | */ 424 | void advertising_start(bool erase_bonds) 425 | { 426 | ret_code_t err_code; 427 | 428 | if (erase_bonds == true) 429 | { 430 | // Advertising is started by the PM_EVT_PEERS_DELETE_SUCCEEDED event. 431 | NRF_LOG_INFO("Erase bonds."); 432 | err_code = pm_peers_delete(); 433 | APP_ERROR_CHECK(err_code); 434 | } 435 | else 436 | { 437 | err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST); 438 | APP_ERROR_CHECK(err_code); 439 | } 440 | } 441 | 442 | 443 | /**@brief Function for assert macro callback. 444 | 445 | @details This function will be called in case of an assert in the SoftDevice. 446 | 447 | @warning This handler is an example only and does not fit a final product. You need to analyze 448 | how your product is supposed to react in case of Assert. 449 | @warning On assert from the SoftDevice, the system can only recover on reset. 450 | 451 | @param[in] line_num Line number of the failing ASSERT call. 452 | @param[in] p_file_name File name of the failing ASSERT call. 453 | */ 454 | void assert_nrf_callback(uint16_t line_num, const uint8_t * p_file_name) 455 | { 456 | app_error_handler(DEAD_BEEF, line_num, p_file_name); 457 | } 458 | 459 | 460 | /**@brief Function for handling the GATT Service Client errors. 461 | * 462 | * @param[in] nrf_error Error code containing information about what went wrong. 463 | */ 464 | static void gatt_c_error_handler(uint32_t nrf_error) 465 | { 466 | APP_ERROR_HANDLER(nrf_error); 467 | } 468 | 469 | 470 | /**@brief Function for the LEDs initialization. 471 | 472 | @details Initializes all LEDs used by the application. 473 | */ 474 | static void leds_init(void) 475 | { 476 | bsp_board_init(BSP_INIT_LEDS); 477 | } 478 | 479 | 480 | /**@brief Function for the Timer initialization. 481 | 482 | @details Initializes the timer module. 483 | */ 484 | static void timers_init(void) 485 | { 486 | ret_code_t err_code; 487 | 488 | err_code = app_timer_init(); 489 | APP_ERROR_CHECK(err_code); 490 | } 491 | 492 | 493 | /**@brief Function for the GAP initialization. 494 | 495 | @details This function sets up all the necessary GAP (Generic Access Profile) parameters of the 496 | device including the device name, appearance, and the preferred connection parameters. 497 | */ 498 | static void gap_params_init(void) 499 | { 500 | ret_code_t err_code; 501 | ble_gap_conn_params_t gap_conn_params; 502 | ble_gap_conn_sec_mode_t sec_mode; 503 | 504 | BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); 505 | 506 | err_code = sd_ble_gap_device_name_set(&sec_mode, 507 | (const uint8_t *)DEVICE_NAME, 508 | strlen(DEVICE_NAME)); 509 | APP_ERROR_CHECK(err_code); 510 | 511 | memset(&gap_conn_params, 0, sizeof(gap_conn_params)); 512 | 513 | gap_conn_params.min_conn_interval = MSEC_TO_UNITS(MIN_CONN_INTERVAL_MSEC, UNIT_1_25_MS); 514 | gap_conn_params.max_conn_interval = MSEC_TO_UNITS(MAX_CONN_INTERVAL_MSEC, UNIT_1_25_MS); 515 | gap_conn_params.slave_latency = SLAVE_LATENCY; 516 | gap_conn_params.conn_sup_timeout = MSEC_TO_UNITS(CONN_SUP_TIMEOUT_MSEC, UNIT_10_MS); 517 | 518 | err_code = sd_ble_gap_ppcp_set(&gap_conn_params); 519 | APP_ERROR_CHECK(err_code); 520 | } 521 | 522 | 523 | /**@brief Function for initializing buttons and leds. 524 | 525 | @param[out] p_erase_bonds Boolean that will be set to true if the device is 526 | woken up by the BSP_EVENT_CLEAR_BONDING_DATA event. 527 | */ 528 | static void buttons_leds_init(bool * p_erase_bonds) 529 | { 530 | ret_code_t err_code; 531 | bsp_event_t startup_event; 532 | 533 | err_code = bsp_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS, NULL); 534 | APP_ERROR_CHECK(err_code); 535 | 536 | err_code = bsp_btn_ble_init(NULL, &startup_event); 537 | APP_ERROR_CHECK(err_code); 538 | 539 | *p_erase_bonds = (startup_event == BSP_EVENT_CLEAR_BONDING_DATA); 540 | } 541 | 542 | 543 | /**@brief Function for handling events from the GATT Servive client module. 544 | 545 | @param[in] p_evt GATT Service event. 546 | */ 547 | static void gatts_evt_handler(nrf_ble_gatts_c_evt_t * p_evt) 548 | { 549 | ret_code_t err_code; 550 | 551 | switch (p_evt->evt_type) 552 | { 553 | case NRF_BLE_GATTS_C_EVT_DISCOVERY_COMPLETE: 554 | { 555 | NRF_LOG_INFO("GATT Service and Service Changed characteristic found on server."); 556 | 557 | err_code = nrf_ble_gatts_c_handles_assign(&m_gatts_c, 558 | p_evt->conn_handle, 559 | &p_evt->params.srv_changed_char); 560 | APP_ERROR_CHECK(err_code); 561 | 562 | pm_peer_id_t peer_id; 563 | err_code = pm_peer_id_get(p_evt->conn_handle, &peer_id); 564 | APP_ERROR_CHECK(err_code); 565 | 566 | 567 | ble_gatt_db_srv_t srv_db_to_store; 568 | srv_db_to_store.charateristics[0] = p_evt->params.srv_changed_char; 569 | memcpy(m_pm_peer_srv_buffer, &srv_db_to_store, sizeof(ble_gatt_db_srv_t)); 570 | 571 | err_code = pm_peer_data_remote_db_store(peer_id, 572 | (ble_gatt_db_srv_t *)m_pm_peer_srv_buffer, 573 | sizeof(m_pm_peer_srv_buffer), 574 | NULL); 575 | 576 | if (err_code == NRF_ERROR_STORAGE_FULL) 577 | { 578 | err_code = fds_gc(); 579 | } 580 | APP_ERROR_CHECK(err_code); 581 | 582 | err_code = nrf_ble_gatts_c_enable_indication(&m_gatts_c, true); 583 | APP_ERROR_CHECK(err_code); 584 | } break; 585 | 586 | case NRF_BLE_GATTS_C_EVT_DISCOVERY_FAILED: 587 | NRF_LOG_INFO("GATT Service or Service Changed characteristic not found on server."); 588 | break; 589 | 590 | case NRF_BLE_GATTS_C_EVT_DISCONN_COMPLETE: 591 | NRF_LOG_INFO("GATTS Service client disconnected connection handle %i.", p_evt->conn_handle); 592 | 593 | break; 594 | 595 | case NRF_BLE_GATTS_C_EVT_SRV_CHANGED: 596 | NRF_LOG_INFO("Service Changed indication received."); 597 | NRF_LOG_INFO("Handle range start: %04x", p_evt->params.handle_range.start_handle); 598 | NRF_LOG_INFO("Handle range end: %04x", p_evt->params.handle_range.end_handle); 599 | break; 600 | 601 | default: 602 | break; 603 | } 604 | } 605 | 606 | 607 | /**@brief Function for handling Peer Manager events. 608 | * 609 | * @param[in] p_evt Peer Manager event. 610 | */ 611 | static void pm_evt_handler(pm_evt_t const * p_evt) 612 | { 613 | ret_code_t err_code; 614 | 615 | pm_handler_on_pm_evt(p_evt); 616 | pm_handler_flash_clean(p_evt); 617 | 618 | switch (p_evt->evt_id) 619 | { 620 | case PM_EVT_BONDED_PEER_CONNECTED: 621 | { 622 | pm_peer_id_t peer_id; 623 | err_code = pm_peer_id_get(p_evt->conn_handle, &peer_id); 624 | APP_ERROR_CHECK(err_code); 625 | if (peer_id != PM_PEER_ID_INVALID) 626 | { 627 | 628 | ble_gatt_db_srv_t * remote_db; 629 | remote_db = (ble_gatt_db_srv_t *)m_pm_peer_srv_buffer; 630 | uint32_t data_len = sizeof(m_pm_peer_srv_buffer); 631 | 632 | err_code = pm_peer_data_remote_db_load(peer_id, remote_db, &data_len); 633 | if (err_code == NRF_ERROR_NOT_FOUND) 634 | { 635 | NRF_LOG_DEBUG("Could not find the remote database in flash."); 636 | err_code = nrf_ble_gatts_c_handles_assign(&m_gatts_c, p_evt->conn_handle, NULL); 637 | APP_ERROR_CHECK(err_code); 638 | 639 | // Discover peer's services. 640 | memset(&m_ble_db_discovery, 0x00, sizeof(m_ble_db_discovery)); 641 | err_code = ble_db_discovery_start(&m_ble_db_discovery, p_evt->conn_handle); 642 | APP_ERROR_CHECK(err_code); 643 | } 644 | else 645 | { 646 | // Check if the load was successful. 647 | NRF_LOG_INFO("Remote Database loaded from flash."); 648 | APP_ERROR_CHECK(err_code); 649 | 650 | // Assign the loaded handles to the GATT Service client module. 651 | ble_gatt_db_char_t service_changed_handles = remote_db->charateristics[0]; 652 | err_code = nrf_ble_gatts_c_handles_assign(&m_gatts_c, 653 | p_evt->conn_handle, 654 | &service_changed_handles); 655 | APP_ERROR_CHECK(err_code); 656 | 657 | // Enable indications. 658 | err_code = nrf_ble_gatts_c_enable_indication(&m_gatts_c, true); 659 | APP_ERROR_CHECK(err_code); 660 | } 661 | } 662 | } break; 663 | 664 | case PM_EVT_CONN_SEC_SUCCEEDED: 665 | // Check it the Service Changed characteristic handle exists in our client instance. 666 | // If it is invalid, we know service discovery is needed. 667 | // (No database was loaded during @ref PM_EVT_BONDED_PEER_CONNECTED) 668 | if (m_gatts_c.srv_changed_char.characteristic.handle_value == BLE_GATT_HANDLE_INVALID) 669 | { 670 | err_code = nrf_ble_gatts_c_handles_assign(&m_gatts_c, p_evt->conn_handle, NULL); 671 | APP_ERROR_CHECK(err_code); 672 | 673 | // Discover peer's services. 674 | memset(&m_ble_db_discovery, 0x00, sizeof(m_ble_db_discovery)); 675 | err_code = ble_db_discovery_start(&m_ble_db_discovery, p_evt->conn_handle); 676 | APP_ERROR_CHECK(err_code); 677 | } 678 | break; 679 | 680 | case PM_EVT_PEERS_DELETE_SUCCEEDED: 681 | // Peer data was cleared from the flash. Start advertising with an empty list of peers. 682 | advertising_start(false); 683 | break; 684 | 685 | default: 686 | // No implementation needed. 687 | break; 688 | } 689 | } 690 | 691 | 692 | /**@brief Function for initializing the Peer Manager. 693 | */ 694 | void peer_manager_init(void) 695 | { 696 | ret_code_t err_code; 697 | ble_gap_sec_params_t sec_param; 698 | 699 | err_code = pm_init(); 700 | APP_ERROR_CHECK(err_code); 701 | 702 | memset(&sec_param, 0, sizeof(ble_gap_sec_params_t)); 703 | 704 | // Security parameters to be used for all security procedures. 705 | sec_param.bond = SEC_PARAM_BOND; 706 | sec_param.mitm = SEC_PARAM_MITM; 707 | sec_param.io_caps = SEC_PARAM_IO_CAPABILITIES; 708 | sec_param.oob = SEC_PARAM_OOB; 709 | sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE; 710 | sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE; 711 | sec_param.kdist_own.enc = 1; 712 | sec_param.kdist_own.id = 1; 713 | sec_param.kdist_peer.enc = 1; 714 | sec_param.kdist_peer.id = 1; 715 | 716 | err_code = pm_sec_params_set(&sec_param); 717 | APP_ERROR_CHECK(err_code); 718 | 719 | err_code = pm_register(pm_evt_handler); 720 | APP_ERROR_CHECK(err_code); 721 | } 722 | 723 | 724 | /**@brief Function for handling database discovery events. 725 | 726 | @details This function is callback function to handle events from the database discovery module. 727 | Depending on the UUIDs that are discovered, this function should forward the events 728 | to their respective services. 729 | 730 | @param[in] p_event Pointer to the database discovery event. 731 | */ 732 | static void db_disc_handler(ble_db_discovery_evt_t * p_evt) 733 | { 734 | nrf_ble_gatts_c_on_db_disc_evt(&m_gatts_c, p_evt); 735 | } 736 | 737 | 738 | /**@brief Function for handling connection events. 739 | 740 | @param[in] p_ble_evt Bluetooth stack event. 741 | */ 742 | static void on_connect(ble_evt_t const * p_ble_evt) 743 | { 744 | ret_code_t err_code; 745 | NRF_LOG_INFO("Connected."); 746 | 747 | err_code = bsp_indication_set(BSP_INDICATE_CONNECTED); 748 | APP_ERROR_CHECK(err_code); 749 | 750 | m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; 751 | err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle); 752 | APP_ERROR_CHECK(err_code); 753 | 754 | ble_connect_state = true; 755 | } 756 | 757 | 758 | /**@brief Function for handling timeout BLE stack events. 759 | 760 | @param[in] p_ble_evt Bluetooth stack event. 761 | */ 762 | static void on_timeout(ble_evt_t const * p_ble_evt) 763 | { 764 | ret_code_t err_code; 765 | 766 | switch (p_ble_evt->header.evt_id) 767 | { 768 | case BLE_GATTC_EVT_TIMEOUT: 769 | NRF_LOG_DEBUG("GATT Client Timeout."); 770 | err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gattc_evt.conn_handle, 771 | BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); 772 | APP_ERROR_CHECK(err_code); 773 | break; 774 | 775 | case BLE_GATTS_EVT_TIMEOUT: 776 | NRF_LOG_DEBUG("GATT Server Timeout."); 777 | err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gatts_evt.conn_handle, 778 | BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); 779 | APP_ERROR_CHECK(err_code); 780 | break; 781 | 782 | default: 783 | // No implementation needed. 784 | break; 785 | } 786 | } 787 | 788 | 789 | /**@brief Function for handling BLE events. 790 | * 791 | * @param[in] p_ble_evt Bluetooth stack event. 792 | * @param[in] p_context Unused. 793 | */ 794 | static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context) 795 | { 796 | ret_code_t err_code; 797 | 798 | pm_handler_secure_on_connection(p_ble_evt); 799 | 800 | switch (p_ble_evt->header.evt_id) 801 | { 802 | case BLE_GAP_EVT_CONNECTED: 803 | { 804 | on_connect(p_ble_evt); 805 | } break; 806 | 807 | case BLE_GAP_EVT_DISCONNECTED: 808 | NRF_LOG_INFO("Disconnected."); 809 | m_conn_handle = BLE_CONN_HANDLE_INVALID; 810 | ble_connect_state = false; 811 | break; 812 | 813 | case BLE_GAP_EVT_PHY_UPDATE_REQUEST: 814 | { 815 | NRF_LOG_DEBUG("PHY update request."); 816 | ble_gap_phys_t const phys = 817 | { 818 | .rx_phys = BLE_GAP_PHY_AUTO, 819 | .tx_phys = BLE_GAP_PHY_AUTO, 820 | }; 821 | err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys); 822 | APP_ERROR_CHECK(err_code); 823 | } break; 824 | 825 | case BLE_GATTS_EVT_SYS_ATTR_MISSING: 826 | // No system attributes have been stored. 827 | err_code = sd_ble_gatts_sys_attr_set(p_ble_evt->evt.gatts_evt.conn_handle, NULL, 0, 0); 828 | APP_ERROR_CHECK(err_code); 829 | break; 830 | 831 | case BLE_GATTC_EVT_TIMEOUT: 832 | // fall-through. 833 | case BLE_GATTS_EVT_TIMEOUT: 834 | on_timeout(p_ble_evt); 835 | break; 836 | 837 | default: 838 | // No implementation needed. 839 | break; 840 | } 841 | } 842 | 843 | 844 | /**@brief Function for initializing the BLE stack. 845 | 846 | @details Initializes the SoftDevice and the BLE event interrupt. 847 | */ 848 | static void ble_stack_init(void) 849 | { 850 | ret_code_t err_code; 851 | 852 | err_code = nrf_sdh_enable_request(); 853 | APP_ERROR_CHECK(err_code); 854 | 855 | // Configure the BLE stack using the default settings. 856 | // Fetch the start address of the application RAM. 857 | uint32_t ram_start = 0; 858 | err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start); 859 | APP_ERROR_CHECK(err_code); 860 | 861 | // Enable BLE stack. 862 | err_code = nrf_sdh_ble_enable(&ram_start); 863 | APP_ERROR_CHECK(err_code); 864 | 865 | // Register handler for BLE events. 866 | NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL); 867 | } 868 | 869 | 870 | /** @brief Database discovery initialization. 871 | */ 872 | static void db_discovery_init(void) 873 | { 874 | ble_db_discovery_init_t db_init; 875 | 876 | memset(&db_init, 0, sizeof(db_init)); 877 | 878 | db_init.evt_handler = db_disc_handler; 879 | db_init.p_gatt_queue = &m_ble_gatt_queue; 880 | 881 | ret_code_t err_code = ble_db_discovery_init(&db_init); 882 | 883 | APP_ERROR_CHECK(err_code); 884 | } 885 | 886 | 887 | /**@brief Function for initializing the nrf log module. 888 | */ 889 | static void log_init(void) 890 | { 891 | ret_code_t err_code = NRF_LOG_INIT(NULL); 892 | 893 | APP_ERROR_CHECK(err_code); 894 | 895 | NRF_LOG_DEFAULT_BACKENDS_INIT(); 896 | } 897 | 898 | 899 | /**@brief Function for initializing power management. 900 | */ 901 | static void power_management_init(void) 902 | { 903 | ret_code_t err_code; 904 | err_code = nrf_pwr_mgmt_init(); 905 | APP_ERROR_CHECK(err_code); 906 | } 907 | 908 | 909 | /**@brief Function for handling the idle state (main loop). If there is no pending log operation, 910 | then sleep until next the next event occurs. 911 | */ 912 | static void idle_state_handle(void) 913 | { 914 | if (NRF_LOG_PROCESS() == false) 915 | { 916 | nrf_pwr_mgmt_run(); 917 | } 918 | } 919 | 920 | 921 | /**@brief Function for initializing the GATT module. 922 | */ 923 | static void gatt_init(void) 924 | { 925 | ret_code_t err_code = nrf_ble_gatt_init(&m_gatt, NULL); 926 | 927 | APP_ERROR_CHECK(err_code); 928 | } 929 | 930 | 931 | /**@brief Function for handling Queued Write Module errors. 932 | * 933 | * @details A pointer to this function will be passed to each service which may need to inform the 934 | * application about an error. 935 | * 936 | * @param[in] nrf_error Error code containing information about what went wrong. 937 | */ 938 | static void nrf_qwr_error_handler(uint32_t nrf_error) 939 | { 940 | APP_ERROR_HANDLER(nrf_error); 941 | } 942 | 943 | 944 | /**@brief Function for initializing services that will be used by the application. 945 | */ 946 | static void services_init(void) 947 | { 948 | ret_code_t err_code; 949 | nrf_ble_gatts_c_init_t gatts_c_init = {0}; 950 | nrf_ble_qwr_init_t qwr_init = {0}; 951 | 952 | 953 | ble_bts_init_t bts_init_obj; 954 | 955 | // Initialize Link Loss Service 956 | memset(&bts_init_obj, 0, sizeof(bts_init_obj)); 957 | 958 | // bts_init_obj.evt_handler = on_bts_evt; 959 | // bts_init_obj.error_handler = service_error_handler; 960 | // bts_init_obj.initial_alert_level = INITIAL_BTS_ALERT_LEVEL; 961 | bts_init_obj.data_handler = bts_data_handler; 962 | 963 | // bts_init_obj.alert_level_rd_sec = SEC_JUST_WORKS; 964 | // bts_init_obj.alert_level_wr_sec = SEC_JUST_WORKS; 965 | 966 | err_code = ble_bts_init(&m_bts, &bts_init_obj); 967 | APP_ERROR_CHECK(err_code); 968 | 969 | 970 | // Initialize Queued Write Module. 971 | qwr_init.error_handler = nrf_qwr_error_handler; 972 | 973 | err_code = nrf_ble_qwr_init(&m_qwr, &qwr_init); 974 | APP_ERROR_CHECK(err_code); 975 | 976 | // Initialize GATTS Client Module. 977 | gatts_c_init.evt_handler = gatts_evt_handler; 978 | gatts_c_init.err_handler = gatt_c_error_handler; 979 | gatts_c_init.p_gatt_queue = &m_ble_gatt_queue; 980 | 981 | err_code = nrf_ble_gatts_c_init(&m_gatts_c, &gatts_c_init); 982 | APP_ERROR_CHECK(err_code); 983 | } 984 | 985 | 986 | /**@brief Function for initializing all the modules used in this example application. 987 | */ 988 | static void modules_init(void) 989 | { 990 | log_init(); 991 | leds_init(); 992 | timers_init(); 993 | buttons_leds_init(&m_erase_bonds); 994 | power_management_init(); 995 | ble_stack_init(); 996 | gap_params_init(); 997 | gatt_init(); 998 | db_discovery_init(); 999 | services_init(); 1000 | advertising_init(); 1001 | peer_manager_init(); 1002 | } 1003 | 1004 | 1005 | /**@brief Function for application main entry. 1006 | */ 1007 | void blinker_ble_init(blinker_callback_with_string_arg_t func) 1008 | // int blinker_ble_init(void) 1009 | { 1010 | blinker_parse_func = func; 1011 | // Initialize. 1012 | modules_init(); 1013 | 1014 | // Start execution. 1015 | NRF_LOG_INFO("GATT Service client started."); 1016 | advertising_start(m_erase_bonds); 1017 | 1018 | // Enter main loop. 1019 | for (;;) 1020 | { 1021 | idle_state_handle(); 1022 | } 1023 | } 1024 | 1025 | 1026 | /** 1027 | * @} 1028 | */ 1029 | 1030 | #endif 1031 | -------------------------------------------------------------------------------- /Blinker/BlinkerBLE.h: -------------------------------------------------------------------------------- 1 | #ifndef BLINKER_BLE_H__ 2 | #define BLINKER_BLE_H__ 3 | 4 | #include "sdk_common.h" 5 | #include 6 | #include 7 | #include "stdlib.h" 8 | #include "BlinkerUtility.h" 9 | #include "BlinkerDebug.h" 10 | #include "ble_bts.h" 11 | #if NRF_MODULE_ENABLED(BLINKER_BLE) 12 | void blinker_ble_flush(void); 13 | void blinker_ble_init(blinker_callback_with_string_arg_t func); 14 | void blinker_ble_print(char * data, bool need_check); 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /Blinker/BlinkerConfig.h: -------------------------------------------------------------------------------- 1 | #ifndef BLINKER_CONFIG_H__ 2 | #define BLINKER_CONFIG_H__ 3 | 4 | #define BLINKER_VERSION "0.1.0" 5 | 6 | #define BLINKER_CONNECT_TIMEOUT_MS 10000UL 7 | 8 | #define BLINKER_STREAM_TIMEOUT 100 9 | 10 | #define BLINKER_NTP_TIMEOUT 1000UL 11 | 12 | #define BLINKER_GPS_MSG_LIMIT 30000UL 13 | 14 | #define BLINKER_PRINT_MSG_LIMIT 20 15 | 16 | #define BLINKER_MQTT_MSG_LIMIT 1000UL 17 | 18 | #define BLINKER_PRO_MSG_LIMIT 200UL 19 | 20 | #define BLINKER_MQTT_CONNECT_TIMESLOT 5000UL 21 | 22 | #define BLINKER_BRIDGE_MSG_LIMIT 10000UL 23 | 24 | #define BLINKER_LINK_MSG_LIMIT 10000UL 25 | 26 | #define BLINKER_MQTT_KEEPALIVE 30000UL 27 | 28 | #define BLINKER_SMS_MSG_LIMIT 60000UL 29 | 30 | #define BLINKER_PUSH_MSG_LIMIT 60000UL 31 | 32 | #define BLINKER_WECHAT_MSG_LIMIT 60000UL 33 | 34 | #define BLINKER_WEATHER_MSG_LIMIT 60000UL 35 | 36 | #define BLINKER_AQI_MSG_LIMIT 60000UL 37 | 38 | #define BLINKER_CONFIG_UPDATE_LIMIT 10000UL 39 | 40 | #define BLINKER_CONFIG_GET_LIMIT 10000UL 41 | 42 | #define BLINKER_WIFI_AUTO_INIT_TIMEOUT 20000UL 43 | 44 | #define BLINKER_AT_MSG_TIMEOUT 1000UL 45 | 46 | #define BLINKER_SERVER_CONNECT_LIMIT 12 47 | 48 | #if defined(BLINKER_DATA_HOUR_UPDATE) 49 | #define BLINKER_DATA_FREQ_TIME 3600UL 50 | #else 51 | #define BLINKER_DATA_FREQ_TIME 60 52 | #endif 53 | 54 | #define BLINKER_DEVICE_HEARTBEAT_TIME 600 55 | 56 | #define BLINKER_MDNS_SERVICE_BLINKER "blinker" 57 | 58 | #define BLINKER_ERROR 0x00 59 | 60 | #define BLINKER_SUCCESS 0x01 61 | 62 | #define BLINKER_MSG_FROM_MQTT 0 63 | 64 | #define BLINKER_MSG_FROM_WS 1 65 | 66 | #define BLINKER_MSG_AUTOFORMAT_TIMEOUT 100 67 | 68 | #define BLINKER_CMD_ON "on" 69 | 70 | #define BLINKER_CMD_OFF "off" 71 | 72 | #define BLINKER_CMD_TRUE "true" 73 | 74 | #define BLINKER_CMD_FALSE "false" 75 | 76 | #define BLINKER_CMD_JOYSTICK "joy" 77 | 78 | #define BLINKER_CMD_GYRO "gyro" 79 | 80 | #define BLINKER_CMD_AHRS "ahrs" 81 | 82 | #define BLINKER_CMD_GPS "gps" 83 | 84 | #define BLINKER_CMD_RGB "rgb" 85 | 86 | #define BLINKER_CMD_VIBRATE "vibrate" 87 | 88 | #define BLINKER_CMD_BUTTON_TAP "tap" 89 | 90 | #define BLINKER_CMD_BUTTON_PRESSED "press" 91 | 92 | #define BLINKER_CMD_BUTTON_RELEASED "pressup" 93 | 94 | #define BLINKER_CMD_BUTTON_PRESS "press" 95 | 96 | #define BLINKER_CMD_BUTTON_PRESSUP "pressup" 97 | 98 | #define BLINKER_CMD_NEWLINE "\n" 99 | 100 | #define BLINKER_CMD_INTERSPACE " " 101 | 102 | #define BLINKER_CMD_DATA "data" 103 | 104 | #define BLINKER_CMD_FREQ "freq" 105 | 106 | #define BLINKER_CMD_GET "get" 107 | 108 | #define BLINKER_CMD_SET "set" 109 | 110 | #define BLINKER_CMD_STATE "state" 111 | 112 | #define BLINKER_CMD_ONLINE "online" 113 | 114 | #define BLINKER_CMD_CONNECTED "connected" 115 | 116 | #define BLINKER_CMD_VERSION "version" 117 | 118 | #define BLINKER_CMD_NOTICE "notice" 119 | 120 | #define BLINKER_CMD_BUILTIN_SWITCH "switch" 121 | 122 | #define BLINKER_CMD_FROMDEVICE "fromDevice" 123 | 124 | #define BLINKER_CMD_NOTFOUND "device not found" 125 | 126 | #define BLINKER_CMD_COMMAND "cmd" 127 | 128 | #define BLINKER_CMD_EVENT "event" 129 | 130 | #define BLINKER_CMD_AUTO "auto" 131 | 132 | #define BLINKER_CMD_AUTOID "autoId" 133 | 134 | #define BLINKER_CMD_ID "id" 135 | 136 | #define BLINKER_CMD_AUTODATA "autoData" 137 | 138 | #define BLINKER_CMD_DELETID "deletId" 139 | 140 | #define BLINKER_CMD_LOGIC "logic" 141 | 142 | #define BLINKER_CMD_LOGICDATA "logicData" 143 | 144 | #define BLINKER_CMD_LOGICTYPE "logicType" 145 | 146 | #define BLINKER_CMD_LESS "<"//"less" 147 | 148 | #define BLINKER_CMD_EQUAL "="//"equal" 149 | 150 | #define BLINKER_CMD_GREATER ">"//"greater" 151 | 152 | #define BLINKER_CMD_NUMBERIC "numberic" 153 | 154 | #define BLINKER_CMD_OR "or" 155 | 156 | #define BLINKER_CMD_AND "and" 157 | 158 | #define BLINKER_CMD_COMPARETYPE "compareType" 159 | 160 | #define BLINKER_CMD_TRIGGER "trigger" 161 | 162 | #define BLINKER_CMD_DURATION "duration" 163 | 164 | #define BLINKER_CMD_TARGETKEY "targetKey" 165 | 166 | #define BLINKER_CMD_TARGETSTATE "targetState" 167 | 168 | #define BLINKER_CMD_TARGETDATA "targetData" 169 | 170 | #define BLINKER_CMD_TIMESLOT "timeSlot" 171 | 172 | #define BLINKER_CMD_RANGE "range" 173 | 174 | #define BLINKER_CMD_LINKDEVICE "linkDevice" 175 | 176 | #define BLINKER_CMD_LINKTYPE "linkType" 177 | 178 | #define BLINKER_CMD_LINKDATA "linkData" 179 | 180 | #define BLINKER_CMD_TRIGGEDDATA "triggedData" 181 | 182 | #define BLINKER_CMD_TYPE "type" 183 | 184 | #define BLINKER_CMD_TIMER "timer" 185 | 186 | #define BLINKER_CMD_RUN "run" 187 | 188 | #define BLINKER_CMD_ENABLE "ena" 189 | 190 | #define BLINKER_CMD_COUNTDOWN "countdown" 191 | 192 | #define BLINKER_CMD_COUNTDOWNDATA "countdownData" 193 | 194 | #define BLINKER_CMD_TOTALTIME "ttim" 195 | 196 | #define BLINKER_CMD_RUNTIME "rtim" 197 | 198 | #define BLINKER_CMD_ACTION "act" 199 | 200 | #define BLINKER_CMD_ACTION1 "act1" 201 | 202 | #define BLINKER_CMD_ACTION2 "act2" 203 | 204 | #define BLINKER_CMD_LOOP "loop" 205 | 206 | #define BLINKER_CMD_LOOPDATA "loopData" 207 | 208 | #define BLINKER_CMD_TIME "tim" 209 | 210 | #define BLINKER_CMD_TIME_ALL "time" 211 | 212 | #define BLINKER_CMD_TIMES "tis" 213 | 214 | #define BLINKER_CMD_TRIGGED "tri" 215 | 216 | #define BLINKER_CMD_TIME1 "dur1" 217 | 218 | #define BLINKER_CMD_TIME2 "dur2" 219 | 220 | #define BLINKER_CMD_TIMING "timing" 221 | 222 | #define BLINKER_CMD_TIMINGDATA "timingData" 223 | 224 | #define BLINKER_CMD_DAY "day" 225 | 226 | #define BLINKER_CMD_TASK "task" 227 | 228 | #define BLINKER_CMD_DELETETASK "dlt" 229 | 230 | #define BLINKER_CMD_DELETE "dlt" 231 | 232 | #define BLINKER_CMD_DETAIL "detail" 233 | 234 | #define BLINKER_CMD_OK "OK" 235 | 236 | #define BLINKER_CMD_ERROR "ERROR" 237 | 238 | #define BLINKER_CMD_MESSAGE "message" 239 | 240 | #define BLINKER_CMD_DEVICENAME "deviceName" 241 | 242 | #define BLINKER_CMD_AUTHKEY "authKey" 243 | 244 | #define BLINKER_CMD_IOTID "iotId" 245 | 246 | #define BLINKER_CMD_IOTTOKEN "iotToken" 247 | 248 | #define BLINKER_CMD_PRODUCTKEY "productKey" 249 | 250 | #define BLINKER_CMD_BROKER "broker" 251 | 252 | #define BLINKER_CMD_UUID "uuid" 253 | 254 | #define BLINKER_CMD_KEY "key" 255 | 256 | #define BLINKER_CMD_SMS "sms" 257 | 258 | #define BLINKER_CMD_PUSH "push" 259 | 260 | #define BLINKER_CMD_WECHAT "wechat" 261 | 262 | #define BLINKER_CMD_WEATHER "weather" 263 | 264 | #define BLINKER_CMD_AQI "aqi" 265 | 266 | #define BLINKER_CMD_CONFIG "config" 267 | 268 | #define BLINKER_CMD_DEFAULT "default" 269 | 270 | #define BLINKER_CMD_SWITCH "swi" 271 | 272 | #define BLINKER_CMD_VALUE "val" 273 | 274 | #define BLINKER_CMD_ICON "ico" 275 | 276 | #define BLINKER_CMD_COLOR "clr" 277 | 278 | #define BLINKER_CMD_COLOR_ "col" 279 | 280 | #define BLINKER_CMD_TITLE "tit" 281 | 282 | #define BLINKER_CMD_CONTENT "con" 283 | 284 | #define BLINKER_CMD_TEXT "tex" 285 | 286 | #define BLINKER_CMD_TEXT1 "tex1" 287 | 288 | #define BLINKER_CMD_TEXTCOLOR "tco" 289 | 290 | #define BLINKER_CMD_UNIT "uni" 291 | 292 | #define BLINKER_CMD_SUMMARY "sum" 293 | 294 | #define BLINKER_CMD_POWERSTATE "pState" 295 | 296 | #define BLINKER_CMD_NUM "num" 297 | 298 | #define BLINKER_CMD_BRIGHTNESS "bright" 299 | 300 | #define BLINKER_CMD_UPBRIGHTNESS "upBright" 301 | 302 | #define BLINKER_CMD_DOWNBRIGHTNESS "downBright" 303 | 304 | #define BLINKER_CMD_COLORTEMP "colTemp" 305 | 306 | #define BLINKER_CMD_UPCOLORTEMP "upColTemp" 307 | 308 | #define BLINKER_CMD_DOWNCOLORTEMP "downColTemp" 309 | 310 | #define BLINKER_CMD_TEMP "temp" 311 | 312 | #define BLINKER_CMD_HUMI "humi" 313 | 314 | #define BLINKER_CMD_PM25 "pm25" 315 | 316 | #define BLINKER_CMD_PM10 "pm10" 317 | 318 | #define BLINKER_CMD_CO2 "co2" 319 | 320 | #define BLINKER_CMD_MAX "max" 321 | 322 | #define BLINKER_CMD_MIN "min" 323 | 324 | #define BLINKER_CMD_MODE "mode" 325 | 326 | #define BLINKER_CMD_CANCELMODE "cMode" 327 | 328 | #define BLINKER_CMD_READING "reading" 329 | 330 | #define BLINKER_CMD_MOVIE "movie" 331 | 332 | #define BLINKER_CMD_SLEEP "sleep" 333 | 334 | #define BLINKER_CMD_HOLIDAY "holiday" 335 | 336 | #define BLINKER_CMD_MUSIC "music" 337 | 338 | #define BLINKER_CMD_COMMON "common" 339 | 340 | #define BLINKER_CMD_ALIGENIE_READING "reading" 341 | 342 | #define BLINKER_CMD_ALIGENIE_MOVIE "movie" 343 | 344 | #define BLINKER_CMD_ALIGENIE_SLEEP "sleep" 345 | 346 | #define BLINKER_CMD_ALIGENIE_HOLIDAY "holiday" 347 | 348 | #define BLINKER_CMD_ALIGENIE_MUSIC "music" 349 | 350 | #define BLINKER_CMD_ALIGENIE_COMMON "common" 351 | 352 | #define BLINKER_CMD_DUEROS_READING "READING" 353 | 354 | #define BLINKER_CMD_DUEROS_SLEEP "SLEEP" 355 | 356 | #define BLINKER_CMD_DUEROS_ALARM "ALARM" 357 | 358 | #define BLINKER_CMD_DUEROS_NIGHT_LIGHT "NIGHT_LIGHT" 359 | 360 | #define BLINKER_CMD_DUEROS_ROMANTIC "ROMANTIC" 361 | 362 | #define BLINKER_CMD_DUEROS_SUNDOWN "SUNDOWN" 363 | 364 | #define BLINKER_CMD_DUEROS_SUNRISE "SUNRISE" 365 | 366 | #define BLINKER_CMD_DUEROS_RELAX "RELAX" 367 | 368 | #define BLINKER_CMD_DUEROS_LIGHTING "LIGHTING" 369 | 370 | #define BLINKER_CMD_DUEROS_SUN "SUN" 371 | 372 | #define BLINKER_CMD_DUEROS_STAR "STAR" 373 | 374 | #define BLINKER_CMD_DUEROS_ENERGY_SAVING "ENERGY_SAVING" 375 | 376 | #define BLINKER_CMD_DUEROS_MOON "MOON" 377 | 378 | #define BLINKER_CMD_DUEROS_JUDI "JUDI" 379 | 380 | #define BLINKER_CMD_MIOT_DAY 0 381 | 382 | #define BLINKER_CMD_MIOT_NIGHT 1 383 | 384 | #define BLINKER_CMD_MIOT_COLOR 2 385 | 386 | #define BLINKER_CMD_MIOT_WARMTH 3 387 | 388 | #define BLINKER_CMD_MIOT_TV 4 389 | 390 | #define BLINKER_CMD_MIOT_READING 5 391 | 392 | #define BLINKER_CMD_MIOT_COMPUTER 6 393 | 394 | #define BLINKER_CMD_UPGRADE "upgrade" 395 | 396 | #define BLINKER_CMD_SHARE "share" 397 | 398 | #define BLINKER_CMD_AUTO_UPDATE_KEY "upKey" 399 | 400 | #define BLINKER_CMD_CANCEL_UPDATE_KEY "cKey" 401 | 402 | #define BLINKER_CMD_ALIGENIE "AliGenie" 403 | 404 | #define BLINKER_CMD_DUEROS "DuerOS" 405 | 406 | #define BLINKER_CMD_MIOT "MIOT" 407 | 408 | #define BLINKER_CMD_SERVERCLIENT "serverClient" 409 | 410 | #define BLINKER_CMD_HELLO "hello" 411 | 412 | // #define BLINKER_CMD_WHOIS "whois" 413 | 414 | #define BLINKER_CMD_AT "AT" 415 | 416 | #define BLINKER_CMD_GATE "gate" 417 | 418 | #define BLINKER_CMD_CONTROL "ctrl" 419 | 420 | #define BLINKER_CMD_DEVICEINFO "dInf" 421 | 422 | #define BLINKER_CMD_NEW "{\"hello\":\"new\"}" 423 | 424 | #define BLINKER_CMD_WHOIS "{\"hello\":\"whois\"}" 425 | 426 | #define BLINKER_CMD_TAB_0 16 // 0x10000 427 | 428 | #define BLINKER_CMD_TAB_1 8 // 0x01000 429 | 430 | #define BLINKER_CMD_TAB_2 4 // 0x00100 431 | 432 | #define BLINKER_CMD_TAB_3 2 // 0x00010 433 | 434 | #define BLINKER_CMD_TAB_4 1 // 0x00001 435 | 436 | // #define BLINKER_SERVER_HOST "iot.diandeng.tech" 437 | 438 | #define BLINKER_SERVER_PORT 443 439 | 440 | #define BLINKER_MQTT_BORKER_ALIYUN "aliyun" 441 | 442 | #define BLINKER_MQTT_ALIYUN_URL "mqtts://public.iot-as-mqtt.cn-shanghai.aliyuncs.com:1883" 443 | 444 | #define BLINKER_MQTT_ALIYUN_HOST "public.iot-as-mqtt.cn-shanghai.aliyuncs.com" 445 | 446 | #define BLINKER_MQTT_ALIYUN_PORT 1883 447 | 448 | #define BLINKER_MSG_FROM_MQTT 0 449 | 450 | #define BLINKER_MSG_FROM_WS 1 451 | 452 | #define BLINKER_MAX_READ_SIZE 128 453 | 454 | #define BLINKER_MAX_SEND_SIZE 128 455 | 456 | #define BLINKER_MAX_WIDGET_SIZE 16 457 | 458 | #define BLINKER_OBJECT_NOT_AVAIL -1 459 | 460 | // #define false 0 461 | 462 | // #define true 1 463 | 464 | #define BLINKER_ALIGENIE_LIGHT "&aliType=light" 465 | 466 | #define BLINKER_ALIGENIE_OUTLET "&aliType=outlet" 467 | 468 | #define BLINKER_ALIGENIE_MULTI_OUTLET "&aliType=multi_outlet" 469 | 470 | #define BLINKER_ALIGENIE_SENSOR "&aliType=sensor" 471 | 472 | #define BLINKER_DUEROS_LIGHT "&duerType=LIGHT" 473 | 474 | #define BLINKER_DUEROS_OUTLET "&duerType=SOCKET" 475 | 476 | #define BLINKER_DUEROS_MULTI_OUTLET "&duerType=MULTI_SOCKET" 477 | 478 | #define BLINKER_DUEROS_SENSOR "&duerType=AIR_MONITOR" 479 | 480 | #define BLINKER_MIOT_LIGHT "&miType=light" 481 | 482 | #define BLINKER_MIOT_OUTLET "&miType=outlet" 483 | 484 | #define BLINKER_MIOT_MULTI_OUTLET "&miType=multi_outlet" 485 | 486 | #define BLINKER_MIOT_SENSOR "&miType=sensor" 487 | 488 | #define BLINKER_CMD_MODE_READING_NUMBER 0 489 | 490 | #define BLINKER_CMD_MODE_MOVIE_NUMBER 1 491 | 492 | #define BLINKER_CMD_SLEEP_NUMBER 2 493 | 494 | #define BLINKER_CMD_HOLIDAY_NUMBER 3 495 | 496 | #define BLINKER_CMD_MUSIC_NUMBER 4 497 | 498 | #define BLINKER_CMD_COMMON_NUMBER 5 499 | 500 | #define BLINKER_CMD_QUERY_ALL_NUMBER 0 501 | 502 | #define BLINKER_CMD_QUERY_POWERSTATE_NUMBER 1 503 | 504 | #define BLINKER_CMD_QUERY_COLOR_NUMBER 2 505 | 506 | #define BLINKER_CMD_QUERY_MODE_NUMBER 3 507 | 508 | #define BLINKER_CMD_QUERY_COLORTEMP_NUMBER 4 509 | 510 | #define BLINKER_CMD_QUERY_BRIGHTNESS_NUMBER 5 511 | 512 | #define BLINKER_CMD_QUERY_TEMP_NUMBER 6 513 | 514 | #define BLINKER_CMD_QUERY_HUMI_NUMBER 7 515 | 516 | #define BLINKER_CMD_QUERY_PM25_NUMBER 8 517 | 518 | #define BLINKER_CMD_QUERY_PM10_NUMBER 9 519 | 520 | #define BLINKER_CMD_QUERY_CO2_NUMBER 10 521 | 522 | #define BLINKER_CMD_QUERY_AQI_NUMBER 11 523 | 524 | #define BLINKER_CMD_QUERY_TIME_NUMBER 12 525 | 526 | #define BLINKER_CMD_SMS_NUMBER 1 527 | 528 | #define BLINKER_CMD_PUSH_NUMBER 2 529 | 530 | #define BLINKER_CMD_WECHAT_NUMBER 3 531 | 532 | #define BLINKER_CMD_WEATHER_NUMBER 4 533 | 534 | #define BLINKER_CMD_AQI_NUMBER 5 535 | 536 | #define BLINKER_CMD_BRIDGE_NUMBER 6 537 | 538 | #define BLINKER_CMD_CONFIG_UPDATE_NUMBER 7 539 | 540 | #define BLINKER_CMD_CONFIG_GET_NUMBER 8 541 | 542 | #define BLINKER_CMD_CONFIG_DELETE_NUMBER 9 543 | 544 | #define BLINKER_CMD_DATA_STORAGE_NUMBER 10 545 | 546 | #define BLINKER_CMD_DATA_GET_NUMBER 11 547 | 548 | #define BLINKER_CMD_DATA_DELETE_NUMBER 12 549 | 550 | #define BLINKER_CMD_AUTO_PULL_NUMBER 13 551 | 552 | #define BLINKER_CMD_OTA_NUMBER 14 553 | 554 | #define BLINKER_CMD_OTA_STATUS_NUMBER 15 555 | 556 | #define BLINKER_CMD_FRESH_SHARERS_NUMBER 16 557 | 558 | #define BLINKER_CMD_LOWPOWER_FREQ_GET_NUM 17 559 | 560 | #define BLINKER_CMD_LOWPOWER_FREQ_UP_NUMBER 18 561 | 562 | #define BLINKER_CMD_LOWPOWER_DATA_GET_NUM 19 563 | 564 | #define BLINKER_CMD_LOWPOWER_DATA_UP_NUMBER 20 565 | 566 | #define BLINKER_CMD_EVENT_DATA_NUMBER 21 567 | 568 | #define BLINKER_CMD_GPS_DATA_NUMBER 22 569 | 570 | #define BLINKER_CMD_DEVICE_HEARTBEAT_NUMBER 23 571 | 572 | #define BLINKER_CMD_EVENT_WARNING_NUMBER 24 573 | 574 | #define BLINKER_CMD_EVENT_ERROR_NUMBER 25 575 | 576 | #define BLINKER_CMD_EVENT_MSG_NUMBER 26 577 | 578 | #define BLINKER_CMD_DEVICE_REGISTER_NUMBER 27 579 | 580 | #define BLINKER_CMD_DEVICE_AUTH_NUMBER 28 581 | 582 | #define BLINKER_CMD_DEFAULT_NUMBER 0 583 | 584 | #define BLINKER_MQTT_MAX_SHARERS_NUM 9 585 | 586 | #define BLINKER_MQTT_FROM_AUTHER BLINKER_MQTT_MAX_SHARERS_NUM 587 | 588 | #define BLINKER_MQTT_FORM_SERVER BLINKER_MQTT_MAX_SHARERS_NUM + 1 589 | 590 | #endif 591 | -------------------------------------------------------------------------------- /Blinker/BlinkerDebug.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blinker-iot/blinker-nRF52/5356e76299038f60587035f2b3dff3b9e62b23f1/Blinker/BlinkerDebug.c -------------------------------------------------------------------------------- /Blinker/BlinkerDebug.h: -------------------------------------------------------------------------------- 1 | #ifndef BLINKER_DEBUG_H__ 2 | #define BLINKER_DEBUG_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "nrf_log.h" 8 | #include "nrf_log_ctrl.h" 9 | #include "nrf_log_default_backends.h" 10 | 11 | #include "BlinkerUtility.h" 12 | 13 | // static bool is_debug_all = false; 14 | 15 | // void blinker_log_init(void) 16 | // { 17 | // ret_code_t err_code = NRF_LOG_INIT(NULL); 18 | 19 | // APP_ERROR_CHECK(err_code); 20 | 21 | // NRF_LOG_DEFAULT_BACKENDS_INIT(); 22 | // } 23 | 24 | // #define BLINKER_LOG_MODULE(...) { \ 25 | // printf("[%d]: ", blinker_millis()); \ 26 | // printf( __VA_ARGS__ ); \ 27 | // printf("\r\n"); \ 28 | // } 29 | 30 | // #define BLINKER_ERR_LOG_MODULE(...) { \ 31 | // printf("[%d]: ERROR: ", blinker_millis()); \ 32 | // printf( __VA_ARGS__ ); \ 33 | // printf("\r\n"); \ 34 | // } 35 | 36 | // #define BLINKER_LOG_ALL_MODULE(...) { \ 37 | // if (is_debug_all) { \ 38 | // BLINKER_LOG_MODULE(__VA_ARGS__); \ 39 | // } \ 40 | // } 41 | 42 | // #define BLINKER_DEBUG_ALL() is_debug_all = true; 43 | 44 | // #define BLINKER_LOG(...) BLINKER_LOG_MODULE( __VA_ARGS__ ); 45 | 46 | // #define BLINKER_LOG_ALL(...) BLINKER_LOG_ALL_MODULE( __VA_ARGS__ ); 47 | 48 | // #define BLINKER_ERR_LOG(...) BLINKER_ERR_LOG_MODULE( __VA_ARGS__ ); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /Blinker/BlinkerUtility.c: -------------------------------------------------------------------------------- 1 | #include "BlinkerUtility.h" 2 | 3 | int8_t isJson(const char *data) 4 | { 5 | if (data[0] != '{' || data[strlen(data) - 1] != '}') return 0; 6 | 7 | return 1; 8 | 9 | // cJSON *root = cJSON_Parse(data); 10 | 11 | // if (!root) 12 | // { 13 | // cJSON_Delete(root); 14 | // return 0; 15 | // } 16 | // else 17 | // { 18 | // cJSON_Delete(root); 19 | // return 1; 20 | // } 21 | 22 | } 23 | 24 | uint32_t blinker_millis(void) 25 | { 26 | return app_timer_cnt_get()* ( (1 + 1 ) * 1000 ) / APP_TIMER_CLOCK_FREQ; 27 | } 28 | 29 | void blinker_substring(char * dest, char * src, uint16_t left, uint16_t right) 30 | { 31 | memset(dest, '\0', strlen(dest)); 32 | 33 | uint16_t len = strlen(src); 34 | 35 | for (uint16_t num = left; num < right; num++) 36 | { 37 | dest[num - left] = src[num]; 38 | } 39 | } -------------------------------------------------------------------------------- /Blinker/BlinkerUtility.h: -------------------------------------------------------------------------------- 1 | #ifndef BLINKER_UTILITY_H__ 2 | #define BLINKER_UTILITY_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "app_timer.h" 8 | // #include "Blinker_cJSON.h" 9 | #include "cJSON.h" 10 | 11 | #include "BlinkerConfig.h" 12 | 13 | typedef void (*blinker_callback_t)(void); 14 | typedef void (*blinker_callback_with_arg_t)(void*); 15 | typedef void (*blinker_callback_with_json_arg_t)(const cJSON *data); 16 | typedef void (*blinker_callback_with_string_arg_t)(const char *data); 17 | typedef void (*blinker_callback_with_string_uint8_arg_t)(const char *data, uint8_t num); 18 | typedef void (*blinker_callback_with_int32_arg_t)(int32_t data); 19 | typedef void (*blinker_callback_with_uint8_arg_t)(uint8_t data); 20 | typedef void (*blinker_callback_with_tab_arg_t)(uint8_t data); 21 | typedef void (*blinker_callback_with_begin_t)(const char * k1, ...); 22 | typedef void (*blinker_callback_with_rgb_arg_t)(uint8_t r_data, uint8_t g_data, uint8_t b_data, uint8_t bright_data); 23 | typedef void (*blinker_callback_with_int32_uint8_arg_t)(int32_t data, uint8_t num); 24 | 25 | int8_t isJson(const char *data); 26 | uint32_t blinker_millis(void); 27 | void blinker_substring(char * dest, char * src, uint16_t left, uint16_t right); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Blinker/ble_bts.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012 - 2019, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | /* Attention! 41 | * To maintain compliance with Nordic Semiconductor ASA's Bluetooth profile 42 | * qualification listings, this section of source code must not be modified. 43 | */ 44 | #include "sdk_common.h" 45 | // #if NRF_MODULE_ENABLED(BLE_LLS) 46 | #include "ble_bts.h" 47 | #include 48 | #include "ble_hci.h" 49 | #include "ble_srv_common.h" 50 | 51 | 52 | 53 | 54 | 55 | /**@brief Function for handling the Connect event. 56 | * 57 | * @param[in] p_bts Link Loss Service structure. 58 | * @param[in] p_ble_evt Event received from the BLE stack. 59 | */ 60 | static void on_connect(ble_bts_t * p_bts, ble_evt_t const * p_ble_evt) 61 | { 62 | ret_code_t err_code; 63 | // Link reconnected, notify application with a no_alert event 64 | ble_bts_evt_t evt; 65 | 66 | ble_gatts_value_t gatts_val; 67 | uint8_t cccd_value[2]; 68 | ble_bts_client_context_t * p_client = NULL; 69 | 70 | // p_bts->conn_handle = p_ble_evt->evt.gap_evt.conn_handle; 71 | 72 | // evt.evt_type = BLE_LLS_EVT_LINK_LOSS_ALERT; 73 | // evt.params.alert_level = BLE_CHAR_ALERT_LEVEL_NO_ALERT; 74 | // p_bts->evt_handler(p_bts, &evt); 75 | 76 | err_code = blcm_link_ctx_get(p_bts->p_link_ctx_storage, 77 | p_ble_evt->evt.gap_evt.conn_handle, 78 | (void *) &p_client); 79 | if (err_code != NRF_SUCCESS) 80 | { 81 | NRF_LOG_ERROR("Link context for 0x%02X connection handle could not be fetched.", 82 | p_ble_evt->evt.gap_evt.conn_handle); 83 | } 84 | 85 | NRF_LOG_INFO("on_connect NRF_SUCCESS"); 86 | 87 | /* Check the hosts CCCD value to inform of readiness to send data using the RX characteristic */ 88 | memset(&gatts_val, 0, sizeof(ble_gatts_value_t)); 89 | gatts_val.p_value = cccd_value; 90 | gatts_val.len = sizeof(cccd_value); 91 | gatts_val.offset = 0; 92 | 93 | // err_code = sd_ble_gatts_value_get(p_ble_evt->evt.gap_evt.conn_handle, 94 | // p_bts->tx_handles.cccd_handle, 95 | // &gatts_val); 96 | err_code = sd_ble_gatts_value_get(p_ble_evt->evt.gap_evt.conn_handle, 97 | p_bts->tx_rx_handles.cccd_handle, 98 | &gatts_val); 99 | 100 | if ((err_code == NRF_SUCCESS) && 101 | (p_bts->data_handler != NULL) && 102 | ble_srv_is_notification_enabled(gatts_val.p_value)) 103 | { 104 | if (p_client != NULL) 105 | { 106 | p_client->is_notification_enabled = true; 107 | } 108 | 109 | memset(&evt, 0, sizeof(ble_bts_evt_t)); 110 | evt.evt_type = BLE_BTS_EVT_COMM_STARTED; 111 | evt.p_bts = p_bts; 112 | evt.conn_handle = p_ble_evt->evt.gap_evt.conn_handle; 113 | evt.p_link_ctx = p_client; 114 | 115 | p_bts->data_handler(&evt); 116 | } 117 | } 118 | 119 | 120 | /**@brief Function for handling the @ref BLE_GATTS_EVT_WRITE event from the SoftDevice. 121 | * 122 | * @param[in] p_bts Nordic UART Service structure. 123 | * @param[in] p_ble_evt Pointer to the event received from BLE stack. 124 | */ 125 | static void on_write(ble_bts_t * p_bts, ble_evt_t const * p_ble_evt) 126 | { 127 | ret_code_t err_code; 128 | ble_bts_evt_t evt; 129 | ble_bts_client_context_t * p_client; 130 | ble_gatts_evt_write_t const * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; 131 | 132 | err_code = blcm_link_ctx_get(p_bts->p_link_ctx_storage, 133 | p_ble_evt->evt.gatts_evt.conn_handle, 134 | (void *) &p_client); 135 | if (err_code != NRF_SUCCESS) 136 | { 137 | NRF_LOG_INFO("Link context for 0x%02X connection handle could not be fetched.", 138 | p_ble_evt->evt.gatts_evt.conn_handle); 139 | } 140 | NRF_LOG_INFO("on_write NRF_SUCCESS"); 141 | 142 | memset(&evt, 0, sizeof(ble_bts_evt_t)); 143 | evt.p_bts = p_bts; 144 | evt.conn_handle = p_ble_evt->evt.gatts_evt.conn_handle; 145 | evt.p_link_ctx = p_client; 146 | 147 | // if ((p_evt_write->handle == p_bts->tx_handles.cccd_handle) && 148 | // (p_evt_write->len == 2)) 149 | if ((p_evt_write->handle == p_bts->tx_rx_handles.cccd_handle) && 150 | (p_evt_write->len == 2)) 151 | { 152 | NRF_LOG_INFO("on_write if 1"); 153 | if (p_client != NULL) 154 | { 155 | if (ble_srv_is_notification_enabled(p_evt_write->data)) 156 | { 157 | p_client->is_notification_enabled = true; 158 | evt.evt_type = BLE_BTS_EVT_COMM_STARTED; 159 | } 160 | else 161 | { 162 | p_client->is_notification_enabled = false; 163 | evt.evt_type = BLE_BTS_EVT_COMM_STOPPED; 164 | } 165 | 166 | if (p_bts->data_handler != NULL) 167 | { 168 | p_bts->data_handler(&evt); 169 | } 170 | 171 | } 172 | } 173 | else if ((p_evt_write->handle == p_bts->tx_rx_handles.value_handle) && 174 | (p_bts->data_handler != NULL)) 175 | // else if ((p_evt_write->handle == p_bts->rx_handles.value_handle) && 176 | // (p_bts->data_handler != NULL)) 177 | { 178 | NRF_LOG_INFO("on_write else if 2"); 179 | evt.evt_type = BLE_BTS_EVT_RX_DATA; 180 | evt.params.rx_data.p_data = p_evt_write->data; 181 | evt.params.rx_data.length = p_evt_write->len; 182 | 183 | p_bts->data_handler(&evt); 184 | } 185 | else 186 | { 187 | NRF_LOG_INFO("on_write else 3"); 188 | // Do Nothing. This event is not relevant for this service. 189 | } 190 | } 191 | 192 | 193 | /**@brief Function for handling the Disconnect event. 194 | * 195 | * @param[in] p_bts Link Loss Service structure. 196 | * @param[in] p_ble_evt Event received from the BLE stack. 197 | */ 198 | // static void on_disconnect(ble_bts_t * p_bts, ble_evt_t const * p_ble_evt) 199 | // { 200 | // uint8_t reason = p_ble_evt->evt.gap_evt.params.disconnected.reason; 201 | 202 | // if (reason == BLE_HCI_CONNECTION_TIMEOUT) 203 | // { 204 | // // Link loss detected, notify application 205 | // uint32_t err_code; 206 | // ble_bts_evt_t evt; 207 | 208 | // evt.evt_type = BLE_LLS_EVT_LINK_LOSS_ALERT; 209 | 210 | // err_code = ble_bts_alert_level_get(p_bts, &evt.params.alert_level); 211 | // if (err_code == NRF_SUCCESS) 212 | // { 213 | // p_bts->evt_handler(p_bts, &evt); 214 | // } 215 | // else 216 | // { 217 | // if (p_bts->error_handler != NULL) 218 | // { 219 | // p_bts->error_handler(err_code); 220 | // } 221 | // } 222 | // } 223 | // } 224 | 225 | 226 | /**@brief Function for handling the Authentication Status event. 227 | * 228 | * @param[in] p_bts Link Loss Service structure. 229 | * @param[in] p_ble_evt Event received from the BLE stack. 230 | */ 231 | // static void on_auth_status(ble_bts_t * p_bts, ble_evt_t const * p_ble_evt) 232 | // { 233 | // if (p_ble_evt->evt.gap_evt.params.auth_status.auth_status == BLE_GAP_SEC_STATUS_SUCCESS) 234 | // { 235 | // ble_bts_evt_t evt; 236 | 237 | // evt.evt_type = BLE_LLS_EVT_LINK_LOSS_ALERT; 238 | // evt.params.alert_level = BLE_CHAR_ALERT_LEVEL_NO_ALERT; 239 | 240 | // p_bts->evt_handler(p_bts, &evt); 241 | // } 242 | // } 243 | 244 | 245 | /**@brief Function for handling the @ref BLE_GATTS_EVT_HVN_TX_COMPLETE event from the SoftDevice. 246 | * 247 | * @param[in] p_bts Nordic UART Service structure. 248 | * @param[in] p_ble_evt Pointer to the event received from BLE stack. 249 | */ 250 | static void on_hvx_tx_complete(ble_bts_t * p_bts, ble_evt_t const * p_ble_evt) 251 | { 252 | ret_code_t err_code; 253 | ble_bts_evt_t evt; 254 | ble_bts_client_context_t * p_client; 255 | 256 | err_code = blcm_link_ctx_get(p_bts->p_link_ctx_storage, 257 | p_ble_evt->evt.gatts_evt.conn_handle, 258 | (void *) &p_client); 259 | if (err_code != NRF_SUCCESS) 260 | { 261 | NRF_LOG_ERROR("Link context for 0x%02X connection handle could not be fetched.", 262 | p_ble_evt->evt.gatts_evt.conn_handle); 263 | return; 264 | } 265 | 266 | if (p_client->is_notification_enabled) 267 | { 268 | memset(&evt, 0, sizeof(ble_bts_evt_t)); 269 | evt.evt_type = BLE_BTS_EVT_TX_RDY; 270 | evt.p_bts = p_bts; 271 | evt.conn_handle = p_ble_evt->evt.gatts_evt.conn_handle; 272 | evt.p_link_ctx = p_client; 273 | 274 | // p_bts->data_handler(&evt); 275 | } 276 | } 277 | 278 | 279 | void ble_bts_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context) 280 | { 281 | ble_bts_t * p_bts = (ble_bts_t *)p_context; 282 | 283 | if (p_bts == NULL || p_ble_evt == NULL) 284 | { 285 | return; 286 | } 287 | 288 | switch (p_ble_evt->header.evt_id) 289 | { 290 | case BLE_GAP_EVT_CONNECTED: 291 | on_connect(p_bts, p_ble_evt); 292 | NRF_LOG_INFO("BLE_GAP_EVT_CONNECTED"); 293 | break; 294 | 295 | case BLE_GATTS_EVT_WRITE: 296 | on_write(p_bts, p_ble_evt); 297 | NRF_LOG_INFO("BLE_GATTS_EVT_WRITE"); 298 | break; 299 | 300 | case BLE_GAP_EVT_DISCONNECTED: 301 | // on_disconnect(p_bts, p_ble_evt); 302 | NRF_LOG_INFO("BLE_GAP_EVT_DISCONNECTED"); 303 | break; 304 | 305 | case BLE_GAP_EVT_AUTH_STATUS: 306 | // on_auth_status(p_bts, p_ble_evt); 307 | NRF_LOG_INFO("BLE_GAP_EVT_AUTH_STATUS"); 308 | break; 309 | 310 | case BLE_GATTS_EVT_HVN_TX_COMPLETE: 311 | on_hvx_tx_complete(p_bts, p_ble_evt); 312 | break; 313 | 314 | default: 315 | // No implementation needed. 316 | break; 317 | } 318 | } 319 | 320 | 321 | uint32_t ble_bts_init(ble_bts_t * p_bts, const ble_bts_init_t * p_bts_init) 322 | { 323 | uint32_t err_code; 324 | ble_uuid_t ble_uuid; 325 | ble_add_char_params_t add_char_params; 326 | 327 | if (p_bts == NULL || p_bts_init == NULL) 328 | { 329 | return NRF_ERROR_NULL; 330 | } 331 | 332 | if (p_bts_init->data_handler == NULL) 333 | { 334 | return NRF_ERROR_INVALID_PARAM; 335 | } 336 | 337 | // Initialize service structure 338 | // p_bts->evt_handler = p_bts_init->evt_handler; 339 | // p_bts->error_handler = p_bts_init->error_handler; 340 | p_bts->data_handler = p_bts_init->data_handler; 341 | 342 | // Add service 343 | // BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_LINK_LOSS_SERVICE); 344 | BLE_UUID_BLE_ASSIGN(ble_uuid, 0xFFE0); 345 | 346 | err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, 347 | &ble_uuid, 348 | &p_bts->service_handle); 349 | // if (err_code != NRF_SUCCESS) 350 | // { 351 | // return err_code; 352 | // } 353 | 354 | VERIFY_SUCCESS(err_code); 355 | 356 | // Add alert level characteristic 357 | memset(&add_char_params, 0, sizeof(add_char_params)); 358 | 359 | add_char_params.uuid = 0xFFE1;//BLE_UUID_ALERT_LEVEL_CHAR; 360 | add_char_params.uuid_type = p_bts->uuid_type; 361 | add_char_params.max_len = 20;//sizeof(uint8_t); 362 | add_char_params.char_props.read = 1; 363 | // add_char_params.char_props.write = 1; 364 | add_char_params.char_props.write_wo_resp = 1; 365 | add_char_params.char_props.notify = 1; 366 | add_char_params.write_access = 1;//p_bts_init->alert_level_wr_sec; 367 | add_char_params.read_access = 1;//p_bts_init->alert_level_rd_sec; 368 | add_char_params.cccd_write_access= 1; 369 | add_char_params.init_len = sizeof(uint8_t); 370 | add_char_params.is_var_len = true; 371 | //add_char_params.p_init_value = (uint8_t *) &(p_bts_init->initial_alert_level); 372 | 373 | return characteristic_add(p_bts->service_handle, 374 | &add_char_params, 375 | &p_bts->tx_rx_handles); 376 | } 377 | 378 | 379 | // uint32_t ble_bts_alert_level_get(ble_bts_t * p_bts, uint8_t * p_alert_level) 380 | // { 381 | // ble_gatts_value_t gatts_value; 382 | 383 | // if (p_bts == NULL || p_alert_level == NULL) 384 | // { 385 | // return NRF_ERROR_NULL; 386 | // } 387 | 388 | // // Initialize value struct. 389 | // memset(&gatts_value, 0, sizeof(gatts_value)); 390 | 391 | // gatts_value.len = sizeof(uint8_t); 392 | // gatts_value.offset = 0; 393 | // gatts_value.p_value = p_alert_level; 394 | 395 | // return sd_ble_gatts_value_get(p_bts->conn_handle, 396 | // p_bts->alert_level_handles.value_handle, 397 | // &gatts_value); 398 | // } 399 | 400 | 401 | uint32_t ble_bts_data_send(ble_bts_t * p_bts, 402 | uint8_t * p_data, 403 | uint16_t * p_length, 404 | uint16_t conn_handle) 405 | { 406 | ret_code_t err_code; 407 | ble_gatts_hvx_params_t hvx_params; 408 | ble_bts_client_context_t * p_client; 409 | 410 | NRF_LOG_INFO("ble_bts_data_send in"); 411 | 412 | VERIFY_PARAM_NOT_NULL(p_bts); 413 | 414 | err_code = blcm_link_ctx_get(p_bts->p_link_ctx_storage, conn_handle, (void *) &p_client); 415 | VERIFY_SUCCESS(err_code); 416 | 417 | if ((conn_handle == BLE_CONN_HANDLE_INVALID) || (p_client == NULL)) 418 | { 419 | NRF_LOG_INFO("NRF_ERROR_NOT_FOUND"); 420 | return NRF_ERROR_NOT_FOUND; 421 | } 422 | 423 | if (!p_client->is_notification_enabled) 424 | { 425 | NRF_LOG_INFO("NRF_ERROR_INVALID_STATE"); 426 | return NRF_ERROR_INVALID_STATE; 427 | } 428 | 429 | if (*p_length > BLE_BTS_MAX_DATA_LEN) 430 | { 431 | NRF_LOG_INFO("NRF_ERROR_INVALID_PARAM"); 432 | return NRF_ERROR_INVALID_PARAM; 433 | } 434 | 435 | NRF_LOG_INFO("ble_bts_data_send"); 436 | 437 | memset(&hvx_params, 0, sizeof(hvx_params)); 438 | 439 | hvx_params.handle = p_bts->tx_rx_handles.value_handle;//tx_handles.value_handle; 440 | hvx_params.p_data = p_data; 441 | hvx_params.p_len = p_length; 442 | hvx_params.type = BLE_GATT_HVX_NOTIFICATION; 443 | 444 | return sd_ble_gatts_hvx(conn_handle, &hvx_params); 445 | } 446 | 447 | // #endif // NRF_MODULE_ENABLED(BLE_LLS) 448 | -------------------------------------------------------------------------------- /Blinker/ble_bts.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012 - 2019, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | /** @file 41 | * 42 | * @defgroup ble_bts Link Loss Service 43 | * @{ 44 | * @ingroup ble_sdk_srv 45 | * @brief Link Loss Service module. 46 | * 47 | * @details This module implements the Link Loss Service with the Alert Level characteristic. 48 | * During initialization it adds the Link Loss Service and Alert Level characteristic 49 | * to the BLE stack database. 50 | * 51 | * The application must supply an event handler for receiving Link Loss Service 52 | * events. Using this handler, the service will notify the application when the 53 | * link has been lost, and which Alert Level has been set. 54 | * 55 | * The service also provides a function for letting the application poll the current 56 | * value of the Alert Level characteristic. 57 | * 58 | * @note The application must register this module as BLE event observer using the 59 | * NRF_SDH_BLE_OBSERVER macro. Example: 60 | * @code 61 | * ble_bts_t instance; 62 | * NRF_SDH_BLE_OBSERVER(anything, BLE_BTS_BLE_OBSERVER_PRIO, 63 | * ble_bts_on_ble_evt, &instance); 64 | * @endcode 65 | * 66 | * @note Attention! 67 | * To maintain compliance with Nordic Semiconductor ASA Bluetooth profile 68 | * qualification listings, this section of source code must not be modified. 69 | */ 70 | 71 | #ifndef BLE_BTS_H__ 72 | #define BLE_BTS_H__ 73 | 74 | #include 75 | #include "ble.h" 76 | #include "ble_srv_common.h" 77 | #include "nrf_sdh_ble.h" 78 | #include "ble_link_ctx_manager.h" 79 | #include "nrf_log.h" 80 | #include "nrf_log_ctrl.h" 81 | #include "nrf_log_default_backends.h" 82 | 83 | 84 | #ifdef __cplusplus 85 | extern "C" { 86 | #endif 87 | 88 | #ifndef BLE_BTS_BLE_OBSERVER_PRIO 89 | #define BLE_BTS_BLE_OBSERVER_PRIO 2 90 | #endif 91 | 92 | /**@brief Macro for defining a ble_bts instance. 93 | * 94 | * @param _name Name of the instance. 95 | * @hideinitializer 96 | */ 97 | #define BLE_BTS_DEF(_name, _bts_max_clients) \ 98 | BLE_LINK_CTX_MANAGER_DEF(CONCAT_2(_name, _link_ctx_storage), \ 99 | (_bts_max_clients), \ 100 | sizeof(ble_bts_client_context_t)); \ 101 | static ble_bts_t _name = \ 102 | { \ 103 | .p_link_ctx_storage = &CONCAT_2(_name, _link_ctx_storage) \ 104 | }; \ 105 | NRF_SDH_BLE_OBSERVER(_name ## _obs, \ 106 | BLE_BTS_BLE_OBSERVER_PRIO, \ 107 | ble_bts_on_ble_evt, &_name) \ 108 | 109 | #define BLE_BTS_MAX_DATA_LEN 20 110 | #define BLE_BTS_MAX_RX_CHAR_LEN BLE_BTS_MAX_DATA_LEN /**< Maximum length of the RX Characteristic (in bytes). */ 111 | #define BLE_BTS_MAX_TX_CHAR_LEN BLE_BTS_MAX_DATA_LEN /**< Maximum length of the TX Characteristic (in bytes). */ 112 | 113 | 114 | /**@brief Link Loss Service event type. */ 115 | typedef enum 116 | { 117 | BLE_BTS_EVT_RX_DATA, /**< Data received. */ 118 | BLE_BTS_EVT_TX_RDY, /**< Service is ready to accept new data to be transmitted. */ 119 | BLE_BTS_EVT_COMM_STARTED, /**< Notification has been enabled. */ 120 | BLE_BTS_EVT_COMM_STOPPED, /**< Notification has been disabled. */ 121 | 122 | // BLE_BTS_EVT_LINK_LOSS_ALERT /**< Alert Level Updated event. */ 123 | } ble_bts_evt_type_t; 124 | 125 | 126 | // Forward declaration of the ble_bts_t type. 127 | typedef struct ble_bts_s ble_bts_t; 128 | 129 | 130 | /**@brief Nordic UART Service @ref BLE_BTS_EVT_RX_DATA event data. 131 | * 132 | * @details This structure is passed to an event when @ref BLE_BTS_EVT_RX_DATA occurs. 133 | */ 134 | typedef struct 135 | { 136 | uint8_t const * p_data; /**< A pointer to the buffer with received data. */ 137 | uint16_t length; /**< Length of received data. */ 138 | } ble_bts_evt_rx_data_t; 139 | 140 | 141 | /**@brief Nordic UART Service client context structure. 142 | * 143 | * @details This structure contains state context related to hosts. 144 | */ 145 | typedef struct 146 | { 147 | bool is_notification_enabled; /**< Variable to indicate if the peer has enabled notification of the RX characteristic.*/ 148 | } ble_bts_client_context_t; 149 | 150 | 151 | /**@brief Link Loss Service event. */ 152 | typedef struct 153 | { 154 | ble_bts_evt_type_t evt_type; /**< Type of event. */ 155 | ble_bts_t * p_bts; /**< A pointer to the instance. */ 156 | uint16_t conn_handle; /**< Connection handle. */ 157 | ble_bts_client_context_t * p_link_ctx; /**< A pointer to the link context. */ 158 | union 159 | { 160 | uint8_t alert_level; /**< New Alert Level value. */ 161 | ble_bts_evt_rx_data_t rx_data; /**< @ref BLE_BTS_EVT_RX_DATA event data. */ 162 | } params; 163 | } ble_bts_evt_t; 164 | 165 | /**@brief Link Loss Service event handler type. */ 166 | typedef void (*ble_bts_evt_handler_t) (ble_bts_t * p_bts, ble_bts_evt_t * p_evt); 167 | 168 | 169 | /**@brief Nordic UART Service event handler type. */ 170 | typedef void (* ble_bts_data_handler_t) (ble_bts_evt_t * p_evt); 171 | 172 | 173 | /**@brief Nordic UART Service initialization structure. 174 | * 175 | * @details This structure contains the initialization information for the service. The application 176 | * must fill this structure and pass it to the service using the @ref ble_bts_init 177 | * function. 178 | */ 179 | // typedef struct 180 | // { 181 | // ble_bts_data_handler_t data_handler; /**< Event handler to be called for handling received data. */ 182 | // } ble_bts_init_t; 183 | 184 | 185 | /**@brief Link Loss Service init structure. This contains all options and data needed for initialization of the service. */ 186 | typedef struct 187 | { 188 | // ble_bts_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Link Loss Service. */ 189 | // ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */ 190 | // uint8_t initial_alert_level; /**< Initial value of the Alert Level characteristic. */ 191 | // security_req_t alert_level_rd_sec; /**< Security requirement for reading Alert Level characteristic. */ 192 | // security_req_t alert_level_wr_sec; /**< Security requirement for writing Alert Level characteristic. */ 193 | ble_bts_data_handler_t data_handler; /**< Event handler to be called for handling received data. */ 194 | } ble_bts_init_t; 195 | 196 | /**@brief Link Loss Service structure. This contains various status information for the service. */ 197 | struct ble_bts_s 198 | { 199 | // ble_bts_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Link Loss Service. */ 200 | // ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */ 201 | uint8_t uuid_type; /**< UUID type for Nordic UART Service Base UUID. */ 202 | uint16_t service_handle; /**< Handle of Link Loss Service (as provided by the BLE stack). */ 203 | // ble_gatts_char_handles_t alert_level_handles; /**< Handles related to the Alert Level characteristic. */ 204 | // uint16_t conn_handle; /**< Handle of the current connection (as provided by the BLE stack, is BLE_CONN_HANDLE_INVALID if not in a connection). */ 205 | ble_gatts_char_handles_t tx_rx_handles; 206 | blcm_link_ctx_storage_t * const p_link_ctx_storage; /**< Pointer to link context storage with handles of all current connections and its context. */ 207 | ble_bts_data_handler_t data_handler; /**< Event handler to be called for handling received data. */ 208 | }; 209 | 210 | 211 | /**@brief Function for initializing the Link Loss Service. 212 | * 213 | * @param[out] p_bts Link Loss Service structure. This structure will have to be supplied by 214 | * the application. It will be initialized by this function, and will later 215 | * be used to identify this particular service instance. 216 | * @param[in] p_bts_init Information needed to initialize the service. 217 | * 218 | * @return NRF_SUCCESS on successful initialization of service, otherwise an error code. 219 | */ 220 | uint32_t ble_bts_init(ble_bts_t * p_bts, const ble_bts_init_t * p_bts_init); 221 | 222 | 223 | /**@brief Function for handling the Application's BLE Stack events. 224 | * 225 | * @details Handles all events from the BLE stack of interest to the Link Loss Service. 226 | * 227 | * @param[in] p_ble_evt Event received from the BLE stack. 228 | * @param[in] p_context Link Loss Service structure. 229 | */ 230 | void ble_bts_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context); 231 | 232 | 233 | /**@brief Function for getting current value of the Alert Level characteristic. 234 | * 235 | * @param[in] p_bts Link Loss Service structure. 236 | * @param[out] p_alert_level Current Alert Level value. 237 | * 238 | * @return NRF_SUCCESS on success, otherwise an error code. 239 | */ 240 | // uint32_t ble_bts_alert_level_get(ble_bts_t * p_bts, uint8_t * p_alert_level); 241 | 242 | 243 | /**@brief Function for sending a data to the peer. 244 | * 245 | * @details This function sends the input string as an RX characteristic notification to the 246 | * peer. 247 | * 248 | * @param[in] p_bts Pointer to the Nordic UART Service structure. 249 | * @param[in] p_data String to be sent. 250 | * @param[in,out] p_length Pointer Length of the string. Amount of sent bytes. 251 | * @param[in] conn_handle Connection Handle of the destination client. 252 | * 253 | * @retval NRF_SUCCESS If the string was sent successfully. Otherwise, an error code is returned. 254 | */ 255 | uint32_t ble_bts_data_send(ble_bts_t * p_bts, 256 | uint8_t * p_data, 257 | uint16_t * p_length, 258 | uint16_t conn_handle); 259 | 260 | 261 | #ifdef __cplusplus 262 | } 263 | #endif 264 | 265 | #endif // BLE_BTS_H__ 266 | 267 | /** @} */ 268 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # blinker-nRF52 2 | Base nordic nrf5 SDK V16.0.0 and nrf5 mesh SDK V4.0.0 3 | 4 | # Blinker Nordic nRF52支持库 5 | 针对 Nordic nRF52xx 系列芯片的Blinker库,需配合 [nRF5 SDK v16.0.0](https://infocenter.nordicsemi.com/topic/struct_sdk/struct/sdk_nrf5_latest.html?cp=7_1) 和 [nRF5 SDK for Mesh v4.0.0](https://infocenter.nordicsemi.com/topic/struct_sdk/struct/sdk_mesh_latest.html?cp=7_2) 6 | 7 | ## 注意 8 | - 有较强的自学能力及文档阅读能力 9 | - nRF52xx 系列开发板 10 | 11 | ## 支持的硬件 12 | * [nRF52xx boards](https://www.nordicsemi.com/Software-and-tools/Development-Kits) 13 | 14 | ## 支持的接入方式 15 | * BLE 5.0 16 | * BLE MESH 17 | 18 | ## 支持的功能 19 | - BLE 5.0 20 | - 直接与手机端/用户端 BLE 连接通信 21 | - 上报/查询设备状态 22 | - BLE MESH 23 | - MESH 网关 24 | - 上传节点数据到云端 25 | - 下发控制数据到节点 26 | - MESH 中继节点 27 | - 中继转发数据 28 | - MESH 低功耗节点 29 | - 上报节点数据 30 | - 执行控制指令 31 | - BLE DFU 32 | - BLE Secure DFU 加密更新 33 | - BLE MESH Secure DFU 加密更新 34 | 35 | ## 支持的应用 36 | - BLE 5.0 37 | - 心跳/睡眠/运动数据 检测上报 38 | - beacon 室内/外定位 39 | - 蓝牙遥控/键盘 等控制设备 40 | - BLE MESH 41 | - 智能家居设备组网 42 | - 灯/开关/窗帘/门磁/温湿度检测 43 | - 工业设备组网 44 | - 工业设备定位/设备运行状态上传/设备控制下发 45 | - 农业设备组网 46 | - 农产品溯源/养殖环境数据上报 47 | - 室内外定位 48 | - 停车场寻车/运动定位及轨迹上报 49 | - BLE DFU 50 | - 基于BLE 5.0加密DFU,可直接手机直连DFU更新 51 | - 基于BLE MESH加密DFU,可直接全部设备或按设备类型等进行分类DFU更新 52 | 53 | ## 准备工作 54 | 使用前你需要做好如下准备: 55 | * 基于官方开发套件 [SES开发环境配置](https://infocenter.nordicsemi.com/pdf/getting_started_ses.pdf) 56 | * [SEGGER Embedded Studio](https://www.segger.com/downloads/embedded-studio/) 57 | * [nRF Command Line Tools](https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Command-Line-Tools/Download#infotabs) 58 | * [micro_ecc](https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/lib_crypto_backend_micro_ecc.html#lib_crypto_backend_micro_ecc_install) 59 | * [nrfutil](https://infocenter.nordicsemi.com/topic/ug_nrfutil/UG/nrfutil/nrfutil_installing.html) 60 | * [Blinker-nRF52](https://github.com/blinker-iot/blinker-nRF52) 将 **Blinker** 文件放到 **nRF5SDK16\components** 目录下, **exmaples** 放到 **nRF5SDK16\examples\ble_peripheral** 目录下 61 | -------------------------------------------------------------------------------- /examples/blinker_ble/app_bsp.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - 2019, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | 41 | /** 42 | * @brief GATT Service client Sample Application main file. 43 | * 44 | * This file contains the source code for a sample server application using the LED Button service. 45 | */ 46 | 47 | #include 48 | #include 49 | #include "nordic_common.h" 50 | #include "nrf.h" 51 | #include "app_error.h" 52 | #include "ble.h" 53 | #include "ble_hci.h" 54 | #include "ble_srv_common.h" 55 | #include "ble_advdata.h" 56 | #include "ble_conn_params.h" 57 | #include "softdevice_handler.h" 58 | #include "app_timer.h" 59 | #include "bsp.h" 60 | #include "bsp_btn_ble.h" 61 | #include "nrf_ble_gatts_c.h" 62 | #include "boards.h" 63 | #include "ble_gap.h" 64 | #include "nrf_ble_gatt.h" 65 | #include "peer_manager.h" 66 | #include "fds.h" 67 | #include "fstorage.h" 68 | #include "ble_conn_state.h" 69 | #include "nrf_log.h" 70 | 71 | #define APP_FEATURE_NOT_SUPPORTED BLE_GATT_STATUS_ATTERR_APP_BEGIN + 2 /**< Reply when unsupported features are requested. */ 72 | 73 | #define ADVERTISING_LED_PIN BSP_BOARD_LED_0 /**< Is on when device is advertising. */ 74 | #define CONNECTED_LED_PIN BSP_BOARD_LED_1 /**< Is on when device has connected. */ 75 | 76 | #define LEDBUTTON_LED_PIN BSP_BOARD_LED_2 /**< LED to be toggled with the help of the LED Button Service. */ 77 | #define LEDBUTTON_BUTTON_PIN BSP_BUTTON_0 /**< Button that will trigger the notification event with the LED Button Service */ 78 | 79 | #define APP_GPIOTE_MAX_USERS 1 /**< Maximum number of users of the GPIOTE handler. */ 80 | #define BUTTON_DETECTION_DELAY APP_TIMER_TICKS(50, APP_TIMER_PRESCALER) /**< Delay from a GPIOTE event until a button is reported as pushed (in number of timer ticks). */ 81 | 82 | /**@brief Function for initializing the LEDs. 83 | * 84 | * @details Initializes all LEDs used by the application. 85 | */ 86 | static void leds_init(void) 87 | { 88 | bsp_board_init(BSP_INIT_LEDS); 89 | } 90 | 91 | 92 | /**@brief Function for putting the chip into sleep mode. 93 | * 94 | * @note This function will not return. 95 | */ 96 | static void sleep_mode_enter(void) 97 | { 98 | ret_code_t err_code; 99 | 100 | err_code = bsp_indication_set(BSP_INDICATE_IDLE); 101 | APP_ERROR_CHECK(err_code); 102 | 103 | // Prepare wakeup buttons. 104 | err_code = bsp_btn_ble_sleep_mode_prepare(); 105 | APP_ERROR_CHECK(err_code); 106 | 107 | // Go to System Off mode (this function will not return; wakeup will cause a reset). 108 | err_code = sd_power_system_off(); 109 | APP_ERROR_CHECK(err_code); 110 | } 111 | 112 | 113 | /**@brief Function for handling events from the BSP module. 114 | * 115 | * @param[in] event Event generated by pressing a button. 116 | */ 117 | void bsp_event_handler(bsp_event_t event) 118 | { 119 | ret_code_t err_code; 120 | 121 | switch (event) 122 | { 123 | case BSP_EVENT_SLEEP: 124 | sleep_mode_enter(); 125 | break; 126 | 127 | case BSP_EVENT_DISCONNECT: 128 | err_code = sd_ble_gap_disconnect(m_conn_handle, 129 | BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); 130 | if (err_code != NRF_ERROR_INVALID_STATE) 131 | { 132 | APP_ERROR_CHECK(err_code); 133 | } 134 | break; 135 | 136 | default: 137 | break; 138 | } 139 | } 140 | 141 | 142 | /**@brief Function for initializing buttons and LEDs. 143 | * 144 | * @param[out] p_erase_bonds True if the clear bonding button was pressed to wake the application up. 145 | */ 146 | static void buttons_leds_init(bool * p_erase_bonds) 147 | { 148 | ret_code_t err_code; 149 | bsp_event_t startup_event; 150 | 151 | err_code = bsp_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS, bsp_event_handler); 152 | APP_ERROR_CHECK(err_code); 153 | 154 | err_code = bsp_btn_ble_init(NULL, &startup_event); 155 | APP_ERROR_CHECK(err_code); 156 | 157 | *p_erase_bonds = (startup_event == BSP_EVENT_CLEAR_BONDING_DATA); 158 | } 159 | -------------------------------------------------------------------------------- /examples/blinker_ble/ble_app_blinker_ble.eww: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $WS_DIR$\pca10040\s132\iar\ble_app_blinker_ble_pca10040_s132.ewp 5 | 6 | $WS_DIR$\pca10056\s140\iar\ble_app_blinker_ble_pca10056_s140.ewp 7 | 8 | $WS_DIR$\pca10040e\s112\iar\ble_app_blinker_ble_pca10040e_s112.ewp 9 | 10 | $WS_DIR$\pca10056e\s112\iar\ble_app_blinker_ble_pca10056e_s112.ewp 11 | 12 | -------------------------------------------------------------------------------- /examples/blinker_ble/hex/license.txt: -------------------------------------------------------------------------------- 1 | The provided HEX files were compiled using the projects located in the folders for the respective boards (pca10xxx). 2 | 3 | For license and copyright information, see the individual .c and .h files that are included in the projects. 4 | -------------------------------------------------------------------------------- /examples/blinker_ble/main.c: -------------------------------------------------------------------------------- 1 | // #define BLINKER_BLE 2 | 3 | #include "BlinkerApi.h" 4 | 5 | BlinkerButton button1 = {.name = "btn-abc"}; 6 | BlinkerNumber number1 = {.name = "num-abc"}; 7 | BlinkerRGB rgb1 = {.name = "rgb"}; 8 | 9 | int counter = 0; 10 | 11 | void button1_callback(const char *data) 12 | { 13 | // BLINKER_LOG("get button data: %s", data); 14 | 15 | blinker_button_config_t config = { 16 | .icon = "fas fa-alicorn", 17 | .color = "0xFF", 18 | .text1 = "test", 19 | }; 20 | 21 | blinker_button_print(&button1, &config); 22 | } 23 | 24 | void rgb1_callback(uint8_t r_value, uint8_t g_value, uint8_t b_value, uint8_t bright_value) 25 | { 26 | // BLINKER_LOG("R value: %d", r_value); 27 | // BLINKER_LOG("G value: %d", g_value); 28 | // BLINKER_LOG("B value: %d", b_value); 29 | // BLINKER_LOG("Rrightness value: %d", bright_value); 30 | 31 | blinker_rgb_config_t config = { 32 | .rgbw = {r_value, g_value, b_value, bright_value}, 33 | }; 34 | 35 | blinker_rgb_print(&rgb1, &config); 36 | } 37 | 38 | void data_callback(const cJSON *data) 39 | { 40 | // BLINKER_LOG("get json data"); 41 | 42 | counter++; 43 | 44 | char count[10]; 45 | sprintf(count, "%d", counter); 46 | 47 | blinker_number_config_t config = { 48 | .value = count, 49 | }; 50 | 51 | blinker_number_print(&number1, &config); 52 | } 53 | 54 | void main(void) 55 | { 56 | // BLINKER_DEBUG_ALL(); 57 | 58 | blinker_button_init(&button1, button1_callback); 59 | blinker_rgb_init(&rgb1, rgb1_callback); 60 | blinker_attach_data(data_callback); 61 | 62 | blinker_init(); 63 | } -------------------------------------------------------------------------------- /examples/blinker_ble/pca10040/s132/arm4/ble_app_blinker_ble_pca10040_s132.uvopt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1.0 5 | 6 |
### uVision Project, (C) Keil Software
7 | 8 | nrf52832_xxaa 9 | 0x4 10 | ARM-ADS 11 | 12 | 1 13 | 14 | Segger\JL2CM3.dll 15 | 16 | 17 | 18 | 0 19 | JL2CM3 20 | -O78 -S0 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD20000000 -FC2000 -FN1 -FF0nrf52xxx -FS00 -FL0200000 -FF1nrf52xxx_uicr.flm -FS110001000 -FL11000 21 | 22 | 23 | 0 24 | UL2CM3 25 | UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0nrf52xxx -FS00 -FL0200000) 26 | 27 | 28 | 29 | 30 | flash_s132_nrf52_7.0.1_softdevice 31 | 0x4 32 | ARM-ADS 33 | 34 | Segger\JL2CM3.dll 35 | 36 | 37 | 38 | 0 39 | JL2CM3 40 | -O78 -S0 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD20000000 -FC2000 -FN1 -FF0nrf52xxx_ecb -FS00 -FL0200000 -FF1nrf52xxx_uicr.flm -FS110001000 -FL11000 41 | 42 | 43 | 0 44 | UL2CM3 45 | UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0nrf52xxx -FS00 -FL0200000) 46 | 47 | 48 | 49 |
50 | 51 | 52 | -------------------------------------------------------------------------------- /examples/blinker_ble/pca10040/s132/arm5_no_packs/ble_app_blinker_ble_pca10040_s132.uvoptx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1.0 5 | 6 |
### uVision Project, (C) Keil Software
7 | 8 | nrf52832_xxaa 9 | 0x4 10 | ARM-ADS 11 | 12 | 13 | 1 14 | 1 15 | 0 16 | 1 17 | 18 | 19 | 1 20 | 65535 21 | 0 22 | 0 23 | 0 24 | 25 | 26 | 79 27 | 66 28 | 8 29 | .\_build\ 30 | 31 | 0 32 | 33 | 0 34 | 1 35 | 1 36 | 1 37 | 1 38 | 1 39 | 1 40 | 1 41 | 1 42 | 1 43 | 1 44 | 1 45 | 1 46 | 1 47 | 0 48 | 1 49 | 0 50 | 1 51 | 1 52 | 1 53 | 0 54 | 0 55 | 7 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | Segger\JL2CM3.dll 67 | 68 | 69 | 70 | 0 71 | JL2CM3 72 | -U408001579 -O78 -S0 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD20000000 -FC2000 -FN2 -FF0nrf52xxx.flm -FS00 -FL0200000 -FP0($$Device:nRF52832_xxAA$Flash\nrf52xxx.flm) -FF1nrf52xxx_uicr -FS110001000 -FL11000 -FP1($$Device:nRF52832_xxAA$Flash\nrf52xxx_uicr.flm) 73 | 74 | 75 | 0 76 | UL2CM3 77 | UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0nrf52xxx -FS00 -FL0200000 -FP0($$Device:nRF52832_xxAA$Flash\nrf52xxx)) 78 | 79 | 80 | 81 | 82 | 0 83 | 84 | 85 | 0 86 | 0 87 | 0 88 | 0 89 | 0 90 | 0 91 | 0 92 | 0 93 | 0 94 | 0 95 | 0 96 | 0 97 | 0 98 | 0 99 | 0 100 | 0 101 | 0 102 | 0 103 | 0 104 | 0 105 | 0 106 | 0 107 | 0 108 | 0 109 | 110 | 111 | 112 | 113 | 114 | flash_s132_nrf52_7.0.1_softdevice 115 | 0x4 116 | ARM-ADS 117 | 118 | 119 | 1 120 | 1 121 | 0 122 | 1 123 | 124 | 125 | 1 126 | 65535 127 | 0 128 | 0 129 | 0 130 | 131 | 132 | 79 133 | 66 134 | 8 135 | .\_build\ 136 | 137 | 0 138 | 139 | 0 140 | 1 141 | 1 142 | 1 143 | 1 144 | 1 145 | 1 146 | 1 147 | 1 148 | 1 149 | 1 150 | 1 151 | 1 152 | 1 153 | 0 154 | 1 155 | 0 156 | 1 157 | 1 158 | 1 159 | 0 160 | 0 161 | 7 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | Segger\JL2CM3.dll 173 | 174 | 175 | 176 | 0 177 | JL2CM3 178 | -U408001579 -O78 -S0 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD20000000 -FC2000 -FN2 -FF0nrf52xxx.flm -FS00 -FL0200000 -FP0($$Device:nRF52832_xxAA$Flash\nrf52xxx.flm) -FF1nrf52xxx_uicr -FS110001000 -FL11000 -FP1($$Device:nRF52832_xxAA$Flash\nrf52xxx_uicr.flm) 179 | 180 | 181 | 0 182 | UL2CM3 183 | UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0nrf52xxx -FS00 -FL0200000 -FP0($$Device:nRF52832_xxAA$Flash\nrf52xxx)) 184 | 185 | 186 | 187 | 188 | 0 189 | 190 | 191 | 0 192 | 0 193 | 0 194 | 0 195 | 0 196 | 0 197 | 0 198 | 0 199 | 0 200 | 0 201 | 0 202 | 0 203 | 0 204 | 0 205 | 0 206 | 0 207 | 0 208 | 0 209 | 0 210 | 0 211 | 0 212 | 0 213 | 0 214 | 0 215 | 216 | 217 | 218 | 219 |
220 | 221 | 222 | -------------------------------------------------------------------------------- /examples/blinker_ble/pca10040/s132/armgcc/Makefile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME := ble_app_blinker_ble_pca10040_s132 2 | TARGETS := nrf52832_xxaa 3 | OUTPUT_DIRECTORY := _build 4 | 5 | SDK_ROOT := ../../../../../.. 6 | PROJ_DIR := ../../.. 7 | 8 | $(OUTPUT_DIRECTORY)/nrf52832_xxaa.out: \ 9 | LINKER_SCRIPT := ble_app_blinker_ble_gcc_nrf52.ld 10 | 11 | # Source files common to all targets 12 | SRC_FILES += \ 13 | $(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52.S \ 14 | $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_rtt.c \ 15 | $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_serial.c \ 16 | $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_uart.c \ 17 | $(SDK_ROOT)/components/libraries/log/src/nrf_log_default_backends.c \ 18 | $(SDK_ROOT)/components/libraries/log/src/nrf_log_frontend.c \ 19 | $(SDK_ROOT)/components/libraries/log/src/nrf_log_str_formatter.c \ 20 | $(SDK_ROOT)/components/libraries/button/app_button.c \ 21 | $(SDK_ROOT)/components/libraries/util/app_error.c \ 22 | $(SDK_ROOT)/components/libraries/util/app_error_handler_gcc.c \ 23 | $(SDK_ROOT)/components/libraries/util/app_error_weak.c \ 24 | $(SDK_ROOT)/components/libraries/scheduler/app_scheduler.c \ 25 | $(SDK_ROOT)/components/libraries/timer/app_timer2.c \ 26 | $(SDK_ROOT)/components/libraries/util/app_util_platform.c \ 27 | $(SDK_ROOT)/components/libraries/crc16/crc16.c \ 28 | $(SDK_ROOT)/components/libraries/timer/drv_rtc.c \ 29 | $(SDK_ROOT)/components/libraries/fds/fds.c \ 30 | $(SDK_ROOT)/components/libraries/hardfault/hardfault_implementation.c \ 31 | $(SDK_ROOT)/components/libraries/util/nrf_assert.c \ 32 | $(SDK_ROOT)/components/libraries/atomic_fifo/nrf_atfifo.c \ 33 | $(SDK_ROOT)/components/libraries/atomic_flags/nrf_atflags.c \ 34 | $(SDK_ROOT)/components/libraries/atomic/nrf_atomic.c \ 35 | $(SDK_ROOT)/components/libraries/balloc/nrf_balloc.c \ 36 | $(SDK_ROOT)/external/fprintf/nrf_fprintf.c \ 37 | $(SDK_ROOT)/external/fprintf/nrf_fprintf_format.c \ 38 | $(SDK_ROOT)/components/libraries/fstorage/nrf_fstorage.c \ 39 | $(SDK_ROOT)/components/libraries/fstorage/nrf_fstorage_sd.c \ 40 | $(SDK_ROOT)/components/libraries/memobj/nrf_memobj.c \ 41 | $(SDK_ROOT)/components/libraries/pwr_mgmt/nrf_pwr_mgmt.c \ 42 | $(SDK_ROOT)/components/libraries/queue/nrf_queue.c \ 43 | $(SDK_ROOT)/components/libraries/ringbuf/nrf_ringbuf.c \ 44 | $(SDK_ROOT)/components/libraries/experimental_section_vars/nrf_section_iter.c \ 45 | $(SDK_ROOT)/components/libraries/sortlist/nrf_sortlist.c \ 46 | $(SDK_ROOT)/components/libraries/strerror/nrf_strerror.c \ 47 | $(SDK_ROOT)/modules/nrfx/mdk/system_nrf52.c \ 48 | $(SDK_ROOT)/components/boards/boards.c \ 49 | $(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_clock.c \ 50 | $(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_uart.c \ 51 | $(SDK_ROOT)/modules/nrfx/soc/nrfx_atomic.c \ 52 | $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_clock.c \ 53 | $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_gpiote.c \ 54 | $(SDK_ROOT)/modules/nrfx/drivers/src/prs/nrfx_prs.c \ 55 | $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uart.c \ 56 | $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uarte.c \ 57 | $(SDK_ROOT)/components/libraries/bsp/bsp.c \ 58 | $(SDK_ROOT)/components/libraries/bsp/bsp_btn_ble.c \ 59 | $(PROJ_DIR)/app_adv.c \ 60 | $(PROJ_DIR)/main.c \ 61 | $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c \ 62 | $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_Syscalls_GCC.c \ 63 | $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c \ 64 | $(SDK_ROOT)/components/ble/peer_manager/auth_status_tracker.c \ 65 | $(SDK_ROOT)/components/ble/common/ble_advdata.c \ 66 | $(SDK_ROOT)/components/ble/ble_advertising/ble_advertising.c \ 67 | $(SDK_ROOT)/components/ble/common/ble_conn_state.c \ 68 | $(SDK_ROOT)/components/ble/ble_db_discovery/ble_db_discovery.c \ 69 | $(SDK_ROOT)/components/ble/common/ble_srv_common.c \ 70 | $(SDK_ROOT)/components/ble/peer_manager/gatt_cache_manager.c \ 71 | $(SDK_ROOT)/components/ble/peer_manager/gatts_cache_manager.c \ 72 | $(SDK_ROOT)/components/ble/peer_manager/id_manager.c \ 73 | $(SDK_ROOT)/components/ble/nrf_ble_gatt/nrf_ble_gatt.c \ 74 | $(SDK_ROOT)/components/ble/nrf_ble_gq/nrf_ble_gq.c \ 75 | $(SDK_ROOT)/components/ble/nrf_ble_qwr/nrf_ble_qwr.c \ 76 | $(SDK_ROOT)/components/ble/peer_manager/peer_data_storage.c \ 77 | $(SDK_ROOT)/components/ble/peer_manager/peer_database.c \ 78 | $(SDK_ROOT)/components/ble/peer_manager/peer_id.c \ 79 | $(SDK_ROOT)/components/ble/peer_manager/peer_manager.c \ 80 | $(SDK_ROOT)/components/ble/peer_manager/peer_manager_handler.c \ 81 | $(SDK_ROOT)/components/ble/peer_manager/pm_buffer.c \ 82 | $(SDK_ROOT)/components/ble/peer_manager/security_dispatcher.c \ 83 | $(SDK_ROOT)/components/ble/peer_manager/security_manager.c \ 84 | $(SDK_ROOT)/external/utf_converter/utf.c \ 85 | $(SDK_ROOT)/components/ble/ble_services/experimental_gatts_c/nrf_ble_gatts_c.c \ 86 | $(SDK_ROOT)/components/softdevice/common/nrf_sdh.c \ 87 | $(SDK_ROOT)/components/softdevice/common/nrf_sdh_ble.c \ 88 | $(SDK_ROOT)/components/softdevice/common/nrf_sdh_soc.c \ 89 | 90 | # Include folders common to all targets 91 | INC_FOLDERS += \ 92 | $(SDK_ROOT)/components/nfc/ndef/generic/message \ 93 | $(SDK_ROOT)/components/nfc/t2t_lib \ 94 | $(PROJ_DIR) \ 95 | $(SDK_ROOT)/components/nfc/t4t_parser/hl_detection_procedure \ 96 | $(SDK_ROOT)/components/ble/ble_services/ble_ancs_c \ 97 | $(SDK_ROOT)/components/ble/ble_services/ble_ias_c \ 98 | $(SDK_ROOT)/components/libraries/pwm \ 99 | $(SDK_ROOT)/components/softdevice/s132/headers/nrf52 \ 100 | $(SDK_ROOT)/components/libraries/usbd/class/cdc/acm \ 101 | $(SDK_ROOT)/components/libraries/usbd/class/hid/generic \ 102 | $(SDK_ROOT)/components/libraries/usbd/class/msc \ 103 | $(SDK_ROOT)/components/libraries/usbd/class/hid \ 104 | $(SDK_ROOT)/modules/nrfx/hal \ 105 | $(SDK_ROOT)/components/nfc/ndef/conn_hand_parser/le_oob_rec_parser \ 106 | $(SDK_ROOT)/components/libraries/log \ 107 | $(SDK_ROOT)/components/ble/ble_services/ble_gls \ 108 | $(SDK_ROOT)/components/libraries/fstorage \ 109 | $(SDK_ROOT)/components/nfc/ndef/text \ 110 | $(SDK_ROOT)/components/libraries/mutex \ 111 | $(SDK_ROOT)/components/libraries/gpiote \ 112 | $(SDK_ROOT)/components/libraries/bootloader/ble_dfu \ 113 | $(SDK_ROOT)/components/nfc/ndef/connection_handover/common \ 114 | $(SDK_ROOT)/components/boards \ 115 | $(SDK_ROOT)/components/nfc/ndef/generic/record \ 116 | $(SDK_ROOT)/components/nfc/t4t_parser/cc_file \ 117 | $(SDK_ROOT)/components/ble/ble_advertising \ 118 | $(SDK_ROOT)/external/utf_converter \ 119 | $(SDK_ROOT)/components/ble/ble_services/experimental_gatts_c \ 120 | $(SDK_ROOT)/components/ble/ble_services/ble_bas_c \ 121 | $(SDK_ROOT)/modules/nrfx/drivers/include \ 122 | $(SDK_ROOT)/components/libraries/experimental_task_manager \ 123 | $(SDK_ROOT)/components/ble/ble_services/ble_hrs_c \ 124 | $(SDK_ROOT)/components/nfc/ndef/connection_handover/le_oob_rec \ 125 | $(SDK_ROOT)/components/libraries/queue \ 126 | $(SDK_ROOT)/components/libraries/pwr_mgmt \ 127 | $(SDK_ROOT)/components/ble/ble_dtm \ 128 | $(SDK_ROOT)/components/toolchain/cmsis/include \ 129 | $(SDK_ROOT)/components/ble/ble_services/ble_rscs_c \ 130 | $(SDK_ROOT)/components/ble/common \ 131 | $(SDK_ROOT)/components/ble/ble_services/ble_lls \ 132 | $(SDK_ROOT)/components/nfc/platform \ 133 | $(SDK_ROOT)/components/libraries/bsp \ 134 | $(SDK_ROOT)/components/ble/ble_db_discovery \ 135 | $(SDK_ROOT)/components/nfc/ndef/connection_handover/ac_rec \ 136 | $(SDK_ROOT)/components/ble/ble_services/ble_bas \ 137 | $(SDK_ROOT)/components/libraries/mpu \ 138 | $(SDK_ROOT)/components/libraries/experimental_section_vars \ 139 | $(SDK_ROOT)/components/softdevice/s132/headers \ 140 | $(SDK_ROOT)/components/ble/ble_services/ble_ans_c \ 141 | $(SDK_ROOT)/components/libraries/slip \ 142 | $(SDK_ROOT)/components/libraries/delay \ 143 | $(SDK_ROOT)/components/libraries/csense_drv \ 144 | $(SDK_ROOT)/components/libraries/memobj \ 145 | $(SDK_ROOT)/components/ble/ble_services/ble_nus_c \ 146 | $(SDK_ROOT)/components/softdevice/common \ 147 | $(SDK_ROOT)/components/ble/ble_services/ble_ias \ 148 | $(SDK_ROOT)/components/libraries/usbd/class/hid/mouse \ 149 | $(SDK_ROOT)/components/libraries/low_power_pwm \ 150 | $(SDK_ROOT)/components/nfc/ndef/conn_hand_parser/ble_oob_advdata_parser \ 151 | $(SDK_ROOT)/components/ble/ble_services/ble_dfu \ 152 | $(SDK_ROOT)/external/fprintf \ 153 | $(SDK_ROOT)/components/libraries/svc \ 154 | $(SDK_ROOT)/components/libraries/atomic \ 155 | $(SDK_ROOT)/components \ 156 | $(SDK_ROOT)/components/libraries/scheduler \ 157 | $(SDK_ROOT)/components/libraries/cli \ 158 | $(SDK_ROOT)/components/ble/ble_services/ble_lbs \ 159 | $(SDK_ROOT)/components/ble/ble_services/ble_hts \ 160 | $(SDK_ROOT)/components/libraries/crc16 \ 161 | $(SDK_ROOT)/components/nfc/t4t_parser/apdu \ 162 | $(SDK_ROOT)/components/libraries/util \ 163 | ../config \ 164 | $(SDK_ROOT)/components/libraries/usbd/class/cdc \ 165 | $(SDK_ROOT)/components/libraries/csense \ 166 | $(SDK_ROOT)/components/libraries/balloc \ 167 | $(SDK_ROOT)/components/libraries/ecc \ 168 | $(SDK_ROOT)/components/libraries/hardfault \ 169 | $(SDK_ROOT)/components/ble/ble_services/ble_cscs \ 170 | $(SDK_ROOT)/components/libraries/hci \ 171 | $(SDK_ROOT)/components/libraries/usbd/class/hid/kbd \ 172 | $(SDK_ROOT)/components/libraries/timer \ 173 | $(SDK_ROOT)/integration/nrfx \ 174 | $(SDK_ROOT)/components/nfc/t4t_parser/tlv \ 175 | $(SDK_ROOT)/components/libraries/sortlist \ 176 | $(SDK_ROOT)/components/libraries/spi_mngr \ 177 | $(SDK_ROOT)/components/libraries/led_softblink \ 178 | $(SDK_ROOT)/components/nfc/ndef/conn_hand_parser \ 179 | $(SDK_ROOT)/components/libraries/sdcard \ 180 | $(SDK_ROOT)/components/nfc/ndef/parser/record \ 181 | $(SDK_ROOT)/modules/nrfx/mdk \ 182 | $(SDK_ROOT)/components/ble/ble_services/ble_cts_c \ 183 | $(SDK_ROOT)/components/ble/ble_services/ble_nus \ 184 | $(SDK_ROOT)/components/libraries/twi_mngr \ 185 | $(SDK_ROOT)/components/ble/ble_services/ble_hids \ 186 | $(SDK_ROOT)/components/libraries/strerror \ 187 | $(SDK_ROOT)/components/libraries/crc32 \ 188 | $(SDK_ROOT)/components/nfc/ndef/connection_handover/ble_oob_advdata \ 189 | $(SDK_ROOT)/components/nfc/t2t_parser \ 190 | $(SDK_ROOT)/components/nfc/ndef/connection_handover/ble_pair_msg \ 191 | $(SDK_ROOT)/components/libraries/usbd/class/audio \ 192 | $(SDK_ROOT)/components/nfc/t4t_lib \ 193 | $(SDK_ROOT)/components/ble/peer_manager \ 194 | $(SDK_ROOT)/components/libraries/mem_manager \ 195 | $(SDK_ROOT)/components/libraries/ringbuf \ 196 | $(SDK_ROOT)/components/ble/ble_services/ble_tps \ 197 | $(SDK_ROOT)/components/nfc/ndef/parser/message \ 198 | $(SDK_ROOT)/components/ble/ble_services/ble_dis \ 199 | $(SDK_ROOT)/components/nfc/ndef/uri \ 200 | $(SDK_ROOT)/components/ble/nrf_ble_gatt \ 201 | $(SDK_ROOT)/components/ble/nrf_ble_qwr \ 202 | $(SDK_ROOT)/components/libraries/gfx \ 203 | $(SDK_ROOT)/components/libraries/button \ 204 | $(SDK_ROOT)/modules/nrfx \ 205 | $(SDK_ROOT)/components/libraries/twi_sensor \ 206 | $(SDK_ROOT)/integration/nrfx/legacy \ 207 | $(SDK_ROOT)/components/libraries/usbd \ 208 | $(SDK_ROOT)/components/nfc/ndef/connection_handover/ep_oob_rec \ 209 | $(SDK_ROOT)/external/segger_rtt \ 210 | $(SDK_ROOT)/components/libraries/atomic_fifo \ 211 | $(SDK_ROOT)/components/ble/ble_services/ble_lbs_c \ 212 | $(SDK_ROOT)/components/nfc/ndef/connection_handover/ble_pair_lib \ 213 | $(SDK_ROOT)/components/libraries/crypto \ 214 | $(SDK_ROOT)/components/ble/ble_racp \ 215 | $(SDK_ROOT)/components/libraries/fds \ 216 | $(SDK_ROOT)/components/nfc/ndef/launchapp \ 217 | $(SDK_ROOT)/components/libraries/atomic_flags \ 218 | $(SDK_ROOT)/components/ble/nrf_ble_gq \ 219 | $(SDK_ROOT)/components/ble/ble_services/ble_hrs \ 220 | $(SDK_ROOT)/components/ble/ble_services/ble_rscs \ 221 | $(SDK_ROOT)/components/nfc/ndef/connection_handover/hs_rec \ 222 | $(SDK_ROOT)/components/nfc/ndef/conn_hand_parser/ac_rec_parser \ 223 | $(SDK_ROOT)/components/libraries/stack_guard \ 224 | $(SDK_ROOT)/components/libraries/log/src \ 225 | 226 | # Libraries common to all targets 227 | LIB_FILES += \ 228 | 229 | # Optimization flags 230 | OPT = -O3 -g3 231 | # Uncomment the line below to enable link time optimization 232 | #OPT += -flto 233 | 234 | # C flags common to all targets 235 | CFLAGS += $(OPT) 236 | CFLAGS += -DAPP_TIMER_V2 237 | CFLAGS += -DAPP_TIMER_V2_RTC1_ENABLED 238 | CFLAGS += -DBOARD_PCA10040 239 | CFLAGS += -DCONFIG_GPIO_AS_PINRESET 240 | CFLAGS += -DFLOAT_ABI_HARD 241 | CFLAGS += -DNRF52 242 | CFLAGS += -DNRF52832_XXAA 243 | CFLAGS += -DNRF52_PAN_74 244 | CFLAGS += -DNRF_SD_BLE_API_VERSION=7 245 | CFLAGS += -DS132 246 | CFLAGS += -DSOFTDEVICE_PRESENT 247 | CFLAGS += -mcpu=cortex-m4 248 | CFLAGS += -mthumb -mabi=aapcs 249 | CFLAGS += -Wall -Werror 250 | CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 251 | # keep every function in a separate section, this allows linker to discard unused ones 252 | CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing 253 | CFLAGS += -fno-builtin -fshort-enums 254 | 255 | # C++ flags common to all targets 256 | CXXFLAGS += $(OPT) 257 | # Assembler flags common to all targets 258 | ASMFLAGS += -g3 259 | ASMFLAGS += -mcpu=cortex-m4 260 | ASMFLAGS += -mthumb -mabi=aapcs 261 | ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 262 | ASMFLAGS += -DAPP_TIMER_V2 263 | ASMFLAGS += -DAPP_TIMER_V2_RTC1_ENABLED 264 | ASMFLAGS += -DBOARD_PCA10040 265 | ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET 266 | ASMFLAGS += -DFLOAT_ABI_HARD 267 | ASMFLAGS += -DNRF52 268 | ASMFLAGS += -DNRF52832_XXAA 269 | ASMFLAGS += -DNRF52_PAN_74 270 | ASMFLAGS += -DNRF_SD_BLE_API_VERSION=7 271 | ASMFLAGS += -DS132 272 | ASMFLAGS += -DSOFTDEVICE_PRESENT 273 | 274 | # Linker flags 275 | LDFLAGS += $(OPT) 276 | LDFLAGS += -mthumb -mabi=aapcs -L$(SDK_ROOT)/modules/nrfx/mdk -T$(LINKER_SCRIPT) 277 | LDFLAGS += -mcpu=cortex-m4 278 | LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 279 | # let linker dump unused sections 280 | LDFLAGS += -Wl,--gc-sections 281 | # use newlib in nano version 282 | LDFLAGS += --specs=nano.specs 283 | 284 | nrf52832_xxaa: CFLAGS += -D__HEAP_SIZE=8192 285 | nrf52832_xxaa: CFLAGS += -D__STACK_SIZE=8192 286 | nrf52832_xxaa: ASMFLAGS += -D__HEAP_SIZE=8192 287 | nrf52832_xxaa: ASMFLAGS += -D__STACK_SIZE=8192 288 | 289 | # Add standard libraries at the very end of the linker input, after all objects 290 | # that may need symbols provided by these libraries. 291 | LIB_FILES += -lc -lnosys -lm 292 | 293 | 294 | .PHONY: default help 295 | 296 | # Default target - first one defined 297 | default: nrf52832_xxaa 298 | 299 | # Print all targets that can be built 300 | help: 301 | @echo following targets are available: 302 | @echo nrf52832_xxaa 303 | @echo flash_softdevice 304 | @echo sdk_config - starting external tool for editing sdk_config.h 305 | @echo flash - flashing binary 306 | 307 | TEMPLATE_PATH := $(SDK_ROOT)/components/toolchain/gcc 308 | 309 | 310 | include $(TEMPLATE_PATH)/Makefile.common 311 | 312 | $(foreach target, $(TARGETS), $(call define_target, $(target))) 313 | 314 | .PHONY: flash flash_softdevice erase 315 | 316 | # Flash the program 317 | flash: default 318 | @echo Flashing: $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex 319 | nrfjprog -f nrf52 --program $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex --sectorerase 320 | nrfjprog -f nrf52 --reset 321 | 322 | # Flash softdevice 323 | flash_softdevice: 324 | @echo Flashing: s132_nrf52_7.0.1_softdevice.hex 325 | nrfjprog -f nrf52 --program $(SDK_ROOT)/components/softdevice/s132/hex/s132_nrf52_7.0.1_softdevice.hex --sectorerase 326 | nrfjprog -f nrf52 --reset 327 | 328 | erase: 329 | nrfjprog -f nrf52 --eraseall 330 | 331 | SDK_CONFIG_FILE := ../config/sdk_config.h 332 | CMSIS_CONFIG_TOOL := $(SDK_ROOT)/external_tools/cmsisconfig/CMSIS_Configuration_Wizard.jar 333 | sdk_config: 334 | java -jar $(CMSIS_CONFIG_TOOL) $(SDK_CONFIG_FILE) 335 | -------------------------------------------------------------------------------- /examples/blinker_ble/pca10040/s132/armgcc/ble_app_blinker_ble_gcc_nrf52.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | 3 | SEARCH_DIR(.) 4 | GROUP(-lgcc -lc -lnosys) 5 | 6 | MEMORY 7 | { 8 | FLASH (rx) : ORIGIN = 0x26000, LENGTH = 0x5a000 9 | RAM (rwx) : ORIGIN = 0x20002250, LENGTH = 0xddb0 10 | } 11 | 12 | SECTIONS 13 | { 14 | } 15 | 16 | SECTIONS 17 | { 18 | . = ALIGN(4); 19 | .mem_section_dummy_ram : 20 | { 21 | } 22 | .cli_sorted_cmd_ptrs : 23 | { 24 | PROVIDE(__start_cli_sorted_cmd_ptrs = .); 25 | KEEP(*(.cli_sorted_cmd_ptrs)) 26 | PROVIDE(__stop_cli_sorted_cmd_ptrs = .); 27 | } > RAM 28 | .fs_data : 29 | { 30 | PROVIDE(__start_fs_data = .); 31 | KEEP(*(.fs_data)) 32 | PROVIDE(__stop_fs_data = .); 33 | } > RAM 34 | .log_dynamic_data : 35 | { 36 | PROVIDE(__start_log_dynamic_data = .); 37 | KEEP(*(SORT(.log_dynamic_data*))) 38 | PROVIDE(__stop_log_dynamic_data = .); 39 | } > RAM 40 | .log_filter_data : 41 | { 42 | PROVIDE(__start_log_filter_data = .); 43 | KEEP(*(SORT(.log_filter_data*))) 44 | PROVIDE(__stop_log_filter_data = .); 45 | } > RAM 46 | 47 | } INSERT AFTER .data; 48 | 49 | SECTIONS 50 | { 51 | .mem_section_dummy_rom : 52 | { 53 | } 54 | .sdh_soc_observers : 55 | { 56 | PROVIDE(__start_sdh_soc_observers = .); 57 | KEEP(*(SORT(.sdh_soc_observers*))) 58 | PROVIDE(__stop_sdh_soc_observers = .); 59 | } > FLASH 60 | .pwr_mgmt_data : 61 | { 62 | PROVIDE(__start_pwr_mgmt_data = .); 63 | KEEP(*(SORT(.pwr_mgmt_data*))) 64 | PROVIDE(__stop_pwr_mgmt_data = .); 65 | } > FLASH 66 | .sdh_ble_observers : 67 | { 68 | PROVIDE(__start_sdh_ble_observers = .); 69 | KEEP(*(SORT(.sdh_ble_observers*))) 70 | PROVIDE(__stop_sdh_ble_observers = .); 71 | } > FLASH 72 | .nrf_queue : 73 | { 74 | PROVIDE(__start_nrf_queue = .); 75 | KEEP(*(.nrf_queue)) 76 | PROVIDE(__stop_nrf_queue = .); 77 | } > FLASH 78 | .sdh_state_observers : 79 | { 80 | PROVIDE(__start_sdh_state_observers = .); 81 | KEEP(*(SORT(.sdh_state_observers*))) 82 | PROVIDE(__stop_sdh_state_observers = .); 83 | } > FLASH 84 | .sdh_stack_observers : 85 | { 86 | PROVIDE(__start_sdh_stack_observers = .); 87 | KEEP(*(SORT(.sdh_stack_observers*))) 88 | PROVIDE(__stop_sdh_stack_observers = .); 89 | } > FLASH 90 | .sdh_req_observers : 91 | { 92 | PROVIDE(__start_sdh_req_observers = .); 93 | KEEP(*(SORT(.sdh_req_observers*))) 94 | PROVIDE(__stop_sdh_req_observers = .); 95 | } > FLASH 96 | .nrf_balloc : 97 | { 98 | PROVIDE(__start_nrf_balloc = .); 99 | KEEP(*(.nrf_balloc)) 100 | PROVIDE(__stop_nrf_balloc = .); 101 | } > FLASH 102 | .cli_command : 103 | { 104 | PROVIDE(__start_cli_command = .); 105 | KEEP(*(.cli_command)) 106 | PROVIDE(__stop_cli_command = .); 107 | } > FLASH 108 | .crypto_data : 109 | { 110 | PROVIDE(__start_crypto_data = .); 111 | KEEP(*(SORT(.crypto_data*))) 112 | PROVIDE(__stop_crypto_data = .); 113 | } > FLASH 114 | .log_const_data : 115 | { 116 | PROVIDE(__start_log_const_data = .); 117 | KEEP(*(SORT(.log_const_data*))) 118 | PROVIDE(__stop_log_const_data = .); 119 | } > FLASH 120 | .log_backends : 121 | { 122 | PROVIDE(__start_log_backends = .); 123 | KEEP(*(SORT(.log_backends*))) 124 | PROVIDE(__stop_log_backends = .); 125 | } > FLASH 126 | 127 | } INSERT AFTER .text 128 | 129 | 130 | INCLUDE "nrf_common.ld" 131 | -------------------------------------------------------------------------------- /examples/blinker_ble/pca10040/s132/iar/ble_app_blinker_ble_iar_nRF5x.icf: -------------------------------------------------------------------------------- 1 | /*###ICF### Section handled by ICF editor, don't touch! ****/ 2 | /*-Editor annotation file-*/ 3 | /* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ 4 | /*-Specials-*/ 5 | define symbol __ICFEDIT_intvec_start__ = 0x26000; 6 | /*-Memory Regions-*/ 7 | define symbol __ICFEDIT_region_ROM_start__ = 0x26000; 8 | define symbol __ICFEDIT_region_ROM_end__ = 0x7ffff; 9 | define symbol __ICFEDIT_region_RAM_start__ = 0x20002250; 10 | define symbol __ICFEDIT_region_RAM_end__ = 0x2000ffff; 11 | export symbol __ICFEDIT_region_RAM_start__; 12 | export symbol __ICFEDIT_region_RAM_end__; 13 | /*-Sizes-*/ 14 | define symbol __ICFEDIT_size_cstack__ = 8192; 15 | define symbol __ICFEDIT_size_heap__ = 8192; 16 | /**** End of ICF editor section. ###ICF###*/ 17 | 18 | define memory mem with size = 4G; 19 | define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; 20 | define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; 21 | 22 | 23 | define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; 24 | define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; 25 | define block RO_END with alignment = 8, size = 0 { }; 26 | 27 | initialize by copy { readwrite }; 28 | do not initialize { section .noinit }; 29 | 30 | keep { section .intvec }; 31 | place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; 32 | place in ROM_region { readonly, 33 | block RO_END }; 34 | place in RAM_region { readwrite, 35 | block CSTACK, 36 | block HEAP }; 37 | 38 | -------------------------------------------------------------------------------- /examples/blinker_ble/pca10040/s132/ses/ble_app_blinker_ble_pca10040_s132.emProject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 153 | 157 | 158 | -------------------------------------------------------------------------------- /examples/blinker_ble/pca10040/s132/ses/ble_app_blinker_ble_pca10040_s132.emSession: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /examples/blinker_ble/pca10040/s132/ses/ble_app_blinker_ble_pca10040_s132_Release.jlink: -------------------------------------------------------------------------------- 1 | [BREAKPOINTS] 2 | ForceImpTypeAny = 0 3 | ShowInfoWin = 1 4 | EnableFlashBP = 2 5 | BPDuringExecution = 0 6 | [CFI] 7 | CFISize = 0x00 8 | CFIAddr = 0x00 9 | [CPU] 10 | MonModeVTableAddr = 0xFFFFFFFF 11 | MonModeDebug = 0 12 | MaxNumAPs = 0 13 | LowPowerHandlingMode = 0 14 | OverrideMemMap = 0 15 | AllowSimulation = 1 16 | ScriptFile="" 17 | [FLASH] 18 | CacheExcludeSize = 0x00 19 | CacheExcludeAddr = 0x00 20 | MinNumBytesFlashDL = 0 21 | SkipProgOnCRCMatch = 1 22 | VerifyDownload = 1 23 | AllowCaching = 1 24 | EnableFlashDL = 2 25 | Override = 0 26 | Device="ARM7" 27 | [GENERAL] 28 | WorkRAMSize = 0x00 29 | WorkRAMAddr = 0x00 30 | RAMUsageLimit = 0x00 31 | [SWO] 32 | SWOLogFile="" 33 | [MEM] 34 | RdOverrideOrMask = 0x00 35 | RdOverrideAndMask = 0xFFFFFFFF 36 | RdOverrideAddr = 0xFFFFFFFF 37 | WrOverrideOrMask = 0x00 38 | WrOverrideAndMask = 0xFFFFFFFF 39 | WrOverrideAddr = 0xFFFFFFFF 40 | -------------------------------------------------------------------------------- /examples/blinker_ble/pca10040/s132/ses/flash_placement.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /version.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1.0" 3 | } --------------------------------------------------------------------------------