/* * Copyright (c) 2019 Actions Semi Co., Inc. * * SPDX-License-Identifier: Apache-2.0 */ /** * @file * @brief test shell. */ #include #include #include #include #include #include #include #ifdef CONFIG_SHELL static int shell_lib_init(const struct shell *shell, size_t argc, char *argv[]) { pay_lib_init(0); vendor_ble_alipay_init(); vendor_ble_alipay_start_adv(); shell_print(shell, "init paylib"); return 0; } static int shell_ble_write(const struct shell *shell, size_t argc, char *argv[]) { unsigned short dat = 0x55aa; if (argc >= 2) { dat = (unsigned short)strtoul(argv[1], NULL, 16); } vendor_ble_alipay_write((uint8_t*)&dat, sizeof(dat)); shell_print(shell, "ble_write test"); return 0; } static int shell_status(const struct shell *shell, size_t argc, char *argv[]) { alipay_status_e binding_status; char buf[128] = {0}; uint32_t buf_len = sizeof(buf); char name[32]; uint32_t name_len = sizeof(name); uint32_t unix_sec = third_paylib_get_unix_second(); bool connected = bt_manager_ble_is_connected(); binding_status = alipay_get_bind_status(unix_sec, connected, 0); shell_print(shell, "binding status: %d", binding_status); alipay_get_bind_code(buf, (uint8_t*)&buf_len); shell_print(shell, "binding_string: %s", buf); alipay_get_userinfo(name, (uint16_t*)&name_len, buf, (uint16_t*)&buf_len); shell_print(shell, "nick_name: %s, logon_ID: %s", name, buf); alipay_get_bind_status(unix_sec, connected, 1); // update paycode alipay_get_pay_code128(buf, (uint16_t*)&buf_len); shell_print(shell, "paycode: %s", buf); return 0; } static int shell_paycode(const struct shell *shell, size_t argc, char *argv[]) { char buf[128] = {0}; uint32_t buf_len = sizeof(buf); uint32_t unix_sec = third_paylib_get_unix_second(); bool connected = bt_manager_ble_is_connected(); alipay_get_bind_status(unix_sec, connected, 1); // update paycode alipay_get_pay_code128(buf, (uint16_t*)&buf_len); shell_print(shell, "paycode: %s", buf); return 0; } static int shell_unbinding(const struct shell *shell, size_t argc, char *argv[]) { alipay_detect_bind(); pay_lib_init(0); shell_print(shell, "unbinding"); return 0; } SHELL_STATIC_SUBCMD_SET_CREATE(alipay_cmds, SHELL_CMD(init, NULL, "init paylib", shell_lib_init), SHELL_CMD(ble_write, NULL, "ble write test", shell_ble_write), SHELL_CMD(status, NULL, "get binding status", shell_status), SHELL_CMD(paycode, NULL, "get paycode", shell_paycode), SHELL_CMD(unbinding, NULL, "unbinding process", shell_unbinding), SHELL_SUBCMD_SET_END ); SHELL_CMD_REGISTER(alipay, &alipay_cmds, "Alipay shell commands", NULL); #endif