| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 | /* * Copyright (c) 2019 Actions Semi Co., Inc. * * SPDX-License-Identifier: Apache-2.0 *//** * @file * @brief test shell. */#include <stdio.h>#include <string.h>#include <stdlib.h>#include <shell/shell.h>#include <bt_manager.h>#include <alipay_third.h>#include <vendor_ble_wxpay.h>#ifdef CONFIG_SHELLstatic int shell_lib_init(const struct shell *shell, size_t argc, char *argv[]){	pay_lib_init(1);	vendor_ble_wxpay_init();	vendor_ble_wxpay_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_wxpay_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[]){	wxpay_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 = wxpay_get_bind_status(unix_sec, connected, 0);	shell_print(shell, "binding status: %d", binding_status);	wxpay_get_bind_code(buf, (uint8_t*)&buf_len);	shell_print(shell, "binding_string: %s", buf);	wxpay_get_userinfo(name, (uint16_t*)&name_len, buf, (uint16_t*)&buf_len);	shell_print(shell, "nick_name: %s, logon_ID: %s", name, buf);	wxpay_get_bind_status(unix_sec, connected, 1); // update paycode	wxpay_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();	wxpay_get_bind_status(unix_sec, connected, 1); // update paycode	wxpay_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[]){	wxpay_detect_bind();	pay_lib_init(1);	shell_print(shell, "unbinding");	return 0;}SHELL_STATIC_SUBCMD_SET_CREATE(wxpay_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(wxpay, &wxpay_cmds, "Wxpay shell commands", NULL);#endif
 |