Skip to content

Commit 334038d

Browse files
authored
Merge pull request #10 from xiangxistu/master
【修改】直接使用ppp_device注册
2 parents 663f11f + 28795ce commit 334038d

File tree

8 files changed

+42
-133
lines changed

8 files changed

+42
-133
lines changed

SConscript

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@ src += Glob('samples/ppp_sample.c')
77

88
# Air720
99
if GetDepend(['PPP_DEVICE_USING_AIR720']):
10-
path += [cwd + '/class/air720']
11-
src += Glob('class/air720/ppp_device_air720.c')
10+
src += Glob('class/ppp_device_air720.c')
1211

1312
# M6312
1413
if GetDepend(['PPP_DEVICE_USING_M6312']):
15-
path += [cwd + '/class/m6312']
16-
src += Glob('class/m6312/ppp_device_m6312.c')
14+
src += Glob('class/ppp_device_m6312.c')
1715

1816
# SIM800
1917
if GetDepend(['PPP_DEVICE_USING_SIM800']):
20-
path += [cwd + '/class/sim800']
21-
src += Glob('class/sim800/ppp_device_sim800.c')
18+
src += Glob('class/ppp_device_sim800.c')
2219

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

class/air720/ppp_device_air720.h

Lines changed: 0 additions & 28 deletions
This file was deleted.

class/m6312/ppp_device_m6312.h

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* 2019-08-15 xiangxistu the first version
99
*/
1010

11-
#include <ppp_device_air720.h>
11+
#include <ppp_device.h>
1212
#include <ppp_chat.h>
1313
#include <rtdevice.h>
1414

@@ -27,6 +27,8 @@
2727
#define AIR720_POWER_PIN -1
2828
#endif
2929

