Skip to content

Commit 47d5346

Browse files
aykevldeadprogram
authored andcommitted
sd: use constants from C instead of magic numbers
1 parent f844306 commit 47d5346

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

error_sd.go

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,73 +3,77 @@
33

44
package bluetooth
55

6+
// #include "nrf_error.h"
7+
// #include "nrf_error_sdm.h"
8+
import "C"
9+
610
// Error is an error from within the SoftDevice.
711
type Error uint32
812

913
func (e Error) Error() string {
1014
switch {
11-
case e < 0x1000:
15+
case e >= C.NRF_ERROR_BASE_NUM && e < C.NRF_ERROR_SDM_BASE_NUM:
1216
// Global errors.
1317
switch e {
14-
case 0:
18+
case C.NRF_SUCCESS:
1519
return "no error"
16-
case 1:
20+
case C.NRF_ERROR_SVC_HANDLER_MISSING:
1721
return "SVC handler is missing"
18-
case 2:
22+
case C.NRF_ERROR_SOFTDEVICE_NOT_ENABLED:
1923
return "SoftDevice has not been enabled"
20-
case 3:
24+
case C.NRF_ERROR_INTERNAL:
2125
return "internal error"
22-
case 4:
26+
case C.NRF_ERROR_NO_MEM:
2327
return "no memory for operation"
24-
case 5:
28+
case C.NRF_ERROR_NOT_FOUND:
2529
return "not found"
26-
case 6:
30+
case C.NRF_ERROR_NOT_SUPPORTED:
2731
return "not supported"
28-
case 7:
32+
case C.NRF_ERROR_INVALID_PARAM:
2933
return "invalid parameter"
30-
case 8:
34+
case C.NRF_ERROR_INVALID_STATE:
3135
return "invalid state, operation disallowed in this state"
32-
case 9:
36+
case C.NRF_ERROR_INVALID_LENGTH:
3337
return "invalid Length"
34-
case 10:
38+
case C.NRF_ERROR_INVALID_FLAGS:
3539
return "invalid flags"
36-
case 11:
40+
case C.NRF_ERROR_INVALID_DATA:
3741
return "invalid data"
38-
case 12:
42+
case C.NRF_ERROR_DATA_SIZE:
3943
return "invalid data size"
40-
case 13:
44+
case C.NRF_ERROR_TIMEOUT:
4145
return "operation timed out"
42-
case 14:
46+
case C.NRF_ERROR_NULL:
4347
return "null pointer"
44-
case 15:
48+
case C.NRF_ERROR_FORBIDDEN:
4549
return "forbidden operation"
46-
case 16:
50+
case C.NRF_ERROR_INVALID_ADDR:
4751
return "bad memory address"
48-
case 17:
52+
case C.NRF_ERROR_BUSY:
4953
return "busy"
50-
case 18:
54+
case 18: // C.NRF_ERROR_CONN_COUNT, not available on nrf51
5155
return "maximum connection count exceeded"
52-
case 19:
56+
case 19: // C.NRF_ERROR_RESOURCES, not available on nrf51
5357
return "not enough resources for operation"
5458
default:
5559
return "other global error"
5660
}
57-
case e < 0x2000:
61+
case e >= C.NRF_ERROR_SDM_BASE_NUM && e < C.NRF_ERROR_SOC_BASE_NUM:
5862
// SDM errors.
5963
switch e {
60-
case 0x1000:
64+
case C.NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN:
6165
return "unknown LFCLK source"
62-
case 0x1001:
66+
case C.NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION:
6367
return "incorrect interrupt configuration"
64-
case 0x1002:
68+
case C.NRF_ERROR_SDM_INCORRECT_CLENR0:
6569
return "incorrect CLENR0"
6670
default:
6771
return "other SDM error"
6872
}
69-
case e < 0x3000:
73+
case e >= C.NRF_ERROR_SOC_BASE_NUM && e < C.NRF_ERROR_STK_BASE_NUM:
7074
// SoC errors.
7175
return "other SoC error"
72-
case e < 0x4000:
76+
case e >= C.NRF_ERROR_STK_BASE_NUM && e < 0x4000:
7377
// STK errors.
7478
return "other STK error"
7579
default:

0 commit comments

Comments
 (0)