1、support adapter_bluetooth and hc08 device;2、fix adapter at agent bug。
This commit is contained in:
@@ -17,3 +17,96 @@
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.06.25
|
||||
*/
|
||||
|
||||
#include <adapter.h>
|
||||
|
||||
#ifdef ADAPTER_HC08
|
||||
extern AdapterProductInfoType Hc08Attach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
#define ADAPTER_BLUETOOTH_NAME "BlueTooth"
|
||||
|
||||
static int AdapterBlueToothRegister(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
strncpy(adapter->name, ADAPTER_BLUETOOTH_NAME, NAME_NUM_MAX);
|
||||
|
||||
adapter->net_protocol = IP_PROTOCOL;
|
||||
adapter->adapter_status = UNREGISTERED;
|
||||
|
||||
ret = AdapterDeviceRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("AdapterBlueToothRegister register error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int AdapterBlueToothInit(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
struct Adapter *adapter = PrivMalloc(sizeof(struct Adapter));
|
||||
if (!adapter) {
|
||||
free(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(adapter, 0, sizeof(struct Adapter));
|
||||
|
||||
ret = AdapterBlueToothRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("AdapterBlueToothInit register BT adapter error\n");
|
||||
free(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef ADAPTER_HC08
|
||||
AdapterProductInfoType product_info = Hc08Attach(adapter);
|
||||
if (!product_info) {
|
||||
printf("AdapterBlueToothInit hc08 attach error\n");
|
||||
free(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
adapter->product_info_flag = 1;
|
||||
adapter->info = product_info;
|
||||
adapter->done = product_info->model_done;
|
||||
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/******************4G TEST*********************/
|
||||
int AdapterBlueToothTest(void)
|
||||
{
|
||||
const char *bluetooth_msg = "BT Adapter Test";
|
||||
char bluetooth_recv_msg[128];
|
||||
char recv_msg[128];
|
||||
int len;
|
||||
int baud_rate = BAUD_RATE_115200;
|
||||
|
||||
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_BLUETOOTH_NAME);
|
||||
|
||||
#ifdef ADAPTER_HC08
|
||||
AdapterDeviceOpen(adapter);
|
||||
AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
|
||||
|
||||
len = strlen(bluetooth_msg);
|
||||
|
||||
while (1) {
|
||||
AdapterDeviceRecv(adapter, bluetooth_recv_msg, 128);
|
||||
printf("bluetooth_recv_msg %s\n", bluetooth_recv_msg);
|
||||
AdapterDeviceSend(adapter, bluetooth_msg, len);
|
||||
printf("send %s after recv\n", bluetooth_msg);
|
||||
PrivTaskDelay(100);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterBlueToothTest, AdapterBlueToothTest, show adapter BT information);
|
||||
|
||||
Reference in New Issue
Block a user