pulkin / micropython

MicroPython implementation on Ai-Thinker GPRS module A9 (RDA8955)
https://micropython.org
MIT License
102 stars 30 forks source link

Add optional timeout arguments to `cellular` and `gps` functions #15

Open pulkin opened 4 years ago

pulkin commented 4 years ago
  1. cellular.SMS.list
  2. cellular.SMS.send
  3. cellular.attach
  4. cellular.activate cellular.gprs
  5. gps.on
pulkin commented 4 years ago
  1. cellular.flight_mode
  2. cellular.register
  3. cellular.stations
pulkin commented 4 years ago
  1. Learn how variable number of arguments is implemented in docs: MP_DEFINE_CONST_FUN_OBJ_KW, etc;
  2. Choose either of the above functions (fixing cellular.gprs is a bit more involved but still the same);
  3. Change the corresponding MP_DEFINE_CONST_FUN_OBJ_0 into MP_DEFINE_CONST_FUN_OBJ_KW;

https://github.com/pulkin/micropython/blob/0b89a2f1fe074767c9de1881fd89a9b048a96156/ports/gprs_a9/modcellular.c#L495-L525

  1. Change the function signature to
STATIC mp_obj_t fun(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
...
}
  1. Parse arguments for a single / additional timeout argument;
  2. Use the timeout argument WAIT_UNTIL macro or the wait loop (if any) instead of the corresponding constant (TIMEOUT_SMS_LIST in this particular case);

https://github.com/pulkin/micropython/blob/0b89a2f1fe074767c9de1881fd89a9b048a96156/ports/gprs_a9/modcellular.c#L510

  1. Note the constant default value and remove it from the corresponding header file

https://github.com/pulkin/micropython/blob/0b89a2f1fe074767c9de1881fd89a9b048a96156/ports/gprs_a9/modcellular.h#L66-L73

  1. Build the firmware and test it;
  2. PR here