Skip to content

Commit

Permalink
Merge pull request #10 from xiangxistu/master
Browse files Browse the repository at this point in the history
【修改】直接使用ppp_device注册
  • Loading branch information
armink authored Oct 11, 2019
2 parents 663f11f + 28795ce commit 334038d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 133 deletions.
9 changes: 3 additions & 6 deletions SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ src += Glob('samples/ppp_sample.c')

# Air720
if GetDepend(['PPP_DEVICE_USING_AIR720']):
path += [cwd + '/class/air720']
src += Glob('class/air720/ppp_device_air720.c')
src += Glob('class/ppp_device_air720.c')

# M6312
if GetDepend(['PPP_DEVICE_USING_M6312']):
path += [cwd + '/class/m6312']
src += Glob('class/m6312/ppp_device_m6312.c')
src += Glob('class/ppp_device_m6312.c')

# SIM800
if GetDepend(['PPP_DEVICE_USING_SIM800']):
path += [cwd + '/class/sim800']
src += Glob('class/sim800/ppp_device_sim800.c')
src += Glob('class/ppp_device_sim800.c')

group = DefineGroup('ppp_device', src, depend = ['PKG_USING_PPP_DEVICE'], CPPPATH = path)

Expand Down
28 changes: 0 additions & 28 deletions class/air720/ppp_device_air720.h

This file was deleted.

28 changes: 0 additions & 28 deletions class/m6312/ppp_device_m6312.h

This file was deleted.

28 changes: 13 additions & 15 deletions class/air720/ppp_device_air720.c → class/ppp_device_air720.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* 2019-08-15 xiangxistu the first version
*/

#include <ppp_device_air720.h>
#include <ppp_device.h>
#include <ppp_chat.h>
#include <rtdevice.h>

Expand All @@ -27,6 +27,8 @@
#define AIR720_POWER_PIN -1
#endif

#define AIR720_WARTING_TIME_BASE 500

