You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

11 months ago
  1. #include "errorcode.h"
  2. #define ERR2STR(code) \
  3. case code: \
  4. return #code;
  5. #define ERR_ITERM(enum) \
  6. { enum, #enum }
  7. static ecode_table_item_t table[] = {
  8. ERR_ITERM(ksucc),
  9. ERR_ITERM(kfail),
  10. ERR_ITERM(kparam_out_of_range),
  11. ERR_ITERM(kcmd_not_support),
  12. ERR_ITERM(kdevice_is_busy),
  13. ERR_ITERM(kdevice_is_offline),
  14. ERR_ITERM(kovertime),
  15. ERR_ITERM(knoack),
  16. ERR_ITERM(kerrorack),
  17. ERR_ITERM(kdevice_offline),
  18. ERR_ITERM(ksubdevice_overtime),
  19. ERR_ITERM(kbuffer_not_enough),
  20. ERR_ITERM(kcmd_param_num_error),
  21. ERR_ITERM(kcheckcode_is_error),
  22. ERR_ITERM(killegal_operation),
  23. ERR_ITERM(kstep_motor_not_found_zero_point),
  24. ERR_ITERM(kstep_motor_not_go_zero),
  25. ERR_ITERM(kstep_motor_over_temperature),
  26. ERR_ITERM(kstep_motor_over_voltage),
  27. ERR_ITERM(kstep_motor_run_overtime),
  28. ERR_ITERM(kstep_motor_not_enable),
  29. ERR_ITERM(kstep_motor_ioindex_out_of_range),
  30. ERR_ITERM(kstep_motor_subic_reset),
  31. ERR_ITERM(kstep_motor_drv_err),
  32. ERR_ITERM(kstep_motor_uv_cp),
  33. ERR_ITERM(kstep_motor_not_found_point_edge),
  34. };
  35. const char* error2str(int32_t code) {
  36. for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++) {
  37. if (table[i].index == code) {
  38. return table[i].info;
  39. }
  40. }
  41. return "unknown error";
  42. }
  43. ecode_table_item_t* error_get_table() { return table; }
  44. int error_get_table_size() { return sizeof(table) / sizeof(table[0]); }