30+
#define AIR720_WARTING_TIME_BASE 500
31+
3032
static const struct modem_chat_data rst_mcd[] =
3133
{
3234
{"+++", MODEM_CHAT_RESP_NOT_NEED, 30, 1, RT_TRUE},
@@ -43,12 +45,11 @@ static const struct modem_chat_data mcd[] =
4345

4446
static rt_err_t ppp_air720_prepare(struct ppp_device *device)
4547
{
46-
struct ppp_air720 *air720 = (struct ppp_air720*)device;
47-
if (air720->power_pin >= 0)
48+
if (device->power_pin >= 0)
4849
{
49-
rt_pin_write(air720->power_pin, AIR720_POWER_OFF);
50+
rt_pin_write(device->power_pin, AIR720_POWER_OFF);
5051
rt_thread_mdelay(AIR720_WARTING_TIME_BASE);
51-
rt_pin_write(air720->power_pin, AIR720_POWER_ON);
52+
rt_pin_write(device->power_pin, AIR720_POWER_ON);
5253
}
5354
else
5455
{
@@ -75,23 +76,20 @@ static struct ppp_device_ops air720_ops =
7576
int ppp_air720_register(void)
7677
{
7778
struct ppp_device *ppp_device = RT_NULL;
78-
struct ppp_air720 *air720 = RT_NULL;
7979

80-
air720 = rt_malloc(sizeof(struct ppp_air720));
81-
if(air720 == RT_NULL)
80+
ppp_device = rt_malloc(sizeof(struct ppp_device));
81+
if(ppp_device == RT_NULL)
8282
{
83-
LOG_E("No memory for struct air720.");
83+
LOG_E("No memory for air720 ppp_device.");
8484
return -RT_ENOMEM;
8585
}
8686

87-
air720->power_pin = AIR720_POWER_PIN;
88-
if (air720->power_pin >= 0)
87+
ppp_device->power_pin = AIR720_POWER_PIN;
88+
if (ppp_device->power_pin >= 0)
8989
{
90-
rt_pin_mode(air720->power_pin, PIN_MODE_OUTPUT);
91-
rt_pin_write(air720->power_pin, AIR720_POWER_OFF);
90+
rt_pin_mode(ppp_device->power_pin, PIN_MODE_OUTPUT);
91+
rt_pin_write(ppp_device->power_pin, AIR720_POWER_OFF);
9292
}
93-
94-
ppp_device = &(air720->device);
9593
ppp_device->ops = &air720_ops;
9694

9795
LOG_D("ppp air720 is registering ppp_device");
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* 2019-09-24 xiaofao the first version
99
*/
1010

11-
#include <ppp_device_m6312.h>
11+
#include <ppp_device.h>
1212
#include <ppp_chat.h>
1313
#include <rtdevice.h>
1414

@@ -27,6 +27,7 @@
2727
#define M6312_POWER_PIN -1
2828
#endif
2929

30+
#define M6312_WARTING_TIME_BASE 500
3031

3132
static const struct modem_chat_data rst_mcd[] =
3233
{
@@ -45,12 +46,11 @@ static const struct modem_chat_data mcd[] =
4546

4647
static rt_err_t ppp_m6312_prepare(struct ppp_device *device)
4748
{
48-
struct ppp_m6312 *m6312 = (struct ppp_m6312*)device;
49-
if (m6312->power_pin >= 0)
49+
if (device->power_pin >= 0)
5050
{
51-
rt_pin_write(m6312->power_pin, M6312_POWER_OFF);
51+
rt_pin_write(device->power_pin, M6312_POWER_OFF);
5252
rt_thread_mdelay(M6312_WARTING_TIME_BASE);
53-
rt_pin_write(m6312->power_pin, M6312_POWER_ON);
53+
rt_pin_write(device->power_pin, M6312_POWER_ON);
5454
}
5555
else
5656
{
@@ -77,23 +77,21 @@ static struct ppp_device_ops m6312_ops =
7777
int ppp_m6312_register(void)
7878
{
7979
struct ppp_device *ppp_device = RT_NULL;
80-
struct ppp_m6312 *m6312 = RT_NULL;
8180

82-
m6312 = rt_malloc(sizeof(struct ppp_m6312));
83-
if(m6312 == RT_NULL)
81+
ppp_device = rt_malloc(sizeof(struct ppp_device));
82+
if(ppp_device == RT_NULL)
8483
{
85-
LOG_E("No memory for struct m6312.");
84+
LOG_E("No memory for struct m6312 ppp_device.");
8685
return -RT_ENOMEM;
8786
}
8887

89-
m6312->power_pin = M6312_POWER_PIN;
90-
if (m6312->power_pin >= 0)
88+
ppp_device->power_pin = M6312_POWER_PIN;
89+
if (ppp_device->power_pin >= 0)
9190
{
92-
rt_pin_mode(m6312->power_pin, PIN_MODE_OUTPUT);
93-
rt_pin_write(m6312->power_pin, M6312_POWER_OFF);
91+
rt_pin_mode(ppp_device->power_pin, PIN_MODE_OUTPUT);
92+
rt_pin_write(ppp_device->power_pin, M6312_POWER_OFF);
9493
}
9594

96-
ppp_device = &(m6312->device);
9795
ppp_device->ops = &m6312_ops;
9896
LOG_D("ppp m6312 is registering ppp_device");
9997
return ppp_device_register(ppp_device, PPP_DEVICE_NAME, RT_NULL, RT_NULL);
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* 2019-08-15 xiangxistu the first version
99
*/
1010

11-
#include <ppp_device_sim800.h>
11+
#include <ppp_device.h>
1212
#include <ppp_chat.h>
1313
#include <rtdevice.h>
1414

@@ -27,6 +27,8 @@
2727
#define SIM800_POWER_PIN -1
2828
#endif
2929

30+
#define SIM800_WARTING_TIME_BASE 500
31+
3032
static const struct modem_chat_data rst_mcd[] =
3133
{
3234
{"+++", MODEM_CHAT_RESP_NOT_NEED, 30, 1, RT_TRUE},
@@ -43,12 +45,11 @@ static const struct modem_chat_data mcd[] =
4345

4446
static rt_err_t ppp_sim800_prepare(struct ppp_device *device)
4547
{
46-
struct ppp_sim800 *sim800 = (struct ppp_sim800*)device;
47-
if (sim800->power_pin >= 0)
48+
if (device->power_pin >= 0)
4849
{
49-
rt_pin_write(sim800->power_pin, SIM800_POWER_OFF);
50+
rt_pin_write(device->power_pin, SIM800_POWER_OFF);
5051
rt_thread_mdelay(SIM800_WARTING_TIME_BASE);
51-
rt_pin_write(sim800->power_pin, SIM800_POWER_ON);
52+
rt_pin_write(device->power_pin, SIM800_POWER_ON);
5253
}
5354
else
5455
{
@@ -75,23 +76,21 @@ static struct ppp_device_ops sim800_ops =
7576
int ppp_sim800_register(void)
7677
{
7778
struct ppp_device *ppp_device = RT_NULL;
78-
struct ppp_sim800 *sim800 = RT_NULL;
7979

80-
sim800 = rt_malloc(sizeof(struct ppp_sim800));
81-
if(sim800 == RT_NULL)
80+
ppp_device = rt_malloc(sizeof(struct ppp_device));
81+
if(ppp_device == RT_NULL)
8282
{
83-
LOG_E("No memory for struct sim800.");
83+
LOG_E("No memory for struct sim800 ppp_device.");
8484
return -RT_ENOMEM;
8585
}
8686

87-
sim800->power_pin = SIM800_POWER_PIN;
88-
if (sim800->power_pin >= 0)
87+
ppp_device->power_pin = SIM800_POWER_PIN;
88+
if (ppp_device->power_pin >= 0)
8989
{
90-
rt_pin_mode(sim800->power_pin, PIN_MODE_OUTPUT);
91-
rt_pin_write(sim800->power_pin, SIM800_POWER_OFF);
90+
rt_pin_mode(ppp_device->power_pin, PIN_MODE_OUTPUT);
91+
rt_pin_write(ppp_device->power_pin, SIM800_POWER_OFF);
9292
}
9393

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

9796
LOG_D("ppp sim800 is registering ppp_device");

class/sim800/ppp_device_sim800.h

Lines changed: 0 additions & 28 deletions
This file was deleted.

inc/ppp_device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct ppp_device
6767
rt_device_t uart; /* low-level uart device object */
6868
const struct ppp_device_ops *ops; /* ppp device ops interface */
6969
enum ppp_conn_type conn_type; /* using usb or uart */
70+
rt_base_t power_pin; /* power pin, if device need hardware reset */
7071

7172
ppp_pcb *pcb; /* ppp protocol control block */
7273
struct netif pppif;

0 commit comments

Comments
 (0)