![](/media/cache/profiles/697e382cfd25b07a3e62275d3ee132b3.jpg.50x50_q85.png)
changed low freq. clock source to IRC
Dependencies: BLE_API mbed nRF51822_IRC
Fork of BLE_ANCS_SDAPI by
debug.cpp
00001 00002 // Set error string based on error number for 00003 // convinience debugging purpose. 00004 // See: API Reference>S110>SofDevice Global Error Codes 00005 #include <stdint.h> 00006 #include <stdio.h> 00007 00008 #include "nRF51822n.h" 00009 00010 #define MAX_BUFFER 100 00011 char m_error_string[MAX_BUFFER]; 00012 char m_event_string[MAX_BUFFER]; 00013 char m_nrfevent_string[MAX_BUFFER]; 00014 char m_ancs_string[MAX_BUFFER]; 00015 00016 00017 char *get_error_unknown(uint32_t error_num) { 00018 snprintf(m_error_string, MAX_BUFFER, "Unknown"); 00019 return m_error_string; 00020 } 00021 00022 // Global error base. 00023 char *get_error_global(uint32_t error_num) { 00024 if(error_num == NRF_ERROR_BASE_NUM + 0){ 00025 snprintf(m_error_string, MAX_BUFFER, "Successful command. "); 00026 } else if(error_num == NRF_ERROR_BASE_NUM + 1){ 00027 snprintf(m_error_string, MAX_BUFFER, "SVC handler is missing. "); 00028 } else if(error_num == NRF_ERROR_BASE_NUM + 2){ 00029 snprintf(m_error_string, MAX_BUFFER, "SoftDevice has not been enabled. "); 00030 } else if(error_num == NRF_ERROR_BASE_NUM + 3){ 00031 snprintf(m_error_string, MAX_BUFFER, "Internal Error. "); 00032 } else if(error_num == NRF_ERROR_BASE_NUM + 4){ 00033 snprintf(m_error_string, MAX_BUFFER, "No Memory for operation. "); 00034 } else if(error_num == NRF_ERROR_BASE_NUM + 5){ 00035 snprintf(m_error_string, MAX_BUFFER, "Not found. "); 00036 } else if(error_num == NRF_ERROR_BASE_NUM + 6){ 00037 snprintf(m_error_string, MAX_BUFFER, "Not supported. "); 00038 } else if(error_num == NRF_ERROR_BASE_NUM + 7){ 00039 snprintf(m_error_string, MAX_BUFFER, "Invalid Parameter. "); 00040 } else if(error_num == NRF_ERROR_BASE_NUM + 8){ 00041 snprintf(m_error_string, MAX_BUFFER, "Invalid state, operation disallowed in this state. "); 00042 } else if(error_num == NRF_ERROR_BASE_NUM + 9){ 00043 snprintf(m_error_string, MAX_BUFFER, "Invalid Length. "); 00044 } else if(error_num == NRF_ERROR_BASE_NUM + 10){ 00045 snprintf(m_error_string, MAX_BUFFER, "Invalid Flags. "); 00046 } else if(error_num == NRF_ERROR_BASE_NUM + 11){ 00047 snprintf(m_error_string, MAX_BUFFER, "Invalid Data. "); 00048 } else if(error_num == NRF_ERROR_BASE_NUM + 12){ 00049 snprintf(m_error_string, MAX_BUFFER, "Data size exceeds limit. "); 00050 } else if(error_num == NRF_ERROR_BASE_NUM + 13){ 00051 snprintf(m_error_string, MAX_BUFFER, "Operation timed out. "); 00052 } else if(error_num == NRF_ERROR_BASE_NUM + 14){ 00053 snprintf(m_error_string, MAX_BUFFER, "Null Pointer. "); 00054 } else if(error_num == NRF_ERROR_BASE_NUM + 15){ 00055 snprintf(m_error_string, MAX_BUFFER, "Forbidden Operation. "); 00056 } else if(error_num == NRF_ERROR_BASE_NUM + 16){ 00057 snprintf(m_error_string, MAX_BUFFER, "Bad Memory Address. "); 00058 } else if(error_num == NRF_ERROR_BASE_NUM + 17){ 00059 snprintf(m_error_string, MAX_BUFFER, "Busy. "); 00060 } else { 00061 return get_error_unknown(error_num); 00062 } 00063 return m_error_string; 00064 } 00065 00066 // SDM error base. 00067 char *get_error_sdm(uint32_t error_num) { 00068 if(error_num == NRF_ERROR_SDM_BASE_NUM + 0){ 00069 snprintf(m_error_string, MAX_BUFFER, "Unknown lfclk source. "); 00070 } else if(error_num == NRF_ERROR_SDM_BASE_NUM + 1){ 00071 snprintf(m_error_string, MAX_BUFFER, "Incorrect interrupt configuration (can be caused by using illegal priority levels, or having enabled SoftDevice interrupts) "); 00072 } else if(error_num == NRF_ERROR_SDM_BASE_NUM + 2){ 00073 snprintf(m_error_string, MAX_BUFFER, "Incorrect CLENR0 (can be caused by erronous SoftDevice flashing) "); 00074 } else { 00075 return get_error_unknown(error_num); 00076 } 00077 return m_error_string; 00078 } 00079 00080 // SoC error base. 00081 char *get_error_soc(uint32_t error_num) { 00082 if(error_num == NRF_ERROR_SOC_BASE_NUM + 0){ 00083 snprintf(m_error_string, MAX_BUFFER, "Mutex already taken. "); 00084 } else if(error_num == NRF_ERROR_SOC_BASE_NUM + 1){ 00085 snprintf(m_error_string, MAX_BUFFER, "NVIC interrupt not available. "); 00086 } else if(error_num == NRF_ERROR_SOC_BASE_NUM + 2){ 00087 snprintf(m_error_string, MAX_BUFFER, "NVIC interrupt priority not allowed. "); 00088 } else if(error_num == NRF_ERROR_SOC_BASE_NUM + 3){ 00089 snprintf(m_error_string, MAX_BUFFER, "NVIC should not return. "); 00090 } else if(error_num == NRF_ERROR_SOC_BASE_NUM + 4){ 00091 snprintf(m_error_string, MAX_BUFFER, "Power mode unknown. "); 00092 } else if(error_num == NRF_ERROR_SOC_BASE_NUM + 5){ 00093 snprintf(m_error_string, MAX_BUFFER, "Power POF threshold unknown. "); 00094 } else if(error_num == NRF_ERROR_SOC_BASE_NUM + 6){ 00095 snprintf(m_error_string, MAX_BUFFER, "Power off should not return. "); 00096 } else if(error_num == NRF_ERROR_SOC_BASE_NUM + 7){ 00097 snprintf(m_error_string, MAX_BUFFER, "RAND not enough values. "); 00098 } else if(error_num == NRF_ERROR_SOC_BASE_NUM + 8){ 00099 snprintf(m_error_string, MAX_BUFFER, "Invalid PPI Channel. "); 00100 } else if(error_num == NRF_ERROR_SOC_BASE_NUM + 9){ 00101 snprintf(m_error_string, MAX_BUFFER, "Invalid PPI Group. "); 00102 } else { 00103 return get_error_unknown(error_num); 00104 } 00105 return m_error_string; 00106 } 00107 00108 // STK error base. 00109 char *get_error_stk(uint32_t error_num) { 00110 snprintf(m_error_string, MAX_BUFFER, "stk error."); 00111 return m_error_string; 00112 } 00113 00114 char *error2string(uint32_t error_num) { 00115 00116 if(error_num<NRF_ERROR_SDM_BASE_NUM) { 00117 return get_error_global(error_num); 00118 } else if(error_num<NRF_ERROR_SDM_BASE_NUM) { 00119 return get_error_sdm(error_num); 00120 } else if(error_num<NRF_ERROR_SOC_BASE_NUM) { 00121 return get_error_soc(error_num); 00122 } else if(error_num<NRF_ERROR_STK_BASE_NUM) { 00123 return get_error_stk(error_num); 00124 } else { 00125 return get_error_unknown(error_num); 00126 } 00127 00128 } 00129 00130 char *event2string(ble_evt_t * p_ble_evt) { 00131 switch (p_ble_evt->header.evt_id) { 00132 // GAP 00133 case BLE_GAP_EVT_CONNECTED: 00134 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GAP_EVT_CONNECTED", "Connection established."); 00135 break; 00136 case BLE_GAP_EVT_DISCONNECTED : 00137 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GAP_EVT_DISCONNECTED ", "Disconnected from peer."); 00138 break; 00139 case BLE_GAP_EVT_CONN_PARAM_UPDATE: 00140 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GAP_EVT_CONN_PARAM_UPDATE", "Connection Parameters updated."); 00141 break; 00142 case BLE_GAP_EVT_SEC_PARAMS_REQUEST : 00143 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GAP_EVT_SEC_PARAMS_REQUEST ", "Request to provide security parameters."); 00144 break; 00145 case BLE_GAP_EVT_SEC_INFO_REQUEST : 00146 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GAP_EVT_SEC_INFO_REQUEST ", "Request to provide security information."); 00147 break; 00148 case BLE_GAP_EVT_PASSKEY_DISPLAY: 00149 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GAP_EVT_PASSKEY_DISPLAY", "Request to display a passkey to the user."); 00150 break; 00151 case BLE_GAP_EVT_AUTH_KEY_REQUEST: 00152 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GAP_EVT_AUTH_KEY_REQUEST", "Request to provide an authentication key."); 00153 break; 00154 case BLE_GAP_EVT_AUTH_STATUS : 00155 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GAP_EVT_AUTH_STATUS ", "Authentication procedure completed with status."); 00156 break; 00157 case BLE_GAP_EVT_CONN_SEC_UPDATE: 00158 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GAP_EVT_CONN_SEC_UPDATE ", "Connection security updated."); 00159 break; 00160 case BLE_GAP_EVT_TIMEOUT : 00161 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GAP_EVT_TIMEOUT ", "Timeout expired."); 00162 break; 00163 case BLE_GAP_EVT_RSSI_CHANGED : 00164 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GAP_EVT_RSSI_CHANGED ", "Signal strength measurement report."); 00165 break; 00166 // GATTC 00167 case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP : 00168 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP ", "Primary Service Discovery Response event."); 00169 break; 00170 case BLE_GATTC_EVT_REL_DISC_RSP : 00171 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GATTC_EVT_REL_DISC_RSP ", "Relationship Discovery Response event."); 00172 break; 00173 case BLE_GATTC_EVT_CHAR_DISC_RSP : 00174 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GATTC_EVT_CHAR_DISC_RSP ", "Characteristic Discovery Response event."); 00175 break; 00176 case BLE_GATTC_EVT_DESC_DISC_RSP : 00177 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GATTC_EVT_DESC_DISC_RSP ", "Descriptor Discovery Response event."); 00178 break; 00179 case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP : 00180 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP", "Read By UUID Response event."); 00181 break; 00182 case BLE_GATTC_EVT_READ_RSP : 00183 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GATTC_EVT_READ_RSP ", "Read Response event."); 00184 break; 00185 case BLE_GATTC_EVT_CHAR_VALS_READ_RSP : 00186 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GATTC_EVT_CHAR_VALS_READ_RSP ", "Read multiple Response event."); 00187 break; 00188 case BLE_GATTC_EVT_WRITE_RSP : 00189 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GATTC_EVT_WRITE_RSP", "Write Response event."); 00190 break; 00191 case BLE_GATTC_EVT_HVX : 00192 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GATTC_EVT_HVX ", "Handle Value Notification or Indication event."); 00193 break; 00194 case BLE_GATTC_EVT_TIMEOUT : 00195 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GATTC_EVT_TIMEOUT ", "Timeout event."); 00196 break; 00197 // GATTS 00198 case BLE_GATTS_EVT_WRITE : 00199 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GATTS_EVT_WRITE ", "Write operation performed."); 00200 break; 00201 case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST : 00202 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST ", "Read/Write Authorization request."); 00203 break; 00204 case BLE_GATTS_EVT_SYS_ATTR_MISSING : 00205 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GATTS_EVT_SYS_ATTR_MISSING ", "A persistent system attribute access is pending, awaiting a sd_ble_gatts_sys_attr_set()."); 00206 break; 00207 case BLE_GATTS_EVT_HVC : 00208 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GATTS_EVT_HVC ", "Handle Value Confirmation."); 00209 break; 00210 case BLE_GATTS_EVT_SC_CONFIRM : 00211 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GATTS_EVT_SC_CONFIRM ", "Service Changed Confirmation."); 00212 break; 00213 case BLE_GATTS_EVT_TIMEOUT : 00214 snprintf(m_event_string, MAX_BUFFER, "%s (%s)", "BLE_GATTS_EVT_TIMEOUT ", "Timeout."); 00215 break; 00216 // 00217 default: 00218 snprintf(m_event_string, MAX_BUFFER, "Event: Unknown (%d)", p_ble_evt->header.evt_id); 00219 break; 00220 } 00221 00222 return m_event_string; 00223 } 00224 00225 00226 char *nrfevent2string(uint32_t evt_id) { 00227 switch (evt_id) { 00228 // case NRF_EVT_HFCLKSTARTED : 00229 // snprintf(m_nrfevent_string, MAX_BUFFER, "%s (%s)", "NRF_EVT_HFCLKSTARTED", "Event indicating that the HFCLK has started."); 00230 // break; 00231 // case NRF_EVT_POWER_FAILURE_WARNING : 00232 // snprintf(m_nrfevent_string, MAX_BUFFER, "%s (%s)", "NRF_EVT_POWER_FAILURE_WARNING", "Event indicating that a power failure warning has occurred."); 00233 // break; 00234 // case NRF_EVT_FLASH_OPERATION_SUCCESS : 00235 // snprintf(m_nrfevent_string, MAX_BUFFER, "%s (%s)", "NRF_EVT_FLASH_OPERATION_SUCCESS", "Event indicating that the ongoing flash operation has completed successfully."); 00236 // break; 00237 // case NRF_EVT_FLASH_OPERATION_ERROR : 00238 // snprintf(m_nrfevent_string, MAX_BUFFER, "%s (%s)", "NRF_EVT_FLASH_OPERATION_ERROR", "Event indicating that the ongoing flash operation has timed out with an error."); 00239 // break; 00240 // case NRF_EVT_HFCLKSTARTED : 00241 // snprintf(m_nrfevent_string, MAX_BUFFER, "%s (%s)", "NRF_EVT_HFCLKSTARTED ", "Event indicating that the HFCLK has started."); 00242 // break; 00243 // case NRF_EVT_POWER_FAILURE_WARNING : 00244 // snprintf(m_nrfevent_string, MAX_BUFFER, "%s (%s)", "NRF_EVT_POWER_FAILURE_WARNING", "Event indicating that a power failure warning has occurred."); 00245 // break; 00246 // case NRF_EVT_FLASH_OPERATION_SUCCESS : 00247 // snprintf(m_nrfevent_string, MAX_BUFFER, "%s (%s)", "NRF_EVT_FLASH_OPERATION_SUCCESS", "Event indicating that the ongoing flash operation has completed successfully."); 00248 // break; 00249 // case NRF_EVT_FLASH_OPERATION_ERROR : 00250 // snprintf(m_nrfevent_string, MAX_BUFFER, "%s (%s)", "NRF_EVT_FLASH_OPERATION_ERROR ", "Event indicating that the ongoing flash operation has timed out with an error."); 00251 // break; 00252 default: 00253 snprintf(m_nrfevent_string, MAX_BUFFER, "Event: Unknown (%d)", evt_id); 00254 break; 00255 } 00256 00257 return m_nrfevent_string; 00258 } 00259 00260 char *eventid2string(uint8_t d) { 00261 switch (d) { 00262 case 0 : 00263 snprintf(m_ancs_string, MAX_BUFFER, "%s", "Notification Added"); 00264 break; 00265 case 1 : 00266 snprintf(m_ancs_string, MAX_BUFFER, "%s", "Notification Modified"); 00267 break; 00268 case 2 : 00269 snprintf(m_ancs_string, MAX_BUFFER, "%s", "Notification Removed"); 00270 break; 00271 default: 00272 snprintf(m_ancs_string, MAX_BUFFER, "Reserved (%d)", d); 00273 break; 00274 } 00275 00276 return m_ancs_string; 00277 } 00278 00279 char *eventflags2string(uint8_t d) { 00280 snprintf(m_ancs_string, MAX_BUFFER, "(no flags)"); 00281 if(d & 3) { 00282 snprintf(m_ancs_string, MAX_BUFFER, "%s", "Silent & Important"); 00283 } else if(d & 1) { 00284 snprintf(m_ancs_string, MAX_BUFFER, "%s", "Silent"); 00285 } else if(d & 2) { 00286 snprintf(m_ancs_string, MAX_BUFFER, "%s", "Important"); 00287 } 00288 00289 return m_ancs_string; 00290 } 00291 00292 char *categoryid2string(uint8_t d) { 00293 switch (d) { 00294 case 0 : 00295 snprintf(m_ancs_string, MAX_BUFFER, "%s", "Other"); 00296 break; 00297 case 1 : 00298 snprintf(m_ancs_string, MAX_BUFFER, "%s", "Incomming Call"); 00299 break; 00300 case 2 : 00301 snprintf(m_ancs_string, MAX_BUFFER, "%s", "Missed Call"); 00302 break; 00303 case 3 : 00304 snprintf(m_ancs_string, MAX_BUFFER, "%s", "Voice Mail"); 00305 break; 00306 case 4 : 00307 snprintf(m_ancs_string, MAX_BUFFER, "%s", "Social"); 00308 break; 00309 case 5 : 00310 snprintf(m_ancs_string, MAX_BUFFER, "%s", "Schedule"); 00311 break; 00312 case 6 : 00313 snprintf(m_ancs_string, MAX_BUFFER, "%s", "Email"); 00314 break; 00315 case 7 : 00316 snprintf(m_ancs_string, MAX_BUFFER, "%s", "News"); 00317 break; 00318 case 8 : 00319 snprintf(m_ancs_string, MAX_BUFFER, "%s", "Health And Fitness"); 00320 break; 00321 case 9 : 00322 snprintf(m_ancs_string, MAX_BUFFER, "%s", "Business And Finance"); 00323 break; 00324 case 10 : 00325 snprintf(m_ancs_string, MAX_BUFFER, "%s", "Location"); // iBeacon? 00326 break; 00327 case 11 : 00328 snprintf(m_ancs_string, MAX_BUFFER, "%s", "Entertainment"); 00329 break; 00330 default: 00331 snprintf(m_ancs_string, MAX_BUFFER, "Reserved (%d)", d); 00332 break; 00333 } 00334 00335 return m_ancs_string; 00336 } 00337 00338
Generated on Tue Jul 12 2022 21:16:00 by
![doxygen](doxygen.png)