extmod/network_ppp: Add stream config parameter.
This makes the stream that the PPP object wraps, which is normally only set once via the constructor, accessible and configurable via the `ppp.config()` method. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
This commit is contained in:
committed by
Damien George
parent
4fd5b72a8b
commit
161e2bd37d
@@ -70,8 +70,11 @@ Methods
|
|||||||
|
|
||||||
.. method:: PPP.config(config_parameters)
|
.. method:: PPP.config(config_parameters)
|
||||||
|
|
||||||
Sets or gets parameters of the PPP interface. There are currently no parameter that
|
Sets or gets parameters of the PPP interface. The only parameter that can be
|
||||||
can be set or retrieved.
|
retrieved and set is the underlying stream, using::
|
||||||
|
|
||||||
|
stream = PPP.config("stream")
|
||||||
|
PPP.config(stream=stream)
|
||||||
|
|
||||||
.. method:: PPP.ipconfig('param')
|
.. method:: PPP.ipconfig('param')
|
||||||
PPP.ipconfig(param=value, ...)
|
PPP.ipconfig(param=value, ...)
|
||||||
|
|||||||
@@ -153,12 +153,17 @@ static mp_obj_t network_ppp_config(size_t n_args, const mp_obj_t *args, mp_map_t
|
|||||||
if (n_args != 1 && kwargs->used != 0) {
|
if (n_args != 1 && kwargs->used != 0) {
|
||||||
mp_raise_TypeError(MP_ERROR_TEXT("either pos or kw args are allowed"));
|
mp_raise_TypeError(MP_ERROR_TEXT("either pos or kw args are allowed"));
|
||||||
}
|
}
|
||||||
// network_ppp_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
network_ppp_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||||
|
|
||||||
if (kwargs->used != 0) {
|
if (kwargs->used != 0) {
|
||||||
for (size_t i = 0; i < kwargs->alloc; i++) {
|
for (size_t i = 0; i < kwargs->alloc; i++) {
|
||||||
if (mp_map_slot_is_filled(kwargs, i)) {
|
if (mp_map_slot_is_filled(kwargs, i)) {
|
||||||
switch (mp_obj_str_get_qstr(kwargs->table[i].key)) {
|
switch (mp_obj_str_get_qstr(kwargs->table[i].key)) {
|
||||||
|
case MP_QSTR_stream: {
|
||||||
|
mp_get_stream_raise(kwargs->table[i].value, MP_STREAM_OP_READ | MP_STREAM_OP_WRITE);
|
||||||
|
self->stream = kwargs->table[i].value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -174,6 +179,10 @@ static mp_obj_t network_ppp_config(size_t n_args, const mp_obj_t *args, mp_map_t
|
|||||||
mp_obj_t val = mp_const_none;
|
mp_obj_t val = mp_const_none;
|
||||||
|
|
||||||
switch (mp_obj_str_get_qstr(args[1])) {
|
switch (mp_obj_str_get_qstr(args[1])) {
|
||||||
|
case MP_QSTR_stream: {
|
||||||
|
val = self->stream;
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
mp_raise_ValueError(MP_ERROR_TEXT("unknown config param"));
|
mp_raise_ValueError(MP_ERROR_TEXT("unknown config param"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -323,6 +323,11 @@ static mp_obj_t ppp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
|
|||||||
for (size_t i = 0; i < kwargs->alloc; i++) {
|
for (size_t i = 0; i < kwargs->alloc; i++) {
|
||||||
if (mp_map_slot_is_filled(kwargs, i)) {
|
if (mp_map_slot_is_filled(kwargs, i)) {
|
||||||
switch (mp_obj_str_get_qstr(kwargs->table[i].key)) {
|
switch (mp_obj_str_get_qstr(kwargs->table[i].key)) {
|
||||||
|
case MP_QSTR_stream: {
|
||||||
|
mp_get_stream_raise(kwargs->table[i].value, MP_STREAM_OP_READ | MP_STREAM_OP_WRITE);
|
||||||
|
self->stream = kwargs->table[i].value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -338,6 +343,10 @@ static mp_obj_t ppp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
|
|||||||
mp_obj_t val = mp_const_none;
|
mp_obj_t val = mp_const_none;
|
||||||
|
|
||||||
switch (mp_obj_str_get_qstr(args[1])) {
|
switch (mp_obj_str_get_qstr(args[1])) {
|
||||||
|
case MP_QSTR_stream: {
|
||||||
|
val = self->stream;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case MP_QSTR_ifname: {
|
case MP_QSTR_ifname: {
|
||||||
if (self->pcb != NULL) {
|
if (self->pcb != NULL) {
|
||||||
struct netif *pppif = ppp_netif(self->pcb);
|
struct netif *pppif = ppp_netif(self->pcb);
|
||||||
|
|||||||
Reference in New Issue
Block a user