diff options
author | Uros Majstorovic <majstor@majstor.org> | 2020-08-09 02:07:13 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2020-08-09 02:07:13 +0200 |
commit | 9dd66a7dd0c5ba39f9b602daafea88a00cef75e8 (patch) | |
tree | 390e414ff712e8316d71d9a57535ca60224e9e8d | |
parent | 8c76421b174c6c53109df411a6670160a85933a1 (diff) |
unicode utf_len added; cell sms services added
-rw-r--r-- | fw/fe310/eos/cell.h | 9 | ||||
-rw-r--r-- | fw/fe310/eos/unicode.c | 24 | ||||
-rw-r--r-- | fw/fe310/eos/unicode.h | 2 |
3 files changed, 30 insertions, 5 deletions
diff --git a/fw/fe310/eos/cell.h b/fw/fe310/eos/cell.h index d8206f9..92c8c7c 100644 --- a/fw/fe310/eos/cell.h +++ b/fw/fe310/eos/cell.h @@ -27,6 +27,11 @@ #define EOS_CELL_MTYPE_VOICE_END 6 #define EOS_CELL_MTYPE_VOICE_MISSED 7 +#define EOS_CELL_MTYPE_SMS_LIST 1 +#define EOS_CELL_MTYPE_SMS_SEND 2 +#define EOS_CELL_MTYPE_SMS_MSG_NEW 3 +#define EOS_CELL_MTYPE_SMS_MSG_ITEM 4 + #define EOS_CELL_MTYPE_USSD_REQUEST 1 #define EOS_CELL_MTYPE_USSD_REPLY 2 @@ -34,5 +39,9 @@ #define EOS_CELL_MTYPE_DATA_CONNECT 2 #define EOS_CELL_MTYPE_DATA_DISCONNECT 3 +#define EOS_CELL_SMS_ADDRTYPE_INTL 1 +#define EOS_CELL_SMS_ADDRTYPE_ALPHA 2 +#define EOS_CELL_SMS_ADDRTYPE_OTHER 3 + void eos_cell_init(void); void eos_cell_set_handler(unsigned char mtype, eos_evt_handler_t handler);
\ No newline at end of file diff --git a/fw/fe310/eos/unicode.c b/fw/fe310/eos/unicode.c index 2915791..e2fb772 100644 --- a/fw/fe310/eos/unicode.c +++ b/fw/fe310/eos/unicode.c @@ -57,6 +57,15 @@ int utf8_dec(utf8_t *str, utf32_t *ch) { } } +int utf8_len(utf8_t *str) { + if ((*str & 0xf8) == 0xf0) return 4; + if ((*str & 0xf0) == 0xe0) return 3; + if ((*str & 0xe0) == 0xc0) return 2; + if ((*str & 0x80) == 0x00) return 1; + + return UTF_ERR; +} + int utf8_seek(utf8_t *str, int off, utf32_t *ch) { int i; int len = 0; @@ -91,11 +100,8 @@ int utf8_verify(utf8_t *str, int str_size, int *str_len) { while (len < str_size) { if (str_size - len < 4) { - if (((str[len] & 0xf8) == 0xf0) || - (((str[len] & 0xf0) == 0xe0) && (str_size - len < 3)) || - (((str[len] & 0xe0) == 0xc0) && (str_size - len < 2))) { - break; - } + int _len = utf8_len(str + len); + if ((_len == UTF_ERR) || ((str_size - len) < _len)) break; } ch_l = utf8_dec(str + len, &ch); if (ch_l > 0) { @@ -151,6 +157,14 @@ int utf16_dec(uint8_t *str, utf32_t *ch) { } } +int utf16_len(uint8_t *str) { + uint16_t ch = (str[0] << 8) | str[1]; + + if ((ch >= 0xdc00) && (ch <= 0xdfff)) return UTF_ERR; + if ((ch >= 0xd800) && (ch <= 0xdfff)) return 4; + return 2; +} + int utf16_seek(uint8_t *str, int off, utf32_t *ch) { int i; int len = 0; diff --git a/fw/fe310/eos/unicode.h b/fw/fe310/eos/unicode.h index a3b9696..12fa99c 100644 --- a/fw/fe310/eos/unicode.h +++ b/fw/fe310/eos/unicode.h @@ -9,9 +9,11 @@ typedef uint32_t utf32_t; int utf8_enc(utf32_t ch, utf8_t *str); int utf8_dec(utf8_t *str, utf32_t *ch); +int utf8_len(utf8_t *str); int utf8_seek(utf8_t *str, int off, utf32_t *ch); int utf8_verify(utf8_t *str, int str_size, int *str_len); int utf16_enc(utf32_t ch, uint8_t *str); int utf16_dec(uint8_t *str, utf32_t *ch); +int utf16_len(uint8_t *str); int utf16_seek(uint8_t *str, int off, utf32_t *ch); |