|
3 | 3 |
|
4 | 4 | package bluetooth |
5 | 5 |
|
| 6 | +// #include "nrf_error.h" |
| 7 | +// #include "nrf_error_sdm.h" |
| 8 | +import "C" |
| 9 | + |
6 | 10 | // Error is an error from within the SoftDevice. |
7 | 11 | type Error uint32 |
8 | 12 |
|
9 | 13 | func (e Error) Error() string { |
10 | 14 | switch { |
11 | | - case e < 0x1000: |
| 15 | + case e >= C.NRF_ERROR_BASE_NUM && e < C.NRF_ERROR_SDM_BASE_NUM: |
12 | 16 | // Global errors. |
13 | 17 | switch e { |
14 | | - case 0: |
| 18 | + case C.NRF_SUCCESS: |
15 | 19 | return "no error" |
16 | | - case 1: |
| 20 | + case C.NRF_ERROR_SVC_HANDLER_MISSING: |
17 | 21 | return "SVC handler is missing" |
18 | | - case 2: |
| 22 | + case C.NRF_ERROR_SOFTDEVICE_NOT_ENABLED: |
19 | 23 | return "SoftDevice has not been enabled" |
20 | | - case 3: |
| 24 | + case C.NRF_ERROR_INTERNAL: |
21 | 25 | return "internal error" |
22 | | - case 4: |
| 26 | + case C.NRF_ERROR_NO_MEM: |
23 | 27 | return "no memory for operation" |
24 | | - case 5: |
| 28 | + case C.NRF_ERROR_NOT_FOUND: |
25 | 29 | return "not found" |
26 | | - case 6: |
| 30 | + case C.NRF_ERROR_NOT_SUPPORTED: |
27 | 31 | return "not supported" |
28 | | - case 7: |
| 32 | + case C.NRF_ERROR_INVALID_PARAM: |
29 | 33 | return "invalid parameter" |
30 | | - case 8: |
| 34 | + case C.NRF_ERROR_INVALID_STATE: |
31 | 35 | return "invalid state, operation disallowed in this state" |
32 | | - case 9: |
| 36 | + case C.NRF_ERROR_INVALID_LENGTH: |
33 | 37 | return "invalid Length" |
34 | | - case 10: |
| 38 | + case C.NRF_ERROR_INVALID_FLAGS: |
35 | 39 | return "invalid flags" |
36 | | - case 11: |
| 40 | + case C.NRF_ERROR_INVALID_DATA: |
37 | 41 | return "invalid data" |
38 | | - case 12: |
| 42 | + case C.NRF_ERROR_DATA_SIZE: |
39 | 43 | return "invalid data size" |
40 | | - case 13: |
| 44 | + case C.NRF_ERROR_TIMEOUT: |
41 | 45 | return "operation timed out" |
42 | | - case 14: |
| 46 | + case C.NRF_ERROR_NULL: |
43 | 47 | return "null pointer" |
44 | | - case 15: |
| 48 | + case C.NRF_ERROR_FORBIDDEN: |
45 | 49 | return "forbidden operation" |
46 | | - case 16: |
| 50 | + case C.NRF_ERROR_INVALID_ADDR: |
47 | 51 | return "bad memory address" |
48 | | - case 17: |
| 52 | + case C.NRF_ERROR_BUSY: |
49 | 53 | return "busy" |
50 | | - case 18: |
| 54 | + case 18: // C.NRF_ERROR_CONN_COUNT, not available on nrf51 |
51 | 55 | return "maximum connection count exceeded" |
52 | | - case 19: |
| 56 | + case 19: // C.NRF_ERROR_RESOURCES, not available on nrf51 |
53 | 57 | return "not enough resources for operation" |
54 | 58 | default: |
55 | 59 | return "other global error" |
56 | 60 | } |
57 | | - case e < 0x2000: |
| 61 | + case e >= C.NRF_ERROR_SDM_BASE_NUM && e < C.NRF_ERROR_SOC_BASE_NUM: |
58 | 62 | // SDM errors. |
59 | 63 | switch e { |
60 | | - case 0x1000: |
| 64 | + case C.NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN: |
61 | 65 | return "unknown LFCLK source" |
62 | | - case 0x1001: |
| 66 | + case C.NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION: |
63 | 67 | return "incorrect interrupt configuration" |
64 | | - case 0x1002: |
| 68 | + case C.NRF_ERROR_SDM_INCORRECT_CLENR0: |
65 | 69 | return "incorrect CLENR0" |
66 | 70 | default: |
67 | 71 | return "other SDM error" |
68 | 72 | } |
69 | | - case e < 0x3000: |
| 73 | + case e >= C.NRF_ERROR_SOC_BASE_NUM && e < C.NRF_ERROR_STK_BASE_NUM: |
70 | 74 | // SoC errors. |
71 | 75 | return "other SoC error" |
72 | | - case e < 0x4000: |
| 76 | + case e >= C.NRF_ERROR_STK_BASE_NUM && e < 0x4000: |
73 | 77 | // STK errors. |
74 | 78 | return "other STK error" |
75 | 79 | default: |
|
0 commit comments