add class bc28
This commit is contained in:
parent
4730f31d96
commit
bd03f57ead
11
SConscript
11
SConscript
|
@ -120,7 +120,16 @@ if GetDepend(['AT_DEVICE_USING_ME3616']):
|
|||
src += Glob('class/me3616/at_socket_me3616.c')
|
||||
if GetDepend(['AT_DEVICE_ME3616_SAMPLE']):
|
||||
src += Glob('samples/at_sample_me3616.c')
|
||||
|
||||
|
||||
# BC28
|
||||
if GetDepend(['AT_DEVICE_USING_BC28']):
|
||||
path += [cwd + '/class/bc28']
|
||||
src += Glob('class/bc28/at_device_bc28.c')
|
||||
if GetDepend(['AT_USING_SOCKET']):
|
||||
src += Glob('class/bc28/at_socket_bc28.c')
|
||||
if GetDepend(['AT_DEVICE_BC28_SAMPLE']):
|
||||
src += Glob('samples/at_sample_bc28.c')
|
||||
|
||||
group = DefineGroup('at_device', src, depend = ['PKG_USING_AT_DEVICE'], CPPPATH = path)
|
||||
|
||||
Return('group')
|
||||
|
|
|
@ -0,0 +1,215 @@
|
|||
/*
|
||||
* File : at_device_bc28.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* Copyright (c) 2020, RudyLo <luhuadong@163.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-02-12 luhuadong first version
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <at_device_bc28.h>
|
||||
|
||||
#define LOG_TAG "at.dev.bc28"
|
||||
#include <at_log.h>
|
||||
|
||||
#ifdef AT_DEVICE_USING_BC28
|
||||
|
||||
#define BC28_WAIT_CONNECT_TIME 5000
|
||||
#define BC28_THREAD_STACK_SIZE 2048
|
||||
#define BC28_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX/2)
|
||||
|
||||
static void bc28_power_on(struct at_device *device)
|
||||
{
|
||||
struct at_device_bc28 *bc28 = RT_NULL;
|
||||
|
||||
bc28 = (struct at_device_bc28 *)device->user_data;
|
||||
bc28->power_status = RT_TRUE;
|
||||
|
||||
/* not need to set pin configuration for bc28 device power on */
|
||||
if (bc28->power_pin == -1)
|
||||
{
|
||||
return(RT_EOK);
|
||||
}
|
||||
|
||||
rt_pin_write(bc28->power_pin, PIN_HIGH);
|
||||
rt_thread_mdelay(500);
|
||||
rt_pin_write(bc28->power_pin, PIN_LOW);
|
||||
|
||||
return(RT_EOK);
|
||||
}
|
||||
|
||||
static void bc28_power_off(struct at_device *device)
|
||||
{
|
||||
at_response_t resp = RT_NULL;
|
||||
struct at_device_bc28 *bc28 = RT_NULL;
|
||||
|
||||
resp = at_create_resp(64, 0, rt_tick_from_millisecond(300));
|
||||
if (resp == RT_NULL)
|
||||
{
|
||||
LOG_D("no memory for resp create.");
|
||||
return(-RT_ERROR);
|
||||
}
|
||||
|
||||
if (at_obj_exec_cmd(device->client, resp, "AT+QPOWD=0") != RT_EOK)
|
||||
{
|
||||
LOG_D("power off fail.");
|
||||
at_delete_resp(resp);
|
||||
return(-RT_ERROR);
|
||||
}
|
||||
|
||||
at_delete_resp(resp);
|
||||
|
||||
bc28 = (struct at_device_bc28 *)device->user_data;
|
||||
bc28->power_status = RT_FALSE;
|
||||
|
||||
return(RT_EOK);
|
||||
}
|
||||
|
||||
at_device_bc28 functions
|
||||
|
||||
|
||||
static int bc28_power_on();
|
||||
static int bc28_power_off();
|
||||
static int bc28_sleep();
|
||||
static int bc28_wakeup();
|
||||
|
||||
static int bc28_check_link_status();
|
||||
static int bc28_netdev_set_info();
|
||||
|
||||
static void bc28_check_link_status_entry();
|
||||
static int bc28_netdev_check_link_status();
|
||||
|
||||
static int bc28_netdev_set_up();
|
||||
static int bc28_netdev_set_down();
|
||||
static int bc28_netdev_set_dns_server();
|
||||
static int bc28_netdev_ping();
|
||||
|
||||
const struct netdev_ops bc28_netdev_ops =
|
||||
{
|
||||
bc28_netdev_set_up,
|
||||
bc28_netdev_set_down,
|
||||
RT_NULL,
|
||||
bc28_netdev_set_dns_server,
|
||||
RT_NULL,
|
||||
#ifdef NETDEV_USING_PING
|
||||
bc28_netdev_ping,
|
||||
#endif
|
||||
RT_NULL,
|
||||
};
|
||||
|
||||
|
||||
static struct netdev *bc28_netdev_add();
|
||||
|
||||
static void bc28_init_thread_entry();
|
||||
|
||||
static int bc28_net_init();
|
||||
|
||||
|
||||
static int bc28_init(struct at_device *device)
|
||||
{
|
||||
struct at_device_bc28 *bc28 = (struct at_device_bc28 *)device->user_data;
|
||||
|
||||
/* initialize AT client */
|
||||
at_client_init(bc28->client_name, bc28->recv_bufsz);
|
||||
|
||||
device->client = at_client_get(bc28->client_name);
|
||||
if (device->client == RT_NULL)
|
||||
{
|
||||
LOG_E("get AT client(%s) failed.", bc28->client_name);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
/* register URC data execution function */
|
||||
#ifdef AT_USING_SOCKET
|
||||
bc28_socket_init(device);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int bc28_deinit(struct at_device *device)
|
||||
{
|
||||
RT_ASSERT(device);
|
||||
|
||||
return bc28_netdev_set_down(device->netdev);
|
||||
}
|
||||
|
||||
static int bc28_control(struct at_device *device, int cmd, void *arg)
|
||||
{
|
||||
int result = -RT_ERROR;
|
||||
|
||||
RT_ASSERT(device);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case AT_DEVICE_CTRL_SLEEP:
|
||||
result = bc28_sleep(device);
|
||||
break;
|
||||
case AT_DEVICE_CTRL_WAKEUP:
|
||||
result = bc28_wakeup(device);
|
||||
break;
|
||||
case AT_DEVICE_CTRL_POWER_ON:
|
||||
case AT_DEVICE_CTRL_POWER_OFF:
|
||||
case AT_DEVICE_CTRL_RESET:
|
||||
case AT_DEVICE_CTRL_LOW_POWER:
|
||||
case AT_DEVICE_CTRL_NET_CONN:
|
||||
case AT_DEVICE_CTRL_NET_DISCONN:
|
||||
case AT_DEVICE_CTRL_SET_WIFI_INFO:
|
||||
case AT_DEVICE_CTRL_GET_SIGNAL:
|
||||
case AT_DEVICE_CTRL_GET_GPS:
|
||||
case AT_DEVICE_CTRL_GET_VER:
|
||||
LOG_W("not support the control command(%d).", cmd);
|
||||
break;
|
||||
default:
|
||||
LOG_E("input error control command(%d).", cmd);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const struct at_device_ops bc28_device_ops =
|
||||
{
|
||||
bc28_init,
|
||||
bc28_deinit,
|
||||
bc28_control,
|
||||
};
|
||||
|
||||
static int bc28_device_class_register(void)
|
||||
{
|
||||
struct at_device_class *class = RT_NULL;
|
||||
|
||||
class = (struct at_device_class *) rt_calloc(1, sizeof(struct at_device_class));
|
||||
if (class == RT_NULL)
|
||||
{
|
||||
LOG_E("no memory for device class create.");
|
||||
return -RT_ENOMEM;
|
||||
}
|
||||
|
||||
/* fill bc26 device class object */
|
||||
#ifdef AT_USING_SOCKET
|
||||
bc28_socket_class_register(class);
|
||||
#endif
|
||||
class->device_ops = &bc28_device_ops;
|
||||
|
||||
return at_device_class_register(class, AT_DEVICE_CLASS_BC28);
|
||||
}
|
||||
INIT_DEVICE_EXPORT(bc28_device_class_register);
|
||||
|
||||
#endif /* AT_DEVICE_USING_BC28 */
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* File : at_device_bc28.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* Copyright (c) 2020, RudyLo <luhuadong@163.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-02-12 luhuadong first version
|
||||
*/
|
||||
|
||||
#ifndef __AT_DEVICE_BC28_H__
|
||||
#define __AT_DEVICE_BC28_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <at_device.h>
|
||||
|
||||
/* The maximum number of sockets supported by the BC28 device */
|
||||
#define AT_DEVICE_BC28_SOCKETS_NUM 7
|
||||
|
||||
struct at_device_bc28
|
||||
{
|
||||
char *device_name;
|
||||
char *client_name;
|
||||
|
||||
int reset_pin;
|
||||
int adc_pin;
|
||||
size_t recv_bufsz;
|
||||
struct at_device device;
|
||||
|
||||
void *socket_data;
|
||||
void *user_data;
|
||||
|
||||
rt_bool_t power_status;
|
||||
rt_bool_t sleep_status;
|
||||
};
|
||||
|
||||
#ifdef AT_USING_SOCKET
|
||||
|
||||
/* bc28 device socket initialize */
|
||||
int bc28_socket_init(struct at_device *device);
|
||||
|
||||
/* bc28 device class socket register */
|
||||
int bc28_socket_class_register(struct at_device_class *class);
|
||||
|
||||
#endif /* AT_USING_SOCKET */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __AT_DEVICE_BC28_H__ */
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* File : at_socket_bc28.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* Copyright (c) 2020, RudyLo <luhuadong@163.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-02-13 luhuadong first version
|
||||
*/
|
|
@ -57,6 +57,7 @@ extern "C" {
|
|||
#define AT_DEVICE_CLASS_BC26 0x0BU
|
||||
#define AT_DEVICE_CLASS_AIR720 0x0CU
|
||||
#define AT_DEVICE_CLASS_ME3616 0x0DU
|
||||
#define AT_DEVICE_CLASS_BC28 0x0EU
|
||||
|
||||
/* Options and Commands for AT device control opreations */
|
||||
#define AT_DEVICE_CTRL_POWER_ON 0x01L
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* File : at_sample_bc28.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* Copyright (c) 2020, RudyLo <luhuadong@163.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-02-13 luhuadong first version
|
||||
*/
|
||||
|
||||
#include <at_device_bc28.h>
|
||||
|
||||
#define LOG_TAG "at.sample.bc28"
|
||||
#include <at_log.h>
|
||||
|
||||
#define BC28_SAMPLE_DEIVCE_NAME "bc28"
|
||||
|
||||
static struct at_device_bc28 _dev =
|
||||
{
|
||||
BC28_SAMPLE_DEIVCE_NAME,
|
||||
BC28_SAMPLE_CLIENT_NAME,
|
||||
|
||||
BC28_SAMPLE_POWER_PIN,
|
||||
BC28_SAMPLE_STATUS_PIN,
|
||||
BC28_SAMPLE_RECV_BUFF_LEN,
|
||||
};
|
||||
|
||||
static int bc28_device_register(void)
|
||||
{
|
||||
struct at_device_bc28 *bc28 = &_dev;
|
||||
|
||||
return at_device_register(&(bc28->device),
|
||||
bc28->device_name,
|
||||
bc28->client_name,
|
||||
AT_DEVICE_CLASS_BC28,
|
||||
(void *) bc28);
|
||||
}
|
||||
INIT_APP_EXPORT(bc28_device_register);
|
||||
|
Loading…
Reference in New Issue