21 #include "platform/mbed_retarget.h" 23 #include "events/EventQueue.h" 24 #include "PlatformMutex.h" 25 #include "nsapi_types.h" 41 #define AT_HANDLER_MUTEX 43 extern const char *OK;
44 extern const char *CRLF;
49 enum DeviceErrorType {
50 DeviceErrorTypeNoError = 0,
52 DeviceErrorTypeErrorCMS,
53 DeviceErrorTypeErrorCME
58 DeviceErrorType errType;
100 const char *delimiter, uint16_t send_delay,
bool debug_on);
148 void inc_ref_count();
154 void dec_ref_count();
167 void set_at_timeout(uint32_t timeout_milliseconds,
bool default_timeout =
false);
174 static void set_at_timeout_list(uint32_t timeout_milliseconds,
bool default_timeout =
false);
178 void restore_at_timeout();
204 void set_is_filehandle_usable(
bool usable);
211 bool sync(
int timeout_ms);
215 #ifdef AT_HANDLER_MUTEX 224 void remove_urc_handler(
const char *prefix);
230 int _last_3gpp_error;
232 uint16_t _oob_string_max_length;
233 char *_output_delimiter;
242 uint32_t _at_timeout;
243 uint32_t _previous_at_timeout;
245 uint16_t _at_send_delay;
246 uint64_t _last_response_stop;
262 virtual void cmd_start(
const char *cmd);
274 void cmd_start_stop(
const char *cmd,
const char *cmd_chr,
const char *format =
"", ...);
286 nsapi_error_t at_cmd_str(
const char *cmd,
const char *cmd_chr,
char *resp_buf,
size_t resp_buf_size,
const char *format =
"", ...);
297 nsapi_error_t at_cmd_int(
const char *cmd,
const char *cmd_chr,
int &resp,
const char *format =
"", ...);
307 nsapi_error_t at_cmd_discard(
const char *cmd,
const char *cmd_chr,
const char *format =
"", ...);
316 void write_int(int32_t param);
325 void write_string(
const char *param,
bool useQuotations =
true);
334 void cmd_stop_read_resp();
344 size_t write_bytes(
const uint8_t *data,
size_t len);
352 void set_stop_tag(
const char *stop_tag_seq);
359 void set_delimiter(
char delimiter);
363 void set_default_delimiter();
369 void use_delimiter(
bool use_delimiter);
375 void skip_param(uint32_t count = 1);
382 void skip_param(ssize_t len, uint32_t count);
390 ssize_t read_bytes(uint8_t *buf,
size_t len);
400 ssize_t read_string(
char *str,
size_t size,
bool read_even_stop_tag =
false);
411 ssize_t read_hex_string(
char *str,
size_t size);
427 void resp_start(
const char *prefix = NULL,
bool stop =
false);
457 bool info_elem(
char start_tag);
463 bool consume_to_stop_tag();
468 int get_3gpp_error();
480 void set_debug(
bool debug_on);
487 bool get_debug()
const;
493 static void set_debug_list(
bool debug_on);
498 char _recv_buff[BUFF_SIZE];
509 enum ScopeType {RespType, InfoType, ElemType, NotSet};
510 void set_scope(ScopeType scope_type);
511 ScopeType _current_scope;
531 bool _prefix_matched;
537 size_t _max_resp_length;
540 char _info_resp_prefix[BUFF_SIZE];
546 uint64_t _start_time;
548 char _cmd_buffer[BUFF_SIZE];
552 void handle_args(
const char *format, std::va_list list);
555 void handle_start(
const char *cmd,
const char *cmd_chr);
558 bool ok_to_proceed();
568 void rewind_buffer();
571 int poll_timeout(
bool wait_for_timeout =
true);
574 bool fill_buffer(
bool wait_for_timeout =
true);
576 void set_tag(tag_t *tag_dest,
const char *tag_seq);
579 bool match(
const char *str,
size_t size);
588 bool consume_char(
char ch);
591 bool consume_to_tag(
const char *tag,
bool consume_tag);
593 void resp(
const char *prefix,
bool check_urc);
596 ScopeType get_scope();
599 void information_response_stop();
601 void information_response_element_stop();
604 void at_error(
bool error_code, DeviceErrorType error_type);
610 void set_3gpp_error(
int err, DeviceErrorType error_type);
612 bool check_cmd_send();
613 size_t write(
const void *data,
size_t len);
624 const char *mem_str(
const char *dest,
size_t dest_len,
const char *src,
size_t src_len);
627 bool find_urc_handler(
const char *prefix);
635 void debug_print(
const char *p,
int len, ATType type);
640 #endif //AT_HANDLER_H_
signed int nsapi_error_t
Type used to represent error codes.
AT response error with error code and type.
Callback class based on template specialization.
Class for sending AT commands and parsing AT responses.