static const struct modem_chat_data rst_mcd[] =
{
{"+++", MODEM_CHAT_RESP_NOT_NEED, 30, 1, RT_TRUE},
Expand All @@ -43,12 +45,11 @@ static const struct modem_chat_data mcd[] =

static rt_err_t ppp_air720_prepare(struct ppp_device *device)
{
struct ppp_air720 *air720 = (struct ppp_air720*)device;
if (air720->power_pin >= 0)
if (device->power_pin >= 0)
{
rt_pin_write(air720->power_pin, AIR720_POWER_OFF);
rt_pin_write(device->power_pin, AIR720_POWER_OFF);
rt_thread_mdelay(AIR720_WARTING_TIME_BASE);
rt_pin_write(air720->power_pin, AIR720_POWER_ON);
rt_pin_write(device->power_pin, AIR720_POWER_ON);
}
else
{
Expand All @@ -75,23 +76,20 @@ static struct ppp_device_ops air720_ops =
int ppp_air720_register(void)
{
struct ppp_device *ppp_device = RT_NULL;
struct ppp_air720 *air720 = RT_NULL;

air720 = rt_malloc(sizeof(struct ppp_air720));
if(air720 == RT_NULL)
ppp_device = rt_malloc(sizeof(struct ppp_device));
if(ppp_device == RT_NULL)
{
LOG_E("No memory for struct air720.");
LOG_E("No memory for air720 ppp_device.");
return -RT_ENOMEM;
}

air720->power_pin = AIR720_POWER_PIN;
if (air720->power_pin >= 0)
ppp_device->power_pin = AIR720_POWER_PIN;
if (ppp_device->power_pin >= 0)
{
rt_pin_mode(air720->power_pin, PIN_MODE_OUTPUT);
rt_pin_write(air720->power_pin, AIR720_POWER_OFF);
rt_pin_mode(ppp_device->power_pin, PIN_MODE_OUTPUT);
rt_pin_write(ppp_device->power_pin, AIR720_POWER_OFF);
}

ppp_device = &(air720->device);
ppp_device->ops = &air720_ops;

LOG_D("ppp air720 is registering ppp_device");
Expand Down
26 changes: 12 additions & 14 deletions class/m6312/ppp_device_m6312.c → class/ppp_device_m6312.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* 2019-09-24 xiaofao the first version
*/

#include <ppp_device_m6312.h>
#include <ppp_device.h>
#include <ppp_chat.h>
#include <rtdevice.h>

Expand All @@ -27,6 +27,7 @@
#define M6312_POWER_PIN -1
#endif

#define M6312_WARTING_TIME_BASE 500

static const struct modem_chat_data rst_mcd[] =
{
Expand All @@ -45,12 +46,11 @@ static const struct modem_chat_data mcd[] =

static rt_err_t ppp_m6312_prepare(struct ppp_device *device)
{
struct ppp_m6312 *m6312 = (struct ppp_m6312*)device;
if (m6312->power_pin >= 0)
if (device->power_pin >= 0)
{
rt_pin_write(m6312->power_pin, M6312_POWER_OFF);
rt_pin_write(device->power_pin, M6312_POWER_OFF);
rt_thread_mdelay(M6312_WARTING_TIME_BASE);
rt_pin_write(m6312->power_pin, M6312_POWER_ON);
rt_pin_write(device->power_pin, M6312_POWER_ON);
}
else
{
Expand All @@ -77,23 +77,21 @@ static struct ppp_device_ops m6312_ops =
int ppp_m6312_register(void)
{
struct ppp_device *ppp_device = RT_NULL;
struct ppp_m6312 *m6312 = RT_NULL;

m6312 = rt_malloc(sizeof(struct ppp_m6312));
if(m6312 == RT_NULL)
ppp_device = rt_malloc(sizeof(struct ppp_device));
if(ppp_device == RT_NULL)
{
LOG_E("No memory for struct m6312.");
LOG_E("No memory for struct m6312 ppp_device.");
return -RT_ENOMEM;
}

m6312->power_pin = M6312_POWER_PIN;
if (m6312->power_pin >= 0)
ppp_device->power_pin = M6312_POWER_PIN;
if (ppp_device->power_pin >= 0)
{
rt_pin_mode(m6312->power_pin, PIN_MODE_OUTPUT);
rt_pin_write(m6312->power_pin, M6312_POWER_OFF);
rt_pin_mode(ppp_device->power_pin, PIN_MODE_OUTPUT);
rt_pin_write(ppp_device->power_pin, M6312_POWER_OFF);
}

ppp_device = &(m6312->device);
ppp_device->ops = &m6312_ops;
LOG_D("ppp m6312 is registering ppp_device");
return ppp_device_register(ppp_device, PPP_DEVICE_NAME, RT_NULL, RT_NULL);
Expand Down
27 changes: 13 additions & 14 deletions class/sim800/ppp_device_sim800.c → class/ppp_device_sim800.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* 2019-08-15 xiangxistu the first version
*/

#include <ppp_device_sim800.h>
#include <ppp_device.h>
#include <ppp_chat.h>
#include <rtdevice.h>

Expand All @@ -27,6 +27,8 @@
#define SIM800_POWER_PIN -1
#endif

#define SIM800_WARTING_TIME_BASE 500

static const struct modem_chat_data rst_mcd[] =
{
{"+++", MODEM_CHAT_RESP_NOT_NEED, 30, 1, RT_TRUE},
Expand All @@ -43,12 +45,11 @@ static const struct modem_chat_data mcd[] =

static rt_err_t ppp_sim800_prepare(struct ppp_device *device)
{
struct ppp_sim800 *sim800 = (struct ppp_sim800*)device;
if (sim800->power_pin >= 0)
if (device->power_pin >= 0)
{
rt_pin_write(sim800->power_pin, SIM800_POWER_OFF);
rt_pin_write(device->power_pin, SIM800_POWER_OFF);
rt_thread_mdelay(SIM800_WARTING_TIME_BASE);
rt_pin_write(sim800->power_pin, SIM800_POWER_ON);
rt_pin_write(device->power_pin, SIM800_POWER_ON);
}
else
{
Expand All @@ -75,23 +76,21 @@ static struct ppp_device_ops sim800_ops =
int ppp_sim800_register(void)
{
struct ppp_device *ppp_device = RT_NULL;
struct ppp_sim800 *sim800 = RT_NULL;

sim800 = rt_malloc(sizeof(struct ppp_sim800));
if(sim800 == RT_NULL)
ppp_device = rt_malloc(sizeof(struct ppp_device));
if(ppp_device == RT_NULL)
{
LOG_E("No memory for struct sim800.");
LOG_E("No memory for struct sim800 ppp_device.");
return -RT_ENOMEM;
}

sim800->power_pin = SIM800_POWER_PIN;
if (sim800->power_pin >= 0)
ppp_device->power_pin = SIM800_POWER_PIN;
if (ppp_device->power_pin >= 0)
{
rt_pin_mode(sim800->power_pin, PIN_MODE_OUTPUT);
rt_pin_write(sim800->power_pin, SIM800_POWER_OFF);
rt_pin_mode(ppp_device->power_pin, PIN_MODE_OUTPUT);
rt_pin_write(ppp_device->power_pin, SIM800_POWER_OFF);
}

ppp_device = &(sim800->device);
ppp_device->ops = &sim800_ops;

LOG_D("ppp sim800 is registering ppp_device");
Expand Down
28 changes: 0 additions & 28 deletions class/sim800/ppp_device_sim800.h

This file was deleted.

1 change: 1 addition & 0 deletions inc/ppp_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct ppp_device
rt_device_t uart; /* low-level uart device object */
const struct ppp_device_ops *ops; /* ppp device ops interface */
enum ppp_conn_type conn_type; /* using usb or uart */
rt_base_t power_pin; /* power pin, if device need hardware reset */

ppp_pcb *pcb; /* ppp protocol control block */
struct netif pppif;
Expand Down

0 comments on commit 334038d

Please sign in to comment.