test_wxpay_shell.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2019 Actions Semi Co., Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief test shell.
  9. */
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <shell/shell.h>
  14. #include <bt_manager.h>
  15. #include <alipay_third.h>
  16. #include <vendor_ble_wxpay.h>
  17. #ifdef CONFIG_SHELL
  18. static int shell_lib_init(const struct shell *shell, size_t argc, char *argv[])
  19. {
  20. pay_lib_init(1);
  21. vendor_ble_wxpay_init();
  22. vendor_ble_wxpay_start_adv();
  23. shell_print(shell, "init paylib");
  24. return 0;
  25. }
  26. static int shell_ble_write(const struct shell *shell, size_t argc, char *argv[])
  27. {
  28. unsigned short dat = 0x55aa;
  29. if (argc >= 2) {
  30. dat = (unsigned short)strtoul(argv[1], NULL, 16);
  31. }
  32. vendor_ble_wxpay_write((uint8_t*)&dat, sizeof(dat));
  33. shell_print(shell, "ble_write test");
  34. return 0;
  35. }
  36. static int shell_status(const struct shell *shell, size_t argc, char *argv[])
  37. {
  38. wxpay_status_e binding_status;
  39. char buf[128] = {0};
  40. uint32_t buf_len = sizeof(buf);
  41. char name[32];
  42. uint32_t name_len = sizeof(name);
  43. uint32_t unix_sec = third_paylib_get_unix_second();
  44. bool connected = bt_manager_ble_is_connected();
  45. binding_status = wxpay_get_bind_status(unix_sec, connected, 0);
  46. shell_print(shell, "binding status: %d", binding_status);
  47. wxpay_get_bind_code(buf, (uint8_t*)&buf_len);
  48. shell_print(shell, "binding_string: %s", buf);
  49. wxpay_get_userinfo(name, (uint16_t*)&name_len, buf, (uint16_t*)&buf_len);
  50. shell_print(shell, "nick_name: %s, logon_ID: %s", name, buf);
  51. wxpay_get_bind_status(unix_sec, connected, 1); // update paycode
  52. wxpay_get_pay_code128(buf, (uint16_t*)&buf_len);
  53. shell_print(shell, "paycode: %s", buf);
  54. return 0;
  55. }
  56. static int shell_paycode(const struct shell *shell, size_t argc, char *argv[])
  57. {
  58. char buf[128] = {0};
  59. uint32_t buf_len = sizeof(buf);
  60. uint32_t unix_sec = third_paylib_get_unix_second();
  61. bool connected = bt_manager_ble_is_connected();
  62. wxpay_get_bind_status(unix_sec, connected, 1); // update paycode
  63. wxpay_get_pay_code128(buf, (uint16_t*)&buf_len);
  64. shell_print(shell, "paycode: %s", buf);
  65. return 0;
  66. }
  67. static int shell_unbinding(const struct shell *shell, size_t argc, char *argv[])
  68. {
  69. wxpay_detect_bind();
  70. pay_lib_init(1);
  71. shell_print(shell, "unbinding");
  72. return 0;
  73. }
  74. SHELL_STATIC_SUBCMD_SET_CREATE(wxpay_cmds,
  75. SHELL_CMD(init, NULL, "init paylib", shell_lib_init),
  76. SHELL_CMD(ble_write, NULL, "ble write test", shell_ble_write),
  77. SHELL_CMD(status, NULL, "get binding status", shell_status),
  78. SHELL_CMD(paycode, NULL, "get paycode", shell_paycode),
  79. SHELL_CMD(unbinding, NULL, "unbinding process", shell_unbinding),
  80. SHELL_SUBCMD_SET_END
  81. );
  82. SHELL_CMD_REGISTER(wxpay, &wxpay_cmds, "Wxpay shell commands", NULL);
  83. #endif