From fbd63b4e8ea4a641cc7c1860d415c99641f944a2 Mon Sep 17 00:00:00 2001 From: jixiaowei Date: Wed, 20 Oct 2021 10:21:45 +0800 Subject: [PATCH] style(components): modify oneos-lite components folder code style --- components/atest/include/atest.h | 193 +++---- components/atest/source/atest.c | 286 +++++----- components/cplusplus/demo/test.cpp | 9 +- components/cplusplus/demo/test1.c | 1 - components/cplusplus/include/cpp_mem.h | 4 +- components/cplusplus/source/cpp_init.c | 12 +- components/cplusplus/source/cpp_mem.cpp | 1 - components/dlog/include/dlog.h | 93 ++- components/dlog/include/syslog/syslog.h | 76 ++- .../dlog/source/backend/console_backend.c | 15 +- components/dlog/source/dlog.c | 533 +++++++++--------- components/dlog/source/log_internal.h | 7 +- components/dlog/source/syslog/syslog.c | 19 +- components/libc/include/armlibc/dirent.h | 1 - components/libc/include/armlibc/fcntl.h | 1 - components/libc/include/armlibc/poll.h | 1 - components/libc/include/armlibc/sys/dirent.h | 49 +- components/libc/include/armlibc/sys/errno.h | 1 - components/libc/include/armlibc/sys/fcntl.h | 47 +- components/libc/include/armlibc/sys/ioctl.h | 391 +++++++------ components/libc/include/armlibc/sys/poll.h | 27 +- components/libc/include/armlibc/sys/select.h | 28 +- components/libc/include/armlibc/sys/stat.h | 93 ++- components/libc/include/armlibc/sys/statfs.h | 9 +- components/libc/include/armlibc/sys/time.h | 13 +- components/libc/include/armlibc/sys/types.h | 23 +- components/libc/include/armlibc/sys/unistd.h | 17 +- components/libc/include/armlibc/sys/vfs.h | 1 - components/libc/include/armlibc/unistd.h | 1 - components/libc/include/extension/errno_ext.h | 175 +++--- components/libc/include/extension/fcntl_ext.h | 15 +- .../libc/include/extension/signal_ext.h | 125 ++-- components/libc/include/extension/stdio_ext.h | 3 +- .../libc/include/extension/string_ext.h | 5 +- components/libc/include/libc_ext.h | 1 - components/libc/include/newlib/poll.h | 1 - components/libc/include/newlib/sys/dirent.h | 51 +- components/libc/include/newlib/sys/ioctl.h | 391 +++++++------ components/libc/include/newlib/sys/poll.h | 27 +- components/libc/include/newlib/sys/statfs.h | 7 +- components/libc/include/newlib/sys/vfs.h | 1 - components/libc/source/armlibc/dirent.c | 65 ++- components/libc/source/armlibc/fcntl.c | 3 +- components/libc/source/armlibc/getcwd.c | 2 +- components/libc/source/armlibc/ioctl.c | 1 - components/libc/source/armlibc/libc.c | 6 +- components/libc/source/armlibc/mem_std.c | 8 +- components/libc/source/armlibc/poll.c | 36 +- components/libc/source/armlibc/select.c | 3 +- components/libc/source/armlibc/stdio.c | 10 +- components/libc/source/armlibc/strdup.c | 7 +- components/libc/source/armlibc/strnlen.c | 1 - components/libc/source/armlibc/stubs.c | 37 +- components/libc/source/armlibc/time.c | 7 +- components/libc/source/common/gmtime_r.c | 33 +- components/libc/source/newlib/dirent.c | 65 ++- components/libc/source/newlib/getcwd.c | 2 +- components/libc/source/newlib/ioctl.c | 1 - components/libc/source/newlib/libc.c | 6 +- components/libc/source/newlib/poll.c | 36 +- components/libc/source/newlib/select.c | 3 +- components/libc/source/newlib/stdio.c | 21 +- components/libc/source/newlib/syscalls.c | 113 ++-- components/libc/source/newlib/time.c | 6 +- components/molink/api/include/mo_api.h | 147 ++--- components/molink/api/include/mo_common.h | 2 +- components/molink/api/include/mo_factory.h | 4 +- components/molink/api/include/mo_general.h | 12 +- components/molink/api/include/mo_mqttc.h | 95 ++-- components/molink/api/include/mo_mqttc_priv.h | 4 +- components/molink/api/include/mo_netconn.h | 87 +-- components/molink/api/include/mo_netserv.h | 102 ++-- components/molink/api/include/mo_onenet_nb.h | 170 +++--- components/molink/api/include/mo_ping.h | 13 +- components/molink/api/include/mo_ppp.h | 2 +- components/molink/api/include/mo_socket.h | 222 ++++---- components/molink/api/include/mo_wifi.h | 80 +-- components/molink/api/source/mo_factory.c | 7 +- components/molink/api/source/mo_general.c | 52 +- components/molink/api/source/mo_ifconfig.c | 2 +- components/molink/api/source/mo_mqttc.c | 109 ++-- components/molink/api/source/mo_netconn.c | 67 ++- components/molink/api/source/mo_netserv.c | 108 ++-- components/molink/api/source/mo_onenet_nb.c | 124 ++-- components/molink/api/source/mo_ping.c | 2 +- components/molink/api/source/mo_ppp.c | 15 +- components/molink/api/source/mo_socket.c | 319 +++++------ components/molink/api/source/mo_wifi.c | 62 +- components/molink/core/include/mo_ipaddr.h | 180 +++--- components/molink/core/include/mo_log.h | 23 +- components/molink/core/include/mo_object.h | 23 +- components/molink/core/source/mo_ipaddr.c | 65 ++- components/molink/core/source/mo_lib.c | 8 +- components/molink/core/source/mo_object.c | 20 +- components/molink/core/source/mo_time.c | 58 +- .../molink/easylog/include/mo_easylog.h | 46 +- components/molink/easylog/source/mo_easylog.c | 31 +- .../molink/module/a7600x/include/a7600x.h | 6 +- .../module/a7600x/include/a7600x_netconn.h | 10 +- .../module/a7600x/include/a7600x_netserv.h | 2 +- .../molink/module/a7600x/source/a7600x.c | 44 +- .../module/a7600x/source/a7600x_ifconfig.c | 16 +- .../module/a7600x/source/a7600x_netconn.c | 135 +++-- .../module/a7600x/source/a7600x_netserv.c | 181 +++--- .../molink/module/a7600x/source/a7600x_ping.c | 52 +- .../molink/module/a7670x/include/a7670x.h | 6 +- .../module/a7670x/include/a7670x_netconn.h | 10 +- .../module/a7670x/include/a7670x_netserv.h | 2 +- .../molink/module/a7670x/source/a7670x.c | 55 +- .../module/a7670x/source/a7670x_ifconfig.c | 16 +- .../module/a7670x/source/a7670x_netconn.c | 126 ++--- .../module/a7670x/source/a7670x_netserv.c | 183 +++--- .../molink/module/a7670x/source/a7670x_ping.c | 52 +- .../molink/module/air720uh/include/air720uh.h | 10 +- .../air720uh/include/air720uh_netconn.h | 10 +- .../module/air720uh/include/air720uh_ping.h | 3 +- .../molink/module/air720uh/source/air720uh.c | 61 +- .../module/air720uh/source/air720uh_general.c | 8 +- .../air720uh/source/air720uh_ifconfig.c | 8 +- .../module/air720uh/source/air720uh_netconn.c | 68 +-- .../module/air720uh/source/air720uh_netserv.c | 2 +- .../module/air720uh/source/air720uh_ping.c | 46 +- .../molink/module/air723ug/include/air723ug.h | 10 +- .../air723ug/include/air723ug_netconn.h | 10 +- .../air723ug/include/air723ug_netserv.h | 2 +- .../module/air723ug/include/air723ug_ping.h | 3 +- .../molink/module/air723ug/source/air723ug.c | 63 ++- .../module/air723ug/source/air723ug_general.c | 8 +- .../air723ug/source/air723ug_ifconfig.c | 8 +- .../module/air723ug/source/air723ug_netconn.c | 64 +-- .../module/air723ug/source/air723ug_netserv.c | 295 +++++----- .../module/air723ug/source/air723ug_ping.c | 46 +- components/molink/module/bc20/include/bc20.h | 18 +- .../molink/module/bc20/include/bc20_netconn.h | 10 +- components/molink/module/bc20/source/bc20.c | 70 ++- .../molink/module/bc20/source/bc20_general.c | 11 +- .../molink/module/bc20/source/bc20_ifconfig.c | 30 +- .../molink/module/bc20/source/bc20_netconn.c | 79 ++- .../molink/module/bc20/source/bc20_netserv.c | 28 +- .../molink/module/bc20/source/bc20_ping.c | 62 +- components/molink/module/bc26/include/bc26.h | 18 +- .../molink/module/bc26/include/bc26_netconn.h | 10 +- components/molink/module/bc26/source/bc26.c | 70 ++- .../molink/module/bc26/source/bc26_general.c | 11 +- .../molink/module/bc26/source/bc26_ifconfig.c | 30 +- .../molink/module/bc26/source/bc26_netconn.c | 79 ++- .../molink/module/bc26/source/bc26_netserv.c | 28 +- .../molink/module/bc26/source/bc26_ping.c | 62 +- components/molink/module/bc28/include/bc28.h | 20 +- .../molink/module/bc28/include/bc28_netconn.h | 10 +- .../module/bc28/include/bc28_onenet_nb.h | 18 +- components/molink/module/bc28/source/bc28.c | 108 ++-- .../molink/module/bc28/source/bc28_general.c | 4 +- .../molink/module/bc28/source/bc28_ifconfig.c | 30 +- .../molink/module/bc28/source/bc28_netconn.c | 195 ++++--- .../molink/module/bc28/source/bc28_netserv.c | 66 ++- .../module/bc28/source/bc28_onenet_nb.c | 389 ++++++------- .../molink/module/bc28/source/bc28_ping.c | 3 +- components/molink/module/bc95/include/bc95.h | 20 +- .../molink/module/bc95/include/bc95_netconn.h | 10 +- .../module/bc95/include/bc95_onenet_nb.h | 18 +- components/molink/module/bc95/source/bc95.c | 108 ++-- .../molink/module/bc95/source/bc95_general.c | 4 +- .../molink/module/bc95/source/bc95_ifconfig.c | 30 +- .../molink/module/bc95/source/bc95_netconn.c | 195 ++++--- .../molink/module/bc95/source/bc95_netserv.c | 70 ++- .../module/bc95/source/bc95_onenet_nb.c | 389 ++++++------- .../molink/module/bc95/source/bc95_ping.c | 3 +- .../module/clm920rv3/include/clm920rv3.h | 8 +- .../clm920rv3/include/clm920rv3_netconn.h | 10 +- .../module/clm920rv3/include/clm920rv3_ping.h | 3 +- .../module/clm920rv3/source/clm920rv3.c | 97 ++-- .../clm920rv3/source/clm920rv3_general.c | 10 +- .../clm920rv3/source/clm920rv3_ifconfig.c | 32 +- .../clm920rv3/source/clm920rv3_netconn.c | 96 ++-- .../clm920rv3/source/clm920rv3_netserv.c | 6 +- .../module/clm920rv3/source/clm920rv3_ping.c | 32 +- .../molink/module/e7025/include/e7025.h | 4 +- .../module/e7025/include/e7025_netconn.h | 10 +- components/molink/module/e7025/source/e7025.c | 39 +- .../module/e7025/source/e7025_ifconfig.c | 14 +- .../module/e7025/source/e7025_netconn.c | 73 ++- .../module/e7025/source/e7025_netserv.c | 2 +- .../molink/module/e7025/source/e7025_ping.c | 27 +- components/molink/module/ec20/include/ec20.h | 6 +- .../molink/module/ec20/include/ec20_netconn.h | 10 +- components/molink/module/ec20/source/ec20.c | 84 ++- .../molink/module/ec20/source/ec20_general.c | 10 +- .../molink/module/ec20/source/ec20_ifconfig.c | 34 +- .../molink/module/ec20/source/ec20_netconn.c | 62 +- .../molink/module/ec20/source/ec20_netserv.c | 10 +- .../molink/module/ec20/source/ec20_ping.c | 44 +- .../molink/module/ec20/source/ec20_ppp.c | 48 +- .../module/ec200x_600s/include/ec200x_600s.h | 4 +- .../ec200x_600s/include/ec200x_600s_netconn.h | 10 +- .../ec200x_600s/include/ec200x_600s_ping.h | 3 +- .../module/ec200x_600s/source/ec200x_600s.c | 48 +- .../ec200x_600s/source/ec200x_600s_general.c | 34 +- .../ec200x_600s/source/ec200x_600s_ifconfig.c | 16 +- .../ec200x_600s/source/ec200x_600s_netconn.c | 69 ++- .../ec200x_600s/source/ec200x_600s_netserv.c | 4 +- .../ec200x_600s/source/ec200x_600s_ping.c | 37 +- .../molink/module/esp32/include/esp32.h | 12 +- .../module/esp32/include/esp32_netconn.h | 10 +- .../molink/module/esp32/include/esp32_wifi.h | 9 +- components/molink/module/esp32/source/esp32.c | 40 +- .../module/esp32/source/esp32_general.c | 4 +- .../module/esp32/source/esp32_ifconfig.c | 18 +- .../module/esp32/source/esp32_netconn.c | 66 +-- .../molink/module/esp32/source/esp32_ping.c | 13 +- .../molink/module/esp32/source/esp32_wifi.c | 30 +- .../molink/module/esp8266/include/esp8266.h | 12 +- .../module/esp8266/include/esp8266_netconn.h | 19 +- .../module/esp8266/include/esp8266_ping.h | 3 +- .../module/esp8266/include/esp8266_wifi.h | 32 +- .../molink/module/esp8266/source/esp8266.c | 77 ++- .../module/esp8266/source/esp8266_general.c | 12 +- .../module/esp8266/source/esp8266_ifconfig.c | 24 +- .../module/esp8266/source/esp8266_netconn.c | 136 ++--- .../module/esp8266/source/esp8266_ping.c | 17 +- .../module/esp8266/source/esp8266_wifi.c | 207 +++---- .../molink/module/gm120/include/gm120.h | 9 +- .../module/gm120/include/gm120_general.h | 18 +- .../module/gm120/include/gm120_ifconfig.h | 2 - .../module/gm120/include/gm120_netconn.h | 11 +- .../module/gm120/include/gm120_netserv.h | 1 - components/molink/module/gm120/source/gm120.c | 113 ++-- .../module/gm120/source/gm120_general.c | 38 +- .../module/gm120/source/gm120_ifconfig.c | 30 +- .../module/gm120/source/gm120_netconn.c | 221 ++++---- .../module/gm120/source/gm120_netserv.c | 4 +- .../molink/module/gm120/source/gm120_ping.c | 70 +-- .../molink/module/gm190/include/gm190.h | 7 +- .../module/gm190/include/gm190_general.h | 18 +- .../module/gm190/include/gm190_ifconfig.h | 1 - .../module/gm190/include/gm190_netconn.h | 9 +- .../module/gm190/include/gm190_netserv.h | 3 +- components/molink/module/gm190/source/gm190.c | 61 +- .../module/gm190/source/gm190_general.c | 38 +- .../module/gm190/source/gm190_ifconfig.c | 15 +- .../module/gm190/source/gm190_netconn.c | 159 +++--- .../module/gm190/source/gm190_netserv.c | 190 +++---- .../molink/module/gm510/include/gm510.h | 9 +- .../module/gm510/include/gm510_general.h | 18 +- .../module/gm510/include/gm510_ifconfig.h | 2 - .../module/gm510/include/gm510_netconn.h | 11 +- .../module/gm510/include/gm510_netserv.h | 1 - components/molink/module/gm510/source/gm510.c | 105 ++-- .../module/gm510/source/gm510_general.c | 38 +- .../module/gm510/source/gm510_ifconfig.c | 18 +- .../module/gm510/source/gm510_netconn.c | 201 +++---- .../module/gm510/source/gm510_netserv.c | 4 +- components/molink/module/l610/include/l610.h | 5 +- .../molink/module/l610/include/l610_netconn.h | 10 +- .../molink/module/l610/include/l610_netserv.h | 2 +- components/molink/module/l610/source/l610.c | 52 +- .../molink/module/l610/source/l610_general.c | 19 +- .../molink/module/l610/source/l610_ifconfig.c | 16 +- .../molink/module/l610/source/l610_netconn.c | 82 ++- .../molink/module/l610/source/l610_netserv.c | 197 ++++--- .../molink/module/l610/source/l610_ping.c | 18 +- .../molink/module/m5310a/include/m5310a.h | 4 +- .../module/m5310a/include/m5310a_netconn.h | 10 +- .../molink/module/m5310a/source/m5310a.c | 70 +-- .../module/m5310a/source/m5310a_general.c | 6 +- .../module/m5310a/source/m5310a_ifconfig.c | 18 +- .../module/m5310a/source/m5310a_netconn.c | 62 +- .../module/m5310a/source/m5310a_netserv.c | 2 +- .../module/m5310a/source/m5310a_onenet_nb.c | 77 +-- .../molink/module/m5310a/source/m5310a_ping.c | 20 +- .../molink/module/m5311/include/m5311.h | 17 +- .../module/m5311/include/m5311_netconn.h | 10 +- components/molink/module/m5311/source/m5311.c | 100 ++-- .../module/m5311/source/m5311_general.c | 36 +- .../module/m5311/source/m5311_ifconfig.c | 20 +- .../module/m5311/source/m5311_netconn.c | 121 ++-- .../module/m5311/source/m5311_netserv.c | 90 +-- .../module/m5311/source/m5311_onenet_nb.c | 116 ++-- .../molink/module/m5311/source/m5311_ping.c | 30 +- components/molink/module/mb26/include/mb26.h | 4 +- .../molink/module/mb26/include/mb26_netconn.h | 10 +- components/molink/module/mb26/source/mb26.c | 52 +- .../molink/module/mb26/source/mb26_general.c | 10 +- .../molink/module/mb26/source/mb26_ifconfig.c | 14 +- .../molink/module/mb26/source/mb26_netconn.c | 75 ++- .../molink/module/mb26/source/mb26_netserv.c | 22 +- .../molink/module/mb26/source/mb26_ping.c | 25 +- .../molink/module/me3616/include/me3616.h | 9 +- .../module/me3616/include/me3616_general.h | 18 +- .../module/me3616/include/me3616_ifconfig.h | 2 - .../module/me3616/include/me3616_netconn.h | 11 +- .../module/me3616/include/me3616_netserv.h | 1 - .../molink/module/me3616/source/me3616.c | 105 ++-- .../module/me3616/source/me3616_general.c | 38 +- .../module/me3616/source/me3616_ifconfig.c | 47 +- .../module/me3616/source/me3616_netconn.c | 198 +++---- .../module/me3616/source/me3616_netserv.c | 6 +- .../molink/module/me3616/source/me3616_ping.c | 66 +-- .../molink/module/me3630_w/include/me3630_w.h | 9 +- .../me3630_w/include/me3630_w_general.h | 18 +- .../me3630_w/include/me3630_w_ifconfig.h | 2 - .../me3630_w/include/me3630_w_netconn.h | 11 +- .../me3630_w/include/me3630_w_netserv.h | 3 +- .../molink/module/me3630_w/source/me3630_w.c | 103 ++-- .../module/me3630_w/source/me3630_w_general.c | 40 +- .../me3630_w/source/me3630_w_ifconfig.c | 22 +- .../module/me3630_w/source/me3630_w_netconn.c | 187 +++--- .../module/me3630_w/source/me3630_w_netserv.c | 196 ++++--- .../molink/module/ml302/include/ml302.h | 11 +- .../module/ml302/include/ml302_general.h | 17 +- .../molink/module/ml302/include/ml302_mqttc.h | 12 +- .../module/ml302/include/ml302_netconn.h | 10 +- .../module/ml302/include/ml302_netserv.h | 4 +- components/molink/module/ml302/source/ml302.c | 76 ++- .../module/ml302/source/ml302_general.c | 31 +- .../module/ml302/source/ml302_ifconfig.c | 10 +- .../molink/module/ml302/source/ml302_mqttc.c | 70 +-- .../module/ml302/source/ml302_netconn.c | 127 ++--- .../module/ml302/source/ml302_netserv.c | 296 +++++----- .../molink/module/ml302/source/ml302_ping.c | 39 +- components/molink/module/n21/include/n21.h | 9 +- .../molink/module/n21/include/n21_netconn.h | 10 +- components/molink/module/n21/source/n21.c | 59 +- .../molink/module/n21/source/n21_general.c | 34 +- .../molink/module/n21/source/n21_ifconfig.c | 11 +- .../molink/module/n21/source/n21_netconn.c | 99 ++-- .../molink/module/n21/source/n21_netserv.c | 26 +- .../molink/module/n21/source/n21_ping.c | 32 +- components/molink/module/n58/include/n58.h | 9 +- .../molink/module/n58/include/n58_netconn.h | 8 +- .../molink/module/n58/include/n58_netserv.h | 2 +- components/molink/module/n58/source/n58.c | 48 +- .../molink/module/n58/source/n58_general.c | 3 +- .../molink/module/n58/source/n58_ifconfig.c | 10 +- .../molink/module/n58/source/n58_netconn.c | 90 +-- .../molink/module/n58/source/n58_netserv.c | 184 +++--- .../molink/module/n58/source/n58_ping.c | 26 +- .../molink/module/sim7020/include/sim7020.h | 4 +- .../module/sim7020/include/sim7020_netconn.h | 10 +- .../module/sim7020/include/sim7020_ping.h | 3 +- .../molink/module/sim7020/source/sim7020.c | 38 +- .../module/sim7020/source/sim7020_ifconfig.c | 18 +- .../module/sim7020/source/sim7020_netconn.c | 54 +- .../module/sim7020/source/sim7020_netserv.c | 2 +- .../module/sim7020/source/sim7020_ping.c | 35 +- .../molink/module/sim7070x/include/sim7070x.h | 8 +- .../sim7070x/include/sim7070x_netconn.h | 10 +- .../module/sim7070x/include/sim7070x_ping.h | 3 +- .../molink/module/sim7070x/source/sim7070x.c | 56 +- .../module/sim7070x/source/sim7070x_general.c | 8 +- .../sim7070x/source/sim7070x_ifconfig.c | 16 +- .../module/sim7070x/source/sim7070x_netconn.c | 116 ++-- .../module/sim7070x/source/sim7070x_netserv.c | 7 +- .../module/sim7070x/source/sim7070x_ping.c | 33 +- .../module/sim7600ce/include/sim7600ce.h | 6 +- .../sim7600ce/include/sim7600ce_netconn.h | 10 +- .../module/sim7600ce/include/sim7600ce_ping.h | 3 +- .../module/sim7600ce/source/sim7600ce.c | 38 +- .../sim7600ce/source/sim7600ce_general.c | 1 - .../sim7600ce/source/sim7600ce_ifconfig.c | 16 +- .../sim7600ce/source/sim7600ce_netconn.c | 127 ++--- .../sim7600ce/source/sim7600ce_netserv.c | 2 +- .../module/sim7600ce/source/sim7600ce_ping.c | 31 +- components/molink/parser/include/at_parser.h | 28 +- components/molink/parser/include/at_resp.h | 20 +- components/molink/parser/source/at_parser.c | 74 ++- components/molink/parser/source/at_resp.c | 6 +- components/ota/cmiot/inc/cmiot_client.h | 24 +- components/ota/cmiot/inc/cmiot_coap.h | 233 ++++---- components/ota/cmiot/inc/cmiot_config.h | 2 +- components/ota/cmiot/inc/cmiot_hal.h | 68 +-- components/ota/cmiot/inc/cmiot_hmd5.h | 12 +- components/ota/cmiot/inc/cmiot_http.h | 12 +- components/ota/cmiot/inc/cmiot_md5.h | 6 +- components/ota/cmiot/inc/cmiot_type.h | 20 +- components/ota/cmiot/inc/cmiot_user.h | 12 +- components/ota/cmiot/inc/cmiot_utils.h | 6 +- components/ringbuf/include/option_parse.h | 26 +- components/ringbuf/include/ring_blk_buff.h | 64 +-- components/ringbuf/include/ring_buff.h | 46 +- components/ringbuf/source/option_parse.c | 35 +- components/ringbuf/source/ring_blk_buff.c | 66 +-- components/ringbuf/source/ring_buff.c | 105 ++-- components/shell/include/shell.h | 49 +- components/shell/source/shell_buildin_cmd.c | 9 +- components/shell/source/shell_internal.h | 51 +- components/shell/source/shell_main.c | 173 +++--- components/shell/source/shell_process.c | 153 +++-- components/shell/source/shell_symbol.c | 19 +- components/socket/include/sys_socket/netdb.h | 6 +- .../socket/include/sys_socket/sys/socket.h | 8 +- components/socket/source/socket.c | 18 +- 392 files changed, 8997 insertions(+), 9462 deletions(-) diff --git a/components/atest/include/atest.h b/components/atest/include/atest.h index a4e60013..91320914 100644 --- a/components/atest/include/atest.h +++ b/components/atest/include/atest.h @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file atest.h @@ -41,9 +41,9 @@ extern "C" { */ enum atest_tc_priority { - TC_PRIORITY_HIGH = 0, /* High priority testcase. */ - TC_PRIORITY_MIDDLE, /* Middle priority testcase. */ - TC_PRIORITY_LOW, /* Low priority testcase. */ + TC_PRIORITY_HIGH = 0, /* High priority testcase. */ + TC_PRIORITY_MIDDLE, /* Middle priority testcase. */ + TC_PRIORITY_LOW, /* Low priority testcase. */ TC_PRIORITY_CNT_MAX }; @@ -56,12 +56,12 @@ enum atest_tc_priority */ struct atest_stats { - os_uint16_t tc_passed_num; /* Total number of testcases passed. */ - os_uint16_t tc_failed_num; /* Total number of testcases failed. */ - os_uint16_t tu_passed_num; /* Total number of test units passed. */ - os_uint16_t tu_failed_num; /* Total number of test units failed. */ - os_uint16_t tp_passed_num; /* Total number of test points passed. */ - os_uint16_t tp_failed_num; /* Total number of test points failed. */ + os_uint16_t tc_passed_num; /* Total number of testcases passed. */ + os_uint16_t tc_failed_num; /* Total number of testcases failed. */ + os_uint16_t tu_passed_num; /* Total number of test units passed. */ + os_uint16_t tu_failed_num; /* Total number of test units failed. */ + os_uint16_t tp_passed_num; /* Total number of test points passed. */ + os_uint16_t tp_failed_num; /* Total number of test points failed. */ }; typedef struct atest_stats atest_stats_t; @@ -74,12 +74,11 @@ typedef struct atest_stats atest_stats_t; */ struct atest_tp_stats { - os_uint16_t tp_passed_num; /* Total number of test points passed in a single testcase. */ - os_uint16_t tp_failed_num; /* Total number of test points failed in a single testcase. */ + os_uint16_t tp_passed_num; /* Total number of test points passed in a single testcase. */ + os_uint16_t tp_failed_num; /* Total number of test points failed in a single testcase. */ }; typedef struct atest_tp_stats atest_tp_stats_t; - /** *********************************************************************************************************************** * @struct atest_tc_entry @@ -89,11 +88,11 @@ typedef struct atest_tp_stats atest_tp_stats_t; */ struct atest_tc_entry { - const char *name; /* Testcase name. */ - os_err_t (*init)(void); /* Initialization before executing the testcase function. */ - void (*tc)(void); /* Execute the testcase function. */ - os_err_t (*cleanup)(void); /* Cleanup after executing the testcase function. */ - enum atest_tc_priority priority; /* The priority of testcase */ + const char *name; /* Testcase name. */ + os_err_t (*init)(void); /* Initialization before executing the testcase function. */ + void (*tc)(void); /* Execute the testcase function. */ + os_err_t (*cleanup)(void); /* Cleanup after executing the testcase function. */ + enum atest_tc_priority priority; /* The priority of testcase */ }; typedef struct atest_tc_entry atest_tc_entry_t; @@ -113,15 +112,9 @@ typedef void (*atest_unit_func_t)(void); * @param priority The testcase priority. *********************************************************************************************************************** */ -#define ATEST_TC_EXPORT(name, testcase, init, cleanup, priority) \ - OS_USED static const atest_tc_entry_t gs_atest##testcase OS_SECTION("AtestTcTab") = \ - { \ - #name, \ - init, \ - testcase, \ - cleanup, \ - priority \ - }; +#define ATEST_TC_EXPORT(name, testcase, init, cleanup, priority) \ + OS_USED static const atest_tc_entry_t gs_atest##testcase OS_SECTION( \ + "AtestTcTab") = {#name, init, testcase, cleanup, priority}; /** *********************************************************************************************************************** @@ -132,111 +125,97 @@ typedef void (*atest_unit_func_t)(void); * @param test_unit_func Unit test function. *********************************************************************************************************************** */ -#define ATEST_UNIT_RUN(test_unit_func) \ - do \ - { \ - atest_unit_run(test_unit_func, #test_unit_func); \ - if (atest_tp_stats_get()->tp_failed_num != 0) \ - { \ - return; \ - } \ +#define ATEST_UNIT_RUN(test_unit_func) \ + do \ + { \ + atest_unit_run(test_unit_func, #test_unit_func); \ + if (atest_tp_stats_get()->tp_failed_num != 0) \ + { \ + return; \ + } \ } while (0) -#define __atest_assert(value, msg) atest_assert(value, __FILE__, __LINE__, __func__, msg) +#define __atest_assert(value, msg) atest_assert(value, __FILE__, __LINE__, __func__, msg) -/* If @value is true, not assert, means passing. */ -#define tp_assert_true(value) __atest_assert(value, "(" #value ") is false") +/* If @value is true, not assert, means passing. */ +#define tp_assert_true(value) __atest_assert(value, "(" #value ") is false") /* If @value is false, not assert, means passing. */ -#define tp_assert_false(value) __atest_assert(!(value), "(" #value ") is true") +#define tp_assert_false(value) __atest_assert(!(value), "(" #value ") is true") /* If @value is null, not assert, means passing. */ -#define tp_assert_null(value) __atest_assert(OS_NULL == (const char *)(value), "(" #value ") is not null") +#define tp_assert_null(value) __atest_assert(OS_NULL == (const char *)(value), "(" #value ") is not null") /* If @value is not null, not assert, means passing. */ -#define tp_assert_not_null(value) __atest_assert(OS_NULL != (const char *)(value), "(" #value ") is null") +#define tp_assert_not_null(value) __atest_assert(OS_NULL != (const char *)(value), "(" #value ") is null") /* If @a equal to @b, not assert, means passing. Integer type test. */ -#define tp_assert_integer_equal(a, b) __atest_assert((a) == (b), "(" #a ") not equal to (" #b ")") +#define tp_assert_integer_equal(a, b) __atest_assert((a) == (b), "(" #a ") not equal to (" #b ")") /* If @a not equal to @b, not assert, means passing. Integer type test. */ -#define tp_assert_integer_not_equal(a, b) __atest_assert((a) != (b), "(" #a ") equal to (" #b ")") +#define tp_assert_integer_not_equal(a, b) __atest_assert((a) != (b), "(" #a ") equal to (" #b ")") /* if @a equal to @b, not assert, means passing. String type test. */ -#define tp_assert_str_equal(a, b) atest_assert_string((const char*)(a), \ - (const char*)(b), \ - OS_TRUE, \ - __FILE__, \ - __LINE__, \ - __func__, \ - "string not equal") +#define tp_assert_str_equal(a, b) \ + atest_assert_string((const char *)(a), (const char *)(b), OS_TRUE, __FILE__, __LINE__, __func__, "string not equal") /* If @a not equal to @b, not assert, means passing. String type test. */ -#define tp_assert_str_not_equal(a, b) atest_assert_string((const char*)(a), \ - (const char*)(b), \ - OS_FALSE, \ - __FILE__, \ - __LINE__, \ - __func__, \ - "string equal") +#define tp_assert_str_not_equal(a, b) \ + atest_assert_string((const char *)(a), (const char *)(b), OS_FALSE, __FILE__, __LINE__, __func__, "string equal") /* If @a equal to @b, not assert, means passing. Buffer type test. */ -#define tp_assert_buf_equal(a, b, size) atest_assert_buf((const os_uint8_t *)(a), \ - (const os_uint8_t *)(b), \ - (size), \ - OS_TRUE, \ - __FILE__, \ - __LINE__, \ - __func__, \ - "buf not equal") +#define tp_assert_buf_equal(a, b, size) \ + atest_assert_buf((const os_uint8_t *)(a), \ + (const os_uint8_t *)(b), \ + (size), \ + OS_TRUE, \ + __FILE__, \ + __LINE__, \ + __func__, \ + "buf not equal") /* If @a not equal to @b, not assert, means passing. Buffer type test. */ -#define tp_assert_buf_not_equal(a, b, size) atest_assert_buf((const os_uint8_t *)(a), \ - (const os_uint8_t *)(b), \ - (size), \ - OS_FALSE, \ - __FILE__, \ - __LINE__, \ - __func__, \ - "buf equal") +#define tp_assert_buf_not_equal(a, b, size) \ + atest_assert_buf((const os_uint8_t *)(a), \ + (const os_uint8_t *)(b), \ + (size), \ + OS_FALSE, \ + __FILE__, \ + __LINE__, \ + __func__, \ + "buf equal") /* If @value is in range of @min and @max, not assert, means passing. */ -#define tp_assert_in_range(value, min, max) __atest_assert(((value >= min) && (value <= max)), \ - "(" #value ") not in range("#min","#max")") +#define tp_assert_in_range(value, min, max) \ + __atest_assert(((value >= min) && (value <= max)), "(" #value ") not in range(" #min "," #max ")") /* If @value is not in range of @min and @max, not assert, means passing. */ -#define tp_assert_not_in_range(value, min, max) __atest_assert(!((value >= min) && (value <= max)), \ - "(" #value ") in range("#min","#max")") - - -extern atest_tp_stats_t *atest_tp_stats_get(void); -extern void atest_unit_run(atest_unit_func_t func, const char *unit_func_name); - -extern void atest_assert(os_bool_t condition, - const char *file, - os_int32_t line, - const char *func, - const char *msg); - -extern void atest_assert_string(const char *str_a, - const char *str_b, - os_bool_t equal, - const char *file, - os_int32_t line, - const char *func, - const char *msg); - -extern void atest_assert_buf(const os_uint8_t *buff_a, - const os_uint8_t *buff_b, - os_size_t size, - os_bool_t equal, - const char *file, - os_int32_t line, - const char *func, - const char *msg); +#define tp_assert_not_in_range(value, min, max) \ + __atest_assert(!((value >= min) && (value <= max)), "(" #value ") in range(" #min "," #max ")") + +extern atest_tp_stats_t *atest_tp_stats_get(void); +extern void atest_unit_run(atest_unit_func_t func, const char *unit_func_name); + +extern void atest_assert(os_bool_t condition, const char *file, os_int32_t line, const char *func, const char *msg); + +extern void atest_assert_string(const char *str_a, + const char *str_b, + os_bool_t equal, + const char *file, + os_int32_t line, + const char *func, + const char *msg); + +extern void atest_assert_buf(const os_uint8_t *buff_a, + const os_uint8_t *buff_b, + os_size_t size, + os_bool_t equal, + const char *file, + os_int32_t line, + const char *func, + const char *msg); #ifdef __cplusplus } #endif #endif /* __ATEST_H__ */ - diff --git a/components/atest/source/atest.c b/components/atest/source/atest.c index 9264aa8d..03e843ce 100644 --- a/components/atest/source/atest.c +++ b/components/atest/source/atest.c @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file atest.c @@ -44,64 +44,65 @@ #error "Atest task priority is greater than or equal to OS_TASK_PRIORITY_MAX" #endif -#define ATEST_NAME_MAX_LEN 128 -#define ATEST_TAG "ATEST" +#define ATEST_NAME_MAX_LEN 128 +#define ATEST_TAG "ATEST" struct atest_tc_table_info { - atest_tc_entry_t *tc_table; - os_uint32_t tc_num; + atest_tc_entry_t *tc_table; + os_uint32_t tc_num; }; typedef struct atest_tc_table_info atest_tc_table_info_t; struct atest_ctrl_info { - char tc_name[ATEST_NAME_MAX_LEN]; - os_int32_t loop_cnt; - os_bool_t use_task; - os_bool_t fail_stop; - os_bool_t print_help; - enum atest_tc_priority run_priority; - atest_stats_t test_stats; - atest_tp_stats_t tp_stats; + char tc_name[ATEST_NAME_MAX_LEN]; + os_int32_t loop_cnt; + os_bool_t use_task; + os_bool_t fail_stop; + os_bool_t print_help; + enum atest_tc_priority run_priority; + atest_stats_t test_stats; + atest_tp_stats_t tp_stats; }; typedef struct atest_ctrl_info atest_ctrl_info_t; -static atest_tc_table_info_t gs_tc_table_info; -static atest_ctrl_info_t gs_ctrl_info; +static atest_tc_table_info_t gs_tc_table_info; +static atest_ctrl_info_t gs_ctrl_info; -static os_bool_t gs_is_busy = OS_FALSE; +static os_bool_t gs_is_busy = OS_FALSE; -#if defined(__ICCARM__) || defined(__ICCRX__) /* For IAR compiler */ -#pragma section="AtestTcTab" +#if defined(__ICCARM__) || defined(__ICCRX__) /* For IAR compiler */ +#pragma section = "AtestTcTab" #endif static os_err_t atest_init(void) { /* Initialize the atest commands table.*/ -#if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM C Compiler */ +#if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM C Compiler */ extern const int AtestTcTab$$Base; extern const int AtestTcTab$$Limit; - + gs_tc_table_info.tc_table = (atest_tc_entry_t *)&AtestTcTab$$Base; - gs_tc_table_info.tc_num = (atest_tc_entry_t *)&AtestTcTab$$Limit - gs_tc_table_info.tc_table; - -#elif defined(__ICCARM__) || defined(__ICCRX__) /* For IAR Compiler */ + gs_tc_table_info.tc_num = (atest_tc_entry_t *)&AtestTcTab$$Limit - gs_tc_table_info.tc_table; + +#elif defined(__ICCARM__) || defined(__ICCRX__) /* For IAR Compiler */ gs_tc_table_info.tc_table = (atest_tc_entry_t *)__section_begin("AtestTcTab"); - gs_tc_table_info.tc_num = (atest_tc_entry_t *)__section_end("AtestTcTab") - gs_tc_table_info.tc_table; - -#elif defined(__GNUC__) /* For GCC Compiler */ + gs_tc_table_info.tc_num = (atest_tc_entry_t *)__section_end("AtestTcTab") - gs_tc_table_info.tc_table; + +#elif defined(__GNUC__) /* For GCC Compiler */ extern const int __atest_tc_table_start; extern const int __atest_tc_table_end; - + gs_tc_table_info.tc_table = (atest_tc_entry_t *)&__atest_tc_table_start; - gs_tc_table_info.tc_num = (atest_tc_entry_t *)&__atest_tc_table_end - gs_tc_table_info.tc_table;; + gs_tc_table_info.tc_num = (atest_tc_entry_t *)&__atest_tc_table_end - gs_tc_table_info.tc_table; + ; #else #error "Use the compilier that is not supported!!!" #endif os_kprintf("Atest is initialized success!\r\n"); - + return OS_EOK; } OS_PREV_INIT(atest_init, OS_INIT_SUBLEVEL_LOW); @@ -134,24 +135,24 @@ void atest_unit_run(atest_unit_func_t func, const char *unit_func_name) if (gs_ctrl_info.tp_stats.tp_failed_num == old_tp_failed_num) { gs_ctrl_info.test_stats.tu_passed_num++; - + os_kprintf("[ TU ] [ PASSED ] Unit name (%s), tp passed (%u), tp failed (%u).\r\n", - unit_func_name, - gs_ctrl_info.tp_stats.tp_passed_num - old_tp_passed_num, - gs_ctrl_info.tp_stats.tp_failed_num - old_tp_failed_num); + unit_func_name, + gs_ctrl_info.tp_stats.tp_passed_num - old_tp_passed_num, + gs_ctrl_info.tp_stats.tp_failed_num - old_tp_failed_num); } else { gs_ctrl_info.test_stats.tu_failed_num++; - + os_kprintf("[ TU ] [ FAILED ] Unit name (%s), tp passed (%u), tp failed (%u).\r\n", - unit_func_name, - gs_ctrl_info.tp_stats.tp_passed_num - old_tp_passed_num, - gs_ctrl_info.tp_stats.tp_failed_num - old_tp_failed_num); + unit_func_name, + gs_ctrl_info.tp_stats.tp_passed_num - old_tp_passed_num, + gs_ctrl_info.tp_stats.tp_failed_num - old_tp_failed_num); } os_kprintf("\r\n"); - + return; } @@ -191,7 +192,7 @@ static const char *atest_file_basename(const char *file) { rst = (char *)(slash_pos + 1); } - + return (const char *)rst; } @@ -216,22 +217,19 @@ void atest_assert(os_bool_t condition, const char *file, os_int32_t line, const { gs_ctrl_info.tp_stats.tp_failed_num++; gs_ctrl_info.test_stats.tp_failed_num++; - + os_kprintf("[ TP ] [ ASSERT ] File: (%s); func: (%s:%d); msg: (%s)\r\n", - atest_file_basename(file), - func, - line, - msg); + atest_file_basename(file), + func, + line, + msg); } else { gs_ctrl_info.tp_stats.tp_passed_num++; gs_ctrl_info.test_stats.tp_passed_num++; - - os_kprintf("[ TP ] [ PASSED ] File: (%s); func: (%s:%d).\r\n", - atest_file_basename(file), - func, - line); + + os_kprintf("[ TP ] [ PASSED ] File: (%s); func: (%s:%d).\r\n", atest_file_basename(file), func, line); } return; @@ -239,7 +237,7 @@ void atest_assert(os_bool_t condition, const char *file, os_int32_t line, const /** *********************************************************************************************************************** - * @brief Judge whether to assert according to the string comparison result and the desired comparison + * @brief Judge whether to assert according to the string comparison result and the desired comparison * condition. * * @param[in] str_a String a. @@ -255,13 +253,13 @@ void atest_assert(os_bool_t condition, const char *file, os_int32_t line, const * @return None. *********************************************************************************************************************** */ -void atest_assert_string(const char *str_a, - const char *str_b, - os_bool_t equal, - const char *file, - os_int32_t line, - const char *func, - const char *msg) +void atest_assert_string(const char *str_a, + const char *str_b, + os_bool_t equal, + const char *file, + os_int32_t line, + const char *func, + const char *msg) { if ((OS_NULL == str_a) || (OS_NULL == str_b)) { @@ -297,7 +295,7 @@ void atest_assert_string(const char *str_a, /** *********************************************************************************************************************** - * @brief Judge whether to assert according to the buffer comparison result and the desired comparison + * @brief Judge whether to assert according to the buffer comparison result and the desired comparison * condition. * * @param[in] buff_a Buffer a. @@ -316,12 +314,12 @@ void atest_assert_string(const char *str_a, */ void atest_assert_buf(const os_uint8_t *buff_a, const os_uint8_t *buff_b, - os_size_t size, - os_bool_t equal, - const char *file, - os_int32_t line, - const char *func, - const char *msg) + os_size_t size, + os_bool_t equal, + const char *file, + os_int32_t line, + const char *func, + const char *msg) { if ((OS_NULL == buff_a) || (OS_NULL == buff_b)) { @@ -342,7 +340,7 @@ void atest_assert_buf(const os_uint8_t *buff_a, } else { - if (!memcmp(buff_a , buff_b, size)) + if (!memcmp(buff_a, buff_b, size)) { atest_assert(OS_FALSE, file, line, func, msg); } @@ -358,57 +356,60 @@ void atest_assert_buf(const os_uint8_t *buff_a, static void atest_help(void) { os_kprintf("\r\n"); - + os_kprintf("Command: atest_run\r\n"); os_kprintf(" Info: Execute testcases.\r\n"); os_kprintf(" Format: atest_run [-n testacse name] [-l loop count] [-p priority level] [-t] [-s] [-h]\r\n"); os_kprintf("\r\n"); - + os_kprintf(" Usage:\r\n"); - + os_kprintf(" -n Specify a testcase name.\r\n"); os_kprintf(" If don't specify this option, run all testcases.\r\n"); os_kprintf("\r\n"); - + os_kprintf(" -l Specify a loop count that the testcase runs.\r\n"); os_kprintf(" If don't specify this option, the testcase only run one times.\r\n"); os_kprintf("\r\n"); - - os_kprintf(" -p Specify a priority level. Only testcases greater or equal than this level can be run.\r\n"); + + os_kprintf( + " -p Specify a priority level. Only testcases greater or equal than this level can be run.\r\n"); os_kprintf(" H -- High priority level.\r\n"); os_kprintf(" M -- Middle priority level.\r\n"); os_kprintf(" L -- Low priority level.\r\n"); os_kprintf(" If don't specify this option, low priority level is be used by default.\r\n"); os_kprintf("\r\n"); - + os_kprintf(" -t Create a new task to execute the testcase(s).\r\n"); os_kprintf(" If don't specify this option, execute the testcase(s) in shell task.\r\n"); os_kprintf("\r\n"); - - os_kprintf(" -s If specify this option, as long as a testcase fails, the subsequent testcases are no\r\n" - " longer running.\r\n"); - os_kprintf(" If don't specify this option, when a testcase fails, the subsequent testcases still run.\r\n"); + + os_kprintf( + " -s If specify this option, as long as a testcase fails, the subsequent testcases are no\r\n" + " longer running.\r\n"); + os_kprintf( + " If don't specify this option, when a testcase fails, the subsequent testcases still run.\r\n"); os_kprintf("\r\n"); - + os_kprintf(" -h Print help information of atest_run command.\r\n"); os_kprintf(" If specify this option, other options are ignored.\r\n"); os_kprintf("\r\n"); - + return; } -static os_err_t atest_ctrl_info_get(os_int32_t argc, char * const *argv, atest_ctrl_info_t *ctrl_info) +static os_err_t atest_ctrl_info_get(os_int32_t argc, char *const *argv, atest_ctrl_info_t *ctrl_info) { opt_state_t state; - os_int32_t opt_ret; - os_int32_t ret; + os_int32_t opt_ret; + os_int32_t ret; memset(ctrl_info, 0, sizeof(atest_ctrl_info_t)); - ctrl_info->loop_cnt = 1; - ctrl_info->use_task = OS_FALSE; - ctrl_info->fail_stop = OS_FALSE; - ctrl_info->print_help = OS_FALSE; - ctrl_info->run_priority = TC_PRIORITY_LOW; + ctrl_info->loop_cnt = 1; + ctrl_info->use_task = OS_FALSE; + ctrl_info->fail_stop = OS_FALSE; + ctrl_info->print_help = OS_FALSE; + ctrl_info->run_priority = TC_PRIORITY_LOW; memset(&state, 0, sizeof(state)); opt_init(&state, 1); @@ -427,14 +428,14 @@ static os_err_t atest_ctrl_info_get(os_int32_t argc, char * const *argv, atest_c ret = OS_ERROR; break; } - + switch (opt_ret) { case 'n': memset(ctrl_info->tc_name, 0, ATEST_NAME_MAX_LEN); strncpy(ctrl_info->tc_name, state.opt_arg, ATEST_NAME_MAX_LEN); break; - + case 'l': ctrl_info->loop_cnt = atoi(state.opt_arg); if (ctrl_info->loop_cnt <= 0) @@ -444,9 +445,9 @@ static os_err_t atest_ctrl_info_get(os_int32_t argc, char * const *argv, atest_c ret = OS_EINVAL; break; } - + break; - + case 'p': if (!strcmp(state.opt_arg, "H")) { @@ -467,20 +468,20 @@ static os_err_t atest_ctrl_info_get(os_int32_t argc, char * const *argv, atest_c ret = OS_EINVAL; break; } - + break; - + case 't': ctrl_info->use_task = OS_TRUE; break; - + case 's': ctrl_info->fail_stop = OS_TRUE; break; case 'h': ctrl_info->print_help = OS_TRUE; break; - + default: os_kprintf("Invalid option: %c\r\n", (char)opt_ret); @@ -511,7 +512,7 @@ static os_err_t atest_run_a_testcase(atest_tc_entry_t *tc_entry, atest_ctrl_info { os_kprintf("[ TC ] [ ====== ] Testcase (%s) begin to run.\r\n", tc_entry->name); os_kprintf("\r\n"); - + if (OS_NULL != tc_entry->init) { init_ret = tc_entry->init(); @@ -527,20 +528,20 @@ static os_err_t atest_run_a_testcase(atest_tc_entry_t *tc_entry, atest_ctrl_info if (OS_NULL != tc_entry->tc) { tc_entry->tc(); - + if (0 == ctrl_info->tp_stats.tp_failed_num) { os_kprintf("[ TC ] [ PASSED ] Testcase (%s), tp passed (%u), tp failed (%u)\r\n", - tc_entry->name, - ctrl_info->tp_stats.tp_passed_num, - ctrl_info->tp_stats.tp_failed_num); + tc_entry->name, + ctrl_info->tp_stats.tp_passed_num, + ctrl_info->tp_stats.tp_failed_num); } else { os_kprintf("[ TC ] [ FAILED ] Testcase (%s), tp passed (%u), tp failed (%u)\r\n", - tc_entry->name, - ctrl_info->tp_stats.tp_passed_num, - ctrl_info->tp_stats.tp_failed_num); + tc_entry->name, + ctrl_info->tp_stats.tp_passed_num, + ctrl_info->tp_stats.tp_failed_num); ret = OS_ERROR; } } @@ -560,19 +561,19 @@ static os_err_t atest_run_a_testcase(atest_tc_entry_t *tc_entry, atest_ctrl_info ret = OS_ERROR; break; } - } + } } while (0); return ret; } -static atest_tc_entry_t *atest_get_next_tc_entry(const atest_ctrl_info_t *ctrl_info, +static atest_tc_entry_t *atest_get_next_tc_entry(const atest_ctrl_info_t *ctrl_info, const atest_tc_table_info_t *tc_table_info, - os_uint16_t *next_query_index) + os_uint16_t *next_query_index) { atest_tc_entry_t *tc_entry; - os_size_t cmp_len; - os_uint16_t index; + os_size_t cmp_len; + os_uint16_t index; if (*next_query_index >= tc_table_info->tc_num) { @@ -617,13 +618,13 @@ static atest_tc_entry_t *atest_get_next_tc_entry(const atest_ctrl_info_t *ct static void atest_tc_do_run(void *arg) { atest_ctrl_info_t *ctrl_info; - atest_tc_entry_t *tc_entry; - os_bool_t found_entry; - os_bool_t abort; - os_uint16_t loop_index; - os_uint16_t next_query_index; - os_uint16_t total; - os_err_t ret; + atest_tc_entry_t *tc_entry; + os_bool_t found_entry; + os_bool_t abort; + os_uint16_t loop_index; + os_uint16_t next_query_index; + os_uint16_t total; + os_err_t ret; ctrl_info = (atest_ctrl_info_t *)arg; ctrl_info->test_stats.tc_passed_num = 0; @@ -634,16 +635,16 @@ static void atest_tc_do_run(void *arg) ctrl_info->test_stats.tp_failed_num = 0; os_kprintf("\r\n"); - + abort = OS_FALSE; for (loop_index = 0; loop_index < ctrl_info->loop_cnt; loop_index++) - { + { os_kprintf("-----------------------------------Loop: %u-------------------------------------\r\n", loop_index + 1); os_kprintf("\r\n"); - - found_entry = OS_FALSE; + + found_entry = OS_FALSE; next_query_index = 0; while (1) @@ -658,21 +659,21 @@ static void atest_tc_do_run(void *arg) { found_entry = OS_TRUE; } - + ret = atest_run_a_testcase(tc_entry, ctrl_info); if (OS_EOK == ret) { - ctrl_info->test_stats.tc_passed_num++; + ctrl_info->test_stats.tc_passed_num++; } else { ctrl_info->test_stats.tc_failed_num++; - + if (ctrl_info->fail_stop) { abort = OS_TRUE; break; - } + } } os_kprintf("\r\n"); @@ -743,7 +744,7 @@ static void atest_tc_do_run(void *arg) static os_err_t atest_tc_run(os_int32_t argc, char **argv) { os_task_t *task; - os_err_t ret; + os_err_t ret; ret = OS_EOK; @@ -752,7 +753,7 @@ static os_err_t atest_tc_run(os_int32_t argc, char **argv) if (OS_TRUE == gs_is_busy) { os_kprintf("Testcases are running, please try again later.\r\n"); - + ret = OS_EBUSY; break; } @@ -764,14 +765,14 @@ static os_err_t atest_tc_run(os_int32_t argc, char **argv) { atest_help(); gs_is_busy = OS_FALSE; - + break; } if (OS_TRUE == gs_ctrl_info.print_help) { atest_help(); - + gs_is_busy = OS_FALSE; break; } @@ -800,15 +801,17 @@ static os_err_t atest_tc_run(os_int32_t argc, char **argv) os_kprintf("Create atest task failed, execute testcase(s) failed.\r\n"); gs_is_busy = OS_FALSE; - + ret = OS_ERROR; } } } while (0); - + return ret; } -SH_CMD_EXPORT(atest_run, atest_tc_run, "atest_run [-n testacse name] [-l loop count] [-p priority level] [-t] [-s] [-h]"); +SH_CMD_EXPORT(atest_run, + atest_tc_run, + "atest_run [-n testacse name] [-l loop count] [-p priority level] [-t] [-s] [-h]"); /** *********************************************************************************************************************** @@ -824,14 +827,14 @@ SH_CMD_EXPORT(atest_run, atest_tc_run, "atest_run [-n testacse name] [-l loop co */ OS_UNUSED static os_err_t atest_tc_list(os_int32_t argc, char **argv) { - os_size_t index; + os_size_t index; os_int32_t priority; - char *prior_str[TC_PRIORITY_CNT_MAX]; + char *prior_str[TC_PRIORITY_CNT_MAX]; + + prior_str[TC_PRIORITY_HIGH] = "High"; + prior_str[TC_PRIORITY_MIDDLE] = "Middle"; + prior_str[TC_PRIORITY_LOW] = "Low"; - prior_str[TC_PRIORITY_HIGH] = "High"; - prior_str[TC_PRIORITY_MIDDLE] = "Middle"; - prior_str[TC_PRIORITY_LOW] = "Low"; - os_kprintf("\r\n"); os_kprintf("%-61.s %-10.s\r\n", "Testcase name", "Priority"); os_kprintf("--------------------------------- --------\r\n"); @@ -844,12 +847,12 @@ OS_UNUSED static os_err_t atest_tc_list(os_int32_t argc, char **argv) } priority = (os_int32_t)gs_tc_table_info.tc_table[index].priority; - + if ((priority < TC_PRIORITY_HIGH) || (priority > TC_PRIORITY_LOW)) { - priority = TC_PRIORITY_CNT_MAX; + priority = TC_PRIORITY_CNT_MAX; } - + os_kprintf("%-62s %s\r\n", gs_tc_table_info.tc_table[index].name, priority != TC_PRIORITY_CNT_MAX ? prior_str[priority] : "Invalid"); @@ -876,10 +879,9 @@ SH_CMD_EXPORT(atest_list, atest_tc_list, "Display all atest testcases"); static void atest_tc_occupancy(void) { /* Do nothing */ - + return; } ATEST_TC_EXPORT(atest_occupancy, atest_tc_occupancy, OS_NULL, OS_NULL, TC_PRIORITY_CNT_MAX); #endif /* OS_USING_ATEST */ - diff --git a/components/cplusplus/demo/test.cpp b/components/cplusplus/demo/test.cpp index ca486330..25bbe043 100644 --- a/components/cplusplus/demo/test.cpp +++ b/components/cplusplus/demo/test.cpp @@ -1,17 +1,16 @@ #include -#include //包含头文件iostream -using namespace std; //使用命名空间std +#include //包含头文件iostream +using namespace std; //使用命名空间std -extern "C" -{ +extern "C" { int test(void); void test_task(void *parameter); } int test() { os_task_t *task; - cout<<"This is a C++ program!\r\n"< #endif -#define DLOG_FILTER_KW_MAX_LEN 15 -#define DLOG_FILTER_TAG_MAX_LEN 15 +#define DLOG_FILTER_KW_MAX_LEN 15 +#define DLOG_FILTER_TAG_MAX_LEN 15 -#define DLOG_NEWLINE_SIGN "\r\n" -#define DLOG_FRAME_MAGIC 0x10 +#define DLOG_NEWLINE_SIGN "\r\n" +#define DLOG_FRAME_MAGIC 0x10 #ifdef DLOG_USING_ASYNC_OUTPUT -#define DLOG_ASYNC_OUTPUT_STORE_LINES (DLOG_ASYNC_OUTPUT_BUF_SIZE * 3 / 2 / OS_LOG_BUFF_SIZE) +#define DLOG_ASYNC_OUTPUT_STORE_LINES (DLOG_ASYNC_OUTPUT_BUF_SIZE * 3 / 2 / OS_LOG_BUFF_SIZE) #if (DLOG_ASYNC_OUTPUT_TASK_PRIORITY > OS_TASK_PRIORITY_MAX - 1) #error "Dlog async task priority is greater than or equal to OS_TASK_PRIORITY_MAX" @@ -49,105 +49,92 @@ * CSI(Control Sequence Introducer/Initiator) sign. * More information on https://en.wikipedia.org/wiki/ANSI_escape_code */ -#define CSI_START "\033[" -#define CSI_END "\033[0m" +#define CSI_START "\033[" +#define CSI_END "\033[0m" /* Output log front color */ -#define F_BLACK "30m" -#define F_RED "31m" -#define F_GREEN "32m" -#define F_YELLOW "33m" -#define F_BLUE "34m" -#define F_MAGENTA "35m" -#define F_CYAN "36m" -#define F_WHITE "37m" - -#define DLOG_COLOR_DEBUG (OS_NULL) -#define DLOG_COLOR_INFO (F_GREEN) -#define DLOG_COLOR_WARN (F_YELLOW) -#define DLOG_COLOR_ERROR (F_RED) +#define F_BLACK "30m" +#define F_RED "31m" +#define F_GREEN "32m" +#define F_YELLOW "33m" +#define F_BLUE "34m" +#define F_MAGENTA "35m" +#define F_CYAN "36m" +#define F_WHITE "37m" + +#define DLOG_COLOR_DEBUG (OS_NULL) +#define DLOG_COLOR_INFO (F_GREEN) +#define DLOG_COLOR_WARN (F_YELLOW) +#define DLOG_COLOR_ERROR (F_RED) #endif /* DLOG_USING_COLOR */ struct dlog_ctrl_info { - os_bool_t init_ok; - os_mutex_t log_locker; + os_bool_t init_ok; + os_mutex_t log_locker; /* Global level */ - os_uint16_t global_level; - + os_uint16_t global_level; + /* All backends */ - os_list_node_t backend_list_head; - + os_list_node_t backend_list_head; + /* The task log's line buffer */ - char log_buf_task[OS_LOG_BUFF_SIZE]; + char log_buf_task[OS_LOG_BUFF_SIZE]; #ifdef DLOG_USING_ISR_LOG - os_ubase_t irq_save; - os_spinlock_t isr_spinlock; - char log_buf_isr[OS_LOG_BUFF_SIZE]; + os_ubase_t irq_save; + os_spinlock_t isr_spinlock; + char log_buf_isr[OS_LOG_BUFF_SIZE]; #endif #ifdef DLOG_USING_ASYNC_OUTPUT - rbb_ctrl_info_t *async_rbb; - os_task_t *async_task; - os_sem_t async_notice_sem; + rbb_ctrl_info_t *async_rbb; + os_task_t *async_task; + os_sem_t async_notice_sem; #endif #ifdef DLOG_USING_FILTER /* All tag's level filter */ - os_list_node_t tag_lvl_list_head; + os_list_node_t tag_lvl_list_head; - /* Global filter tag and keyword */ - char tag[DLOG_FILTER_TAG_MAX_LEN + 1]; - char keyword[DLOG_FILTER_KW_MAX_LEN + 1]; + /* Global filter tag and keyword */ + char tag[DLOG_FILTER_TAG_MAX_LEN + 1]; + char keyword[DLOG_FILTER_KW_MAX_LEN + 1]; #endif }; /* Tag's level filter */ struct dlog_tag_lvl_filter { - os_list_node_t list_node; - char tag[DLOG_FILTER_TAG_MAX_LEN + 1]; - os_uint16_t level; + os_list_node_t list_node; + char tag[DLOG_FILTER_TAG_MAX_LEN + 1]; + os_uint16_t level; }; typedef struct dlog_tag_lvl_filter dlog_tag_lvl_filter_t; struct dlog_frame { - os_uint8_t magic; /* Magic word is 0x10 ('lo') */ - os_uint8_t is_raw; - os_uint16_t level; - os_uint32_t log_len; - char *log; + os_uint8_t magic; /* Magic word is 0x10 ('lo') */ + os_uint8_t is_raw; + os_uint16_t level; + os_uint32_t log_len; + char *log; }; typedef struct dlog_frame dlog_frame_t; - - -static const char *gs_level_output_info[] = -{ - "EM/", - "A/", - "C/", - "E/", - "W/", - "N/", - "I/", - "D/" -}; +static const char *gs_level_output_info[] = {"EM/", "A/", "C/", "E/", "W/", "N/", "I/", "D/"}; #ifdef DLOG_USING_COLOR /* Color output info */ -static const char *gs_color_output_info[] = -{ - F_MAGENTA, /* Compatible for LOG_EMERG */ - F_MAGENTA, /* Compatible for LOG_ALERT */ - F_RED, /* Compatible for LOG_CRIT */ +static const char *gs_color_output_info[] = { + F_MAGENTA, /* Compatible for LOG_EMERG */ + F_MAGENTA, /* Compatible for LOG_ALERT */ + F_RED, /* Compatible for LOG_CRIT */ DLOG_COLOR_ERROR, DLOG_COLOR_WARN, - F_GREEN, /* Compatible for LOG_NOTICE */ + F_GREEN, /* Compatible for LOG_NOTICE */ DLOG_COLOR_INFO, DLOG_COLOR_DEBUG, }; @@ -176,7 +163,7 @@ static os_size_t dlog_strcpy(os_size_t cur_len, char *dst, const char *src) break; } } - + return src - src_old; } @@ -185,29 +172,29 @@ OS_UNUSED static os_size_t dlog_ultoa(char *str, unsigned long value) os_size_t i; os_size_t j; os_size_t len; - char swap; + char swap; - i = 0; - j = 0; + i = 0; + j = 0; len = 0; - + do { str[len] = value % 10 + '0'; - value = value / 10; + value = value / 10; len++; } while (value); - + str[len] = '\0'; /* Reverse string */ for (i = 0, j = len - 1; i < j; ++i, --j) { - swap = str[i]; + swap = str[i]; str[i] = str[j]; str[j] = swap; } - + return len; } @@ -216,9 +203,9 @@ static void dlog_lock(void) os_bool_t irq_active; os_bool_t irq_disabled; os_bool_t sched_locked; - os_err_t ret; + os_err_t ret; - irq_active = os_is_irq_active(); + irq_active = os_is_irq_active(); irq_disabled = os_is_irq_disabled(); sched_locked = os_is_schedule_locked(); @@ -227,7 +214,7 @@ static void dlog_lock(void) #ifdef DLOG_USING_ISR_LOG /* Interrupt context, interrupt disabled, or schedule locked */ os_spin_lock_irqsave(&gs_dlog_ctrl_info.isr_spinlock, &gs_dlog_ctrl_info.irq_save); -#endif +#endif } else { @@ -246,9 +233,9 @@ static void dlog_unlock(void) os_bool_t irq_active; os_bool_t irq_disabled; os_bool_t sched_locked; - os_err_t ret; + os_err_t ret; - irq_active = os_is_irq_active(); + irq_active = os_is_irq_active(); irq_disabled = os_is_irq_disabled(); sched_locked = os_is_schedule_locked(); @@ -273,10 +260,11 @@ static void dlog_unlock(void) static char *dlog_get_log_buf(void) { - os_bool_t irq_active; - char *log_buff;; + os_bool_t irq_active; + char *log_buff; + ; - log_buff = OS_NULL; + log_buff = OS_NULL; irq_active = os_is_irq_active(); /* Is in task context */ @@ -300,10 +288,10 @@ static char *dlog_get_log_buf(void) #ifdef DLOG_USING_FILTER OS_UNUSED static os_err_t dlog_tag_lvl_filter_set(const char *tag, os_uint16_t level) { - os_list_node_t *node; + os_list_node_t *node; dlog_tag_lvl_filter_t *tag_lvl; - os_int32_t ret; - os_bool_t found; + os_int32_t ret; + os_bool_t found; OS_ASSERT(OS_NULL != tag); OS_ASSERT(level <= DLOG_DEBUG); @@ -316,21 +304,21 @@ OS_UNUSED static os_err_t dlog_tag_lvl_filter_set(const char *tag, os_uint16_t l dlog_lock(); found = OS_FALSE; - os_list_for_each(node, &gs_dlog_ctrl_info.tag_lvl_list_head) + os_list_for_each(node, &gs_dlog_ctrl_info.tag_lvl_list_head) { tag_lvl = os_list_entry(node, dlog_tag_lvl_filter_t, list_node); if (!strncmp(tag_lvl->tag, tag, DLOG_FILTER_TAG_MAX_LEN)) { - found = OS_TRUE; + found = OS_TRUE; tag_lvl->level = level; - + break; } } - + dlog_unlock(); - - ret = OS_EOK; + + ret = OS_EOK; if (!found) { /* New a tag's level filter */ @@ -351,40 +339,40 @@ OS_UNUSED static os_err_t dlog_tag_lvl_filter_set(const char *tag, os_uint16_t l ret = OS_ENOMEM; } } - + return ret; } OS_UNUSED static os_err_t dlog_tag_lvl_filter_get(const char *tag, os_uint16_t *level) { - os_list_node_t *node; + os_list_node_t *node; dlog_tag_lvl_filter_t *tag_lvl; - os_bool_t found; - os_err_t ret; + os_bool_t found; + os_err_t ret; OS_ASSERT(OS_NULL != tag); OS_ASSERT(OS_NULL != level); - + if (OS_TRUE != gs_dlog_ctrl_info.init_ok) { return OS_ERROR; } - + dlog_lock(); found = OS_FALSE; - os_list_for_each(node, &gs_dlog_ctrl_info.tag_lvl_list_head) + os_list_for_each(node, &gs_dlog_ctrl_info.tag_lvl_list_head) { tag_lvl = os_list_entry(node, dlog_tag_lvl_filter_t, list_node); if (!strncmp(tag_lvl->tag, tag, DLOG_FILTER_TAG_MAX_LEN)) { - found = OS_TRUE; + found = OS_TRUE; *level = tag_lvl->level; - + break; } } - + dlog_unlock(); if (found) @@ -401,33 +389,33 @@ OS_UNUSED static os_err_t dlog_tag_lvl_filter_get(const char *tag, os_uint16_t * OS_UNUSED static os_err_t dlog_tag_lvl_filter_del(const char *tag) { - os_list_node_t *node; + os_list_node_t *node; dlog_tag_lvl_filter_t *tag_lvl; - os_bool_t found; - os_err_t ret; + os_bool_t found; + os_err_t ret; OS_ASSERT(OS_NULL != tag); - + if (OS_TRUE != gs_dlog_ctrl_info.init_ok) { return OS_ERROR; } - + dlog_lock(); found = OS_FALSE; - os_list_for_each(node, &gs_dlog_ctrl_info.tag_lvl_list_head) + os_list_for_each(node, &gs_dlog_ctrl_info.tag_lvl_list_head) { tag_lvl = os_list_entry(node, dlog_tag_lvl_filter_t, list_node); if (!strncmp(tag_lvl->tag, tag, DLOG_FILTER_TAG_MAX_LEN)) { - found = OS_TRUE; + found = OS_TRUE; os_list_del(&tag_lvl->list_node); os_free(tag_lvl); break; } } - + dlog_unlock(); if (found) @@ -440,7 +428,6 @@ OS_UNUSED static os_err_t dlog_tag_lvl_filter_del(const char *tag) } return ret; - } OS_UNUSED static void dlog_global_filter_tag_set(const char *tag) @@ -449,7 +436,7 @@ OS_UNUSED static void dlog_global_filter_tag_set(const char *tag) memset(gs_dlog_ctrl_info.tag, 0, sizeof(gs_dlog_ctrl_info.tag)); strncpy(gs_dlog_ctrl_info.tag, tag, DLOG_FILTER_TAG_MAX_LEN); - + return; } @@ -491,9 +478,9 @@ OS_UNUSED static void dlog_global_filter_kw_del(void) void dlog_global_lvl_set(os_uint16_t level) { OS_ASSERT(level <= DLOG_DEBUG); - + gs_dlog_ctrl_info.global_level = level; - + return; } @@ -502,16 +489,12 @@ os_uint16_t dlog_global_lvl_get(void) return gs_dlog_ctrl_info.global_level; } -static os_size_t dlog_formater(char *log_buf, - os_uint16_t level, - const char *tag, - os_bool_t newline, - const char *format, - va_list args) +static os_size_t +dlog_formater(char *log_buf, os_uint16_t level, const char *tag, os_bool_t newline, const char *format, va_list args) { /* The caller has locker, so it can use static variable for reduce stack usage */ - static os_size_t s_log_len; - static os_size_t s_newline_len; + static os_size_t s_log_len; + static os_size_t s_newline_len; static os_int32_t s_fmt_result; s_log_len = 0; @@ -524,7 +507,7 @@ static os_size_t dlog_formater(char *log_buf, { s_newline_len = 0; } - + #ifdef DLOG_USING_COLOR /* Add CSI start sign and color info */ if (OS_NULL != gs_color_output_info[level]) @@ -538,13 +521,13 @@ static os_size_t dlog_formater(char *log_buf, /* Add time info */ { #ifdef DLOG_TIME_USING_TIMESTAMP - static time_t s_now; + static time_t s_now; static struct tm *s_tm; - static struct tm s_tm_tmp; + static struct tm s_tm_tmp; s_now = time(OS_NULL); - s_tm = gmtime_r(&s_now, &s_tm_tmp); - + s_tm = gmtime_r(&s_now, &s_tm_tmp); + snprintf(log_buf + s_log_len, OS_LOG_BUFF_SIZE - s_log_len, "%02d-%02d %02d:%02d:%02d", @@ -558,7 +541,7 @@ static os_size_t dlog_formater(char *log_buf, log_buf[s_log_len] = '['; tick_len = dlog_ultoa(log_buf + s_log_len + 1, os_tick_get()); - log_buf[s_log_len + 1 + tick_len] = ']'; + log_buf[s_log_len + 1 + tick_len] = ']'; log_buf[s_log_len + 1 + tick_len + 1] = '\0'; #endif /* DLOG_TIME_USING_TIMESTAMP */ @@ -632,23 +615,20 @@ static os_size_t dlog_formater(char *log_buf, log_buf[s_log_len] = '\0'; s_log_len++; - + return s_log_len; } -static void dlog_output_to_all_backend(os_uint16_t level, - os_bool_t is_raw, - char *log, - os_size_t log_len) +static void dlog_output_to_all_backend(os_uint16_t level, os_bool_t is_raw, char *log, os_size_t log_len) { - os_list_node_t *node; - dlog_backend_t *backend; - os_bool_t irq_active; + os_list_node_t *node; + dlog_backend_t *backend; + os_bool_t irq_active; irq_active = os_is_irq_active(); - + /* Output for all backends */ - os_list_for_each(node, &gs_dlog_ctrl_info.backend_list_head) + os_list_for_each(node, &gs_dlog_ctrl_info.backend_list_head) { backend = os_list_entry(node, dlog_backend_t, list_node); @@ -675,8 +655,8 @@ static void dlog_output_to_all_backend(os_uint16_t level, os_size_t output_size; color_info_len = strlen(gs_color_output_info[level]); - output_size = log_len; - + output_size = log_len; + if (color_info_len) { os_size_t color_hdr_len; @@ -687,7 +667,7 @@ static void dlog_output_to_all_backend(os_uint16_t level, /* "1" is '\0' */ output_size -= (color_hdr_len + strlen(CSI_END)); } - + backend->output(backend, log, output_size); } #endif /* DLOG_USING_COLOR */ @@ -699,28 +679,28 @@ static void dlog_output_to_all_backend(os_uint16_t level, static void dlog_do_output(os_uint16_t level, const char *tag, os_bool_t is_raw, char *log_buf, os_size_t log_len) { #ifdef DLOG_USING_ASYNC_OUTPUT - rbb_blk_t *log_blk; + rbb_blk_t *log_blk; dlog_frame_t *log_frame; - os_err_t ret; + os_err_t ret; /* allocate log frame */ log_blk = rbb_blk_alloc(gs_dlog_ctrl_info.async_rbb, OS_ALIGN_UP(sizeof(dlog_frame_t) + log_len, OS_ALIGN_SIZE)); if (log_blk) { /* Package the log frame */ - log_frame = (dlog_frame_t *)log_blk->buf; - log_frame->magic = DLOG_FRAME_MAGIC; - log_frame->is_raw = is_raw; - log_frame->level = level; + log_frame = (dlog_frame_t *)log_blk->buf; + log_frame->magic = DLOG_FRAME_MAGIC; + log_frame->is_raw = is_raw; + log_frame->level = level; log_frame->log_len = log_len; - log_frame->log = (char *)log_blk->buf + sizeof(dlog_frame_t); + log_frame->log = (char *)log_blk->buf + sizeof(dlog_frame_t); /* Copy log data */ memcpy(log_blk->buf + sizeof(dlog_frame_t), log_buf, log_len); - + /* Put the block */ rbb_blk_put(log_blk); - + /* Send a notice */ ret = os_sem_post(&gs_dlog_ctrl_info.async_notice_sem); if (OS_EOK != ret) @@ -731,7 +711,7 @@ static void dlog_do_output(os_uint16_t level, const char *tag, os_bool_t is_raw, else { static os_bool_t already_output = OS_FALSE; - + if (already_output == OS_FALSE) { os_kprintf("Warning: There is no enough buffer for saving async log, " @@ -744,7 +724,7 @@ static void dlog_do_output(os_uint16_t level, const char *tag, os_bool_t is_raw, /* Output to all backends */ dlog_output_to_all_backend(level, is_raw, log_buf, log_len); - + #endif /* DLOG_USING_ASYNC_OUTPUT */ return; @@ -752,14 +732,14 @@ static void dlog_do_output(os_uint16_t level, const char *tag, os_bool_t is_raw, void dlog_voutput(os_uint16_t level, const char *tag, os_bool_t newline, const char *format, va_list args) { - char *log_buf; - os_size_t log_len; - os_uint16_t tag_level; - os_uint16_t global_level; + char *log_buf; + os_size_t log_len; + os_uint16_t tag_level; + os_uint16_t global_level; #ifdef DLOG_USING_FILTER - os_err_t ret; -#endif - + os_err_t ret; +#endif + OS_ASSERT(level <= DLOG_DEBUG); OS_ASSERT(OS_NULL != tag); OS_ASSERT(OS_NULL != format); @@ -772,7 +752,7 @@ void dlog_voutput(os_uint16_t level, const char *tag, os_bool_t newline, const c } tag_level = OS_UINT16_MAX; - + #ifdef DLOG_USING_FILTER ret = dlog_tag_lvl_filter_get(tag, &tag_level); if (ret != OS_EOK) @@ -831,15 +811,14 @@ void dlog_voutput(os_uint16_t level, const char *tag, os_bool_t newline, const c /* Do log output */ dlog_do_output(level, tag, OS_FALSE, log_buf, log_len); - + dlog_unlock(); } while (0); - + return; } - void dlog_output(os_uint16_t level, const char *tag, os_bool_t newline, const char *format, ...) { va_list args; @@ -853,9 +832,9 @@ void dlog_output(os_uint16_t level, const char *tag, os_bool_t newline, const ch void dlog_raw(const char *format, ...) { - os_size_t log_len; - char *log_buf; - va_list args; + os_size_t log_len; + char *log_buf; + va_list args; if (OS_TRUE == gs_dlog_ctrl_info.init_ok) { @@ -866,7 +845,7 @@ void dlog_raw(const char *format, ...) va_start(args, format); #ifdef DLOG_OUTPUT_FLOAT - /* + /* * When log size is larger than buffer size, this function will truncature * and fill '\0' at the buffer tail. The return len is log size without '\0' */ @@ -891,29 +870,27 @@ void dlog_raw(const char *format, ...) } } - return; + return; } - - static void dlog_do_hexdump(const char *tag, - os_size_t width, + os_size_t width, os_uint8_t *data_buf, - os_size_t data_buf_size, - char *log_buf, - os_size_t log_buf_size) + os_size_t data_buf_size, + char *log_buf, + os_size_t log_buf_size) { -#define __is_print(ch) ((unsigned int)((ch) - ' ') < 127U - ' ') - - os_size_t i; - os_size_t j; - os_size_t log_len; - os_size_t name_len; - char dump_string[8]; +#define __is_print(ch) ((unsigned int)((ch) - ' ') < 127U - ' ') + + os_size_t i; + os_size_t j; + os_size_t log_len; + os_size_t name_len; + char dump_string[8]; os_int32_t fmt_result; - + name_len = strlen(tag); - + dlog_lock(); log_len = 0; @@ -931,8 +908,10 @@ static void dlog_do_hexdump(const char *tag, log_len = 6 + name_len + 2; memset(log_buf, ' ', log_len); } - - fmt_result = os_snprintf(log_buf + log_len, log_buf_size - log_len, "%04X-%04X: ", + + fmt_result = os_snprintf(log_buf + log_len, + log_buf_size - log_len, + "%04X-%04X: ", (os_uint16_t)i, (os_uint16_t)(i + width)); @@ -945,7 +924,7 @@ static void dlog_do_hexdump(const char *tag, { log_len = log_buf_size; } - + /* Dump hex */ for (j = 0; j < width; j++) { @@ -957,14 +936,14 @@ static void dlog_do_hexdump(const char *tag, { strncpy(dump_string, " ", sizeof(dump_string)); } - + log_len += dlog_strcpy(log_len, log_buf + log_len, dump_string); if ((j + 1) % 8 == 0) { log_len += dlog_strcpy(log_len, log_buf + log_len, " "); } } - + log_len += dlog_strcpy(log_len, log_buf + log_len, " "); /* Dump char for hex */ @@ -972,26 +951,29 @@ static void dlog_do_hexdump(const char *tag, { if (i + j < data_buf_size) { - os_snprintf(dump_string, sizeof(dump_string), "%c", __is_print(data_buf[i + j]) ? data_buf[i + j] : '.'); + os_snprintf(dump_string, + sizeof(dump_string), + "%c", + __is_print(data_buf[i + j]) ? data_buf[i + j] : '.'); log_len += dlog_strcpy(log_len, log_buf + log_len, dump_string); } } - + /* Overflow check and reserve some space for newline sign */ if (log_len > log_buf_size - strlen(DLOG_NEWLINE_SIGN) - 1) { log_len = log_buf_size - strlen(DLOG_NEWLINE_SIGN) - 1; } - + /* Package newline sign */ log_len += dlog_strcpy(log_len, log_buf + log_len, DLOG_NEWLINE_SIGN); log_buf[log_len] = '\0'; log_len++; - + /* Do log output */ dlog_do_output(DLOG_DEBUG, OS_NULL, OS_TRUE, log_buf, log_len); } - + dlog_unlock(); return; @@ -1021,9 +1003,9 @@ void dlog_hexdump(const char *tag, os_size_t width, os_uint8_t *buf, os_size_t s #ifdef DLOG_USING_ASYNC_OUTPUT static void dlog_async_output_task_entry(void *arg) { - rbb_blk_t *log_blk; + rbb_blk_t *log_blk; dlog_frame_t *log_frame; - os_err_t ret; + os_err_t ret; while (1) { @@ -1032,9 +1014,9 @@ static void dlog_async_output_task_entry(void *arg) { OS_ASSERT_EX(0, "Why sem wait failed?"); } - + while (1) - { + { log_blk = rbb_blk_get(gs_dlog_ctrl_info.async_rbb); if (OS_NULL == log_blk) { @@ -1047,7 +1029,7 @@ static void dlog_async_output_task_entry(void *arg) /* Output to all backends */ dlog_output_to_all_backend(log_frame->level, log_frame->is_raw, log_frame->log, log_frame->log_len); } - + rbb_blk_free(gs_dlog_ctrl_info.async_rbb, log_blk); } } @@ -1055,7 +1037,7 @@ static void dlog_async_output_task_entry(void *arg) OS_UNUSED static void dlog_async_output(void) { - rbb_blk_t *log_blk; + rbb_blk_t *log_blk; dlog_frame_t *log_frame; log_blk = rbb_blk_get(gs_dlog_ctrl_info.async_rbb); @@ -1066,9 +1048,9 @@ OS_UNUSED static void dlog_async_output(void) { dlog_output_to_all_backend(log_frame->level, log_frame->is_raw, log_frame->log, log_frame->log_len); } - + rbb_blk_free(gs_dlog_ctrl_info.async_rbb, log_blk); - + log_blk = rbb_blk_get(gs_dlog_ctrl_info.async_rbb); } @@ -1101,7 +1083,7 @@ void dlog_flush(void) } dlog_unlock(); - + return; } @@ -1109,26 +1091,26 @@ os_err_t dlog_backend_register(dlog_backend_t *backend) { dlog_backend_t *backend_iter; os_list_node_t *node; - os_bool_t found; - os_err_t ret; + os_bool_t found; + os_err_t ret; OS_ASSERT(OS_NULL != backend); OS_ASSERT(OS_NULL != backend->output); found = OS_FALSE; - ret = OS_EOK; + ret = OS_EOK; if (OS_TRUE == gs_dlog_ctrl_info.init_ok) { dlog_lock(); - os_list_for_each(node, &gs_dlog_ctrl_info.backend_list_head) + os_list_for_each(node, &gs_dlog_ctrl_info.backend_list_head) { backend_iter = os_list_entry(node, dlog_backend_t, list_node); if (backend == backend_iter) { found = OS_TRUE; break; - } + } } dlog_unlock(); @@ -1148,7 +1130,7 @@ os_err_t dlog_backend_register(dlog_backend_t *backend) { ret = OS_EPERM; } - + return ret; } @@ -1156,27 +1138,27 @@ os_err_t dlog_backend_unregister(dlog_backend_t *backend) { dlog_backend_t *backend_iter; os_list_node_t *node; - os_bool_t found; - os_err_t ret; + os_bool_t found; + os_err_t ret; OS_ASSERT(OS_NULL != backend); found = OS_FALSE; - ret = OS_EOK; + ret = OS_EOK; if (OS_TRUE == gs_dlog_ctrl_info.init_ok) { dlog_lock(); - os_list_for_each(node, &gs_dlog_ctrl_info.backend_list_head) + os_list_for_each(node, &gs_dlog_ctrl_info.backend_list_head) { backend_iter = os_list_entry(node, dlog_backend_t, list_node); if (backend == backend_iter) { found = OS_TRUE; os_list_del(&backend->list_node); - + break; - } + } } dlog_unlock(); @@ -1208,7 +1190,7 @@ os_err_t dlog_init(void) ret = os_mutex_init(&gs_dlog_ctrl_info.log_locker, "dlog_locker", OS_FALSE); OS_ASSERT(OS_EOK == ret); - + os_list_init(&gs_dlog_ctrl_info.backend_list_head); #ifdef DLOG_USING_FILTER @@ -1219,17 +1201,18 @@ os_err_t dlog_init(void) os_spin_lock_init(&gs_dlog_ctrl_info.isr_spinlock); #endif -#ifdef DLOG_USING_ASYNC_OUTPUT - OS_ASSERT_EX(DLOG_ASYNC_OUTPUT_STORE_LINES >= 2, "Asynchronous output buffer(%u) is too small.", +#ifdef DLOG_USING_ASYNC_OUTPUT + OS_ASSERT_EX(DLOG_ASYNC_OUTPUT_STORE_LINES >= 2, + "Asynchronous output buffer(%u) is too small.", DLOG_ASYNC_OUTPUT_BUF_SIZE); /* Async output ring block buffer */ - gs_dlog_ctrl_info.async_rbb = rbb_create(OS_ALIGN_UP(DLOG_ASYNC_OUTPUT_BUF_SIZE, OS_ALIGN_SIZE), - DLOG_ASYNC_OUTPUT_STORE_LINES); + gs_dlog_ctrl_info.async_rbb = + rbb_create(OS_ALIGN_UP(DLOG_ASYNC_OUTPUT_BUF_SIZE, OS_ALIGN_SIZE), DLOG_ASYNC_OUTPUT_STORE_LINES); if (OS_NULL == gs_dlog_ctrl_info.async_rbb) { os_kprintf("Dlog init failed! No memory for async rbb.\r\n"); - + (void)os_mutex_deinit(&gs_dlog_ctrl_info.log_locker); ret = OS_ENOMEM; @@ -1247,17 +1230,17 @@ os_err_t dlog_init(void) os_kprintf("Dlog init failed! Create async output task failed.\r\n"); rbb_destroy(gs_dlog_ctrl_info.async_rbb); - + ret = os_mutex_deinit(&gs_dlog_ctrl_info.log_locker); OS_ASSERT(OS_EOK == ret); - + ret = OS_ERROR; break; } ret = os_sem_init(&gs_dlog_ctrl_info.async_notice_sem, "dlog_sem", 0, OS_SEM_MAX_VALUE); OS_ASSERT(OS_EOK == ret); - + ret = os_task_startup(gs_dlog_ctrl_info.async_task); OS_ASSERT(OS_EOK == ret); @@ -1268,7 +1251,7 @@ os_err_t dlog_init(void) break; } while (0); - + return ret; } OS_PREV_INIT(dlog_init, OS_INIT_SUBLEVEL_HIGH); @@ -1278,48 +1261,38 @@ OS_PREV_INIT(dlog_init, OS_INIT_SUBLEVEL_HIGH); #include #include -#define SH_DLOG_LEVEL_INVALID 0xFFFFU +#define SH_DLOG_LEVEL_INVALID 0xFFFFU struct dlog_cmd_ctrl_info { - os_int32_t ctrl_info; - + os_int32_t ctrl_info; + #ifdef DLOG_USING_FILTER - char tag_name[DLOG_FILTER_TAG_MAX_LEN + 1]; - char keyword [DLOG_FILTER_KW_MAX_LEN + 1]; + char tag_name[DLOG_FILTER_TAG_MAX_LEN + 1]; + char keyword[DLOG_FILTER_KW_MAX_LEN + 1]; #endif - - os_uint16_t level; + + os_uint16_t level; }; typedef struct dlog_cmd_ctrl_info dlog_cmd_ctrl_info_t; -static dlog_cmd_ctrl_info_t gs_dlog_cmd_ctrl_info = {0}; +static dlog_cmd_ctrl_info_t gs_dlog_cmd_ctrl_info = {0}; -static char *gs_dlog_level_info[8] = -{ - "emerg", - "alert", - "crit", - "error", - "warning", - "notice", - "info", - "debug" -}; +static char *gs_dlog_level_info[8] = {"emerg", "alert", "crit", "error", "warning", "notice", "info", "debug"}; -#define COMMAND_SET_OPTION 1 -#define COMMAND_GET_OPTION 2 -#define COMMAND_DEL_OPTION 3 +#define COMMAND_SET_OPTION 1 +#define COMMAND_GET_OPTION 2 +#define COMMAND_DEL_OPTION 3 -static os_err_t sh_dlog_ctrl_info_get(os_int32_t argc, char * const *argv, dlog_cmd_ctrl_info_t *ctrl_info) +static os_err_t sh_dlog_ctrl_info_get(os_int32_t argc, char *const *argv, dlog_cmd_ctrl_info_t *ctrl_info) { opt_state_t state; - os_int32_t opt_ret; - os_int32_t ret; + os_int32_t opt_ret; + os_int32_t ret; - memset(ctrl_info, 0 , sizeof(dlog_cmd_ctrl_info_t)); + memset(ctrl_info, 0, sizeof(dlog_cmd_ctrl_info_t)); ctrl_info->level = SH_DLOG_LEVEL_INVALID; - + memset(&state, 0, sizeof(state)); opt_init(&state, 1); @@ -1337,7 +1310,7 @@ static os_err_t sh_dlog_ctrl_info_get(os_int32_t argc, char * const *argv, dlog_ ret = OS_ERROR; break; } - + switch (opt_ret) { case 's': @@ -1347,15 +1320,15 @@ static os_err_t sh_dlog_ctrl_info_get(os_int32_t argc, char * const *argv, dlog_ case 'g': ctrl_info->ctrl_info = COMMAND_GET_OPTION; break; - + case 'd': ctrl_info->ctrl_info = COMMAND_DEL_OPTION; break; - + case 'l': ctrl_info->level = (os_uint16_t)atoi(state.opt_arg); break; - + #ifdef DLOG_USING_FILTER case 't': memset(ctrl_info->tag_name, 0, sizeof(ctrl_info->tag_name)); @@ -1366,7 +1339,7 @@ static os_err_t sh_dlog_ctrl_info_get(os_int32_t argc, char * const *argv, dlog_ memset(ctrl_info->keyword, 0, sizeof(ctrl_info->keyword)); strncpy(ctrl_info->keyword, state.opt_arg, DLOG_FILTER_KW_MAX_LEN); break; -#endif +#endif default: os_kprintf("Invalid option: %c\r\n", (char)opt_ret); @@ -1394,13 +1367,13 @@ static void sh_dlog_glvl_ctrl_help(void) os_kprintf(" -g Get global level option.\r\n"); os_kprintf(" -l Specify a global level that want to be set.\r\n"); os_kprintf(" level: 0-emerg, 1-alert, 2-crit, 3-error, 4-warning, 5-notice, 6-info, 7-debug\r\n"); - + return; } static os_err_t sh_dlog_glvl_ctrl(os_int32_t argc, char **argv) { - os_err_t ret; + os_err_t ret; os_uint16_t level; ret = sh_dlog_ctrl_info_get(argc, argv, &gs_dlog_cmd_ctrl_info); @@ -1409,8 +1382,8 @@ static os_err_t sh_dlog_glvl_ctrl(os_int32_t argc, char **argv) if (COMMAND_GET_OPTION == gs_dlog_cmd_ctrl_info.ctrl_info) { level = dlog_global_lvl_get(); - - os_kprintf("Global level is: %s\r\n", gs_dlog_level_info[level]); + + os_kprintf("Global level is: %s\r\n", gs_dlog_level_info[level]); } else if (COMMAND_SET_OPTION == gs_dlog_cmd_ctrl_info.ctrl_info) { @@ -1426,8 +1399,8 @@ static os_err_t sh_dlog_glvl_ctrl(os_int32_t argc, char **argv) } else { - (void)dlog_global_lvl_set(gs_dlog_cmd_ctrl_info.level); - os_kprintf("Set global level(%s) success!\r\n", gs_dlog_level_info[gs_dlog_cmd_ctrl_info.level]); + (void)dlog_global_lvl_set(gs_dlog_cmd_ctrl_info.level); + os_kprintf("Set global level(%s) success!\r\n", gs_dlog_level_info[gs_dlog_cmd_ctrl_info.level]); } } else @@ -1446,19 +1419,17 @@ static os_err_t sh_dlog_glvl_ctrl(os_int32_t argc, char **argv) sh_dlog_glvl_ctrl_help(); } - return ret; - + return ret; } SH_CMD_EXPORT(dlog_glvl_ctrl, sh_dlog_glvl_ctrl, "Dlog global level control"); - #ifdef DLOG_USING_FILTER static void sh_dlog_tlvl_ctrl_help(void) { os_kprintf("Command format:\r\n"); os_kprintf("dlog_tlvl_ctrl <-s | -g | -d> <-t tag name> [-l tag level]\r\n"); os_kprintf("parameter Usage:\r\n"); - + os_kprintf(" -s Set tag level option.\r\n"); os_kprintf(" -g Get tag level option.\r\n"); os_kprintf(" -d Delete tag level option.\r\n"); @@ -1472,7 +1443,7 @@ static void sh_dlog_tlvl_ctrl_help(void) static os_err_t sh_do_dlog_tlvl_ctrl(os_int32_t ctrl_info, char *tag_name, os_uint16_t set_level) { os_uint16_t get_level; - os_err_t ret; + os_err_t ret; ret = OS_EOK; @@ -1485,7 +1456,7 @@ static os_err_t sh_do_dlog_tlvl_ctrl(os_int32_t ctrl_info, char *tag_name, os_ui } else { - os_kprintf("The tag(%s) level is: %s.\r\n", tag_name, gs_dlog_level_info[get_level]); + os_kprintf("The tag(%s) level is: %s.\r\n", tag_name, gs_dlog_level_info[get_level]); } } else if (COMMAND_SET_OPTION == gs_dlog_cmd_ctrl_info.ctrl_info) @@ -1510,7 +1481,7 @@ static os_err_t sh_do_dlog_tlvl_ctrl(os_int32_t ctrl_info, char *tag_name, os_ui else { os_kprintf("Set tag success, tag: %s, level: %s\r\n", tag_name, gs_dlog_level_info[set_level]); - } + } } } else @@ -1533,39 +1504,38 @@ static os_err_t sh_dlog_tlvl_ctrl(os_int32_t argc, char **argv) { os_bool_t cmd_option_valid; os_bool_t tag_name_valid; - os_err_t ret; + os_err_t ret; cmd_option_valid = OS_TRUE; - tag_name_valid = OS_TRUE; + tag_name_valid = OS_TRUE; ret = sh_dlog_ctrl_info_get(argc, argv, &gs_dlog_cmd_ctrl_info); if (OS_EOK == ret) { - if ((COMMAND_GET_OPTION != gs_dlog_cmd_ctrl_info.ctrl_info) - && (COMMAND_SET_OPTION != gs_dlog_cmd_ctrl_info.ctrl_info) - && (COMMAND_DEL_OPTION != gs_dlog_cmd_ctrl_info.ctrl_info)) + if ((COMMAND_GET_OPTION != gs_dlog_cmd_ctrl_info.ctrl_info) && + (COMMAND_SET_OPTION != gs_dlog_cmd_ctrl_info.ctrl_info) && + (COMMAND_DEL_OPTION != gs_dlog_cmd_ctrl_info.ctrl_info)) { os_kprintf("No command option, please input -s, -g or -d!\r\n"); - cmd_option_valid = OS_FALSE; + cmd_option_valid = OS_FALSE; } if (0U == strlen(gs_dlog_cmd_ctrl_info.tag_name)) { os_kprintf("No tag name option!\r\n"); - tag_name_valid = OS_FALSE; - } + tag_name_valid = OS_FALSE; + } if ((OS_TRUE == cmd_option_valid) && (OS_TRUE == tag_name_valid)) { ret = sh_do_dlog_tlvl_ctrl(gs_dlog_cmd_ctrl_info.ctrl_info, gs_dlog_cmd_ctrl_info.tag_name, - gs_dlog_cmd_ctrl_info.level); + gs_dlog_cmd_ctrl_info.level); } else { ret = OS_EINVAL; } - } else { @@ -1597,7 +1567,7 @@ static void sh_dlog_gtag_ctrl_help(void) static os_err_t sh_dlog_gtag_ctrl(os_int32_t argc, char **argv) { const char *tag; - os_err_t ret; + os_err_t ret; ret = sh_dlog_ctrl_info_get(argc, argv, &gs_dlog_cmd_ctrl_info); if (OS_EOK == ret) @@ -1631,7 +1601,7 @@ static os_err_t sh_dlog_gtag_ctrl(os_int32_t argc, char **argv) else if (COMMAND_DEL_OPTION == gs_dlog_cmd_ctrl_info.ctrl_info) { dlog_global_filter_tag_del(); - os_kprintf("Del global filter tag success.\r\n"); + os_kprintf("Del global filter tag success.\r\n"); } else { @@ -1670,7 +1640,7 @@ static void sh_dlog_gkw_ctrl_help(void) static os_err_t sh_dlog_gkw_ctrl(os_int32_t argc, char **argv) { const char *keyword; - os_err_t ret; + os_err_t ret; ret = sh_dlog_ctrl_info_get(argc, argv, &gs_dlog_cmd_ctrl_info); if (OS_EOK == ret) @@ -1704,7 +1674,7 @@ static os_err_t sh_dlog_gkw_ctrl(os_int32_t argc, char **argv) else if (COMMAND_DEL_OPTION == gs_dlog_cmd_ctrl_info.ctrl_info) { dlog_global_filter_kw_del(); - os_kprintf("Del global filter keyword success.\r\n"); + os_kprintf("Del global filter keyword success.\r\n"); } else { @@ -1739,4 +1709,3 @@ SH_CMD_EXPORT(dlog_flush, sh_dlog_flush, "Flush dlog cache"); #endif /* OS_USING_SHELL */ #endif /* OS_USING_DLOG */ - diff --git a/components/dlog/source/log_internal.h b/components/dlog/source/log_internal.h index ef722a80..ab875afa 100644 --- a/components/dlog/source/log_internal.h +++ b/components/dlog/source/log_internal.h @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file log_internal.h @@ -27,4 +27,3 @@ extern void dlog_voutput(os_uint16_t level, const char *tag, os_bool_t newline, const char *format, va_list args); #endif /* __LOG_INTERNAL_H__ */ - diff --git a/components/dlog/source/syslog/syslog.c b/components/dlog/source/syslog/syslog.c index 66878f3a..92fa48a2 100644 --- a/components/dlog/source/syslog/syslog.c +++ b/components/dlog/source/syslog/syslog.c @@ -3,13 +3,13 @@ * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * COPYRIGHT (C) 2006 - 2018,RT - Thread Development Team * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file syslog.c @@ -43,9 +43,9 @@ #ifdef DLOG_USING_SYSLOG -#define DLOG_SYSLOG_IDENT_MAX_LEN 15 +#define DLOG_SYSLOG_IDENT_MAX_LEN 15 -static char gs_local_ident[DLOG_SYSLOG_IDENT_MAX_LEN + 1] = {0}; +static char gs_local_ident[DLOG_SYSLOG_IDENT_MAX_LEN + 1] = {0}; static os_bool_t gs_is_open = OS_FALSE; /** @@ -73,7 +73,7 @@ void openlog(const char *ident, int option, int facility) if (OS_EOK == ret) { memset(gs_local_ident, 0, sizeof(gs_local_ident)); - + if (OS_NULL != ident) { strncpy(gs_local_ident, ident, DLOG_SYSLOG_IDENT_MAX_LEN); @@ -92,7 +92,7 @@ void openlog(const char *ident, int option, int facility) } return; -} +} /** *********************************************************************************************************************** @@ -113,7 +113,7 @@ void syslog(int priority, const char *format, ...) { openlog(OS_NULL, 0, 0); } - + /* Args point to the first variable parameter */ va_start(args, format); dlog_voutput((os_uint16_t)priority, gs_local_ident, OS_TRUE, format, args); @@ -137,8 +137,7 @@ void closelog(void) { gs_is_open = OS_FALSE; } - + return; } #endif /* DLOG_USING_SYSLOG */ - diff --git a/components/libc/include/armlibc/dirent.h b/components/libc/include/armlibc/dirent.h index 6b065d59..1be79b25 100644 --- a/components/libc/include/armlibc/dirent.h +++ b/components/libc/include/armlibc/dirent.h @@ -26,4 +26,3 @@ #include #endif /* __DIRENT_H__ */ - diff --git a/components/libc/include/armlibc/fcntl.h b/components/libc/include/armlibc/fcntl.h index a271cb83..f81365ae 100644 --- a/components/libc/include/armlibc/fcntl.h +++ b/components/libc/include/armlibc/fcntl.h @@ -26,4 +26,3 @@ #include #endif /* __FCNTL_H__ */ - diff --git a/components/libc/include/armlibc/poll.h b/components/libc/include/armlibc/poll.h index 9e97c9c4..d98f3b40 100644 --- a/components/libc/include/armlibc/poll.h +++ b/components/libc/include/armlibc/poll.h @@ -26,4 +26,3 @@ #include #endif /* __POLL_H__ */ - diff --git a/components/libc/include/armlibc/sys/dirent.h b/components/libc/include/armlibc/sys/dirent.h index 8bba6c81..175cdf45 100644 --- a/components/libc/include/armlibc/sys/dirent.h +++ b/components/libc/include/armlibc/sys/dirent.h @@ -30,32 +30,32 @@ extern "C" { #endif /* Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html */ -#define DT_UNKNOWN 0 -#define DT_FIFO 1 -#define DT_CHR 2 -#define DT_DIR 4 -#define DT_BLK 6 -#define DT_REG 8 -#define DT_LNK 10 -#define DT_SOCK 12 -#define DT_WHT 14 +#define DT_UNKNOWN 0 +#define DT_FIFO 1 +#define DT_CHR 2 +#define DT_DIR 4 +#define DT_BLK 6 +#define DT_REG 8 +#define DT_LNK 10 +#define DT_SOCK 12 +#define DT_WHT 14 struct dirent { - ino_t d_ino; /* file number */ - unsigned char d_type; /* The type of the file. */ - char d_name[256]; /* The null-terminated file name. */ + ino_t d_ino; /* file number */ + unsigned char d_type; /* The type of the file. */ + char d_name[256]; /* The null-terminated file name. */ }; struct __dirstream { - int fd; /* File descriptor. */ - size_t allocation; /* Space allocated for the block. */ - size_t size; /* Total valid data in the block. */ - size_t offset; /* Current offset into the block. */ - off_t filepos; /* Position of next entry to read. */ - int errcode; /* Delayed error code. */ - void *priv; + int fd; /* File descriptor. */ + size_t allocation; /* Space allocated for the block. */ + size_t size; /* Total valid data in the block. */ + size_t offset; /* Current offset into the block. */ + off_t filepos; /* Position of next entry to read. */ + int errcode; /* Delayed error code. */ + void *priv; }; /* @@ -64,16 +64,15 @@ struct __dirstream */ typedef struct __dirstream DIR; -extern int closedir(DIR *pdir); -extern DIR *opendir(const char *path); +extern int closedir(DIR *pdir); +extern DIR *opendir(const char *path); extern struct dirent *readdir(DIR *pdir); -extern void rewinddir(DIR *pdir); -extern void seekdir(DIR *pdir, long ofst); -extern long telldir(DIR *pdir); +extern void rewinddir(DIR *pdir); +extern void seekdir(DIR *pdir, long ofst); +extern long telldir(DIR *pdir); #ifdef __cplusplus } #endif #endif /* __SYS_DIRENT_H__ */ - diff --git a/components/libc/include/armlibc/sys/errno.h b/components/libc/include/armlibc/sys/errno.h index fb715fdb..376cdfef 100644 --- a/components/libc/include/armlibc/sys/errno.h +++ b/components/libc/include/armlibc/sys/errno.h @@ -26,4 +26,3 @@ #include "../../extension/errno_ext.h" #endif /* __SYS_ERRNO_H__ */ - diff --git a/components/libc/include/armlibc/sys/fcntl.h b/components/libc/include/armlibc/sys/fcntl.h index 79db6ec8..6b4f365b 100644 --- a/components/libc/include/armlibc/sys/fcntl.h +++ b/components/libc/include/armlibc/sys/fcntl.h @@ -23,35 +23,34 @@ #ifndef __SYS_FCNTL_H__ #define __SYS_FCNTL_H__ -#define O_RDONLY 0 -#define O_WRONLY 1 -#define O_RDWR 2 +#define O_RDONLY 0 +#define O_WRONLY 1 +#define O_RDWR 2 -#define O_APPEND 0x0008 -#define O_CREAT 0x0200 -#define O_TRUNC 0x0400 -#define O_EXCL 0x0800 -#define O_SYNC 0x2000 -#define O_NONBLOCK 0x4000 -#define O_NOCTTY 0x8000 -#define O_BINARY 0x10000 -#define O_DIRECTORY 0x200000 +#define O_APPEND 0x0008 +#define O_CREAT 0x0200 +#define O_TRUNC 0x0400 +#define O_EXCL 0x0800 +#define O_SYNC 0x2000 +#define O_NONBLOCK 0x4000 +#define O_NOCTTY 0x8000 +#define O_BINARY 0x10000 +#define O_DIRECTORY 0x200000 -#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR) +#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR) -#define F_DUPFD 0 -#define F_GETFD 1 -#define F_SETFD 2 -#define F_GETFL 3 -#define F_SETFL 4 -#define F_GETOWN 5 -#define F_SETOWN 6 -#define F_GETLK 7 -#define F_SETLK 8 -#define F_SETLKW 9 +#define F_DUPFD 0 +#define F_GETFD 1 +#define F_SETFD 2 +#define F_GETFL 3 +#define F_SETFL 4 +#define F_GETOWN 5 +#define F_SETOWN 6 +#define F_GETLK 7 +#define F_SETLK 8 +#define F_SETLKW 9 extern int open(const char *path, int oflag, ...); extern int fcntl(int fd, int flag, ...); #endif /* __SYS_FCNTL_H__ */ - diff --git a/components/libc/include/armlibc/sys/ioctl.h b/components/libc/include/armlibc/sys/ioctl.h index 44b63384..f0796b32 100644 --- a/components/libc/include/armlibc/sys/ioctl.h +++ b/components/libc/include/armlibc/sys/ioctl.h @@ -23,104 +23,104 @@ #ifndef __SYS_IOCTL_H__ #define __SYS_IOCTL_H__ -#define _IOC(a,b,c,d) (((a)<<30) | ((b)<<8) | (c) | ((d)<<16)) -#define _IOC_NONE 0U -#define _IOC_WRITE 1U -#define _IOC_READ 2U +#define _IOC(a, b, c, d) (((a) << 30) | ((b) << 8) | (c) | ((d) << 16)) +#define _IOC_NONE 0U +#define _IOC_WRITE 1U +#define _IOC_READ 2U #ifndef _WIN32 -#define _IO(a,b) _IOC(_IOC_NONE, (a), (b), 0) -#define _IOW(a,b,c) _IOC(_IOC_WRITE, (a), (b), sizeof(c)) -#define _IOR(a,b,c) _IOC(_IOC_READ, (a), (b), sizeof(c)) -#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE, (a), (b), sizeof(c)) - -#define FIONREAD _IOR('f', 127, int) /* Get # bytes to read. */ -#define FIONBIO _IOW('f', 126, int) /* Set/clear non-blocking i/o. */ -#define FIONWRITE _IOR('f', 121, int) /* Get # bytes outstanding in send queue. */ +#define _IO(a, b) _IOC(_IOC_NONE, (a), (b), 0) +#define _IOW(a, b, c) _IOC(_IOC_WRITE, (a), (b), sizeof(c)) +#define _IOR(a, b, c) _IOC(_IOC_READ, (a), (b), sizeof(c)) +#define _IOWR(a, b, c) _IOC(_IOC_READ | _IOC_WRITE, (a), (b), sizeof(c)) + +#define FIONREAD _IOR('f', 127, int) /* Get # bytes to read. */ +#define FIONBIO _IOW('f', 126, int) /* Set/clear non-blocking i/o. */ +#define FIONWRITE _IOR('f', 121, int) /* Get # bytes outstanding in send queue. */ #endif -#define TCGETS 0x5401 -#define TCSETS 0x5402 -#define TCSETSW 0x5403 -#define TCSETSF 0x5404 -#define TCGETA 0x5405 -#define TCSETA 0x5406 -#define TCSETAW 0x5407 -#define TCSETAF 0x5408 -#define TCSBRK 0x5409 -#define TCXONC 0x540A -#define TCFLSH 0x540B -#define TIOCEXCL 0x540C -#define TIOCNXCL 0x540D -#define TIOCSCTTY 0x540E -#define TIOCGPGRP 0x540F -#define TIOCSPGRP 0x5410 -#define TIOCOUTQ 0x5411 -#define TIOCSTI 0x5412 -#define TIOCGWINSZ 0x5413 -#define TIOCSWINSZ 0x5414 -#define TIOCMGET 0x5415 -#define TIOCMBIS 0x5416 -#define TIOCMBIC 0x5417 -#define TIOCMSET 0x5418 -#define TIOCGSOFTCAR 0x5419 -#define TIOCSSOFTCAR 0x541A -#define TIOCINQ FIONREAD -#define TIOCLINUX 0x541C -#define TIOCCONS 0x541D -#define TIOCGSERIAL 0x541E -#define TIOCSSERIAL 0x541F -#define TIOCPKT 0x5420 -#define TIOCNOTTY 0x5422 -#define TIOCSETD 0x5423 -#define TIOCGETD 0x5424 -#define TCSBRKP 0x5425 -#define TIOCSBRK 0x5427 -#define TIOCCBRK 0x5428 -#define TIOCGSID 0x5429 -#define TIOCGRS485 0x542E -#define TIOCSRS485 0x542F -#define TIOCGPTN 0x80045430 -#define TIOCSPTLCK 0x40045431 -#define TIOCGDEV 0x80045432 -#define TCGETX 0x5432 -#define TCSETX 0x5433 -#define TCSETXF 0x5434 -#define TCSETXW 0x5435 -#define TIOCSIG 0x40045436 -#define TIOCVHANGUP 0x5437 -#define TIOCGPKT 0x80045438 -#define TIOCGPTLCK 0x80045439 -#define TIOCGEXCL 0x80045440 - -#define FIONCLEX 0x5450 -#define FIOCLEX 0x5451 -#define FIOASYNC 0x5452 - -#define TIOCSERCONFIG 0x5453 -#define TIOCSERGWILD 0x5454 -#define TIOCSERSWILD 0x5455 -#define TIOCGLCKTRMIOS 0x5456 -#define TIOCSLCKTRMIOS 0x5457 -#define TIOCSERGSTRUCT 0x5458 -#define TIOCSERGETLSR 0x5459 -#define TIOCSERGETMULTI 0x545A -#define TIOCSERSETMULTI 0x545B - -#define TIOCMIWAIT 0x545C -#define TIOCGICOUNT 0x545D -#define FIOQSIZE 0x5460 - -#define TIOCPKT_DATA 0 -#define TIOCPKT_FLUSHREAD 1 -#define TIOCPKT_FLUSHWRITE 2 -#define TIOCPKT_STOP 4 -#define TIOCPKT_START 8 -#define TIOCPKT_NOSTOP 16 -#define TIOCPKT_DOSTOP 32 -#define TIOCPKT_IOCTL 64 - -#define TIOCSER_TEMT 0x01 +#define TCGETS 0x5401 +#define TCSETS 0x5402 +#define TCSETSW 0x5403 +#define TCSETSF 0x5404 +#define TCGETA 0x5405 +#define TCSETA 0x5406 +#define TCSETAW 0x5407 +#define TCSETAF 0x5408 +#define TCSBRK 0x5409 +#define TCXONC 0x540A +#define TCFLSH 0x540B +#define TIOCEXCL 0x540C +#define TIOCNXCL 0x540D +#define TIOCSCTTY 0x540E +#define TIOCGPGRP 0x540F +#define TIOCSPGRP 0x5410 +#define TIOCOUTQ 0x5411 +#define TIOCSTI 0x5412 +#define TIOCGWINSZ 0x5413 +#define TIOCSWINSZ 0x5414 +#define TIOCMGET 0x5415 +#define TIOCMBIS 0x5416 +#define TIOCMBIC 0x5417 +#define TIOCMSET 0x5418 +#define TIOCGSOFTCAR 0x5419 +#define TIOCSSOFTCAR 0x541A +#define TIOCINQ FIONREAD +#define TIOCLINUX 0x541C +#define TIOCCONS 0x541D +#define TIOCGSERIAL 0x541E +#define TIOCSSERIAL 0x541F +#define TIOCPKT 0x5420 +#define TIOCNOTTY 0x5422 +#define TIOCSETD 0x5423 +#define TIOCGETD 0x5424 +#define TCSBRKP 0x5425 +#define TIOCSBRK 0x5427 +#define TIOCCBRK 0x5428 +#define TIOCGSID 0x5429 +#define TIOCGRS485 0x542E +#define TIOCSRS485 0x542F +#define TIOCGPTN 0x80045430 +#define TIOCSPTLCK 0x40045431 +#define TIOCGDEV 0x80045432 +#define TCGETX 0x5432 +#define TCSETX 0x5433 +#define TCSETXF 0x5434 +#define TCSETXW 0x5435 +#define TIOCSIG 0x40045436 +#define TIOCVHANGUP 0x5437 +#define TIOCGPKT 0x80045438 +#define TIOCGPTLCK 0x80045439 +#define TIOCGEXCL 0x80045440 + +#define FIONCLEX 0x5450 +#define FIOCLEX 0x5451 +#define FIOASYNC 0x5452 + +#define TIOCSERCONFIG 0x5453 +#define TIOCSERGWILD 0x5454 +#define TIOCSERSWILD 0x5455 +#define TIOCGLCKTRMIOS 0x5456 +#define TIOCSLCKTRMIOS 0x5457 +#define TIOCSERGSTRUCT 0x5458 +#define TIOCSERGETLSR 0x5459 +#define TIOCSERGETMULTI 0x545A +#define TIOCSERSETMULTI 0x545B + +#define TIOCMIWAIT 0x545C +#define TIOCGICOUNT 0x545D +#define FIOQSIZE 0x5460 + +#define TIOCPKT_DATA 0 +#define TIOCPKT_FLUSHREAD 1 +#define TIOCPKT_FLUSHWRITE 2 +#define TIOCPKT_STOP 4 +#define TIOCPKT_START 8 +#define TIOCPKT_NOSTOP 16 +#define TIOCPKT_DOSTOP 32 +#define TIOCPKT_IOCTL 64 + +#define TIOCSER_TEMT 0x01 struct winsize { @@ -130,109 +130,108 @@ struct winsize unsigned short ws_ypixel; }; -#define TIOCM_LE 0x001 -#define TIOCM_DTR 0x002 -#define TIOCM_RTS 0x004 -#define TIOCM_ST 0x008 -#define TIOCM_SR 0x010 -#define TIOCM_CTS 0x020 -#define TIOCM_CAR 0x040 -#define TIOCM_RNG 0x080 -#define TIOCM_DSR 0x100 -#define TIOCM_CD TIOCM_CAR -#define TIOCM_RI TIOCM_RNG -#define TIOCM_OUT1 0x2000 -#define TIOCM_OUT2 0x4000 -#define TIOCM_LOOP 0x8000 - -#define N_TTY 0 -#define N_SLIP 1 -#define N_MOUSE 2 -#define N_PPP 3 -#define N_STRIP 4 -#define N_AX25 5 -#define N_X25 6 -#define N_6PACK 7 -#define N_MASC 8 -#define N_R3964 9 -#define N_PROFIBUS_FDL 10 -#define N_IRDA 11 -#define N_SMSBLOCK 12 -#define N_HDLC 13 -#define N_SYNC_PPP 14 -#define N_HCI 15 - -#define FIOSETOWN 0x8901 -#define SIOCSPGRP 0x8902 -#define FIOGETOWN 0x8903 -#define SIOCGPGRP 0x8904 -#define SIOCGSTAMP 0x8906 -#define SIOCGSTAMPNS 0x8907 - -#define SIOCADDRT 0x890B -#define SIOCDELRT 0x890C -#define SIOCRTMSG 0x890D - -#define SIOCGIFNAME 0x8910 -#define SIOCSIFLINK 0x8911 -#define SIOCGIFCONF 0x8912 -#define SIOCGIFFLAGS 0x8913 -#define SIOCSIFFLAGS 0x8914 -#define SIOCGIFADDR 0x8915 -#define SIOCSIFADDR 0x8916 -#define SIOCGIFDSTADDR 0x8917 -#define SIOCSIFDSTADDR 0x8918 -#define SIOCGIFBRDADDR 0x8919 -#define SIOCSIFBRDADDR 0x891a -#define SIOCGIFNETMASK 0x891b -#define SIOCSIFNETMASK 0x891c -#define SIOCGIFMETRIC 0x891d -#define SIOCSIFMETRIC 0x891e -#define SIOCGIFMEM 0x891f -#define SIOCSIFMEM 0x8920 -#define SIOCGIFMTU 0x8921 -#define SIOCSIFMTU 0x8922 -#define SIOCSIFNAME 0x8923 -#define SIOCSIFHWADDR 0x8924 -#define SIOCGIFENCAP 0x8925 -#define SIOCSIFENCAP 0x8926 -#define SIOCGIFHWADDR 0x8927 -#define SIOCGIFSLAVE 0x8929 -#define SIOCSIFSLAVE 0x8930 -#define SIOCADDMULTI 0x8931 -#define SIOCDELMULTI 0x8932 -#define SIOCGIFINDEX 0x8933 -#define SIOGIFINDEX SIOCGIFINDEX -#define SIOCSIFPFLAGS 0x8934 -#define SIOCGIFPFLAGS 0x8935 -#define SIOCDIFADDR 0x8936 -#define SIOCSIFHWBROADCAST 0x8937 -#define SIOCGIFCOUNT 0x8938 - -#define SIOCGIFBR 0x8940 -#define SIOCSIFBR 0x8941 - -#define SIOCGIFTXQLEN 0x8942 -#define SIOCSIFTXQLEN 0x8943 - -#define SIOCDARP 0x8953 -#define SIOCGARP 0x8954 -#define SIOCSARP 0x8955 - -#define SIOCDRARP 0x8960 -#define SIOCGRARP 0x8961 -#define SIOCSRARP 0x8962 - -#define SIOCGIFMAP 0x8970 -#define SIOCSIFMAP 0x8971 - -#define SIOCADDDLCI 0x8980 -#define SIOCDELDLCI 0x8981 - -#define SIOCDEVPRIVATE 0x89F0 -#define SIOCPROTOPRIVATE 0x89E0 +#define TIOCM_LE 0x001 +#define TIOCM_DTR 0x002 +#define TIOCM_RTS 0x004 +#define TIOCM_ST 0x008 +#define TIOCM_SR 0x010 +#define TIOCM_CTS 0x020 +#define TIOCM_CAR 0x040 +#define TIOCM_RNG 0x080 +#define TIOCM_DSR 0x100 +#define TIOCM_CD TIOCM_CAR +#define TIOCM_RI TIOCM_RNG +#define TIOCM_OUT1 0x2000 +#define TIOCM_OUT2 0x4000 +#define TIOCM_LOOP 0x8000 + +#define N_TTY 0 +#define N_SLIP 1 +#define N_MOUSE 2 +#define N_PPP 3 +#define N_STRIP 4 +#define N_AX25 5 +#define N_X25 6 +#define N_6PACK 7 +#define N_MASC 8 +#define N_R3964 9 +#define N_PROFIBUS_FDL 10 +#define N_IRDA 11 +#define N_SMSBLOCK 12 +#define N_HDLC 13 +#define N_SYNC_PPP 14 +#define N_HCI 15 + +#define FIOSETOWN 0x8901 +#define SIOCSPGRP 0x8902 +#define FIOGETOWN 0x8903 +#define SIOCGPGRP 0x8904 +#define SIOCGSTAMP 0x8906 +#define SIOCGSTAMPNS 0x8907 + +#define SIOCADDRT 0x890B +#define SIOCDELRT 0x890C +#define SIOCRTMSG 0x890D + +#define SIOCGIFNAME 0x8910 +#define SIOCSIFLINK 0x8911 +#define SIOCGIFCONF 0x8912 +#define SIOCGIFFLAGS 0x8913 +#define SIOCSIFFLAGS 0x8914 +#define SIOCGIFADDR 0x8915 +#define SIOCSIFADDR 0x8916 +#define SIOCGIFDSTADDR 0x8917 +#define SIOCSIFDSTADDR 0x8918 +#define SIOCGIFBRDADDR 0x8919 +#define SIOCSIFBRDADDR 0x891a +#define SIOCGIFNETMASK 0x891b +#define SIOCSIFNETMASK 0x891c +#define SIOCGIFMETRIC 0x891d +#define SIOCSIFMETRIC 0x891e +#define SIOCGIFMEM 0x891f +#define SIOCSIFMEM 0x8920 +#define SIOCGIFMTU 0x8921 +#define SIOCSIFMTU 0x8922 +#define SIOCSIFNAME 0x8923 +#define SIOCSIFHWADDR 0x8924 +#define SIOCGIFENCAP 0x8925 +#define SIOCSIFENCAP 0x8926 +#define SIOCGIFHWADDR 0x8927 +#define SIOCGIFSLAVE 0x8929 +#define SIOCSIFSLAVE 0x8930 +#define SIOCADDMULTI 0x8931 +#define SIOCDELMULTI 0x8932 +#define SIOCGIFINDEX 0x8933 +#define SIOGIFINDEX SIOCGIFINDEX +#define SIOCSIFPFLAGS 0x8934 +#define SIOCGIFPFLAGS 0x8935 +#define SIOCDIFADDR 0x8936 +#define SIOCSIFHWBROADCAST 0x8937 +#define SIOCGIFCOUNT 0x8938 + +#define SIOCGIFBR 0x8940 +#define SIOCSIFBR 0x8941 + +#define SIOCGIFTXQLEN 0x8942 +#define SIOCSIFTXQLEN 0x8943 + +#define SIOCDARP 0x8953 +#define SIOCGARP 0x8954 +#define SIOCSARP 0x8955 + +#define SIOCDRARP 0x8960 +#define SIOCGRARP 0x8961 +#define SIOCSRARP 0x8962 + +#define SIOCGIFMAP 0x8970 +#define SIOCSIFMAP 0x8971 + +#define SIOCADDDLCI 0x8980 +#define SIOCDELDLCI 0x8981 + +#define SIOCDEVPRIVATE 0x89F0 +#define SIOCPROTOPRIVATE 0x89E0 extern int ioctl(int fd, unsigned long request, ...); #endif /* __SYS_IOCTL_H__ */ - diff --git a/components/libc/include/armlibc/sys/poll.h b/components/libc/include/armlibc/sys/poll.h index 900168fd..232ae653 100644 --- a/components/libc/include/armlibc/sys/poll.h +++ b/components/libc/include/armlibc/sys/poll.h @@ -23,23 +23,23 @@ #ifndef __SYS_POLL_H__ #define __SYS_POLL_H__ -#define POLLIN 0x0001 -#define POLLPRI 0x0002 -#define POLLOUT 0x0004 -#define POLLERR 0x0008 -#define POLLHUP 0x0010 -#define POLLNVAL 0x0020 -#define POLLRDNORM 0x0040 -#define POLLRDBAND 0x0080 -#define POLLWRNORM 0x0100 -#define POLLWRBAND 0x0200 +#define POLLIN 0x0001 +#define POLLPRI 0x0002 +#define POLLOUT 0x0004 +#define POLLERR 0x0008 +#define POLLHUP 0x0010 +#define POLLNVAL 0x0020 +#define POLLRDNORM 0x0040 +#define POLLRDBAND 0x0080 +#define POLLWRNORM 0x0100 +#define POLLWRBAND 0x0200 struct pollfd { /* The Following three item member is must be include */ - int fd; /* The following descriptor being polled. */ - short events; /* The input event flags. */ - short revents; /* The output event flags. */ + int fd; /* The following descriptor being polled. */ + short events; /* The input event flags. */ + short revents; /* The output event flags. */ }; typedef unsigned int nfds_t; @@ -47,4 +47,3 @@ typedef unsigned int nfds_t; extern int poll(struct pollfd fds[], nfds_t nfds, int timeout); #endif /* __SYS_POLL_H__ */ - diff --git a/components/libc/include/armlibc/sys/select.h b/components/libc/include/armlibc/sys/select.h index 6f5a2f2c..8a9a673d 100644 --- a/components/libc/include/armlibc/sys/select.h +++ b/components/libc/include/armlibc/sys/select.h @@ -6,33 +6,33 @@ #include #if !defined(PRESET_FD_SETSIZE) -#define FD_SETSIZE 64 /* default set FD_SETSIZE */ +#define FD_SETSIZE 64 /* default set FD_SETSIZE */ #else -#define FD_SETSIZE PRESET_FD_SETSIZE +#define FD_SETSIZE PRESET_FD_SETSIZE #endif -#define NBBY 8 /* number of bits in a byte */ +#define NBBY 8 /* number of bits in a byte */ -typedef unsigned long fd_mask; -#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */ +typedef unsigned long fd_mask; +#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */ #ifndef howmany -#define howmany(x,y) (((x)+((y)-1))/(y)) +#define howmany(x, y) (((x) + ((y)-1)) / (y)) #endif /* We use a macro for fd_set so that including Sockets.h afterwards can work. */ -typedef struct _types_fd_set { - fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; +typedef struct _types_fd_set +{ + fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; } _types_fd_set; -#define fd_set _types_fd_set +#define fd_set _types_fd_set -#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS))) -#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS))) -#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS))) -#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) +#define FD_SET(n, p) ((p)->fds_bits[(n) / NFDBITS] |= (1L << ((n) % NFDBITS))) +#define FD_CLR(n, p) ((p)->fds_bits[(n) / NFDBITS] &= ~(1L << ((n) % NFDBITS))) +#define FD_ISSET(n, p) ((p)->fds_bits[(n) / NFDBITS] & (1L << ((n) % NFDBITS))) +#define FD_ZERO(p) memset((void *)(p), 0, sizeof(*(p))) extern int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); #endif /* _SYS_SELECT_H__ */ - diff --git a/components/libc/include/armlibc/sys/stat.h b/components/libc/include/armlibc/sys/stat.h index 5fde3199..d5e33512 100644 --- a/components/libc/include/armlibc/sys/stat.h +++ b/components/libc/include/armlibc/sys/stat.h @@ -27,60 +27,60 @@ #include #include -#define S_IFMT 00170000 -#define S_IFSOCK 0140000 -#define S_IFLNK 0120000 -#define S_IFREG 0100000 -#define S_IFBLK 0060000 -#define S_IFDIR 0040000 -#define S_IFCHR 0020000 -#define S_IFIFO 0010000 -#define S_ISUID 0004000 -#define S_ISGID 0002000 -#define S_ISVTX 0001000 +#define S_IFMT 00170000 +#define S_IFSOCK 0140000 +#define S_IFLNK 0120000 +#define S_IFREG 0100000 +#define S_IFBLK 0060000 +#define S_IFDIR 0040000 +#define S_IFCHR 0020000 +#define S_IFIFO 0010000 +#define S_ISUID 0004000 +#define S_ISGID 0002000 +#define S_ISVTX 0001000 -#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) -#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) -#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) -#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) -#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) +#define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK) +#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) +#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) +#define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR) +#define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK) +#define S_ISFIFO(m) (((m)&S_IFMT) == S_IFIFO) +#define S_ISSOCK(m) (((m)&S_IFMT) == S_IFSOCK) -#define S_IRWXU 00700 -#define S_IRUSR 00400 -#define S_IWUSR 00200 -#define S_IXUSR 00100 +#define S_IRWXU 00700 +#define S_IRUSR 00400 +#define S_IWUSR 00200 +#define S_IXUSR 00100 -#define S_IRWXG 00070 -#define S_IRGRP 00040 -#define S_IWGRP 00020 -#define S_IXGRP 00010 +#define S_IRWXG 00070 +#define S_IRGRP 00040 +#define S_IWGRP 00020 +#define S_IXGRP 00010 -#define S_IRWXO 00007 -#define S_IROTH 00004 -#define S_IWOTH 00002 -#define S_IXOTH 00001 +#define S_IRWXO 00007 +#define S_IROTH 00004 +#define S_IWOTH 00002 +#define S_IXOTH 00001 struct stat { - dev_t st_dev; - ino_t st_ino; - mode_t st_mode; - nlink_t st_nlink; - uid_t st_uid; - gid_t st_gid; - dev_t st_rdev; - off_t st_size; - time_t st_atime; - long st_spare1; - time_t st_mtime; - long st_spare2; - time_t st_ctime; - long st_spare3; + dev_t st_dev; + ino_t st_ino; + mode_t st_mode; + nlink_t st_nlink; + uid_t st_uid; + gid_t st_gid; + dev_t st_rdev; + off_t st_size; + time_t st_atime; + long st_spare1; + time_t st_mtime; + long st_spare2; + time_t st_ctime; + long st_spare3; blksize_t st_blksize; - blkcnt_t st_blocks; - long st_spare4[2]; + blkcnt_t st_blocks; + long st_spare4[2]; }; extern int mkdir(const char *path, mode_t mode); @@ -88,4 +88,3 @@ extern int stat(const char *path, struct stat *sbuf); extern int fstat(int fd, struct stat *sbuf); #endif /* __SYS_STAT_H__ */ - diff --git a/components/libc/include/armlibc/sys/statfs.h b/components/libc/include/armlibc/sys/statfs.h index b35674ad..9deb65e6 100644 --- a/components/libc/include/armlibc/sys/statfs.h +++ b/components/libc/include/armlibc/sys/statfs.h @@ -25,12 +25,11 @@ struct statfs { - unsigned long f_bsize; /* Block size. */ - unsigned long f_blocks; /* Total data blocks in file system. */ - unsigned long f_bfree; /* Free blocks in file system. */ + unsigned long f_bsize; /* Block size. */ + unsigned long f_blocks; /* Total data blocks in file system. */ + unsigned long f_bfree; /* Free blocks in file system. */ }; -extern int statfs (const char *path, struct statfs *buf); +extern int statfs(const char *path, struct statfs *buf); #endif /* __SYS_STATFS_H__ */ - diff --git a/components/libc/include/armlibc/sys/time.h b/components/libc/include/armlibc/sys/time.h index 4ea7e7b9..8af60452 100644 --- a/components/libc/include/armlibc/sys/time.h +++ b/components/libc/include/armlibc/sys/time.h @@ -36,8 +36,8 @@ extern "C" { /* Structure returned by gettimeofday(2) system call, and used in other calls. */ struct timeval { - long tv_sec; /* Seconds. */ - long tv_usec; /* Microseconds. */ + long tv_sec; /* Seconds. */ + long tv_usec; /* Microseconds. */ }; #endif /* _TIMEVAL_DEFINED */ @@ -47,10 +47,10 @@ struct timeval /* Structure defined by POSIX.1b to be like a timeval. */ struct timespec { - time_t tv_sec; /* Seconds. */ - long tv_nsec; /* Nanoseconds. */ + time_t tv_sec; /* Seconds. */ + long tv_nsec; /* Nanoseconds. */ }; -#endif /* _TIMESPEC_DEFINED */ +#endif /* _TIMESPEC_DEFINED */ struct timezone { @@ -58,7 +58,7 @@ struct timezone int tz_dsttime; /* Type of dst correction. */ }; -extern int gettimeofday(struct timeval *tp, void *ignore); +extern int gettimeofday(struct timeval *tp, void *ignore); extern struct tm *gmtime_r(const time_t *timep, struct tm *r); #ifdef __cplusplus @@ -66,4 +66,3 @@ extern struct tm *gmtime_r(const time_t *timep, struct tm *r); #endif #endif /* __SYS_TIME_H__ */ - diff --git a/components/libc/include/armlibc/sys/types.h b/components/libc/include/armlibc/sys/types.h index 07ecb75e..e756f862 100644 --- a/components/libc/include/armlibc/sys/types.h +++ b/components/libc/include/armlibc/sys/types.h @@ -25,20 +25,19 @@ #include -typedef signed int clockid_t; -typedef signed int key_t; /* Used for interprocess communication. */ -typedef signed int pid_t; /* Used for process IDs and process group IDs. */ -typedef signed long ssize_t; /* Used for a count of bytes or an error indication. */ -typedef long off_t; -typedef int mode_t; -typedef unsigned int ino_t; -typedef unsigned int size_t; -typedef unsigned long dev_t; +typedef signed int clockid_t; +typedef signed int key_t; /* Used for interprocess communication. */ +typedef signed int pid_t; /* Used for process IDs and process group IDs. */ +typedef signed long ssize_t; /* Used for a count of bytes or an error indication. */ +typedef long off_t; +typedef int mode_t; +typedef unsigned int ino_t; +typedef unsigned int size_t; +typedef unsigned long dev_t; typedef unsigned short nlink_t; typedef unsigned short uid_t; typedef unsigned short gid_t; -typedef long blksize_t; -typedef long blkcnt_t; +typedef long blksize_t; +typedef long blkcnt_t; #endif /* __SYS_TYPES_H__ */ - diff --git a/components/libc/include/armlibc/sys/unistd.h b/components/libc/include/armlibc/sys/unistd.h index 938dd05a..7b7763fd 100644 --- a/components/libc/include/armlibc/sys/unistd.h +++ b/components/libc/include/armlibc/sys/unistd.h @@ -25,16 +25,15 @@ #include -extern int chdir(const char *path); +extern int chdir(const char *path); extern char *getcwd(char *buf, size_t size); -extern int read(int fd, void *buf, size_t nbyte); -extern int close(int fildes); -extern int write(int fd, const void *buf, size_t nbyte); -extern int unlink(const char *path); +extern int read(int fd, void *buf, size_t nbyte); +extern int close(int fildes); +extern int write(int fd, const void *buf, size_t nbyte); +extern int unlink(const char *path); extern off_t lseek(int fildes, off_t offset, int whence); -extern int fsync(int fd); -extern int access(const char *pathname, int mode); -extern int rmdir(const char *pathname); +extern int fsync(int fd); +extern int access(const char *pathname, int mode); +extern int rmdir(const char *pathname); #endif /* __SYS_UNISTD_H__ */ - diff --git a/components/libc/include/armlibc/sys/vfs.h b/components/libc/include/armlibc/sys/vfs.h index 5a17568c..67b34c2a 100644 --- a/components/libc/include/armlibc/sys/vfs.h +++ b/components/libc/include/armlibc/sys/vfs.h @@ -26,4 +26,3 @@ #include #endif /* __SYS_VFS_H__ */ - diff --git a/components/libc/include/armlibc/unistd.h b/components/libc/include/armlibc/unistd.h index d84fd86e..ac55c189 100644 --- a/components/libc/include/armlibc/unistd.h +++ b/components/libc/include/armlibc/unistd.h @@ -26,4 +26,3 @@ #include "sys/unistd.h" #endif /* __UNISTD_H__ */ - diff --git a/components/libc/include/extension/errno_ext.h b/components/libc/include/extension/errno_ext.h index 96cdda20..82a9019a 100644 --- a/components/libc/include/extension/errno_ext.h +++ b/components/libc/include/extension/errno_ext.h @@ -28,109 +28,109 @@ #if defined(__CC_ARM) || defined(__CLANG_ARM) -#define ERROR_BASE_NO 7 // Armcc already define 1~6, refer to include/errno.h under armcc toolchain path - -#define EPERM (ERROR_BASE_NO + 1) -#define ENOENT (ERROR_BASE_NO + 2) -#define ESRCH (ERROR_BASE_NO + 3) -#define EINTR (ERROR_BASE_NO + 4) -#define EIO (ERROR_BASE_NO + 5) -#define ENXIO (ERROR_BASE_NO + 6) -#define E2BIG (ERROR_BASE_NO + 7) -#define ENOEXEC (ERROR_BASE_NO + 8) -#define EBADF (ERROR_BASE_NO + 9) -#define ECHILD (ERROR_BASE_NO + 10) -#define EAGAIN (ERROR_BASE_NO + 11) +#define ERROR_BASE_NO 7 // Armcc already define 1~6, refer to include/errno.h under armcc toolchain path + +#define EPERM (ERROR_BASE_NO + 1) +#define ENOENT (ERROR_BASE_NO + 2) +#define ESRCH (ERROR_BASE_NO + 3) +#define EINTR (ERROR_BASE_NO + 4) +#define EIO (ERROR_BASE_NO + 5) +#define ENXIO (ERROR_BASE_NO + 6) +#define E2BIG (ERROR_BASE_NO + 7) +#define ENOEXEC (ERROR_BASE_NO + 8) +#define EBADF (ERROR_BASE_NO + 9) +#define ECHILD (ERROR_BASE_NO + 10) +#define EAGAIN (ERROR_BASE_NO + 11) #ifndef ENOMEM -#define ENOMEM (ERROR_BASE_NO + 12) +#define ENOMEM (ERROR_BASE_NO + 12) #endif -#define EACCES (ERROR_BASE_NO + 13) -#define EFAULT (ERROR_BASE_NO + 14) -#define ENOTBLK (ERROR_BASE_NO + 15) -#define EBUSY (ERROR_BASE_NO + 16) -#define EEXIST (ERROR_BASE_NO + 17) -#define EXDEV (ERROR_BASE_NO + 18) -#define ENODEV (ERROR_BASE_NO + 19) -#define ENOTDIR (ERROR_BASE_NO + 20) -#define EISDIR (ERROR_BASE_NO + 21) +#define EACCES (ERROR_BASE_NO + 13) +#define EFAULT (ERROR_BASE_NO + 14) +#define ENOTBLK (ERROR_BASE_NO + 15) +#define EBUSY (ERROR_BASE_NO + 16) +#define EEXIST (ERROR_BASE_NO + 17) +#define EXDEV (ERROR_BASE_NO + 18) +#define ENODEV (ERROR_BASE_NO + 19) +#define ENOTDIR (ERROR_BASE_NO + 20) +#define EISDIR (ERROR_BASE_NO + 21) #ifndef EINVAL -#define EINVAL (ERROR_BASE_NO + 22) +#define EINVAL (ERROR_BASE_NO + 22) #endif -#define ENFILE (ERROR_BASE_NO + 23) -#define EMFILE (ERROR_BASE_NO + 24) -#define ENOTTY (ERROR_BASE_NO + 25) -#define ETXTBSY (ERROR_BASE_NO + 26) -#define EFBIG (ERROR_BASE_NO + 27) -#define ENOSPC (ERROR_BASE_NO + 28) -#define ESPIPE (ERROR_BASE_NO + 29) -#define EROFS (ERROR_BASE_NO + 30) -#define EMLINK (ERROR_BASE_NO + 31) -#define EPIPE (ERROR_BASE_NO + 32) +#define ENFILE (ERROR_BASE_NO + 23) +#define EMFILE (ERROR_BASE_NO + 24) +#define ENOTTY (ERROR_BASE_NO + 25) +#define ETXTBSY (ERROR_BASE_NO + 26) +#define EFBIG (ERROR_BASE_NO + 27) +#define ENOSPC (ERROR_BASE_NO + 28) +#define ESPIPE (ERROR_BASE_NO + 29) +#define EROFS (ERROR_BASE_NO + 30) +#define EMLINK (ERROR_BASE_NO + 31) +#define EPIPE (ERROR_BASE_NO + 32) #ifndef EDOM -#define EDOM (ERROR_BASE_NO + 33) +#define EDOM (ERROR_BASE_NO + 33) #endif #ifndef ERANGE -#define ERANGE (ERROR_BASE_NO + 34) +#define ERANGE (ERROR_BASE_NO + 34) #endif -#define EDEADLK (ERROR_BASE_NO + 35) -#define ENAMETOOLONG (ERROR_BASE_NO + 36) -#define ENOLCK (ERROR_BASE_NO + 37) -#define ENOSYS (ERROR_BASE_NO + 38) -#define ENOTEMPTY (ERROR_BASE_NO + 39) -#define ELOOP (ERROR_BASE_NO + 40) -#define EWOULDBLOCK EAGAIN -#define ENOMSG (ERROR_BASE_NO + 42) -#define EIDRM (ERROR_BASE_NO + 43) -#define ECHRNG (ERROR_BASE_NO + 44) -#define EL2NSYNC (ERROR_BASE_NO + 45) -#define EL3HLT (ERROR_BASE_NO + 46) -#define EL3RST (ERROR_BASE_NO + 47) -#define ELNRNG (ERROR_BASE_NO + 48) -#define EUNATCH (ERROR_BASE_NO + 49) -#define ENOCSI (ERROR_BASE_NO + 50) -#define EL2HLT (ERROR_BASE_NO + 51) -#define EBADE (ERROR_BASE_NO + 52) -#define EBADR (ERROR_BASE_NO + 53) -#define EXFULL (ERROR_BASE_NO + 54) -#define ENOANO (ERROR_BASE_NO + 55) -#define EBADRQC (ERROR_BASE_NO + 56) -#define EBADSLT (ERROR_BASE_NO + 57) -#define EDEADLOCK EDEADLK -#define EBFONT (ERROR_BASE_NO + 59) -#define ENOSTR (ERROR_BASE_NO + 60) -#define ENODATA (ERROR_BASE_NO + 61) -#define ETIME (ERROR_BASE_NO + 62) -#define ENOSR (ERROR_BASE_NO + 63) -#define ENONET (ERROR_BASE_NO + 64) -#define ENOPKG (ERROR_BASE_NO + 65) -#define EREMOTE (ERROR_BASE_NO + 66) -#define ENOLINK (ERROR_BASE_NO + 67) -#define EADV (ERROR_BASE_NO + 68) -#define ESRMNT (ERROR_BASE_NO + 69) -#define ECOMM (ERROR_BASE_NO + 70) -#define EPROTO (ERROR_BASE_NO + 71) -#define EMULTIHOP (ERROR_BASE_NO + 72) -#define EDOTDOT (ERROR_BASE_NO + 73) -#define EBADMSG (ERROR_BASE_NO + 74) -#define EOVERFLOW (ERROR_BASE_NO + 75) -#define ENOTUNIQ (ERROR_BASE_NO + 76) -#define EBADFD (ERROR_BASE_NO + 77) -#define EREMCHG (ERROR_BASE_NO + 78) -#define ELIBACC (ERROR_BASE_NO + 79) -#define ELIBBAD (ERROR_BASE_NO + 80) -#define ELIBSCN (ERROR_BASE_NO + 81) -#define ELIBMAX (ERROR_BASE_NO + 82) -#define ELIBEXEC (ERROR_BASE_NO + 83) +#define EDEADLK (ERROR_BASE_NO + 35) +#define ENAMETOOLONG (ERROR_BASE_NO + 36) +#define ENOLCK (ERROR_BASE_NO + 37) +#define ENOSYS (ERROR_BASE_NO + 38) +#define ENOTEMPTY (ERROR_BASE_NO + 39) +#define ELOOP (ERROR_BASE_NO + 40) +#define EWOULDBLOCK EAGAIN +#define ENOMSG (ERROR_BASE_NO + 42) +#define EIDRM (ERROR_BASE_NO + 43) +#define ECHRNG (ERROR_BASE_NO + 44) +#define EL2NSYNC (ERROR_BASE_NO + 45) +#define EL3HLT (ERROR_BASE_NO + 46) +#define EL3RST (ERROR_BASE_NO + 47) +#define ELNRNG (ERROR_BASE_NO + 48) +#define EUNATCH (ERROR_BASE_NO + 49) +#define ENOCSI (ERROR_BASE_NO + 50) +#define EL2HLT (ERROR_BASE_NO + 51) +#define EBADE (ERROR_BASE_NO + 52) +#define EBADR (ERROR_BASE_NO + 53) +#define EXFULL (ERROR_BASE_NO + 54) +#define ENOANO (ERROR_BASE_NO + 55) +#define EBADRQC (ERROR_BASE_NO + 56) +#define EBADSLT (ERROR_BASE_NO + 57) +#define EDEADLOCK EDEADLK +#define EBFONT (ERROR_BASE_NO + 59) +#define ENOSTR (ERROR_BASE_NO + 60) +#define ENODATA (ERROR_BASE_NO + 61) +#define ETIME (ERROR_BASE_NO + 62) +#define ENOSR (ERROR_BASE_NO + 63) +#define ENONET (ERROR_BASE_NO + 64) +#define ENOPKG (ERROR_BASE_NO + 65) +#define EREMOTE (ERROR_BASE_NO + 66) +#define ENOLINK (ERROR_BASE_NO + 67) +#define EADV (ERROR_BASE_NO + 68) +#define ESRMNT (ERROR_BASE_NO + 69) +#define ECOMM (ERROR_BASE_NO + 70) +#define EPROTO (ERROR_BASE_NO + 71) +#define EMULTIHOP (ERROR_BASE_NO + 72) +#define EDOTDOT (ERROR_BASE_NO + 73) +#define EBADMSG (ERROR_BASE_NO + 74) +#define EOVERFLOW (ERROR_BASE_NO + 75) +#define ENOTUNIQ (ERROR_BASE_NO + 76) +#define EBADFD (ERROR_BASE_NO + 77) +#define EREMCHG (ERROR_BASE_NO + 78) +#define ELIBACC (ERROR_BASE_NO + 79) +#define ELIBBAD (ERROR_BASE_NO + 80) +#define ELIBSCN (ERROR_BASE_NO + 81) +#define ELIBMAX (ERROR_BASE_NO + 82) +#define ELIBEXEC (ERROR_BASE_NO + 83) #ifndef EILSEQ -#define EILSEQ (ERROR_BASE_NO + 84) +#define EILSEQ (ERROR_BASE_NO + 84) #endif #define ERESTART (ERROR_BASE_NO + 85) @@ -144,7 +144,7 @@ #define EPROTONOSUPPORT (ERROR_BASE_NO + 93) #define ESOCKTNOSUPPORT (ERROR_BASE_NO + 94) #define EOPNOTSUPP (ERROR_BASE_NO + 95) -#define ENOTSUP EOPNOTSUPP +#define ENOTSUP EOPNOTSUPP #define EPFNOSUPPORT (ERROR_BASE_NO + 96) #define EAFNOSUPPORT (ERROR_BASE_NO + 97) #define EADDRINUSE (ERROR_BASE_NO + 98) @@ -187,4 +187,3 @@ #endif /* defined(__CC_ARM) || defined(__CLANG_ARM) */ #endif /* __LIBC_ERRNO_H__ */ - diff --git a/components/libc/include/extension/fcntl_ext.h b/components/libc/include/extension/fcntl_ext.h index 2f9d2c40..9cb12672 100644 --- a/components/libc/include/extension/fcntl_ext.h +++ b/components/libc/include/extension/fcntl_ext.h @@ -30,30 +30,29 @@ #include #ifndef O_NONBLOCK -#define O_NONBLOCK 0x4000 +#define O_NONBLOCK 0x4000 #endif #ifndef F_GETFL -#define F_GETFL 3 +#define F_GETFL 3 #endif #ifndef F_SETFL -#define F_SETFL 4 +#define F_SETFL 4 #endif #ifndef O_DIRECTORY -#define O_DIRECTORY 0x200000 +#define O_DIRECTORY 0x200000 #endif #ifndef O_BINARY -#ifdef _O_BINARY -#define O_BINARY _O_BINARY +#ifdef _O_BINARY +#define O_BINARY _O_BINARY #else -#define O_BINARY 0 +#define O_BINARY 0 #endif #endif /* Not define _BINARY */ #endif /* defined(__GNUC__) && defined(OS_USING_NEWLIB_ADAPTER) */ #endif /* __LIBC_FCNTL_H__ */ - diff --git a/components/libc/include/extension/signal_ext.h b/components/libc/include/extension/signal_ext.h index 9b9535b7..72b6ee6a 100644 --- a/components/libc/include/extension/signal_ext.h +++ b/components/libc/include/extension/signal_ext.h @@ -35,54 +35,54 @@ extern "C" { * NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and * sigev_notify_attributes to the sigevent structure. */ -union sigval +union sigval { - int sival_int; /* Integer signal value. */ - void *sival_ptr; /* Pointer signal value. */ + int sival_int; /* Integer signal value. */ + void *sival_ptr; /* Pointer signal value. */ }; struct sigevent { - int sigev_notify; /* Notification type. */ - int sigev_signo; /* Signal number. */ - union sigval sigev_value; /* Signal value. */ - void (*sigev_notify_function)( union sigval ); /* Notification function. */ - void *sigev_notify_attributes; /* Notification Attributes, really pthread_attr_t. */ + int sigev_notify; /* Notification type. */ + int sigev_signo; /* Signal number. */ + union sigval sigev_value; /* Signal value. */ + void (*sigev_notify_function)(union sigval); /* Notification function. */ + void *sigev_notify_attributes; /* Notification Attributes, really pthread_attr_t. */ }; struct siginfo { - int si_signo; - int si_code; + int si_signo; + int si_code; union sigval si_value; }; typedef struct siginfo siginfo_t; /* for si_code */ -#define SI_USER 0x01 /* Signal sent by kill(). */ -#define SI_QUEUE 0x02 /* Signal sent by sigqueue(). */ -#define SI_TIMER 0x03 /* Signal generated by expiration of a timer set by timer_settime(). */ -#define SI_ASYNCIO 0x04 /* Signal generated by completion of an asynchronous I/O request. */ -#define SI_MESGQ 0x05 /* Signal generated by arrival of a message on an empty message queue. */ +#define SI_USER 0x01 /* Signal sent by kill(). */ +#define SI_QUEUE 0x02 /* Signal sent by sigqueue(). */ +#define SI_TIMER 0x03 /* Signal generated by expiration of a timer set by timer_settime(). */ +#define SI_ASYNCIO 0x04 /* Signal generated by completion of an asynchronous I/O request. */ +#define SI_MESGQ 0x05 /* Signal generated by arrival of a message on an empty message queue. */ #ifndef SIGEV_SIGNAL -#define SIGEV_SIGNAL 0 /* notify via signal */ +#define SIGEV_SIGNAL 0 /* notify via signal */ #endif #ifndef SIGEV_NONE -#define SIGEV_NONE 1 /* other notification: meaningless */ +#define SIGEV_NONE 1 /* other notification: meaningless */ #endif #ifndef SIGEV_THREAD -#define SIGEV_THREAD 2 /* deliver via thread creation */ +#define SIGEV_THREAD 2 /* deliver via thread creation */ #endif -#if defined(__GNUC__) /* GNUC */ +#if defined(__GNUC__) /* GNUC */ -#if defined(OS_USING_NEWLIB_ADAPTER) /* Newlib */ +#if defined(OS_USING_NEWLIB_ADAPTER) /* Newlib */ #include -#elif defined(OS_USING_MINILIB_ADAPTER) /* Minilib */ +#elif defined(OS_USING_MINILIB_ADAPTER) /* Minilib */ /* TODO: Need Add */ #endif /* defined(OS_USING_NEWLIB_ADAPTER) */ @@ -90,87 +90,87 @@ typedef struct siginfo siginfo_t; #elif defined(__CC_ARM) || defined(__CLANG_ARM) /* Armcc or armclang */ #include -typedef unsigned long sigset_t; +typedef unsigned long sigset_t; -#define SIGHUP 1 +#define SIGHUP 1 #ifndef SIGINT -#define SIGINT 2 +#define SIGINT 2 #endif -#define SIGQUIT 3 +#define SIGQUIT 3 #ifndef SIGILL -#define SIGILL 4 +#define SIGILL 4 #endif -#define SIGTRAP 5 +#define SIGTRAP 5 #ifndef SIGABRT -#define SIGABRT 6 +#define SIGABRT 6 #endif -#define SIGEMT 7 +#define SIGEMT 7 #ifndef SIGFPE -#define SIGFPE 8 +#define SIGFPE 8 #endif -#define SIGKILL 9 -#define SIGBUS 10 +#define SIGKILL 9 +#define SIGBUS 10 #ifndef SIGSEGV -#define SIGSEGV 11 +#define SIGSEGV 11 #endif -#define SIGSYS 12 -#define SIGPIPE 13 -#define SIGALRM 14 +#define SIGSYS 12 +#define SIGPIPE 13 +#define SIGALRM 14 #ifndef SIGTERM -#define SIGTERM 15 +#define SIGTERM 15 #endif -#define SIGURG 16 -#define SIGSTOP 17 -#define SIGTSTP 18 -#define SIGCONT 19 -#define SIGCHLD 20 -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGPOLL 23 -#define SIGWINCH 24 +#define SIGURG 16 +#define SIGSTOP 17 +#define SIGTSTP 18 +#define SIGCONT 19 +#define SIGCHLD 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGPOLL 23 +#define SIGWINCH 24 #ifndef SIGUSR1 -#define SIGUSR1 25 +#define SIGUSR1 25 #endif #ifndef SIGUSR2 -#define SIGUSR2 26 +#define SIGUSR2 26 #endif -#define SIGRTMIN 27 -#define SIGRTMAX 31 -#define NSIG 32 +#define SIGRTMIN 27 +#define SIGRTMAX 31 +#define NSIG 32 -#define SIG_SETMASK 0 /* Set mask with sigprocmask(). */ -#define SIG_BLOCK 1 /* Set of signals to block. */ -#define SIG_UNBLOCK 2 /* Set of signals to, well, unblock. */ +#define SIG_SETMASK 0 /* Set mask with sigprocmask(). */ +#define SIG_BLOCK 1 /* Set of signals to block. */ +#define SIG_UNBLOCK 2 /* Set of signals to, well, unblock. */ typedef void (*_sig_func_ptr)(int); -struct sigaction +struct sigaction { _sig_func_ptr sa_handler; - sigset_t sa_mask; - int sa_flags; + sigset_t sa_mask; + int sa_flags; }; -#define sigaddset(what,sig) (*(what) |= (1 << (sig)), 0) -#define sigdelset(what,sig) (*(what) &= ~(1 << (sig)), 0) -#define sigemptyset(what) (*(what) = 0, 0) -#define sigfillset(what) (*(what) = ~(0), 0) -#define sigismember(what,sig) (((*(what)) & (1 << (sig))) != 0) +#define sigaddset(what, sig) (*(what) |= (1 << (sig)), 0) +#define sigdelset(what, sig) (*(what) &= ~(1 << (sig)), 0) +#define sigemptyset(what) (*(what) = 0, 0) +#define sigfillset(what) (*(what) = ~(0), 0) +#define sigismember(what, sig) (((*(what)) & (1 << (sig))) != 0) extern int sigprocmask(int how, const sigset_t *set, sigset_t *oset); extern int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); @@ -182,4 +182,3 @@ extern int sigaction(int signum, const struct sigaction *act, struct sigaction * #endif #endif /* __SIGNAL_EXT_H__ */ - diff --git a/components/libc/include/extension/stdio_ext.h b/components/libc/include/extension/stdio_ext.h index a52c0200..4b210214 100644 --- a/components/libc/include/extension/stdio_ext.h +++ b/components/libc/include/extension/stdio_ext.h @@ -32,7 +32,7 @@ extern "C" { /* These defines is server for printf system interface */ extern int libc_system_init(void); -extern int libc_stdio_set_console(const char* device_name, int mode); +extern int libc_stdio_set_console(const char *device_name, int mode); extern int libc_stdio_get_console(void); /* These define is define for extending printf under ARMCC or ARMCLANG */ @@ -46,4 +46,3 @@ extern int libc_stdio_write(const void *buffer, size_t size); #endif #endif /* __STDIO_EXT_H__ */ - diff --git a/components/libc/include/extension/string_ext.h b/components/libc/include/extension/string_ext.h index 2f73adc1..bb5ec577 100644 --- a/components/libc/include/extension/string_ext.h +++ b/components/libc/include/extension/string_ext.h @@ -33,8 +33,8 @@ extern "C" { /* These define is define for extending as follow functions under ARMCC or ARMCLANG */ #if defined(__CC_ARM) || defined(__CLANG_ARM) -extern size_t strnlen(const char *s, size_t maxlen); -extern char *strdup(const char *s); +extern size_t strnlen(const char *s, size_t maxlen); +extern char *strdup(const char *s); #endif #ifdef __cplusplus @@ -42,4 +42,3 @@ extern char *strdup(const char *s); #endif #endif /* __STRING_EXT_H__ */ - diff --git a/components/libc/include/libc_ext.h b/components/libc/include/libc_ext.h index 89a2f79e..266953c6 100644 --- a/components/libc/include/libc_ext.h +++ b/components/libc/include/libc_ext.h @@ -35,4 +35,3 @@ #define EXPORT_SYMBOL(symbol) #endif /* __OS_LIBC_H__ */ - diff --git a/components/libc/include/newlib/poll.h b/components/libc/include/newlib/poll.h index 9e97c9c4..d98f3b40 100644 --- a/components/libc/include/newlib/poll.h +++ b/components/libc/include/newlib/poll.h @@ -26,4 +26,3 @@ #include #endif /* __POLL_H__ */ - diff --git a/components/libc/include/newlib/sys/dirent.h b/components/libc/include/newlib/sys/dirent.h index a4526a6c..175cdf45 100644 --- a/components/libc/include/newlib/sys/dirent.h +++ b/components/libc/include/newlib/sys/dirent.h @@ -30,50 +30,49 @@ extern "C" { #endif /* Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html */ -#define DT_UNKNOWN 0 -#define DT_FIFO 1 -#define DT_CHR 2 -#define DT_DIR 4 -#define DT_BLK 6 -#define DT_REG 8 -#define DT_LNK 10 -#define DT_SOCK 12 -#define DT_WHT 14 +#define DT_UNKNOWN 0 +#define DT_FIFO 1 +#define DT_CHR 2 +#define DT_DIR 4 +#define DT_BLK 6 +#define DT_REG 8 +#define DT_LNK 10 +#define DT_SOCK 12 +#define DT_WHT 14 struct dirent { - ino_t d_ino; /* file number */ - unsigned char d_type; /* The type of the file. */ - char d_name[256]; /* The null-terminated file name. */ + ino_t d_ino; /* file number */ + unsigned char d_type; /* The type of the file. */ + char d_name[256]; /* The null-terminated file name. */ }; struct __dirstream { - int fd; /* File descriptor. */ - size_t allocation; /* Space allocated for the block. */ - size_t size; /* Total valid data in the block. */ - size_t offset; /* Current offset into the block. */ - off_t filepos; /* Position of next entry to read. */ - int errcode; /* Delayed error code. */ - void *priv; + int fd; /* File descriptor. */ + size_t allocation; /* Space allocated for the block. */ + size_t size; /* Total valid data in the block. */ + size_t offset; /* Current offset into the block. */ + off_t filepos; /* Position of next entry to read. */ + int errcode; /* Delayed error code. */ + void *priv; }; -/* +/* * This is the data type of directory stream objects. * The actual structure is opaque to users. */ typedef struct __dirstream DIR; -extern int closedir(DIR *pdir); -extern DIR *opendir(const char *path); +extern int closedir(DIR *pdir); +extern DIR *opendir(const char *path); extern struct dirent *readdir(DIR *pdir); -extern void rewinddir(DIR *pdir); -extern void seekdir(DIR *pdir, long ofst); -extern long telldir(DIR *pdir); +extern void rewinddir(DIR *pdir); +extern void seekdir(DIR *pdir, long ofst); +extern long telldir(DIR *pdir); #ifdef __cplusplus } #endif #endif /* __SYS_DIRENT_H__ */ - diff --git a/components/libc/include/newlib/sys/ioctl.h b/components/libc/include/newlib/sys/ioctl.h index af34a1f7..e07431f5 100644 --- a/components/libc/include/newlib/sys/ioctl.h +++ b/components/libc/include/newlib/sys/ioctl.h @@ -23,104 +23,104 @@ #ifndef __SYS_IOCTL_H__ #define __SYS_IOCTL_H__ -#define _IOC(a,b,c,d) (((a)<<30) | ((b)<<8) | (c) | ((d)<<16)) -#define _IOC_NONE 0U -#define _IOC_WRITE 1U -#define _IOC_READ 2U +#define _IOC(a, b, c, d) (((a) << 30) | ((b) << 8) | (c) | ((d) << 16)) +#define _IOC_NONE 0U +#define _IOC_WRITE 1U +#define _IOC_READ 2U #ifndef _WIN32 -#define _IO(a,b) _IOC(_IOC_NONE, (a), (b), 0) -#define _IOW(a,b,c) _IOC(_IOC_WRITE, (a), (b), sizeof(c)) -#define _IOR(a,b,c) _IOC(_IOC_READ, (a), (b), sizeof(c)) -#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE, (a), (b), sizeof(c)) - -#define FIONREAD _IOR('f', 127, int) /* Get # bytes to read. */ -#define FIONBIO _IOW('f', 126, int) /* Set/clear non-blocking i/o. */ -#define FIONWRITE _IOR('f', 121, int) /* Get # bytes outstanding in send queue. */ +#define _IO(a, b) _IOC(_IOC_NONE, (a), (b), 0) +#define _IOW(a, b, c) _IOC(_IOC_WRITE, (a), (b), sizeof(c)) +#define _IOR(a, b, c) _IOC(_IOC_READ, (a), (b), sizeof(c)) +#define _IOWR(a, b, c) _IOC(_IOC_READ | _IOC_WRITE, (a), (b), sizeof(c)) + +#define FIONREAD _IOR('f', 127, int) /* Get # bytes to read. */ +#define FIONBIO _IOW('f', 126, int) /* Set/clear non-blocking i/o. */ +#define FIONWRITE _IOR('f', 121, int) /* Get # bytes outstanding in send queue. */ #endif -#define TCGETS 0x5401 -#define TCSETS 0x5402 -#define TCSETSW 0x5403 -#define TCSETSF 0x5404 -#define TCGETA 0x5405 -#define TCSETA 0x5406 -#define TCSETAW 0x5407 -#define TCSETAF 0x5408 -#define TCSBRK 0x5409 -#define TCXONC 0x540A -#define TCFLSH 0x540B -#define TIOCEXCL 0x540C -#define TIOCNXCL 0x540D -#define TIOCSCTTY 0x540E -#define TIOCGPGRP 0x540F -#define TIOCSPGRP 0x5410 -#define TIOCOUTQ 0x5411 -#define TIOCSTI 0x5412 -#define TIOCGWINSZ 0x5413 -#define TIOCSWINSZ 0x5414 -#define TIOCMGET 0x5415 -#define TIOCMBIS 0x5416 -#define TIOCMBIC 0x5417 -#define TIOCMSET 0x5418 -#define TIOCGSOFTCAR 0x5419 -#define TIOCSSOFTCAR 0x541A -#define TIOCINQ FIONREAD -#define TIOCLINUX 0x541C -#define TIOCCONS 0x541D -#define TIOCGSERIAL 0x541E -#define TIOCSSERIAL 0x541F -#define TIOCPKT 0x5420 -#define TIOCNOTTY 0x5422 -#define TIOCSETD 0x5423 -#define TIOCGETD 0x5424 -#define TCSBRKP 0x5425 -#define TIOCSBRK 0x5427 -#define TIOCCBRK 0x5428 -#define TIOCGSID 0x5429 -#define TIOCGRS485 0x542E -#define TIOCSRS485 0x542F -#define TIOCGPTN 0x80045430 -#define TIOCSPTLCK 0x40045431 -#define TIOCGDEV 0x80045432 -#define TCGETX 0x5432 -#define TCSETX 0x5433 -#define TCSETXF 0x5434 -#define TCSETXW 0x5435 -#define TIOCSIG 0x40045436 -#define TIOCVHANGUP 0x5437 -#define TIOCGPKT 0x80045438 -#define TIOCGPTLCK 0x80045439 -#define TIOCGEXCL 0x80045440 - -#define FIONCLEX 0x5450 -#define FIOCLEX 0x5451 -#define FIOASYNC 0x5452 - -#define TIOCSERCONFIG 0x5453 -#define TIOCSERGWILD 0x5454 -#define TIOCSERSWILD 0x5455 -#define TIOCGLCKTRMIOS 0x5456 -#define TIOCSLCKTRMIOS 0x5457 -#define TIOCSERGSTRUCT 0x5458 -#define TIOCSERGETLSR 0x5459 -#define TIOCSERGETMULTI 0x545A -#define TIOCSERSETMULTI 0x545B - -#define TIOCMIWAIT 0x545C -#define TIOCGICOUNT 0x545D -#define FIOQSIZE 0x5460 - -#define TIOCPKT_DATA 0 -#define TIOCPKT_FLUSHREAD 1 -#define TIOCPKT_FLUSHWRITE 2 -#define TIOCPKT_STOP 4 -#define TIOCPKT_START 8 -#define TIOCPKT_NOSTOP 16 -#define TIOCPKT_DOSTOP 32 -#define TIOCPKT_IOCTL 64 - -#define TIOCSER_TEMT 0x01 +#define TCGETS 0x5401 +#define TCSETS 0x5402 +#define TCSETSW 0x5403 +#define TCSETSF 0x5404 +#define TCGETA 0x5405 +#define TCSETA 0x5406 +#define TCSETAW 0x5407 +#define TCSETAF 0x5408 +#define TCSBRK 0x5409 +#define TCXONC 0x540A +#define TCFLSH 0x540B +#define TIOCEXCL 0x540C +#define TIOCNXCL 0x540D +#define TIOCSCTTY 0x540E +#define TIOCGPGRP 0x540F +#define TIOCSPGRP 0x5410 +#define TIOCOUTQ 0x5411 +#define TIOCSTI 0x5412 +#define TIOCGWINSZ 0x5413 +#define TIOCSWINSZ 0x5414 +#define TIOCMGET 0x5415 +#define TIOCMBIS 0x5416 +#define TIOCMBIC 0x5417 +#define TIOCMSET 0x5418 +#define TIOCGSOFTCAR 0x5419 +#define TIOCSSOFTCAR 0x541A +#define TIOCINQ FIONREAD +#define TIOCLINUX 0x541C +#define TIOCCONS 0x541D +#define TIOCGSERIAL 0x541E +#define TIOCSSERIAL 0x541F +#define TIOCPKT 0x5420 +#define TIOCNOTTY 0x5422 +#define TIOCSETD 0x5423 +#define TIOCGETD 0x5424 +#define TCSBRKP 0x5425 +#define TIOCSBRK 0x5427 +#define TIOCCBRK 0x5428 +#define TIOCGSID 0x5429 +#define TIOCGRS485 0x542E +#define TIOCSRS485 0x542F +#define TIOCGPTN 0x80045430 +#define TIOCSPTLCK 0x40045431 +#define TIOCGDEV 0x80045432 +#define TCGETX 0x5432 +#define TCSETX 0x5433 +#define TCSETXF 0x5434 +#define TCSETXW 0x5435 +#define TIOCSIG 0x40045436 +#define TIOCVHANGUP 0x5437 +#define TIOCGPKT 0x80045438 +#define TIOCGPTLCK 0x80045439 +#define TIOCGEXCL 0x80045440 + +#define FIONCLEX 0x5450 +#define FIOCLEX 0x5451 +#define FIOASYNC 0x5452 + +#define TIOCSERCONFIG 0x5453 +#define TIOCSERGWILD 0x5454 +#define TIOCSERSWILD 0x5455 +#define TIOCGLCKTRMIOS 0x5456 +#define TIOCSLCKTRMIOS 0x5457 +#define TIOCSERGSTRUCT 0x5458 +#define TIOCSERGETLSR 0x5459 +#define TIOCSERGETMULTI 0x545A +#define TIOCSERSETMULTI 0x545B + +#define TIOCMIWAIT 0x545C +#define TIOCGICOUNT 0x545D +#define FIOQSIZE 0x5460 + +#define TIOCPKT_DATA 0 +#define TIOCPKT_FLUSHREAD 1 +#define TIOCPKT_FLUSHWRITE 2 +#define TIOCPKT_STOP 4 +#define TIOCPKT_START 8 +#define TIOCPKT_NOSTOP 16 +#define TIOCPKT_DOSTOP 32 +#define TIOCPKT_IOCTL 64 + +#define TIOCSER_TEMT 0x01 struct winsize { @@ -130,109 +130,108 @@ struct winsize unsigned short ws_ypixel; }; -#define TIOCM_LE 0x001 -#define TIOCM_DTR 0x002 -#define TIOCM_RTS 0x004 -#define TIOCM_ST 0x008 -#define TIOCM_SR 0x010 -#define TIOCM_CTS 0x020 -#define TIOCM_CAR 0x040 -#define TIOCM_RNG 0x080 -#define TIOCM_DSR 0x100 -#define TIOCM_CD TIOCM_CAR -#define TIOCM_RI TIOCM_RNG -#define TIOCM_OUT1 0x2000 -#define TIOCM_OUT2 0x4000 -#define TIOCM_LOOP 0x8000 - -#define N_TTY 0 -#define N_SLIP 1 -#define N_MOUSE 2 -#define N_PPP 3 -#define N_STRIP 4 -#define N_AX25 5 -#define N_X25 6 -#define N_6PACK 7 -#define N_MASC 8 -#define N_R3964 9 -#define N_PROFIBUS_FDL 10 -#define N_IRDA 11 -#define N_SMSBLOCK 12 -#define N_HDLC 13 -#define N_SYNC_PPP 14 -#define N_HCI 15 - -#define FIOSETOWN 0x8901 -#define SIOCSPGRP 0x8902 -#define FIOGETOWN 0x8903 -#define SIOCGPGRP 0x8904 -#define SIOCGSTAMP 0x8906 -#define SIOCGSTAMPNS 0x8907 - -#define SIOCADDRT 0x890B -#define SIOCDELRT 0x890C -#define SIOCRTMSG 0x890D - -#define SIOCGIFNAME 0x8910 -#define SIOCSIFLINK 0x8911 -#define SIOCGIFCONF 0x8912 -#define SIOCGIFFLAGS 0x8913 -#define SIOCSIFFLAGS 0x8914 -#define SIOCGIFADDR 0x8915 -#define SIOCSIFADDR 0x8916 -#define SIOCGIFDSTADDR 0x8917 -#define SIOCSIFDSTADDR 0x8918 -#define SIOCGIFBRDADDR 0x8919 -#define SIOCSIFBRDADDR 0x891a -#define SIOCGIFNETMASK 0x891b -#define SIOCSIFNETMASK 0x891c -#define SIOCGIFMETRIC 0x891d -#define SIOCSIFMETRIC 0x891e -#define SIOCGIFMEM 0x891f -#define SIOCSIFMEM 0x8920 -#define SIOCGIFMTU 0x8921 -#define SIOCSIFMTU 0x8922 -#define SIOCSIFNAME 0x8923 -#define SIOCSIFHWADDR 0x8924 -#define SIOCGIFENCAP 0x8925 -#define SIOCSIFENCAP 0x8926 -#define SIOCGIFHWADDR 0x8927 -#define SIOCGIFSLAVE 0x8929 -#define SIOCSIFSLAVE 0x8930 -#define SIOCADDMULTI 0x8931 -#define SIOCDELMULTI 0x8932 -#define SIOCGIFINDEX 0x8933 -#define SIOGIFINDEX SIOCGIFINDEX -#define SIOCSIFPFLAGS 0x8934 -#define SIOCGIFPFLAGS 0x8935 -#define SIOCDIFADDR 0x8936 -#define SIOCSIFHWBROADCAST 0x8937 -#define SIOCGIFCOUNT 0x8938 - -#define SIOCGIFBR 0x8940 -#define SIOCSIFBR 0x8941 - -#define SIOCGIFTXQLEN 0x8942 -#define SIOCSIFTXQLEN 0x8943 - -#define SIOCDARP 0x8953 -#define SIOCGARP 0x8954 -#define SIOCSARP 0x8955 - -#define SIOCDRARP 0x8960 -#define SIOCGRARP 0x8961 -#define SIOCSRARP 0x8962 - -#define SIOCGIFMAP 0x8970 -#define SIOCSIFMAP 0x8971 - -#define SIOCADDDLCI 0x8980 -#define SIOCDELDLCI 0x8981 - -#define SIOCDEVPRIVATE 0x89F0 -#define SIOCPROTOPRIVATE 0x89E0 +#define TIOCM_LE 0x001 +#define TIOCM_DTR 0x002 +#define TIOCM_RTS 0x004 +#define TIOCM_ST 0x008 +#define TIOCM_SR 0x010 +#define TIOCM_CTS 0x020 +#define TIOCM_CAR 0x040 +#define TIOCM_RNG 0x080 +#define TIOCM_DSR 0x100 +#define TIOCM_CD TIOCM_CAR +#define TIOCM_RI TIOCM_RNG +#define TIOCM_OUT1 0x2000 +#define TIOCM_OUT2 0x4000 +#define TIOCM_LOOP 0x8000 + +#define N_TTY 0 +#define N_SLIP 1 +#define N_MOUSE 2 +#define N_PPP 3 +#define N_STRIP 4 +#define N_AX25 5 +#define N_X25 6 +#define N_6PACK 7 +#define N_MASC 8 +#define N_R3964 9 +#define N_PROFIBUS_FDL 10 +#define N_IRDA 11 +#define N_SMSBLOCK 12 +#define N_HDLC 13 +#define N_SYNC_PPP 14 +#define N_HCI 15 + +#define FIOSETOWN 0x8901 +#define SIOCSPGRP 0x8902 +#define FIOGETOWN 0x8903 +#define SIOCGPGRP 0x8904 +#define SIOCGSTAMP 0x8906 +#define SIOCGSTAMPNS 0x8907 + +#define SIOCADDRT 0x890B +#define SIOCDELRT 0x890C +#define SIOCRTMSG 0x890D + +#define SIOCGIFNAME 0x8910 +#define SIOCSIFLINK 0x8911 +#define SIOCGIFCONF 0x8912 +#define SIOCGIFFLAGS 0x8913 +#define SIOCSIFFLAGS 0x8914 +#define SIOCGIFADDR 0x8915 +#define SIOCSIFADDR 0x8916 +#define SIOCGIFDSTADDR 0x8917 +#define SIOCSIFDSTADDR 0x8918 +#define SIOCGIFBRDADDR 0x8919 +#define SIOCSIFBRDADDR 0x891a +#define SIOCGIFNETMASK 0x891b +#define SIOCSIFNETMASK 0x891c +#define SIOCGIFMETRIC 0x891d +#define SIOCSIFMETRIC 0x891e +#define SIOCGIFMEM 0x891f +#define SIOCSIFMEM 0x8920 +#define SIOCGIFMTU 0x8921 +#define SIOCSIFMTU 0x8922 +#define SIOCSIFNAME 0x8923 +#define SIOCSIFHWADDR 0x8924 +#define SIOCGIFENCAP 0x8925 +#define SIOCSIFENCAP 0x8926 +#define SIOCGIFHWADDR 0x8927 +#define SIOCGIFSLAVE 0x8929 +#define SIOCSIFSLAVE 0x8930 +#define SIOCADDMULTI 0x8931 +#define SIOCDELMULTI 0x8932 +#define SIOCGIFINDEX 0x8933 +#define SIOGIFINDEX SIOCGIFINDEX +#define SIOCSIFPFLAGS 0x8934 +#define SIOCGIFPFLAGS 0x8935 +#define SIOCDIFADDR 0x8936 +#define SIOCSIFHWBROADCAST 0x8937 +#define SIOCGIFCOUNT 0x8938 + +#define SIOCGIFBR 0x8940 +#define SIOCSIFBR 0x8941 + +#define SIOCGIFTXQLEN 0x8942 +#define SIOCSIFTXQLEN 0x8943 + +#define SIOCDARP 0x8953 +#define SIOCGARP 0x8954 +#define SIOCSARP 0x8955 + +#define SIOCDRARP 0x8960 +#define SIOCGRARP 0x8961 +#define SIOCSRARP 0x8962 + +#define SIOCGIFMAP 0x8970 +#define SIOCSIFMAP 0x8971 + +#define SIOCADDDLCI 0x8980 +#define SIOCDELDLCI 0x8981 + +#define SIOCDEVPRIVATE 0x89F0 +#define SIOCPROTOPRIVATE 0x89E0 extern int ioctl(int fd, unsigned long request, ...); #endif /* __SYS_IOCTL_H__ */ - diff --git a/components/libc/include/newlib/sys/poll.h b/components/libc/include/newlib/sys/poll.h index 650900eb..232ae653 100644 --- a/components/libc/include/newlib/sys/poll.h +++ b/components/libc/include/newlib/sys/poll.h @@ -23,23 +23,23 @@ #ifndef __SYS_POLL_H__ #define __SYS_POLL_H__ -#define POLLIN 0x0001 -#define POLLPRI 0x0002 -#define POLLOUT 0x0004 -#define POLLERR 0x0008 -#define POLLHUP 0x0010 -#define POLLNVAL 0x0020 -#define POLLRDNORM 0x0040 -#define POLLRDBAND 0x0080 -#define POLLWRNORM 0x0100 -#define POLLWRBAND 0x0200 +#define POLLIN 0x0001 +#define POLLPRI 0x0002 +#define POLLOUT 0x0004 +#define POLLERR 0x0008 +#define POLLHUP 0x0010 +#define POLLNVAL 0x0020 +#define POLLRDNORM 0x0040 +#define POLLRDBAND 0x0080 +#define POLLWRNORM 0x0100 +#define POLLWRBAND 0x0200 struct pollfd { /* The Following three item member is must be include */ - int fd; /* The following descriptor being polled. */ - short events; /* The input event flags. */ - short revents; /* The output event flags. */ + int fd; /* The following descriptor being polled. */ + short events; /* The input event flags. */ + short revents; /* The output event flags. */ }; typedef unsigned int nfds_t; @@ -47,4 +47,3 @@ typedef unsigned int nfds_t; extern int poll(struct pollfd fds[], nfds_t nfds, int timeout); #endif /* __SYS_POLL_H__ */ - diff --git a/components/libc/include/newlib/sys/statfs.h b/components/libc/include/newlib/sys/statfs.h index 8dce8308..9deb65e6 100644 --- a/components/libc/include/newlib/sys/statfs.h +++ b/components/libc/include/newlib/sys/statfs.h @@ -25,12 +25,11 @@ struct statfs { - unsigned long f_bsize; /* Block size. */ - unsigned long f_blocks; /* Total data blocks in file system. */ - unsigned long f_bfree; /* Free blocks in file system. */ + unsigned long f_bsize; /* Block size. */ + unsigned long f_blocks; /* Total data blocks in file system. */ + unsigned long f_bfree; /* Free blocks in file system. */ }; extern int statfs(const char *path, struct statfs *buf); #endif /* __SYS_STATFS_H__ */ - diff --git a/components/libc/include/newlib/sys/vfs.h b/components/libc/include/newlib/sys/vfs.h index 5a17568c..67b34c2a 100644 --- a/components/libc/include/newlib/sys/vfs.h +++ b/components/libc/include/newlib/sys/vfs.h @@ -26,4 +26,3 @@ #include #endif /* __SYS_VFS_H__ */ - diff --git a/components/libc/source/armlibc/dirent.c b/components/libc/source/armlibc/dirent.c index 563617da..a8ef0a83 100644 --- a/components/libc/source/armlibc/dirent.c +++ b/components/libc/source/armlibc/dirent.c @@ -14,19 +14,19 @@ int closedir(DIR *pdir) { int res = -1; - if (!pdir) + if (!pdir) { errno = EBADF; LOG_E(DIRENT_TAG, "Invalid directory stream descriptor\r\n"); - } + } else { - #ifdef OS_USING_VFS +#ifdef OS_USING_VFS res = vfs_closedir(pdir->priv); - #if defined (OS_USING_SYS_HEAP) +#if defined(OS_USING_SYS_HEAP) os_free(pdir); - #endif - #endif +#endif +#endif } return res; @@ -34,25 +34,25 @@ int closedir(DIR *pdir) DIR *opendir(const char *path) { - DIR *pdir = OS_NULL; + DIR *pdir = OS_NULL; #ifdef OS_USING_VFS void *priv = OS_NULL; - if (OS_NULL == path) + if (OS_NULL == path) { errno = ENOENT; LOG_E(DIRENT_TAG, "Path is null\r\n"); - } - else + } + else { if (OS_NULL != (priv = vfs_opendir(path))) { - #if defined (OS_USING_SYS_HEAP) - pdir = (DIR*)os_malloc(sizeof(DIR)); - #else +#if defined(OS_USING_SYS_HEAP) + pdir = (DIR *)os_malloc(sizeof(DIR)); +#else pdir = OS_NULL; - #endif +#endif if (OS_NULL != pdir) { pdir->priv = priv; @@ -68,16 +68,16 @@ struct dirent *readdir(DIR *pdir) { struct dirent *pdirent = OS_NULL; - if (!pdir) + if (!pdir) { errno = EBADF; LOG_E(DIRENT_TAG, "Invalid directory stream descriptor\r\n"); } - else + else { - #ifdef OS_USING_VFS +#ifdef OS_USING_VFS pdirent = vfs_readdir(pdir->priv); - #endif +#endif } return pdirent; @@ -85,31 +85,31 @@ struct dirent *readdir(DIR *pdir) void rewinddir(DIR *pdir) { - if (!pdir) + if (!pdir) { errno = EBADF; LOG_E(DIRENT_TAG, "Invalid directory stream descriptor\r\n"); - } - else + } + else { - #ifdef OS_USING_VFS +#ifdef OS_USING_VFS vfs_rewinddir(pdir->priv); - #endif +#endif } } void seekdir(DIR *pdir, long ofst) { - if (!pdir) + if (!pdir) { errno = EBADF; LOG_E(DIRENT_TAG, "Invalid directory stream descriptor\r\n"); - } - else + } + else { - #ifdef OS_USING_VFS +#ifdef OS_USING_VFS vfs_seekdir(pdir->priv, ofst); - #endif +#endif } } @@ -117,18 +117,17 @@ long telldir(DIR *pdir) { long res = 0; - if (!pdir) + if (!pdir) { errno = EBADF; LOG_E(DIRENT_TAG, "Invalid directory stream descriptor\r\n"); } - else + else { - #ifdef OS_USING_VFS +#ifdef OS_USING_VFS res = vfs_telldir(pdir->priv); - #endif +#endif } return res; } - diff --git a/components/libc/source/armlibc/fcntl.c b/components/libc/source/armlibc/fcntl.c index ae530da4..8dc7d0ad 100644 --- a/components/libc/source/armlibc/fcntl.c +++ b/components/libc/source/armlibc/fcntl.c @@ -7,7 +7,7 @@ int fcntl(int fd, int flag, ...) { - int ret = -1; + int ret = -1; #ifdef OS_USING_VFS va_list va; void *arg = OS_NULL; @@ -21,4 +21,3 @@ int fcntl(int fd, int flag, ...) #endif return ret; } - diff --git a/components/libc/source/armlibc/getcwd.c b/components/libc/source/armlibc/getcwd.c index b07f932d..6a4cad72 100644 --- a/components/libc/source/armlibc/getcwd.c +++ b/components/libc/source/armlibc/getcwd.c @@ -6,7 +6,7 @@ #include "vfs_posix.h" #endif -char* getcwd(char *buf, size_t size ) +char *getcwd(char *buf, size_t size) { #ifdef OS_USING_VFS return vfs_getcwd(buf, size); diff --git a/components/libc/source/armlibc/ioctl.c b/components/libc/source/armlibc/ioctl.c index d82298b1..c5c53fcd 100644 --- a/components/libc/source/armlibc/ioctl.c +++ b/components/libc/source/armlibc/ioctl.c @@ -21,4 +21,3 @@ int ioctl(int fd, unsigned long request, ...) #endif return ret; } - diff --git a/components/libc/source/armlibc/libc.c b/components/libc/source/armlibc/libc.c index a8302b05..616d7487 100644 --- a/components/libc/source/armlibc/libc.c +++ b/components/libc/source/armlibc/libc.c @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file libc.c diff --git a/components/libc/source/armlibc/mem_std.c b/components/libc/source/armlibc/mem_std.c index 1db350ef..b9e709b6 100644 --- a/components/libc/source/armlibc/mem_std.c +++ b/components/libc/source/armlibc/mem_std.c @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file mem_std.c @@ -62,7 +62,7 @@ void *calloc(size_t nelem, size_t elsize) void free(void *rmem) { #if defined(OS_USING_SYS_HEAP) - if (OS_NULL != rmem) + if (OS_NULL != rmem) { os_free(rmem); } diff --git a/components/libc/source/armlibc/poll.c b/components/libc/source/armlibc/poll.c index 3a776361..90c5c729 100644 --- a/components/libc/source/armlibc/poll.c +++ b/components/libc/source/armlibc/poll.c @@ -9,45 +9,45 @@ int poll(struct pollfd fds[], nfds_t nfds, int timeout) { struct vfs_pollfd *pfds = OS_NULL; - int ret = -1; + int ret = -1; unsigned int i = 0; - if (OS_NULL == fds) + if (OS_NULL == fds) { os_kprintf("File Descriptor is NULL\r\n"); - } - else + } + else { - #if defined(OS_USING_VFS) +#if defined(OS_USING_VFS) - #if defined(OS_USING_SYS_HEAP) - pfds = (struct vfs_pollfd*)os_malloc(sizeof(struct vfs_pollfd) * nfds); - #else +#if defined(OS_USING_SYS_HEAP) + pfds = (struct vfs_pollfd *)os_malloc(sizeof(struct vfs_pollfd) * nfds); +#else pfds = OS_NULL; - #endif - if (OS_NULL == pfds) +#endif + if (OS_NULL == pfds) { os_kprintf("Pollfd memory alloc failed\r\n"); } else { - for (i = 0; i < nfds; i++) + for (i = 0; i < nfds; i++) { - pfds[i].fd = fds[i].fd; - pfds[i].events = fds[i].events; + pfds[i].fd = fds[i].fd; + pfds[i].events = fds[i].events; } - ret = vfs_poll(pfds, nfds, timeout); + ret = vfs_poll(pfds, nfds, timeout); - for (i = 0; i < nfds; i++) + for (i = 0; i < nfds; i++) { fds[i].revents = pfds[i].revents; } - #if defined(OS_USING_SYS_HEAP) +#if defined(OS_USING_SYS_HEAP) os_free(pfds); - #endif +#endif } - #endif +#endif } return ret; diff --git a/components/libc/source/armlibc/select.c b/components/libc/source/armlibc/select.c index 9dcb22fe..b3adee43 100644 --- a/components/libc/source/armlibc/select.c +++ b/components/libc/source/armlibc/select.c @@ -7,8 +7,7 @@ #include #endif -int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - struct timeval *timeout) +int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) { #if defined(OS_USING_VFS) return vfs_select(nfds, readfds, writefds, exceptfds, timeout); diff --git a/components/libc/source/armlibc/stdio.c b/components/libc/source/armlibc/stdio.c index 8ed226e9..d5fccc58 100644 --- a/components/libc/source/armlibc/stdio.c +++ b/components/libc/source/armlibc/stdio.c @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file stdio.c @@ -33,10 +33,10 @@ #if defined(OS_USING_VFS) && defined(OS_USING_VFS_DEVFS) #include -#define STDIO_DEVICE_NAME_MAX 32 +#define STDIO_DEVICE_NAME_MAX 32 static int std_fd = -1; -int libc_stdio_set_console(const char* device_name, int mode) +int libc_stdio_set_console(const char *device_name, int mode) { int fd; char name[STDIO_DEVICE_NAME_MAX]; diff --git a/components/libc/source/armlibc/strdup.c b/components/libc/source/armlibc/strdup.c index 401e4dfb..eb080f61 100644 --- a/components/libc/source/armlibc/strdup.c +++ b/components/libc/source/armlibc/strdup.c @@ -4,11 +4,11 @@ char *strdup(const char *s) { - size_t len; - char *str_tmp; + size_t len; + char *str_tmp; len = strlen(s) + 1; -#if defined (OS_USING_SYS_HEAP) +#if defined(OS_USING_SYS_HEAP) str_tmp = (char *)os_malloc(len); #else str_tmp = OS_NULL; @@ -22,4 +22,3 @@ char *strdup(const char *s) return str_tmp; } - diff --git a/components/libc/source/armlibc/strnlen.c b/components/libc/source/armlibc/strnlen.c index abb68393..bc4acaa0 100644 --- a/components/libc/source/armlibc/strnlen.c +++ b/components/libc/source/armlibc/strnlen.c @@ -11,4 +11,3 @@ size_t strnlen(const char *s, size_t maxlen) return (str_tmp - s); } - diff --git a/components/libc/source/armlibc/stubs.c b/components/libc/source/armlibc/stubs.c index 49b66a8f..d59819a3 100644 --- a/components/libc/source/armlibc/stubs.c +++ b/components/libc/source/armlibc/stubs.c @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file stubs.c @@ -43,12 +43,12 @@ __asm(".global __use_no_semihosting\n\t"); #endif /* Standard IO device handles. */ -#define STDIN 0 -#define STDOUT 1 -#define STDERR 2 +#define STDIN 0 +#define STDOUT 1 +#define STDERR 2 /* Standard IO device name defines. */ -const char __stdin_name[] = "STDIN"; +const char __stdin_name[] = "STDIN"; const char __stdout_name[] = "STDOUT"; const char __stderr_name[] = "STDERR"; @@ -74,12 +74,12 @@ FILEHANDLE _sys_open(const char *name, int openmode) { return (STDIN); } - + if (strcmp(name, __stdout_name) == 0) { return (STDOUT); } - + if (strcmp(name, __stderr_name) == 0) { return (STDERR); @@ -157,15 +157,15 @@ int _sys_close(FILEHANDLE fh) *********************************************************************************************************************** * @brief Reads the contents of a file into a buffer. * - * @attention It is also legal to signal EOF by returning no data but signalling no error (i.e. the top-bit-set + * @attention It is also legal to signal EOF by returning no data but signalling no error (i.e. the top-bit-set * mechanism need never be used). - * So if (for example) the user is trying to read 8 bytes at a time from a file in which only 5 remain, + * So if (for example) the user is trying to read 8 bytes at a time from a file in which only 5 remain, * this routine can do three equally valid things: * - it can return 0x80000003 (3 bytes not read due to EOF). - * - OR it can return 3 (3 bytes not read), and then return 0x80000008 (8 bytes not read due to EOF) + * - OR it can return 3 (3 bytes not read), and then return 0x80000008 (8 bytes not read due to EOF) * on the next attempt. - * - OR it can return 3 (3 bytes not read), and then return 8 (8 bytes not read, meaning 0 read, meaning - * EOF) on the next attempt. + * - OR it can return 3 (3 bytes not read), and then return 8 (8 bytes not read, meaning 0 read, + *meaning EOF) on the next attempt. * * @param[in] fh File handle. * @param[in] len Buffer length. @@ -175,7 +175,7 @@ int _sys_close(FILEHANDLE fh) * @return Can return: * - zero if the read was completely successful. * - the number of bytes _not_ read, if the read was partially successful. - * - the number of bytes not read, plus the top bit set (0x80000000), if the read was partially + * - the number of bytes not read, plus the top bit set (0x80000000), if the read was partially * successful due to end of file. * - -1 if some error other than EOF occurred. *********************************************************************************************************************** @@ -389,7 +389,8 @@ char *_sys_command_string(char *cmd, int len) OS_WEAK void _sys_exit(int return_code) { /* TODO: perhaps exit the task which is invoking this function. */ - while (1); + while (1) + ; } /* Use system(const char *string) implementation in the msh. */ @@ -419,7 +420,7 @@ volatile int *__aeabi_errno_addr(void) #ifdef __MICROLIB #include -int fputc(int c, FILE *f) +int fputc(int c, FILE *f) { char ch[2] = {0}; @@ -428,7 +429,7 @@ int fputc(int c, FILE *f) return 1; } -int fgetc(FILE *f) +int fgetc(FILE *f) { #ifdef OS_USING_VFS_DEVFS char ch; diff --git a/components/libc/source/armlibc/time.c b/components/libc/source/armlibc/time.c index 80d911c1..e3539b62 100644 --- a/components/libc/source/armlibc/time.c +++ b/components/libc/source/armlibc/time.c @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file time.c @@ -120,4 +120,3 @@ OS_WEAK clock_t clock(void) { return os_tick_get(); } - diff --git a/components/libc/source/common/gmtime_r.c b/components/libc/source/common/gmtime_r.c index 6bd711d6..2e2bc434 100644 --- a/components/libc/source/common/gmtime_r.c +++ b/components/libc/source/common/gmtime_r.c @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file gmtime_r.c @@ -21,15 +21,14 @@ *********************************************************************************************************************** */ #include -#if defined(__CC_ARM) || defined(__CLANG_ARM) || defined (__IAR_SYSTEMS_ICC__) +#if defined(__CC_ARM) || defined(__CLANG_ARM) || defined(__IAR_SYSTEMS_ICC__) #include /* Seconds per day. */ #define SPD (24 * 60 * 60) /* Days per month -- nonleap! */ -const short __spm[13] = -{ +const short __spm[13] = { 0, (31), (31 + 28), @@ -67,15 +66,15 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r) { time_t i; register time_t work = *timep % (SPD); - - r->tm_sec = work % 60; - work /= 60; - r->tm_min = work % 60; + + r->tm_sec = work % 60; + work /= 60; + r->tm_min = work % 60; r->tm_hour = work / 60; - work = *timep / (SPD); + work = *timep / (SPD); r->tm_wday = (4 + work) % 7; - for (i = 1970; ; ++i) + for (i = 1970;; ++i) { register time_t k = __isleap(i) ? 366 : 365; if (work >= k) @@ -97,16 +96,16 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r) { r->tm_mday = 2; /* 29.2. */ } - + work -= 1; } - for (i = 11; i && (__spm[i] > work); --i); - + for (i = 11; i && (__spm[i] > work); --i) + ; + r->tm_mon = i; r->tm_mday += work - __spm[i]; - + return r; } #endif /* end of __CC_ARM or __CLANG_ARM or __IAR_SYSTEMS_ICC__ */ - diff --git a/components/libc/source/newlib/dirent.c b/components/libc/source/newlib/dirent.c index 563617da..a8ef0a83 100644 --- a/components/libc/source/newlib/dirent.c +++ b/components/libc/source/newlib/dirent.c @@ -14,19 +14,19 @@ int closedir(DIR *pdir) { int res = -1; - if (!pdir) + if (!pdir) { errno = EBADF; LOG_E(DIRENT_TAG, "Invalid directory stream descriptor\r\n"); - } + } else { - #ifdef OS_USING_VFS +#ifdef OS_USING_VFS res = vfs_closedir(pdir->priv); - #if defined (OS_USING_SYS_HEAP) +#if defined(OS_USING_SYS_HEAP) os_free(pdir); - #endif - #endif +#endif +#endif } return res; @@ -34,25 +34,25 @@ int closedir(DIR *pdir) DIR *opendir(const char *path) { - DIR *pdir = OS_NULL; + DIR *pdir = OS_NULL; #ifdef OS_USING_VFS void *priv = OS_NULL; - if (OS_NULL == path) + if (OS_NULL == path) { errno = ENOENT; LOG_E(DIRENT_TAG, "Path is null\r\n"); - } - else + } + else { if (OS_NULL != (priv = vfs_opendir(path))) { - #if defined (OS_USING_SYS_HEAP) - pdir = (DIR*)os_malloc(sizeof(DIR)); - #else +#if defined(OS_USING_SYS_HEAP) + pdir = (DIR *)os_malloc(sizeof(DIR)); +#else pdir = OS_NULL; - #endif +#endif if (OS_NULL != pdir) { pdir->priv = priv; @@ -68,16 +68,16 @@ struct dirent *readdir(DIR *pdir) { struct dirent *pdirent = OS_NULL; - if (!pdir) + if (!pdir) { errno = EBADF; LOG_E(DIRENT_TAG, "Invalid directory stream descriptor\r\n"); } - else + else { - #ifdef OS_USING_VFS +#ifdef OS_USING_VFS pdirent = vfs_readdir(pdir->priv); - #endif +#endif } return pdirent; @@ -85,31 +85,31 @@ struct dirent *readdir(DIR *pdir) void rewinddir(DIR *pdir) { - if (!pdir) + if (!pdir) { errno = EBADF; LOG_E(DIRENT_TAG, "Invalid directory stream descriptor\r\n"); - } - else + } + else { - #ifdef OS_USING_VFS +#ifdef OS_USING_VFS vfs_rewinddir(pdir->priv); - #endif +#endif } } void seekdir(DIR *pdir, long ofst) { - if (!pdir) + if (!pdir) { errno = EBADF; LOG_E(DIRENT_TAG, "Invalid directory stream descriptor\r\n"); - } - else + } + else { - #ifdef OS_USING_VFS +#ifdef OS_USING_VFS vfs_seekdir(pdir->priv, ofst); - #endif +#endif } } @@ -117,18 +117,17 @@ long telldir(DIR *pdir) { long res = 0; - if (!pdir) + if (!pdir) { errno = EBADF; LOG_E(DIRENT_TAG, "Invalid directory stream descriptor\r\n"); } - else + else { - #ifdef OS_USING_VFS +#ifdef OS_USING_VFS res = vfs_telldir(pdir->priv); - #endif +#endif } return res; } - diff --git a/components/libc/source/newlib/getcwd.c b/components/libc/source/newlib/getcwd.c index 3ad845b3..ba328503 100644 --- a/components/libc/source/newlib/getcwd.c +++ b/components/libc/source/newlib/getcwd.c @@ -7,7 +7,7 @@ #include "vfs_posix.h" #endif -char* getcwd(char *buf, size_t size) +char *getcwd(char *buf, size_t size) { #ifdef OS_USING_VFS return vfs_getcwd(buf, size); diff --git a/components/libc/source/newlib/ioctl.c b/components/libc/source/newlib/ioctl.c index 884ca56d..b86157bd 100644 --- a/components/libc/source/newlib/ioctl.c +++ b/components/libc/source/newlib/ioctl.c @@ -21,4 +21,3 @@ int ioctl(int fd, unsigned long request, ...) #endif return ret; } - diff --git a/components/libc/source/newlib/libc.c b/components/libc/source/newlib/libc.c index 14da5508..607612d7 100644 --- a/components/libc/source/newlib/libc.c +++ b/components/libc/source/newlib/libc.c @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file libc.c diff --git a/components/libc/source/newlib/poll.c b/components/libc/source/newlib/poll.c index 3a776361..90c5c729 100644 --- a/components/libc/source/newlib/poll.c +++ b/components/libc/source/newlib/poll.c @@ -9,45 +9,45 @@ int poll(struct pollfd fds[], nfds_t nfds, int timeout) { struct vfs_pollfd *pfds = OS_NULL; - int ret = -1; + int ret = -1; unsigned int i = 0; - if (OS_NULL == fds) + if (OS_NULL == fds) { os_kprintf("File Descriptor is NULL\r\n"); - } - else + } + else { - #if defined(OS_USING_VFS) +#if defined(OS_USING_VFS) - #if defined(OS_USING_SYS_HEAP) - pfds = (struct vfs_pollfd*)os_malloc(sizeof(struct vfs_pollfd) * nfds); - #else +#if defined(OS_USING_SYS_HEAP) + pfds = (struct vfs_pollfd *)os_malloc(sizeof(struct vfs_pollfd) * nfds); +#else pfds = OS_NULL; - #endif - if (OS_NULL == pfds) +#endif + if (OS_NULL == pfds) { os_kprintf("Pollfd memory alloc failed\r\n"); } else { - for (i = 0; i < nfds; i++) + for (i = 0; i < nfds; i++) { - pfds[i].fd = fds[i].fd; - pfds[i].events = fds[i].events; + pfds[i].fd = fds[i].fd; + pfds[i].events = fds[i].events; } - ret = vfs_poll(pfds, nfds, timeout); + ret = vfs_poll(pfds, nfds, timeout); - for (i = 0; i < nfds; i++) + for (i = 0; i < nfds; i++) { fds[i].revents = pfds[i].revents; } - #if defined(OS_USING_SYS_HEAP) +#if defined(OS_USING_SYS_HEAP) os_free(pfds); - #endif +#endif } - #endif +#endif } return ret; diff --git a/components/libc/source/newlib/select.c b/components/libc/source/newlib/select.c index 68bba93d..6ef2f9df 100644 --- a/components/libc/source/newlib/select.c +++ b/components/libc/source/newlib/select.c @@ -7,8 +7,7 @@ #include #endif -int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - struct timeval *timeout) +int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) { #if defined(OS_USING_VFS) return vfs_select(nfds, readfds, writefds, exceptfds, timeout); diff --git a/components/libc/source/newlib/stdio.c b/components/libc/source/newlib/stdio.c index e1161831..4a1d0cdc 100644 --- a/components/libc/source/newlib/stdio.c +++ b/components/libc/source/newlib/stdio.c @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file stdio.c @@ -29,17 +29,17 @@ #include #include "libc_ext.h" -#define STDIO_DEVICE_NAME_MAX 32 +#define STDIO_DEVICE_NAME_MAX 32 int fileno(FILE *); -static FILE* std_console = NULL; +static FILE *std_console = NULL; -int libc_stdio_set_console(const char* device_name, int mode) +int libc_stdio_set_console(const char *device_name, int mode) { FILE *fp; char *file_mode; - char name[STDIO_DEVICE_NAME_MAX]; + char name[STDIO_DEVICE_NAME_MAX]; snprintf(name, sizeof(name) - 1, "/dev/%s", device_name); name[STDIO_DEVICE_NAME_MAX - 1] = '\0'; @@ -71,11 +71,11 @@ int libc_stdio_set_console(const char* device_name, int mode) if (mode == O_RDWR) { - _GLOBAL_REENT->_stdin = std_console; + _GLOBAL_REENT->_stdin = std_console; } - else + else { - _GLOBAL_REENT->_stdin = NULL; + _GLOBAL_REENT->_stdin = NULL; } if (mode == O_RDONLY) @@ -111,4 +111,3 @@ int libc_stdio_get_console(void) return -1; } } - diff --git a/components/libc/source/newlib/syscalls.c b/components/libc/source/newlib/syscalls.c index 6e8face0..8c5337e0 100644 --- a/components/libc/source/newlib/syscalls.c +++ b/components/libc/source/newlib/syscalls.c @@ -2,18 +2,18 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file syscalls.c * - * @brief This file provides system call related adaptation, including file system, memory management, time + * @brief This file provides system call related adaptation, including file system, memory management, time * management,etc. * * @revision @@ -59,18 +59,18 @@ int _close_r(struct _reent *ptr, int fd) { #ifndef OS_USING_VFS ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; #else return vfs_close(fd); #endif } -int _execve_r(struct _reent *ptr, const char * name, char *const *argv, char *const *env) +int _execve_r(struct _reent *ptr, const char *name, char *const *argv, char *const *env) { /* Return "not supported". */ ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; } @@ -79,7 +79,7 @@ int _fcntl_r(struct _reent *ptr, int fd, int cmd, int arg) #ifndef OS_USING_VFS /* Return "not supported". */ ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; #else int rc; @@ -93,7 +93,7 @@ int _fork_r(struct _reent *ptr) { /* Return "not supported". */ ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; } @@ -101,7 +101,7 @@ int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat) { #ifndef OS_USING_VFS ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; #else int rc; @@ -114,7 +114,7 @@ int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat) int _getpid_r(struct _reent *ptr) { ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; } @@ -127,7 +127,7 @@ int _isatty_r(struct _reent *ptr, int fd) /* Return "not supported". */ ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; } @@ -135,7 +135,7 @@ int _kill_r(struct _reent *ptr, int pid, int sig) { /* Return "not supported". */ ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; } @@ -143,7 +143,7 @@ int _link_r(struct _reent *ptr, const char *old, const char *new) { /* Return "not supported". */ ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; } @@ -151,7 +151,7 @@ _off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) { #ifndef OS_USING_VFS ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; #else _off_t rc; @@ -165,7 +165,7 @@ int _mkdir_r(struct _reent *ptr, const char *name, int mode) { #ifndef OS_USING_VFS ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; #else int rc; @@ -179,7 +179,7 @@ int _open_r(struct _reent *ptr, const char *file, int flags, int mode) { #ifndef OS_USING_VFS ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; #else int rc; @@ -193,7 +193,7 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) { #ifndef OS_USING_VFS ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; #else _ssize_t rc; @@ -207,7 +207,7 @@ int _rename_r(struct _reent *ptr, const char *old, const char *new) { #ifndef OS_USING_VFS ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; #else int rc; @@ -227,7 +227,7 @@ int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) { #ifndef OS_USING_VFS ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; #else int rc; @@ -241,7 +241,7 @@ _CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms) { /* Return "not supported". */ ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; } @@ -249,7 +249,7 @@ int _unlink_r(struct _reent *ptr, const char *file) { #ifndef OS_USING_VFS ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; #else int rc; @@ -263,11 +263,11 @@ int _wait_r(struct _reent *ptr, int *status) { /* Return "not supported". */ ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; } -#if defined(OS_USING_DEVICE) /* && defined(OS_USING_CONSOLE) */ // TODO: need check +#if defined(OS_USING_DEVICE) /* && defined(OS_USING_CONSOLE) */ // TODO: need check _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) { #ifndef OS_USING_VFS @@ -275,18 +275,18 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) { os_device_t *console; - #ifdef OS_USING_CONSOLE +#ifdef OS_USING_CONSOLE console = os_console_get_device(); - #else +#else console = OS_NULL; - #endif +#endif if (console) { - #ifdef OS_USING_DEVICE_BLOCK +#ifdef OS_USING_DEVICE_BLOCK return os_device_write_block(console, -1, buf, nbytes); - #else +#else return os_device_write_nonblock(console, -1, buf, nbytes); - #endif +#endif } } @@ -300,20 +300,20 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) } #endif -#define MILLISECOND_PER_SECOND 1000UL -#define MICROSECOND_PER_SECOND 1000000UL -#define NANOSECOND_PER_SECOND 1000000000UL +#define MILLISECOND_PER_SECOND 1000UL +#define MICROSECOND_PER_SECOND 1000000UL +#define NANOSECOND_PER_SECOND 1000000000UL -#define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / OS_TICK_PER_SECOND) -#define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / OS_TICK_PER_SECOND) -#define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / OS_TICK_PER_SECOND) +#define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / OS_TICK_PER_SECOND) +#define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / OS_TICK_PER_SECOND) +#define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / OS_TICK_PER_SECOND) struct timeval _timevalue = {0}; #ifdef OS_USING_DEVICE static void libc_system_time_init(void) { - time_t time; - os_tick_t tick; + time_t time; + os_tick_t tick; os_device_t *device; time = 0; @@ -321,16 +321,16 @@ static void libc_system_time_init(void) if (device != OS_NULL) { /* Get realtime seconds. */ - #if defined(OS_USING_RTC) +#if defined(OS_USING_RTC) os_device_control(device, OS_DEVICE_CTRL_RTC_GET_TIME, &time); - #endif +#endif } /* Get tick. */ tick = os_tick_get(); _timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick % OS_TICK_PER_SECOND) * MICROSECOND_PER_TICK; - _timevalue.tv_sec = time - tick / OS_TICK_PER_SECOND - 1; + _timevalue.tv_sec = time - tick / OS_TICK_PER_SECOND - 1; } #endif @@ -351,7 +351,7 @@ int libc_get_time(struct timespec *time) /* Get tick. */ tick = os_tick_get(); - time->tv_sec = _timevalue.tv_sec + tick / OS_TICK_PER_SECOND; + time->tv_sec = _timevalue.tv_sec + tick / OS_TICK_PER_SECOND; time->tv_nsec = (_timevalue.tv_usec + (tick % OS_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000; return 0; @@ -365,7 +365,7 @@ int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp) { if (__tp != OS_NULL) { - __tp->tv_sec = tp.tv_sec; + __tp->tv_sec = tp.tv_sec; __tp->tv_usec = tp.tv_nsec / 1000UL; } @@ -374,23 +374,22 @@ int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp) /* Return "not supported". */ ptr->_errno = ENOTSUP; - errno = ENOTSUP; + errno = ENOTSUP; return -1; } - void *_malloc_r(struct _reent *ptr, size_t size) { - void* result; + void *result; #if defined(OS_USING_SYS_HEAP) - result = (void*)os_malloc(size); + result = (void *)os_malloc(size); #else result = OS_NULL; #endif if (result == OS_NULL) { ptr->_errno = ENOMEM; - errno = ENOMEM; + errno = ENOMEM; } return result; @@ -398,17 +397,17 @@ void *_malloc_r(struct _reent *ptr, size_t size) void *_realloc_r(struct _reent *ptr, void *old, size_t newlen) { - void* result; + void *result; #if defined(OS_USING_SYS_HEAP) - result = (void*)os_realloc(old, newlen); + result = (void *)os_realloc(old, newlen); #else result = OS_NULL; #endif if (result == OS_NULL) { ptr->_errno = ENOMEM; - errno = ENOMEM; + errno = ENOMEM; } return result; @@ -416,17 +415,17 @@ void *_realloc_r(struct _reent *ptr, void *old, size_t newlen) void *_calloc_r(struct _reent *ptr, size_t size, size_t len) { - void* result; + void *result; #if defined(OS_USING_SYS_HEAP) - result = (void*)os_calloc(size, len); + result = (void *)os_calloc(size, len); #else result = OS_NULL; #endif if (result == OS_NULL) { ptr->_errno = ENOMEM; - errno = ENOMEM; + errno = ENOMEM; } return result; @@ -447,7 +446,8 @@ void exit(int status) os_kprintf("task:%s exit with %d\n", os_task_name(os_task_self()), status); OS_ASSERT(0); - while (1); + while (1) + ; } void _system(const char *s) @@ -483,5 +483,6 @@ void abort(void) os_task_suspend(self); } - while (1); + while (1) + ; } diff --git a/components/libc/source/newlib/time.c b/components/libc/source/newlib/time.c index 6f7ef2bf..8d03bd97 100644 --- a/components/libc/source/newlib/time.c +++ b/components/libc/source/newlib/time.c @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file time.c diff --git a/components/molink/api/include/mo_api.h b/components/molink/api/include/mo_api.h index 155207b7..e7ed6195 100644 --- a/components/molink/api/include/mo_api.h +++ b/components/molink/api/include/mo_api.h @@ -75,87 +75,88 @@ *********************************************************************************************************************** */ #ifdef MOLINK_USING_GENERAL_OPS -#define at_test() mo_at_test(mo_get_default()) -#define get_imei(value, len) mo_get_imei(mo_get_default(), value, len) -#define get_imsi(value, len) mo_get_imsi(mo_get_default(), value, len) -#define get_iccid(value, len) mo_get_iccid(mo_get_default(), value, len) -#define get_cfun(fun_lvl) mo_get_cfun(mo_get_default(), fun_lvl) -#define set_cfun(fun_lvl) mo_set_cfun(mo_get_default(), fun_lvl) -#define get_firmware_version(value, len) mo_get_firmware_version(mo_get_default(), value, len) -#define sleep_mode_set(fun_lvl) mo_sleep_mode_set(mo_get_default(), fun_lvl) -#define get_eid(eid, len) mo_get_eid(mo_get_default(), eid, len) -#define get_local_time(l_tm) mo_get_local_time(mo_get_default(), l_tm) +#define at_test() mo_at_test(mo_get_default()) +#define get_imei(value, len) mo_get_imei(mo_get_default(), value, len) +#define get_imsi(value, len) mo_get_imsi(mo_get_default(), value, len) +#define get_iccid(value, len) mo_get_iccid(mo_get_default(), value, len) +#define get_cfun(fun_lvl) mo_get_cfun(mo_get_default(), fun_lvl) +#define set_cfun(fun_lvl) mo_set_cfun(mo_get_default(), fun_lvl) +#define get_firmware_version(value, len) mo_get_firmware_version(mo_get_default(), value, len) +#define sleep_mode_set(fun_lvl) mo_sleep_mode_set(mo_get_default(), fun_lvl) +#define get_eid(eid, len) mo_get_eid(mo_get_default(), eid, len) +#define get_local_time(l_tm) mo_get_local_time(mo_get_default(), l_tm) #endif /* MOLINK_USING_GENERAL_OPS */ #ifdef MOLINK_USING_NETSERV_OPS -#define set_attach(attach_stat) mo_set_attach(mo_get_default(), attach_stat) -#define get_attach(attach_stat) mo_get_attach(mo_get_default(), attach_stat) -#define set_reg(reg_n) mo_set_reg(mo_get_default(), reg_n) -#define get_reg(info) mo_get_reg(mo_get_default(), info) -#define set_cgact(cid, act_stat) mo_set_cgact(mo_get_default(), cid, act_stat) -#define get_cgact(cid, act_stat) mo_get_cgact(mo_get_default(), cid, act_stat) -#define get_csq(rssi, ber) mo_get_csq(mo_get_default(), rssi, ber) -#define get_radio(radio_info) mo_get_radio(mo_get_default(), radio_info) -#define get_cell_info(onepos_cell_info) mo_get_cell_info(mo_get_default(), onepos_cell_info) -#define get_psm(info) mo_get_psm(mo_get_default(), info) -#define set_psm(info) mo_set_psm(mo_get_default(), info) -#define set_edrx_cfg(cfg) mo_set_edrx_cfg(mo_get_default(), cfg) -#define get_edrx_cfg(edrx_local) mo_get_edrx_cfg(mo_get_default(), edrx_local) -#define get_edrx_dynamic(edrx_dynamic) mo_get_edrx_dynamic(mo_get_default(), edrx_dynamic) -#define set_band(band_list, num) mo_set_band(mo_get_default(), band_list, num) -#define set_earfcn(earfcn) mo_set_earfcn(mo_get_default(), earfcn) -#define get_earfcn(earfcn) mo_get_earfcn(mo_get_default(), earfcn) -#define clear_stored_earfcn() mo_clear_stored_earfcn(mo_get_default()) -#define clear_plmn() mo_clear_plmn(mo_get_default()) +#define set_attach(attach_stat) mo_set_attach(mo_get_default(), attach_stat) +#define get_attach(attach_stat) mo_get_attach(mo_get_default(), attach_stat) +#define set_reg(reg_n) mo_set_reg(mo_get_default(), reg_n) +#define get_reg(info) mo_get_reg(mo_get_default(), info) +#define set_cgact(cid, act_stat) mo_set_cgact(mo_get_default(), cid, act_stat) +#define get_cgact(cid, act_stat) mo_get_cgact(mo_get_default(), cid, act_stat) +#define get_csq(rssi, ber) mo_get_csq(mo_get_default(), rssi, ber) +#define get_radio(radio_info) mo_get_radio(mo_get_default(), radio_info) +#define get_cell_info(onepos_cell_info) mo_get_cell_info(mo_get_default(), onepos_cell_info) +#define get_psm(info) mo_get_psm(mo_get_default(), info) +#define set_psm(info) mo_set_psm(mo_get_default(), info) +#define set_edrx_cfg(cfg) mo_set_edrx_cfg(mo_get_default(), cfg) +#define get_edrx_cfg(edrx_local) mo_get_edrx_cfg(mo_get_default(), edrx_local) +#define get_edrx_dynamic(edrx_dynamic) mo_get_edrx_dynamic(mo_get_default(), edrx_dynamic) +#define set_band(band_list, num) mo_set_band(mo_get_default(), band_list, num) +#define set_earfcn(earfcn) mo_set_earfcn(mo_get_default(), earfcn) +#define get_earfcn(earfcn) mo_get_earfcn(mo_get_default(), earfcn) +#define clear_stored_earfcn() mo_clear_stored_earfcn(mo_get_default()) +#define clear_plmn() mo_clear_plmn(mo_get_default()) #endif /* MOLINK_USING_NETSERV_OPS */ #ifdef MOLINK_USING_PING_OPS -#define ping(host, len, timeout, resp) mo_ping(mo_get_default(), host, len, timeout, resp) +#define ping(host, len, timeout, resp) mo_ping(mo_get_default(), host, len, timeout, resp) #endif /* MOLINK_USING_NETSERV_OPS */ #ifdef MOLINK_USING_IFCONFIG_OPS -#define ifconfig() mo_ifconfig(mo_get_default()) -#define get_ipaddr(ip) mo_get_ipaddr(mo_get_default(), ip) -#define set_dnsserver(dns) mo_set_dnsserver(mo_get_default(), dns) -#define get_dnsserver(dns) mo_get_dnsserver(mo_get_default(), dns) +#define ifconfig() mo_ifconfig(mo_get_default()) +#define get_ipaddr(ip) mo_get_ipaddr(mo_get_default(), ip) +#define set_dnsserver(dns) mo_set_dnsserver(mo_get_default(), dns) +#define get_dnsserver(dns) mo_get_dnsserver(mo_get_default(), dns) #endif /* MOLINK_USING_IFCONFIG_OPS */ #ifdef MOLINK_USING_NETCONN_OPS -#define netconn_create(type) mo_netconn_create(mo_get_default(), type) -#define netconn_destroy(netconn) mo_netconn_destroy(mo_get_default(), netconn) +#define netconn_create(type) mo_netconn_create(mo_get_default(), type) +#define netconn_destroy(netconn) mo_netconn_destroy(mo_get_default(), netconn) #ifdef MOLINK_USING_SERVER_MODE -#define netconn_bind(netconn, addr, port) mo_netconn_bind(mo_get_default(), netconn, addr, port) +#define netconn_bind(netconn, addr, port) mo_netconn_bind(mo_get_default(), netconn, addr, port) #endif /* MOLINK_USING_SERVER_MODE */ -#define netconn_connect(netconn, addr, port) mo_netconn_connect(mo_get_default(), netconn, addr, port) +#define netconn_connect(netconn, addr, port) mo_netconn_connect(mo_get_default(), netconn, addr, port) #ifdef MOLINK_USING_UDP -#define netconn_sendto(netconn, addr, port, data, size) \ - mo_netconn_sendto(mo_get_default(), netconn, addr, port, data, size) -#define netconn_recvfrom(netconn, data, size, addr, port, timeout) \ - mo_netconn_recvfrom(mo_get_default(), netconn, data, size, addr, port, timeout) +#define netconn_sendto(netconn, addr, port, data, size) \ + mo_netconn_sendto(mo_get_default(), netconn, addr, port, data, size) +#define netconn_recvfrom(netconn, data, size, addr, port, timeout) \ + mo_netconn_recvfrom(mo_get_default(), netconn, data, size, addr, port, timeout) #endif /* MOLINK_USING_UDP */ #ifdef MOLINK_USING_TCP -#define netconn_send(netconn, data, size) mo_netconn_send(mo_get_default(), netconn, data, size) -#define netconn_recv(netconn, data, size, timeout) mo_netconn_recvfrom(mo_get_default(), netconn, data, size, OS_NULL, OS_NULL, timeout) +#define netconn_send(netconn, data, size) mo_netconn_send(mo_get_default(), netconn, data, size) +#define netconn_recv(netconn, data, size, timeout) \ + mo_netconn_recvfrom(mo_get_default(), netconn, data, size, OS_NULL, OS_NULL, timeout) #endif /* MOLINK_USING_TCP */ #ifdef MOLINK_USING_DNS -#define netconn_gethostbyname(domain_name, addr) mo_netconn_gethostbyname(mo_get_default(), domain_name, addr) +#define netconn_gethostbyname(domain_name, addr) mo_netconn_gethostbyname(mo_get_default(), domain_name, addr) #endif /* MOLINK_USING_DNS */ #endif /* MOLINK_USING_NETCONN_OPS */ #ifdef MOLINK_USING_WIFI_OPS -#define wifi_set_mode(mode) mo_wifi_set_mode(mo_get_default(), mode) -#define wifi_get_mode() mo_wifi_get_mode(mo_get_default()) -#define wifi_get_stat() mo_wifi_get_stat(mo_get_default()) -#define wifi_scan_info(ssid, scan_result) mo_wifi_scan_info(mo_get_default(), ssid, scan_result) -#define wifi_scan_info_free(scan_result) mo_wifi_scan_info_free(scan_result) -#define wifi_connect_ap(ssid, password) mo_wifi_connect_ap(mo_get_default(), ssid, password) -#define wifi_disconnect_ap() mo_wifi_disconnect_ap(mo_get_default()) +#define wifi_set_mode(mode) mo_wifi_set_mode(mo_get_default(), mode) +#define wifi_get_mode() mo_wifi_get_mode(mo_get_default()) +#define wifi_get_stat() mo_wifi_get_stat(mo_get_default()) +#define wifi_scan_info(ssid, scan_result) mo_wifi_scan_info(mo_get_default(), ssid, scan_result) +#define wifi_scan_info_free(scan_result) mo_wifi_scan_info_free(scan_result) +#define wifi_connect_ap(ssid, password) mo_wifi_connect_ap(mo_get_default(), ssid, password) +#define wifi_disconnect_ap() mo_wifi_disconnect_ap(mo_get_default()) #endif /* MOLINK_USING_WIFI_OPS */ #ifdef MOLINK_USING_PPP_OPS -#define ppp_init() mo_ppp_init(mo_get_default()) -#define ppp_dial() mo_ppp_dial(mo_get_default()) -#define ppp_exit() mo_ppp_exit(mo_get_default()) +#define ppp_init() mo_ppp_init(mo_get_default()) +#define ppp_dial() mo_ppp_dial(mo_get_default()) +#define ppp_exit() mo_ppp_exit(mo_get_default()) #endif /* MOLINK_USING_PPP_OPS */ #ifdef MOLINK_USING_ONENET_NB_OPS @@ -171,19 +172,29 @@ mo_onenetnb_parameterrsp(mo_get_default(), timeout, resp, format, __VA_ARGS__) #define onenetnb_get_write(timeout, resp, format, ...) \ mo_onenetnb_get_write(mo_get_default(), timeout, resp, format, __VA_ARGS__) -#define onenetnb_create(timeout, resp, format, ...) mo_onenetnb_create(mo_get_default(), timeout, resp, format, __VA_ARGS__) -#define onenetnb_createex(timeout, resp, format, ...) mo_onenetnb_createex(mo_get_default(), timeout, resp, format, __VA_ARGS__) -#define onenetnb_delete(timeout, resp, format, ...) mo_onenetnb_delete(mo_get_default(), timeout, resp, format, __VA_ARGS__) -#define onenetnb_addobj(timeout, resp, format, ...) mo_onenetnb_addobj(mo_get_default(), timeout, resp, format, __VA_ARGS__) -#define onenetnb_delobj(timeout, resp, format, ...) mo_onenetnb_delobj(mo_get_default(), timeout, resp, format, __VA_ARGS__) -#define onenetnb_nmi(timeout, resp, format, ...) mo_onenetnb_nmi(mo_get_default(), timeout, resp, format, __VA_ARGS__) -#define onenetnb_open(timeout, resp, format, ...) mo_onenetnb_open(mo_get_default(), timeout, resp, format, __VA_ARGS__) -#define onenetnb_close(timeout, resp, format, ...) mo_onenetnb_close(mo_get_default(), timeout, resp, format, __VA_ARGS__) -#define onenetnb_readrsp(timeout, resp, format, ...) mo_onenetnb_readrsp(mo_get_default(), timeout, resp, format, __VA_ARGS__) -#define onenetnb_writersp(timeout, resp, format, ...) mo_onenetnb_writersp(mo_get_default(), timeout, resp, format, __VA_ARGS__) -#define onenetnb_notify(timeout, resp, format, ...) mo_onenetnb_notify(mo_get_default(), timeout, resp, format, __VA_ARGS__) -#define onenetnb_update(timeout, resp, format, ...) mo_onenetnb_update(mo_get_default(), timeout, resp, format, __VA_ARGS__) -#define onenetnb_cb_register(user_callbacks) mo_onenetnb_cb_register(mo_get_default(), user_callbacks) +#define onenetnb_create(timeout, resp, format, ...) \ + mo_onenetnb_create(mo_get_default(), timeout, resp, format, __VA_ARGS__) +#define onenetnb_createex(timeout, resp, format, ...) \ + mo_onenetnb_createex(mo_get_default(), timeout, resp, format, __VA_ARGS__) +#define onenetnb_delete(timeout, resp, format, ...) \ + mo_onenetnb_delete(mo_get_default(), timeout, resp, format, __VA_ARGS__) +#define onenetnb_addobj(timeout, resp, format, ...) \ + mo_onenetnb_addobj(mo_get_default(), timeout, resp, format, __VA_ARGS__) +#define onenetnb_delobj(timeout, resp, format, ...) \ + mo_onenetnb_delobj(mo_get_default(), timeout, resp, format, __VA_ARGS__) +#define onenetnb_nmi(timeout, resp, format, ...) mo_onenetnb_nmi(mo_get_default(), timeout, resp, format, __VA_ARGS__) +#define onenetnb_open(timeout, resp, format, ...) mo_onenetnb_open(mo_get_default(), timeout, resp, format, __VA_ARGS__) +#define onenetnb_close(timeout, resp, format, ...) \ + mo_onenetnb_close(mo_get_default(), timeout, resp, format, __VA_ARGS__) +#define onenetnb_readrsp(timeout, resp, format, ...) \ + mo_onenetnb_readrsp(mo_get_default(), timeout, resp, format, __VA_ARGS__) +#define onenetnb_writersp(timeout, resp, format, ...) \ + mo_onenetnb_writersp(mo_get_default(), timeout, resp, format, __VA_ARGS__) +#define onenetnb_notify(timeout, resp, format, ...) \ + mo_onenetnb_notify(mo_get_default(), timeout, resp, format, __VA_ARGS__) +#define onenetnb_update(timeout, resp, format, ...) \ + mo_onenetnb_update(mo_get_default(), timeout, resp, format, __VA_ARGS__) +#define onenetnb_cb_register(user_callbacks) mo_onenetnb_cb_register(mo_get_default(), user_callbacks) #endif /* MOLINK_USING_ONENET_NB_OPS */ #endif /* __MO_API_H__ */ diff --git a/components/molink/api/include/mo_common.h b/components/molink/api/include/mo_common.h index 0d81faad..2d2ee7a4 100644 --- a/components/molink/api/include/mo_common.h +++ b/components/molink/api/include/mo_common.h @@ -39,7 +39,7 @@ mo_object_t *mo_get(void); #elif defined(MOLINK_USING_MULTI_MODULES) mo_object_t *mo_get_by_name(const char *name); mo_object_t *mo_get_default(void); -void mo_set_default(mo_object_t *self); +void mo_set_default(mo_object_t *self); #endif #ifdef __cplusplus diff --git a/components/molink/api/include/mo_factory.h b/components/molink/api/include/mo_factory.h index fd4ba236..d9214a9d 100644 --- a/components/molink/api/include/mo_factory.h +++ b/components/molink/api/include/mo_factory.h @@ -31,10 +31,10 @@ extern "C" { #endif /* __cplusplus */ typedef mo_object_t *(*mo_create_fn)(const char *name, void *parser_config); -typedef os_err_t (*mo_destory_fn)(mo_object_t *self); +typedef os_err_t (*mo_destory_fn)(mo_object_t *self); mo_object_t *mo_create(const char *name, mo_type_t type, void *parser_config); -os_err_t mo_destroy(mo_object_t *self, mo_type_t type); +os_err_t mo_destroy(mo_object_t *self, mo_type_t type); #ifdef __cplusplus } diff --git a/components/molink/api/include/mo_general.h b/components/molink/api/include/mo_general.h index 9cf80f7b..6ddb6cb7 100644 --- a/components/molink/api/include/mo_general.h +++ b/components/molink/api/include/mo_general.h @@ -34,9 +34,9 @@ extern "C" { #endif /* __cplusplus */ -#define MO_IMEI_LEN (15) /* International Mobile Equipment Identity */ -#define MO_IMSI_LEN (15) /* International Mobile Subscriber Identity */ -#define MO_ICCID_LEN (20) /* Integrate Circuit Card Identity */ +#define MO_IMEI_LEN (15) /* International Mobile Equipment Identity */ +#define MO_IMSI_LEN (15) /* International Mobile Subscriber Identity */ +#define MO_ICCID_LEN (20) /* Integrate Circuit Card Identity */ /** *********************************************************************************************************************** @@ -47,8 +47,8 @@ extern "C" { */ typedef struct mo_firmware_version { - os_size_t line_counts; /* The number of lines of firmware version information */ - char **ver_info; /* The text of the firmware version information */ + os_size_t line_counts; /* The number of lines of firmware version information */ + char **ver_info; /* The text of the firmware version information */ } mo_firmware_version_t; /** @@ -79,7 +79,7 @@ os_err_t mo_get_iccid(mo_object_t *self, char *value, os_size_t len); os_err_t mo_get_cfun(mo_object_t *self, os_uint8_t *fun_lvl); os_err_t mo_set_cfun(mo_object_t *self, os_uint8_t fun_lvl); os_err_t mo_get_firmware_version(mo_object_t *self, mo_firmware_version_t *version); -void mo_get_firmware_version_free(mo_firmware_version_t *version); +void mo_get_firmware_version_free(mo_firmware_version_t *version); os_err_t mo_get_eid(mo_object_t *self, char *eid, os_size_t len); os_err_t mo_gm_time(mo_object_t *self, struct tm *l_tm); os_err_t mo_time(mo_object_t *self, time_t *timep); diff --git a/components/molink/api/include/mo_mqttc.h b/components/molink/api/include/mo_mqttc.h index e0cec1ba..d15c8f80 100644 --- a/components/molink/api/include/mo_mqttc.h +++ b/components/molink/api/include/mo_mqttc.h @@ -83,7 +83,7 @@ typedef enum mqttc_qos */ typedef struct mqttc_string { - char *data; + char *data; os_size_t len; } mqttc_string_t; @@ -98,8 +98,8 @@ typedef struct mqttc_will_opts { mqttc_string_t topic_name; /* The LWT topic to which the LWT message will be published */ mqttc_string_t message; /* The LWT payload */ - mqttc_qos_t qos; /* The quality of service setting for the LWT message */ - os_uint8_t retained; /* The retained flag for the LWT message */ + mqttc_qos_t qos; /* The quality of service setting for the LWT message */ + os_uint8_t retained; /* The retained flag for the LWT message */ } mqttc_will_opts_t; /** @@ -111,12 +111,12 @@ typedef struct mqttc_will_opts */ typedef struct mqttc_conn_opts { - mqttc_string_t client_id; /* The MQTT client identifier string */ + mqttc_string_t client_id; /* The MQTT client identifier string */ - os_uint8_t mqtt_version; /* The Version of MQTT to be used. 3 = 3.1 4 = 3.1.1 */ - os_uint32_t keep_alive; /* The keep alive time, unit second */ - os_uint8_t clean_session; /* The flag of clean_session option */ - os_uint8_t will_flag; /* The flag of will option */ + os_uint8_t mqtt_version; /* The Version of MQTT to be used. 3 = 3.1 4 = 3.1.1 */ + os_uint32_t keep_alive; /* The keep alive time, unit second */ + os_uint8_t clean_session; /* The flag of clean_session option */ + os_uint8_t will_flag; /* The flag of will option */ mqttc_will_opts_t will_opts; /* The options of will */ @@ -133,10 +133,10 @@ typedef struct mqttc_conn_opts */ typedef struct mqttc_create_opts { - mqttc_string_t address; /* The MQTT server address */ - os_uint16_t port; /* The MQTT server port */ - os_uint32_t command_timeout; /* The MQTT client ACK timeout, unit ms*/ - os_size_t max_msgs; /* The max number of messages.*/ + mqttc_string_t address; /* The MQTT server address */ + os_uint16_t port; /* The MQTT server port */ + os_uint32_t command_timeout; /* The MQTT client ACK timeout, unit ms*/ + os_size_t max_msgs; /* The max number of messages.*/ } mqttc_create_opts_t; /** @@ -148,12 +148,12 @@ typedef struct mqttc_create_opts */ typedef struct mqttc_msg { - mqttc_qos_t qos; /* The quality of service setting for the message */ + mqttc_qos_t qos; /* The quality of service setting for the message */ - os_uint8_t retained; /* The retained flag for the message */ - os_uint8_t dup; /* The dup flag for the message*/ + os_uint8_t retained; /* The retained flag for the message */ + os_uint8_t dup; /* The dup flag for the message*/ - void *payload; /* The data of the message */ + void *payload; /* The data of the message */ os_size_t payload_len; /* The length of data */ } mqttc_msg_t; @@ -166,7 +166,7 @@ typedef struct mqttc_msg */ typedef struct mqttc_msg_data { - mqttc_msg_t message; + mqttc_msg_t message; mqttc_string_t topic_name; } mqttc_msg_data_t; @@ -177,7 +177,7 @@ typedef struct mqttc_msg_data * @brief molink mqtt client message handler *********************************************************************************************************************** */ -typedef void (*mqttc_msg_handler_t)(mqttc_msg_data_t*); +typedef void (*mqttc_msg_handler_t)(mqttc_msg_data_t *); /** *********************************************************************************************************************** @@ -188,32 +188,32 @@ typedef void (*mqttc_msg_handler_t)(mqttc_msg_data_t*); */ typedef struct mo_mqttc { - mo_object_t *module; /* The module used by the MQTT client */ + mo_object_t *module; /* The module used by the MQTT client */ - os_uint32_t mqttc_id; /* The MQTT client identity */ + os_uint32_t mqttc_id; /* The MQTT client identity */ - mqttc_stat_t stat; /* The MQTT client status */ + mqttc_stat_t stat; /* The MQTT client status */ - char *address; /* The MQTT server address */ - os_uint16_t port; /* The MQTT server port */ + char *address; /* The MQTT server address */ + os_uint16_t port; /* The MQTT server port */ os_uint32_t keep_alive; /* The keep alive time, unit second */ os_uint32_t command_timeout; /* The MQTT client ACK timeout, unit ms*/ - os_uint8_t clean_session; /* The flag of clean_session option */ + os_uint8_t clean_session; /* The flag of clean_session option */ struct mqtt_msg_handlers { - const char *topic_filter; + const char *topic_filter; mqttc_msg_handler_t handler; - } msg_handlers[MQTTC_MAX_MESSAGE_HANDLERS]; /* The MQTT client handlers */ - - mqttc_msg_handler_t default_handler; /* The MQTT client default handlers */ + } msg_handlers[MQTTC_MAX_MESSAGE_HANDLERS]; /* The MQTT client handlers */ + + mqttc_msg_handler_t default_handler; /* The MQTT client default handlers */ - os_mq_t mq; /* The queue used to receive the data */ + os_mq_t mq; /* The queue used to receive the data */ #if defined(MOLINK_USING_MQTTC_TASK) os_mutex_t mutex; - os_task_t *task; /* The thread that receives data and executes handler */ + os_task_t *task; /* The thread that receives data and executes handler */ #endif } mo_mqttc_t; @@ -228,30 +228,27 @@ typedef struct mo_mqttc typedef struct mo_mqttc_ops { mo_mqttc_t *(*create)(mo_object_t *module, mqttc_create_opts_t *create_opts); - os_err_t (*connect)(mo_mqttc_t *client, mqttc_conn_opts_t *conn_opts); - os_err_t (*publish)(mo_mqttc_t *client, const char *topic_filter, mqttc_msg_t *msg); - os_err_t (*subscribe)(mo_mqttc_t *client, const char *topic_filter, mqttc_qos_t qos); - os_err_t (*unsubscribe)(mo_mqttc_t *client, const char *topic_filter); - os_err_t (*disconnect)(mo_mqttc_t *client); - os_err_t (*destroy)(mo_mqttc_t *client); + os_err_t (*connect)(mo_mqttc_t *client, mqttc_conn_opts_t *conn_opts); + os_err_t (*publish)(mo_mqttc_t *client, const char *topic_filter, mqttc_msg_t *msg); + os_err_t (*subscribe)(mo_mqttc_t *client, const char *topic_filter, mqttc_qos_t qos); + os_err_t (*unsubscribe)(mo_mqttc_t *client, const char *topic_filter); + os_err_t (*disconnect)(mo_mqttc_t *client); + os_err_t (*destroy)(mo_mqttc_t *client); } mo_mqttc_ops_t; mo_mqttc_t *mo_mqttc_create(mo_object_t *module, mqttc_create_opts_t *create_opts); -os_err_t mo_mqttc_connect(mo_mqttc_t *client, mqttc_conn_opts_t *conn_opts); -os_err_t mo_mqttc_publish(mo_mqttc_t *client, const char *topic_filter, mqttc_msg_t *msg); -os_err_t mo_mqttc_set_msg_handler(mo_mqttc_t *client, const char *topic_filter, mqttc_msg_handler_t handler); -os_err_t mo_mqttc_subscribe(mo_mqttc_t *client, - const char *topic_filter, - mqttc_qos_t qos, - mqttc_msg_handler_t handler); -os_err_t mo_mqttc_unsubscribe(mo_mqttc_t *client, const char *topic_filter); -os_err_t mo_mqttc_disconnect(mo_mqttc_t *client); -os_bool_t mo_mqttc_isconnect(mo_mqttc_t *client); -os_err_t mo_mqttc_destroy(mo_mqttc_t *client); -os_err_t mo_mqttc_yield(mo_mqttc_t *client, os_uint32_t timeout_ms); +os_err_t mo_mqttc_connect(mo_mqttc_t *client, mqttc_conn_opts_t *conn_opts); +os_err_t mo_mqttc_publish(mo_mqttc_t *client, const char *topic_filter, mqttc_msg_t *msg); +os_err_t mo_mqttc_set_msg_handler(mo_mqttc_t *client, const char *topic_filter, mqttc_msg_handler_t handler); +os_err_t mo_mqttc_subscribe(mo_mqttc_t *client, const char *topic_filter, mqttc_qos_t qos, mqttc_msg_handler_t handler); +os_err_t mo_mqttc_unsubscribe(mo_mqttc_t *client, const char *topic_filter); +os_err_t mo_mqttc_disconnect(mo_mqttc_t *client); +os_bool_t mo_mqttc_isconnect(mo_mqttc_t *client); +os_err_t mo_mqttc_destroy(mo_mqttc_t *client); +os_err_t mo_mqttc_yield(mo_mqttc_t *client, os_uint32_t timeout_ms); #if defined(MOLINK_USING_MQTTC_TASK) -os_err_t mo_mqttc_start_task(mo_mqttc_t *client); +os_err_t mo_mqttc_start_task(mo_mqttc_t *client); #endif #ifdef __cplusplus diff --git a/components/molink/api/include/mo_mqttc_priv.h b/components/molink/api/include/mo_mqttc_priv.h index 1474990d..2acf1173 100644 --- a/components/molink/api/include/mo_mqttc_priv.h +++ b/components/molink/api/include/mo_mqttc_priv.h @@ -33,8 +33,8 @@ extern "C" { #endif /* __cplusplus */ os_err_t mo_mqttc_data_queue_push_notice(mo_mqttc_t *client, mqttc_msg_data_t *msg); -void mo_mqttc_data_queue_disconnect_notice(mo_mqttc_t *client); -void mo_mqttc_data_queue_destroy(mo_mqttc_t *client); +void mo_mqttc_data_queue_disconnect_notice(mo_mqttc_t *client); +void mo_mqttc_data_queue_destroy(mo_mqttc_t *client); #ifdef __cplusplus } diff --git a/components/molink/api/include/mo_netconn.h b/components/molink/api/include/mo_netconn.h index b2a5d063..ef70d852 100644 --- a/components/molink/api/include/mo_netconn.h +++ b/components/molink/api/include/mo_netconn.h @@ -71,15 +71,15 @@ typedef enum mo_netconn_type /** *********************************************************************************************************************** * Used to inform the callback function about changes - * - * RCVPLUS events say: Safe to perform a potentially blocking call call once more. + * + * RCVPLUS events say: Safe to perform a potentially blocking call call once more. * They are counted in sockets - three RCVPLUS events for accept mbox means you are safe * to call netconn_accept 3 times without being blocked. * Same thing for receive mbox. - * + * * RCVMINUS events say: Your call to to a possibly blocking function is "acknowledged". * Socket implementation decrements the counter. - * + * * For TX, there is no need to count, its merely a flag. SENDPLUS means you may send something. * SENDPLUS occurs when enough data was delivered to peer so netconn_send() can be called again. * A SENDMINUS event occurs when the next call to a netconn_send() would be blocking. @@ -117,12 +117,12 @@ typedef struct mo_netconn mo_netconn_stat_t stat; mo_netconn_type_t type; - - ip_addr_t remote_ip; + + ip_addr_t remote_ip; os_uint16_t remote_port; os_uint16_t local_port; - - os_mq_t *mq; + + os_mq_t *mq; } mo_netconn_t; @@ -135,7 +135,7 @@ typedef struct mo_netconn */ typedef struct mo_netconn_info { - os_uint32_t netconn_nums; + os_uint32_t netconn_nums; const mo_netconn_t *netconn_array; } mo_netconn_info_t; @@ -148,9 +148,9 @@ typedef struct mo_netconn_info */ typedef struct mo_notconn_msg { - ip_addr_t addr; + ip_addr_t addr; os_uint16_t port; - char *data; + char *data; os_uint32_t data_len; } mo_notconn_msg_t; @@ -164,36 +164,46 @@ typedef struct mo_notconn_msg typedef struct mo_netconn_ops { mo_netconn_t *(*create)(mo_object_t *module, mo_netconn_type_t type); - os_err_t (*destroy)(mo_object_t *module, mo_netconn_t *netconn); - os_err_t (*connect)(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); - os_err_t (*bind)(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); - os_size_t (*sendto)(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t remote_ip, os_uint16_t remote_port, const char *data, os_size_t size); - os_size_t (*send)(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); - os_err_t (*gethostbyname)(mo_object_t *module, const char *domain_name, ip_addr_t *addr); - os_err_t (*get_info)(mo_object_t *module, mo_netconn_info_t *info); + os_err_t (*destroy)(mo_object_t *module, mo_netconn_t *netconn); + os_err_t (*connect)(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); + os_err_t (*bind)(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); + os_size_t (*sendto)(mo_object_t *module, + mo_netconn_t *netconn, + ip_addr_t remote_ip, + os_uint16_t remote_port, + const char *data, + os_size_t size); + os_size_t (*send)(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); + os_err_t (*gethostbyname)(mo_object_t *module, const char *domain_name, ip_addr_t *addr); + os_err_t (*get_info)(mo_object_t *module, mo_netconn_info_t *info); } mo_netconn_ops_t; mo_netconn_t *mo_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t mo_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t mo_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); #ifdef MOLINK_USING_SERVER_MODE -os_err_t mo_netconn_bind(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_err_t mo_netconn_bind(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); #endif /* MOLINK_USING_SERVER_MODE */ -os_err_t mo_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_err_t mo_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); #ifdef MOLINK_USING_UDP -os_size_t mo_netconn_sendto(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t remote_ip, os_uint16_t remote_port, const char *data, os_size_t size); +os_size_t mo_netconn_sendto(mo_object_t *module, + mo_netconn_t *netconn, + ip_addr_t remote_ip, + os_uint16_t remote_port, + const char *data, + os_size_t size); #endif /* MOLINK_USING_UDP */ #ifdef MOLINK_USING_TCP -os_size_t mo_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_size_t mo_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #endif /* MOLINK_USING_TCP */ -os_err_t mo_netconn_recvfrom(mo_object_t *module, - mo_netconn_t *netconn, - void **data, - os_size_t *size, - ip_addr_t *addr, - os_uint16_t *port, - os_tick_t timeout); +os_err_t mo_netconn_recvfrom(mo_object_t *module, + mo_netconn_t *netconn, + void **data, + os_size_t *size, + ip_addr_t *addr, + os_uint16_t *port, + os_tick_t timeout); #ifdef MOLINK_USING_DNS -os_err_t mo_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr); +os_err_t mo_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr); #endif /** @@ -201,12 +211,15 @@ os_err_t mo_netconn_gethostbyname(mo_object_t *module, const char *domain_n * @note These functions are called by the molink component *********************************************************************************************************************** */ -os_err_t mo_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); -void mo_netconn_pasv_close_notice(mo_netconn_t *netconn); -void mo_wifi_netconn_data_recv_notice(mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port, char *data, os_size_t size); -void mo_netconn_data_recv_notice(mo_netconn_t *netconn, char *data, os_size_t size); -void mo_netconn_mq_destroy(os_mq_t *mq); - +os_err_t mo_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +void mo_netconn_pasv_close_notice(mo_netconn_t *netconn); +void mo_wifi_netconn_data_recv_notice(mo_netconn_t *netconn, + ip_addr_t addr, + os_uint16_t port, + char *data, + os_size_t size); +void mo_netconn_data_recv_notice(mo_netconn_t *netconn, char *data, os_size_t size); +void mo_netconn_mq_destroy(os_mq_t *mq); #ifdef __cplusplus } diff --git a/components/molink/api/include/mo_netserv.h b/components/molink/api/include/mo_netserv.h index 6c993e06..9d38b436 100644 --- a/components/molink/api/include/mo_netserv.h +++ b/components/molink/api/include/mo_netserv.h @@ -33,12 +33,12 @@ extern "C" { #endif /* __cplusplus */ -#define CELL_ID_MAX_LEN (28) +#define CELL_ID_MAX_LEN (28) -#define PSM_TIMER_MAX_STR_LEN (9) /* 3GPP timer len 8 plus 1 byte for character array's '\0' */ -#define REG_TAC_MAX_STR_LEN (5) /* 2 bytes hex plus 1 byte for character array's '\0' */ -#define REG_CELL_ID_MAX_STR_LEN (9) /* 4 bytes hex plus 1 byte for character array's '\0' */ -#define DRX_EXTEND_MAX_STR_LEN (5) /* Extended DRX parameters information element string len */ +#define PSM_TIMER_MAX_STR_LEN (9) /* 3GPP timer len 8 plus 1 byte for character array's '\0' */ +#define REG_TAC_MAX_STR_LEN (5) /* 2 bytes hex plus 1 byte for character array's '\0' */ +#define REG_CELL_ID_MAX_STR_LEN (9) /* 4 bytes hex plus 1 byte for character array's '\0' */ +#define DRX_EXTEND_MAX_STR_LEN (5) /* Extended DRX parameters information element string len */ /** *********************************************************************************************************************** @@ -78,14 +78,14 @@ typedef enum pdp_context_state typedef struct eps_registration_info { os_uint8_t reg_n; - os_uint8_t reg_stat; /* EPS registration status */ - char tac[REG_TAC_MAX_STR_LEN]; /* tracking area code, HEX string */ - char cell_id[REG_CELL_ID_MAX_STR_LEN]; /* cell ID, HEX string */ - os_uint8_t act; /* Access technology of the registered network */ - os_uint8_t cause_type; /* indicates the type of */ - os_uint8_t reject_cause; /* contains the cause of the failed registration */ - char active_time[PSM_TIMER_MAX_STR_LEN]; /* GPRS Timer 2 IE in 3GPP TS 24.008 Table 10.5.163 */ - char periodic_tau[PSM_TIMER_MAX_STR_LEN]; /* GPRS Timer 3 IE in 3GPP TS 24.008 Table 10.5.163a */ + os_uint8_t reg_stat; /* EPS registration status */ + char tac[REG_TAC_MAX_STR_LEN]; /* tracking area code, HEX string */ + char cell_id[REG_CELL_ID_MAX_STR_LEN]; /* cell ID, HEX string */ + os_uint8_t act; /* Access technology of the registered network */ + os_uint8_t cause_type; /* indicates the type of */ + os_uint8_t reject_cause; /* contains the cause of the failed registration */ + char active_time[PSM_TIMER_MAX_STR_LEN]; /* GPRS Timer 2 IE in 3GPP TS 24.008 Table 10.5.163 */ + char periodic_tau[PSM_TIMER_MAX_STR_LEN]; /* GPRS Timer 3 IE in 3GPP TS 24.008 Table 10.5.163a */ } eps_reg_info_t; /** @@ -115,12 +115,13 @@ typedef struct radio_info * @brief struct that holds molink module cell information, belongs to onepos_cell_info_t *********************************************************************************************************************** */ -typedef struct{ +typedef struct +{ os_uint32_t mnc; os_uint32_t mcc; os_uint32_t lac; os_uint32_t cid; - os_int32_t ss; + os_int32_t ss; // os_uint32_t ta; } cell_info_t; @@ -131,13 +132,13 @@ typedef struct{ * @brief struct that holds molink module mo_get_cell_info return information *********************************************************************************************************************** */ -typedef struct{ - os_uint32_t cell_num; - os_uint8_t net_type; +typedef struct +{ + os_uint32_t cell_num; + os_uint8_t net_type; cell_info_t *cell_info; } onepos_cell_info_t; - /** *********************************************************************************************************************** * @struct mo_psm_mode_t @@ -147,10 +148,10 @@ typedef struct{ */ typedef enum mo_psm_mode { - MO_PSM_DISABLE = 0, /* Disable the use of PSM. */ - MO_PSM_ENABLE, /* Enable the use of PSM. */ - MO_PSM_DISABLE_RESET, /* Disable the use of PSM & - reset to the manufacturer specific default values. */ + MO_PSM_DISABLE = 0, /* Disable the use of PSM. */ + MO_PSM_ENABLE, /* Enable the use of PSM. */ + MO_PSM_DISABLE_RESET, /* Disable the use of PSM & + reset to the manufacturer specific default values. */ } mo_psm_mode_t; /** @@ -162,11 +163,11 @@ typedef enum mo_psm_mode */ typedef struct mo_psm_info { - mo_psm_mode_t psm_mode; /* See mo_psm_mode_t */ - char periodic_rau[PSM_TIMER_MAX_STR_LEN]; /* Reserved */ - char gprs_ready_timer[PSM_TIMER_MAX_STR_LEN]; /* Reserved */ - char periodic_tau[PSM_TIMER_MAX_STR_LEN]; /* See GPRS Timer (3GPP TS 24.008) */ - char active_time[PSM_TIMER_MAX_STR_LEN]; /* See GPRS Timer (3GPP TS 24.008) */ + mo_psm_mode_t psm_mode; /* See mo_psm_mode_t */ + char periodic_rau[PSM_TIMER_MAX_STR_LEN]; /* Reserved */ + char gprs_ready_timer[PSM_TIMER_MAX_STR_LEN]; /* Reserved */ + char periodic_tau[PSM_TIMER_MAX_STR_LEN]; /* See GPRS Timer (3GPP TS 24.008) */ + char active_time[PSM_TIMER_MAX_STR_LEN]; /* See GPRS Timer (3GPP TS 24.008) */ } mo_psm_info_t; /** @@ -178,11 +179,11 @@ typedef struct mo_psm_info */ typedef enum edrx_mode { - MO_EDRX_DISABLE = 0, /* Disable the use of eDRX */ - MO_EDRX_ENABLE, /* Enable the use of eDRX */ - MO_EDRX_ENABLE_WITH_URC, /* Enable the use of eDRX and enable the unsolicited result code */ - MO_EDRX_RESET, /* Disable the use of eDRX and discard all parameters for eDRX or, - if available,reset to the manufacturer specific default values */ + MO_EDRX_DISABLE = 0, /* Disable the use of eDRX */ + MO_EDRX_ENABLE, /* Enable the use of eDRX */ + MO_EDRX_ENABLE_WITH_URC, /* Enable the use of eDRX and enable the unsolicited result code */ + MO_EDRX_RESET, /* Disable the use of eDRX and discard all parameters for eDRX or, + if available,reset to the manufacturer specific default values */ } edrx_mode_t; /** @@ -194,12 +195,12 @@ typedef enum edrx_mode */ typedef enum edrx_act_type { - MO_EDRX_NOT_USING = 0, /* Access technology is not using eDRX. Only use in URC. */ - MO_EDRX_EC_GSM_IOT, /* EC-GSM-IoT (A/Gb mode) */ - MO_EDRX_GSM, /* GSM (A/Gb mode) */ - MO_EDRX_UTRAN, /* UTRAN (Iu mode) */ - MO_EDRX_E_UTRAN_WB_S1, /* E-UTRAN (WB-S1 mode) */ - MO_EDRX_E_UTRAN_NB_S1, /* E-UTRAN (NB-S1 mode) */ + MO_EDRX_NOT_USING = 0, /* Access technology is not using eDRX. Only use in URC. */ + MO_EDRX_EC_GSM_IOT, /* EC-GSM-IoT (A/Gb mode) */ + MO_EDRX_GSM, /* GSM (A/Gb mode) */ + MO_EDRX_UTRAN, /* UTRAN (Iu mode) */ + MO_EDRX_E_UTRAN_WB_S1, /* E-UTRAN (WB-S1 mode) */ + MO_EDRX_E_UTRAN_NB_S1, /* E-UTRAN (NB-S1 mode) */ } edrx_act_type_t; /** @@ -211,10 +212,11 @@ typedef enum edrx_act_type */ typedef struct mo_edrx { - edrx_act_type_t act_type; /* Access technology type */ - char req_edrx_value[DRX_EXTEND_MAX_STR_LEN]; /* Requested eDRX value, sub-clause 10.5.5.32 of 3GPP TS 24.008 */ - char nw_edrx_value[DRX_EXTEND_MAX_STR_LEN]; /* NW provided eDRX value, sub-clause 10.5.5.32 of 3GPP TS 24.008 */ - char paging_time_window[DRX_EXTEND_MAX_STR_LEN];/* Paging time window, see sub-clause 10.5.5.32 of 3GPP TS 24.008 */ + edrx_act_type_t act_type; /* Access technology type */ + char req_edrx_value[DRX_EXTEND_MAX_STR_LEN]; /* Requested eDRX value, sub-clause 10.5.5.32 of 3GPP TS 24.008 */ + char nw_edrx_value[DRX_EXTEND_MAX_STR_LEN]; /* NW provided eDRX value, sub-clause 10.5.5.32 of 3GPP TS 24.008 */ + char + paging_time_window[DRX_EXTEND_MAX_STR_LEN]; /* Paging time window, see sub-clause 10.5.5.32 of 3GPP TS 24.008 */ } mo_edrx_t; /** @@ -226,8 +228,8 @@ typedef struct mo_edrx */ typedef struct mo_edrx_cfg { - edrx_mode_t mode; /* mode that the use of eDRX in the UE */ - mo_edrx_t edrx; + edrx_mode_t mode; /* mode that the use of eDRX in the UE */ + mo_edrx_t edrx; } mo_edrx_cfg_t; /** @@ -239,10 +241,10 @@ typedef struct mo_edrx_cfg */ typedef struct mo_earfcn { - os_uint8_t mode; /* Search(lock) mode */ - os_uint32_t earfcn; /* On witch EARFCN to lock; range:Quectel[1-65535] OneMo[0-262143] */ - os_uint16_t pci; /* Physical cell ID; range[0-503]/[0x00-0x1F7] */ - os_uint8_t earfcn_offset; /* Requested EARFCN offset; Only valid on OneMo */ + os_uint8_t mode; /* Search(lock) mode */ + os_uint32_t earfcn; /* On witch EARFCN to lock; range:Quectel[1-65535] OneMo[0-262143] */ + os_uint16_t pci; /* Physical cell ID; range[0-503]/[0x00-0x1F7] */ + os_uint8_t earfcn_offset; /* Requested EARFCN offset; Only valid on OneMo */ } mo_earfcn_t; /** @@ -284,7 +286,7 @@ os_err_t mo_set_cgact(mo_object_t *self, os_uint8_t cid, os_uint8_t act_stat); os_err_t mo_get_cgact(mo_object_t *self, os_uint8_t *cid, os_uint8_t *act_stat); os_err_t mo_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber); os_err_t mo_get_radio(mo_object_t *self, radio_info_t *radio_info); -os_err_t mo_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info); +os_err_t mo_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info); os_err_t mo_set_psm(mo_object_t *self, mo_psm_info_t info); os_err_t mo_get_psm(mo_object_t *self, mo_psm_info_t *info); os_err_t mo_set_edrx_cfg(mo_object_t *self, mo_edrx_cfg_t cfg); diff --git a/components/molink/api/include/mo_onenet_nb.h b/components/molink/api/include/mo_onenet_nb.h index 6998ea8d..de83709a 100644 --- a/components/molink/api/include/mo_onenet_nb.h +++ b/components/molink/api/include/mo_onenet_nb.h @@ -34,12 +34,12 @@ extern "C" { #endif /* __cplusplus */ -#define NBCONFIG_AUTHCODE_MAX_LEN (16) -#define NBCONFIG_PSK_MAX_LEN (16) -#define NBEVENT_TIME_STAMP_MAX_LEN (14) -#define NBCONFIG_AUTHCODE_MAX_STR_LEN (NBCONFIG_AUTHCODE_MAX_LEN + 3) -#define NBCONFIG_PSK_MAX_STR_LEN (NBCONFIG_PSK_MAX_LEN + 3) -#define NBEVENT_TIME_STAMP_MAX_STR_LEN (NBEVENT_TIME_STAMP_MAX_LEN + 1) +#define NBCONFIG_AUTHCODE_MAX_LEN (16) +#define NBCONFIG_PSK_MAX_LEN (16) +#define NBEVENT_TIME_STAMP_MAX_LEN (14) +#define NBCONFIG_AUTHCODE_MAX_STR_LEN (NBCONFIG_AUTHCODE_MAX_LEN + 3) +#define NBCONFIG_PSK_MAX_STR_LEN (NBCONFIG_PSK_MAX_LEN + 3) +#define NBEVENT_TIME_STAMP_MAX_STR_LEN (NBEVENT_TIME_STAMP_MAX_LEN + 1) /** *********************************************************************************************************************** @@ -50,19 +50,19 @@ extern "C" { */ typedef struct mo_config_resp { - os_int8_t guide_mode_enable; /* Guide mode enable; -1:invalid */ - os_int8_t ip[IPADDR_MAX_STR_LEN + 1]; /* Server ip */ - os_uint16_t port; /* Server port; [0-15535] */ - os_uint8_t rsp_timeout; /* Respond timeout; 0:invalid, range:[2-20](s) */ - os_int8_t obs_autoack_enable; /* Obs autoack mode enable; -1:invalid */ - os_int8_t auth_enable; /* Auth mode enable; -1:invalid */ - os_int8_t auth_code[NBCONFIG_AUTHCODE_MAX_STR_LEN]; - /* Auth code string with Double quotation marks */ - os_int8_t dtls_enable; /* DTLS mode enable; -1:invalid */ - os_int8_t psk[NBCONFIG_PSK_MAX_STR_LEN]; /* PSK string with Double quotation marks */ - os_int8_t write_format; /* Write format; -1:invalid */ - os_int8_t buf_cfg; /* Downlink data cache configuration; -1:invalid */ - os_int8_t buf_urc_mode; /* Downlink data cache enabled indication;-1:invalid */ + os_int8_t guide_mode_enable; /* Guide mode enable; -1:invalid */ + os_int8_t ip[IPADDR_MAX_STR_LEN + 1]; /* Server ip */ + os_uint16_t port; /* Server port; [0-15535] */ + os_uint8_t rsp_timeout; /* Respond timeout; 0:invalid, range:[2-20](s) */ + os_int8_t obs_autoack_enable; /* Obs autoack mode enable; -1:invalid */ + os_int8_t auth_enable; /* Auth mode enable; -1:invalid */ + os_int8_t auth_code[NBCONFIG_AUTHCODE_MAX_STR_LEN]; + /* Auth code string with Double quotation marks */ + os_int8_t dtls_enable; /* DTLS mode enable; -1:invalid */ + os_int8_t psk[NBCONFIG_PSK_MAX_STR_LEN]; /* PSK string with Double quotation marks */ + os_int8_t write_format; /* Write format; -1:invalid */ + os_int8_t buf_cfg; /* Downlink data cache configuration; -1:invalid */ + os_int8_t buf_urc_mode; /* Downlink data cache enabled indication;-1:invalid */ } mo_config_resp_t; /** @@ -74,9 +74,9 @@ typedef struct mo_config_resp */ typedef struct mo_onenet_discover { - os_uint32_t ref; /* The descriptor of molink module instance */ - os_int32_t msg_id; /* MessageID */ - os_int32_t obj_id; /* ObjectID */ + os_uint32_t ref; /* The descriptor of molink module instance */ + os_int32_t msg_id; /* MessageID */ + os_int32_t obj_id; /* ObjectID */ } mo_onenet_discover_t; /** @@ -88,12 +88,12 @@ typedef struct mo_onenet_discover */ typedef struct mo_onenet_observe { - os_uint32_t ref; /* The descriptor of molink module instance */ - os_int32_t msg_id; /* MessageID */ - os_int8_t flag; /* Observe enable flag */ - os_int32_t obj_id; /* ObjectID */ - os_int32_t ins_id; /* InstanceID; -1:request all ins */ - os_int32_t res_id; /* ResourceID; -1:request all res */ + os_uint32_t ref; /* The descriptor of molink module instance */ + os_int32_t msg_id; /* MessageID */ + os_int8_t flag; /* Observe enable flag */ + os_int32_t obj_id; /* ObjectID */ + os_int32_t ins_id; /* InstanceID; -1:request all ins */ + os_int32_t res_id; /* ResourceID; -1:request all res */ } mo_onenet_observe_t; /** @@ -105,11 +105,11 @@ typedef struct mo_onenet_observe */ typedef struct mo_onenet_read { - os_uint32_t ref; /* The descriptor of molink module instance */ - os_int32_t msg_id; /* MessageID */ - os_int32_t obj_id; /* ObjectID */ - os_int32_t ins_id; /* InstanceID; -1:request all ins */ - os_int32_t res_id; /* ResourceID; -1:request all res */ + os_uint32_t ref; /* The descriptor of molink module instance */ + os_int32_t msg_id; /* MessageID */ + os_int32_t obj_id; /* ObjectID */ + os_int32_t ins_id; /* InstanceID; -1:request all ins */ + os_int32_t res_id; /* ResourceID; -1:request all res */ } mo_onenet_read_t; /** @@ -121,15 +121,15 @@ typedef struct mo_onenet_read */ typedef struct mo_onenet_write { - os_uint32_t ref; /* The descriptor of molink module instance */ - os_int32_t msg_id; /* MessageID */ - os_int32_t obj_id; /* ObjectID */ - os_int32_t ins_id; /* InstanceID */ - os_int32_t res_id; /* ResourceID */ - os_int8_t value_type; /* Value type; @see +MIPLWRITE */ - os_int32_t len; /* Value len; @see +MIPLWRITE */ - os_int8_t flag; /* Message flag, indicate messages position of value */ - os_int32_t index; /* Index of write request messages */ + os_uint32_t ref; /* The descriptor of molink module instance */ + os_int32_t msg_id; /* MessageID */ + os_int32_t obj_id; /* ObjectID */ + os_int32_t ins_id; /* InstanceID */ + os_int32_t res_id; /* ResourceID */ + os_int8_t value_type; /* Value type; @see +MIPLWRITE */ + os_int32_t len; /* Value len; @see +MIPLWRITE */ + os_int8_t flag; /* Message flag, indicate messages position of value */ + os_int32_t index; /* Index of write request messages */ } mo_onenet_write_t; /** @@ -141,12 +141,12 @@ typedef struct mo_onenet_write */ typedef struct mo_onenet_execute { - os_uint32_t ref; /* The descriptor of molink module instance */ - os_int32_t msg_id; /* MessageID */ - os_int32_t obj_id; /* ObjectID */ - os_int32_t ins_id; /* InstanceID */ - os_int32_t res_id; /* ResourceID */ - os_int32_t len; /* Execute arguements length; (optional) */ + os_uint32_t ref; /* The descriptor of molink module instance */ + os_int32_t msg_id; /* MessageID */ + os_int32_t obj_id; /* ObjectID */ + os_int32_t ins_id; /* InstanceID */ + os_int32_t res_id; /* ResourceID */ + os_int32_t len; /* Execute arguements length; (optional) */ } mo_onenet_execute_t; /** @@ -158,12 +158,12 @@ typedef struct mo_onenet_execute */ typedef struct mo_onenet_parameter { - os_uint32_t ref; /* The descriptor of molink module instance */ - os_int32_t msg_id; /* MessageID */ - os_int32_t obj_id; /* ObjectID */ - os_int32_t ins_id; /* InstanceID; -1:request all ins */ - os_int32_t res_id; /* ResourceID; -1:request all res, checkout IPSO */ - os_int32_t len; /* Parameter length */ + os_uint32_t ref; /* The descriptor of molink module instance */ + os_int32_t msg_id; /* MessageID */ + os_int32_t obj_id; /* ObjectID */ + os_int32_t ins_id; /* InstanceID; -1:request all ins */ + os_int32_t res_id; /* ResourceID; -1:request all res, checkout IPSO */ + os_int32_t len; /* Parameter length */ } mo_onenet_parameter_t; /** @@ -175,13 +175,13 @@ typedef struct mo_onenet_parameter */ typedef struct mo_onenet_event { - os_uint32_t ref; /* The descriptor of molink module instance */ - os_uint8_t evt_id; /* EventID; 0:invalid */ - os_int32_t extend; /* Extend; (optional) -1:invalid */ - os_uint16_t ack_id; /* AckID; (optional) 0:invalid range:[1-65535] */ - os_uint8_t time_stamp[NBEVENT_TIME_STAMP_MAX_STR_LEN]; - /* Time stamp; (optional) YYYYMMDDHHmmSS */ - os_int8_t cache_command_flag; /* Cache command enable Flag; (optional) -1:invalid */ + os_uint32_t ref; /* The descriptor of molink module instance */ + os_uint8_t evt_id; /* EventID; 0:invalid */ + os_int32_t extend; /* Extend; (optional) -1:invalid */ + os_uint16_t ack_id; /* AckID; (optional) 0:invalid range:[1-65535] */ + os_uint8_t time_stamp[NBEVENT_TIME_STAMP_MAX_STR_LEN]; + /* Time stamp; (optional) YYYYMMDDHHmmSS */ + os_int8_t cache_command_flag; /* Cache command enable Flag; (optional) -1:invalid */ } mo_onenet_event_t; /** @@ -191,23 +191,23 @@ typedef struct mo_onenet_event * @brief Struct contains urc messages receiving callbacks (Now support Quectel platform only) *********************************************************************************************************************** */ -typedef void (*discover_notify_cb_t) (mo_onenet_discover_t *discover_notify); -typedef void (*observe_notify_cb_t) (mo_onenet_observe_t *observe_notify); -typedef void (*read_notify_cb_t) (mo_onenet_read_t *read_notify); -typedef void (*write_notify_cb_t) (mo_onenet_write_t *write_notify, const char *value); -typedef void (*execute_notify_cb_t) (mo_onenet_execute_t *execute_notify, const char *arguments); -typedef void (*parameter_notify_cb_t) (mo_onenet_parameter_t *parameter_notify, const char *parameter); -typedef void (*event_notify_cb_t) (mo_onenet_event_t *event_notify); +typedef void (*discover_notify_cb_t)(mo_onenet_discover_t *discover_notify); +typedef void (*observe_notify_cb_t)(mo_onenet_observe_t *observe_notify); +typedef void (*read_notify_cb_t)(mo_onenet_read_t *read_notify); +typedef void (*write_notify_cb_t)(mo_onenet_write_t *write_notify, const char *value); +typedef void (*execute_notify_cb_t)(mo_onenet_execute_t *execute_notify, const char *arguments); +typedef void (*parameter_notify_cb_t)(mo_onenet_parameter_t *parameter_notify, const char *parameter); +typedef void (*event_notify_cb_t)(mo_onenet_event_t *event_notify); typedef struct mo_onenetnb_cb { - discover_notify_cb_t discover_notify_cb; - observe_notify_cb_t observe_notify_cb; - read_notify_cb_t read_notify_cb; - write_notify_cb_t write_notify_cb; - execute_notify_cb_t execute_notify_cb; - parameter_notify_cb_t parameter_notify_cb; - event_notify_cb_t event_notify_cb; + discover_notify_cb_t discover_notify_cb; + observe_notify_cb_t observe_notify_cb; + read_notify_cb_t read_notify_cb; + write_notify_cb_t write_notify_cb; + execute_notify_cb_t execute_notify_cb; + parameter_notify_cb_t parameter_notify_cb; + event_notify_cb_t event_notify_cb; } mo_onenet_cb_t; /** @@ -219,17 +219,17 @@ typedef struct mo_onenetnb_cb */ typedef struct module_mgr_resp { - os_uint32_t ref; /* The descriptor of molink module instance */ - os_uint32_t mid; /* +MIPLREAD mid */ - os_uint32_t objid; /* ObjectID */ - os_uint32_t insid; /* InstanceID */ - os_uint32_t resid; /* ResourceID */ - os_uint32_t type; /* Value type */ - os_uint32_t len; /* Value length */ - os_int8_t *value; /* Value */ + os_uint32_t ref; /* The descriptor of molink module instance */ + os_uint32_t mid; /* +MIPLREAD mid */ + os_uint32_t objid; /* ObjectID */ + os_uint32_t insid; /* InstanceID */ + os_uint32_t resid; /* ResourceID */ + os_uint32_t type; /* Value type */ + os_uint32_t len; /* Value length */ + os_int8_t *value; /* Value */ } module_mgr_resp_t; -#define ONENET_NB_FUNC_ARGS (mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args) +#define ONENET_NB_FUNC_ARGS (mo_object_t * module, os_int32_t timeout, void *resp, const char *format, va_list args) /** *********************************************************************************************************************** @@ -240,7 +240,7 @@ typedef struct module_mgr_resp */ typedef struct mo_onenet_ops { -#define DEFINE_ONENET_OPT_FUNC(NAME, ARGS) os_err_t (*NAME) ARGS +#define DEFINE_ONENET_OPT_FUNC(NAME, ARGS) os_err_t(*NAME) ARGS DEFINE_ONENET_OPT_FUNC(onenetnb_get_config, ONENET_NB_FUNC_ARGS); DEFINE_ONENET_OPT_FUNC(onenetnb_set_config, ONENET_NB_FUNC_ARGS); DEFINE_ONENET_OPT_FUNC(onenetnb_create, ONENET_NB_FUNC_ARGS); diff --git a/components/molink/api/include/mo_ping.h b/components/molink/api/include/mo_ping.h index 4d8a8aa4..98ddfd0e 100644 --- a/components/molink/api/include/mo_ping.h +++ b/components/molink/api/include/mo_ping.h @@ -36,16 +36,17 @@ extern "C" { typedef struct ping_resp { - ip_addr_t ip_addr; /* response IP address */ - os_uint16_t data_len; /* response data length */ - os_uint16_t ttl; /* time to live */ - os_uint32_t time; /* response time, unit ms */ - void *user_data; /* user-specific data */ + ip_addr_t ip_addr; /* response IP address */ + os_uint16_t data_len; /* response data length */ + os_uint16_t ttl; /* time to live */ + os_uint32_t time; /* response time, unit ms */ + void *user_data; /* user-specific data */ } ping_resp_t; typedef struct mo_ping_ops { - os_err_t (*ping)(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout_ms, struct ping_resp *resp); + os_err_t ( + *ping)(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout_ms, struct ping_resp *resp); } mo_ping_ops_t; os_err_t mo_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout_ms, struct ping_resp *resp); diff --git a/components/molink/api/include/mo_ppp.h b/components/molink/api/include/mo_ppp.h index 686477b3..ce010606 100644 --- a/components/molink/api/include/mo_ppp.h +++ b/components/molink/api/include/mo_ppp.h @@ -44,7 +44,7 @@ typedef struct mo_ppp_ops os_err_t (*ppp_init)(mo_object_t *module); os_err_t (*ppp_dial)(mo_object_t *module); os_err_t (*ppp_exit)(mo_object_t *module); - + } mo_ppp_ops_t; os_err_t mo_ppp_init(mo_object_t *module); diff --git a/components/molink/api/include/mo_socket.h b/components/molink/api/include/mo_socket.h index 634f7a36..70c1d832 100644 --- a/components/molink/api/include/mo_socket.h +++ b/components/molink/api/include/mo_socket.h @@ -50,7 +50,7 @@ extern "C" { #define MOLINK_NUM_SOCKETS 6 #endif -#define MOLINK_SOCKETS_FD_MAX MOLINK_NUM_SOCKETS +#define MOLINK_SOCKETS_FD_MAX MOLINK_NUM_SOCKETS #ifndef MOLINK_DNS_MAX_NAME_LEN #define MOLINK_DNS_MAX_NAME_LEN 56 @@ -105,33 +105,33 @@ extern "C" { /* Level number for (get/set)sockopt() to apply to socket itself */ #define SOL_SOCKET 0xfff /* options for socket level */ -#define AF_UNSPEC 0 -#define AF_INET 2 +#define AF_UNSPEC 0 +#define AF_INET 2 #ifdef MOLINK_USING_IPV6 -#define AF_INET6 10 +#define AF_INET6 10 #else /* MOLINK_USING_IPV6 */ -#define AF_INET6 AF_UNSPEC +#define AF_INET6 AF_UNSPEC #endif /* MOLINK_USING_IPV6 */ -#define PF_INET AF_INET -#define PF_INET6 AF_INET6 -#define PF_UNSPEC AF_UNSPEC - -#define IPPROTO_IP 0 -#define IPPROTO_ICMP 1 -#define IPPROTO_TCP 6 -#define IPPROTO_UDP 17 +#define PF_INET AF_INET +#define PF_INET6 AF_INET6 +#define PF_UNSPEC AF_UNSPEC + +#define IPPROTO_IP 0 +#define IPPROTO_ICMP 1 +#define IPPROTO_TCP 6 +#define IPPROTO_UDP 17 #ifdef MOLINK_USING_IPV6 -#define IPPROTO_IPV6 41 -#define IPPROTO_ICMPV6 58 +#define IPPROTO_IPV6 41 +#define IPPROTO_ICMPV6 58 #endif /* MOLINK_USING_IPV6 */ #define IPPROTO_UDPLITE 136 #define IPPROTO_RAW 255 /* Flags we can use with send and recv */ -#define MSG_PEEK 0x01 /* Peeks at an incoming message */ -#define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full */ +#define MSG_PEEK 0x01 /* Peeks at an incoming message */ +#define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full */ /* amount of data requested can be returned */ -#define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics */ +#define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics */ /* of out-of-band data are protocol-specific */ #define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */ #define MSG_MORE 0x10 /* Sender will send more */ @@ -198,11 +198,11 @@ typedef uint16_t in_port_t; struct hostent { - char *h_name; /* Official name of the host. */ + char *h_name; /* Official name of the host. */ char **h_aliases; /* A pointer to an array of pointers to alternative host names, */ /* terminated by a null pointer. */ - int h_addrtype; /* Address type. */ - int h_length; /* The length, in bytes, of the address. */ + int h_addrtype; /* Address type. */ + int h_length; /* The length, in bytes, of the address. */ char **h_addr_list; /* A pointer to an array of pointers to network addresses */ /* (in network byte order) for the host,terminated by a null pointer */ #define h_addr h_addr_list[0] /* for backward compatibility */ @@ -210,50 +210,51 @@ struct hostent struct sockaddr { - uint8_t sa_len; + uint8_t sa_len; sa_family_t sa_family; - char sa_data[14]; + char sa_data[14]; }; struct sockaddr_in { - uint8_t sin_len; - sa_family_t sin_family; - in_port_t sin_port; + uint8_t sin_len; + sa_family_t sin_family; + in_port_t sin_port; struct in_addr sin_addr; #define SIN_ZERO_LEN 8 - char sin_zero[SIN_ZERO_LEN]; + char sin_zero[SIN_ZERO_LEN]; }; #ifdef MOLINK_USING_IPV6 -struct sockaddr_in6 { - uint8_t sin6_len; /* length of this structure */ - sa_family_t sin6_family; /* AF_INET6 */ - in_port_t sin6_port; /* Transport layer port # */ - uint32_t sin6_flowinfo; /* IPv6 flow information */ - struct in6_addr sin6_addr; /* IPv6 address */ - uint32_t sin6_scope_id; /* Set of interfaces for scope */ +struct sockaddr_in6 +{ + uint8_t sin6_len; /* length of this structure */ + sa_family_t sin6_family; /* AF_INET6 */ + in_port_t sin6_port; /* Transport layer port # */ + uint32_t sin6_flowinfo; /* IPv6 flow information */ + struct in6_addr sin6_addr; /* IPv6 address */ + uint32_t sin6_scope_id; /* Set of interfaces for scope */ }; #endif struct addrinfo { - int ai_flags; /* Input flags. */ - int ai_family; /* Address family of socket. */ - int ai_socktype; /* Socket type. */ - int ai_protocol; /* Protocol of socket. */ - socklen_t ai_addrlen; /* Length of socket address. */ - struct sockaddr *ai_addr; /* Socket address of socket. */ - char *ai_canonname; /* Canonical name of service location. */ - struct addrinfo *ai_next; /* Pointer to next in list. */ + int ai_flags; /* Input flags. */ + int ai_family; /* Address family of socket. */ + int ai_socktype; /* Socket type. */ + int ai_protocol; /* Protocol of socket. */ + socklen_t ai_addrlen; /* Length of socket address. */ + struct sockaddr *ai_addr; /* Socket address of socket. */ + char *ai_canonname; /* Canonical name of service location. */ + struct addrinfo *ai_next; /* Pointer to next in list. */ }; struct sockaddr_storage { - uint8_t s2_len; + uint8_t s2_len; sa_family_t ss_family; - char s2_data1[2]; - uint32_t s2_data2[3]; + char s2_data1[2]; + uint32_t s2_data2[3]; }; typedef struct ip_mreq @@ -266,7 +267,7 @@ typedef struct ip_mreq typedef struct poll_req { struct vfs_pollfd *req; - os_slist_node_t req_list; + os_slist_node_t req_list; } poll_req_t; #endif /* OS_USING_IO_MULTIPLEXING */ @@ -274,16 +275,16 @@ typedef struct mo_sock { mo_netconn_t *netconn; - void *lastdata; /* data that was left from the previous read */ - os_size_t lastlen; /* data length that was left from the previous read */ - os_uint16_t lastoffset; /* offset in the data that was left from the previous read */ - os_int32_t recv_timeout; /* timeout to wait for received data in milliseconds */ + void *lastdata; /* data that was left from the previous read */ + os_size_t lastlen; /* data length that was left from the previous read */ + os_uint16_t lastoffset; /* offset in the data that was left from the previous read */ + os_int32_t recv_timeout; /* timeout to wait for received data in milliseconds */ - os_int8_t rcvevent; /* number of times data was received, set by event_callback(), + os_int8_t rcvevent; /* number of times data was received, set by event_callback(), tested by the receive and select functions */ - os_uint8_t sendevent; /* number of times data was ACKed (free send buffer), + os_uint8_t sendevent; /* number of times data was ACKed (free send buffer), set by event_callback(),tested by select */ - os_uint8_t errevent; /* error happened for this socket, set by event_callback(), tested by select */ + os_uint8_t errevent; /* error happened for this socket, set by event_callback(), tested by select */ os_uint32_t select_waiting; /* counter of how many threads are waiting for this socket using select */ #ifdef OS_USING_IO_MULTIPLEXING os_slist_node_t req_slist_head; @@ -293,26 +294,33 @@ typedef struct mo_sock #if 0 /* FD_SET used for mo_select */ #ifndef FD_SET -#undef FD_SETSIZE +#undef FD_SETSIZE /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */ -#define FD_SETSIZE MOLINK_SOCKETS_FD_MAX +#define FD_SETSIZE MOLINK_SOCKETS_FD_MAX typedef unsigned long fd_mask; -#define NBBY (8) /* number of bits in a byte */ -#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */ -#define __FD_MASK(n) ((fd_mask)(1UL << ((n) % NFDBITS))) +#define NBBY (8) /* number of bits in a byte */ +#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */ +#define __FD_MASK(n) ((fd_mask)(1UL << ((n) % NFDBITS))) #ifndef HOWMANY -#define HOWMANY(x,y) (((x)+((y)-1))/(y)) +#define HOWMANY(x, y) (((x) + ((y)-1)) / (y)) #endif /* HOWMANY */ -#define FDSAFESET(n, code) do {if (((n) < MOLINK_SOCKETS_FD_MAX) && (((int)(n)) >= 0)) { code; }} while(0) -#define FDSAFEGET(n, code) (((n) < MOLINK_SOCKETS_FD_MAX) && (((int)(n)) >= 0) ? (code) : 0) - -#define FD_SET(n, p) FDSAFESET(n, (p)->fd_bits[(n)/NFDBITS] |= __FD_MASK(n)) -#define FD_CLR(n, p) FDSAFESET(n, (p)->fd_bits[(n)/NFDBITS] &= ~__FD_MASK(n)) -#define FD_ISSET(n,p) FDSAFEGET(n, (p)->fd_bits[(n)/NFDBITS] & __FD_MASK(n)) -#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) +#define FDSAFESET(n, code) \ + do \ + { \ + if (((n) < MOLINK_SOCKETS_FD_MAX) && (((int)(n)) >= 0)) \ + { \ + code; \ + } \ + } while (0) +#define FDSAFEGET(n, code) (((n) < MOLINK_SOCKETS_FD_MAX) && (((int)(n)) >= 0) ? (code) : 0) + +#define FD_SET(n, p) FDSAFESET(n, (p)->fd_bits[(n) / NFDBITS] |= __FD_MASK(n)) +#define FD_CLR(n, p) FDSAFESET(n, (p)->fd_bits[(n) / NFDBITS] &= ~__FD_MASK(n)) +#define FD_ISSET(n, p) FDSAFEGET(n, (p)->fd_bits[(n) / NFDBITS] & __FD_MASK(n)) +#define FD_ZERO(p) memset((void *)(p), 0, sizeof(*(p))) typedef struct fd_set { @@ -333,7 +341,7 @@ typedef struct fd_set /* * If defined MOLINK_USING_SINGLE_MODULE, mo socket api is like bsd socket, * can also use bsd socket by define MOLINK_USING_BSD_SOCKET. - * If defined MOLINK_USING_MULTI_MODULES, mo socket api need mo_object point + * If defined MOLINK_USING_MULTI_MODULES, mo socket api need mo_object point * as first parameter, if need use bsd socket, you need menu config Socket Kit. */ #if defined(MOLINK_USING_SINGLE_MODULE) @@ -345,18 +353,8 @@ int mo_bind_with_cb(int socket, const struct sockaddr *name, socklen_t namelen, #endif /* MOLINK_USING_SERVER_MODE */ int mo_connect(int socket, const struct sockaddr *name, socklen_t namelen); #ifdef MOLINK_USING_UDP -int mo_sendto(int socket, - const void *data, - size_t size, - int flags, - const struct sockaddr *to, - socklen_t tolen); -int mo_recvfrom(int socket, - void *mem, - size_t len, - int flags, - struct sockaddr *from, - socklen_t *fromlen); +int mo_sendto(int socket, const void *data, size_t size, int flags, const struct sockaddr *to, socklen_t tolen); +int mo_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen); #endif /* MOLINK_USING_UDP */ #ifdef MOLINK_USING_TCP int mo_send(int socket, const void *data, size_t size, int flags); @@ -372,24 +370,28 @@ int mo_socket(mo_object_t *module, int domain, int type, int protocol); int mo_closesocket(mo_object_t *module, int socket); #ifdef MOLINK_USING_SERVER_MODE int mo_bind(mo_object_t *module, int socket, const struct sockaddr *name, socklen_t namelen); -int mo_bind_with_cb(mo_object_t *module, int socket, const struct sockaddr *name, socklen_t namelen, mo_netconn_data_callback cb); +int mo_bind_with_cb(mo_object_t *module, + int socket, + const struct sockaddr *name, + socklen_t namelen, + mo_netconn_data_callback cb); #endif /* MOLINK_USING_SERVER_MODE */ int mo_connect(mo_object_t *module, int socket, const struct sockaddr *name, socklen_t namelen); #ifdef MOLINK_USING_UDP -int mo_sendto(mo_object_t *module, - int socket, - const void *data, - size_t size, - int flags, +int mo_sendto(mo_object_t *module, + int socket, + const void *data, + size_t size, + int flags, const struct sockaddr *to, - socklen_t tolen); -int mo_recvfrom(mo_object_t *module, - int socket, - void *mem, - size_t len, - int flags, + socklen_t tolen); +int mo_recvfrom(mo_object_t *module, + int socket, + void *mem, + size_t len, + int flags, struct sockaddr *from, - socklen_t *fromlen); + socklen_t *fromlen); #endif /* MOLINK_USING_UDP */ #ifdef MOLINK_USING_TCP int mo_send(mo_object_t *module, int socket, const void *data, size_t size, int flags); @@ -403,11 +405,11 @@ struct hostent *mo_gethostbyname(mo_object_t *module, const char *name); #endif /* MOLINK_USING_SINGLE_MODULE */ #ifdef MOLINK_USING_SELECT -int mo_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout); +int mo_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout); #endif /* MOLINK_USING_SELECT */ #if defined(MOLINK_USING_ADDRINFO) && defined(MOLINK_USING_DNS) -int mo_getaddrinfo(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res); +int mo_getaddrinfo(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res); void mo_freeaddrinfo(struct addrinfo *ai); #endif /* MOLINK_USING_ADDRINFO && MOLINK_USING_DNS */ @@ -423,36 +425,38 @@ int mo_poll(int socket, struct vfs_pollfd *req, os_bool_t poll_setup); #if defined(NET_USING_BSD) #error "Only one Module, molink can support bsd socket, do not config Socket Kit in menu" #endif /* NET_USING_BSD */ -#define socket(domain,type,protocol) mo_socket(domain,type,protocol) -#define closesocket(s) mo_closesocket(s) +#define socket(domain, type, protocol) mo_socket(domain, type, protocol) +#define closesocket(s) mo_closesocket(s) #ifdef MOLINK_USING_SERVER_MODE -#define bind(s, name, namelen) mo_bind(s, name, namelen) +#define bind(s, name, namelen) mo_bind(s, name, namelen) #endif /* MOLINK_USING_SERVER_MODE */ -#define connect(s,name,namelen) mo_connect(s,name,namelen) +#define connect(s, name, namelen) mo_connect(s, name, namelen) #ifdef MOLINK_USING_UDP -#define sendto(s,dataptr,size,flags,to,tolen) mo_sendto(s,dataptr,size,flags,to,tolen) -#define recvfrom(s,mem,len,flags,from,fromlen) mo_recvfrom(s,mem,len,flags,from,fromlen) +#define sendto(s, dataptr, size, flags, to, tolen) mo_sendto(s, dataptr, size, flags, to, tolen) +#define recvfrom(s, mem, len, flags, from, fromlen) mo_recvfrom(s, mem, len, flags, from, fromlen) #endif /* MOLINK_USING_UDP */ #ifdef MOLINK_USING_TCP -#define send(s,dataptr,size,flags) mo_send(s,dataptr,size,flags) -#define recv(s,mem,len,flags) mo_recv(s,mem,len,flags) +#define send(s, dataptr, size, flags) mo_send(s, dataptr, size, flags) +#define recv(s, mem, len, flags) mo_recv(s, mem, len, flags) #endif /* MOLINK_USING_TCP */ -#define getsockopt(s,level,optname,optval,optlen) mo_getsockopt(s,level,optname,optval,optlen) -#define setsockopt(s,level,optname,optval,optlen) mo_setsockopt(s,level,optname,optval,optlen) +#define getsockopt(s, level, optname, optval, optlen) mo_getsockopt(s, level, optname, optval, optlen) +#define setsockopt(s, level, optname, optval, optlen) mo_setsockopt(s, level, optname, optval, optlen) #ifdef MOLINK_USING_DNS -#define gethostbyname(name) mo_gethostbyname(name) +#define gethostbyname(name) mo_gethostbyname(name) #ifdef MOLINK_USING_ADDRINFO -#define getaddrinfo(nodename,servname,hints,res) mo_getaddrinfo(nodename,servname,hints,res) -#define freeaddrinfo(addrinfo) mo_freeaddrinfo(addrinfo) +#define getaddrinfo(nodename, servname, hints, res) mo_getaddrinfo(nodename, servname, hints, res) +#define freeaddrinfo(addrinfo) mo_freeaddrinfo(addrinfo) #endif /* MOLINK_USING_ADDRINFO */ #endif /* MOLINK_USING_DNS */ #ifdef MOLINK_USING_SELECT -#define select(maxfdp1,readset,writeset,exceptset,timeout) mo_select(maxfdp1,readset,writeset,exceptset,timeout) +#define select(maxfdp1, readset, writeset, exceptset, timeout) mo_select(maxfdp1, readset, writeset, exceptset, timeout) #endif /* MOLINK_USING_SELECT */ #ifdef OS_USING_IO_MULTIPLEXING -#define poll(s,req,pollsetup); mo_poll(s,req,pollsetup); +#define poll(s, req, pollsetup) \ + ; \ + mo_poll(s, req, pollsetup); #endif /* OS_USING_IO_MULTIPLEXING */ #endif /* MOLINK_USING_SINGLE_MODULE && MOLINK_COMPAT_BSD_SOCKET */ diff --git a/components/molink/api/include/mo_wifi.h b/components/molink/api/include/mo_wifi.h index d5de1652..1a5e0588 100644 --- a/components/molink/api/include/mo_wifi.h +++ b/components/molink/api/include/mo_wifi.h @@ -70,8 +70,8 @@ typedef enum mo_wifi_stat MO_WIFI_STAT_INIT, MO_WIFI_STAT_CONNECTED, MO_WIFI_STAT_DISCONNECTED, - MO_WIFI_STAT_GOT_IP = 0x8, - MO_WIFI_STAT_GOT_IPV6 = 0x10, + MO_WIFI_STAT_GOT_IP = 0x8, + MO_WIFI_STAT_GOT_IPV6 = 0x10, MO_WIFI_STAT_MAX } mo_wifi_stat_t; @@ -98,8 +98,8 @@ typedef enum mo_cipdinfo_mode */ typedef enum mo_wifi_cipv6 { - MO_WIFI_CIPV6_DISABLE = 0, - MO_WIFI_CIPV6_ENABLE = 1, + MO_WIFI_CIPV6_DISABLE = 0, + MO_WIFI_CIPV6_ENABLE = 1, } mo_wifi_cipv6_t; /** @@ -142,7 +142,7 @@ typedef struct mo_wifi_ssid */ typedef struct mo_wifi_bssid { - char bssid_str[MO_WIFI_BSSID_MAX_LENGTH + 1]; /* hwaddr */ + char bssid_str[MO_WIFI_BSSID_MAX_LENGTH + 1]; /* hwaddr */ os_uint8_t bssid_array[MO_WIFI_BSSID_ARRAY_LENGTH]; } mo_wifi_bssid_t; @@ -155,11 +155,11 @@ typedef struct mo_wifi_bssid */ typedef struct mo_wifi_info { - mo_wifi_ecn_t ecn_mode; /* encryption mode */ - os_int32_t channel; /* radio channel */ - os_int32_t rssi; /* signal strength */ - mo_wifi_ssid_t ssid; /* ssid */ - mo_wifi_bssid_t bssid; /* hwaddr */ + mo_wifi_ecn_t ecn_mode; /* encryption mode */ + os_int32_t channel; /* radio channel */ + os_int32_t rssi; /* signal strength */ + mo_wifi_ssid_t ssid; /* ssid */ + mo_wifi_bssid_t bssid; /* hwaddr */ } mo_wifi_info_t; /** @@ -172,7 +172,7 @@ typedef struct mo_wifi_info typedef struct mo_wifi_scan_result { mo_wifi_info_t *info_array; - os_size_t info_num; + os_size_t info_num; } mo_wifi_scan_result_t; /** @@ -184,36 +184,48 @@ typedef struct mo_wifi_scan_result */ typedef struct mo_wifi_ops { - os_err_t (*set_mode)(mo_object_t *module, mo_wifi_mode_t mode); + os_err_t (*set_mode)(mo_object_t *module, mo_wifi_mode_t mode); mo_wifi_mode_t (*get_mode)(mo_object_t *module); mo_wifi_stat_t (*get_stat)(mo_object_t *module); - os_err_t (*get_sta_cip)(mo_object_t *module, ip_addr_t *ip, ip_addr_t *gw, ip_addr_t *mask, ip_addr_t *ip6_ll, ip_addr_t *ip6_gl); - os_err_t (*set_ap_cip)(mo_object_t *module, char *ip, char *gw, char *mask); - os_err_t (*get_ap_cip)(mo_object_t *module, ip_addr_t *ip, ip_addr_t *gw, ip_addr_t *mask); - os_err_t (*get_sta_mac)(mo_object_t *module, char mac[]); - os_err_t (*get_ap_mac)(mo_object_t *module, char mac[]); - os_err_t (*scan_info)(mo_object_t *module, char *ssid, mo_wifi_scan_result_t *scan_result); - os_err_t (*connect_ap)(mo_object_t *module, const char *ssid, const char *password); - os_err_t (*disconnect_ap)(mo_object_t *module); + os_err_t (*get_sta_cip)(mo_object_t *module, + ip_addr_t *ip, + ip_addr_t *gw, + ip_addr_t *mask, + ip_addr_t *ip6_ll, + ip_addr_t *ip6_gl); + os_err_t (*set_ap_cip)(mo_object_t *module, char *ip, char *gw, char *mask); + os_err_t (*get_ap_cip)(mo_object_t *module, ip_addr_t *ip, ip_addr_t *gw, ip_addr_t *mask); + os_err_t (*get_sta_mac)(mo_object_t *module, char mac[]); + os_err_t (*get_ap_mac)(mo_object_t *module, char mac[]); + os_err_t (*scan_info)(mo_object_t *module, char *ssid, mo_wifi_scan_result_t *scan_result); + os_err_t (*connect_ap)(mo_object_t *module, const char *ssid, const char *password); + os_err_t (*disconnect_ap)(mo_object_t *module); // ecn, encryption method - os_err_t (*start_ap)(mo_object_t *module, const char *ssid, const char *password, os_uint8_t channel, os_uint8_t ecn); - os_err_t (*stop_ap)(mo_object_t *module); + os_err_t ( + *start_ap)(mo_object_t *module, const char *ssid, const char *password, os_uint8_t channel, os_uint8_t ecn); + os_err_t (*stop_ap)(mo_object_t *module); } mo_wifi_ops_t; -os_err_t mo_wifi_set_mode(mo_object_t *module, mo_wifi_mode_t mode); +os_err_t mo_wifi_set_mode(mo_object_t *module, mo_wifi_mode_t mode); mo_wifi_mode_t mo_wifi_get_mode(mo_object_t *module); mo_wifi_stat_t mo_wifi_get_stat(mo_object_t *module); -os_err_t mo_wifi_get_sta_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t *gw, ip_addr_t *mask, ip_addr_t *ip6_ll, ip_addr_t *ip6_gl); -os_err_t mo_wifi_set_ap_cip(mo_object_t *module, char *ip, char *gw, char *mask); -os_err_t mo_wifi_get_ap_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t *gw, ip_addr_t *mask); -os_err_t mo_wifi_get_sta_mac(mo_object_t *module, char mac[]); -os_err_t mo_wifi_get_ap_mac(mo_object_t *module, char mac[]); -os_err_t mo_wifi_scan_info(mo_object_t *module, char *ssid, mo_wifi_scan_result_t *scan_result); -void mo_wifi_scan_info_free(mo_wifi_scan_result_t *scan_result); -os_err_t mo_wifi_connect_ap(mo_object_t *module, const char *ssid, const char *password); -os_err_t mo_wifi_disconnect_ap(mo_object_t *module); -os_err_t mo_wifi_start_ap(mo_object_t *module, const char *ssid, const char *password, os_uint8_t channel, os_uint8_t ecn); -os_err_t mo_wifi_stop_ap(mo_object_t *module); +os_err_t mo_wifi_get_sta_cip(mo_object_t *module, + ip_addr_t *ip, + ip_addr_t *gw, + ip_addr_t *mask, + ip_addr_t *ip6_ll, + ip_addr_t *ip6_gl); +os_err_t mo_wifi_set_ap_cip(mo_object_t *module, char *ip, char *gw, char *mask); +os_err_t mo_wifi_get_ap_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t *gw, ip_addr_t *mask); +os_err_t mo_wifi_get_sta_mac(mo_object_t *module, char mac[]); +os_err_t mo_wifi_get_ap_mac(mo_object_t *module, char mac[]); +os_err_t mo_wifi_scan_info(mo_object_t *module, char *ssid, mo_wifi_scan_result_t *scan_result); +void mo_wifi_scan_info_free(mo_wifi_scan_result_t *scan_result); +os_err_t mo_wifi_connect_ap(mo_object_t *module, const char *ssid, const char *password); +os_err_t mo_wifi_disconnect_ap(mo_object_t *module); +os_err_t +mo_wifi_start_ap(mo_object_t *module, const char *ssid, const char *password, os_uint8_t channel, os_uint8_t ecn); +os_err_t mo_wifi_stop_ap(mo_object_t *module); #ifdef __cplusplus } diff --git a/components/molink/api/source/mo_factory.c b/components/molink/api/source/mo_factory.c index c386b897..3940896f 100644 --- a/components/molink/api/source/mo_factory.c +++ b/components/molink/api/source/mo_factory.c @@ -25,7 +25,7 @@ #include #define MO_LOG_TAG "module.factory" -#define MO_LOG_LVL MO_LOG_EMERG +#define MO_LOG_LVL MO_LOG_EMERG #include "mo_log.h" /***************************************** Start to list of NB-IoT modules ********************************************/ @@ -81,7 +81,6 @@ #endif /***************************************** End of NB-IoT modules list *************************************************/ - /*************************************** Start to list of 4G cat1 modules *********************************************/ #ifdef MOLINK_USING_EC200X_600S #include "ec200x_600s.h" @@ -123,7 +122,6 @@ #endif /**************************************** End of 4G cat1 modules list *************************************************/ - /*************************************** Start to list of 4G cat4 modules *********************************************/ #ifdef MOLINK_USING_GM510 @@ -144,7 +142,6 @@ /**************************************** End of 4G cat4 modules list *************************************************/ - /*************************************** Start to list of wifi modules ************************************************/ #ifdef MOLINK_USING_ESP8266 #include "esp8266.h" @@ -154,7 +151,6 @@ #endif /***************************************** End of wifi modules list ***************************************************/ - static const mo_create_fn gs_mo_create_t[] = { /* Type of NB-IoT modules */ #ifdef MOLINK_USING_M5310A @@ -243,7 +239,6 @@ static const mo_create_fn gs_mo_create_t[] = { [MODULE_TYPE_ME3630_W] = module_me3630_w_create, #endif - /* Type of wifi modules */ #ifdef MOLINK_USING_ESP8266 [MODULE_TYPE_ESP8266] = module_esp8266_create, diff --git a/components/molink/api/source/mo_general.c b/components/molink/api/source/mo_general.c index 4e49162e..d4dc9540 100644 --- a/components/molink/api/source/mo_general.c +++ b/components/molink/api/source/mo_general.c @@ -25,7 +25,7 @@ #include #define MO_LOG_TAG "molink.general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_GENERAL_OPS @@ -48,7 +48,7 @@ static mo_general_ops_t *get_general_ops(mo_object_t *self) * * @param[in] self The descriptor of molink module instance * - * @return On success, return OS_EOK; on error, return a error code. + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK AT test successfully * @retval OS_ERROR AT test error * @retval OS_ETIMEOUT AT test timeout @@ -81,8 +81,8 @@ os_err_t mo_at_test(mo_object_t *self) * @param[in] self The descriptor of molink module instance * @param[out] value The buffer to store imei * @param[in] len The buffer length - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get imei successfully * @retval OS_ERROR Get imei error * @retval OS_ETIMEOUT Get imei timeout @@ -116,8 +116,8 @@ os_err_t mo_get_imei(mo_object_t *self, char *value, os_size_t len) * @param[in] self The descriptor of molink module instance * @param[out] value The buffer to store imsi * @param[in] len The buffer length - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get imsi successfully * @retval OS_ERROR Get imsi error * @retval OS_ETIMEOUT Get imsi timeout @@ -151,8 +151,8 @@ os_err_t mo_get_imsi(mo_object_t *self, char *value, os_size_t len) * @param[in] self The descriptor of molink module instance * @param[out] value The buffer to store iccid * @param[in] len The buffer length - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get iccid successfully * @retval OS_ERROR Get iccid error * @retval OS_ETIMEOUT Get iccid timeout @@ -185,8 +185,8 @@ os_err_t mo_get_iccid(mo_object_t *self, char *value, os_size_t len) * * @param[in] self The descriptor of molink module instance * @param[out] fun_lvl The buffer to store module functionality level - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get module functionality level successfully * @retval OS_ERROR Get module functionality level error * @retval OS_ETIMEOUT Get module functionality level timeout @@ -219,8 +219,8 @@ os_err_t mo_get_cfun(mo_object_t *self, os_uint8_t *fun_lvl) * * @param[in] self The descriptor of molink module instance * @param[in] fun_lvl The functionality level - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Set module functionality level successfully * @retval OS_ERROR Set module functionality level error * @retval OS_ETIMEOUT Set module functionality level timeout @@ -253,8 +253,8 @@ os_err_t mo_set_cfun(mo_object_t *self, os_uint8_t fun_lvl) * @param[in] self The descriptor of molink module instance * @param[in] value The buffer to store app version * @param[in] len The buffer length - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get module firmware app version successfully * @retval OS_ERROR Get module firmware app version error * @retval OS_ETIMEOUT Get module firmware app version timeout @@ -322,12 +322,12 @@ void mo_get_firmware_version_free(mo_firmware_version_t *version) *********************************************************************************************************************** * @brief Execute the AT command to get module eID * Without spec for eID len, current api design for all typical cases - * + * * @param[in] self The descriptor of molink module instance * @param[in] eid The buffer to store eID * @param[in] len The buffer length - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get module eID successfully * @retval OS_ERROR Get module eID error * @retval OS_ETIMEOUT Get module eID timeout @@ -357,11 +357,11 @@ os_err_t mo_get_eid(mo_object_t *self, char *eid, os_size_t len) /** *********************************************************************************************************************** * @brief Execute the AT command to get current broken-down time - * + * * @param[in] self The descriptor of molink module instance * @param[in] l_tm The user buffer to store tm struct - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get module gmtime successfully * @retval OS_ERROR Get module gmtime error * @retval OS_ETIMEOUT Get module gmtime timeout @@ -391,11 +391,11 @@ os_err_t mo_gm_time(mo_object_t *self, struct tm *l_tm) /** *********************************************************************************************************************** * @brief Execute the command to get current time - * + * * @param[in] self The descriptor of molink module instance * @param[in] timep The user buffer to store current time - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get module current time successfully * @retval OS_ERROR Get module current time error * @retval OS_ETIMEOUT Get module current time timeout @@ -408,7 +408,7 @@ os_err_t mo_time(mo_object_t *self, time_t *timep) OS_ASSERT(OS_NULL != self); OS_ASSERT(OS_NULL != timep); - struct tm l_tm = {0}; + struct tm l_tm = {0}; os_err_t result = OS_EOK; mo_general_ops_t *ops = get_general_ops(self); @@ -424,7 +424,7 @@ os_err_t mo_time(mo_object_t *self, time_t *timep) } result = ops->gm_time(self, &l_tm); - + if (OS_EOK == result) { time_t time = mktime(&l_tm); @@ -432,7 +432,7 @@ os_err_t mo_time(mo_object_t *self, time_t *timep) { memcpy(timep, &time, sizeof(time_t)); } - else + else { ERROR("Module %s %s maketime error", self->name, __func__); return OS_ERROR; diff --git a/components/molink/api/source/mo_ifconfig.c b/components/molink/api/source/mo_ifconfig.c index e429905b..7b495528 100644 --- a/components/molink/api/source/mo_ifconfig.c +++ b/components/molink/api/source/mo_ifconfig.c @@ -26,7 +26,7 @@ #include "mo_ifconfig.h" #define MO_LOG_TAG "molink.ifconfig" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_IFCONFIG_OPS diff --git a/components/molink/api/source/mo_mqttc.c b/components/molink/api/source/mo_mqttc.c index b1842d7c..9a255630 100644 --- a/components/molink/api/source/mo_mqttc.c +++ b/components/molink/api/source/mo_mqttc.c @@ -28,7 +28,7 @@ #include #define MO_LOG_TAG "molink.mqttc" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifndef MQTTC_TASK_STACK_SIZE @@ -57,15 +57,14 @@ static mo_mqttc_ops_t *get_mqttc_ops(mo_object_t *self) return ops; } - /** *********************************************************************************************************************** * @brief This function create an instance of a molink mqtt client * - * @param[in] module The descriptor of molink module instance + * @param[in] module The descriptor of molink module instance * @param[in] create_opts The create options of client. @ref mqttc_create_opts_t - * - * @return On success, return a molink mqtt client descriptor; + * + * @return On success, return a molink mqtt client descriptor; * On error, OS_NULL is returned. *********************************************************************************************************************** */ @@ -94,9 +93,9 @@ mo_mqttc_t *mo_mqttc_create(mo_object_t *module, mqttc_create_opts_t *create_opt *********************************************************************************************************************** * @brief This function open the mqtt client connection to the server * - * @param[in] client The descriptor of molink mqtt client instance + * @param[in] client The descriptor of molink mqtt client instance * @param[in] connect_opts The connect options of client. @ref mqttc_conn_opts_t - * + * * @return Returns the result of the operation * @retval OS_ERROR Connect failed * @retval OS_ETIMEOUT Connect timeout @@ -164,10 +163,10 @@ static void mqttc_close_session(mo_mqttc_t *client) *********************************************************************************************************************** * @brief This function tries to publish the message to a given topic * - * @param[in] client The descriptor of molink mqtt client instance + * @param[in] client The descriptor of molink mqtt client instance * @param[in] topic_filter The topic associated with this message * @param[in] msg The message to be published. @ref mqttc_msg_t - * + * * @return Returns the result of the operation * @retval OS_ERROR Publish failed * @retval OS_ETIMEOUT Publish timeout @@ -225,10 +224,10 @@ os_err_t mo_mqttc_publish(mo_mqttc_t *client, const char *topic_filter, mqttc_ms *********************************************************************************************************************** * @brief This function set or remove a per topic message handler * - * @param[in] client The descriptor of molink mqtt client instance + * @param[in] client The descriptor of molink mqtt client instance * @param[in] topic_filter The topic filter set the message handler for * @param[in] handler Pointer to the message handler function or NULL to remove. @ref mqttc_msg_handler_t - * + * * @return Returns the result of the operation * @retval OS_ERROR Set failed * @retval OS_EOK Set successfully @@ -240,7 +239,7 @@ os_err_t mo_mqttc_set_msg_handler(mo_mqttc_t *client, const char *topic_filter, OS_ASSERT(OS_NULL != topic_filter); os_err_t result = OS_ERROR; - + os_int32_t i = -1; /* first check for an existing matching slot */ @@ -252,7 +251,7 @@ os_err_t mo_mqttc_set_msg_handler(mo_mqttc_t *client, const char *topic_filter, if (OS_NULL == handler) /* remove existing */ { client->msg_handlers[i].topic_filter = OS_NULL; - client->msg_handlers[i].handler = OS_NULL; + client->msg_handlers[i].handler = OS_NULL; } result = OS_EOK; break; @@ -275,7 +274,7 @@ os_err_t mo_mqttc_set_msg_handler(mo_mqttc_t *client, const char *topic_filter, if (i < MQTTC_MAX_MESSAGE_HANDLERS) { client->msg_handlers[i].topic_filter = topic_filter; - client->msg_handlers[i].handler = handler; + client->msg_handlers[i].handler = handler; } } @@ -286,11 +285,11 @@ os_err_t mo_mqttc_set_msg_handler(mo_mqttc_t *client, const char *topic_filter, *********************************************************************************************************************** * @brief This function attempts to subscribe a client to a single topic * - * @param[in] client The descriptor of molink mqtt client instance + * @param[in] client The descriptor of molink mqtt client instance * @param[in] topic_filter The subscription topic * @param[in] qos The requested quality of service for the subscription. * @param[in] handler Pointer to the message handler function. @ref mqttc_msg_handler_t - * + * * @return Returns the result of the operation * @retval OS_ERROR Subscribe failed * @retval OS_ETIMEOUT Subscribe timeout @@ -344,7 +343,7 @@ os_err_t mo_mqttc_subscribe(mo_mqttc_t *client, const char *topic_filter, mqttc_ #if defined(MOLINK_USING_MQTTC_TASK) os_mutex_unlock(&client->mutex); #endif - + return result; } @@ -352,9 +351,9 @@ os_err_t mo_mqttc_subscribe(mo_mqttc_t *client, const char *topic_filter, mqttc_ *********************************************************************************************************************** * @brief This function attempts to remove an existing subscription made by the specified client. * - * @param[in] client The descriptor of molink mqtt client instance + * @param[in] client The descriptor of molink mqtt client instance * @param[in] topic_filter The topic for the subscription to be removed - * + * * @return Returns the result of the operation * @retval OS_ERROR Remove failed * @retval OS_ETIMEOUT Remove timeout @@ -396,7 +395,7 @@ os_err_t mo_mqttc_unsubscribe(mo_mqttc_t *client, const char *topic_filter) os_err_t result = ops->unsubscribe(client, topic_filter); if (OS_EOK == result) - { + { /* remove the subscription message handler associated with this topic, if there is one */ result = mo_mqttc_set_msg_handler(client, topic_filter, OS_NULL); } @@ -417,8 +416,8 @@ os_err_t mo_mqttc_unsubscribe(mo_mqttc_t *client, const char *topic_filter) *********************************************************************************************************************** * @brief This function attempts to disconnect the client from the MQTT server * - * @param[in] client The descriptor of molink mqtt client instance - * + * @param[in] client The descriptor of molink mqtt client instance + * * @return Returns the result of the operation * @retval OS_ERROR Disconnect failed * @retval OS_ETIMEOUT Disconnect timeout @@ -468,11 +467,11 @@ os_err_t mo_mqttc_disconnect(mo_mqttc_t *client) /** *********************************************************************************************************************** - * @brief This function allows the client application to test whether or not + * @brief This function allows the client application to test whether or not * a client is currently connected to the MQTT server. * - * @param[in] client The descriptor of molink mqtt client instance - * + * @param[in] client The descriptor of molink mqtt client instance + * * @return Boolean OS_TURE if the client is connected, otherwise OS_FALSE. *********************************************************************************************************************** */ @@ -488,8 +487,8 @@ os_bool_t mo_mqttc_isconnect(mo_mqttc_t *client) *********************************************************************************************************************** * @brief This function destroy an instance of a molink mqtt client * - * @param[in] client The descriptor of molink mqtt client instance - * + * @param[in] client The descriptor of molink mqtt client instance + * * @return Returns the result of the operation * @retval OS_ERROR Destroy failed * @retval OS_EOK Destroy successfully @@ -535,12 +534,12 @@ os_err_t mo_mqttc_destroy(mo_mqttc_t *client) * assume topic filter and name is in correct format * # can only be at end * + and # can only be next to separator -*/ -static os_bool_t is_topic_matched(char* topicFilter, mqttc_string_t* topic_name) + */ +static os_bool_t is_topic_matched(char *topicFilter, mqttc_string_t *topic_name) { - char* curf = topicFilter; - char* curn = topic_name->data; - char* curn_end = curn + topic_name->len; + char *curf = topicFilter; + char *curn = topic_name->data; + char *curn_end = curn + topic_name->len; while (*curf && curn < curn_end) { @@ -549,8 +548,8 @@ static os_bool_t is_topic_matched(char* topicFilter, mqttc_string_t* topic_name) if (*curf != '+' && *curf != '#' && *curf != *curn) break; if (*curf == '+') - { // skip until we meet the next separator, or end of string - char* nextpos = curn + 1; + { // skip until we meet the next separator, or end of string + char *nextpos = curn + 1; while (nextpos < curn_end && *nextpos != '/') nextpos = ++curn + 1; } @@ -586,7 +585,7 @@ static os_err_t deliver_message(mo_mqttc_t *client, mqttc_msg_data_t *msg) client->default_handler(msg); result = OS_EOK; } - + return result; } @@ -595,16 +594,16 @@ static os_err_t mqttc_pop_message(mo_mqttc_t *client, os_tick_t timeout) mqttc_msg_data_t *msg = OS_NULL; os_size_t msg_len = 0; - os_err_t result = os_mq_recv(&client->mq, (const void**)&msg, sizeof(msg), timeout, &msg_len); + os_err_t result = os_mq_recv(&client->mq, (const void **)&msg, sizeof(msg), timeout, &msg_len); if (client->stat != MQTTC_STAT_CONNECT && (OS_EEMPTY == result || OS_ETIMEOUT == result)) { DEBUG("Module %s mqtt client %d does not connect to server, pop message failed!", - module->name, - client->mqttc_id); + module->name, + client->mqttc_id); return OS_ERROR; } - switch(result) + switch (result) { case OS_ERROR: ERROR("Module %s mqtt client %d pop message error", client->module->name, client->mqttc_id); @@ -637,8 +636,8 @@ static os_err_t mqttc_pop_message(mo_mqttc_t *client, os_tick_t timeout) * call this function periodically to allow processing of message * * @param[in] client The descriptor of molink mqtt client instance - * @param[in] timeout_ms The length of time to wait for a message in milliseconds. - * + * @param[in] timeout_ms The length of time to wait for a message in milliseconds. + * * @return Returns the result of the operation *********************************************************************************************************************** */ @@ -670,7 +669,7 @@ os_err_t mo_mqttc_yield(mo_mqttc_t *client, os_uint32_t timeout_ms) } } while (1); - + return result; } @@ -681,11 +680,11 @@ static void mqttc_run(void *parameter) while (1) { #if defined(MOLINK_USING_MQTTC_TASK) - os_mutex_lock(&client->mutex, OS_WAIT_FOREVER); + os_mutex_lock(&client->mutex, OS_WAIT_FOREVER); #endif - mqttc_pop_message(client, os_tick_from_ms(500)); + mqttc_pop_message(client, os_tick_from_ms(500)); #if defined(MOLINK_USING_MQTTC_TASK) - os_mutex_unlock(&client->mutex); + os_mutex_unlock(&client->mutex); #endif } } @@ -696,7 +695,7 @@ static void mqttc_run(void *parameter) * @brief MQTT start background task for a client. After this, mo_mqttc_yield should not be called. * * @param[in] client The descriptor of molink mqtt client instance - * + * * @return Returns the result of the operation *********************************************************************************************************************** */ @@ -708,18 +707,14 @@ os_err_t mo_mqttc_start_task(mo_mqttc_t *client) snprintf(task_name, OS_NAME_MAX, "%smqc%d", client->module->name, client->mqttc_id); - client->task = os_task_create(task_name, - mqttc_run, - client, - MQTTC_TASK_STACK_SIZE, - MQTTC_TASK_PRIORITY, - MQTTC_TASK_TIMESLICE); + client->task = + os_task_create(task_name, mqttc_run, client, MQTTC_TASK_STACK_SIZE, MQTTC_TASK_PRIORITY, MQTTC_TASK_TIMESLICE); if (OS_NULL == client->task) { ERROR("Create Module %s mqtt client %d task failed!", client->module->name, client->mqttc_id); return OS_ERROR; } - + return os_task_startup(client->task); } #endif @@ -740,7 +735,7 @@ os_err_t mo_mqttc_data_queue_push_notice(mo_mqttc_t *client, mqttc_msg_data_t *m result = OS_ERROR; ERROR("MQTT client id %d push state error", client->mqttc_id); } - + return result; } @@ -765,9 +760,9 @@ void mo_mqttc_data_queue_destroy(mo_mqttc_t *client) os_data_queue_t *msg_queue = &client->msg_queue; - os_err_t result = OS_EOK; - os_size_t data_size = 0; - mqttc_msg_data_t *msg_ptr = OS_NULL; + os_err_t result = OS_EOK; + os_size_t data_size = 0; + mqttc_msg_data_t *msg_ptr = OS_NULL; do { diff --git a/components/molink/api/source/mo_netconn.c b/components/molink/api/source/mo_netconn.c index 099f18dc..694b6f77 100644 --- a/components/molink/api/source/mo_netconn.c +++ b/components/molink/api/source/mo_netconn.c @@ -28,7 +28,7 @@ #include #define MO_LOG_TAG "molink.netconn" -#define MO_LOG_LVL MO_LOG_EMERG +#define MO_LOG_LVL MO_LOG_EMERG #include "mo_log.h" #ifdef MOLINK_USING_NETCONN_OPS @@ -45,7 +45,11 @@ static mo_netconn_ops_t *get_netconn_ops(mo_object_t *module) return ops; } -void mo_wifi_netconn_data_recv_notice(mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port, char *data, os_size_t size) +void mo_wifi_netconn_data_recv_notice(mo_netconn_t *netconn, + ip_addr_t addr, + os_uint16_t port, + char *data, + os_size_t size) { OS_ASSERT(OS_NULL != netconn); OS_ASSERT(OS_NULL != data); @@ -54,25 +58,25 @@ void mo_wifi_netconn_data_recv_notice(mo_netconn_t *netconn, ip_addr_t addr, os_ { mo_notconn_msg_t msg = {0}; - msg.addr = addr; - msg.port = port; - msg.data = data; + msg.addr = addr; + msg.port = port; + msg.data = data; msg.data_len = size; #ifdef MOLINK_USING_SOCKETS_OPS - if (OS_NULL != netconn->data_func) - { - netconn->data_func(OS_NULL, addr, port, data, size); - free(data); - } - else - { - os_mq_send(netconn->mq, (void *)&msg, sizeof(mo_notconn_msg_t), OS_WAIT_FOREVER); - if (OS_NULL != netconn->evt_func) + if (OS_NULL != netconn->data_func) { - netconn->evt_func(netconn, MO_NETCONN_EVT_RCVPLUS, size); + netconn->data_func(OS_NULL, addr, port, data, size); + free(data); + } + else + { + os_mq_send(netconn->mq, (void *)&msg, sizeof(mo_notconn_msg_t), OS_WAIT_FOREVER); + if (OS_NULL != netconn->evt_func) + { + netconn->evt_func(netconn, MO_NETCONN_EVT_RCVPLUS, size); + } } - } #else os_mq_send(netconn->mq, (void *)&msg, sizeof(mo_notconn_msg_t), OS_WAIT_FOREVER); #endif @@ -95,7 +99,7 @@ void mo_netconn_data_recv_notice(mo_netconn_t *netconn, char *data, os_size_t si { mo_notconn_msg_t msg = {0}; - msg.data = data; + msg.data = data; msg.data_len = size; result = os_mq_send(netconn->mq, (void *)&msg, sizeof(mo_notconn_msg_t), OS_WAIT_FOREVER); @@ -185,7 +189,7 @@ void mo_netconn_mq_destroy(os_mq_t *mq) { OS_ASSERT(OS_NULL != mq); - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; os_size_t data_size = 0; mo_notconn_msg_t msg = {0}; @@ -258,7 +262,7 @@ os_err_t mo_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) OS_ASSERT(OS_NULL != module); OS_ASSERT(OS_NULL != netconn); - if (NETCONN_STAT_NULL == netconn->stat) + if (NETCONN_STAT_NULL == netconn->stat) { ERROR("Module %s netconn id %d connect state %d error!", module->name, netconn->connect_id, netconn->stat); return OS_ERROR; @@ -424,7 +428,12 @@ os_err_t mo_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_ * @return The length of data successfully sent *********************************************************************************************************************** */ -os_size_t mo_netconn_sendto(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t remote_ip, os_uint16_t remote_port, const char *data, os_size_t size) +os_size_t mo_netconn_sendto(mo_object_t *module, + mo_netconn_t *netconn, + ip_addr_t remote_ip, + os_uint16_t remote_port, + const char *data, + os_size_t size) { OS_ASSERT(OS_NULL != module); OS_ASSERT(OS_NULL != netconn); @@ -442,7 +451,7 @@ os_size_t mo_netconn_sendto(mo_object_t *module, mo_netconn_t *netconn, ip_addr_ { return 0; } - + /* now just module esp8266 has support udp socket server & udp sendto func */ #ifdef MOLINK_USING_ESP8266 if (module->type == MODULE_TYPE_ESP8266) @@ -536,15 +545,21 @@ os_size_t mo_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char * @retval OS_EOK Receive data successfully *********************************************************************************************************************** */ -os_err_t mo_netconn_recvfrom(mo_object_t *module, mo_netconn_t *netconn, void **data, os_size_t *size, ip_addr_t *addr, os_uint16_t *port, os_tick_t timeout) +os_err_t mo_netconn_recvfrom(mo_object_t *module, + mo_netconn_t *netconn, + void **data, + os_size_t *size, + ip_addr_t *addr, + os_uint16_t *port, + os_tick_t timeout) { OS_ASSERT(OS_NULL != module); OS_ASSERT(OS_NULL != netconn); OS_ASSERT(OS_NULL != data); OS_ASSERT(OS_NULL != size); - mo_notconn_msg_t msg = {0}; - os_size_t msg_size = 0; + mo_notconn_msg_t msg = {0}; + os_size_t msg_size = 0; os_err_t result = os_mq_recv(netconn->mq, (void *)&msg, sizeof(mo_notconn_msg_t), timeout, &msg_size); @@ -588,9 +603,9 @@ os_err_t mo_netconn_recvfrom(mo_object_t *module, mo_netconn_t *netconn, void * { *port = msg.port; } - + #ifdef MOLINK_USING_SOCKETS_OPS - if (OS_NULL!= netconn->evt_func) + if (OS_NULL != netconn->evt_func) { netconn->evt_func(netconn, MO_NETCONN_EVT_RCVMINUS, *size); } diff --git a/components/molink/api/source/mo_netserv.c b/components/molink/api/source/mo_netserv.c index a0264426..d9b7f569 100644 --- a/components/molink/api/source/mo_netserv.c +++ b/components/molink/api/source/mo_netserv.c @@ -27,7 +27,7 @@ #include #define MO_LOG_TAG "molink.nerserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_NETSERV_OPS @@ -50,8 +50,8 @@ static mo_netserv_ops_t *get_netserv_ops(mo_object_t *self) * * @param[in] self The descriptor of molink module instance * @param[in] attach_stat Indicates the state of PS attachment - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Set the state of PS attachment successfully * @retval OS_ERROR Set the state of PS attachment error * @retval OS_ETIMEOUT Set the state of PS attachment timeout @@ -83,8 +83,8 @@ os_err_t mo_set_attach(mo_object_t *self, os_uint8_t attach_stat) * * @param[in] self The descriptor of molink module instance * @param[out] attach_stat The buffer to store the state of PS attachment - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get the state of PS attachment successfully * @retval OS_ERROR Get the state of PS attachment error * @retval OS_ETIMEOUT Get the state of PS attachment timeout @@ -117,8 +117,8 @@ os_err_t mo_get_attach(mo_object_t *self, os_uint8_t *attach_stat) * * @param[in] self The descriptor of molink module instance * @param[in] reg_n The presentation of an network registration urc data - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Set the presentation of an network registration urc data successfully * @retval OS_ERROR Set the presentation of an network registration urc data error * @retval OS_ETIMEOUT Set the presentation of an network registration urc data timeout @@ -137,22 +137,22 @@ os_err_t mo_set_reg(mo_object_t *self, os_uint8_t reg_n) if (OS_NULL == ops->set_reg) { - ERROR("Module %s does not support set register state operate", self->name); - return OS_ERROR; - } + ERROR("Module %s does not support set register state operate", self->name); + return OS_ERROR; + } - return ops->set_reg(self, reg_n); + return ops->set_reg(self, reg_n); } /** *********************************************************************************************************************** - * @brief Execute AT command to get the presentation of an network registration urc data and + * @brief Execute AT command to get the presentation of an network registration urc data and * the network registration status * * @param[in] self The descriptor of molink module instance * @param[out] info The struct to store the presentation of an network registration info - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get successfully * @retval OS_ERROR Get error * @retval OS_ETIMEOUT Get timeout @@ -186,8 +186,8 @@ os_err_t mo_get_reg(mo_object_t *self, eps_reg_info_t *info) * @param[in] self The descriptor of molink module instance * @param[in] cid A numeric parameter which specifies a particular PDP context * @param[in] act_stat Indicates the state of PDP context activation - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Activate or deactivate PDP Context successfully * @retval OS_ERROR Activate or deactivate PDP Context error * @retval OS_ETIMEOUT Activate or deactivate PDP Context timeout @@ -208,20 +208,20 @@ os_err_t mo_set_cgact(mo_object_t *self, os_uint8_t cid, os_uint8_t act_stat) { ERROR("Module %s does not support set cgact operate", self->name); return OS_ERROR; - } + } - return ops->set_cgact(self, cid, act_stat); + return ops->set_cgact(self, cid, act_stat); } /** *********************************************************************************************************************** - * @brief Execute AT command to get the state of PDP context activation + * @brief Execute AT command to get the state of PDP context activation * * @param[in] self The descriptor of molink module instance * @param[out] cid The buffer to store the cid * @param[out] act_stat The buffer to store the state of PDP context activation - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get the state of PDP context activation successfully * @retval OS_ERROR Get the state of PDP context activation error * @retval OS_ETIMEOUT Get the state of PDP context activation timeout @@ -232,7 +232,7 @@ os_err_t mo_get_cgact(mo_object_t *self, os_uint8_t *cid, os_uint8_t *act_stat) OS_ASSERT(OS_NULL != self); OS_ASSERT(OS_NULL != cid); OS_ASSERT(OS_NULL != act_stat); - + mo_netserv_ops_t *ops = get_netserv_ops(self); if (OS_NULL == ops) @@ -251,14 +251,14 @@ os_err_t mo_get_cgact(mo_object_t *self, os_uint8_t *cid, os_uint8_t *act_stat) /** *********************************************************************************************************************** - * @brief Execute AT command to get the signal strength indication and + * @brief Execute AT command to get the signal strength indication and * channel bit error rate from the ME * * @param[in] self The descriptor of molink module instance * @param[out] rssi The buffer to store the signal strength * @param[out] ber The buffer to store the channel bit error rate - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get the signal quality successfully * @retval OS_ERROR Get the signal quality error * @retval OS_ETIMEOUT Get the signal quality timeout @@ -292,8 +292,8 @@ os_err_t mo_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber) * * @param[in] self The descriptor of molink module instance * @param[out] radio_info The buffer to store the UE statistics - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get the signal quality successfully * @retval OS_ERROR Get the signal quality error * @retval OS_ETIMEOUT Get the signal quality timeout @@ -326,14 +326,14 @@ os_err_t mo_get_radio(mo_object_t *self, radio_info_t *radio_info) * * @param[in] self The descriptor of molink module instance * @param[out] onepos_cell_info The buffer to store cell infomation - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get cell infomation successfully * @retval OS_ETIMEOUT Get cell infomation timeout * @retval OS_ERROR Get cell infomation error *********************************************************************************************************************** */ -os_err_t mo_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info) +os_err_t mo_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info) { OS_ASSERT(OS_NULL != self); OS_ASSERT(OS_NULL != onepos_cell_info); @@ -351,7 +351,7 @@ os_err_t mo_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_inf return OS_ERROR; } - return ops->get_cell_info(self, onepos_cell_info); + return ops->get_cell_info(self, onepos_cell_info); } /** @@ -360,8 +360,8 @@ os_err_t mo_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_inf * * @param[in] self The descriptor of molink module instance * @param[in] info The PSM setting info - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Set module PSM(power saving mode) configuration successfully * @retval OS_ERROR Set module PSM(power saving mode) configuration error * @retval OS_ETIMEOUT Set module PSM(power saving mode) configuration timeout @@ -393,8 +393,8 @@ os_err_t mo_set_psm(mo_object_t *self, mo_psm_info_t info) * * @param[in] self The descriptor of molink module instance * @param[in] info The pointer of mo_psm_info_t to store PSM info - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get module PSM(power saving mode) info successfully * @retval OS_ERROR Get module PSM(power saving mode) info error * @retval OS_ETIMEOUT Get module PSM(power saving mode) info timeout @@ -427,8 +427,8 @@ os_err_t mo_get_psm(mo_object_t *self, mo_psm_info_t *info) * * @param[in] self The descriptor of molink module instance * @param[in] cfg The eDRX setting info - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Set module eDRX's configuration successfully * @retval OS_ERROR Set module eDRX's configuration error * @retval OS_ETIMEOUT Set module eDRX's configuration timeout @@ -460,8 +460,8 @@ os_err_t mo_set_edrx_cfg(mo_object_t *self, mo_edrx_cfg_t cfg) * * @param[in] self The descriptor of molink module instance * @param[in] edrx_local Witch struct that holds eDRX setting info - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get module eDRX's configuration successfully * @retval OS_ERROR Get module eDRX's configuration error * @retval OS_ETIMEOUT Get module eDRX's configuration timeout @@ -494,8 +494,8 @@ os_err_t mo_get_edrx_cfg(mo_object_t *self, mo_edrx_t *edrx_local) * * @param[in] self The descriptor of molink module instance * @param[in] edrx_dynamic Witch struct that holds Effective parameters - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get module eDRX's dynamic parameters successfully * @retval OS_ERROR Get module eDRX's dynamic parameters error * @retval OS_ETIMEOUT Get module eDRX's dynamic parameters timeout @@ -529,8 +529,8 @@ os_err_t mo_get_edrx_dynamic(mo_object_t *self, mo_edrx_t *edrx_dynamic) * @param[in] self The descriptor of molink module instance * @param[in] band_list String that hold chosen using bands * @param[in] num band number in band_list - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Set module using bands successfully * @retval OS_ERROR Set module using bands error * @retval OS_ETIMEOUT Set module using bands timeout @@ -563,8 +563,8 @@ os_err_t mo_set_band(mo_object_t *self, char band_list[], os_uint8_t num) * * @param[in] self The descriptor of molink module instance * @param[in] earfcn Struct that hold earfcn configurations - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Set module locking to specific earfcn successfully * @retval OS_ERROR Set module locking to specific earfcn error * @retval OS_ETIMEOUT Set module locking to specific earfcn timeout @@ -596,8 +596,8 @@ os_err_t mo_set_earfcn(mo_object_t *self, mo_earfcn_t earfcn) * * @param[in] self The descriptor of molink module instance * @param[in] earfcn Struct that hold returning earfcn configurations - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Get module earfcn successfully * @retval OS_ERROR Get module earfcn error * @retval OS_ETIMEOUT Get module earfcn timeout @@ -630,7 +630,7 @@ os_err_t mo_get_earfcn(mo_object_t *self, mo_earfcn_t *earfcn) * * @param[in] self The descriptor of molink module instance * - * @return On success, return OS_EOK; on error, return a error code. + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Clear stored earfcn successfully * @retval OS_ERROR Clear stored earfcn error * @retval OS_ETIMEOUT Clear stored earfcn timeout @@ -662,7 +662,7 @@ os_err_t mo_clear_stored_earfcn(mo_object_t *self) * * @param[in] self The descriptor of molink module instance * - * @return On success, return OS_EOK; on error, return a error code. + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Clear PLMN successfully * @retval OS_ERROR Clear PLMN error * @retval OS_ETIMEOUT Clear PLMN timeout @@ -696,12 +696,12 @@ os_err_t mo_clear_plmn(mo_object_t *self) #include #include -os_err_t module_get_reg_sh(int argc, char* argv[]) -{ +os_err_t module_get_reg_sh(int argc, char *argv[]) +{ eps_reg_info_t info; - + mo_object_t *mo_def_obj = OS_NULL; - + mo_def_obj = mo_get_default(); if (OS_NULL == mo_def_obj) { @@ -713,7 +713,7 @@ os_err_t module_get_reg_sh(int argc, char* argv[]) { INFO("Get reg reg_n:%d, reg_status:%d!\n", info.reg_n, info.reg_stat); } - + return OS_EOK; } SH_CMD_EXPORT(mo_get_reg, module_get_reg_sh, "Get module network reg status"); diff --git a/components/molink/api/source/mo_onenet_nb.c b/components/molink/api/source/mo_onenet_nb.c index 9f382b28..fc00edff 100644 --- a/components/molink/api/source/mo_onenet_nb.c +++ b/components/molink/api/source/mo_onenet_nb.c @@ -25,31 +25,31 @@ #include "mo_common.h" #define MO_LOG_TAG "module.onenet_nb" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define CALL_MODULE_FUNC(FUNC_NAME, OPT_NAME) \ do \ { \ os_err_t error = OS_ERROR; \ - va_list args = {0}; \ + va_list args = {0}; \ va_start(args, format); \ \ - if (OS_NULL == module) \ + if (OS_NULL == module) \ { \ - module = mo_get_default(); \ + module = mo_get_default(); \ } \ - mo_onenet_ops_t *ops = module_get_onenet_ops(module); \ + mo_onenet_ops_t *ops = module_get_onenet_ops(module); \ if (OS_NULL == ops) \ { \ return error; \ } \ if (OS_NULL == ops->FUNC_NAME) \ { \ - ERROR("Module %s does not support %s operate", module->name, OPT_NAME); \ + ERROR("Module %s does not support %s operate", module->name, OPT_NAME); \ return OS_ERROR; \ } \ - error = ops->FUNC_NAME(module, timeout, resp, format, args); \ + error = ops->FUNC_NAME(module, timeout, resp, format, args); \ va_end(args); \ \ return error; \ @@ -57,7 +57,7 @@ OS_INLINE mo_onenet_ops_t *module_get_onenet_ops(mo_object_t *module) { - if(OS_NULL == module) + if (OS_NULL == module) { ERROR("%s Input module is NULL.", __func__); return OS_NULL; @@ -83,8 +83,8 @@ OS_INLINE mo_onenet_ops_t *module_get_onenet_ops(mo_object_t *module) * @param[in] format Reserved, please set an empty sting "". * @param[in] ... Reserved. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -107,8 +107,8 @@ os_err_t mo_onenetnb_get_config(mo_object_t *module, os_int32_t timeout, void *r * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -131,8 +131,8 @@ os_err_t mo_onenetnb_set_config(mo_object_t *module, os_int32_t timeout, void *r * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -155,8 +155,8 @@ os_err_t mo_onenetnb_create(mo_object_t *module, os_int32_t timeout, void *resp, * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -179,8 +179,8 @@ os_err_t mo_onenetnb_createex(mo_object_t *module, os_int32_t timeout, void *res * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -203,8 +203,8 @@ os_err_t mo_onenetnb_delete(mo_object_t *module, os_int32_t timeout, void *resp, * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -227,8 +227,8 @@ os_err_t mo_onenetnb_addobj(mo_object_t *module, os_int32_t timeout, void *resp, * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -251,8 +251,8 @@ os_err_t mo_onenetnb_delobj(mo_object_t *module, os_int32_t timeout, void *resp, * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -275,8 +275,8 @@ os_err_t mo_onenetnb_nmi(mo_object_t *module, os_int32_t timeout, void *resp, co * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -299,8 +299,8 @@ os_err_t mo_onenetnb_open(mo_object_t *module, os_int32_t timeout, void *resp, c * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -323,8 +323,8 @@ os_err_t mo_onenetnb_close(mo_object_t *module, os_int32_t timeout, void *resp, * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -347,8 +347,8 @@ os_err_t mo_onenetnb_discoverrsp(mo_object_t *module, os_int32_t timeout, void * * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -371,8 +371,8 @@ os_err_t mo_onenetnb_observersp(mo_object_t *module, os_int32_t timeout, void *r * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -395,8 +395,8 @@ os_err_t mo_onenetnb_readrsp(mo_object_t *module, os_int32_t timeout, void *resp * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -419,8 +419,8 @@ os_err_t mo_onenetnb_writersp(mo_object_t *module, os_int32_t timeout, void *res * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -443,8 +443,8 @@ os_err_t mo_onenetnb_executersp(mo_object_t *module, os_int32_t timeout, void *r * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -467,8 +467,8 @@ os_err_t mo_onenetnb_parameterrsp(mo_object_t *module, os_int32_t timeout, void * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -491,8 +491,8 @@ os_err_t mo_onenetnb_notify(mo_object_t *module, os_int32_t timeout, void *resp, * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -507,7 +507,8 @@ os_err_t mo_onenetnb_update(mo_object_t *module, os_int32_t timeout, void *resp, /** *********************************************************************************************************************** * @brief Fetch unread 'write' operations in URC non-default mode - * OneNet LwM2M extend function,Fetch unread 'write' operations in URC non-default mode(OneMo platform only) + * OneNet LwM2M extend function,Fetch unread 'write' operations in URC non-default mode(OneMo platform + *only) * * @param[in] module The descriptor of molink module instance. * @param[in] timeout The AT parser get resp timeout value, set by os ticks. @@ -515,8 +516,8 @@ os_err_t mo_onenetnb_update(mo_object_t *module, os_int32_t timeout, void *resp, * @param[in] format The parameter expression of command @see AT Commands Manual. * @param[in] ... The expression arguments.. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed * @retval OS_EBUSY Busy @@ -531,13 +532,14 @@ os_err_t mo_onenetnb_get_write(mo_object_t *module, os_int32_t timeout, void *re /** *********************************************************************************************************************** * @brief Reigster the user callbacks that is used to get the URC messages - * Extend function,Reigster the user callbacks that is used to get the URC messages(Quectel platform only) + * Extend function,Reigster the user callbacks that is used to get the URC messages(Quectel platform + *only) * * @param[in] module The descriptor of molink module instance. * @param[in] user_callbacks A mo_onenet_cb_t type struct contains user callbacks. * - * @return On success, return OS_EOK; - * On error, return an error code. + * @return On success, return OS_EOK; + * On error, return an error code. * @retval OS_EOK Success * @retval OS_ERROR Failed *********************************************************************************************************************** @@ -686,9 +688,9 @@ os_err_t module_onenetnb_notify_sh(int argc, char *argv[]) { ++uip; ERROR("notify mid:0, obj:3200, insid:0, resid:5750, type:1, len: %d, value: %s, index:0, flag:0, ack_id:%d\n", - atoi(argv[1]), - argv[2], - uip); + atoi(argv[1]), + argv[2], + uip); } return OS_EOK; } @@ -718,14 +720,14 @@ os_err_t module_onenetnb_get_write_sh(int argc, char *argv[]) if (mo_onenetnb_get_write(OS_NULL, 2000, &mgr, "0") == OS_EOK) { ERROR("result ref:%d, mid:%d, objid:%d, insid:%d, resid:%d, type:%d, len:%d, value:%s\n", - mgr.ref, - mgr.mid, - mgr.objid, - mgr.insid, - mgr.resid, - mgr.type, - mgr.len, - mgr.value); + mgr.ref, + mgr.mid, + mgr.objid, + mgr.insid, + mgr.resid, + mgr.type, + mgr.len, + mgr.value); } free(mgr.value); diff --git a/components/molink/api/source/mo_ping.c b/components/molink/api/source/mo_ping.c index 2790e672..5709c255 100644 --- a/components/molink/api/source/mo_ping.c +++ b/components/molink/api/source/mo_ping.c @@ -23,7 +23,7 @@ #include "mo_ping.h" #define MO_LOG_TAG "molink.ping" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_PING_OPS diff --git a/components/molink/api/source/mo_ppp.c b/components/molink/api/source/mo_ppp.c index 6f5a9d64..ed0047f1 100644 --- a/components/molink/api/source/mo_ppp.c +++ b/components/molink/api/source/mo_ppp.c @@ -24,7 +24,7 @@ #include "mo_common.h" #define MO_LOG_TAG "molink.ppp" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_PPP_OPS @@ -46,8 +46,8 @@ static mo_ppp_ops_t *get_ppp_ops(mo_object_t *module) * @brief module ppp init session, check status & active pdp context * * @param[in] module The descriptor of molink module instance - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Init successfully * @retval OS_ETIMEOUT Init timeout * @retval OS_ERROR Init error @@ -70,7 +70,6 @@ os_err_t mo_ppp_init(mo_object_t *module) } return ops->ppp_init(module); - } /** @@ -79,8 +78,8 @@ os_err_t mo_ppp_init(mo_object_t *module) * execute this func before init lwip ppp create * * @param[in] module The descriptor of molink module instance - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Dail successfully * @retval OS_ETIMEOUT Dail timeout * @retval OS_ERROR Dail error @@ -111,8 +110,8 @@ os_err_t mo_ppp_dial(mo_object_t *module) * execute this func after ppp_close * * @param[in] module The descriptor of molink module instance - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Dail successfully * @retval OS_ETIMEOUT Dail timeout * @retval OS_ERROR Dail error diff --git a/components/molink/api/source/mo_socket.c b/components/molink/api/source/mo_socket.c index 2afc43dd..a0d99d1a 100644 --- a/components/molink/api/source/mo_socket.c +++ b/components/molink/api/source/mo_socket.c @@ -62,11 +62,11 @@ struct mo_select_cb os_sem_t sem; }; -static os_slist_node_t gs_mo_select_cb_slist = {OS_NULL}; -static volatile int gs_mo_select_cb_ctr; +static os_slist_node_t gs_mo_select_cb_slist = {OS_NULL}; +static volatile int gs_mo_select_cb_ctr; #endif /* MOLINK_USING_SELECT */ -static mo_sock_t gs_sockets[MOLINK_NUM_SOCKETS] = {0}; +static mo_sock_t gs_sockets[MOLINK_NUM_SOCKETS] = {0}; static mo_sock_t *mo_get_socket(int socket) { @@ -108,17 +108,17 @@ static mo_sock_t *mo_tryget_socket(int socket) */ static void mo_event_callback(mo_netconn_t *netconn, mo_netconn_evt_t evt, os_uint16_t len) { - os_bool_t do_check_waiter; + os_bool_t do_check_waiter; struct mo_select_cb *scb; - os_slist_node_t * node; - int last_select_cb_ctr; - int do_signal; - os_int32_t s; - mo_sock_t * sock; + os_slist_node_t *node; + int last_select_cb_ctr; + int do_signal; + os_int32_t s; + mo_sock_t *sock; #ifdef OS_USING_IO_MULTIPLEXING - os_uint16_t evt_key = 0; - os_slist_node_t *poll_node; - poll_req_t *poll_req; + os_uint16_t evt_key = 0; + os_slist_node_t *poll_node; + poll_req_t *poll_req; #endif // Get socket @@ -147,7 +147,7 @@ static void mo_event_callback(mo_netconn_t *netconn, mo_netconn_evt_t evt, os_ui case MO_NETCONN_EVT_ERROR: do_check_waiter = OS_TRUE; - sock->errevent = 1; + sock->errevent = 1; break; case MO_NETCONN_EVT_RCVMINUS: @@ -288,11 +288,11 @@ static int alloc_socket(mo_netconn_t *netconn) if (!gs_sockets[i].select_waiting) { netconn->socket_id = i; - #ifdef MOLINK_USING_SELECT - netconn->evt_func = mo_event_callback; - #else - netconn->evt_func = OS_NULL; - #endif +#ifdef MOLINK_USING_SELECT + netconn->evt_func = mo_event_callback; +#else + netconn->evt_func = OS_NULL; +#endif MO_SYS_ARCH_UNPROTECT; return i; @@ -340,32 +340,32 @@ int mo_socket(mo_object_t *module, int domain, int type, int protocol) switch (type) { - #ifdef MOLINK_USING_UDP +#ifdef MOLINK_USING_UDP case SOCK_DGRAM: if (PF_INET6 == domain) { ntc_type = NETCONN_TYPE_UDP_V6; - } + } else { ntc_type = NETCONN_TYPE_UDP; } netconn = mo_netconn_create(module, ntc_type); break; - #endif - #ifdef MOLINK_USING_TCP +#endif +#ifdef MOLINK_USING_TCP case SOCK_STREAM: if (PF_INET6 == domain) { ntc_type = NETCONN_TYPE_TCP_V6; - } + } else { ntc_type = NETCONN_TYPE_TCP; } netconn = mo_netconn_create(module, ntc_type); break; - #endif +#endif default: WARN("Module %s Don't support socket type %d", module->name, type); break; @@ -384,15 +384,15 @@ int mo_socket(mo_object_t *module, int domain, int type, int protocol) return -1; } - gs_sockets[socket_id].netconn = netconn; - gs_sockets[socket_id].lastdata = OS_NULL; - gs_sockets[socket_id].lastoffset = 0; + gs_sockets[socket_id].netconn = netconn; + gs_sockets[socket_id].lastdata = OS_NULL; + gs_sockets[socket_id].lastoffset = 0; gs_sockets[socket_id].recv_timeout = 0; gs_sockets[socket_id].rcvevent = 0; // when sock create successful, sock can write - gs_sockets[socket_id].sendevent = 1; - gs_sockets[socket_id].errevent = 0; + gs_sockets[socket_id].sendevent = 1; + gs_sockets[socket_id].errevent = 0; gs_sockets[socket_id].select_waiting = 0; #ifdef OS_USING_IO_MULTIPLEXING os_slist_init(&gs_sockets[socket_id].req_slist_head); @@ -422,7 +422,7 @@ int mo_closesocket(int socket) int mo_closesocket(mo_object_t *module, int socket) { #endif - OS_ASSERT(module != OS_NULL); + OS_ASSERT(module != OS_NULL); int ret; mo_sock_t *sock = mo_get_socket(socket); @@ -444,7 +444,7 @@ int mo_closesocket(mo_object_t *module, int socket) MO_SYS_ARCH_PROTECT; mo_netconn_t *netconn = sock->netconn; - sock->netconn = OS_NULL; + sock->netconn = OS_NULL; MO_SYS_ARCH_UNPROTECT; if (OS_NULL != sock->lastdata) @@ -460,10 +460,10 @@ int mo_closesocket(mo_object_t *module, int socket) if (OS_NULL != netconn) { ret = mo_netconn_destroy(module, netconn); - if(ret != OS_EOK) + if (ret != OS_EOK) { ERROR("Module %s close socket %d failed!", module->name, socket); - return ret; + return ret; } } @@ -503,10 +503,10 @@ int mo_bind(mo_object_t *module, int socket, const struct sockaddr *name, sockle return -1; } - ip_addr_t remote_ip = {0}; + ip_addr_t remote_ip = {0}; os_uint16_t remote_port = 0; - //socketaddr_to_ipaddr_port(name, &remote_ip, &remote_port); + // socketaddr_to_ipaddr_port(name, &remote_ip, &remote_port); SOCKADDR_TO_IPADDR_PORT(name, &remote_ip, &remote_port); os_err_t result = mo_netconn_bind(module, sock->netconn, remote_ip, remote_port); @@ -538,7 +538,11 @@ int mo_bind_with_cb(int socket, const struct sockaddr *name, socklen_t namelen, { mo_object_t *module = mo_object_get(); #elif defined(MOLINK_USING_MULTI_MODULES) -int mo_bind_with_cb(mo_object_t *module, int socket, const struct sockaddr *name, socklen_t namelen, mo_netconn_data_callback cb) +int mo_bind_with_cb(mo_object_t *module, + int socket, + const struct sockaddr *name, + socklen_t namelen, + mo_netconn_data_callback cb) { #endif OS_ASSERT(module != OS_NULL); @@ -551,10 +555,10 @@ int mo_bind_with_cb(mo_object_t *module, int socket, const struct sockaddr *name return -1; } - ip_addr_t remote_ip = {0}; + ip_addr_t remote_ip = {0}; os_uint16_t remote_port = 0; - //socketaddr_to_ipaddr_port(name, &remote_ip, &remote_port); + // socketaddr_to_ipaddr_port(name, &remote_ip, &remote_port); SOCKADDR_TO_IPADDR_PORT(name, &remote_ip, &remote_port); os_err_t result = mo_netconn_bind(module, sock->netconn, remote_ip, remote_port); @@ -566,7 +570,7 @@ int mo_bind_with_cb(mo_object_t *module, int socket, const struct sockaddr *name #ifdef MOLINK_USING_SOCKETS_OPS sock->netconn->data_func = cb; #endif - + return 0; } #endif /* MOLINK_USING_SERVER_MODE */ @@ -603,10 +607,10 @@ int mo_connect(mo_object_t *module, int socket, const struct sockaddr *name, soc return -1; } - ip_addr_t remote_ip = {0}; + ip_addr_t remote_ip = {0}; os_uint16_t remote_port = 0; - //socketaddr_to_ipaddr_port(name, &remote_ip, &remote_port); + // socketaddr_to_ipaddr_port(name, &remote_ip, &remote_port); SOCKADDR_TO_IPADDR_PORT(name, &remote_ip, &remote_port); os_err_t result = mo_netconn_connect(module, sock->netconn, remote_ip, remote_port); @@ -638,17 +642,17 @@ static int module_tcp_send(mo_object_t *module, mo_netconn_t *netconn, const cha #endif #ifdef MOLINK_USING_UDP -static int module_udp_sendto(mo_object_t * module, - mo_netconn_t * netconn, - const char * data, - os_size_t size, +static int module_udp_sendto(mo_object_t *module, + mo_netconn_t *netconn, + const char *data, + os_size_t size, const struct sockaddr *to, - socklen_t tolen) + socklen_t tolen) { - ip_addr_t remote_ip = {0}; + ip_addr_t remote_ip = {0}; os_uint16_t remote_port = 0; - //socketaddr_to_ipaddr_port(to, &remote_ip, &remote_port); + // socketaddr_to_ipaddr_port(to, &remote_ip, &remote_port); SOCKADDR_TO_IPADDR_PORT(to, &remote_ip, &remote_port); if (netconn->stat != NETCONN_STAT_CONNECT) @@ -660,7 +664,7 @@ static int module_udp_sendto(mo_object_t * module, return -1; } } - + os_size_t sent_size = mo_netconn_sendto(module, netconn, remote_ip, remote_port, data, size); if (sent_size <= 0) { @@ -689,22 +693,17 @@ static int module_udp_sendto(mo_object_t * module, *********************************************************************************************************************** */ #if defined(MOLINK_USING_SINGLE_MODULE) -int mo_sendto(int socket, - const void * data, - size_t size, - int flags, - const struct sockaddr *to, - socklen_t tolen) +int mo_sendto(int socket, const void *data, size_t size, int flags, const struct sockaddr *to, socklen_t tolen) { mo_object_t *module = mo_object_get(); #elif defined(MOLINK_USING_MULTI_MODULES) -int mo_sendto(mo_object_t * module, - int socket, - const void * data, - size_t size, - int flags, +int mo_sendto(mo_object_t *module, + int socket, + const void *data, + size_t size, + int flags, const struct sockaddr *to, - socklen_t tolen) + socklen_t tolen) { #endif OS_ASSERT(module != OS_NULL); @@ -720,17 +719,17 @@ int mo_sendto(mo_object_t * module, int result = -1; switch (sock->netconn->type) { - #ifdef MOLINK_USING_TCP +#ifdef MOLINK_USING_TCP case NETCONN_TYPE_TCP: result = module_tcp_send(module, sock->netconn, (const char *)data, size); break; - #endif - #ifdef MOLINK_USING_UDP +#endif +#ifdef MOLINK_USING_UDP case NETCONN_TYPE_UDP: case NETCONN_TYPE_UDP_V6: result = module_udp_sendto(module, sock->netconn, (const char *)data, size, to, tolen); - break; - #endif + break; +#endif default: break; } @@ -781,11 +780,11 @@ int mo_send(mo_object_t *module, int socket, const void *data, size_t size, int #ifdef MOLINK_USING_TCP static int module_recv_tcp(mo_object_t *module, mo_sock_t *sock, void *mem, size_t len, int flags) { - os_size_t recvd = 0; - void * data_ptr = OS_NULL; - os_size_t data_len = 0; - os_err_t result = OS_EOK; - os_uint16_t copylen = 0; + os_size_t recvd = 0; + void *data_ptr = OS_NULL; + os_size_t data_len = 0; + os_err_t result = OS_EOK; + os_uint16_t copylen = 0; os_size_t recv_left = (len <= OS_UINT32_MAX) ? (ssize_t)len : OS_UINT32_MAX; @@ -804,7 +803,7 @@ static int module_recv_tcp(mo_object_t *module, mo_sock_t *sock, void *mem, size { MO_SYS_ARCH_UNPROTECT; /* No data was left from the previous operation, so we try to get some from the network. */ - result = mo_netconn_recvfrom(module, sock->netconn, &data_ptr, &data_len, OS_NULL, OS_NULL, timeout); + result = mo_netconn_recvfrom(module, sock->netconn, &data_ptr, &data_len, OS_NULL, OS_NULL, timeout); if (result != OS_EOK) { if (recvd > 0) @@ -823,9 +822,9 @@ static int module_recv_tcp(mo_object_t *module, mo_sock_t *sock, void *mem, size else if (OS_ETIMEOUT == result || OS_EEMPTY == result) { DEBUG("Module %s socket %d receive (%d ticks) timeout", - module->name, - sock->netconn->socket_id, - os_tick_from_ms(sock->recv_timeout)); + module->name, + sock->netconn->socket_id, + os_tick_from_ms(sock->recv_timeout)); errno = EAGAIN; return -1; @@ -833,8 +832,8 @@ static int module_recv_tcp(mo_object_t *module, mo_sock_t *sock, void *mem, size } MO_SYS_ARCH_PROTECT; - sock->lastdata = data_ptr; - sock->lastlen = data_len; + sock->lastdata = data_ptr; + sock->lastlen = data_len; sock->lastoffset = 0; } @@ -866,8 +865,8 @@ static int module_recv_tcp(mo_object_t *module, mo_sock_t *sock, void *mem, size } else { - sock->lastdata = OS_NULL; - sock->lastlen = 0; + sock->lastdata = OS_NULL; + sock->lastlen = 0; sock->lastoffset = 0; MO_SYS_ARCH_UNPROTECT; @@ -884,15 +883,27 @@ static int module_recv_tcp(mo_object_t *module, mo_sock_t *sock, void *mem, size #endif #ifdef MOLINK_USING_UDP -static int module_recvfrom_udp(mo_object_t *module, mo_sock_t *sock, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen) +static int module_recvfrom_udp(mo_object_t *module, + mo_sock_t *sock, + void *mem, + size_t len, + int flags, + struct sockaddr *from, + socklen_t *fromlen) { os_size_t data_len = 0; - void * data_tmp = OS_NULL; - os_err_t result = OS_EOK; + void *data_tmp = OS_NULL; + os_err_t result = OS_EOK; ip_addr_t addr; os_uint16_t port; - - result = mo_netconn_recvfrom(module, sock->netconn, &data_tmp, &data_len, &addr, &port, os_tick_from_ms(sock->recv_timeout)); + + result = mo_netconn_recvfrom(module, + sock->netconn, + &data_tmp, + &data_len, + &addr, + &port, + os_tick_from_ms(sock->recv_timeout)); if (OS_ERROR == result) { ERROR("Module %s receive error, socket %d state %d error", @@ -908,7 +919,7 @@ static int module_recvfrom_udp(mo_object_t *module, mo_sock_t *sock, void *mem, module->name, sock->netconn->socket_id, os_tick_from_ms(sock->recv_timeout)); -#endif +#endif errno = EAGAIN; return -1; } @@ -923,9 +934,8 @@ static int module_recvfrom_udp(mo_object_t *module, mo_sock_t *sock, void *mem, memcpy(mem, data_tmp, data_len); os_free(data_tmp); - //TODO: to check fromlen ? - IPADDR_PORT_TO_SOCKADDR(from, &addr, &port); - + // TODO: to check fromlen ? + IPADDR_PORT_TO_SOCKADDR(from, &addr, &port); if (data_len > 0) { @@ -954,22 +964,17 @@ static int module_recvfrom_udp(mo_object_t *module, mo_sock_t *sock, void *mem, *********************************************************************************************************************** */ #if defined(MOLINK_USING_SINGLE_MODULE) -int mo_recvfrom(int socket, - void * mem, - size_t len, - int flags, - struct sockaddr *from, - socklen_t * fromlen) +int mo_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen) { mo_object_t *module = mo_object_get(); #elif defined(MOLINK_USING_MULTI_MODULES) -int mo_recvfrom(mo_object_t * module, - int socket, - void * mem, - size_t len, - int flags, +int mo_recvfrom(mo_object_t *module, + int socket, + void *mem, + size_t len, + int flags, struct sockaddr *from, - socklen_t * fromlen) + socklen_t *fromlen) { #endif OS_ASSERT(module != OS_NULL); @@ -985,17 +990,17 @@ int mo_recvfrom(mo_object_t * module, int result = -1; if (NETCONN_TYPE_TCP == sock->netconn->type) { - #ifdef MOLINK_USING_TCP +#ifdef MOLINK_USING_TCP result = module_recv_tcp(module, sock, mem, len, flags); - #endif +#endif } else /* NETCONN_TYPE_UDP */ - { - #ifdef MOLINK_USING_UDP + { +#ifdef MOLINK_USING_UDP result = module_recvfrom_udp(module, sock, mem, len, flags, from, fromlen); - #endif +#endif } - + return result; } @@ -1074,8 +1079,8 @@ int mo_getsockopt(mo_object_t *module, int socket, int level, int optname, void switch (optname) { case SO_RCVTIMEO: - timeout = sock->recv_timeout; - ((struct timeval *)(optval))->tv_sec = (timeout) / 1000U; + timeout = sock->recv_timeout; + ((struct timeval *)(optval))->tv_sec = (timeout) / 1000U; ((struct timeval *)(optval))->tv_usec = (timeout % 1000U) * 1000U; break; default: @@ -1175,10 +1180,10 @@ struct hostent *mo_gethostbyname(mo_object_t *module, const char *name) /* buffer variables for mo_gethostbyname() */ static struct hostent s_hostent; - static char * s_aliases; - static ip_addr_t s_hostent_addr; - static ip_addr_t * s_phostent_addr[2]; - static char s_hostname[MOLINK_DNS_MAX_NAME_LEN + 1]; + static char *s_aliases; + static ip_addr_t s_hostent_addr; + static ip_addr_t *s_phostent_addr[2]; + static char s_hostname[MOLINK_DNS_MAX_NAME_LEN + 1]; os_err_t result = mo_netconn_gethostbyname(module, name, &addr); if (result != OS_EOK) @@ -1188,18 +1193,18 @@ struct hostent *mo_gethostbyname(mo_object_t *module, const char *name) } /* fill hostent */ - s_hostent_addr = addr; + s_hostent_addr = addr; s_phostent_addr[0] = &s_hostent_addr; s_phostent_addr[1] = OS_NULL; strncpy(s_hostname, name, MOLINK_DNS_MAX_NAME_LEN); s_hostname[MOLINK_DNS_MAX_NAME_LEN] = 0; - s_hostent.h_name = s_hostname; - s_aliases = OS_NULL; - s_hostent.h_aliases = &s_aliases; - s_hostent.h_addrtype = AF_INET; - s_hostent.h_length = sizeof(ip_addr_t); + s_hostent.h_name = s_hostname; + s_aliases = OS_NULL; + s_hostent.h_aliases = &s_aliases; + s_hostent.h_addrtype = AF_INET; + s_hostent.h_length = sizeof(ip_addr_t); s_hostent.h_addr_list = (char **)&s_phostent_addr; return &s_hostent; @@ -1296,7 +1301,7 @@ int mo_getaddrinfo(const char *nodename, const char *servname, const struct addr } os_size_t total_size = sizeof(struct addrinfo) + sizeof(struct sockaddr_storage); - os_size_t namelen = 0; + os_size_t namelen = 0; if (nodename != OS_NULL) { namelen = strlen(nodename); @@ -1317,21 +1322,21 @@ int mo_getaddrinfo(const char *nodename, const char *servname, const struct addr } /* cast through void* to get rid of alignment warnings */ - struct sockaddr_storage *sa = (struct sockaddr_storage *)(void *)((uint8_t *)ai + sizeof(struct addrinfo)); - struct sockaddr_in * sa4 = (struct sockaddr_in *)sa; + struct sockaddr_storage *sa = (struct sockaddr_storage *)(void *)((uint8_t *)ai + sizeof(struct addrinfo)); + struct sockaddr_in *sa4 = (struct sockaddr_in *)sa; /* set up sockaddr */ #if defined(MOLINK_USING_IPV4) && defined(MOLINK_USING_IPV6) sa4->sin_addr.s_addr = addr.u_addr.ip4.addr; - //sa4->type = IPADDR_TYPE_V4; + // sa4->type = IPADDR_TYPE_V4; #elif defined(MOLINK_USING_IPV4) sa4->sin_addr.s_addr = addr.addr; #elif defined(MOLINK_USING_IPV6) #error "Not support IPV6." #endif /* MOLINK_USING_IPV4 && MOLINK_USING_IPV6 */ sa4->sin_family = AF_INET; - sa4->sin_len = sizeof(struct sockaddr_in); - sa4->sin_port = htons((os_uint16_t)port_nr); - ai->ai_family = AF_INET; + sa4->sin_len = sizeof(struct sockaddr_in); + sa4->sin_port = htons((os_uint16_t)port_nr); + ai->ai_family = AF_INET; /* set up addrinfo */ if (hints != OS_NULL) @@ -1348,7 +1353,7 @@ int mo_getaddrinfo(const char *nodename, const char *servname, const struct addr ai->ai_canonname[namelen] = 0; } ai->ai_addrlen = sizeof(struct sockaddr_storage); - ai->ai_addr = (struct sockaddr *)sa; + ai->ai_addr = (struct sockaddr *)sa; *res = ai; @@ -1390,7 +1395,7 @@ void mo_freeaddrinfo(struct addrinfo *ai) * @param exceptset_out set os sockets that had error events * @return number of sockets that had events (read/write/exception) (>= 0) */ -static int mo_selscan(int maxfdp1, +static int mo_selscan(int maxfdp1, fd_set *readset_in, fd_set *writeset_in, fd_set *exceptset_in, @@ -1398,16 +1403,16 @@ static int mo_selscan(int maxfdp1, fd_set *writeset_out, fd_set *exceptset_out) { - fd_set lreadset; - fd_set lwriteset; - fd_set lexceptset; + fd_set lreadset; + fd_set lwriteset; + fd_set lexceptset; mo_sock_t *sock; - void * lastdata; - os_int8_t rcvevent; + void *lastdata; + os_int8_t rcvevent; os_uint8_t sendevent; os_uint8_t errevent; - int nready; - int index; + int nready; + int index; FD_ZERO(&lreadset); FD_ZERO(&lwriteset); @@ -1428,10 +1433,10 @@ static int mo_selscan(int maxfdp1, sock = mo_get_socket(index); if (NULL != sock) { - lastdata = sock->lastdata; - rcvevent = sock->rcvevent; + lastdata = sock->lastdata; + rcvevent = sock->rcvevent; sendevent = sock->sendevent; - errevent = sock->errevent; + errevent = sock->errevent; MO_SYS_ARCH_UNPROTECT; @@ -1462,8 +1467,8 @@ static int mo_selscan(int maxfdp1, } // copy local sets to the ones provided as arguments - *readset_out = lreadset; - *writeset_out = lwriteset; + *readset_out = lreadset; + *writeset_out = lwriteset; *exceptset_out = lexceptset; return nready; @@ -1471,7 +1476,7 @@ static int mo_selscan(int maxfdp1, static os_err_t mo_do_sem_init(os_sem_t *sem, os_uint32_t value, os_uint32_t max_value) { - char name[OS_NAME_MAX + 1]; + char name[OS_NAME_MAX + 1]; static int cnt = 0; snprintf(name, OS_NAME_MAX, "slt_sem_%d", cnt++); @@ -1484,16 +1489,16 @@ static os_err_t mo_do_sem_init(os_sem_t *sem, os_uint32_t value, os_uint32_t max */ int mo_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout) { - fd_set lreadset; - fd_set lwriteset; - fd_set lexceptset; + fd_set lreadset; + fd_set lwriteset; + fd_set lexceptset; struct mo_select_cb select_cb; - mo_sock_t * sock; - os_err_t op_err; - os_tick_t timeout_tick; - int maxfdp2; - int nready; - int index; + mo_sock_t *sock; + os_err_t op_err; + os_tick_t timeout_tick; + int maxfdp2; + int nready; + int index; do { @@ -1519,9 +1524,9 @@ int mo_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, // create select_cb wait event os_slist_init(&select_cb.slist); - select_cb.readset = readset; - select_cb.writeset = writeset; - select_cb.exceptset = exceptset; + select_cb.readset = readset; + select_cb.writeset = writeset; + select_cb.exceptset = exceptset; select_cb.sem_signalled = 0; // init sem invalid, one sem for thread op_err = mo_do_sem_init(&select_cb.sem, 0, OS_SEM_MAX_VALUE); @@ -1558,7 +1563,7 @@ int mo_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, // Not a valid socket, socket may closed if (OS_NULL == sock || OS_NULL == sock->netconn) { - nready = -1; + nready = -1; maxfdp2 = index + 1; MO_SYS_ARCH_UNPROTECT; break; @@ -1661,11 +1666,11 @@ int mo_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, #ifdef OS_USING_IO_MULTIPLEXING int mo_poll(int socket, struct vfs_pollfd *req, os_bool_t poll_setup) { - mo_sock_t *sock; - int mask = 0; + mo_sock_t *sock; + int mask = 0; os_slist_node_t *node; os_slist_node_t *tmp_node; - poll_req_t *poll_req = OS_NULL; + poll_req_t *poll_req = OS_NULL; sock = mo_get_socket(socket); @@ -1690,7 +1695,7 @@ int mo_poll(int socket, struct vfs_pollfd *req, os_bool_t poll_setup) os_slist_add_tail(&sock->req_slist_head, &poll_req->req_list); MO_SYS_ARCH_UNPROTECT; } - else // poll end + else // poll end { os_slist_for_each_safe(node, tmp_node, &sock->req_slist_head) { diff --git a/components/molink/api/source/mo_wifi.c b/components/molink/api/source/mo_wifi.c index c293dda3..7d3faf5e 100644 --- a/components/molink/api/source/mo_wifi.c +++ b/components/molink/api/source/mo_wifi.c @@ -27,7 +27,7 @@ #include #define MO_LOG_TAG "molink.wifi" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_WIFI_OPS @@ -50,8 +50,8 @@ static mo_wifi_ops_t *get_wifi_ops(mo_object_t *self) * * @param[in] module The descriptor of molink module instance * @param[in] mode The wifi mode @see mo_wifi_mode_t - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Set module functionality level successfully * @retval OS_ERROR Set module functionality level error * @retval OS_ETIMEOUT Set module functionality level timeout @@ -83,7 +83,7 @@ os_err_t mo_wifi_set_mode(mo_object_t *module, mo_wifi_mode_t mode) * @brief Execute AT command to get module wifi mode * * @param[in] module The descriptor of molink module instance - * + * * @return On success, return wifi mode; on error, return MO_WIFI_MODE_NULL. @see mo_wifi_mode_t *********************************************************************************************************************** */ @@ -112,7 +112,7 @@ mo_wifi_mode_t mo_wifi_get_mode(mo_object_t *module) * @brief Execute AT command to get module wifi state * * @param[in] module The descriptor of molink module instance - * + * * @return On success, return wifi state; on error, return MO_WIFI_STAT_NULL. @see mo_wifi_stat_t *********************************************************************************************************************** */ @@ -144,13 +144,18 @@ mo_wifi_stat_t mo_wifi_get_stat(mo_object_t *module) * @param[out] ip The ip to store * @param[out] gw The gw to store * @param[out] mask The mask to store - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK get sta cip infomation successfully * @retval OS_ERROR get sta cip infomation error *********************************************************************************************************************** */ -os_err_t mo_wifi_get_sta_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t *gw, ip_addr_t *mask, ip_addr_t *ip6_ll, ip_addr_t *ip6_gl) +os_err_t mo_wifi_get_sta_cip(mo_object_t *module, + ip_addr_t *ip, + ip_addr_t *gw, + ip_addr_t *mask, + ip_addr_t *ip6_ll, + ip_addr_t *ip6_gl) { OS_ASSERT(OS_NULL != module); @@ -178,8 +183,8 @@ os_err_t mo_wifi_get_sta_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t *gw, * @param[in] ip The ip to set * @param[in] gw The gw to set * @param[in] mask The mask to set - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK get ap cip infomation successfully * @retval OS_ERROR get ap cip infomation error *********************************************************************************************************************** @@ -213,8 +218,8 @@ os_err_t mo_wifi_set_ap_cip(mo_object_t *module, char *ip, char *gw, char *mask) * @param[out] ip The ip to store * @param[out] gw The gw to store * @param[out] mask The mask to store - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK get ap cip infomation successfully * @retval OS_ERROR get ap cip infomation error *********************************************************************************************************************** @@ -248,8 +253,8 @@ os_err_t mo_wifi_get_ap_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t *gw, i * * @param[in] module The descriptor of molink module instance * @param[out] mac The mac to store - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK get sta mac infomation successfully * @retval OS_ERROR get sta mac infomation error *********************************************************************************************************************** @@ -281,8 +286,8 @@ os_err_t mo_wifi_get_sta_mac(mo_object_t *module, char mac[]) * * @param[in] module The descriptor of molink module instance * @param[out] mac The mac to store - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK get ap mac infomation successfully * @retval OS_ERROR get ap mac infomation error *********************************************************************************************************************** @@ -315,8 +320,8 @@ os_err_t mo_wifi_get_ap_mac(mo_object_t *module, char mac[]) * @param[in] module The descriptor of molink module instance * @param[in] ssid The ssid of ap to scan, if ssid is NULL, scan all available ap * @param[out] scan_result The buffer to store scan ap infomation - * - * @return On success, return OS_EOK; on error, return a error code. + * + * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Scan infomation successfully * @retval OS_ETIMEOUT Scan infomation timeout * @retval OS_ERROR Scan infomation error @@ -359,12 +364,12 @@ void mo_wifi_scan_info_free(mo_wifi_scan_result_t *scan_result) /** *********************************************************************************************************************** - * @brief Execute AT command to connect to ap + * @brief Execute AT command to connect to ap * * @param[in] module The descriptor of molink module instance * @param[in] ssid The ssid of ap to connect * @param[in] password The password of ap to connect - * + * * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Connect successfully * @retval OS_ETIMEOUT Connect timeout @@ -375,7 +380,7 @@ os_err_t mo_wifi_connect_ap(mo_object_t *module, const char *ssid, const char *p { OS_ASSERT(OS_NULL != module); OS_ASSERT(OS_NULL != ssid); - //OS_ASSERT(OS_NULL != password); + // OS_ASSERT(OS_NULL != password); mo_wifi_ops_t *ops = get_wifi_ops(module); @@ -395,10 +400,10 @@ os_err_t mo_wifi_connect_ap(mo_object_t *module, const char *ssid, const char *p /** *********************************************************************************************************************** - * @brief Execute AT command to disconnect to ap + * @brief Execute AT command to disconnect to ap * * @param[in] module The descriptor of molink module instance - * + * * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK Disconnect successfully * @retval OS_ETIMEOUT Disconnect timeout @@ -427,21 +432,22 @@ os_err_t mo_wifi_disconnect_ap(mo_object_t *module) /** *********************************************************************************************************************** - * @brief Execute AT command to start ap + * @brief Execute AT command to start ap * * @param[in] module The descriptor of molink module instance * @param[in] ssid The ssid of ap to start * @param[in] password The password of ap to start * @param[in] channel The channel of ap to start * @param[in] ecn The encryption method of ap to start - * + * * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK start successfully * @retval OS_ETIMEOUT start timeout * @retval OS_ERROR start error *********************************************************************************************************************** */ -os_err_t mo_wifi_start_ap(mo_object_t *module, const char *ssid, const char *password, os_uint8_t channel, os_uint8_t ecn) +os_err_t +mo_wifi_start_ap(mo_object_t *module, const char *ssid, const char *password, os_uint8_t channel, os_uint8_t ecn) { OS_ASSERT(OS_NULL != module); OS_ASSERT(OS_NULL != ssid); @@ -465,10 +471,10 @@ os_err_t mo_wifi_start_ap(mo_object_t *module, const char *ssid, const char *pas /** *********************************************************************************************************************** - * @brief Execute AT command to stop ap + * @brief Execute AT command to stop ap * * @param[in] module The descriptor of molink module instance - * + * * @return On success, return OS_EOK; on error, return a error code. * @retval OS_EOK stop successfully * @retval OS_ETIMEOUT stop timeout diff --git a/components/molink/core/include/mo_ipaddr.h b/components/molink/core/include/mo_ipaddr.h index dae26201..f8f996c9 100644 --- a/components/molink/core/include/mo_ipaddr.h +++ b/components/molink/core/include/mo_ipaddr.h @@ -34,12 +34,12 @@ extern "C" { #endif #ifdef MOLINK_USING_IPV6 -#define IPADDR_MAX_STR_LEN (45) /* without '\0' */ +#define IPADDR_MAX_STR_LEN (45) /* without '\0' */ #else -#define IPADDR_MAX_STR_LEN (15) /* without '\0' */ +#define IPADDR_MAX_STR_LEN (15) /* without '\0' */ #endif -#define IPADDR_MIN_STR_LEN (7) /* without '\0' */ +#define IPADDR_MIN_STR_LEN (7) /* without '\0' */ /* * Definitions of bits in internet address integers. @@ -155,9 +155,9 @@ typedef struct ip4_addr #define ip4_addr_isany(ipaddr) ((ipaddr) == NULL || ip4_addr_isany_val(*(ipaddr))) in_addr_t net_ipaddr_addr(const char *cp); -int net_ip4addr_aton(const char *cp, ip4_addr_t *addr); -char * net_ip4addr_ntoa(const ip4_addr_t *addr); -char * net_ip4addr_ntoa_r(const ip4_addr_t *addr, char *buf, int buflen); +int net_ip4addr_aton(const char *cp, ip4_addr_t *addr); +char *net_ip4addr_ntoa(const ip4_addr_t *addr); +char *net_ip4addr_ntoa_r(const ip4_addr_t *addr, char *buf, int buflen); #endif /* MOLINK_USING_IPV4 */ struct in6_addr @@ -165,7 +165,7 @@ struct in6_addr union { uint32_t u32_addr[4]; - uint8_t u8_addr[16]; + uint8_t u8_addr[16]; } un; #define s6_addr un.u8_addr }; @@ -174,12 +174,12 @@ struct in6_addr enum molink_ipv6_scope_type { - /** Unknown */ - IP6_UNKNOWN = 0, - /** Unicast */ - IP6_UNICAST = 1, - /** Multicast */ - IP6_MULTICAST = 2 + /** Unknown */ + IP6_UNKNOWN = 0, + /** Unicast */ + IP6_UNICAST = 1, + /** Multicast */ + IP6_MULTICAST = 2 }; typedef struct ip6_addr @@ -191,13 +191,13 @@ typedef struct ip6_addr } ip6_addr_t; #ifdef MOLINK_USING_IPV6_SCOPES -#define ip6_addr_clear_zone(ip6addr) ((ip6addr)->zone = 0) -#define ip6_addr_zone(ip6addr) ((ip6addr)->zone) +#define ip6_addr_clear_zone(ip6addr) ((ip6addr)->zone = 0) +#define ip6_addr_zone(ip6addr) ((ip6addr)->zone) #else #define ip6_addr_clear_zone(ip6addr) -#define ip6_addr_zone(ip6addr) 0 +#define ip6_addr_zone(ip6addr) 0 #endif -#define ip6_addr_has_scope(ip6addr, type) 0 +#define ip6_addr_has_scope(ip6addr, type) 0 /** This macro can be used to initialize a variable of type struct in6_addr to the IPv6 wildcard address. */ @@ -260,7 +260,7 @@ extern const struct in6_addr in6addr_any; (((ip6addr).addr[0] == 0) && ((ip6addr).addr[1] == 0) && ((ip6addr).addr[2] == 0) && ((ip6addr).addr[3] == 0)) #define ip6_addr_isany(ip6addr) (((ip6addr) == NULL) || ip6_addr_isany_val(*(ip6addr))) -int net_ip6addr_aton(const char *cp, ip6_addr_t *addr); +int net_ip6addr_aton(const char *cp, ip6_addr_t *addr); char *net_ip6addr_ntoa(const ip6_addr_t *addr); char *net_ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen); #endif /* MOLINK_USING_IPV6 */ @@ -292,7 +292,7 @@ typedef struct _ip_addr } while (0) #define IP_GET_TYPE(ipaddr) ((ipaddr)->type) -#define IP_IS_ANY_TYPE_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_ANY) +#define IP_IS_ANY_TYPE_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_ANY) #define IP_IS_V4_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V4) #define IP_IS_V6_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V6) @@ -373,7 +373,7 @@ typedef struct _ip_addr typedef ip4_addr_t ip_addr_t; -#define IP_IS_ANY_TYPE_VAL(ipaddr) 0 +#define IP_IS_ANY_TYPE_VAL(ipaddr) 0 #define IP_SET_TYPE_VAL(ipaddr, iptype) #define IP_SET_TYPE(ipaddr, iptype) @@ -398,7 +398,7 @@ typedef ip4_addr_t ip_addr_t; typedef ip6_addr_t ip_addr_t; -#define IP_IS_ANY_TYPE_VAL(ipaddr) 0 +#define IP_IS_ANY_TYPE_VAL(ipaddr) 0 #define IP_SET_TYPE_VAL(ipaddr, iptype) #define IP_SET_TYPE(ipaddr, iptype) @@ -421,7 +421,7 @@ typedef ip6_addr_t ip_addr_t; #endif /* MOLINK_USING_IPV4 && MOLINK_USING_IPV6 */ const char *net_inet_ntop(int af, const void *src, char *dst, int32_t size); -int net_inet_pton(int af, const char *src, void *dst); +int net_inet_pton(int af, const char *src, void *dst); #define inet_ntop(af, src, dst, size) net_inet_ntop(af, src, dst, size) #define inet_pton(af, src, dst) net_inet_pton(af, src, dst) @@ -432,46 +432,65 @@ int net_inet_pton(int af, const char *src, void *dst); #endif #ifdef MOLINK_USING_IPV6 -#define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr) {(target_in6addr)->un.u32_addr[0] = (source_ip6addr)->addr[0]; \ - (target_in6addr)->un.u32_addr[1] = (source_ip6addr)->addr[1]; \ - (target_in6addr)->un.u32_addr[2] = (source_ip6addr)->addr[2]; \ - (target_in6addr)->un.u32_addr[3] = (source_ip6addr)->addr[3];} -#define inet6_addr_to_ip6addr(target_ip6addr, source_in6addr) {(target_ip6addr)->addr[0] = (source_in6addr)->un.u32_addr[0]; \ - (target_ip6addr)->addr[1] = (source_in6addr)->un.u32_addr[1]; \ - (target_ip6addr)->addr[2] = (source_in6addr)->un.u32_addr[2]; \ - (target_ip6addr)->addr[3] = (source_in6addr)->un.u32_addr[3]; \ - ip6_addr_clear_zone(target_ip6addr);} -#endif +#define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr) \ + { \ + (target_in6addr)->un.u32_addr[0] = (source_ip6addr)->addr[0]; \ + (target_in6addr)->un.u32_addr[1] = (source_ip6addr)->addr[1]; \ + (target_in6addr)->un.u32_addr[2] = (source_ip6addr)->addr[2]; \ + (target_in6addr)->un.u32_addr[3] = (source_ip6addr)->addr[3]; \ + } +#define inet6_addr_to_ip6addr(target_ip6addr, source_in6addr) \ + { \ + (target_ip6addr)->addr[0] = (source_in6addr)->un.u32_addr[0]; \ + (target_ip6addr)->addr[1] = (source_in6addr)->un.u32_addr[1]; \ + (target_ip6addr)->addr[2] = (source_in6addr)->un.u32_addr[2]; \ + (target_ip6addr)->addr[3] = (source_in6addr)->un.u32_addr[3]; \ + ip6_addr_clear_zone(target_ip6addr); \ + } +#endif #ifdef MOLINK_USING_IPV4 -#define IP4ADDR_PORT_TO_SOCKADDR(sin, ipaddr, port) do { \ - (sin)->sin_len = sizeof(struct sockaddr_in); \ - (sin)->sin_family = AF_INET; \ - (sin)->sin_port = htons(*(port)); \ - inet_addr_from_ip4addr(&(sin)->sin_addr, ipaddr); \ - memset((sin)->sin_zero, 0, SIN_ZERO_LEN); }while(0) -#define SOCKADDR4_TO_IP4ADDR_PORT(sin, ipaddr, port) do { \ - inet_addr_to_ip4addr(ip_2_ip4(ipaddr), &((sin)->sin_addr)); \ - *(port) = ntohs((sin)->sin_port); }while(0) +#define IP4ADDR_PORT_TO_SOCKADDR(sin, ipaddr, port) \ + do \ + { \ + (sin)->sin_len = sizeof(struct sockaddr_in); \ + (sin)->sin_family = AF_INET; \ + (sin)->sin_port = htons(*(port)); \ + inet_addr_from_ip4addr(&(sin)->sin_addr, ipaddr); \ + memset((sin)->sin_zero, 0, SIN_ZERO_LEN); \ + } while (0) +#define SOCKADDR4_TO_IP4ADDR_PORT(sin, ipaddr, port) \ + do \ + { \ + inet_addr_to_ip4addr(ip_2_ip4(ipaddr), &((sin)->sin_addr)); \ + *(port) = ntohs((sin)->sin_port); \ + } while (0) #endif /* MOLINK_USING_IPV4 */ #ifdef MOLINK_USING_IPV6 #define ip6_addr_set_zone(ip6addr, zone_idx) -#define IP6ADDR_PORT_TO_SOCKADDR(sin6, ipaddr, port) do { \ - (sin6)->sin6_len = sizeof(struct sockaddr_in6); \ - (sin6)->sin6_family = AF_INET6; \ - (sin6)->sin6_port = htons(*(port)); \ - (sin6)->sin6_flowinfo = 0; \ - inet6_addr_from_ip6addr(&(sin6)->sin6_addr, ipaddr); \ - (sin6)->sin6_scope_id = ip6_addr_zone(ipaddr); }while(0) -#define SOCKADDR6_TO_IP6ADDR_PORT(sin6, ipaddr, port) do { \ - inet6_addr_to_ip6addr(ip_2_ip6(ipaddr), &((sin6)->sin6_addr)); \ - if (ip6_addr_has_scope(ip_2_ip6(ipaddr), IP6_UNKNOWN)) { \ - ip6_addr_set_zone(ip_2_ip6(ipaddr), (uint8_t)((sin6)->sin6_scope_id)); \ - } \ - *(port) = ntohs((sin6)->sin6_port); }while(0) +#define IP6ADDR_PORT_TO_SOCKADDR(sin6, ipaddr, port) \ + do \ + { \ + (sin6)->sin6_len = sizeof(struct sockaddr_in6); \ + (sin6)->sin6_family = AF_INET6; \ + (sin6)->sin6_port = htons(*(port)); \ + (sin6)->sin6_flowinfo = 0; \ + inet6_addr_from_ip6addr(&(sin6)->sin6_addr, ipaddr); \ + (sin6)->sin6_scope_id = ip6_addr_zone(ipaddr); \ + } while (0) +#define SOCKADDR6_TO_IP6ADDR_PORT(sin6, ipaddr, port) \ + do \ + { \ + inet6_addr_to_ip6addr(ip_2_ip6(ipaddr), &((sin6)->sin6_addr)); \ + if (ip6_addr_has_scope(ip_2_ip6(ipaddr), IP6_UNKNOWN)) \ + { \ + ip6_addr_set_zone(ip_2_ip6(ipaddr), (uint8_t)((sin6)->sin6_scope_id)); \ + } \ + *(port) = ntohs((sin6)->sin6_port); \ + } while (0) #endif /* MOLINK_USING_IPV6 */ #if defined(MOLINK_USING_IPV4) && defined(MOLINK_USING_IPV6) @@ -480,32 +499,41 @@ static void sockaddr_to_ipaddr_port(const struct sockaddr *sockaddr, ip_addr_t * { #define AF_INET 2 #define AF_INET6 10 - if (AF_INET6 == sockaddr->sa_family) { - SOCKADDR6_TO_IP6ADDR_PORT((const struct sockaddr_in6 *)(const void *)(sockaddr), ipaddr, port); - ipaddr->type = IPADDR_TYPE_V6; - } else { - SOCKADDR4_TO_IP4ADDR_PORT((const struct sockaddr_in *)(const void *)(sockaddr), ipaddr, port); - ipaddr->type = IPADDR_TYPE_V4; - } + if (AF_INET6 == sockaddr->sa_family) + { + SOCKADDR6_TO_IP6ADDR_PORT((const struct sockaddr_in6 *)(const void *)(sockaddr), ipaddr, port); + ipaddr->type = IPADDR_TYPE_V6; + } + else + { + SOCKADDR4_TO_IP4ADDR_PORT((const struct sockaddr_in *)(const void *)(sockaddr), ipaddr, port); + ipaddr->type = IPADDR_TYPE_V4; + } } -#define IPADDR_PORT_TO_SOCKADDR(sockaddr, ipaddr, port) do { \ - if (IP_IS_ANY_TYPE_VAL(*ipaddr) || IP_IS_V6_VAL(*ipaddr)) { \ - IP6ADDR_PORT_TO_SOCKADDR((struct sockaddr_in6*)(void*)(sockaddr), ip_2_ip6(ipaddr), port); \ - } else { \ - IP4ADDR_PORT_TO_SOCKADDR((struct sockaddr_in*)(void*)(sockaddr), ip_2_ip4(ipaddr), port); \ - } } while(0) +#define IPADDR_PORT_TO_SOCKADDR(sockaddr, ipaddr, port) \ + do \ + { \ + if (IP_IS_ANY_TYPE_VAL(*ipaddr) || IP_IS_V6_VAL(*ipaddr)) \ + { \ + IP6ADDR_PORT_TO_SOCKADDR((struct sockaddr_in6 *)(void *)(sockaddr), ip_2_ip6(ipaddr), port); \ + } \ + else \ + { \ + IP4ADDR_PORT_TO_SOCKADDR((struct sockaddr_in *)(void *)(sockaddr), ip_2_ip4(ipaddr), port); \ + } \ + } while (0) #define SOCKADDR_TO_IPADDR_PORT(sockaddr, ipaddr, port) sockaddr_to_ipaddr_port(sockaddr, ipaddr, port) -#elif defined (MOLINK_USING_IPV6) -#define IPADDR_PORT_TO_SOCKADDR(sockaddr, ipaddr, port) \ - IP6ADDR_PORT_TO_SOCKADDR((struct sockaddr_in6*)(void*)(sockaddr), ip_2_ip6(ipaddr), port) -#define SOCKADDR_TO_IPADDR_PORT(sockaddr, ipaddr, port) \ - SOCKADDR6_TO_IP6ADDR_PORT((const struct sockaddr_in6*)(const void*)(sockaddr), ipaddr, port) +#elif defined(MOLINK_USING_IPV6) +#define IPADDR_PORT_TO_SOCKADDR(sockaddr, ipaddr, port) \ + IP6ADDR_PORT_TO_SOCKADDR((struct sockaddr_in6 *)(void *)(sockaddr), ip_2_ip6(ipaddr), port) +#define SOCKADDR_TO_IPADDR_PORT(sockaddr, ipaddr, port) \ + SOCKADDR6_TO_IP6ADDR_PORT((const struct sockaddr_in6 *)(const void *)(sockaddr), ipaddr, port) #else -#define IPADDR_PORT_TO_SOCKADDR(sockaddr, ipaddr, port) \ - IP4ADDR_PORT_TO_SOCKADDR((struct sockaddr_in*)(void*)(sockaddr), ip_2_ip4(ipaddr), port) -#define SOCKADDR_TO_IPADDR_PORT(sockaddr, ipaddr, port) \ - SOCKADDR4_TO_IP4ADDR_PORT((const struct sockaddr_in*)(const void*)(sockaddr), ipaddr, port) +#define IPADDR_PORT_TO_SOCKADDR(sockaddr, ipaddr, port) \ + IP4ADDR_PORT_TO_SOCKADDR((struct sockaddr_in *)(void *)(sockaddr), ip_2_ip4(ipaddr), port) +#define SOCKADDR_TO_IPADDR_PORT(sockaddr, ipaddr, port) \ + SOCKADDR4_TO_IP4ADDR_PORT((const struct sockaddr_in *)(const void *)(sockaddr), ipaddr, port) #endif #ifdef __cplusplus diff --git a/components/molink/core/include/mo_log.h b/components/molink/core/include/mo_log.h index bb9534a0..049df601 100644 --- a/components/molink/core/include/mo_log.h +++ b/components/molink/core/include/mo_log.h @@ -21,7 +21,6 @@ *********************************************************************************************************************** */ - #ifndef __MO_LOG_H__ #define __MO_LOG_H__ @@ -32,7 +31,7 @@ extern "C" { #endif /* __cplusplus */ #if !defined(MO_LOG_TAG) -#define MO_LOG_TAG "MO_TAG" +#define MO_LOG_TAG "MO_TAG" #endif #ifdef OS_USING_DLOG @@ -41,9 +40,9 @@ extern "C" { /* Debug contorol by dlog config */ #define ERROR(fmt, ...) LOG_E(MO_LOG_TAG, fmt, ##__VA_ARGS__) -#define WARN(fmt, ...) LOG_W(MO_LOG_TAG, fmt, ##__VA_ARGS__) +#define WARN(fmt, ...) LOG_W(MO_LOG_TAG, fmt, ##__VA_ARGS__) -#define INFO(fmt, ...) LOG_I(MO_LOG_TAG, fmt, ##__VA_ARGS__) +#define INFO(fmt, ...) LOG_I(MO_LOG_TAG, fmt, ##__VA_ARGS__) #define DEBUG(fmt, ...) LOG_D(MO_LOG_TAG, fmt, ##__VA_ARGS__) @@ -51,14 +50,14 @@ extern "C" { #include #if !defined(MO_LOG_LVL) -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #endif -#define MO_LOG_EMERG (0) /* System is unusable */ -#define MO_LOG_ERROR (3) /* Error conditions */ -#define MO_LOG_WARNING (4) /* Warning conditions */ -#define MO_LOG_INFO (6) /* Informational */ -#define MO_LOG_DEBUG (7) /* Debug-level messages */ +#define MO_LOG_EMERG (0) /* System is unusable */ +#define MO_LOG_ERROR (3) /* Error conditions */ +#define MO_LOG_WARNING (4) /* Warning conditions */ +#define MO_LOG_INFO (6) /* Informational */ +#define MO_LOG_DEBUG (7) /* Debug-level messages */ #if (MO_LOG_ERROR <= MO_LOG_LVL) #define ERROR(fmt, ...) os_kprintf("[ERROR] [%s] " fmt "\r\n", MO_LOG_TAG, ##__VA_ARGS__); @@ -67,13 +66,13 @@ extern "C" { #endif #if (MO_LOG_WARNING <= MO_LOG_LVL) -#define WARN(fmt, ...) os_kprintf("[WARN] [%s] " fmt "\r\n", MO_LOG_TAG, ##__VA_ARGS__); +#define WARN(fmt, ...) os_kprintf("[WARN] [%s] " fmt "\r\n", MO_LOG_TAG, ##__VA_ARGS__); #else #define WARN(fmt, ...) #endif #if (MO_LOG_INFO <= MO_LOG_LVL) -#define INFO(fmt, ...) os_kprintf("[INFO] [%s] " fmt "\r\n", MO_LOG_TAG, ##__VA_ARGS__); +#define INFO(fmt, ...) os_kprintf("[INFO] [%s] " fmt "\r\n", MO_LOG_TAG, ##__VA_ARGS__); #else #define INFO(fmt, ...) #endif diff --git a/components/molink/core/include/mo_object.h b/components/molink/core/include/mo_object.h index a6615bba..ac1f17f0 100644 --- a/components/molink/core/include/mo_object.h +++ b/components/molink/core/include/mo_object.h @@ -63,9 +63,9 @@ typedef enum mo_platform #ifdef MOLINK_PLATFORM_MCU typedef struct mo_parser_config { - const char *parser_name; + const char *parser_name; os_device_t *parser_device; - os_size_t recv_buff_len; + os_size_t recv_buff_len; } mo_parser_config_t; #endif /* MOLINK_PLATFORM_MCU */ @@ -78,16 +78,16 @@ typedef struct mo_parser_config */ typedef struct mo_object { -#ifdef MOLINK_USING_MULTI_MODULES - os_slist_node_t list; /* module object manage list */ +#ifdef MOLINK_USING_MULTI_MODULES + os_slist_node_t list; /* module object manage list */ #endif - char name[OS_NAME_MAX + 1]; /* module object name */ - mo_type_t type; /* module object type */ - mo_platform_t platform; /* module object platform */ + char name[OS_NAME_MAX + 1]; /* module object name */ + mo_type_t type; /* module object type */ + mo_platform_t platform; /* module object platform */ #ifdef MOLINK_PLATFORM_MCU - at_parser_t parser; /* module object at parser */ -#endif /* MOLINK_PLATFORM_MCU */ - const void *ops_table[MODULE_OPS_MAX]; /* module object operates table */ + at_parser_t parser; /* module object at parser */ +#endif /* MOLINK_PLATFORM_MCU */ + const void *ops_table[MODULE_OPS_MAX]; /* module object operates table */ } mo_object_t; os_err_t mo_object_init(mo_object_t *self, const char *name, void *parser_config); @@ -99,7 +99,7 @@ mo_object_t *mo_object_get(void); #elif defined(MOLINK_USING_MULTI_MODULES) mo_object_t *mo_object_get_by_name(const char *name); mo_object_t *mo_object_get_default(void); -void mo_object_set_default(mo_object_t *self); +void mo_object_set_default(mo_object_t *self); #endif #ifdef __cplusplus @@ -109,4 +109,3 @@ void mo_object_set_default(mo_object_t *self); #endif /* NET_USING_MOLINK */ #endif /* __MO_OBJECT_H__ */ - diff --git a/components/molink/core/source/mo_ipaddr.c b/components/molink/core/source/mo_ipaddr.c index 9fbede82..bd2562d0 100644 --- a/components/molink/core/source/mo_ipaddr.c +++ b/components/molink/core/source/mo_ipaddr.c @@ -56,11 +56,11 @@ */ int net_ip4addr_aton(const char *cp, ip4_addr_t *addr) { - uint32_t val = 0; - uint8_t base = 0; - uint32_t parts[4] = {0}; - uint32_t *pp = parts; - char c = *cp; + uint32_t val = 0; + uint8_t base = 0; + uint32_t parts[4] = {0}; + uint32_t *pp = parts; + char c = *cp; for (;;) { @@ -73,7 +73,7 @@ int net_ip4addr_aton(const char *cp, ip4_addr_t *addr) { return 0; } - val = 0; + val = 0; base = 10; if (c == '0') { @@ -81,7 +81,7 @@ int net_ip4addr_aton(const char *cp, ip4_addr_t *addr) if (c == 'x' || c == 'X') { base = 16; - c = *++cp; + c = *++cp; } else { @@ -93,12 +93,12 @@ int net_ip4addr_aton(const char *cp, ip4_addr_t *addr) if (isdigit(c)) { val = (val * base) + (uint32_t)(c - '0'); - c = *++cp; + c = *++cp; } else if (base == 16 && isxdigit(c)) { val = (val << 4) | (uint32_t)(c + 10 - (islower(c) ? 'a' : 'A')); - c = *++cp; + c = *++cp; } else { @@ -118,7 +118,7 @@ int net_ip4addr_aton(const char *cp, ip4_addr_t *addr) return 0; } *pp++ = val; - c = *++cp; + c = *++cp; } else { @@ -182,7 +182,6 @@ int net_ip4addr_aton(const char *cp, ip4_addr_t *addr) break; default: OS_ASSERT(0); - } if (addr) { @@ -205,14 +204,14 @@ int net_ip4addr_aton(const char *cp, ip4_addr_t *addr) */ char *net_ip4addr_ntoa_r(const ip4_addr_t *addr, char *buf, int buflen) { - char inv[3] = {0}; - char *rp = OS_NULL; + char inv[3] = {0}; + char *rp = OS_NULL; uint32_t s_addr = 0; - uint8_t *ap = OS_NULL; - uint8_t rem = 0; - uint8_t n = 0; - uint8_t i = 0; - int32_t len = 0; + uint8_t *ap = OS_NULL; + uint8_t rem = 0; + uint8_t n = 0; + uint8_t i = 0; + int32_t len = 0; s_addr = ip4_addr_get_u32(addr); @@ -304,8 +303,8 @@ OS_WEAK const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; */ int net_ip6addr_aton(const char *cp, ip6_addr_t *addr) { - uint32_t addr_index = 0; - uint32_t zero_blocks = 8; + uint32_t addr_index = 0; + uint32_t zero_blocks = 8; uint32_t current_block_index = 0; uint32_t current_block_value = 0; const char *s; @@ -439,10 +438,10 @@ char *net_ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen) { uint32_t current_block_index = 0; uint32_t current_block_value = 0; - uint32_t next_block_value = 0; - int32_t i = 0; - uint8_t zero_flag = 0; - uint8_t empty_block_flag = 0; /* used to indicate a zero chain for "::' */ + uint32_t next_block_value = 0; + int32_t i = 0; + uint8_t zero_flag = 0; + uint8_t empty_block_flag = 0; /* used to indicate a zero chain for "::' */ for (current_block_index = 0; current_block_index < 8; current_block_index++) { @@ -480,7 +479,7 @@ char *net_ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen) if (next_block_value == 0) { empty_block_flag = 1; - buf[i++] = ':'; + buf[i++] = ':'; if (i >= buflen) { return OS_NULL; @@ -515,7 +514,7 @@ char *net_ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen) } else { - buf[i++] = xchar(((current_block_value & 0xf000) >> 12)); + buf[i++] = xchar(((current_block_value & 0xf000) >> 12)); zero_flag = 0; if (i >= buflen) { @@ -529,7 +528,7 @@ char *net_ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen) } else { - buf[i++] = xchar(((current_block_value & 0xf00) >> 8)); + buf[i++] = xchar(((current_block_value & 0xf00) >> 8)); zero_flag = 0; if (i >= buflen) { @@ -543,7 +542,7 @@ char *net_ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen) } else { - buf[i++] = xchar(((current_block_value & 0xf0) >> 4)); + buf[i++] = xchar(((current_block_value & 0xf0) >> 4)); zero_flag = 0; if (i >= buflen) { @@ -588,8 +587,8 @@ const char *net_inet_ntop(int af, const void *src, char *dst, int32_t size) #define AF_INET 2 #define AF_INET6 10 - const char *ret = OS_NULL; - int size_int = (int)size; + const char *ret = OS_NULL; + int size_int = (int)size; if (size_int < 0) { return OS_NULL; @@ -598,11 +597,11 @@ const char *net_inet_ntop(int af, const void *src, char *dst, int32_t size) { #if NTEDEV_IPV4 case AF_INET: - return net_ip4addr_ntoa_r((const ip4_addr_t*)src, dst, size_int); + return net_ip4addr_ntoa_r((const ip4_addr_t *)src, dst, size_int); #endif #if defined(MOLINK_USING_IPV6) case AF_INET6: - return net_ip6addr_ntoa_r((const ip6_addr_t*)src, dst, size_int); + return net_ip6addr_ntoa_r((const ip6_addr_t *)src, dst, size_int); #endif default: break; @@ -620,7 +619,7 @@ int net_inet_pton(int af, const char *src, void *dst) { #if defined(MOLINK_USING_IPV4) case AF_INET: - err = net_ip4addr_aton(src, (ip4_addr_t*)dst); + err = net_ip4addr_aton(src, (ip4_addr_t *)dst); break; #endif #if defined(MOLINK_USING_IPV6) diff --git a/components/molink/core/source/mo_lib.c b/components/molink/core/source/mo_lib.c index 4af15bac..46b85e6b 100644 --- a/components/molink/core/source/mo_lib.c +++ b/components/molink/core/source/mo_lib.c @@ -31,12 +31,12 @@ void bytes_to_hexstr(const char *source, char *dest, os_size_t source_size) OS_ASSERT(OS_NULL != dest); os_uint8_t high_byte = 0; - os_uint8_t low_byte = 0; + os_uint8_t low_byte = 0; for (int i = 0; i < source_size; i++) { high_byte = source[i] >> 4; - low_byte = source[i] & 0x0f; + low_byte = source[i] & 0x0f; high_byte += 0x30; @@ -68,12 +68,12 @@ void hexstr_to_bytes(const char *source, char *dest, os_size_t source_size) OS_ASSERT(OS_NULL != dest); os_uint8_t high_byte = 0; - os_uint8_t low_byte = 0; + os_uint8_t low_byte = 0; for (int i = 0; i < source_size; i += 2) { high_byte = toupper(source[i]); - low_byte = toupper(source[i + 1]); + low_byte = toupper(source[i + 1]); if (high_byte > 0x39) { diff --git a/components/molink/core/source/mo_object.c b/components/molink/core/source/mo_object.c index 923be482..e31dbed7 100644 --- a/components/molink/core/source/mo_object.c +++ b/components/molink/core/source/mo_object.c @@ -29,15 +29,15 @@ #include #define MO_LOG_TAG "molink.core" -#define MO_LOG_LVL MO_LOG_EMERG +#define MO_LOG_LVL MO_LOG_EMERG #include "mo_log.h" #ifdef NET_USING_MOLINK #ifdef MOLINK_USING_MULTI_MODULES -static os_slist_node_t gs_mo_object_list = {0}; +static os_slist_node_t gs_mo_object_list = {0}; #endif -static mo_object_t *gs_mo_object_default = OS_NULL; +static mo_object_t *gs_mo_object_default = OS_NULL; #if defined(MOLINK_USING_SINGLE_MODULE) mo_object_t *mo_object_get(void) @@ -72,8 +72,8 @@ static void mo_object_list_del(mo_object_t *self) { OS_ASSERT(self != OS_NULL); - os_slist_node_t *node = OS_NULL; - mo_object_t *entry = OS_NULL; + os_slist_node_t *node = OS_NULL; + mo_object_t *entry = OS_NULL; os_schedule_lock(); @@ -99,8 +99,8 @@ mo_object_t *mo_object_get_by_name(const char *name) { OS_ASSERT(name != OS_NULL); - os_slist_node_t *node = OS_NULL; - mo_object_t *entry = OS_NULL; + os_slist_node_t *node = OS_NULL; + mo_object_t *entry = OS_NULL; if (OS_NULL == gs_mo_object_list.next) { @@ -149,8 +149,8 @@ mo_object_t *module_object_get_by_device(os_device_t *device) { OS_ASSERT(device != OS_NULL); - os_slist_node_t *node = OS_NULL; - mo_object_t *entry = OS_NULL; + os_slist_node_t *node = OS_NULL; + mo_object_t *entry = OS_NULL; if (OS_NULL == gs_mo_object_list.next) { @@ -199,7 +199,7 @@ static os_err_t mo_object_init_with_mcu(mo_object_t *self, const char *name, mo_ #if defined(MOLINK_USING_SINGLE_MODULE) mo_object_set(self); -#elif defined(MOLINK_USING_MULTI_MODULES) +#elif defined(MOLINK_USING_MULTI_MODULES) mo_object_list_add(self); #endif diff --git a/components/molink/core/source/mo_time.c b/components/molink/core/source/mo_time.c index 873b8a16..b8e6329e 100644 --- a/components/molink/core/source/mo_time.c +++ b/components/molink/core/source/mo_time.c @@ -31,15 +31,15 @@ static os_bool_t in_leap_year(os_int32_t year) static os_int32_t day_of_the_week(os_int32_t year, os_int32_t month, os_int32_t day) { - os_int32_t y,m; + os_int32_t y, m; /* Kim larsen calculation formula: w=(d+2m+3(m+1)/5+y+y/4-y/100+y/400+1)%7 */ - if (1 == month || 2 == month) + if (1 == month || 2 == month) { m = month + 12; - y = year - 1; + y = year - 1; } - return (day+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1)%7; + return (day + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400 + 1) % 7; } /** @@ -51,7 +51,7 @@ static os_int32_t day_of_the_week(os_int32_t year, os_int32_t month, os_int32_t * * @param[in] mo_tm mo_tm_t that hold original time info * @param[in] _tm pointer to struct tm that user gives to - * + * * @return void *********************************************************************************************************************** */ @@ -62,12 +62,12 @@ void time_struct_convert(_mo_tm_t *mo_tm, struct tm *_tm) /* UTC time without timezone cast, if in the leap year, set days_table */ if (in_leap_year(mo_tm->tm_year)) { - days_table[1] = 29; // when leap year, feburary has 29 days + days_table[1] = 29; // when leap year, feburary has 29 days } /* set month & years for struct tm: (Month.[0-11]. Year since 1900.) */ - mo_tm->tm_mon -= 1; // struct's tm_mon [0-11] - mo_tm->tm_year -= 1900; // struct's tm_year since 1900 + mo_tm->tm_mon -= 1; // struct's tm_mon [0-11] + mo_tm->tm_year -= 1900; // struct's tm_year since 1900 /* timezone handle process */ if (0 == mo_tm->tm_q_off) @@ -81,54 +81,56 @@ void time_struct_convert(_mo_tm_t *mo_tm, struct tm *_tm) { mo_tm->tm_hour = ((0 < mo_tm->tm_q_off) ? -mo_tm->tm_hour : mo_tm->tm_hour) + 24; } - else + else { - goto __final; // not enffect the month day count, finished. + goto __final; // not enffect the month day count, finished. } /* days-month-years */ if (0 < mo_tm->tm_q_off) { // next day is not in the next month - if (mo_tm->tm_mday <= days_table[mo_tm->tm_mon] - 1) + if (mo_tm->tm_mday <= days_table[mo_tm->tm_mon] - 1) { mo_tm->tm_mday++; } // next month is not in the next year - else if (11 > mo_tm->tm_mon + 1) + else if (11 > mo_tm->tm_mon + 1) { mo_tm->tm_mday = 1; mo_tm->tm_mon++; } // next day is in the next year's first month - else + else { mo_tm->tm_mday = 1; - mo_tm->tm_mon = 0; + mo_tm->tm_mon = 0; mo_tm->tm_year++; - if (in_leap_year(mo_tm->tm_year + 1900)) days_table[1] = 29; + if (in_leap_year(mo_tm->tm_year + 1900)) + days_table[1] = 29; } } - else + else { // previous day is not in the previous month - if (1 < mo_tm->tm_mday) + if (1 < mo_tm->tm_mday) { mo_tm->tm_mday--; } // previous month is not in the previous year - else if (0 <= mo_tm->tm_mon - 1) + else if (0 <= mo_tm->tm_mon - 1) { mo_tm->tm_mday = days_table[mo_tm->tm_mon - 1]; mo_tm->tm_mon--; } // previous day is in the last year's december - else + else { - mo_tm->tm_mon = 11; + mo_tm->tm_mon = 11; mo_tm->tm_mday = days_table[mo_tm->tm_mon]; mo_tm->tm_year--; - if (in_leap_year(mo_tm->tm_year + 1900)) days_table[1] = 29; + if (in_leap_year(mo_tm->tm_year + 1900)) + days_table[1] = 29; } } @@ -145,13 +147,13 @@ __final: _tm->tm_yday += mo_tm->tm_mday - 1; /* for readable reason, copy param here. */ - _tm->tm_isdst = -1; // -1 DST means let system choose - _tm->tm_sec = mo_tm->tm_sec; - _tm->tm_min = mo_tm->tm_min; - _tm->tm_hour = mo_tm->tm_hour; - _tm->tm_mday = mo_tm->tm_mday; - _tm->tm_mon = mo_tm->tm_mon; - _tm->tm_year = mo_tm->tm_year; + _tm->tm_isdst = -1; // -1 DST means let system choose + _tm->tm_sec = mo_tm->tm_sec; + _tm->tm_min = mo_tm->tm_min; + _tm->tm_hour = mo_tm->tm_hour; + _tm->tm_mday = mo_tm->tm_mday; + _tm->tm_mon = mo_tm->tm_mon; + _tm->tm_year = mo_tm->tm_year; return; } diff --git a/components/molink/easylog/include/mo_easylog.h b/components/molink/easylog/include/mo_easylog.h index 27d017c4..7ae2f5d9 100644 --- a/components/molink/easylog/include/mo_easylog.h +++ b/components/molink/easylog/include/mo_easylog.h @@ -35,11 +35,11 @@ extern "C" { #ifdef MOLINK_USING_EASYLOG -#define MO_EASYLOG_SYS_TIME_LEN (23) -#define MO_EASTLOG_CSQ_WARNING_LV (10) /* Alarm threshold for poor signal quality, define by user */ +#define MO_EASYLOG_SYS_TIME_LEN (23) +#define MO_EASTLOG_CSQ_WARNING_LV (10) /* Alarm threshold for poor signal quality, define by user */ #ifndef MO_EASYLOG_USER_DATA_LEN -#define MO_EASYLOG_USER_DATA_LEN (8) /* The size defined by user application, default value 8 */ +#define MO_EASYLOG_USER_DATA_LEN (8) /* The size defined by user application, default value 8 */ #endif typedef enum mo_easylog_upload_flag @@ -63,54 +63,54 @@ typedef enum mo_easylog_network_status typedef struct mo_easylog { - os_uint8_t upload_flag; + os_uint8_t upload_flag; os_uint16_t len; - os_uint8_t net_status; + os_uint8_t net_status; #ifdef OS_USING_RTC - char sys_time[MO_EASYLOG_SYS_TIME_LEN + 1]; /* "Jan 1 01:07:59 2000"--2000年01月01日01时07分59秒 */ + char sys_time[MO_EASYLOG_SYS_TIME_LEN + 1]; /* "Jan 1 01:07:59 2000"--2000年01月01日01时07分59秒 */ #endif #ifdef MOLINK_EASYLOG_USING_IMEI - char imei[MO_IMEI_LEN + 1]; + char imei[MO_IMEI_LEN + 1]; #endif #ifdef MOLINK_EASYLOG_USING_IMSI - char imsi[MO_IMSI_LEN + 1]; + char imsi[MO_IMSI_LEN + 1]; #endif #ifdef MOLINK_EASYLOG_USING_ICCID - char iccid[MO_ICCID_LEN + 1]; + char iccid[MO_ICCID_LEN + 1]; #endif #ifdef MOLINK_EASYLOG_USING_CSQ - os_uint8_t csq_rssi; - os_uint8_t csq_ber; + os_uint8_t csq_rssi; + os_uint8_t csq_ber; #endif #ifdef MOLINK_EASYLOG_USING_PCI - os_int32_t pci; + os_int32_t pci; #endif #ifdef MOLINK_EASYLOG_USING_EARFCN - os_int32_t earfcn; + os_int32_t earfcn; #endif #ifdef MOLINK_EASYLOG_USING_CELLID - char cell_id[CELL_ID_MAX_LEN + 1]; + char cell_id[CELL_ID_MAX_LEN + 1]; #endif #ifdef MOLINK_EASYLOG_USING_RSRP - os_int32_t rsrp; + os_int32_t rsrp; #endif #ifdef MOLINK_EASYLOG_USING_RSRQ - os_int32_t rsrq; + os_int32_t rsrq; #endif #ifdef MOLINK_EASYLOG_USING_SNR - os_int32_t snr; + os_int32_t snr; #endif #ifdef MOLINK_EASYLOG_USING_TX_PWR - os_int32_t tx_power; + os_int32_t tx_power; #endif #ifdef MOLINK_EASYLOG_USING_ECL - os_int32_t ecl; + os_int32_t ecl; #endif #ifdef MOLINK_EASYLOG_USING_USER_DATA - os_uint8_t user_data[MO_EASYLOG_USER_DATA_LEN]; + os_uint8_t user_data[MO_EASYLOG_USER_DATA_LEN]; #endif #ifdef MOLINK_EASYLOG_USING_CHECKSUM - os_uint8_t checksum; + os_uint8_t checksum; #endif } mo_easylog_t; @@ -119,8 +119,8 @@ os_uint8_t mo_easylog_calculate_rx_checksum(os_uint8_t *data, os_uint32_t len); #endif mo_easylog_t *mo_easylog_create(const os_uint8_t *user_data, os_size_t data_len); -os_err_t mo_easylog_destory(mo_easylog_t *easylog); -os_err_t mo_easylog_info_printf(mo_easylog_t *easylog_obj); +os_err_t mo_easylog_destory(mo_easylog_t *easylog); +os_err_t mo_easylog_info_printf(mo_easylog_t *easylog_obj); #endif /* MOLINK_USING_EASYLOG */ #endif /* NET_USING_MOLINK */ diff --git a/components/molink/easylog/source/mo_easylog.c b/components/molink/easylog/source/mo_easylog.c index 4e104980..f64f6a8a 100644 --- a/components/molink/easylog/source/mo_easylog.c +++ b/components/molink/easylog/source/mo_easylog.c @@ -41,7 +41,7 @@ #endif static mo_easylog_t *easylog_obj = OS_NULL; -static mo_object_t *def_module = OS_NULL; +static mo_object_t *def_module = OS_NULL; static os_err_t mo_easylog_info_update(const os_uint8_t *user_data, os_size_t data_len); static os_err_t mo_easylog_get_sys_time(void); @@ -50,19 +50,18 @@ static os_err_t mo_easylog_get_imsi(void); static os_err_t mo_easylog_get_iccid(void); static os_err_t mo_easylog_get_csq(void); static os_err_t mo_easylog_get_radio_info(void); -static void mo_easylog_init_user_data(const os_uint8_t *data, os_size_t len); +static void mo_easylog_init_user_data(const os_uint8_t *data, os_size_t len); static os_uint8_t mo_easylog_calculate_tx_checksum(os_uint8_t *data, os_uint32_t len); static mo_easylog_network_status_t mo_easylog_get_network_status(mo_object_t *module, mo_easylog_t *e_obj); - static mo_easylog_network_status_t mo_easylog_get_network_status(mo_object_t *module, mo_easylog_t *e_obj) { mo_easylog_network_status_t net_status = NETWORK_STATUS_OK; - os_err_t reslut = OS_ERROR; + os_err_t reslut = OS_ERROR; os_uint8_t status = 0; - os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t rssi = 0; + os_uint8_t ber = 0; char tmp[MO_IMSI_LEN + 1] = {0}; @@ -155,7 +154,7 @@ __exit: static os_err_t mo_easylog_get_sys_time(void) { time_t sys_time; - char tmp[32] = {0}; + char tmp[32] = {0}; if (OS_NULL == easylog_obj) { @@ -300,8 +299,8 @@ static void mo_easylog_init_user_data(const os_uint8_t *data, os_size_t len) #ifdef MOLINK_EASYLOG_USING_CHECKSUM static os_uint8_t mo_easylog_calculate_tx_checksum(os_uint8_t *data, os_uint32_t len) { - os_uint32_t i = 0; - os_uint8_t ret = 0; + os_uint32_t i = 0; + os_uint8_t ret = 0; if ((OS_NULL == data) || (len == 0)) { @@ -319,8 +318,8 @@ static os_uint8_t mo_easylog_calculate_tx_checksum(os_uint8_t *data, os_uint32_t os_uint8_t mo_easylog_rx_data_check(os_uint8_t *data, os_uint32_t len) { - os_uint32_t i = 0; - os_uint8_t ret = 0; + os_uint32_t i = 0; + os_uint8_t ret = 0; if ((OS_NULL == data) || (len == 0)) { @@ -492,8 +491,8 @@ os_err_t mo_easylog_info_printf(mo_easylog_t *easylog_obj) mo_easylog_t *mo_easylog_create(const os_uint8_t *user_data, os_size_t data_len) { - os_uint16_t size = 0; - os_err_t result = OS_EOK; + os_uint16_t size = 0; + os_err_t result = OS_EOK; def_module = mo_get_default(); if (OS_NULL == def_module) @@ -513,9 +512,9 @@ mo_easylog_t *mo_easylog_create(const os_uint8_t *user_data, os_size_t data_len) memset(easylog_obj, 0, size); easylog_obj->upload_flag = EASYLOG_NOT_UPLOAD; - easylog_obj->len = size; + easylog_obj->len = size; - if(OS_EOK != mo_easylog_info_update(user_data, data_len)) + if (OS_EOK != mo_easylog_info_update(user_data, data_len)) { os_kprintf("Molink easylog info update fail\r\n"); } @@ -545,7 +544,7 @@ os_err_t mo_easylog_destory(mo_easylog_t *easylog) easylog_obj = OS_NULL; } - def_module = OS_NULL; + def_module = OS_NULL; return OS_EOK; } diff --git a/components/molink/module/a7600x/include/a7600x.h b/components/molink/module/a7600x/include/a7600x.h index a2724ce4..aecdee38 100644 --- a/components/molink/module/a7600x/include/a7600x.h +++ b/components/molink/module/a7600x/include/a7600x.h @@ -77,13 +77,13 @@ typedef struct mo_a7600x mo_object_t parent; #ifdef A7600X_USING_NETCONN_OPS mo_netconn_t netconn[A7600X_NETCONN_NUM]; - os_event_t netconn_evt; - os_mutex_t netconn_lock; + os_event_t netconn_evt; + os_mutex_t netconn_lock; #endif /* A7600X_USING_NETCONN_OPS */ } mo_a7600x_t; mo_object_t *module_a7600x_create(const char *name, void *parser_config); -os_err_t module_a7600x_destroy(mo_object_t *self); +os_err_t module_a7600x_destroy(mo_object_t *self); #endif /* MOLINK_USING_A7600X */ diff --git a/components/molink/module/a7600x/include/a7600x_netconn.h b/components/molink/module/a7600x/include/a7600x_netconn.h index fc1f7041..9491a153 100644 --- a/components/molink/module/a7600x/include/a7600x_netconn.h +++ b/components/molink/module/a7600x/include/a7600x_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef A7600X_USING_NETCONN_OPS -os_err_t a7600x_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t a7600x_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *a7600x_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t a7600x_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t a7600x_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t a7600x_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t a7600x_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t a7600x_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t a7600x_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef A7600X_USING_DNS -os_err_t a7600x_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t a7600x_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* A7600X_USING_NETCONN_OPS */ diff --git a/components/molink/module/a7600x/include/a7600x_netserv.h b/components/molink/module/a7600x/include/a7600x_netserv.h index c010ae4e..f5ff03f1 100644 --- a/components/molink/module/a7600x/include/a7600x_netserv.h +++ b/components/molink/module/a7600x/include/a7600x_netserv.h @@ -40,7 +40,7 @@ os_err_t a7600x_set_cgact(mo_object_t *self, os_uint8_t cid, os_uint8_t act_stat os_err_t a7600x_get_cgact(mo_object_t *self, os_uint8_t *cid, os_uint8_t *act_stat); os_err_t a7600x_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber); os_err_t a7600x_get_radio(mo_object_t *self, radio_info_t *radio_info); -os_err_t a7600x_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info); +os_err_t a7600x_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info); #endif /* A7600X_USING_NETSERV_OPS */ diff --git a/components/molink/module/a7600x/source/a7600x.c b/components/molink/module/a7600x/source/a7600x.c index f78ddff4..c7261aee 100644 --- a/components/molink/module/a7600x/source/a7600x.c +++ b/components/molink/module/a7600x/source/a7600x.c @@ -36,25 +36,25 @@ #ifdef A7600X_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = a7600x_at_test, - .get_imei = a7600x_get_imei, - .get_imsi = a7600x_get_imsi, + .at_test = a7600x_at_test, + .get_imei = a7600x_get_imei, + .get_imsi = a7600x_get_imsi, .get_iccid = a7600x_get_iccid, - .get_cfun = a7600x_get_cfun, - .set_cfun = a7600x_set_cfun, + .get_cfun = a7600x_get_cfun, + .set_cfun = a7600x_set_cfun, }; #endif /* A7600X_USING_GENERAL_OPS */ #ifdef A7600X_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = a7600x_set_attach, - .get_attach = a7600x_get_attach, - .set_reg = a7600x_set_reg, - .get_reg = a7600x_get_reg, - .set_cgact = a7600x_set_cgact, - .get_cgact = a7600x_get_cgact, - .get_csq = a7600x_get_csq, - .get_cell_info = a7600x_get_cell_info, + .set_attach = a7600x_set_attach, + .get_attach = a7600x_get_attach, + .set_reg = a7600x_set_reg, + .get_reg = a7600x_get_reg, + .set_cgact = a7600x_set_cgact, + .get_cgact = a7600x_get_cgact, + .get_csq = a7600x_get_csq, + .get_cell_info = a7600x_get_cell_info, }; #endif /* A7600X_USING_NETSERV_OPS */ @@ -67,7 +67,7 @@ static const struct mo_ping_ops gs_ping_ops = { #ifdef A7600X_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = a7600x_ifconfig, + .ifconfig = a7600x_ifconfig, .get_ipaddr = a7600x_get_ipaddr, }; #endif /* A7600X_USING_IFCONFIG_OPS */ @@ -76,14 +76,14 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void a7600x_netconn_init(mo_a7600x_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = a7600x_netconn_create, - .destroy = a7600x_netconn_destroy, + .create = a7600x_netconn_create, + .destroy = a7600x_netconn_destroy, #ifdef A7600X_USING_DNS .gethostbyname = a7600x_netconn_gethostbyname, #endif - .connect = a7600x_netconn_connect, - .send = a7600x_netconn_send, - .get_info = a7600x_netconn_get_info, + .connect = a7600x_netconn_connect, + .send = a7600x_netconn_send, + .get_info = a7600x_netconn_get_info, }; #endif /* A7600X_USING_NETCONN_OPS */ @@ -100,9 +100,7 @@ static os_err_t a7600x_at_init(mo_object_t *self) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 2 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * OS_TICK_PER_SECOND}; return at_parser_exec_cmd(parser, &resp, "ATE0"); } @@ -203,7 +201,7 @@ int a7600x_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = A7600X_NAME, + mo_parser_config_t parser_config = {.parser_name = A7600X_NAME, .parser_device = device, .recv_buff_len = A7600X_RECV_BUFF_LEN}; diff --git a/components/molink/module/a7600x/source/a7600x_ifconfig.c b/components/molink/module/a7600x/source/a7600x_ifconfig.c index b7726a84..77295e79 100644 --- a/components/molink/module/a7600x/source/a7600x_ifconfig.c +++ b/components/molink/module/a7600x/source/a7600x_ifconfig.c @@ -38,14 +38,14 @@ os_err_t a7600x_ifconfig(mo_object_t *self) { char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; - char imei[MO_IMEI_LEN + 1] = {0}; - char iccid[MO_ICCID_LEN + 1] = {0}; - char imsi[MO_IMSI_LEN + 1] = {0}; + char imei[MO_IMEI_LEN + 1] = {0}; + char iccid[MO_ICCID_LEN + 1] = {0}; + char imsi[MO_IMSI_LEN + 1] = {0}; - os_err_t ret = OS_EOK; + os_err_t ret = OS_EOK; os_uint8_t rssi = 0; - os_uint8_t ber = 0; - os_int32_t i = 0; + os_uint8_t ber = 0; + os_int32_t i = 0; if (a7600x_get_ipaddr(self, ipaddr) != OS_EOK) { @@ -74,7 +74,7 @@ os_err_t a7600x_ifconfig(mo_object_t *self) if (a7600x_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; ret = OS_ERROR; } @@ -104,7 +104,7 @@ os_err_t a7600x_ifconfig(mo_object_t *self) os_err_t a7600x_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t len = -1; + os_int8_t len = -1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; diff --git a/components/molink/module/a7600x/source/a7600x_netconn.c b/components/molink/module/a7600x/source/a7600x_netconn.c index 52059b6d..72d44d33 100644 --- a/components/molink/module/a7600x/source/a7600x_netconn.c +++ b/components/molink/module/a7600x/source/a7600x_netconn.c @@ -32,7 +32,7 @@ #define MO_LOG_LVL MO_LOG_INFO #include -#define SEND_DATA_MAX_SIZE (1360) +#define SEND_DATA_MAX_SIZE (1360) #define A7600X_NETCONN_MQ_NAME "a7600x_nc_mq" @@ -41,10 +41,10 @@ #endif #ifndef A7600X_NETCONN_MQ_MSG_MAX -#define A7600X_NETCONN_MQ_MSG_MAX (10) +#define A7600X_NETCONN_MQ_MSG_MAX (10) #endif -#define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) +#define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) #define A7600X_EVENT_NETCONN_OK (1L << 0) #define A7600X_EVENT_NETCONN_FAIL (1L << 1) @@ -56,25 +56,25 @@ enum net_transfer_mode { NON_TRANSPARENT_MODE = 0, - TRANSPARENT_MODE = 1, + TRANSPARENT_MODE = 1, }; enum net_server_status { NET_SERVER_DISABLE = 0, - NET_SERVER_ENABLE = 1, + NET_SERVER_ENABLE = 1, }; enum netconn_send_status { - CONN_DISCONNECTED = -1, + CONN_DISCONNECTED = -1, CONN_SEND_BUFF_FULL = 0, }; enum link_close_reason { - LINK_CLOSED_BY_LOCAL = 0, - LINK_CLOSED_BY_REMOTE = 1, + LINK_CLOSED_BY_LOCAL = 0, + LINK_CLOSED_BY_REMOTE = 1, SEND_TIMEOUT_OR_DTR_OFF = 2, LINK_CLOSED_UNKNOWN, }; @@ -138,7 +138,7 @@ os_err_t a7600x_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_a7600x_t *a7600x = os_container_of(module, mo_a7600x_t, parent); info->netconn_array = a7600x->netconn; - info->netconn_nums = sizeof(a7600x->netconn) / sizeof(a7600x->netconn[0]); + info->netconn_nums = sizeof(a7600x->netconn) / sizeof(a7600x->netconn[0]); return OS_EOK; } @@ -146,8 +146,8 @@ os_err_t a7600x_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) static os_err_t a7600x_netconn_set_transfer_mode(mo_object_t *module) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_int32_t mode = -1; + os_err_t result = OS_EOK; + os_int32_t mode = -1; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -188,8 +188,8 @@ static os_err_t a7600x_netconn_set_transfer_mode(mo_object_t *module) static os_err_t a7600x_netconn_server_open(mo_object_t *module) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_int32_t stat = -1; + os_err_t result = OS_EOK; + os_int32_t stat = -1; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -230,7 +230,7 @@ static os_err_t a7600x_netconn_server_open(mo_object_t *module) static os_err_t a7600x_net_server_config(mo_object_t *module) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -282,7 +282,7 @@ static os_err_t a7600x_net_server_config(mo_object_t *module) mo_netconn_t *a7600x_netconn_create(mo_object_t *module, mo_netconn_type_t type) { mo_a7600x_t *a7600x = os_container_of(module, mo_a7600x_t, parent); - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; a7600x_lock(&a7600x->netconn_lock); @@ -322,14 +322,14 @@ mo_netconn_t *a7600x_netconn_create(mo_object_t *module, mo_netconn_type_t type) os_err_t a7600x_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; INFO("Module %s in %d netconn status", module->name, netconn->stat); - mo_a7600x_t *a7600x = os_container_of(module, mo_a7600x_t, parent); + mo_a7600x_t *a7600x = os_container_of(module, mo_a7600x_t, parent); if (a7600x == OS_NULL) { ERROR("Module %s destroy netconn failed, get netconn_lock failed", module->name); @@ -347,7 +347,9 @@ os_err_t a7600x_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) result = at_parser_exec_cmd(parser, &resp, "AT+CIPCLOSE=%d", netconn->connect_id); if (result != OS_EOK) { - ERROR("Module %s destroy %s netconn failed", module->name, (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + ERROR("Module %s destroy %s netconn failed", + module->name, + (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); a7600x_unlock(&a7600x->netconn_lock); return result; } @@ -366,11 +368,11 @@ os_err_t a7600x_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn_id: %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; - netconn->local_port = 0; + netconn->local_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); a7600x_unlock(&a7600x->netconn_lock); @@ -383,13 +385,11 @@ os_err_t a7600x_netconn_gethostbyname(mo_object_t *self, const char *domain_name { at_parser_t *parser = &self->parser; - char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; + char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 20 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CDNSGIP=\"%s\"", domain_name); if (result < 0) @@ -437,19 +437,17 @@ __exit: #ifdef A7600X_USING_TCP static os_err_t a7600x_tcp_connect(mo_object_t *module, mo_netconn_t *netconn, char *ip_addr, os_uint16_t port) { - mo_a7600x_t *a7600x = os_container_of(module, mo_a7600x_t, parent); - at_parser_t *parser = &module->parser; - os_int32_t connect_id = netconn->connect_id; - os_err_t result = OS_ERROR; - os_uint32_t event = SET_EVENT(netconn->connect_id, A7600X_EVENT_NETCONN_OK | A7600X_EVENT_NETCONN_FAIL); + mo_a7600x_t *a7600x = os_container_of(module, mo_a7600x_t, parent); + at_parser_t *parser = &module->parser; + os_int32_t connect_id = netconn->connect_id; + os_err_t result = OS_ERROR; + os_uint32_t event = SET_EVENT(netconn->connect_id, A7600X_EVENT_NETCONN_OK | A7600X_EVENT_NETCONN_FAIL); - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; os_event_recv(&a7600x->netconn_evt, event, OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, OS_NO_WAIT, OS_NULL); - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 30 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 30 * OS_TICK_PER_SECOND}; a7600x_lock(&a7600x->netconn_lock); @@ -498,19 +496,14 @@ __exit: #ifdef A7600X_USING_UDP static os_err_t a7600x_udp_connect(mo_object_t *module, mo_netconn_t *netconn) { - at_parser_t *parser = &module->parser; + at_parser_t *parser = &module->parser; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 30 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 30 * OS_TICK_PER_SECOND}; - os_err_t result = at_parser_exec_cmd(parser, - &resp, - "AT+CIPOPEN=%d,\"UDP\",,,%u", - netconn->connect_id, - netconn->local_port); + os_err_t result = + at_parser_exec_cmd(parser, &resp, "AT+CIPOPEN=%d,\"UDP\",,,%u", netconn->connect_id, netconn->local_port); if (result != OS_EOK) { ERROR("AT cmd exec failed: AT+CIPOPEN=%d,\"UDP\",,,%u", netconn->connect_id, netconn->local_port); @@ -557,7 +550,7 @@ os_err_t a7600x_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_a ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%u successfully!", module->name, remote_ip, port); @@ -566,15 +559,15 @@ os_err_t a7600x_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_a os_size_t a7600x_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t cur_pkt_size = 0; - os_uint32_t event = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t cur_pkt_size = 0; + os_uint32_t event = 0; mo_a7600x_t *a7600x = os_container_of(module, mo_a7600x_t, parent); - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 60 * OS_TICK_PER_SECOND}; @@ -713,9 +706,9 @@ static void urc_tcp_connect_func(struct at_parser *parser, const char *data, os_ mo_a7600x_t *a7600x = os_container_of(module, mo_a7600x_t, parent); os_int32_t connect_id = -1; - os_int32_t result = -1; + os_int32_t result = -1; - sscanf(data, "+CIPOPEN: %d,%d", &connect_id , &result); + sscanf(data, "+CIPOPEN: %d,%d", &connect_id, &result); if (0 == result) { @@ -735,11 +728,11 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = -1; - os_int32_t closed_by = -1; + os_int32_t closed_by = -1; sscanf(data, "+IPCLOSE: %d,%d", &connect_id, &closed_by); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = a7600x_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) @@ -748,7 +741,7 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t return; } - switch(closed_by) + switch (closed_by) { case LINK_CLOSED_BY_LOCAL: DEBUG("Module %s connect %d, closed by local, active", module->name, connect_id); @@ -779,8 +772,8 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; - os_int32_t timeout = 0; + os_int32_t data_size = 0; + os_int32_t timeout = 0; /* For ex: +RECEIVE,0,10\r\n 0123456789 */ sscanf(data, "+RECEIVE,%d,%d,", &connect_id, &data_size); @@ -788,7 +781,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t timeout = data_size > 10 ? data_size : 10; - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = a7600x_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) { @@ -798,8 +791,8 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t if (netconn->stat == NETCONN_STAT_CONNECT) { - char *recv_buff = os_calloc(1, data_size + 1); - char temp_buff[8] = {0}; + char *recv_buff = os_calloc(1, data_size + 1); + char temp_buff[8] = {0}; if (recv_buff == OS_NULL) { @@ -848,16 +841,16 @@ static void urc_send_msg_func(struct at_parser *parser, const char *data, os_siz OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - os_int32_t connect_id = -1; - os_int32_t reqsend_len = -1; - os_int32_t cnfsend_len = -2; - os_err_t result = OS_EOK; + os_int32_t connect_id = -1; + os_int32_t reqsend_len = -1; + os_int32_t cnfsend_len = -2; + os_err_t result = OS_EOK; /* +CIPSEND: 0,1500,1500\r\n */ sscanf(data, "+CIPSEND: %d,%d,%d", &connect_id, &reqsend_len, &cnfsend_len); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_a7600x_t *a7600x = os_container_of(module, mo_a7600x_t, parent); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_a7600x_t *a7600x = os_container_of(module, mo_a7600x_t, parent); mo_netconn_t *netconn = a7600x_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) @@ -900,10 +893,10 @@ static void urc_send_msg_func(struct at_parser *parser, const char *data, os_siz } static at_urc_t gs_urc_table[] = { - {.prefix = "+CIPOPEN:", .suffix = "\r\n", .func = urc_tcp_connect_func}, - {.prefix = "+IPCLOSE:", .suffix = "\r\n", .func = urc_close_func}, - {.prefix = "+CIPSEND:", .suffix = "\r\n", .func = urc_send_msg_func}, - {.prefix = "+RECEIVE,", .suffix = "\r\n", .func = urc_recv_func}, + {.prefix = "+CIPOPEN:", .suffix = "\r\n", .func = urc_tcp_connect_func}, + {.prefix = "+IPCLOSE:", .suffix = "\r\n", .func = urc_close_func}, + {.prefix = "+CIPSEND:", .suffix = "\r\n", .func = urc_send_msg_func}, + {.prefix = "+RECEIVE,", .suffix = "\r\n", .func = urc_recv_func}, }; void a7600x_netconn_init(mo_a7600x_t *module) diff --git a/components/molink/module/a7600x/source/a7600x_netserv.c b/components/molink/module/a7600x/source/a7600x_netserv.c index 30e8d460..15bb29e9 100644 --- a/components/molink/module/a7600x/source/a7600x_netserv.c +++ b/components/molink/module/a7600x/source/a7600x_netserv.c @@ -59,7 +59,7 @@ os_err_t a7600x_get_attach(mo_object_t *self, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) { ERROR("Get %s module attach state failed", self->name); return OS_ERROR; @@ -159,98 +159,97 @@ os_err_t a7600x_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber) return OS_EOK; } -#define GET_A7600X_RSSI(rxlev) (0 - (63 - rxlev + 48)) -#define A7600X_MODULE_NET_TYPE 5 -os_err_t a7600x_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info) -{ - os_err_t ret = OS_EOK; - cell_info_t *cell_info = OS_NULL; - char *temp_buff = OS_NULL; - os_uint32_t cell_num = 0; - os_uint32_t rxlev = 0; - - at_parser_t *parser = &self->parser; - - if (parser == OS_NULL) - { - ERROR("A7600X ping: at parser is NULL."); - return OS_ERROR; - } - if(!onepos_cell_info) - { - ERROR("input param is error!"); - return OS_ERROR; - } - - at_resp_t resp = {.buff = os_calloc(1, 1024), - .buff_size = 1024, - .timeout = 50 * OS_TICK_PER_SECOND - }; - - if (OS_NULL == resp.buff) - { - ERROR("Calloc a7600x cell info response memory failed!"); - ret = OS_ENOMEM; - goto __exit; - } - - /* neighbor cell */ - if (at_parser_exec_cmd(parser, &resp, "AT+CPSI?") < 0) - { - ret = OS_ERROR; - ERROR("AT cmd exec fail: AT+CPSI?\n"); - goto __exit; - } - DEBUG("resp->line_counts : %d\r\n", resp.line_counts); - - cell_info = os_calloc(1, sizeof(cell_info_t)); - if(NULL == cell_info) - { - ERROR("malloc cell_info is null"); - ret = OS_ENOMEM; - return ret; - } - - INFO(" MCC MNC CID LAC RSSI\n"); - INFO(" ------------ ------------ ------------ ------------ ----\n"); - - /* main cell */ - - temp_buff = (char*)at_resp_get_line(&resp, 1); - - if(strlen(temp_buff) > 25) +#define GET_A7600X_RSSI(rxlev) (0 - (63 - rxlev + 48)) +#define A7600X_MODULE_NET_TYPE 5 +os_err_t a7600x_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info) +{ + os_err_t ret = OS_EOK; + cell_info_t *cell_info = OS_NULL; + char *temp_buff = OS_NULL; + os_uint32_t cell_num = 0; + os_uint32_t rxlev = 0; + + at_parser_t *parser = &self->parser; + + if (parser == OS_NULL) + { + ERROR("A7600X ping: at parser is NULL."); + return OS_ERROR; + } + if (!onepos_cell_info) + { + ERROR("input param is error!"); + return OS_ERROR; + } + + at_resp_t resp = {.buff = os_calloc(1, 1024), .buff_size = 1024, .timeout = 50 * OS_TICK_PER_SECOND}; + + if (OS_NULL == resp.buff) + { + ERROR("Calloc a7600x cell info response memory failed!"); + ret = OS_ENOMEM; + goto __exit; + } + + /* neighbor cell */ + if (at_parser_exec_cmd(parser, &resp, "AT+CPSI?") < 0) + { + ret = OS_ERROR; + ERROR("AT cmd exec fail: AT+CPSI?\n"); + goto __exit; + } + DEBUG("resp->line_counts : %d\r\n", resp.line_counts); + + cell_info = os_calloc(1, sizeof(cell_info_t)); + if (NULL == cell_info) { - sscanf(temp_buff, - "+CPSI:%*[^,],%*[^,],%u-%u,0x%x,%u, %*[^,], %*[^,], %*[^,], %*[^,], %*[^,], %*[^,], %*[^,], %u, %*[^\r]", - &cell_info[cell_num].mcc, - &cell_info[cell_num].mnc, + ERROR("malloc cell_info is null"); + ret = OS_ENOMEM; + return ret; + } + + INFO(" MCC MNC CID LAC RSSI\n"); + INFO(" ------------ ------------ ------------ ------------ ----\n"); + + /* main cell */ + + temp_buff = (char *)at_resp_get_line(&resp, 1); + + if (strlen(temp_buff) > 25) + { + sscanf(temp_buff, + "+CPSI:%*[^,],%*[^,],%u-%u,0x%x,%u, %*[^,], %*[^,], %*[^,], %*[^,], %*[^,], %*[^,], %*[^,], %u, %*[^\r]", + &cell_info[cell_num].mcc, + &cell_info[cell_num].mnc, &cell_info[cell_num].lac, &cell_info[cell_num].cid, - &rxlev - ); - cell_info[cell_num].ss = GET_A7600X_RSSI(rxlev); - INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", - cell_info[cell_num].mcc, cell_info[cell_num].mnc, cell_info[cell_num].cid, - cell_info[cell_num].lac, cell_info[cell_num].ss); - } - else - { - cell_num --; - } - INFO(" ------------ ------------ ------------ ------------ ----\n"); - - onepos_cell_info->cell_num = ++cell_num; - onepos_cell_info->cell_info = cell_info; - onepos_cell_info->net_type = A7600X_MODULE_NET_TYPE; - -__exit: - - if (resp.buff != OS_NULL) - { - os_free(resp.buff); - } - - return ret; -} + &rxlev); + cell_info[cell_num].ss = GET_A7600X_RSSI(rxlev); + INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", + cell_info[cell_num].mcc, + cell_info[cell_num].mnc, + cell_info[cell_num].cid, + cell_info[cell_num].lac, + cell_info[cell_num].ss); + } + else + { + cell_num--; + } + INFO(" ------------ ------------ ------------ ------------ ----\n"); + + onepos_cell_info->cell_num = ++cell_num; + onepos_cell_info->cell_info = cell_info; + onepos_cell_info->net_type = A7600X_MODULE_NET_TYPE; + +__exit: + + if (resp.buff != OS_NULL) + { + os_free(resp.buff); + } + + return ret; +} #endif /* A7600X_USING_NETSERV_OPS */ diff --git a/components/molink/module/a7600x/source/a7600x_ping.c b/components/molink/module/a7600x/source/a7600x_ping.c index aab6ddd3..361fc733 100644 --- a/components/molink/module/a7600x/source/a7600x_ping.c +++ b/components/molink/module/a7600x/source/a7600x_ping.c @@ -40,16 +40,16 @@ typedef enum a7600x_ping_ret_tpye PING_TIMEOUT, PING_SUMMARY, PING_UNKNOWN_RET -}a7600x_ping_ret_tpye_t; +} a7600x_ping_ret_tpye_t; os_err_t a7600x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - os_int16_t req_time = -1; - os_int16_t ttl = -1; - os_int16_t req_len = -1; - os_uint8_t ping_stat = 0; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; + os_int16_t req_time = -1; + os_int16_t ttl = -1; + os_int16_t req_len = -1; + os_uint8_t ping_stat = 0; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -62,20 +62,20 @@ os_err_t a7600x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ui if ((len > A7600X_MAX_PING_PKG_LEN) || (len < A7600X_MIN_PING_PKG_LEN)) { ERROR("%s ping: ping package len[%d] is out of range[%d, %d].", - self->name, - len, - A7600X_MIN_PING_PKG_LEN, - A7600X_MAX_PING_PKG_LEN); + self->name, + len, + A7600X_MIN_PING_PKG_LEN, + A7600X_MAX_PING_PKG_LEN); return OS_ERROR; } if (timeout > A7600X_MAX_PING_TIMEOUT) { ERROR("%s ping: user set ping timeout value %ums is out of range[%dms, %dms].", - self->name, - timeout, - A7600X_MIN_PING_TIMEOUT, - A7600X_MAX_PING_TIMEOUT); + self->name, + timeout, + A7600X_MIN_PING_TIMEOUT, + A7600X_MAX_PING_TIMEOUT); return OS_ERROR; } @@ -83,10 +83,10 @@ os_err_t a7600x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ui if (timeout < A7600X_MIN_PING_TIMEOUT) { DEBUG("%s ping: config timeout %ums is less than the min effective value %dms, set timeout to %d.", - self->name, - timeout, - A7600X_MIN_PING_TIMEOUT, - A7600X_MIN_PING_TIMEOUT); + self->name, + timeout, + A7600X_MIN_PING_TIMEOUT, + A7600X_MIN_PING_TIMEOUT); timeout = A7600X_MIN_PING_TIMEOUT; } @@ -95,10 +95,10 @@ os_err_t a7600x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ui char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; /* Need to wait for 6 lines response msg */ - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .line_num = 3, - .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; + .line_num = 3, + .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; /* Exec AT+CPING="www.baidu.com",1,1,64,,10000; */ /* Def ping timeout: OK\r\n +CPING: 2\r\n +CPING: 3,1,0,1,0,0,0\r\n */ @@ -117,7 +117,7 @@ os_err_t a7600x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ui goto __exit; } - switch(ping_stat) + switch (ping_stat) { case PING_OK: if (at_resp_get_data_by_line(&at_resp, 2, "+CPING: 1,%[^,],%d,%d,%d", ipaddr, &req_len, &req_time, &ttl) < 0) @@ -131,9 +131,9 @@ os_err_t a7600x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ui DEBUG("%s ping: resp parse ip[%s], req_time[%d], ttl[%d]", self->name, ipaddr, req_time, ttl); inet_aton(ipaddr, &(resp->ip_addr)); resp->data_len = len; - resp->ttl = ttl; - resp->time = req_time; - result = OS_EOK; + resp->ttl = ttl; + resp->time = req_time; + result = OS_EOK; } break; diff --git a/components/molink/module/a7670x/include/a7670x.h b/components/molink/module/a7670x/include/a7670x.h index f85dd9d7..f4d2ab88 100644 --- a/components/molink/module/a7670x/include/a7670x.h +++ b/components/molink/module/a7670x/include/a7670x.h @@ -77,13 +77,13 @@ typedef struct mo_a7670x mo_object_t parent; #ifdef A7670X_USING_NETCONN_OPS mo_netconn_t netconn[A7670X_NETCONN_NUM]; - os_event_t netconn_evt; - os_mutex_t netconn_lock; + os_event_t netconn_evt; + os_mutex_t netconn_lock; #endif /* A7670X_USING_NETCONN_OPS */ } mo_a7670x_t; mo_object_t *module_a7670x_create(const char *name, void *parser_config); -os_err_t module_a7670x_destroy(mo_object_t *self); +os_err_t module_a7670x_destroy(mo_object_t *self); #endif /* MOLINK_USING_A7670X */ diff --git a/components/molink/module/a7670x/include/a7670x_netconn.h b/components/molink/module/a7670x/include/a7670x_netconn.h index d2e67c4b..00b12218 100644 --- a/components/molink/module/a7670x/include/a7670x_netconn.h +++ b/components/molink/module/a7670x/include/a7670x_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef A7670X_USING_NETCONN_OPS -os_err_t a7670x_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t a7670x_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *a7670x_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t a7670x_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t a7670x_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t a7670x_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t a7670x_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t a7670x_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t a7670x_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef A7670X_USING_DNS -os_err_t a7670x_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t a7670x_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* A7670X_USING_NETCONN_OPS */ diff --git a/components/molink/module/a7670x/include/a7670x_netserv.h b/components/molink/module/a7670x/include/a7670x_netserv.h index a21e4918..b957a01d 100644 --- a/components/molink/module/a7670x/include/a7670x_netserv.h +++ b/components/molink/module/a7670x/include/a7670x_netserv.h @@ -40,7 +40,7 @@ os_err_t a7670x_set_cgact(mo_object_t *self, os_uint8_t cid, os_uint8_t act_stat os_err_t a7670x_get_cgact(mo_object_t *self, os_uint8_t *cid, os_uint8_t *act_stat); os_err_t a7670x_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber); os_err_t a7670x_get_radio(mo_object_t *self, radio_info_t *radio_info); -os_err_t a7670x_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info); +os_err_t a7670x_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info); #endif /* A7670X_USING_NETSERV_OPS */ #ifdef __cplusplus diff --git a/components/molink/module/a7670x/source/a7670x.c b/components/molink/module/a7670x/source/a7670x.c index be391a2a..4c35ac32 100644 --- a/components/molink/module/a7670x/source/a7670x.c +++ b/components/molink/module/a7670x/source/a7670x.c @@ -37,24 +37,24 @@ #ifdef A7670X_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = a7670x_at_test, - .get_imei = a7670x_get_imei, - .get_imsi = a7670x_get_imsi, + .at_test = a7670x_at_test, + .get_imei = a7670x_get_imei, + .get_imsi = a7670x_get_imsi, .get_iccid = a7670x_get_iccid, - .get_cfun = a7670x_get_cfun, - .set_cfun = a7670x_set_cfun, + .get_cfun = a7670x_get_cfun, + .set_cfun = a7670x_set_cfun, }; #endif /* A7670X_USING_GENERAL_OPS */ #ifdef A7670X_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = a7670x_set_attach, - .get_attach = a7670x_get_attach, - .set_reg = a7670x_set_reg, - .get_reg = a7670x_get_reg, - .set_cgact = a7670x_set_cgact, - .get_cgact = a7670x_get_cgact, - .get_csq = a7670x_get_csq, + .set_attach = a7670x_set_attach, + .get_attach = a7670x_get_attach, + .set_reg = a7670x_set_reg, + .get_reg = a7670x_get_reg, + .set_cgact = a7670x_set_cgact, + .get_cgact = a7670x_get_cgact, + .get_csq = a7670x_get_csq, .get_cell_info = a7670x_get_cell_info, }; #endif /* A7670X_USING_NETSERV_OPS */ @@ -67,7 +67,7 @@ static const struct mo_ping_ops gs_ping_ops = { #ifdef A7670X_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = a7670x_ifconfig, + .ifconfig = a7670x_ifconfig, .get_ipaddr = a7670x_get_ipaddr, }; #endif /* A7670X_USING_IFCONFIG_OPS */ @@ -76,14 +76,14 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void a7670x_netconn_init(mo_a7670x_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = a7670x_netconn_create, - .destroy = a7670x_netconn_destroy, + .create = a7670x_netconn_create, + .destroy = a7670x_netconn_destroy, #ifdef A7670X_USING_DNS .gethostbyname = a7670x_netconn_gethostbyname, #endif - .connect = a7670x_netconn_connect, - .send = a7670x_netconn_send, - .get_info = a7670x_netconn_get_info, + .connect = a7670x_netconn_connect, + .send = a7670x_netconn_send, + .get_info = a7670x_netconn_get_info, }; #endif /* A7670X_USING_NETCONN_OPS */ @@ -92,17 +92,22 @@ static void urc_cereg_info_func(struct at_parser *parser, const char *data, os_s OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - int stat = 0; + int stat = 0; int access = 0; char area_code[AT_RESP_BUFF_SIZE_DEF] = {0}; - char cell_id [AT_RESP_BUFF_SIZE_DEF] = {0}; + char cell_id[AT_RESP_BUFF_SIZE_DEF] = {0}; /* For ex: +CEREG: 1,"8109","0ee5e687",7\r\n, +CEREG: [,,[,]] */ sscanf(data, "+CEREG: %d,\"%[^\"]\",\"%[^\"]\",%d", &stat, area_code, cell_id, &access); - WARN("The module %s access network base station has been switched. network status[%d], tac[%s], cell_id[%s], AcT[%d]", - parser->name, stat, area_code, cell_id, access); + WARN("The module %s access network base station has been switched. network status[%d], tac[%s], cell_id[%s], " + "AcT[%d]", + parser->name, + stat, + area_code, + cell_id, + access); return; } @@ -126,9 +131,7 @@ static os_err_t a7670x_at_init(mo_object_t *self) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 2 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * OS_TICK_PER_SECOND}; return at_parser_exec_cmd(parser, &resp, "ATE0"); } @@ -229,7 +232,7 @@ int a7670x_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = A7670X_NAME, + mo_parser_config_t parser_config = {.parser_name = A7670X_NAME, .parser_device = device, .recv_buff_len = A7670X_RECV_BUFF_LEN}; diff --git a/components/molink/module/a7670x/source/a7670x_ifconfig.c b/components/molink/module/a7670x/source/a7670x_ifconfig.c index 06684e6b..59016b33 100644 --- a/components/molink/module/a7670x/source/a7670x_ifconfig.c +++ b/components/molink/module/a7670x/source/a7670x_ifconfig.c @@ -38,14 +38,14 @@ os_err_t a7670x_ifconfig(mo_object_t *self) { char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; - char imei[MO_IMEI_LEN + 1] = {0}; - char iccid[MO_ICCID_LEN + 1] = {0}; - char imsi[MO_IMSI_LEN + 1] = {0}; + char imei[MO_IMEI_LEN + 1] = {0}; + char iccid[MO_ICCID_LEN + 1] = {0}; + char imsi[MO_IMSI_LEN + 1] = {0}; - os_err_t ret = OS_EOK; + os_err_t ret = OS_EOK; os_uint8_t rssi = 0; - os_uint8_t ber = 0; - os_int32_t i = 0; + os_uint8_t ber = 0; + os_int32_t i = 0; if (a7670x_get_ipaddr(self, ipaddr) != OS_EOK) { @@ -73,7 +73,7 @@ os_err_t a7670x_ifconfig(mo_object_t *self) if (a7670x_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; ret = OS_ERROR; } @@ -103,7 +103,7 @@ os_err_t a7670x_ifconfig(mo_object_t *self) os_err_t a7670x_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t len = -1; + os_int8_t len = -1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; diff --git a/components/molink/module/a7670x/source/a7670x_netconn.c b/components/molink/module/a7670x/source/a7670x_netconn.c index 0b5e3632..d9f6e43d 100644 --- a/components/molink/module/a7670x/source/a7670x_netconn.c +++ b/components/molink/module/a7670x/source/a7670x_netconn.c @@ -32,7 +32,7 @@ #define MO_LOG_LVL MO_LOG_INFO #include -#define SEND_DATA_MAX_SIZE (1360) +#define SEND_DATA_MAX_SIZE (1360) #define A7670X_NETCONN_MQ_NAME "a7670x_nc_mq" @@ -41,11 +41,10 @@ #endif #ifndef A7670X_NETCONN_MQ_MSG_MAX -#define A7670X_NETCONN_MQ_MSG_MAX (16) +#define A7670X_NETCONN_MQ_MSG_MAX (16) #endif - -#define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) +#define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) #define A7670X_EVENT_NETCONN_OK (1L << 0) #define A7670X_EVENT_NETCONN_FAIL (1L << 1) @@ -57,25 +56,25 @@ enum net_transfer_mode { NON_TRANSPARENT_MODE = 0, - TRANSPARENT_MODE = 1, + TRANSPARENT_MODE = 1, }; enum net_server_status { NET_SERVER_DISABLE = 0, - NET_SERVER_ENABLE = 1, + NET_SERVER_ENABLE = 1, }; enum netconn_send_status { - CONN_DISCONNECTED = -1, + CONN_DISCONNECTED = -1, CONN_SEND_BUFF_FULL = 0, }; enum link_close_reason { - LINK_CLOSED_BY_LOCAL = 0, - LINK_CLOSED_BY_REMOTE = 1, + LINK_CLOSED_BY_LOCAL = 0, + LINK_CLOSED_BY_REMOTE = 1, SEND_TIMEOUT_OR_DTR_OFF = 2, LINK_CLOSED_UNKNOWN, }; @@ -139,7 +138,7 @@ os_err_t a7670x_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_a7670x_t *a7670x = os_container_of(module, mo_a7670x_t, parent); info->netconn_array = a7670x->netconn; - info->netconn_nums = sizeof(a7670x->netconn) / sizeof(a7670x->netconn[0]); + info->netconn_nums = sizeof(a7670x->netconn) / sizeof(a7670x->netconn[0]); return OS_EOK; } @@ -147,8 +146,8 @@ os_err_t a7670x_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) static os_err_t a7670x_netconn_set_transfer_mode(mo_object_t *module) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_int32_t mode = -1; + os_err_t result = OS_EOK; + os_int32_t mode = -1; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -189,8 +188,8 @@ static os_err_t a7670x_netconn_set_transfer_mode(mo_object_t *module) static os_err_t a7670x_netconn_server_open(mo_object_t *module) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_int32_t stat = -1; + os_err_t result = OS_EOK; + os_int32_t stat = -1; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -231,7 +230,7 @@ static os_err_t a7670x_netconn_server_open(mo_object_t *module) static os_err_t a7670x_net_server_config(mo_object_t *module) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -283,7 +282,7 @@ static os_err_t a7670x_net_server_config(mo_object_t *module) mo_netconn_t *a7670x_netconn_create(mo_object_t *module, mo_netconn_type_t type) { mo_a7670x_t *a7670x = os_container_of(module, mo_a7670x_t, parent); - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; a7670x_lock(&a7670x->netconn_lock); @@ -323,7 +322,7 @@ mo_netconn_t *a7670x_netconn_create(mo_object_t *module, mo_netconn_type_t type) os_err_t a7670x_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -370,11 +369,11 @@ os_err_t a7670x_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn_id: %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; - netconn->local_port = 0; + netconn->local_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); a7670x_unlock(&a7670x->netconn_lock); @@ -387,12 +386,10 @@ os_err_t a7670x_netconn_gethostbyname(mo_object_t *self, const char *domain_name { at_parser_t *parser = &self->parser; - char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; + char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 20 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CDNSGIP=\"%s\"", domain_name); if (result < 0) @@ -440,19 +437,17 @@ __exit: #ifdef A7670X_USING_TCP static os_err_t a7670x_tcp_connect(mo_object_t *module, mo_netconn_t *netconn, char *ip_addr, os_uint16_t port) { - mo_a7670x_t *a7670x = os_container_of(module, mo_a7670x_t, parent); - at_parser_t *parser = &module->parser; - os_int32_t connect_id = netconn->connect_id; - os_err_t result = OS_ERROR; - os_uint32_t event = SET_EVENT(netconn->connect_id, A7670X_EVENT_NETCONN_OK | A7670X_EVENT_NETCONN_FAIL); + mo_a7670x_t *a7670x = os_container_of(module, mo_a7670x_t, parent); + at_parser_t *parser = &module->parser; + os_int32_t connect_id = netconn->connect_id; + os_err_t result = OS_ERROR; + os_uint32_t event = SET_EVENT(netconn->connect_id, A7670X_EVENT_NETCONN_OK | A7670X_EVENT_NETCONN_FAIL); - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; os_event_recv(&a7670x->netconn_evt, event, OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, OS_NO_WAIT, OS_NULL); - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 30 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 30 * OS_TICK_PER_SECOND}; a7670x_lock(&a7670x->netconn_lock); @@ -505,15 +500,10 @@ static os_err_t a7670x_udp_connect(mo_object_t *module, mo_netconn_t *netconn) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 30 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 30 * OS_TICK_PER_SECOND}; - os_err_t result = at_parser_exec_cmd(parser, - &resp, - "AT+CIPOPEN=%d,\"UDP\",,,%u", - netconn->connect_id, - netconn->local_port); + os_err_t result = + at_parser_exec_cmd(parser, &resp, "AT+CIPOPEN=%d,\"UDP\",,,%u", netconn->connect_id, netconn->local_port); if (result != OS_EOK) { ERROR("AT cmd exec failed: AT+CIPOPEN=%d,\"UDP\",,,%u", netconn->connect_id, netconn->local_port); @@ -560,7 +550,7 @@ os_err_t a7670x_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_a ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%u successfully!", module->name, remote_ip, port); @@ -569,16 +559,16 @@ os_err_t a7670x_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_a os_size_t a7670x_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t cur_pkt_size = 0; - os_uint32_t event = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t cur_pkt_size = 0; + os_uint32_t event = 0; mo_a7670x_t *a7670x = os_container_of(module, mo_a7670x_t, parent); a7670x_lock(&a7670x->netconn_lock); - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 60 * OS_TICK_PER_SECOND}; @@ -718,9 +708,9 @@ static void urc_tcp_connect_func(struct at_parser *parser, const char *data, os_ mo_a7670x_t *a7670x = os_container_of(module, mo_a7670x_t, parent); os_int32_t connect_id = -1; - os_int32_t result = -1; + os_int32_t result = -1; - sscanf(data, "+CIPOPEN: %d,%d", &connect_id , &result); + sscanf(data, "+CIPOPEN: %d,%d", &connect_id, &result); if (0 == result) { @@ -740,11 +730,11 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = -1; - os_int32_t closed_by = -1; + os_int32_t closed_by = -1; sscanf(data, "+IPCLOSE: %d,%d", &connect_id, &closed_by); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = a7670x_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) @@ -753,7 +743,7 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t return; } - switch(closed_by) + switch (closed_by) { case LINK_CLOSED_BY_LOCAL: DEBUG("Module %s connect %d, closed by local, active", module->name, connect_id); @@ -784,8 +774,8 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; - os_int32_t timeout = 0; + os_int32_t data_size = 0; + os_int32_t timeout = 0; /* For ex: +RECEIVE,0,10\r\n 0123456789 */ sscanf(data, "+RECEIVE,%d,%d,", &connect_id, &data_size); @@ -793,7 +783,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t timeout = data_size > 10 ? data_size : 10; - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = a7670x_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) { @@ -803,8 +793,8 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t if (netconn->stat == NETCONN_STAT_CONNECT) { - char *recv_buff = os_calloc(1, data_size + 1); - char temp_buff[8] = {0}; + char *recv_buff = os_calloc(1, data_size + 1); + char temp_buff[8] = {0}; if (recv_buff == OS_NULL) { @@ -853,15 +843,15 @@ static void urc_send_msg_func(struct at_parser *parser, const char *data, os_siz OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - os_int32_t connect_id = -1; - os_int32_t reqsend_len = -1; - os_int32_t cnfsend_len = -2; - os_err_t result = OS_EOK; + os_int32_t connect_id = -1; + os_int32_t reqsend_len = -1; + os_int32_t cnfsend_len = -2; + os_err_t result = OS_EOK; /* +CIPSEND: 0,1500,1500\r\n */ sscanf(data, "+CIPSEND: %d,%d,%d", &connect_id, &reqsend_len, &cnfsend_len); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_a7670x_t *a7670x = os_container_of(module, mo_a7670x_t, parent); mo_netconn_t *netconn = a7670x_get_netconn_by_id(module, connect_id); @@ -905,10 +895,10 @@ static void urc_send_msg_func(struct at_parser *parser, const char *data, os_siz } static at_urc_t gs_urc_table[] = { - {.prefix = "+CIPOPEN:", .suffix = "\r\n", .func = urc_tcp_connect_func}, - {.prefix = "+IPCLOSE:", .suffix = "\r\n", .func = urc_close_func}, - {.prefix = "+CIPSEND:", .suffix = "\r\n", .func = urc_send_msg_func}, - {.prefix = "+RECEIVE,", .suffix = "\r\n", .func = urc_recv_func}, + {.prefix = "+CIPOPEN:", .suffix = "\r\n", .func = urc_tcp_connect_func}, + {.prefix = "+IPCLOSE:", .suffix = "\r\n", .func = urc_close_func}, + {.prefix = "+CIPSEND:", .suffix = "\r\n", .func = urc_send_msg_func}, + {.prefix = "+RECEIVE,", .suffix = "\r\n", .func = urc_recv_func}, }; void a7670x_netconn_init(mo_a7670x_t *module) diff --git a/components/molink/module/a7670x/source/a7670x_netserv.c b/components/molink/module/a7670x/source/a7670x_netserv.c index 80e9c067..2ef9fa3c 100644 --- a/components/molink/module/a7670x/source/a7670x_netserv.c +++ b/components/molink/module/a7670x/source/a7670x_netserv.c @@ -58,7 +58,7 @@ os_err_t a7670x_get_attach(mo_object_t *self, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) { ERROR("Get %s module attach state failed", self->name); return OS_ERROR; @@ -158,98 +158,97 @@ os_err_t a7670x_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber) return OS_EOK; } -#define GET_A7670X_RSSI(rxlev) (0 - (63 - rxlev + 48)) -#define A7670X_MODULE_NET_TYPE 5 -os_err_t a7670x_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info) -{ - os_err_t ret = OS_EOK; - cell_info_t *cell_info = OS_NULL; - char *temp_buff = OS_NULL; - os_uint32_t cell_num = 0; - os_uint32_t rxlev = 0; - - at_parser_t *parser = &self->parser; - - if (parser == OS_NULL) - { - ERROR("A7670X ping: at parser is NULL."); - return OS_ERROR; - } - if(!onepos_cell_info) - { - ERROR("input param is error!"); - return OS_ERROR; - } - - at_resp_t resp = {.buff = os_calloc(1, 1024), - .buff_size = 1024, - .timeout = 50 * OS_TICK_PER_SECOND - }; - - if (OS_NULL == resp.buff) - { - ERROR("Calloc a7670x cell info response memory failed!"); - ret = OS_ENOMEM; - goto __exit; - } - - /* neighbor cell */ - if (at_parser_exec_cmd(parser, &resp, "AT+CPSI?") < 0) - { - ret = OS_ERROR; - ERROR("AT cmd exec fail: AT+CPSI?\n"); - goto __exit; - } - DEBUG("resp->line_counts : %d\r\n", resp.line_counts); - - cell_info = os_calloc(1, sizeof(cell_info_t)); - if(NULL == cell_info) - { - ERROR("malloc cell_info is null"); - ret = OS_ENOMEM; - return ret; - } - - INFO(" MCC MNC CID LAC RSSI\n"); - INFO(" ------------ ------------ ------------ ------------ ----\n"); - - /* main cell */ - - temp_buff = (char*)at_resp_get_line(&resp, 1); - - if(strlen(temp_buff) > 25) - { - sscanf(temp_buff, - "+CPSI:%*[^,],%*[^,],%u-%u,0x%x,%u, %*[^,], %*[^,], %*[^,], %*[^,], %*[^,], %*[^,], %*[^,], %u, %*[^\r]", - &cell_info[cell_num].mcc, - &cell_info[cell_num].mnc, +#define GET_A7670X_RSSI(rxlev) (0 - (63 - rxlev + 48)) +#define A7670X_MODULE_NET_TYPE 5 +os_err_t a7670x_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info) +{ + os_err_t ret = OS_EOK; + cell_info_t *cell_info = OS_NULL; + char *temp_buff = OS_NULL; + os_uint32_t cell_num = 0; + os_uint32_t rxlev = 0; + + at_parser_t *parser = &self->parser; + + if (parser == OS_NULL) + { + ERROR("A7670X ping: at parser is NULL."); + return OS_ERROR; + } + if (!onepos_cell_info) + { + ERROR("input param is error!"); + return OS_ERROR; + } + + at_resp_t resp = {.buff = os_calloc(1, 1024), .buff_size = 1024, .timeout = 50 * OS_TICK_PER_SECOND}; + + if (OS_NULL == resp.buff) + { + ERROR("Calloc a7670x cell info response memory failed!"); + ret = OS_ENOMEM; + goto __exit; + } + + /* neighbor cell */ + if (at_parser_exec_cmd(parser, &resp, "AT+CPSI?") < 0) + { + ret = OS_ERROR; + ERROR("AT cmd exec fail: AT+CPSI?\n"); + goto __exit; + } + DEBUG("resp->line_counts : %d\r\n", resp.line_counts); + + cell_info = os_calloc(1, sizeof(cell_info_t)); + if (NULL == cell_info) + { + ERROR("malloc cell_info is null"); + ret = OS_ENOMEM; + return ret; + } + + INFO(" MCC MNC CID LAC RSSI\n"); + INFO(" ------------ ------------ ------------ ------------ ----\n"); + + /* main cell */ + + temp_buff = (char *)at_resp_get_line(&resp, 1); + + if (strlen(temp_buff) > 25) + { + sscanf(temp_buff, + "+CPSI:%*[^,],%*[^,],%u-%u,0x%x,%u, %*[^,], %*[^,], %*[^,], %*[^,], %*[^,], %*[^,], %*[^,], %u, %*[^\r]", + &cell_info[cell_num].mcc, + &cell_info[cell_num].mnc, &cell_info[cell_num].lac, &cell_info[cell_num].cid, - &rxlev - ); - cell_info[cell_num].ss = GET_A7670X_RSSI(rxlev); - INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", - cell_info[cell_num].mcc, cell_info[cell_num].mnc, cell_info[cell_num].cid, - cell_info[cell_num].lac, cell_info[cell_num].ss); - } - else - { - cell_num --; - } - INFO(" ------------ ------------ ------------ ------------ ----\n"); - - onepos_cell_info->cell_num = ++cell_num; - onepos_cell_info->cell_info = cell_info; - onepos_cell_info->net_type = A7670X_MODULE_NET_TYPE; - -__exit: - - if (resp.buff != OS_NULL) - { - os_free(resp.buff); - } - - return ret; -} + &rxlev); + cell_info[cell_num].ss = GET_A7670X_RSSI(rxlev); + INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", + cell_info[cell_num].mcc, + cell_info[cell_num].mnc, + cell_info[cell_num].cid, + cell_info[cell_num].lac, + cell_info[cell_num].ss); + } + else + { + cell_num--; + } + INFO(" ------------ ------------ ------------ ------------ ----\n"); + + onepos_cell_info->cell_num = ++cell_num; + onepos_cell_info->cell_info = cell_info; + onepos_cell_info->net_type = A7670X_MODULE_NET_TYPE; + +__exit: + + if (resp.buff != OS_NULL) + { + os_free(resp.buff); + } + + return ret; +} #endif /* A7670X_USING_NETSERV_OPS */ diff --git a/components/molink/module/a7670x/source/a7670x_ping.c b/components/molink/module/a7670x/source/a7670x_ping.c index 032a406a..0b0cdac3 100644 --- a/components/molink/module/a7670x/source/a7670x_ping.c +++ b/components/molink/module/a7670x/source/a7670x_ping.c @@ -40,16 +40,16 @@ typedef enum a7670x_ping_ret_tpye PING_TIMEOUT, PING_SUMMARY, PING_UNKNOWN_RET -}a7670x_ping_ret_tpye_t; +} a7670x_ping_ret_tpye_t; os_err_t a7670x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - os_int16_t req_time = -1; - os_int16_t ttl = -1; - os_int16_t req_len = -1; - os_uint8_t ping_stat = 0; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; + os_int16_t req_time = -1; + os_int16_t ttl = -1; + os_int16_t req_len = -1; + os_uint8_t ping_stat = 0; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -62,20 +62,20 @@ os_err_t a7670x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ui if ((len > A7670X_MAX_PING_PKG_LEN) || (len < A7670X_MIN_PING_PKG_LEN)) { ERROR("%s ping: ping package len[%d] is out of range[%d, %d].", - self->name, - len, - A7670X_MIN_PING_PKG_LEN, - A7670X_MAX_PING_PKG_LEN); + self->name, + len, + A7670X_MIN_PING_PKG_LEN, + A7670X_MAX_PING_PKG_LEN); return OS_ERROR; } if (timeout > A7670X_MAX_PING_TIMEOUT) { ERROR("%s ping: user set ping timeout value %ums is out of range[%dms, %dms].", - self->name, - timeout, - A7670X_MIN_PING_TIMEOUT, - A7670X_MAX_PING_TIMEOUT); + self->name, + timeout, + A7670X_MIN_PING_TIMEOUT, + A7670X_MAX_PING_TIMEOUT); return OS_ERROR; } @@ -83,10 +83,10 @@ os_err_t a7670x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ui if (timeout < A7670X_MIN_PING_TIMEOUT) { DEBUG("%s ping: config timeout %ums is less than the min effective value %dms, set timeout to %d.", - self->name, - timeout, - A7670X_MIN_PING_TIMEOUT, - A7670X_MIN_PING_TIMEOUT); + self->name, + timeout, + A7670X_MIN_PING_TIMEOUT, + A7670X_MIN_PING_TIMEOUT); timeout = A7670X_MIN_PING_TIMEOUT; } @@ -95,10 +95,10 @@ os_err_t a7670x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ui char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; /* Need to wait for 6 lines response msg */ - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .line_num = 3, - .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; + .line_num = 3, + .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; /* Exec AT+CPING="www.baidu.com",1,1,64,,10000; */ /* Def ping timeout: OK\r\n +CPING: 2\r\n +CPING: 3,1,0,1,0,0,0\r\n */ @@ -117,7 +117,7 @@ os_err_t a7670x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ui goto __exit; } - switch(ping_stat) + switch (ping_stat) { case PING_OK: if (at_resp_get_data_by_line(&at_resp, 2, "+CPING: 1,%[^,],%d,%d,%d", ipaddr, &req_len, &req_time, &ttl) < 0) @@ -131,9 +131,9 @@ os_err_t a7670x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ui DEBUG("%s ping: resp parse ip[%s], req_time[%d], ttl[%d]", self->name, ipaddr, req_time, ttl); inet_aton(ipaddr, &(resp->ip_addr)); resp->data_len = len; - resp->ttl = ttl; - resp->time = req_time; - result = OS_EOK; + resp->ttl = ttl; + resp->time = req_time; + result = OS_EOK; } break; diff --git a/components/molink/module/air720uh/include/air720uh.h b/components/molink/module/air720uh/include/air720uh.h index 0a6badfc..593da770 100644 --- a/components/molink/module/air720uh/include/air720uh.h +++ b/components/molink/module/air720uh/include/air720uh.h @@ -72,16 +72,16 @@ typedef struct mo_air720uh { mo_object_t parent; #ifdef AIR720UH_USING_NETCONN_OPS - mo_netconn_t netconn[AIR720UH_NETCONN_NUM]; + mo_netconn_t netconn[AIR720UH_NETCONN_NUM]; - os_event_t netconn_evt; - os_mutex_t netconn_lock; - void *netconn_data; + os_event_t netconn_evt; + os_mutex_t netconn_lock; + void *netconn_data; #endif /* AIR720UH_USING_NETCONN_OPS */ } mo_air720uh_t; mo_object_t *module_air720uh_create(const char *name, void *parser_config); -os_err_t module_air720uh_destroy(mo_object_t *self); +os_err_t module_air720uh_destroy(mo_object_t *self); #endif /* MOLINK_USING_AIR720UH */ diff --git a/components/molink/module/air720uh/include/air720uh_netconn.h b/components/molink/module/air720uh/include/air720uh_netconn.h index f8f7d4fb..af37b556 100644 --- a/components/molink/module/air720uh/include/air720uh_netconn.h +++ b/components/molink/module/air720uh/include/air720uh_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef AIR720UH_USING_NETCONN_OPS -os_err_t air720uh_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t air720uh_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *air720uh_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t air720uh_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t air720uh_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t air720uh_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t air720uh_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t air720uh_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t air720uh_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef AIR720UH_USING_DNS -os_err_t air720uh_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t air720uh_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* AIR720UH_USING_NETCONN_OPS */ diff --git a/components/molink/module/air720uh/include/air720uh_ping.h b/components/molink/module/air720uh/include/air720uh_ping.h index 0aa34bae..f5600d7a 100644 --- a/components/molink/module/air720uh/include/air720uh_ping.h +++ b/components/molink/module/air720uh/include/air720uh_ping.h @@ -31,7 +31,8 @@ extern "C" { #ifdef AIR720UH_USING_PING_OPS -os_err_t air720uh_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); +os_err_t +air720uh_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); #endif /* AIR720UH_USING_PING_OPS */ diff --git a/components/molink/module/air720uh/source/air720uh.c b/components/molink/module/air720uh/source/air720uh.c index 9842b2e2..b90e5ad7 100644 --- a/components/molink/module/air720uh/source/air720uh.c +++ b/components/molink/module/air720uh/source/air720uh.c @@ -28,7 +28,7 @@ #include #define MO_LOG_TAG "air720uh" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_AIR720UH @@ -37,38 +37,38 @@ #ifdef AIR720UH_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = air720uh_at_test, - .get_imei = air720uh_get_imei, - .get_imsi = air720uh_get_imsi, - .get_iccid = air720uh_get_iccid, - .get_cfun = air720uh_get_cfun, - .set_cfun = air720uh_set_cfun, + .at_test = air720uh_at_test, + .get_imei = air720uh_get_imei, + .get_imsi = air720uh_get_imsi, + .get_iccid = air720uh_get_iccid, + .get_cfun = air720uh_get_cfun, + .set_cfun = air720uh_set_cfun, .get_firmware_version = air720uh_get_firmware_version, }; #endif /* AIR720UH_USING_GENERAL_OPS */ #ifdef AIR720UH_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = air720uh_set_attach, - .get_attach = air720uh_get_attach, - .set_reg = air720uh_set_reg, - .get_reg = air720uh_get_reg, - .set_cgact = air720uh_set_cgact, - .get_cgact = air720uh_get_cgact, - .get_csq = air720uh_get_csq, + .set_attach = air720uh_set_attach, + .get_attach = air720uh_get_attach, + .set_reg = air720uh_set_reg, + .get_reg = air720uh_get_reg, + .set_cgact = air720uh_set_cgact, + .get_cgact = air720uh_get_cgact, + .get_csq = air720uh_get_csq, }; #endif /* AIR720UH_USING_NETSERV_OPS */ #ifdef AIR720UH_USING_PING_OPS static const struct mo_ping_ops gs_ping_ops = { - .ping = air720uh_ping, + .ping = air720uh_ping, }; #endif /* AIR720UH_USING_PING_OPS */ #ifdef AIR720UH_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = air720uh_ifconfig, - .get_ipaddr = air720uh_get_ipaddr, + .ifconfig = air720uh_ifconfig, + .get_ipaddr = air720uh_get_ipaddr, }; #endif /* AIR720UH_USING_IFCONFIG_OPS */ @@ -76,14 +76,14 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void air720uh_netconn_init(mo_air720uh_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = air720uh_netconn_create, - .destroy = air720uh_netconn_destroy, + .create = air720uh_netconn_create, + .destroy = air720uh_netconn_destroy, #ifdef AIR720UH_USING_DNS - .gethostbyname = air720uh_netconn_gethostbyname, + .gethostbyname = air720uh_netconn_gethostbyname, #endif - .connect = air720uh_netconn_connect, - .send = air720uh_netconn_send, - .get_info = air720uh_netconn_get_info, + .connect = air720uh_netconn_connect, + .send = air720uh_netconn_send, + .get_info = air720uh_netconn_get_info, }; #endif /* AIR720UH_USING_NETCONN_OPS */ @@ -93,7 +93,7 @@ void air720uh_poweron_sequence(void) os_pin_mode(GET_PIN(A, 4), PIN_MODE_OUTPUT); os_pin_write(GET_PIN(A, 4), PIN_HIGH); os_pin_write(GET_PIN(A, 3), PIN_HIGH); - os_task_msleep( 500 ); + os_task_msleep(500); os_pin_write(GET_PIN(A, 3), PIN_LOW); INFO("%s Executed power on process.", __func__); @@ -123,9 +123,7 @@ static os_err_t air720uh_at_init(mo_object_t *self) char resp_buff[32] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; return at_parser_exec_cmd(parser, &resp, "ATE0"); } @@ -227,14 +225,14 @@ int air720uh_auto_create(void) return OS_ERROR; } - uart_config.baud_rate = AIR720UH_DEVICE_RATE; + uart_config.baud_rate = AIR720UH_DEVICE_RATE; // air720uh_poweron_sequence(); INFO("Auto create %s module object with [%s]:[%d]bps", AIR720UH_NAME, AIR720UH_DEVICE_NAME, AIR720UH_DEVICE_RATE); os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = AIR720UH_NAME, + mo_parser_config_t parser_config = {.parser_name = AIR720UH_NAME, .parser_device = device, .recv_buff_len = AIR720UH_RECV_BUFF_LEN}; @@ -246,7 +244,10 @@ int air720uh_auto_create(void) return OS_ERROR; } - INFO("Auto create %s module object success [%s]:[%d]bps!", AIR720UH_NAME, AIR720UH_DEVICE_NAME, AIR720UH_DEVICE_RATE); + INFO("Auto create %s module object success [%s]:[%d]bps!", + AIR720UH_NAME, + AIR720UH_DEVICE_NAME, + AIR720UH_DEVICE_RATE); return OS_EOK; } OS_CMPOENT_INIT(air720uh_auto_create, OS_INIT_SUBLEVEL_MIDDLE); diff --git a/components/molink/module/air720uh/source/air720uh_general.c b/components/molink/module/air720uh/source/air720uh_general.c index 50001f28..c1da7bed 100644 --- a/components/molink/module/air720uh/source/air720uh_general.c +++ b/components/molink/module/air720uh/source/air720uh_general.c @@ -26,7 +26,7 @@ #include #define MO_LOG_TAG "air720uh_general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef AIR720UH_USING_GENERAL_OPS @@ -169,9 +169,7 @@ os_err_t air720uh_get_firmware_version(mo_object_t *self, mo_firmware_version_t char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+VER"); if (result != OS_EOK) @@ -186,7 +184,7 @@ os_err_t air720uh_get_firmware_version(mo_object_t *self, mo_firmware_version_t } const char *source_line = at_resp_get_line(&resp, 1); - os_size_t line_length = strlen(source_line); + os_size_t line_length = strlen(source_line); /* TODO test return line or set to dynamic dump */ char **dest_line = &version->ver_info[0]; diff --git a/components/molink/module/air720uh/source/air720uh_ifconfig.c b/components/molink/module/air720uh/source/air720uh_ifconfig.c index 60c31c42..fc0185c4 100644 --- a/components/molink/module/air720uh/source/air720uh_ifconfig.c +++ b/components/molink/module/air720uh/source/air720uh_ifconfig.c @@ -29,7 +29,7 @@ #include #define MO_LOG_TAG "air720uh_ifconfig" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef AIR720UH_USING_IFCONFIG_OPS @@ -55,12 +55,12 @@ os_err_t air720uh_ifconfig(mo_object_t *self) } os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t ber = 0; if (air720uh_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; } os_kprintf("\r\nLIST AT MODULE INFORMATIONS\r\n"); @@ -88,7 +88,7 @@ os_err_t air720uh_ifconfig(mo_object_t *self) os_err_t air720uh_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t len = -1; + os_int8_t len = -1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; diff --git a/components/molink/module/air720uh/source/air720uh_netconn.c b/components/molink/module/air720uh/source/air720uh_netconn.c index ee63369d..f6cdbfce 100644 --- a/components/molink/module/air720uh/source/air720uh_netconn.c +++ b/components/molink/module/air720uh/source/air720uh_netconn.c @@ -29,12 +29,11 @@ #include #define MO_LOG_TAG "air720uh_netconn" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define SEND_DATA_MAX_SIZE (1460) - #define AIR720_NETCONN_MQ_NAME "air720uh_nc_mq" #ifndef AIR720_NETCONN_MQ_MSG_SIZE @@ -42,23 +41,23 @@ #endif #ifndef AIR720_NETCONN_MQ_MSG_MAX -#define AIR720_NETCONN_MQ_MSG_MAX (5) +#define AIR720_NETCONN_MQ_MSG_MAX (5) #endif #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) -#define AIR720UH_EVENT_SEND_OK (1L << 0) -#define AIR720UH_EVENT_SEND_FAIL (1L << 1) -#define AIR720UH_EVENT_RECV_OK (1L << 2) -#define AIR720UH_EVENT_CONN_OK (1L << 3) -#define AIR720UH_EVENT_CONN_FAIL (1L << 4) -#define AIR720UH_EVENT_CLOSE_OK (1L << 5) +#define AIR720UH_EVENT_SEND_OK (1L << 0) +#define AIR720UH_EVENT_SEND_FAIL (1L << 1) +#define AIR720UH_EVENT_RECV_OK (1L << 2) +#define AIR720UH_EVENT_CONN_OK (1L << 3) +#define AIR720UH_EVENT_CONN_FAIL (1L << 4) +#define AIR720UH_EVENT_CLOSE_OK (1L << 5) #define AIR720UH_EVENT_CLOSE_FAIL (1L << 6) -#define AIR720UH_EVENT_DOMAIN_OK (1L << 7) -#define AIR720UH_EVENT_LINK_OK (1L << 8) -#define AIR720UH_EVENT_LINK_FAIL (1L << 9) +#define AIR720UH_EVENT_DOMAIN_OK (1L << 7) +#define AIR720UH_EVENT_LINK_OK (1L << 8) +#define AIR720UH_EVENT_LINK_FAIL (1L << 9) -#define AIR720UH_MULTI_CONN_ENABLE (1) +#define AIR720UH_MULTI_CONN_ENABLE (1) #define AIR720UH_MULTI_CONN_DISABLE (0) #ifdef AIR720UH_USING_NETCONN_OPS @@ -99,7 +98,7 @@ static mo_netconn_t *air720uh_get_netconn_by_id(mo_object_t *module, os_int32_t ERROR("%s INVALID connet_id:[%d]!", __func__, connect_id); return OS_NULL; } - + mo_air720uh_t *air720uh = os_container_of(module, mo_air720uh_t, parent); return &air720uh->netconn[connect_id]; @@ -129,9 +128,7 @@ mo_netconn_t *air720uh_netconn_create(mo_object_t *module, mo_netconn_type_t typ return OS_NULL; } - netconn->mq = os_mq_create(AIR720_NETCONN_MQ_NAME, - AIR720_NETCONN_MQ_MSG_SIZE, - AIR720_NETCONN_MQ_MSG_MAX); + netconn->mq = os_mq_create(AIR720_NETCONN_MQ_NAME, AIR720_NETCONN_MQ_MSG_SIZE, AIR720_NETCONN_MQ_MSG_MAX); if (OS_NULL == netconn->mq) { ERROR("%s data queue create failed, no enough memory.", module->name); @@ -154,7 +151,10 @@ static os_err_t air720uh_netconn_close(mo_object_t *module, mo_netconn_t *netcon at_parser_t *parser; char at_cmd[20] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .line_num = 1, .timeout = 10 * AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, + .buff_size = sizeof(resp_buff), + .line_num = 1, + .timeout = 10 * AT_RESP_TIMEOUT_DEF}; os_err_t result = OS_ERROR; event = SET_EVENT(netconn->connect_id, AIR720UH_EVENT_CLOSE_OK | AIR720UH_EVENT_CLOSE_FAIL); @@ -162,7 +162,7 @@ static os_err_t air720uh_netconn_close(mo_object_t *module, mo_netconn_t *netcon os_event_recv(&air720uh->netconn_evt, event, OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, OS_NO_WAIT, OS_NULL); parser = &module->parser; - sprintf(at_cmd,"AT+CIPCLOSE=%d\r\n", netconn->connect_id); + sprintf(at_cmd, "AT+CIPCLOSE=%d\r\n", netconn->connect_id); result = at_parser_send(parser, at_cmd, 15); if (result < 0) { @@ -239,9 +239,7 @@ os_err_t air720uh_netconn_gethostbyname(mo_object_t *self, const char *domain_na at_parser_t *parser = &self->parser; char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 20 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; mo_air720uh_t *air720uh = os_container_of(self, mo_air720uh_t, parent); @@ -279,9 +277,7 @@ os_err_t air720uh_check_link_status(mo_object_t *module, mo_netconn_t *netconn) os_err_t result; os_int32_t mode; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; mo_air720uh_t *air720uh = os_container_of(module, mo_air720uh_t, parent); @@ -371,23 +367,15 @@ os_err_t air720uh_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip { #ifdef AIR720UH_USING_TCP case NETCONN_TYPE_TCP: - result = at_parser_exec_cmd(parser, - &resp, - "AT+CIPSTART=%d,\"TCP\",\"%s\",%d", - netconn->connect_id, - remote_ip, - port); + result = + at_parser_exec_cmd(parser, &resp, "AT+CIPSTART=%d,\"TCP\",\"%s\",%d", netconn->connect_id, remote_ip, port); break; #endif #ifdef AIR720UH_USING_UDP case NETCONN_TYPE_UDP: - result = at_parser_exec_cmd(parser, - &resp, - "AT+CIPSTART=%d,\"UDP\",\"%s\",%d", - netconn->connect_id, - remote_ip, - port); + result = + at_parser_exec_cmd(parser, &resp, "AT+CIPSTART=%d,\"UDP\",\"%s\",%d", netconn->connect_id, remote_ip, port); break; #endif @@ -462,9 +450,7 @@ os_size_t air720uh_netconn_send(mo_object_t *module, mo_netconn_t *netconn, cons char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 5 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; at_parser_set_end_mark(parser, ">", 1); @@ -476,7 +462,7 @@ os_size_t air720uh_netconn_send(mo_object_t *module, mo_netconn_t *netconn, cons result = OS_ERROR; goto __exit; } - + if (size - sent_size < SEND_DATA_MAX_SIZE) { curr_size = size - sent_size; diff --git a/components/molink/module/air720uh/source/air720uh_netserv.c b/components/molink/module/air720uh/source/air720uh_netserv.c index fec8f215..4af90795 100644 --- a/components/molink/module/air720uh/source/air720uh_netserv.c +++ b/components/molink/module/air720uh/source/air720uh_netserv.c @@ -32,7 +32,7 @@ #endif /* MOLINK_USING_IP */ #define MO_LOG_TAG "air720uh_netserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef AIR720UH_USING_NETSERV_OPS diff --git a/components/molink/module/air720uh/source/air720uh_ping.c b/components/molink/module/air720uh/source/air720uh_ping.c index de498c6e..4317d7c6 100644 --- a/components/molink/module/air720uh/source/air720uh_ping.c +++ b/components/molink/module/air720uh/source/air720uh_ping.c @@ -24,7 +24,7 @@ #include "air720uh_ping.h" #define MO_LOG_TAG "air720uh_ping" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define AIR720UH_MIN_PING_PKG_LEN (0) @@ -34,13 +34,14 @@ #ifdef AIR720UH_USING_PING_OPS -os_err_t air720uh_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) +os_err_t +air720uh_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - os_int16_t req_time = -1; - os_int16_t replyid = -1; - os_int16_t ttl = -1; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; + os_int16_t req_time = -1; + os_int16_t replyid = -1; + os_int16_t ttl = -1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -53,10 +54,10 @@ os_err_t air720uh_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ if (len > AIR720UH_MAX_PING_PKG_LEN) { ERROR("%s ping: ping package len[%d] is out of rang[%d, %d].", - self->name, - len, - AIR720UH_MIN_PING_PKG_LEN, - AIR720UH_MAX_PING_PKG_LEN); + self->name, + len, + AIR720UH_MIN_PING_PKG_LEN, + AIR720UH_MAX_PING_PKG_LEN); return OS_ERROR; } @@ -65,10 +66,10 @@ os_err_t air720uh_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ if ((timeout < AIR720UH_MIN_PING_TIMEOUT) || (timeout > AIR720UH_MAX_PING_TIMEOUT)) { ERROR("%s ping: user set ping timeout value %ums is out of rang[%dms, %dms].", - self->name, - timeout * 100, - AIR720UH_MIN_PING_TIMEOUT * 100, - AIR720UH_MAX_PING_TIMEOUT * 100); + self->name, + timeout * 100, + AIR720UH_MIN_PING_TIMEOUT * 100, + AIR720UH_MAX_PING_TIMEOUT * 100); return OS_ERROR; } @@ -76,10 +77,10 @@ os_err_t air720uh_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ char resp_buff[256] = {0}; /* Need to wait for 3 lines response msg */ - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .line_num = 2, - .timeout =(5 + timeout / 10) * OS_TICK_PER_SECOND}; + at_resp_t at_resp = {.buff = resp_buff, + .buff_size = sizeof(resp_buff), + .line_num = 2, + .timeout = (5 + timeout / 10) * OS_TICK_PER_SECOND}; /* Exec AT+CIPPING="www.baidu.com",4,64,50; def ping timeout: +CIPPING: 1,39.156.66.14,50,0 */ /* Success: +CIPPING: 1,39.156.66.14,84,52 */ @@ -90,7 +91,8 @@ os_err_t air720uh_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ goto __exit; } - if (at_resp_get_data_by_kw(&at_resp, "+CIPPING", "+CIPPING: %d,%[^,],%d,%d", &replyid, ipaddr, &req_time, &ttl) <= 0) + if (at_resp_get_data_by_kw(&at_resp, "+CIPPING", "+CIPPING: %d,%[^,],%d,%d", &replyid, ipaddr, &req_time, &ttl) <= + 0) { ERROR("%s ping %s fail: check network status and try to set a longer timeout.", self->name, host); result = OS_ERROR; @@ -113,8 +115,8 @@ os_err_t air720uh_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ { inet_aton(ipaddr, &(resp->ip_addr)); resp->data_len = len; - resp->ttl = ttl; - resp->time = (req_time * 100); + resp->ttl = ttl; + resp->time = (req_time * 100); } __exit: diff --git a/components/molink/module/air723ug/include/air723ug.h b/components/molink/module/air723ug/include/air723ug.h index 716b3311..8d865aee 100644 --- a/components/molink/module/air723ug/include/air723ug.h +++ b/components/molink/module/air723ug/include/air723ug.h @@ -72,16 +72,16 @@ typedef struct mo_air723ug { mo_object_t parent; #ifdef AIR723UG_USING_NETCONN_OPS - mo_netconn_t netconn[AIR723UG_NETCONN_NUM]; + mo_netconn_t netconn[AIR723UG_NETCONN_NUM]; - os_event_t netconn_evt; - os_mutex_t netconn_lock; - void *netconn_data; + os_event_t netconn_evt; + os_mutex_t netconn_lock; + void *netconn_data; #endif /* AIR723UG_USING_NETCONN_OPS */ } mo_air723ug_t; mo_object_t *module_air723ug_create(const char *name, void *parser_config); -os_err_t module_air723ug_destroy(mo_object_t *self); +os_err_t module_air723ug_destroy(mo_object_t *self); #endif /* MOLINK_USING_AIR723UG */ diff --git a/components/molink/module/air723ug/include/air723ug_netconn.h b/components/molink/module/air723ug/include/air723ug_netconn.h index aeeecbc5..b0b4ab5c 100644 --- a/components/molink/module/air723ug/include/air723ug_netconn.h +++ b/components/molink/module/air723ug/include/air723ug_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef AIR723UG_USING_NETCONN_OPS -os_err_t air723ug_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t air723ug_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *air723ug_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t air723ug_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t air723ug_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t air723ug_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t air723ug_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t air723ug_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t air723ug_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef AIR723UG_USING_DNS -os_err_t air723ug_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t air723ug_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* AIR723UG_USING_NETCONN_OPS */ diff --git a/components/molink/module/air723ug/include/air723ug_netserv.h b/components/molink/module/air723ug/include/air723ug_netserv.h index b7c9e88c..f714977e 100644 --- a/components/molink/module/air723ug/include/air723ug_netserv.h +++ b/components/molink/module/air723ug/include/air723ug_netserv.h @@ -39,7 +39,7 @@ os_err_t air723ug_get_reg(mo_object_t *self, eps_reg_info_t *info); os_err_t air723ug_set_cgact(mo_object_t *self, os_uint8_t cid, os_uint8_t act_stat); os_err_t air723ug_get_cgact(mo_object_t *self, os_uint8_t *cid, os_uint8_t *act_stat); os_err_t air723ug_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber); -os_err_t air723ug_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info); +os_err_t air723ug_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info); #endif /* AIR723UG_USING_NETSERV_OPS */ diff --git a/components/molink/module/air723ug/include/air723ug_ping.h b/components/molink/module/air723ug/include/air723ug_ping.h index e0158b36..4fea522d 100644 --- a/components/molink/module/air723ug/include/air723ug_ping.h +++ b/components/molink/module/air723ug/include/air723ug_ping.h @@ -31,7 +31,8 @@ extern "C" { #ifdef AIR723UG_USING_PING_OPS -os_err_t air723ug_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); +os_err_t +air723ug_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); #endif /* AIR723UG_USING_PING_OPS */ diff --git a/components/molink/module/air723ug/source/air723ug.c b/components/molink/module/air723ug/source/air723ug.c index 5f451966..7624e687 100644 --- a/components/molink/module/air723ug/source/air723ug.c +++ b/components/molink/module/air723ug/source/air723ug.c @@ -28,7 +28,7 @@ #include #define MO_LOG_TAG "air723ug" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_AIR723UG @@ -37,39 +37,39 @@ #ifdef AIR723UG_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = air723ug_at_test, - .get_imei = air723ug_get_imei, - .get_imsi = air723ug_get_imsi, - .get_iccid = air723ug_get_iccid, - .get_cfun = air723ug_get_cfun, - .set_cfun = air723ug_set_cfun, + .at_test = air723ug_at_test, + .get_imei = air723ug_get_imei, + .get_imsi = air723ug_get_imsi, + .get_iccid = air723ug_get_iccid, + .get_cfun = air723ug_get_cfun, + .set_cfun = air723ug_set_cfun, .get_firmware_version = air723ug_get_firmware_version, }; #endif /* AIR723UG_USING_GENERAL_OPS */ #ifdef AIR723UG_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = air723ug_set_attach, - .get_attach = air723ug_get_attach, - .set_reg = air723ug_set_reg, - .get_reg = air723ug_get_reg, - .set_cgact = air723ug_set_cgact, - .get_cgact = air723ug_get_cgact, - .get_csq = air723ug_get_csq, - .get_cell_info = air723ug_get_cell_info, + .set_attach = air723ug_set_attach, + .get_attach = air723ug_get_attach, + .set_reg = air723ug_set_reg, + .get_reg = air723ug_get_reg, + .set_cgact = air723ug_set_cgact, + .get_cgact = air723ug_get_cgact, + .get_csq = air723ug_get_csq, + .get_cell_info = air723ug_get_cell_info, }; #endif /* AIR723UG_USING_NETSERV_OPS */ #ifdef AIR723UG_USING_PING_OPS static const struct mo_ping_ops gs_ping_ops = { - .ping = air723ug_ping, + .ping = air723ug_ping, }; #endif /* AIR723UG_USING_PING_OPS */ #ifdef AIR723UG_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = air723ug_ifconfig, - .get_ipaddr = air723ug_get_ipaddr, + .ifconfig = air723ug_ifconfig, + .get_ipaddr = air723ug_get_ipaddr, }; #endif /* AIR723UG_USING_IFCONFIG_OPS */ @@ -77,14 +77,14 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void air723ug_netconn_init(mo_air723ug_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = air723ug_netconn_create, - .destroy = air723ug_netconn_destroy, + .create = air723ug_netconn_create, + .destroy = air723ug_netconn_destroy, #ifdef AIR723UG_USING_DNS - .gethostbyname = air723ug_netconn_gethostbyname, + .gethostbyname = air723ug_netconn_gethostbyname, #endif - .connect = air723ug_netconn_connect, - .send = air723ug_netconn_send, - .get_info = air723ug_netconn_get_info, + .connect = air723ug_netconn_connect, + .send = air723ug_netconn_send, + .get_info = air723ug_netconn_get_info, }; #endif /* AIR723UG_USING_NETCONN_OPS */ @@ -94,7 +94,7 @@ void air723ug_poweron_sequence(void) os_pin_mode(GET_PIN(A, 4), PIN_MODE_OUTPUT); os_pin_write(GET_PIN(A, 4), PIN_HIGH); os_pin_write(GET_PIN(A, 3), PIN_HIGH); - os_task_msleep( 500 ); + os_task_msleep(500); os_pin_write(GET_PIN(A, 3), PIN_LOW); INFO("%s Executed power on process.", __func__); @@ -124,9 +124,7 @@ static os_err_t air723ug_at_init(mo_object_t *self) char resp_buff[32] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; return at_parser_exec_cmd(parser, &resp, "ATE0"); } @@ -228,14 +226,14 @@ int air723ug_auto_create(void) return OS_ERROR; } - uart_config.baud_rate = AIR723UG_DEVICE_RATE; + uart_config.baud_rate = AIR723UG_DEVICE_RATE; // air723ug_poweron_sequence(); INFO("Auto create %s module object with [%s]:[%d]bps", AIR723UG_NAME, AIR723UG_DEVICE_NAME, AIR723UG_DEVICE_RATE); os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = AIR723UG_NAME, + mo_parser_config_t parser_config = {.parser_name = AIR723UG_NAME, .parser_device = device, .recv_buff_len = AIR723UG_RECV_BUFF_LEN}; @@ -247,7 +245,10 @@ int air723ug_auto_create(void) return OS_ERROR; } - INFO("Auto create %s module object success [%s]:[%d]bps!", AIR723UG_NAME, AIR723UG_DEVICE_NAME, AIR723UG_DEVICE_RATE); + INFO("Auto create %s module object success [%s]:[%d]bps!", + AIR723UG_NAME, + AIR723UG_DEVICE_NAME, + AIR723UG_DEVICE_RATE); return OS_EOK; } OS_CMPOENT_INIT(air723ug_auto_create, OS_INIT_SUBLEVEL_MIDDLE); diff --git a/components/molink/module/air723ug/source/air723ug_general.c b/components/molink/module/air723ug/source/air723ug_general.c index 482f788b..8898ef19 100644 --- a/components/molink/module/air723ug/source/air723ug_general.c +++ b/components/molink/module/air723ug/source/air723ug_general.c @@ -26,7 +26,7 @@ #include #define MO_LOG_TAG "air723ug_general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef AIR723UG_USING_GENERAL_OPS @@ -169,9 +169,7 @@ os_err_t air723ug_get_firmware_version(mo_object_t *self, mo_firmware_version_t char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+VER"); if (result != OS_EOK) @@ -186,7 +184,7 @@ os_err_t air723ug_get_firmware_version(mo_object_t *self, mo_firmware_version_t } const char *source_line = at_resp_get_line(&resp, 1); - os_size_t line_length = strlen(source_line); + os_size_t line_length = strlen(source_line); /* TODO test return line or set to dynamic dump */ char **dest_line = &version->ver_info[0]; diff --git a/components/molink/module/air723ug/source/air723ug_ifconfig.c b/components/molink/module/air723ug/source/air723ug_ifconfig.c index d65d3c3d..973251a6 100644 --- a/components/molink/module/air723ug/source/air723ug_ifconfig.c +++ b/components/molink/module/air723ug/source/air723ug_ifconfig.c @@ -29,7 +29,7 @@ #include #define MO_LOG_TAG "air723ug_ifconfig" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef AIR723UG_USING_IFCONFIG_OPS @@ -55,12 +55,12 @@ os_err_t air723ug_ifconfig(mo_object_t *self) } os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t ber = 0; if (air723ug_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; } os_kprintf("\r\nLIST AT MODULE INFORMATIONS\r\n"); @@ -88,7 +88,7 @@ os_err_t air723ug_ifconfig(mo_object_t *self) os_err_t air723ug_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t len = -1; + os_int8_t len = -1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; diff --git a/components/molink/module/air723ug/source/air723ug_netconn.c b/components/molink/module/air723ug/source/air723ug_netconn.c index b8817d14..4b28936c 100644 --- a/components/molink/module/air723ug/source/air723ug_netconn.c +++ b/components/molink/module/air723ug/source/air723ug_netconn.c @@ -29,12 +29,11 @@ #include #define MO_LOG_TAG "air723ug_netconn" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define SEND_DATA_MAX_SIZE (1460) - #define AIR723_NETCONN_MQ_NAME "air723_nc_mq" #ifndef AIR723_NETCONN_MQ_MSG_SIZE @@ -42,23 +41,23 @@ #endif #ifndef AIR723_NETCONN_MQ_MSG_MAX -#define AIR723_NETCONN_MQ_MSG_MAX (5) +#define AIR723_NETCONN_MQ_MSG_MAX (5) #endif #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) -#define AIR723UG_EVENT_SEND_OK (1L << 0) -#define AIR723UG_EVENT_SEND_FAIL (1L << 1) -#define AIR723UG_EVENT_RECV_OK (1L << 2) -#define AIR723UG_EVENT_CONN_OK (1L << 3) -#define AIR723UG_EVENT_CONN_FAIL (1L << 4) -#define AIR723UG_EVENT_CLOSE_OK (1L << 5) +#define AIR723UG_EVENT_SEND_OK (1L << 0) +#define AIR723UG_EVENT_SEND_FAIL (1L << 1) +#define AIR723UG_EVENT_RECV_OK (1L << 2) +#define AIR723UG_EVENT_CONN_OK (1L << 3) +#define AIR723UG_EVENT_CONN_FAIL (1L << 4) +#define AIR723UG_EVENT_CLOSE_OK (1L << 5) #define AIR723UG_EVENT_CLOSE_FAIL (1L << 6) -#define AIR723UG_EVENT_DOMAIN_OK (1L << 7) -#define AIR723UG_EVENT_LINK_OK (1L << 8) -#define AIR723UG_EVENT_LINK_FAIL (1L << 9) +#define AIR723UG_EVENT_DOMAIN_OK (1L << 7) +#define AIR723UG_EVENT_LINK_OK (1L << 8) +#define AIR723UG_EVENT_LINK_FAIL (1L << 9) -#define AIR723UG_MULTI_CONN_ENABLE (1) +#define AIR723UG_MULTI_CONN_ENABLE (1) #define AIR723UG_MULTI_CONN_DISABLE (0) #ifdef AIR723UG_USING_NETCONN_OPS @@ -129,9 +128,7 @@ mo_netconn_t *air723ug_netconn_create(mo_object_t *module, mo_netconn_type_t typ return OS_NULL; } - netconn->mq = os_mq_create(AIR723_NETCONN_MQ_NAME, - AIR723_NETCONN_MQ_MSG_SIZE, - AIR723_NETCONN_MQ_MSG_MAX); + netconn->mq = os_mq_create(AIR723_NETCONN_MQ_NAME, AIR723_NETCONN_MQ_MSG_SIZE, AIR723_NETCONN_MQ_MSG_MAX); if (OS_NULL == netconn->mq) { ERROR("%s data queue create failed, no enough memory.", module->name); @@ -154,7 +151,10 @@ static os_err_t air723ug_netconn_close(mo_object_t *module, mo_netconn_t *netcon at_parser_t *parser; char at_cmd[20] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .line_num = 1, .timeout = 10 * AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, + .buff_size = sizeof(resp_buff), + .line_num = 1, + .timeout = 10 * AT_RESP_TIMEOUT_DEF}; os_err_t result = OS_ERROR; event = SET_EVENT(netconn->connect_id, AIR723UG_EVENT_CLOSE_OK | AIR723UG_EVENT_CLOSE_FAIL); @@ -162,7 +162,7 @@ static os_err_t air723ug_netconn_close(mo_object_t *module, mo_netconn_t *netcon os_event_recv(&air723ug->netconn_evt, event, OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, OS_NO_WAIT, OS_NULL); parser = &module->parser; - sprintf(at_cmd,"AT+CIPCLOSE=%d\r\n", netconn->connect_id); + sprintf(at_cmd, "AT+CIPCLOSE=%d\r\n", netconn->connect_id); result = at_parser_send(parser, at_cmd, 15); if (result < 0) { @@ -239,9 +239,7 @@ os_err_t air723ug_netconn_gethostbyname(mo_object_t *self, const char *domain_na at_parser_t *parser = &self->parser; char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 20 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; mo_air723ug_t *air723ug = os_container_of(self, mo_air723ug_t, parent); @@ -279,9 +277,7 @@ os_err_t air723ug_check_link_status(mo_object_t *module, mo_netconn_t *netconn) os_err_t result; os_int32_t mode; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; mo_air723ug_t *air723ug = os_container_of(module, mo_air723ug_t, parent); @@ -371,23 +367,15 @@ os_err_t air723ug_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip { #ifdef AIR723UG_USING_TCP case NETCONN_TYPE_TCP: - result = at_parser_exec_cmd(parser, - &resp, - "AT+CIPSTART=%d,\"TCP\",\"%s\",%d", - netconn->connect_id, - remote_ip, - port); + result = + at_parser_exec_cmd(parser, &resp, "AT+CIPSTART=%d,\"TCP\",\"%s\",%d", netconn->connect_id, remote_ip, port); break; #endif #ifdef AIR723UG_USING_UDP case NETCONN_TYPE_UDP: - result = at_parser_exec_cmd(parser, - &resp, - "AT+CIPSTART=%d,\"UDP\",\"%s\",%d", - netconn->connect_id, - remote_ip, - port); + result = + at_parser_exec_cmd(parser, &resp, "AT+CIPSTART=%d,\"UDP\",\"%s\",%d", netconn->connect_id, remote_ip, port); break; #endif @@ -462,9 +450,7 @@ os_size_t air723ug_netconn_send(mo_object_t *module, mo_netconn_t *netconn, cons char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 5 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; at_parser_set_end_mark(parser, ">", 1); diff --git a/components/molink/module/air723ug/source/air723ug_netserv.c b/components/molink/module/air723ug/source/air723ug_netserv.c index 2d841fd8..2165b5e4 100644 --- a/components/molink/module/air723ug/source/air723ug_netserv.c +++ b/components/molink/module/air723ug/source/air723ug_netserv.c @@ -32,7 +32,7 @@ #endif /* MOLINK_USING_IP */ #define MO_LOG_TAG "air723ug_netserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef AIR723UG_USING_NETSERV_OPS @@ -170,151 +170,154 @@ os_err_t air723ug_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber) return OS_EOK; } -#define GET_AIR723UG_RSSI(rxlev) (0 - (63 - rxlev + 48)) -#define AIR723UG_MODULE_NET_TYPE 5 - -os_err_t air723ug_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info) -{ - os_err_t ret = OS_EOK; - os_size_t i = 0; - cell_info_t *cell_info = OS_NULL; - char *temp_buff = OS_NULL; - os_uint32_t cell_num = 0; - os_uint32_t frequency = 0; - os_uint32_t rsrp = 0; - os_uint32_t rsrq = 0; - os_uint32_t rxlev = 0; - os_uint32_t pcid = 0; - char imsi[20]; - char earfcn[10]; - os_uint32_t roming_flag; - os_uint32_t bandinfo; - char bandwidth[20]; - at_parser_t *parser = &self->parser; - - if (parser == OS_NULL) - { - ERROR("AIR723UG ping: at parser is NULL."); - return OS_ERROR; - } - if(!onepos_cell_info) - { - ERROR("input param is error!"); - return OS_ERROR; - } - - at_resp_t resp = {.buff = os_calloc(1, 1024), - .buff_size = 1024, - .timeout = 50 * OS_TICK_PER_SECOND - }; - - if (OS_NULL == resp.buff) - { - ERROR("Calloc air723ug cell info response memory failed!"); - ret = OS_ENOMEM; - goto __exit; - } - - /* neighbor cell */ - if (at_parser_exec_cmd(parser, &resp, "AT+CCED=0,2") < 0) - { - ret = OS_ERROR; - ERROR("AT cmd exec fail: AT+CCED=0,2\n"); - goto __exit; - } - DEBUG("resp->line_counts : %d\r\n", resp.line_counts); - - cell_info = os_calloc((resp.line_counts), sizeof(cell_info_t)); - ERROR("resp.line_counts =%d",resp.line_counts); - if(NULL == cell_info) - { - ERROR("malloc cell_info is null"); - ret = OS_ENOMEM; - return ret; - } - - INFO(" MCC MNC CID LAC RSSI\n"); - INFO(" ------------ ------------ ------------ ------------ ----\n"); - - for (i = 1; i < resp.line_counts; i++) - { - temp_buff = (char*)at_resp_get_line(&resp, i); - if(strlen(temp_buff) > 25) { - sscanf(temp_buff, - " +CCED:LTE neighbor cell:%u,%u,%u,%u,%u,%u,%u,%u,%u", - &cell_info[cell_num].mcc, - &cell_info[cell_num].mnc, - &frequency, - &cell_info[cell_num].cid, - &rsrp, - &rsrq, - &cell_info[cell_num].lac, - &rxlev, - &pcid); - - cell_info[cell_num].ss = GET_AIR723UG_RSSI(rxlev); - if(cell_info[cell_num].mcc) - { - INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", - cell_info[cell_num].mcc, cell_info[cell_num].mnc, cell_info[cell_num].cid, - cell_info[cell_num].lac, cell_info[cell_num].ss); - cell_num ++; - } - } - } - /* main cell */ - if (at_parser_exec_cmd(parser, &resp, "AT+CCED=0,1") < 0) - { - ret = OS_ERROR; - os_free(cell_info); - ERROR("AT cmd exec fail: AT+CCED=0,1\n"); - goto __exit; - } - DEBUG("resp->line_counts : %d\r\n", &resp.line_counts); - - temp_buff = (char*)at_resp_get_line(&resp, 1); - if(strlen(temp_buff) > 25) - { - sscanf(temp_buff, - "+CCED:LTE current cell:%u,%u,%[^,],%u,%u,%[^,],%*[^,],%[^,],%u,%u,%u,%u,%u,%u", - &cell_info[cell_num].mcc, - &cell_info[cell_num].mnc, - imsi, - &roming_flag, +#define GET_AIR723UG_RSSI(rxlev) (0 - (63 - rxlev + 48)) +#define AIR723UG_MODULE_NET_TYPE 5 + +os_err_t air723ug_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info) +{ + os_err_t ret = OS_EOK; + os_size_t i = 0; + cell_info_t *cell_info = OS_NULL; + char *temp_buff = OS_NULL; + os_uint32_t cell_num = 0; + os_uint32_t frequency = 0; + os_uint32_t rsrp = 0; + os_uint32_t rsrq = 0; + os_uint32_t rxlev = 0; + os_uint32_t pcid = 0; + char imsi[20]; + char earfcn[10]; + os_uint32_t roming_flag; + os_uint32_t bandinfo; + char bandwidth[20]; + at_parser_t *parser = &self->parser; + + if (parser == OS_NULL) + { + ERROR("AIR723UG ping: at parser is NULL."); + return OS_ERROR; + } + if (!onepos_cell_info) + { + ERROR("input param is error!"); + return OS_ERROR; + } + + at_resp_t resp = {.buff = os_calloc(1, 1024), .buff_size = 1024, .timeout = 50 * OS_TICK_PER_SECOND}; + + if (OS_NULL == resp.buff) + { + ERROR("Calloc air723ug cell info response memory failed!"); + ret = OS_ENOMEM; + goto __exit; + } + + /* neighbor cell */ + if (at_parser_exec_cmd(parser, &resp, "AT+CCED=0,2") < 0) + { + ret = OS_ERROR; + ERROR("AT cmd exec fail: AT+CCED=0,2\n"); + goto __exit; + } + DEBUG("resp->line_counts : %d\r\n", resp.line_counts); + + cell_info = os_calloc((resp.line_counts), sizeof(cell_info_t)); + ERROR("resp.line_counts =%d", resp.line_counts); + if (NULL == cell_info) + { + ERROR("malloc cell_info is null"); + ret = OS_ENOMEM; + return ret; + } + + INFO(" MCC MNC CID LAC RSSI\n"); + INFO(" ------------ ------------ ------------ ------------ ----\n"); + + for (i = 1; i < resp.line_counts; i++) + { + temp_buff = (char *)at_resp_get_line(&resp, i); + if (strlen(temp_buff) > 25) + { + sscanf(temp_buff, + " +CCED:LTE neighbor cell:%u,%u,%u,%u,%u,%u,%u,%u,%u", + &cell_info[cell_num].mcc, + &cell_info[cell_num].mnc, + &frequency, + &cell_info[cell_num].cid, + &rsrp, + &rsrq, + &cell_info[cell_num].lac, + &rxlev, + &pcid); + + cell_info[cell_num].ss = GET_AIR723UG_RSSI(rxlev); + if (cell_info[cell_num].mcc) + { + INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", + cell_info[cell_num].mcc, + cell_info[cell_num].mnc, + cell_info[cell_num].cid, + cell_info[cell_num].lac, + cell_info[cell_num].ss); + cell_num++; + } + } + } + /* main cell */ + if (at_parser_exec_cmd(parser, &resp, "AT+CCED=0,1") < 0) + { + ret = OS_ERROR; + os_free(cell_info); + ERROR("AT cmd exec fail: AT+CCED=0,1\n"); + goto __exit; + } + DEBUG("resp->line_counts : %d\r\n", &resp.line_counts); + + temp_buff = (char *)at_resp_get_line(&resp, 1); + if (strlen(temp_buff) > 25) + { + sscanf(temp_buff, + "+CCED:LTE current cell:%u,%u,%[^,],%u,%u,%[^,],%*[^,],%[^,],%u,%u,%u,%u,%u,%u", + &cell_info[cell_num].mcc, + &cell_info[cell_num].mnc, + imsi, + &roming_flag, &bandinfo, - bandwidth, - earfcn, - &cell_info[cell_num].cid, - &rsrp, - &rsrq, - &cell_info[cell_num].lac, - &rxlev, - &pcid); - - cell_info[cell_num].ss = GET_AIR723UG_RSSI(rxlev); - INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", - cell_info[cell_num].mcc, cell_info[cell_num].mnc, cell_info[cell_num].cid, - cell_info[cell_num].lac, cell_info[cell_num].ss); - - } - else - { - cell_num --; - } - INFO(" ------------ ------------ ------------ ------------ ----\n"); - - onepos_cell_info->cell_num = ++cell_num; - onepos_cell_info->cell_info = cell_info; - onepos_cell_info->net_type = AIR723UG_MODULE_NET_TYPE; - -__exit: - - if (resp.buff != OS_NULL) - { - os_free(resp.buff); - } - - return ret; -} + bandwidth, + earfcn, + &cell_info[cell_num].cid, + &rsrp, + &rsrq, + &cell_info[cell_num].lac, + &rxlev, + &pcid); + + cell_info[cell_num].ss = GET_AIR723UG_RSSI(rxlev); + INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", + cell_info[cell_num].mcc, + cell_info[cell_num].mnc, + cell_info[cell_num].cid, + cell_info[cell_num].lac, + cell_info[cell_num].ss); + } + else + { + cell_num--; + } + INFO(" ------------ ------------ ------------ ------------ ----\n"); + + onepos_cell_info->cell_num = ++cell_num; + onepos_cell_info->cell_info = cell_info; + onepos_cell_info->net_type = AIR723UG_MODULE_NET_TYPE; + +__exit: + + if (resp.buff != OS_NULL) + { + os_free(resp.buff); + } + + return ret; +} #endif /* AIR723UG_USING_NETSERV_OPS */ diff --git a/components/molink/module/air723ug/source/air723ug_ping.c b/components/molink/module/air723ug/source/air723ug_ping.c index 7978dfda..82135851 100644 --- a/components/molink/module/air723ug/source/air723ug_ping.c +++ b/components/molink/module/air723ug/source/air723ug_ping.c @@ -24,7 +24,7 @@ #include "air723ug_ping.h" #define MO_LOG_TAG "air723ug_ping" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define AIR723UG_MIN_PING_PKG_LEN (0) @@ -34,13 +34,14 @@ #ifdef AIR723UG_USING_PING_OPS -os_err_t air723ug_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) +os_err_t +air723ug_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - os_int16_t req_time = -1; - os_int16_t replyid = -1; - os_int16_t ttl = -1; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; + os_int16_t req_time = -1; + os_int16_t replyid = -1; + os_int16_t ttl = -1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -53,10 +54,10 @@ os_err_t air723ug_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ if (len > AIR723UG_MAX_PING_PKG_LEN) { ERROR("%s ping: ping package len[%d] is out of rang[%d, %d].", - self->name, - len, - AIR723UG_MIN_PING_PKG_LEN, - AIR723UG_MAX_PING_PKG_LEN); + self->name, + len, + AIR723UG_MIN_PING_PKG_LEN, + AIR723UG_MAX_PING_PKG_LEN); return OS_ERROR; } @@ -65,10 +66,10 @@ os_err_t air723ug_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ if ((timeout < AIR723UG_MIN_PING_TIMEOUT) || (timeout > AIR723UG_MAX_PING_TIMEOUT)) { ERROR("%s ping: user set ping timeout value %ums is out of rang[%dms, %dms].", - self->name, - timeout * 100, - AIR723UG_MIN_PING_TIMEOUT * 100, - AIR723UG_MAX_PING_TIMEOUT * 100); + self->name, + timeout * 100, + AIR723UG_MIN_PING_TIMEOUT * 100, + AIR723UG_MAX_PING_TIMEOUT * 100); return OS_ERROR; } @@ -76,10 +77,10 @@ os_err_t air723ug_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ char resp_buff[256] = {0}; /* Need to wait for 3 lines response msg */ - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .line_num = 2, - .timeout =(5 + timeout / 10) * OS_TICK_PER_SECOND}; + at_resp_t at_resp = {.buff = resp_buff, + .buff_size = sizeof(resp_buff), + .line_num = 2, + .timeout = (5 + timeout / 10) * OS_TICK_PER_SECOND}; /* Exec AT+CIPPING="www.baidu.com",4,64,50; def ping timeout: +CIPPING: 1,39.156.66.14,50,0 */ /* Success: +CIPPING: 1,39.156.66.14,84,52 */ @@ -90,7 +91,8 @@ os_err_t air723ug_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ goto __exit; } - if (at_resp_get_data_by_kw(&at_resp, "+CIPPING", "+CIPPING: %d,%[^,],%d,%d", &replyid, ipaddr, &req_time, &ttl) <= 0) + if (at_resp_get_data_by_kw(&at_resp, "+CIPPING", "+CIPPING: %d,%[^,],%d,%d", &replyid, ipaddr, &req_time, &ttl) <= + 0) { ERROR("%s ping %s fail: check network status and try to set a longer timeout.", self->name, host); result = OS_ERROR; @@ -113,8 +115,8 @@ os_err_t air723ug_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ { inet_aton(ipaddr, &(resp->ip_addr)); resp->data_len = len; - resp->ttl = ttl; - resp->time = (req_time * 100); + resp->ttl = ttl; + resp->time = (req_time * 100); } __exit: diff --git a/components/molink/module/bc20/include/bc20.h b/components/molink/module/bc20/include/bc20.h index d1b682e7..581de18f 100644 --- a/components/molink/module/bc20/include/bc20.h +++ b/components/molink/module/bc20/include/bc20.h @@ -65,28 +65,28 @@ extern "C" { #endif #ifndef BC20_NETCONN_NUM -#define BC20_NETCONN_NUM (5) +#define BC20_NETCONN_NUM (5) #endif typedef struct mo_bc20 { - mo_object_t parent; + mo_object_t parent; #ifdef BC20_USING_NETCONN_OPS mo_netconn_t netconn[BC20_NETCONN_NUM]; - os_int32_t curr_connect; - os_event_t netconn_evt; - os_mutex_t netconn_lock; - void *netconn_data; + os_int32_t curr_connect; + os_event_t netconn_evt; + os_mutex_t netconn_lock; + void *netconn_data; #endif /* BC20_USING_NETCONN_OPS */ #ifdef BC20_USING_PING_OPS - char *ping_data; - os_event_t ping_evt; + char *ping_data; + os_event_t ping_evt; #endif /* BC20_USING_PING_OPS */ } mo_bc20_t; mo_object_t *module_bc20_create(const char *name, void *parser_config); -os_err_t module_bc20_destroy(mo_object_t *self); +os_err_t module_bc20_destroy(mo_object_t *self); #endif /* MOLINK_USING_BC20 */ diff --git a/components/molink/module/bc20/include/bc20_netconn.h b/components/molink/module/bc20/include/bc20_netconn.h index 5e1b7328..d71e534c 100644 --- a/components/molink/module/bc20/include/bc20_netconn.h +++ b/components/molink/module/bc20/include/bc20_netconn.h @@ -33,13 +33,13 @@ extern "C" { #ifdef BC20_USING_NETCONN_OPS mo_netconn_t *bc20_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t bc20_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t bc20_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t bc20_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t bc20_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t bc20_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t bc20_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef BC20_USING_DNS -os_err_t bc20_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr); +os_err_t bc20_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr); #endif -os_err_t bc20_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t bc20_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); #endif /* BC20_USING_NETCONN_OPS */ #ifdef __cplusplus diff --git a/components/molink/module/bc20/source/bc20.c b/components/molink/module/bc20/source/bc20.c index 9225de39..e1eeb36d 100644 --- a/components/molink/module/bc20/source/bc20.c +++ b/components/molink/module/bc20/source/bc20.c @@ -27,7 +27,7 @@ #include #define MO_LOG_TAG "bc20" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_BC20 @@ -38,12 +38,12 @@ extern void bc20_general_init(mo_bc20_t *module); static const struct mo_general_ops gs_general_ops = { - .at_test = bc20_at_test, - .get_imei = bc20_get_imei, - .get_imsi = bc20_get_imsi, - .get_iccid = bc20_get_iccid, - .get_cfun = bc20_get_cfun, - .set_cfun = bc20_set_cfun, + .at_test = bc20_at_test, + .get_imei = bc20_get_imei, + .get_imsi = bc20_get_imsi, + .get_iccid = bc20_get_iccid, + .get_cfun = bc20_get_cfun, + .set_cfun = bc20_set_cfun, }; #endif /* BC20_USING_GENERAL_OPS */ @@ -51,30 +51,30 @@ static const struct mo_general_ops gs_general_ops = { extern void bc20_netserv_init(mo_bc20_t *module); static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = bc20_set_attach, - .get_attach = bc20_get_attach, - .set_reg = bc20_set_reg, - .get_reg = bc20_get_reg, - .set_cgact = bc20_set_cgact, - .get_cgact = bc20_get_cgact, - .get_csq = bc20_get_csq, - .get_radio = bc20_get_radio, + .set_attach = bc20_set_attach, + .get_attach = bc20_get_attach, + .set_reg = bc20_set_reg, + .get_reg = bc20_get_reg, + .set_cgact = bc20_set_cgact, + .get_cgact = bc20_get_cgact, + .get_csq = bc20_get_csq, + .get_radio = bc20_get_radio, }; #endif /* BC20_USING_NETSERV_OPS */ #ifdef BC20_USING_PING_OPS extern void bc20_ping_init(mo_bc20_t *module); static const struct mo_ping_ops gs_ping_ops = { - .ping = bc20_ping, + .ping = bc20_ping, }; #endif /* BC20_USING_PING_OPS */ #ifdef BC20_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = bc20_ifconfig, - .get_ipaddr = bc20_get_ipaddr, - .set_dnsserver = bc20_set_dnsserver, - .get_dnsserver = bc20_get_dnsserver, + .ifconfig = bc20_ifconfig, + .get_ipaddr = bc20_get_ipaddr, + .set_dnsserver = bc20_set_dnsserver, + .get_dnsserver = bc20_get_dnsserver, }; #endif /* BC20_USING_IFCONFIG_OPS */ @@ -82,27 +82,25 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void bc20_netconn_init(mo_bc20_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = bc20_netconn_create, - .destroy = bc20_netconn_destroy, + .create = bc20_netconn_create, + .destroy = bc20_netconn_destroy, #ifdef BC20_USING_DNS - .gethostbyname = bc20_netconn_gethostbyname, + .gethostbyname = bc20_netconn_gethostbyname, #endif - .connect = bc20_netconn_connect, - .send = bc20_netconn_send, - .get_info = bc20_netconn_get_info, + .connect = bc20_netconn_connect, + .send = bc20_netconn_send, + .get_info = bc20_netconn_get_info, }; #endif /* BC20_USING_NETCONN_OPS */ static os_err_t bc20_at_init(mo_object_t *self) { at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = OS_TICK_PER_SECOND}; result = at_parser_connect(parser, BC20_RETRY_TIMES); if (result != OS_EOK) @@ -133,7 +131,7 @@ __exit: mo_object_t *module_bc20_create(const char *name, void *parser_config) { os_err_t result = OS_ERROR; - + mo_bc20_t *module = (mo_bc20_t *)os_calloc(1, sizeof(mo_bc20_t)); if (OS_NULL == module) { @@ -179,7 +177,7 @@ mo_object_t *module_bc20_create(const char *name, void *parser_config) os_event_init(&module->netconn_evt, "bc20_nc"); os_mutex_init(&module->netconn_lock, "bc20_nc", OS_TRUE); #endif /* BC20_USING_NETCONN_OPS */ - + __exit: if (OS_EOK != result) { @@ -190,7 +188,7 @@ __exit: os_mutex_deinit(&module->netconn_lock); } #endif /* BC20_USING_NETCONN_OPS */ - + #ifdef BC20_USING_PING_OPS if (OS_NULL != module->parent.ops_table[MODULE_OPS_PING]) { @@ -245,12 +243,12 @@ int bc20_auto_create(void) ERROR("Auto create failed, Can not find BC20 interface device %s!", BC20_DEVICE_NAME); return OS_ERROR; } - - uart_config.baud_rate = BC20_DEVICE_RATE; + + uart_config.baud_rate = BC20_DEVICE_RATE; os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = BC20_NAME, + mo_parser_config_t parser_config = {.parser_name = BC20_NAME, .parser_device = device, .recv_buff_len = BC20_RECV_BUFF_LEN}; diff --git a/components/molink/module/bc20/source/bc20_general.c b/components/molink/module/bc20/source/bc20_general.c index cde1ea62..23592af2 100644 --- a/components/molink/module/bc20/source/bc20_general.c +++ b/components/molink/module/bc20/source/bc20_general.c @@ -27,7 +27,7 @@ #include #define MO_LOG_TAG "bc20.general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef BC20_USING_GENERAL_OPS @@ -172,7 +172,7 @@ static void bc20_ip_indicator_urc(struct at_parser *parser, const char *data, os char ip_indicator_buf[AT_RESP_BUFF_SIZE_DEF] = {0}; sscanf(data, "+IP: %63s", ip_indicator_buf); - + INFO("%s IP indocator:[%s]", __func__, ip_indicator_buf); return; } @@ -185,13 +185,13 @@ static void bc20_cpin_indicator_urc(struct at_parser *parser, const char *data, char cpin_indicator_buf[AT_RESP_BUFF_SIZE_DEF] = {0}; sscanf(data, "+CPIN: %63s", cpin_indicator_buf); - + INFO("%s CPIN indocator:[%s]", __func__, cpin_indicator_buf); return; } static at_urc_t bc20_general_urc_table[] = { - {.prefix = "+IP:", .suffix = "\r\n", .func = bc20_ip_indicator_urc }, + {.prefix = "+IP:", .suffix = "\r\n", .func = bc20_ip_indicator_urc}, {.prefix = "+CPIN:", .suffix = "\r\n", .func = bc20_cpin_indicator_urc}, }; @@ -199,7 +199,8 @@ void bc20_general_init(mo_bc20_t *module) { /* Set general urc table */ at_parser_t *parser = &(module->parent.parser); - at_parser_set_urc_table(parser, bc20_general_urc_table, + at_parser_set_urc_table(parser, + bc20_general_urc_table, sizeof(bc20_general_urc_table) / sizeof(bc20_general_urc_table[0])); } diff --git a/components/molink/module/bc20/source/bc20_ifconfig.c b/components/molink/module/bc20/source/bc20_ifconfig.c index 37fa6d7e..b67aa56a 100644 --- a/components/molink/module/bc20/source/bc20_ifconfig.c +++ b/components/molink/module/bc20/source/bc20_ifconfig.c @@ -32,7 +32,7 @@ #ifdef BC20_USING_IFCONFIG_OPS #define MO_LOG_TAG "bc20.ifconfig" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define BC20_IFCONFIG_INVALID_DFT (-1) @@ -58,12 +58,12 @@ os_err_t bc20_ifconfig(mo_object_t *module) } os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t ber = 0; if (bc20_get_csq(module, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; } os_kprintf("\r\nLIST AT MODULE INFORMATION\r\n"); @@ -91,7 +91,7 @@ os_err_t bc20_ifconfig(mo_object_t *module) os_err_t bc20_set_dnsserver(mo_object_t *module, dns_server_t dns) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -118,14 +118,14 @@ os_err_t bc20_set_dnsserver(mo_object_t *module, dns_server_t dns) { result = at_parser_exec_cmd(parser, &resp, "AT+QIDNSCFG=1,\"%s\",\"%s\"", dns.primary_dns, dns.secondary_dns); } - + return result; } os_err_t bc20_get_dnsserver(mo_object_t *module, dns_server_t *dns) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; char primary_dns[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -143,13 +143,15 @@ os_err_t bc20_get_dnsserver(mo_object_t *module, dns_server_t *dns) char resp_buff[4 * AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = OS_TICK_PER_SECOND}; + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = OS_TICK_PER_SECOND}; result = at_parser_exec_cmd(parser, &at_resp, "AT+QIDNSCFG=1"); - if (at_resp_get_data_by_kw(&at_resp, "+QIDNSCFG:", "+QIDNSCFG: 1,%[^,],\"%[^\"]", primary_dns, dns->secondary_dns) <= 0) + if (at_resp_get_data_by_kw(&at_resp, + "+QIDNSCFG:", + "+QIDNSCFG: 1,%[^,],\"%[^\"]", + primary_dns, + dns->secondary_dns) <= 0) { ERROR("BC20 %s: get dns failed.", __FUNCTION__); result = OS_ERROR; @@ -167,8 +169,8 @@ __exit: os_err_t bc20_get_ipaddr(mo_object_t *module, char ip[]) { at_parser_t *parser = &module->parser; - os_int8_t ucid = BC20_IFCONFIG_INVALID_DFT; - os_int8_t len = BC20_IFCONFIG_INVALID_DFT; + os_int8_t ucid = BC20_IFCONFIG_INVALID_DFT; + os_int8_t len = BC20_IFCONFIG_INVALID_DFT; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -205,7 +207,7 @@ os_err_t bc20_get_ipaddr(mo_object_t *module, char ip[]) } __exit: - + return result; } diff --git a/components/molink/module/bc20/source/bc20_netconn.c b/components/molink/module/bc20/source/bc20_netconn.c index 725317bb..fc1d4dd0 100644 --- a/components/molink/module/bc20/source/bc20_netconn.c +++ b/components/molink/module/bc20/source/bc20_netconn.c @@ -29,18 +29,18 @@ #include #define MO_LOG_TAG "bc20.netconn" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define BC20_CONN_ID_NULL (-1) #define SEND_DATA_MAX_SIZE (1024) -#define BC20_NETCONN_MQ_NAME "bc20_nc_mq" +#define BC20_NETCONN_MQ_NAME "bc20_nc_mq" #ifndef BC20_NETCONN_MQ_MSG_SIZE #define BC20_NETCONN_MQ_MSG_SIZE (sizeof(mo_notconn_msg_t)) #endif /* BC20_NETCONN_MQ_MSG_SIZE */ #ifndef BC20_NETCONN_MQ_MSG_MAX -#define BC20_NETCONN_MQ_MSG_MAX (5) +#define BC20_NETCONN_MQ_MSG_MAX (5) #endif /* BC20_NETCONN_MQ_MSG_MAX */ #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) @@ -146,7 +146,7 @@ os_err_t bc20_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_bc20_t *bc20 = os_container_of(module, mo_bc20_t, parent); info->netconn_array = bc20->netconn; - info->netconn_nums = sizeof(bc20->netconn) / sizeof(bc20->netconn[0]); + info->netconn_nums = sizeof(bc20->netconn) / sizeof(bc20->netconn[0]); return OS_EOK; } @@ -165,9 +165,7 @@ mo_netconn_t *bc20_netconn_create(mo_object_t *module, mo_netconn_type_t type) return OS_NULL; } - netconn->mq = os_mq_create(BC20_NETCONN_MQ_NAME, - BC20_NETCONN_MQ_MSG_SIZE, - BC20_NETCONN_MQ_MSG_MAX); + netconn->mq = os_mq_create(BC20_NETCONN_MQ_NAME, BC20_NETCONN_MQ_MSG_SIZE, BC20_NETCONN_MQ_MSG_MAX); if (OS_NULL == netconn->mq) { ERROR("%s message queue create failed, no enough memory.", module->name); @@ -186,8 +184,8 @@ mo_netconn_t *bc20_netconn_create(mo_object_t *module, mo_netconn_type_t type) os_err_t bc20_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; - mo_bc20_t *bc20 = os_container_of(module, mo_bc20_t, parent); + os_err_t result = OS_ERROR; + mo_bc20_t *bc20 = os_container_of(module, mo_bc20_t, parent); bc20_lock(&bc20->netconn_lock); @@ -203,28 +201,28 @@ os_err_t bc20_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) case NETCONN_STAT_CONNECT: os_event_recv(&bc20->netconn_evt, - BC20_EVNET_CLOSE_OK, - OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, - OS_NO_WAIT, - OS_NULL); + BC20_EVNET_CLOSE_OK, + OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, + OS_NO_WAIT, + OS_NULL); result = at_parser_exec_cmd(parser, &resp, "AT+QICLOSE=%d", netconn->connect_id); if (result != OS_EOK) { ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + module->name, + (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); goto __exit; } /* get async close info */ result = os_event_recv(&bc20->netconn_evt, - BC20_EVNET_CLOSE_OK, - OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, - 4 * OS_TICK_PER_SECOND, - OS_NULL); + BC20_EVNET_CLOSE_OK, + OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, + 4 * OS_TICK_PER_SECOND, + OS_NULL); - if(OS_EOK != result) + if (OS_EOK != result) { ERROR("%s destroy netconn:%d failed", __func__, netconn->connect_id); goto __exit; @@ -243,13 +241,12 @@ os_err_t bc20_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn id %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = BC20_CONN_ID_NULL; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = BC20_CONN_ID_NULL; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); - __exit: bc20_unlock(&bc20->netconn_lock); return result; @@ -346,7 +343,7 @@ __exit: { ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); } @@ -360,11 +357,11 @@ __exit: os_size_t bc20_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t curr_size = 0; - os_uint32_t event = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t curr_size = 0; + os_uint32_t event = 0; mo_bc20_t *bc20 = os_container_of(module, mo_bc20_t, parent); @@ -374,9 +371,7 @@ os_size_t bc20_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const ch char resp_buff[2 * AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 10 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; at_parser_set_end_mark(parser, ">", 1); @@ -462,7 +457,7 @@ __exit: os_err_t bc20_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[2 * AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -515,9 +510,9 @@ static void urc_connect_func(struct at_parser *parser, const char *data, os_size mo_bc20_t *bc20 = os_container_of(module, mo_bc20_t, parent); os_int32_t connect_id = 0; - os_int32_t result = 0; + os_int32_t result = 0; - sscanf(data, "+QIOPEN: %d,%d", &connect_id , &result); + sscanf(data, "+QIOPEN: %d,%d", &connect_id, &result); if (0 == result) { @@ -595,7 +590,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; + os_int32_t data_size = 0; sscanf(data, "+QIURC: \"recv\",%d,%d", &connect_id, &data_size); @@ -612,13 +607,13 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t return; } - char *recv_buff = os_calloc(1, data_size); - char temp_buff[8] = {0}; + char *recv_buff = os_calloc(1, data_size); + char temp_buff[8] = {0}; if (recv_buff == OS_NULL) { /* read and clean the coming data */ ERROR("alloc recv buff %d bytes fail, no enough memory", data_size); - os_size_t temp_size = 0; + os_size_t temp_size = 0; while (temp_size < data_size) { if (data_size - temp_size > sizeof(temp_buff)) @@ -732,9 +727,9 @@ static void urc_qiurc_func(struct at_parser *parser, const char *data, os_size_t } static at_urc_t gs_urc_table[] = { - {.prefix = "SEND", .suffix = "\r\n", .func = urc_send_func}, + {.prefix = "SEND", .suffix = "\r\n", .func = urc_send_func}, {.prefix = "+QIOPEN:", .suffix = "\r\n", .func = urc_connect_func}, - {.prefix = "+QIURC:", .suffix = "\r\n", .func = urc_qiurc_func}, + {.prefix = "+QIURC:", .suffix = "\r\n", .func = urc_qiurc_func}, {.prefix = "CLOSE OK", .suffix = "\r\n", .func = urc_close_result_func}, }; diff --git a/components/molink/module/bc20/source/bc20_netserv.c b/components/molink/module/bc20/source/bc20_netserv.c index 6304366f..0db824d6 100644 --- a/components/molink/module/bc20/source/bc20_netserv.c +++ b/components/molink/module/bc20/source/bc20_netserv.c @@ -29,13 +29,13 @@ #include #define MO_LOG_TAG "bc20.netserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef BC20_USING_NETSERV_OPS -#define BC20_EARFCN_MAX (65535) -#define BC20_PCI_MAX (0x1F7) +#define BC20_EARFCN_MAX (65535) +#define BC20_PCI_MAX (0x1F7) os_err_t bc20_set_attach(mo_object_t *module, os_uint8_t attach_stat) { @@ -62,7 +62,7 @@ os_err_t bc20_get_attach(mo_object_t *module, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) { ERROR("Get %s module attach state failed", module->name); return OS_ERROR; @@ -178,7 +178,7 @@ os_err_t bc20_get_radio(mo_object_t *module, radio_info_t *radio_info) memset(radio_info, 0, sizeof(radio_info_t)); - int at_ret = 0; + int at_ret = 0; char resp_buff[4 * AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 3 * OS_TICK_PER_SECOND}; @@ -192,18 +192,20 @@ os_err_t bc20_get_radio(mo_object_t *module, radio_info_t *radio_info) /** * =0: * +QENG: 0,,,,,[],[],[],[], - * ,,[],[], + * ,,[],[], * [+QENG: 1,,,,,[…]] * SINR: Signal to Interference plus Noise Ratio * SNR : Signal Noise Ratio * */ - at_ret = at_resp_get_data_by_kw(&resp, "+QENG: 0", "+QENG: 0,%d,%*d,%*d,\"%[^\"]\",%*d,%d,%*d,%d,%*d,%*[^,],%d,%d,", - &radio_info->earfcn, - radio_info->cell_id, - &radio_info->rsrq, - &radio_info->snr, - &radio_info->ecl, - &radio_info->signal_power); + at_ret = at_resp_get_data_by_kw(&resp, + "+QENG: 0", + "+QENG: 0,%d,%*d,%*d,\"%[^\"]\",%*d,%d,%*d,%d,%*d,%*[^,],%d,%d,", + &radio_info->earfcn, + radio_info->cell_id, + &radio_info->rsrq, + &radio_info->snr, + &radio_info->ecl, + &radio_info->signal_power); if (0 >= at_ret) { ERROR("Get %s module signal power failed", module->name); diff --git a/components/molink/module/bc20/source/bc20_ping.c b/components/molink/module/bc20/source/bc20_ping.c index 1a6e6b2a..89caeee1 100644 --- a/components/molink/module/bc20/source/bc20_ping.c +++ b/components/molink/module/bc20/source/bc20_ping.c @@ -27,7 +27,7 @@ #include #define MO_LOG_TAG "bc20.ping" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef BC20_USING_PING_OPS @@ -39,21 +39,21 @@ #define BC20_PING_INVALID_DEF (-1) #define BC20_PING_BUFFER_SIZE (4 * AT_RESP_BUFF_SIZE_DEF) -#define BC20_EVENT_PING_OK (1L << 0) -#define BC20_EVENT_PING_FAIL (1L << 1) +#define BC20_EVENT_PING_OK (1L << 0) +#define BC20_EVENT_PING_FAIL (1L << 1) os_err_t bc20_ping(mo_object_t *module, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_int16_t ttl = BC20_PING_INVALID_DEF; - os_uint32_t timeout_s = timeout / 1000; - os_uint32_t req_time = 0; - os_uint32_t event = 0; - mo_bc20_t *bc20 = os_container_of(module, mo_bc20_t, parent); - - char ip_recv[IPADDR_MAX_STR_LEN + 1] = {0}; - char resp_buff[4 * AT_RESP_BUFF_SIZE_DEF] = {0}; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_int16_t ttl = BC20_PING_INVALID_DEF; + os_uint32_t timeout_s = timeout / 1000; + os_uint32_t req_time = 0; + os_uint32_t event = 0; + mo_bc20_t *bc20 = os_container_of(module, mo_bc20_t, parent); + + char ip_recv[IPADDR_MAX_STR_LEN + 1] = {0}; + char resp_buff[4 * AT_RESP_BUFF_SIZE_DEF] = {0}; char ping_result[BC20_PING_BUFFER_SIZE + 1] = {0}; memset(resp, 0, sizeof(ping_resp_t)); @@ -67,14 +67,18 @@ os_err_t bc20_ping(mo_object_t *module, const char *host, os_uint16_t len, os_ui if ((len < BC20_MIN_PING_PKG_LEN) || (len > BC20_MAX_PING_PKG_LEN)) { ERROR("BC20 ping: ping package len[%d] is out of rang[%d, %d].", - len, BC20_MIN_PING_PKG_LEN, BC20_MAX_PING_PKG_LEN); + len, + BC20_MIN_PING_PKG_LEN, + BC20_MAX_PING_PKG_LEN); return OS_ERROR; } if ((timeout_s < BC20_MIN_PING_TIMEOUT_SEC) || (timeout_s > BC20_MAX_PING_TIMEOUT_SEC)) { ERROR("BC20 ping: user set ping timeout_s value %u s is out of rang[%d, %d]s.", - timeout_s, BC20_MIN_PING_TIMEOUT_SEC, BC20_MAX_PING_TIMEOUT_SEC); + timeout_s, + BC20_MIN_PING_TIMEOUT_SEC, + BC20_MAX_PING_TIMEOUT_SEC); return OS_ERROR; } @@ -89,9 +93,9 @@ os_err_t bc20_ping(mo_object_t *module, const char *host, os_uint16_t len, os_ui * +QPING: [,,,,,,] * Because unable to synchronize time between board & module, 5 seconds reserved * **/ - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .timeout = (10 + timeout_s) * OS_TICK_PER_SECOND}; + .timeout = (10 + timeout_s) * OS_TICK_PER_SECOND}; os_event_clear(&bc20->ping_evt, BC20_EVENT_PING_OK | BC20_EVENT_PING_FAIL); @@ -103,9 +107,9 @@ os_err_t bc20_ping(mo_object_t *module, const char *host, os_uint16_t len, os_ui } result = os_event_recv(&bc20->ping_evt, - BC20_EVENT_PING_OK | BC20_EVENT_PING_FAIL, - OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, - at_resp.timeout, + BC20_EVENT_PING_OK | BC20_EVENT_PING_FAIL, + OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, + at_resp.timeout, &event); if (result != OS_EOK) { @@ -139,9 +143,9 @@ os_err_t bc20_ping(mo_object_t *module, const char *host, os_uint16_t len, os_ui { inet_aton(ip_recv, &(resp->ip_addr)); resp->data_len = len; - resp->ttl = ttl; - resp->time = req_time; - result = OS_EOK; + resp->ttl = ttl; + resp->time = req_time; + result = OS_EOK; } } @@ -159,12 +163,12 @@ static void urc_ping_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - os_err_t result = OS_EOK; - os_int32_t ret = 0; + os_err_t result = OS_EOK; + os_int32_t ret = 0; mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_bc20_t *bc20 = os_container_of(module, mo_bc20_t, parent); - os_int32_t ping_result = BC20_PING_INVALID_DEF; - char ping_sign = 0; + mo_bc20_t *bc20 = os_container_of(module, mo_bc20_t, parent); + os_int32_t ping_result = BC20_PING_INVALID_DEF; + char ping_sign = 0; if (OS_NULL == bc20->ping_data) { @@ -203,7 +207,7 @@ static void urc_ping_func(struct at_parser *parser, const char *data, os_size_t } __exit: - + if (OS_EOK == result && 0 == ping_result) { memcpy(bc20->ping_data, data, size); diff --git a/components/molink/module/bc26/include/bc26.h b/components/molink/module/bc26/include/bc26.h index a728f3be..8e931982 100644 --- a/components/molink/module/bc26/include/bc26.h +++ b/components/molink/module/bc26/include/bc26.h @@ -65,28 +65,28 @@ extern "C" { #endif #ifndef BC26_NETCONN_NUM -#define BC26_NETCONN_NUM (5) +#define BC26_NETCONN_NUM (5) #endif typedef struct mo_bc26 { - mo_object_t parent; + mo_object_t parent; #ifdef BC26_USING_NETCONN_OPS mo_netconn_t netconn[BC26_NETCONN_NUM]; - os_int32_t curr_connect; - os_event_t netconn_evt; - os_mutex_t netconn_lock; - void *netconn_data; + os_int32_t curr_connect; + os_event_t netconn_evt; + os_mutex_t netconn_lock; + void *netconn_data; #endif /* BC26_USING_NETCONN_OPS */ #ifdef BC26_USING_PING_OPS - char *ping_data; - os_event_t ping_evt; + char *ping_data; + os_event_t ping_evt; #endif /* BC26_USING_PING_OPS */ } mo_bc26_t; mo_object_t *module_bc26_create(const char *name, void *parser_config); -os_err_t module_bc26_destroy(mo_object_t *self); +os_err_t module_bc26_destroy(mo_object_t *self); #endif /* MOLINK_USING_BC26 */ diff --git a/components/molink/module/bc26/include/bc26_netconn.h b/components/molink/module/bc26/include/bc26_netconn.h index 3c371ff8..beeb7a4b 100644 --- a/components/molink/module/bc26/include/bc26_netconn.h +++ b/components/molink/module/bc26/include/bc26_netconn.h @@ -33,13 +33,13 @@ extern "C" { #ifdef BC26_USING_NETCONN_OPS mo_netconn_t *bc26_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t bc26_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t bc26_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t bc26_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t bc26_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t bc26_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t bc26_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef BC26_USING_DNS -os_err_t bc26_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr); +os_err_t bc26_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr); #endif -os_err_t bc26_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t bc26_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); #endif /* BC26_USING_NETCONN_OPS */ #ifdef __cplusplus diff --git a/components/molink/module/bc26/source/bc26.c b/components/molink/module/bc26/source/bc26.c index b552fdf1..76d61390 100644 --- a/components/molink/module/bc26/source/bc26.c +++ b/components/molink/module/bc26/source/bc26.c @@ -27,7 +27,7 @@ #include #define MO_LOG_TAG "bc26" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_BC26 @@ -38,12 +38,12 @@ extern void bc26_general_init(mo_bc26_t *module); static const struct mo_general_ops gs_general_ops = { - .at_test = bc26_at_test, - .get_imei = bc26_get_imei, - .get_imsi = bc26_get_imsi, - .get_iccid = bc26_get_iccid, - .get_cfun = bc26_get_cfun, - .set_cfun = bc26_set_cfun, + .at_test = bc26_at_test, + .get_imei = bc26_get_imei, + .get_imsi = bc26_get_imsi, + .get_iccid = bc26_get_iccid, + .get_cfun = bc26_get_cfun, + .set_cfun = bc26_set_cfun, }; #endif /* BC26_USING_GENERAL_OPS */ @@ -51,30 +51,30 @@ static const struct mo_general_ops gs_general_ops = { extern void bc26_netserv_init(mo_bc26_t *module); static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = bc26_set_attach, - .get_attach = bc26_get_attach, - .set_reg = bc26_set_reg, - .get_reg = bc26_get_reg, - .set_cgact = bc26_set_cgact, - .get_cgact = bc26_get_cgact, - .get_csq = bc26_get_csq, - .get_radio = bc26_get_radio, + .set_attach = bc26_set_attach, + .get_attach = bc26_get_attach, + .set_reg = bc26_set_reg, + .get_reg = bc26_get_reg, + .set_cgact = bc26_set_cgact, + .get_cgact = bc26_get_cgact, + .get_csq = bc26_get_csq, + .get_radio = bc26_get_radio, }; #endif /* BC26_USING_NETSERV_OPS */ #ifdef BC26_USING_PING_OPS extern void bc26_ping_init(mo_bc26_t *module); static const struct mo_ping_ops gs_ping_ops = { - .ping = bc26_ping, + .ping = bc26_ping, }; #endif /* BC26_USING_PING_OPS */ #ifdef BC26_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = bc26_ifconfig, - .get_ipaddr = bc26_get_ipaddr, - .set_dnsserver = bc26_set_dnsserver, - .get_dnsserver = bc26_get_dnsserver, + .ifconfig = bc26_ifconfig, + .get_ipaddr = bc26_get_ipaddr, + .set_dnsserver = bc26_set_dnsserver, + .get_dnsserver = bc26_get_dnsserver, }; #endif /* BC26_USING_IFCONFIG_OPS */ @@ -82,27 +82,25 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void bc26_netconn_init(mo_bc26_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = bc26_netconn_create, - .destroy = bc26_netconn_destroy, + .create = bc26_netconn_create, + .destroy = bc26_netconn_destroy, #ifdef BC26_USING_DNS - .gethostbyname = bc26_netconn_gethostbyname, + .gethostbyname = bc26_netconn_gethostbyname, #endif - .connect = bc26_netconn_connect, - .send = bc26_netconn_send, - .get_info = bc26_netconn_get_info, + .connect = bc26_netconn_connect, + .send = bc26_netconn_send, + .get_info = bc26_netconn_get_info, }; #endif /* BC26_USING_NETCONN_OPS */ static os_err_t bc26_at_init(mo_object_t *self) { at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = OS_TICK_PER_SECOND}; result = at_parser_connect(parser, BC26_RETRY_TIMES); if (result != OS_EOK) @@ -133,7 +131,7 @@ __exit: mo_object_t *module_bc26_create(const char *name, void *parser_config) { os_err_t result = OS_ERROR; - + mo_bc26_t *module = (mo_bc26_t *)os_calloc(1, sizeof(mo_bc26_t)); if (OS_NULL == module) { @@ -179,7 +177,7 @@ mo_object_t *module_bc26_create(const char *name, void *parser_config) os_event_init(&module->netconn_evt, "bc26_nc"); os_mutex_init(&module->netconn_lock, "bc26_nc", OS_TRUE); #endif /* BC26_USING_NETCONN_OPS */ - + __exit: if (OS_EOK != result) { @@ -190,7 +188,7 @@ __exit: os_mutex_deinit(&module->netconn_lock); } #endif /* BC26_USING_NETCONN_OPS */ - + #ifdef BC26_USING_PING_OPS if (OS_NULL != module->parent.ops_table[MODULE_OPS_PING]) { @@ -245,12 +243,12 @@ int bc26_auto_create(void) ERROR("Auto create failed, Can not find BC26 interface device %s!", BC26_DEVICE_NAME); return OS_ERROR; } - - uart_config.baud_rate = BC26_DEVICE_RATE; + + uart_config.baud_rate = BC26_DEVICE_RATE; os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = BC26_NAME, + mo_parser_config_t parser_config = {.parser_name = BC26_NAME, .parser_device = device, .recv_buff_len = BC26_RECV_BUFF_LEN}; diff --git a/components/molink/module/bc26/source/bc26_general.c b/components/molink/module/bc26/source/bc26_general.c index 25d6af33..6110e0f9 100644 --- a/components/molink/module/bc26/source/bc26_general.c +++ b/components/molink/module/bc26/source/bc26_general.c @@ -27,7 +27,7 @@ #include #define MO_LOG_TAG "bc26.general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef BC26_USING_GENERAL_OPS @@ -172,7 +172,7 @@ static void bc26_ip_indicator_urc(struct at_parser *parser, const char *data, os char ip_indicator_buf[AT_RESP_BUFF_SIZE_DEF] = {0}; sscanf(data, "+IP: %63s", ip_indicator_buf); - + INFO("%s IP indocator:[%s]", __func__, ip_indicator_buf); return; } @@ -185,13 +185,13 @@ static void bc26_cpin_indicator_urc(struct at_parser *parser, const char *data, char cpin_indicator_buf[AT_RESP_BUFF_SIZE_DEF] = {0}; sscanf(data, "+CPIN: %63s", cpin_indicator_buf); - + INFO("%s CPIN indocator:[%s]", __func__, cpin_indicator_buf); return; } static at_urc_t bc26_general_urc_table[] = { - {.prefix = "+IP:", .suffix = "\r\n", .func = bc26_ip_indicator_urc }, + {.prefix = "+IP:", .suffix = "\r\n", .func = bc26_ip_indicator_urc}, {.prefix = "+CPIN:", .suffix = "\r\n", .func = bc26_cpin_indicator_urc}, }; @@ -199,7 +199,8 @@ void bc26_general_init(mo_bc26_t *module) { /* Set general urc table */ at_parser_t *parser = &(module->parent.parser); - at_parser_set_urc_table(parser, bc26_general_urc_table, + at_parser_set_urc_table(parser, + bc26_general_urc_table, sizeof(bc26_general_urc_table) / sizeof(bc26_general_urc_table[0])); } diff --git a/components/molink/module/bc26/source/bc26_ifconfig.c b/components/molink/module/bc26/source/bc26_ifconfig.c index d571060a..7cae3b61 100644 --- a/components/molink/module/bc26/source/bc26_ifconfig.c +++ b/components/molink/module/bc26/source/bc26_ifconfig.c @@ -32,7 +32,7 @@ #ifdef BC26_USING_IFCONFIG_OPS #define MO_LOG_TAG "bc26.ifconfig" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define BC26_IFCONFIG_INVALID_DFT (-1) @@ -58,12 +58,12 @@ os_err_t bc26_ifconfig(mo_object_t *module) } os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t ber = 0; if (bc26_get_csq(module, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; } os_kprintf("\r\nLIST AT MODULE INFORMATION\r\n"); @@ -91,7 +91,7 @@ os_err_t bc26_ifconfig(mo_object_t *module) os_err_t bc26_set_dnsserver(mo_object_t *module, dns_server_t dns) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -118,14 +118,14 @@ os_err_t bc26_set_dnsserver(mo_object_t *module, dns_server_t dns) { result = at_parser_exec_cmd(parser, &resp, "AT+QIDNSCFG=1,\"%s\",\"%s\"", dns.primary_dns, dns.secondary_dns); } - + return result; } os_err_t bc26_get_dnsserver(mo_object_t *module, dns_server_t *dns) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; char primary_dns[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -143,13 +143,15 @@ os_err_t bc26_get_dnsserver(mo_object_t *module, dns_server_t *dns) char resp_buff[4 * AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = OS_TICK_PER_SECOND}; + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = OS_TICK_PER_SECOND}; result = at_parser_exec_cmd(parser, &at_resp, "AT+QIDNSCFG=1"); - if (at_resp_get_data_by_kw(&at_resp, "+QIDNSCFG:", "+QIDNSCFG: 1,%[^,],\"%[^\"]", primary_dns, dns->secondary_dns) <= 0) + if (at_resp_get_data_by_kw(&at_resp, + "+QIDNSCFG:", + "+QIDNSCFG: 1,%[^,],\"%[^\"]", + primary_dns, + dns->secondary_dns) <= 0) { ERROR("BC26 %s: get dns failed.", __FUNCTION__); result = OS_ERROR; @@ -167,8 +169,8 @@ __exit: os_err_t bc26_get_ipaddr(mo_object_t *module, char ip[]) { at_parser_t *parser = &module->parser; - os_int8_t ucid = BC26_IFCONFIG_INVALID_DFT; - os_int8_t len = BC26_IFCONFIG_INVALID_DFT; + os_int8_t ucid = BC26_IFCONFIG_INVALID_DFT; + os_int8_t len = BC26_IFCONFIG_INVALID_DFT; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -205,7 +207,7 @@ os_err_t bc26_get_ipaddr(mo_object_t *module, char ip[]) } __exit: - + return result; } diff --git a/components/molink/module/bc26/source/bc26_netconn.c b/components/molink/module/bc26/source/bc26_netconn.c index 82f26b39..6e348143 100644 --- a/components/molink/module/bc26/source/bc26_netconn.c +++ b/components/molink/module/bc26/source/bc26_netconn.c @@ -29,18 +29,18 @@ #include #define MO_LOG_TAG "bc26.netconn" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define BC26_CONN_ID_NULL (-1) #define SEND_DATA_MAX_SIZE (1024) -#define BC26_NETCONN_MQ_NAME "bc26_nc_mq" +#define BC26_NETCONN_MQ_NAME "bc26_nc_mq" #ifndef BC26_NETCONN_MQ_MSG_SIZE #define BC26_NETCONN_MQ_MSG_SIZE (sizeof(mo_notconn_msg_t)) #endif /* BC26_NETCONN_MQ_MSG_SIZE */ #ifndef BC26_NETCONN_MQ_MSG_MAX -#define BC26_NETCONN_MQ_MSG_MAX (5) +#define BC26_NETCONN_MQ_MSG_MAX (5) #endif /* BC26_NETCONN_MQ_MSG_MAX */ #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) @@ -146,7 +146,7 @@ os_err_t bc26_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_bc26_t *bc26 = os_container_of(module, mo_bc26_t, parent); info->netconn_array = bc26->netconn; - info->netconn_nums = sizeof(bc26->netconn) / sizeof(bc26->netconn[0]); + info->netconn_nums = sizeof(bc26->netconn) / sizeof(bc26->netconn[0]); return OS_EOK; } @@ -165,9 +165,7 @@ mo_netconn_t *bc26_netconn_create(mo_object_t *module, mo_netconn_type_t type) return OS_NULL; } - netconn->mq = os_mq_create(BC26_NETCONN_MQ_NAME, - BC26_NETCONN_MQ_MSG_SIZE, - BC26_NETCONN_MQ_MSG_MAX); + netconn->mq = os_mq_create(BC26_NETCONN_MQ_NAME, BC26_NETCONN_MQ_MSG_SIZE, BC26_NETCONN_MQ_MSG_MAX); if (OS_NULL == netconn->mq) { ERROR("%s message queue create failed, no enough memory.", module->name); @@ -186,8 +184,8 @@ mo_netconn_t *bc26_netconn_create(mo_object_t *module, mo_netconn_type_t type) os_err_t bc26_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; - mo_bc26_t *bc26 = os_container_of(module, mo_bc26_t, parent); + os_err_t result = OS_ERROR; + mo_bc26_t *bc26 = os_container_of(module, mo_bc26_t, parent); bc26_lock(&bc26->netconn_lock); @@ -203,28 +201,28 @@ os_err_t bc26_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) case NETCONN_STAT_CONNECT: os_event_recv(&bc26->netconn_evt, - BC26_EVNET_CLOSE_OK, - OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, - OS_NO_WAIT, - OS_NULL); + BC26_EVNET_CLOSE_OK, + OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, + OS_NO_WAIT, + OS_NULL); result = at_parser_exec_cmd(parser, &resp, "AT+QICLOSE=%d", netconn->connect_id); if (result != OS_EOK) { ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + module->name, + (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); goto __exit; } /* get async close info */ result = os_event_recv(&bc26->netconn_evt, - BC26_EVNET_CLOSE_OK, - OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, - 4 * OS_TICK_PER_SECOND, - OS_NULL); + BC26_EVNET_CLOSE_OK, + OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, + 4 * OS_TICK_PER_SECOND, + OS_NULL); - if(OS_EOK != result) + if (OS_EOK != result) { ERROR("%s destroy netconn:%d failed", __func__, netconn->connect_id); goto __exit; @@ -243,13 +241,12 @@ os_err_t bc26_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn id %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = BC26_CONN_ID_NULL; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = BC26_CONN_ID_NULL; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); - __exit: bc26_unlock(&bc26->netconn_lock); return result; @@ -346,7 +343,7 @@ __exit: { ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); } @@ -360,11 +357,11 @@ __exit: os_size_t bc26_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t curr_size = 0; - os_uint32_t event = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t curr_size = 0; + os_uint32_t event = 0; mo_bc26_t *bc26 = os_container_of(module, mo_bc26_t, parent); @@ -374,9 +371,7 @@ os_size_t bc26_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const ch char resp_buff[2 * AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 10 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; at_parser_set_end_mark(parser, ">", 1); @@ -462,7 +457,7 @@ __exit: os_err_t bc26_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[2 * AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -515,9 +510,9 @@ static void urc_connect_func(struct at_parser *parser, const char *data, os_size mo_bc26_t *bc26 = os_container_of(module, mo_bc26_t, parent); os_int32_t connect_id = 0; - os_int32_t result = 0; + os_int32_t result = 0; - sscanf(data, "+QIOPEN: %d,%d", &connect_id , &result); + sscanf(data, "+QIOPEN: %d,%d", &connect_id, &result); if (0 == result) { @@ -595,7 +590,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; + os_int32_t data_size = 0; sscanf(data, "+QIURC: \"recv\",%d,%d", &connect_id, &data_size); @@ -612,13 +607,13 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t return; } - char *recv_buff = os_calloc(1, data_size); - char temp_buff[8] = {0}; + char *recv_buff = os_calloc(1, data_size); + char temp_buff[8] = {0}; if (recv_buff == OS_NULL) { /* read and clean the coming data */ ERROR("alloc recv buff %d bytes fail, no enough memory", data_size); - os_size_t temp_size = 0; + os_size_t temp_size = 0; while (temp_size < data_size) { if (data_size - temp_size > sizeof(temp_buff)) @@ -732,9 +727,9 @@ static void urc_qiurc_func(struct at_parser *parser, const char *data, os_size_t } static at_urc_t gs_urc_table[] = { - {.prefix = "SEND", .suffix = "\r\n", .func = urc_send_func}, + {.prefix = "SEND", .suffix = "\r\n", .func = urc_send_func}, {.prefix = "+QIOPEN:", .suffix = "\r\n", .func = urc_connect_func}, - {.prefix = "+QIURC:", .suffix = "\r\n", .func = urc_qiurc_func}, + {.prefix = "+QIURC:", .suffix = "\r\n", .func = urc_qiurc_func}, {.prefix = "CLOSE OK", .suffix = "\r\n", .func = urc_close_result_func}, }; diff --git a/components/molink/module/bc26/source/bc26_netserv.c b/components/molink/module/bc26/source/bc26_netserv.c index e6f74922..d287a438 100644 --- a/components/molink/module/bc26/source/bc26_netserv.c +++ b/components/molink/module/bc26/source/bc26_netserv.c @@ -29,13 +29,13 @@ #include #define MO_LOG_TAG "bc26.netserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef BC26_USING_NETSERV_OPS -#define BC26_EARFCN_MAX (65535) -#define BC26_PCI_MAX (0x1F7) +#define BC26_EARFCN_MAX (65535) +#define BC26_PCI_MAX (0x1F7) os_err_t bc26_set_attach(mo_object_t *module, os_uint8_t attach_stat) { @@ -62,7 +62,7 @@ os_err_t bc26_get_attach(mo_object_t *module, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) { ERROR("Get %s module attach state failed", module->name); return OS_ERROR; @@ -178,7 +178,7 @@ os_err_t bc26_get_radio(mo_object_t *module, radio_info_t *radio_info) memset(radio_info, 0, sizeof(radio_info_t)); - int at_ret = 0; + int at_ret = 0; char resp_buff[4 * AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 3 * OS_TICK_PER_SECOND}; @@ -192,18 +192,20 @@ os_err_t bc26_get_radio(mo_object_t *module, radio_info_t *radio_info) /** * =0: * +QENG: 0,,,,,[],[],[],[], - * ,,[],[], + * ,,[],[], * [+QENG: 1,,,,,[…]] * SINR: Signal to Interference plus Noise Ratio * SNR : Signal Noise Ratio * */ - at_ret = at_resp_get_data_by_kw(&resp, "+QENG: 0", "+QENG: 0,%d,%*d,%*d,\"%[^\"]\",%*d,%d,%*d,%d,%*d,%*[^,],%d,%d,", - &radio_info->earfcn, - radio_info->cell_id, - &radio_info->rsrq, - &radio_info->snr, - &radio_info->ecl, - &radio_info->signal_power); + at_ret = at_resp_get_data_by_kw(&resp, + "+QENG: 0", + "+QENG: 0,%d,%*d,%*d,\"%[^\"]\",%*d,%d,%*d,%d,%*d,%*[^,],%d,%d,", + &radio_info->earfcn, + radio_info->cell_id, + &radio_info->rsrq, + &radio_info->snr, + &radio_info->ecl, + &radio_info->signal_power); if (0 >= at_ret) { ERROR("Get %s module signal power failed", module->name); diff --git a/components/molink/module/bc26/source/bc26_ping.c b/components/molink/module/bc26/source/bc26_ping.c index 7536ae11..0bc4f8c7 100644 --- a/components/molink/module/bc26/source/bc26_ping.c +++ b/components/molink/module/bc26/source/bc26_ping.c @@ -27,7 +27,7 @@ #include #define MO_LOG_TAG "bc26.ping" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef BC26_USING_PING_OPS @@ -39,21 +39,21 @@ #define BC26_PING_INVALID_DEF (-1) #define BC26_PING_BUFFER_SIZE (4 * AT_RESP_BUFF_SIZE_DEF) -#define BC26_EVENT_PING_OK (1L << 0) -#define BC26_EVENT_PING_FAIL (1L << 1) +#define BC26_EVENT_PING_OK (1L << 0) +#define BC26_EVENT_PING_FAIL (1L << 1) os_err_t bc26_ping(mo_object_t *module, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_int16_t ttl = BC26_PING_INVALID_DEF; - os_uint32_t timeout_s = timeout / 1000; - os_uint32_t req_time = 0; - os_uint32_t event = 0; - mo_bc26_t *bc26 = os_container_of(module, mo_bc26_t, parent); - - char ip_recv[IPADDR_MAX_STR_LEN + 1] = {0}; - char resp_buff[4 * AT_RESP_BUFF_SIZE_DEF] = {0}; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_int16_t ttl = BC26_PING_INVALID_DEF; + os_uint32_t timeout_s = timeout / 1000; + os_uint32_t req_time = 0; + os_uint32_t event = 0; + mo_bc26_t *bc26 = os_container_of(module, mo_bc26_t, parent); + + char ip_recv[IPADDR_MAX_STR_LEN + 1] = {0}; + char resp_buff[4 * AT_RESP_BUFF_SIZE_DEF] = {0}; char ping_result[BC26_PING_BUFFER_SIZE + 1] = {0}; memset(resp, 0, sizeof(ping_resp_t)); @@ -67,14 +67,18 @@ os_err_t bc26_ping(mo_object_t *module, const char *host, os_uint16_t len, os_ui if ((len < BC26_MIN_PING_PKG_LEN) || (len > BC26_MAX_PING_PKG_LEN)) { ERROR("BC26 ping: ping package len[%d] is out of rang[%d, %d].", - len, BC26_MIN_PING_PKG_LEN, BC26_MAX_PING_PKG_LEN); + len, + BC26_MIN_PING_PKG_LEN, + BC26_MAX_PING_PKG_LEN); return OS_ERROR; } if ((timeout_s < BC26_MIN_PING_TIMEOUT_SEC) || (timeout_s > BC26_MAX_PING_TIMEOUT_SEC)) { ERROR("BC26 ping: user set ping timeout_s value %u s is out of rang[%d, %d]s.", - timeout_s, BC26_MIN_PING_TIMEOUT_SEC, BC26_MAX_PING_TIMEOUT_SEC); + timeout_s, + BC26_MIN_PING_TIMEOUT_SEC, + BC26_MAX_PING_TIMEOUT_SEC); return OS_ERROR; } @@ -89,9 +93,9 @@ os_err_t bc26_ping(mo_object_t *module, const char *host, os_uint16_t len, os_ui * +QPING: [,,,,,,] * Because unable to synchronize time between board & module, 5 seconds reserved * **/ - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .timeout = (10 + timeout_s) * OS_TICK_PER_SECOND}; + .timeout = (10 + timeout_s) * OS_TICK_PER_SECOND}; os_event_clear(&bc26->ping_evt, BC26_EVENT_PING_OK | BC26_EVENT_PING_FAIL); @@ -103,9 +107,9 @@ os_err_t bc26_ping(mo_object_t *module, const char *host, os_uint16_t len, os_ui } result = os_event_recv(&bc26->ping_evt, - BC26_EVENT_PING_OK | BC26_EVENT_PING_FAIL, - OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, - at_resp.timeout, + BC26_EVENT_PING_OK | BC26_EVENT_PING_FAIL, + OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, + at_resp.timeout, &event); if (result != OS_EOK) { @@ -139,9 +143,9 @@ os_err_t bc26_ping(mo_object_t *module, const char *host, os_uint16_t len, os_ui { inet_aton(ip_recv, &(resp->ip_addr)); resp->data_len = len; - resp->ttl = ttl; - resp->time = req_time; - result = OS_EOK; + resp->ttl = ttl; + resp->time = req_time; + result = OS_EOK; } } @@ -159,12 +163,12 @@ static void urc_ping_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - os_err_t result = OS_EOK; - os_int32_t ret = 0; + os_err_t result = OS_EOK; + os_int32_t ret = 0; mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_bc26_t *bc26 = os_container_of(module, mo_bc26_t, parent); - os_int32_t ping_result = BC26_PING_INVALID_DEF; - char ping_sign = 0; + mo_bc26_t *bc26 = os_container_of(module, mo_bc26_t, parent); + os_int32_t ping_result = BC26_PING_INVALID_DEF; + char ping_sign = 0; if (OS_NULL == bc26->ping_data) { @@ -203,7 +207,7 @@ static void urc_ping_func(struct at_parser *parser, const char *data, os_size_t } __exit: - + if (OS_EOK == result && 0 == ping_result) { memcpy(bc26->ping_data, data, size); diff --git a/components/molink/module/bc28/include/bc28.h b/components/molink/module/bc28/include/bc28.h index 5d3788ac..ee2d21d8 100644 --- a/components/molink/module/bc28/include/bc28.h +++ b/components/molink/module/bc28/include/bc28.h @@ -65,30 +65,30 @@ extern "C" { #endif #ifndef BC28_RECV_BUFF_LEN -#define BC28_RECV_BUFF_LEN (1500) +#define BC28_RECV_BUFF_LEN (1500) #endif #ifndef BC28_NETCONN_NUM -#define BC28_NETCONN_NUM (5) /* module service occupied 2 socket */ +#define BC28_NETCONN_NUM (5) /* module service occupied 2 socket */ #endif typedef struct mo_bc28 { - mo_object_t parent; + mo_object_t parent; #ifdef BC28_USING_NETCONN_OPS - mo_netconn_t netconn[BC28_NETCONN_NUM]; - os_mutex_t netconn_lock; - char *netconn_data; - os_event_t netconn_evt; + mo_netconn_t netconn[BC28_NETCONN_NUM]; + os_mutex_t netconn_lock; + char *netconn_data; + os_event_t netconn_evt; #endif /* BC28_USING_NETCONN_OPS */ #ifdef BC28_USING_ONENET_NB_OPS - mo_onenet_cb_t *regist_cb; /* module onenet register callback */ -#endif /* BC28_USING_ONENET_NB_OPS */ + mo_onenet_cb_t *regist_cb; /* module onenet register callback */ +#endif /* BC28_USING_ONENET_NB_OPS */ } mo_bc28_t; mo_object_t *module_bc28_create(const char *name, void *parser_config); -os_err_t module_bc28_destroy(mo_object_t *self); +os_err_t module_bc28_destroy(mo_object_t *self); #endif /* MOLINK_USING_BC28 */ diff --git a/components/molink/module/bc28/include/bc28_netconn.h b/components/molink/module/bc28/include/bc28_netconn.h index 169ec57c..05cbd317 100644 --- a/components/molink/module/bc28/include/bc28_netconn.h +++ b/components/molink/module/bc28/include/bc28_netconn.h @@ -33,13 +33,13 @@ extern "C" { #ifdef BC28_USING_NETCONN_OPS mo_netconn_t *bc28_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t bc28_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t bc28_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t bc28_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t bc28_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t bc28_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t bc28_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef BC28_USING_DNS -os_err_t bc28_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr); +os_err_t bc28_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr); #endif -os_err_t bc28_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t bc28_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); #endif /* BC28_USING_NETCONN_OPS */ #ifdef __cplusplus diff --git a/components/molink/module/bc28/include/bc28_onenet_nb.h b/components/molink/module/bc28/include/bc28_onenet_nb.h index 1b9fc7cc..0497f911 100644 --- a/components/molink/module/bc28/include/bc28_onenet_nb.h +++ b/components/molink/module/bc28/include/bc28_onenet_nb.h @@ -32,8 +32,10 @@ extern "C" { #ifdef BC28_USING_ONENET_NB_OPS -os_err_t bc28_onenetnb_get_config(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); -os_err_t bc28_onenetnb_set_config(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); +os_err_t +bc28_onenetnb_get_config(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); +os_err_t +bc28_onenetnb_set_config(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); os_err_t bc28_onenetnb_create(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); os_err_t bc28_onenetnb_delete(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); @@ -42,12 +44,16 @@ os_err_t bc28_onenetnb_delobj(mo_object_t *module, os_int32_t timeout, void *res os_err_t bc28_onenetnb_open(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); os_err_t bc28_onenetnb_close(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); -os_err_t bc28_onenetnb_discoverrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); -os_err_t bc28_onenetnb_observersp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); +os_err_t +bc28_onenetnb_discoverrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); +os_err_t +bc28_onenetnb_observersp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); os_err_t bc28_onenetnb_readrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); os_err_t bc28_onenetnb_writersp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); -os_err_t bc28_onenetnb_executersp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); -os_err_t bc28_onenetnb_parameterrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); +os_err_t +bc28_onenetnb_executersp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); +os_err_t +bc28_onenetnb_parameterrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); os_err_t bc28_onenetnb_notify(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); os_err_t bc28_onenetnb_update(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); diff --git a/components/molink/module/bc28/source/bc28.c b/components/molink/module/bc28/source/bc28.c index 59b14fed..7f88d3b2 100644 --- a/components/molink/module/bc28/source/bc28.c +++ b/components/molink/module/bc28/source/bc28.c @@ -29,7 +29,7 @@ #include #define MO_LOG_TAG "bc28" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_BC28 @@ -38,12 +38,12 @@ #ifdef BC28_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = bc28_at_test, - .get_imei = bc28_get_imei, - .get_imsi = bc28_get_imsi, - .get_iccid = bc28_get_iccid, - .get_cfun = bc28_get_cfun, - .set_cfun = bc28_set_cfun, + .at_test = bc28_at_test, + .get_imei = bc28_get_imei, + .get_imsi = bc28_get_imsi, + .get_iccid = bc28_get_iccid, + .get_cfun = bc28_get_cfun, + .set_cfun = bc28_set_cfun, }; #endif /* BC28_USING_GENERAL_OPS */ @@ -51,34 +51,34 @@ static const struct mo_general_ops gs_general_ops = { extern void bc28_netserv_init(mo_bc28_t *module); static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = bc28_set_attach, - .get_attach = bc28_get_attach, - .set_reg = bc28_set_reg, - .get_reg = bc28_get_reg, - .set_cgact = bc28_set_cgact, - .get_cgact = bc28_get_cgact, - .get_csq = bc28_get_csq, - .get_radio = bc28_get_radio, - .set_psm = bc28_set_psm, - .get_psm = bc28_get_psm, - .set_edrx_cfg = bc28_set_edrx_cfg, - .get_edrx_cfg = bc28_get_edrx_cfg, - .get_edrx_dynamic = bc28_get_edrx_dynamic, + .set_attach = bc28_set_attach, + .get_attach = bc28_get_attach, + .set_reg = bc28_set_reg, + .get_reg = bc28_get_reg, + .set_cgact = bc28_set_cgact, + .get_cgact = bc28_get_cgact, + .get_csq = bc28_get_csq, + .get_radio = bc28_get_radio, + .set_psm = bc28_set_psm, + .get_psm = bc28_get_psm, + .set_edrx_cfg = bc28_set_edrx_cfg, + .get_edrx_cfg = bc28_get_edrx_cfg, + .get_edrx_dynamic = bc28_get_edrx_dynamic, }; #endif /* BC28_USING_NETSERV_OPS */ #ifdef BC28_USING_PING_OPS static const struct mo_ping_ops gs_ping_ops = { - .ping = bc28_ping, + .ping = bc28_ping, }; #endif /* BC28_USING_PING_OPS */ #ifdef BC28_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = bc28_ifconfig, - .get_ipaddr = bc28_get_ipaddr, - .set_dnsserver = bc28_set_dnsserver, - .get_dnsserver = bc28_get_dnsserver, + .ifconfig = bc28_ifconfig, + .get_ipaddr = bc28_get_ipaddr, + .set_dnsserver = bc28_set_dnsserver, + .get_dnsserver = bc28_get_dnsserver, }; #endif /* BC28_USING_IFCONFIG_OPS */ @@ -86,39 +86,39 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void bc28_netconn_init(mo_bc28_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = bc28_netconn_create, - .destroy = bc28_netconn_destroy, + .create = bc28_netconn_create, + .destroy = bc28_netconn_destroy, #ifdef BC28_USING_DNS - .gethostbyname = bc28_netconn_gethostbyname, + .gethostbyname = bc28_netconn_gethostbyname, #endif - .connect = bc28_netconn_connect, - .send = bc28_netconn_send, - .get_info = bc28_netconn_get_info, + .connect = bc28_netconn_connect, + .send = bc28_netconn_send, + .get_info = bc28_netconn_get_info, }; #endif /* BC28_USING_NETCONN_OPS */ #ifdef BC28_USING_ONENET_NB_OPS extern os_err_t bc28_onenetnb_init(mo_bc28_t *module); -extern void bc28_onenetnb_deinit(mo_bc28_t *module); +extern void bc28_onenetnb_deinit(mo_bc28_t *module); static const mo_onenet_ops_t gs_onenet_ops = { - .onenetnb_get_config = bc28_onenetnb_get_config, - .onenetnb_set_config = bc28_onenetnb_set_config, - .onenetnb_create = bc28_onenetnb_create, - .onenetnb_delete = bc28_onenetnb_delete, - .onenetnb_addobj = bc28_onenetnb_addobj, - .onenetnb_delobj = bc28_onenetnb_delobj, - .onenetnb_open = bc28_onenetnb_open, - .onenetnb_close = bc28_onenetnb_close, - .onenetnb_discoverrsp = bc28_onenetnb_discoverrsp, - .onenetnb_observersp = bc28_onenetnb_observersp, - .onenetnb_readrsp = bc28_onenetnb_readrsp, - .onenetnb_writersp = bc28_onenetnb_writersp, - .onenetnb_executersp = bc28_onenetnb_executersp, + .onenetnb_get_config = bc28_onenetnb_get_config, + .onenetnb_set_config = bc28_onenetnb_set_config, + .onenetnb_create = bc28_onenetnb_create, + .onenetnb_delete = bc28_onenetnb_delete, + .onenetnb_addobj = bc28_onenetnb_addobj, + .onenetnb_delobj = bc28_onenetnb_delobj, + .onenetnb_open = bc28_onenetnb_open, + .onenetnb_close = bc28_onenetnb_close, + .onenetnb_discoverrsp = bc28_onenetnb_discoverrsp, + .onenetnb_observersp = bc28_onenetnb_observersp, + .onenetnb_readrsp = bc28_onenetnb_readrsp, + .onenetnb_writersp = bc28_onenetnb_writersp, + .onenetnb_executersp = bc28_onenetnb_executersp, .onenetnb_parameterrsp = bc28_onenetnb_parameterrsp, - .onenetnb_notify = bc28_onenetnb_notify, - .onenetnb_update = bc28_onenetnb_update, - .onenetnb_cb_register = bc28_onenetnb_cb_register, + .onenetnb_notify = bc28_onenetnb_notify, + .onenetnb_update = bc28_onenetnb_update, + .onenetnb_cb_register = bc28_onenetnb_cb_register, }; #endif /* BC28_USING_ONENET_OPS */ @@ -144,7 +144,7 @@ static os_err_t bc28_at_init(mo_object_t *self) mo_object_t *module_bc28_create(const char *name, void *parser_config) { os_err_t result = OS_ERROR; - + mo_bc28_t *module = (mo_bc28_t *)os_calloc(1, sizeof(mo_bc28_t)); if (OS_NULL == module) { @@ -197,7 +197,7 @@ mo_object_t *module_bc28_create(const char *name, void *parser_config) } module->parent.ops_table[MODULE_OPS_ONENET_NB] = &gs_onenet_ops; #endif /* BC28_USING_ONENET_NB_OPS */ - + __exit: if (OS_EOK != result) { @@ -221,7 +221,7 @@ __exit: } os_free(module); - + return OS_NULL; } @@ -262,12 +262,12 @@ int bc28_auto_create(void) ERROR("Auto create failed, Can not find BC28 interface device %s!", BC28_DEVICE_NAME); return OS_ERROR; } - - uart_config.baud_rate = BC28_DEVICE_RATE; + + uart_config.baud_rate = BC28_DEVICE_RATE; os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = BC28_NAME, + mo_parser_config_t parser_config = {.parser_name = BC28_NAME, .parser_device = device, .recv_buff_len = BC28_RECV_BUFF_LEN}; diff --git a/components/molink/module/bc28/source/bc28_general.c b/components/molink/module/bc28/source/bc28_general.c index 5809f8b6..70b633a7 100644 --- a/components/molink/module/bc28/source/bc28_general.c +++ b/components/molink/module/bc28/source/bc28_general.c @@ -24,12 +24,12 @@ #include "bc28_general.h" #define MO_LOG_TAG "bc28.general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef BC28_USING_GENERAL_OPS -#define BC28_GENERAL_TIMEOUT_DFT (1 * OS_TICK_PER_SECOND) +#define BC28_GENERAL_TIMEOUT_DFT (1 * OS_TICK_PER_SECOND) os_err_t bc28_at_test(mo_object_t *module) { diff --git a/components/molink/module/bc28/source/bc28_ifconfig.c b/components/molink/module/bc28/source/bc28_ifconfig.c index 49dd6f88..8dacf704 100644 --- a/components/molink/module/bc28/source/bc28_ifconfig.c +++ b/components/molink/module/bc28/source/bc28_ifconfig.c @@ -31,7 +31,7 @@ #ifdef BC28_USING_IFCONFIG_OPS #define MO_LOG_TAG "bc28.ifconfig" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define BC28_IFCONFIG_INVALID_DEF (-1) @@ -57,12 +57,12 @@ os_err_t bc28_ifconfig(mo_object_t *module) } os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t ber = 0; if (bc28_get_csq(module, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; } os_kprintf("\r\nLIST AT MODULE INFORMATION\r\n"); @@ -89,10 +89,10 @@ os_err_t bc28_ifconfig(mo_object_t *module) os_err_t bc28_set_dnsserver(mo_object_t *module, dns_server_t dns) { - /* BC28 must set usable dns server befor QDNS(gethostbyname), + /* BC28 must set usable dns server befor QDNS(gethostbyname), otherwise both func will not be reachable before reboot! */ at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -119,16 +119,16 @@ os_err_t bc28_set_dnsserver(mo_object_t *module, dns_server_t dns) { result = at_parser_exec_cmd(parser, &resp, "AT+QIDNSCFG=\"%s\",\"%s\"", dns.primary_dns, dns.secondary_dns); } - + return result; } os_err_t bc28_get_dnsserver(mo_object_t *module, dns_server_t *dns) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; - char primary_dns[IPADDR_MAX_STR_LEN + 1] = {0}; + char primary_dns[IPADDR_MAX_STR_LEN + 1] = {0}; char secondary_dns[IPADDR_MAX_STR_LEN + 1] = {0}; if (OS_NULL == parser) @@ -145,9 +145,7 @@ os_err_t bc28_get_dnsserver(mo_object_t *module, dns_server_t *dns) char resp_buff[4 * AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 16 * OS_TICK_PER_SECOND}; + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 16 * OS_TICK_PER_SECOND}; result = at_parser_exec_cmd(parser, &at_resp, "AT+QIDNSCFG?"); @@ -178,10 +176,10 @@ __exit: os_err_t bc28_get_ipaddr(mo_object_t *module, char ip[]) { at_parser_t *parser = &module->parser; - os_int8_t ucid = BC28_IFCONFIG_INVALID_DEF; - os_int8_t len = BC28_IFCONFIG_INVALID_DEF; + os_int8_t ucid = BC28_IFCONFIG_INVALID_DEF; + os_int8_t len = BC28_IFCONFIG_INVALID_DEF; - char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; + char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[2 * AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; @@ -215,7 +213,7 @@ os_err_t bc28_get_ipaddr(mo_object_t *module, char ip[]) } __exit: - + return result; } diff --git a/components/molink/module/bc28/source/bc28_netconn.c b/components/molink/module/bc28/source/bc28_netconn.c index 4ae903d4..4d1b6e44 100644 --- a/components/molink/module/bc28/source/bc28_netconn.c +++ b/components/molink/module/bc28/source/bc28_netconn.c @@ -32,37 +32,37 @@ #ifdef BC28_USING_NETCONN_OPS #define MO_LOG_TAG "bc28.netconn" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" -#define BC28_EVENT_DOMAIN_OK (1L << 0) -#define BC28_EVENT_DOMAIN_FAIL (1L << 1) -#ifdef BC28_USING_PING_OPS -#define BC28_EVENT_PING_OK (1L << 2) -#define BC28_EVENT_PING_FAIL (1L << 3) +#define BC28_EVENT_DOMAIN_OK (1L << 0) +#define BC28_EVENT_DOMAIN_FAIL (1L << 1) +#ifdef BC28_USING_PING_OPS +#define BC28_EVENT_PING_OK (1L << 2) +#define BC28_EVENT_PING_FAIL (1L << 3) #endif /* BC28_USING_PING_OPS */ -#define PROTOCOL_TYPE_TCP (6) -#define PROTOCOL_TYPE_UDP (17) -#define SEND_DATA_MAX_SIZE (1358) -#define BC28_CONN_ID_NULL (-1) -#define BC28_SEND_BLOCK_SIZE (128) - -#ifdef BC28_USING_PING_OPS -#define BC28_MIN_PING_PKG_LEN (12) -#define BC28_MAX_PING_PKG_LEN (1500) -#define BC28_MIN_PING_TIMEOUT (10) -#define BC28_MAX_PING_TIMEOUT (600000) -#define BC28_PING_INVALID_DEF (-1) -#define BC28_PING_BUFFER_SIZE (128) +#define PROTOCOL_TYPE_TCP (6) +#define PROTOCOL_TYPE_UDP (17) +#define SEND_DATA_MAX_SIZE (1358) +#define BC28_CONN_ID_NULL (-1) +#define BC28_SEND_BLOCK_SIZE (128) + +#ifdef BC28_USING_PING_OPS +#define BC28_MIN_PING_PKG_LEN (12) +#define BC28_MAX_PING_PKG_LEN (1500) +#define BC28_MIN_PING_TIMEOUT (10) +#define BC28_MAX_PING_TIMEOUT (600000) +#define BC28_PING_INVALID_DEF (-1) +#define BC28_PING_BUFFER_SIZE (128) #endif /* BC28_USING_PING_OPS */ -#define BC28_NETCONN_MQ_NAME "bc28_nc_mq" +#define BC28_NETCONN_MQ_NAME "bc28_nc_mq" #ifndef BC28_NETCONN_MQ_MSG_SIZE #define BC28_NETCONN_MQ_MSG_SIZE (sizeof(mo_notconn_msg_t)) #endif /* BC28_NETCONN_MQ_MSG_SIZE */ #ifndef BC28_NETCONN_MQ_MSG_MAX -#define BC28_NETCONN_MQ_MSG_MAX (5) +#define BC28_NETCONN_MQ_MSG_MAX (5) #endif /* BC28_NETCONN_MQ_MSG_MAX */ static os_err_t bc28_lock(os_mutex_t *mutex) @@ -124,16 +124,16 @@ os_err_t bc28_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_bc28_t *bc28 = os_container_of(module, mo_bc28_t, parent); info->netconn_array = bc28->netconn; - info->netconn_nums = sizeof(bc28->netconn) / sizeof(bc28->netconn[0]); + info->netconn_nums = sizeof(bc28->netconn) / sizeof(bc28->netconn[0]); return OS_EOK; } mo_netconn_t *bc28_netconn_create(mo_object_t *module, mo_netconn_type_t type) { - mo_bc28_t *bc28 = os_container_of(module, mo_bc28_t, parent); + mo_bc28_t *bc28 = os_container_of(module, mo_bc28_t, parent); at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; bc28_lock(&bc28->netconn_lock); @@ -191,9 +191,7 @@ mo_netconn_t *bc28_netconn_create(mo_object_t *module, mo_netconn_type_t type) return OS_NULL; } - netconn->mq = os_mq_create(BC28_NETCONN_MQ_NAME, - BC28_NETCONN_MQ_MSG_SIZE, - BC28_NETCONN_MQ_MSG_MAX); + netconn->mq = os_mq_create(BC28_NETCONN_MQ_NAME, BC28_NETCONN_MQ_MSG_SIZE, BC28_NETCONN_MQ_MSG_MAX); if (OS_NULL == netconn->mq) { ERROR("%s message queue create failed, no enough memory.", module->name); @@ -210,9 +208,9 @@ mo_netconn_t *bc28_netconn_create(mo_object_t *module, mo_netconn_type_t type) os_err_t bc28_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; - os_int32_t conn_id = BC28_CONN_ID_NULL; + at_parser_t *parser = &module->parser; + os_err_t result = OS_ERROR; + os_int32_t conn_id = BC28_CONN_ID_NULL; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -228,8 +226,8 @@ os_err_t bc28_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) if (result != OS_EOK) { ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + module->name, + (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); return result; } break; @@ -244,12 +242,12 @@ os_err_t bc28_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) netconn->mq = OS_NULL; } - conn_id = netconn->connect_id; - netconn->connect_id = BC28_CONN_ID_NULL; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + conn_id = netconn->connect_id; + netconn->connect_id = BC28_CONN_ID_NULL; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; - netconn->local_port = 0; + netconn->local_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); INFO("Module %s netconn_id: %d destroyed", module->name, conn_id); @@ -260,17 +258,15 @@ os_err_t bc28_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) #ifdef BC28_USING_DNS os_err_t bc28_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr) { - os_err_t result = OS_EOK; - os_uint32_t event = 0; + os_err_t result = OS_EOK; + os_uint32_t event = 0; at_parser_t *parser = &module->parser; - mo_bc28_t *bc28 = os_container_of(module, mo_bc28_t, parent); + mo_bc28_t *bc28 = os_container_of(module, mo_bc28_t, parent); char resp_buff[4 * AT_RESP_BUFF_SIZE_DEF] = {0}; - char addr_str[IPADDR_MAX_STR_LEN + 1] = {0}; + char addr_str[IPADDR_MAX_STR_LEN + 1] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 20 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; bc28_lock(&bc28->netconn_lock); @@ -350,7 +346,7 @@ static os_err_t bc28_tcp_connect(at_parser_t *parser, os_int32_t connect_id, cha os_err_t bc28_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -366,7 +362,7 @@ os_err_t bc28_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_add #ifdef BC28_USING_UDP case NETCONN_TYPE_UDP: - result = OS_EOK; /* UDP does not need to connect */ + result = OS_EOK; /* UDP does not need to connect */ break; #endif @@ -383,7 +379,7 @@ os_err_t bc28_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_add ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%u successfully!", module->name, remote_ip, port); @@ -392,8 +388,8 @@ os_err_t bc28_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_add static os_size_t bc28_single_packet_send(at_parser_t *parser, const char *data, os_size_t size) { - os_size_t sent_size = 0; /* raw data sent size */ - os_size_t curr_pkt_size = 0; /* raw data current packet size */ + os_size_t sent_size = 0; /* raw data sent size */ + os_size_t curr_pkt_size = 0; /* raw data current packet size */ char hex_str_buff[BC28_SEND_BLOCK_SIZE] = {0}; @@ -418,17 +414,17 @@ __exit: static os_size_t bc28_hexdata_send(at_parser_t *parser, mo_netconn_t *netconn, const char *data, os_size_t size) { - os_err_t result = OS_EOK; - os_int32_t connect_id = BC28_CONN_ID_NULL; - os_size_t sent_size = 0; - os_size_t cur_pkt_size = 0; - os_size_t cnt = 0; + os_err_t result = OS_EOK; + os_int32_t connect_id = BC28_CONN_ID_NULL; + os_size_t sent_size = 0; + os_size_t cur_pkt_size = 0; + os_size_t cnt = 0; - char send_cmd[AT_RESP_BUFF_SIZE_DEF] = {0}; + char send_cmd[AT_RESP_BUFF_SIZE_DEF] = {0}; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = AT_RESP_BUFF_SIZE_DEF, .timeout = 10 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = AT_RESP_BUFF_SIZE_DEF, .timeout = 10 * OS_TICK_PER_SECOND}; strncpy(remote_ip, inet_ntoa(netconn->remote_ip), IPADDR_MAX_STR_LEN); @@ -454,19 +450,17 @@ static os_size_t bc28_hexdata_send(at_parser_t *parser, mo_netconn_t *netconn, c if (NETCONN_TYPE_TCP == netconn->type) { - snprintf(send_cmd, sizeof(send_cmd), - "AT+NSOSD=%d,%d,", - netconn->connect_id, - (int)cur_pkt_size); + snprintf(send_cmd, sizeof(send_cmd), "AT+NSOSD=%d,%d,", netconn->connect_id, (int)cur_pkt_size); } else /* other cases judged by upper function */ { - snprintf(send_cmd, sizeof(send_cmd), - "AT+NSOST=%d,%s,%d,%hu,", + snprintf(send_cmd, + sizeof(send_cmd), + "AT+NSOST=%d,%s,%d,%hu,", netconn->connect_id, remote_ip, netconn->remote_port, - (int)cur_pkt_size); + (int)cur_pkt_size); } /* send cmd prefix */ @@ -504,10 +498,7 @@ __exit: at_parser_exec_unlock(parser); if (result != OS_EOK) { - ERROR("Module %s netconn %d send %d bytes data failed!", - parser->name, - netconn->connect_id, - cur_pkt_size); + ERROR("Module %s netconn %d send %d bytes data failed!", parser->name, netconn->connect_id, cur_pkt_size); return 0; } @@ -515,12 +506,11 @@ __exit: return sent_size; } - os_size_t bc28_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_size_t sent_size = 0; - mo_bc28_t *bc28 = os_container_of(module, mo_bc28_t, parent); + at_parser_t *parser = &module->parser; + os_size_t sent_size = 0; + mo_bc28_t *bc28 = os_container_of(module, mo_bc28_t, parent); if (OS_EOK != bc28_lock(&bc28->netconn_lock)) { @@ -547,19 +537,20 @@ os_size_t bc28_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const ch } #ifdef BC28_USING_PING_OPS -os_err_t bc28_ping_handler(mo_object_t *module, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) +os_err_t +bc28_ping_handler(mo_object_t *module, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_int16_t ttl = BC28_PING_INVALID_DEF; - ip_addr_t addr = {0}; - os_uint32_t req_time = 0; - os_uint32_t event = 0; - mo_bc28_t *bc28 = os_container_of(module, mo_bc28_t, parent); - - char ip_send[IPADDR_MAX_STR_LEN + 1] = {0}; - char ip_recv[IPADDR_MAX_STR_LEN + 1] = {0}; - char ret_buff[BC28_PING_BUFFER_SIZE] = {0}; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_int16_t ttl = BC28_PING_INVALID_DEF; + ip_addr_t addr = {0}; + os_uint32_t req_time = 0; + os_uint32_t event = 0; + mo_bc28_t *bc28 = os_container_of(module, mo_bc28_t, parent); + + char ip_send[IPADDR_MAX_STR_LEN + 1] = {0}; + char ip_recv[IPADDR_MAX_STR_LEN + 1] = {0}; + char ret_buff[BC28_PING_BUFFER_SIZE] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; bc28_lock(&bc28->netconn_lock); @@ -573,14 +564,18 @@ os_err_t bc28_ping_handler(mo_object_t *module, const char *host, os_uint16_t le if ((len < BC28_MIN_PING_PKG_LEN) || (len > BC28_MAX_PING_PKG_LEN)) { ERROR("BC28 ping: ping package len[%d] is out of range[%d, %d].", - len, BC28_MIN_PING_PKG_LEN, BC28_MAX_PING_PKG_LEN); + len, + BC28_MIN_PING_PKG_LEN, + BC28_MAX_PING_PKG_LEN); return OS_ERROR; } if ((timeout < BC28_MIN_PING_TIMEOUT) || (timeout > BC28_MAX_PING_TIMEOUT)) { ERROR("BC28 ping: user set ping timeout value %ums is out of range[%dms, %dms].", - timeout, BC28_MIN_PING_TIMEOUT, BC28_MAX_PING_TIMEOUT); + timeout, + BC28_MIN_PING_TIMEOUT, + BC28_MAX_PING_TIMEOUT); return OS_ERROR; } @@ -604,9 +599,9 @@ os_err_t bc28_ping_handler(mo_object_t *module, const char *host, os_uint16_t le * Module only support IPV4, BC28 only support Dotted Dec/Hex/Oct Notation * Because unable to synchronize time between board & module, 5 seconds reserved * **/ - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; + .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; os_event_clear(&bc28->netconn_evt, BC28_EVENT_PING_OK | BC28_EVENT_PING_FAIL); @@ -657,9 +652,9 @@ os_err_t bc28_ping_handler(mo_object_t *module, const char *host, os_uint16_t le { inet_aton(ip_recv, &(resp->ip_addr)); resp->data_len = len; - resp->ttl = ttl; - resp->time = req_time; - result = OS_EOK; + resp->ttl = ttl; + resp->time = req_time; + result = OS_EOK; } } @@ -677,9 +672,9 @@ static void urc_ping_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_bc28_t *bc28 = os_container_of(module, mo_bc28_t, parent); + mo_bc28_t *bc28 = os_container_of(module, mo_bc28_t, parent); if (OS_NULL == bc28->netconn_data) { @@ -717,7 +712,7 @@ static void urc_ping_err_func(struct at_parser *parser, const char *data, os_siz OS_ASSERT(OS_NULL != data); mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_bc28_t *bc28 = os_container_of(module, mo_bc28_t, parent); + mo_bc28_t *bc28 = os_container_of(module, mo_bc28_t, parent); ERROR("%s-%d: ping error[%s]", __func__, __LINE__, data); @@ -759,7 +754,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; + os_int32_t data_size = 0; sscanf(data, "+NSONMI:%d,%*[^,],%*d,%d,", &connect_id, &data_size); @@ -811,9 +806,9 @@ static void urc_dns_func(struct at_parser *parser, const char *data, os_size_t s OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_bc28_t *bc28 = os_container_of(module, mo_bc28_t, parent); + mo_bc28_t *bc28 = os_container_of(module, mo_bc28_t, parent); char ret_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; if (OS_NULL == bc28->netconn_data) @@ -855,13 +850,13 @@ __exit: static at_urc_t netconn_urc_table[] = { {.prefix = "+NSOCLI:", .suffix = "\r\n", .func = urc_close_func}, - {.prefix = "+NSONMI:", .suffix = "\r\n", .func = urc_recv_func }, - {.prefix = "+QDNS:", .suffix = "\r\n", .func = urc_dns_func }, + {.prefix = "+NSONMI:", .suffix = "\r\n", .func = urc_recv_func}, + {.prefix = "+QDNS:", .suffix = "\r\n", .func = urc_dns_func}, }; #ifdef BC28_USING_PING_OPS static at_urc_t ping_urc_table[] = { - {.prefix = "+NPING:", .suffix = "\r\n", .func = urc_ping_func }, + {.prefix = "+NPING:", .suffix = "\r\n", .func = urc_ping_func}, {.prefix = "+NPINGERR:", .suffix = "\r\n", .func = urc_ping_err_func}, }; #endif /* BC28_USING_PING_OPS */ diff --git a/components/molink/module/bc28/source/bc28_netserv.c b/components/molink/module/bc28/source/bc28_netserv.c index befb08ad..f42dc638 100644 --- a/components/molink/module/bc28/source/bc28_netserv.c +++ b/components/molink/module/bc28/source/bc28_netserv.c @@ -29,7 +29,7 @@ #include #define MO_LOG_TAG "bc28.netserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef BC28_USING_NETSERV_OPS @@ -59,7 +59,7 @@ os_err_t bc28_get_attach(mo_object_t *module, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) { ERROR("Get %s module attach state failed", module->name); return OS_ERROR; @@ -226,17 +226,19 @@ __exit: os_err_t bc28_set_psm(mo_object_t *module, mo_psm_info_t info) { at_parser_t *parser = &module->parser; - + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 1 * OS_TICK_PER_SECOND}; - return at_parser_exec_cmd(parser, &resp, "AT+CPSMS=%d,%s,%s,%s,%s", - info.psm_mode, - info.periodic_rau, - info.gprs_ready_timer, - info.periodic_tau, - info.active_time); + return at_parser_exec_cmd(parser, + &resp, + "AT+CPSMS=%d,%s,%s,%s,%s", + info.psm_mode, + info.periodic_rau, + info.gprs_ready_timer, + info.periodic_tau, + info.active_time); } os_err_t bc28_get_psm(mo_object_t *module, mo_psm_info_t *info) @@ -254,7 +256,12 @@ os_err_t bc28_get_psm(mo_object_t *module, mo_psm_info_t *info) memset(info, 0, sizeof(mo_psm_info_t)); - if ( 0 >= at_resp_get_data_by_kw(&resp, "+CPSMS", "+CPSMS: %d,,,%[^,],%s", &info->psm_mode, info->periodic_tau, info->active_time)) + if (0 >= at_resp_get_data_by_kw(&resp, + "+CPSMS", + "+CPSMS: %d,,,%[^,],%s", + &info->psm_mode, + info->periodic_tau, + info->active_time)) { ERROR("Get %s module psm info failed", module->name); return OS_ERROR; @@ -266,14 +273,12 @@ os_err_t bc28_get_psm(mo_object_t *module, mo_psm_info_t *info) os_err_t bc28_set_edrx_cfg(mo_object_t *module, mo_edrx_cfg_t cfg) { at_parser_t *parser = &module->parser; - + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 1 * OS_TICK_PER_SECOND}; - return at_parser_exec_cmd(parser, &resp, "AT+CEDRXS=%d,5,%s", - cfg.mode, - cfg.edrx.req_edrx_value); + return at_parser_exec_cmd(parser, &resp, "AT+CEDRXS=%d,5,%s", cfg.mode, cfg.edrx.req_edrx_value); } os_err_t bc28_get_edrx_cfg(mo_object_t *module, mo_edrx_t *edrx_local) @@ -292,9 +297,11 @@ os_err_t bc28_get_edrx_cfg(mo_object_t *module, mo_edrx_t *edrx_local) memset(edrx_local, 0, sizeof(mo_edrx_t)); - if (0 >= at_resp_get_data_by_kw(&resp, "+CEDRXS", "+CEDRXS: %d,\"%[^\"]", - &edrx_local->act_type, - edrx_local->req_edrx_value)) + if (0 >= at_resp_get_data_by_kw(&resp, + "+CEDRXS", + "+CEDRXS: %d,\"%[^\"]", + &edrx_local->act_type, + edrx_local->req_edrx_value)) { ERROR("Get %s module edrx local config failed", module->name); return OS_ERROR; @@ -319,11 +326,13 @@ os_err_t bc28_get_edrx_dynamic(mo_object_t *module, mo_edrx_t *edrx_dynamic) memset(edrx_dynamic, 0, sizeof(mo_edrx_t)); - if (0 >= at_resp_get_data_by_kw(&resp, "+CEDRXRDP", "+CEDRXRDP: %d,\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"", - &edrx_dynamic->act_type, - edrx_dynamic->req_edrx_value, - edrx_dynamic->nw_edrx_value, - edrx_dynamic->paging_time_window)) + if (0 >= at_resp_get_data_by_kw(&resp, + "+CEDRXRDP", + "+CEDRXRDP: %d,\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"", + &edrx_dynamic->act_type, + edrx_dynamic->req_edrx_value, + edrx_dynamic->nw_edrx_value, + edrx_dynamic->paging_time_window)) { ERROR("Get %s module edrx dynamic config failed", module->name); return OS_ERROR; @@ -339,11 +348,12 @@ void bc28_edrx_urc_handler(struct at_parser *parser, const char *data, os_size_t mo_edrx_t edrx_urc; memset(&edrx_urc, 0, sizeof(mo_edrx_t)); - sscanf(data, "+CEDRXP: %d,\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"", - (int *)&edrx_urc.act_type, - edrx_urc.req_edrx_value, - edrx_urc.nw_edrx_value, - edrx_urc.paging_time_window); + sscanf(data, + "+CEDRXP: %d,\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"", + (int *)&edrx_urc.act_type, + edrx_urc.req_edrx_value, + edrx_urc.nw_edrx_value, + edrx_urc.paging_time_window); INFO("Get %s module edrx urc act_type[%d]", parser->name, edrx_urc.act_type); INFO("Get %s module edrx urc req_edrx_value[%s]", parser->name, edrx_urc.req_edrx_value); INFO("Get %s module edrx urc nw_edrx_value[%s]", parser->name, edrx_urc.nw_edrx_value); @@ -353,7 +363,7 @@ void bc28_edrx_urc_handler(struct at_parser *parser, const char *data, os_size_t } static at_urc_t bc28_netserv_urc_table[] = { - {.prefix = "+CEDRXP:", .suffix = "\r\n", .func = bc28_edrx_urc_handler}, + {.prefix = "+CEDRXP:", .suffix = "\r\n", .func = bc28_edrx_urc_handler}, }; void bc28_netserv_init(mo_bc28_t *module) diff --git a/components/molink/module/bc28/source/bc28_onenet_nb.c b/components/molink/module/bc28/source/bc28_onenet_nb.c index 638ef74b..a815ef7e 100644 --- a/components/molink/module/bc28/source/bc28_onenet_nb.c +++ b/components/molink/module/bc28/source/bc28_onenet_nb.c @@ -35,50 +35,50 @@ #include #define MO_LOG_TAG "bc28.onenet_nb" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" -#define BC28_URC_HEAD_MAXLEN (16) -#define BC28_REGEX_LEN_DEFAULT (64) -#define BC28_TIMEOUT_DEFAULT (5 * OS_TICK_PER_SECOND) -#define BC28_URC_MQ_NAME "BC28_URC_MQ" -#define BC28_URC_MQ_MSGNUM_MAX (10) -#define BC28_URC_MANAGER_TASK_NAME "bc28_manager" +#define BC28_URC_HEAD_MAXLEN (16) +#define BC28_REGEX_LEN_DEFAULT (64) +#define BC28_TIMEOUT_DEFAULT (5 * OS_TICK_PER_SECOND) +#define BC28_URC_MQ_NAME "BC28_URC_MQ" +#define BC28_URC_MQ_MSGNUM_MAX (10) +#define BC28_URC_MANAGER_TASK_NAME "bc28_manager" /* ============================kconfig_options============================= */ -#ifndef BC28_URC_MANAGER_STACK_SIZE -#define BC28_URC_MANAGER_STACK_SIZE (2048) +#ifndef BC28_URC_MANAGER_STACK_SIZE +#define BC28_URC_MANAGER_STACK_SIZE (2048) #endif /* BC28_URC_MANAGER_STACK_SIZE */ #ifndef BC28_RESP_BUFF_SIZE -#define BC28_RESP_BUFF_SIZE (128) +#define BC28_RESP_BUFF_SIZE (128) #endif /* BC28_RESP_BUFF_SIZE */ #ifndef BC28_URC_MANAGER_TASK_PRIORITY -#define BC28_URC_MANAGER_TASK_PRIORITY (0x10) +#define BC28_URC_MANAGER_TASK_PRIORITY (0x10) #endif /* BC28_URC_MANAGER_TASK_PRIORITY */ /* ===========================kconfig_option_tail========================== */ -static os_mq_t *bc28_nb_mq = OS_NULL; -static os_task_t bc28_nb_manager_task; -static os_uint8_t bc28_nb_manager_task_stack[BC28_URC_MANAGER_STACK_SIZE]; +static os_mq_t *bc28_nb_mq = OS_NULL; +static os_task_t bc28_nb_manager_task; +static os_uint8_t bc28_nb_manager_task_stack[BC28_URC_MANAGER_STACK_SIZE]; -static const os_int8_t BC28_ONENETNB_INVALID_DEFAULT = -1; +static const os_int8_t BC28_ONENETNB_INVALID_DEFAULT = -1; typedef struct bc28_onenet_urc { - const char *prefix; /* URC data prefix */ - void (*func)(mo_onenet_cb_t *regist_cb, const char *data, os_size_t size); - /* URC hanlder function */ + const char *prefix; /* URC data prefix */ + void (*func)(mo_onenet_cb_t *regist_cb, const char *data, os_size_t size); + /* URC hanlder function */ } bc28_onenet_urc_t; typedef struct bc28_onenet_mq_msg { - mo_onenet_cb_t *regist_cb; /* user regist cb ptr */ - const char *data; /* URC data */ - os_size_t len; /* URC data len */ + mo_onenet_cb_t *regist_cb; /* user regist cb ptr */ + const char *data; /* URC data */ + os_size_t len; /* URC data len */ void (*func)(mo_onenet_cb_t *regist_cb, const char *data, os_size_t size); - /* URC hanlder function */ + /* URC hanlder function */ } bc28_onenet_mq_msg_t; typedef enum bc28_config_mode @@ -93,28 +93,25 @@ typedef enum bc28_config_mode BC28_ONENETNB_BUF_CONFIG, } bc28_config_mode_t; -#define CALL_BC28_BASIC_FUNC(AT_FRONT_OPT) \ -do \ -{ \ - OS_ASSERT(module != OS_NULL); \ - OS_ASSERT(format != OS_NULL); \ - \ - at_parser_t *parser = &module->parser; \ - os_err_t result = OS_EOK; \ - \ - char resp_buff[BC28_RESP_BUFF_SIZE] = {0}; \ - at_resp_t at_resp = {.buff = resp_buff, \ - .buff_size = sizeof(resp_buff), \ - .line_num = 0, \ - .timeout = timeout}; \ - \ - char tmp_format[BC28_RESP_BUFF_SIZE] = AT_FRONT_OPT; \ - strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); \ - \ - result = at_parser_exec_cmd_valist(parser, &at_resp, tmp_format, args); \ - \ - return result; \ -} while (0); +#define CALL_BC28_BASIC_FUNC(AT_FRONT_OPT) \ + do \ + { \ + OS_ASSERT(module != OS_NULL); \ + OS_ASSERT(format != OS_NULL); \ + \ + at_parser_t *parser = &module->parser; \ + os_err_t result = OS_EOK; \ + \ + char resp_buff[BC28_RESP_BUFF_SIZE] = {0}; \ + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .line_num = 0, .timeout = timeout}; \ + \ + char tmp_format[BC28_RESP_BUFF_SIZE] = AT_FRONT_OPT; \ + strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); \ + \ + result = at_parser_exec_cmd_valist(parser, &at_resp, tmp_format, args); \ + \ + return result; \ + } while (0); os_err_t bc28_onenetnb_get_config(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args) { @@ -122,21 +119,18 @@ os_err_t bc28_onenetnb_get_config(mo_object_t *module, os_int32_t timeout, void OS_ASSERT(module != OS_NULL); OS_ASSERT(resp != OS_NULL); - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_uint32_t line; - char tmp_buff[128] = {0}; - os_int32_t getline_num = 0; - os_int32_t config_mode_ref; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_uint32_t line; + char tmp_buff[128] = {0}; + os_int32_t getline_num = 0; + os_int32_t config_mode_ref; - mo_config_resp_t *config_resp = (mo_config_resp_t *)resp; + mo_config_resp_t *config_resp = (mo_config_resp_t *)resp; memset(config_resp, 0, sizeof(mo_config_resp_t)); char resp_buff[128] = {0}; - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .line_num = 0, - .timeout = timeout}; + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .line_num = 0, .timeout = timeout}; result = at_parser_exec_cmd(parser, &at_resp, "AT+MIPLCONFIG?"); if (OS_EOK != result) @@ -146,16 +140,16 @@ os_err_t bc28_onenetnb_get_config(mo_object_t *module, os_int32_t timeout, void } /* set default invalid value */ - config_resp->guide_mode_enable = BC28_ONENETNB_INVALID_DEFAULT; + config_resp->guide_mode_enable = BC28_ONENETNB_INVALID_DEFAULT; config_resp->obs_autoack_enable = BC28_ONENETNB_INVALID_DEFAULT; - config_resp->auth_enable = BC28_ONENETNB_INVALID_DEFAULT; - config_resp->dtls_enable = BC28_ONENETNB_INVALID_DEFAULT; - config_resp->write_format = BC28_ONENETNB_INVALID_DEFAULT; - config_resp->buf_cfg = BC28_ONENETNB_INVALID_DEFAULT; - config_resp->buf_urc_mode = BC28_ONENETNB_INVALID_DEFAULT; + config_resp->auth_enable = BC28_ONENETNB_INVALID_DEFAULT; + config_resp->dtls_enable = BC28_ONENETNB_INVALID_DEFAULT; + config_resp->write_format = BC28_ONENETNB_INVALID_DEFAULT; + config_resp->buf_cfg = BC28_ONENETNB_INVALID_DEFAULT; + config_resp->buf_urc_mode = BC28_ONENETNB_INVALID_DEFAULT; /* return mode with 7 lines */ - for (line = 1; ; line++) - { + for (line = 1;; line++) + { getline_num = at_resp_get_data_by_line(&at_resp, line, "+MIPLCONFIG:%d,%s", &config_mode_ref, tmp_buff); if (0 == getline_num) /* empty line */ { @@ -198,7 +192,7 @@ os_err_t bc28_onenetnb_get_config(mo_object_t *module, os_int32_t timeout, void ERROR("Get %s module onenetnb mode:%d invalid", module->name, config_mode_ref); break; } - + memset(tmp_buff, 0, sizeof(tmp_buff)); } @@ -209,7 +203,7 @@ __exit: os_err_t bc28_onenetnb_set_config(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args) { - CALL_BC28_BASIC_FUNC("AT+MIPLCONFIG="); /* maximum return time out 300ms, suggest more than it */ + CALL_BC28_BASIC_FUNC("AT+MIPLCONFIG="); /* maximum return time out 300ms, suggest more than it */ } os_err_t bc28_onenetnb_create(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args) @@ -220,10 +214,7 @@ os_err_t bc28_onenetnb_create(mo_object_t *module, os_int32_t timeout, void *res at_parser_t *parser = &module->parser; char resp_buff[128] = {0}; - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .line_num = 0, - .timeout = timeout}; + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .line_num = 0, .timeout = timeout}; char tmp_format[128] = "AT+MIPLCREATE"; @@ -233,7 +224,7 @@ os_err_t bc28_onenetnb_create(mo_object_t *module, os_int32_t timeout, void *res } os_uint8_t ref = 0; - + if (at_resp_get_data_by_kw(&at_resp, "+MIPLCREATE:", "+MIPLCREATE:%hhu", &ref) > 0) { *(os_uint8_t *)resp = ref; @@ -271,7 +262,8 @@ os_err_t bc28_onenetnb_close(mo_object_t *module, os_int32_t timeout, void *resp CALL_BC28_BASIC_FUNC("AT+MIPLCLOSE="); } -os_err_t bc28_onenetnb_discoverrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args) +os_err_t +bc28_onenetnb_discoverrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args) { CALL_BC28_BASIC_FUNC("AT+MIPLDISCOVERRSP="); } @@ -296,7 +288,8 @@ os_err_t bc28_onenetnb_executersp(mo_object_t *module, os_int32_t timeout, void CALL_BC28_BASIC_FUNC("AT+MIPLEXECUTERSP="); } -os_err_t bc28_onenetnb_parameterrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args) +os_err_t +bc28_onenetnb_parameterrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args) { CALL_BC28_BASIC_FUNC("AT+MIPLPARAMETERRSP="); } @@ -323,15 +316,12 @@ static void urc_discover_handler(mo_onenet_cb_t *regist_cb, const char *data, os WARN("[%d][%s] No discover callback registed.", __LINE__, __func__); return; } - - mo_onenet_discover_t discover_info; + + mo_onenet_discover_t discover_info; memset(&discover_info, 0, sizeof(mo_onenet_discover_t)); - sscanf(data, "+MIPLDISCOVER: %u,%d,%d", - &discover_info.ref, - &discover_info.msg_id, - &discover_info.obj_id); - + sscanf(data, "+MIPLDISCOVER: %u,%d,%d", &discover_info.ref, &discover_info.msg_id, &discover_info.obj_id); + regist_cb->discover_notify_cb(&discover_info); return; @@ -349,17 +339,18 @@ static void urc_observe_handler(mo_onenet_cb_t *regist_cb, const char *data, os_ return; } - mo_onenet_observe_t observe_info; + mo_onenet_observe_t observe_info; memset(&observe_info, 0, sizeof(mo_onenet_observe_t)); - sscanf(data, "+MIPLOBSERVE: %u,%d,%hhd,%d,%d,%d", - &observe_info.ref, - &observe_info.msg_id, - &observe_info.flag, - &observe_info.obj_id, - &observe_info.ins_id, - &observe_info.res_id); - + sscanf(data, + "+MIPLOBSERVE: %u,%d,%hhd,%d,%d,%d", + &observe_info.ref, + &observe_info.msg_id, + &observe_info.flag, + &observe_info.obj_id, + &observe_info.ins_id, + &observe_info.res_id); + regist_cb->observe_notify_cb(&observe_info); return; @@ -377,16 +368,17 @@ static void urc_read_handler(mo_onenet_cb_t *regist_cb, const char *data, os_siz return; } - mo_onenet_read_t read_info; + mo_onenet_read_t read_info; memset(&read_info, 0, sizeof(mo_onenet_read_t)); - sscanf(data, "+MIPLREAD: %u,%d,%d,%d,%d", - &read_info.ref, - &read_info.msg_id, - &read_info.obj_id, - &read_info.ins_id, - &read_info.res_id); - + sscanf(data, + "+MIPLREAD: %u,%d,%d,%d,%d", + &read_info.ref, + &read_info.msg_id, + &read_info.obj_id, + &read_info.ins_id, + &read_info.res_id); + regist_cb->read_notify_cb(&read_info); return; @@ -405,10 +397,10 @@ static void urc_write_handler(mo_onenet_cb_t *regist_cb, const char *data, os_si return; } - mo_onenet_write_t write_info; - os_int8_t *value = OS_NULL; - os_int8_t value_trait = 0; /* value trait:string/hexstring */ - + mo_onenet_write_t write_info; + os_int8_t *value = OS_NULL; + os_int8_t value_trait = 0; /* value trait:string/hexstring */ + memset(&write_info, 0, sizeof(mo_onenet_write_t)); char regex[BC28_REGEX_LEN_DEFAULT] = {0}; @@ -423,26 +415,27 @@ static void urc_write_handler(mo_onenet_cb_t *regist_cb, const char *data, os_si value = os_calloc(1, write_info.len * 2 + 1); strcpy(regex, "+MIPLWRITE: %u,%d,%d,%d,%d,%hhd,%*d,%[^,],%hhd,%d"); } - + if (value == OS_NULL) { ERROR("Calloc onenetNB[%s] value str failed, no enough memory", __func__); return; } - sscanf(data, regex, - &write_info.ref, - &write_info.msg_id, - &write_info.obj_id, - &write_info.ins_id, - &write_info.res_id, - &write_info.value_type, - value, - &write_info.flag, - &write_info.index); - + sscanf(data, + regex, + &write_info.ref, + &write_info.msg_id, + &write_info.obj_id, + &write_info.ins_id, + &write_info.res_id, + &write_info.value_type, + value, + &write_info.flag, + &write_info.index); + regist_cb->write_notify_cb(&write_info, (const char *)value); - + os_free(value); return; } @@ -460,28 +453,29 @@ static void urc_execute_handler(mo_onenet_cb_t *regist_cb, const char *data, os_ return; } - mo_onenet_execute_t execute_info; + mo_onenet_execute_t execute_info; memset(&execute_info, 0, sizeof(mo_onenet_execute_t)); sscanf(data, "+MIPLEXECUTE: %*d,%*d,%*d,%*d,%*d,%d", &execute_info.len); - - os_uint8_t *arguments = os_calloc(1, execute_info.len + 1); - + + os_uint8_t *arguments = os_calloc(1, execute_info.len + 1); + if (OS_NULL == arguments) { ERROR("Calloc onenetNB[%s] arguments str failed, no enough memory", __func__); return; } - sscanf(data, "+MIPLEXECUTE: %u,%d,%d,%d,%d,%*d,\"%s\"", - &execute_info.ref, - &execute_info.msg_id, - &execute_info.obj_id, - &execute_info.ins_id, - &execute_info.res_id, + sscanf(data, + "+MIPLEXECUTE: %u,%d,%d,%d,%d,%*d,\"%s\"", + &execute_info.ref, + &execute_info.msg_id, + &execute_info.obj_id, + &execute_info.ins_id, + &execute_info.res_id, arguments); - + regist_cb->execute_notify_cb(&execute_info, (const char *)arguments); - + os_free(arguments); return; } @@ -498,28 +492,29 @@ static void urc_parameter_handler(mo_onenet_cb_t *regist_cb, const char *data, o return; } - mo_onenet_parameter_t parameter_info; + mo_onenet_parameter_t parameter_info; memset(¶meter_info, 0, sizeof(mo_onenet_parameter_t)); sscanf(data, "+MIPLPARAMETER: %*d,%*d,%*d,%*d,%*d,%d", ¶meter_info.len); - - os_uint8_t *arguments = os_calloc(1, parameter_info.len + 1); - + + os_uint8_t *arguments = os_calloc(1, parameter_info.len + 1); + if (OS_NULL == arguments) { ERROR("Calloc onenetNB[%s] arguments str failed, no enough memory", __func__); return; } - sscanf(data, "+MIPLPARAMETER: %u,%d,%d,%d,%d,%*d,\"%s\"", - ¶meter_info.ref, - ¶meter_info.msg_id, - ¶meter_info.obj_id, - ¶meter_info.ins_id, - ¶meter_info.res_id, + sscanf(data, + "+MIPLPARAMETER: %u,%d,%d,%d,%d,%*d,\"%s\"", + ¶meter_info.ref, + ¶meter_info.msg_id, + ¶meter_info.obj_id, + ¶meter_info.ins_id, + ¶meter_info.res_id, arguments); - + regist_cb->parameter_notify_cb(¶meter_info, (const char *)arguments); - + os_free(arguments); return; } @@ -536,46 +531,47 @@ static void urc_event_handler(mo_onenet_cb_t *regist_cb, const char *data, os_si return; } - mo_onenet_event_t event_info; + mo_onenet_event_t event_info; memset(&event_info, 0, sizeof(mo_onenet_event_t)); - event_info.extend = BC28_ONENETNB_INVALID_DEFAULT; + event_info.extend = BC28_ONENETNB_INVALID_DEFAULT; event_info.cache_command_flag = BC28_ONENETNB_INVALID_DEFAULT; - sscanf(data, "+MIPLEVENT: %u,%hhu,%d,%hu,%s,%hhd", - &event_info.ref, - &event_info.evt_id, - &event_info.extend, - &event_info.ack_id, + sscanf(data, + "+MIPLEVENT: %u,%hhu,%d,%hu,%s,%hhd", + &event_info.ref, + &event_info.evt_id, + &event_info.extend, + &event_info.ack_id, event_info.time_stamp, - &event_info.cache_command_flag); - + &event_info.cache_command_flag); + regist_cb->event_notify_cb(&event_info); - + return; } static bc28_onenet_urc_t bc28_nb_urc_handler_table[] = { - {.prefix = "MIPLDISCOVER", .func = urc_discover_handler }, - {.prefix = "MIPLOBSERVE", .func = urc_observe_handler }, - {.prefix = "MIPLREAD", .func = urc_read_handler }, - {.prefix = "MIPLWRITE", .func = urc_write_handler }, - {.prefix = "MIPLEXECUTE", .func = urc_execute_handler }, + {.prefix = "MIPLDISCOVER", .func = urc_discover_handler}, + {.prefix = "MIPLOBSERVE", .func = urc_observe_handler}, + {.prefix = "MIPLREAD", .func = urc_read_handler}, + {.prefix = "MIPLWRITE", .func = urc_write_handler}, + {.prefix = "MIPLEXECUTE", .func = urc_execute_handler}, {.prefix = "MIPLPARAMETER", .func = urc_parameter_handler}, - {.prefix = "MIPLEVENT", .func = urc_event_handler }, + {.prefix = "MIPLEVENT", .func = urc_event_handler}, }; static void bc28_urc_receiver(struct at_parser *parser, const char *data, os_size_t size) { OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - - char *urc_data = OS_NULL; - os_int8_t handler_ref = BC28_ONENETNB_INVALID_DEFAULT; - char urc_cmd_head[BC28_URC_HEAD_MAXLEN] = {0}; - + + char *urc_data = OS_NULL; + os_int8_t handler_ref = BC28_ONENETNB_INVALID_DEFAULT; + char urc_cmd_head[BC28_URC_HEAD_MAXLEN] = {0}; + /* parse from cmd */ sscanf(data, "+%[^:]", urc_cmd_head); - + /* find registration */ for (int i = 0; i < sizeof(bc28_nb_urc_handler_table) / sizeof(bc28_onenet_urc_t); i++) { @@ -606,11 +602,8 @@ static void bc28_urc_receiver(struct at_parser *parser, const char *data, os_siz mo_bc28_t *module = os_container_of(module, mo_bc28_t, parent); /* send handle_msg to mq */ - bc28_onenet_mq_msg_t handle_msg = {module->regist_cb, - urc_data, - size, - bc28_nb_urc_handler_table[handler_ref].func}; - + bc28_onenet_mq_msg_t handle_msg = {module->regist_cb, urc_data, size, bc28_nb_urc_handler_table[handler_ref].func}; + if (OS_EOK != os_mq_send(bc28_nb_mq, &handle_msg, sizeof(handle_msg), OS_NO_WAIT)) { WARN("[%s] mq send failed, too many unsolved urc.", __func__); @@ -623,19 +616,15 @@ static void bc28_urc_manager_task(void *parameter) { INFO("[%s] task start up.", __func__); bc28_onenet_mq_msg_t handle_msg; - os_err_t result = OS_ERROR; - os_size_t recv_size = 0; + os_err_t result = OS_ERROR; + os_size_t recv_size = 0; while (1) { memset(&handle_msg, 0, sizeof(bc28_onenet_mq_msg_t)); - + /* wait & pop */ - result = os_mq_recv(bc28_nb_mq, - &handle_msg, - sizeof(handle_msg), - OS_WAIT_FOREVER, - &recv_size); + result = os_mq_recv(bc28_nb_mq, &handle_msg, sizeof(handle_msg), OS_WAIT_FOREVER, &recv_size); if (OS_EOK != result) { INFO("[%s] mq received mq_control [exit] msg.[%d].", __func__, result); @@ -646,12 +635,10 @@ static void bc28_urc_manager_task(void *parameter) /* [*] add recursive lock, NB AT session */ - /* execute urc handler */ OS_ASSERT(OS_NULL != handle_msg.func); handle_msg.func(handle_msg.regist_cb, handle_msg.data, handle_msg.len); - /* [*] unlock */ /* free buffer alloced in bc28_urc_receiver */ @@ -660,19 +647,19 @@ static void bc28_urc_manager_task(void *parameter) } static at_urc_t bc28_nb_urc_table[] = { - {.prefix = "+MIPLDISCOVER:", .suffix = "\r\n", .func = bc28_urc_receiver}, - {.prefix = "+MIPLOBSERVE:", .suffix = "\r\n", .func = bc28_urc_receiver}, - {.prefix = "+MIPLREAD:", .suffix = "\r\n", .func = bc28_urc_receiver}, - {.prefix = "+MIPLWRITE:", .suffix = "\r\n", .func = bc28_urc_receiver}, - {.prefix = "+MIPLEXECUTE:", .suffix = "\r\n", .func = bc28_urc_receiver}, + {.prefix = "+MIPLDISCOVER:", .suffix = "\r\n", .func = bc28_urc_receiver}, + {.prefix = "+MIPLOBSERVE:", .suffix = "\r\n", .func = bc28_urc_receiver}, + {.prefix = "+MIPLREAD:", .suffix = "\r\n", .func = bc28_urc_receiver}, + {.prefix = "+MIPLWRITE:", .suffix = "\r\n", .func = bc28_urc_receiver}, + {.prefix = "+MIPLEXECUTE:", .suffix = "\r\n", .func = bc28_urc_receiver}, {.prefix = "+MIPLPARAMETER:", .suffix = "\r\n", .func = bc28_urc_receiver}, - {.prefix = "+MIPLEVENT:", .suffix = "\r\n", .func = bc28_urc_receiver}, + {.prefix = "+MIPLEVENT:", .suffix = "\r\n", .func = bc28_urc_receiver}, }; os_err_t bc28_onenetnb_init(mo_bc28_t *module) { OS_ASSERT(OS_NULL != module); - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = OS_NULL; module->regist_cb = os_calloc(1, sizeof(mo_onenet_cb_t)); @@ -684,9 +671,7 @@ os_err_t bc28_onenetnb_init(mo_bc28_t *module) } /* create mq for urc manager */ - bc28_nb_mq = os_mq_create(BC28_URC_MQ_NAME, - sizeof(bc28_onenet_mq_msg_t), - BC28_URC_MQ_MSGNUM_MAX); + bc28_nb_mq = os_mq_create(BC28_URC_MQ_NAME, sizeof(bc28_onenet_mq_msg_t), BC28_URC_MQ_MSGNUM_MAX); if (OS_NULL == bc28_nb_mq) { ERROR("Module %s NB mq create failed, no enough memory!", module->parent.name); @@ -695,13 +680,13 @@ os_err_t bc28_onenetnb_init(mo_bc28_t *module) } /* create&start urc manager task */ - result = os_task_init(&bc28_nb_manager_task, - BC28_URC_MANAGER_TASK_NAME, - bc28_urc_manager_task, - OS_NULL, - bc28_nb_manager_task_stack, - BC28_URC_MANAGER_STACK_SIZE, - BC28_URC_MANAGER_TASK_PRIORITY); + result = os_task_init(&bc28_nb_manager_task, + BC28_URC_MANAGER_TASK_NAME, + bc28_urc_manager_task, + OS_NULL, + bc28_nb_manager_task_stack, + BC28_URC_MANAGER_STACK_SIZE, + BC28_URC_MANAGER_TASK_PRIORITY); if (OS_EOK != result) { ERROR("Module %s NB create manager task failed[%d]!", module->parent.name, result); @@ -745,22 +730,19 @@ void bc28_onenetnb_deinit(mo_bc28_t *module) OS_ASSERT(OS_NULL != bc28_nb_mq); bc28_onenet_mq_msg_t handle_msg; - os_err_t result = OS_ERROR; - os_size_t recv_size = 0; + os_err_t result = OS_ERROR; + os_size_t recv_size = 0; /* free buff in mq which alloced in bc28_urc_receiver */ while (OS_TRUE) { memset(&handle_msg, 0, sizeof(bc28_onenet_mq_msg_t)); - result = os_mq_recv(bc28_nb_mq, - &handle_msg, - sizeof(handle_msg), - OS_NO_WAIT, - &recv_size); - if (OS_EOK != result) break; + result = os_mq_recv(bc28_nb_mq, &handle_msg, sizeof(handle_msg), OS_NO_WAIT, &recv_size); + if (OS_EOK != result) + break; os_free((void *)handle_msg.data); } - + /* auto deinit urc manager task */ // os_mq_control(bc28_nb_mq, OS_IPC_CMD_RESET, OS_NULL); /* TODO make sure */ os_mq_destroy(bc28_nb_mq); @@ -784,14 +766,11 @@ os_err_t bc28_onenetnb_all(mo_object_t *module, os_int32_t timeout, void *resp, { OS_ASSERT(module != OS_NULL); OS_ASSERT(format != OS_NULL); - + at_parser_t *parser = &module->parser; char resp_buff[256] = {0}; - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .line_num = 0, - .timeout = timeout}; + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .line_num = 0, .timeout = timeout}; if (at_parser_exec_cmd_valist(parser, &at_resp, format, args) == OS_EOK) { diff --git a/components/molink/module/bc28/source/bc28_ping.c b/components/molink/module/bc28/source/bc28_ping.c index 321732c8..f784fe8e 100644 --- a/components/molink/module/bc28/source/bc28_ping.c +++ b/components/molink/module/bc28/source/bc28_ping.c @@ -27,7 +27,8 @@ #ifdef BC28_USING_PING_OPS -extern os_err_t bc28_ping_handler(mo_object_t *module, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); +extern os_err_t +bc28_ping_handler(mo_object_t *module, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); os_err_t bc28_ping(mo_object_t *module, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { diff --git a/components/molink/module/bc95/include/bc95.h b/components/molink/module/bc95/include/bc95.h index c2b202ff..0384592b 100644 --- a/components/molink/module/bc95/include/bc95.h +++ b/components/molink/module/bc95/include/bc95.h @@ -65,30 +65,30 @@ extern "C" { #endif #ifndef BC95_RECV_BUFF_LEN -#define BC95_RECV_BUFF_LEN (1500) +#define BC95_RECV_BUFF_LEN (1500) #endif #ifndef BC95_NETCONN_NUM -#define BC95_NETCONN_NUM (5) /* module service occupied 2 socket */ +#define BC95_NETCONN_NUM (5) /* module service occupied 2 socket */ #endif typedef struct mo_bc95 { - mo_object_t parent; + mo_object_t parent; #ifdef BC95_USING_NETCONN_OPS - mo_netconn_t netconn[BC95_NETCONN_NUM]; - os_mutex_t netconn_lock; - char *netconn_data; - os_event_t netconn_evt; + mo_netconn_t netconn[BC95_NETCONN_NUM]; + os_mutex_t netconn_lock; + char *netconn_data; + os_event_t netconn_evt; #endif /* BC95_USING_NETCONN_OPS */ #ifdef BC95_USING_ONENET_NB_OPS - mo_onenet_cb_t *regist_cb; /* module onenet register callback */ -#endif /* BC95_USING_ONENET_NB_OPS */ + mo_onenet_cb_t *regist_cb; /* module onenet register callback */ +#endif /* BC95_USING_ONENET_NB_OPS */ } mo_bc95_t; mo_object_t *module_bc95_create(const char *name, void *parser_config); -os_err_t module_bc95_destroy(mo_object_t *self); +os_err_t module_bc95_destroy(mo_object_t *self); #endif /* MOLINK_USING_BC95 */ diff --git a/components/molink/module/bc95/include/bc95_netconn.h b/components/molink/module/bc95/include/bc95_netconn.h index bb1de3ba..82831b49 100644 --- a/components/molink/module/bc95/include/bc95_netconn.h +++ b/components/molink/module/bc95/include/bc95_netconn.h @@ -33,13 +33,13 @@ extern "C" { #ifdef BC95_USING_NETCONN_OPS mo_netconn_t *bc95_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t bc95_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t bc95_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t bc95_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t bc95_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t bc95_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t bc95_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef BC95_USING_DNS -os_err_t bc95_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr); +os_err_t bc95_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr); #endif -os_err_t bc95_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t bc95_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); #endif /* BC95_USING_NETCONN_OPS */ #ifdef __cplusplus diff --git a/components/molink/module/bc95/include/bc95_onenet_nb.h b/components/molink/module/bc95/include/bc95_onenet_nb.h index 6d21f1b9..48cda20c 100644 --- a/components/molink/module/bc95/include/bc95_onenet_nb.h +++ b/components/molink/module/bc95/include/bc95_onenet_nb.h @@ -32,8 +32,10 @@ extern "C" { #ifdef BC95_USING_ONENET_NB_OPS -os_err_t bc95_onenetnb_get_config(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); -os_err_t bc95_onenetnb_set_config(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); +os_err_t +bc95_onenetnb_get_config(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); +os_err_t +bc95_onenetnb_set_config(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); os_err_t bc95_onenetnb_create(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); os_err_t bc95_onenetnb_delete(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); @@ -42,12 +44,16 @@ os_err_t bc95_onenetnb_delobj(mo_object_t *module, os_int32_t timeout, void *res os_err_t bc95_onenetnb_open(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); os_err_t bc95_onenetnb_close(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); -os_err_t bc95_onenetnb_discoverrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); -os_err_t bc95_onenetnb_observersp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); +os_err_t +bc95_onenetnb_discoverrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); +os_err_t +bc95_onenetnb_observersp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); os_err_t bc95_onenetnb_readrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); os_err_t bc95_onenetnb_writersp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); -os_err_t bc95_onenetnb_executersp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); -os_err_t bc95_onenetnb_parameterrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); +os_err_t +bc95_onenetnb_executersp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); +os_err_t +bc95_onenetnb_parameterrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); os_err_t bc95_onenetnb_notify(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); os_err_t bc95_onenetnb_update(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args); diff --git a/components/molink/module/bc95/source/bc95.c b/components/molink/module/bc95/source/bc95.c index 6bd00cc9..35efa8a0 100644 --- a/components/molink/module/bc95/source/bc95.c +++ b/components/molink/module/bc95/source/bc95.c @@ -29,7 +29,7 @@ #include #define MO_LOG_TAG "bc95" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_BC95 @@ -38,12 +38,12 @@ #ifdef BC95_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = bc95_at_test, - .get_imei = bc95_get_imei, - .get_imsi = bc95_get_imsi, - .get_iccid = bc95_get_iccid, - .get_cfun = bc95_get_cfun, - .set_cfun = bc95_set_cfun, + .at_test = bc95_at_test, + .get_imei = bc95_get_imei, + .get_imsi = bc95_get_imsi, + .get_iccid = bc95_get_iccid, + .get_cfun = bc95_get_cfun, + .set_cfun = bc95_set_cfun, }; #endif /* BC95_USING_GENERAL_OPS */ @@ -51,34 +51,34 @@ static const struct mo_general_ops gs_general_ops = { extern void bc95_netserv_init(mo_bc95_t *module); static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = bc95_set_attach, - .get_attach = bc95_get_attach, - .set_reg = bc95_set_reg, - .get_reg = bc95_get_reg, - .set_cgact = bc95_set_cgact, - .get_cgact = bc95_get_cgact, - .get_csq = bc95_get_csq, - .get_radio = bc95_get_radio, - .set_psm = bc95_set_psm, - .get_psm = bc95_get_psm, - .set_edrx_cfg = bc95_set_edrx_cfg, - .get_edrx_cfg = bc95_get_edrx_cfg, - .get_edrx_dynamic = bc95_get_edrx_dynamic, + .set_attach = bc95_set_attach, + .get_attach = bc95_get_attach, + .set_reg = bc95_set_reg, + .get_reg = bc95_get_reg, + .set_cgact = bc95_set_cgact, + .get_cgact = bc95_get_cgact, + .get_csq = bc95_get_csq, + .get_radio = bc95_get_radio, + .set_psm = bc95_set_psm, + .get_psm = bc95_get_psm, + .set_edrx_cfg = bc95_set_edrx_cfg, + .get_edrx_cfg = bc95_get_edrx_cfg, + .get_edrx_dynamic = bc95_get_edrx_dynamic, }; #endif /* BC95_USING_NETSERV_OPS */ #ifdef BC95_USING_PING_OPS static const struct mo_ping_ops gs_ping_ops = { - .ping = bc95_ping, + .ping = bc95_ping, }; #endif /* BC95_USING_PING_OPS */ #ifdef BC95_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = bc95_ifconfig, - .get_ipaddr = bc95_get_ipaddr, - .set_dnsserver = bc95_set_dnsserver, - .get_dnsserver = bc95_get_dnsserver, + .ifconfig = bc95_ifconfig, + .get_ipaddr = bc95_get_ipaddr, + .set_dnsserver = bc95_set_dnsserver, + .get_dnsserver = bc95_get_dnsserver, }; #endif /* BC95_USING_IFCONFIG_OPS */ @@ -86,39 +86,39 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void bc95_netconn_init(mo_bc95_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = bc95_netconn_create, - .destroy = bc95_netconn_destroy, + .create = bc95_netconn_create, + .destroy = bc95_netconn_destroy, #ifdef BC95_USING_DNS - .gethostbyname = bc95_netconn_gethostbyname, + .gethostbyname = bc95_netconn_gethostbyname, #endif - .connect = bc95_netconn_connect, - .send = bc95_netconn_send, - .get_info = bc95_netconn_get_info, + .connect = bc95_netconn_connect, + .send = bc95_netconn_send, + .get_info = bc95_netconn_get_info, }; #endif /* BC95_USING_NETCONN_OPS */ #ifdef BC95_USING_ONENET_NB_OPS extern os_err_t bc95_onenetnb_init(mo_bc95_t *module); -extern void bc95_onenetnb_deinit(mo_bc95_t *module); +extern void bc95_onenetnb_deinit(mo_bc95_t *module); static const mo_onenet_ops_t gs_onenet_ops = { - .onenetnb_get_config = bc95_onenetnb_get_config, - .onenetnb_set_config = bc95_onenetnb_set_config, - .onenetnb_create = bc95_onenetnb_create, - .onenetnb_delete = bc95_onenetnb_delete, - .onenetnb_addobj = bc95_onenetnb_addobj, - .onenetnb_delobj = bc95_onenetnb_delobj, - .onenetnb_open = bc95_onenetnb_open, - .onenetnb_close = bc95_onenetnb_close, - .onenetnb_discoverrsp = bc95_onenetnb_discoverrsp, - .onenetnb_observersp = bc95_onenetnb_observersp, - .onenetnb_readrsp = bc95_onenetnb_readrsp, - .onenetnb_writersp = bc95_onenetnb_writersp, - .onenetnb_executersp = bc95_onenetnb_executersp, + .onenetnb_get_config = bc95_onenetnb_get_config, + .onenetnb_set_config = bc95_onenetnb_set_config, + .onenetnb_create = bc95_onenetnb_create, + .onenetnb_delete = bc95_onenetnb_delete, + .onenetnb_addobj = bc95_onenetnb_addobj, + .onenetnb_delobj = bc95_onenetnb_delobj, + .onenetnb_open = bc95_onenetnb_open, + .onenetnb_close = bc95_onenetnb_close, + .onenetnb_discoverrsp = bc95_onenetnb_discoverrsp, + .onenetnb_observersp = bc95_onenetnb_observersp, + .onenetnb_readrsp = bc95_onenetnb_readrsp, + .onenetnb_writersp = bc95_onenetnb_writersp, + .onenetnb_executersp = bc95_onenetnb_executersp, .onenetnb_parameterrsp = bc95_onenetnb_parameterrsp, - .onenetnb_notify = bc95_onenetnb_notify, - .onenetnb_update = bc95_onenetnb_update, - .onenetnb_cb_register = bc95_onenetnb_cb_register, + .onenetnb_notify = bc95_onenetnb_notify, + .onenetnb_update = bc95_onenetnb_update, + .onenetnb_cb_register = bc95_onenetnb_cb_register, }; #endif /* BC95_USING_ONENET_OPS */ @@ -144,7 +144,7 @@ static os_err_t bc95_at_init(mo_object_t *self) mo_object_t *module_bc95_create(const char *name, void *parser_config) { os_err_t result = OS_ERROR; - + mo_bc95_t *module = (mo_bc95_t *)os_calloc(1, sizeof(mo_bc95_t)); if (OS_NULL == module) { @@ -197,7 +197,7 @@ mo_object_t *module_bc95_create(const char *name, void *parser_config) } module->parent.ops_table[MODULE_OPS_ONENET_NB] = &gs_onenet_ops; #endif /* BC95_USING_ONENET_NB_OPS */ - + __exit: if (OS_EOK != result) { @@ -221,7 +221,7 @@ __exit: } os_free(module); - + return OS_NULL; } @@ -262,12 +262,12 @@ int bc95_auto_create(void) ERROR("Auto create failed, Can not find BC95 interface device %s!", BC95_DEVICE_NAME); return OS_ERROR; } - - uart_config.baud_rate = BC95_DEVICE_RATE; + + uart_config.baud_rate = BC95_DEVICE_RATE; os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = BC95_NAME, + mo_parser_config_t parser_config = {.parser_name = BC95_NAME, .parser_device = device, .recv_buff_len = BC95_RECV_BUFF_LEN}; diff --git a/components/molink/module/bc95/source/bc95_general.c b/components/molink/module/bc95/source/bc95_general.c index 596dcac3..920b5142 100644 --- a/components/molink/module/bc95/source/bc95_general.c +++ b/components/molink/module/bc95/source/bc95_general.c @@ -24,12 +24,12 @@ #include "bc95_general.h" #define MO_LOG_TAG "bc95.general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef BC95_USING_GENERAL_OPS -#define BC95_GENERAL_TIMEOUT_DFT (1 * OS_TICK_PER_SECOND) +#define BC95_GENERAL_TIMEOUT_DFT (1 * OS_TICK_PER_SECOND) os_err_t bc95_at_test(mo_object_t *module) { diff --git a/components/molink/module/bc95/source/bc95_ifconfig.c b/components/molink/module/bc95/source/bc95_ifconfig.c index 170e9083..6d54062b 100644 --- a/components/molink/module/bc95/source/bc95_ifconfig.c +++ b/components/molink/module/bc95/source/bc95_ifconfig.c @@ -31,7 +31,7 @@ #ifdef BC95_USING_IFCONFIG_OPS #define MO_LOG_TAG "bc95.ifconfig" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define BC95_IFCONFIG_INVALID_DEF (-1) @@ -57,12 +57,12 @@ os_err_t bc95_ifconfig(mo_object_t *module) } os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t ber = 0; if (bc95_get_csq(module, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; } os_kprintf("\r\nLIST AT MODULE INFORMATION\r\n"); @@ -89,10 +89,10 @@ os_err_t bc95_ifconfig(mo_object_t *module) os_err_t bc95_set_dnsserver(mo_object_t *module, dns_server_t dns) { - /* BC95 must set usable dns server befor QDNS(gethostbyname), + /* BC95 must set usable dns server befor QDNS(gethostbyname), otherwise both func will not be reachable before reboot! */ at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -119,16 +119,16 @@ os_err_t bc95_set_dnsserver(mo_object_t *module, dns_server_t dns) { result = at_parser_exec_cmd(parser, &resp, "AT+QIDNSCFG=\"%s\",\"%s\"", dns.primary_dns, dns.secondary_dns); } - + return result; } os_err_t bc95_get_dnsserver(mo_object_t *module, dns_server_t *dns) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; - char primary_dns[IPADDR_MAX_STR_LEN + 1] = {0}; + char primary_dns[IPADDR_MAX_STR_LEN + 1] = {0}; char secondary_dns[IPADDR_MAX_STR_LEN + 1] = {0}; if (OS_NULL == parser) @@ -145,9 +145,7 @@ os_err_t bc95_get_dnsserver(mo_object_t *module, dns_server_t *dns) char resp_buff[4 * AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 16 * OS_TICK_PER_SECOND}; + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 16 * OS_TICK_PER_SECOND}; result = at_parser_exec_cmd(parser, &at_resp, "AT+QIDNSCFG?"); @@ -178,10 +176,10 @@ __exit: os_err_t bc95_get_ipaddr(mo_object_t *module, char ip[]) { at_parser_t *parser = &module->parser; - os_int8_t ucid = BC95_IFCONFIG_INVALID_DEF; - os_int8_t len = BC95_IFCONFIG_INVALID_DEF; + os_int8_t ucid = BC95_IFCONFIG_INVALID_DEF; + os_int8_t len = BC95_IFCONFIG_INVALID_DEF; - char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; + char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[2 * AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; @@ -215,7 +213,7 @@ os_err_t bc95_get_ipaddr(mo_object_t *module, char ip[]) } __exit: - + return result; } diff --git a/components/molink/module/bc95/source/bc95_netconn.c b/components/molink/module/bc95/source/bc95_netconn.c index 18bf403b..88811184 100644 --- a/components/molink/module/bc95/source/bc95_netconn.c +++ b/components/molink/module/bc95/source/bc95_netconn.c @@ -32,37 +32,37 @@ #ifdef BC95_USING_NETCONN_OPS #define MO_LOG_TAG "bc95.netconn" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" -#define BC95_EVENT_DOMAIN_OK (1L << 0) -#define BC95_EVENT_DOMAIN_FAIL (1L << 1) -#ifdef BC95_USING_PING_OPS -#define BC95_EVENT_PING_OK (1L << 2) -#define BC95_EVENT_PING_FAIL (1L << 3) +#define BC95_EVENT_DOMAIN_OK (1L << 0) +#define BC95_EVENT_DOMAIN_FAIL (1L << 1) +#ifdef BC95_USING_PING_OPS +#define BC95_EVENT_PING_OK (1L << 2) +#define BC95_EVENT_PING_FAIL (1L << 3) #endif /* BC95_USING_PING_OPS */ -#define PROTOCOL_TYPE_TCP (6) -#define PROTOCOL_TYPE_UDP (17) -#define SEND_DATA_MAX_SIZE (1358) -#define BC95_CONN_ID_NULL (-1) -#define BC95_SEND_BLOCK_SIZE (128) - -#ifdef BC95_USING_PING_OPS -#define BC95_MIN_PING_PKG_LEN (12) -#define BC95_MAX_PING_PKG_LEN (1500) -#define BC95_MIN_PING_TIMEOUT (10) -#define BC95_MAX_PING_TIMEOUT (600000) -#define BC95_PING_INVALID_DEF (-1) -#define BC95_PING_BUFFER_SIZE (128) +#define PROTOCOL_TYPE_TCP (6) +#define PROTOCOL_TYPE_UDP (17) +#define SEND_DATA_MAX_SIZE (1358) +#define BC95_CONN_ID_NULL (-1) +#define BC95_SEND_BLOCK_SIZE (128) + +#ifdef BC95_USING_PING_OPS +#define BC95_MIN_PING_PKG_LEN (12) +#define BC95_MAX_PING_PKG_LEN (1500) +#define BC95_MIN_PING_TIMEOUT (10) +#define BC95_MAX_PING_TIMEOUT (600000) +#define BC95_PING_INVALID_DEF (-1) +#define BC95_PING_BUFFER_SIZE (128) #endif /* BC95_USING_PING_OPS */ -#define BC95_NETCONN_MQ_NAME "bc95_nc_mq" +#define BC95_NETCONN_MQ_NAME "bc95_nc_mq" #ifndef BC95_NETCONN_MQ_MSG_SIZE #define BC95_NETCONN_MQ_MSG_SIZE (sizeof(mo_notconn_msg_t)) #endif /* BC95_NETCONN_MQ_MSG_SIZE */ #ifndef BC95_NETCONN_MQ_MSG_MAX -#define BC95_NETCONN_MQ_MSG_MAX (5) +#define BC95_NETCONN_MQ_MSG_MAX (5) #endif /* BC95_NETCONN_MQ_MSG_MAX */ static os_err_t bc95_lock(os_mutex_t *mutex) @@ -124,16 +124,16 @@ os_err_t bc95_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_bc95_t *bc95 = os_container_of(module, mo_bc95_t, parent); info->netconn_array = bc95->netconn; - info->netconn_nums = sizeof(bc95->netconn) / sizeof(bc95->netconn[0]); + info->netconn_nums = sizeof(bc95->netconn) / sizeof(bc95->netconn[0]); return OS_EOK; } mo_netconn_t *bc95_netconn_create(mo_object_t *module, mo_netconn_type_t type) { - mo_bc95_t *bc95 = os_container_of(module, mo_bc95_t, parent); + mo_bc95_t *bc95 = os_container_of(module, mo_bc95_t, parent); at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; bc95_lock(&bc95->netconn_lock); @@ -191,9 +191,7 @@ mo_netconn_t *bc95_netconn_create(mo_object_t *module, mo_netconn_type_t type) return OS_NULL; } - netconn->mq = os_mq_create(BC95_NETCONN_MQ_NAME, - BC95_NETCONN_MQ_MSG_SIZE, - BC95_NETCONN_MQ_MSG_MAX); + netconn->mq = os_mq_create(BC95_NETCONN_MQ_NAME, BC95_NETCONN_MQ_MSG_SIZE, BC95_NETCONN_MQ_MSG_MAX); if (OS_NULL == netconn->mq) { ERROR("%s message queue create failed, no enough memory.", module->name); @@ -210,9 +208,9 @@ mo_netconn_t *bc95_netconn_create(mo_object_t *module, mo_netconn_type_t type) os_err_t bc95_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; - os_int32_t conn_id = BC95_CONN_ID_NULL; + at_parser_t *parser = &module->parser; + os_err_t result = OS_ERROR; + os_int32_t conn_id = BC95_CONN_ID_NULL; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -228,8 +226,8 @@ os_err_t bc95_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) if (result != OS_EOK) { ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + module->name, + (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); return result; } break; @@ -244,12 +242,12 @@ os_err_t bc95_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) netconn->mq = OS_NULL; } - conn_id = netconn->connect_id; - netconn->connect_id = BC95_CONN_ID_NULL; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + conn_id = netconn->connect_id; + netconn->connect_id = BC95_CONN_ID_NULL; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; - netconn->local_port = 0; + netconn->local_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); INFO("Module %s netconn_id: %d destroyed", module->name, conn_id); @@ -260,17 +258,15 @@ os_err_t bc95_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) #ifdef BC95_USING_DNS os_err_t bc95_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr) { - os_err_t result = OS_EOK; - os_uint32_t event = 0; + os_err_t result = OS_EOK; + os_uint32_t event = 0; at_parser_t *parser = &module->parser; - mo_bc95_t *bc95 = os_container_of(module, mo_bc95_t, parent); + mo_bc95_t *bc95 = os_container_of(module, mo_bc95_t, parent); char resp_buff[4 * AT_RESP_BUFF_SIZE_DEF] = {0}; - char addr_str[IPADDR_MAX_STR_LEN + 1] = {0}; + char addr_str[IPADDR_MAX_STR_LEN + 1] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 20 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; bc95_lock(&bc95->netconn_lock); @@ -350,7 +346,7 @@ static os_err_t bc95_tcp_connect(at_parser_t *parser, os_int32_t connect_id, cha os_err_t bc95_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -366,7 +362,7 @@ os_err_t bc95_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_add #ifdef BC95_USING_UDP case NETCONN_TYPE_UDP: - result = OS_EOK; /* UDP does not need to connect */ + result = OS_EOK; /* UDP does not need to connect */ break; #endif @@ -383,7 +379,7 @@ os_err_t bc95_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_add ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%u successfully!", module->name, remote_ip, port); @@ -392,8 +388,8 @@ os_err_t bc95_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_add static os_size_t bc95_single_packet_send(at_parser_t *parser, const char *data, os_size_t size) { - os_size_t sent_size = 0; /* raw data sent size */ - os_size_t curr_pkt_size = 0; /* raw data current packet size */ + os_size_t sent_size = 0; /* raw data sent size */ + os_size_t curr_pkt_size = 0; /* raw data current packet size */ char hex_str_buff[BC95_SEND_BLOCK_SIZE] = {0}; @@ -418,17 +414,17 @@ __exit: static os_size_t bc95_hexdata_send(at_parser_t *parser, mo_netconn_t *netconn, const char *data, os_size_t size) { - os_err_t result = OS_EOK; - os_int32_t connect_id = BC95_CONN_ID_NULL; - os_size_t sent_size = 0; - os_size_t cur_pkt_size = 0; - os_size_t cnt = 0; + os_err_t result = OS_EOK; + os_int32_t connect_id = BC95_CONN_ID_NULL; + os_size_t sent_size = 0; + os_size_t cur_pkt_size = 0; + os_size_t cnt = 0; - char send_cmd[AT_RESP_BUFF_SIZE_DEF] = {0}; + char send_cmd[AT_RESP_BUFF_SIZE_DEF] = {0}; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = AT_RESP_BUFF_SIZE_DEF, .timeout = 10 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = AT_RESP_BUFF_SIZE_DEF, .timeout = 10 * OS_TICK_PER_SECOND}; strncpy(remote_ip, inet_ntoa(netconn->remote_ip), IPADDR_MAX_STR_LEN); @@ -454,19 +450,17 @@ static os_size_t bc95_hexdata_send(at_parser_t *parser, mo_netconn_t *netconn, c if (NETCONN_TYPE_TCP == netconn->type) { - snprintf(send_cmd, sizeof(send_cmd), - "AT+NSOSD=%d,%d,", - netconn->connect_id, - (int)cur_pkt_size); + snprintf(send_cmd, sizeof(send_cmd), "AT+NSOSD=%d,%d,", netconn->connect_id, (int)cur_pkt_size); } else /* other cases judged by upper function */ { - snprintf(send_cmd, sizeof(send_cmd), - "AT+NSOST=%d,%s,%d,%hu,", + snprintf(send_cmd, + sizeof(send_cmd), + "AT+NSOST=%d,%s,%d,%hu,", netconn->connect_id, remote_ip, netconn->remote_port, - (int)cur_pkt_size); + (int)cur_pkt_size); } /* send cmd prefix */ @@ -505,22 +499,18 @@ __exit: if (result != OS_EOK) { - ERROR("Module %s netconn %d send %d bytes data failed!", - parser->name, - netconn->connect_id, - cur_pkt_size); + ERROR("Module %s netconn %d send %d bytes data failed!", parser->name, netconn->connect_id, cur_pkt_size); return 0; } return sent_size; } - os_size_t bc95_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_size_t sent_size = 0; - mo_bc95_t *bc95 = os_container_of(module, mo_bc95_t, parent); + at_parser_t *parser = &module->parser; + os_size_t sent_size = 0; + mo_bc95_t *bc95 = os_container_of(module, mo_bc95_t, parent); if (OS_EOK != bc95_lock(&bc95->netconn_lock)) { @@ -547,19 +537,20 @@ os_size_t bc95_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const ch } #ifdef BC95_USING_PING_OPS -os_err_t bc95_ping_handler(mo_object_t *module, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) +os_err_t +bc95_ping_handler(mo_object_t *module, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_int16_t ttl = BC95_PING_INVALID_DEF; - ip_addr_t addr = {0}; - os_uint32_t req_time = 0; - os_uint32_t event = 0; - mo_bc95_t *bc95 = os_container_of(module, mo_bc95_t, parent); - - char ip_send[IPADDR_MAX_STR_LEN + 1] = {0}; - char ip_recv[IPADDR_MAX_STR_LEN + 1] = {0}; - char ret_buff[BC95_PING_BUFFER_SIZE] = {0}; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_int16_t ttl = BC95_PING_INVALID_DEF; + ip_addr_t addr = {0}; + os_uint32_t req_time = 0; + os_uint32_t event = 0; + mo_bc95_t *bc95 = os_container_of(module, mo_bc95_t, parent); + + char ip_send[IPADDR_MAX_STR_LEN + 1] = {0}; + char ip_recv[IPADDR_MAX_STR_LEN + 1] = {0}; + char ret_buff[BC95_PING_BUFFER_SIZE] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; bc95_lock(&bc95->netconn_lock); @@ -573,14 +564,18 @@ os_err_t bc95_ping_handler(mo_object_t *module, const char *host, os_uint16_t le if ((len < BC95_MIN_PING_PKG_LEN) || (len > BC95_MAX_PING_PKG_LEN)) { ERROR("BC95 ping: ping package len[%d] is out of range[%d, %d].", - len, BC95_MIN_PING_PKG_LEN, BC95_MAX_PING_PKG_LEN); + len, + BC95_MIN_PING_PKG_LEN, + BC95_MAX_PING_PKG_LEN); return OS_ERROR; } if ((timeout < BC95_MIN_PING_TIMEOUT) || (timeout > BC95_MAX_PING_TIMEOUT)) { ERROR("BC95 ping: user set ping timeout value %ums is out of range[%dms, %dms].", - timeout, BC95_MIN_PING_TIMEOUT, BC95_MAX_PING_TIMEOUT); + timeout, + BC95_MIN_PING_TIMEOUT, + BC95_MAX_PING_TIMEOUT); return OS_ERROR; } @@ -604,9 +599,9 @@ os_err_t bc95_ping_handler(mo_object_t *module, const char *host, os_uint16_t le * Module only support IPV4, BC95 only support Dotted Dec/Hex/Oct Notation * Because unable to synchronize time between board & module, 5 seconds reserved * **/ - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; + .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; os_event_clear(&bc95->netconn_evt, BC95_EVENT_PING_OK | BC95_EVENT_PING_FAIL); @@ -657,9 +652,9 @@ os_err_t bc95_ping_handler(mo_object_t *module, const char *host, os_uint16_t le { inet_aton(ip_recv, &(resp->ip_addr)); resp->data_len = len; - resp->ttl = ttl; - resp->time = req_time; - result = OS_EOK; + resp->ttl = ttl; + resp->time = req_time; + result = OS_EOK; } } @@ -677,9 +672,9 @@ static void urc_ping_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_bc95_t *bc95 = os_container_of(module, mo_bc95_t, parent); + mo_bc95_t *bc95 = os_container_of(module, mo_bc95_t, parent); if (OS_NULL == bc95->netconn_data) { @@ -717,7 +712,7 @@ static void urc_ping_err_func(struct at_parser *parser, const char *data, os_siz OS_ASSERT(OS_NULL != data); mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_bc95_t *bc95 = os_container_of(module, mo_bc95_t, parent); + mo_bc95_t *bc95 = os_container_of(module, mo_bc95_t, parent); ERROR("%s-%d: ping error[%s]", __func__, __LINE__, data); @@ -759,7 +754,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; + os_int32_t data_size = 0; sscanf(data, "+NSONMI:%d,%*[^,],%*d,%d,", &connect_id, &data_size); @@ -811,9 +806,9 @@ static void urc_dns_func(struct at_parser *parser, const char *data, os_size_t s OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_bc95_t *bc95 = os_container_of(module, mo_bc95_t, parent); + mo_bc95_t *bc95 = os_container_of(module, mo_bc95_t, parent); char ret_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; if (OS_NULL == bc95->netconn_data) @@ -855,13 +850,13 @@ __exit: static at_urc_t netconn_urc_table[] = { {.prefix = "+NSOCLI:", .suffix = "\r\n", .func = urc_close_func}, - {.prefix = "+NSONMI:", .suffix = "\r\n", .func = urc_recv_func }, - {.prefix = "+QDNS:", .suffix = "\r\n", .func = urc_dns_func }, + {.prefix = "+NSONMI:", .suffix = "\r\n", .func = urc_recv_func}, + {.prefix = "+QDNS:", .suffix = "\r\n", .func = urc_dns_func}, }; #ifdef BC95_USING_PING_OPS static at_urc_t ping_urc_table[] = { - {.prefix = "+NPING:", .suffix = "\r\n", .func = urc_ping_func }, + {.prefix = "+NPING:", .suffix = "\r\n", .func = urc_ping_func}, {.prefix = "+NPINGERR:", .suffix = "\r\n", .func = urc_ping_err_func}, }; #endif /* BC95_USING_PING_OPS */ diff --git a/components/molink/module/bc95/source/bc95_netserv.c b/components/molink/module/bc95/source/bc95_netserv.c index 3f36fe3d..53f135bd 100644 --- a/components/molink/module/bc95/source/bc95_netserv.c +++ b/components/molink/module/bc95/source/bc95_netserv.c @@ -29,13 +29,13 @@ #include #define MO_LOG_TAG "bc95.netserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef BC95_USING_NETSERV_OPS -#define BC95_EARFCN_MAX (65535) -#define BC95_PCI_MAX (0x1F7) +#define BC95_EARFCN_MAX (65535) +#define BC95_PCI_MAX (0x1F7) os_err_t bc95_set_attach(mo_object_t *module, os_uint8_t attach_stat) { @@ -62,7 +62,7 @@ os_err_t bc95_get_attach(mo_object_t *module, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) { ERROR("Get %s module attach state failed", module->name); return OS_ERROR; @@ -229,17 +229,19 @@ __exit: os_err_t bc95_set_psm(mo_object_t *module, mo_psm_info_t info) { at_parser_t *parser = &module->parser; - + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 1 * OS_TICK_PER_SECOND}; - return at_parser_exec_cmd(parser, &resp, "AT+CPSMS=%d,%s,%s,%s,%s", - info.psm_mode, - info.periodic_rau, - info.gprs_ready_timer, - info.periodic_tau, - info.active_time); + return at_parser_exec_cmd(parser, + &resp, + "AT+CPSMS=%d,%s,%s,%s,%s", + info.psm_mode, + info.periodic_rau, + info.gprs_ready_timer, + info.periodic_tau, + info.active_time); } os_err_t bc95_get_psm(mo_object_t *module, mo_psm_info_t *info) @@ -257,7 +259,12 @@ os_err_t bc95_get_psm(mo_object_t *module, mo_psm_info_t *info) memset(info, 0, sizeof(mo_psm_info_t)); - if ( 0 >= at_resp_get_data_by_kw(&resp, "+CPSMS", "+CPSMS: %d,,,%[^,],%s", &info->psm_mode, info->periodic_tau, info->active_time)) + if (0 >= at_resp_get_data_by_kw(&resp, + "+CPSMS", + "+CPSMS: %d,,,%[^,],%s", + &info->psm_mode, + info->periodic_tau, + info->active_time)) { ERROR("Get %s module psm info failed", module->name); return OS_ERROR; @@ -269,14 +276,12 @@ os_err_t bc95_get_psm(mo_object_t *module, mo_psm_info_t *info) os_err_t bc95_set_edrx_cfg(mo_object_t *module, mo_edrx_cfg_t cfg) { at_parser_t *parser = &module->parser; - + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 1 * OS_TICK_PER_SECOND}; - return at_parser_exec_cmd(parser, &resp, "AT+CEDRXS=%d,5,%s", - cfg.mode, - cfg.edrx.req_edrx_value); + return at_parser_exec_cmd(parser, &resp, "AT+CEDRXS=%d,5,%s", cfg.mode, cfg.edrx.req_edrx_value); } os_err_t bc95_get_edrx_cfg(mo_object_t *module, mo_edrx_t *edrx_local) @@ -295,9 +300,11 @@ os_err_t bc95_get_edrx_cfg(mo_object_t *module, mo_edrx_t *edrx_local) memset(edrx_local, 0, sizeof(mo_edrx_t)); - if (0 >= at_resp_get_data_by_kw(&resp, "+CEDRXS", "+CEDRXS: %d,\"%[^\"]", - &edrx_local->act_type, - edrx_local->req_edrx_value)) + if (0 >= at_resp_get_data_by_kw(&resp, + "+CEDRXS", + "+CEDRXS: %d,\"%[^\"]", + &edrx_local->act_type, + edrx_local->req_edrx_value)) { ERROR("Get %s module edrx local config failed", module->name); return OS_ERROR; @@ -322,11 +329,13 @@ os_err_t bc95_get_edrx_dynamic(mo_object_t *module, mo_edrx_t *edrx_dynamic) memset(edrx_dynamic, 0, sizeof(mo_edrx_t)); - if (0 >= at_resp_get_data_by_kw(&resp, "+CEDRXRDP", "+CEDRXRDP: %d,\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"", - &edrx_dynamic->act_type, - edrx_dynamic->req_edrx_value, - edrx_dynamic->nw_edrx_value, - edrx_dynamic->paging_time_window)) + if (0 >= at_resp_get_data_by_kw(&resp, + "+CEDRXRDP", + "+CEDRXRDP: %d,\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"", + &edrx_dynamic->act_type, + edrx_dynamic->req_edrx_value, + edrx_dynamic->nw_edrx_value, + edrx_dynamic->paging_time_window)) { ERROR("Get %s module edrx dynamic config failed", module->name); return OS_ERROR; @@ -405,11 +414,12 @@ void bc95_edrx_urc_handler(struct at_parser *parser, const char *data, os_size_t mo_edrx_t edrx_urc; memset(&edrx_urc, 0, sizeof(mo_edrx_t)); - sscanf(data, "+CEDRXP: %d,\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"", - (int *)&edrx_urc.act_type, - edrx_urc.req_edrx_value, - edrx_urc.nw_edrx_value, - edrx_urc.paging_time_window); + sscanf(data, + "+CEDRXP: %d,\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"", + (int *)&edrx_urc.act_type, + edrx_urc.req_edrx_value, + edrx_urc.nw_edrx_value, + edrx_urc.paging_time_window); INFO("Get %s module edrx urc act_type[%d]", parser->name, edrx_urc.act_type); INFO("Get %s module edrx urc req_edrx_value[%s]", parser->name, edrx_urc.req_edrx_value); INFO("Get %s module edrx urc nw_edrx_value[%s]", parser->name, edrx_urc.nw_edrx_value); @@ -419,7 +429,7 @@ void bc95_edrx_urc_handler(struct at_parser *parser, const char *data, os_size_t } static at_urc_t bc95_netserv_urc_table[] = { - {.prefix = "+CEDRXP:", .suffix = "\r\n", .func = bc95_edrx_urc_handler}, + {.prefix = "+CEDRXP:", .suffix = "\r\n", .func = bc95_edrx_urc_handler}, }; void bc95_netserv_init(mo_bc95_t *module) diff --git a/components/molink/module/bc95/source/bc95_onenet_nb.c b/components/molink/module/bc95/source/bc95_onenet_nb.c index b14a329b..432da486 100644 --- a/components/molink/module/bc95/source/bc95_onenet_nb.c +++ b/components/molink/module/bc95/source/bc95_onenet_nb.c @@ -35,50 +35,50 @@ #include #define MO_LOG_TAG "bc95.onenet_nb" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" -#define BC95_URC_HEAD_MAXLEN (16) -#define BC95_REGEX_LEN_DEFAULT (64) -#define BC95_TIMEOUT_DEFAULT (5 * OS_TICK_PER_SECOND) -#define BC95_URC_MQ_NAME "BC95_URC_MQ" -#define BC95_URC_MQ_MSGNUM_MAX (10) -#define BC95_URC_MANAGER_TASK_NAME "bc95_manager" +#define BC95_URC_HEAD_MAXLEN (16) +#define BC95_REGEX_LEN_DEFAULT (64) +#define BC95_TIMEOUT_DEFAULT (5 * OS_TICK_PER_SECOND) +#define BC95_URC_MQ_NAME "BC95_URC_MQ" +#define BC95_URC_MQ_MSGNUM_MAX (10) +#define BC95_URC_MANAGER_TASK_NAME "bc95_manager" /* ============================kconfig_options============================= */ -#ifndef BC95_URC_MANAGER_STACK_SIZE -#define BC95_URC_MANAGER_STACK_SIZE (2048) +#ifndef BC95_URC_MANAGER_STACK_SIZE +#define BC95_URC_MANAGER_STACK_SIZE (2048) #endif /* BC95_URC_MANAGER_STACK_SIZE */ #ifndef BC95_RESP_BUFF_SIZE -#define BC95_RESP_BUFF_SIZE (128) +#define BC95_RESP_BUFF_SIZE (128) #endif /* BC95_RESP_BUFF_SIZE */ #ifndef BC95_URC_MANAGER_TASK_PRIORITY -#define BC95_URC_MANAGER_TASK_PRIORITY (0x10) +#define BC95_URC_MANAGER_TASK_PRIORITY (0x10) #endif /* BC95_URC_MANAGER_TASK_PRIORITY */ /* ===========================kconfig_option_tail========================== */ -static os_mq_t *bc95_nb_mq = OS_NULL; -static os_task_t bc95_nb_manager_task; -static os_uint8_t bc95_nb_manager_task_stack[BC95_URC_MANAGER_STACK_SIZE]; +static os_mq_t *bc95_nb_mq = OS_NULL; +static os_task_t bc95_nb_manager_task; +static os_uint8_t bc95_nb_manager_task_stack[BC95_URC_MANAGER_STACK_SIZE]; -static const os_int8_t BC95_ONENETNB_INVALID_DEFAULT = -1; +static const os_int8_t BC95_ONENETNB_INVALID_DEFAULT = -1; typedef struct bc95_onenet_urc { - const char *prefix; /* URC data prefix */ - void (*func)(mo_onenet_cb_t *regist_cb, const char *data, os_size_t size); - /* URC hanlder function */ + const char *prefix; /* URC data prefix */ + void (*func)(mo_onenet_cb_t *regist_cb, const char *data, os_size_t size); + /* URC hanlder function */ } bc95_onenet_urc_t; typedef struct bc95_onenet_mq_msg { - mo_onenet_cb_t *regist_cb; /* user regist cb ptr */ - const char *data; /* URC data */ - os_size_t len; /* URC data len */ + mo_onenet_cb_t *regist_cb; /* user regist cb ptr */ + const char *data; /* URC data */ + os_size_t len; /* URC data len */ void (*func)(mo_onenet_cb_t *regist_cb, const char *data, os_size_t size); - /* URC hanlder function */ + /* URC hanlder function */ } bc95_onenet_mq_msg_t; typedef enum bc95_config_mode @@ -93,28 +93,25 @@ typedef enum bc95_config_mode BC95_ONENETNB_BUF_CONFIG, } bc95_config_mode_t; -#define CALL_BC95_BASIC_FUNC(AT_FRONT_OPT) \ -do \ -{ \ - OS_ASSERT(module != OS_NULL); \ - OS_ASSERT(format != OS_NULL); \ - \ - at_parser_t *parser = &module->parser; \ - os_err_t result = OS_EOK; \ - \ - char resp_buff[BC95_RESP_BUFF_SIZE] = {0}; \ - at_resp_t at_resp = {.buff = resp_buff, \ - .buff_size = sizeof(resp_buff), \ - .line_num = 0, \ - .timeout = timeout}; \ - \ - char tmp_format[BC95_RESP_BUFF_SIZE] = AT_FRONT_OPT; \ - strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); \ - \ - result = at_parser_exec_cmd_valist(parser, &at_resp, tmp_format, args); \ - \ - return result; \ -} while (0); +#define CALL_BC95_BASIC_FUNC(AT_FRONT_OPT) \ + do \ + { \ + OS_ASSERT(module != OS_NULL); \ + OS_ASSERT(format != OS_NULL); \ + \ + at_parser_t *parser = &module->parser; \ + os_err_t result = OS_EOK; \ + \ + char resp_buff[BC95_RESP_BUFF_SIZE] = {0}; \ + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .line_num = 0, .timeout = timeout}; \ + \ + char tmp_format[BC95_RESP_BUFF_SIZE] = AT_FRONT_OPT; \ + strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); \ + \ + result = at_parser_exec_cmd_valist(parser, &at_resp, tmp_format, args); \ + \ + return result; \ + } while (0); os_err_t bc95_onenetnb_get_config(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args) { @@ -122,21 +119,18 @@ os_err_t bc95_onenetnb_get_config(mo_object_t *module, os_int32_t timeout, void OS_ASSERT(module != OS_NULL); OS_ASSERT(resp != OS_NULL); - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_uint32_t line; - char tmp_buff[128] = {0}; - os_int32_t getline_num = 0; - os_int32_t config_mode_ref; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_uint32_t line; + char tmp_buff[128] = {0}; + os_int32_t getline_num = 0; + os_int32_t config_mode_ref; - mo_config_resp_t *config_resp = (mo_config_resp_t *)resp; + mo_config_resp_t *config_resp = (mo_config_resp_t *)resp; memset(config_resp, 0, sizeof(mo_config_resp_t)); char resp_buff[128] = {0}; - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .line_num = 0, - .timeout = timeout}; + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .line_num = 0, .timeout = timeout}; result = at_parser_exec_cmd(parser, &at_resp, "AT+MIPLCONFIG?"); if (OS_EOK != result) @@ -146,16 +140,16 @@ os_err_t bc95_onenetnb_get_config(mo_object_t *module, os_int32_t timeout, void } /* set default invalid value */ - config_resp->guide_mode_enable = BC95_ONENETNB_INVALID_DEFAULT; + config_resp->guide_mode_enable = BC95_ONENETNB_INVALID_DEFAULT; config_resp->obs_autoack_enable = BC95_ONENETNB_INVALID_DEFAULT; - config_resp->auth_enable = BC95_ONENETNB_INVALID_DEFAULT; - config_resp->dtls_enable = BC95_ONENETNB_INVALID_DEFAULT; - config_resp->write_format = BC95_ONENETNB_INVALID_DEFAULT; - config_resp->buf_cfg = BC95_ONENETNB_INVALID_DEFAULT; - config_resp->buf_urc_mode = BC95_ONENETNB_INVALID_DEFAULT; + config_resp->auth_enable = BC95_ONENETNB_INVALID_DEFAULT; + config_resp->dtls_enable = BC95_ONENETNB_INVALID_DEFAULT; + config_resp->write_format = BC95_ONENETNB_INVALID_DEFAULT; + config_resp->buf_cfg = BC95_ONENETNB_INVALID_DEFAULT; + config_resp->buf_urc_mode = BC95_ONENETNB_INVALID_DEFAULT; /* return mode with 7 lines */ - for (line = 1; ; line++) - { + for (line = 1;; line++) + { getline_num = at_resp_get_data_by_line(&at_resp, line, "+MIPLCONFIG:%d,%s", &config_mode_ref, tmp_buff); if (0 == getline_num) /* empty line */ { @@ -198,7 +192,7 @@ os_err_t bc95_onenetnb_get_config(mo_object_t *module, os_int32_t timeout, void ERROR("Get %s module onenetnb mode:%d invalid", module->name, config_mode_ref); break; } - + memset(tmp_buff, 0, sizeof(tmp_buff)); } @@ -209,7 +203,7 @@ __exit: os_err_t bc95_onenetnb_set_config(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args) { - CALL_BC95_BASIC_FUNC("AT+MIPLCONFIG="); /* maximum return time out 300ms, suggest more than it */ + CALL_BC95_BASIC_FUNC("AT+MIPLCONFIG="); /* maximum return time out 300ms, suggest more than it */ } os_err_t bc95_onenetnb_create(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args) @@ -220,10 +214,7 @@ os_err_t bc95_onenetnb_create(mo_object_t *module, os_int32_t timeout, void *res at_parser_t *parser = &module->parser; char resp_buff[128] = {0}; - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .line_num = 0, - .timeout = timeout}; + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .line_num = 0, .timeout = timeout}; char tmp_format[128] = "AT+MIPLCREATE"; @@ -233,7 +224,7 @@ os_err_t bc95_onenetnb_create(mo_object_t *module, os_int32_t timeout, void *res } os_uint8_t ref = 0; - + if (at_resp_get_data_by_kw(&at_resp, "+MIPLCREATE:", "+MIPLCREATE:%hhu", &ref) > 0) { *(os_uint8_t *)resp = ref; @@ -271,7 +262,8 @@ os_err_t bc95_onenetnb_close(mo_object_t *module, os_int32_t timeout, void *resp CALL_BC95_BASIC_FUNC("AT+MIPLCLOSE="); } -os_err_t bc95_onenetnb_discoverrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args) +os_err_t +bc95_onenetnb_discoverrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args) { CALL_BC95_BASIC_FUNC("AT+MIPLDISCOVERRSP="); } @@ -296,7 +288,8 @@ os_err_t bc95_onenetnb_executersp(mo_object_t *module, os_int32_t timeout, void CALL_BC95_BASIC_FUNC("AT+MIPLEXECUTERSP="); } -os_err_t bc95_onenetnb_parameterrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args) +os_err_t +bc95_onenetnb_parameterrsp(mo_object_t *module, os_int32_t timeout, void *resp, const char *format, va_list args) { CALL_BC95_BASIC_FUNC("AT+MIPLPARAMETERRSP="); } @@ -323,15 +316,12 @@ static void urc_discover_handler(mo_onenet_cb_t *regist_cb, const char *data, os WARN("[%d][%s] No discover callback registed.", __LINE__, __func__); return; } - - mo_onenet_discover_t discover_info; + + mo_onenet_discover_t discover_info; memset(&discover_info, 0, sizeof(mo_onenet_discover_t)); - sscanf(data, "+MIPLDISCOVER: %u,%d,%d", - &discover_info.ref, - &discover_info.msg_id, - &discover_info.obj_id); - + sscanf(data, "+MIPLDISCOVER: %u,%d,%d", &discover_info.ref, &discover_info.msg_id, &discover_info.obj_id); + regist_cb->discover_notify_cb(&discover_info); return; @@ -349,17 +339,18 @@ static void urc_observe_handler(mo_onenet_cb_t *regist_cb, const char *data, os_ return; } - mo_onenet_observe_t observe_info; + mo_onenet_observe_t observe_info; memset(&observe_info, 0, sizeof(mo_onenet_observe_t)); - sscanf(data, "+MIPLOBSERVE: %u,%d,%hhd,%d,%d,%d", - &observe_info.ref, - &observe_info.msg_id, - &observe_info.flag, - &observe_info.obj_id, - &observe_info.ins_id, - &observe_info.res_id); - + sscanf(data, + "+MIPLOBSERVE: %u,%d,%hhd,%d,%d,%d", + &observe_info.ref, + &observe_info.msg_id, + &observe_info.flag, + &observe_info.obj_id, + &observe_info.ins_id, + &observe_info.res_id); + regist_cb->observe_notify_cb(&observe_info); return; @@ -377,16 +368,17 @@ static void urc_read_handler(mo_onenet_cb_t *regist_cb, const char *data, os_siz return; } - mo_onenet_read_t read_info; + mo_onenet_read_t read_info; memset(&read_info, 0, sizeof(mo_onenet_read_t)); - sscanf(data, "+MIPLREAD: %u,%d,%d,%d,%d", - &read_info.ref, - &read_info.msg_id, - &read_info.obj_id, - &read_info.ins_id, - &read_info.res_id); - + sscanf(data, + "+MIPLREAD: %u,%d,%d,%d,%d", + &read_info.ref, + &read_info.msg_id, + &read_info.obj_id, + &read_info.ins_id, + &read_info.res_id); + regist_cb->read_notify_cb(&read_info); return; @@ -405,10 +397,10 @@ static void urc_write_handler(mo_onenet_cb_t *regist_cb, const char *data, os_si return; } - mo_onenet_write_t write_info; - os_int8_t *value = OS_NULL; - os_int8_t value_trait = 0; /* value trait:string/hexstring */ - + mo_onenet_write_t write_info; + os_int8_t *value = OS_NULL; + os_int8_t value_trait = 0; /* value trait:string/hexstring */ + memset(&write_info, 0, sizeof(mo_onenet_write_t)); char regex[BC95_REGEX_LEN_DEFAULT] = {0}; @@ -423,26 +415,27 @@ static void urc_write_handler(mo_onenet_cb_t *regist_cb, const char *data, os_si value = os_calloc(1, write_info.len * 2 + 1); strcpy(regex, "+MIPLWRITE: %u,%d,%d,%d,%d,%hhd,%*d,%[^,],%hhd,%d"); } - + if (value == OS_NULL) { ERROR("Calloc onenetNB[%s] value str failed, no enough memory", __func__); return; } - sscanf(data, regex, - &write_info.ref, - &write_info.msg_id, - &write_info.obj_id, - &write_info.ins_id, - &write_info.res_id, - &write_info.value_type, - value, - &write_info.flag, - &write_info.index); - + sscanf(data, + regex, + &write_info.ref, + &write_info.msg_id, + &write_info.obj_id, + &write_info.ins_id, + &write_info.res_id, + &write_info.value_type, + value, + &write_info.flag, + &write_info.index); + regist_cb->write_notify_cb(&write_info, (const char *)value); - + os_free(value); return; } @@ -460,28 +453,29 @@ static void urc_execute_handler(mo_onenet_cb_t *regist_cb, const char *data, os_ return; } - mo_onenet_execute_t execute_info; + mo_onenet_execute_t execute_info; memset(&execute_info, 0, sizeof(mo_onenet_execute_t)); sscanf(data, "+MIPLEXECUTE: %*d,%*d,%*d,%*d,%*d,%d", &execute_info.len); - - os_uint8_t *arguments = os_calloc(1, execute_info.len + 1); - + + os_uint8_t *arguments = os_calloc(1, execute_info.len + 1); + if (OS_NULL == arguments) { ERROR("Calloc onenetNB[%s] arguments str failed, no enough memory", __func__); return; } - sscanf(data, "+MIPLEXECUTE: %u,%d,%d,%d,%d,%*d,\"%s\"", - &execute_info.ref, - &execute_info.msg_id, - &execute_info.obj_id, - &execute_info.ins_id, - &execute_info.res_id, + sscanf(data, + "+MIPLEXECUTE: %u,%d,%d,%d,%d,%*d,\"%s\"", + &execute_info.ref, + &execute_info.msg_id, + &execute_info.obj_id, + &execute_info.ins_id, + &execute_info.res_id, arguments); - + regist_cb->execute_notify_cb(&execute_info, (const char *)arguments); - + os_free(arguments); return; } @@ -498,28 +492,29 @@ static void urc_parameter_handler(mo_onenet_cb_t *regist_cb, const char *data, o return; } - mo_onenet_parameter_t parameter_info; + mo_onenet_parameter_t parameter_info; memset(¶meter_info, 0, sizeof(mo_onenet_parameter_t)); sscanf(data, "+MIPLPARAMETER: %*d,%*d,%*d,%*d,%*d,%d", ¶meter_info.len); - - os_uint8_t *arguments = os_calloc(1, parameter_info.len + 1); - + + os_uint8_t *arguments = os_calloc(1, parameter_info.len + 1); + if (OS_NULL == arguments) { ERROR("Calloc onenetNB[%s] arguments str failed, no enough memory", __func__); return; } - sscanf(data, "+MIPLPARAMETER: %u,%d,%d,%d,%d,%*d,\"%s\"", - ¶meter_info.ref, - ¶meter_info.msg_id, - ¶meter_info.obj_id, - ¶meter_info.ins_id, - ¶meter_info.res_id, + sscanf(data, + "+MIPLPARAMETER: %u,%d,%d,%d,%d,%*d,\"%s\"", + ¶meter_info.ref, + ¶meter_info.msg_id, + ¶meter_info.obj_id, + ¶meter_info.ins_id, + ¶meter_info.res_id, arguments); - + regist_cb->parameter_notify_cb(¶meter_info, (const char *)arguments); - + os_free(arguments); return; } @@ -536,46 +531,47 @@ static void urc_event_handler(mo_onenet_cb_t *regist_cb, const char *data, os_si return; } - mo_onenet_event_t event_info; + mo_onenet_event_t event_info; memset(&event_info, 0, sizeof(mo_onenet_event_t)); - event_info.extend = BC95_ONENETNB_INVALID_DEFAULT; + event_info.extend = BC95_ONENETNB_INVALID_DEFAULT; event_info.cache_command_flag = BC95_ONENETNB_INVALID_DEFAULT; - sscanf(data, "+MIPLEVENT: %u,%hhu,%d,%hu,%s,%hhd", - &event_info.ref, - &event_info.evt_id, - &event_info.extend, - &event_info.ack_id, + sscanf(data, + "+MIPLEVENT: %u,%hhu,%d,%hu,%s,%hhd", + &event_info.ref, + &event_info.evt_id, + &event_info.extend, + &event_info.ack_id, event_info.time_stamp, - &event_info.cache_command_flag); - + &event_info.cache_command_flag); + regist_cb->event_notify_cb(&event_info); - + return; } static bc95_onenet_urc_t bc95_nb_urc_handler_table[] = { - {.prefix = "MIPLDISCOVER", .func = urc_discover_handler }, - {.prefix = "MIPLOBSERVE", .func = urc_observe_handler }, - {.prefix = "MIPLREAD", .func = urc_read_handler }, - {.prefix = "MIPLWRITE", .func = urc_write_handler }, - {.prefix = "MIPLEXECUTE", .func = urc_execute_handler }, + {.prefix = "MIPLDISCOVER", .func = urc_discover_handler}, + {.prefix = "MIPLOBSERVE", .func = urc_observe_handler}, + {.prefix = "MIPLREAD", .func = urc_read_handler}, + {.prefix = "MIPLWRITE", .func = urc_write_handler}, + {.prefix = "MIPLEXECUTE", .func = urc_execute_handler}, {.prefix = "MIPLPARAMETER", .func = urc_parameter_handler}, - {.prefix = "MIPLEVENT", .func = urc_event_handler }, + {.prefix = "MIPLEVENT", .func = urc_event_handler}, }; static void bc95_urc_receiver(struct at_parser *parser, const char *data, os_size_t size) { OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - - char *urc_data = OS_NULL; - os_int8_t handler_ref = BC95_ONENETNB_INVALID_DEFAULT; - char urc_cmd_head[BC95_URC_HEAD_MAXLEN] = {0}; - + + char *urc_data = OS_NULL; + os_int8_t handler_ref = BC95_ONENETNB_INVALID_DEFAULT; + char urc_cmd_head[BC95_URC_HEAD_MAXLEN] = {0}; + /* parse from cmd */ sscanf(data, "+%[^:]", urc_cmd_head); - + /* find registration */ for (int i = 0; i < sizeof(bc95_nb_urc_handler_table) / sizeof(bc95_onenet_urc_t); i++) { @@ -606,11 +602,8 @@ static void bc95_urc_receiver(struct at_parser *parser, const char *data, os_siz mo_bc95_t *module = os_container_of(module, mo_bc95_t, parent); /* send handle_msg to mq */ - bc95_onenet_mq_msg_t handle_msg = {module->regist_cb, - urc_data, - size, - bc95_nb_urc_handler_table[handler_ref].func}; - + bc95_onenet_mq_msg_t handle_msg = {module->regist_cb, urc_data, size, bc95_nb_urc_handler_table[handler_ref].func}; + if (OS_EOK != os_mq_send(bc95_nb_mq, &handle_msg, sizeof(handle_msg), OS_NO_WAIT)) { WARN("[%s] mq send failed, too many unsolved urc.", __func__); @@ -623,19 +616,15 @@ static void bc95_urc_manager_task(void *parameter) { INFO("[%s] task start up.", __func__); bc95_onenet_mq_msg_t handle_msg; - os_err_t result = OS_ERROR; - os_size_t recv_size = 0; + os_err_t result = OS_ERROR; + os_size_t recv_size = 0; while (1) { memset(&handle_msg, 0, sizeof(bc95_onenet_mq_msg_t)); - + /* wait & pop */ - result = os_mq_recv(bc95_nb_mq, - &handle_msg, - sizeof(handle_msg), - OS_WAIT_FOREVER, - &recv_size); + result = os_mq_recv(bc95_nb_mq, &handle_msg, sizeof(handle_msg), OS_WAIT_FOREVER, &recv_size); if (OS_EOK != result) { INFO("[%s] mq received mq_control [exit] msg.[%d].", __func__, result); @@ -646,12 +635,10 @@ static void bc95_urc_manager_task(void *parameter) /* [*] add recursive lock, NB AT session */ - /* execute urc handler */ OS_ASSERT(OS_NULL != handle_msg.func); handle_msg.func(handle_msg.regist_cb, handle_msg.data, handle_msg.len); - /* [*] unlock */ /* free buffer alloced in bc95_urc_receiver */ @@ -660,19 +647,19 @@ static void bc95_urc_manager_task(void *parameter) } static at_urc_t bc95_nb_urc_table[] = { - {.prefix = "+MIPLDISCOVER:", .suffix = "\r\n", .func = bc95_urc_receiver}, - {.prefix = "+MIPLOBSERVE:", .suffix = "\r\n", .func = bc95_urc_receiver}, - {.prefix = "+MIPLREAD:", .suffix = "\r\n", .func = bc95_urc_receiver}, - {.prefix = "+MIPLWRITE:", .suffix = "\r\n", .func = bc95_urc_receiver}, - {.prefix = "+MIPLEXECUTE:", .suffix = "\r\n", .func = bc95_urc_receiver}, + {.prefix = "+MIPLDISCOVER:", .suffix = "\r\n", .func = bc95_urc_receiver}, + {.prefix = "+MIPLOBSERVE:", .suffix = "\r\n", .func = bc95_urc_receiver}, + {.prefix = "+MIPLREAD:", .suffix = "\r\n", .func = bc95_urc_receiver}, + {.prefix = "+MIPLWRITE:", .suffix = "\r\n", .func = bc95_urc_receiver}, + {.prefix = "+MIPLEXECUTE:", .suffix = "\r\n", .func = bc95_urc_receiver}, {.prefix = "+MIPLPARAMETER:", .suffix = "\r\n", .func = bc95_urc_receiver}, - {.prefix = "+MIPLEVENT:", .suffix = "\r\n", .func = bc95_urc_receiver}, + {.prefix = "+MIPLEVENT:", .suffix = "\r\n", .func = bc95_urc_receiver}, }; os_err_t bc95_onenetnb_init(mo_bc95_t *module) { OS_ASSERT(OS_NULL != module); - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = OS_NULL; module->regist_cb = os_calloc(1, sizeof(mo_onenet_cb_t)); @@ -684,9 +671,7 @@ os_err_t bc95_onenetnb_init(mo_bc95_t *module) } /* create mq for urc manager */ - bc95_nb_mq = os_mq_create(BC95_URC_MQ_NAME, - sizeof(bc95_onenet_mq_msg_t), - BC95_URC_MQ_MSGNUM_MAX); + bc95_nb_mq = os_mq_create(BC95_URC_MQ_NAME, sizeof(bc95_onenet_mq_msg_t), BC95_URC_MQ_MSGNUM_MAX); if (OS_NULL == bc95_nb_mq) { ERROR("Module %s NB mq create failed, no enough memory!", module->parent.name); @@ -695,13 +680,13 @@ os_err_t bc95_onenetnb_init(mo_bc95_t *module) } /* create&start urc manager task */ - result = os_task_init(&bc95_nb_manager_task, - BC95_URC_MANAGER_TASK_NAME, - bc95_urc_manager_task, - OS_NULL, - bc95_nb_manager_task_stack, - BC95_URC_MANAGER_STACK_SIZE, - BC95_URC_MANAGER_TASK_PRIORITY); + result = os_task_init(&bc95_nb_manager_task, + BC95_URC_MANAGER_TASK_NAME, + bc95_urc_manager_task, + OS_NULL, + bc95_nb_manager_task_stack, + BC95_URC_MANAGER_STACK_SIZE, + BC95_URC_MANAGER_TASK_PRIORITY); if (OS_EOK != result) { ERROR("Module %s NB create manager task failed[%d]!", module->parent.name, result); @@ -745,22 +730,19 @@ void bc95_onenetnb_deinit(mo_bc95_t *module) OS_ASSERT(OS_NULL != bc95_nb_mq); bc95_onenet_mq_msg_t handle_msg; - os_err_t result = OS_ERROR; - os_size_t recv_size = 0; + os_err_t result = OS_ERROR; + os_size_t recv_size = 0; /* free buff in mq which alloced in bc95_urc_receiver */ while (OS_TRUE) { memset(&handle_msg, 0, sizeof(bc95_onenet_mq_msg_t)); - result = os_mq_recv(bc95_nb_mq, - &handle_msg, - sizeof(handle_msg), - OS_NO_WAIT, - &recv_size); - if (OS_EOK != result) break; + result = os_mq_recv(bc95_nb_mq, &handle_msg, sizeof(handle_msg), OS_NO_WAIT, &recv_size); + if (OS_EOK != result) + break; os_free((void *)handle_msg.data); } - + /* auto deinit urc manager task */ // os_mq_control(bc95_nb_mq, OS_IPC_CMD_RESET, OS_NULL); /* TODO make sure */ os_mq_destroy(bc95_nb_mq); @@ -784,14 +766,11 @@ os_err_t bc95_onenetnb_all(mo_object_t *module, os_int32_t timeout, void *resp, { OS_ASSERT(module != OS_NULL); OS_ASSERT(format != OS_NULL); - + at_parser_t *parser = &module->parser; char resp_buff[256] = {0}; - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .line_num = 0, - .timeout = timeout}; + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .line_num = 0, .timeout = timeout}; if (at_parser_exec_cmd_valist(parser, &at_resp, format, args) == OS_EOK) { diff --git a/components/molink/module/bc95/source/bc95_ping.c b/components/molink/module/bc95/source/bc95_ping.c index 2f3f5930..5813b8ca 100644 --- a/components/molink/module/bc95/source/bc95_ping.c +++ b/components/molink/module/bc95/source/bc95_ping.c @@ -27,7 +27,8 @@ #ifdef BC95_USING_PING_OPS -extern os_err_t bc95_ping_handler(mo_object_t *module, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); +extern os_err_t +bc95_ping_handler(mo_object_t *module, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); os_err_t bc95_ping(mo_object_t *module, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { diff --git a/components/molink/module/clm920rv3/include/clm920rv3.h b/components/molink/module/clm920rv3/include/clm920rv3.h index cb9a6825..bcf3e3e0 100644 --- a/components/molink/module/clm920rv3/include/clm920rv3.h +++ b/components/molink/module/clm920rv3/include/clm920rv3.h @@ -57,7 +57,7 @@ extern "C" { #endif #ifndef CLM920RV3_DEVICE_NAME -#define CLM920RV3_DEVICE_NAME "uart2" +#define CLM920RV3_DEVICE_NAME "uart2" #endif #ifndef CLM920RV3_RECV_BUFF_LEN @@ -65,7 +65,7 @@ extern "C" { #endif #ifndef CLM920RV3_NETCONN_NUM -#define CLM920RV3_NETCONN_NUM (6) +#define CLM920RV3_NETCONN_NUM (6) #endif typedef struct mo_clm920rv3 @@ -76,12 +76,12 @@ typedef struct mo_clm920rv3 os_event_t netconn_evt; os_mutex_t netconn_lock; - void *netconn_data; + void *netconn_data; #endif /* CLM920RV3_USING_NETCONN_OPS */ } mo_clm920rv3_t; mo_object_t *module_clm920rv3_create(const char *name, void *parser_config); -os_err_t module_clm920rv3_destroy(mo_object_t *self); +os_err_t module_clm920rv3_destroy(mo_object_t *self); #endif /* MOLINK_USING_CLM920RV3 */ diff --git a/components/molink/module/clm920rv3/include/clm920rv3_netconn.h b/components/molink/module/clm920rv3/include/clm920rv3_netconn.h index 789f4859..c15bc675 100644 --- a/components/molink/module/clm920rv3/include/clm920rv3_netconn.h +++ b/components/molink/module/clm920rv3/include/clm920rv3_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef CLM920RV3_USING_NETCONN_OPS -os_err_t clm920rv3_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t clm920rv3_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *clm920rv3_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t clm920rv3_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t clm920rv3_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t clm920rv3_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t clm920rv3_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t clm920rv3_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t clm920rv3_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef CLM920RV3_USING_DNS -os_err_t clm920rv3_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr); +os_err_t clm920rv3_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr); #endif #endif /* CLM920RV3_USING_NETCONN_OPS */ diff --git a/components/molink/module/clm920rv3/include/clm920rv3_ping.h b/components/molink/module/clm920rv3/include/clm920rv3_ping.h index 7bf55162..7e4217d6 100644 --- a/components/molink/module/clm920rv3/include/clm920rv3_ping.h +++ b/components/molink/module/clm920rv3/include/clm920rv3_ping.h @@ -31,7 +31,8 @@ extern "C" { #ifdef CLM920RV3_USING_PING_OPS -os_err_t clm920rv3_ping(mo_object_t *module, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); +os_err_t +clm920rv3_ping(mo_object_t *module, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); #endif /* CLM920RV3_USING_PING_OPS */ diff --git a/components/molink/module/clm920rv3/source/clm920rv3.c b/components/molink/module/clm920rv3/source/clm920rv3.c index c9412d93..31e10b51 100644 --- a/components/molink/module/clm920rv3/source/clm920rv3.c +++ b/components/molink/module/clm920rv3/source/clm920rv3.c @@ -30,47 +30,47 @@ #ifdef MOLINK_USING_CLM920RV3 #define MO_LOG_TAG "clm920rv3" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define CLM920RV3_RETRY_TIMES (10) #ifdef CLM920RV3_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = clm920rv3_at_test, - .get_imei = clm920rv3_get_imei, - .get_imsi = clm920rv3_get_imsi, - .get_iccid = clm920rv3_get_iccid, - .get_cfun = clm920rv3_get_cfun, - .set_cfun = clm920rv3_set_cfun, + .at_test = clm920rv3_at_test, + .get_imei = clm920rv3_get_imei, + .get_imsi = clm920rv3_get_imsi, + .get_iccid = clm920rv3_get_iccid, + .get_cfun = clm920rv3_get_cfun, + .set_cfun = clm920rv3_set_cfun, .get_firmware_version = clm920rv3_get_firmware_version, }; #endif /* CLM920RV3_USING_GENERAL_OPS */ #ifdef CLM920RV3_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = clm920rv3_set_attach, - .get_attach = clm920rv3_get_attach, - .set_reg = clm920rv3_set_reg, - .get_reg = clm920rv3_get_reg, - .get_cgact = clm920rv3_get_cgact, - .get_csq = clm920rv3_get_csq, + .set_attach = clm920rv3_set_attach, + .get_attach = clm920rv3_get_attach, + .set_reg = clm920rv3_set_reg, + .get_reg = clm920rv3_get_reg, + .get_cgact = clm920rv3_get_cgact, + .get_csq = clm920rv3_get_csq, }; #endif /* CLM920RV3_USING_NETSERV_OPS */ #ifdef CLM920RV3_USING_PING_OPS /* CLM920RV3 ping function just for test use, not officially support for now. */ static const struct mo_ping_ops gs_ping_ops = { - .ping = clm920rv3_ping, + .ping = clm920rv3_ping, }; #endif /* CLM920RV3_USING_PING_OPS */ #ifdef CLM920RV3_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = clm920rv3_ifconfig, - .get_ipaddr = clm920rv3_get_ipaddr, - .set_dnsserver = clm920rv3_set_dnsserver, - .get_dnsserver = clm920rv3_get_dnsserver, + .ifconfig = clm920rv3_ifconfig, + .get_ipaddr = clm920rv3_get_ipaddr, + .set_dnsserver = clm920rv3_set_dnsserver, + .get_dnsserver = clm920rv3_get_dnsserver, }; #endif /* CLM920RV3_USING_IFCONFIG_OPS */ @@ -78,14 +78,14 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern os_err_t clm920rv3_netconn_init(mo_clm920rv3_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = clm920rv3_netconn_create, - .destroy = clm920rv3_netconn_destroy, + .create = clm920rv3_netconn_create, + .destroy = clm920rv3_netconn_destroy, #ifdef CLM920RV3_USING_DNS - .gethostbyname = clm920rv3_netconn_gethostbyname, + .gethostbyname = clm920rv3_netconn_gethostbyname, #endif - .connect = clm920rv3_netconn_connect, - .send = clm920rv3_netconn_send, - .get_info = clm920rv3_netconn_get_info, + .connect = clm920rv3_netconn_connect, + .send = clm920rv3_netconn_send, + .get_info = clm920rv3_netconn_get_info, }; #endif /* CLM920RV3_USING_NETCONN_OPS */ @@ -97,27 +97,27 @@ static void urc_info_func(struct at_parser *parser, const char *data, os_size_t } static at_urc_t clm920rv3_urc_table[] = { - {.prefix = "RDY", .suffix = "\r\n", .func = urc_info_func}, + {.prefix = "RDY", .suffix = "\r\n", .func = urc_info_func}, {.prefix = "*ATREADY:", .suffix = "\r\n", .func = urc_info_func}, - {.prefix = "+CPIN:", .suffix = "\r\n", .func = urc_info_func}, - {.prefix = "^MODE:", .suffix = "\r\n", .func = urc_info_func}, - {.prefix = "+CGEV:", .suffix = "\r\n", .func = urc_info_func}, - {.prefix = "+NITZ:", .suffix = "\r\n", .func = urc_info_func}, - {.prefix = "+CTZV:", .suffix = "\r\n", .func = urc_info_func}, - {.prefix = "+CREG:", .suffix = "\r\n", .func = urc_info_func}, + {.prefix = "+CPIN:", .suffix = "\r\n", .func = urc_info_func}, + {.prefix = "^MODE:", .suffix = "\r\n", .func = urc_info_func}, + {.prefix = "+CGEV:", .suffix = "\r\n", .func = urc_info_func}, + {.prefix = "+NITZ:", .suffix = "\r\n", .func = urc_info_func}, + {.prefix = "+CTZV:", .suffix = "\r\n", .func = urc_info_func}, + {.prefix = "+CREG:", .suffix = "\r\n", .func = urc_info_func}, }; static os_err_t clm920rv3_at_init(mo_object_t *self) { char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - + at_parser_t *parser = &self->parser; - os_err_t result = OS_ERROR; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = OS_TICK_PER_SECOND}; + os_err_t result = OS_ERROR; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = OS_TICK_PER_SECOND}; /* set urc table first to handle module init-process unused urc */ at_parser_set_urc_table(parser, clm920rv3_urc_table, sizeof(clm920rv3_urc_table) / sizeof(at_urc_t)); - + if (OS_EOK != at_parser_connect(parser, CLM920RV3_RETRY_TIMES)) { ERROR("Connect to %s module failed, please check whether the module connection is correct", self->name); @@ -125,10 +125,13 @@ static os_err_t clm920rv3_at_init(mo_object_t *self) } /* basic environment set */ - if (OS_EOK != at_parser_exec_cmd(parser, &resp, "ATE0")) goto __exit; - if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CREG=0")) goto __exit; - if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CEREG=0")) goto __exit; - + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "ATE0")) + goto __exit; + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CREG=0")) + goto __exit; + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CEREG=0")) + goto __exit; + result = OS_EOK; INFO("%s init success", __func__); @@ -236,14 +239,17 @@ int clm920rv3_auto_create(void) ERROR("Auto create failed, Can not find CLM920RV3 interface device %s!", CLM920RV3_DEVICE_NAME); return OS_ERROR; } - - uart_config.baud_rate = CLM920RV3_DEVICE_RATE; - INFO("Auto create %s module object with [%s]:[%d]bps", CLM920RV3_NAME, CLM920RV3_DEVICE_NAME, CLM920RV3_DEVICE_RATE); + uart_config.baud_rate = CLM920RV3_DEVICE_RATE; + + INFO("Auto create %s module object with [%s]:[%d]bps", + CLM920RV3_NAME, + CLM920RV3_DEVICE_NAME, + CLM920RV3_DEVICE_RATE); os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = CLM920RV3_NAME, + mo_parser_config_t parser_config = {.parser_name = CLM920RV3_NAME, .parser_device = device, .recv_buff_len = CLM920RV3_RECV_BUFF_LEN}; @@ -255,7 +261,10 @@ int clm920rv3_auto_create(void) return OS_ERROR; } - INFO("Auto create %s module object success [%s]:[%d]bps!", CLM920RV3_NAME, CLM920RV3_DEVICE_NAME, CLM920RV3_DEVICE_RATE); + INFO("Auto create %s module object success [%s]:[%d]bps!", + CLM920RV3_NAME, + CLM920RV3_DEVICE_NAME, + CLM920RV3_DEVICE_RATE); return OS_EOK; } OS_CMPOENT_INIT(clm920rv3_auto_create, OS_INIT_SUBLEVEL_MIDDLE); diff --git a/components/molink/module/clm920rv3/source/clm920rv3_general.c b/components/molink/module/clm920rv3/source/clm920rv3_general.c index 7c009e7b..d1b573f1 100644 --- a/components/molink/module/clm920rv3/source/clm920rv3_general.c +++ b/components/molink/module/clm920rv3/source/clm920rv3_general.c @@ -28,7 +28,7 @@ #ifdef CLM920RV3_USING_GENERAL_OPS #define MO_LOG_TAG "clm920rv3.general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" os_err_t clm920rv3_at_test(mo_object_t *module) @@ -176,9 +176,7 @@ os_err_t clm920rv3_get_firmware_version(mo_object_t *module, mo_firmware_version char resp_buff[4 * AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CGMR"); if (result != OS_EOK) @@ -193,8 +191,8 @@ os_err_t clm920rv3_get_firmware_version(mo_object_t *module, mo_firmware_version } const char *source_line = at_resp_get_line(&resp, 1); - os_size_t line_length = strlen(source_line); - char **dest_line = &version->ver_info[0]; + os_size_t line_length = strlen(source_line); + char **dest_line = &version->ver_info[0]; *dest_line = os_calloc(1, line_length + 1); if (OS_NULL == *dest_line) diff --git a/components/molink/module/clm920rv3/source/clm920rv3_ifconfig.c b/components/molink/module/clm920rv3/source/clm920rv3_ifconfig.c index 0d71afee..d2347a6f 100644 --- a/components/molink/module/clm920rv3/source/clm920rv3_ifconfig.c +++ b/components/molink/module/clm920rv3/source/clm920rv3_ifconfig.c @@ -29,7 +29,7 @@ #ifdef CLM920RV3_USING_IFCONFIG_OPS #define MO_LOG_TAG "clm920rv3.ifconfig" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" extern os_err_t clm920rv3_pdp_act(mo_object_t *module); @@ -55,12 +55,12 @@ os_err_t clm920rv3_ifconfig(mo_object_t *module) } os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t ber = 0; if (clm920rv3_get_csq(module, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; } os_kprintf("\r\nLIST AT MODULE INFORMATIONS\r\n"); @@ -88,7 +88,7 @@ os_err_t clm920rv3_ifconfig(mo_object_t *module) os_err_t clm920rv3_get_ipaddr(mo_object_t *module, char ip[]) { at_parser_t *parser = &module->parser; - os_int8_t len = -1; + os_int8_t len = -1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -125,7 +125,7 @@ os_err_t clm920rv3_get_ipaddr(mo_object_t *module, char ip[]) } __exit: - + return result; } @@ -133,12 +133,12 @@ os_err_t clm920rv3_set_dnsserver(mo_object_t *module, dns_server_t dns) { /* CLM920RV3 set dnsserver function just for test use, not officially support for now. */ at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - char ip[IPADDR_MAX_STR_LEN + 1] = {0}; - + char ip[IPADDR_MAX_STR_LEN + 1] = {0}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = OS_TICK_PER_SECOND}; - + if (OS_NULL == parser) { ERROR("CLM920RV3 %s: at parser is NULL.", __func__); @@ -152,28 +152,28 @@ os_err_t clm920rv3_set_dnsserver(mo_object_t *module, dns_server_t dns) } /** - * CLM920RV3 set dns server function just for test use, not officially support for now. + * CLM920RV3 set dns server function just for test use, not officially support for now. * and it appears that CLM920RV3 not support "0" to reset the DNS server address. **/ - if (!strlen(dns.primary_dns) || !strlen(dns.secondary_dns) || - !strcmp(dns.secondary_dns, "0") || !strcmp(dns.secondary_dns, "0")) + if (!strlen(dns.primary_dns) || !strlen(dns.secondary_dns) || !strcmp(dns.secondary_dns, "0") || + !strcmp(dns.secondary_dns, "0")) { ERROR("CLM920RV3 %s: with invalid param.", __func__); return OS_ERROR; } result = at_parser_exec_cmd(parser, &resp, "AT*NETDNS=1,\"%s\",\"%s\"", dns.primary_dns, dns.secondary_dns); - + return result; } os_err_t clm920rv3_get_dnsserver(mo_object_t *module, dns_server_t *dns) { /* CLM920RV3 get dnsserver function just for test use, not officially support for now. */ - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; - char primary_dns[IPADDR_MAX_STR_LEN + 1] = {0}; + char primary_dns[IPADDR_MAX_STR_LEN + 1] = {0}; char secondary_dns[IPADDR_MAX_STR_LEN + 1] = {0}; if (OS_NULL == parser) diff --git a/components/molink/module/clm920rv3/source/clm920rv3_netconn.c b/components/molink/module/clm920rv3/source/clm920rv3_netconn.c index 06917699..bac3f55b 100644 --- a/components/molink/module/clm920rv3/source/clm920rv3_netconn.c +++ b/components/molink/module/clm920rv3/source/clm920rv3_netconn.c @@ -31,19 +31,19 @@ #ifdef CLM920RV3_USING_NETCONN_OPS #define MO_LOG_TAG "clm920rv3.netconn" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define CLM920RV3_SEND_MAX_SIZE (1460) #define CLM920RV3_RESP_DEF_SIZE (256) #define CLM920RV3_CONN_ID_NULL (-1) -#define CLM920RV3_NETCONN_MQ_NAME "clm920rv3_nc_mq" +#define CLM920RV3_NETCONN_MQ_NAME "clm920rv3_nc_mq" #ifndef CLM920RV3_NETCONN_MQ_MSG_SIZE #define CLM920RV3_NETCONN_MQ_MSG_SIZE (sizeof(mo_notconn_msg_t)) #endif /* CLM920RV3_NETCONN_MQ_MSG_SIZE */ #ifndef CLM920RV3_NETCONN_MQ_MSG_MAX -#define CLM920RV3_NETCONN_MQ_MSG_MAX (5) +#define CLM920RV3_NETCONN_MQ_MSG_MAX (5) #endif /* CLM920RV3_NETCONN_MQ_MSG_MAX */ #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) @@ -107,7 +107,7 @@ os_err_t clm920rv3_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info mo_clm920rv3_t *clm920rv3 = os_container_of(module, mo_clm920rv3_t, parent); info->netconn_array = clm920rv3->netconn; - info->netconn_nums = sizeof(clm920rv3->netconn) / sizeof(clm920rv3->netconn[0]); + info->netconn_nums = sizeof(clm920rv3->netconn) / sizeof(clm920rv3->netconn[0]); return OS_EOK; } @@ -115,7 +115,7 @@ os_err_t clm920rv3_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info os_err_t clm920rv3_pdp_act(mo_clm920rv3_t *clm920rv3) { char tmp_data[20] = {0}; - char APN[10] = {0}; + char APN[10] = {0}; at_parser_t *parser = &clm920rv3->parent.parser; @@ -140,16 +140,16 @@ os_err_t clm920rv3_pdp_act(mo_clm920rv3_t *clm920rv3) switch (atoi(tmp_data + 3)) { - case 0: /* 46000 */ - case 2: /* 46002 */ - case 4: /* 46004 */ - case 7: /* 46007 */ + case 0: /* 46000 */ + case 2: /* 46002 */ + case 4: /* 46004 */ + case 7: /* 46007 */ strncpy(APN, "cmnet", strlen("cmnet")); break; - case 1: /* 46001 */ - case 6: /* 46006 */ - case 9: /* 46009 */ + case 1: /* 46001 */ + case 6: /* 46006 */ + case 9: /* 46009 */ strncpy(APN, "3gnet", strlen("3gnet")); break; @@ -181,12 +181,12 @@ os_err_t clm920rv3_pdp_act(mo_clm920rv3_t *clm920rv3) /* PDP context active process, recommend timeout:12s */ os_event_recv(&clm920rv3->netconn_evt, - CLM920RV3_EVENT_PDP_ACT, - OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, - OS_NO_WAIT, - OS_NULL); + CLM920RV3_EVENT_PDP_ACT, + OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, + OS_NO_WAIT, + OS_NULL); - resp.timeout = 10 * OS_TICK_PER_SECOND; + resp.timeout = 10 * OS_TICK_PER_SECOND; result = at_parser_exec_cmd(parser, &resp, "AT+QIPACT=1"); if (result != OS_EOK) @@ -229,9 +229,7 @@ mo_netconn_t *clm920rv3_netconn_create(mo_object_t *module, mo_netconn_type_t ty return OS_NULL; } - netconn->mq = os_mq_create(CLM920RV3_NETCONN_MQ_NAME, - CLM920RV3_NETCONN_MQ_MSG_SIZE, - CLM920RV3_NETCONN_MQ_MSG_MAX); + netconn->mq = os_mq_create(CLM920RV3_NETCONN_MQ_NAME, CLM920RV3_NETCONN_MQ_MSG_SIZE, CLM920RV3_NETCONN_MQ_MSG_MAX); if (OS_NULL == netconn->mq) { ERROR("%s message queue create failed, no enough memory.", module->name); @@ -250,7 +248,7 @@ mo_netconn_t *clm920rv3_netconn_create(mo_object_t *module, mo_netconn_type_t ty os_err_t clm920rv3_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; DEBUG("Module %s in %d netconn status", module->name, netconn->stat); @@ -267,8 +265,8 @@ os_err_t clm920rv3_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) if (result != OS_EOK) { ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + module->name, + (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); return result; } break; @@ -285,8 +283,8 @@ os_err_t clm920rv3_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn id %d destroyed", module->name, netconn->connect_id); - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); @@ -385,7 +383,7 @@ __exit: { ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); } @@ -399,20 +397,18 @@ __exit: os_size_t clm920rv3_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t curr_size = 0; - os_int32_t connect_id = CLM920RV3_CONN_ID_NULL; - os_size_t cnt = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t curr_size = 0; + os_int32_t connect_id = CLM920RV3_CONN_ID_NULL; + os_size_t cnt = 0; at_parser_exec_lock(parser); char resp_buff[CLM920RV3_RESP_DEF_SIZE] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 10 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; while (sent_size < size) { @@ -487,9 +483,9 @@ static void urc_connect_func(struct at_parser *parser, const char *data, os_size mo_clm920rv3_t *clm920rv3 = os_container_of(module, mo_clm920rv3_t, parent); os_int32_t connect_id = 0; - os_int32_t result = 0; + os_int32_t result = 0; - sscanf(data, "+QIPOPEN: %d,%d", &connect_id , &result); + sscanf(data, "+QIPOPEN: %d,%d", &connect_id, &result); if (0 == result) { @@ -509,7 +505,7 @@ os_err_t clm920rv3_netconn_gethostbyname(mo_object_t *module, const char *domain OS_ASSERT(OS_NULL != addr); at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[CLM920RV3_RESP_DEF_SIZE] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = OS_TICK_PER_SECOND}; @@ -577,7 +573,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; + os_int32_t data_size = 0; sscanf(data, "RECV FROM: %d,%*[^,],%*d,%d", &connect_id, &data_size); @@ -592,13 +588,13 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t return; } - char *recv_buff = os_calloc(1, data_size); - char temp_buff[8] = {0}; + char *recv_buff = os_calloc(1, data_size); + char temp_buff[8] = {0}; if (recv_buff == OS_NULL) { /* read and clean the coming data */ ERROR("alloc recv buff %d bytes fail, no enough memory", data_size); - os_size_t temp_size = 0; + os_size_t temp_size = 0; while (temp_size < data_size) { if (data_size - temp_size > sizeof(temp_buff)) @@ -637,11 +633,11 @@ static void urc_pdpact_func(struct at_parser *parser, const char *data, os_size_ OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_clm920rv3_t *clm920rv3 = os_container_of(module, mo_clm920rv3_t, parent); - char ip[IPADDR_MAX_STR_LEN +1] = {0}; - os_int32_t context_id = 0; + char ip[IPADDR_MAX_STR_LEN + 1] = {0}; + os_int32_t context_id = 0; os_int32_t context_type = 0; if (0 >= sscanf(data, "+QIPACTURC: %d,%d,\"%[^\"]", &context_id, &context_type, ip)) @@ -695,11 +691,11 @@ static void urc_cdns_func(struct at_parser *parser, const char *data, os_size_t } static at_urc_t gs_urc_table[] = { - {.prefix = "+QIPOPEN:", .suffix = "\r\n", .func = urc_connect_func}, - {.prefix = "+QIPCLOSEURC:", .suffix = "\r\n", .func = urc_close_func }, - {.prefix = "+QIPACTURC:", .suffix = "\r\n", .func = urc_pdpact_func }, - {.prefix = "RECV FROM:", .suffix = "\r\n", .func = urc_recv_func }, - {.prefix = "+CDNS:", .suffix = "\r\n", .func = urc_cdns_func }, + {.prefix = "+QIPOPEN:", .suffix = "\r\n", .func = urc_connect_func}, + {.prefix = "+QIPCLOSEURC:", .suffix = "\r\n", .func = urc_close_func}, + {.prefix = "+QIPACTURC:", .suffix = "\r\n", .func = urc_pdpact_func}, + {.prefix = "RECV FROM:", .suffix = "\r\n", .func = urc_recv_func}, + {.prefix = "+CDNS:", .suffix = "\r\n", .func = urc_cdns_func}, }; os_err_t clm920rv3_netconn_init(mo_clm920rv3_t *module) diff --git a/components/molink/module/clm920rv3/source/clm920rv3_netserv.c b/components/molink/module/clm920rv3/source/clm920rv3_netserv.c index 60b8605f..743df80a 100644 --- a/components/molink/module/clm920rv3/source/clm920rv3_netserv.c +++ b/components/molink/module/clm920rv3/source/clm920rv3_netserv.c @@ -33,7 +33,7 @@ #ifdef CLM920RV3_USING_NETSERV_OPS #define MO_LOG_TAG "clm920rv3.netserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" os_err_t clm920rv3_set_attach(mo_object_t *module, os_uint8_t attach_stat) @@ -61,12 +61,12 @@ os_err_t clm920rv3_get_attach(mo_object_t *module, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) { ERROR("Get %s module attach state failed", module->name); return OS_ERROR; } - + return OS_EOK; } diff --git a/components/molink/module/clm920rv3/source/clm920rv3_ping.c b/components/molink/module/clm920rv3/source/clm920rv3_ping.c index dd999bdc..e74f25d4 100644 --- a/components/molink/module/clm920rv3/source/clm920rv3_ping.c +++ b/components/molink/module/clm920rv3/source/clm920rv3_ping.c @@ -27,19 +27,20 @@ #ifdef CLM920RV3_USING_PING_OPS #define MO_LOG_TAG "clm920rv3.ping" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" -os_err_t clm920rv3_ping(mo_object_t *module, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) +os_err_t +clm920rv3_ping(mo_object_t *module, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { /* CLM920RV3 ping function just for test use, not officially support for now. */ - - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_int32_t response = -1; - os_uint16_t recv_data_len = 0; - os_uint32_t ping_time = 0; - os_int16_t ttl = -1; + + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_int32_t response = -1; + os_uint16_t recv_data_len = 0; + os_uint32_t ping_time = 0; + os_int16_t ttl = -1; memset(resp, 0, sizeof(ping_resp_t)); @@ -57,10 +58,10 @@ os_err_t clm920rv3_ping(mo_object_t *module, const char *host, os_uint16_t len, char resp_buff[8 * AT_RESP_BUFF_SIZE_DEF] = {0}; /* Need to wait for 7 lines response msg */ - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .line_num = 2, - .timeout = 4 * OS_TICK_PER_SECOND}; + .line_num = 2, + .timeout = 4 * OS_TICK_PER_SECOND}; /* REF: CLM920RV3 CPING */ if (at_parser_exec_cmd(parser, &at_resp, "AT+CPING=%s", host) < 0) @@ -95,8 +96,8 @@ os_err_t clm920rv3_ping(mo_object_t *module, const char *host, os_uint16_t len, inet_aton(ip_addr, &(resp->ip_addr)); resp->data_len = recv_data_len; - resp->time = ping_time; - resp->ttl = ttl; + resp->time = ping_time; + resp->ttl = ttl; result = OS_EOK; break; @@ -108,7 +109,8 @@ os_err_t clm920rv3_ping(mo_object_t *module, const char *host, os_uint16_t len, __exit: - if (OS_EOK != result) ERROR("CLM920RV3 ping failed."); + if (OS_EOK != result) + ERROR("CLM920RV3 ping failed."); return result; } diff --git a/components/molink/module/e7025/include/e7025.h b/components/molink/module/e7025/include/e7025.h index 79b4d87c..d4b3dbe5 100644 --- a/components/molink/module/e7025/include/e7025.h +++ b/components/molink/module/e7025/include/e7025.h @@ -77,12 +77,12 @@ typedef struct mo_e7025 mo_object_t parent; #ifdef E7025_USING_NETCONN_OPS mo_netconn_t netconn[E7025_NETCONN_NUM]; - os_mutex_t netconn_lock; + os_mutex_t netconn_lock; #endif /* E7025_USING_NETCONN_OPS */ } mo_e7025_t; mo_object_t *module_e7025_create(const char *name, void *parser_config); -os_err_t module_e7025_destroy(mo_object_t *self); +os_err_t module_e7025_destroy(mo_object_t *self); #endif /* MOLINK_USING_E7025 */ diff --git a/components/molink/module/e7025/include/e7025_netconn.h b/components/molink/module/e7025/include/e7025_netconn.h index 085947c6..d9f632b7 100644 --- a/components/molink/module/e7025/include/e7025_netconn.h +++ b/components/molink/module/e7025/include/e7025_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef E7025_USING_NETCONN_OPS -os_err_t e7025_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t e7025_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *e7025_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t e7025_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t e7025_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t e7025_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t e7025_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t e7025_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t e7025_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef E7025_USING_DNS -os_err_t e7025_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t e7025_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* E7025_USING_NETCONN_OPS */ diff --git a/components/molink/module/e7025/source/e7025.c b/components/molink/module/e7025/source/e7025.c index e779e386..40c31e74 100644 --- a/components/molink/module/e7025/source/e7025.c +++ b/components/molink/module/e7025/source/e7025.c @@ -36,12 +36,12 @@ #ifdef E7025_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = e7025_at_test, - .get_imei = e7025_get_imei, - .get_imsi = e7025_get_imsi, + .at_test = e7025_at_test, + .get_imei = e7025_get_imei, + .get_imsi = e7025_get_imsi, .get_iccid = e7025_get_iccid, - .get_cfun = e7025_get_cfun, - .set_cfun = e7025_set_cfun, + .get_cfun = e7025_get_cfun, + .set_cfun = e7025_set_cfun, }; #endif /* E7025_USING_GENERAL_OPS */ @@ -49,11 +49,11 @@ static const struct mo_general_ops gs_general_ops = { static const struct mo_netserv_ops gs_netserv_ops = { .set_attach = e7025_set_attach, .get_attach = e7025_get_attach, - .set_reg = e7025_set_reg, - .get_reg = e7025_get_reg, - .set_cgact = e7025_set_cgact, - .get_cgact = e7025_get_cgact, - .get_csq = e7025_get_csq, + .set_reg = e7025_set_reg, + .get_reg = e7025_get_reg, + .set_cgact = e7025_set_cgact, + .get_cgact = e7025_get_cgact, + .get_csq = e7025_get_csq, }; #endif /* E7025_USING_NETSERV_OPS */ @@ -65,7 +65,7 @@ static const struct mo_ping_ops gs_ping_ops = { #ifdef E7025_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = e7025_ifconfig, + .ifconfig = e7025_ifconfig, .get_ipaddr = e7025_get_ipaddr, }; #endif /* E7025_USING_IFCONFIG_OPS */ @@ -74,14 +74,13 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void e7025_netconn_init(mo_e7025_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = e7025_netconn_create, - .destroy = e7025_netconn_destroy, + .create = e7025_netconn_create, + .destroy = e7025_netconn_destroy, #ifdef E7025_USING_DNS .gethostbyname = e7025_netconn_gethostbyname, -endif - .connect = e7025_netconn_connect, - .send = e7025_netconn_send, - .get_info = e7025_netconn_get_info, + endif.connect = e7025_netconn_connect, + .send = e7025_netconn_send, + .get_info = e7025_netconn_get_info, }; #endif /* E7025_USING_NETCONN_OPS */ @@ -98,9 +97,7 @@ static os_err_t e7025_at_init(mo_object_t *self) char resp_buff[32] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; return at_parser_exec_cmd(parser, &resp, "ATE0"); } @@ -200,7 +197,7 @@ int e7025_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = E7025_NAME, + mo_parser_config_t parser_config = {.parser_name = E7025_NAME, .parser_device = device, .recv_buff_len = E7025_RECV_BUFF_LEN}; diff --git a/components/molink/module/e7025/source/e7025_ifconfig.c b/components/molink/module/e7025/source/e7025_ifconfig.c index 73048e1b..f1f5cfa1 100644 --- a/components/molink/module/e7025/source/e7025_ifconfig.c +++ b/components/molink/module/e7025/source/e7025_ifconfig.c @@ -38,13 +38,13 @@ os_err_t e7025_ifconfig(mo_object_t *self) { char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; - char imei[MO_IMEI_LEN + 1] = {0}; - char iccid[MO_ICCID_LEN + 1] = {0}; + char imei[MO_IMEI_LEN + 1] = {0}; + char iccid[MO_ICCID_LEN + 1] = {0}; - os_err_t ret = OS_EOK; + os_err_t ret = OS_EOK; os_uint8_t rssi = 0; - os_uint8_t ber = 0; - os_int32_t i = 0; + os_uint8_t ber = 0; + os_int32_t i = 0; if (e7025_get_ipaddr(self, ipaddr) != OS_EOK) { @@ -67,7 +67,7 @@ os_err_t e7025_ifconfig(mo_object_t *self) if (e7025_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; ret = OS_ERROR; } @@ -96,7 +96,7 @@ os_err_t e7025_ifconfig(mo_object_t *self) os_err_t e7025_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t len = -1; + os_int8_t len = -1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; diff --git a/components/molink/module/e7025/source/e7025_netconn.c b/components/molink/module/e7025/source/e7025_netconn.c index 73ba7818..e1047205 100644 --- a/components/molink/module/e7025/source/e7025_netconn.c +++ b/components/molink/module/e7025/source/e7025_netconn.c @@ -33,7 +33,7 @@ #define DBG_EXT_LVL DBG_EXT_INFO #include -#define SEND_DATA_MAX_SIZE (1358) +#define SEND_DATA_MAX_SIZE (1358) #ifndef E7025_DATA_QUEUE_SIZE #define E7025_DATA_QUEUE_SIZE (5) @@ -96,17 +96,17 @@ os_err_t e7025_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_e7025_t *e7025 = os_container_of(module, mo_e7025_t, parent); info->netconn_array = e7025->netconn; - info->netconn_nums = sizeof(e7025->netconn) / sizeof(e7025->netconn[0]); + info->netconn_nums = sizeof(e7025->netconn) / sizeof(e7025->netconn[0]); return OS_EOK; } mo_netconn_t *e7025_netconn_create(mo_object_t *module, mo_netconn_type_t type) { - mo_e7025_t *e7025 = os_container_of(module, mo_e7025_t, parent); - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_int32_t conn_id = -1; + mo_e7025_t *e7025 = os_container_of(module, mo_e7025_t, parent); + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_int32_t conn_id = -1; e7025_lock(&e7025->netconn_lock); @@ -177,7 +177,7 @@ mo_netconn_t *e7025_netconn_create(mo_object_t *module, mo_netconn_type_t type) os_err_t e7025_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; LOG_EXT_I("Module %s in %d netconn status", module->name, netconn->stat); @@ -210,9 +210,9 @@ os_err_t e7025_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) LOG_EXT_I("Module %s netconn_id: %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); @@ -224,13 +224,11 @@ os_err_t e7025_netconn_gethostbyname(mo_object_t *self, const char *domain_name, { at_parser_t *parser = &self->parser; - char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; + char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 20 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+ECDNS=\"%s\"", domain_name); if (result < 0) @@ -257,7 +255,11 @@ os_err_t e7025_netconn_gethostbyname(mo_object_t *self, const char *domain_name, } else { - LOG_EXT_D("Module %s domain resolve: \"%s\" domain ip is %s, addrlen %d", self->name, domain_name, recvip, strlen(recvip)); + LOG_EXT_D("Module %s domain resolve: \"%s\" domain ip is %s, addrlen %d", + self->name, + domain_name, + recvip, + strlen(recvip)); inet_aton(recvip, addr); if (IPADDR_ANY == addr->addr || IPADDR_LOOPBACK == addr->addr) @@ -279,14 +281,12 @@ __exit: os_err_t e7025_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 20 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; strncpy(remote_ip, inet_ntoa(addr), IPADDR_MAX_STR_LEN); @@ -317,7 +317,7 @@ os_err_t e7025_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ad ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; LOG_EXT_D("Module %s connect to %s:%u successfully!", module->name, remote_ip, port); @@ -326,17 +326,15 @@ os_err_t e7025_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ad static os_size_t e7025_tcp_udp_send(at_parser_t *parser, mo_netconn_t *netconn, const char *data, os_size_t size) { - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t cur_pkt_size = 0; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t cur_pkt_size = 0; - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; - char send_cmd[128] = {0}; + char send_cmd[128] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 20 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; strncpy(remote_ip, inet_ntoa(netconn->remote_ip), IPADDR_MAX_STR_LEN); @@ -372,7 +370,9 @@ static os_size_t e7025_tcp_udp_send(at_parser_t *parser, mo_netconn_t *netconn, #ifdef E7025_USING_UDP case NETCONN_TYPE_UDP: - snprintf(send_cmd, sizeof(send_cmd), "AT+ECSOST=%d,\"%s\",%u,%d,", + snprintf(send_cmd, + sizeof(send_cmd), + "AT+ECSOST=%d,\"%s\",%u,%d,", netconn->connect_id, remote_ip, netconn->remote_port, @@ -416,10 +416,7 @@ __exit: if (result != OS_EOK) { - LOG_EXT_E("Module %s netconn %d send %d bytes data failed!", - parser->name, - netconn->connect_id, - cur_pkt_size); + LOG_EXT_E("Module %s netconn %d send %d bytes data failed!", parser->name, netconn->connect_id, cur_pkt_size); return 0; } @@ -429,8 +426,8 @@ __exit: os_size_t e7025_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_size_t sent_size = 0; + at_parser_t *parser = &module->parser; + os_size_t sent_size = 0; char *hexstr = calloc(1, size * 2 + 1); if (OS_NULL == hexstr) @@ -463,7 +460,7 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t err_code = 0; + os_int32_t err_code = 0; sscanf(data, "+ECSOCLI: %d,%d", &connect_id, &err_code); @@ -489,7 +486,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; + os_int32_t data_size = 0; /* For ex: +ECSONMI: 1,10,"30313233343536373839" -- the actual data is "0-9"*/ sscanf(data, "+ECSONMI: %d,%d,", &connect_id, &data_size); diff --git a/components/molink/module/e7025/source/e7025_netserv.c b/components/molink/module/e7025/source/e7025_netserv.c index 2b479a8b..b780015e 100644 --- a/components/molink/module/e7025/source/e7025_netserv.c +++ b/components/molink/module/e7025/source/e7025_netserv.c @@ -58,7 +58,7 @@ os_err_t e7025_get_attach(mo_object_t *self, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) { LOG_EXT_E("Get %s module attach state failed", self->name); return OS_ERROR; diff --git a/components/molink/module/e7025/source/e7025_ping.c b/components/molink/module/e7025/source/e7025_ping.c index 5eb531d1..432d8514 100644 --- a/components/molink/module/e7025/source/e7025_ping.c +++ b/components/molink/module/e7025/source/e7025_ping.c @@ -36,9 +36,9 @@ os_err_t e7025_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - os_int16_t req_time = -1; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; + os_int16_t req_time = -1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -72,10 +72,10 @@ os_err_t e7025_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uin char resp_buff[256] = {0}; /* At least, need to wait for 4 lines response msg */ - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .line_num = 4, - .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; + .line_num = 4, + .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; /* Exec AT+ECPING="180.101.147.115",1,64,10000; */ /* Def ping timeout: +ECPING: FAIL, dest: 180.101.147.115, time out: 10000 ms*/ @@ -87,9 +87,17 @@ os_err_t e7025_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uin goto __exit; } - if (at_resp_get_data_by_kw(&at_resp, "+ECPING: SUCC", "+ECPING: SUCC, dest: %[^,], RTT: %u ms", ipaddr, &req_time) <= 0) + if (at_resp_get_data_by_kw(&at_resp, + "+ECPING: SUCC", + "+ECPING: SUCC, dest: %[^,], RTT: %u ms", + ipaddr, + &req_time) <= 0) { - if(at_resp_get_data_by_kw(&at_resp, "+ECPING: FAIL", "+ECPING: FAIL, dest: %[^,], time out: %u ms", ipaddr, &req_time) <= 0) + if (at_resp_get_data_by_kw(&at_resp, + "+ECPING: FAIL", + "+ECPING: FAIL, dest: %[^,], time out: %u ms", + ipaddr, + &req_time) <= 0) { LOG_EXT_E("Module %s ping %s fail: check network status or try to set a longer timeout.", self->name, host); result = OS_ERROR; @@ -97,7 +105,6 @@ os_err_t e7025_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uin } } - LOG_EXT_D("Module %s ping: resp parse ip[%s], req_time[%d]", self->name, ipaddr, req_time); if (req_time == timeout) { @@ -110,7 +117,7 @@ os_err_t e7025_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uin inet_aton(ipaddr, &(resp->ip_addr)); resp->data_len = len; - resp->time = req_time; + resp->time = req_time; __exit: diff --git a/components/molink/module/ec20/include/ec20.h b/components/molink/module/ec20/include/ec20.h index eb7cac38..bd5d2dbe 100644 --- a/components/molink/module/ec20/include/ec20.h +++ b/components/molink/module/ec20/include/ec20.h @@ -76,7 +76,7 @@ typedef struct mo_ec20 { mo_object_t parent; #ifdef EC20_USING_NETCONN_OPS - os_bool_t pdp_act; + os_bool_t pdp_act; #endif /* EC20_USING_NETCONN_OPS */ #ifdef EC20_USING_NETCONN_OPS @@ -85,12 +85,12 @@ typedef struct mo_ec20 os_int32_t curr_connect; os_event_t netconn_evt; os_mutex_t netconn_lock; - void *netconn_data; + void *netconn_data; #endif /* EC20_USING_NETCONN_OPS */ } mo_ec20_t; mo_object_t *module_ec20_create(const char *name, void *parser_config); -os_err_t module_ec20_destroy(mo_object_t *self); +os_err_t module_ec20_destroy(mo_object_t *self); #endif /* MOLINK_USING_EC20 */ diff --git a/components/molink/module/ec20/include/ec20_netconn.h b/components/molink/module/ec20/include/ec20_netconn.h index 7954c6c4..68cb1c2a 100644 --- a/components/molink/module/ec20/include/ec20_netconn.h +++ b/components/molink/module/ec20/include/ec20_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef EC20_USING_NETCONN_OPS -os_err_t ec20_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t ec20_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *ec20_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t ec20_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t ec20_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t ec20_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t ec20_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t ec20_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t ec20_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef EC20_USING_DNS -os_err_t ec20_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t ec20_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* EC20_USING_NETCONN_OPS */ diff --git a/components/molink/module/ec20/source/ec20.c b/components/molink/module/ec20/source/ec20.c index 9868d2c5..5784286f 100644 --- a/components/molink/module/ec20/source/ec20.c +++ b/components/molink/module/ec20/source/ec20.c @@ -28,7 +28,7 @@ #include #define MO_LOG_TAG "ec20" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_EC20 @@ -37,40 +37,40 @@ #ifdef EC20_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = ec20_at_test, - .get_imei = ec20_get_imei, - .get_imsi = ec20_get_imsi, - .get_iccid = ec20_get_iccid, - .get_cfun = ec20_get_cfun, - .set_cfun = ec20_set_cfun, + .at_test = ec20_at_test, + .get_imei = ec20_get_imei, + .get_imsi = ec20_get_imsi, + .get_iccid = ec20_get_iccid, + .get_cfun = ec20_get_cfun, + .set_cfun = ec20_set_cfun, .get_firmware_version = ec20_get_firmware_version, }; #endif /* EC20_USING_GENERAL_OPS */ #ifdef EC20_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = ec20_set_attach, - .get_attach = ec20_get_attach, - .set_reg = ec20_set_reg, - .get_reg = ec20_get_reg, - .set_cgact = ec20_set_cgact, - .get_cgact = ec20_get_cgact, - .get_csq = ec20_get_csq, + .set_attach = ec20_set_attach, + .get_attach = ec20_get_attach, + .set_reg = ec20_set_reg, + .get_reg = ec20_get_reg, + .set_cgact = ec20_set_cgact, + .get_cgact = ec20_get_cgact, + .get_csq = ec20_get_csq, }; #endif /* EC20_USING_NETSERV_OPS */ #ifdef EC20_USING_PING_OPS static const struct mo_ping_ops gs_ping_ops = { - .ping = ec20_ping, + .ping = ec20_ping, }; #endif /* EC20_USING_PING_OPS */ #ifdef EC20_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = ec20_ifconfig, - .get_ipaddr = ec20_get_ipaddr, - .set_dnsserver = ec20_set_dnsserver, - .get_dnsserver = ec20_get_dnsserver, + .ifconfig = ec20_ifconfig, + .get_ipaddr = ec20_get_ipaddr, + .set_dnsserver = ec20_set_dnsserver, + .get_dnsserver = ec20_get_dnsserver, }; #endif /* EC20_USING_IFCONFIG_OPS */ @@ -78,22 +78,22 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void ec20_netconn_init(mo_ec20_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = ec20_netconn_create, - .destroy = ec20_netconn_destroy, + .create = ec20_netconn_create, + .destroy = ec20_netconn_destroy, #ifdef EC20_USING_DNS - .gethostbyname = ec20_netconn_gethostbyname, + .gethostbyname = ec20_netconn_gethostbyname, #endif - .connect = ec20_netconn_connect, - .send = ec20_netconn_send, - .get_info = ec20_netconn_get_info, + .connect = ec20_netconn_connect, + .send = ec20_netconn_send, + .get_info = ec20_netconn_get_info, }; #endif /* EC20_USING_NETCONN_OPS */ #ifdef EC20_USING_PPP_OPS static const struct mo_ppp_ops gs_ppp_ops = { - .ppp_init = ec20_ppp_init, - .ppp_dial = ec20_ppp_dial, - .ppp_exit = ec20_ppp_exit, + .ppp_init = ec20_ppp_init, + .ppp_dial = ec20_ppp_dial, + .ppp_exit = ec20_ppp_exit, }; #endif /* EC20_USING_PPP_OPS */ @@ -106,12 +106,12 @@ void ec20_poweron_sequence(void) os_task_msleep(500); os_pin_write(GET_PIN(A, 3), PIN_LOW); - INFO("%s Executed power on process.", __func__); + INFO("%s Executed power on process.", __func__); } static void urc_ready_func(struct at_parser *parser, const char *data, os_size_t size) { - DEBUG("ME initialization is successful"); + DEBUG("ME initialization is successful"); } static at_urc_t gs_urc_table[] = { @@ -127,15 +127,13 @@ static os_err_t ec20_at_init(mo_object_t *self) os_err_t result = at_parser_connect(parser, EC20_RETRY_TIMES); if (result != OS_EOK) { - ERROR("Connect to %s module failed, please check whether the module connection is correct", self->name); + ERROR("Connect to %s module failed, please check whether the module connection is correct", self->name); return result; } char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; return at_parser_exec_cmd(parser, &resp, "ATE0"); } @@ -144,7 +142,7 @@ mo_object_t *module_ec20_create(const char *name, void *parser_config) mo_ec20_t *module = (mo_ec20_t *)os_calloc(1, sizeof(mo_ec20_t)); if (OS_NULL == module) { - ERROR("Create %s module instance failed, no enough memory.", name); + ERROR("Create %s module instance failed, no enough memory.", name); return OS_NULL; } @@ -240,18 +238,18 @@ int ec20_auto_create(void) if (OS_NULL == device) { - ERROR("Auto create failed, Can not find EC20 interface device %s!", EC20_DEVICE_NAME); + ERROR("Auto create failed, Can not find EC20 interface device %s!", EC20_DEVICE_NAME); return OS_ERROR; } - - uart_config.baud_rate = EC20_DEVICE_RATE; + + uart_config.baud_rate = EC20_DEVICE_RATE; // ec20_poweron_sequence(); - INFO("Auto create %s module object with [%s]:[%d]bps", EC20_NAME, EC20_DEVICE_NAME, EC20_DEVICE_RATE); + INFO("Auto create %s module object with [%s]:[%d]bps", EC20_NAME, EC20_DEVICE_NAME, EC20_DEVICE_RATE); os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = EC20_NAME, + mo_parser_config_t parser_config = {.parser_name = EC20_NAME, .parser_device = device, .recv_buff_len = EC20_RECV_BUFF_LEN}; @@ -259,14 +257,14 @@ int ec20_auto_create(void) if (OS_NULL == module) { - ERROR("Auto create failed, Can not create %s module object!", EC20_NAME); + ERROR("Auto create failed, Can not create %s module object!", EC20_NAME); return OS_ERROR; } - INFO("Auto create %s module object success [%s]:[%d]bps!", EC20_NAME, EC20_DEVICE_NAME, EC20_DEVICE_RATE); + INFO("Auto create %s module object success [%s]:[%d]bps!", EC20_NAME, EC20_DEVICE_NAME, EC20_DEVICE_RATE); return OS_EOK; } -OS_CMPOENT_INIT(ec20_auto_create,OS_INIT_SUBLEVEL_MIDDLE); +OS_CMPOENT_INIT(ec20_auto_create, OS_INIT_SUBLEVEL_MIDDLE); #endif /* EC20_AUTO_CREATE */ diff --git a/components/molink/module/ec20/source/ec20_general.c b/components/molink/module/ec20/source/ec20_general.c index b5c7ff85..8587b04c 100644 --- a/components/molink/module/ec20/source/ec20_general.c +++ b/components/molink/module/ec20/source/ec20_general.c @@ -26,7 +26,7 @@ #include #define MO_LOG_TAG "ec20_general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef EC20_USING_GENERAL_OPS @@ -87,7 +87,7 @@ os_err_t ec20_get_imsi(mo_object_t *self, char *value, os_size_t len) return OS_ERROR; } - if (at_resp_get_data_by_line(&resp,1, "%s", value) <= 0) + if (at_resp_get_data_by_line(&resp, 1, "%s", value) <= 0) { ERROR("Get %s module imsi failed", self->name); return OS_ERROR; @@ -169,9 +169,7 @@ os_err_t ec20_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ver char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+GMR"); if (result != OS_EOK) @@ -186,7 +184,7 @@ os_err_t ec20_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ver } const char *source_line = at_resp_get_line(&resp, 1); - os_size_t line_length = strlen(source_line); + os_size_t line_length = strlen(source_line); /* TODO test return line or set to dynamic dump */ char **dest_line = &version->ver_info[0]; diff --git a/components/molink/module/ec20/source/ec20_ifconfig.c b/components/molink/module/ec20/source/ec20_ifconfig.c index da7e7541..ab52a5a0 100644 --- a/components/molink/module/ec20/source/ec20_ifconfig.c +++ b/components/molink/module/ec20/source/ec20_ifconfig.c @@ -28,7 +28,7 @@ #include #define MO_LOG_TAG "ec20_ifconfig" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef EC20_USING_IFCONFIG_OPS @@ -56,12 +56,12 @@ os_err_t ec20_ifconfig(mo_object_t *self) } os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t ber = 0; if (ec20_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; } os_kprintf("\r\nLIST AT MODULE INFORMATIONS\r\n"); @@ -89,7 +89,7 @@ os_err_t ec20_ifconfig(mo_object_t *self) os_err_t ec20_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t len = -1; + os_int8_t len = -1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -126,15 +126,15 @@ os_err_t ec20_get_ipaddr(mo_object_t *self, char ip[]) } __exit: - + return result; } os_err_t ec20_set_dnsserver(mo_object_t *self, dns_server_t dns) { at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - + os_err_t result = OS_EOK; + mo_ec20_t *ec20 = os_container_of(self, mo_ec20_t, parent); char ip[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -143,7 +143,7 @@ os_err_t ec20_set_dnsserver(mo_object_t *self, dns_server_t dns) ERROR("EC20 %s: module registrition hasn't been complete.", __func__); return OS_ERROR; } - + if (OS_FALSE == ec20->pdp_act) { result = ec20_pdp_act(self); @@ -179,14 +179,14 @@ os_err_t ec20_set_dnsserver(mo_object_t *self, dns_server_t dns) { result = at_parser_exec_cmd(parser, &resp, "AT+QIDNSCFG=1,\"%s\",\"%s\"", dns.primary_dns, dns.secondary_dns); } - + return result; } os_err_t ec20_get_dnsserver(mo_object_t *self, dns_server_t *dns) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; char primary_dns[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -204,14 +204,18 @@ os_err_t ec20_get_dnsserver(mo_object_t *self, dns_server_t *dns) char resp_buff[256] = {0}; - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .line_num = 2, - .timeout = OS_TICK_PER_SECOND}; + .line_num = 2, + .timeout = OS_TICK_PER_SECOND}; result = at_parser_exec_cmd(parser, &at_resp, "AT+QIDNSCFG=1"); - if (at_resp_get_data_by_kw(&at_resp, "+QIDNSCFG:", "+QIDNSCFG: 1,%[^,],\"%[^\"]", primary_dns, dns->secondary_dns) <= 0) + if (at_resp_get_data_by_kw(&at_resp, + "+QIDNSCFG:", + "+QIDNSCFG: 1,%[^,],\"%[^\"]", + primary_dns, + dns->secondary_dns) <= 0) { ERROR("EC20 %s: get dns failed.", __FUNCTION__); result = OS_ERROR; diff --git a/components/molink/module/ec20/source/ec20_netconn.c b/components/molink/module/ec20/source/ec20_netconn.c index c2afa269..744c93ad 100644 --- a/components/molink/module/ec20/source/ec20_netconn.c +++ b/components/molink/module/ec20/source/ec20_netconn.c @@ -29,7 +29,7 @@ #include #define MO_LOG_TAG "ec20_netconn" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define SEND_DATA_MAX_SIZE (1460) @@ -42,7 +42,7 @@ #endif #ifndef EC20_NETCONN_MQ_MSG_MAX -#define EC20_NETCONN_MQ_MSG_MAX (5) +#define EC20_NETCONN_MQ_MSG_MAX (5) #endif #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) @@ -133,7 +133,7 @@ os_err_t ec20_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_ec20_t *ec20 = os_container_of(module, mo_ec20_t, parent); info->netconn_array = ec20->netconn; - info->netconn_nums = sizeof(ec20->netconn) / sizeof(ec20->netconn[0]); + info->netconn_nums = sizeof(ec20->netconn) / sizeof(ec20->netconn[0]); return OS_EOK; } @@ -141,7 +141,7 @@ os_err_t ec20_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) os_err_t ec20_pdp_act(mo_object_t *module) { char tmp_data[20] = {0}; - char APN[10] = {0}; + char APN[10] = {0}; at_parser_t *parser = &module->parser; @@ -163,7 +163,6 @@ os_err_t ec20_pdp_act(mo_object_t *module) goto __exit; } - if (strcmp(tmp_data, "CHINA MOBILE") == 0) { strncpy(APN, "CMNET", strlen("CMNET")); @@ -225,9 +224,7 @@ mo_netconn_t *ec20_netconn_create(mo_object_t *module, mo_netconn_type_t type) return OS_NULL; } - netconn->mq = os_mq_create(EC20_NETCONN_MQ_NAME, - EC20_NETCONN_MQ_MSG_SIZE, - EC20_NETCONN_MQ_MSG_MAX); + netconn->mq = os_mq_create(EC20_NETCONN_MQ_NAME, EC20_NETCONN_MQ_MSG_SIZE, EC20_NETCONN_MQ_MSG_MAX); if (OS_NULL == netconn->mq) { ERROR("%s data queue create failed, no enough memory.", module->name); @@ -235,7 +232,6 @@ mo_netconn_t *ec20_netconn_create(mo_object_t *module, mo_netconn_type_t type) return OS_NULL; } - netconn->stat = NETCONN_STAT_INIT; netconn->type = type; @@ -247,7 +243,7 @@ mo_netconn_t *ec20_netconn_create(mo_object_t *module, mo_netconn_type_t type) os_err_t ec20_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; DEBUG("Module %s in %d netconn status", module->name, netconn->stat); @@ -263,8 +259,8 @@ os_err_t ec20_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) if (result != OS_EOK) { ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + module->name, + (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); return result; } break; @@ -281,9 +277,9 @@ os_err_t ec20_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn id %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); @@ -381,7 +377,7 @@ __exit: { ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); } @@ -395,11 +391,11 @@ __exit: os_size_t ec20_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t curr_size = 0; - os_uint32_t event = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t curr_size = 0; + os_uint32_t event = 0; mo_ec20_t *ec20 = os_container_of(module, mo_ec20_t, parent); @@ -409,9 +405,7 @@ os_size_t ec20_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const ch char resp_buff[EC20_RESP_DEF_SIZE] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 10 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; at_parser_set_end_mark(parser, ">", 1); @@ -502,7 +496,7 @@ os_err_t ec20_netconn_gethostbyname(mo_object_t *self, const char *domain_name, OS_ASSERT(OS_NULL != addr); at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[EC20_RESP_DEF_SIZE] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = OS_TICK_PER_SECOND}; @@ -558,9 +552,9 @@ static void urc_connect_func(struct at_parser *parser, const char *data, os_size mo_ec20_t *ec20 = os_container_of(module, mo_ec20_t, parent); os_int32_t connect_id = 0; - os_int32_t result = 0; + os_int32_t result = 0; - sscanf(data, "+QIOPEN: %d,%d", &connect_id , &result); + sscanf(data, "+QIOPEN: %d,%d", &connect_id, &result); if (0 == result) { @@ -623,7 +617,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; + os_int32_t data_size = 0; sscanf(data, "+QIURC: \"recv\",%d,%d", &connect_id, &data_size); @@ -638,13 +632,13 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t return; } - char *recv_buff = os_calloc(1, data_size); - char temp_buff[8] = {0}; + char *recv_buff = os_calloc(1, data_size); + char temp_buff[8] = {0}; if (recv_buff == OS_NULL) { /* read and clean the coming data */ ERROR("Calloc recv buff %d bytes fail, no enough memory", data_size); - os_size_t temp_size = 0; + os_size_t temp_size = 0; while (temp_size < data_size) { if (data_size - temp_size > sizeof(temp_buff)) @@ -762,9 +756,9 @@ static void urc_qiurc_func(struct at_parser *parser, const char *data, os_size_t } static at_urc_t gs_urc_table[] = { - {.prefix = "SEND", .suffix = "\r\n", .func = urc_send_func}, + {.prefix = "SEND", .suffix = "\r\n", .func = urc_send_func}, {.prefix = "+QIOPEN:", .suffix = "\r\n", .func = urc_connect_func}, - {.prefix = "+QIURC:", .suffix = "\r\n", .func = urc_qiurc_func}, + {.prefix = "+QIURC:", .suffix = "\r\n", .func = urc_qiurc_func}, }; void ec20_netconn_init(mo_ec20_t *module) @@ -776,7 +770,7 @@ void ec20_netconn_init(mo_ec20_t *module) module->netconn[i].connect_id = -1; } - ec20_pdp_act(&module->parent); + ec20_pdp_act(&module->parent); /* Set netconn urc table */ at_parser_t *parser = &(module->parent.parser); diff --git a/components/molink/module/ec20/source/ec20_netserv.c b/components/molink/module/ec20/source/ec20_netserv.c index 2b624933..9098580f 100644 --- a/components/molink/module/ec20/source/ec20_netserv.c +++ b/components/molink/module/ec20/source/ec20_netserv.c @@ -32,7 +32,7 @@ #endif /* MOLINK_USING_IP */ #define MO_LOG_TAG "ec20_netserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef EC20_USING_NETSERV_OPS @@ -62,12 +62,12 @@ os_err_t ec20_get_attach(mo_object_t *self, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) { ERROR("Get %s module attach state failed", self->name); return OS_ERROR; } - + return OS_EOK; } @@ -121,10 +121,10 @@ os_err_t ec20_get_cgact(mo_object_t *self, os_uint8_t *cid, os_uint8_t *act_stat at_parser_t *parser = &self->parser; char resp_buff[128] = {0}; - char tem_cgact[20] = {0}; + char tem_cgact[20] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 150 * AT_RESP_TIMEOUT_DEF}; - if (*cid < 1 || *cid > 5) + if (*cid < 1 || *cid > 5) { ERROR("%s module cgact cid range is [1,5], input out of range", self->name); return OS_ERROR; diff --git a/components/molink/module/ec20/source/ec20_ping.c b/components/molink/module/ec20/source/ec20_ping.c index 62e2f0ec..1765b17b 100644 --- a/components/molink/module/ec20/source/ec20_ping.c +++ b/components/molink/module/ec20/source/ec20_ping.c @@ -25,23 +25,23 @@ #include #define MO_LOG_TAG "ec20_ping" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" -#define EC20_MIN_PING_TIME (1) -#define EC20_MAX_PING_TIME (255) +#define EC20_MIN_PING_TIME (1) +#define EC20_MAX_PING_TIME (255) #ifdef EC20_USING_PING_OPS os_err_t ec20_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - os_int32_t response = -1; - os_uint16_t recv_data_len = 0; - os_uint32_t ping_time = 0; - os_int16_t ttl = -1; - os_uint32_t timeout_s = timeout / 1000; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; + os_int32_t response = -1; + os_uint16_t recv_data_len = 0; + os_uint32_t ping_time = 0; + os_int16_t ttl = -1; + os_uint32_t timeout_s = timeout / 1000; memset(resp, 0, sizeof(ping_resp_t)); @@ -49,34 +49,36 @@ os_err_t ec20_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint if (parser == OS_NULL) { - ERROR("EC20 ping: at parser is NULL."); + ERROR("EC20 ping: at parser is NULL."); return OS_ERROR; } - DEBUG("EC20 series module does not support setting ping package size."); + DEBUG("EC20 series module does not support setting ping package size."); /* ec20 ping timeout_s range: 1s-255s */ if ((timeout_s < EC20_MIN_PING_TIME) || (timeout_s > EC20_MAX_PING_TIME)) { - ERROR("EC20 ping: ping timeout_s %us is out of range[%ds, %ds].", - timeout_s, EC20_MIN_PING_TIME, EC20_MAX_PING_TIME); + ERROR("EC20 ping: ping timeout_s %us is out of range[%ds, %ds].", + timeout_s, + EC20_MIN_PING_TIME, + EC20_MAX_PING_TIME); return OS_ERROR; } - DEBUG("EC20 ping: %s, timeout_s: %us", host, timeout_s); + DEBUG("EC20 ping: %s, timeout_s: %us", host, timeout_s); char resp_buff[256] = {0}; /* Need to wait for 4 lines response msg */ - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .line_num = 3, - .timeout = (5 + timeout_s) * OS_TICK_PER_SECOND}; + .line_num = 3, + .timeout = (5 + timeout_s) * OS_TICK_PER_SECOND}; /* REF: EC20 QPING */ if (at_parser_exec_cmd(parser, &at_resp, "AT+QPING=1,\"%s\",%u,1", host, timeout_s) < 0) { - ERROR("Ping: AT cmd exec fail: AT+QPING=1,\"%s\",%u,1", host, timeout_s); + ERROR("Ping: AT cmd exec fail: AT+QPING=1,\"%s\",%u,1", host, timeout_s); result = OS_ERROR; goto __exit; } @@ -106,8 +108,8 @@ os_err_t ec20_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint inet_aton(ip_addr, &(resp->ip_addr)); resp->data_len = recv_data_len; - resp->time = ping_time; - resp->ttl = ttl; + resp->time = ping_time; + resp->ttl = ttl; result = OS_EOK; break; diff --git a/components/molink/module/ec20/source/ec20_ppp.c b/components/molink/module/ec20/source/ec20_ppp.c index 85acbfbd..d38fb9dc 100644 --- a/components/molink/module/ec20/source/ec20_ppp.c +++ b/components/molink/module/ec20/source/ec20_ppp.c @@ -43,11 +43,11 @@ os_err_t ec20_ppp_init(mo_object_t *module) { OS_ASSERT(OS_NULL != module); - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; at_parser_t *parser = &module->parser; - char tmp_data[20] = {0}; - char APN[10] = {0}; + char tmp_data[20] = {0}; + char APN[10] = {0}; char resp_buff[256] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = OS_TICK_PER_SECOND}; @@ -71,7 +71,7 @@ os_err_t ec20_ppp_init(mo_object_t *module) /* Query current Network Operator */ result = at_parser_exec_cmd(parser, &resp, "AT+COPS?"); - + if (result != OS_EOK) { LOG_EXT_E("%s query APN failed!", __func__); @@ -100,18 +100,19 @@ os_err_t ec20_ppp_init(mo_object_t *module) /* Set PDP context */ memset(resp_buff, 0, sizeof(resp_buff)); result = at_parser_exec_cmd(parser, &resp, "AT+CGDCONT=1,\"IP\",\"%s\"", APN); - + if (OS_EOK != result) { LOG_EXT_E("%s set apn failed!", __func__); goto __exit; } - else LOG_EXT_I("%s set apn success", __func__); + else + LOG_EXT_I("%s set apn success", __func__); /* deact pdp max timeout:40s */ resp.timeout = 40 * OS_TICK_PER_SECOND; result = at_parser_exec_cmd(parser, &resp, "AT+QIDEACT=1"); - + if (result != OS_EOK) { LOG_EXT_E("%s deactice PDP context (QIDEACT) failed!", __func__); @@ -121,7 +122,7 @@ os_err_t ec20_ppp_init(mo_object_t *module) /* act pdp max timeout:150s */ resp.timeout = 150 * OS_TICK_PER_SECOND; result = at_parser_exec_cmd(parser, &resp, "AT+QIACT=1"); - + if (result != OS_EOK) { LOG_EXT_E("%s actice PDP context (QIACT) failed!", __func__); @@ -142,13 +143,10 @@ os_err_t ec20_ppp_dial(mo_object_t *module) OS_ASSERT(OS_NULL != module); at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .line_num = 2, - .buff_size = sizeof(resp_buff), - .timeout = OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .line_num = 2, .buff_size = sizeof(resp_buff), .timeout = OS_TICK_PER_SECOND}; /* Start PPP dialing by ATD*99# */ result = at_parser_exec_cmd(parser, &resp, "ATD*99#"); @@ -182,7 +180,7 @@ __exit: { LOG_EXT_I("%s Into PPP data mode!", __func__); } - + return result; } @@ -192,8 +190,8 @@ os_err_t ec20_ppp_exit(mo_object_t *module) /* ec20 needs more than 1s around +++ input */ const int EC20_PPP_EXIT_DELAY_MS = 2000; - - os_err_t result = OS_EOK; + + os_err_t result = OS_EOK; at_parser_t *parser = &module->parser; /* rebind device for ppp using */ @@ -203,43 +201,41 @@ os_err_t ec20_ppp_exit(mo_object_t *module) LOG_EXT_E("%s at rebind device failed!", __func__); goto __exit; } - + /* exit ppp, do not send anything to device in exit process */ /* 1) Do not input any character within 1s or longer before inputting “+++”. */ os_task_mdelay(EC20_PPP_EXIT_DELAY_MS); - + /* 2) Input “+++” within 1s, and no other characters can be inputted during the time. */ os_device_write_block(parser->device, 0, "+++", 3); - + /* 3) Do not input any character within 1s after “+++” has been inputted. */ os_task_mdelay(EC20_PPP_EXIT_DELAY_MS); /* unlock at_parser_exec lock */ at_parser_exec_unlock(parser); - + /* test result by at cmd */ for (int i = 0; i < 5; i++) { result = mo_at_test(module); - if (OS_EOK == result) break; + if (OS_EOK == result) + break; } - + __exit: if (OS_EOK != result) { LOG_EXT_E("%s ppp exit failed", __func__); } - else + else { LOG_EXT_I("%s ppp exit success, into command mode.", __func__); } - return result; } - - #endif /* EC20_USING_PPP_OPS */ diff --git a/components/molink/module/ec200x_600s/include/ec200x_600s.h b/components/molink/module/ec200x_600s/include/ec200x_600s.h index 5a515af4..7a20e6d3 100644 --- a/components/molink/module/ec200x_600s/include/ec200x_600s.h +++ b/components/molink/module/ec200x_600s/include/ec200x_600s.h @@ -77,12 +77,12 @@ typedef struct mo_ec200x_600s os_int32_t curr_connect; os_event_t netconn_evt; os_mutex_t netconn_lock; - void *netconn_data; + void *netconn_data; #endif /* EC200X_600S_USING_NETCONN_OPS */ } mo_ec200x_600s_t; mo_object_t *module_ec200x_600s_create(const char *name, void *parser_config); -os_err_t module_ec200x_600s_destroy(mo_object_t *self); +os_err_t module_ec200x_600s_destroy(mo_object_t *self); #endif /* MOLINK_USING_EC200X_600S */ diff --git a/components/molink/module/ec200x_600s/include/ec200x_600s_netconn.h b/components/molink/module/ec200x_600s/include/ec200x_600s_netconn.h index 7d02008c..f2d50dbf 100644 --- a/components/molink/module/ec200x_600s/include/ec200x_600s_netconn.h +++ b/components/molink/module/ec200x_600s/include/ec200x_600s_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef EC200X_600S_USING_NETCONN_OPS -os_err_t ec200x_600s_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t ec200x_600s_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *ec200x_600s_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t ec200x_600s_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t ec200x_600s_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t ec200x_600s_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t ec200x_600s_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t ec200x_600s_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t ec200x_600s_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef EC200X_600S_USING_DNS -os_err_t ec200x_600s_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t ec200x_600s_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* EC200X_600S_USING_NETCONN_OPS */ diff --git a/components/molink/module/ec200x_600s/include/ec200x_600s_ping.h b/components/molink/module/ec200x_600s/include/ec200x_600s_ping.h index e02c678b..4fd0fe26 100644 --- a/components/molink/module/ec200x_600s/include/ec200x_600s_ping.h +++ b/components/molink/module/ec200x_600s/include/ec200x_600s_ping.h @@ -31,7 +31,8 @@ extern "C" { #ifdef EC200X_600S_USING_PING_OPS -os_err_t ec200x_600s_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); +os_err_t +ec200x_600s_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); #endif /* EC200X_600S_USING_PING_OPS */ diff --git a/components/molink/module/ec200x_600s/source/ec200x_600s.c b/components/molink/module/ec200x_600s/source/ec200x_600s.c index a0234988..7499ccb1 100644 --- a/components/molink/module/ec200x_600s/source/ec200x_600s.c +++ b/components/molink/module/ec200x_600s/source/ec200x_600s.c @@ -36,39 +36,39 @@ #ifdef EC200X_600S_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = ec200x_600s_at_test, - .get_imei = ec200x_600s_get_imei, - .get_imsi = ec200x_600s_get_imsi, - .get_iccid = ec200x_600s_get_iccid, - .get_cfun = ec200x_600s_get_cfun, - .set_cfun = ec200x_600s_set_cfun, + .at_test = ec200x_600s_at_test, + .get_imei = ec200x_600s_get_imei, + .get_imsi = ec200x_600s_get_imsi, + .get_iccid = ec200x_600s_get_iccid, + .get_cfun = ec200x_600s_get_cfun, + .set_cfun = ec200x_600s_set_cfun, .get_firmware_version = ec200x_600s_get_firmware_version, - .sleep_mode_set = ec200x_600s_sleep_mode_set, + .sleep_mode_set = ec200x_600s_sleep_mode_set, }; #endif /* EC200X_600S_USING_GENERAL_OPS */ #ifdef EC200X_600S_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = ec200x_600s_set_attach, - .get_attach = ec200x_600s_get_attach, - .set_reg = ec200x_600s_set_reg, - .get_reg = ec200x_600s_get_reg, - .set_cgact = ec200x_600s_set_cgact, - .get_cgact = ec200x_600s_get_cgact, - .get_csq = ec200x_600s_get_csq, + .set_attach = ec200x_600s_set_attach, + .get_attach = ec200x_600s_get_attach, + .set_reg = ec200x_600s_set_reg, + .get_reg = ec200x_600s_get_reg, + .set_cgact = ec200x_600s_set_cgact, + .get_cgact = ec200x_600s_get_cgact, + .get_csq = ec200x_600s_get_csq, }; #endif /* EC200X_600S_USING_NETSERV_OPS */ #ifdef EC200X_600S_USING_PING_OPS static const struct mo_ping_ops gs_ping_ops = { - .ping = ec200x_600s_ping, + .ping = ec200x_600s_ping, }; #endif /* EC200X_600S_USING_PING_OPS */ #ifdef EC200X_600S_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = ec200x_600s_ifconfig, - .get_ipaddr = ec200x_600s_get_ipaddr, + .ifconfig = ec200x_600s_ifconfig, + .get_ipaddr = ec200x_600s_get_ipaddr, }; #endif /* EC200X_600S_USING_IFCONFIG_OPS */ @@ -76,14 +76,14 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void ec200x_600s_netconn_init(mo_ec200x_600s_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = ec200x_600s_netconn_create, - .destroy = ec200x_600s_netconn_destroy, + .create = ec200x_600s_netconn_create, + .destroy = ec200x_600s_netconn_destroy, #ifdef EC200X_600S_USING_DNS - .gethostbyname = ec200x_600s_netconn_gethostbyname, + .gethostbyname = ec200x_600s_netconn_gethostbyname, #endif - .connect = ec200x_600s_netconn_connect, - .send = ec200x_600s_netconn_send, - .get_info = ec200x_600s_netconn_get_info, + .connect = ec200x_600s_netconn_connect, + .send = ec200x_600s_netconn_send, + .get_info = ec200x_600s_netconn_get_info, }; #endif /* EC200X_600S_USING_NETCONN_OPS */ @@ -218,7 +218,7 @@ int ec200x_600s_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = EC200X_600S_NAME, + mo_parser_config_t parser_config = {.parser_name = EC200X_600S_NAME, .parser_device = device, .recv_buff_len = EC200X_600S_RECV_BUFF_LEN}; diff --git a/components/molink/module/ec200x_600s/source/ec200x_600s_general.c b/components/molink/module/ec200x_600s/source/ec200x_600s_general.c index 05e91cc5..0f6e3f9a 100644 --- a/components/molink/module/ec200x_600s/source/ec200x_600s_general.c +++ b/components/molink/module/ec200x_600s/source/ec200x_600s_general.c @@ -186,7 +186,7 @@ os_err_t ec200x_600s_get_firmware_version(mo_object_t *self, mo_firmware_version } const char *source_line = at_resp_get_line(&resp, 1); - os_size_t line_length = strlen(source_line); + os_size_t line_length = strlen(source_line); char **dest_line = &version->ver_info[0]; @@ -203,8 +203,6 @@ os_err_t ec200x_600s_get_firmware_version(mo_object_t *self, mo_firmware_version return OS_EOK; } - - #ifndef EC200X_600S_DTR_PIN_NUM #define EC200X_600S_DTR_PIN_NUM (-1) #endif @@ -220,10 +218,10 @@ os_err_t ec200x_600s_sleep_mode_set(mo_object_t *self, os_uint8_t fun_lvl) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; os_err_t result; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; - + os_pin_mode(EC200X_600S_DTR_PIN_NUM, PIN_MODE_OUTPUT); os_pin_mode(EC200X_600S_WAKE_IN_PIN_NUM, PIN_MODE_OUTPUT); - + if (fun_lvl == 1) { result = at_parser_exec_cmd(parser, &resp, "AT+QSCLK=1"); @@ -231,33 +229,31 @@ os_err_t ec200x_600s_sleep_mode_set(mo_object_t *self, os_uint8_t fun_lvl) { return result; } - os_pin_write(EC200X_600S_DTR_PIN_NUM,PIN_HIGH); - os_pin_write(EC200X_600S_WAKE_IN_PIN_NUM,PIN_HIGH); - - os_task_msleep(6000); + os_pin_write(EC200X_600S_DTR_PIN_NUM, PIN_HIGH); + os_pin_write(EC200X_600S_WAKE_IN_PIN_NUM, PIN_HIGH); + + os_task_msleep(6000); } else if (fun_lvl == 0) - { - os_pin_write(EC200X_600S_DTR_PIN_NUM,PIN_LOW); - os_pin_write(EC200X_600S_WAKE_IN_PIN_NUM,PIN_LOW); - + { + os_pin_write(EC200X_600S_DTR_PIN_NUM, PIN_LOW); + os_pin_write(EC200X_600S_WAKE_IN_PIN_NUM, PIN_LOW); + os_task_msleep(200); - + os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+QSCLK=0"); if (result != OS_EOK) { return result; - } - } + } + } else { ERROR("Set sleep mode arg error,the arg is 0 or 1!"); return OS_ERROR; } - + return OS_EOK; } - - #endif /* EC200X_600S_USING_GENERAL_OPS */ diff --git a/components/molink/module/ec200x_600s/source/ec200x_600s_ifconfig.c b/components/molink/module/ec200x_600s/source/ec200x_600s_ifconfig.c index 001bf71d..1571308e 100644 --- a/components/molink/module/ec200x_600s/source/ec200x_600s_ifconfig.c +++ b/components/molink/module/ec200x_600s/source/ec200x_600s_ifconfig.c @@ -37,13 +37,13 @@ os_err_t ec200x_600s_ifconfig(mo_object_t *self) { char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; - char imei[MO_IMEI_LEN + 1] = {0}; - char iccid[MO_ICCID_LEN + 1] = {0}; - char imsi[MO_IMSI_LEN + 1] = {0}; + char imei[MO_IMEI_LEN + 1] = {0}; + char iccid[MO_ICCID_LEN + 1] = {0}; + char imsi[MO_IMSI_LEN + 1] = {0}; os_uint8_t rssi = 0; - os_uint8_t ber = 0; - os_err_t ret = OS_EOK; + os_uint8_t ber = 0; + os_err_t ret = OS_EOK; if (ec200x_600s_get_ipaddr(self, ipaddr) != OS_EOK) { @@ -72,7 +72,7 @@ os_err_t ec200x_600s_ifconfig(mo_object_t *self) if (ec200x_600s_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; ret = OS_ERROR; } @@ -102,9 +102,9 @@ os_err_t ec200x_600s_ifconfig(mo_object_t *self) os_err_t ec200x_600s_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t len = -1; + os_int8_t len = -1; - char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; + char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_128] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; diff --git a/components/molink/module/ec200x_600s/source/ec200x_600s_netconn.c b/components/molink/module/ec200x_600s/source/ec200x_600s_netconn.c index 964d3df4..18342291 100644 --- a/components/molink/module/ec200x_600s/source/ec200x_600s_netconn.c +++ b/components/molink/module/ec200x_600s/source/ec200x_600s_netconn.c @@ -41,7 +41,7 @@ #endif #ifndef EC200X_600S_NETCONN_MQ_MSG_MAX -#define EC200X_600S_NETCONN_MQ_MSG_MAX (16) +#define EC200X_600S_NETCONN_MQ_MSG_MAX (16) #endif #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) @@ -131,7 +131,7 @@ os_err_t ec200x_600s_netconn_get_info(mo_object_t *module, mo_netconn_info_t *in mo_ec200x_600s_t *ec200x_600s = os_container_of(module, mo_ec200x_600s_t, parent); info->netconn_array = ec200x_600s->netconn; - info->netconn_nums = sizeof(ec200x_600s->netconn) / sizeof(ec200x_600s->netconn[0]); + info->netconn_nums = sizeof(ec200x_600s->netconn) / sizeof(ec200x_600s->netconn[0]); return OS_EOK; } @@ -150,7 +150,8 @@ mo_netconn_t *ec200x_600s_netconn_create(mo_object_t *module, mo_netconn_type_t return OS_NULL; } - netconn->mq = os_mq_create(EC200X_600S_NETCONN_MQ_NAME, EC200X_600S_NETCONN_MQ_MSG_SIZE, EC200X_600S_NETCONN_MQ_MSG_MAX); + netconn->mq = + os_mq_create(EC200X_600S_NETCONN_MQ_NAME, EC200X_600S_NETCONN_MQ_MSG_SIZE, EC200X_600S_NETCONN_MQ_MSG_MAX); if (OS_NULL == netconn->mq) { ERROR("%s data queue create failed, no enough memory.", module->name); @@ -169,7 +170,7 @@ mo_netconn_t *ec200x_600s_netconn_create(mo_object_t *module, mo_netconn_type_t os_err_t ec200x_600s_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; DEBUG("Module %s in %d netconn status", module->name, netconn->stat); @@ -213,9 +214,9 @@ os_err_t ec200x_600s_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn id %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); @@ -226,10 +227,10 @@ os_err_t ec200x_600s_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) os_err_t ec200x_600s_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port) { - at_parser_t *parser = &module->parser; + at_parser_t *parser = &module->parser; mo_ec200x_600s_t *ec200x_600s = os_container_of(module, mo_ec200x_600s_t, parent); - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 150 * OS_TICK_PER_SECOND}; @@ -315,7 +316,7 @@ __exit: { ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); } @@ -329,11 +330,11 @@ __exit: os_size_t ec200x_600s_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t curr_size = 0; - os_uint32_t event = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t curr_size = 0; + os_uint32_t event = 0; mo_ec200x_600s_t *ec200x_600s = os_container_of(module, mo_ec200x_600s_t, parent); @@ -343,9 +344,7 @@ os_size_t ec200x_600s_netconn_send(mo_object_t *module, mo_netconn_t *netconn, c char resp_buff[AT_RESP_BUFF_SIZE_128] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 5 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; /* Protect data sending process, prevent other threads to send AT commands */ at_parser_exec_lock(parser); @@ -438,7 +437,7 @@ os_err_t ec200x_600s_netconn_gethostbyname(mo_object_t *self, const char *domain OS_ASSERT(OS_NULL != addr); at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[AT_RESP_BUFF_SIZE_128] = {0}; @@ -483,13 +482,13 @@ static void urc_connect_func(struct at_parser *parser, const char *data, os_size OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_ec200x_600s_t *ec200x_600s = os_container_of(module, mo_ec200x_600s_t, parent); os_int32_t connect_id = 0; - os_int32_t result = 0; + os_int32_t result = 0; - sscanf(data, "+QIOPEN: %d,%d", &connect_id , &result); + sscanf(data, "+QIOPEN: %d,%d", &connect_id, &result); if (0 == result) { @@ -508,7 +507,7 @@ static void urc_send_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_ec200x_600s_t *ec200x_600s = os_container_of(module, mo_ec200x_600s_t, parent); os_int32_t curr_connect = ec200x_600s->curr_connect; @@ -534,7 +533,7 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t sscanf(data, "+QIURC: \"closed\",%d", &connect_id); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = ec200x_600s_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) { @@ -555,7 +554,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; + os_int32_t data_size = 0; sscanf(data, "+QIURC: \"recv\",%d,%d", &connect_id, &data_size); @@ -563,7 +562,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t INFO("Moudle %s netconn %d receive %d bytes data", parser->name, connect_id, data_size); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = ec200x_600s_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) { @@ -571,14 +570,14 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t return; } - char *recv_buff = os_calloc(1, data_size); - char temp_buff[8] = {0}; + char *recv_buff = os_calloc(1, data_size); + char temp_buff[8] = {0}; if (recv_buff == OS_NULL) { /* read and clean the coming data */ ERROR("Calloc recv buff %d bytes fail, no enough memory", data_size); - os_size_t temp_size = 0; + os_size_t temp_size = 0; while (temp_size < data_size) { if (data_size - temp_size > sizeof(temp_buff)) @@ -632,7 +631,7 @@ static void urc_dnsqip_func(struct at_parser *parser, const char *data, os_size_ OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_ec200x_600s_t *ec200x_600s = os_container_of(module, mo_ec200x_600s_t, parent); int j = 0; @@ -704,23 +703,21 @@ static void urc_qiurc_func(struct at_parser *parser, const char *data, os_size_t } static at_urc_t gs_urc_table[] = { - {.prefix = "SEND", .suffix = "\r\n", .func = urc_send_func}, + {.prefix = "SEND", .suffix = "\r\n", .func = urc_send_func}, {.prefix = "+QIOPEN:", .suffix = "\r\n", .func = urc_connect_func}, - {.prefix = "+QIURC:", .suffix = "\r\n", .func = urc_qiurc_func}, + {.prefix = "+QIURC:", .suffix = "\r\n", .func = urc_qiurc_func}, }; static os_err_t ec200x_600s_network_init(mo_object_t *module) { char tmp_data[20] = {0}; - char APN[10] = {0}; + char APN[10] = {0}; at_parser_t *parser = &module->parser; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 10 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; /* Use AT+COPS? to query current Network Operator */ os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+COPS?"); diff --git a/components/molink/module/ec200x_600s/source/ec200x_600s_netserv.c b/components/molink/module/ec200x_600s/source/ec200x_600s_netserv.c index 9b74925c..2e0180d3 100644 --- a/components/molink/module/ec200x_600s/source/ec200x_600s_netserv.c +++ b/components/molink/module/ec200x_600s/source/ec200x_600s_netserv.c @@ -43,7 +43,7 @@ os_err_t ec200x_600s_set_attach(mo_object_t *self, os_uint8_t attach_stat) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 140 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 140 * OS_TICK_PER_SECOND}; return at_parser_exec_cmd(parser, &resp, "AT+CGATT=%hhu", attach_stat); } @@ -62,7 +62,7 @@ os_err_t ec200x_600s_get_attach(mo_object_t *self, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) { ERROR("Get %s module attach state failed", self->name); return OS_ERROR; diff --git a/components/molink/module/ec200x_600s/source/ec200x_600s_ping.c b/components/molink/module/ec200x_600s/source/ec200x_600s_ping.c index 2d9269b7..dfad0489 100644 --- a/components/molink/module/ec200x_600s/source/ec200x_600s_ping.c +++ b/components/molink/module/ec200x_600s/source/ec200x_600s_ping.c @@ -27,22 +27,23 @@ #define MO_LOG_LVL MO_LOG_INFO #include -#define EC200X_600S_MIN_PING_TIME (1) -#define EC200X_600S_MAX_PING_TIME (255) -#define EC200X_600S_PING_OK (0) -#define EC200X_600S_PING_TIMEOUT (569) +#define EC200X_600S_MIN_PING_TIME (1) +#define EC200X_600S_MAX_PING_TIME (255) +#define EC200X_600S_PING_OK (0) +#define EC200X_600S_PING_TIMEOUT (569) #ifdef EC200X_600S_USING_PING_OPS -os_err_t ec200x_600s_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) +os_err_t +ec200x_600s_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - os_int32_t response = -1; - os_uint16_t recv_data_len = 0; - os_uint32_t ping_time = 0; - os_int16_t ttl = -1; - os_uint32_t timeout_s = timeout / 1000; /* Milliseconds convert to seconds */ + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; + os_int32_t response = -1; + os_uint16_t recv_data_len = 0; + os_uint32_t ping_time = 0; + os_int16_t ttl = -1; + os_uint32_t timeout_s = timeout / 1000; /* Milliseconds convert to seconds */ char ip_addr[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -63,10 +64,10 @@ os_err_t ec200x_600s_ping(mo_object_t *self, const char *host, os_uint16_t len, char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; /* Need to wait for 3 lines response msg */ - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .line_num = 3, - .timeout = (5 + timeout_s) * OS_TICK_PER_SECOND}; + .line_num = 3, + .timeout = (5 + timeout_s) * OS_TICK_PER_SECOND}; /* REF: EC200S_600S QPING */ if (at_parser_exec_cmd(parser, &at_resp, "AT+QPING=1,%s,%u,1", host, timeout_s) < 0) @@ -101,9 +102,9 @@ os_err_t ec200x_600s_ping(mo_object_t *self, const char *host, os_uint16_t len, inet_aton(ip_addr, &(resp->ip_addr)); resp->data_len = recv_data_len; - resp->time = ping_time; - resp->ttl = ttl; - result = OS_EOK; + resp->time = ping_time; + resp->ttl = ttl; + result = OS_EOK; break; case EC200X_600S_PING_TIMEOUT: diff --git a/components/molink/module/esp32/include/esp32.h b/components/molink/module/esp32/include/esp32.h index 297690b0..4fba7c25 100644 --- a/components/molink/module/esp32/include/esp32.h +++ b/components/molink/module/esp32/include/esp32.h @@ -78,16 +78,16 @@ typedef struct mo_esp32 #ifdef ESP32_USING_NETCONN_OPS mo_netconn_t netconn[ESP32_NETCONN_NUM]; - os_int32_t curr_connect; - os_size_t curr_sent_size; - os_event_t netconn_evt; - os_mutex_t netconn_lock; - void *netconn_data; + os_int32_t curr_connect; + os_size_t curr_sent_size; + os_event_t netconn_evt; + os_mutex_t netconn_lock; + void *netconn_data; #endif /* ESP32_USING_NETCONN_OPS */ } mo_esp32_t; mo_object_t *module_esp32_create(const char *name, void *parser_config); -os_err_t module_esp32_destroy(mo_object_t *self); +os_err_t module_esp32_destroy(mo_object_t *self); #endif /* MOLINK_USING_ESP32 */ diff --git a/components/molink/module/esp32/include/esp32_netconn.h b/components/molink/module/esp32/include/esp32_netconn.h index 10e37a0a..36ea97c4 100644 --- a/components/molink/module/esp32/include/esp32_netconn.h +++ b/components/molink/module/esp32/include/esp32_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef ESP32_USING_NETCONN_OPS -os_err_t esp32_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t esp32_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *esp32_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t esp32_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t esp32_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t esp32_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t esp32_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t esp32_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t esp32_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef ESP32_USING_DNS -os_err_t esp32_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t esp32_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* ESP32_USING_NETCONN_OPS */ diff --git a/components/molink/module/esp32/include/esp32_wifi.h b/components/molink/module/esp32/include/esp32_wifi.h index d000c650..40882636 100644 --- a/components/molink/module/esp32/include/esp32_wifi.h +++ b/components/molink/module/esp32/include/esp32_wifi.h @@ -24,7 +24,6 @@ #ifndef __ESP32_WIFI_H__ #define __ESP32_WIFI_H__ - #include "mo_wifi.h" #ifdef __cplusplus extern "C" { @@ -32,12 +31,12 @@ extern "C" { #ifdef ESP32_USING_WIFI_OPS -os_err_t esp32_wifi_set_mode(mo_object_t *module, mo_wifi_mode_t mode); +os_err_t esp32_wifi_set_mode(mo_object_t *module, mo_wifi_mode_t mode); mo_wifi_mode_t esp32_wifi_get_mode(mo_object_t *module); mo_wifi_stat_t esp32_wifi_get_stat(mo_object_t *module); -os_err_t esp32_wifi_scan_info(mo_object_t *module, char *ssid, mo_wifi_scan_result_t *scan_result); -os_err_t esp32_wifi_connect_ap(mo_object_t *module, const char *ssid, const char *password); -os_err_t esp32_wifi_disconnect_ap(mo_object_t *module); +os_err_t esp32_wifi_scan_info(mo_object_t *module, char *ssid, mo_wifi_scan_result_t *scan_result); +os_err_t esp32_wifi_connect_ap(mo_object_t *module, const char *ssid, const char *password); +os_err_t esp32_wifi_disconnect_ap(mo_object_t *module); #endif /* ESP32_USING_WIFI_OPS */ diff --git a/components/molink/module/esp32/source/esp32.c b/components/molink/module/esp32/source/esp32.c index 047f3b93..a8f1599d 100644 --- a/components/molink/module/esp32/source/esp32.c +++ b/components/molink/module/esp32/source/esp32.c @@ -37,23 +37,23 @@ #ifdef ESP32_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = esp32_at_test, + .at_test = esp32_at_test, .get_firmware_version = esp32_get_firmware_version, }; #endif /* ESP32_USING_GENERAL_OPS */ #ifdef ESP32_USING_PING_OPS static const struct mo_ping_ops gs_ping_ops = { - .ping = esp32_ping, + .ping = esp32_ping, }; #endif /* ESP32_USING_PING_OPS */ #ifdef ESP32_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = esp32_ifconfig, - .get_ipaddr = esp32_get_ipaddr, - .set_dnsserver = esp32_set_dnsserver, - .get_dnsserver = esp32_get_dnsserver, + .ifconfig = esp32_ifconfig, + .get_ipaddr = esp32_get_ipaddr, + .set_dnsserver = esp32_set_dnsserver, + .get_dnsserver = esp32_get_dnsserver, }; #endif /* ESP32_USING_IFCONFIG_OPS */ @@ -61,14 +61,14 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern os_err_t esp32_netconn_init(mo_esp32_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = esp32_netconn_create, - .destroy = esp32_netconn_destroy, + .create = esp32_netconn_create, + .destroy = esp32_netconn_destroy, #ifdef ESP32_USING_DNS - .gethostbyname = esp32_netconn_gethostbyname, + .gethostbyname = esp32_netconn_gethostbyname, #endif - .connect = esp32_netconn_connect, - .send = esp32_netconn_send, - .get_info = esp32_netconn_get_info, + .connect = esp32_netconn_connect, + .send = esp32_netconn_send, + .get_info = esp32_netconn_get_info, }; #endif /* ESP32_USING_NETCONN_OPS */ @@ -76,12 +76,12 @@ static const struct mo_netconn_ops gs_netconn_ops = { extern os_err_t esp32_wifi_init(mo_object_t *module); static const struct mo_wifi_ops gs_wifi_ops = { - .set_mode = esp32_wifi_set_mode, - .get_mode = esp32_wifi_get_mode, - .get_stat = esp32_wifi_get_stat, - .connect_ap = esp32_wifi_connect_ap, - .scan_info = esp32_wifi_scan_info, - .disconnect_ap = esp32_wifi_disconnect_ap, + .set_mode = esp32_wifi_set_mode, + .get_mode = esp32_wifi_get_mode, + .get_stat = esp32_wifi_get_stat, + .connect_ap = esp32_wifi_connect_ap, + .scan_info = esp32_wifi_scan_info, + .disconnect_ap = esp32_wifi_disconnect_ap, }; #endif /* ESP32_USING_WIFI_OPS */ @@ -101,7 +101,7 @@ static void urc_busy_s_func(struct at_parser *parser, const char *data, os_size_ } static at_urc_t gs_urc_table[] = { - {.prefix = "ready", .suffix = "\r\n", .func = urc_ready_func}, + {.prefix = "ready", .suffix = "\r\n", .func = urc_ready_func}, {.prefix = "busy p", .suffix = "\r\n", .func = urc_busy_p_func}, {.prefix = "busy s", .suffix = "\r\n", .func = urc_busy_s_func}, }; @@ -248,7 +248,7 @@ int esp32_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = ESP32_NAME, + mo_parser_config_t parser_config = {.parser_name = ESP32_NAME, .parser_device = device, .recv_buff_len = ESP32_RECV_BUFF_LEN}; diff --git a/components/molink/module/esp32/source/esp32_general.c b/components/molink/module/esp32/source/esp32_general.c index 865c59cf..6965d378 100644 --- a/components/molink/module/esp32/source/esp32_general.c +++ b/components/molink/module/esp32/source/esp32_general.c @@ -67,7 +67,7 @@ os_err_t esp32_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ve for (int i = 1; i <= resp.line_counts - 2; i++) { const char *source_line = at_resp_get_line(&resp, i); - os_size_t line_length = strlen(source_line); + os_size_t line_length = strlen(source_line); char **dest_line = &version->ver_info[version->line_counts]; @@ -79,7 +79,7 @@ os_err_t esp32_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ve } strncpy(*dest_line, source_line, line_length); - version->line_counts ++; + version->line_counts++; } return OS_EOK; diff --git a/components/molink/module/esp32/source/esp32_ifconfig.c b/components/molink/module/esp32/source/esp32_ifconfig.c index 478af6ac..cc0add94 100644 --- a/components/molink/module/esp32/source/esp32_ifconfig.c +++ b/components/molink/module/esp32/source/esp32_ifconfig.c @@ -36,16 +36,16 @@ os_err_t esp32_ifconfig(mo_object_t *self) { const char *mode_to_str[] = { - [MO_WIFI_MODE_NULL] = "Null", - [MO_WIFI_MODE_STA] = "Station", - [MO_WIFI_MODE_AP] = "SoftAP", + [MO_WIFI_MODE_NULL] = "Null", + [MO_WIFI_MODE_STA] = "Station", + [MO_WIFI_MODE_AP] = "SoftAP", [MO_WIFI_MODE_AP_STA] = "SoftAP+Station", }; const char *stat_to_str[] = { - [MO_WIFI_STAT_NULL] = "Null", - [MO_WIFI_STAT_INIT] = "Initial", - [MO_WIFI_STAT_CONNECTED] = "Connected", + [MO_WIFI_STAT_NULL] = "Null", + [MO_WIFI_STAT_INIT] = "Initial", + [MO_WIFI_STAT_CONNECTED] = "Connected", [MO_WIFI_STAT_DISCONNECTED] = "Disconnected", }; @@ -90,9 +90,9 @@ os_err_t esp32_ifconfig(mo_object_t *self) os_err_t esp32_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t len = -1; + os_int8_t len = -1; - char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; + char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_128] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; @@ -147,7 +147,7 @@ os_err_t esp32_set_dnsserver(mo_object_t *self, dns_server_t dns) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = OS_EOK; diff --git a/components/molink/module/esp32/source/esp32_netconn.c b/components/molink/module/esp32/source/esp32_netconn.c index b150b316..0d7886bd 100644 --- a/components/molink/module/esp32/source/esp32_netconn.c +++ b/components/molink/module/esp32/source/esp32_netconn.c @@ -41,7 +41,7 @@ #endif #ifndef ESP32_NETCONN_MQ_MSG_MAX -#define ESP32_NETCONN_MQ_MSG_MAX (10) +#define ESP32_NETCONN_MQ_MSG_MAX (10) #endif #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) @@ -69,7 +69,7 @@ static os_err_t esp32_unlock(os_mutex_t *mutex) static mo_netconn_t *esp32_netconn_alloc(mo_object_t *module) { - mo_esp32_t *esp32 = os_container_of(module, mo_esp32_t, parent); + mo_esp32_t *esp32 = os_container_of(module, mo_esp32_t, parent); at_parser_t *parser = &module->parser; char check_kw[AT_RESP_BUFF_SIZE_DEF / 4] = {0}; @@ -127,7 +127,7 @@ os_err_t esp32_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_esp32_t *esp32 = os_container_of(module, mo_esp32_t, parent); info->netconn_array = esp32->netconn; - info->netconn_nums = sizeof(esp32->netconn) / sizeof(esp32->netconn[0]); + info->netconn_nums = sizeof(esp32->netconn) / sizeof(esp32->netconn[0]); return OS_EOK; } @@ -165,7 +165,7 @@ mo_netconn_t *esp32_netconn_create(mo_object_t *module, mo_netconn_type_t type) os_err_t esp32_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; DEBUG("Module %s in %d netconn status", module->name, netconn->stat); @@ -188,8 +188,8 @@ os_err_t esp32_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) if (result != OS_EOK) { ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + module->name, + (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); esp32_unlock(&esp32->netconn_lock); return result; } @@ -208,9 +208,9 @@ os_err_t esp32_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn id %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); @@ -231,7 +231,7 @@ os_err_t esp32_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ad } esp32_lock(&esp32->netconn_lock); - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 150 * OS_TICK_PER_SECOND}; @@ -255,12 +255,8 @@ os_err_t esp32_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ad #ifdef ESP32_USING_UDP case NETCONN_TYPE_UDP: - result = at_parser_exec_cmd(parser, - &resp, - "AT+CIPSTART=%d,\"UDP\",\"%s\",%d", - netconn->connect_id, - remote_ip, - port); + result = + at_parser_exec_cmd(parser, &resp, "AT+CIPSTART=%d,\"UDP\",\"%s\",%d", netconn->connect_id, remote_ip, port); break; #endif @@ -280,7 +276,7 @@ __exit: { ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); } @@ -296,11 +292,11 @@ __exit: os_size_t esp32_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t curr_size = 0; - os_uint32_t event = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t curr_size = 0; + os_uint32_t event = 0; mo_esp32_t *esp32 = os_container_of(module, mo_esp32_t, parent); @@ -408,7 +404,7 @@ os_err_t esp32_netconn_gethostbyname(mo_object_t *module, const char *domain_nam at_parser_t *parser = &module->parser; char resp_buff[AT_RESP_BUFF_SIZE_128] = {0}; - char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; + char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; @@ -463,7 +459,7 @@ static void urc_send_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_esp32_t *esp32 = os_container_of(module, mo_esp32_t, parent); + mo_esp32_t *esp32 = os_container_of(module, mo_esp32_t, parent); os_int32_t curr_connect = esp32->curr_connect; @@ -488,7 +484,7 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t sscanf(data, "%d,CLOSED", &connect_id); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = esp32_get_netconn_by_id(module, connect_id); if (netconn == OS_NULL) { @@ -509,7 +505,7 @@ static void urc_send_bfsz_func(struct at_parser *parser, const char *data, os_si OS_ASSERT(OS_NULL != data); mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_esp32_t *esp32 = os_container_of(module, mo_esp32_t, parent); + mo_esp32_t *esp32 = os_container_of(module, mo_esp32_t, parent); os_int32_t send_bfsz = 0; @@ -526,7 +522,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; + os_int32_t data_size = 0; sscanf(data, "+IPD,%d,%d:", &connect_id, &data_size); @@ -534,7 +530,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t INFO("Moudle %s netconn %d receive %d bytes data", parser->name, connect_id, data_size); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = esp32_get_netconn_by_id(module, connect_id); if (netconn == OS_NULL) { @@ -547,8 +543,8 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t { /* read and clean the coming data */ ERROR("Calloc recv buff %d bytes fail, no enough memory", data_size * 2); - os_size_t temp_size = 0; - char temp_buff[8] = {0}; + os_size_t temp_size = 0; + char temp_buff[8] = {0}; while (temp_size < data_size) { if (data_size - temp_size > sizeof(temp_buff)) @@ -579,11 +575,11 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t } static at_urc_t gs_urc_table[] = { - {.prefix = "SEND OK", .suffix = "\r\n", .func = urc_send_func}, - {.prefix = "SEND FAIL", .suffix = "\r\n", .func = urc_send_func}, - {.prefix = "Recv", .suffix = "bytes\r\n", .func = urc_send_bfsz_func}, - {.prefix = "+IPD", .suffix = ":", .func = urc_recv_func}, - {.prefix = "", .suffix = ",CLOSED\r\n", .func = urc_close_func}, + {.prefix = "SEND OK", .suffix = "\r\n", .func = urc_send_func}, + {.prefix = "SEND FAIL", .suffix = "\r\n", .func = urc_send_func}, + {.prefix = "Recv", .suffix = "bytes\r\n", .func = urc_send_bfsz_func}, + {.prefix = "+IPD", .suffix = ":", .func = urc_recv_func}, + {.prefix = "", .suffix = ",CLOSED\r\n", .func = urc_close_func}, }; os_err_t esp32_netconn_init(mo_esp32_t *module) diff --git a/components/molink/module/esp32/source/esp32_ping.c b/components/molink/module/esp32/source/esp32_ping.c index c3c561fd..31eeec73 100644 --- a/components/molink/module/esp32/source/esp32_ping.c +++ b/components/molink/module/esp32/source/esp32_ping.c @@ -31,10 +31,10 @@ os_err_t esp32_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_uint32_t ping_time = 0; + at_parser_t *parser = &self->parser; + os_uint32_t ping_time = 0; - char ip_addr[IPADDR_MAX_STR_LEN + 1] = {0}; + char ip_addr[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_128] = {0}; at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; @@ -64,7 +64,8 @@ os_err_t esp32_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uin goto __exit; } - if ((at_resp_get_data_by_kw(&at_resp, "+", "+%u", &ping_time) < 0) && (at_resp_get_data_by_kw(&at_resp, "+PING", "+PING:%u", &ping_time) < 0)) + if ((at_resp_get_data_by_kw(&at_resp, "+", "+%u", &ping_time) < 0) && + (at_resp_get_data_by_kw(&at_resp, "+PING", "+PING:%u", &ping_time) < 0)) { ERROR("ping: get the ping time error"); result = OS_ERROR; @@ -75,8 +76,8 @@ os_err_t esp32_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uin { inet_aton(ip_addr, &(resp->ip_addr)); resp->data_len = 32; /* The default ICMP payload length is 32 bytes */ - resp->ttl = 0; /* There is no TTL data in the response */ - resp->time = ping_time; + resp->ttl = 0; /* There is no TTL data in the response */ + resp->time = ping_time; } __exit: diff --git a/components/molink/module/esp32/source/esp32_wifi.c b/components/molink/module/esp32/source/esp32_wifi.c index 304f9820..641e9714 100644 --- a/components/molink/module/esp32/source/esp32_wifi.c +++ b/components/molink/module/esp32/source/esp32_wifi.c @@ -64,8 +64,8 @@ os_err_t esp32_wifi_set_mode(mo_object_t *module, mo_wifi_mode_t mode) mo_wifi_mode_t esp32_wifi_get_mode(mo_object_t *module) { - at_parser_t *parser = &module->parser; - os_int8_t mode_data = 0; + at_parser_t *parser = &module->parser; + os_int8_t mode_data = 0; mo_wifi_mode_t wifi_mode = MO_WIFI_MODE_NULL; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -106,7 +106,7 @@ __exit: mo_wifi_stat_t esp32_wifi_get_stat(mo_object_t *module) { - mo_esp32_t *esp32 = os_container_of(module, mo_esp32_t, parent); + mo_esp32_t *esp32 = os_container_of(module, mo_esp32_t, parent); at_parser_t *parser = &module->parser; char *resp_buff = os_calloc(1, AT_RESP_BUFF_SIZE_384); @@ -156,16 +156,16 @@ mo_wifi_stat_t esp32_wifi_get_stat(mo_object_t *module) os_err_t esp32_wifi_scan_info(mo_object_t *module, char *ssid, mo_wifi_scan_result_t *scan_result) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_int32_t ecn_mode = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_int32_t ecn_mode = 0; const char *data_format1 = "+CWLAP:(%d,\"%[^\"]\",%d,\"%[^\"]\",%d,%*s)"; const char *data_format2 = "+CWLAP:(%*d,\"\",%d,\"%[^\"]\",%d,%*s)"; - at_resp_t resp = {.buff = os_calloc(1, ESP32_SCAN_RESP_BUFF_LEN), + at_resp_t resp = {.buff = os_calloc(1, ESP32_SCAN_RESP_BUFF_LEN), .buff_size = ESP32_SCAN_RESP_BUFF_LEN, - .timeout = 10 * OS_TICK_PER_SECOND}; + .timeout = 10 * OS_TICK_PER_SECOND}; if (resp.buff == OS_NULL) { @@ -218,12 +218,8 @@ os_err_t esp32_wifi_scan_info(mo_object_t *module, char *ssid, mo_wifi_scan_resu if (1 == get_result) { /* ssid is null */ - get_result = at_resp_get_data_by_line(&resp, - i + 1, - data_format2, - &tmp->rssi, - tmp->bssid.bssid_str, - &tmp->channel); + get_result = + at_resp_get_data_by_line(&resp, i + 1, data_format2, &tmp->rssi, tmp->bssid.bssid_str, &tmp->channel); } if (get_result > 0) @@ -318,7 +314,7 @@ static void urc_connect_func(struct at_parser *parser, const char *data, os_size OS_ASSERT(OS_NULL != data); mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_esp32_t *esp32 = os_container_of(module, mo_esp32_t, parent); + mo_esp32_t *esp32 = os_container_of(module, mo_esp32_t, parent); if (strstr(data, "WIFI CONNECTED")) { @@ -340,9 +336,9 @@ static void urc_ip_func(struct at_parser *parser, const char *data, os_size_t si } static at_urc_t gs_urc_table[] = { - {.prefix = "WIFI CONNECTED", .suffix = "\r\n", .func = urc_connect_func}, + {.prefix = "WIFI CONNECTED", .suffix = "\r\n", .func = urc_connect_func}, {.prefix = "WIFI DISCONNECT", .suffix = "\r\n", .func = urc_connect_func}, - {.prefix = "WIFI GOT IP", .suffix = "\r\n", .func = urc_ip_func}, + {.prefix = "WIFI GOT IP", .suffix = "\r\n", .func = urc_ip_func}, }; os_err_t esp32_wifi_init(mo_object_t *module) diff --git a/components/molink/module/esp8266/include/esp8266.h b/components/molink/module/esp8266/include/esp8266.h index 327f7952..2cb7843e 100644 --- a/components/molink/module/esp8266/include/esp8266.h +++ b/components/molink/module/esp8266/include/esp8266.h @@ -80,16 +80,16 @@ typedef struct mo_esp8266 #ifdef ESP8266_USING_NETCONN_OPS mo_netconn_t netconn[ESP8266_NETCONN_NUM]; - os_int32_t curr_connect; - os_size_t curr_sent_size; - os_event_t netconn_evt; - os_mutex_t netconn_lock; - void *netconn_data; + os_int32_t curr_connect; + os_size_t curr_sent_size; + os_event_t netconn_evt; + os_mutex_t netconn_lock; + void *netconn_data; #endif /* ESP8266_USING_NETCONN_OPS */ } mo_esp8266_t; mo_object_t *module_esp8266_create(const char *name, void *parser_config); -os_err_t module_esp8266_destroy(mo_object_t *self); +os_err_t module_esp8266_destroy(mo_object_t *self); #ifdef ESP8266_USING_HW_CONTROL void esp8266_hw_rst(os_base_t rst_pin); diff --git a/components/molink/module/esp8266/include/esp8266_netconn.h b/components/molink/module/esp8266/include/esp8266_netconn.h index 9a6a5417..8bae547d 100644 --- a/components/molink/module/esp8266/include/esp8266_netconn.h +++ b/components/molink/module/esp8266/include/esp8266_netconn.h @@ -32,21 +32,26 @@ extern "C" { #ifdef ESP8266_USING_NETCONN_OPS -os_err_t esp8266_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t esp8266_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *esp8266_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t esp8266_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t esp8266_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); #ifdef ESP8266_USING_SERVER_MODE -os_err_t esp8266_netconn_bind(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_err_t esp8266_netconn_bind(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); #endif -os_err_t esp8266_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_err_t esp8266_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); #ifdef ESP8266_USING_UDP -os_size_t esp8266_netconn_sendto(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port, const char *data, os_size_t size); +os_size_t esp8266_netconn_sendto(mo_object_t *module, + mo_netconn_t *netconn, + ip_addr_t addr, + os_uint16_t port, + const char *data, + os_size_t size); #endif #ifdef ESP8266_USING_TCP -os_size_t esp8266_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_size_t esp8266_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #endif #ifdef ESP8266_USING_DNS -os_err_t esp8266_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t esp8266_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* ESP8266_USING_NETCONN_OPS */ diff --git a/components/molink/module/esp8266/include/esp8266_ping.h b/components/molink/module/esp8266/include/esp8266_ping.h index 4edf23ee..9646efb7 100644 --- a/components/molink/module/esp8266/include/esp8266_ping.h +++ b/components/molink/module/esp8266/include/esp8266_ping.h @@ -31,7 +31,8 @@ extern "C" { #ifdef ESP8266_USING_PING_OPS -os_err_t esp8266_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); +os_err_t +esp8266_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); #endif /* ESP8266_USING_PING_OPS */ diff --git a/components/molink/module/esp8266/include/esp8266_wifi.h b/components/molink/module/esp8266/include/esp8266_wifi.h index ad2d73a4..a318beb8 100644 --- a/components/molink/module/esp8266/include/esp8266_wifi.h +++ b/components/molink/module/esp8266/include/esp8266_wifi.h @@ -32,21 +32,27 @@ extern "C" { #ifdef ESP8266_USING_WIFI_OPS -os_err_t esp8266_wifi_set_ipdinofo(mo_object_t *module, mo_cipdinfo_mode_t ipd_mode); -os_err_t esp8266_wifi_set_ipv6(mo_object_t *module, mo_wifi_cipv6_t ipv6); -os_err_t esp8266_wifi_set_mode(mo_object_t *module, mo_wifi_mode_t mode); +os_err_t esp8266_wifi_set_ipdinofo(mo_object_t *module, mo_cipdinfo_mode_t ipd_mode); +os_err_t esp8266_wifi_set_ipv6(mo_object_t *module, mo_wifi_cipv6_t ipv6); +os_err_t esp8266_wifi_set_mode(mo_object_t *module, mo_wifi_mode_t mode); mo_wifi_mode_t esp8266_wifi_get_mode(mo_object_t *module); mo_wifi_stat_t esp8266_wifi_get_stat(mo_object_t *module); -os_err_t esp8266_wifi_get_sta_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t *gw, ip_addr_t *mask, ip_addr_t *ip6_ll, ip_addr_t *ip6_gl); -os_err_t esp8266_wifi_set_ap_cip(mo_object_t *module, char *ip, char *gw, char *mask); -os_err_t esp8266_wifi_get_ap_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t *gw, ip_addr_t *mask); -os_err_t esp8266_wifi_get_sta_mac(mo_object_t *module, char mac[]); -os_err_t esp8266_wifi_get_ap_mac(mo_object_t *module, char mac[]); -os_err_t esp8266_wifi_scan_info(mo_object_t *module, char *ssid, mo_wifi_scan_result_t *scan_result); -os_err_t esp8266_wifi_connect_ap(mo_object_t *module, const char *ssid, const char *password); -os_err_t esp8266_wifi_disconnect_ap(mo_object_t *module); -os_err_t esp8266_wifi_start_ap(mo_object_t *module, const char *ssid, const char *password, os_uint8_t channel, os_uint8_t ecn); -os_err_t esp8266_wifi_stop_ap(mo_object_t *module); +os_err_t esp8266_wifi_get_sta_cip(mo_object_t *module, + ip_addr_t *ip, + ip_addr_t *gw, + ip_addr_t *mask, + ip_addr_t *ip6_ll, + ip_addr_t *ip6_gl); +os_err_t esp8266_wifi_set_ap_cip(mo_object_t *module, char *ip, char *gw, char *mask); +os_err_t esp8266_wifi_get_ap_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t *gw, ip_addr_t *mask); +os_err_t esp8266_wifi_get_sta_mac(mo_object_t *module, char mac[]); +os_err_t esp8266_wifi_get_ap_mac(mo_object_t *module, char mac[]); +os_err_t esp8266_wifi_scan_info(mo_object_t *module, char *ssid, mo_wifi_scan_result_t *scan_result); +os_err_t esp8266_wifi_connect_ap(mo_object_t *module, const char *ssid, const char *password); +os_err_t esp8266_wifi_disconnect_ap(mo_object_t *module); +os_err_t +esp8266_wifi_start_ap(mo_object_t *module, const char *ssid, const char *password, os_uint8_t channel, os_uint8_t ecn); +os_err_t esp8266_wifi_stop_ap(mo_object_t *module); #endif /* ESP8266_USING_WIFI_OPS */ diff --git a/components/molink/module/esp8266/source/esp8266.c b/components/molink/module/esp8266/source/esp8266.c index f7223c85..1ac46690 100644 --- a/components/molink/module/esp8266/source/esp8266.c +++ b/components/molink/module/esp8266/source/esp8266.c @@ -45,23 +45,23 @@ #ifdef ESP8266_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = esp8266_at_test, + .at_test = esp8266_at_test, .get_firmware_version = esp8266_get_firmware_version, }; #endif /* ESP8266_USING_GENERAL_OPS */ #ifdef ESP8266_USING_PING_OPS static const struct mo_ping_ops gs_ping_ops = { - .ping = esp8266_ping, + .ping = esp8266_ping, }; #endif /* ESP8266_USING_PING_OPS */ #ifdef ESP8266_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = esp8266_ifconfig, - .get_ipaddr = esp8266_get_ipaddr, - .set_dnsserver = esp8266_set_dnsserver, - .get_dnsserver = esp8266_get_dnsserver, + .ifconfig = esp8266_ifconfig, + .get_ipaddr = esp8266_get_ipaddr, + .set_dnsserver = esp8266_set_dnsserver, + .get_dnsserver = esp8266_get_dnsserver, }; #endif /* ESP8266_USING_IFCONFIG_OPS */ @@ -69,22 +69,22 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern os_err_t esp8266_netconn_init(mo_esp8266_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = esp8266_netconn_create, - .destroy = esp8266_netconn_destroy, + .create = esp8266_netconn_create, + .destroy = esp8266_netconn_destroy, #ifdef ESP8266_USING_DNS - .gethostbyname = esp8266_netconn_gethostbyname, + .gethostbyname = esp8266_netconn_gethostbyname, #endif #ifdef ESP8266_USING_SERVER_MODE - .bind = esp8266_netconn_bind, + .bind = esp8266_netconn_bind, #endif - .connect = esp8266_netconn_connect, + .connect = esp8266_netconn_connect, #ifdef ESP8266_USING_UDP - .sendto = esp8266_netconn_sendto, + .sendto = esp8266_netconn_sendto, #endif #ifdef ESP8266_USING_TCP - .send = esp8266_netconn_send, + .send = esp8266_netconn_send, #endif - .get_info = esp8266_netconn_get_info, + .get_info = esp8266_netconn_get_info, }; #endif /* ESP8266_USING_NETCONN_OPS */ @@ -92,19 +92,19 @@ static const struct mo_netconn_ops gs_netconn_ops = { extern os_err_t esp8266_wifi_init(mo_object_t *module); static const struct mo_wifi_ops gs_wifi_ops = { - .set_mode = esp8266_wifi_set_mode, - .get_mode = esp8266_wifi_get_mode, - .get_stat = esp8266_wifi_get_stat, - .get_sta_cip = esp8266_wifi_get_sta_cip, - .set_ap_cip = esp8266_wifi_set_ap_cip, - .get_ap_cip = esp8266_wifi_get_ap_cip, - .get_sta_mac = esp8266_wifi_get_sta_mac, - .get_ap_mac = esp8266_wifi_get_ap_mac, - .connect_ap = esp8266_wifi_connect_ap, - .scan_info = esp8266_wifi_scan_info, - .disconnect_ap = esp8266_wifi_disconnect_ap, - .start_ap = esp8266_wifi_start_ap, - .stop_ap = esp8266_wifi_stop_ap, + .set_mode = esp8266_wifi_set_mode, + .get_mode = esp8266_wifi_get_mode, + .get_stat = esp8266_wifi_get_stat, + .get_sta_cip = esp8266_wifi_get_sta_cip, + .set_ap_cip = esp8266_wifi_set_ap_cip, + .get_ap_cip = esp8266_wifi_get_ap_cip, + .get_sta_mac = esp8266_wifi_get_sta_mac, + .get_ap_mac = esp8266_wifi_get_ap_mac, + .connect_ap = esp8266_wifi_connect_ap, + .scan_info = esp8266_wifi_scan_info, + .disconnect_ap = esp8266_wifi_disconnect_ap, + .start_ap = esp8266_wifi_start_ap, + .stop_ap = esp8266_wifi_stop_ap, }; #endif /* ESP8266_USING_WIFI_OPS */ @@ -124,12 +124,11 @@ static void urc_busy_s_func(struct at_parser *parser, const char *data, os_size_ } static at_urc_t gs_urc_table[] = { - {.prefix = "ready", .suffix = "\r\n", .func = urc_ready_func}, + {.prefix = "ready", .suffix = "\r\n", .func = urc_ready_func}, {.prefix = "busy p", .suffix = "\r\n", .func = urc_busy_p_func}, {.prefix = "busy s", .suffix = "\r\n", .func = urc_busy_s_func}, }; - #ifdef ESP8266_USING_HW_CONTROL void esp8266_hw_rst(os_base_t rst_pin) @@ -169,9 +168,7 @@ static os_err_t esp8266_at_init(mo_object_t *self) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; return at_parser_exec_cmd(parser, &resp, "ATE0"); } @@ -186,7 +183,7 @@ mo_object_t *module_esp8266_create(const char *name, void *parser_config) } os_err_t result = mo_object_init(&(module->parent), name, parser_config); - if (result != OS_EOK) + if (result != OS_EOK) { os_free(module); return OS_NULL; @@ -227,23 +224,23 @@ mo_object_t *module_esp8266_create(const char *name, void *parser_config) mo_get_firmware_version_free(&version); } #endif /* ESP8266_USING_GENERAL_OPS */ - + #ifdef ESP8266_USING_WIFI_OPS - //os_task_msleep(2000); + // os_task_msleep(2000); result = esp8266_wifi_init(&module->parent); if (result != OS_EOK) { goto __exit; } - //os_task_msleep(1000); + // os_task_msleep(1000); result = esp8266_wifi_set_mode(&module->parent, MO_WIFI_MODE_AP_STA); if (result != OS_EOK) { goto __exit; } - + /* not all esp8266 soft version support IPV6 */ #ifdef ESP8266_USING_IPV6 result = esp8266_wifi_set_ipv6(&module->parent, MO_WIFI_CIPV6_ENABLE); @@ -251,8 +248,8 @@ mo_object_t *module_esp8266_create(const char *name, void *parser_config) { INFO("module no support ipv6"); } -#endif - +#endif + result = esp8266_wifi_set_ipdinofo(&module->parent, MO_WIFI_CIPINFO_SHOW_IP_PORT); if (result != OS_EOK) { @@ -332,7 +329,7 @@ int esp8266_auto_create(void) esp8266_hw_rst(ESP8266_RST_PIN_NUM); #endif - mo_parser_config_t parser_config = {.parser_name = ESP8266_NAME, + mo_parser_config_t parser_config = {.parser_name = ESP8266_NAME, .parser_device = device, .recv_buff_len = ESP8266_RECV_BUFF_LEN}; diff --git a/components/molink/module/esp8266/source/esp8266_general.c b/components/molink/module/esp8266/source/esp8266_general.c index 9f49ea4c..503a0181 100644 --- a/components/molink/module/esp8266/source/esp8266_general.c +++ b/components/molink/module/esp8266/source/esp8266_general.c @@ -37,9 +37,7 @@ os_err_t esp8266_at_test(mo_object_t *self) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; return at_parser_exec_cmd(parser, &resp, "AT"); } @@ -50,9 +48,7 @@ os_err_t esp8266_get_firmware_version(mo_object_t *self, mo_firmware_version_t * char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+GMR"); if (result != OS_EOK) @@ -71,7 +67,7 @@ os_err_t esp8266_get_firmware_version(mo_object_t *self, mo_firmware_version_t * for (int i = 1; i <= resp.line_counts - 1; i++) { const char *source_line = at_resp_get_line(&resp, i); - os_size_t line_length = strlen(source_line) - 1; + os_size_t line_length = strlen(source_line) - 1; char **dest_line = &version->ver_info[version->line_counts]; @@ -84,7 +80,7 @@ os_err_t esp8266_get_firmware_version(mo_object_t *self, mo_firmware_version_t * } strncpy(*dest_line, source_line, line_length); - version->line_counts ++; + version->line_counts++; } return OS_EOK; diff --git a/components/molink/module/esp8266/source/esp8266_ifconfig.c b/components/molink/module/esp8266/source/esp8266_ifconfig.c index edf839fd..1107b91d 100644 --- a/components/molink/module/esp8266/source/esp8266_ifconfig.c +++ b/components/molink/module/esp8266/source/esp8266_ifconfig.c @@ -36,16 +36,16 @@ os_err_t esp8266_ifconfig(mo_object_t *self) { const char *mode_to_str[] = { - [MO_WIFI_MODE_NULL] = "Null", - [MO_WIFI_MODE_STA] = "Station", - [MO_WIFI_MODE_AP] = "SoftAP", + [MO_WIFI_MODE_NULL] = "Null", + [MO_WIFI_MODE_STA] = "Station", + [MO_WIFI_MODE_AP] = "SoftAP", [MO_WIFI_MODE_AP_STA] = "SoftAP+Station", }; const char *stat_to_str[] = { - [MO_WIFI_STAT_NULL] = "Null", - [MO_WIFI_STAT_INIT] = "Initial", - [MO_WIFI_STAT_CONNECTED] = "Connected", + [MO_WIFI_STAT_NULL] = "Null", + [MO_WIFI_STAT_INIT] = "Initial", + [MO_WIFI_STAT_CONNECTED] = "Connected", [MO_WIFI_STAT_DISCONNECTED] = "Disconnected", }; @@ -94,9 +94,9 @@ os_err_t esp8266_ifconfig(mo_object_t *self) os_err_t esp8266_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t len = -1; + os_int8_t len = -1; - char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; + char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; @@ -151,9 +151,7 @@ os_err_t esp8266_set_dnsserver(mo_object_t *self, dns_server_t dns) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = OS_EOK; @@ -175,9 +173,7 @@ os_err_t esp8266_get_dnsserver(mo_object_t *self, dns_server_t *dns) char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CIPDNS_DEF?"); if (result != OS_EOK) diff --git a/components/molink/module/esp8266/source/esp8266_netconn.c b/components/molink/module/esp8266/source/esp8266_netconn.c index cc1ce88f..4090b613 100644 --- a/components/molink/module/esp8266/source/esp8266_netconn.c +++ b/components/molink/module/esp8266/source/esp8266_netconn.c @@ -44,7 +44,7 @@ #endif #ifndef ESP8266_NETCONN_MQ_MSG_MAX -#define ESP8266_NETCONN_MQ_MSG_MAX (10) +#define ESP8266_NETCONN_MQ_MSG_MAX (10) #endif #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) @@ -131,7 +131,7 @@ os_err_t esp8266_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_esp8266_t *esp8266 = os_container_of(module, mo_esp8266_t, parent); info->netconn_array = esp8266->netconn; - info->netconn_nums = sizeof(esp8266->netconn) / sizeof(esp8266->netconn[0]); + info->netconn_nums = sizeof(esp8266->netconn) / sizeof(esp8266->netconn[0]); return OS_EOK; } @@ -169,7 +169,7 @@ mo_netconn_t *esp8266_netconn_create(mo_object_t *module, mo_netconn_type_t type os_err_t esp8266_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; DEBUG("Module %s in %d netconn status", module->name, netconn->stat); @@ -211,9 +211,9 @@ os_err_t esp8266_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn id %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; #ifdef MOLINK_USING_SOCKETS_OPS netconn->socket_id = -1; @@ -238,9 +238,9 @@ os_err_t esp8266_netconn_bind(mo_object_t *module, mo_netconn_t *netconn, ip_add char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; - //INFO("loacl addr step 1:0x%08x", addr.addr); - //addr.addr |= 0x000000FF; - //INFO("loacl addr step 2:0x%08x", addr.addr); + // INFO("loacl addr step 1:0x%08x", addr.addr); + // addr.addr |= 0x000000FF; + // INFO("loacl addr step 2:0x%08x", addr.addr); strncpy(remote_ip, inet_ntoa(addr), IPADDR_MAX_STR_LEN); INFO("loacl addr:%s", remote_ip); @@ -254,7 +254,7 @@ os_err_t esp8266_netconn_bind(mo_object_t *module, mo_netconn_t *netconn, ip_add "AT+CIPSTART=%d,\"UDP\",\"%s\",0,%d,2", netconn->connect_id, remote_ip, - port); + port); break; case NETCONN_TYPE_UDP_V6: result = at_parser_exec_cmd(parser, @@ -273,13 +273,13 @@ os_err_t esp8266_netconn_bind(mo_object_t *module, mo_netconn_t *netconn, ip_add { goto __exit; } - + __exit: if (OS_EOK == result) { ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; INFO("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); } @@ -321,12 +321,8 @@ os_err_t esp8266_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ #ifdef ESP8266_USING_UDP case NETCONN_TYPE_UDP: - result = at_parser_exec_cmd(parser, - &resp, - "AT+CIPSTART=%d,\"UDP\",\"%s\",%d", - netconn->connect_id, - remote_ip, - port); + result = + at_parser_exec_cmd(parser, &resp, "AT+CIPSTART=%d,\"UDP\",\"%s\",%d", netconn->connect_id, remote_ip, port); break; #endif @@ -346,7 +342,7 @@ __exit: { ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); } @@ -359,24 +355,27 @@ __exit: } #ifdef ESP8266_USING_UDP -os_size_t esp8266_netconn_sendto(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port, const char *data, os_size_t size) +os_size_t esp8266_netconn_sendto(mo_object_t *module, + mo_netconn_t *netconn, + ip_addr_t addr, + os_uint16_t port, + const char *data, + os_size_t size) { char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t curr_size = 0; - os_uint32_t event = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t curr_size = 0; + os_uint32_t event = 0; mo_esp8266_t *esp8266 = os_container_of(module, mo_esp8266_t, parent); - + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; strncpy(remote_ip, inet_ntoa(addr), IPADDR_MAX_STR_LEN); - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 5 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; at_parser_exec_lock(parser); esp8266->curr_connect = netconn->connect_id; @@ -395,7 +394,13 @@ os_size_t esp8266_netconn_sendto(mo_object_t *module, mo_netconn_t *netconn, ip_ /* Protect the data sending process, prevent other threads to send AT commands */ - result = at_parser_exec_cmd(parser, &resp, "AT+CIPSEND=%d,%d,\"%s\",%d", netconn->connect_id, curr_size, remote_ip, port); + result = at_parser_exec_cmd(parser, + &resp, + "AT+CIPSEND=%d,%d,\"%s\",%d", + netconn->connect_id, + curr_size, + remote_ip, + port); if (result != OS_EOK) { goto __exit; @@ -455,7 +460,7 @@ __exit: if (result != OS_EOK) { ERROR("Module %s netconn %d send %d bytes data failed!", parser->name, netconn->connect_id, size); - + return 0; } @@ -466,21 +471,19 @@ __exit: #ifdef ESP8266_USING_TCP os_size_t esp8266_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t curr_size = 0; - os_uint32_t event = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t curr_size = 0; + os_uint32_t event = 0; mo_esp8266_t *esp8266 = os_container_of(module, mo_esp8266_t, parent); - + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 5 * OS_TICK_PER_SECOND}; - - /* Protect the data sending process, prevent other threads to send AT commands */ + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; + + /* Protect the data sending process, prevent other threads to send AT commands */ at_parser_exec_lock(parser); esp8266->curr_connect = netconn->connect_id; @@ -585,9 +588,7 @@ os_err_t esp8266_netconn_gethostbyname(mo_object_t *module, const char *domain_n char resp_buff[AT_RESP_BUFF_SIZE_128] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 20 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CIPDOMAIN=\"%s\"", domain_name); if (result != OS_EOK) @@ -620,10 +621,10 @@ os_err_t esp8266_netconn_gethostbyname(mo_object_t *module, const char *domain_n inet_aton(recvip, addr); #ifdef MOLINK_USING_IPV4 #ifdef MOLINK_USING_IPV6 - if (IPADDR_ANY == addr->u_addr.ip4.addr || IPADDR_LOOPBACK == addr->u_addr.ip4.addr) + if (IPADDR_ANY == addr->u_addr.ip4.addr || IPADDR_LOOPBACK == addr->u_addr.ip4.addr) #else if (IPADDR_ANY == addr->addr || IPADDR_LOOPBACK == addr->addr) -#endif +#endif { ip_addr_set_zero(addr); result = OS_ERROR; @@ -644,7 +645,7 @@ static void urc_send_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_esp8266_t *esp8266 = os_container_of(module, mo_esp8266_t, parent); os_int32_t curr_connect = esp8266->curr_connect; @@ -670,7 +671,7 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t sscanf(data, "%d,CLOSED", &connect_id); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = esp8266_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) @@ -691,7 +692,7 @@ static void urc_send_bfsz_func(struct at_parser *parser, const char *data, os_si OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_esp8266_t *esp8266 = os_container_of(module, mo_esp8266_t, parent); os_int32_t send_bfsz = 0; @@ -748,20 +749,20 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - os_int32_t connect_id = 0; - os_int32_t data_size = 0; - ip_addr_t addr = {0}; - os_uint16_t port = 0; + os_int32_t connect_id = 0; + os_int32_t data_size = 0; + ip_addr_t addr = {0}; + os_uint16_t port = 0; char ipd_prefix[80]; memset(ipd_prefix, 0, sizeof(ipd_prefix)); memcpy(ipd_prefix, data, size); mo_object_t *module = os_container_of(parser, mo_object_t, parser); - + #ifdef ESP8266_USING_WIFI_OPS char remote_ip[IPADDR_MAX_STR_LEN + 1 + 2] = {0}; int len; - + mo_esp8266_t *esp8266 = os_container_of(module, mo_esp8266_t, parent); if (MO_WIFI_CIPINFO_SHOW_IP_PORT == esp8266->wifi_ipdinfo) @@ -786,8 +787,9 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t #endif os_int32_t timeout = data_size > 10 ? data_size : 10; - // INFO("--%s", ipd_prefix); - // INFO("Moudle %s netconn %d receive %d bytes data from[%s,%d]", parser->name, connect_id, data_size, remote_ip, port); + // INFO("--%s", ipd_prefix); + // INFO("Moudle %s netconn %d receive %d bytes data from[%s,%d]", parser->name, connect_id, data_size, remote_ip, + // port); mo_netconn_t *netconn = esp8266_get_netconn_by_id(module, connect_id); @@ -802,8 +804,8 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t { /* read and clean the coming data */ ERROR("os_calloc recv buff %d bytes fail, no enough memory", data_size); - os_size_t temp_size = 0; - char temp_buff[8] = {0}; + os_size_t temp_size = 0; + char temp_buff[8] = {0}; while (temp_size < data_size) { @@ -834,9 +836,9 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t ip_addr_set_zero(&addr); if (NETCONN_TYPE_UDP_V6 == netconn->type || NETCONN_TYPE_TCP_V6 == netconn->type) { - IP_SET_TYPE(&addr, IPADDR_TYPE_V6); + IP_SET_TYPE(&addr, IPADDR_TYPE_V6); } - + inet_aton(remote_ip, &addr); #endif mo_wifi_netconn_data_recv_notice(netconn, addr, (os_uint16_t)port, recv_buff, data_size); @@ -845,11 +847,11 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t } static at_urc_t gs_urc_table[] = { - {.prefix = "SEND OK", .suffix = "\r\n", .func = urc_send_func}, - {.prefix = "SEND FAIL", .suffix = "\r\n", .func = urc_send_func}, - {.prefix = "Recv", .suffix = "bytes\r\n", .func = urc_send_bfsz_func}, - {.prefix = "+IPD", .suffix = ",", .func = urc_recv_func}, - {.prefix = "", .suffix = ",CLOSED\r\n", .func = urc_close_func}, + {.prefix = "SEND OK", .suffix = "\r\n", .func = urc_send_func}, + {.prefix = "SEND FAIL", .suffix = "\r\n", .func = urc_send_func}, + {.prefix = "Recv", .suffix = "bytes\r\n", .func = urc_send_bfsz_func}, + {.prefix = "+IPD", .suffix = ",", .func = urc_recv_func}, + {.prefix = "", .suffix = ",CLOSED\r\n", .func = urc_close_func}, }; os_err_t esp8266_netconn_init(mo_esp8266_t *module) diff --git a/components/molink/module/esp8266/source/esp8266_ping.c b/components/molink/module/esp8266/source/esp8266_ping.c index e97cf591..76436c3b 100644 --- a/components/molink/module/esp8266/source/esp8266_ping.c +++ b/components/molink/module/esp8266/source/esp8266_ping.c @@ -31,15 +31,13 @@ os_err_t esp8266_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_uint32_t ping_time = 0; + at_parser_t *parser = &self->parser; + os_uint32_t ping_time = 0; - char ip_addr[IPADDR_MAX_STR_LEN + 1] = {0}; + char ip_addr[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_128] = {0}; - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 20 * AT_RESP_TIMEOUT_DEF}; + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &at_resp, "AT+CIPDOMAIN=\"%s\"", host); @@ -66,7 +64,8 @@ os_err_t esp8266_ping(mo_object_t *self, const char *host, os_uint16_t len, os_u goto __exit; } - if ((at_resp_get_data_by_kw(&at_resp, "+", "+%u", &ping_time) < 0) && (at_resp_get_data_by_kw(&at_resp, "+PING", "+PING:%u", &ping_time) < 0)) + if ((at_resp_get_data_by_kw(&at_resp, "+", "+%u", &ping_time) < 0) && + (at_resp_get_data_by_kw(&at_resp, "+PING", "+PING:%u", &ping_time) < 0)) { ERROR("ping: get the ping time error"); result = OS_ERROR; @@ -77,8 +76,8 @@ os_err_t esp8266_ping(mo_object_t *self, const char *host, os_uint16_t len, os_u { inet_aton(ip_addr, &(resp->ip_addr)); resp->data_len = 32; /* The default ICMP payload length is 32 bytes */ - resp->ttl = 0; /* There is no TTL data in the response */ - resp->time = ping_time; + resp->ttl = 0; /* There is no TTL data in the response */ + resp->time = ping_time; } __exit: diff --git a/components/molink/module/esp8266/source/esp8266_wifi.c b/components/molink/module/esp8266/source/esp8266_wifi.c index 7682b9e6..db402e47 100644 --- a/components/molink/module/esp8266/source/esp8266_wifi.c +++ b/components/molink/module/esp8266/source/esp8266_wifi.c @@ -133,8 +133,8 @@ os_err_t esp8266_wifi_set_mode(mo_object_t *module, mo_wifi_mode_t mode) mo_wifi_mode_t esp8266_wifi_get_mode(mo_object_t *module) { - at_parser_t *parser = &module->parser; - os_int8_t mode_data = 0; + at_parser_t *parser = &module->parser; + os_int8_t mode_data = 0; mo_wifi_mode_t wifi_mode = MO_WIFI_MODE_NULL; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -153,7 +153,6 @@ mo_wifi_mode_t esp8266_wifi_get_mode(mo_object_t *module) goto __exit; } - switch (mode_data) { case 1: @@ -179,7 +178,7 @@ __exit: mo_wifi_stat_t esp8266_wifi_get_stat(mo_object_t *module) { mo_esp8266_t *esp8266 = os_container_of(module, mo_esp8266_t, parent); - at_parser_t *parser = &module->parser; + at_parser_t *parser = &module->parser; if (esp8266->wifi_stat >= MO_WIFI_STAT_GOT_IP) { @@ -231,15 +230,20 @@ mo_wifi_stat_t esp8266_wifi_get_stat(mo_object_t *module) return esp8266->wifi_stat; } -os_err_t esp8266_wifi_get_sta_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t *gw, ip_addr_t *mask, ip_addr_t *ip6_ll, ip_addr_t *ip6_gl) +os_err_t esp8266_wifi_get_sta_cip(mo_object_t *module, + ip_addr_t *ip, + ip_addr_t *gw, + ip_addr_t *mask, + ip_addr_t *ip6_ll, + ip_addr_t *ip6_gl) { at_parser_t *parser = &module->parser; - os_int8_t len = -1; -// mo_esp8266_t *esp8266 = os_container_of(module, mo_esp8266_t, parent); + os_int8_t len = -1; + // mo_esp8266_t *esp8266 = os_container_of(module, mo_esp8266_t, parent); char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; - //char gateway[IPADDR_MAX_STR_LEN + 1] = {0}; - //char netmask[IPADDR_MAX_STR_LEN + 1] = {0}; + // char gateway[IPADDR_MAX_STR_LEN + 1] = {0}; + // char netmask[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; @@ -270,13 +274,13 @@ os_err_t esp8266_wifi_get_sta_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t IP_SET_TYPE(ip, IPADDR_TYPE_V4); inet_aton(ipaddr, ip); } -// #ifdef MOLINK_USING_IPV4 -// #ifdef MOLINK_USING_IPV6 -// ip->u_addr.ip4.addr = inet_addr(ipaddr); -// #else -// ip->addr = inet_addr(ipaddr); -// #endif -// #endif + // #ifdef MOLINK_USING_IPV4 + // #ifdef MOLINK_USING_IPV6 + // ip->u_addr.ip4.addr = inet_addr(ipaddr); + // #else + // ip->addr = inet_addr(ipaddr); + // #endif + // #endif DEBUG("IP address: %s", ipaddr); } @@ -300,13 +304,13 @@ os_err_t esp8266_wifi_get_sta_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t IP_SET_TYPE(gw, IPADDR_TYPE_V4); inet_aton(ipaddr, gw); } -// #ifdef MOLINK_USING_IPV4 -// #ifdef MOLINK_USING_IPV6 -// gw->u_addr.ip4.addr = inet_addr(ipaddr); -// #else -// gw->addr = inet_addr(ipaddr); -// #endif -// #endif + // #ifdef MOLINK_USING_IPV4 + // #ifdef MOLINK_USING_IPV6 + // gw->u_addr.ip4.addr = inet_addr(ipaddr); + // #else + // gw->addr = inet_addr(ipaddr); + // #endif + // #endif DEBUG("Gateway: %s", ipaddr); } @@ -330,13 +334,13 @@ os_err_t esp8266_wifi_get_sta_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t IP_SET_TYPE(mask, IPADDR_TYPE_V4); inet_aton(ipaddr, mask); } -// #ifdef MOLINK_USING_IPV4 -// #ifdef MOLINK_USING_IPV6 -// mask->u_addr.ip4.addr = inet_addr(ipaddr); -// #else -// mask->addr = inet_addr(ipaddr); -// #endif -// #endif + // #ifdef MOLINK_USING_IPV4 + // #ifdef MOLINK_USING_IPV6 + // mask->u_addr.ip4.addr = inet_addr(ipaddr); + // #else + // mask->addr = inet_addr(ipaddr); + // #endif + // #endif DEBUG("Netmask: %s", ipaddr); } @@ -362,7 +366,7 @@ os_err_t esp8266_wifi_get_sta_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t if (OS_NULL != ip6_ll) { IP_SET_TYPE(ip6_ll, IPADDR_TYPE_V6); - inet_aton(ipaddr, ip6_ll); + inet_aton(ipaddr, ip6_ll); } } @@ -384,7 +388,7 @@ os_err_t esp8266_wifi_get_sta_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t if (OS_NULL != ip6_gl) { IP_SET_TYPE(ip6_gl, IPADDR_TYPE_V6); - inet_aton(ipaddr, ip6_gl); + inet_aton(ipaddr, ip6_gl); } } } @@ -404,20 +408,20 @@ os_err_t esp8266_wifi_set_ap_cip(mo_object_t *module, char *ip, char *gw, char * at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; snprintf(cmd, sizeof(cmd), "AT+CIPAP=\"%s\"", ip); - + return at_parser_exec_cmd(parser, &resp, cmd); } os_err_t esp8266_wifi_get_ap_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t *gw, ip_addr_t *mask) { at_parser_t *parser = &module->parser; - + char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; char gateway[IPADDR_MAX_STR_LEN + 1] = {0}; char netmask[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; int len; - + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CIPAP?"); @@ -447,7 +451,7 @@ os_err_t esp8266_wifi_get_ap_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t * #else ip->addr = inet_addr(ipaddr); #endif -#endif +#endif DEBUG("IP address: %s", ipaddr); } @@ -469,8 +473,8 @@ os_err_t esp8266_wifi_get_ap_cip(mo_object_t *module, ip_addr_t *ip, ip_addr_t * #ifdef MOLINK_USING_IPV4 #ifdef MOLINK_USING_IPV6 gw->u_addr.ip4.addr = inet_addr(gateway); -#else - gw->addr = inet_addr(gateway); +#else + gw->addr = inet_addr(gateway); #endif #endif DEBUG("Gateway: %s", gateway); @@ -507,26 +511,30 @@ __exit: } /* Returns int value of hex string character |c| */ -static uint8_t hex_to_uint(uint8_t c) { - if ('0' <= c && c <= '9') { - return (uint8_t)(c - '0'); - } - if ('A' <= c && c <= 'F') { - return (uint8_t)(c - 'A' + 10); - } - if ('a' <= c && c <= 'f') { - return (uint8_t)(c - 'a' + 10); - } - return 0; +static uint8_t hex_to_uint(uint8_t c) +{ + if ('0' <= c && c <= '9') + { + return (uint8_t)(c - '0'); + } + if ('A' <= c && c <= 'F') + { + return (uint8_t)(c - 'A' + 10); + } + if ('a' <= c && c <= 'f') + { + return (uint8_t)(c - 'a' + 10); + } + return 0; } os_err_t esp8266_wifi_get_sta_mac(mo_object_t *module, char mac[]) { - at_parser_t *parser = &module->parser; + at_parser_t *parser = &module->parser; const char *mac_resp; char *resp_buff = calloc(1, 128); char mac_key[] = "+CIPSTAMAC:\""; - const char *mac_start; + const char *mac_start; int index; at_resp_t resp = {.buff = resp_buff, .buff_size = 128, .timeout = 5 * OS_TICK_PER_SECOND}; @@ -543,20 +551,20 @@ os_err_t esp8266_wifi_get_sta_mac(mo_object_t *module, char mac[]) { free(resp_buff); - return OS_ERROR; + return OS_ERROR; } - mac_start = mac_resp + strlen(mac_key); - for (index = 0; index < 6; index++) - { - mac[index] = hex_to_uint(*mac_start); - mac[index] = mac[index] << 4; + mac_start = mac_resp + strlen(mac_key); + for (index = 0; index < 6; index++) + { + mac[index] = hex_to_uint(*mac_start); + mac[index] = mac[index] << 4; - mac_start++; - mac[index] += hex_to_uint(*mac_start); - mac_start++; - mac_start++; - } + mac_start++; + mac[index] += hex_to_uint(*mac_start); + mac_start++; + mac_start++; + } free(resp_buff); @@ -565,11 +573,11 @@ os_err_t esp8266_wifi_get_sta_mac(mo_object_t *module, char mac[]) os_err_t esp8266_wifi_get_ap_mac(mo_object_t *module, char mac[]) { - at_parser_t *parser = &module->parser; + at_parser_t *parser = &module->parser; const char *mac_resp; char *resp_buff = calloc(1, 128); char mac_key[] = "+CIPAPMAC:\""; - const char *mac_start; + const char *mac_start; int index; at_resp_t resp = {.buff = resp_buff, .buff_size = 128, .timeout = 5 * OS_TICK_PER_SECOND}; @@ -584,21 +592,21 @@ os_err_t esp8266_wifi_get_ap_mac(mo_object_t *module, char mac[]) if (OS_NULL == mac_resp) { free(resp_buff); - return OS_ERROR; + return OS_ERROR; } - mac_start = mac_resp + strlen(mac_key); - for (index = 0; index < 6; index++) - { - mac[index] = hex_to_uint(*mac_start); - mac[index] = mac[index] << 4; + mac_start = mac_resp + strlen(mac_key); + for (index = 0; index < 6; index++) + { + mac[index] = hex_to_uint(*mac_start); + mac[index] = mac[index] << 4; + + mac_start++; + mac[index] += hex_to_uint(*mac_start); + mac_start++; + mac_start++; + } - mac_start++; - mac[index] += hex_to_uint(*mac_start); - mac_start++; - mac_start++; - } - free(resp_buff); return OS_EOK; @@ -606,16 +614,16 @@ os_err_t esp8266_wifi_get_ap_mac(mo_object_t *module, char mac[]) os_err_t esp8266_wifi_scan_info(mo_object_t *module, char *ssid, mo_wifi_scan_result_t *scan_result) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_int32_t ecn_mode = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_int32_t ecn_mode = 0; const char *data_format1 = "+CWLAP:(%d,\"%[^\"]\",%d,\"%[^\"]\",%d,%*s)"; const char *data_format2 = "+CWLAP:(%*d,\"\",%d,\"%[^\"]\",%d,%*s)"; - at_resp_t resp = {.buff = os_calloc(1, ESP8266_SCAN_RESP_BUFF_LEN), + at_resp_t resp = {.buff = os_calloc(1, ESP8266_SCAN_RESP_BUFF_LEN), .buff_size = ESP8266_SCAN_RESP_BUFF_LEN, - .timeout = 5 * OS_TICK_PER_SECOND}; + .timeout = 5 * OS_TICK_PER_SECOND}; if (OS_NULL == resp.buff) { @@ -668,12 +676,8 @@ os_err_t esp8266_wifi_scan_info(mo_object_t *module, char *ssid, mo_wifi_scan_re if (1 == get_result) { /* ssid is null */ - get_result = at_resp_get_data_by_line(&resp, - i + 1, - data_format2, - &tmp->rssi, - tmp->bssid.bssid_str, - &tmp->channel); + get_result = + at_resp_get_data_by_line(&resp, i + 1, data_format2, &tmp->rssi, tmp->bssid.bssid_str, &tmp->channel); } if (get_result > 0) @@ -726,7 +730,7 @@ __exit: { os_free(scan_result->info_array); } - os_task_msleep(1000); + os_task_msleep(1000); } if (resp.buff != OS_NULL) @@ -778,7 +782,8 @@ os_err_t esp8266_wifi_disconnect_ap(mo_object_t *module) return at_parser_exec_cmd(parser, &resp, "AT+CWQAP"); } -os_err_t esp8266_wifi_start_ap(mo_object_t *module, const char *ssid, const char *password, os_uint8_t channel, os_uint8_t ecn) +os_err_t +esp8266_wifi_start_ap(mo_object_t *module, const char *ssid, const char *password, os_uint8_t channel, os_uint8_t ecn) { at_parser_t *parser = &module->parser; @@ -797,8 +802,8 @@ os_err_t esp8266_wifi_start_ap(mo_object_t *module, const char *ssid, const char os_err_t esp8266_wifi_stop_ap(mo_object_t *module) { - //at_parser_t *parser = &module->parser; - + // at_parser_t *parser = &module->parser; + return OS_EOK; } @@ -806,7 +811,7 @@ static void urc_connect_func(struct at_parser *parser, const char *data, os_size { OS_ASSERT(OS_NULL != data); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_esp8266_t *esp8266 = os_container_of(module, mo_esp8266_t, parent); if (strstr(data, "WIFI CONNECTED")) @@ -823,7 +828,7 @@ static void urc_connect_func(struct at_parser *parser, const char *data, os_size static void urc_ip_func(struct at_parser *parser, const char *data, os_size_t size) { - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_esp8266_t *esp8266 = os_container_of(module, mo_esp8266_t, parent); INFO("ESP8266 WIFI has get ip"); @@ -832,7 +837,7 @@ static void urc_ip_func(struct at_parser *parser, const char *data, os_size_t si static void urc_ipv6_func(struct at_parser *parser, const char *data, os_size_t size) { - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_esp8266_t *esp8266 = os_container_of(module, mo_esp8266_t, parent); INFO("ESP8266 WIFI has get ipv6 gl"); @@ -856,13 +861,13 @@ static void urc_dist_sta_ip_func(struct at_parser *parser, const char *data, os_ } static at_urc_t gs_urc_table[] = { - {.prefix = "WIFI CONNECTED", .suffix = "\n", .func = urc_connect_func}, - {.prefix = "WIFI DISCONNECT", .suffix = "\r\n", .func = urc_connect_func}, - {.prefix = "WIFI GOT IPv6 GL", .suffix = "\r\n", .func = urc_ipv6_func}, - {.prefix = "WIFI GOT IP", .suffix = "\r\n", .func = urc_ip_func}, - {.prefix = "+STA_CONNECTED:", .suffix = "\n", .func = urc_sta_connected_func}, - {.prefix = "+STA_DISCONNECTED:", .suffix = "\n", .func = urc_sta_disconnected_func}, - {.prefix = "+DIST_STA_IP:", .suffix = "\n", .func = urc_dist_sta_ip_func}, + {.prefix = "WIFI CONNECTED", .suffix = "\n", .func = urc_connect_func}, + {.prefix = "WIFI DISCONNECT", .suffix = "\r\n", .func = urc_connect_func}, + {.prefix = "WIFI GOT IPv6 GL", .suffix = "\r\n", .func = urc_ipv6_func}, + {.prefix = "WIFI GOT IP", .suffix = "\r\n", .func = urc_ip_func}, + {.prefix = "+STA_CONNECTED:", .suffix = "\n", .func = urc_sta_connected_func}, + {.prefix = "+STA_DISCONNECTED:", .suffix = "\n", .func = urc_sta_disconnected_func}, + {.prefix = "+DIST_STA_IP:", .suffix = "\n", .func = urc_dist_sta_ip_func}, }; os_err_t esp8266_wifi_init(mo_object_t *module) diff --git a/components/molink/module/gm120/include/gm120.h b/components/molink/module/gm120/include/gm120.h index 38c1d34a..fb60fa14 100644 --- a/components/molink/module/gm120/include/gm120.h +++ b/components/molink/module/gm120/include/gm120.h @@ -73,16 +73,16 @@ typedef struct mo_gm120 mo_object_t parent; #ifdef GM120_USING_NETCONN_OPS mo_netconn_t netconn[GM120_NETCONN_NUM]; - - os_int32_t curr_connect; + + os_int32_t curr_connect; os_event_t netconn_evt; os_mutex_t netconn_lock; - void *netconn_data; + void *netconn_data; #endif /* GM120_USING_NETCONN_OPS */ } mo_gm120_t; mo_object_t *module_gm120_create(const char *name, void *parser_config); -os_err_t module_gm120_destroy(mo_object_t *self); +os_err_t module_gm120_destroy(mo_object_t *self); #endif /* MOLINK_USING_GM120 */ @@ -91,4 +91,3 @@ os_err_t module_gm120_destroy(mo_object_t *self); #endif /* __cplusplus */ #endif /* __GM120_H__ */ - diff --git a/components/molink/module/gm120/include/gm120_general.h b/components/molink/module/gm120/include/gm120_general.h index fcc37080..22fa7d37 100644 --- a/components/molink/module/gm120/include/gm120_general.h +++ b/components/molink/module/gm120/include/gm120_general.h @@ -21,17 +21,16 @@ *********************************************************************************************************************** */ - -#ifndef __GM120_GENERAL_H__ -#define __GM120_GENERAL_H__ +#ifndef __GM120_GENERAL_H__ +#define __GM120_GENERAL_H__ #include "mo_general.h" -#ifdef __cplusplus -extern "C" { +#ifdef __cplusplus +extern "C" { #endif -#ifdef GM120_USING_GENERAL_OPS +#ifdef GM120_USING_GENERAL_OPS os_err_t gm120_at_test(mo_object_t *self); os_err_t gm120_get_imei(mo_object_t *self, char *value, os_size_t len); @@ -41,11 +40,10 @@ os_err_t gm120_get_cfun(mo_object_t *self, os_uint8_t *fun_lvl); os_err_t gm120_set_cfun(mo_object_t *self, os_uint8_t fun_lvl); os_err_t gm120_get_firmware_version(mo_object_t *self, mo_firmware_version_t *version); -#endif /* GM120_USING_GENERAL_OPS */ +#endif /* GM120_USING_GENERAL_OPS */ -#ifdef __cplusplus +#ifdef __cplusplus } #endif -#endif /* __GM120_GENERAL_H__ */ - +#endif /* __GM120_GENERAL_H__ */ diff --git a/components/molink/module/gm120/include/gm120_ifconfig.h b/components/molink/module/gm120/include/gm120_ifconfig.h index bae813b2..02692d6c 100644 --- a/components/molink/module/gm120/include/gm120_ifconfig.h +++ b/components/molink/module/gm120/include/gm120_ifconfig.h @@ -41,5 +41,3 @@ os_err_t gm120_get_ipaddr(mo_object_t *self, char ip[]); #endif /* __cplusplus */ #endif /* __GM120_IFCONFIG_H__ */ - - diff --git a/components/molink/module/gm120/include/gm120_netconn.h b/components/molink/module/gm120/include/gm120_netconn.h index 2fe568a2..b8059e3b 100644 --- a/components/molink/module/gm120/include/gm120_netconn.h +++ b/components/molink/module/gm120/include/gm120_netconn.h @@ -33,12 +33,12 @@ extern "C" { #ifdef GM120_USING_NETCONN_OPS mo_netconn_t *gm120_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t gm120_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); -os_err_t gm120_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t gm120_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t gm120_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t gm120_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t gm120_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t gm120_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t gm120_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef GM120_USING_DNS -os_err_t gm120_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t gm120_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* GM120_USING_NETCONN_OPS */ @@ -48,4 +48,3 @@ os_err_t gm120_netconn_gethostbyname(mo_object_t *self, const char *domain_ #endif /* __cplusplus */ #endif /* __M5310A_NETCONN_H__ */ - diff --git a/components/molink/module/gm120/include/gm120_netserv.h b/components/molink/module/gm120/include/gm120_netserv.h index 28603e11..8b9fe6fd 100644 --- a/components/molink/module/gm120/include/gm120_netserv.h +++ b/components/molink/module/gm120/include/gm120_netserv.h @@ -47,4 +47,3 @@ os_err_t gm120_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber); #endif /* __cplusplus */ #endif /* __GM120_NETSERV_H__ */ - diff --git a/components/molink/module/gm120/source/gm120.c b/components/molink/module/gm120/source/gm120.c index 3d113117..e32ab5cb 100644 --- a/components/molink/module/gm120/source/gm120.c +++ b/components/molink/module/gm120/source/gm120.c @@ -1,31 +1,31 @@ - /** - *********************************************************************************************************************** - * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * @file gm120.c - * - * @brief gm120.c module api - * - * @revision - * Date Author Notes - * 2020-11-13 OneOS Team First Version - *********************************************************************************************************************** - */ +/** +*********************************************************************************************************************** +* Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. +* +* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +* specific language governing permissions and limitations under the License. +* +* @file gm120.c +* +* @brief gm120.c module api +* +* @revision +* Date Author Notes +* 2020-11-13 OneOS Team First Version +*********************************************************************************************************************** +*/ #include "gm120.h" #include #define MO_LOG_TAG "gm120" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_GM120 @@ -34,58 +34,54 @@ #ifdef GM120_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = gm120_at_test, - .get_imei = gm120_get_imei, - .get_imsi = gm120_get_imsi, + .at_test = gm120_at_test, + .get_imei = gm120_get_imei, + .get_imsi = gm120_get_imsi, .get_iccid = gm120_get_iccid, - .get_cfun = gm120_get_cfun, - .set_cfun = gm120_set_cfun, + .get_cfun = gm120_get_cfun, + .set_cfun = gm120_set_cfun, .get_firmware_version = gm120_get_firmware_version, }; #endif /* GM120_USING_GENERAL_OPS */ #ifdef GM120_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = gm120_set_attach, - .get_attach = gm120_get_attach, - .set_reg = gm120_set_reg, - .get_reg = gm120_get_reg, - .set_cgact = gm120_set_cgact, - .get_cgact = gm120_get_cgact, - .get_csq = gm120_get_csq, + .set_attach = gm120_set_attach, + .get_attach = gm120_get_attach, + .set_reg = gm120_set_reg, + .get_reg = gm120_get_reg, + .set_cgact = gm120_set_cgact, + .get_cgact = gm120_get_cgact, + .get_csq = gm120_get_csq, }; #endif /* GM120_USING_NETSERV_OPS */ #ifdef GM120_USING_PING_OPS static const struct mo_ping_ops gs_ping_ops = { - .ping = gm120_ping, + .ping = gm120_ping, }; #endif #ifdef GM120_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = gm120_ifconfig, - .get_ipaddr = gm120_get_ipaddr, + .ifconfig = gm120_ifconfig, + .get_ipaddr = gm120_get_ipaddr, }; #endif /* GM120_USING_IFCONFIG_OPS */ #ifdef GM120_USING_NETCONN_OPS extern void gm120_netconn_init(mo_gm120_t *module); -static const struct mo_netconn_ops gs_netconn_ops = { - .create = gm120_netconn_create, - .destroy = gm120_netconn_destroy, - .connect = gm120_netconn_connect, - .send = gm120_netconn_send, +static const struct mo_netconn_ops gs_netconn_ops = {.create = gm120_netconn_create, + .destroy = gm120_netconn_destroy, + .connect = gm120_netconn_connect, + .send = gm120_netconn_send, #ifdef GM120_USING_DNS - .gethostbyname = gm120_netconn_gethostbyname, + .gethostbyname = gm120_netconn_gethostbyname, #endif - .get_info = gm120_netconn_get_info -}; + .get_info = gm120_netconn_get_info}; #endif /* GM120_USING_NETCONN_OPS */ - - static os_err_t gm120_at_init(mo_object_t *self) { at_parser_t *parser = &self->parser; @@ -99,9 +95,7 @@ static os_err_t gm120_at_init(mo_object_t *self) char resp_buff[32] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; return at_parser_exec_cmd(parser, &resp, "AT+WORKLOCK=1"); } @@ -114,8 +108,8 @@ mo_object_t *module_gm120_create(const char *name, void *parser_config) ERROR("Create %s module instance failed, no enough memory.", name); return OS_NULL; } - -// os_task_mdelay(5000); + + // os_task_mdelay(5000); /* make sure gm120 power on and be ready */ os_err_t result = mo_object_init(&(module->parent), name, parser_config); if (result != OS_EOK) @@ -140,12 +134,12 @@ mo_object_t *module_gm120_create(const char *name, void *parser_config) #ifdef GM120_USING_PING_OPS module->parent.ops_table[MODULE_OPS_PING] = &gs_ping_ops; -#endif - +#endif + #ifdef GM120_USING_IFCONFIG_OPS module->parent.ops_table[MODULE_OPS_IFCONFIG] = &gs_ifconfig_ops; #endif /* GM120_USING_IFCONFIG_OPS */ - + #ifdef GM120_USING_NETCONN_OPS module->parent.ops_table[MODULE_OPS_NETCONN] = &gs_netconn_ops; @@ -181,13 +175,13 @@ os_err_t module_gm120_destroy(mo_object_t *self) mo_gm120_t *module = os_container_of(self, mo_gm120_t, parent); mo_object_deinit(self); - + #ifdef GM120_USING_NETCONN_OPS os_event_deinit(&module->netconn_evt); os_mutex_deinit(&module->netconn_lock); - + #endif /* GM120_USING_NETCONN_OPS */ os_free(module); @@ -213,7 +207,7 @@ int gm120_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = GM120_NAME, + mo_parser_config_t parser_config = {.parser_name = GM120_NAME, .parser_device = device, .recv_buff_len = GM120_RECV_BUFF_LEN}; @@ -231,4 +225,3 @@ OS_CMPOENT_INIT(gm120_auto_create, OS_INIT_SUBLEVEL_MIDDLE); #endif /* GM120_AUTO_CREATE */ #endif /* MOLINK_USING_GM120 */ - diff --git a/components/molink/module/gm120/source/gm120_general.c b/components/molink/module/gm120/source/gm120_general.c index e3ddc410..f0b1c105 100644 --- a/components/molink/module/gm120/source/gm120_general.c +++ b/components/molink/module/gm120/source/gm120_general.c @@ -21,13 +21,12 @@ *********************************************************************************************************************** */ - #include #include #include "gm120_general.h" #define MO_LOG_TAG "gm120_general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef GM120_USING_GENERAL_OPS @@ -43,7 +42,7 @@ os_err_t gm120_at_test(mo_object_t *self) return at_parser_exec_cmd(parser, &resp, "AT"); } -os_err_t gm120_get_imei(mo_object_t * self,char * value, os_size_t len) +os_err_t gm120_get_imei(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_IMEI_LEN); @@ -52,18 +51,17 @@ os_err_t gm120_get_imei(mo_object_t * self,char * value, os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN=1")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN=1")) { return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGSN:", "+CGSN: %s", value) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGSN:", "+CGSN: %s", value) <= 0) { ERROR("Get %s module imei failed."); return OS_ERROR; } - value[MO_IMEI_LEN] = '\0'; INFO("%s module imei:%s", self->name, value); @@ -71,7 +69,7 @@ os_err_t gm120_get_imei(mo_object_t * self,char * value, os_size_t len) return OS_EOK; } -os_err_t gm120_get_imsi(mo_object_t * self,char * value, os_size_t len) +os_err_t gm120_get_imsi(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_IMSI_LEN); @@ -80,12 +78,12 @@ os_err_t gm120_get_imsi(mo_object_t * self,char * value, os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * AT_RESP_TIMEOUT_DEF}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CIMI")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CIMI")) { return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CIMI:", "+CIMI: %s", value) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CIMI:", "+CIMI: %s", value) <= 0) { ERROR("Get %s module imsi failed."); return OS_ERROR; @@ -93,12 +91,12 @@ os_err_t gm120_get_imsi(mo_object_t * self,char * value, os_size_t len) value[MO_IMSI_LEN] = '\0'; - DEBUG("%s module imsi:%s",self->name,value); + DEBUG("%s module imsi:%s", self->name, value); return OS_EOK; } -os_err_t gm120_get_iccid(mo_object_t * self,char * value, os_size_t len) +os_err_t gm120_get_iccid(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_ICCID_LEN); @@ -107,12 +105,12 @@ os_err_t gm120_get_iccid(mo_object_t * self,char * value, os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+NCCID")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+NCCID")) { return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+NCCID:", "+NCCID: %s", value) <= 0) + if (at_resp_get_data_by_kw(&resp, "+NCCID:", "+NCCID: %s", value) <= 0) { ERROR("Get %s module ccid failed.", self->parser); return OS_ERROR; @@ -123,7 +121,7 @@ os_err_t gm120_get_iccid(mo_object_t * self,char * value, os_size_t len) return OS_EOK; } -os_err_t gm120_get_cfun(mo_object_t * self, os_uint8_t *fun_lvl) +os_err_t gm120_get_cfun(mo_object_t *self, os_uint8_t *fun_lvl) { at_parser_t *parser = &self->parser; @@ -136,7 +134,7 @@ os_err_t gm120_get_cfun(mo_object_t * self, os_uint8_t *fun_lvl) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CFUN:", "+CFUN: %hhu",fun_lvl) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CFUN:", "+CFUN: %hhu", fun_lvl) <= 0) { ERROR("Get %s module level of functionality failed.", self->name); return OS_ERROR; @@ -162,9 +160,7 @@ os_err_t gm120_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ve char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CGMR"); if (result != OS_EOK) @@ -179,7 +175,7 @@ os_err_t gm120_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ve } const char *source_line = at_resp_get_line(&resp, 1); - os_size_t line_length = strlen(source_line); + os_size_t line_length = strlen(source_line); char **dest_line = &version->ver_info[0]; @@ -197,6 +193,4 @@ os_err_t gm120_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ve return OS_EOK; } - -#endif /* GM120_USING_GENERAL_OPS */ - +#endif /* GM120_USING_GENERAL_OPS */ diff --git a/components/molink/module/gm120/source/gm120_ifconfig.c b/components/molink/module/gm120/source/gm120_ifconfig.c index ea74c575..425cc4cc 100644 --- a/components/molink/module/gm120/source/gm120_ifconfig.c +++ b/components/molink/module/gm120/source/gm120_ifconfig.c @@ -30,7 +30,7 @@ #include #define MO_LOG_TAG "gm120_ifconfig" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef GM120_USING_IFCONFIG_OPS @@ -56,12 +56,12 @@ os_err_t gm120_ifconfig(mo_object_t *self) } os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t ber = 0; if (gm120_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; } os_kprintf("\r\nLIST AT MODULE INFORMATIONS\r\n"); @@ -89,9 +89,9 @@ os_err_t gm120_ifconfig(mo_object_t *self) os_err_t gm120_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t ucid = -1; - os_int8_t len = -1; - int i = 1; + os_int8_t ucid = -1; + os_int8_t len = -1; + int i = 1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[512] = {0}; @@ -104,21 +104,20 @@ os_err_t gm120_get_ipaddr(mo_object_t *self, char ip[]) ERROR("Get ip address fail: AT+CGPADDR cmd exec fail."); goto __exit; } - - /* Response for ex: +CGPADDR:0,100.113.120.235 */ + + /* Response for ex: +CGPADDR:0,100.113.120.235 */ do { - if (at_resp_get_data_by_line(&resp, i , "+CGPADDR:%d, \"%[^\"]", &ucid, ipaddr) <= 0) + if (at_resp_get_data_by_line(&resp, i, "+CGPADDR:%d, \"%[^\"]", &ucid, ipaddr) <= 0) { ERROR("Get ip address: parse resp fail."); result = OS_ERROR; goto __exit; - } - i = i + 1; - len = strlen(ipaddr); - } - while(len == 0); - + } + i = i + 1; + len = strlen(ipaddr); + } while (len == 0); + if ((len < IPADDR_MIN_STR_LEN) || (len > IPADDR_MAX_STR_LEN)) { ERROR("IP address size [%d] error.", len); @@ -137,4 +136,3 @@ __exit: } #endif /* GM120_USING_IFCONFIG_OPS */ - diff --git a/components/molink/module/gm120/source/gm120_netconn.c b/components/molink/module/gm120/source/gm120_netconn.c index 60d63a0f..703a1d93 100644 --- a/components/molink/module/gm120/source/gm120_netconn.c +++ b/components/molink/module/gm120/source/gm120_netconn.c @@ -29,7 +29,7 @@ #include #define MO_LOG_TAG "gm120_netconn" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define SEND_DATA_MAX_SIZE (1400) @@ -42,20 +42,18 @@ #endif #ifndef GM120_NETCONN_MQ_MSG_MAX -#define GM120_NETCONN_MQ_MSG_MAX (5) +#define GM120_NETCONN_MQ_MSG_MAX (5) #endif #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) -#define GM120_EVENT_CONN_OK (1L << 0) -#define GM120_EVENT_SEND_OK (1L << 1) -#define GM120_EVENT_RECV_OK (1L << 2) -#define GM120_EVENT_CLOSE_OK (1L << 3) - +#define GM120_EVENT_CONN_OK (1L << 0) +#define GM120_EVENT_SEND_OK (1L << 1) +#define GM120_EVENT_RECV_OK (1L << 2) +#define GM120_EVENT_CLOSE_OK (1L << 3) #ifdef GM120_USING_NETCONN_OPS - static os_err_t gm120_lock(os_mutex_t *mutex) { return os_mutex_recursive_lock(mutex, OS_WAIT_FOREVER); @@ -95,7 +93,7 @@ static mo_netconn_t *gm120_get_netconn_by_id(mo_object_t *module, os_int32_t con } mo_gm120_t *gm120 = os_container_of(module, mo_gm120_t, parent); - + for (int i = 0; i < GM120_NETCONN_NUM; i++) { if (connect_id == gm120->netconn[i].connect_id) @@ -105,7 +103,6 @@ static mo_netconn_t *gm120_get_netconn_by_id(mo_object_t *module, os_int32_t con } return OS_NULL; - } os_err_t gm120_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) @@ -113,7 +110,7 @@ os_err_t gm120_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_gm120_t *gm120 = os_container_of(module, mo_gm120_t, parent); info->netconn_array = gm120->netconn; - info->netconn_nums = sizeof(gm120->netconn) / sizeof(gm120->netconn[0]); + info->netconn_nums = sizeof(gm120->netconn) / sizeof(gm120->netconn[0]); return OS_EOK; } @@ -121,9 +118,9 @@ os_err_t gm120_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_netconn_t *gm120_netconn_create(mo_object_t *module, mo_netconn_type_t type) { mo_gm120_t *gm120 = os_container_of(module, mo_gm120_t, parent); - + gm120_lock(&gm120->netconn_lock); - + mo_netconn_t *netconn = gm120_netconn_alloc(module); if (OS_NULL == netconn) { @@ -131,9 +128,7 @@ mo_netconn_t *gm120_netconn_create(mo_object_t *module, mo_netconn_type_t type) return OS_NULL; } - netconn->mq = os_mq_create(GM120_NETCONN_MQ_NAME, - GM120_NETCONN_MQ_MSG_SIZE, - GM120_NETCONN_MQ_MSG_MAX); + netconn->mq = os_mq_create(GM120_NETCONN_MQ_NAME, GM120_NETCONN_MQ_MSG_SIZE, GM120_NETCONN_MQ_MSG_MAX); if (OS_NULL == netconn->mq) { ERROR("%s data queue create failed, no enough memory.", module->name); @@ -149,20 +144,17 @@ mo_netconn_t *gm120_netconn_create(mo_object_t *module, mo_netconn_type_t type) os_err_t gm120_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; - - mo_gm120_t * gm120 = os_container_of(module, mo_gm120_t, parent); + at_parser_t *parser = &module->parser; + os_err_t result = OS_ERROR; + + mo_gm120_t *gm120 = os_container_of(module, mo_gm120_t, parent); gm120_lock(&gm120->netconn_lock); - + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 10 * OS_TICK_PER_SECOND - }; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; os_uint32_t event = SET_EVENT(netconn->connect_id, GM120_EVENT_CONN_OK); os_event_recv(&gm120->netconn_evt, event, OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, OS_NO_WAIT, OS_NULL); - + switch (netconn->stat) { case NETCONN_STAT_INIT: @@ -172,28 +164,28 @@ os_err_t gm120_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) if (result != OS_EOK) { ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + module->name, + (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); gm120_unlock(&gm120->netconn_lock); return result; } - + result = os_event_recv(&gm120->netconn_evt, - SET_EVENT(netconn->connect_id, 0), - OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, - 60 * OS_TICK_PER_SECOND, - OS_NULL); + SET_EVENT(netconn->connect_id, 0), + OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, + 60 * OS_TICK_PER_SECOND, + OS_NULL); if (result != OS_EOK) { gm120_unlock(&gm120->netconn_lock); return result; } - result = os_event_recv(&gm120->netconn_evt, - GM120_EVENT_CLOSE_OK, - OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, - 1 * OS_TICK_PER_SECOND, - &event); + result = os_event_recv(&gm120->netconn_evt, + GM120_EVENT_CLOSE_OK, + OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, + 1 * OS_TICK_PER_SECOND, + &event); if (result != OS_EOK) { gm120_unlock(&gm120->netconn_lock); @@ -213,54 +205,49 @@ os_err_t gm120_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn id %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); - + gm120_unlock(&gm120->netconn_lock); - + return OS_EOK; } - os_err_t gm120_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - mo_gm120_t * gm120 = os_container_of(module, mo_gm120_t, parent); - os_uint8_t socket_id; - - gm120_lock(&gm120->netconn_lock); - + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + mo_gm120_t *gm120 = os_container_of(module, mo_gm120_t, parent); + os_uint8_t socket_id; + + gm120_lock(&gm120->netconn_lock); + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 150 * OS_TICK_PER_SECOND}; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; strncpy(remote_ip, inet_ntoa(addr), IPADDR_MAX_STR_LEN); - os_event_recv(&gm120->netconn_evt, GM120_EVENT_CONN_OK, OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, OS_NO_WAIT, OS_NULL); - + os_event_recv(&gm120->netconn_evt, + GM120_EVENT_CONN_OK, + OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, + OS_NO_WAIT, + OS_NULL); + switch (netconn->type) { #ifdef GM120_USING_TCP case NETCONN_TYPE_TCP: - result = at_parser_exec_cmd(parser, - &resp, - "AT+SOPEN=0,%s,%d", - remote_ip, - port); + result = at_parser_exec_cmd(parser, &resp, "AT+SOPEN=0,%s,%d", remote_ip, port); break; #endif #ifdef GM120_USING_UDP case NETCONN_TYPE_UDP: - result = at_parser_exec_cmd(parser, - &resp, - "AT+SOPEN=1,%s,%d", - remote_ip, - port); + result = at_parser_exec_cmd(parser, &resp, "AT+SOPEN=1,%s,%d", remote_ip, port); break; #endif @@ -273,19 +260,19 @@ os_err_t gm120_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ad { goto __exit; } - + if (at_resp_get_data_by_kw(&resp, "+SOPEN:", "+SOPEN: %d", &socket_id) <= 0) { result = OS_ERROR; goto __exit; } - + if (socket_id != 1 && socket_id != 0) { result = OS_ERROR; goto __exit; } - + netconn->connect_id = socket_id; result = os_event_recv(&gm120->netconn_evt, @@ -296,14 +283,14 @@ os_err_t gm120_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ad if (result != OS_EOK) { goto __exit; - } + } __exit: if (OS_EOK == result) { ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); } @@ -318,9 +305,9 @@ __exit: os_size_t gm120_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + mo_gm120_t *gm120 = os_container_of(module, mo_gm120_t, parent); at_parser_exec_lock(parser); @@ -329,26 +316,23 @@ os_size_t gm120_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const c char resp_buff[128] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 5 * OS_TICK_PER_SECOND - }; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; if (size > SEND_DATA_MAX_SIZE || size < SEND_DATA_MIN_SIZE) { result = OS_ERROR; - ERROR("Send data size (%d) is out of range [1,1400]",size); - goto __exit; + ERROR("Send data size (%d) is out of range [1,1400]", size); + goto __exit; } - - for(int i = 0; i< size - 1; i++) + + for (int i = 0; i < size - 1; i++) { - if((*(data + i)) == '\r' && (*(data + i + 1)) == '\n') + if ((*(data + i)) == '\r' && (*(data + i + 1)) == '\n') { - ERROR("Error: send data contain [CR LF]"); + ERROR("Error: send data contain [CR LF]"); result = OS_ERROR; - goto __exit; - } + goto __exit; + } } result = at_parser_exec_cmd(parser, &resp, "AT+SSEND=%d,%d,\"%s\"", netconn->connect_id, size, data); @@ -356,7 +340,6 @@ os_size_t gm120_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const c { goto __exit; } - __exit: @@ -377,29 +360,29 @@ os_err_t gm120_netconn_gethostbyname(mo_object_t *self, const char *domain_name, OS_ASSERT(OS_NULL != domain_name); OS_ASSERT(OS_NULL != addr); - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; - char resp_buff[128] = {0}; + char resp_buff[128] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 15 * OS_TICK_PER_SECOND}; mo_gm120_t *gm120 = os_container_of(self, mo_gm120_t, parent); gm120->netconn_data = addr; - + result = at_parser_exec_cmd(parser, &resp, "AT+DNS=\"%s\"", domain_name); if (result != OS_EOK) { goto __exit; } - + if (at_resp_get_data_by_kw(&resp, "+DNS:", "+DNS: %s", &recvip) <= 0) { result = OS_ERROR; goto __exit; } - + recvip[IPADDR_MAX_STR_LEN] = '\0'; inet_aton(recvip, (ip_addr_t *)gm120->netconn_data); @@ -417,11 +400,11 @@ static void urc_stat_func(struct at_parser *parser, const char *data, os_size_t { OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - - os_int32_t stat = 0; - os_int32_t connect_id = -1; - mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_gm120_t *gm120 = os_container_of(module, mo_gm120_t, parent); + + os_int32_t stat = 0; + os_int32_t connect_id = -1; + mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_gm120_t *gm120 = os_container_of(module, mo_gm120_t, parent); sscanf(data, "+SSTATE: %d,%d", &connect_id, &stat); @@ -435,16 +418,15 @@ static void urc_stat_func(struct at_parser *parser, const char *data, os_size_t } } - static void urc_recv_data_func(struct at_parser *parser, mo_netconn_t *netconn, os_size_t data_size) { - mo_object_t *module = os_container_of(parser, mo_object_t, parser); - os_int32_t timeout = data_size > 10 ? data_size : 10; + mo_object_t *module = os_container_of(parser, mo_object_t, parser); + os_int32_t timeout = data_size > 10 ? data_size : 10; INFO("Moudle %s netconn %d receive %d bytes data", parser->name, netconn->connect_id, data_size); - char *recv_buff = os_calloc(1, data_size); - char temp_buff[8] = {0}; + char *recv_buff = os_calloc(1, data_size); + char temp_buff[8] = {0}; if (recv_buff == OS_NULL) { /* read and clean the coming data */ @@ -489,20 +471,20 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); char tmp_ch; - + at_parser_recv(parser, &tmp_ch, 1, 0); os_int32_t connect_id = atoi(&tmp_ch); - - mo_object_t *module = os_container_of(parser, mo_object_t, parser); - + + mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_netconn_t *netconn = gm120_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) { ERROR("Module %s receive error recv urc data of connect %d", module->name, connect_id); return; } - + at_parser_recv(parser, &tmp_ch, 1, 0); /* Get data size */ char tmp_str[5] = {0}; @@ -518,24 +500,24 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t tmp_str[i] = tmp_ch; } os_size_t data_size = atoi(tmp_str); - + at_parser_recv(parser, &tmp_ch, 1, 0); - + urc_recv_data_func(parser, netconn, data_size); return; } static at_urc_t gs_urc_table[] = { - {.prefix = "+SSTATE:", .suffix = "\r\n", .func = urc_stat_func}, - {.prefix = "", .suffix = "+SRECV:", .func = urc_recv_func}, + {.prefix = "+SSTATE:", .suffix = "\r\n", .func = urc_stat_func}, + {.prefix = "", .suffix = "+SRECV:", .func = urc_recv_func}, }; static void gm120_network_init(mo_object_t *module) { - at_parser_t *parser = &module->parser; - os_int32_t enable_num = 0; - os_int32_t reg_state = 0; - os_err_t result = OS_ERROR; + at_parser_t *parser = &module->parser; + os_int32_t enable_num = 0; + os_int32_t reg_state = 0; + os_err_t result = OS_ERROR; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; @@ -545,19 +527,19 @@ static void gm120_network_init(mo_object_t *module) { INFO("Send data type is not string"); } - + result = at_parser_exec_cmd(parser, &resp, "AT+CEREG?"); if (result != OS_EOK) { goto __exit; } - - if (at_resp_get_data_by_kw(&resp, "+CEREG:", "+CEREG: %d,%d", &enable_num , ®_state) < 0) + + if (at_resp_get_data_by_kw(&resp, "+CEREG:", "+CEREG: %d,%d", &enable_num, ®_state) < 0) { result = OS_ERROR; goto __exit; } - + if (1 == reg_state || 5 == reg_state) { result = OS_EOK; @@ -566,10 +548,10 @@ static void gm120_network_init(mo_object_t *module) else { result = OS_ERROR; - goto __exit; + goto __exit; } __exit: - if(result != OS_EOK) + if (result != OS_EOK) { WARN("GM120 network init failed"); } @@ -596,4 +578,3 @@ void gm120_netconn_init(mo_gm120_t *module) } #endif /* GM120_USING_NETCONN_OPS */ - diff --git a/components/molink/module/gm120/source/gm120_netserv.c b/components/molink/module/gm120/source/gm120_netserv.c index 2112af21..d38301bf 100644 --- a/components/molink/module/gm120/source/gm120_netserv.c +++ b/components/molink/module/gm120/source/gm120_netserv.c @@ -29,12 +29,11 @@ #include #define MO_LOG_TAG "gm120_netserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define IP_SIZE 16 - #ifdef GM120_USING_NETSERV_OPS os_err_t gm120_set_attach(mo_object_t *self, os_uint8_t attach_stat) @@ -163,4 +162,3 @@ os_err_t gm120_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber) } #endif /* gm120_USING_NETSERV_OPS */ - diff --git a/components/molink/module/gm120/source/gm120_ping.c b/components/molink/module/gm120/source/gm120_ping.c index eee83475..1a3f7647 100644 --- a/components/molink/module/gm120/source/gm120_ping.c +++ b/components/molink/module/gm120/source/gm120_ping.c @@ -27,7 +27,7 @@ #include #define MO_LOG_TAG "gm120_ping" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define GM120_MIN_PING_PKG_LEN (1) @@ -35,8 +35,8 @@ #define GM120_MIN_PING_TIMEOUT (1) #define GM120_MAX_PING_TIMEOUT (65534) -#define MB_MAX_MAILS 5 -#define TEST_NAME_MAX 16 +#define MB_MAX_MAILS 5 +#define TEST_NAME_MAX 16 #ifdef GM120_USING_PING_OPS @@ -46,11 +46,11 @@ static void urc_ping_func(struct at_parser *parser, const char *data, os_size_t { OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - char tmp_str[5] = {0}; + char tmp_str[5] = {0}; char *tmp; - - tmp = strstr(data,"time:"); - tmp = tmp + 5; + + tmp = strstr(data, "time:"); + tmp = tmp + 5; for (int i = 0;; i++) { if ('m' == tmp[i]) @@ -59,8 +59,8 @@ static void urc_ping_func(struct at_parser *parser, const char *data, os_size_t } tmp_str[i] = tmp[i]; - } - + } + os_mb_send(mb_dynamic, (os_uint32_t)atoi(tmp_str), OS_WAIT_FOREVER); } @@ -70,14 +70,13 @@ static at_urc_t gs_urc_table[] = { os_err_t gm120_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - os_uint32_t req_time = 0; - os_int16_t ttl = -1; - os_uint32_t timeout_s = timeout / 1000; /* Milliseconds convert to seconds */ - os_ubase_t recv_data = 0; - - + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; + os_uint32_t req_time = 0; + os_int16_t ttl = -1; + os_uint32_t timeout_s = timeout / 1000; /* Milliseconds convert to seconds */ + os_ubase_t recv_data = 0; + if (parser == OS_NULL) { ERROR("GM120 ping: at parser is NULL."); @@ -86,23 +85,27 @@ os_err_t gm120_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uin if ((len < GM120_MIN_PING_PKG_LEN) || (len > GM120_MAX_PING_PKG_LEN)) { - ERROR("GM120 ping: ping package len[%d] is out of range[%d, %d].", - len, GM120_MIN_PING_PKG_LEN, GM120_MAX_PING_PKG_LEN); + ERROR("GM120 ping: ping package len[%d] is out of range[%d, %d].", + len, + GM120_MIN_PING_PKG_LEN, + GM120_MAX_PING_PKG_LEN); return OS_ERROR; } if ((timeout_s < GM120_MIN_PING_TIMEOUT) || (timeout_s > GM120_MAX_PING_TIMEOUT)) { - ERROR("GM120 ping: ping timeout %us is out of range[%ds, %ds].", - timeout_s, GM120_MIN_PING_TIMEOUT, GM120_MAX_PING_TIMEOUT); + ERROR("GM120 ping: ping timeout %us is out of range[%ds, %ds].", + timeout_s, + GM120_MIN_PING_TIMEOUT, + GM120_MAX_PING_TIMEOUT); return OS_ERROR; } - + /* Set netconn urc table */ at_parser_set_urc_table(parser, gs_urc_table, sizeof(gs_urc_table) / sizeof(gs_urc_table[0])); - + mb_dynamic = os_mb_create("mailbox_dynamic", MB_MAX_MAILS); - if(!mb_dynamic) + if (!mb_dynamic) { WARN("mailbox_dynamic_sample mailbox create ERR"); return OS_ERROR; @@ -111,15 +114,14 @@ os_err_t gm120_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uin char resp_buff[256] = {0}; - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .timeout = (5 + timeout_s) * OS_TICK_PER_SECOND - }; + .timeout = (5 + timeout_s) * OS_TICK_PER_SECOND}; /* Send commond "AT+MPING= or ip addr" and wait response */ /* Exec AT+MPING="www.baidu.com",2,1,64 and return: 0 183.232.231.172: bytes = 36 time = 96(ms), TTL = 255 */ - if (at_parser_exec_cmd(parser, &at_resp, "AT+NPING=%s,%u,1,%d,%d", host,len, timeout_s, timeout_s + 1) < 0) + if (at_parser_exec_cmd(parser, &at_resp, "AT+NPING=%s,%u,1,%d,%d", host, len, timeout_s, timeout_s + 1) < 0) { result = OS_ERROR; goto __exit; @@ -128,16 +130,16 @@ os_err_t gm120_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uin { result = OS_ERROR; goto __exit; - } - - req_time = recv_data; - + } + + req_time = recv_data; + if (0 != req_time) { inet_aton(host, &(resp->ip_addr)); resp->data_len = len; - resp->ttl = ttl; - resp->time = req_time; + resp->ttl = ttl; + resp->time = req_time; } else { diff --git a/components/molink/module/gm190/include/gm190.h b/components/molink/module/gm190/include/gm190.h index 1c9f6c92..30d7d886 100644 --- a/components/molink/module/gm190/include/gm190.h +++ b/components/molink/module/gm190/include/gm190.h @@ -69,15 +69,15 @@ typedef struct mo_gm190 mo_object_t parent; #ifdef GM190_USING_NETCONN_OPS mo_netconn_t netconn[GM190_NETCONN_NUM]; - os_int32_t curr_connect; + os_int32_t curr_connect; os_event_t netconn_evt; os_mutex_t netconn_lock; - void *netconn_data; + void *netconn_data; #endif /* GM190_USING_NETCONN_OPS */ } mo_gm190_t; mo_object_t *module_gm190_create(const char *name, void *parser_config); -os_err_t module_gm190_destroy(mo_object_t *self); +os_err_t module_gm190_destroy(mo_object_t *self); #endif /* MOLINK_USING_GM190 */ @@ -86,4 +86,3 @@ os_err_t module_gm190_destroy(mo_object_t *self); #endif /* __cplusplus */ #endif /* __GM190_H__ */ - diff --git a/components/molink/module/gm190/include/gm190_general.h b/components/molink/module/gm190/include/gm190_general.h index 267b6c91..93da7bd6 100644 --- a/components/molink/module/gm190/include/gm190_general.h +++ b/components/molink/module/gm190/include/gm190_general.h @@ -21,17 +21,16 @@ *********************************************************************************************************************** */ - -#ifndef __GM190_GENERAL_H__ -#define __GM190_GENERAL_H__ +#ifndef __GM190_GENERAL_H__ +#define __GM190_GENERAL_H__ #include "mo_general.h" -#ifdef __cplusplus -extern "C" { +#ifdef __cplusplus +extern "C" { #endif -#ifdef GM190_USING_GENERAL_OPS +#ifdef GM190_USING_GENERAL_OPS os_err_t gm190_at_test(mo_object_t *self); os_err_t gm190_get_imei(mo_object_t *self, char *value, os_size_t len); @@ -41,11 +40,10 @@ os_err_t gm190_get_cfun(mo_object_t *self, os_uint8_t *fun_lvl); os_err_t gm190_set_cfun(mo_object_t *self, os_uint8_t fun_lvl); os_err_t gm190_get_firmware_version(mo_object_t *self, mo_firmware_version_t *version); -#endif /* GM190_USING_GENERAL_OPS */ +#endif /* GM190_USING_GENERAL_OPS */ -#ifdef __cplusplus +#ifdef __cplusplus } #endif -#endif /* __GM190_GENERAL_H__ */ - +#endif /* __GM190_GENERAL_H__ */ diff --git a/components/molink/module/gm190/include/gm190_ifconfig.h b/components/molink/module/gm190/include/gm190_ifconfig.h index b83270b9..193e7baa 100644 --- a/components/molink/module/gm190/include/gm190_ifconfig.h +++ b/components/molink/module/gm190/include/gm190_ifconfig.h @@ -41,4 +41,3 @@ os_err_t gm190_get_ipaddr(mo_object_t *self, char ip[]); #endif /* __cplusplus */ #endif /* __GM190_IFCONFIG_H__ */ - diff --git a/components/molink/module/gm190/include/gm190_netconn.h b/components/molink/module/gm190/include/gm190_netconn.h index 53bfb964..cfc60def 100644 --- a/components/molink/module/gm190/include/gm190_netconn.h +++ b/components/molink/module/gm190/include/gm190_netconn.h @@ -33,10 +33,10 @@ extern "C" { #ifdef GM190_USING_NETCONN_OPS mo_netconn_t *gm190_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t gm190_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); -os_err_t gm190_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t gm190_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t gm190_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t gm190_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t gm190_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t gm190_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t gm190_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #endif /* GM190_USING_NETCONN_OPS */ @@ -45,4 +45,3 @@ os_size_t gm190_netconn_send(mo_object_t *module, mo_netconn_t *netconn, con #endif /* __cplusplus */ #endif /* __M5310A_NETCONN_H__ */ - diff --git a/components/molink/module/gm190/include/gm190_netserv.h b/components/molink/module/gm190/include/gm190_netserv.h index 4131401e..edf2fc10 100644 --- a/components/molink/module/gm190/include/gm190_netserv.h +++ b/components/molink/module/gm190/include/gm190_netserv.h @@ -39,7 +39,7 @@ os_err_t gm190_get_reg(mo_object_t *self, eps_reg_info_t *info); os_err_t gm190_set_cgact(mo_object_t *self, os_uint8_t cid, os_uint8_t act_n); os_err_t gm190_get_cgact(mo_object_t *self, os_uint8_t *cid, os_uint8_t *act_stat); os_err_t gm190_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber); -os_err_t gm190_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info); +os_err_t gm190_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info); #endif /* GM190_USING_NETSERV_OPS */ @@ -48,4 +48,3 @@ os_err_t gm190_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_ #endif /* __cplusplus */ #endif /* __GM190_NETSERV_H__ */ - diff --git a/components/molink/module/gm190/source/gm190.c b/components/molink/module/gm190/source/gm190.c index 9f828cb4..b0b72f99 100644 --- a/components/molink/module/gm190/source/gm190.c +++ b/components/molink/module/gm190/source/gm190.c @@ -25,7 +25,7 @@ #include #define MO_LOG_TAG "gm190.h" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_GM190 @@ -33,50 +33,46 @@ #ifdef GM190_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = gm190_at_test, - .get_imei = gm190_get_imei, - .get_imsi = gm190_get_imsi, + .at_test = gm190_at_test, + .get_imei = gm190_get_imei, + .get_imsi = gm190_get_imsi, .get_iccid = gm190_get_iccid, - .get_cfun = gm190_get_cfun, - .set_cfun = gm190_set_cfun, + .get_cfun = gm190_get_cfun, + .set_cfun = gm190_set_cfun, .get_firmware_version = gm190_get_firmware_version, }; #endif /* GM190_USING_GENERAL_OPS */ #ifdef GM190_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = gm190_set_attach, - .get_attach = gm190_get_attach, - .set_reg = gm190_set_reg, - .get_reg = gm190_get_reg, - .set_cgact = gm190_set_cgact, - .get_cgact = gm190_get_cgact, - .get_csq = gm190_get_csq, + .set_attach = gm190_set_attach, + .get_attach = gm190_get_attach, + .set_reg = gm190_set_reg, + .get_reg = gm190_get_reg, + .set_cgact = gm190_set_cgact, + .get_cgact = gm190_get_cgact, + .get_csq = gm190_get_csq, .get_cell_info = gm190_get_cell_info, }; #endif /* GM190_USING_NETSERV_OPS */ #ifdef GM190_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = gm190_ifconfig, - .get_ipaddr = gm190_get_ipaddr, + .ifconfig = gm190_ifconfig, + .get_ipaddr = gm190_get_ipaddr, }; #endif /* GM190_USING_IFCONFIG_OPS */ #ifdef GM190_USING_NETCONN_OPS extern void gm190_netconn_init(mo_gm190_t *module); -static const struct mo_netconn_ops gs_netconn_ops = { - .create = gm190_netconn_create, - .destroy = gm190_netconn_destroy, - .connect = gm190_netconn_connect, - .send = gm190_netconn_send, - .get_info = gm190_netconn_get_info -}; +static const struct mo_netconn_ops gs_netconn_ops = {.create = gm190_netconn_create, + .destroy = gm190_netconn_destroy, + .connect = gm190_netconn_connect, + .send = gm190_netconn_send, + .get_info = gm190_netconn_get_info}; #endif /* GM190_USING_NETCONN_OPS */ - - static os_err_t gm190_at_init(mo_object_t *self) { at_parser_t *parser = &self->parser; @@ -90,9 +86,7 @@ static os_err_t gm190_at_init(mo_object_t *self) char resp_buff[32] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; return at_parser_exec_cmd(parser, &resp, "ATE0"); } @@ -105,7 +99,7 @@ mo_object_t *module_gm190_create(const char *name, void *parser_config) ERROR("Create %s module instance failed, no enough memory.", name); return OS_NULL; } - + os_task_msleep(20); /* make sure gm190 power on and be ready */ os_err_t result = mo_object_init(&(module->parent), name, parser_config); @@ -128,11 +122,11 @@ mo_object_t *module_gm190_create(const char *name, void *parser_config) #ifdef GM190_USING_NETSERV_OPS module->parent.ops_table[MODULE_OPS_NETSERV] = &gs_netserv_ops; #endif /* GM190_USING_NETSERV_OPS */ - + #ifdef GM190_USING_IFCONFIG_OPS module->parent.ops_table[MODULE_OPS_IFCONFIG] = &gs_ifconfig_ops; #endif /* GM190_USING_IFCONFIG_OPS */ - + #ifdef GM190_USING_NETCONN_OPS module->parent.ops_table[MODULE_OPS_NETCONN] = &gs_netconn_ops; @@ -168,13 +162,13 @@ os_err_t module_gm190_destroy(mo_object_t *self) mo_gm190_t *module = os_container_of(self, mo_gm190_t, parent); mo_object_deinit(self); - + #ifdef GM190_USING_NETCONN_OPS os_event_deinit(&module->netconn_evt); os_mutex_deinit(&module->netconn_lock); - + #endif /* GM190_USING_NETCONN_OPS */ os_free(module); @@ -200,7 +194,7 @@ int gm190_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = GM190_NAME, + mo_parser_config_t parser_config = {.parser_name = GM190_NAME, .parser_device = device, .recv_buff_len = GM190_RECV_BUFF_LEN}; @@ -218,4 +212,3 @@ OS_CMPOENT_INIT(gm190_auto_create, OS_INIT_SUBLEVEL_MIDDLE); #endif /* GM190_AUTO_CREATE */ #endif /* MOLINK_USING_GM190 */ - diff --git a/components/molink/module/gm190/source/gm190_general.c b/components/molink/module/gm190/source/gm190_general.c index 7ea9dab5..b6aa5e9d 100644 --- a/components/molink/module/gm190/source/gm190_general.c +++ b/components/molink/module/gm190/source/gm190_general.c @@ -21,13 +21,12 @@ *********************************************************************************************************************** */ - #include #include #include "gm190_general.h" #define MO_LOG_TAG "gm190_general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef GM190_USING_GENERAL_OPS @@ -43,7 +42,7 @@ os_err_t gm190_at_test(mo_object_t *self) return at_parser_exec_cmd(parser, &resp, "AT"); } -os_err_t gm190_get_imei(mo_object_t * self,char * value, os_size_t len) +os_err_t gm190_get_imei(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_IMEI_LEN); @@ -52,18 +51,17 @@ os_err_t gm190_get_imei(mo_object_t * self,char * value, os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN")) { return OS_ERROR; } - if(at_resp_get_data_by_line(&resp, resp.line_counts - 1, "%s", value) <= 0) + if (at_resp_get_data_by_line(&resp, resp.line_counts - 1, "%s", value) <= 0) { ERROR("Get %s module imei failed."); return OS_ERROR; } - value[MO_IMEI_LEN] = '\0'; INFO("%s module imei:%s", self->name, value); @@ -71,7 +69,7 @@ os_err_t gm190_get_imei(mo_object_t * self,char * value, os_size_t len) return OS_EOK; } -os_err_t gm190_get_imsi(mo_object_t * self,char * value, os_size_t len) +os_err_t gm190_get_imsi(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_IMSI_LEN); @@ -80,12 +78,12 @@ os_err_t gm190_get_imsi(mo_object_t * self,char * value, os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CIMI")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CIMI")) { return OS_ERROR; } - if(at_resp_get_data_by_line(&resp, resp.line_counts - 1, "%s", value) <= 0) + if (at_resp_get_data_by_line(&resp, resp.line_counts - 1, "%s", value) <= 0) { ERROR("Get %s module imsi failed."); return OS_ERROR; @@ -93,12 +91,12 @@ os_err_t gm190_get_imsi(mo_object_t * self,char * value, os_size_t len) value[MO_IMSI_LEN] = '\0'; - DEBUG("%s module imsi:%s",self->name,value); + DEBUG("%s module imsi:%s", self->name, value); return OS_EOK; } -os_err_t gm190_get_iccid(mo_object_t * self,char * value, os_size_t len) +os_err_t gm190_get_iccid(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_ICCID_LEN); @@ -107,12 +105,12 @@ os_err_t gm190_get_iccid(mo_object_t * self,char * value, os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+ZGETICCID")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+ZGETICCID")) { return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+ZGETICCID:", "+ZGETICCID: %s", value) <= 0) + if (at_resp_get_data_by_kw(&resp, "+ZGETICCID:", "+ZGETICCID: %s", value) <= 0) { ERROR("Get %s module ccid failed.", self->name); return OS_ERROR; @@ -123,7 +121,7 @@ os_err_t gm190_get_iccid(mo_object_t * self,char * value, os_size_t len) return OS_EOK; } -os_err_t gm190_get_cfun(mo_object_t * self, os_uint8_t *fun_lvl) +os_err_t gm190_get_cfun(mo_object_t *self, os_uint8_t *fun_lvl) { at_parser_t *parser = &self->parser; @@ -136,7 +134,7 @@ os_err_t gm190_get_cfun(mo_object_t * self, os_uint8_t *fun_lvl) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CFUN:", "+CFUN: %hhu",fun_lvl) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CFUN:", "+CFUN: %hhu", fun_lvl) <= 0) { ERROR("Get %s module level of functionality failed.", self->name); return OS_ERROR; @@ -162,9 +160,7 @@ os_err_t gm190_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ve char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+GMR"); if (result != OS_EOK) @@ -179,7 +175,7 @@ os_err_t gm190_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ve } const char *source_line = at_resp_get_line(&resp, 1); - os_size_t line_length = strlen(source_line); + os_size_t line_length = strlen(source_line); char **dest_line = &version->ver_info[0]; @@ -197,6 +193,4 @@ os_err_t gm190_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ve return OS_EOK; } - -#endif /* GM190_USING_GENERAL_OPS */ - +#endif /* GM190_USING_GENERAL_OPS */ diff --git a/components/molink/module/gm190/source/gm190_ifconfig.c b/components/molink/module/gm190/source/gm190_ifconfig.c index fe802b2b..c0971243 100644 --- a/components/molink/module/gm190/source/gm190_ifconfig.c +++ b/components/molink/module/gm190/source/gm190_ifconfig.c @@ -30,7 +30,7 @@ #include #define MO_LOG_TAG "gm190_ifconfig.h" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef GM190_USING_IFCONFIG_OPS @@ -56,12 +56,12 @@ os_err_t gm190_ifconfig(mo_object_t *self) } os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t ber = 0; if (gm190_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; } os_kprintf("\r\nLIST AT MODULE INFORMATIONS\r\n"); @@ -88,10 +88,10 @@ os_err_t gm190_ifconfig(mo_object_t *self) os_err_t gm190_get_ipaddr(mo_object_t *self, char ip[]) { -#define GM190_IPADDR_MAX_STR_LEN (64) +#define GM190_IPADDR_MAX_STR_LEN (64) at_parser_t *parser = &self->parser; - os_int8_t ucid = -1; - os_int8_t len = -1; + os_int8_t ucid = -1; + os_int8_t len = -1; char ipaddr[GM190_IPADDR_MAX_STR_LEN + 1] = {0}; @@ -122,7 +122,7 @@ os_err_t gm190_get_ipaddr(mo_object_t *self, char ip[]) } else { - strncpy(ip, ipaddr,len); + strncpy(ip, ipaddr, len); DEBUG("IP address: %s", ip); } @@ -132,4 +132,3 @@ __exit: } #endif /* GM190_USING_IFCONFIG_OPS */ - diff --git a/components/molink/module/gm190/source/gm190_netconn.c b/components/molink/module/gm190/source/gm190_netconn.c index 88b4e5a0..9a40fe8d 100644 --- a/components/molink/module/gm190/source/gm190_netconn.c +++ b/components/molink/module/gm190/source/gm190_netconn.c @@ -29,7 +29,7 @@ #include #define MO_LOG_TAG "gm190_netconn" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define SEND_DATA_MAX_SIZE (1400) @@ -40,7 +40,7 @@ #endif #ifndef GM190_NETCONN_MQ_MSG_MAX -#define GM190_NETCONN_MQ_MSG_MAX (5) +#define GM190_NETCONN_MQ_MSG_MAX (5) #endif #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) @@ -52,9 +52,9 @@ #ifdef GM190_USING_NETCONN_OPS -static os_bool_t gm190_pdp_set(mo_object_t *module) +static os_bool_t gm190_pdp_set(mo_object_t *module) { - at_parser_t *parser = &module->parser; + at_parser_t *parser = &module->parser; char resp_buff[256] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * AT_RESP_TIMEOUT_DEF}; @@ -75,15 +75,14 @@ static os_bool_t gm190_pdp_set(mo_object_t *module) } return OS_TRUE; - } static os_bool_t gm190_check_zipcall(mo_object_t *module, os_int32_t connect_id) { - at_parser_t *parser = &module->parser; - char zipcall[30] = {0}; - char resp_buff[256] = {0}; - char zpas[30] = {0}; + at_parser_t *parser = &module->parser; + char zipcall[30] = {0}; + char resp_buff[256] = {0}; + char zpas[30] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * AT_RESP_TIMEOUT_DEF}; @@ -115,7 +114,7 @@ static os_bool_t gm190_check_zipcall(mo_object_t *module, os_int32_t connect_id) return OS_FALSE; } - if ('1' != zipcall[0] ) + if ('1' != zipcall[0]) { if (at_parser_exec_cmd(parser, &resp, "AT+ZIPCALL=1") != OS_EOK) { @@ -127,7 +126,6 @@ static os_bool_t gm190_check_zipcall(mo_object_t *module, os_int32_t connect_id) INFO("Check call ip ready!"); return OS_TRUE; - } static os_err_t gm190_lock(os_mutex_t *mutex) @@ -140,24 +138,24 @@ static os_err_t gm190_unlock(os_mutex_t *mutex) return os_mutex_recursive_unlock(mutex); } -static os_err_t gm190_check_state(mo_object_t *module,os_int32_t connect_id) +static os_err_t gm190_check_state(mo_object_t *module, os_int32_t connect_id) { - at_parser_t *parser = &module->parser; - char resp_buff[256] = {0}; - os_err_t result = OS_ERROR; - os_uint16_t recv_id = 0; - os_uint16_t recv_stat = 0; + at_parser_t *parser = &module->parser; + char resp_buff[256] = {0}; + os_err_t result = OS_ERROR; + os_uint16_t recv_id = 0; + os_uint16_t recv_stat = 0; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 6 * OS_TICK_PER_SECOND}; - if (at_parser_exec_cmd(parser, &resp, "AT+ZIPSTAT=%d",connect_id) != OS_EOK) + if (at_parser_exec_cmd(parser, &resp, "AT+ZIPSTAT=%d", connect_id) != OS_EOK) { - ERROR("Check connecd id %d state failed!",connect_id); + ERROR("Check connecd id %d state failed!", connect_id); result = OS_ERROR; goto __exit; } - if(at_resp_get_data_by_kw(&resp, "+ZIPSTAT:", "+ZIPSTAT: %d,%d",&recv_id, &recv_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+ZIPSTAT:", "+ZIPSTAT: %d,%d", &recv_id, &recv_stat) <= 0) { ERROR("Get %s module zipstat key word failed.", module->name); result = OS_ERROR; @@ -237,7 +235,6 @@ static mo_netconn_t *gm190_get_netconn_by_id(mo_object_t *module, os_int32_t con } return OS_NULL; - } os_err_t gm190_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) @@ -245,7 +242,7 @@ os_err_t gm190_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_gm190_t *gm190 = os_container_of(module, mo_gm190_t, parent); info->netconn_array = gm190->netconn; - info->netconn_nums = sizeof(gm190->netconn) / sizeof(gm190->netconn[0]); + info->netconn_nums = sizeof(gm190->netconn) / sizeof(gm190->netconn[0]); return OS_EOK; } @@ -263,9 +260,7 @@ mo_netconn_t *gm190_netconn_create(mo_object_t *module, mo_netconn_type_t type) return OS_NULL; } - netconn->mq = os_mq_create(GM190_NETCONN_MQ_NAME, - GM190_NETCONN_MQ_MSG_SIZE, - GM190_NETCONN_MQ_MSG_MAX); + netconn->mq = os_mq_create(GM190_NETCONN_MQ_NAME, GM190_NETCONN_MQ_MSG_SIZE, GM190_NETCONN_MQ_MSG_MAX); if (OS_NULL == netconn->mq) { ERROR("%s data queue create failed, no enough memory.", module->name); @@ -282,19 +277,16 @@ mo_netconn_t *gm190_netconn_create(mo_object_t *module, mo_netconn_type_t type) os_err_t gm190_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; - char zipstat[10] = {0}; - int i = 0; + os_err_t result = OS_ERROR; + char zipstat[10] = {0}; + int i = 0; mo_gm190_t *gm190 = os_container_of(module, mo_gm190_t, parent); gm190_lock(&gm190->netconn_lock); char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 10 * OS_TICK_PER_SECOND - }; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; switch (netconn->stat) { @@ -306,8 +298,8 @@ os_err_t gm190_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) if (result != OS_EOK) { ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + module->name, + (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); gm190_unlock(&gm190->netconn_lock); return result; @@ -316,7 +308,7 @@ os_err_t gm190_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) do { os_task_msleep(1000); - result = at_parser_exec_cmd(parser, &resp, "AT+ZIPSTAT=%d",netconn->connect_id); + result = at_parser_exec_cmd(parser, &resp, "AT+ZIPSTAT=%d", netconn->connect_id); if (result != OS_EOK) { @@ -332,8 +324,7 @@ os_err_t gm190_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) return result; } i++; - } - while('3' == zipstat[2]); + } while ('3' == zipstat[2]); if ('0' != zipstat[2]) { @@ -356,9 +347,9 @@ os_err_t gm190_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn id %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); @@ -367,14 +358,12 @@ os_err_t gm190_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) return OS_EOK; } - - os_err_t gm190_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port) { #define ZIP_CALL_TIMES (3) at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - mo_gm190_t * gm190 = os_container_of(module, mo_gm190_t, parent); + os_err_t result = OS_EOK; + mo_gm190_t *gm190 = os_container_of(module, mo_gm190_t, parent); gm190_lock(&gm190->netconn_lock); @@ -397,7 +386,7 @@ os_err_t gm190_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ad { ERROR("Wait module %s call ip !", module->name); i++; - if(i > ZIP_CALL_TIMES) + if (i > ZIP_CALL_TIMES) { ERROR("Wait module %s call ip failed !", module->name); break; @@ -410,23 +399,13 @@ os_err_t gm190_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ad { #ifdef GM190_USING_TCP case NETCONN_TYPE_TCP: - result = at_parser_exec_cmd(parser, - &resp, - "AT+ZIPOPEN=%d,0,%s,%d", - netconn->connect_id, - remote_ip, - port); + result = at_parser_exec_cmd(parser, &resp, "AT+ZIPOPEN=%d,0,%s,%d", netconn->connect_id, remote_ip, port); break; #endif #ifdef GM190_USING_UDP case NETCONN_TYPE_UDP: - result = at_parser_exec_cmd(parser, - &resp, - "AT+ZIPOPEN=%d,1,%s,%d", - netconn->connect_id, - remote_ip, - port); + result = at_parser_exec_cmd(parser, &resp, "AT+ZIPOPEN=%d,1,%s,%d", netconn->connect_id, remote_ip, port); break; #endif @@ -442,7 +421,7 @@ os_err_t gm190_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ad os_task_msleep(1000); - if (OS_EOK == gm190_check_state(module,netconn->connect_id)) + if (OS_EOK == gm190_check_state(module, netconn->connect_id)) { ERROR("Module %s netconn id %d connect fail", module->name, netconn->connect_id); result = OS_ERROR; @@ -454,7 +433,7 @@ __exit: { ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); } @@ -469,13 +448,13 @@ __exit: os_size_t gm190_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - int curr_size = 0; - os_uint32_t event = 0; - char at_cmd[30] = {0}; - int cmd_len = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + int curr_size = 0; + os_uint32_t event = 0; + char at_cmd[30] = {0}; + int cmd_len = 0; mo_gm190_t *gm190 = os_container_of(module, mo_gm190_t, parent); at_parser_exec_lock(parser); @@ -500,12 +479,12 @@ os_size_t gm190_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const c curr_size = SEND_DATA_MAX_SIZE; } - cmd_len = sprintf(at_cmd,"AT+ZIPSENDRAW=%d,%d\r\n", netconn->connect_id, curr_size); - if(cmd_len <= 0) + cmd_len = sprintf(at_cmd, "AT+ZIPSENDRAW=%d,%d\r\n", netconn->connect_id, curr_size); + if (cmd_len <= 0) { goto __exit; } - INFO("cmd_len = %d, strlen(at_cmd) = %d",cmd_len,strlen(at_cmd)); + INFO("cmd_len = %d, strlen(at_cmd) = %d", cmd_len, strlen(at_cmd)); if (at_parser_send(parser, at_cmd, cmd_len) <= 0) { @@ -583,9 +562,9 @@ static void urc_send_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; - mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_gm190_t *gm190 = os_container_of(module, mo_gm190_t, parent); + os_int32_t data_size = 0; + mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_gm190_t *gm190 = os_container_of(module, mo_gm190_t, parent); sscanf(data, "+ZIPSENDRAW: %d,%d", &connect_id, &data_size); @@ -603,13 +582,13 @@ static void urc_send_func(struct at_parser *parser, const char *data, os_size_t static void urc_recv_data_func(struct at_parser *parser, mo_netconn_t *netconn, os_size_t data_size) { - mo_object_t *module = os_container_of(parser, mo_object_t, parser); - os_int32_t timeout = data_size > 10 ? data_size : 10; + mo_object_t *module = os_container_of(parser, mo_object_t, parser); + os_int32_t timeout = data_size > 10 ? data_size : 10; INFO("Moudle %s netconn %d receive %d bytes data", parser->name, netconn->connect_id, data_size); - char *recv_buff = os_calloc(1, data_size); - char temp_buff[8] = {0}; + char *recv_buff = os_calloc(1, data_size); + char temp_buff[8] = {0}; if (recv_buff == OS_NULL) { /* read and clean the coming data */ @@ -659,7 +638,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t os_int32_t connect_id = atoi(&tmp_ch); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = gm190_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) @@ -702,7 +681,7 @@ static void urc_conn_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_gm190_t *gm190 = os_container_of(module, mo_gm190_t, parent); os_int32_t curr_connect = gm190->curr_connect; @@ -711,17 +690,17 @@ static void urc_conn_func(struct at_parser *parser, const char *data, os_size_t } static at_urc_t gs_urc_table[] = { - {.prefix = "+ZIPSENDRAW:", .suffix = "\r\n", .func = urc_send_func}, - {.prefix = "", .suffix = "+ZIPRECV:", .func = urc_recv_func}, - {.prefix = "CONNECT", .suffix = "\r\n", .func = urc_conn_func}, + {.prefix = "+ZIPSENDRAW:", .suffix = "\r\n", .func = urc_send_func}, + {.prefix = "", .suffix = "+ZIPRECV:", .func = urc_recv_func}, + {.prefix = "CONNECT", .suffix = "\r\n", .func = urc_conn_func}, }; static void gm190_network_init(mo_object_t *module) { - at_parser_t *parser = &module->parser; - os_int32_t enable_num = 0; - os_int32_t reg_state = 0; - os_err_t result = OS_ERROR; + at_parser_t *parser = &module->parser; + os_int32_t enable_num = 0; + os_int32_t reg_state = 0; + os_err_t result = OS_ERROR; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; @@ -731,7 +710,7 @@ static void gm190_network_init(mo_object_t *module) { goto __exit; } - if (at_resp_get_data_by_kw(&resp, "+CREG:", "+CREG: %d,%d", &enable_num , ®_state) < 0) + if (at_resp_get_data_by_kw(&resp, "+CREG:", "+CREG: %d,%d", &enable_num, ®_state) < 0) { result = OS_ERROR; goto __exit; @@ -748,14 +727,12 @@ static void gm190_network_init(mo_object_t *module) { result = OS_ERROR; goto __exit; - } if (at_parser_exec_cmd(parser, &resp, "AT+CFUN=0") != OS_EOK) { result = OS_ERROR; goto __exit; - } if (at_parser_exec_cmd(parser, &resp, "AT+CFUN=1") != OS_EOK) @@ -770,7 +747,7 @@ static void gm190_network_init(mo_object_t *module) goto __exit; } - if (at_resp_get_data_by_kw(&resp, "+CREG:", "+CREG: %d,%d", &enable_num , ®_state) < 0) + if (at_resp_get_data_by_kw(&resp, "+CREG:", "+CREG: %d,%d", &enable_num, ®_state) < 0) { goto __exit; } @@ -787,7 +764,7 @@ static void gm190_network_init(mo_object_t *module) } __exit: - if(result != OS_EOK) + if (result != OS_EOK) { WARN("GM190 network init failed"); } @@ -814,5 +791,3 @@ void gm190_netconn_init(mo_gm190_t *module) } #endif /* GM190_USING_NETCONN_OPS */ - - diff --git a/components/molink/module/gm190/source/gm190_netserv.c b/components/molink/module/gm190/source/gm190_netserv.c index e8920f8a..2dee42bc 100644 --- a/components/molink/module/gm190/source/gm190_netserv.c +++ b/components/molink/module/gm190/source/gm190_netserv.c @@ -29,12 +29,11 @@ #include #define MO_LOG_TAG "gm190_netserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define IP_SIZE 16 - #ifdef GM190_USING_NETSERV_OPS os_err_t gm190_set_attach(mo_object_t *self, os_uint8_t attach_stat) @@ -62,7 +61,7 @@ os_err_t gm190_get_attach(mo_object_t *self, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%d", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%d", attach_stat) <= 0) { ERROR("Get %s module attach state failed", self->name); return OS_ERROR; @@ -162,101 +161,98 @@ os_err_t gm190_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber) return OS_EOK; } -#define GET_GM190_RSSI(rxlev) (0 - (63 - rxlev + 48)) -#define GM190_MODULE_NET_TYPE 5 - -os_err_t gm190_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info) -{ - os_err_t ret = OS_EOK; - cell_info_t *cell_info = OS_NULL; - char *temp_buff = OS_NULL; - os_uint32_t cell_num = 0; - char earfcn[10]; - - at_parser_t *parser = &self->parser; - - if (parser == OS_NULL) - { - ERROR("GM190 ping: at parser is NULL."); - return OS_ERROR; - } - if(!onepos_cell_info) - { - ERROR("input param is error!"); - return OS_ERROR; - } - - at_resp_t resp = {.buff = os_calloc(1, 1024), - .buff_size = 1024, - .timeout = 50 * OS_TICK_PER_SECOND - }; - - if (OS_NULL == resp.buff) - { - ERROR("Calloc gm190 cell info response memory failed!"); - ret = OS_ENOMEM; - goto __exit; - } - - /* neighbor cell */ - if (at_parser_exec_cmd(parser, &resp, "AT+ZCDS?") < 0) - { - ret = OS_ERROR; - ERROR("AT cmd exec fail: AT+ZCDS?\n"); - goto __exit; - } - DEBUG("resp->line_counts : %d\r\n", resp.line_counts); - - cell_info = os_calloc(1, sizeof(cell_info_t)); - if(NULL == cell_info) - { - ERROR("malloc cell_info is null"); - ret = OS_ENOMEM; - return ret; - } - - INFO(" MCC MNC CID LAC RSSI\n"); - INFO(" ------------ ------------ ------------ ------------ ----\n"); - - /* main cell */ - - temp_buff = (char*)at_resp_get_line(&resp, 1); - if(strlen(temp_buff) > 25) - { - sscanf(temp_buff, - "+ZCDS:%[^,],%u,%u,%x,%x,%d,%*[^\r]", - earfcn, - &cell_info[cell_num].mcc, - &cell_info[cell_num].mnc, +#define GET_GM190_RSSI(rxlev) (0 - (63 - rxlev + 48)) +#define GM190_MODULE_NET_TYPE 5 + +os_err_t gm190_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info) +{ + os_err_t ret = OS_EOK; + cell_info_t *cell_info = OS_NULL; + char *temp_buff = OS_NULL; + os_uint32_t cell_num = 0; + char earfcn[10]; + + at_parser_t *parser = &self->parser; + + if (parser == OS_NULL) + { + ERROR("GM190 ping: at parser is NULL."); + return OS_ERROR; + } + if (!onepos_cell_info) + { + ERROR("input param is error!"); + return OS_ERROR; + } + + at_resp_t resp = {.buff = os_calloc(1, 1024), .buff_size = 1024, .timeout = 50 * OS_TICK_PER_SECOND}; + + if (OS_NULL == resp.buff) + { + ERROR("Calloc gm190 cell info response memory failed!"); + ret = OS_ENOMEM; + goto __exit; + } + + /* neighbor cell */ + if (at_parser_exec_cmd(parser, &resp, "AT+ZCDS?") < 0) + { + ret = OS_ERROR; + ERROR("AT cmd exec fail: AT+ZCDS?\n"); + goto __exit; + } + DEBUG("resp->line_counts : %d\r\n", resp.line_counts); + + cell_info = os_calloc(1, sizeof(cell_info_t)); + if (NULL == cell_info) + { + ERROR("malloc cell_info is null"); + ret = OS_ENOMEM; + return ret; + } + + INFO(" MCC MNC CID LAC RSSI\n"); + INFO(" ------------ ------------ ------------ ------------ ----\n"); + + /* main cell */ + + temp_buff = (char *)at_resp_get_line(&resp, 1); + if (strlen(temp_buff) > 25) + { + sscanf(temp_buff, + "+ZCDS:%[^,],%u,%u,%x,%x,%d,%*[^\r]", + earfcn, + &cell_info[cell_num].mcc, + &cell_info[cell_num].mnc, &cell_info[cell_num].lac, &cell_info[cell_num].cid, - &cell_info[cell_num].ss - ); - - INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", - cell_info[cell_num].mcc, cell_info[cell_num].mnc, cell_info[cell_num].cid, - cell_info[cell_num].lac, cell_info[cell_num].ss); - - } - else - { - cell_num --; - } - INFO(" ------------ ------------ ------------ ------------ ----\n"); - - onepos_cell_info->cell_num = ++cell_num; - onepos_cell_info->cell_info = cell_info; - onepos_cell_info->net_type = GM190_MODULE_NET_TYPE; - -__exit: - - if (resp.buff != OS_NULL) - { - os_free(resp.buff); - } - - return ret; -} + &cell_info[cell_num].ss); + + INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", + cell_info[cell_num].mcc, + cell_info[cell_num].mnc, + cell_info[cell_num].cid, + cell_info[cell_num].lac, + cell_info[cell_num].ss); + } + else + { + cell_num--; + } + INFO(" ------------ ------------ ------------ ------------ ----\n"); -#endif /* gm190_USING_NETSERV_OPS */ + onepos_cell_info->cell_num = ++cell_num; + onepos_cell_info->cell_info = cell_info; + onepos_cell_info->net_type = GM190_MODULE_NET_TYPE; + +__exit: + if (resp.buff != OS_NULL) + { + os_free(resp.buff); + } + + return ret; +} + +#endif /* gm190_USING_NETSERV_OPS */ diff --git a/components/molink/module/gm510/include/gm510.h b/components/molink/module/gm510/include/gm510.h index 6e92c8a1..44e95e60 100644 --- a/components/molink/module/gm510/include/gm510.h +++ b/components/molink/module/gm510/include/gm510.h @@ -69,16 +69,16 @@ typedef struct mo_gm510 mo_object_t parent; #ifdef GM510_USING_NETCONN_OPS mo_netconn_t netconn[GM510_NETCONN_NUM]; - - os_int32_t curr_connect; + + os_int32_t curr_connect; os_event_t netconn_evt; os_mutex_t netconn_lock; - void *netconn_data; + void *netconn_data; #endif /* GM510_USING_NETCONN_OPS */ } mo_gm510_t; mo_object_t *module_gm510_create(const char *name, void *parser_config); -os_err_t module_gm510_destroy(mo_object_t *self); +os_err_t module_gm510_destroy(mo_object_t *self); #endif /* MOLINK_USING_GM510 */ @@ -87,4 +87,3 @@ os_err_t module_gm510_destroy(mo_object_t *self); #endif /* __cplusplus */ #endif /* __GM510_H__ */ - diff --git a/components/molink/module/gm510/include/gm510_general.h b/components/molink/module/gm510/include/gm510_general.h index 4e99e157..0cc84558 100644 --- a/components/molink/module/gm510/include/gm510_general.h +++ b/components/molink/module/gm510/include/gm510_general.h @@ -21,17 +21,16 @@ *********************************************************************************************************************** */ - -#ifndef __GM510_GENERAL_H__ -#define __GM510_GENERAL_H__ +#ifndef __GM510_GENERAL_H__ +#define __GM510_GENERAL_H__ #include "mo_general.h" -#ifdef __cplusplus -extern "C" { +#ifdef __cplusplus +extern "C" { #endif -#ifdef GM510_USING_GENERAL_OPS +#ifdef GM510_USING_GENERAL_OPS os_err_t gm510_at_test(mo_object_t *self); os_err_t gm510_get_imei(mo_object_t *self, char *value, os_size_t len); @@ -41,11 +40,10 @@ os_err_t gm510_get_cfun(mo_object_t *self, os_uint8_t *fun_lvl); os_err_t gm510_set_cfun(mo_object_t *self, os_uint8_t fun_lvl); os_err_t gm510_get_firmware_version(mo_object_t *self, mo_firmware_version_t *version); -#endif /* GM510_USING_GENERAL_OPS */ +#endif /* GM510_USING_GENERAL_OPS */ -#ifdef __cplusplus +#ifdef __cplusplus } #endif -#endif /* __GM510_GENERAL_H__ */ - +#endif /* __GM510_GENERAL_H__ */ diff --git a/components/molink/module/gm510/include/gm510_ifconfig.h b/components/molink/module/gm510/include/gm510_ifconfig.h index 6fb5fe81..cf295e09 100644 --- a/components/molink/module/gm510/include/gm510_ifconfig.h +++ b/components/molink/module/gm510/include/gm510_ifconfig.h @@ -41,5 +41,3 @@ os_err_t gm510_get_ipaddr(mo_object_t *self, char ip[]); #endif /* __cplusplus */ #endif /* __GM510_IFCONFIG_H__ */ - - diff --git a/components/molink/module/gm510/include/gm510_netconn.h b/components/molink/module/gm510/include/gm510_netconn.h index 6ccb8eca..a460bd86 100644 --- a/components/molink/module/gm510/include/gm510_netconn.h +++ b/components/molink/module/gm510/include/gm510_netconn.h @@ -33,12 +33,12 @@ extern "C" { #ifdef GM510_USING_NETCONN_OPS mo_netconn_t *gm510_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t gm510_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t gm510_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); -os_err_t gm510_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t gm510_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t gm510_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t gm510_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t gm510_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t gm510_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef GM510_USING_DNS -os_err_t gm510_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t gm510_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* GM510_USING_NETCONN_OPS */ @@ -48,4 +48,3 @@ os_err_t gm510_netconn_gethostbyname(mo_object_t *self, const char *domain_ #endif /* __cplusplus */ #endif /* __M5310A_NETCONN_H__ */ - diff --git a/components/molink/module/gm510/include/gm510_netserv.h b/components/molink/module/gm510/include/gm510_netserv.h index 84710389..512c121f 100644 --- a/components/molink/module/gm510/include/gm510_netserv.h +++ b/components/molink/module/gm510/include/gm510_netserv.h @@ -47,4 +47,3 @@ os_err_t gm510_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber); #endif /* __cplusplus */ #endif /* __GM510_NETSERV_H__ */ - diff --git a/components/molink/module/gm510/source/gm510.c b/components/molink/module/gm510/source/gm510.c index 243df92e..b257a6e1 100644 --- a/components/molink/module/gm510/source/gm510.c +++ b/components/molink/module/gm510/source/gm510.c @@ -1,31 +1,31 @@ - /** - *********************************************************************************************************************** - * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * @file gm510.c - * - * @brief gm510.c module api - * - * @revision - * Date Author Notes - * 2020-11-13 OneOS Team First Version - *********************************************************************************************************************** - */ +/** +*********************************************************************************************************************** +* Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. +* +* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +* specific language governing permissions and limitations under the License. +* +* @file gm510.c +* +* @brief gm510.c module api +* +* @revision +* Date Author Notes +* 2020-11-13 OneOS Team First Version +*********************************************************************************************************************** +*/ #include "gm510.h" #include #define MO_LOG_TAG "gm510" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_GM510 @@ -34,32 +34,32 @@ #ifdef GM510_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = gm510_at_test, - .get_imei = gm510_get_imei, - .get_imsi = gm510_get_imsi, + .at_test = gm510_at_test, + .get_imei = gm510_get_imei, + .get_imsi = gm510_get_imsi, .get_iccid = gm510_get_iccid, - .get_cfun = gm510_get_cfun, - .set_cfun = gm510_set_cfun, + .get_cfun = gm510_get_cfun, + .set_cfun = gm510_set_cfun, .get_firmware_version = gm510_get_firmware_version, }; #endif /* GM510_USING_GENERAL_OPS */ #ifdef GM510_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = gm510_set_attach, - .get_attach = gm510_get_attach, - .set_reg = gm510_set_reg, - .get_reg = gm510_get_reg, - .set_cgact = gm510_set_cgact, - .get_cgact = gm510_get_cgact, - .get_csq = gm510_get_csq, + .set_attach = gm510_set_attach, + .get_attach = gm510_get_attach, + .set_reg = gm510_set_reg, + .get_reg = gm510_get_reg, + .set_cgact = gm510_set_cgact, + .get_cgact = gm510_get_cgact, + .get_csq = gm510_get_csq, }; #endif /* GM510_USING_NETSERV_OPS */ #ifdef GM510_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = gm510_ifconfig, - .get_ipaddr = gm510_get_ipaddr, + .ifconfig = gm510_ifconfig, + .get_ipaddr = gm510_get_ipaddr, }; #endif /* GM510_USING_IFCONFIG_OPS */ @@ -67,19 +67,17 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void gm510_netconn_init(mo_gm510_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = gm510_netconn_create, - .destroy = gm510_netconn_destroy, - .get_info = gm510_netconn_get_info, - .connect = gm510_netconn_connect, - .send = gm510_netconn_send, + .create = gm510_netconn_create, + .destroy = gm510_netconn_destroy, + .get_info = gm510_netconn_get_info, + .connect = gm510_netconn_connect, + .send = gm510_netconn_send, #ifdef GM510_USING_DNS .gethostbyname = gm510_netconn_gethostbyname, #endif }; #endif /* GM510_USING_NETCONN_OPS */ - - static os_err_t gm510_at_init(mo_object_t *self) { at_parser_t *parser = &self->parser; @@ -93,9 +91,7 @@ static os_err_t gm510_at_init(mo_object_t *self) char resp_buff[32] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; return at_parser_exec_cmd(parser, &resp, "ATE0"); } @@ -108,7 +104,7 @@ mo_object_t *module_gm510_create(const char *name, void *parser_config) ERROR("Create %s module instance failed, no enough memory.", name); return OS_NULL; } - + os_task_msleep(5000); /* make sure gm510 power on and be ready */ os_err_t result = mo_object_init(&(module->parent), name, parser_config); @@ -131,11 +127,11 @@ mo_object_t *module_gm510_create(const char *name, void *parser_config) #ifdef GM510_USING_NETSERV_OPS module->parent.ops_table[MODULE_OPS_NETSERV] = &gs_netserv_ops; #endif /* GM510_USING_NETSERV_OPS */ - + #ifdef GM510_USING_IFCONFIG_OPS module->parent.ops_table[MODULE_OPS_IFCONFIG] = &gs_ifconfig_ops; #endif /* GM510_USING_IFCONFIG_OPS */ - + #ifdef GM510_USING_NETCONN_OPS module->parent.ops_table[MODULE_OPS_NETCONN] = &gs_netconn_ops; @@ -171,13 +167,13 @@ os_err_t module_gm510_destroy(mo_object_t *self) mo_gm510_t *module = os_container_of(self, mo_gm510_t, parent); mo_object_deinit(self); - + #ifdef GM510_USING_NETCONN_OPS os_event_deinit(&module->netconn_evt); os_mutex_deinit(&module->netconn_lock); - + #endif /* GM510_USING_NETCONN_OPS */ os_free(module); @@ -203,7 +199,7 @@ int gm510_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = GM510_NAME, + mo_parser_config_t parser_config = {.parser_name = GM510_NAME, .parser_device = device, .recv_buff_len = GM510_RECV_BUFF_LEN}; @@ -217,8 +213,7 @@ int gm510_auto_create(void) INFO("Auto create %s module object success!", GM510_NAME); return OS_EOK; } -OS_CMPOENT_INIT(gm510_auto_create,OS_INIT_SUBLEVEL_MIDDLE); +OS_CMPOENT_INIT(gm510_auto_create, OS_INIT_SUBLEVEL_MIDDLE); #endif /* GM510_AUTO_CREATE */ #endif /* MOLINK_USING_GM510 */ - diff --git a/components/molink/module/gm510/source/gm510_general.c b/components/molink/module/gm510/source/gm510_general.c index 5cee595c..bb4b2a40 100644 --- a/components/molink/module/gm510/source/gm510_general.c +++ b/components/molink/module/gm510/source/gm510_general.c @@ -21,13 +21,12 @@ *********************************************************************************************************************** */ - #include #include #include "gm510_general.h" #define MO_LOG_TAG "gm510_general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef GM510_USING_GENERAL_OPS @@ -43,7 +42,7 @@ os_err_t gm510_at_test(mo_object_t *self) return at_parser_exec_cmd(parser, &resp, "AT"); } -os_err_t gm510_get_imei(mo_object_t * self,char * value, os_size_t len) +os_err_t gm510_get_imei(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_IMEI_LEN); @@ -52,18 +51,17 @@ os_err_t gm510_get_imei(mo_object_t * self,char * value, os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN")) { return OS_ERROR; } - if(at_resp_get_data_by_line(&resp, 1, "%s", value) <= 0) + if (at_resp_get_data_by_line(&resp, 1, "%s", value) <= 0) { ERROR("Get %s module imei failed."); return OS_ERROR; } - value[MO_IMEI_LEN] = '\0'; INFO("%s module imei:%s", self->name, value); @@ -71,7 +69,7 @@ os_err_t gm510_get_imei(mo_object_t * self,char * value, os_size_t len) return OS_EOK; } -os_err_t gm510_get_imsi(mo_object_t * self,char * value, os_size_t len) +os_err_t gm510_get_imsi(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_IMSI_LEN); @@ -80,12 +78,12 @@ os_err_t gm510_get_imsi(mo_object_t * self,char * value, os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * AT_RESP_TIMEOUT_DEF}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CIMI")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CIMI")) { return OS_ERROR; } - if(at_resp_get_data_by_line(&resp, 1, "%s", value) <= 0) + if (at_resp_get_data_by_line(&resp, 1, "%s", value) <= 0) { ERROR("Get %s module imsi failed."); return OS_ERROR; @@ -93,12 +91,12 @@ os_err_t gm510_get_imsi(mo_object_t * self,char * value, os_size_t len) value[MO_IMSI_LEN] = '\0'; - DEBUG("%s module imsi:%s",self->name,value); + DEBUG("%s module imsi:%s", self->name, value); return OS_EOK; } -os_err_t gm510_get_iccid(mo_object_t * self,char * value, os_size_t len) +os_err_t gm510_get_iccid(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_ICCID_LEN); @@ -107,12 +105,12 @@ os_err_t gm510_get_iccid(mo_object_t * self,char * value, os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+ZGETICCID")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+ZGETICCID")) { return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+ZGETICCID:", "+ZGETICCID: %s", value) <= 0) + if (at_resp_get_data_by_kw(&resp, "+ZGETICCID:", "+ZGETICCID: %s", value) <= 0) { ERROR("Get %s module ccid failed.", self->parser); return OS_ERROR; @@ -123,7 +121,7 @@ os_err_t gm510_get_iccid(mo_object_t * self,char * value, os_size_t len) return OS_EOK; } -os_err_t gm510_get_cfun(mo_object_t * self, os_uint8_t *fun_lvl) +os_err_t gm510_get_cfun(mo_object_t *self, os_uint8_t *fun_lvl) { at_parser_t *parser = &self->parser; @@ -136,7 +134,7 @@ os_err_t gm510_get_cfun(mo_object_t * self, os_uint8_t *fun_lvl) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CFUN:", "+CFUN: %hhu",fun_lvl) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CFUN:", "+CFUN: %hhu", fun_lvl) <= 0) { ERROR("Get %s module level of functionality failed.", self->name); return OS_ERROR; @@ -162,9 +160,7 @@ os_err_t gm510_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ve char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+GMR"); if (result != OS_EOK) @@ -179,7 +175,7 @@ os_err_t gm510_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ve } const char *source_line = at_resp_get_line(&resp, 1); - os_size_t line_length = strlen(source_line); + os_size_t line_length = strlen(source_line); char **dest_line = &version->ver_info[0]; @@ -197,6 +193,4 @@ os_err_t gm510_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ve return OS_EOK; } - -#endif /* GM510_USING_GENERAL_OPS */ - +#endif /* GM510_USING_GENERAL_OPS */ diff --git a/components/molink/module/gm510/source/gm510_ifconfig.c b/components/molink/module/gm510/source/gm510_ifconfig.c index b1b9c19c..4610c8e1 100644 --- a/components/molink/module/gm510/source/gm510_ifconfig.c +++ b/components/molink/module/gm510/source/gm510_ifconfig.c @@ -30,7 +30,7 @@ #include #define MO_LOG_TAG "gm510_ifconfig" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef GM510_USING_IFCONFIG_OPS @@ -56,12 +56,12 @@ os_err_t gm510_ifconfig(mo_object_t *self) } os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t ber = 0; if (gm510_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; } os_kprintf("\r\nLIST AT MODULE INFORMATIONS\r\n"); @@ -89,9 +89,9 @@ os_err_t gm510_ifconfig(mo_object_t *self) os_err_t gm510_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t ucid = -1; - os_int8_t len = -1; - int i = 1; + os_int8_t ucid = -1; + os_int8_t len = -1; + int i = 1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[512] = {0}; @@ -108,7 +108,7 @@ os_err_t gm510_get_ipaddr(mo_object_t *self, char ip[]) /* Response for ex: +CGPADDR:0,100.113.120.235 */ do { - if (at_resp_get_data_by_line(&resp, i , "+CGPADDR:%d, \"%[^\"]", &ucid, ipaddr) <= 0) + if (at_resp_get_data_by_line(&resp, i, "+CGPADDR:%d, \"%[^\"]", &ucid, ipaddr) <= 0) { ERROR("Get ip address: parse resp fail."); result = OS_ERROR; @@ -116,8 +116,7 @@ os_err_t gm510_get_ipaddr(mo_object_t *self, char ip[]) } i = i + 1; len = strlen(ipaddr); - } - while(len == 0); + } while (len == 0); if ((len < IPADDR_MIN_STR_LEN) || (len > IPADDR_MAX_STR_LEN)) { @@ -137,4 +136,3 @@ __exit: } #endif /* GM510_USING_IFCONFIG_OPS */ - diff --git a/components/molink/module/gm510/source/gm510_netconn.c b/components/molink/module/gm510/source/gm510_netconn.c index ba099f30..2e38a6dc 100644 --- a/components/molink/module/gm510/source/gm510_netconn.c +++ b/components/molink/module/gm510/source/gm510_netconn.c @@ -29,10 +29,10 @@ #include #define MO_LOG_TAG "gm510_netconn" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" -#define SEND_DATA_MAX_SIZE (1400) +#define SEND_DATA_MAX_SIZE (1400) #define GM510_NETCONN_MQ_NAME "gm510_nc_mq" #ifndef GM510_NETCONN_MQ_MSG_SIZE @@ -40,28 +40,26 @@ #endif #ifndef GM510_NETCONN_MQ_MSG_MAX -#define GM510_NETCONN_MQ_MSG_MAX (5) +#define GM510_NETCONN_MQ_MSG_MAX (5) #endif #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) -#define GM510_EVENT_CONN_OK (1L << 0) -#define GM510_EVENT_SEND_OK (1L << 1) -#define GM510_EVENT_RECV_OK (1L << 2) -#define GM510_EVENT_CLOSE_OK (1L << 3) -#define GM510_EVENT_CONN_FAIL (1L << 4) -#define GM510_EVENT_SEND_FAIL (1L << 5) -#define GM510_EVENT_DOMAIN_OK (1L << 6) -#define GM510_EVENT_STAT_OK (1L << 7) -#define GM510_EVENT_STAT_FAIL (1L << 8) - - +#define GM510_EVENT_CONN_OK (1L << 0) +#define GM510_EVENT_SEND_OK (1L << 1) +#define GM510_EVENT_RECV_OK (1L << 2) +#define GM510_EVENT_CLOSE_OK (1L << 3) +#define GM510_EVENT_CONN_FAIL (1L << 4) +#define GM510_EVENT_SEND_FAIL (1L << 5) +#define GM510_EVENT_DOMAIN_OK (1L << 6) +#define GM510_EVENT_STAT_OK (1L << 7) +#define GM510_EVENT_STAT_FAIL (1L << 8) #ifdef GM510_USING_NETCONN_OPS -static os_bool_t gm510_pdp_set(mo_object_t *module) +static os_bool_t gm510_pdp_set(mo_object_t *module) { - at_parser_t *parser = &module->parser; + at_parser_t *parser = &module->parser; char resp_buff[256] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * AT_RESP_TIMEOUT_DEF}; @@ -86,10 +84,10 @@ static os_bool_t gm510_pdp_set(mo_object_t *module) static os_bool_t gm510_check_zipcall(mo_object_t *module) { - at_parser_t *parser = &module->parser; - char zipcall[30] = {0}; - char resp_buff[256] = {0}; - char zpas[30] = {0}; + at_parser_t *parser = &module->parser; + char zipcall[30] = {0}; + char resp_buff[256] = {0}; + char zpas[30] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * AT_RESP_TIMEOUT_DEF}; if (at_parser_exec_cmd(parser, &resp, "AT+ZPAS?") != OS_EOK) @@ -108,7 +106,6 @@ static os_bool_t gm510_check_zipcall(mo_object_t *module) return OS_FALSE; } - if (at_parser_exec_cmd(parser, &resp, "AT+ZIPCALL?") != OS_EOK) { ERROR("Get ip call failed"); @@ -121,9 +118,9 @@ static os_bool_t gm510_check_zipcall(mo_object_t *module) return OS_FALSE; } - if ('1' != zipcall[0] ) + if ('1' != zipcall[0]) { - if (at_parser_exec_cmd(parser, &resp, "AT+ZIPCALL=1") != OS_EOK) + if (at_parser_exec_cmd(parser, &resp, "AT+ZIPCALL=1") != OS_EOK) { ERROR("Get ip call not ready"); return OS_FALSE; @@ -145,17 +142,17 @@ static os_err_t gm510_unlock(os_mutex_t *mutex) return os_mutex_recursive_unlock(mutex); } -static os_err_t gm510_check_state(mo_object_t *module,os_int32_t connect_id) +static os_err_t gm510_check_state(mo_object_t *module, os_int32_t connect_id) { - at_parser_t *parser = &module->parser; - char resp_buff[256] = {0}; - char zipstat[30] = {0}; + at_parser_t *parser = &module->parser; + char resp_buff[256] = {0}; + char zipstat[30] = {0}; - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 6 * OS_TICK_PER_SECOND}; - result = at_parser_exec_cmd(parser, &resp, "AT+ZIPSTAT=%d",connect_id); + result = at_parser_exec_cmd(parser, &resp, "AT+ZIPSTAT=%d", connect_id); if (result != OS_EOK) { @@ -169,7 +166,6 @@ static os_err_t gm510_check_state(mo_object_t *module,os_int32_t connect_id) goto __exit; } - if ('1' == zipstat[2]) { result = OS_ERROR; @@ -230,7 +226,6 @@ static mo_netconn_t *gm510_get_netconn_by_id(mo_object_t *module, os_int32_t con } return OS_NULL; - } os_err_t gm510_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) @@ -238,7 +233,7 @@ os_err_t gm510_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_gm510_t *gm510 = os_container_of(module, mo_gm510_t, parent); info->netconn_array = gm510->netconn; - info->netconn_nums = sizeof(gm510->netconn) / sizeof(gm510->netconn[0]); + info->netconn_nums = sizeof(gm510->netconn) / sizeof(gm510->netconn[0]); return OS_EOK; } @@ -254,9 +249,7 @@ mo_netconn_t *gm510_netconn_create(mo_object_t *module, mo_netconn_type_t type) gm510_unlock(&gm510->netconn_lock); return OS_NULL; } - netconn->mq = os_mq_create(GM510_NETCONN_MQ_NAME, - GM510_NETCONN_MQ_MSG_SIZE, - GM510_NETCONN_MQ_MSG_MAX); + netconn->mq = os_mq_create(GM510_NETCONN_MQ_NAME, GM510_NETCONN_MQ_MSG_SIZE, GM510_NETCONN_MQ_MSG_MAX); if (netconn->stat != NETCONN_STAT_NULL) { @@ -272,18 +265,15 @@ mo_netconn_t *gm510_netconn_create(mo_object_t *module, mo_netconn_type_t type) os_err_t gm510_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; - char zipstat[10] = {0}; + at_parser_t *parser = &module->parser; + os_err_t result = OS_ERROR; + char zipstat[10] = {0}; - mo_gm510_t * gm510 = os_container_of(module, mo_gm510_t, parent); + mo_gm510_t *gm510 = os_container_of(module, mo_gm510_t, parent); gm510_lock(&gm510->netconn_lock); char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 10 * OS_TICK_PER_SECOND - }; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; switch (netconn->stat) { @@ -294,24 +284,24 @@ os_err_t gm510_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) if (result != OS_EOK) { ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + module->name, + (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); gm510_unlock(&gm510->netconn_lock); return result; } if (at_resp_get_data_by_kw(&resp, "+ZIPSTAT:", "+ZIPSTAT: %s", &zipstat) <= 0) - { - result = OS_ERROR; + { + result = OS_ERROR; gm510_unlock(&gm510->netconn_lock); - return result; - } + return result; + } - if ('0' != zipstat[2]) - { + if ('0' != zipstat[2]) + { result = OS_ERROR; gm510_unlock(&gm510->netconn_lock); - return result; - } + return result; + } break; default: @@ -327,9 +317,9 @@ os_err_t gm510_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn id %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); @@ -338,15 +328,13 @@ os_err_t gm510_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) return OS_EOK; } - - os_err_t gm510_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port) { #define ZIP_CALL_TIMES (6) - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - char zipstat[10] = {0}; - mo_gm510_t * gm510 = os_container_of(module, mo_gm510_t, parent); + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + char zipstat[10] = {0}; + mo_gm510_t *gm510 = os_container_of(module, mo_gm510_t, parent); gm510_lock(&gm510->netconn_lock); char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -371,13 +359,13 @@ os_err_t gm510_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ad { ERROR("Wait module %s call ip !", module->name); i++; - if(i > ZIP_CALL_TIMES) + if (i > ZIP_CALL_TIMES) { ERROR("Wait module %s call ip failed !", module->name); break; } - os_task_msleep(5000); + os_task_msleep(5000); } } @@ -385,23 +373,13 @@ os_err_t gm510_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ad { #ifdef GM510_USING_TCP case NETCONN_TYPE_TCP: - result = at_parser_exec_cmd(parser, - &resp, - "AT+ZIPOPEN=%d,0,%s,%d", - netconn->connect_id, - remote_ip, - port); + result = at_parser_exec_cmd(parser, &resp, "AT+ZIPOPEN=%d,0,%s,%d", netconn->connect_id, remote_ip, port); break; #endif #ifdef GM510_USING_UDP case NETCONN_TYPE_UDP: - result = at_parser_exec_cmd(parser, - &resp, - "AT+ZIPOPEN=%d,1,%s,%d", - netconn->connect_id, - remote_ip, - port); + result = at_parser_exec_cmd(parser, &resp, "AT+ZIPOPEN=%d,1,%s,%d", netconn->connect_id, remote_ip, port); break; #endif @@ -418,7 +396,7 @@ os_err_t gm510_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ad do { os_task_msleep(1000); - result = at_parser_exec_cmd(parser, &resp, "AT+ZIPSTAT=%d",netconn->connect_id); + result = at_parser_exec_cmd(parser, &resp, "AT+ZIPSTAT=%d", netconn->connect_id); if (result != OS_EOK) { @@ -431,13 +409,12 @@ os_err_t gm510_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ad result = OS_ERROR; goto __exit; } - } - while('3' == zipstat[2]); + } while ('3' == zipstat[2]); if ('1' != zipstat[2]) { result = OS_ERROR; - goto __exit; + goto __exit; } __exit: @@ -445,7 +422,7 @@ __exit: { ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); } @@ -460,11 +437,11 @@ __exit: os_size_t gm510_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t curr_size = 0; - os_uint32_t event = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t curr_size = 0; + os_uint32_t event = 0; mo_gm510_t *gm510 = os_container_of(module, mo_gm510_t, parent); at_parser_exec_lock(parser); @@ -473,10 +450,7 @@ os_size_t gm510_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const c char resp_buff[128] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 5 * OS_TICK_PER_SECOND - }; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; at_parser_set_end_mark(parser, ">", 1); @@ -565,10 +539,10 @@ os_err_t gm510_netconn_gethostbyname(mo_object_t *self, const char *domain_name, OS_ASSERT(OS_NULL != domain_name); OS_ASSERT(OS_NULL != addr); - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; - char resp_buff[128] = {0}; + char resp_buff[128] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 6 * OS_TICK_PER_SECOND}; @@ -576,7 +550,7 @@ os_err_t gm510_netconn_gethostbyname(mo_object_t *self, const char *domain_name, gm510->netconn_data = addr; - if(OS_FALSE == gm510_check_zipcall(self)) + if (OS_FALSE == gm510_check_zipcall(self)) { result = OS_ERROR; goto __exit; @@ -613,9 +587,9 @@ static void urc_send_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; - mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_gm510_t *gm510 = os_container_of(module, mo_gm510_t, parent); + os_int32_t data_size = 0; + mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_gm510_t *gm510 = os_container_of(module, mo_gm510_t, parent); sscanf(data, "+ZIPSENDRAW: %d,%d", &connect_id, &data_size); @@ -631,16 +605,15 @@ static void urc_send_func(struct at_parser *parser, const char *data, os_size_t } } - static void urc_recv_data_func(struct at_parser *parser, mo_netconn_t *netconn, os_size_t data_size) { - mo_object_t *module = os_container_of(parser, mo_object_t, parser); - os_int32_t timeout = data_size > 10 ? data_size : 10; + mo_object_t *module = os_container_of(parser, mo_object_t, parser); + os_int32_t timeout = data_size > 10 ? data_size : 10; INFO("Moudle %s netconn %d receive %d bytes data", parser->name, netconn->connect_id, data_size); - char *recv_buff = os_calloc(1, data_size); - char temp_buff[8] = {0}; + char *recv_buff = os_calloc(1, data_size); + char temp_buff[8] = {0}; if (recv_buff == OS_NULL) { /* read and clean the coming data */ @@ -690,7 +663,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t os_int32_t connect_id = atoi(&tmp_ch); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = gm510_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) @@ -728,16 +701,16 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t return; } static at_urc_t gs_urc_table[] = { - {.prefix = "+ZIPSENDRAW:", .suffix = "\r\n", .func = urc_send_func}, - {.prefix = "", .suffix = "+ZIPRECV:", .func = urc_recv_func}, + {.prefix = "+ZIPSENDRAW:", .suffix = "\r\n", .func = urc_send_func}, + {.prefix = "", .suffix = "+ZIPRECV:", .func = urc_recv_func}, }; static void gm510_network_init(mo_object_t *module) { - at_parser_t *parser = &module->parser; - os_int32_t enable_num = 0; - os_int32_t reg_state = 0; - os_err_t result = OS_ERROR; + at_parser_t *parser = &module->parser; + os_int32_t enable_num = 0; + os_int32_t reg_state = 0; + os_err_t result = OS_ERROR; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; @@ -747,7 +720,7 @@ static void gm510_network_init(mo_object_t *module) { goto __exit; } - if (at_resp_get_data_by_kw(&resp, "+CREG:", "+CREG: %d,%d", &enable_num , ®_state) < 0) + if (at_resp_get_data_by_kw(&resp, "+CREG:", "+CREG: %d,%d", &enable_num, ®_state) < 0) { result = OS_ERROR; goto __exit; @@ -764,14 +737,12 @@ static void gm510_network_init(mo_object_t *module) { result = OS_ERROR; goto __exit; - } if (at_parser_exec_cmd(parser, &resp, "AT+CFUN=0") != OS_EOK) { result = OS_ERROR; goto __exit; - } if (at_parser_exec_cmd(parser, &resp, "AT+CFUN=1") != OS_EOK) @@ -785,7 +756,7 @@ static void gm510_network_init(mo_object_t *module) { goto __exit; } - if (at_resp_get_data_by_kw(&resp, "+CREG:", "+CREG: %d,%d", &enable_num , ®_state) < 0) + if (at_resp_get_data_by_kw(&resp, "+CREG:", "+CREG: %d,%d", &enable_num, ®_state) < 0) { goto __exit; } @@ -800,9 +771,8 @@ static void gm510_network_init(mo_object_t *module) goto __exit; } - __exit: - if(result != OS_EOK) + if (result != OS_EOK) { WARN("GM510 network init failed"); } @@ -829,4 +799,3 @@ void gm510_netconn_init(mo_gm510_t *module) } #endif /* GM510_USING_NETCONN_OPS */ - diff --git a/components/molink/module/gm510/source/gm510_netserv.c b/components/molink/module/gm510/source/gm510_netserv.c index fa0331f4..99456dbe 100644 --- a/components/molink/module/gm510/source/gm510_netserv.c +++ b/components/molink/module/gm510/source/gm510_netserv.c @@ -29,12 +29,11 @@ #include #define MO_LOG_TAG "gm510_netserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define IP_SIZE 16 - #ifdef GM510_USING_NETSERV_OPS os_err_t gm510_set_attach(mo_object_t *self, os_uint8_t attach_stat) @@ -163,4 +162,3 @@ os_err_t gm510_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber) } #endif /* gm510_USING_NETSERV_OPS */ - diff --git a/components/molink/module/l610/include/l610.h b/components/molink/module/l610/include/l610.h index 092ca596..83a412a7 100644 --- a/components/molink/module/l610/include/l610.h +++ b/components/molink/module/l610/include/l610.h @@ -73,14 +73,14 @@ typedef struct mo_l610 mo_object_t parent; #ifdef L610_USING_NETCONN_OPS mo_netconn_t netconn[L610_NETCONN_NUM]; - + os_event_t netconn_evt; os_mutex_t netconn_lock; #endif /* L610_USING_NETCONN_OPS */ } mo_l610_t; mo_object_t *module_l610_create(const char *name, void *parser_config); -os_err_t module_l610_destroy(mo_object_t *self); +os_err_t module_l610_destroy(mo_object_t *self); #endif /* MOLINK_USING_L610 */ @@ -89,4 +89,3 @@ os_err_t module_l610_destroy(mo_object_t *self); #endif /* __cplusplus */ #endif /* __L610_H__ */ - diff --git a/components/molink/module/l610/include/l610_netconn.h b/components/molink/module/l610/include/l610_netconn.h index bdcccf0e..2fb7fb58 100644 --- a/components/molink/module/l610/include/l610_netconn.h +++ b/components/molink/module/l610/include/l610_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef L610_USING_NETCONN_OPS -os_err_t l610_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t l610_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *l610_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t l610_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t l610_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t l610_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t l610_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t l610_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t l610_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef L610_USING_DNS -os_err_t l610_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t l610_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* L610_USING_NETCONN_OPS */ diff --git a/components/molink/module/l610/include/l610_netserv.h b/components/molink/module/l610/include/l610_netserv.h index 7175c2b8..81555c7d 100644 --- a/components/molink/module/l610/include/l610_netserv.h +++ b/components/molink/module/l610/include/l610_netserv.h @@ -40,7 +40,7 @@ os_err_t l610_set_cgact(mo_object_t *self, os_uint8_t cid, os_uint8_t act_n); os_err_t l610_get_cgact(mo_object_t *self, os_uint8_t *cid, os_uint8_t *act_stat); os_err_t l610_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber); os_err_t l610_netserv_open(mo_object_t *self); -os_err_t l610_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info); +os_err_t l610_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info); #endif /* L610_USING_NETSERV_OPS */ diff --git a/components/molink/module/l610/source/l610.c b/components/molink/module/l610/source/l610.c index 03798a6c..bb2fcf20 100644 --- a/components/molink/module/l610/source/l610.c +++ b/components/molink/module/l610/source/l610.c @@ -36,39 +36,39 @@ #ifdef L610_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = l610_at_test, - .get_imei = l610_get_imei, - .get_imsi = l610_get_imsi, - .get_iccid = l610_get_iccid, - .get_cfun = l610_get_cfun, - .set_cfun = l610_set_cfun, + .at_test = l610_at_test, + .get_imei = l610_get_imei, + .get_imsi = l610_get_imsi, + .get_iccid = l610_get_iccid, + .get_cfun = l610_get_cfun, + .set_cfun = l610_set_cfun, .get_firmware_version = l610_get_firmware_version, }; #endif /* L610_USING_GENERAL_OPS */ #ifdef L610_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = l610_set_attach, - .get_attach = l610_get_attach, - .set_reg = l610_set_reg, - .get_reg = l610_get_reg, - .set_cgact = l610_set_cgact, - .get_cgact = l610_get_cgact, - .get_csq = l610_get_csq, - .get_cell_info = l610_get_cell_info, + .set_attach = l610_set_attach, + .get_attach = l610_get_attach, + .set_reg = l610_set_reg, + .get_reg = l610_get_reg, + .set_cgact = l610_set_cgact, + .get_cgact = l610_get_cgact, + .get_csq = l610_get_csq, + .get_cell_info = l610_get_cell_info, }; #endif /* L610_USING_NETSERV_OPS */ - + #ifdef L610_USING_PING_OPS static const struct mo_ping_ops gs_ping_ops = { - .ping = l610_ping, + .ping = l610_ping, }; #endif /* L610_USING_PING_OPS */ #ifdef L610_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = l610_ifconfig, - .get_ipaddr = l610_get_ipaddr, + .ifconfig = l610_ifconfig, + .get_ipaddr = l610_get_ipaddr, }; #endif /* L610_USING_IFCONFIG_OPS */ @@ -76,14 +76,14 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void l610_netconn_init(mo_l610_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = l610_netconn_create, - .destroy = l610_netconn_destroy, + .create = l610_netconn_create, + .destroy = l610_netconn_destroy, #ifdef L610_USING_DNS - .gethostbyname = l610_netconn_gethostbyname, + .gethostbyname = l610_netconn_gethostbyname, #endif - .connect = l610_netconn_connect, - .send = l610_netconn_send, - .get_info = l610_netconn_get_info, + .connect = l610_netconn_connect, + .send = l610_netconn_send, + .get_info = l610_netconn_get_info, }; #endif /* L610_USING_NETCONN_OPS */ @@ -101,7 +101,7 @@ static void urc_sim_func(struct at_parser *parser, const char *data, os_size_t s static at_urc_t gs_urc_table[] = { {.prefix = "AT command", .suffix = "ready\r\n", .func = urc_ready_func}, - {.prefix = "+SIM", .suffix = "READY\r\n", .func = urc_sim_func}, + {.prefix = "+SIM", .suffix = "READY\r\n", .func = urc_sim_func}, }; #ifdef L610_USING_GENERAL_OPS @@ -332,7 +332,7 @@ int l610_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = L610_NAME, + mo_parser_config_t parser_config = {.parser_name = L610_NAME, .parser_device = device, .recv_buff_len = L610_RECV_BUFF_LEN}; diff --git a/components/molink/module/l610/source/l610_general.c b/components/molink/module/l610/source/l610_general.c index db23e5cd..6cc37f34 100644 --- a/components/molink/module/l610/source/l610_general.c +++ b/components/molink/module/l610/source/l610_general.c @@ -37,7 +37,7 @@ os_err_t l610_at_test(mo_object_t *self) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 1 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 1 * OS_TICK_PER_SECOND}; return at_parser_exec_cmd(parser, &resp, "AT"); } @@ -50,9 +50,9 @@ os_err_t l610_get_imei(mo_object_t *self, char *value, os_size_t len) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 1 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 1 * OS_TICK_PER_SECOND}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN=1")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN=1")) { return OS_ERROR; } @@ -78,7 +78,7 @@ os_err_t l610_get_imsi(mo_object_t *self, char *value, os_size_t len) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 1 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 1 * OS_TICK_PER_SECOND}; if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CIMI?")) { @@ -106,7 +106,7 @@ os_err_t l610_get_iccid(mo_object_t *self, char *value, os_size_t len) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 1 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 1 * OS_TICK_PER_SECOND}; if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CCID?")) { @@ -160,7 +160,7 @@ static os_err_t l610_set_apn(mo_object_t *self) } resp.line_num = 2; - resp.timeout = 150 * OS_TICK_PER_SECOND; + resp.timeout = 150 * OS_TICK_PER_SECOND; if (at_parser_exec_cmd(parser, &resp, "AT+MIPCALL=1,\"%s\"", apn) != OS_EOK) { @@ -186,7 +186,7 @@ os_err_t l610_get_cfun(mo_object_t *self, os_uint8_t *fun_lvl) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 1 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 1 * OS_TICK_PER_SECOND}; if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CFUN?")) { @@ -238,7 +238,7 @@ os_err_t l610_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ver char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+GMR"); if (result != OS_EOK) @@ -254,7 +254,7 @@ os_err_t l610_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ver } const char *source_line = at_resp_get_line(&resp, 1); - os_size_t line_length = strlen(source_line); + os_size_t line_length = strlen(source_line); char **dest_line = &version->ver_info[0]; @@ -273,4 +273,3 @@ os_err_t l610_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ver } #endif /* L610_USING_GENERAL_OPS */ - diff --git a/components/molink/module/l610/source/l610_ifconfig.c b/components/molink/module/l610/source/l610_ifconfig.c index 8002ab2b..822b31d5 100644 --- a/components/molink/module/l610/source/l610_ifconfig.c +++ b/components/molink/module/l610/source/l610_ifconfig.c @@ -37,13 +37,13 @@ os_err_t l610_ifconfig(mo_object_t *self) { char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; - char imei[MO_IMEI_LEN + 1] = {0}; - char iccid[MO_ICCID_LEN + 1] = {0}; - char imsi[MO_IMSI_LEN + 1] = {0}; + char imei[MO_IMEI_LEN + 1] = {0}; + char iccid[MO_ICCID_LEN + 1] = {0}; + char imsi[MO_IMSI_LEN + 1] = {0}; - os_err_t ret = OS_EOK; + os_err_t ret = OS_EOK; os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t ber = 0; if (l610_get_ipaddr(self, ipaddr) != OS_EOK) { @@ -72,7 +72,7 @@ os_err_t l610_ifconfig(mo_object_t *self) if (l610_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; ret = OS_ERROR; } @@ -103,10 +103,10 @@ os_err_t l610_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; + char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CGPADDR"); if (result != OS_EOK) diff --git a/components/molink/module/l610/source/l610_netconn.c b/components/molink/module/l610/source/l610_netconn.c index 37f8df89..4bf0334b 100644 --- a/components/molink/module/l610/source/l610_netconn.c +++ b/components/molink/module/l610/source/l610_netconn.c @@ -41,7 +41,7 @@ #endif #ifndef L610_NETCONN_MQ_MSG_MAX -#define L610_NETCONN_MQ_MSG_MAX (10) +#define L610_NETCONN_MQ_MSG_MAX (10) #endif #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) @@ -114,7 +114,7 @@ os_err_t l610_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); info->netconn_array = l610->netconn; - info->netconn_nums = sizeof(l610->netconn) / sizeof(l610->netconn[0]); + info->netconn_nums = sizeof(l610->netconn) / sizeof(l610->netconn[0]); return OS_EOK; } @@ -138,7 +138,7 @@ static os_err_t l610_netconn_set_format(mo_object_t *module) mo_netconn_t *l610_netconn_create(mo_object_t *module, mo_netconn_type_t type) { - mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); + mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); mo_netconn_t *netconn = l610_netconn_alloc(module); if (OS_NULL == netconn) @@ -171,7 +171,7 @@ mo_netconn_t *l610_netconn_create(mo_object_t *module, mo_netconn_type_t type) static os_err_t l610_netconn_do_destroy(mo_object_t *module, mo_netconn_t *netconn) { - mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); + mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); at_parser_t *parser = &module->parser; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -191,9 +191,7 @@ static os_err_t l610_netconn_do_destroy(mo_object_t *module, mo_netconn_t *netco os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+MIPCLOSE=%d", netconn->connect_id); if (result != OS_EOK) { - ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + ERROR("Module %s destroy %s netconn failed", module->name, (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); return result; } @@ -205,9 +203,7 @@ static os_err_t l610_netconn_do_destroy(mo_object_t *module, mo_netconn_t *netco if (result != OS_EOK) { - ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + ERROR("Module %s destroy %s netconn failed", module->name, (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); } return result; @@ -215,8 +211,8 @@ static os_err_t l610_netconn_do_destroy(mo_object_t *module, mo_netconn_t *netco os_err_t l610_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { - mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); - os_err_t result = OS_EOK; + mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); + os_err_t result = OS_EOK; if (l610 == OS_NULL) { @@ -254,9 +250,9 @@ os_err_t l610_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn id %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); @@ -269,10 +265,10 @@ os_err_t l610_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) os_err_t l610_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port) { at_parser_t *parser = &module->parser; - mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); - os_uint32_t event = SET_EVENT(netconn->connect_id, L610_EVENT_CONN_OK | L610_EVENT_CONN_FAIL); + mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); + os_uint32_t event = SET_EVENT(netconn->connect_id, L610_EVENT_CONN_OK | L610_EVENT_CONN_FAIL); - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 60 * OS_TICK_PER_SECOND}; @@ -334,7 +330,7 @@ __exit: { ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); } else @@ -347,16 +343,16 @@ __exit: os_size_t l610_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t curr_size = 0; - os_uint32_t event = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t curr_size = 0; + os_uint32_t event = 0; char resp_buff[AT_RESP_BUFF_SIZE_128] = {0}; mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 12 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 12 * OS_TICK_PER_SECOND}; at_parser_exec_lock(parser); @@ -448,10 +444,10 @@ os_err_t l610_netconn_gethostbyname(mo_object_t *self, const char *domain_name, OS_ASSERT(OS_NULL != addr); at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[AT_RESP_BUFF_SIZE_128] = {0}; - char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; + char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 15 * OS_TICK_PER_SECOND}; @@ -499,7 +495,7 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); + mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); os_int32_t connect_id = 0; @@ -518,10 +514,10 @@ static void urc_connect_func(struct at_parser *parser, const char *data, os_size OS_ASSERT(OS_NULL != data); mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); + mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); os_int32_t connect_id = 0; - os_int32_t stat = 0; + os_int32_t stat = 0; sscanf(data, "+MIPOPEN: %d,%d", &connect_id, &stat); @@ -546,10 +542,10 @@ static void urc_send_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); + mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); os_int32_t connect_id = 0; - os_int32_t stat = 0; + os_int32_t stat = 0; sscanf(data, "+MIPSEND: %d,%d,%*d", &connect_id, &stat); @@ -582,7 +578,7 @@ static void urc_state_func(struct at_parser *parser, const char *data, os_size_t sscanf(data, "+MIPSTAT: %d,&*d", &connect_id); mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); + mo_l610_t *l610 = os_container_of(module, mo_l610_t, parent); mo_netconn_t *netconn = l610_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) @@ -607,9 +603,9 @@ static void urc_state_func(struct at_parser *parser, const char *data, os_size_t static void urc_recv_func(struct at_parser *parser, mo_netconn_t *netconn, os_size_t data_size) { mo_object_t *module = os_container_of(parser, mo_object_t, parser); - os_int32_t timeout = data_size > 10 ? data_size : 10; + os_int32_t timeout = data_size > 10 ? data_size : 10; - char temp_buff[8] = {0}; + char temp_buff[8] = {0}; INFO("Moudle %s netconn %d receive %d bytes data", parser->name, netconn->connect_id, data_size); @@ -667,7 +663,7 @@ static void urc_tcprecv_func(struct at_parser *parser, const char *data, os_size os_int32_t connect_id = atoi(&tmp_ch); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = l610_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) { @@ -721,7 +717,7 @@ static void urc_udprecv_func(struct at_parser *parser, const char *data, os_size os_int32_t connect_id = atoi(&tmp_ch); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = l610_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) { @@ -754,12 +750,12 @@ static void urc_udprecv_func(struct at_parser *parser, const char *data, os_size } static at_urc_t gs_urc_table[] = { - {.prefix = "+MIPSEND:", .suffix = "\r\n", .func = urc_send_func}, - {.prefix = "+MIPOPEN:", .suffix = "\r\n", .func = urc_connect_func}, - {.prefix = "+MIPSTAT:", .suffix = "\r\n", .func = urc_state_func}, - {.prefix = "+MIPCLOSE:", .suffix = "\r\n", .func = urc_close_func}, - {.prefix = "", .suffix = "+MIPRTCP:", .func = urc_tcprecv_func}, - {.prefix = "", .suffix = "+MIPRUDP:", .func = urc_udprecv_func}, + {.prefix = "+MIPSEND:", .suffix = "\r\n", .func = urc_send_func}, + {.prefix = "+MIPOPEN:", .suffix = "\r\n", .func = urc_connect_func}, + {.prefix = "+MIPSTAT:", .suffix = "\r\n", .func = urc_state_func}, + {.prefix = "+MIPCLOSE:", .suffix = "\r\n", .func = urc_close_func}, + {.prefix = "", .suffix = "+MIPRTCP:", .func = urc_tcprecv_func}, + {.prefix = "", .suffix = "+MIPRUDP:", .func = urc_udprecv_func}, }; void l610_netconn_init(mo_l610_t *module) diff --git a/components/molink/module/l610/source/l610_netserv.c b/components/molink/module/l610/source/l610_netserv.c index 1004de39..8d6c29ff 100644 --- a/components/molink/module/l610/source/l610_netserv.c +++ b/components/molink/module/l610/source/l610_netserv.c @@ -70,7 +70,7 @@ os_err_t l610_netserv_open(mo_object_t *self) } resp.line_num = 2; - resp.timeout = 150 * OS_TICK_PER_SECOND; + resp.timeout = 150 * OS_TICK_PER_SECOND; if (at_parser_exec_cmd(parser, &resp, "AT+MIPCALL=1,\"%s\"", apn) != OS_EOK) { @@ -133,7 +133,7 @@ os_err_t l610_get_attach(mo_object_t *self, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) { ERROR("Get %s module attach state failed", self->name); return OS_ERROR; @@ -182,7 +182,7 @@ os_err_t l610_set_cgact(mo_object_t *self, os_uint8_t cid, os_uint8_t act_stat) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 30 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 30 * OS_TICK_PER_SECOND}; return at_parser_exec_cmd(parser, &resp, "AT+CGACT=%d,%d", act_stat, cid); } @@ -193,7 +193,7 @@ os_err_t l610_get_cgact(mo_object_t *self, os_uint8_t *cid, os_uint8_t *act_stat char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 3 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 3 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CGACT?"); if (result != OS_EOK) @@ -216,7 +216,7 @@ os_err_t l610_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CSQ?"); if (result != OS_EOK) @@ -233,98 +233,97 @@ os_err_t l610_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber) return OS_EOK; } -#define L610_MODULE_NET_TYPE 5 - -os_err_t l610_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info) -{ - os_err_t ret = OS_EOK; - os_size_t i = 0; - cell_info_t *cell_info = OS_NULL; - char *temp_buff = OS_NULL; - os_uint32_t cell_num = 0; - - at_parser_t *parser = &self->parser; - if (parser == OS_NULL) - { - ERROR("L610 ping: at parser is NULL."); - return OS_ERROR; - } - if(!onepos_cell_info) - { - ERROR("input param is error!"); - return OS_ERROR; - } - - at_resp_t resp = {.buff = os_calloc(1, 1024), - .buff_size = 1024, - .timeout = 50 * OS_TICK_PER_SECOND - }; - - if (OS_NULL == resp.buff) - { - ERROR("Calloc l610 cell info response memory failed!"); - ret = OS_ENOMEM; - goto __exit; - } - - /* neighbor cell */ - if (at_parser_exec_cmd(parser, &resp, "AT+MCELL=0,26") < 0) - { - ret = OS_ERROR; - ERROR("AT cmd exec fail: AT+MCELL=0,26\n"); - goto __exit; - } - DEBUG("resp->line_counts : %d\r\n", resp.line_counts); - - cell_info = os_calloc((resp.line_counts), sizeof(cell_info_t)); - if(NULL == cell_info) - { - ERROR("malloc cell_info is null"); - ret = OS_ENOMEM; - return ret; - } - - INFO(" MCC MNC CID LAC RSSI\n"); - INFO(" ------------ ------------ ------------ ------------ ----\n"); - - for (i = 1; i < resp.line_counts; i++) - { - temp_buff = (char*)at_resp_get_line(&resp, i); - if(strlen(temp_buff) > 25) { - sscanf(temp_buff, - "MCC:%u,MNC:%u,LAC:%x,CELL ID:%x,%*[^,],%*[^,],%*[^,],RxDbm:%d", - &cell_info[cell_num].mcc, - &cell_info[cell_num].mnc, - &cell_info[cell_num].lac, - &cell_info[cell_num].cid, - &cell_info[cell_num].ss - ); - - if(cell_info[cell_num].mcc) - { - INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", - cell_info[cell_num].mcc, cell_info[cell_num].mnc, cell_info[cell_num].cid, - cell_info[cell_num].lac, cell_info[cell_num].ss); - cell_num ++; - } - } - } - /* main cell */ - - INFO(" ------------ ------------ ------------ ------------ ----\n"); - - onepos_cell_info->cell_num = ++cell_num; - onepos_cell_info->cell_info = cell_info; - onepos_cell_info->net_type = L610_MODULE_NET_TYPE; - -__exit: - - if (resp.buff != OS_NULL) - { - os_free(resp.buff); - } - - return ret; -} -#endif /* L610_USING_NETSERV_OPS */ +#define L610_MODULE_NET_TYPE 5 + +os_err_t l610_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info) +{ + os_err_t ret = OS_EOK; + os_size_t i = 0; + cell_info_t *cell_info = OS_NULL; + char *temp_buff = OS_NULL; + os_uint32_t cell_num = 0; + at_parser_t *parser = &self->parser; + if (parser == OS_NULL) + { + ERROR("L610 ping: at parser is NULL."); + return OS_ERROR; + } + if (!onepos_cell_info) + { + ERROR("input param is error!"); + return OS_ERROR; + } + + at_resp_t resp = {.buff = os_calloc(1, 1024), .buff_size = 1024, .timeout = 50 * OS_TICK_PER_SECOND}; + + if (OS_NULL == resp.buff) + { + ERROR("Calloc l610 cell info response memory failed!"); + ret = OS_ENOMEM; + goto __exit; + } + + /* neighbor cell */ + if (at_parser_exec_cmd(parser, &resp, "AT+MCELL=0,26") < 0) + { + ret = OS_ERROR; + ERROR("AT cmd exec fail: AT+MCELL=0,26\n"); + goto __exit; + } + DEBUG("resp->line_counts : %d\r\n", resp.line_counts); + + cell_info = os_calloc((resp.line_counts), sizeof(cell_info_t)); + if (NULL == cell_info) + { + ERROR("malloc cell_info is null"); + ret = OS_ENOMEM; + return ret; + } + + INFO(" MCC MNC CID LAC RSSI\n"); + INFO(" ------------ ------------ ------------ ------------ ----\n"); + + for (i = 1; i < resp.line_counts; i++) + { + temp_buff = (char *)at_resp_get_line(&resp, i); + if (strlen(temp_buff) > 25) + { + sscanf(temp_buff, + "MCC:%u,MNC:%u,LAC:%x,CELL ID:%x,%*[^,],%*[^,],%*[^,],RxDbm:%d", + &cell_info[cell_num].mcc, + &cell_info[cell_num].mnc, + &cell_info[cell_num].lac, + &cell_info[cell_num].cid, + &cell_info[cell_num].ss); + + if (cell_info[cell_num].mcc) + { + INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", + cell_info[cell_num].mcc, + cell_info[cell_num].mnc, + cell_info[cell_num].cid, + cell_info[cell_num].lac, + cell_info[cell_num].ss); + cell_num++; + } + } + } + /* main cell */ + + INFO(" ------------ ------------ ------------ ------------ ----\n"); + + onepos_cell_info->cell_num = ++cell_num; + onepos_cell_info->cell_info = cell_info; + onepos_cell_info->net_type = L610_MODULE_NET_TYPE; + +__exit: + + if (resp.buff != OS_NULL) + { + os_free(resp.buff); + } + + return ret; +} +#endif /* L610_USING_NETSERV_OPS */ diff --git a/components/molink/module/l610/source/l610_ping.c b/components/molink/module/l610/source/l610_ping.c index f0e6b633..0c72512e 100644 --- a/components/molink/module/l610/source/l610_ping.c +++ b/components/molink/module/l610/source/l610_ping.c @@ -39,15 +39,17 @@ os_err_t l610_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint at_parser_t *parser = &self->parser; char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; - char ip_addr[IPADDR_MAX_STR_LEN + 1] = {0}; + char ip_addr[IPADDR_MAX_STR_LEN + 1] = {0}; os_int32_t req_time = 0; - os_int32_t ttl = 0; + os_int32_t ttl = 0; - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .line_num = 3, - .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND,}; + at_resp_t at_resp = { + .buff = resp_buff, + .buff_size = sizeof(resp_buff), + .line_num = 3, + .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND, + }; if (len > L610_MAX_PING_PKG_LEN) { @@ -107,8 +109,8 @@ os_err_t l610_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint inet_aton(ip_addr, &(resp->ip_addr)); resp->data_len = len; - resp->ttl = ttl; - resp->time = req_time; + resp->ttl = ttl; + resp->time = req_time; } return result; diff --git a/components/molink/module/m5310a/include/m5310a.h b/components/molink/module/m5310a/include/m5310a.h index 2ec4a3cc..47e998f8 100644 --- a/components/molink/module/m5310a/include/m5310a.h +++ b/components/molink/module/m5310a/include/m5310a.h @@ -77,12 +77,12 @@ typedef struct mo_m5310a mo_object_t parent; #ifdef M5310A_USING_NETCONN_OPS mo_netconn_t netconn[M5310A_NETCONN_NUM]; - os_mutex_t netconn_lock; + os_mutex_t netconn_lock; #endif /* M5310A_USING_NETCONN_OPS */ } mo_m5310a_t; mo_object_t *module_m5310a_create(const char *name, void *parser_config); -os_err_t module_m5310a_destroy(mo_object_t *self); +os_err_t module_m5310a_destroy(mo_object_t *self); #endif /* MOLINK_USING_M5310A */ diff --git a/components/molink/module/m5310a/include/m5310a_netconn.h b/components/molink/module/m5310a/include/m5310a_netconn.h index 5c8b7507..0c4d134e 100644 --- a/components/molink/module/m5310a/include/m5310a_netconn.h +++ b/components/molink/module/m5310a/include/m5310a_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef M5310A_USING_NETCONN_OPS -os_err_t m5310a_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t m5310a_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *m5310a_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t m5310a_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t m5310a_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t m5310a_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t m5310a_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t m5310a_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t m5310a_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef M5310A_USING_DNS -os_err_t m5310a_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t m5310a_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* M5310A_USING_NETCONN_OPS */ diff --git a/components/molink/module/m5310a/source/m5310a.c b/components/molink/module/m5310a/source/m5310a.c index 527ba9b3..e119128c 100644 --- a/components/molink/module/m5310a/source/m5310a.c +++ b/components/molink/module/m5310a/source/m5310a.c @@ -36,40 +36,40 @@ #ifdef M5310A_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = m5310a_at_test, - .get_imei = m5310a_get_imei, - .get_imsi = m5310a_get_imsi, - .get_iccid = m5310a_get_iccid, - .get_cfun = m5310a_get_cfun, - .set_cfun = m5310a_set_cfun, + .at_test = m5310a_at_test, + .get_imei = m5310a_get_imei, + .get_imsi = m5310a_get_imsi, + .get_iccid = m5310a_get_iccid, + .get_cfun = m5310a_get_cfun, + .set_cfun = m5310a_set_cfun, .get_firmware_version = m5310a_get_firmware_version, }; #endif /* M5310A_USING_GENERAL_OPS */ #ifdef M5310A_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = m5310a_set_attach, - .get_attach = m5310a_get_attach, - .set_reg = m5310a_set_reg, - .get_reg = m5310a_get_reg, - .set_cgact = m5310a_set_cgact, - .get_cgact = m5310a_get_cgact, - .get_csq = m5310a_get_csq, - .get_radio = m5310a_get_radio, - .clear_stored_earfcn = m5310a_clear_stored_earfcn, + .set_attach = m5310a_set_attach, + .get_attach = m5310a_get_attach, + .set_reg = m5310a_set_reg, + .get_reg = m5310a_get_reg, + .set_cgact = m5310a_set_cgact, + .get_cgact = m5310a_get_cgact, + .get_csq = m5310a_get_csq, + .get_radio = m5310a_get_radio, + .clear_stored_earfcn = m5310a_clear_stored_earfcn, }; #endif /* M5310A_USING_NETSERV_OPS */ #ifdef M5310A_USING_PING_OPS static const struct mo_ping_ops gs_ping_ops = { - .ping = m5310a_ping, + .ping = m5310a_ping, }; #endif /* M5310A_USING_PING_OPS */ #ifdef M5310A_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = m5310a_ifconfig, - .get_ipaddr = m5310a_get_ipaddr, + .ifconfig = m5310a_ifconfig, + .get_ipaddr = m5310a_get_ipaddr, }; #endif /* M5310A_USING_IFCONFIG_OPS */ @@ -77,31 +77,31 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void m5310a_netconn_init(mo_m5310a_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = m5310a_netconn_create, - .destroy = m5310a_netconn_destroy, + .create = m5310a_netconn_create, + .destroy = m5310a_netconn_destroy, #ifdef M5310A_USING_DNS - .gethostbyname = m5310a_netconn_gethostbyname, + .gethostbyname = m5310a_netconn_gethostbyname, #endif - .connect = m5310a_netconn_connect, - .send = m5310a_netconn_send, - .get_info = m5310a_netconn_get_info, + .connect = m5310a_netconn_connect, + .send = m5310a_netconn_send, + .get_info = m5310a_netconn_get_info, }; #endif /* M5310A_USING_NETCONN_OPS */ #ifdef M5310A_USING_ONENET_NB_OPS static const mo_onenet_ops_t gs_onenet_ops = { - .onenetnb_create = m5310_onenetnb_create, - .onenetnb_createex = m5310_onenetnb_createex, - .onenetnb_addobj = m5310_onenetnb_addobj, + .onenetnb_create = m5310_onenetnb_create, + .onenetnb_createex = m5310_onenetnb_createex, + .onenetnb_addobj = m5310_onenetnb_addobj, .onenetnb_discoverrsp = m5310_onenetnb_discoverrsp, - .onenetnb_nmi = m5310_onenetnb_set_nmi, - .onenetnb_open = m5310_onenetnb_open, - .onenetnb_notify = m5310_onenetnb_notify, - .onenetnb_update = m5310_onenetnb_update, - .onenetnb_get_write = m5310_onenetnb_get_write, - .onenetnb_writersp = m5310_onenetnb_writersp, + .onenetnb_nmi = m5310_onenetnb_set_nmi, + .onenetnb_open = m5310_onenetnb_open, + .onenetnb_notify = m5310_onenetnb_notify, + .onenetnb_update = m5310_onenetnb_update, + .onenetnb_get_write = m5310_onenetnb_get_write, + .onenetnb_writersp = m5310_onenetnb_writersp, #ifdef OS_USING_SHELL - .onenetnb_all = m5310_onenetnb_all, + .onenetnb_all = m5310_onenetnb_all, #endif }; #endif /* M5310A_USING_ONENET_OPS */ @@ -216,7 +216,7 @@ int m5310_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = M5310A_NAME, + mo_parser_config_t parser_config = {.parser_name = M5310A_NAME, .parser_device = device, .recv_buff_len = M5310A_RECV_BUFF_LEN}; diff --git a/components/molink/module/m5310a/source/m5310a_general.c b/components/molink/module/m5310a/source/m5310a_general.c index 10840666..a752a000 100644 --- a/components/molink/module/m5310a/source/m5310a_general.c +++ b/components/molink/module/m5310a/source/m5310a_general.c @@ -165,7 +165,7 @@ os_err_t m5310a_set_cfun(mo_object_t *self, os_uint8_t fun_lvl) os_err_t m5310a_get_firmware_version(mo_object_t *self, mo_firmware_version_t *version) { - at_parser_t *parser = &self->parser; + at_parser_t *parser = &self->parser; char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; @@ -188,7 +188,7 @@ os_err_t m5310a_get_firmware_version(mo_object_t *self, mo_firmware_version_t *v for (int i = 2; i <= resp.line_counts - 1; i += 2) { const char *source_line = at_resp_get_line(&resp, i); - os_size_t line_length = strlen(source_line); + os_size_t line_length = strlen(source_line); char **dest_line = &version->ver_info[version->line_counts]; @@ -201,7 +201,7 @@ os_err_t m5310a_get_firmware_version(mo_object_t *self, mo_firmware_version_t *v } strncpy(*dest_line, source_line, line_length); - version->line_counts ++; + version->line_counts++; } return OS_EOK; diff --git a/components/molink/module/m5310a/source/m5310a_ifconfig.c b/components/molink/module/m5310a/source/m5310a_ifconfig.c index 1340e467..1556dab0 100644 --- a/components/molink/module/m5310a/source/m5310a_ifconfig.c +++ b/components/molink/module/m5310a/source/m5310a_ifconfig.c @@ -38,14 +38,14 @@ os_err_t m5310a_ifconfig(mo_object_t *self) { char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; - char imei[MO_IMEI_LEN + 1] = {0}; - char iccid[MO_ICCID_LEN + 1] = {0}; - char imsi[MO_IMSI_LEN + 1] = {0}; + char imei[MO_IMEI_LEN + 1] = {0}; + char iccid[MO_ICCID_LEN + 1] = {0}; + char imsi[MO_IMSI_LEN + 1] = {0}; - os_err_t ret = OS_EOK; + os_err_t ret = OS_EOK; os_uint8_t rssi = 0; - os_uint8_t ber = 0; - os_int32_t i = 0; + os_uint8_t ber = 0; + os_int32_t i = 0; if (m5310a_get_ipaddr(self, ipaddr) != OS_EOK) { @@ -74,7 +74,7 @@ os_err_t m5310a_ifconfig(mo_object_t *self) if (m5310a_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; ret = OS_ERROR; } @@ -104,8 +104,8 @@ os_err_t m5310a_ifconfig(mo_object_t *self) os_err_t m5310a_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t ucid = -1; - os_int8_t len = -1; + os_int8_t ucid = -1; + os_int8_t len = -1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; diff --git a/components/molink/module/m5310a/source/m5310a_netconn.c b/components/molink/module/m5310a/source/m5310a_netconn.c index 56caaf69..df0ea8ef 100644 --- a/components/molink/module/m5310a/source/m5310a_netconn.c +++ b/components/molink/module/m5310a/source/m5310a_netconn.c @@ -36,8 +36,8 @@ #define PROTOCOL_TYPE_TCP (6) #define PROTOCOL_TYPE_UDP (17) -#define SEND_DATA_MAX_SIZE (1358) -#define M5310A_SEND_HEXDATA_BLOCK_SIZE (256) +#define SEND_DATA_MAX_SIZE (1358) +#define M5310A_SEND_HEXDATA_BLOCK_SIZE (256) #define M5310A_NETCONN_MQ_NAME "m5310a_nc_mq" @@ -46,7 +46,7 @@ #endif #ifndef M5310A_NETCONN_MQ_MSG_MAX -#define M5310A_NETCONN_MQ_MSG_MAX (8) +#define M5310A_NETCONN_MQ_MSG_MAX (8) #endif #ifdef M5310A_USING_NETCONN_OPS @@ -106,7 +106,7 @@ os_err_t m5310a_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_m5310a_t *m5310a = os_container_of(module, mo_m5310a_t, parent); info->netconn_array = m5310a->netconn; - info->netconn_nums = sizeof(m5310a->netconn) / sizeof(m5310a->netconn[0]); + info->netconn_nums = sizeof(m5310a->netconn) / sizeof(m5310a->netconn[0]); return OS_EOK; } @@ -115,7 +115,7 @@ mo_netconn_t *m5310a_netconn_create(mo_object_t *module, mo_netconn_type_t type) { mo_m5310a_t *m5310a = os_container_of(module, mo_m5310a_t, parent); at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; m5310a_lock(&m5310a->netconn_lock); @@ -185,7 +185,7 @@ mo_netconn_t *m5310a_netconn_create(mo_object_t *module, mo_netconn_type_t type) os_err_t m5310a_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; INFO("Module %s in %d netconn status", module->name, netconn->stat); @@ -219,9 +219,9 @@ os_err_t m5310a_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn_id:%d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); @@ -237,10 +237,10 @@ os_err_t m5310a_netconn_gethostbyname(mo_object_t *self, const char *domain_name char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; - at_resp_t resp = {.buff = resp_buff, + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .line_num = 2, - .timeout = 20 * OS_TICK_PER_SECOND}; + .line_num = 2, + .timeout = 20 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CMDNS=\"%s\"", domain_name); if (result < 0) @@ -291,10 +291,10 @@ static os_err_t m5310a_tcp_connect(at_parser_t *parser, os_int32_t connect_id, c { char resp_buff[AT_RESP_BUFF_SIZE_128] = {0}; - at_resp_t resp = {.buff = resp_buff, + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .line_num = 2, - .timeout = 40 * OS_TICK_PER_SECOND}; + .line_num = 2, + .timeout = 40 * OS_TICK_PER_SECOND}; char buf[16] = {0}; @@ -326,7 +326,7 @@ __exit: os_err_t m5310a_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -342,7 +342,7 @@ os_err_t m5310a_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_a #ifdef M5310A_USING_UDP case NETCONN_TYPE_UDP: - result = OS_EOK; /* UDP does not need to connect */ + result = OS_EOK; /* UDP does not need to connect */ break; #endif @@ -359,7 +359,7 @@ os_err_t m5310a_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_a ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); @@ -368,8 +368,8 @@ os_err_t m5310a_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_a static os_size_t m5310a_one_hexdata_block_send(at_parser_t *parser, const char *data, os_size_t size) { - os_size_t sent_size = 0; /* raw data sent size */ - os_size_t curr_pkt_size = 0; /* raw data current packet size */ + os_size_t sent_size = 0; /* raw data sent size */ + os_size_t curr_pkt_size = 0; /* raw data current packet size */ char hex_str_buff[M5310A_SEND_HEXDATA_BLOCK_SIZE + 1] = {0}; @@ -401,16 +401,16 @@ __exit: os_size_t m5310a_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t cur_pkt_size = 0; - os_int32_t connect_id = -1; - os_size_t cnt = 0; - - char send_cmd [AT_RESP_BUFF_SIZE_DEF] = {0}; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t cur_pkt_size = 0; + os_int32_t connect_id = -1; + os_size_t cnt = 0; + + char send_cmd[AT_RESP_BUFF_SIZE_DEF] = {0}; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 30 * OS_TICK_PER_SECOND}; @@ -551,7 +551,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; + os_int32_t data_size = 0; sscanf(data, "+NSORF:%d,%*[^,],%*d,%d,", &connect_id, &data_size); @@ -599,7 +599,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t static at_urc_t gs_urc_table[] = { {.prefix = "+NSOCLI:", .suffix = "\r\n", .func = urc_close_func}, - {.prefix = "+NSORF:", .suffix = "\r\n", .func = urc_recv_func}, + {.prefix = "+NSORF:", .suffix = "\r\n", .func = urc_recv_func}, }; void m5310a_netconn_init(mo_m5310a_t *module) diff --git a/components/molink/module/m5310a/source/m5310a_netserv.c b/components/molink/module/m5310a/source/m5310a_netserv.c index 317ca0f7..5adf204b 100644 --- a/components/molink/module/m5310a/source/m5310a_netserv.c +++ b/components/molink/module/m5310a/source/m5310a_netserv.c @@ -58,7 +58,7 @@ os_err_t m5310a_get_attach(mo_object_t *self, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) { ERROR("Get %s module attach state failed", self->name); return OS_ERROR; diff --git a/components/molink/module/m5310a/source/m5310a_onenet_nb.c b/components/molink/module/m5310a/source/m5310a_onenet_nb.c index 8bb20abf..11b804b2 100644 --- a/components/molink/module/m5310a/source/m5310a_onenet_nb.c +++ b/components/molink/module/m5310a/source/m5310a_onenet_nb.c @@ -39,8 +39,8 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_create, ONENET_NB_FUNC_ARGS) OS_ASSERT(resp != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; - os_uint8_t ref = 0; + os_err_t result = OS_ERROR; + os_uint8_t ref = 0; at_parser_t *parser = &self->parser; char tmp_format[128] = "AT+MIPLCREATE="; @@ -58,7 +58,7 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_create, ONENET_NB_FUNC_ARGS) if (at_resp_get_data_by_kw(&at_resp, "+MIPLCREATE:", "+MIPLCREATE:%hhu", &ref) > 0) { *(os_uint8_t *)resp = ref; - result = OS_EOK; + result = OS_EOK; } __exit: @@ -72,11 +72,11 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_createex, ONENET_NB_FUNC_ARGS) OS_ASSERT(resp != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = &self->parser; - os_uint8_t ref = 0; - char tmp_format[64] = "AT+MIPLCREATEEX="; + os_uint8_t ref = 0; + char tmp_format[64] = "AT+MIPLCREATEEX="; strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -91,7 +91,7 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_createex, ONENET_NB_FUNC_ARGS) if (at_resp_get_data_by_kw(&at_resp, "+MIPLCREATEEX:", "+MIPLCREATEEX:%hhu", &ref) > 0) { *(os_uint8_t *)resp = ref; - result = OS_EOK; + result = OS_EOK; } __exit: @@ -104,7 +104,7 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_addobj, ONENET_NB_FUNC_ARGS) OS_ASSERT(self != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = &self->parser; char tmp_format[64] = "AT+MIPLADDOBJ="; @@ -127,7 +127,7 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_discoverrsp, ONENET_NB_FUNC_ARGS) OS_ASSERT(self != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = &self->parser; char tmp_format[128] = "AT+MIPLDISCOVERRSP="; @@ -150,7 +150,7 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_set_nmi, ONENET_NB_FUNC_ARGS) OS_ASSERT(self != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = &self->parser; char tmp_format[28] = "AT+MIPLNMI="; @@ -173,7 +173,7 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_open, ONENET_NB_FUNC_ARGS) OS_ASSERT(self != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = &self->parser; char tmp_format[28] = "AT+MIPLOPEN="; @@ -181,10 +181,10 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_open, ONENET_NB_FUNC_ARGS) char resp_buff[128] = {0}; - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .line_num = 3, - .timeout = os_tick_from_ms(timeout)}; + at_resp_t at_resp = {.buff = resp_buff, + .buff_size = sizeof(resp_buff), + .line_num = 3, + .timeout = os_tick_from_ms(timeout)}; if (at_parser_exec_cmd_valist(parser, &at_resp, tmp_format, args) != OS_EOK) { @@ -204,8 +204,8 @@ __exit: os_err_t m5310_get_onenetnb_notify_ackid(const char *format, va_list args, os_uint16_t *id) { /* if has ackid, must be the 11 element */ - int num_count = 1; - os_int32_t id_tmp = -1; + int num_count = 1; + os_int32_t id_tmp = -1; os_uint8_t qualifier; for (; *format; ++format) @@ -295,8 +295,8 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_notify, ONENET_NB_FUNC_ARGS) OS_ASSERT(self != OS_NULL); OS_ASSERT(format != OS_NULL); - os_bool_t is_ack = OS_FALSE; - os_err_t result = OS_ERROR; + os_bool_t is_ack = OS_FALSE; + os_err_t result = OS_ERROR; at_parser_t *parser = &self->parser; m5310a_nmi_t nmi; if (m5310_onenetnb_get_nmi(self, -1, &nmi, OS_NULL, args) != OS_EOK) /* get nsmi */ @@ -304,8 +304,8 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_notify, ONENET_NB_FUNC_ARGS) return OS_ERROR; } - os_uint16_t ackid_in = 0; - os_int32_t ackid_out = 0; + os_uint16_t ackid_in = 0; + os_int32_t ackid_out = 0; if (m5310_get_onenetnb_notify_ackid(format, args, &ackid_in) == OS_EOK) /* whether has ackid */ { is_ack = OS_TRUE; @@ -320,10 +320,10 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_notify, ONENET_NB_FUNC_ARGS) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .line_num = line_num, - .timeout = os_tick_from_ms(timeout)}; + at_resp_t at_resp = {.buff = resp_buff, + .buff_size = sizeof(resp_buff), + .line_num = line_num, + .timeout = os_tick_from_ms(timeout)}; if (at_parser_exec_cmd_valist(parser, &at_resp, tmp_format, args) != OS_EOK) { @@ -356,17 +356,20 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_update, ONENET_NB_FUNC_ARGS) OS_ASSERT(self != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = &self->parser; - os_uint8_t ref = 0; - os_uint16_t event_id = 0; - char tmp_format[64] = "AT+MIPLUPDATE="; + os_uint8_t ref = 0; + os_uint16_t event_id = 0; + char tmp_format[64] = "AT+MIPLUPDATE="; strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .line_num = 2, .timeout = os_tick_from_ms(timeout)}; + at_resp_t at_resp = {.buff = resp_buff, + .buff_size = sizeof(resp_buff), + .line_num = 2, + .timeout = os_tick_from_ms(timeout)}; if (at_parser_exec_cmd_valist(parser, &at_resp, tmp_format, args) != OS_EOK) { @@ -399,7 +402,7 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_get_write, ONENET_NB_FUNC_ARGS) return OS_ERROR; } - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = &self->parser; char tmp_format[128] = "AT+MIPLMGR="; @@ -427,7 +430,7 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_get_write, ONENET_NB_FUNC_ARGS) mgr->value) > 0) { mgr->value[mgr->len] = '\0'; - result = OS_EOK; + result = OS_EOK; } __exit: @@ -440,7 +443,7 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_writersp, ONENET_NB_FUNC_ARGS) OS_ASSERT(self != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = &self->parser; char tmp_format[128] = "AT+MIPLWRITERSP="; @@ -464,7 +467,7 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_get_nmi, ONENET_NB_FUNC_ARGS) OS_ASSERT(self != OS_NULL); OS_ASSERT(resp != OS_NULL); - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = &self->parser; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -484,10 +487,10 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_get_nmi, ONENET_NB_FUNC_ARGS) { goto __exit; } - ((m5310a_nmi_t *)resp)->ref = ref; + ((m5310a_nmi_t *)resp)->ref = ref; ((m5310a_nmi_t *)resp)->nnmi = nnmi; ((m5310a_nmi_t *)resp)->nsmi = nsmi; - result = OS_EOK; + result = OS_EOK; __exit: @@ -500,7 +503,7 @@ DEFINE_M5310A_ONENET_FUNC(m5310_onenetnb_all, ONENET_NB_FUNC_ARGS) OS_ASSERT(self != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = &self->parser; char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; diff --git a/components/molink/module/m5310a/source/m5310a_ping.c b/components/molink/module/m5310a/source/m5310a_ping.c index b0a57f1f..cd55aafd 100644 --- a/components/molink/module/m5310a/source/m5310a_ping.c +++ b/components/molink/module/m5310a/source/m5310a_ping.c @@ -36,12 +36,12 @@ os_err_t m5310a_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - os_uint32_t req_time = 0; - os_int16_t ttl = -1; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; + os_uint32_t req_time = 0; + os_int16_t ttl = -1; - char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; + char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; char ret_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; if (parser == OS_NULL) @@ -72,10 +72,10 @@ os_err_t m5310a_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ui char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; /* Need to wait for 4 lines response msg, and timeout comming with ms */ - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .line_num = 2, - .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; + .line_num = 2, + .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; /* Default set timeout to 5000ms */ /* It is found that the ping packet of M5310-A takes 4 seconds to return */ @@ -116,8 +116,8 @@ os_err_t m5310a_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ui { inet_aton(ipaddr, &(resp->ip_addr)); resp->data_len = len; - resp->ttl = ttl; - resp->time = req_time; + resp->ttl = ttl; + resp->time = req_time; } __exit: diff --git a/components/molink/module/m5311/include/m5311.h b/components/molink/module/m5311/include/m5311.h index 64dc9c58..a2c6c3e2 100644 --- a/components/molink/module/m5311/include/m5311.h +++ b/components/molink/module/m5311/include/m5311.h @@ -69,25 +69,26 @@ extern "C" { #endif #ifndef M5311_NETCONN_NUM -#define M5311_NETCONN_NUM (5) +#define M5311_NETCONN_NUM (5) #endif -typedef struct mo_m5311 { +typedef struct mo_m5311 +{ mo_object_t parent; #ifdef M5311_USING_NETCONN_OPS mo_netconn_t netconn[M5311_NETCONN_NUM]; - os_mutex_t netconn_lock; - char *netconn_data; - os_event_t netconn_evt; + os_mutex_t netconn_lock; + char *netconn_data; + os_event_t netconn_evt; #endif /* M5311_USING_NETCONN_OPS */ #ifdef M5311_USING_ONENET_NB_OPS - os_mutex_t onenetnb_lock; - os_event_t onenetnb_evt; + os_mutex_t onenetnb_lock; + os_event_t onenetnb_evt; #endif /* M5311_USING_ONENET_NB_OPS */ } mo_m5311_t; mo_object_t *module_m5311_create(const char *name, void *parser_config); -os_err_t module_m5311_destroy(mo_object_t *self); +os_err_t module_m5311_destroy(mo_object_t *self); #endif /* MOLINK_USING_M5311 */ diff --git a/components/molink/module/m5311/include/m5311_netconn.h b/components/molink/module/m5311/include/m5311_netconn.h index bec30f7b..4bf5cf4f 100644 --- a/components/molink/module/m5311/include/m5311_netconn.h +++ b/components/molink/module/m5311/include/m5311_netconn.h @@ -33,13 +33,13 @@ extern "C" { #ifdef M5311_USING_NETCONN_OPS mo_netconn_t *m5311_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t m5311_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t m5311_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t m5311_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t m5311_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t m5311_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t m5311_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef M5311_USING_DNS -os_err_t m5311_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr); +os_err_t m5311_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr); #endif -os_err_t m5311_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t m5311_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); #endif /* M5311_USING_NETCONN_OPS */ diff --git a/components/molink/module/m5311/source/m5311.c b/components/molink/module/m5311/source/m5311.c index d982cc27..e35dd331 100644 --- a/components/molink/module/m5311/source/m5311.c +++ b/components/molink/module/m5311/source/m5311.c @@ -28,7 +28,7 @@ #include #define MO_LOG_TAG "m5311" -#define MO_LOG_LVL MO_LOG_EMERG +#define MO_LOG_LVL MO_LOG_EMERG #include "mo_log.h" #ifdef MOLINK_USING_M5311 @@ -37,13 +37,13 @@ #ifdef M5311_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = m5311_at_test, - .get_imei = m5311_get_imei, - .get_imsi = m5311_get_imsi, - .get_iccid = m5311_get_iccid, - .get_cfun = m5311_get_cfun, - .set_cfun = m5311_set_cfun, - .gm_time = m5311_gm_time, + .at_test = m5311_at_test, + .get_imei = m5311_get_imei, + .get_imsi = m5311_get_imsi, + .get_iccid = m5311_get_iccid, + .get_cfun = m5311_get_cfun, + .set_cfun = m5311_set_cfun, + .gm_time = m5311_gm_time, }; #endif /* M5311_USING_GENERAL_OPS */ @@ -51,32 +51,32 @@ static const struct mo_general_ops gs_general_ops = { extern void m5311_netserv_init(mo_m5311_t *module); static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = m5311_set_attach, - .get_attach = m5311_get_attach, - .set_reg = m5311_set_reg, - .get_reg = m5311_get_reg, - .set_cgact = m5311_set_cgact, - .get_cgact = m5311_get_cgact, - .get_csq = m5311_get_csq, - .get_radio = m5311_get_radio, - .set_psm = m5311_set_psm, - .get_psm = m5311_get_psm, - .set_edrx_cfg = m5311_set_edrx_cfg, - .get_edrx_cfg = m5311_get_edrx_cfg, - .get_edrx_dynamic = m5311_get_edrx_dynamic, + .set_attach = m5311_set_attach, + .get_attach = m5311_get_attach, + .set_reg = m5311_set_reg, + .get_reg = m5311_get_reg, + .set_cgact = m5311_set_cgact, + .get_cgact = m5311_get_cgact, + .get_csq = m5311_get_csq, + .get_radio = m5311_get_radio, + .set_psm = m5311_set_psm, + .get_psm = m5311_get_psm, + .set_edrx_cfg = m5311_set_edrx_cfg, + .get_edrx_cfg = m5311_get_edrx_cfg, + .get_edrx_dynamic = m5311_get_edrx_dynamic, }; #endif /* M5311_USING_NETSERV_OPS */ #ifdef M5311_USING_PING_OPS static const struct mo_ping_ops gs_ping_ops = { - .ping = m5311_ping, + .ping = m5311_ping, }; #endif /* M5311_USING_PING_OPS */ #ifdef M5311_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = m5311_ifconfig, - .get_ipaddr = m5311_get_ipaddr, + .ifconfig = m5311_ifconfig, + .get_ipaddr = m5311_get_ipaddr, }; #endif /* M5311_USING_IFCONFIG_OPS */ @@ -84,14 +84,14 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void m5311_netconn_init(mo_m5311_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = m5311_netconn_create, - .destroy = m5311_netconn_destroy, + .create = m5311_netconn_create, + .destroy = m5311_netconn_destroy, #ifdef M5311_USING_DNS - .gethostbyname = m5311_netconn_gethostbyname, + .gethostbyname = m5311_netconn_gethostbyname, #endif - .connect = m5311_netconn_connect, - .send = m5311_netconn_send, - .get_info = m5311_netconn_get_info, + .connect = m5311_netconn_connect, + .send = m5311_netconn_send, + .get_info = m5311_netconn_get_info, }; #endif /* M5311_USING_NETCONN_OPS */ @@ -99,21 +99,21 @@ static const struct mo_netconn_ops gs_netconn_ops = { extern void m5311_onenetnb_init(mo_m5311_t *module); static const mo_onenet_ops_t gs_onenet_ops = { - .onenetnb_create = m5311_onenetnb_create, - .onenetnb_delete = m5311_onenetnb_delete, - .onenetnb_createex = m5311_onenetnb_createex, - .onenetnb_addobj = m5311_onenetnb_addobj, - .onenetnb_delobj = m5311_onenetnb_delobj, + .onenetnb_create = m5311_onenetnb_create, + .onenetnb_delete = m5311_onenetnb_delete, + .onenetnb_createex = m5311_onenetnb_createex, + .onenetnb_addobj = m5311_onenetnb_addobj, + .onenetnb_delobj = m5311_onenetnb_delobj, .onenetnb_discoverrsp = m5311_onenetnb_discoverrsp, - .onenetnb_nmi = m5311_onenetnb_set_nmi, - .onenetnb_open = m5311_onenetnb_open, - .onenetnb_close = m5311_onenetnb_close, - .onenetnb_notify = m5311_onenetnb_notify, - .onenetnb_update = m5311_onenetnb_update, - .onenetnb_get_write = m5311_onenetnb_get_write, - .onenetnb_writersp = m5311_onenetnb_writersp, + .onenetnb_nmi = m5311_onenetnb_set_nmi, + .onenetnb_open = m5311_onenetnb_open, + .onenetnb_close = m5311_onenetnb_close, + .onenetnb_notify = m5311_onenetnb_notify, + .onenetnb_update = m5311_onenetnb_update, + .onenetnb_get_write = m5311_onenetnb_get_write, + .onenetnb_writersp = m5311_onenetnb_writersp, #ifdef OS_USING_SHELL - .onenetnb_all = m5311_onenetnb_all, + .onenetnb_all = m5311_onenetnb_all, #endif }; #endif /* M5311_USING_ONENET_OPS */ @@ -124,15 +124,15 @@ static void urc_misc_func(struct at_parser *parser, const char *data, os_size_t } static at_urc_t m5311_misc_urc_table[] = { - {.prefix = "+IP:", .suffix = "\r\n", .func = urc_misc_func}, - {.prefix = "+CPIN:", .suffix = "\r\n", .func = urc_misc_func}, + {.prefix = "+IP:", .suffix = "\r\n", .func = urc_misc_func}, + {.prefix = "+CPIN:", .suffix = "\r\n", .func = urc_misc_func}, {.prefix = "*ATREADY:", .suffix = "\r\n", .func = urc_misc_func}, }; static os_err_t m5311_at_init(mo_object_t *self) { at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; at_parser_set_urc_table(parser, m5311_misc_urc_table, sizeof(m5311_misc_urc_table) / sizeof(at_urc_t)); @@ -144,16 +144,14 @@ static os_err_t m5311_at_init(mo_object_t *self) } char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; return at_parser_exec_cmd(parser, &resp, "ATE0"); } mo_object_t *module_m5311_create(const char *name, void *parser_config) { - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; mo_m5311_t *module = (mo_m5311_t *)os_calloc(1, sizeof(mo_m5311_t)); if (OS_NULL == module) { @@ -256,7 +254,7 @@ int m5311_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = M5311_NAME, + mo_parser_config_t parser_config = {.parser_name = M5311_NAME, .parser_device = device, .recv_buff_len = M5311_RECV_BUFF_LEN}; diff --git a/components/molink/module/m5311/source/m5311_general.c b/components/molink/module/m5311/source/m5311_general.c index 39c84766..d1abf10c 100644 --- a/components/molink/module/m5311/source/m5311_general.c +++ b/components/molink/module/m5311/source/m5311_general.c @@ -27,15 +27,14 @@ #include "mo_time.h" #define MO_LOG_TAG "m5311.general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef M5311_USING_GENERAL_OPS -#define M5311_GENERAL_TIMEOUT_DFT (2 * OS_TICK_PER_SECOND) -#define M5311_PSM_QUOTES_LEN (2) -#define M5311_TIMEZONE_STR_LEN_DEF (8) - +#define M5311_GENERAL_TIMEOUT_DFT (2 * OS_TICK_PER_SECOND) +#define M5311_PSM_QUOTES_LEN (2) +#define M5311_TIMEZONE_STR_LEN_DEF (8) os_err_t m5311_at_test(mo_object_t *self) { @@ -53,13 +52,13 @@ os_err_t m5311_get_imei(mo_object_t *self, char *value, os_size_t len) OS_ASSERT(len > MO_IMEI_LEN); at_parser_t *parser = &self->parser; - + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = M5311_GENERAL_TIMEOUT_DFT}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = M5311_GENERAL_TIMEOUT_DFT}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+GSN"); - if(result != OS_EOK) + if (result != OS_EOK) { return OS_ERROR; } @@ -171,12 +170,12 @@ os_err_t m5311_set_cfun(mo_object_t *self, os_uint8_t fun_lvl) os_err_t m5311_gm_time(mo_object_t *self, struct tm *l_tm) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - _mo_tm_t mo_tm = {0}; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; + _mo_tm_t mo_tm = {0}; char timezone_str[M5311_TIMEZONE_STR_LEN_DEF] = {0}; - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 90 * OS_TICK_PER_SECOND}; @@ -188,14 +187,16 @@ os_err_t m5311_gm_time(mo_object_t *self, struct tm *l_tm) } /* at least 6 parm required: yy/MM/dd,hh:mm:ss */ - if (6 >= at_resp_get_data_by_kw(&resp, "+CCLK:", "+CCLK: %d/%d/%d,%d:%d:%d%s", - &mo_tm.tm_year, + if (6 >= at_resp_get_data_by_kw(&resp, + "+CCLK:", + "+CCLK: %d/%d/%d,%d:%d:%d%s", + &mo_tm.tm_year, &mo_tm.tm_mon, &mo_tm.tm_mday, &mo_tm.tm_hour, &mo_tm.tm_min, &mo_tm.tm_sec, - timezone_str)) + timezone_str)) { ERROR("%s-%d:get local time failed", __func__, __LINE__); result = OS_ERROR; @@ -210,7 +211,7 @@ os_err_t m5311_gm_time(mo_object_t *self, struct tm *l_tm) { DEBUG("%s-%d:no timezone info passed by module.", __func__, __LINE__); } - else if (0 >= sscanf(timezone_str, "%d", &mo_tm.tm_q_off)) + else if (0 >= sscanf(timezone_str, "%d", &mo_tm.tm_q_off)) { WARN("%s-%d:parse timezone info failed.", __func__, __LINE__); } @@ -219,7 +220,8 @@ os_err_t m5311_gm_time(mo_object_t *self, struct tm *l_tm) __exit: - if (OS_EOK != result) memset(l_tm, 0, sizeof(struct tm)); + if (OS_EOK != result) + memset(l_tm, 0, sizeof(struct tm)); return result; } diff --git a/components/molink/module/m5311/source/m5311_ifconfig.c b/components/molink/module/m5311/source/m5311_ifconfig.c index 446f8af3..7b186104 100644 --- a/components/molink/module/m5311/source/m5311_ifconfig.c +++ b/components/molink/module/m5311/source/m5311_ifconfig.c @@ -30,7 +30,7 @@ #include "m5311_ifconfig.h" #define MO_LOG_TAG "m5311.ifconfig" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef M5311_USING_IFCONFIG_OPS @@ -40,14 +40,14 @@ os_err_t m5311_ifconfig(mo_object_t *self) { char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; - char imei[MO_IMEI_LEN + 1] = {0}; - char iccid[MO_ICCID_LEN + 1] = {0}; - char imsi[MO_IMSI_LEN + 1] = {0}; + char imei[MO_IMEI_LEN + 1] = {0}; + char iccid[MO_ICCID_LEN + 1] = {0}; + char imsi[MO_IMSI_LEN + 1] = {0}; - os_err_t ret = OS_EOK; + os_err_t ret = OS_EOK; os_uint8_t rssi = 0; - os_uint8_t ber = 0; - os_int32_t i = 0; + os_uint8_t ber = 0; + os_int32_t i = 0; if (m5311_get_ipaddr(self, ipaddr) != OS_EOK) { @@ -75,7 +75,7 @@ os_err_t m5311_ifconfig(mo_object_t *self) if (m5311_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; ret = OS_ERROR; } @@ -105,8 +105,8 @@ os_err_t m5311_ifconfig(mo_object_t *self) os_err_t m5311_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t ucid = M5311_IFCONFIG_INVALID_DEF; - os_int8_t len = M5311_IFCONFIG_INVALID_DEF; + os_int8_t ucid = M5311_IFCONFIG_INVALID_DEF; + os_int8_t len = M5311_IFCONFIG_INVALID_DEF; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; diff --git a/components/molink/module/m5311/source/m5311_netconn.c b/components/molink/module/m5311/source/m5311_netconn.c index 96754b06..f2658e41 100644 --- a/components/molink/module/m5311/source/m5311_netconn.c +++ b/components/molink/module/m5311/source/m5311_netconn.c @@ -33,27 +33,27 @@ #ifdef M5311_USING_NETCONN_OPS #define MO_LOG_TAG "m5311.netconn" -#define MO_LOG_LVL MO_LOG_EMERG +#define MO_LOG_LVL MO_LOG_EMERG #include "mo_log.h" #define M5311_NETCONN_TIMEOUT_DFT (2 * OS_TICK_PER_SECOND) -#define M5311_EVENT_CONN_OK (1L << 0) -#define M5311_EVENT_CONN_FAIL (1L << 1) -#define M5311_EVENT_DOMAIN_OK (1L << 2) -#define M5311_EVENT_DOMAIN_FAIL (1L << 3) +#define M5311_EVENT_CONN_OK (1L << 0) +#define M5311_EVENT_CONN_FAIL (1L << 1) +#define M5311_EVENT_DOMAIN_OK (1L << 2) +#define M5311_EVENT_DOMAIN_FAIL (1L << 3) -#define M5311_NETCONN_ID_INVALID (-1) -#define M5311_TCP_SEND_MAX_SIZE (720) -#define M5311_UDP_SEND_MAX_SIZE (712) -#define M5311_SEND_BLOCK_SIZE (64) +#define M5311_NETCONN_ID_INVALID (-1) +#define M5311_TCP_SEND_MAX_SIZE (720) +#define M5311_UDP_SEND_MAX_SIZE (712) +#define M5311_SEND_BLOCK_SIZE (64) -#define M5311_NETCONN_MQ_NAME "m5311_nc_mq" +#define M5311_NETCONN_MQ_NAME "m5311_nc_mq" #ifndef M5311_NETCONN_MQ_MSG_SIZE #define M5311_NETCONN_MQ_MSG_SIZE (sizeof(mo_notconn_msg_t)) #endif /* M5311_NETCONN_MQ_MSG_SIZE */ #ifndef M5311_NETCONN_MQ_MSG_MAX -#define M5311_NETCONN_MQ_MSG_MAX (5) +#define M5311_NETCONN_MQ_MSG_MAX (5) #endif /* M5311_NETCONN_MQ_MSG_MAX */ static os_err_t m5311_lock(os_mutex_t *mutex) @@ -120,16 +120,16 @@ os_err_t m5311_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); info->netconn_array = m5311->netconn; - info->netconn_nums = sizeof(m5311->netconn) / sizeof(m5311->netconn[0]); + info->netconn_nums = sizeof(m5311->netconn) / sizeof(m5311->netconn[0]); return OS_EOK; } mo_netconn_t *m5311_netconn_create(mo_object_t *module, mo_netconn_type_t type) { - mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); + mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; m5311_lock(&m5311->netconn_lock); @@ -160,9 +160,7 @@ mo_netconn_t *m5311_netconn_create(mo_object_t *module, mo_netconn_type_t type) return OS_NULL; } - netconn->mq = os_mq_create(M5311_NETCONN_MQ_NAME, - M5311_NETCONN_MQ_MSG_SIZE, - M5311_NETCONN_MQ_MSG_MAX); + netconn->mq = os_mq_create(M5311_NETCONN_MQ_NAME, M5311_NETCONN_MQ_MSG_SIZE, M5311_NETCONN_MQ_MSG_MAX); if (OS_NULL == netconn->mq) { ERROR("%s message queue create failed, no enough memory.", module->name); @@ -180,7 +178,7 @@ mo_netconn_t *m5311_netconn_create(mo_object_t *module, mo_netconn_type_t type) os_err_t m5311_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; INFO("Module %s in %d netconn status", module->name, netconn->stat); @@ -195,8 +193,8 @@ os_err_t m5311_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) if (result != OS_EOK) { ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + module->name, + (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); return result; } break; @@ -211,8 +209,8 @@ os_err_t m5311_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) netconn->mq = OS_NULL; } - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); @@ -224,17 +222,15 @@ os_err_t m5311_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) #ifdef M5311_USING_DNS os_err_t m5311_netconn_gethostbyname(mo_object_t *module, const char *domain_name, ip_addr_t *addr) { - os_err_t result = OS_EOK; - os_uint32_t event = 0; + os_err_t result = OS_EOK; + os_uint32_t event = 0; at_parser_t *parser = &module->parser; - mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); + mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); char resp_buff[4 * AT_RESP_BUFF_SIZE_DEF] = {0}; - char addr_str[IPADDR_MAX_STR_LEN + 1] = {0}; + char addr_str[IPADDR_MAX_STR_LEN + 1] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 20 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; m5311_lock(&m5311->netconn_lock); @@ -301,16 +297,16 @@ __exit: #ifdef M5311_USING_TCP static os_err_t m5311_tcp_connect(mo_object_t *module, os_int32_t connect_id, char *ip_addr, os_uint16_t port) { - os_err_t result = OS_EOK; - os_uint32_t event = 0; + os_err_t result = OS_EOK; + os_uint32_t event = 0; at_parser_t *parser = &module->parser; - mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); + mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); char resp_buff[2 * AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .timeout = 41 * OS_TICK_PER_SECOND}; /* about 40s return failed */ + .timeout = 41 * OS_TICK_PER_SECOND}; /* about 40s return failed */ /* M5311 return 'CONNECT OK' behind 'OK' without id. so we add lock for mutithread. */ m5311_lock(&m5311->netconn_lock); @@ -368,7 +364,7 @@ static os_err_t m5311_udp_connect(mo_object_t *module, os_int32_t connect_id, ch os_err_t m5311_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port) { - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -401,7 +397,7 @@ os_err_t m5311_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ad ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%hu successfully!", module->name, remote_ip, port); @@ -410,14 +406,15 @@ os_err_t m5311_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ad static os_size_t m5311_single_packet_send(at_parser_t *parser, const char *data, os_size_t size) { - os_size_t sent_size = 0; /* raw data sent size */ - os_size_t curr_pkt_size = 0; /* raw data current packet size */ + os_size_t sent_size = 0; /* raw data sent size */ + os_size_t curr_pkt_size = 0; /* raw data current packet size */ char hex_str_buff[M5311_SEND_BLOCK_SIZE] = {0}; while (size > sent_size) { - curr_pkt_size = (size - sent_size) < (M5311_SEND_BLOCK_SIZE / 2) ? (size - sent_size) : M5311_SEND_BLOCK_SIZE / 2; + curr_pkt_size = + (size - sent_size) < (M5311_SEND_BLOCK_SIZE / 2) ? (size - sent_size) : M5311_SEND_BLOCK_SIZE / 2; bytes_to_hexstr(data + sent_size, hex_str_buff, curr_pkt_size); @@ -436,19 +433,20 @@ __exit: static os_size_t m5311_hexdata_send(at_parser_t *parser, mo_netconn_t *netconn, const char *data, os_size_t size) { - os_err_t result = OS_EOK; - os_int32_t connect_id = M5311_NETCONN_ID_INVALID; - os_size_t sent_size = 0; - os_size_t cur_pkt_size = 0; - os_size_t cnt = 0; + os_err_t result = OS_EOK; + os_int32_t connect_id = M5311_NETCONN_ID_INVALID; + os_size_t sent_size = 0; + os_size_t cur_pkt_size = 0; + os_size_t cnt = 0; char prefix_send_cmd[AT_RESP_BUFF_SIZE_DEF] = {0}; char suffix_send_cmd[AT_RESP_BUFF_SIZE_DEF] = {0}; - char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = AT_RESP_BUFF_SIZE_DEF, .timeout = 10 * OS_TICK_PER_SECOND}; + char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + at_resp_t resp = {.buff = resp_buff, .buff_size = AT_RESP_BUFF_SIZE_DEF, .timeout = 10 * OS_TICK_PER_SECOND}; /* M5311 UDP send size <= 712, different from the spec size 720 */ - const os_int32_t send_max_size = netconn->type == NETCONN_TYPE_TCP ? M5311_TCP_SEND_MAX_SIZE : M5311_UDP_SEND_MAX_SIZE; + const os_int32_t send_max_size = + netconn->type == NETCONN_TYPE_TCP ? M5311_TCP_SEND_MAX_SIZE : M5311_UDP_SEND_MAX_SIZE; strncpy(remote_ip, inet_ntoa(netconn->remote_ip), IPADDR_MAX_STR_LEN); @@ -521,10 +519,7 @@ __exit: if (result != OS_EOK) { - ERROR("Module %s netconn %d send %d bytes data failed!", - parser->name, - netconn->connect_id, - cur_pkt_size); + ERROR("Module %s netconn %d send %d bytes data failed!", parser->name, netconn->connect_id, cur_pkt_size); return 0; } @@ -534,9 +529,9 @@ __exit: os_size_t m5311_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_size_t sent_size = 0; - mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); + at_parser_t *parser = &module->parser; + os_size_t sent_size = 0; + mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); if (OS_EOK != m5311_lock(&m5311->netconn_lock)) { @@ -593,7 +588,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = M5311_NETCONN_ID_INVALID; - os_int32_t data_size = 0; + os_int32_t data_size = 0; sscanf(data, "+IPRD: %d,%d,", &connect_id, &data_size); INFO("Moudle %s netconn %d receive %d bytes data", parser->name, connect_id, data_size); @@ -642,9 +637,9 @@ static void urc_dns_func(struct at_parser *parser, const char *data, os_size_t s OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); + mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); char ret_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; if (OS_NULL == m5311->netconn_data) @@ -692,7 +687,7 @@ static void urc_connect_func(struct at_parser *parser, const char *data, os_size OS_ASSERT(OS_NULL != data); mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); + mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); if (OS_NULL != strstr(data, "CONNECT OK")) { @@ -707,10 +702,10 @@ static void urc_connect_func(struct at_parser *parser, const char *data, os_size } static at_urc_t nc_urc_table[] = { - {.prefix = "+IPCLOSE:", .suffix = "\r\n", .func = urc_close_func }, - {.prefix = "+IPRD:", .suffix = "\r\n", .func = urc_recv_func }, - {.prefix = "+CMDNS:", .suffix = "\r\n", .func = urc_dns_func }, - {.prefix = "CONNECT OK", .suffix = "\r\n", .func = urc_connect_func}, + {.prefix = "+IPCLOSE:", .suffix = "\r\n", .func = urc_close_func}, + {.prefix = "+IPRD:", .suffix = "\r\n", .func = urc_recv_func}, + {.prefix = "+CMDNS:", .suffix = "\r\n", .func = urc_dns_func}, + {.prefix = "CONNECT OK", .suffix = "\r\n", .func = urc_connect_func}, {.prefix = "CONNECT FAIL", .suffix = "\r\n", .func = urc_connect_func}, }; diff --git a/components/molink/module/m5311/source/m5311_netserv.c b/components/molink/module/m5311/source/m5311_netserv.c index 38cf6d3c..6021cc9b 100644 --- a/components/molink/module/m5311/source/m5311_netserv.c +++ b/components/molink/module/m5311/source/m5311_netserv.c @@ -29,7 +29,7 @@ #include #define MO_LOG_TAG "m5311.netserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef M5311_USING_NETSERV_OPS @@ -65,7 +65,7 @@ os_err_t m5311_get_attach(mo_object_t *self, os_uint8_t *attach_stat) return OS_ERROR; } - if(0 >= at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat)) + if (0 >= at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat)) { ERROR("Get %s module attach state failed", self->name); return OS_ERROR; @@ -172,7 +172,7 @@ os_err_t m5311_get_radio(mo_object_t *self, radio_info_t *radio_info) at_parser_t *parser = &self->parser; memset(radio_info, 0, sizeof(radio_info_t)); - + char resp_buff[4 * AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = M5311_NETSERV_TIMEOUT_DFT}; @@ -182,16 +182,18 @@ os_err_t m5311_get_radio(mo_object_t *self, radio_info_t *radio_info) { goto __exit; } - + /* return eg: *ENGINFOSC: 3684,2,131,"85B0F15"\n,-107,-13,-93,-3,8,"5A21",0, */ /* ,,,, [],[],[],[],,,[],[] */ - if (0 >= at_resp_get_data_by_kw(&resp, "*ENGINFOSC:", M5311_NETSTAT_REGEX, - &radio_info->earfcn, - &radio_info->cell_id, - &radio_info->rsrq, - &radio_info->snr, - &radio_info->ecl)) + if (0 >= at_resp_get_data_by_kw(&resp, + "*ENGINFOSC:", + M5311_NETSTAT_REGEX, + &radio_info->earfcn, + &radio_info->cell_id, + &radio_info->rsrq, + &radio_info->snr, + &radio_info->ecl)) { ERROR("Get %s module radio_info failed", self->name); result = OS_ERROR; @@ -206,12 +208,12 @@ __exit: os_err_t m5311_set_psm(mo_object_t *self, mo_psm_info_t info) { at_parser_t *parser = &self->parser; - + /* M5311 needs double quotes */ - os_int8_t periodic_rau[PSM_TIMER_MAX_STR_LEN + M5311_PSM_QUOTES_LEN] = {0}; + os_int8_t periodic_rau[PSM_TIMER_MAX_STR_LEN + M5311_PSM_QUOTES_LEN] = {0}; os_int8_t gprs_ready_timer[PSM_TIMER_MAX_STR_LEN + M5311_PSM_QUOTES_LEN] = {0}; - os_int8_t periodic_tau[PSM_TIMER_MAX_STR_LEN + M5311_PSM_QUOTES_LEN] = {0}; - os_int8_t active_time[PSM_TIMER_MAX_STR_LEN + M5311_PSM_QUOTES_LEN] = {0}; + os_int8_t periodic_tau[PSM_TIMER_MAX_STR_LEN + M5311_PSM_QUOTES_LEN] = {0}; + os_int8_t active_time[PSM_TIMER_MAX_STR_LEN + M5311_PSM_QUOTES_LEN] = {0}; /* only insert double quotes when the value is valid */ if (0 != strlen(info.periodic_rau)) @@ -227,12 +229,14 @@ os_err_t m5311_set_psm(mo_object_t *self, mo_psm_info_t info) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = M5311_NETSERV_TIMEOUT_DFT}; - return at_parser_exec_cmd(parser, &resp, "AT+CPSMS=%d,%s,%s,%s,%s", - info.psm_mode, - periodic_rau, - gprs_ready_timer, - periodic_tau, - active_time); + return at_parser_exec_cmd(parser, + &resp, + "AT+CPSMS=%d,%s,%s,%s,%s", + info.psm_mode, + periodic_rau, + gprs_ready_timer, + periodic_tau, + active_time); } os_err_t m5311_get_psm(mo_object_t *self, mo_psm_info_t *info) @@ -251,7 +255,12 @@ os_err_t m5311_get_psm(mo_object_t *self, mo_psm_info_t *info) memset(info, 0, sizeof(mo_psm_info_t)); - if (0 >= at_resp_get_data_by_kw(&resp, "+CPSMS", "+CPSMS: %d,,,\"%[^\"]\",\"%[^\"]", &info->psm_mode, info->periodic_tau, info->active_time)) + if (0 >= at_resp_get_data_by_kw(&resp, + "+CPSMS", + "+CPSMS: %d,,,\"%[^\"]\",\"%[^\"]", + &info->psm_mode, + info->periodic_tau, + info->active_time)) { ERROR("Get %s module psm info failed", self->name); return OS_ERROR; @@ -263,14 +272,12 @@ os_err_t m5311_get_psm(mo_object_t *self, mo_psm_info_t *info) os_err_t m5311_set_edrx_cfg(mo_object_t *self, mo_edrx_cfg_t cfg) { at_parser_t *parser = &self->parser; - + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = M5311_NETSERV_TIMEOUT_DFT}; - return at_parser_exec_cmd(parser, &resp, "AT+CEDRXS=%d,5,%s", - cfg.mode, - cfg.edrx.req_edrx_value); + return at_parser_exec_cmd(parser, &resp, "AT+CEDRXS=%d,5,%s", cfg.mode, cfg.edrx.req_edrx_value); } os_err_t m5311_get_edrx_cfg(mo_object_t *self, mo_edrx_t *edrx_local) @@ -289,9 +296,11 @@ os_err_t m5311_get_edrx_cfg(mo_object_t *self, mo_edrx_t *edrx_local) memset(edrx_local, 0, sizeof(mo_edrx_t)); - if (0 >= at_resp_get_data_by_kw(&resp, "+CEDRXS", "+CEDRXS: %d,\"%[^\"]", - &edrx_local->act_type, - edrx_local->req_edrx_value)) + if (0 >= at_resp_get_data_by_kw(&resp, + "+CEDRXS", + "+CEDRXS: %d,\"%[^\"]", + &edrx_local->act_type, + edrx_local->req_edrx_value)) { ERROR("Get %s module edrx local config failed", self->name); return OS_ERROR; @@ -316,11 +325,13 @@ os_err_t m5311_get_edrx_dynamic(mo_object_t *self, mo_edrx_t *edrx_dynamic) memset(edrx_dynamic, 0, sizeof(mo_edrx_t)); - if (0 >= at_resp_get_data_by_kw(&resp, "+CEDRXRDP", "+CEDRXRDP: %d,\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"", - &edrx_dynamic->act_type, - edrx_dynamic->req_edrx_value, - edrx_dynamic->nw_edrx_value, - edrx_dynamic->paging_time_window)) + if (0 >= at_resp_get_data_by_kw(&resp, + "+CEDRXRDP", + "+CEDRXRDP: %d,\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"", + &edrx_dynamic->act_type, + edrx_dynamic->req_edrx_value, + edrx_dynamic->nw_edrx_value, + edrx_dynamic->paging_time_window)) { ERROR("Get %s module edrx dynamic config failed", self->name); return OS_ERROR; @@ -475,11 +486,12 @@ void m5311_edrx_urc_handler(struct at_parser *parser, const char *data, os_size_ mo_edrx_t edrx_urc; memset(&edrx_urc, 0, sizeof(mo_edrx_t)); - sscanf(data, "+CEDRXP: %d,\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"", - (int *)&edrx_urc.act_type, - edrx_urc.req_edrx_value, - edrx_urc.nw_edrx_value, - edrx_urc.paging_time_window); + sscanf(data, + "+CEDRXP: %d,\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"", + (int *)&edrx_urc.act_type, + edrx_urc.req_edrx_value, + edrx_urc.nw_edrx_value, + edrx_urc.paging_time_window); INFO("Get %s module edrx urc act_type[%d]", parser->name, edrx_urc.act_type); INFO("Get %s module edrx urc req_edrx_value[%s]", parser->name, edrx_urc.req_edrx_value); INFO("Get %s module edrx urc nw_edrx_value[%s]", parser->name, edrx_urc.nw_edrx_value); @@ -490,7 +502,7 @@ void m5311_edrx_urc_handler(struct at_parser *parser, const char *data, os_size_ static at_urc_t m5311_netserv_urc_table[] = { {.prefix = "NO CARRIER", .suffix = "\r\n", .func = m5311_pdp_urc_handler}, - {.prefix = "+CEDRXP:", .suffix = "\r\n", .func = m5311_edrx_urc_handler}, + {.prefix = "+CEDRXP:", .suffix = "\r\n", .func = m5311_edrx_urc_handler}, }; void m5311_netserv_init(mo_m5311_t *module) diff --git a/components/molink/module/m5311/source/m5311_onenet_nb.c b/components/molink/module/m5311/source/m5311_onenet_nb.c index 4c14ce81..4ce83434 100644 --- a/components/molink/module/m5311/source/m5311_onenet_nb.c +++ b/components/molink/module/m5311/source/m5311_onenet_nb.c @@ -30,7 +30,7 @@ #include #define MO_LOG_TAG "m5311.onenet_nb" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define M5311_ONENET_EVENTID_BOOTSTRAP_OK (2) @@ -43,15 +43,15 @@ #define M5311_ONENET_EVENTID_DELETE_BY_PLATFORM (31) #define M5311_ONENET_EVENTID_DTLS_IP_AGINT (32) -#define M5311_ONENET_EVENT_BOOTSTRAP_OK (1L << 0) -#define M5311_ONENET_EVENT_BOOTSTRAP_FAIL (1L << 1) -#define M5311_ONENET_EVENT_REG_OK (1L << 2) -#define M5311_ONENET_EVENT_REG_FAIL (1L << 3) -#define M5311_ONENET_EVENT_UPDATE_OK (1L << 4) -#define M5311_ONENET_EVENT_LOGOUT (1L << 5) -#define M5311_ONENET_EVENT_NOTIFY_OK (1L << 6) -#define M5311_ONENET_EVENT_DELETE_BY_PLATFORM (1L << 7) -#define M5311_ONENET_EVENT_DTLS_IP_AGINT (1L << 8) +#define M5311_ONENET_EVENT_BOOTSTRAP_OK (1L << 0) +#define M5311_ONENET_EVENT_BOOTSTRAP_FAIL (1L << 1) +#define M5311_ONENET_EVENT_REG_OK (1L << 2) +#define M5311_ONENET_EVENT_REG_FAIL (1L << 3) +#define M5311_ONENET_EVENT_UPDATE_OK (1L << 4) +#define M5311_ONENET_EVENT_LOGOUT (1L << 5) +#define M5311_ONENET_EVENT_NOTIFY_OK (1L << 6) +#define M5311_ONENET_EVENT_DELETE_BY_PLATFORM (1L << 7) +#define M5311_ONENET_EVENT_DTLS_IP_AGINT (1L << 8) static os_err_t m5311_nb_lock(os_mutex_t *mutex) { @@ -69,12 +69,12 @@ DEFINE_M5311_ONENET_FUNC(m5311_onenetnb_create, ONENET_NB_FUNC_ARGS) OS_ASSERT(resp != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; - os_uint8_t ref = 0; + os_err_t result = OS_ERROR; + os_uint8_t ref = 0; at_parser_t *parser = &module->parser; char tmp_format[AT_RESP_BUFF_SIZE_128] = "AT+MIPLCREATE="; - char resp_buff [AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); @@ -104,7 +104,7 @@ DEFINE_M5311_ONENET_FUNC(m5311_onenetnb_delete, ONENET_NB_FUNC_ARGS) at_parser_t *parser = &module->parser; char tmp_format[AT_RESP_BUFF_SIZE_DEF] = "AT+MIPLDELETE="; - char resp_buff [AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); @@ -119,13 +119,13 @@ DEFINE_M5311_ONENET_FUNC(m5311_onenetnb_createex, ONENET_NB_FUNC_ARGS) OS_ASSERT(resp != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = &module->parser; os_uint8_t ref = 0; char tmp_format[AT_RESP_BUFF_SIZE_DEF] = "AT+MIPLCREATEEX="; - char resp_buff [AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); @@ -155,7 +155,7 @@ DEFINE_M5311_ONENET_FUNC(m5311_onenetnb_addobj, ONENET_NB_FUNC_ARGS) at_parser_t *parser = &module->parser; char tmp_format[AT_RESP_BUFF_SIZE_DEF] = "AT+MIPLADDOBJ="; - char resp_buff [AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); @@ -172,7 +172,7 @@ DEFINE_M5311_ONENET_FUNC(m5311_onenetnb_delobj, ONENET_NB_FUNC_ARGS) at_parser_t *parser = &module->parser; char tmp_format[AT_RESP_BUFF_SIZE_DEF] = "AT+MIPLDELOBJ="; - char resp_buff [AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); @@ -186,11 +186,11 @@ DEFINE_M5311_ONENET_FUNC(m5311_onenetnb_discoverrsp, ONENET_NB_FUNC_ARGS) OS_ASSERT(module != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = &module->parser; char tmp_format[AT_RESP_BUFF_SIZE_128] = "AT+MIPLDISCOVERRSP="; - char resp_buff [AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); @@ -209,11 +209,11 @@ DEFINE_M5311_ONENET_FUNC(m5311_onenetnb_set_nmi, ONENET_NB_FUNC_ARGS) OS_ASSERT(module != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = &module->parser; char tmp_format[AT_RESP_BUFF_SIZE_DEF] = "AT+MIPLNMI="; - char resp_buff [AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); @@ -232,21 +232,19 @@ DEFINE_M5311_ONENET_FUNC(m5311_onenetnb_open, ONENET_NB_FUNC_ARGS) OS_ASSERT(module != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; - os_uint32_t event = 0; + os_err_t result = OS_ERROR; + os_uint32_t event = 0; at_parser_t *parser = &module->parser; - mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); + mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); m5311_nb_lock(&m5311->onenetnb_lock); char tmp_format[AT_RESP_BUFF_SIZE_DEF] = "AT+MIPLOPEN="; - char resp_buff [AT_RESP_BUFF_SIZE_128] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_128] = {0}; strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = os_tick_from_ms(timeout)}; + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = os_tick_from_ms(timeout)}; os_event_clear(&m5311->onenetnb_evt, M5311_ONENET_EVENT_REG_OK | M5311_ONENET_EVENT_REG_FAIL); @@ -291,21 +289,19 @@ DEFINE_M5311_ONENET_FUNC(m5311_onenetnb_close, ONENET_NB_FUNC_ARGS) OS_ASSERT(module != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; - os_uint32_t event = 0; + os_err_t result = OS_ERROR; + os_uint32_t event = 0; at_parser_t *parser = &module->parser; - mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); + mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); m5311_nb_lock(&m5311->onenetnb_lock); char tmp_format[AT_RESP_BUFF_SIZE_DEF] = "AT+MIPLCLOSE="; - char resp_buff [AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = os_tick_from_ms(timeout)}; + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = os_tick_from_ms(timeout)}; os_event_clear(&m5311->onenetnb_evt, M5311_ONENET_EVENT_LOGOUT); @@ -342,8 +338,8 @@ __exit: os_err_t m5311_get_onenetnb_notify_ackid(const char *format, va_list args, os_uint16_t *id) { /* if has ackid, must be the 11 element */ - int num_count = 1; - os_int32_t id_tmp = -1; + int num_count = 1; + os_int32_t id_tmp = -1; os_uint8_t qualifier; for (; *format; ++format) @@ -433,21 +429,19 @@ DEFINE_M5311_ONENET_FUNC(m5311_onenetnb_notify, ONENET_NB_FUNC_ARGS) OS_ASSERT(module != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; - os_uint32_t event = 0; + os_err_t result = OS_ERROR; + os_uint32_t event = 0; at_parser_t *parser = &module->parser; - mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); + mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); m5311_nb_lock(&m5311->onenetnb_lock); - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; char tmp_format[AT_RESP_BUFF_SIZE_128] = "AT+MIPLNOTIFY="; strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = os_tick_from_ms(timeout)}; + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = os_tick_from_ms(timeout)}; os_event_clear(&m5311->onenetnb_evt, M5311_ONENET_EVENT_NOTIFY_OK); @@ -486,10 +480,10 @@ DEFINE_M5311_ONENET_FUNC(m5311_onenetnb_update, ONENET_NB_FUNC_ARGS) OS_ASSERT(module != OS_NULL); OS_ASSERT(format != OS_NULL); - at_parser_t *parser = &module->parser; + at_parser_t *parser = &module->parser; char tmp_format[AT_RESP_BUFF_SIZE_DEF] = "AT+MIPLUPDATE="; - char resp_buff [AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); @@ -510,11 +504,11 @@ DEFINE_M5311_ONENET_FUNC(m5311_onenetnb_get_write, ONENET_NB_FUNC_ARGS) return OS_ERROR; } - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = &module->parser; char tmp_format[AT_RESP_BUFF_SIZE_128] = "AT+MIPLMGR="; - char resp_buff [AT_RESP_BUFF_SIZE_256] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; strncpy(tmp_format + strlen(tmp_format), format, strlen(format)); @@ -551,7 +545,7 @@ DEFINE_M5311_ONENET_FUNC(m5311_onenetnb_writersp, ONENET_NB_FUNC_ARGS) OS_ASSERT(module != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = &module->parser; char tmp_format[128] = "AT+MIPLWRITERSP="; @@ -575,7 +569,7 @@ DEFINE_M5311_ONENET_FUNC(m5311_onenetnb_get_nmi, ONENET_NB_FUNC_ARGS) OS_ASSERT(module != OS_NULL); OS_ASSERT(resp != OS_NULL); - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = &module->parser; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -595,7 +589,7 @@ DEFINE_M5311_ONENET_FUNC(m5311_onenetnb_get_nmi, ONENET_NB_FUNC_ARGS) { goto __exit; } - ((m5311_nmi_t *)resp)->ref = ref; + ((m5311_nmi_t *)resp)->ref = ref; ((m5311_nmi_t *)resp)->nnmi = nnmi; ((m5311_nmi_t *)resp)->nsmi = nsmi; @@ -612,9 +606,9 @@ static void urc_onenetnb_miplnsmi_msg_func(struct at_parser *parser, const char OS_ASSERT(OS_NULL != data); mo_object_t *module = os_container_of(parser, mo_object_t, parser); - os_int32_t ref = 0; - os_int32_t status = 0; - os_int32_t num = 0; + os_int32_t ref = 0; + os_int32_t status = 0; + os_int32_t num = 0; if (0 >= sscanf(data, "+MIPLNSMI:%d,%d,%d", &ref, &status, &num)) { @@ -640,9 +634,9 @@ static void urc_onenetnb_evt_recv_func(struct at_parser *parser, const char *dat OS_ASSERT(OS_NULL != data); mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); - os_int32_t ref = 0; - os_int32_t evtid = 0; + mo_m5311_t *m5311 = os_container_of(module, mo_m5311_t, parent); + os_int32_t ref = 0; + os_int32_t evtid = 0; /* +MIPLEVENT:0,2\r\n */ if (0 >= sscanf(data, "+MIPLEVENT:%d,%d", &ref, &evtid)) @@ -702,8 +696,8 @@ static void urc_onenetnb_evt_recv_func(struct at_parser *parser, const char *dat } static at_urc_t onenet_nb_urc_table[] = { - {.prefix = "+MIPLEVENT:", .suffix = "\r\n", .func = urc_onenetnb_evt_recv_func}, - {.prefix = "+MIPLNSMI:", .suffix = "\r\n", .func = urc_onenetnb_miplnsmi_msg_func}, + {.prefix = "+MIPLEVENT:", .suffix = "\r\n", .func = urc_onenetnb_evt_recv_func}, + {.prefix = "+MIPLNSMI:", .suffix = "\r\n", .func = urc_onenetnb_miplnsmi_msg_func}, }; void m5311_onenetnb_init(mo_m5311_t *module) @@ -719,7 +713,7 @@ DEFINE_M5311_ONENET_FUNC(m5311_onenetnb_all, ONENET_NB_FUNC_ARGS) OS_ASSERT(module != OS_NULL); OS_ASSERT(format != OS_NULL); - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_parser_t *parser = &module->parser; char resp_buff[256] = {0}; diff --git a/components/molink/module/m5311/source/m5311_ping.c b/components/molink/module/m5311/source/m5311_ping.c index 6f6e2edd..19035f60 100644 --- a/components/molink/module/m5311/source/m5311_ping.c +++ b/components/molink/module/m5311/source/m5311_ping.c @@ -24,7 +24,7 @@ #include "m5311_ping.h" #define MO_LOG_TAG "m5311.ping" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define M5311_MIN_PING_PKG_LEN (8) @@ -34,12 +34,12 @@ os_err_t m5311_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - os_uint32_t req_time = 0; - os_int16_t ttl = -1; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; + os_uint32_t req_time = 0; + os_int16_t ttl = -1; - char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; + char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; char ret_buff[2 * AT_RESP_BUFF_SIZE_DEF] = {0}; if (parser == OS_NULL) @@ -51,7 +51,9 @@ os_err_t m5311_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uin if ((len < M5311_MIN_PING_PKG_LEN) || (len > M5311_MAX_PING_PKG_LEN)) { ERROR("M5311 ping: ping package len[%hu] is out of range[%d, %d].", - len, M5311_MIN_PING_PKG_LEN, M5311_MAX_PING_PKG_LEN); + len, + M5311_MIN_PING_PKG_LEN, + M5311_MAX_PING_PKG_LEN); return OS_ERROR; } @@ -61,10 +63,10 @@ os_err_t m5311_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uin /* Need to wait for 5 lines response msg */ char resp_buff[4 * AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .line_num = 5, - .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; + at_resp_t at_resp = {.buff = resp_buff, + .buff_size = sizeof(resp_buff), + .line_num = 5, + .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; /* Exec commond "AT+PING="www.baidu.com",32,2000,1 and wait response */ /* Return: success: +PING: 39.156.66.14,49,1206 fail: +PINGERR: 1 */ @@ -99,9 +101,9 @@ os_err_t m5311_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uin { inet_aton(ipaddr, &(resp->ip_addr)); resp->data_len = len; - resp->ttl = ttl; - resp->time = req_time; - result = OS_EOK; + resp->ttl = ttl; + resp->time = req_time; + result = OS_EOK; } } diff --git a/components/molink/module/mb26/include/mb26.h b/components/molink/module/mb26/include/mb26.h index b4055422..bafd3c61 100644 --- a/components/molink/module/mb26/include/mb26.h +++ b/components/molink/module/mb26/include/mb26.h @@ -73,12 +73,12 @@ typedef struct mo_mb26 mo_object_t parent; #ifdef MB26_USING_NETCONN_OPS mo_netconn_t netconn[MB26_NETCONN_NUM]; - os_mutex_t netconn_lock; + os_mutex_t netconn_lock; #endif /* MB26_USING_NETCONN_OPS */ } mo_mb26_t; mo_object_t *module_mb26_create(const char *name, void *parser_config); -os_err_t module_mb26_destroy(mo_object_t *self); +os_err_t module_mb26_destroy(mo_object_t *self); #endif /* MOLINK_USING_MB26 */ diff --git a/components/molink/module/mb26/include/mb26_netconn.h b/components/molink/module/mb26/include/mb26_netconn.h index 38c3db22..902d6d81 100644 --- a/components/molink/module/mb26/include/mb26_netconn.h +++ b/components/molink/module/mb26/include/mb26_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef MB26_USING_NETCONN_OPS -os_err_t mb26_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t mb26_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *mb26_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t mb26_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t mb26_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t mb26_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t mb26_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t mb26_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t mb26_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef MB26_USING_DNS -os_err_t mb26_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t mb26_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* MB26_USING_NETCONN_OPS */ diff --git a/components/molink/module/mb26/source/mb26.c b/components/molink/module/mb26/source/mb26.c index 8b0d1ed0..f8769484 100644 --- a/components/molink/module/mb26/source/mb26.c +++ b/components/molink/module/mb26/source/mb26.c @@ -36,39 +36,39 @@ #ifdef MB26_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = mb26_at_test, - .get_imei = mb26_get_imei, - .get_imsi = mb26_get_imsi, - .get_iccid = mb26_get_iccid, - .get_cfun = mb26_get_cfun, - .set_cfun = mb26_set_cfun, + .at_test = mb26_at_test, + .get_imei = mb26_get_imei, + .get_imsi = mb26_get_imsi, + .get_iccid = mb26_get_iccid, + .get_cfun = mb26_get_cfun, + .set_cfun = mb26_set_cfun, .get_firmware_version = mb26_get_firmware_version, }; #endif /* MB26_USING_GENERAL_OPS */ #ifdef MB26_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = mb26_set_attach, - .get_attach = mb26_get_attach, - .set_reg = mb26_set_reg, - .get_reg = mb26_get_reg, - .set_cgact = mb26_set_cgact, - .get_cgact = mb26_get_cgact, - .get_csq = mb26_get_csq, - .get_radio = mb26_get_radio, + .set_attach = mb26_set_attach, + .get_attach = mb26_get_attach, + .set_reg = mb26_set_reg, + .get_reg = mb26_get_reg, + .set_cgact = mb26_set_cgact, + .get_cgact = mb26_get_cgact, + .get_csq = mb26_get_csq, + .get_radio = mb26_get_radio, }; #endif /* MB26_USING_NETSERV_OPS */ #ifdef MB26_USING_PING_OPS static const struct mo_ping_ops gs_ping_ops = { - .ping = mb26_ping, + .ping = mb26_ping, }; #endif /* MB26_USING_PING_OPS */ #ifdef MB26_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = mb26_ifconfig, - .get_ipaddr = mb26_get_ipaddr, + .ifconfig = mb26_ifconfig, + .get_ipaddr = mb26_get_ipaddr, }; #endif /* MB26_USING_IFCONFIG_OPS */ @@ -76,14 +76,14 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void mb26_netconn_init(mo_mb26_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = mb26_netconn_create, - .destroy = mb26_netconn_destroy, + .create = mb26_netconn_create, + .destroy = mb26_netconn_destroy, #ifdef MB26_USING_DNSs - .gethostbyname = mb26_netconn_gethostbyname, + .gethostbyname = mb26_netconn_gethostbyname, #endif - .connect = mb26_netconn_connect, - .send = mb26_netconn_send, - .get_info = mb26_netconn_get_info, + .connect = mb26_netconn_connect, + .send = mb26_netconn_send, + .get_info = mb26_netconn_get_info, }; #endif /* MB26_USING_NETCONN_OPS */ @@ -100,9 +100,7 @@ static os_err_t mb26_at_init(mo_object_t *self) char resp_buff[32] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 3 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 3 * OS_TICK_PER_SECOND}; result = at_parser_exec_cmd(parser, &resp, "ATE0"); if (result != OS_EOK) @@ -209,7 +207,7 @@ int mb26_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = MB26_NAME, + mo_parser_config_t parser_config = {.parser_name = MB26_NAME, .parser_device = device, .recv_buff_len = MB26_RECV_BUFF_LEN}; diff --git a/components/molink/module/mb26/source/mb26_general.c b/components/molink/module/mb26/source/mb26_general.c index e86aac99..74cb2882 100644 --- a/components/molink/module/mb26/source/mb26_general.c +++ b/components/molink/module/mb26/source/mb26_general.c @@ -166,13 +166,11 @@ os_err_t mb26_set_cfun(mo_object_t *self, os_uint8_t fun_lvl) os_err_t mb26_get_firmware_version(mo_object_t *self, mo_firmware_version_t *version) { - at_parser_t *parser = &self->parser; + at_parser_t *parser = &self->parser; char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 5 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CGMR"); if (result != OS_EOK) @@ -193,7 +191,7 @@ os_err_t mb26_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ver for (int i = 3; i <= resp.line_counts - 2; i++) { const char *source_line = at_resp_get_line(&resp, i); - os_size_t line_length = strlen(source_line); + os_size_t line_length = strlen(source_line); char **dest_line = &version->ver_info[version->line_counts]; @@ -205,7 +203,7 @@ os_err_t mb26_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ver } strncpy(*dest_line, source_line, line_length); - version->line_counts ++; + version->line_counts++; } return OS_EOK; diff --git a/components/molink/module/mb26/source/mb26_ifconfig.c b/components/molink/module/mb26/source/mb26_ifconfig.c index 5ab9287b..056ce15b 100644 --- a/components/molink/module/mb26/source/mb26_ifconfig.c +++ b/components/molink/module/mb26/source/mb26_ifconfig.c @@ -38,12 +38,12 @@ os_err_t mb26_ifconfig(mo_object_t *self) { char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; - char imei[MO_IMEI_LEN + 1] = {0}; - char iccid[MO_ICCID_LEN + 1] = {0}; + char imei[MO_IMEI_LEN + 1] = {0}; + char iccid[MO_ICCID_LEN + 1] = {0}; os_uint8_t rssi = 0; - os_uint8_t ber = 0; - os_int32_t i = 0; + os_uint8_t ber = 0; + os_int32_t i = 0; if (mb26_get_ipaddr(self, ipaddr) != OS_EOK) { @@ -63,7 +63,7 @@ os_err_t mb26_ifconfig(mo_object_t *self) if (mb26_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; } os_kprintf("\nLIST AT MODULE INFORMATION\n"); @@ -91,8 +91,8 @@ os_err_t mb26_ifconfig(mo_object_t *self) os_err_t mb26_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t ucid = -1; - os_int8_t len = -1; + os_int8_t ucid = -1; + os_int8_t len = -1; char addr[IPADDR_MAX_STR_LEN + 1] = {0}; diff --git a/components/molink/module/mb26/source/mb26_netconn.c b/components/molink/module/mb26/source/mb26_netconn.c index 5fc793c8..a94c333a 100644 --- a/components/molink/module/mb26/source/mb26_netconn.c +++ b/components/molink/module/mb26/source/mb26_netconn.c @@ -106,17 +106,17 @@ os_err_t mb26_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_mb26_t *mb26 = os_container_of(module, mo_mb26_t, parent); info->netconn_array = mb26->netconn; - info->netconn_nums = sizeof(mb26->netconn) / sizeof(mb26->netconn[0]); + info->netconn_nums = sizeof(mb26->netconn) / sizeof(mb26->netconn[0]); return OS_EOK; } mo_netconn_t *mb26_netconn_create(mo_object_t *module, mo_netconn_type_t type) { - mo_mb26_t *mb26 = os_container_of(module, mo_mb26_t, parent); - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_int32_t conn_id = -1; + mo_mb26_t *mb26 = os_container_of(module, mo_mb26_t, parent); + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_int32_t conn_id = -1; mb26_lock(&mb26->netconn_lock); @@ -191,7 +191,7 @@ mo_netconn_t *mb26_netconn_create(mo_object_t *module, mo_netconn_type_t type) os_err_t mb26_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; LOG_EXT_I("Module %s in %d netconn status", module->name, netconn->stat); @@ -224,9 +224,9 @@ os_err_t mb26_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) LOG_EXT_I("Module %s netconn_id: %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); @@ -238,13 +238,11 @@ os_err_t mb26_netconn_gethostbyname(mo_object_t *self, const char *domain_name, { at_parser_t *parser = &self->parser; - char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; + char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 20 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+ECDNS=\"%s\"", domain_name); if (result < 0) @@ -271,10 +269,10 @@ os_err_t mb26_netconn_gethostbyname(mo_object_t *self, const char *domain_name, else { LOG_EXT_D("Module %s domain resolve: \"%s\" domain ip is %s, addrlen %d", - self->name, - domain_name, - recvip, - strlen(recvip)); + self->name, + domain_name, + recvip, + strlen(recvip)); inet_aton(recvip, addr); if (IPADDR_ANY == addr->addr || IPADDR_LOOPBACK == addr->addr) @@ -296,14 +294,12 @@ __exit: os_err_t mb26_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 20 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; strncpy(remote_ip, inet_ntoa(addr), IPADDR_MAX_STR_LEN); result = at_parser_exec_cmd(parser, &resp, "AT+SKTCONNECT=%d,%s,%d", netconn->connect_id, remote_ip, port); @@ -315,7 +311,7 @@ os_err_t mb26_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_add ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; LOG_EXT_D("Module %s connection[%d] connect to %s: %d success", module->name, netconn->connect_id, remote_ip, port); @@ -324,11 +320,11 @@ os_err_t mb26_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_add static os_size_t mb26_tcp_udp_send(at_parser_t *parser, mo_netconn_t *netconn, const char *data, os_size_t size) { - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t cur_pkt_size = 0; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t cur_pkt_size = 0; - char send_cmd [AT_RESP_BUFF_SIZE_DEF] = {0}; + char send_cmd[AT_RESP_BUFF_SIZE_DEF] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; @@ -387,10 +383,7 @@ __exit: if (result != OS_EOK) { - LOG_EXT_E("Module %s netconn %d send %d bytes data failed!", - parser->name, - netconn->connect_id, - size); + LOG_EXT_E("Module %s netconn %d send %d bytes data failed!", parser->name, netconn->connect_id, size); return 0; } @@ -399,8 +392,8 @@ __exit: os_size_t mb26_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_size_t sent_size = 0; + at_parser_t *parser = &module->parser; + os_size_t sent_size = 0; char *hexstr = calloc(1, size * 2 + 1); if (OS_NULL == hexstr) @@ -431,18 +424,18 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = -1; - os_int32_t err_code = -1; + os_int32_t err_code = -1; /* URC msg: +SKTERR: fd, */ - sscanf(data, "+SKTERR: %d,%d", &connect_id,&err_code); + sscanf(data, "+SKTERR: %d,%d", &connect_id, &err_code); - if((connect_id <= 0) || (connect_id > MB26_NETCONN_NUM)) + if ((connect_id <= 0) || (connect_id > MB26_NETCONN_NUM)) { LOG_EXT_E("Module %s receive error close urc data of connect %d", parser->name, connect_id); return; } - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = mb26_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) { @@ -463,19 +456,19 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; + os_int32_t data_size = 0; /* +SKTRECV: 1,10,"30313233343536373839" */ sscanf(data, "+SKTRECV: %d,%d,", &connect_id, &data_size); - if((connect_id <= 0) || (connect_id > MB26_NETCONN_NUM)) + if ((connect_id <= 0) || (connect_id > MB26_NETCONN_NUM)) { LOG_EXT_E("Module %s receive error recv urc data of connect %d", parser->name, connect_id); return; } LOG_EXT_I("Moudle %s netconn %d receive %d bytes data", parser->name, connect_id, data_size); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = mb26_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) { @@ -516,7 +509,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t } static at_urc_t gs_urc_table[] = { - {.prefix = "+SKTERR:", .suffix = "\r\n", .func = urc_close_func}, + {.prefix = "+SKTERR:", .suffix = "\r\n", .func = urc_close_func}, {.prefix = "+SKTRECV:", .suffix = "\r\n", .func = urc_recv_func}, }; diff --git a/components/molink/module/mb26/source/mb26_netserv.c b/components/molink/module/mb26/source/mb26_netserv.c index c4f0931d..1d09fd08 100644 --- a/components/molink/module/mb26/source/mb26_netserv.c +++ b/components/molink/module/mb26/source/mb26_netserv.c @@ -59,7 +59,7 @@ os_err_t mb26_get_attach(mo_object_t *self, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) { LOG_EXT_E("Get %s module attach state failed", self->name); return OS_ERROR; @@ -161,10 +161,10 @@ os_err_t mb26_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber) os_err_t mb26_get_radio(mo_object_t *self, radio_info_t *radio_info) { - at_parser_t *parser = &self->parser; - os_uint32_t buff_len = 1024; - const char *tmp_src_resp = OS_NULL; - char *dest_ptr = OS_NULL; + at_parser_t *parser = &self->parser; + os_uint32_t buff_len = 1024; + const char *tmp_src_resp = OS_NULL; + char *dest_ptr = OS_NULL; memset(radio_info, 0, sizeof(radio_info_t)); @@ -213,7 +213,7 @@ os_err_t mb26_get_radio(mo_object_t *self, radio_info_t *radio_info) result = OS_ERROR; goto __exit; } - sscanf(dest_ptr, "RSRP:%d,",&radio_info->rsrp); + sscanf(dest_ptr, "RSRP:%d,", &radio_info->rsrp); /* Get RSRQ info form tmp_src_resp buff */ dest_ptr = strstr(tmp_src_resp, "RSRQ:"); @@ -223,7 +223,7 @@ os_err_t mb26_get_radio(mo_object_t *self, radio_info_t *radio_info) result = OS_ERROR; goto __exit; } - sscanf(dest_ptr, "RSRQ:%d,",&radio_info->rsrq); + sscanf(dest_ptr, "RSRQ:%d,", &radio_info->rsrq); /* Get SNR info form tmp_src_resp buff */ dest_ptr = strstr(tmp_src_resp, "SNR:"); @@ -233,7 +233,7 @@ os_err_t mb26_get_radio(mo_object_t *self, radio_info_t *radio_info) result = OS_ERROR; goto __exit; } - sscanf(dest_ptr, "SNR:%d,",&radio_info->snr); + sscanf(dest_ptr, "SNR:%d,", &radio_info->snr); /* Get ECL info form tmp_src_resp buff */ dest_ptr = strstr(tmp_src_resp, "CeLevel:"); @@ -243,7 +243,7 @@ os_err_t mb26_get_radio(mo_object_t *self, radio_info_t *radio_info) result = OS_ERROR; goto __exit; } - sscanf(dest_ptr, "CeLevel:%d,",&radio_info->ecl); + sscanf(dest_ptr, "CeLevel:%d,", &radio_info->ecl); tmp_src_resp = at_resp_get_line_by_kw(&resp, "+ECSTATUS: RRC"); /* Get CellId info form tmp_src_resp buff */ @@ -254,11 +254,11 @@ os_err_t mb26_get_radio(mo_object_t *self, radio_info_t *radio_info) result = OS_ERROR; goto __exit; } - sscanf(dest_ptr, "CellId:%s",radio_info->cell_id); + sscanf(dest_ptr, "CellId:%s", radio_info->cell_id); __exit: - if(resp_buff != OS_NULL) + if (resp_buff != OS_NULL) { free(resp_buff); } diff --git a/components/molink/module/mb26/source/mb26_ping.c b/components/molink/module/mb26/source/mb26_ping.c index 61abe1c1..ecb18b05 100644 --- a/components/molink/module/mb26/source/mb26_ping.c +++ b/components/molink/module/mb26/source/mb26_ping.c @@ -36,9 +36,9 @@ os_err_t mb26_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - os_uint32_t req_time = 0; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; + os_uint32_t req_time = 0; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -51,14 +51,18 @@ os_err_t mb26_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint if ((len < MB26_MIN_PING_PKG_LEN) || (len > MB26_MAX_PING_PKG_LEN)) { LOG_EXT_E("MB26 ping: ping package len[%u] is out of range[%u, %u].", - len, MB26_MIN_PING_PKG_LEN, MB26_MAX_PING_PKG_LEN); + len, + MB26_MIN_PING_PKG_LEN, + MB26_MAX_PING_PKG_LEN); return OS_ERROR; } if ((timeout < MB26_MIN_PING_TIMEOUT) || (timeout > MB26_MAX_PING_TIMEOUT)) { LOG_EXT_E("MB26 ping: user set ping timeout value %ums is out of range[%ums, %ums].", - timeout, MB26_MIN_PING_TIMEOUT, MB26_MAX_PING_TIMEOUT); + timeout, + MB26_MIN_PING_TIMEOUT, + MB26_MAX_PING_TIMEOUT); return OS_ERROR; } @@ -66,10 +70,10 @@ os_err_t mb26_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint char resp_buff[256] = {0}; /* Need to wait for 4 lines response msg, and timeout comming with ms */ - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .line_num = 6, - .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; + .line_num = 6, + .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; /* Default set timeout to 5000ms */ /* Exec commond "AT+ECPING="180.101.147.115",1,64,10000 and wait response */ @@ -82,7 +86,8 @@ os_err_t mb26_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint goto __exit; } - if (at_resp_get_data_by_kw(&at_resp, "+ECPING: SUCC", "+ECPING: SUCC, dest: %[^,], RTT: %u", ipaddr, &req_time) <= 0) + if (at_resp_get_data_by_kw(&at_resp, "+ECPING: SUCC", "+ECPING: SUCC, dest: %[^,], RTT: %u", ipaddr, &req_time) <= + 0) { LOG_EXT_E("MB26 ping %s fail: check network status and try to set a longer timeout.", host); result = OS_ERROR; @@ -105,7 +110,7 @@ os_err_t mb26_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint { inet_aton(ipaddr, &(resp->ip_addr)); resp->data_len = len; - resp->time = req_time; + resp->time = req_time; } __exit: diff --git a/components/molink/module/me3616/include/me3616.h b/components/molink/module/me3616/include/me3616.h index d2cb8f7e..363019ba 100644 --- a/components/molink/module/me3616/include/me3616.h +++ b/components/molink/module/me3616/include/me3616.h @@ -73,16 +73,16 @@ typedef struct mo_me3616 mo_object_t parent; #ifdef ME3616_USING_NETCONN_OPS mo_netconn_t netconn[ME3616_NETCONN_NUM]; - - os_int32_t curr_connect; + + os_int32_t curr_connect; os_event_t netconn_evt; os_mutex_t netconn_lock; - void *netconn_data; + void *netconn_data; #endif /* ME3616_USING_NETCONN_OPS */ } mo_me3616_t; mo_object_t *module_me3616_create(const char *name, void *parser_config); -os_err_t module_me3616_destroy(mo_object_t *self); +os_err_t module_me3616_destroy(mo_object_t *self); #endif /* MOLINK_USING_ME3616 */ @@ -91,4 +91,3 @@ os_err_t module_me3616_destroy(mo_object_t *self); #endif /* __cplusplus */ #endif /* __ME3616_H__ */ - diff --git a/components/molink/module/me3616/include/me3616_general.h b/components/molink/module/me3616/include/me3616_general.h index 3ee0c319..f5ef2abe 100644 --- a/components/molink/module/me3616/include/me3616_general.h +++ b/components/molink/module/me3616/include/me3616_general.h @@ -21,17 +21,16 @@ *********************************************************************************************************************** */ - -#ifndef __ME3616_GENERAL_H__ -#define __ME3616_GENERAL_H__ +#ifndef __ME3616_GENERAL_H__ +#define __ME3616_GENERAL_H__ #include "mo_general.h" -#ifdef __cplusplus -extern "C" { +#ifdef __cplusplus +extern "C" { #endif -#ifdef ME3616_USING_GENERAL_OPS +#ifdef ME3616_USING_GENERAL_OPS os_err_t me3616_at_test(mo_object_t *self); os_err_t me3616_get_imei(mo_object_t *self, char *value, os_size_t len); @@ -41,11 +40,10 @@ os_err_t me3616_get_cfun(mo_object_t *self, os_uint8_t *fun_lvl); os_err_t me3616_set_cfun(mo_object_t *self, os_uint8_t fun_lvl); os_err_t me3616_get_firmware_version(mo_object_t *self, mo_firmware_version_t *version); -#endif /* ME3616_USING_GENERAL_OPS */ +#endif /* ME3616_USING_GENERAL_OPS */ -#ifdef __cplusplus +#ifdef __cplusplus } #endif -#endif /* __ME3616_GENERAL_H__ */ - +#endif /* __ME3616_GENERAL_H__ */ diff --git a/components/molink/module/me3616/include/me3616_ifconfig.h b/components/molink/module/me3616/include/me3616_ifconfig.h index 5c520248..ea45a5ba 100644 --- a/components/molink/module/me3616/include/me3616_ifconfig.h +++ b/components/molink/module/me3616/include/me3616_ifconfig.h @@ -41,5 +41,3 @@ os_err_t me3616_get_ipaddr(mo_object_t *self, char ip[]); #endif /* __cplusplus */ #endif /* __ME3616_IFCONFIG_H__ */ - - diff --git a/components/molink/module/me3616/include/me3616_netconn.h b/components/molink/module/me3616/include/me3616_netconn.h index 683e8821..8b2cc479 100644 --- a/components/molink/module/me3616/include/me3616_netconn.h +++ b/components/molink/module/me3616/include/me3616_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef ME3616_USING_NETCONN_OPS -os_err_t me3616_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t me3616_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *me3616_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t me3616_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t me3616_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t me3616_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t me3616_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t me3616_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t me3616_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef ME3616_USING_DNS -os_err_t me3616_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t me3616_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* ME3616_USING_NETCONN_OPS */ @@ -48,4 +48,3 @@ os_err_t me3616_netconn_gethostbyname(mo_object_t *self, const char *domain #endif /* __cplusplus */ #endif /* __M5310A_NETCONN_H__ */ - diff --git a/components/molink/module/me3616/include/me3616_netserv.h b/components/molink/module/me3616/include/me3616_netserv.h index dd6bb8d4..91375e22 100644 --- a/components/molink/module/me3616/include/me3616_netserv.h +++ b/components/molink/module/me3616/include/me3616_netserv.h @@ -47,4 +47,3 @@ os_err_t me3616_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber); #endif /* __cplusplus */ #endif /* __ME3616_NETSERV_H__ */ - diff --git a/components/molink/module/me3616/source/me3616.c b/components/molink/module/me3616/source/me3616.c index e1add6d2..1dc74bd1 100644 --- a/components/molink/module/me3616/source/me3616.c +++ b/components/molink/module/me3616/source/me3616.c @@ -1,31 +1,31 @@ - /** - *********************************************************************************************************************** - * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * @file me3616.c - * - * @brief me3616.c module api - * - * @revision - * Date Author Notes - * 2020-12-1 OneOS Team First Version - *********************************************************************************************************************** - */ +/** +*********************************************************************************************************************** +* Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. +* +* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +* specific language governing permissions and limitations under the License. +* +* @file me3616.c +* +* @brief me3616.c module api +* +* @revision +* Date Author Notes +* 2020-12-1 OneOS Team First Version +*********************************************************************************************************************** +*/ #include "me3616.h" #include #define MO_LOG_TAG "me3616" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_ME3616 @@ -34,37 +34,37 @@ #ifdef ME3616_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = me3616_at_test, - .get_imei = me3616_get_imei, - .get_imsi = me3616_get_imsi, + .at_test = me3616_at_test, + .get_imei = me3616_get_imei, + .get_imsi = me3616_get_imsi, .get_iccid = me3616_get_iccid, - .get_cfun = me3616_get_cfun, - .set_cfun = me3616_set_cfun, + .get_cfun = me3616_get_cfun, + .set_cfun = me3616_set_cfun, .get_firmware_version = me3616_get_firmware_version, }; #endif /* ME3616_USING_GENERAL_OPS */ #ifdef ME3616_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = me3616_set_attach, - .get_attach = me3616_get_attach, - .set_reg = me3616_set_reg, - .get_reg = me3616_get_reg, - .get_cgact = me3616_get_cgact, - .get_csq = me3616_get_csq, + .set_attach = me3616_set_attach, + .get_attach = me3616_get_attach, + .set_reg = me3616_set_reg, + .get_reg = me3616_get_reg, + .get_cgact = me3616_get_cgact, + .get_csq = me3616_get_csq, }; #endif /* ME3616_USING_NETSERV_OPS */ #ifdef ME3616_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = me3616_ifconfig, - .get_ipaddr = me3616_get_ipaddr, + .ifconfig = me3616_ifconfig, + .get_ipaddr = me3616_get_ipaddr, }; #endif /* ME3616_USING_IFCONFIG_OPS */ #ifdef ME3616_USING_PING_OPS static const struct mo_ping_ops gs_ping_ops = { - .ping = me3616_ping, + .ping = me3616_ping, }; #endif /* ME3616_USING_PING_OPS */ @@ -72,19 +72,17 @@ static const struct mo_ping_ops gs_ping_ops = { extern void me3616_netconn_init(mo_me3616_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = me3616_netconn_create, - .destroy = me3616_netconn_destroy, - .connect = me3616_netconn_connect, - .send = me3616_netconn_send, + .create = me3616_netconn_create, + .destroy = me3616_netconn_destroy, + .connect = me3616_netconn_connect, + .send = me3616_netconn_send, #ifdef ME3616_USING_DNS .gethostbyname = me3616_netconn_gethostbyname, #endif - .get_info = me3616_netconn_get_info, + .get_info = me3616_netconn_get_info, }; #endif /* ME3616_USING_NETCONN_OPS */ - - static os_err_t me3616_at_init(mo_object_t *self) { at_parser_t *parser = &self->parser; @@ -98,9 +96,7 @@ static os_err_t me3616_at_init(mo_object_t *self) char resp_buff[32] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; return at_parser_exec_cmd(parser, &resp, "ATE0"); } @@ -113,7 +109,7 @@ mo_object_t *module_me3616_create(const char *name, void *parser_config) ERROR("Create %s module instance failed, no enough memory.", name); return OS_NULL; } - + os_task_msleep(100); /* make sure me3616 power on and be ready */ os_err_t result = mo_object_init(&(module->parent), name, parser_config); @@ -136,15 +132,15 @@ mo_object_t *module_me3616_create(const char *name, void *parser_config) #ifdef ME3616_USING_NETSERV_OPS module->parent.ops_table[MODULE_OPS_NETSERV] = &gs_netserv_ops; #endif /* ME3616_USING_NETSERV_OPS */ - + #ifdef ME3616_USING_IFCONFIG_OPS module->parent.ops_table[MODULE_OPS_IFCONFIG] = &gs_ifconfig_ops; #endif /* ME3616_USING_IFCONFIG_OPS */ #ifdef ME3616_USING_PING_OPS module->parent.ops_table[MODULE_OPS_PING] = &gs_ping_ops; -#endif - +#endif + #ifdef ME3616_USING_NETCONN_OPS module->parent.ops_table[MODULE_OPS_NETCONN] = &gs_netconn_ops; @@ -178,11 +174,11 @@ os_err_t module_me3616_destroy(mo_object_t *self) mo_me3616_t *module = os_container_of(self, mo_me3616_t, parent); mo_object_deinit(self); - + #ifdef ME3616_USING_NETCONN_OPS os_mutex_deinit(&module->netconn_lock); - + #endif /* ME3616_USING_NETCONN_OPS */ os_free(module); @@ -208,7 +204,7 @@ int me3616_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = ME3616_NAME, + mo_parser_config_t parser_config = {.parser_name = ME3616_NAME, .parser_device = device, .recv_buff_len = ME3616_RECV_BUFF_LEN}; @@ -226,4 +222,3 @@ OS_CMPOENT_INIT(me3616_auto_create, OS_INIT_SUBLEVEL_MIDDLE); #endif /* ME3616_AUTO_CREATE */ #endif /* MOLINK_USING_ME3616 */ - diff --git a/components/molink/module/me3616/source/me3616_general.c b/components/molink/module/me3616/source/me3616_general.c index 38b12993..7c226792 100644 --- a/components/molink/module/me3616/source/me3616_general.c +++ b/components/molink/module/me3616/source/me3616_general.c @@ -21,13 +21,12 @@ *********************************************************************************************************************** */ - #include #include #include "me3616_general.h" #define MO_LOG_TAG "me3616_general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef ME3616_USING_GENERAL_OPS @@ -43,7 +42,7 @@ os_err_t me3616_at_test(mo_object_t *self) return at_parser_exec_cmd(parser, &resp, "AT"); } -os_err_t me3616_get_imei(mo_object_t * self,char * value, os_size_t len) +os_err_t me3616_get_imei(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_IMEI_LEN); @@ -52,18 +51,17 @@ os_err_t me3616_get_imei(mo_object_t * self,char * value, os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN=1")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN=1")) { return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGSN:", "+CGSN: %s", value) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGSN:", "+CGSN: %s", value) <= 0) { ERROR("Get %s module imei failed."); return OS_ERROR; } - value[MO_IMEI_LEN] = '\0'; INFO("%s module imei:%s", self->name, value); @@ -71,7 +69,7 @@ os_err_t me3616_get_imei(mo_object_t * self,char * value, os_size_t len) return OS_EOK; } -os_err_t me3616_get_imsi(mo_object_t * self,char * value, os_size_t len) +os_err_t me3616_get_imsi(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_IMSI_LEN); @@ -80,12 +78,12 @@ os_err_t me3616_get_imsi(mo_object_t * self,char * value, os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * AT_RESP_TIMEOUT_DEF}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CIMI")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CIMI")) { return OS_ERROR; } - if(at_resp_get_data_by_line(&resp, 1, "%s", value) <= 0) + if (at_resp_get_data_by_line(&resp, 1, "%s", value) <= 0) { ERROR("Get %s module imsi failed."); return OS_ERROR; @@ -93,12 +91,12 @@ os_err_t me3616_get_imsi(mo_object_t * self,char * value, os_size_t len) value[MO_IMSI_LEN] = '\0'; - DEBUG("%s module imsi:%s",self->name,value); + DEBUG("%s module imsi:%s", self->name, value); return OS_EOK; } -os_err_t me3616_get_iccid(mo_object_t * self,char * value, os_size_t len) +os_err_t me3616_get_iccid(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_ICCID_LEN); @@ -107,12 +105,12 @@ os_err_t me3616_get_iccid(mo_object_t * self,char * value, os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT*MICCID")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT*MICCID")) { return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "*MICCID:", "*MICCID: %s", value) <= 0) + if (at_resp_get_data_by_kw(&resp, "*MICCID:", "*MICCID: %s", value) <= 0) { ERROR("Get %s module ccid failed.", self->parser); return OS_ERROR; @@ -123,7 +121,7 @@ os_err_t me3616_get_iccid(mo_object_t * self,char * value, os_size_t len) return OS_EOK; } -os_err_t me3616_get_cfun(mo_object_t * self, os_uint8_t *fun_lvl) +os_err_t me3616_get_cfun(mo_object_t *self, os_uint8_t *fun_lvl) { at_parser_t *parser = &self->parser; @@ -136,7 +134,7 @@ os_err_t me3616_get_cfun(mo_object_t * self, os_uint8_t *fun_lvl) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CFUN:", "+CFUN: %hhu",fun_lvl) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CFUN:", "+CFUN: %hhu", fun_lvl) <= 0) { ERROR("Get %s module level of functionality failed.", self->name); return OS_ERROR; @@ -162,9 +160,7 @@ os_err_t me3616_get_firmware_version(mo_object_t *self, mo_firmware_version_t *v char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+GMR"); if (result != OS_EOK) @@ -179,7 +175,7 @@ os_err_t me3616_get_firmware_version(mo_object_t *self, mo_firmware_version_t *v } const char *source_line = at_resp_get_line(&resp, 1); - os_size_t line_length = strlen(source_line); + os_size_t line_length = strlen(source_line); char **dest_line = &version->ver_info[0]; @@ -197,6 +193,4 @@ os_err_t me3616_get_firmware_version(mo_object_t *self, mo_firmware_version_t *v return OS_EOK; } - -#endif /* ME3616_USING_GENERAL_OPS */ - +#endif /* ME3616_USING_GENERAL_OPS */ diff --git a/components/molink/module/me3616/source/me3616_ifconfig.c b/components/molink/module/me3616/source/me3616_ifconfig.c index 3a958536..d314df81 100644 --- a/components/molink/module/me3616/source/me3616_ifconfig.c +++ b/components/molink/module/me3616/source/me3616_ifconfig.c @@ -30,7 +30,7 @@ #include #define MO_LOG_TAG "me3616_ifconfig" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef ME3616_USING_IFCONFIG_OPS @@ -56,12 +56,12 @@ os_err_t me3616_ifconfig(mo_object_t *self) } os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t ber = 0; if (me3616_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; } os_kprintf("\r\nLIST AT MODULE INFORMATIONS\r\n"); @@ -88,15 +88,15 @@ os_err_t me3616_ifconfig(mo_object_t *self) os_err_t me3616_get_ipaddr(mo_object_t *self, char ip[]) { - at_parser_t *parser = &self->parser; - os_int8_t len = -1; - os_int8_t len_start = 0; - os_int8_t len_end = 0; - char cgcontrdp[128] = {0}; - char resp_buff[256] = {0}; - char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; - int j = 0; - int k = 0; + at_parser_t *parser = &self->parser; + os_int8_t len = -1; + os_int8_t len_start = 0; + os_int8_t len_end = 0; + char cgcontrdp[128] = {0}; + char resp_buff[256] = {0}; + char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; + int j = 0; + int k = 0; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CGCONTRDP"); @@ -105,28 +105,28 @@ os_err_t me3616_get_ipaddr(mo_object_t *self, char ip[]) ERROR("Get ip address fail: AT+CGPADDR cmd exec fail."); goto __exit; } - - if (at_resp_get_data_by_kw(&resp,"+CGCONTRDP: ","+CGCONTRDP: %s", cgcontrdp) <= 0) + + if (at_resp_get_data_by_kw(&resp, "+CGCONTRDP: ", "+CGCONTRDP: %s", cgcontrdp) <= 0) { result = OS_ERROR; goto __exit; } - for (int i = 0; ; i++) + for (int i = 0;; i++) { - if(cgcontrdp[i] == '\"') + if (cgcontrdp[i] == '\"') { j++; - if(j ==3) + if (j == 3) { len_start = i + 1; } } - - if(cgcontrdp[i] == '.') + + if (cgcontrdp[i] == '.') { k++; - if(k ==4) + if (k == 4) { len_end = i; break; @@ -134,9 +134,9 @@ os_err_t me3616_get_ipaddr(mo_object_t *self, char ip[]) } } len = len_end - len_start; - - strncpy(ipaddr,&cgcontrdp[len_start],len); - + + strncpy(ipaddr, &cgcontrdp[len_start], len); + if ((len < IPADDR_MIN_STR_LEN) || (len > IPADDR_MAX_STR_LEN)) { ERROR("IP address size [%d] error.", len); @@ -155,4 +155,3 @@ __exit: } #endif /* ME3616_USING_IFCONFIG_OPS */ - diff --git a/components/molink/module/me3616/source/me3616_netconn.c b/components/molink/module/me3616/source/me3616_netconn.c index 04773e52..0889b018 100644 --- a/components/molink/module/me3616/source/me3616_netconn.c +++ b/components/molink/module/me3616/source/me3616_netconn.c @@ -30,7 +30,7 @@ #include #define MO_LOG_TAG "me3616_netconn" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define SEND_DATA_MAX_SIZE (512) @@ -43,12 +43,11 @@ #endif #ifndef ME3616_NETCONN_MQ_MSG_MAX -#define ME3616_NETCONN_MQ_MSG_MAX (5) +#define ME3616_NETCONN_MQ_MSG_MAX (5) #endif #ifdef ME3616_USING_NETCONN_OPS - static os_err_t me3616_lock(os_mutex_t *mutex) { return os_mutex_recursive_lock(mutex, OS_WAIT_FOREVER); @@ -61,20 +60,17 @@ static os_err_t me3616_unlock(os_mutex_t *mutex) static mo_netconn_t *me3616_netconn_alloc(mo_object_t *module, mo_netconn_type_t type) { - at_parser_t *parser = &module->parser; - mo_me3616_t *me3616 = os_container_of(module, mo_me3616_t, parent); - os_uint8_t socket_id = 0; + at_parser_t *parser = &module->parser; + mo_me3616_t *me3616 = os_container_of(module, mo_me3616_t, parent); + os_uint8_t socket_id = 0; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 10 * OS_TICK_PER_SECOND - }; - + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; + for (int i = 0; i < ME3616_NETCONN_NUM; i++) { if (NETCONN_STAT_NULL == me3616->netconn[i].stat) - { - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+ESOC=1,%d,1", type)) + { + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+ESOC=1,%d,1", type)) { continue; } @@ -82,7 +78,7 @@ static mo_netconn_t *me3616_netconn_alloc(mo_object_t *module, mo_netconn_type_t if (at_resp_get_data_by_kw(&resp, "+ESOC=", "+ESOC=%d", &socket_id) <= 0) { continue; - } + } me3616->netconn[i].connect_id = socket_id; return &me3616->netconn[i]; } @@ -104,7 +100,7 @@ static mo_netconn_t *me3616_get_netconn_by_id(mo_object_t *module, os_int32_t co } mo_me3616_t *me3616 = os_container_of(module, mo_me3616_t, parent); - + for (int i = 0; i < ME3616_NETCONN_NUM; i++) { if (connect_id == me3616->netconn[i].connect_id) @@ -114,7 +110,6 @@ static mo_netconn_t *me3616_get_netconn_by_id(mo_object_t *module, os_int32_t co } return OS_NULL; - } os_err_t me3616_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) @@ -122,7 +117,7 @@ os_err_t me3616_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_me3616_t *me3616 = os_container_of(module, mo_me3616_t, parent); info->netconn_array = me3616->netconn; - info->netconn_nums = sizeof(me3616->netconn) / sizeof(me3616->netconn[0]); + info->netconn_nums = sizeof(me3616->netconn) / sizeof(me3616->netconn[0]); return OS_EOK; } @@ -133,9 +128,7 @@ mo_netconn_t *me3616_netconn_create(mo_object_t *module, mo_netconn_type_t type) me3616_lock(&me3616->netconn_lock); mo_netconn_t *netconn = me3616_netconn_alloc(module, type); - netconn->mq = os_mq_create(ME3616_NETCONN_MQ_NAME, - ME3616_NETCONN_MQ_MSG_SIZE, - ME3616_NETCONN_MQ_MSG_MAX); + netconn->mq = os_mq_create(ME3616_NETCONN_MQ_NAME, ME3616_NETCONN_MQ_MSG_SIZE, ME3616_NETCONN_MQ_MSG_MAX); if (OS_NULL == netconn->mq) { ERROR("%s data queue create failed, no enough memory.", module->name); @@ -151,18 +144,15 @@ mo_netconn_t *me3616_netconn_create(mo_object_t *module, mo_netconn_type_t type) os_err_t me3616_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; - - mo_me3616_t * me3616 = os_container_of(module, mo_me3616_t, parent); + at_parser_t *parser = &module->parser; + os_err_t result = OS_ERROR; + + mo_me3616_t *me3616 = os_container_of(module, mo_me3616_t, parent); me3616_lock(&me3616->netconn_lock); - + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 10 * OS_TICK_PER_SECOND - }; - + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; + switch (netconn->stat) { case NETCONN_STAT_INIT: @@ -171,12 +161,12 @@ os_err_t me3616_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) if (result != OS_EOK) { ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + module->name, + (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); me3616_unlock(&me3616->netconn_lock); return result; } - + break; default: /* add handler when we need */ @@ -191,48 +181,43 @@ os_err_t me3616_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn id %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); - + me3616_unlock(&me3616->netconn_lock); - + return OS_EOK; } - - os_err_t me3616_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - mo_me3616_t * me3616 = os_container_of(module, mo_me3616_t, parent); - - me3616_lock(&me3616->netconn_lock); - + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + mo_me3616_t *me3616 = os_container_of(module, mo_me3616_t, parent); + + me3616_lock(&me3616->netconn_lock); + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 60 * OS_TICK_PER_SECOND}; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; - strncpy(remote_ip, inet_ntoa(addr), IPADDR_MAX_STR_LEN); - - result = at_parser_exec_cmd(parser, &resp, "AT+ESOCON=%d,%d,\"%s\"", - netconn->connect_id, - port, - remote_ip); + strncpy(remote_ip, inet_ntoa(addr), IPADDR_MAX_STR_LEN); + + result = at_parser_exec_cmd(parser, &resp, "AT+ESOCON=%d,%d,\"%s\"", netconn->connect_id, port, remote_ip); if (result != OS_EOK) { goto __exit; } - + __exit: if (OS_EOK == result) { ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); } @@ -247,47 +232,39 @@ __exit: os_size_t me3616_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - - mo_me3616_t *me3616 = os_container_of(module, mo_me3616_t, parent); + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + + mo_me3616_t *me3616 = os_container_of(module, mo_me3616_t, parent); at_parser_exec_lock(parser); - - me3616->curr_connect = netconn->connect_id; - char *hexstr = os_calloc(1, size * 2 + 1); - char resp_buff[128] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 5 * OS_TICK_PER_SECOND - }; - - if(size > SEND_DATA_MAX_SIZE || size < SEND_DATA_MIN_SIZE) + + me3616->curr_connect = netconn->connect_id; + char *hexstr = os_calloc(1, size * 2 + 1); + char resp_buff[128] = {0}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; + + if (size > SEND_DATA_MAX_SIZE || size < SEND_DATA_MIN_SIZE) { - ERROR("Moudle %s send data len: %d out of the range [1,512]!", - module->name, - size ); + ERROR("Moudle %s send data len: %d out of the range [1,512]!", module->name, size); result = OS_ERROR; goto __exit; } - + if (OS_NULL == hexstr) { - ERROR("Moudle %s netconn %d calloc %d bytes memory failed!", - module->name, - netconn->connect_id, - size * 2 + 1); + ERROR("Moudle %s netconn %d calloc %d bytes memory failed!", module->name, netconn->connect_id, size * 2 + 1); result = OS_ERROR; goto __exit; } bytes_to_hexstr(data, hexstr, size); - + result = at_parser_exec_cmd(parser, &resp, "AT+ESOSEND=%d,%d,%s", netconn->connect_id, size, hexstr); if (result != OS_EOK) { goto __exit; - } + } __exit: @@ -309,23 +286,23 @@ os_err_t me3616_netconn_gethostbyname(mo_object_t *self, const char *domain_name OS_ASSERT(OS_NULL != domain_name); OS_ASSERT(OS_NULL != addr); - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; - char resp_buff[128] = {0}; + char resp_buff[128] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 30 * OS_TICK_PER_SECOND}; mo_me3616_t *me3616 = os_container_of(self, mo_me3616_t, parent); me3616->netconn_data = addr; - + result = at_parser_exec_cmd(parser, &resp, "AT+EDNS=\"%s\"", domain_name); if (result != OS_EOK) { goto __exit; } - + if (at_resp_get_data_by_kw(&resp, "IPV4:", "IPV4:%s", &recvip) <= 0) { result = OS_ERROR; @@ -349,23 +326,26 @@ static void urc_err_func(struct at_parser *parser, const char *data, os_size_t s { OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - - os_int32_t error_code = 0; - os_int32_t connect_id = -1; - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + + os_int32_t error_code = 0; + os_int32_t connect_id = -1; + mo_object_t *module = os_container_of(parser, mo_object_t, parser); sscanf(data, "+ESOERR=%d,%d", &connect_id, &error_code); - + mo_netconn_t *netconn = me3616_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) { return; } - ERROR("Module %s connect_id: %d recv error_code: %d and the netconn destroyed", module->name, connect_id, error_code); - - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + ERROR("Module %s connect_id: %d recv error_code: %d and the netconn destroyed", + module->name, + connect_id, + error_code); + + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); } @@ -376,7 +356,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = -1; - os_int32_t data_size = 0; + os_int32_t data_size = 0; sscanf(data, "+ESONMI=%d,%d,", &connect_id, &data_size); INFO("Moudle %s netconn %d receive %d bytes data", parser->name, connect_id, data_size); @@ -412,41 +392,41 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t /* from mo_lib */ hexstr_to_bytes(recv_buff, recv_str, data_size * 2); - + mo_netconn_data_recv_notice(netconn, recv_str, data_size); os_free(recv_buff); - - return; + + return; } static at_urc_t gs_urc_table[] = { - {.prefix = "+ESONMI=", .suffix = "\r\n", .func = urc_recv_func}, - {.prefix = "+ESOERR=", .suffix = "\r\n", .func = urc_err_func}, + {.prefix = "+ESONMI=", .suffix = "\r\n", .func = urc_recv_func}, + {.prefix = "+ESOERR=", .suffix = "\r\n", .func = urc_err_func}, }; static void me3616_network_init(mo_object_t *module) { - at_parser_t *parser = &module->parser; - os_int32_t enable_num = 0; - os_int32_t reg_state = 0; - os_err_t result = OS_ERROR; + at_parser_t *parser = &module->parser; + os_int32_t enable_num = 0; + os_int32_t reg_state = 0; + os_err_t result = OS_ERROR; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; - + result = at_parser_exec_cmd(parser, &resp, "AT+CEREG?"); if (result != OS_EOK) { goto __exit; } - - if (at_resp_get_data_by_kw(&resp, "+CEREG:", "+CEREG: %d,%d", &enable_num , ®_state) < 0) + + if (at_resp_get_data_by_kw(&resp, "+CEREG:", "+CEREG: %d,%d", &enable_num, ®_state) < 0) { result = OS_ERROR; goto __exit; } - + if (1 == reg_state || 5 == reg_state) { result = OS_EOK; @@ -455,10 +435,10 @@ static void me3616_network_init(mo_object_t *module) else { result = OS_ERROR; - goto __exit; + goto __exit; } __exit: - if(result != OS_EOK) + if (result != OS_EOK) { WARN("ME3616 network init failed"); } diff --git a/components/molink/module/me3616/source/me3616_netserv.c b/components/molink/module/me3616/source/me3616_netserv.c index 517f0be4..2d541492 100644 --- a/components/molink/module/me3616/source/me3616_netserv.c +++ b/components/molink/module/me3616/source/me3616_netserv.c @@ -29,12 +29,11 @@ #include #define MO_LOG_TAG "me3616_netserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define IP_SIZE 16 - #ifdef ME3616_USING_NETSERV_OPS os_err_t me3616_set_attach(mo_object_t *self, os_uint8_t attach_stat) @@ -118,7 +117,7 @@ os_err_t me3616_get_cgact(mo_object_t *self, os_uint8_t *cid, os_uint8_t *act_st { return OS_ERROR; } - + if (at_resp_get_data_by_line(&resp, *cid, "+CGACT: %d,%d", cid, act_stat) <= 0) { ERROR("Get %s module cgact state failed", self->name); @@ -152,4 +151,3 @@ os_err_t me3616_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber) } #endif /* me3616_USING_NETSERV_OPS */ - diff --git a/components/molink/module/me3616/source/me3616_ping.c b/components/molink/module/me3616/source/me3616_ping.c index ed41bdd5..3f6245cd 100644 --- a/components/molink/module/me3616/source/me3616_ping.c +++ b/components/molink/module/me3616/source/me3616_ping.c @@ -27,7 +27,7 @@ #include #define MO_LOG_TAG "me3616_ping" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define ME3616_MIN_PING_PKG_LEN (8) @@ -35,8 +35,8 @@ #define ME3616_MIN_PING_TIMEOUT (1) #define ME3616_MAX_PING_TIMEOUT (65535) -#define MB_MAX_MAILS 5 -#define TEST_NAME_MAX 16 +#define MB_MAX_MAILS 5 +#define TEST_NAME_MAX 16 #ifdef ME3616_USING_PING_OPS @@ -46,11 +46,11 @@ static void urc_ping_func(struct at_parser *parser, const char *data, os_size_t { OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - char tmp_str[5] = {0}; + char tmp_str[5] = {0}; char *tmp; - - tmp = strstr(data,"Average"); - tmp = tmp + 10; + + tmp = strstr(data, "Average"); + tmp = tmp + 10; for (int i = 0;; i++) { if ('\r' == tmp[i]) @@ -59,7 +59,7 @@ static void urc_ping_func(struct at_parser *parser, const char *data, os_size_t } tmp_str[i] = tmp[i]; - } + } os_mb_send(mb_dynamic, (os_uint32_t)atoi(tmp_str), OS_WAIT_FOREVER); } @@ -70,12 +70,12 @@ static at_urc_t gs_urc_table[] = { os_err_t me3616_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - os_uint32_t req_time = 0; - os_int16_t ttl = -1; - os_uint32_t timeout_s = timeout / 1000; /* Milliseconds convert to seconds */ - os_ubase_t recv_data = 0; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; + os_uint32_t req_time = 0; + os_int16_t ttl = -1; + os_uint32_t timeout_s = timeout / 1000; /* Milliseconds convert to seconds */ + os_ubase_t recv_data = 0; if (parser == OS_NULL) { @@ -85,42 +85,44 @@ os_err_t me3616_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ui if ((len < ME3616_MIN_PING_PKG_LEN) || (len > ME3616_MAX_PING_PKG_LEN)) { - ERROR("ME3616 ping: ping package len[%d] is out of range[%d, %d].", - len, ME3616_MIN_PING_PKG_LEN, ME3616_MAX_PING_PKG_LEN); + ERROR("ME3616 ping: ping package len[%d] is out of range[%d, %d].", + len, + ME3616_MIN_PING_PKG_LEN, + ME3616_MAX_PING_PKG_LEN); return OS_ERROR; } if ((timeout_s < ME3616_MIN_PING_TIMEOUT) || (timeout_s > ME3616_MAX_PING_TIMEOUT)) { - ERROR("ME3616 ping: ping timeout %us is out of range[%ds, %ds].", - timeout_s, ME3616_MIN_PING_TIMEOUT, ME3616_MAX_PING_TIMEOUT); + ERROR("ME3616 ping: ping timeout %us is out of range[%ds, %ds].", + timeout_s, + ME3616_MIN_PING_TIMEOUT, + ME3616_MAX_PING_TIMEOUT); return OS_ERROR; } - + /* Set netconn urc table */ at_parser_set_urc_table(parser, gs_urc_table, sizeof(gs_urc_table) / sizeof(gs_urc_table[0])); - + mb_dynamic = os_mb_create("mailbox_dynamic", MB_MAX_MAILS); - if(!mb_dynamic) + if (!mb_dynamic) { ERROR("mailbox_dynamic_sample mailbox create ERR"); return OS_ERROR; } - DEBUG("ME3616 ping: %s, len: %d, timeout: %us", host, len, timeout_s); char resp_buff[512] = {0}; - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .timeout = (5 + timeout_s) * OS_TICK_PER_SECOND - }; + .timeout = (5 + timeout_s) * OS_TICK_PER_SECOND}; /* Send commond "AT+MPING= or ip addr" and wait response */ /* Exec AT+MPING="www.baidu.com",2,1,64 and return: 0 183.232.231.172: bytes = 36 time = 96(ms), TTL = 255 */ - if (at_parser_exec_cmd(parser, &at_resp, "AT+PING=%s -l %d -n 1 -w %d", host, len, timeout) < 0) + if (at_parser_exec_cmd(parser, &at_resp, "AT+PING=%s -l %d -n 1 -w %d", host, len, timeout) < 0) { result = OS_ERROR; goto __exit; @@ -130,16 +132,16 @@ os_err_t me3616_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ui { result = OS_ERROR; goto __exit; - } - - req_time = recv_data; - + } + + req_time = recv_data; + if (0 != req_time) { inet_aton(host, &(resp->ip_addr)); resp->data_len = len; - resp->ttl = ttl; - resp->time = req_time; + resp->ttl = ttl; + resp->time = req_time; } else { diff --git a/components/molink/module/me3630_w/include/me3630_w.h b/components/molink/module/me3630_w/include/me3630_w.h index 24e88718..87da2a30 100644 --- a/components/molink/module/me3630_w/include/me3630_w.h +++ b/components/molink/module/me3630_w/include/me3630_w.h @@ -69,16 +69,16 @@ typedef struct mo_me3630_w mo_object_t parent; #ifdef ME3630_W_USING_NETCONN_OPS mo_netconn_t netconn[ME3630_W_NETCONN_NUM]; - - os_int32_t curr_connect; + + os_int32_t curr_connect; os_event_t netconn_evt; os_mutex_t netconn_lock; - void *netconn_data; + void *netconn_data; #endif /* ME3630_W_USING_NETCONN_OPS */ } mo_me3630_w_t; mo_object_t *module_me3630_w_create(const char *name, void *parser_config); -os_err_t module_me3630_w_destroy(mo_object_t *self); +os_err_t module_me3630_w_destroy(mo_object_t *self); #endif /* MOLINK_USING_ME3630_W */ @@ -87,4 +87,3 @@ os_err_t module_me3630_w_destroy(mo_object_t *self); #endif /* __cplusplus */ #endif /* __ME3630_W_H__ */ - diff --git a/components/molink/module/me3630_w/include/me3630_w_general.h b/components/molink/module/me3630_w/include/me3630_w_general.h index 316b3d2c..0b61124a 100644 --- a/components/molink/module/me3630_w/include/me3630_w_general.h +++ b/components/molink/module/me3630_w/include/me3630_w_general.h @@ -21,17 +21,16 @@ *********************************************************************************************************************** */ - -#ifndef __ME3630_W_GENERAL_H__ -#define __ME3630_W_GENERAL_H__ +#ifndef __ME3630_W_GENERAL_H__ +#define __ME3630_W_GENERAL_H__ #include "mo_general.h" -#ifdef __cplusplus -extern "C" { +#ifdef __cplusplus +extern "C" { #endif -#ifdef ME3630_W_USING_GENERAL_OPS +#ifdef ME3630_W_USING_GENERAL_OPS os_err_t me3630_w_at_test(mo_object_t *self); os_err_t me3630_w_get_imei(mo_object_t *self, char *value, os_size_t len); @@ -41,11 +40,10 @@ os_err_t me3630_w_get_cfun(mo_object_t *self, os_uint8_t *fun_lvl); os_err_t me3630_w_set_cfun(mo_object_t *self, os_uint8_t fun_lvl); os_err_t me3630_w_get_firmware_version(mo_object_t *self, mo_firmware_version_t *version); -#endif /* ME3630_W_USING_GENERAL_OPS */ +#endif /* ME3630_W_USING_GENERAL_OPS */ -#ifdef __cplusplus +#ifdef __cplusplus } #endif -#endif /* __ME3630_W_GENERAL_H__ */ - +#endif /* __ME3630_W_GENERAL_H__ */ diff --git a/components/molink/module/me3630_w/include/me3630_w_ifconfig.h b/components/molink/module/me3630_w/include/me3630_w_ifconfig.h index e4f2a886..f55a41b5 100644 --- a/components/molink/module/me3630_w/include/me3630_w_ifconfig.h +++ b/components/molink/module/me3630_w/include/me3630_w_ifconfig.h @@ -41,5 +41,3 @@ os_err_t me3630_w_get_ipaddr(mo_object_t *self, char ip[]); #endif /* __cplusplus */ #endif /* __ME3630_W_IFCONFIG_H__ */ - - diff --git a/components/molink/module/me3630_w/include/me3630_w_netconn.h b/components/molink/module/me3630_w/include/me3630_w_netconn.h index 46167540..976002f9 100644 --- a/components/molink/module/me3630_w/include/me3630_w_netconn.h +++ b/components/molink/module/me3630_w/include/me3630_w_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef ME3630_W_USING_NETCONN_OPS -os_err_t me3630_w_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t me3630_w_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *me3630_w_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t me3630_w_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t me3630_w_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t me3630_w_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t me3630_w_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t me3630_w_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t me3630_w_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef ME3630_W_USING_DNS -os_err_t me3630_w_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t me3630_w_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* ME3630_W_USING_NETCONN_OPS */ @@ -48,4 +48,3 @@ os_err_t me3630_w_netconn_gethostbyname(mo_object_t *self, const char *doma #endif /* __cplusplus */ #endif /* __M5310A_NETCONN_H__ */ - diff --git a/components/molink/module/me3630_w/include/me3630_w_netserv.h b/components/molink/module/me3630_w/include/me3630_w_netserv.h index 09fa5846..825093cb 100644 --- a/components/molink/module/me3630_w/include/me3630_w_netserv.h +++ b/components/molink/module/me3630_w/include/me3630_w_netserv.h @@ -39,7 +39,7 @@ os_err_t me3630_w_get_reg(mo_object_t *self, eps_reg_info_t *info); os_err_t me3630_w_set_cgact(mo_object_t *self, os_uint8_t cid, os_uint8_t act_n); os_err_t me3630_w_get_cgact(mo_object_t *self, os_uint8_t *cid, os_uint8_t *act_stat); os_err_t me3630_w_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber); -os_err_t me3630_w_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info); +os_err_t me3630_w_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info); #endif /* ME3630_W_USING_NETSERV_OPS */ #ifdef __cplusplus @@ -47,4 +47,3 @@ os_err_t me3630_w_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_ce #endif /* __cplusplus */ #endif /* __ME3630_W_NETSERV_H__ */ - diff --git a/components/molink/module/me3630_w/source/me3630_w.c b/components/molink/module/me3630_w/source/me3630_w.c index c865ffd0..e4af8290 100644 --- a/components/molink/module/me3630_w/source/me3630_w.c +++ b/components/molink/module/me3630_w/source/me3630_w.c @@ -1,31 +1,31 @@ - /** - *********************************************************************************************************************** - * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * @file me3630_w.c - * - * @brief me3630_w.c module api - * - * @revision - * Date Author Notes - * 2020-12-1 OneOS Team First Version - *********************************************************************************************************************** - */ +/** +*********************************************************************************************************************** +* Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. +* +* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +* specific language governing permissions and limitations under the License. +* +* @file me3630_w.c +* +* @brief me3630_w.c module api +* +* @revision +* Date Author Notes +* 2020-12-1 OneOS Team First Version +*********************************************************************************************************************** +*/ #include "me3630_w.h" #include #define MO_LOG_TAG "me3630_w" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_ME3630_W @@ -34,33 +34,33 @@ #ifdef ME3630_W_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = me3630_w_at_test, - .get_imei = me3630_w_get_imei, - .get_imsi = me3630_w_get_imsi, + .at_test = me3630_w_at_test, + .get_imei = me3630_w_get_imei, + .get_imsi = me3630_w_get_imsi, .get_iccid = me3630_w_get_iccid, - .get_cfun = me3630_w_get_cfun, - .set_cfun = me3630_w_set_cfun, + .get_cfun = me3630_w_get_cfun, + .set_cfun = me3630_w_set_cfun, .get_firmware_version = me3630_w_get_firmware_version, }; #endif /* ME3630_W_USING_GENERAL_OPS */ #ifdef ME3630_W_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = me3630_w_set_attach, - .get_attach = me3630_w_get_attach, - .set_reg = me3630_w_set_reg, - .get_reg = me3630_w_get_reg, - .set_cgact = me3630_w_set_cgact, - .get_cgact = me3630_w_get_cgact, - .get_csq = me3630_w_get_csq, + .set_attach = me3630_w_set_attach, + .get_attach = me3630_w_get_attach, + .set_reg = me3630_w_set_reg, + .get_reg = me3630_w_get_reg, + .set_cgact = me3630_w_set_cgact, + .get_cgact = me3630_w_get_cgact, + .get_csq = me3630_w_get_csq, .get_cell_info = me3630_w_get_cell_info, }; #endif /* ME3630_W_USING_NETSERV_OPS */ #ifdef ME3630_W_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = me3630_w_ifconfig, - .get_ipaddr = me3630_w_get_ipaddr, + .ifconfig = me3630_w_ifconfig, + .get_ipaddr = me3630_w_get_ipaddr, }; #endif /* ME3630_W_USING_IFCONFIG_OPS */ @@ -68,19 +68,17 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void me3630_w_netconn_init(mo_me3630_w_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = me3630_w_netconn_create, - .destroy = me3630_w_netconn_destroy, - .connect = me3630_w_netconn_connect, - .send = me3630_w_netconn_send, + .create = me3630_w_netconn_create, + .destroy = me3630_w_netconn_destroy, + .connect = me3630_w_netconn_connect, + .send = me3630_w_netconn_send, #ifdef ME3630_W_USING_DNS .gethostbyname = me3630_w_netconn_gethostbyname, #endif - .get_info = me3630_w_netconn_get_info, + .get_info = me3630_w_netconn_get_info, }; #endif /* ME3630_W_USING_NETCONN_OPS */ - - static os_err_t me3630_w_at_init(mo_object_t *self) { at_parser_t *parser = &self->parser; @@ -94,9 +92,7 @@ static os_err_t me3630_w_at_init(mo_object_t *self) char resp_buff[32] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; return at_parser_exec_cmd(parser, &resp, "ATE0"); } @@ -109,7 +105,7 @@ mo_object_t *module_me3630_w_create(const char *name, void *parser_config) ERROR("Create %s module instance failed, no enough memory.", name); return OS_NULL; } - + os_task_msleep(5000); /* make sure me3630_w power on and be ready */ os_err_t result = mo_object_init(&(module->parent), name, parser_config); @@ -132,11 +128,11 @@ mo_object_t *module_me3630_w_create(const char *name, void *parser_config) #ifdef ME3630_W_USING_NETSERV_OPS module->parent.ops_table[MODULE_OPS_NETSERV] = &gs_netserv_ops; #endif /* ME3630_W_USING_NETSERV_OPS */ - + #ifdef ME3630_W_USING_IFCONFIG_OPS module->parent.ops_table[MODULE_OPS_IFCONFIG] = &gs_ifconfig_ops; #endif /* ME3630_W_USING_IFCONFIG_OPS */ - + #ifdef ME3630_W_USING_NETCONN_OPS module->parent.ops_table[MODULE_OPS_NETCONN] = &gs_netconn_ops; @@ -172,13 +168,13 @@ os_err_t module_me3630_w_destroy(mo_object_t *self) mo_me3630_w_t *module = os_container_of(self, mo_me3630_w_t, parent); mo_object_deinit(self); - + #ifdef ME3630_W_USING_NETCONN_OPS os_event_deinit(&module->netconn_evt); os_mutex_deinit(&module->netconn_lock); - + #endif /* ME3630_W_USING_NETCONN_OPS */ os_free(module); @@ -204,7 +200,7 @@ int me3630_w_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = ME3630_W_NAME, + mo_parser_config_t parser_config = {.parser_name = ME3630_W_NAME, .parser_device = device, .recv_buff_len = ME3630_W_RECV_BUFF_LEN}; @@ -223,4 +219,3 @@ OS_CMPOENT_INIT(me3630_w_auto_create, OS_INIT_SUBLEVEL_MIDDLE); #endif /* ME3630_W_AUTO_CREATE */ #endif /* MOLINK_USING_ME3630_W */ - diff --git a/components/molink/module/me3630_w/source/me3630_w_general.c b/components/molink/module/me3630_w/source/me3630_w_general.c index ed5e406e..54f674a9 100644 --- a/components/molink/module/me3630_w/source/me3630_w_general.c +++ b/components/molink/module/me3630_w/source/me3630_w_general.c @@ -21,13 +21,12 @@ *********************************************************************************************************************** */ - #include #include #include "me3630_w_general.h" #define MO_LOG_TAG "me3630_w_general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef ME3630_W_USING_GENERAL_OPS @@ -43,7 +42,7 @@ os_err_t me3630_w_at_test(mo_object_t *self) return at_parser_exec_cmd(parser, &resp, "AT"); } -os_err_t me3630_w_get_imei(mo_object_t * self,char * value, os_size_t len) +os_err_t me3630_w_get_imei(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_IMEI_LEN); @@ -52,18 +51,17 @@ os_err_t me3630_w_get_imei(mo_object_t * self,char * value, os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN")) { return OS_ERROR; } - if(at_resp_get_data_by_line(&resp, resp.line_counts - 1, "%s", value) <= 0) + if (at_resp_get_data_by_line(&resp, resp.line_counts - 1, "%s", value) <= 0) { ERROR("Get %s module imei failed.", self->name); return OS_ERROR; } - value[MO_IMEI_LEN] = '\0'; INFO("%s module imei:%s", self->name, value); @@ -71,7 +69,7 @@ os_err_t me3630_w_get_imei(mo_object_t * self,char * value, os_size_t len) return OS_EOK; } -os_err_t me3630_w_get_imsi(mo_object_t * self,char * value, os_size_t len) +os_err_t me3630_w_get_imsi(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_IMSI_LEN); @@ -80,12 +78,12 @@ os_err_t me3630_w_get_imsi(mo_object_t * self,char * value, os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * AT_RESP_TIMEOUT_DEF}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CIMI")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CIMI")) { return OS_ERROR; } - if(at_resp_get_data_by_line(&resp, resp.line_counts - 1, "%s", value) <= 0) + if (at_resp_get_data_by_line(&resp, resp.line_counts - 1, "%s", value) <= 0) { ERROR("Get %s module imsi failed.", self->name); return OS_ERROR; @@ -93,12 +91,12 @@ os_err_t me3630_w_get_imsi(mo_object_t * self,char * value, os_size_t len) value[MO_IMSI_LEN] = '\0'; - DEBUG("%s module imsi:%s",self->name,value); + DEBUG("%s module imsi:%s", self->name, value); return OS_EOK; } -os_err_t me3630_w_get_iccid(mo_object_t * self,char * value, os_size_t len) +os_err_t me3630_w_get_iccid(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_ICCID_LEN); @@ -107,14 +105,14 @@ os_err_t me3630_w_get_iccid(mo_object_t * self,char * value, os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+ZGETICCID")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+ZGETICCID")) { return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+ZGETICCID:", "+ZGETICCID: %s", value) <= 0) + if (at_resp_get_data_by_kw(&resp, "+ZGETICCID:", "+ZGETICCID: %s", value) <= 0) { - ERROR("Get %s module ccid failed.",self->name); + ERROR("Get %s module ccid failed.", self->name); return OS_ERROR; } @@ -123,7 +121,7 @@ os_err_t me3630_w_get_iccid(mo_object_t * self,char * value, os_size_t len) return OS_EOK; } -os_err_t me3630_w_get_cfun(mo_object_t * self, os_uint8_t *fun_lvl) +os_err_t me3630_w_get_cfun(mo_object_t *self, os_uint8_t *fun_lvl) { at_parser_t *parser = &self->parser; @@ -136,7 +134,7 @@ os_err_t me3630_w_get_cfun(mo_object_t * self, os_uint8_t *fun_lvl) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CFUN:", "+CFUN: %hhu",fun_lvl) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CFUN:", "+CFUN: %hhu", fun_lvl) <= 0) { ERROR("Get %s module level of functionality failed.", self->name); return OS_ERROR; @@ -162,9 +160,7 @@ os_err_t me3630_w_get_firmware_version(mo_object_t *self, mo_firmware_version_t char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+GMR"); if (result != OS_EOK) @@ -179,7 +175,7 @@ os_err_t me3630_w_get_firmware_version(mo_object_t *self, mo_firmware_version_t } const char *source_line = at_resp_get_line(&resp, 1); - os_size_t line_length = strlen(source_line); + os_size_t line_length = strlen(source_line); char **dest_line = &version->ver_info[0]; @@ -197,6 +193,4 @@ os_err_t me3630_w_get_firmware_version(mo_object_t *self, mo_firmware_version_t return OS_EOK; } - -#endif /* ME3630_W_USING_GENERAL_OPS */ - +#endif /* ME3630_W_USING_GENERAL_OPS */ diff --git a/components/molink/module/me3630_w/source/me3630_w_ifconfig.c b/components/molink/module/me3630_w/source/me3630_w_ifconfig.c index 4cd749d1..d005fa1a 100644 --- a/components/molink/module/me3630_w/source/me3630_w_ifconfig.c +++ b/components/molink/module/me3630_w/source/me3630_w_ifconfig.c @@ -30,7 +30,7 @@ #include #define MO_LOG_TAG "me3630_w.ifconfig" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef ME3630_W_USING_IFCONFIG_OPS @@ -56,12 +56,12 @@ os_err_t me3630_w_ifconfig(mo_object_t *self) } os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t ber = 0; if (me3630_w_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; } os_kprintf("\r\nLIST AT MODULE INFORMATIONS\r\n"); @@ -90,9 +90,9 @@ os_err_t me3630_w_get_ipaddr(mo_object_t *self, char ip[]) { #define IPADDR_MAX_STR_LEN_ME3630 64 at_parser_t *parser = &self->parser; - os_int8_t ucid = -1; - os_int8_t len = -1; - int i = 1; + os_int8_t ucid = -1; + os_int8_t len = -1; + int i = 1; char ipaddr[IPADDR_MAX_STR_LEN_ME3630] = {0}; char resp_buff[512] = {0}; @@ -110,7 +110,7 @@ os_err_t me3630_w_get_ipaddr(mo_object_t *self, char ip[]) do { memset(ipaddr, 0, sizeof(ipaddr)); - if (at_resp_get_data_by_line(&resp, i , "+CGPADDR: %d,%s", &ucid, ipaddr) <= 0) + if (at_resp_get_data_by_line(&resp, i, "+CGPADDR: %d,%s", &ucid, ipaddr) <= 0) { ERROR("Get ip address: parse resp fail."); result = OS_ERROR; @@ -118,12 +118,11 @@ os_err_t me3630_w_get_ipaddr(mo_object_t *self, char ip[]) } i = i + 1; len = strlen(ipaddr); - if(i > 6) + if (i > 6) { break; } - } - while(len == 0 || ipaddr[0] == '0' ); + } while (len == 0 || ipaddr[0] == '0'); if ((len < IPADDR_MIN_STR_LEN) || (len > IPADDR_MAX_STR_LEN)) { @@ -133,7 +132,7 @@ os_err_t me3630_w_get_ipaddr(mo_object_t *self, char ip[]) } else { - strncpy(ip, ipaddr,len); + strncpy(ip, ipaddr, len); DEBUG("IP address: %s", ip); } @@ -143,4 +142,3 @@ __exit: } #endif /* ME3630_W_USING_IFCONFIG_OPS */ - diff --git a/components/molink/module/me3630_w/source/me3630_w_netconn.c b/components/molink/module/me3630_w/source/me3630_w_netconn.c index 0100cb93..6a0aa3c2 100644 --- a/components/molink/module/me3630_w/source/me3630_w_netconn.c +++ b/components/molink/module/me3630_w/source/me3630_w_netconn.c @@ -29,7 +29,7 @@ #include #define MO_LOG_TAG "me3630_w.netconn" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define SEND_DATA_MAX_SIZE (1024) @@ -41,28 +41,26 @@ #endif #ifndef ME3630_W_NETCONN_MQ_MSG_MAX -#define ME3630_W_NETCONN_MQ_MSG_MAX (5) +#define ME3630_W_NETCONN_MQ_MSG_MAX (5) #endif #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) -#define ME3630_W_EVENT_CONN_OK (1L << 0) -#define ME3630_W_EVENT_SEND_OK (1L << 1) -#define ME3630_W_EVENT_RECV_OK (1L << 2) -#define ME3630_W_EVENT_CLOSE_OK (1L << 3) -#define ME3630_W_EVENT_CONN_FAIL (1L << 4) -#define ME3630_W_EVENT_SEND_FAIL (1L << 5) -#define ME3630_W_EVENT_DOMAIN_OK (1L << 6) -#define ME3630_W_EVENT_STAT_OK (1L << 7) -#define ME3630_W_EVENT_STAT_FAIL (1L << 8) - - +#define ME3630_W_EVENT_CONN_OK (1L << 0) +#define ME3630_W_EVENT_SEND_OK (1L << 1) +#define ME3630_W_EVENT_RECV_OK (1L << 2) +#define ME3630_W_EVENT_CLOSE_OK (1L << 3) +#define ME3630_W_EVENT_CONN_FAIL (1L << 4) +#define ME3630_W_EVENT_SEND_FAIL (1L << 5) +#define ME3630_W_EVENT_DOMAIN_OK (1L << 6) +#define ME3630_W_EVENT_STAT_OK (1L << 7) +#define ME3630_W_EVENT_STAT_FAIL (1L << 8) #ifdef ME3630_W_USING_NETCONN_OPS -static os_bool_t me3630_w_pdp_set(mo_object_t *module) +static os_bool_t me3630_w_pdp_set(mo_object_t *module) { - at_parser_t *parser = &module->parser; + at_parser_t *parser = &module->parser; char resp_buff[256] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * AT_RESP_TIMEOUT_DEF}; @@ -87,10 +85,10 @@ static os_bool_t me3630_w_pdp_set(mo_object_t *module) static os_bool_t me3630_w_check_zipcall(mo_object_t *module) { - at_parser_t *parser = &module->parser; - char zipcall[30] = {0}; - char resp_buff[256] = {0}; - char zpas[30] = {0}; + at_parser_t *parser = &module->parser; + char zipcall[30] = {0}; + char resp_buff[256] = {0}; + char zpas[30] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * AT_RESP_TIMEOUT_DEF}; if (at_parser_exec_cmd(parser, &resp, "AT+ZPAS?") != OS_EOK) @@ -109,7 +107,6 @@ static os_bool_t me3630_w_check_zipcall(mo_object_t *module) return OS_FALSE; } - if (at_parser_exec_cmd(parser, &resp, "AT+ZIPCALL?") != OS_EOK) { ERROR("Get ip call failed"); @@ -122,7 +119,7 @@ static os_bool_t me3630_w_check_zipcall(mo_object_t *module) return OS_FALSE; } - if ('1' != zipcall[0] ) + if ('1' != zipcall[0]) { if (at_parser_exec_cmd(parser, &resp, "AT+ZIPCALL=1") != OS_EOK) { @@ -146,17 +143,17 @@ static os_err_t me3630_w_unlock(os_mutex_t *mutex) return os_mutex_recursive_unlock(mutex); } -static os_err_t me3630_w_check_state(mo_object_t *module,os_int32_t connect_id) +static os_err_t me3630_w_check_state(mo_object_t *module, os_int32_t connect_id) { - at_parser_t *parser = &module->parser; - char resp_buff[256] = {0}; - char zipstat[30] = {0}; + at_parser_t *parser = &module->parser; + char resp_buff[256] = {0}; + char zipstat[30] = {0}; - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 6 * OS_TICK_PER_SECOND}; - result = at_parser_exec_cmd(parser, &resp, "AT+ZIPSTAT=%d",connect_id); + result = at_parser_exec_cmd(parser, &resp, "AT+ZIPSTAT=%d", connect_id); if (result != OS_EOK) { @@ -231,7 +228,6 @@ static mo_netconn_t *me3630_w_get_netconn_by_id(mo_object_t *module, os_int32_t } return OS_NULL; - } os_err_t me3630_w_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) @@ -239,7 +235,7 @@ os_err_t me3630_w_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_me3630_w_t *me3630_w = os_container_of(module, mo_me3630_w_t, parent); info->netconn_array = me3630_w->netconn; - info->netconn_nums = sizeof(me3630_w->netconn) / sizeof(me3630_w->netconn[0]); + info->netconn_nums = sizeof(me3630_w->netconn) / sizeof(me3630_w->netconn[0]); return OS_EOK; } @@ -256,9 +252,7 @@ mo_netconn_t *me3630_w_netconn_create(mo_object_t *module, mo_netconn_type_t typ return OS_NULL; } - netconn->mq = os_mq_create(ME3630_W_NETCONN_MQ_NAME, - ME3630_W_NETCONN_MQ_MSG_SIZE, - ME3630_W_NETCONN_MQ_MSG_MAX); + netconn->mq = os_mq_create(ME3630_W_NETCONN_MQ_NAME, ME3630_W_NETCONN_MQ_MSG_SIZE, ME3630_W_NETCONN_MQ_MSG_MAX); if (OS_NULL == netconn->mq) { ERROR("%s data queue create failed, no enough memory.", module->name); @@ -274,20 +268,17 @@ mo_netconn_t *me3630_w_netconn_create(mo_object_t *module, mo_netconn_type_t typ os_err_t me3630_w_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; - char zipstat[10] = {0}; - int i = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_ERROR; + char zipstat[10] = {0}; + int i = 0; - mo_me3630_w_t * me3630_w = os_container_of(module, mo_me3630_w_t, parent); + mo_me3630_w_t *me3630_w = os_container_of(module, mo_me3630_w_t, parent); me3630_w_lock(&me3630_w->netconn_lock); char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 10 * OS_TICK_PER_SECOND - }; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; switch (netconn->stat) { @@ -298,16 +289,16 @@ os_err_t me3630_w_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) if (result != OS_EOK) { ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); - me3630_w_unlock(&me3630_w->netconn_lock); + module->name, + (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + me3630_w_unlock(&me3630_w->netconn_lock); return result; } do { os_task_msleep(1000); - result = at_parser_exec_cmd(parser, &resp, "AT+ZIPSTAT=%d",netconn->connect_id); + result = at_parser_exec_cmd(parser, &resp, "AT+ZIPSTAT=%d", netconn->connect_id); if (result != OS_EOK) { @@ -323,8 +314,7 @@ os_err_t me3630_w_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) return result; } i++; - } - while('4' == zipstat[2]); + } while ('4' == zipstat[2]); if ('0' != zipstat[2]) { @@ -347,9 +337,9 @@ os_err_t me3630_w_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn id %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); @@ -358,15 +348,13 @@ os_err_t me3630_w_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) return OS_EOK; } - - os_err_t me3630_w_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port) { #define ZIP_CALL_TIMES (6) - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - char zipstat[10] = {0}; - mo_me3630_w_t * me3630_w = os_container_of(module, mo_me3630_w_t, parent); + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + char zipstat[10] = {0}; + mo_me3630_w_t *me3630_w = os_container_of(module, mo_me3630_w_t, parent); me3630_w_lock(&me3630_w->netconn_lock); char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -392,13 +380,13 @@ os_err_t me3630_w_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip ERROR("Wait module %s call ip !", module->name); i++; - if(i > ZIP_CALL_TIMES) + if (i > ZIP_CALL_TIMES) { ERROR("Wait module %s call ip failed !", module->name); break; } - os_task_msleep(5000); + os_task_msleep(5000); } } @@ -406,23 +394,13 @@ os_err_t me3630_w_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip { #ifdef ME3630_W_USING_TCP case NETCONN_TYPE_TCP: - result = at_parser_exec_cmd(parser, - &resp, - "AT+ZIPOPEN=%d,0,%s,%d", - netconn->connect_id, - remote_ip, - port); + result = at_parser_exec_cmd(parser, &resp, "AT+ZIPOPEN=%d,0,%s,%d", netconn->connect_id, remote_ip, port); break; #endif #ifdef ME3630_W_USING_UDP case NETCONN_TYPE_UDP: - result = at_parser_exec_cmd(parser, - &resp, - "AT+ZIPOPEN=%d,1,%s,%d", - netconn->connect_id, - remote_ip, - port); + result = at_parser_exec_cmd(parser, &resp, "AT+ZIPOPEN=%d,1,%s,%d", netconn->connect_id, remote_ip, port); break; #endif @@ -439,7 +417,7 @@ os_err_t me3630_w_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip do { os_task_msleep(1000); - result = at_parser_exec_cmd(parser, &resp, "AT+ZIPSTAT=%d",netconn->connect_id); + result = at_parser_exec_cmd(parser, &resp, "AT+ZIPSTAT=%d", netconn->connect_id); if (result != OS_EOK) { @@ -452,8 +430,7 @@ os_err_t me3630_w_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip result = OS_ERROR; goto __exit; } - } - while('3' == zipstat[2]); + } while ('3' == zipstat[2]); if ('1' != zipstat[2]) { @@ -466,7 +443,7 @@ __exit: { ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); } @@ -481,11 +458,11 @@ __exit: os_size_t me3630_w_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t curr_size = 0; - os_uint32_t event = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t curr_size = 0; + os_uint32_t event = 0; mo_me3630_w_t *me3630_w = os_container_of(module, mo_me3630_w_t, parent); at_parser_exec_lock(parser); @@ -494,10 +471,7 @@ os_size_t me3630_w_netconn_send(mo_object_t *module, mo_netconn_t *netconn, cons char resp_buff[128] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 5 * OS_TICK_PER_SECOND - }; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; at_parser_set_end_mark(parser, ">", 1); @@ -586,10 +560,10 @@ os_err_t me3630_w_netconn_gethostbyname(mo_object_t *self, const char *domain_na OS_ASSERT(OS_NULL != domain_name); OS_ASSERT(OS_NULL != addr); - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; - char resp_buff[128] = {0}; + char resp_buff[128] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 6 * OS_TICK_PER_SECOND}; @@ -597,7 +571,7 @@ os_err_t me3630_w_netconn_gethostbyname(mo_object_t *self, const char *domain_na me3630_w->netconn_data = addr; - if(OS_FALSE == me3630_w_check_zipcall(self)) + if (OS_FALSE == me3630_w_check_zipcall(self)) { result = OS_ERROR; goto __exit; @@ -634,9 +608,9 @@ static void urc_send_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; - mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_me3630_w_t *me3630_w = os_container_of(module, mo_me3630_w_t, parent); + os_int32_t data_size = 0; + mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_me3630_w_t *me3630_w = os_container_of(module, mo_me3630_w_t, parent); sscanf(data, "+ZIPSENDRAW: %d,%d", &connect_id, &data_size); @@ -652,16 +626,15 @@ static void urc_send_func(struct at_parser *parser, const char *data, os_size_t } } - static void urc_recv_data_func(struct at_parser *parser, mo_netconn_t *netconn, os_size_t data_size) { - mo_object_t *module = os_container_of(parser, mo_object_t, parser); - os_int32_t timeout = data_size > 10 ? data_size : 10; + mo_object_t *module = os_container_of(parser, mo_object_t, parser); + os_int32_t timeout = data_size > 10 ? data_size : 10; INFO("Moudle %s netconn %d receive %d bytes data", parser->name, netconn->connect_id, data_size); - char *recv_buff = os_calloc(1, data_size + 1); - char temp_buff[8] = {0}; + char *recv_buff = os_calloc(1, data_size + 1); + char temp_buff[8] = {0}; if (recv_buff == OS_NULL) { /* read and clean the coming data */ @@ -711,7 +684,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t os_int32_t connect_id = atoi(&tmp_ch); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = me3630_w_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) @@ -749,16 +722,16 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t return; } static at_urc_t gs_urc_table[] = { - {.prefix = "+ZIPSENDRAW:", .suffix = "\r\n", .func = urc_send_func}, - {.prefix = "", .suffix = "+ZIPRECV:", .func = urc_recv_func}, + {.prefix = "+ZIPSENDRAW:", .suffix = "\r\n", .func = urc_send_func}, + {.prefix = "", .suffix = "+ZIPRECV:", .func = urc_recv_func}, }; static void me3630_w_network_init(mo_object_t *module) { - at_parser_t *parser = &module->parser; - os_int32_t enable_num = 0; - os_int32_t reg_state = 0; - os_err_t result = OS_ERROR; + at_parser_t *parser = &module->parser; + os_int32_t enable_num = 0; + os_int32_t reg_state = 0; + os_err_t result = OS_ERROR; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; @@ -768,7 +741,7 @@ static void me3630_w_network_init(mo_object_t *module) { goto __exit; } - if (at_resp_get_data_by_kw(&resp, "+CREG:", "+CREG: %d,%d", &enable_num , ®_state) < 0) + if (at_resp_get_data_by_kw(&resp, "+CREG:", "+CREG: %d,%d", &enable_num, ®_state) < 0) { result = OS_ERROR; goto __exit; @@ -785,14 +758,12 @@ static void me3630_w_network_init(mo_object_t *module) { result = OS_ERROR; goto __exit; - } if (at_parser_exec_cmd(parser, &resp, "AT+CFUN=0") != OS_EOK) { result = OS_ERROR; goto __exit; - } if (at_parser_exec_cmd(parser, &resp, "AT+CFUN=1") != OS_EOK) @@ -806,7 +777,7 @@ static void me3630_w_network_init(mo_object_t *module) { goto __exit; } - if (at_resp_get_data_by_kw(&resp, "+CREG:", "+CREG: %d,%d", &enable_num , ®_state) < 0) + if (at_resp_get_data_by_kw(&resp, "+CREG:", "+CREG: %d,%d", &enable_num, ®_state) < 0) { goto __exit; } @@ -821,9 +792,8 @@ static void me3630_w_network_init(mo_object_t *module) goto __exit; } - __exit: - if(result != OS_EOK) + if (result != OS_EOK) { WARN("ME3630_W network init failed"); } @@ -850,4 +820,3 @@ void me3630_w_netconn_init(mo_me3630_w_t *module) } #endif /* ME3630_W_USING_NETCONN_OPS */ - diff --git a/components/molink/module/me3630_w/source/me3630_w_netserv.c b/components/molink/module/me3630_w/source/me3630_w_netserv.c index 88e2367e..69bb6dd6 100644 --- a/components/molink/module/me3630_w/source/me3630_w_netserv.c +++ b/components/molink/module/me3630_w/source/me3630_w_netserv.c @@ -29,12 +29,11 @@ #include #define MO_LOG_TAG "me3630_w.netserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define IP_SIZE 16 - #ifdef ME3630_W_USING_NETSERV_OPS os_err_t me3630_w_set_attach(mo_object_t *self, os_uint8_t attach_stat) @@ -124,7 +123,7 @@ os_err_t me3630_w_get_cgact(mo_object_t *self, os_uint8_t *cid, os_uint8_t *act_ at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; - if(0 == *cid) + if (0 == *cid) { ERROR("%s module not support cid 0!", self->name); return OS_ERROR; @@ -134,8 +133,8 @@ os_err_t me3630_w_get_cgact(mo_object_t *self, os_uint8_t *cid, os_uint8_t *act_ { return OS_ERROR; } - - if (at_resp_get_data_by_line(&resp, *cid , "+CGACT: %d,%d", cid, act_stat) <= 0) + + if (at_resp_get_data_by_line(&resp, *cid, "+CGACT: %d,%d", cid, act_stat) <= 0) { ERROR("Get %s module cgact state failed", self->name); return OS_ERROR; @@ -167,102 +166,99 @@ os_err_t me3630_w_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber) return OS_EOK; } -#define GET_ME3630_W_RSSI(rxlev) (0 - (63 - rxlev + 48)) -#define ME3630_W_MODULE_NET_TYPE 5 - -os_err_t me3630_w_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info) -{ - os_err_t ret = OS_EOK; - cell_info_t *cell_info = OS_NULL; - char *temp_buff = OS_NULL; - os_uint32_t cell_num = 0; - char earfcn[10]; -// char tmp_recv[120]; - - at_parser_t *parser = &self->parser; - - if (parser == OS_NULL) - { - ERROR("ME3630_W ping: at parser is NULL."); - return OS_ERROR; - } - if(!onepos_cell_info) - { - ERROR("input param is error!"); - return OS_ERROR; - } - - at_resp_t resp = {.buff = os_calloc(1, 1024), - .buff_size = 1024, - .timeout = 50 * OS_TICK_PER_SECOND - }; - - if (OS_NULL == resp.buff) - { - ERROR("Calloc me3630_w cell info response memory failed!"); - ret = OS_ENOMEM; - goto __exit; - } - - /* neighbor cell */ - if (at_parser_exec_cmd(parser, &resp, "AT+ZCDS?") < 0) - { - ret = OS_ERROR; - ERROR("AT cmd exec fail: AT+ZCDS?\n"); - goto __exit; - } - DEBUG("resp->line_counts : %d\r\n", resp.line_counts); - - cell_info = os_calloc(1, sizeof(cell_info_t)); - if(NULL == cell_info) - { - ERROR("malloc cell_info is null"); - ret = OS_ENOMEM; - return ret; - } - - INFO(" MCC MNC CID LAC RSSI\n"); - INFO(" ------------ ------------ ------------ ------------ ----\n"); - - /* main cell */ - - temp_buff = (char*)at_resp_get_line(&resp, 1); - if(strlen(temp_buff) > 25) - { - sscanf(temp_buff, - "+ZCDS:%[^,],%u,%u,%x,%x,%d,%*[^\r]", - earfcn, - &cell_info[cell_num].mcc, - &cell_info[cell_num].mnc, +#define GET_ME3630_W_RSSI(rxlev) (0 - (63 - rxlev + 48)) +#define ME3630_W_MODULE_NET_TYPE 5 + +os_err_t me3630_w_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info) +{ + os_err_t ret = OS_EOK; + cell_info_t *cell_info = OS_NULL; + char *temp_buff = OS_NULL; + os_uint32_t cell_num = 0; + char earfcn[10]; + // char tmp_recv[120]; + + at_parser_t *parser = &self->parser; + + if (parser == OS_NULL) + { + ERROR("ME3630_W ping: at parser is NULL."); + return OS_ERROR; + } + if (!onepos_cell_info) + { + ERROR("input param is error!"); + return OS_ERROR; + } + + at_resp_t resp = {.buff = os_calloc(1, 1024), .buff_size = 1024, .timeout = 50 * OS_TICK_PER_SECOND}; + + if (OS_NULL == resp.buff) + { + ERROR("Calloc me3630_w cell info response memory failed!"); + ret = OS_ENOMEM; + goto __exit; + } + + /* neighbor cell */ + if (at_parser_exec_cmd(parser, &resp, "AT+ZCDS?") < 0) + { + ret = OS_ERROR; + ERROR("AT cmd exec fail: AT+ZCDS?\n"); + goto __exit; + } + DEBUG("resp->line_counts : %d\r\n", resp.line_counts); + + cell_info = os_calloc(1, sizeof(cell_info_t)); + if (NULL == cell_info) + { + ERROR("malloc cell_info is null"); + ret = OS_ENOMEM; + return ret; + } + + INFO(" MCC MNC CID LAC RSSI\n"); + INFO(" ------------ ------------ ------------ ------------ ----\n"); + + /* main cell */ + + temp_buff = (char *)at_resp_get_line(&resp, 1); + if (strlen(temp_buff) > 25) + { + sscanf(temp_buff, + "+ZCDS:%[^,],%u,%u,%x,%x,%d,%*[^\r]", + earfcn, + &cell_info[cell_num].mcc, + &cell_info[cell_num].mnc, &cell_info[cell_num].lac, &cell_info[cell_num].cid, - &cell_info[cell_num].ss - ); - - INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", - cell_info[cell_num].mcc, cell_info[cell_num].mnc, cell_info[cell_num].cid, - cell_info[cell_num].lac, cell_info[cell_num].ss); - - } - else - { - cell_num --; - } - INFO(" ------------ ------------ ------------ ------------ ----\n"); - - onepos_cell_info->cell_num = ++cell_num; - onepos_cell_info->cell_info = cell_info; - onepos_cell_info->net_type = ME3630_W_MODULE_NET_TYPE; - -__exit: - - if (resp.buff != OS_NULL) - { - os_free(resp.buff); - } - - return ret; -} + &cell_info[cell_num].ss); + + INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", + cell_info[cell_num].mcc, + cell_info[cell_num].mnc, + cell_info[cell_num].cid, + cell_info[cell_num].lac, + cell_info[cell_num].ss); + } + else + { + cell_num--; + } + INFO(" ------------ ------------ ------------ ------------ ----\n"); -#endif /* me3630_w_USING_NETSERV_OPS */ + onepos_cell_info->cell_num = ++cell_num; + onepos_cell_info->cell_info = cell_info; + onepos_cell_info->net_type = ME3630_W_MODULE_NET_TYPE; + +__exit: + if (resp.buff != OS_NULL) + { + os_free(resp.buff); + } + + return ret; +} + +#endif /* me3630_w_USING_NETSERV_OPS */ diff --git a/components/molink/module/ml302/include/ml302.h b/components/molink/module/ml302/include/ml302.h index 3be87b57..74ed763c 100644 --- a/components/molink/module/ml302/include/ml302.h +++ b/components/molink/module/ml302/include/ml302.h @@ -74,18 +74,18 @@ extern "C" { #define ML302_NETCONN_NUM 6 #endif -#define ML302_MQTTC_NUM 1 /* The ML302 supports only one MQTT client */ +#define ML302_MQTTC_NUM 1 /* The ML302 supports only one MQTT client */ typedef struct mo_ml302 { mo_object_t parent; #ifdef ML302_USING_NETCONN_OPS mo_netconn_t netconn[ML302_NETCONN_NUM]; - - os_int32_t curr_connect; + + os_int32_t curr_connect; os_event_t netconn_evt; os_mutex_t netconn_lock; - void *netconn_data; + void *netconn_data; #endif /* ML302_USING_NETCONN_OPS */ #ifdef ML302_USING_MQTTC_OPS mo_mqttc_t mqttc[ML302_MQTTC_NUM]; @@ -94,7 +94,7 @@ typedef struct mo_ml302 } mo_ml302_t; mo_object_t *module_ml302_create(const char *name, void *parser_config); -os_err_t module_ml302_destroy(mo_object_t *self); +os_err_t module_ml302_destroy(mo_object_t *self); #endif /* MOLINK_USING_ML302 */ @@ -103,4 +103,3 @@ os_err_t module_ml302_destroy(mo_object_t *self); #endif /* __cplusplus */ #endif /* __ML302_H__ */ - diff --git a/components/molink/module/ml302/include/ml302_general.h b/components/molink/module/ml302/include/ml302_general.h index 3fb60812..6f3eb0c9 100644 --- a/components/molink/module/ml302/include/ml302_general.h +++ b/components/molink/module/ml302/include/ml302_general.h @@ -21,17 +21,16 @@ *********************************************************************************************************************** */ - -#ifndef __ML302_GENERAL_H__ -#define __ML302_GENERAL_H__ +#ifndef __ML302_GENERAL_H__ +#define __ML302_GENERAL_H__ #include "mo_general.h" -#ifdef __cplusplus -extern "C" { +#ifdef __cplusplus +extern "C" { #endif -#ifdef ML302_USING_GENERAL_OPS +#ifdef ML302_USING_GENERAL_OPS os_err_t ml302_at_test(mo_object_t *self); os_err_t ml302_get_imei(mo_object_t *self, char *value, os_size_t len); @@ -41,10 +40,10 @@ os_err_t ml302_get_cfun(mo_object_t *self, os_uint8_t *fun_lvl); os_err_t ml302_set_cfun(mo_object_t *self, os_uint8_t fun_lvl); os_err_t ml302_get_firmware_version(mo_object_t *self, mo_firmware_version_t *version); -#endif /* ML302_USING_GENERAL_OPS */ +#endif /* ML302_USING_GENERAL_OPS */ -#ifdef __cplusplus +#ifdef __cplusplus } #endif -#endif /* __ML302_GENERAL_H__ */ +#endif /* __ML302_GENERAL_H__ */ diff --git a/components/molink/module/ml302/include/ml302_mqttc.h b/components/molink/module/ml302/include/ml302_mqttc.h index f1216471..993ba11a 100644 --- a/components/molink/module/ml302/include/ml302_mqttc.h +++ b/components/molink/module/ml302/include/ml302_mqttc.h @@ -33,12 +33,12 @@ extern "C" { #ifdef ML302_USING_MQTTC_OPS mo_mqttc_t *ml302_mqttc_create(mo_object_t *module, mqttc_create_opts_t *create_opts); -os_err_t ml302_mqttc_connect(mo_mqttc_t *client, mqttc_conn_opts_t *conn_opts); -os_err_t ml302_mqttc_publish(mo_mqttc_t *client, const char *topic_filter, mqttc_msg_t *msg); -os_err_t ml302_mqttc_subscribe(mo_mqttc_t *client, const char *topic_filter, mqttc_qos_t qos); -os_err_t ml302_mqttc_unsubscribe(mo_mqttc_t *client, const char *topic_filter); -os_err_t ml302_mqttc_disconnect(mo_mqttc_t *client); -os_err_t ml302_mqttc_destroy(mo_mqttc_t *client); +os_err_t ml302_mqttc_connect(mo_mqttc_t *client, mqttc_conn_opts_t *conn_opts); +os_err_t ml302_mqttc_publish(mo_mqttc_t *client, const char *topic_filter, mqttc_msg_t *msg); +os_err_t ml302_mqttc_subscribe(mo_mqttc_t *client, const char *topic_filter, mqttc_qos_t qos); +os_err_t ml302_mqttc_unsubscribe(mo_mqttc_t *client, const char *topic_filter); +os_err_t ml302_mqttc_disconnect(mo_mqttc_t *client); +os_err_t ml302_mqttc_destroy(mo_mqttc_t *client); #endif /* ML302_USING_MQTTC_OPS */ diff --git a/components/molink/module/ml302/include/ml302_netconn.h b/components/molink/module/ml302/include/ml302_netconn.h index 7a3cb4ef..f6492470 100644 --- a/components/molink/module/ml302/include/ml302_netconn.h +++ b/components/molink/module/ml302/include/ml302_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef ML302_USING_NETCONN_OPS -os_err_t ml302_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t ml302_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *ml302_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t ml302_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t ml302_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t ml302_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t ml302_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t ml302_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t ml302_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef ML302_USING_DNS -os_err_t ml302_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t ml302_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* ML302_USING_NETCONN_OPS */ diff --git a/components/molink/module/ml302/include/ml302_netserv.h b/components/molink/module/ml302/include/ml302_netserv.h index 3e0feb19..738e181a 100644 --- a/components/molink/module/ml302/include/ml302_netserv.h +++ b/components/molink/module/ml302/include/ml302_netserv.h @@ -39,8 +39,7 @@ os_err_t ml302_get_reg(mo_object_t *self, eps_reg_info_t *info); os_err_t ml302_set_cgact(mo_object_t *self, os_uint8_t cid, os_uint8_t act_n); os_err_t ml302_get_cgact(mo_object_t *self, os_uint8_t *cid, os_uint8_t *act_stat); os_err_t ml302_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber); -os_err_t ml302_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info); - +os_err_t ml302_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info); #endif /* ML302_USING_NETSERV_OPS */ @@ -49,4 +48,3 @@ os_err_t ml302_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_ #endif /* __cplusplus */ #endif /* __ML302_NETSERV_H__ */ - diff --git a/components/molink/module/ml302/source/ml302.c b/components/molink/module/ml302/source/ml302.c index 16a151c8..7829b156 100644 --- a/components/molink/module/ml302/source/ml302.c +++ b/components/molink/module/ml302/source/ml302.c @@ -26,7 +26,7 @@ #include #define MO_LOG_TAG "ml302" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_ML302 @@ -35,39 +35,39 @@ #ifdef ML302_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = ml302_at_test, - .get_imei = ml302_get_imei, - .get_imsi = ml302_get_imsi, - .get_iccid = ml302_get_iccid, - .get_cfun = ml302_get_cfun, - .set_cfun = ml302_set_cfun, + .at_test = ml302_at_test, + .get_imei = ml302_get_imei, + .get_imsi = ml302_get_imsi, + .get_iccid = ml302_get_iccid, + .get_cfun = ml302_get_cfun, + .set_cfun = ml302_set_cfun, .get_firmware_version = ml302_get_firmware_version, }; #endif /* ML302_USING_GENERAL_OPS */ #ifdef ML302_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = ml302_set_attach, - .get_attach = ml302_get_attach, - .set_reg = ml302_set_reg, - .get_reg = ml302_get_reg, - .set_cgact = ml302_set_cgact, - .get_cgact = ml302_get_cgact, - .get_csq = ml302_get_csq, - .get_cell_info = ml302_get_cell_info, + .set_attach = ml302_set_attach, + .get_attach = ml302_get_attach, + .set_reg = ml302_set_reg, + .get_reg = ml302_get_reg, + .set_cgact = ml302_set_cgact, + .get_cgact = ml302_get_cgact, + .get_csq = ml302_get_csq, + .get_cell_info = ml302_get_cell_info, }; #endif /* ML302_USING_NETSERV_OPS */ #ifdef ML302_USING_PING_OPS static const struct mo_ping_ops gs_ping_ops = { - .ping = ml302_ping, + .ping = ml302_ping, }; #endif /* ML302_USING_PING_OPS */ #ifdef ML302_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = ml302_ifconfig, - .get_ipaddr = ml302_get_ipaddr, + .ifconfig = ml302_ifconfig, + .get_ipaddr = ml302_get_ipaddr, }; #endif /* ML302_USING_IFCONFIG_OPS */ @@ -75,14 +75,14 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void ml302_netconn_init(mo_ml302_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = ml302_netconn_create, - .destroy = ml302_netconn_destroy, + .create = ml302_netconn_create, + .destroy = ml302_netconn_destroy, #ifdef ML302_USING_DNS - .gethostbyname = ml302_netconn_gethostbyname, + .gethostbyname = ml302_netconn_gethostbyname, #endif - .connect = ml302_netconn_connect, - .send = ml302_netconn_send, - .get_info = ml302_netconn_get_info, + .connect = ml302_netconn_connect, + .send = ml302_netconn_send, + .get_info = ml302_netconn_get_info, }; #endif /* ML302_USING_NETCONN_OPS */ @@ -90,13 +90,13 @@ static const struct mo_netconn_ops gs_netconn_ops = { extern void ml302_mqttc_init(mo_ml302_t *module); static const struct mo_mqttc_ops gs_mqttc_ops = { - .create = ml302_mqttc_create, - .connect = ml302_mqttc_connect, - .publish = ml302_mqttc_publish, - .subscribe = ml302_mqttc_subscribe, - .unsubscribe = ml302_mqttc_unsubscribe, - .disconnect = ml302_mqttc_disconnect, - .destroy = ml302_mqttc_destroy, + .create = ml302_mqttc_create, + .connect = ml302_mqttc_connect, + .publish = ml302_mqttc_publish, + .subscribe = ml302_mqttc_subscribe, + .unsubscribe = ml302_mqttc_unsubscribe, + .disconnect = ml302_mqttc_disconnect, + .destroy = ml302_mqttc_destroy, }; #endif /* ML302_USING_MQTTC_OPS */ @@ -131,12 +131,10 @@ static void ml302_gernel_at_init(mo_object_t *self) static void ml302_netserv_at_init(mo_object_t *self) { at_parser_t *parser = &self->parser; - + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 5 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; os_int32_t verctrl_data1 = -1; os_int32_t verctrl_data2 = -1; @@ -201,9 +199,7 @@ static os_err_t ml302_at_init(mo_object_t *self) char resp_buff[32] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; result = at_parser_exec_cmd(parser, &resp, "ATE0"); if (result != OS_EOK) @@ -258,7 +254,7 @@ mo_object_t *module_ml302_create(const char *name, void *parser_config) ERROR("Create %s module instance failed, no enough memory.", name); return OS_NULL; } - + os_task_msleep(5000); /* make sure ml302 power on and be ready */ os_err_t result = mo_object_init(&(module->parent), name, parser_config); @@ -347,7 +343,7 @@ int ml302_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = ML302_NAME, + mo_parser_config_t parser_config = {.parser_name = ML302_NAME, .parser_device = device, .recv_buff_len = ML302_RECV_BUFF_LEN}; diff --git a/components/molink/module/ml302/source/ml302_general.c b/components/molink/module/ml302/source/ml302_general.c index e47e0e37..f0fd1e95 100644 --- a/components/molink/module/ml302/source/ml302_general.c +++ b/components/molink/module/ml302/source/ml302_general.c @@ -26,7 +26,7 @@ #include #define MO_LOG_TAG "ml302_general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef ML302_USING_GENERAL_OPS @@ -42,7 +42,7 @@ os_err_t ml302_at_test(mo_object_t *self) return at_parser_exec_cmd(parser, &resp, "AT"); } -os_err_t ml302_get_imei(mo_object_t * self,char * value,os_size_t len) +os_err_t ml302_get_imei(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_IMEI_LEN); @@ -51,7 +51,7 @@ os_err_t ml302_get_imei(mo_object_t * self,char * value,os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = OS_TICK_PER_SECOND}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN=1")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN=1")) { return OS_ERROR; } @@ -69,7 +69,7 @@ os_err_t ml302_get_imei(mo_object_t * self,char * value,os_size_t len) return OS_EOK; } -os_err_t ml302_get_imsi(mo_object_t * self,char * value,os_size_t len) +os_err_t ml302_get_imsi(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_IMSI_LEN); @@ -78,12 +78,12 @@ os_err_t ml302_get_imsi(mo_object_t * self,char * value,os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 3 * OS_TICK_PER_SECOND}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CIMI")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CIMI")) { return OS_ERROR; } - if(at_resp_get_data_by_line(&resp, 1, "%s", value) <= 0) + if (at_resp_get_data_by_line(&resp, 1, "%s", value) <= 0) { ERROR("Get %s module imsi failed."); return OS_ERROR; @@ -91,12 +91,12 @@ os_err_t ml302_get_imsi(mo_object_t * self,char * value,os_size_t len) value[MO_IMSI_LEN] = '\0'; - DEBUG("%s module imsi:%s",self->name,value); + DEBUG("%s module imsi:%s", self->name, value); return OS_EOK; } -os_err_t ml302_get_iccid(mo_object_t * self,char * value,os_size_t len) +os_err_t ml302_get_iccid(mo_object_t *self, char *value, os_size_t len) { OS_ASSERT(len > MO_ICCID_LEN); @@ -105,12 +105,12 @@ os_err_t ml302_get_iccid(mo_object_t * self,char * value,os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = OS_TICK_PER_SECOND}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+ICCID")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+ICCID")) { return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+ICCID:", "+ICCID: %s", value) <= 0) + if (at_resp_get_data_by_kw(&resp, "+ICCID:", "+ICCID: %s", value) <= 0) { ERROR("Get %s module ccid failed.", self->parser); return OS_ERROR; @@ -121,7 +121,7 @@ os_err_t ml302_get_iccid(mo_object_t * self,char * value,os_size_t len) return OS_EOK; } -os_err_t ml302_get_cfun(mo_object_t * self,os_uint8_t *fun_lvl) +os_err_t ml302_get_cfun(mo_object_t *self, os_uint8_t *fun_lvl) { at_parser_t *parser = &self->parser; @@ -134,7 +134,7 @@ os_err_t ml302_get_cfun(mo_object_t * self,os_uint8_t *fun_lvl) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CFUN:", "+CFUN: %hhu",fun_lvl) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CFUN:", "+CFUN: %hhu", fun_lvl) <= 0) { ERROR("Get %s module level of functionality failed.", self->name); return OS_ERROR; @@ -160,9 +160,7 @@ os_err_t ml302_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ve char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+GMR"); if (result != OS_EOK) @@ -177,7 +175,7 @@ os_err_t ml302_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ve } const char *source_line = at_resp_get_line(&resp, 1); - os_size_t line_length = strlen(source_line); + os_size_t line_length = strlen(source_line); char **dest_line = &version->ver_info[0]; @@ -196,4 +194,3 @@ os_err_t ml302_get_firmware_version(mo_object_t *self, mo_firmware_version_t *ve } #endif /* ML302_USING_GENERAL_OPS */ - diff --git a/components/molink/module/ml302/source/ml302_ifconfig.c b/components/molink/module/ml302/source/ml302_ifconfig.c index 902dd041..5f06f754 100644 --- a/components/molink/module/ml302/source/ml302_ifconfig.c +++ b/components/molink/module/ml302/source/ml302_ifconfig.c @@ -29,7 +29,7 @@ #include #define MO_LOG_TAG "ml302.ifconfig" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef ML302_USING_IFCONFIG_OPS @@ -55,12 +55,12 @@ os_err_t ml302_ifconfig(mo_object_t *self) } os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t ber = 0; if (ml302_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; } os_kprintf("\r\nLIST AT MODULE INFORMATION\r\n"); @@ -88,8 +88,8 @@ os_err_t ml302_ifconfig(mo_object_t *self) os_err_t ml302_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t ucid = -1; - os_int8_t len = -1; + os_int8_t ucid = -1; + os_int8_t len = -1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; diff --git a/components/molink/module/ml302/source/ml302_mqttc.c b/components/molink/module/ml302/source/ml302_mqttc.c index f3d5688d..acf75e19 100644 --- a/components/molink/module/ml302/source/ml302_mqttc.c +++ b/components/molink/module/ml302/source/ml302_mqttc.c @@ -30,7 +30,7 @@ #include #define MO_LOG_TAG "ml302.mqttc" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define ML302_MQTTC_ADDRESS_LEN_MAX (128) @@ -53,11 +53,10 @@ static os_bool_t ml302_check_create_opts(mqttc_create_opts_t *create_opts) } else if (create_opts->address.len > ML302_MQTTC_ADDRESS_LEN_MAX) { - ERROR("The host address or IP string is too long and the longest length is %d.", - ML302_MQTTC_ADDRESS_LEN_MAX); + ERROR("The host address or IP string is too long and the longest length is %d.", ML302_MQTTC_ADDRESS_LEN_MAX); return OS_FALSE; } - + return OS_TRUE; } @@ -67,9 +66,7 @@ static os_bool_t ml302_mqttc_check_state(mo_object_t *module) char resp_buff[128] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; if (at_parser_exec_cmd(parser, &resp, "AT+MQTTCFG?") != OS_EOK) { @@ -80,7 +77,7 @@ static os_bool_t ml302_mqttc_check_state(mo_object_t *module) if (OS_NULL == at_resp_get_line_by_kw(&resp, "+MQTTCFG:\"(null)\"")) { ERROR("The MQTT client in the %s module has not been released, please reset the module and try again", - module->name); + module->name); return OS_FALSE; } @@ -103,7 +100,7 @@ static mo_mqttc_t *ml302_mqttc_alloc(mo_object_t *module) ml302->mqttc[0].mqttc_id = 0; return &ml302->mqttc[0]; } - + return OS_NULL; } @@ -144,7 +141,7 @@ mo_mqttc_t *ml302_mqttc_create(mo_object_t *module, mqttc_create_opts_t *create_ ERROR("Module %s create options is not valid", module->name); return OS_NULL; } - + mo_ml302_t *ml302 = os_container_of(module, mo_ml302_t, parent); os_mutex_lock(&ml302->mqttc_lock, OS_IPC_WAITING_FOREVER); @@ -161,10 +158,11 @@ mo_mqttc_t *ml302_mqttc_create(mo_object_t *module, mqttc_create_opts_t *create_ { memset(client, 0, sizeof(mo_mqttc_t)); client = OS_NULL; - }else + } + else { client->module = module; - client->stat = MQTTC_STAT_INIT; + client->stat = MQTTC_STAT_INIT; } os_mutex_unlock(&ml302->mqttc_lock); @@ -208,14 +206,14 @@ static os_bool_t ml302_check_conn_opts(mqttc_conn_opts_t *conn_opts) return OS_FALSE; } } - + return OS_TRUE; } os_err_t ml302_mqttc_connect(mo_mqttc_t *client, mqttc_conn_opts_t *conn_opts) { mo_object_t *module = client->module; - + if (!ml302_check_conn_opts(conn_opts)) { ERROR("Module %s connect options is not valid", module->name); @@ -226,9 +224,7 @@ os_err_t ml302_mqttc_connect(mo_mqttc_t *client, mqttc_conn_opts_t *conn_opts) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 1 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 1 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+MQTTTO=%d", client->command_timeout / 1000); if (result != OS_EOK) @@ -257,14 +253,14 @@ os_err_t ml302_mqttc_connect(mo_mqttc_t *client, mqttc_conn_opts_t *conn_opts) } os_uint8_t user_falg = conn_opts->username.len > 0 ? 1 : 0; - os_uint8_t pwd_flag = conn_opts->password.len > 0 ? 1 : 0; + os_uint8_t pwd_flag = conn_opts->password.len > 0 ? 1 : 0; mqttc_will_opts_t *will_opts = &conn_opts->will_opts; resp.line_num = 4; /* AT+MQTTOPEN=,,,,,, */ - result = at_parser_exec_cmd(parser,\ + result = at_parser_exec_cmd(parser, &resp, "AT+MQTTOPEN=%d,%d,%d,%d,%d,\"%s\",\"%s\"", user_falg, @@ -301,7 +297,7 @@ os_err_t ml302_mqttc_publish(mo_mqttc_t *client, const char *topic_filter, mqttc ERROR("Module %s publish topic string length %d is not valid", module->name, strlen(topic_filter)); return OS_ERROR; } - + if (msg->payload_len > ML302_MQTTC_MSG_LEN_MAX) { ERROR("Module %s publish message length %d is not valid", module->name, msg->payload_len); @@ -312,10 +308,10 @@ os_err_t ml302_mqttc_publish(mo_mqttc_t *client, const char *topic_filter, mqttc char resp_buff[128] = {0}; - at_resp_t resp = {.buff = resp_buff, + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .line_num = 2, - .timeout = 5 * OS_TICK_PER_SECOND}; + .line_num = 2, + .timeout = 5 * OS_TICK_PER_SECOND}; at_parser_exec_lock(parser); @@ -371,9 +367,7 @@ os_err_t ml302_mqttc_subscribe(mo_mqttc_t *client, const char *topic_filter, mqt char resp_buff[128] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 5 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; /* AT+MQTTSUB=, */ os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+MQTTSUB=\"%s\",%d", topic_filter, qos); @@ -399,9 +393,7 @@ os_err_t ml302_mqttc_unsubscribe(mo_mqttc_t *client, const char *topic_filter) char resp_buff[128] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 5 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; /* AT+MQTTUNSUB= */ os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+MQTTUNSUB=\"%s\"", topic_filter); @@ -420,9 +412,7 @@ static os_err_t ml302_mqttc_do_disconnect(mo_mqttc_t *client) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 10 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+MQTTDISC"); if (result != OS_EOK) @@ -451,9 +441,7 @@ static os_err_t ml302_mqttc_do_destroy(mo_mqttc_t *client) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; return at_parser_exec_cmd(parser, &resp, "AT+MQTTDEL"); } @@ -520,12 +508,12 @@ static void urc_disconnect_func(struct at_parser *parser, const char *data, os_s { OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - + /* +MQTTDISC: OK */ if (strstr(data, "OK") != OS_NULL) { mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_ml302_t * ml302 = os_container_of(module, mo_ml302_t, parent); + mo_ml302_t *ml302 = os_container_of(module, mo_ml302_t, parent); mo_mqttc_t *client = &ml302->mqttc[0]; @@ -606,8 +594,8 @@ static void urc_publish_func(struct at_parser *parser, const char *data, os_size } mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_ml302_t *ml302 = os_container_of(module, mo_ml302_t, parent); - mo_mqttc_t *client = &ml302->mqttc[0]; + mo_ml302_t *ml302 = os_container_of(module, mo_ml302_t, parent); + mo_mqttc_t *client = &ml302->mqttc[0]; os_err_t result = mo_mqttc_data_queue_push_notice(client, msg); if (result != OS_EOK) @@ -619,8 +607,8 @@ static void urc_publish_func(struct at_parser *parser, const char *data, os_size static at_urc_t gs_urc_table[] = { {.prefix = "+MQTTPINGRSP:", .suffix = "\r\n", .func = urc_ping_func}, - {.prefix = "+MQTTREC:", .suffix = "\r\n", .func = urc_reconnect_func}, - {.prefix = "+MQTTDISC:", .suffix = "\r\n", .func = urc_disconnect_func}, + {.prefix = "+MQTTREC:", .suffix = "\r\n", .func = urc_reconnect_func}, + {.prefix = "+MQTTDISC:", .suffix = "\r\n", .func = urc_disconnect_func}, {.prefix = "+MQTTPUBLISH:", .suffix = "\r\n", .func = urc_publish_func}, }; diff --git a/components/molink/module/ml302/source/ml302_netconn.c b/components/molink/module/ml302/source/ml302_netconn.c index 599e605c..897c9bcc 100644 --- a/components/molink/module/ml302/source/ml302_netconn.c +++ b/components/molink/module/ml302/source/ml302_netconn.c @@ -30,7 +30,7 @@ #include #define MO_LOG_TAG "ml302.netconn" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define SEND_DATA_MAX_SIZE (1460) @@ -41,7 +41,7 @@ #endif #ifndef ML302_NETCONN_MQ_MSG_MAX -#define ML302_NETCONN_MQ_MSG_MAX (5) +#define ML302_NETCONN_MQ_MSG_MAX (5) #endif #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) @@ -69,10 +69,10 @@ static os_err_t ml302_unlock(os_mutex_t *mutex) static os_bool_t ml302_check_state(mo_object_t *module, os_int32_t connect_id) { - at_parser_t *parser = &module->parser; - char mipstate[50] = {0}; - const char connect[10] = "CONNECT"; - const char listen[10] = "LISTEN"; + at_parser_t *parser = &module->parser; + char mipstate[50] = {0}; + const char connect[10] = "CONNECT"; + const char listen[10] = "LISTEN"; char resp_buff[256] = {0}; @@ -141,14 +141,14 @@ os_err_t ml302_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_ml302_t *ml302 = os_container_of(module, mo_ml302_t, parent); info->netconn_array = ml302->netconn; - info->netconn_nums = sizeof(ml302->netconn) / sizeof(ml302->netconn[0]); + info->netconn_nums = sizeof(ml302->netconn) / sizeof(ml302->netconn[0]); return OS_EOK; } mo_netconn_t *ml302_netconn_create(mo_object_t *module, mo_netconn_type_t type) { - mo_ml302_t *ml302 = os_container_of(module, mo_ml302_t, parent); + mo_ml302_t *ml302 = os_container_of(module, mo_ml302_t, parent); ml302_lock(&ml302->netconn_lock); @@ -159,9 +159,7 @@ mo_netconn_t *ml302_netconn_create(mo_object_t *module, mo_netconn_type_t type) return OS_NULL; } - netconn->mq = os_mq_create(ML302_NETCONN_MQ_NAME, - ML302_NETCONN_MQ_MSG_SIZE, - ML302_NETCONN_MQ_MSG_MAX); + netconn->mq = os_mq_create(ML302_NETCONN_MQ_NAME, ML302_NETCONN_MQ_MSG_SIZE, ML302_NETCONN_MQ_MSG_MAX); if (OS_NULL == netconn->mq) { ERROR("%s data queue create failed, no enough memory.", module->name); @@ -183,10 +181,10 @@ static os_err_t ml302_netconn_do_destroy(mo_object_t *module, mo_netconn_t *netc char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .timeout = 5 * OS_TICK_PER_SECOND, - .line_num = 1}; + .timeout = 5 * OS_TICK_PER_SECOND, + .line_num = 1}; os_err_t result = OS_EOK; @@ -194,23 +192,18 @@ static os_err_t ml302_netconn_do_destroy(mo_object_t *module, mo_netconn_t *netc if (result != OS_EOK) { - ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + ERROR("Module %s destroy %s netconn failed", module->name, (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); return result; } const char *source_line = at_resp_get_line(&resp, 1); if (OS_NULL == source_line) { - ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + ERROR("Module %s destroy %s netconn failed", module->name, (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); return OS_ERROR; } - if ((strstr(source_line, ",CLOSE OK") != OS_NULL && - (source_line[0] - 0X30) == netconn->connect_id) || + if ((strstr(source_line, ",CLOSE OK") != OS_NULL && (source_line[0] - 0X30) == netconn->connect_id) || ml302_check_state(module, netconn->connect_id)) /* Reconfirm that the connection is closed */ { return OS_EOK; @@ -221,10 +214,10 @@ static os_err_t ml302_netconn_do_destroy(mo_object_t *module, mo_netconn_t *netc os_err_t ml302_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; DEBUG("Module %s in %d netconn status", module->name, netconn->stat); - mo_ml302_t *ml302 = os_container_of(module, mo_ml302_t, parent); + mo_ml302_t *ml302 = os_container_of(module, mo_ml302_t, parent); ml302_lock(&ml302->netconn_lock); switch (netconn->stat) @@ -236,8 +229,8 @@ os_err_t ml302_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) if (result != OS_EOK) { ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + module->name, + (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); ml302_unlock(&ml302->netconn_lock); return result; @@ -256,9 +249,9 @@ os_err_t ml302_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn id %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); @@ -271,8 +264,7 @@ os_err_t ml302_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ad { at_parser_t *parser = &module->parser; - - mo_ml302_t * ml302 = os_container_of(module, mo_ml302_t, parent); + mo_ml302_t *ml302 = os_container_of(module, mo_ml302_t, parent); ml302_lock(&ml302->netconn_lock); char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -293,23 +285,15 @@ os_err_t ml302_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ad { #ifdef ML302_USING_TCP case NETCONN_TYPE_TCP: - result = at_parser_exec_cmd(parser, - &resp, - "AT+MIPOPEN=%d,\"TCP\",\"%s\",%d", - netconn->connect_id, - remote_ip, - port); + result = + at_parser_exec_cmd(parser, &resp, "AT+MIPOPEN=%d,\"TCP\",\"%s\",%d", netconn->connect_id, remote_ip, port); break; #endif #ifdef ML302_USING_UDP case NETCONN_TYPE_UDP: - result = at_parser_exec_cmd(parser, - &resp, - "AT+MIPOPEN=%d,\"UDP\",\"%s\",%d", - netconn->connect_id, - remote_ip, - port); + result = + at_parser_exec_cmd(parser, &resp, "AT+MIPOPEN=%d,\"UDP\",\"%s\",%d", netconn->connect_id, remote_ip, port); break; #endif @@ -356,7 +340,7 @@ __exit: { ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); } @@ -370,11 +354,11 @@ __exit: os_size_t ml302_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t curr_size = 0; - os_uint32_t event = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t curr_size = 0; + os_uint32_t event = 0; mo_ml302_t *ml302 = os_container_of(module, mo_ml302_t, parent); @@ -384,10 +368,7 @@ os_size_t ml302_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const c char resp_buff[128] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 5 * OS_TICK_PER_SECOND - }; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; at_parser_set_end_mark(parser, ">", 1); @@ -478,8 +459,8 @@ os_err_t ml302_netconn_gethostbyname(mo_object_t *self, const char *domain_name, OS_ASSERT(OS_NULL != addr); at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - os_uint32_t event = 0; + os_err_t result = OS_EOK; + os_uint32_t event = 0; char resp_buff[128] = {0}; @@ -532,7 +513,7 @@ static void urc_connect_func(struct at_parser *parser, const char *data, os_size OS_ASSERT(OS_NULL != data); mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_ml302_t *ml302 = os_container_of(module, mo_ml302_t, parent); + mo_ml302_t *ml302 = os_container_of(module, mo_ml302_t, parent); os_int32_t connect_id = -1; connect_id = data[0] - '0'; @@ -552,7 +533,7 @@ static void urc_send_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_ml302_t *ml302 = os_container_of(module, mo_ml302_t, parent); + mo_ml302_t *ml302 = os_container_of(module, mo_ml302_t, parent); os_int32_t curr_connect = ml302->curr_connect; @@ -573,7 +554,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; + os_int32_t data_size = 0; sscanf(data, "+MIPURC: \"recv\",%d,%d", &connect_id, &data_size); @@ -595,8 +576,8 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t { /* read and clean the coming data */ ERROR("Calloc recv buff %d bytes fail, no enough memory", data_size * 2); - os_size_t temp_size = 0; - char temp_buff[8] = {0}; + os_size_t temp_size = 0; + char temp_buff[8] = {0}; while (temp_size < data_size) { if (data_size - temp_size > sizeof(temp_buff)) @@ -630,7 +611,7 @@ static void urc_state_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - os_int32_t connect_id = 0; + os_int32_t connect_id = 0; os_int32_t connect_state = 0; sscanf(data, "+MIPURC: \"STATE\",%d,%d", &connect_id, &connect_state); @@ -642,14 +623,10 @@ static void urc_state_func(struct at_parser *parser, const char *data, os_size_t switch (connect_state) { case 1: - WARN("Module %s receive close urc data of connect %d, server closed the connection.", - module->name, - connect_id); + WARN("Module %s receive close urc data of connect %d, server closed the connection.", module->name, connect_id); break; case 2: - WARN("Module %s receive close urc data of connect %d, connection exception.", - module->name, - connect_id); + WARN("Module %s receive close urc data of connect %d, connection exception.", module->name, connect_id); break; default: break; @@ -664,7 +641,7 @@ static void urc_mdnsgip_func(struct at_parser *parser, const char *data, os_size OS_ASSERT(OS_NULL != data); #define HOST_NAME_MAX_LEN 50 mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_ml302_t *ml302 = os_container_of(module, mo_ml302_t, parent); + mo_ml302_t *ml302 = os_container_of(module, mo_ml302_t, parent); os_int32_t result = 0; @@ -672,7 +649,7 @@ static void urc_mdnsgip_func(struct at_parser *parser, const char *data, os_size if (0 == result) { - char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; + char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; sscanf(data, "+MDNSGIP: %*d,\"%*[^\"]\",\"%[^\"]", recvip); recvip[IPADDR_MAX_STR_LEN] = '\0'; inet_aton(recvip, (ip_addr_t *)ml302->netconn_data); @@ -711,7 +688,7 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t sscanf(data, "%d,CLOSED", &connect_id); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = ml302_get_netconn_by_id(module, connect_id); if (NETCONN_STAT_CONNECT == netconn->stat) @@ -723,11 +700,11 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t } static at_urc_t gs_urc_table[] = { - {.prefix = "", .suffix = "CONNECT OK\r\n", .func = urc_connect_func}, - {.prefix = "", .suffix = "SEND OK\r\n", .func = urc_send_func}, - {.prefix = "+MIPURC:", .suffix = "\r\n", .func = urc_mipurc_func}, - {.prefix = "+MDNSGIP:", .suffix = "\r\n", .func = urc_mdnsgip_func}, - {.prefix = "", .suffix = ",CLOSED\r\n", .func = urc_close_func}, + {.prefix = "", .suffix = "CONNECT OK\r\n", .func = urc_connect_func}, + {.prefix = "", .suffix = "SEND OK\r\n", .func = urc_send_func}, + {.prefix = "+MIPURC:", .suffix = "\r\n", .func = urc_mipurc_func}, + {.prefix = "+MDNSGIP:", .suffix = "\r\n", .func = urc_mdnsgip_func}, + {.prefix = "", .suffix = ",CLOSED\r\n", .func = urc_close_func}, }; void ml302_netconn_init(mo_ml302_t *module) diff --git a/components/molink/module/ml302/source/ml302_netserv.c b/components/molink/module/ml302/source/ml302_netserv.c index 093fabd5..79c6a7e1 100644 --- a/components/molink/module/ml302/source/ml302_netserv.c +++ b/components/molink/module/ml302/source/ml302_netserv.c @@ -29,7 +29,7 @@ #include #define MO_LOG_TAG "ml302.netserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef ML302_USING_NETSERV_OPS @@ -59,7 +59,7 @@ os_err_t ml302_get_attach(mo_object_t *self, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) { ERROR("Get %s module attach state failed", self->name); return OS_ERROR; @@ -159,150 +159,152 @@ os_err_t ml302_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber) return OS_EOK; } -#define GET_ML302_RSSI(rxlev) (0 - (63 - rxlev + 48)) -#define ML302_MODULE_NET_TYPE 5 - -os_err_t ml302_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info) -{ - os_err_t ret = OS_EOK; - os_size_t i = 0; - cell_info_t *cell_info = OS_NULL; - char *temp_buff = OS_NULL; - os_uint32_t cell_num = 0; - os_uint32_t frequency = 0; - os_uint32_t rsrp = 0; - os_uint32_t rsrq = 0; - os_uint32_t rxlev = 0; - os_uint32_t pcid = 0; - char imsi[20]; - char earfcn[10]; - os_uint32_t roming_flag; - os_uint32_t bandinfo; - at_parser_t *parser = &self->parser; - - if (parser == OS_NULL) - { - ERROR("ML302 ping: at parser is NULL."); - return OS_ERROR; - } - if(!onepos_cell_info) - { - ERROR("input param is error!"); - return OS_ERROR; - } - - at_resp_t resp = {.buff = os_calloc(1, 1024), - .buff_size = 1024, - .timeout = 50 * OS_TICK_PER_SECOND - }; - - if (OS_NULL == resp.buff) - { - ERROR("Calloc ml302 cell info response memory failed!"); - ret = OS_ENOMEM; - goto __exit; - } - - /* neighbor cell */ - if (at_parser_exec_cmd(parser, &resp, "AT+CCED=0,2") < 0) - { - ret = OS_ERROR; - ERROR("AT cmd exec fail: AT+CCED=0,2\n"); - goto __exit; - } - DEBUG("resp->line_counts : %d\r\n", resp.line_counts); - - cell_info = os_calloc((resp.line_counts), sizeof(cell_info_t)); - ERROR("resp.line_counts =%d",resp.line_counts); - if(NULL == cell_info) - { - ERROR("malloc cell_info is null"); - ret = OS_ENOMEM; - return ret; - } - - INFO(" MCC MNC CID LAC RSSI\n"); - INFO(" ------------ ------------ ------------ ------------ ----\n"); - - for (i = 1; i < resp.line_counts; i++) - { - temp_buff = (char*)at_resp_get_line(&resp, i); - if(strlen(temp_buff) > 25) { - sscanf(temp_buff, - "+CCED:LTE neighbor cell:%u,%u,%u,%u,%u,%u,%u,%u,%u", - &cell_info[cell_num].mcc, - &cell_info[cell_num].mnc, - &frequency, - &cell_info[cell_num].cid, - &rsrp, - &rsrq, - &cell_info[cell_num].lac, - &rxlev, - &pcid); - - cell_info[cell_num].ss = GET_ML302_RSSI(rxlev); - if(cell_info[cell_num].mcc) - { - INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", - cell_info[cell_num].mcc, cell_info[cell_num].mnc, cell_info[cell_num].cid, - cell_info[cell_num].lac, cell_info[cell_num].ss); - cell_num ++; - } - } - } - /* main cell */ - if (at_parser_exec_cmd(parser, &resp, "AT+CCED=0,1") < 0) - { - ret = OS_ERROR; - os_free(cell_info); - ERROR("AT cmd exec fail: AT+CCED=0,1\n"); - goto __exit; - } - DEBUG("resp->line_counts : %d\r\n", &resp.line_counts); - - temp_buff = (char*)at_resp_get_line(&resp, 1); - if(strlen(temp_buff) > 25) - { - sscanf(temp_buff, - "+CCED:LTE current cell:%u,%u,%[^,],%u,%u,%*[^,],%[^,],%u,%u,%u,%u,%u,%u", - &cell_info[cell_num].mcc, - &cell_info[cell_num].mnc, - imsi, - &roming_flag, - &bandinfo, - earfcn, - &cell_info[cell_num].cid, - &rsrp, - &rsrq, - &cell_info[cell_num].lac, - &rxlev, - &pcid); - - cell_info[cell_num].ss = GET_ML302_RSSI(rxlev); - INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", - cell_info[cell_num].mcc, cell_info[cell_num].mnc, cell_info[cell_num].cid, - cell_info[cell_num].lac, cell_info[cell_num].ss); - - } - else - { - cell_num --; - } - INFO(" ------------ ------------ ------------ ------------ ----\n"); - - onepos_cell_info->cell_num = ++cell_num; - onepos_cell_info->cell_info = cell_info; - onepos_cell_info->net_type = ML302_MODULE_NET_TYPE; - -__exit: - - if (resp.buff != OS_NULL) - { - os_free(resp.buff); - } - - return ret; -} +#define GET_ML302_RSSI(rxlev) (0 - (63 - rxlev + 48)) +#define ML302_MODULE_NET_TYPE 5 -#endif /* ml302_USING_NETSERV_OPS */ +os_err_t ml302_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info) +{ + os_err_t ret = OS_EOK; + os_size_t i = 0; + cell_info_t *cell_info = OS_NULL; + char *temp_buff = OS_NULL; + os_uint32_t cell_num = 0; + os_uint32_t frequency = 0; + os_uint32_t rsrp = 0; + os_uint32_t rsrq = 0; + os_uint32_t rxlev = 0; + os_uint32_t pcid = 0; + char imsi[20]; + char earfcn[10]; + os_uint32_t roming_flag; + os_uint32_t bandinfo; + at_parser_t *parser = &self->parser; + + if (parser == OS_NULL) + { + ERROR("ML302 ping: at parser is NULL."); + return OS_ERROR; + } + if (!onepos_cell_info) + { + ERROR("input param is error!"); + return OS_ERROR; + } + + at_resp_t resp = {.buff = os_calloc(1, 1024), .buff_size = 1024, .timeout = 50 * OS_TICK_PER_SECOND}; + + if (OS_NULL == resp.buff) + { + ERROR("Calloc ml302 cell info response memory failed!"); + ret = OS_ENOMEM; + goto __exit; + } + + /* neighbor cell */ + if (at_parser_exec_cmd(parser, &resp, "AT+CCED=0,2") < 0) + { + ret = OS_ERROR; + ERROR("AT cmd exec fail: AT+CCED=0,2\n"); + goto __exit; + } + DEBUG("resp->line_counts : %d\r\n", resp.line_counts); + + cell_info = os_calloc((resp.line_counts), sizeof(cell_info_t)); + ERROR("resp.line_counts =%d", resp.line_counts); + if (NULL == cell_info) + { + ERROR("malloc cell_info is null"); + ret = OS_ENOMEM; + return ret; + } + INFO(" MCC MNC CID LAC RSSI\n"); + INFO(" ------------ ------------ ------------ ------------ ----\n"); + + for (i = 1; i < resp.line_counts; i++) + { + temp_buff = (char *)at_resp_get_line(&resp, i); + if (strlen(temp_buff) > 25) + { + sscanf(temp_buff, + "+CCED:LTE neighbor cell:%u,%u,%u,%u,%u,%u,%u,%u,%u", + &cell_info[cell_num].mcc, + &cell_info[cell_num].mnc, + &frequency, + &cell_info[cell_num].cid, + &rsrp, + &rsrq, + &cell_info[cell_num].lac, + &rxlev, + &pcid); + + cell_info[cell_num].ss = GET_ML302_RSSI(rxlev); + if (cell_info[cell_num].mcc) + { + INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", + cell_info[cell_num].mcc, + cell_info[cell_num].mnc, + cell_info[cell_num].cid, + cell_info[cell_num].lac, + cell_info[cell_num].ss); + cell_num++; + } + } + } + /* main cell */ + if (at_parser_exec_cmd(parser, &resp, "AT+CCED=0,1") < 0) + { + ret = OS_ERROR; + os_free(cell_info); + ERROR("AT cmd exec fail: AT+CCED=0,1\n"); + goto __exit; + } + DEBUG("resp->line_counts : %d\r\n", &resp.line_counts); + + temp_buff = (char *)at_resp_get_line(&resp, 1); + if (strlen(temp_buff) > 25) + { + sscanf(temp_buff, + "+CCED:LTE current cell:%u,%u,%[^,],%u,%u,%*[^,],%[^,],%u,%u,%u,%u,%u,%u", + &cell_info[cell_num].mcc, + &cell_info[cell_num].mnc, + imsi, + &roming_flag, + &bandinfo, + earfcn, + &cell_info[cell_num].cid, + &rsrp, + &rsrq, + &cell_info[cell_num].lac, + &rxlev, + &pcid); + + cell_info[cell_num].ss = GET_ML302_RSSI(rxlev); + INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", + cell_info[cell_num].mcc, + cell_info[cell_num].mnc, + cell_info[cell_num].cid, + cell_info[cell_num].lac, + cell_info[cell_num].ss); + } + else + { + cell_num--; + } + INFO(" ------------ ------------ ------------ ------------ ----\n"); + + onepos_cell_info->cell_num = ++cell_num; + onepos_cell_info->cell_info = cell_info; + onepos_cell_info->net_type = ML302_MODULE_NET_TYPE; + +__exit: + + if (resp.buff != OS_NULL) + { + os_free(resp.buff); + } + + return ret; +} + +#endif /* ml302_USING_NETSERV_OPS */ diff --git a/components/molink/module/ml302/source/ml302_ping.c b/components/molink/module/ml302/source/ml302_ping.c index 47633975..e4597ac1 100644 --- a/components/molink/module/ml302/source/ml302_ping.c +++ b/components/molink/module/ml302/source/ml302_ping.c @@ -24,7 +24,7 @@ #include "ml302_ping.h" #define MO_LOG_TAG "ml302.ping" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define ML302_MIN_PING_PKG_LEN (36) @@ -36,15 +36,15 @@ os_err_t ml302_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - os_uint32_t req_time = 0; - os_uint16_t rcv_len = 0; - os_int16_t ttl = -1; - os_uint32_t timeout_s = timeout / 1000; /* Milliseconds convert to seconds */ + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; + os_uint32_t req_time = 0; + os_uint16_t rcv_len = 0; + os_int16_t ttl = -1; + os_uint32_t timeout_s = timeout / 1000; /* Milliseconds convert to seconds */ char ip_addr[IPADDR_MAX_STR_LEN + 1] = {0}; - char ret_buff[36] = {0}; + char ret_buff[36] = {0}; if (parser == OS_NULL) { @@ -54,15 +54,19 @@ os_err_t ml302_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uin if ((len < ML302_MIN_PING_PKG_LEN) || (len > ML302_MAX_PING_PKG_LEN)) { - ERROR("ML302 ping: ping package len[%d] is out of range[%d, %d].", - len, ML302_MIN_PING_PKG_LEN, ML302_MAX_PING_PKG_LEN); + ERROR("ML302 ping: ping package len[%d] is out of range[%d, %d].", + len, + ML302_MIN_PING_PKG_LEN, + ML302_MAX_PING_PKG_LEN); return OS_ERROR; } if ((timeout_s < ML302_MIN_PING_TIMEOUT) || (timeout_s > ML302_MAX_PING_TIMEOUT)) { - ERROR("ML302 ping: ping timeout %us is out of range[%ds, %ds].", - timeout_s, ML302_MIN_PING_TIMEOUT, ML302_MAX_PING_TIMEOUT); + ERROR("ML302 ping: ping timeout %us is out of range[%ds, %ds].", + timeout_s, + ML302_MIN_PING_TIMEOUT, + ML302_MAX_PING_TIMEOUT); return OS_ERROR; } @@ -70,11 +74,10 @@ os_err_t ml302_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uin char resp_buff[256] = {0}; - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .line_num = 3, - .timeout = (5 + timeout_s) * OS_TICK_PER_SECOND - }; + .line_num = 3, + .timeout = (5 + timeout_s) * OS_TICK_PER_SECOND}; /* Send commond "AT+MPING= or ip addr" and wait response */ /* Exec AT+MPING="www.baidu.com",2,1,64 and return: 0 183.232.231.172: bytes = 36 time = 96(ms), TTL = 255 */ @@ -119,8 +122,8 @@ os_err_t ml302_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uin { inet_aton(ip_addr, &(resp->ip_addr)); resp->data_len = rcv_len; - resp->ttl = ttl; - resp->time = req_time; + resp->ttl = ttl; + resp->time = req_time; } __exit: diff --git a/components/molink/module/n21/include/n21.h b/components/molink/module/n21/include/n21.h index 962956e6..448e7b64 100644 --- a/components/molink/module/n21/include/n21.h +++ b/components/molink/module/n21/include/n21.h @@ -73,16 +73,16 @@ typedef struct mo_n21 mo_object_t parent; #ifdef N21_USING_NETCONN_OPS mo_netconn_t netconn[N21_NETCONN_NUM]; - - os_int32_t curr_connect; + + os_int32_t curr_connect; os_event_t netconn_evt; os_mutex_t netconn_lock; - void *netconn_data; + void *netconn_data; #endif /* N21_USING_NETCONN_OPS */ } mo_n21_t; mo_object_t *module_n21_create(const char *name, void *parser_config); -os_err_t module_n21_destroy(mo_object_t *self); +os_err_t module_n21_destroy(mo_object_t *self); #endif /* MOLINK_USING_N21 */ @@ -91,4 +91,3 @@ os_err_t module_n21_destroy(mo_object_t *self); #endif /* __cplusplus */ #endif /* __N21_H__ */ - diff --git a/components/molink/module/n21/include/n21_netconn.h b/components/molink/module/n21/include/n21_netconn.h index 60ff7ce3..79b97b42 100644 --- a/components/molink/module/n21/include/n21_netconn.h +++ b/components/molink/module/n21/include/n21_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef N21_USING_NETCONN_OPS -os_err_t n21_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t n21_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *n21_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t n21_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t n21_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t n21_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t n21_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t n21_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t n21_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef N21_USING_DNS -os_err_t n21_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t n21_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* N21_USING_NETCONN_OPS */ diff --git a/components/molink/module/n21/source/n21.c b/components/molink/module/n21/source/n21.c index ceacaebd..54cef968 100644 --- a/components/molink/module/n21/source/n21.c +++ b/components/molink/module/n21/source/n21.c @@ -27,46 +27,45 @@ #include #define MO_LOG_TAG "n21" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" - #ifdef MOLINK_USING_N21 #define N21_RETRY_TIMES (10) #ifdef N21_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = n21_at_test, - .get_imei = n21_get_imei, - .get_imsi = n21_get_imsi, - .get_iccid = n21_get_iccid, - .get_cfun = n21_get_cfun, - .set_cfun = n21_set_cfun, + .at_test = n21_at_test, + .get_imei = n21_get_imei, + .get_imsi = n21_get_imsi, + .get_iccid = n21_get_iccid, + .get_cfun = n21_get_cfun, + .set_cfun = n21_set_cfun, .get_firmware_version = n21_get_firmware_version, }; #endif /* N21_USING_GENERAL_OPS */ #ifdef N21_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = n21_set_attach, - .get_attach = n21_get_attach, - .set_reg = n21_set_reg, - .get_reg = n21_get_reg, - .get_csq = n21_get_csq, + .set_attach = n21_set_attach, + .get_attach = n21_get_attach, + .set_reg = n21_set_reg, + .get_reg = n21_get_reg, + .get_csq = n21_get_csq, }; #endif /* N21_USING_NETSERV_OPS */ #ifdef N21_USING_PING_OPS static const struct mo_ping_ops gs_ping_ops = { - .ping = n21_ping, + .ping = n21_ping, }; #endif /* N21_USING_PING_OPS */ #ifdef N21_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = n21_ifconfig, - .get_ipaddr = n21_get_ipaddr, + .ifconfig = n21_ifconfig, + .get_ipaddr = n21_get_ipaddr, }; #endif /* N21_USING_IFCONFIG_OPS */ @@ -74,14 +73,14 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void n21_netconn_init(mo_n21_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = n21_netconn_create, - .destroy = n21_netconn_destroy, + .create = n21_netconn_create, + .destroy = n21_netconn_destroy, #ifdef N21_USING_DNS - .gethostbyname = n21_netconn_gethostbyname, + .gethostbyname = n21_netconn_gethostbyname, #endif - .connect = n21_netconn_connect, - .send = n21_netconn_send, - .get_info = n21_netconn_get_info, + .connect = n21_netconn_connect, + .send = n21_netconn_send, + .get_info = n21_netconn_get_info, }; #endif /* N21_USING_NETCONN_OPS */ @@ -121,9 +120,7 @@ static void n21_netserv_open(mo_object_t *self) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; if (at_parser_exec_cmd(parser, &resp, "AT+XIIC=1") != OS_EOK) { @@ -137,9 +134,7 @@ static void n21_netserv_at_init(mo_object_t *self) char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = OS_TICK_PER_SECOND}; eps_reg_info_t reg_info = {0}; @@ -193,16 +188,14 @@ static os_err_t n21_at_init(mo_object_t *self) char resp_buff[32] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; result = at_parser_exec_cmd(parser, &resp, "ATE0"); if (result != OS_EOK) { return result; } - + /* Try to initialize the module */ #ifdef N21_USING_GENERAL_OPS n21_gernel_at_init(self); @@ -325,7 +318,7 @@ int n21_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = N21_NAME, + mo_parser_config_t parser_config = {.parser_name = N21_NAME, .parser_device = device, .recv_buff_len = N21_RECV_BUFF_LEN}; diff --git a/components/molink/module/n21/source/n21_general.c b/components/molink/module/n21/source/n21_general.c index e9fd1112..58250b15 100644 --- a/components/molink/module/n21/source/n21_general.c +++ b/components/molink/module/n21/source/n21_general.c @@ -26,10 +26,9 @@ #include #define MO_LOG_TAG "n21_general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" - #define N21_VERSION_INFO_LEN (30) #ifdef N21_USING_GENERAL_OPS @@ -40,9 +39,7 @@ os_err_t n21_at_test(mo_object_t *self) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; return at_parser_exec_cmd(parser, &resp, "AT"); } @@ -55,11 +52,9 @@ os_err_t n21_get_imei(mo_object_t *self, char *value, os_size_t len) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN")) { return OS_ERROR; } @@ -85,9 +80,7 @@ os_err_t n21_get_imsi(mo_object_t *self, char *value, os_size_t len) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CIMI")) { @@ -115,9 +108,7 @@ os_err_t n21_get_iccid(mo_object_t *self, char *value, os_size_t len) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CCID")) { @@ -141,9 +132,7 @@ os_err_t n21_get_cfun(mo_object_t *self, os_uint8_t *fun_lvl) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CFUN?")) { @@ -165,9 +154,7 @@ os_err_t n21_set_cfun(mo_object_t *self, os_uint8_t fun_lvl) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 5 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND}; return at_parser_exec_cmd(parser, &resp, "AT+CFUN=%hhu", fun_lvl); } @@ -178,9 +165,7 @@ os_err_t n21_get_firmware_version(mo_object_t *self, mo_firmware_version_t *vers char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CGMR"); if (result != OS_EOK) @@ -221,4 +206,3 @@ os_err_t n21_get_firmware_version(mo_object_t *self, mo_firmware_version_t *vers } #endif /* N21_USING_GENERAL_OPS */ - diff --git a/components/molink/module/n21/source/n21_ifconfig.c b/components/molink/module/n21/source/n21_ifconfig.c index 60814fc0..a321f5bf 100644 --- a/components/molink/module/n21/source/n21_ifconfig.c +++ b/components/molink/module/n21/source/n21_ifconfig.c @@ -29,10 +29,9 @@ #include #define MO_LOG_TAG "n21_ifconfig" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" - #ifdef N21_USING_IFCONFIG_OPS os_err_t n21_ifconfig(mo_object_t *self) @@ -56,12 +55,12 @@ os_err_t n21_ifconfig(mo_object_t *self) } os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t ber = 0; if (n21_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; } os_kprintf("\r\nLIST AT MODULE INFORMATION\r\n"); @@ -94,9 +93,7 @@ os_err_t n21_get_ipaddr(mo_object_t *self, char ip[]) char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+XIIC?"); if (result != OS_EOK) diff --git a/components/molink/module/n21/source/n21_netconn.c b/components/molink/module/n21/source/n21_netconn.c index 2c176d2b..3205991b 100644 --- a/components/molink/module/n21/source/n21_netconn.c +++ b/components/molink/module/n21/source/n21_netconn.c @@ -29,10 +29,9 @@ #include #define MO_LOG_TAG "n21_netconn" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" - #define TCP_SEND_DATA_MAX_SIZE (4096) #define UDP_SEND_DATA_MAX_SIZE (1024) @@ -43,7 +42,7 @@ #endif #ifndef N21_NETCONN_MQ_MSG_MAX -#define N21_NETCONN_MQ_MSG_MAX (5) +#define N21_NETCONN_MQ_MSG_MAX (5) #endif #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) @@ -74,9 +73,7 @@ static os_bool_t n21_check_netconn_state(mo_object_t *module, os_int32_t connect char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; if (at_parser_exec_cmd(parser, &resp, "AT+IPSTATUS=%d", connect_id) != OS_EOK) { @@ -151,7 +148,7 @@ os_err_t n21_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_n21_t *n21 = os_container_of(module, mo_n21_t, parent); info->netconn_array = n21->netconn; - info->netconn_nums = sizeof(n21->netconn) / sizeof(n21->netconn[0]); + info->netconn_nums = sizeof(n21->netconn) / sizeof(n21->netconn[0]); return OS_EOK; } @@ -162,9 +159,7 @@ static os_err_t n21_netconn_set_format(mo_object_t *module) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; if (at_parser_exec_cmd(parser, &resp, "AT+RECVMODE?") != OS_EOK) { @@ -209,9 +204,7 @@ mo_netconn_t *n21_netconn_create(mo_object_t *module, mo_netconn_type_t type) return OS_NULL; } - netconn->mq = os_mq_create(N21_NETCONN_MQ_NAME, - N21_NETCONN_MQ_MSG_SIZE, - N21_NETCONN_MQ_MSG_MAX); + netconn->mq = os_mq_create(N21_NETCONN_MQ_NAME, N21_NETCONN_MQ_MSG_SIZE, N21_NETCONN_MQ_MSG_MAX); if (OS_NULL == netconn->mq) { ERROR("%s data queue create failed, no enough memory.", module->name); @@ -232,10 +225,7 @@ static os_err_t n21_netconn_do_destroy(mo_object_t *module, mo_netconn_t *netcon char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF, - .line_num = 1}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF, .line_num = 1}; os_err_t result = OS_EOK; @@ -250,18 +240,14 @@ static os_err_t n21_netconn_do_destroy(mo_object_t *module, mo_netconn_t *netcon if (result != OS_EOK) { - ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + ERROR("Module %s destroy %s netconn failed", module->name, (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); return result; } const char *source_line = at_resp_get_line(&resp, 1); if (OS_NULL == source_line) { - ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + ERROR("Module %s destroy %s netconn failed", module->name, (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); return OS_ERROR; } @@ -305,9 +291,9 @@ os_err_t n21_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn id %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); @@ -328,9 +314,7 @@ os_err_t n21_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 60 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 60 * OS_TICK_PER_SECOND}; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -340,7 +324,7 @@ os_err_t n21_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr /* AT+UDPSETUP=,, */ if (NETCONN_TYPE_TCP == netconn->type) - { /* AT+TCPSETUP=,, */ + { /* AT+TCPSETUP=,, */ result = at_parser_exec_cmd(parser, &resp, "AT+TCPSETUP=%d,%s,%d", netconn->connect_id, remote_ip, port); } else /* NETCONN_TYPE_UDP == netconn->type */ @@ -388,7 +372,7 @@ __exit: { ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); } @@ -402,11 +386,11 @@ __exit: os_size_t n21_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t curr_size = 0; - os_uint32_t event = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t curr_size = 0; + os_uint32_t event = 0; mo_n21_t *n21 = os_container_of(module, mo_n21_t, parent); @@ -416,14 +400,12 @@ os_size_t n21_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const cha char resp_buff[128] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 12 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 12 * OS_TICK_PER_SECOND}; at_parser_set_end_mark(parser, ">", 1); - os_size_t sent_max_size = 0; - char cmd_format[17] = {0}; + os_size_t sent_max_size = 0; + char cmd_format[17] = {0}; if (NETCONN_TYPE_TCP == netconn->type) { /* AT+TCPSEND=, */ @@ -525,14 +507,14 @@ os_err_t n21_netconn_gethostbyname(mo_object_t *self, const char *domain_name, i OS_ASSERT(OS_NULL != addr); at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[128] = {0}; - at_resp_t resp = {.buff = resp_buff, + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .timeout = 15 * OS_TICK_PER_SECOND, - .line_num = 2}; + .timeout = 15 * OS_TICK_PER_SECOND, + .line_num = 2}; result = at_parser_exec_cmd(parser, &resp, "AT+CDNSGIP=\"%s\"", domain_name); if (result != OS_EOK) @@ -569,10 +551,7 @@ os_err_t n21_netconn_gethostbyname(mo_object_t *self, const char *domain_name, i } else { - DEBUG("Module %s domain resolve: \"%s\" domain ip is %s, addrlen %d", - domain_name, - recvip, - strlen(recvip)); + DEBUG("Module %s domain resolve: \"%s\" domain ip is %s, addrlen %d", domain_name, recvip, strlen(recvip)); inet_aton(recvip, addr); if (IPADDR_ANY == addr->addr || IPADDR_LOOPBACK == addr->addr) @@ -614,7 +593,7 @@ static void urc_connect_func(struct at_parser *parser, const char *data, os_size OS_ASSERT(OS_NULL != data); mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_n21_t *n21 = os_container_of(module, mo_n21_t, parent); + mo_n21_t *n21 = os_container_of(module, mo_n21_t, parent); os_int32_t connect_id = 0; @@ -645,7 +624,7 @@ static void urc_send_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_n21_t *n21 = os_container_of(module, mo_n21_t, parent); + mo_n21_t *n21 = os_container_of(module, mo_n21_t, parent); os_int32_t connect_id = 0; @@ -711,8 +690,8 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t INFO("Moudle %s netconn %d receive %d bytes data", parser->name, netconn->connect_id, data_size); - char *recv_buff = os_calloc(1, data_size); - char temp_buff[8] = {0}; + char *recv_buff = os_calloc(1, data_size); + char temp_buff[8] = {0}; if (recv_buff == OS_NULL) { /* read and clean the coming data */ @@ -752,13 +731,13 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t } static at_urc_t gs_urc_table[] = { - {.prefix = "+TCPSEND", .suffix = "\r\n", .func = urc_send_func}, - {.prefix = "+UDPSEND", .suffix = "\r\n", .func = urc_send_func}, - {.prefix = "+TCPSETUP:", .suffix = "\r\n", .func = urc_connect_func}, - {.prefix = "+UDPSETUP:", .suffix = "\r\n", .func = urc_connect_func}, - {.prefix = "+TCPCLOSE:", .suffix = "Closed\r\n",.func = urc_close_func}, - {.prefix = "", .suffix = "+TCPRECV:", .func = urc_recv_func}, - {.prefix = "", .suffix = "+UDPRECV:", .func = urc_recv_func}, + {.prefix = "+TCPSEND", .suffix = "\r\n", .func = urc_send_func}, + {.prefix = "+UDPSEND", .suffix = "\r\n", .func = urc_send_func}, + {.prefix = "+TCPSETUP:", .suffix = "\r\n", .func = urc_connect_func}, + {.prefix = "+UDPSETUP:", .suffix = "\r\n", .func = urc_connect_func}, + {.prefix = "+TCPCLOSE:", .suffix = "Closed\r\n", .func = urc_close_func}, + {.prefix = "", .suffix = "+TCPRECV:", .func = urc_recv_func}, + {.prefix = "", .suffix = "+UDPRECV:", .func = urc_recv_func}, }; void n21_netconn_init(mo_n21_t *module) diff --git a/components/molink/module/n21/source/n21_netserv.c b/components/molink/module/n21/source/n21_netserv.c index 988eaf5a..cf929e7a 100644 --- a/components/molink/module/n21/source/n21_netserv.c +++ b/components/molink/module/n21/source/n21_netserv.c @@ -29,10 +29,9 @@ #include #define MO_LOG_TAG "n21_netserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" - #ifdef N21_USING_NETSERV_OPS os_err_t n21_set_attach(mo_object_t *self, os_uint8_t attach_stat) @@ -41,9 +40,7 @@ os_err_t n21_set_attach(mo_object_t *self, os_uint8_t attach_stat) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 30 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 30 * OS_TICK_PER_SECOND}; return at_parser_exec_cmd(parser, &resp, "AT+CGATT=%d", attach_stat); } @@ -54,9 +51,7 @@ os_err_t n21_get_attach(mo_object_t *self, os_uint8_t *attach_stat) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CGATT?"); if (result != OS_EOK) @@ -64,7 +59,7 @@ os_err_t n21_get_attach(mo_object_t *self, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) { ERROR("Get %s module attach state failed", self->name); return OS_ERROR; @@ -79,9 +74,7 @@ os_err_t n21_set_reg(mo_object_t *self, os_uint8_t reg_n) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; return at_parser_exec_cmd(parser, &resp, "AT+CEREG=%d", reg_n); } @@ -92,9 +85,7 @@ os_err_t n21_get_reg(mo_object_t *self, eps_reg_info_t *info) char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CEREG?"); if (result != OS_EOK) @@ -117,9 +108,7 @@ os_err_t n21_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CSQ"); if (result != OS_EOK) @@ -137,4 +126,3 @@ os_err_t n21_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber) } #endif /* N21_USING_NETSERV_OPS */ - diff --git a/components/molink/module/n21/source/n21_ping.c b/components/molink/module/n21/source/n21_ping.c index dd32e307..417dc478 100644 --- a/components/molink/module/n21/source/n21_ping.c +++ b/components/molink/module/n21/source/n21_ping.c @@ -26,10 +26,9 @@ #include #define MO_LOG_TAG "n21_ping" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" - #define N21_MIN_PING_PKG_LEN (36) #define N21_MAX_PING_PKG_LEN (1500) #define N21_MIN_PING_TIMEOUT (0) @@ -41,8 +40,10 @@ os_err_t n21_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint3 { if (len > N21_MAX_PING_PKG_LEN) { - ERROR("N21 ping: ping package len[%d] is out of range[%d, %d].", - len, N21_MIN_PING_PKG_LEN, N21_MAX_PING_PKG_LEN); + ERROR("N21 ping: ping package len[%d] is out of range[%d, %d].", + len, + N21_MIN_PING_PKG_LEN, + N21_MAX_PING_PKG_LEN); return OS_ERROR; } @@ -50,8 +51,10 @@ os_err_t n21_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint3 if (timeout_s > N21_MAX_PING_TIMEOUT) { - ERROR("N21 ping: ping timeout %us is out of range[%ds, %ds].", - timeout_s, N21_MIN_PING_TIMEOUT, N21_MAX_PING_TIMEOUT); + ERROR("N21 ping: ping timeout %us is out of range[%ds, %ds].", + timeout_s, + N21_MIN_PING_TIMEOUT, + N21_MAX_PING_TIMEOUT); return OS_ERROR; } @@ -61,11 +64,12 @@ os_err_t n21_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint3 char resp_buff[256] = {0}; - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .line_num = 4, - .timeout = os_tick_from_ms(1000 + timeout), - }; + at_resp_t at_resp = { + .buff = resp_buff, + .buff_size = sizeof(resp_buff), + .line_num = 4, + .timeout = os_tick_from_ms(1000 + timeout), + }; at_parser_exec_lock(parser); @@ -77,7 +81,7 @@ os_err_t n21_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint3 } char ip_addr[IPADDR_MAX_STR_LEN + 1] = {0}; - os_int16_t ttl = -1; + os_int16_t ttl = -1; os_uint32_t req_time = 0; /* Reply from 58.60.184.213: bytes= 64 time = 873(ms), TTL = 255 */ @@ -110,8 +114,8 @@ os_err_t n21_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint3 { inet_aton(ip_addr, &(resp->ip_addr)); resp->data_len = len; - resp->ttl = 255; - resp->time = req_time; + resp->ttl = 255; + resp->time = req_time; } at_parser_exec_unlock(parser); diff --git a/components/molink/module/n58/include/n58.h b/components/molink/module/n58/include/n58.h index a22ce282..1145a9c7 100644 --- a/components/molink/module/n58/include/n58.h +++ b/components/molink/module/n58/include/n58.h @@ -73,16 +73,16 @@ typedef struct mo_n58 mo_object_t parent; #ifdef N58_USING_NETCONN_OPS mo_netconn_t netconn[N58_NETCONN_NUM]; - - os_int32_t curr_connect; + + os_int32_t curr_connect; os_event_t netconn_evt; os_mutex_t netconn_lock; - void *netconn_data; + void *netconn_data; #endif /* N58_USING_NETCONN_OPS */ } mo_n58_t; mo_object_t *module_n58_create(const char *name, void *parser_config); -os_err_t module_n58_destroy(mo_object_t *self); +os_err_t module_n58_destroy(mo_object_t *self); #endif /* MOLINK_USING_N58 */ @@ -91,4 +91,3 @@ os_err_t module_n58_destroy(mo_object_t *self); #endif /* __cplusplus */ #endif /* __N58_H__ */ - diff --git a/components/molink/module/n58/include/n58_netconn.h b/components/molink/module/n58/include/n58_netconn.h index 6978c78d..b7bc3e94 100644 --- a/components/molink/module/n58/include/n58_netconn.h +++ b/components/molink/module/n58/include/n58_netconn.h @@ -32,11 +32,11 @@ extern "C" { #ifdef N58_USING_NETCONN_OPS -os_err_t n58_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t n58_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *n58_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t n58_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t n58_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t n58_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t n58_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t n58_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t n58_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #endif /* N58_USING_NETCONN_OPS */ diff --git a/components/molink/module/n58/include/n58_netserv.h b/components/molink/module/n58/include/n58_netserv.h index 32aa83d4..4b43b89a 100644 --- a/components/molink/module/n58/include/n58_netserv.h +++ b/components/molink/module/n58/include/n58_netserv.h @@ -37,7 +37,7 @@ os_err_t n58_get_attach(mo_object_t *self, os_uint8_t *attach_stat); os_err_t n58_set_reg(mo_object_t *self, os_uint8_t reg_n); os_err_t n58_get_reg(mo_object_t *self, eps_reg_info_t *info); os_err_t n58_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber); -os_err_t n58_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info); +os_err_t n58_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info); #endif /* N58_USING_NETSERV_OPS */ diff --git a/components/molink/module/n58/source/n58.c b/components/molink/module/n58/source/n58.c index 839778fa..b6be553f 100644 --- a/components/molink/module/n58/source/n58.c +++ b/components/molink/module/n58/source/n58.c @@ -36,37 +36,37 @@ #ifdef N58_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = n58_at_test, - .get_imei = n58_get_imei, - .get_imsi = n58_get_imsi, - .get_iccid = n58_get_iccid, - .get_cfun = n58_get_cfun, - .set_cfun = n58_set_cfun, + .at_test = n58_at_test, + .get_imei = n58_get_imei, + .get_imsi = n58_get_imsi, + .get_iccid = n58_get_iccid, + .get_cfun = n58_get_cfun, + .set_cfun = n58_set_cfun, .get_firmware_version = n58_get_firmware_version, }; #endif /* N58_USING_GENERAL_OPS */ #ifdef N58_USING_NETSERV_OPS static const struct mo_netserv_ops gs_netserv_ops = { - .set_attach = n58_set_attach, - .get_attach = n58_get_attach, - .set_reg = n58_set_reg, - .get_reg = n58_get_reg, - .get_csq = n58_get_csq, - .get_cell_info = n58_get_cell_info, + .set_attach = n58_set_attach, + .get_attach = n58_get_attach, + .set_reg = n58_set_reg, + .get_reg = n58_get_reg, + .get_csq = n58_get_csq, + .get_cell_info = n58_get_cell_info, }; #endif /* N58_USING_NETSERV_OPS */ #ifdef N58_USING_PING_OPS static const struct mo_ping_ops gs_ping_ops = { - .ping = n58_ping, + .ping = n58_ping, }; #endif /* N58_USING_PING_OPS */ #ifdef N58_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = n58_ifconfig, - .get_ipaddr = n58_get_ipaddr, + .ifconfig = n58_ifconfig, + .get_ipaddr = n58_get_ipaddr, }; #endif /* N58_USING_IFCONFIG_OPS */ @@ -74,11 +74,11 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void n58_netconn_init(mo_n58_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = n58_netconn_create, - .destroy = n58_netconn_destroy, - .connect = n58_netconn_connect, - .send = n58_netconn_send, - .get_info = n58_netconn_get_info, + .create = n58_netconn_create, + .destroy = n58_netconn_destroy, + .connect = n58_netconn_connect, + .send = n58_netconn_send, + .get_info = n58_netconn_get_info, /* The N58 module does not support domain name resolution */ }; #endif /* N58_USING_NETCONN_OPS */ @@ -96,7 +96,7 @@ static void n58_gernel_at_init(mo_object_t *self) { char imsi[MO_IMSI_LEN + 1] = {0}; - os_uint8_t fun_lvl = 0; + os_uint8_t fun_lvl = 0; if (n58_get_imsi(self, imsi, sizeof(imsi)) != OS_EOK) { @@ -144,12 +144,12 @@ static void n58_netserv_open(mo_object_t *self) static void n58_netserv_at_init(mo_object_t *self) { - at_parser_t *parser = &self->parser; + at_parser_t *parser = &self->parser; eps_reg_info_t reg_info = {0}; char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * OS_TICK_PER_SECOND}; for (int i = 0; i < N58_RETRY_TIMES; i++) { @@ -333,7 +333,7 @@ int n58_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = N58_NAME, + mo_parser_config_t parser_config = {.parser_name = N58_NAME, .parser_device = device, .recv_buff_len = N58_RECV_BUFF_LEN}; diff --git a/components/molink/module/n58/source/n58_general.c b/components/molink/module/n58/source/n58_general.c index 44a9bc2b..8cefb5cb 100644 --- a/components/molink/module/n58/source/n58_general.c +++ b/components/molink/module/n58/source/n58_general.c @@ -54,7 +54,7 @@ os_err_t n58_get_imei(mo_object_t *self, char *value, os_size_t len) at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * OS_TICK_PER_SECOND}; - if(OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN")) + if (OS_EOK != at_parser_exec_cmd(parser, &resp, "AT+CGSN")) { return OS_ERROR; } @@ -218,4 +218,3 @@ os_err_t n58_get_firmware_version(mo_object_t *self, mo_firmware_version_t *vers } #endif /* N58_USING_GENERAL_OPS */ - diff --git a/components/molink/module/n58/source/n58_ifconfig.c b/components/molink/module/n58/source/n58_ifconfig.c index 50df527c..ff27cfc5 100644 --- a/components/molink/module/n58/source/n58_ifconfig.c +++ b/components/molink/module/n58/source/n58_ifconfig.c @@ -37,11 +37,11 @@ os_err_t n58_ifconfig(mo_object_t *self) { char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; - char imsi[MO_IMSI_LEN + 1] = {0}; + char imsi[MO_IMSI_LEN + 1] = {0}; - os_err_t ret = OS_EOK; + os_err_t ret = OS_EOK; os_uint8_t rssi = 0; - os_uint8_t ber = 0; + os_uint8_t ber = 0; if (n58_get_ipaddr(self, ipaddr) != OS_EOK) { @@ -72,7 +72,7 @@ os_err_t n58_ifconfig(mo_object_t *self) if (n58_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; ret = OS_ERROR; } @@ -103,7 +103,7 @@ os_err_t n58_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; + char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; diff --git a/components/molink/module/n58/source/n58_netconn.c b/components/molink/module/n58/source/n58_netconn.c index 2b595a0f..641445e1 100644 --- a/components/molink/module/n58/source/n58_netconn.c +++ b/components/molink/module/n58/source/n58_netconn.c @@ -41,7 +41,7 @@ #endif #ifndef N58_NETCONN_MQ_MSG_MAX -#define N58_NETCONN_MQ_MSG_MAX (10) +#define N58_NETCONN_MQ_MSG_MAX (10) #endif #define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) @@ -71,9 +71,12 @@ static os_bool_t n58_check_netconn_state(mo_object_t *module, os_int32_t connect at_parser_t *parser = &module->parser; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - char netconn_stat[11] = {0}; + char netconn_stat[11] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * OS_TICK_PER_SECOND, .line_num = 1}; + at_resp_t resp = {.buff = resp_buff, + .buff_size = sizeof(resp_buff), + .timeout = 2 * OS_TICK_PER_SECOND, + .line_num = 1}; if (at_parser_exec_cmd(parser, &resp, "AT+IPSTATUS=%d", connect_id) != OS_EOK) { @@ -138,7 +141,7 @@ os_err_t n58_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_n58_t *n58 = os_container_of(module, mo_n58_t, parent); info->netconn_array = n58->netconn; - info->netconn_nums = sizeof(n58->netconn) / sizeof(n58->netconn[0]); + info->netconn_nums = sizeof(n58->netconn) / sizeof(n58->netconn[0]); return OS_EOK; } @@ -216,7 +219,10 @@ static os_err_t n58_netconn_do_destroy(mo_object_t *module, mo_netconn_t *netcon char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 5 * OS_TICK_PER_SECOND, .line_num = 1}; + at_resp_t resp = {.buff = resp_buff, + .buff_size = sizeof(resp_buff), + .timeout = 5 * OS_TICK_PER_SECOND, + .line_num = 1}; os_err_t result = OS_EOK; @@ -231,18 +237,14 @@ static os_err_t n58_netconn_do_destroy(mo_object_t *module, mo_netconn_t *netcon if (result != OS_EOK) { - ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + ERROR("Module %s destroy %s netconn failed", module->name, (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); return result; } const char *source_line = at_resp_get_line(&resp, 1); if (OS_NULL == source_line) { - ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + ERROR("Module %s destroy %s netconn failed", module->name, (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); return OS_ERROR; } @@ -261,7 +263,7 @@ os_err_t n58_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) DEBUG("Module %s in %d netconn status", module->name, netconn->stat); - mo_n58_t *n58 = os_container_of(module, mo_n58_t, parent); + mo_n58_t *n58 = os_container_of(module, mo_n58_t, parent); if (n58 == OS_NULL) { ERROR("Module %s destroy netconn failed, get netconn_lock failed", module->name); @@ -296,9 +298,9 @@ os_err_t n58_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn id %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); @@ -310,10 +312,10 @@ os_err_t n58_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) os_err_t n58_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port) { at_parser_t *parser = &module->parser; - mo_n58_t *n58 = os_container_of(module, mo_n58_t, parent); - os_err_t result = OS_EOK; + mo_n58_t *n58 = os_container_of(module, mo_n58_t, parent); + os_err_t result = OS_EOK; - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 60 * OS_TICK_PER_SECOND}; @@ -388,7 +390,7 @@ __exit: { ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%d successfully!", module->name, remote_ip, port); } else @@ -401,17 +403,17 @@ __exit: os_size_t n58_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t curr_size = 0; - os_uint32_t event = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t curr_size = 0; + os_uint32_t event = 0; - char resp_buff [AT_RESP_BUFF_SIZE_128] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_128] = {0}; char cmd_format[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 12 * OS_TICK_PER_SECOND}; - mo_n58_t *n58 = os_container_of(module, mo_n58_t, parent); + mo_n58_t *n58 = os_container_of(module, mo_n58_t, parent); /* Protect the data sending process, prevent other threads to send AT commands */ at_parser_exec_lock(parser); @@ -529,8 +531,8 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); - os_int32_t connect_id = 0; + mo_object_t *module = os_container_of(parser, mo_object_t, parser); + os_int32_t connect_id = 0; sscanf(data, "+TCPCLOSE: %d,&*s", &connect_id); @@ -552,9 +554,9 @@ static void urc_connect_func(struct at_parser *parser, const char *data, os_size OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_n58_t *n58 = os_container_of(module, mo_n58_t, parent); - os_int32_t connect_id = 0; + mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_n58_t *n58 = os_container_of(module, mo_n58_t, parent); + os_int32_t connect_id = 0; sscanf(data, "%*[^:]: %d,%*s", &connect_id); @@ -582,9 +584,9 @@ static void urc_send_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); - mo_n58_t *n58 = os_container_of(module, mo_n58_t, parent); - os_int32_t connect_id = 0; + mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_n58_t *n58 = os_container_of(module, mo_n58_t, parent); + os_int32_t connect_id = 0; sscanf(data, "%*[^:]: %d,%*s", &connect_id); @@ -611,7 +613,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t { mo_object_t *module = os_container_of(parser, mo_object_t, parser); - char tmp_ch; /* Get connecnt id */ + char tmp_ch; /* Get connecnt id */ /* handle the blank space */ at_parser_recv(parser, &tmp_ch, 1, 0); @@ -644,12 +646,12 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t } os_size_t data_size = atoi(tmp_str); - os_int32_t timeout = data_size > 10 ? data_size : 10; + os_int32_t timeout = data_size > 10 ? data_size : 10; INFO("Moudle %s netconn %d receive %d bytes data", parser->name, netconn->connect_id, data_size); - char *recv_buff = os_calloc(1, data_size); - char temp_buff[8] = {0}; + char *recv_buff = os_calloc(1, data_size); + char temp_buff[8] = {0}; if (recv_buff == OS_NULL) { /* read and clean the coming data */ @@ -691,13 +693,13 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t } static at_urc_t gs_urc_table[] = { - {.prefix = "+TCPSEND", .suffix = "\r\n", .func = urc_send_func}, - {.prefix = "+UDPSEND", .suffix = "\r\n", .func = urc_send_func}, - {.prefix = "+TCPSETUP:", .suffix = "\r\n", .func = urc_connect_func}, - {.prefix = "+UDPSETUP:", .suffix = "\r\n", .func = urc_connect_func}, + {.prefix = "+TCPSEND", .suffix = "\r\n", .func = urc_send_func}, + {.prefix = "+UDPSEND", .suffix = "\r\n", .func = urc_send_func}, + {.prefix = "+TCPSETUP:", .suffix = "\r\n", .func = urc_connect_func}, + {.prefix = "+UDPSETUP:", .suffix = "\r\n", .func = urc_connect_func}, {.prefix = "+TCPCLOSE:", .suffix = "Closed\r\n", .func = urc_close_func}, - {.prefix = "", .suffix = "+TCPRECV:", .func = urc_recv_func}, - {.prefix = "", .suffix = "+UDPRECV:", .func = urc_recv_func}, + {.prefix = "", .suffix = "+TCPRECV:", .func = urc_recv_func}, + {.prefix = "", .suffix = "+UDPRECV:", .func = urc_recv_func}, }; void n58_netconn_init(mo_n58_t *module) diff --git a/components/molink/module/n58/source/n58_netserv.c b/components/molink/module/n58/source/n58_netserv.c index 7f2c52e6..121973e8 100644 --- a/components/molink/module/n58/source/n58_netserv.c +++ b/components/molink/module/n58/source/n58_netserv.c @@ -72,7 +72,7 @@ os_err_t n58_get_attach(mo_object_t *self, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT:%hhu", attach_stat) <= 0) { ERROR("Get %s module attach state failed", self->name); return OS_ERROR; @@ -138,97 +138,95 @@ os_err_t n58_get_csq(mo_object_t *self, os_uint8_t *rssi, os_uint8_t *ber) return OS_EOK; } -#define N58_MODULE_NET_TYPE 5 - -os_err_t n58_get_cell_info(mo_object_t *self, onepos_cell_info_t* onepos_cell_info) -{ - os_err_t ret = OS_EOK; - cell_info_t *cell_info = OS_NULL; - char *temp_buff = OS_NULL; - os_uint32_t cell_num = 0; - - at_parser_t *parser = &self->parser; - if (parser == OS_NULL) - { - ERROR("N58 get_cell_info: at parser is NULL."); - return OS_ERROR; - } - if(!onepos_cell_info) - { - ERROR("input param is error!"); - return OS_ERROR; - } - - at_resp_t resp = {.buff = os_calloc(1, 1024), - .buff_size = 1024, - .timeout = 50 * OS_TICK_PER_SECOND - }; - - if (OS_NULL == resp.buff) - { - ERROR("Calloc n58 cell info response memory failed!"); - ret = OS_ENOMEM; - goto __exit; - } - - /* neighbor cell */ - if (at_parser_exec_cmd(parser, &resp, "AT+NETDMSG") < 0) - { - ret = OS_ERROR; - ERROR("AT cmd exec fail: AT+MCELL=0,26\n"); - goto __exit; - } - DEBUG("resp->line_counts : %d\r\n", resp.line_counts); - - cell_info = os_calloc(1, sizeof(cell_info_t)); - if(NULL == cell_info) - { - ERROR("malloc cell_info is null"); - ret = OS_ENOMEM; - return ret; - } - - INFO(" MCC MNC CID LAC RSSI\n"); - INFO(" ------------ ------------ ------------ ------------ ----\n"); - - temp_buff = (char*)at_resp_get_line(&resp, 1); - if(strlen(temp_buff) > 25) - { - sscanf(temp_buff, - "+NETDMSG: \"%u+%u\", 0x%x, 0x%x,%*[^,],%*[^,],%*[^,],%*[^,], %d,%*[^\r]", - &cell_info[cell_num].mcc, - &cell_info[cell_num].mnc, - &cell_info[cell_num].lac, - &cell_info[cell_num].cid, - &cell_info[cell_num].ss - ); - - if(cell_info[cell_num].mcc) - { - INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", - cell_info[cell_num].mcc, cell_info[cell_num].mnc, cell_info[cell_num].cid, - cell_info[cell_num].lac, cell_info[cell_num].ss); - cell_num ++; - } - } - - /* main cell */ - - INFO(" ------------ ------------ ------------ ------------ ----\n"); - - onepos_cell_info->cell_num = ++cell_num; - onepos_cell_info->cell_info = cell_info; - onepos_cell_info->net_type = N58_MODULE_NET_TYPE; - -__exit: - - if (resp.buff != OS_NULL) - { - os_free(resp.buff); - } - - return ret; -} +#define N58_MODULE_NET_TYPE 5 -#endif /* N58_USING_NETSERV_OPS */ +os_err_t n58_get_cell_info(mo_object_t *self, onepos_cell_info_t *onepos_cell_info) +{ + os_err_t ret = OS_EOK; + cell_info_t *cell_info = OS_NULL; + char *temp_buff = OS_NULL; + os_uint32_t cell_num = 0; + + at_parser_t *parser = &self->parser; + if (parser == OS_NULL) + { + ERROR("N58 get_cell_info: at parser is NULL."); + return OS_ERROR; + } + if (!onepos_cell_info) + { + ERROR("input param is error!"); + return OS_ERROR; + } + + at_resp_t resp = {.buff = os_calloc(1, 1024), .buff_size = 1024, .timeout = 50 * OS_TICK_PER_SECOND}; + + if (OS_NULL == resp.buff) + { + ERROR("Calloc n58 cell info response memory failed!"); + ret = OS_ENOMEM; + goto __exit; + } + + /* neighbor cell */ + if (at_parser_exec_cmd(parser, &resp, "AT+NETDMSG") < 0) + { + ret = OS_ERROR; + ERROR("AT cmd exec fail: AT+MCELL=0,26\n"); + goto __exit; + } + DEBUG("resp->line_counts : %d\r\n", resp.line_counts); + cell_info = os_calloc(1, sizeof(cell_info_t)); + if (NULL == cell_info) + { + ERROR("malloc cell_info is null"); + ret = OS_ENOMEM; + return ret; + } + + INFO(" MCC MNC CID LAC RSSI\n"); + INFO(" ------------ ------------ ------------ ------------ ----\n"); + + temp_buff = (char *)at_resp_get_line(&resp, 1); + if (strlen(temp_buff) > 25) + { + sscanf(temp_buff, + "+NETDMSG: \"%u+%u\", 0x%x, 0x%x,%*[^,],%*[^,],%*[^,],%*[^,], %d,%*[^\r]", + &cell_info[cell_num].mcc, + &cell_info[cell_num].mnc, + &cell_info[cell_num].lac, + &cell_info[cell_num].cid, + &cell_info[cell_num].ss); + + if (cell_info[cell_num].mcc) + { + INFO("cell_info: %-12u %-12u %-12u %-12u %-4d\n", + cell_info[cell_num].mcc, + cell_info[cell_num].mnc, + cell_info[cell_num].cid, + cell_info[cell_num].lac, + cell_info[cell_num].ss); + cell_num++; + } + } + + /* main cell */ + + INFO(" ------------ ------------ ------------ ------------ ----\n"); + + onepos_cell_info->cell_num = ++cell_num; + onepos_cell_info->cell_info = cell_info; + onepos_cell_info->net_type = N58_MODULE_NET_TYPE; + +__exit: + + if (resp.buff != OS_NULL) + { + os_free(resp.buff); + } + + return ret; +} + +#endif /* N58_USING_NETSERV_OPS */ diff --git a/components/molink/module/n58/source/n58_ping.c b/components/molink/module/n58/source/n58_ping.c index 0c82205f..bc2f6c6f 100644 --- a/components/molink/module/n58/source/n58_ping.c +++ b/components/molink/module/n58/source/n58_ping.c @@ -41,17 +41,18 @@ os_err_t n58_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint3 at_parser_t *parser = &self->parser; char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; - char ip_addr[IPADDR_MAX_STR_LEN + 1] = {0}; + char ip_addr[IPADDR_MAX_STR_LEN + 1] = {0}; os_uint32_t timeout_s = timeout / 1000; /* Milliseconds convert to seconds */ - os_uint32_t req_time = 0; - os_uint32_t ttl = 0; + os_uint32_t req_time = 0; + os_uint32_t ttl = 0; - at_resp_t at_resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .line_num = 5, - .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND, - }; + at_resp_t at_resp = { + .buff = resp_buff, + .buff_size = sizeof(resp_buff), + .line_num = 5, + .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND, + }; if ((len > N58_MAX_PING_PKG_LEN) || (len < N58_MIN_PING_PKG_LEN)) { @@ -61,7 +62,10 @@ os_err_t n58_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint3 if (timeout_s > N58_MAX_PING_TIMEOUT) { - ERROR("N58 ping: ping timeout %us is out of range[%ds, %ds].", timeout_s, N58_MIN_PING_TIMEOUT, N58_MAX_PING_TIMEOUT); + ERROR("N58 ping: ping timeout %us is out of range[%ds, %ds].", + timeout_s, + N58_MIN_PING_TIMEOUT, + N58_MAX_PING_TIMEOUT); return OS_ERROR; } @@ -109,8 +113,8 @@ os_err_t n58_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint3 inet_aton(ip_addr, &(resp->ip_addr)); resp->data_len = len; - resp->ttl = ttl; - resp->time = req_time; + resp->ttl = ttl; + resp->time = req_time; } at_parser_exec_unlock(parser); diff --git a/components/molink/module/sim7020/include/sim7020.h b/components/molink/module/sim7020/include/sim7020.h index dfeded09..b046468a 100644 --- a/components/molink/module/sim7020/include/sim7020.h +++ b/components/molink/module/sim7020/include/sim7020.h @@ -77,12 +77,12 @@ typedef struct mo_sim7020 mo_object_t parent; #ifdef SIM7020_USING_NETCONN_OPS mo_netconn_t netconn[SIM7020_NETCONN_NUM]; - os_mutex_t netconn_lock; + os_mutex_t netconn_lock; #endif /* SIM7020_USING_NETCONN_OPS */ } mo_sim7020_t; mo_object_t *module_sim7020_create(const char *name, void *parser_config); -os_err_t module_sim7020_destroy(mo_object_t *self); +os_err_t module_sim7020_destroy(mo_object_t *self); #endif /* MOLINK_USING_SIM7020 */ diff --git a/components/molink/module/sim7020/include/sim7020_netconn.h b/components/molink/module/sim7020/include/sim7020_netconn.h index 6519c119..bba4c8d0 100644 --- a/components/molink/module/sim7020/include/sim7020_netconn.h +++ b/components/molink/module/sim7020/include/sim7020_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef SIM7020_USING_NETCONN_OPS -os_err_t sim7020_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t sim7020_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *sim7020_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t sim7020_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t sim7020_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t sim7020_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t sim7020_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t sim7020_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t sim7020_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef SIM7020_USING_DNS -os_err_t sim7020_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t sim7020_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* SIM7020_USING_NETCONN_OPS */ diff --git a/components/molink/module/sim7020/include/sim7020_ping.h b/components/molink/module/sim7020/include/sim7020_ping.h index 586b6226..2c7de1de 100644 --- a/components/molink/module/sim7020/include/sim7020_ping.h +++ b/components/molink/module/sim7020/include/sim7020_ping.h @@ -31,7 +31,8 @@ extern "C" { #ifdef SIM7020_USING_PING_OPS -os_err_t sim7020_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); +os_err_t +sim7020_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); #endif /* SIM7020_USING_PING_OPS */ diff --git a/components/molink/module/sim7020/source/sim7020.c b/components/molink/module/sim7020/source/sim7020.c index 36d61090..e4a6e90d 100644 --- a/components/molink/module/sim7020/source/sim7020.c +++ b/components/molink/module/sim7020/source/sim7020.c @@ -36,12 +36,12 @@ #ifdef SIM7020_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = sim7020_at_test, - .get_imei = sim7020_get_imei, - .get_imsi = sim7020_get_imsi, + .at_test = sim7020_at_test, + .get_imei = sim7020_get_imei, + .get_imsi = sim7020_get_imsi, .get_iccid = sim7020_get_iccid, - .get_cfun = sim7020_get_cfun, - .set_cfun = sim7020_set_cfun, + .get_cfun = sim7020_get_cfun, + .set_cfun = sim7020_set_cfun, }; #endif /* SIM7020_USING_GENERAL_OPS */ @@ -49,11 +49,11 @@ static const struct mo_general_ops gs_general_ops = { static const struct mo_netserv_ops gs_netserv_ops = { .set_attach = sim7020_set_attach, .get_attach = sim7020_get_attach, - .set_reg = sim7020_set_reg, - .get_reg = sim7020_get_reg, - .set_cgact = sim7020_set_cgact, - .get_cgact = sim7020_get_cgact, - .get_csq = sim7020_get_csq, + .set_reg = sim7020_set_reg, + .get_reg = sim7020_get_reg, + .set_cgact = sim7020_set_cgact, + .get_cgact = sim7020_get_cgact, + .get_csq = sim7020_get_csq, }; #endif /* SIM7020_USING_NETSERV_OPS */ @@ -65,7 +65,7 @@ static const struct mo_ping_ops gs_ping_ops = { #ifdef SIM7020_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = sim7020_ifconfig, + .ifconfig = sim7020_ifconfig, .get_ipaddr = sim7020_get_ipaddr, }; #endif /* SIM7020_USING_IFCONFIG_OPS */ @@ -74,14 +74,14 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void sim7020_netconn_init(mo_sim7020_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = sim7020_netconn_create, - .destroy = sim7020_netconn_destroy, + .create = sim7020_netconn_create, + .destroy = sim7020_netconn_destroy, #ifdef SIM7020_USING_DNS .gethostbyname = sim7020_netconn_gethostbyname, #endif - .connect = sim7020_netconn_connect, - .send = sim7020_netconn_send, - .get_info = sim7020_netconn_get_info, + .connect = sim7020_netconn_connect, + .send = sim7020_netconn_send, + .get_info = sim7020_netconn_get_info, }; #endif /* SIM7020_USING_NETCONN_OPS */ @@ -98,9 +98,7 @@ static os_err_t sim7020_at_init(mo_object_t *self) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; return at_parser_exec_cmd(parser, &resp, "ATE0"); } @@ -198,7 +196,7 @@ int sim7020_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = SIM7020_NAME, + mo_parser_config_t parser_config = {.parser_name = SIM7020_NAME, .parser_device = device, .recv_buff_len = SIM7020_RECV_BUFF_LEN}; diff --git a/components/molink/module/sim7020/source/sim7020_ifconfig.c b/components/molink/module/sim7020/source/sim7020_ifconfig.c index 1cba2ee0..8db0035f 100644 --- a/components/molink/module/sim7020/source/sim7020_ifconfig.c +++ b/components/molink/module/sim7020/source/sim7020_ifconfig.c @@ -38,14 +38,14 @@ os_err_t sim7020_ifconfig(mo_object_t *self) { char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; - char imei[MO_IMEI_LEN + 1] = {0}; - char iccid[MO_ICCID_LEN + 1] = {0}; - char imsi[MO_IMSI_LEN + 1] = {0}; + char imei[MO_IMEI_LEN + 1] = {0}; + char iccid[MO_ICCID_LEN + 1] = {0}; + char imsi[MO_IMSI_LEN + 1] = {0}; - os_err_t ret = OS_EOK; + os_err_t ret = OS_EOK; os_uint8_t rssi = 0; - os_uint8_t ber = 0; - os_int32_t i = 0; + os_uint8_t ber = 0; + os_int32_t i = 0; if (sim7020_get_ipaddr(self, ipaddr) != OS_EOK) { @@ -74,8 +74,8 @@ os_err_t sim7020_ifconfig(mo_object_t *self) if (sim7020_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; - ret = OS_ERROR; + ber = 0; + ret = OS_ERROR; } os_kprintf("\r\nLIST AT MODULE INFORMATION\r\n"); @@ -104,7 +104,7 @@ os_err_t sim7020_ifconfig(mo_object_t *self) os_err_t sim7020_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t len = -1; + os_int8_t len = -1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; diff --git a/components/molink/module/sim7020/source/sim7020_netconn.c b/components/molink/module/sim7020/source/sim7020_netconn.c index 8b34ac70..997b8335 100644 --- a/components/molink/module/sim7020/source/sim7020_netconn.c +++ b/components/molink/module/sim7020/source/sim7020_netconn.c @@ -33,8 +33,8 @@ #define MO_LOG_LVL MO_LOG_INFO #include -#define SEND_DATA_MAX_SIZE (512) -#define SIM7020_SEND_HEXDATA_BLOCK_SIZE (256) +#define SEND_DATA_MAX_SIZE (512) +#define SIM7020_SEND_HEXDATA_BLOCK_SIZE (256) #define SIM7020_NETCONN_MQ_NAME "sim7020_nc_mq" @@ -43,7 +43,7 @@ #endif #ifndef SIM7020_NETCONN_MQ_MSG_MAX -#define SIM7020_NETCONN_MQ_MSG_MAX (8) +#define SIM7020_NETCONN_MQ_MSG_MAX (8) #endif #ifdef SIM7020_USING_NETCONN_OPS @@ -103,7 +103,7 @@ os_err_t sim7020_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_sim7020_t *sim7020 = os_container_of(module, mo_sim7020_t, parent); info->netconn_array = sim7020->netconn; - info->netconn_nums = sizeof(sim7020->netconn) / sizeof(sim7020->netconn[0]); + info->netconn_nums = sizeof(sim7020->netconn) / sizeof(sim7020->netconn[0]); return OS_EOK; } @@ -111,8 +111,8 @@ os_err_t sim7020_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_netconn_t *sim7020_netconn_create(mo_object_t *module, mo_netconn_type_t type) { mo_sim7020_t *sim7020 = os_container_of(module, mo_sim7020_t, parent); - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; sim7020_lock(&sim7020->netconn_lock); @@ -190,7 +190,7 @@ mo_netconn_t *sim7020_netconn_create(mo_object_t *module, mo_netconn_type_t type os_err_t sim7020_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; INFO("Module %s in %d netconn status", module->name, netconn->stat); @@ -224,9 +224,9 @@ os_err_t sim7020_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn_id: %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); @@ -242,10 +242,10 @@ os_err_t sim7020_netconn_gethostbyname(mo_object_t *self, const char *domain_nam char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; - at_resp_t resp = {.buff = resp_buff, + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .line_num = 2, - .timeout = 20 * OS_TICK_PER_SECOND}; + .line_num = 2, + .timeout = 20 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CDNSGIP=\"%s\"", domain_name); if (result < 0) @@ -294,11 +294,9 @@ __exit: static os_err_t sim7020_tcp_udp_connect(at_parser_t *parser, os_int32_t connect_id, char *ip_addr, os_uint16_t port) { char resp_buff[AT_RESP_BUFF_SIZE_128] = {0}; - char buf[AT_RESP_BUFF_SIZE_DEF] = {0}; + char buf[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 20 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CSOCON=%d,%u,\"%s\"", connect_id, port, ip_addr); if (result != OS_EOK) @@ -327,7 +325,7 @@ __exit: os_err_t sim7020_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -343,7 +341,7 @@ os_err_t sim7020_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%u successfully!", module->name, remote_ip, port); @@ -352,8 +350,8 @@ os_err_t sim7020_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_ static os_size_t sim7020_one_hexdata_block_send(at_parser_t *parser, const char *data, os_size_t size) { - os_size_t sent_size = 0; /* raw data sent size */ - os_size_t curr_pkt_size = 0; /* raw data current packet size */ + os_size_t sent_size = 0; /* raw data sent size */ + os_size_t curr_pkt_size = 0; /* raw data current packet size */ char hex_str_buff[SIM7020_SEND_HEXDATA_BLOCK_SIZE + 1] = {0}; @@ -385,12 +383,12 @@ __exit: os_size_t sim7020_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t cur_pkt_size = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t cur_pkt_size = 0; - char send_cmd [AT_RESP_BUFF_SIZE_DEF] = {0}; + char send_cmd[AT_RESP_BUFF_SIZE_DEF] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; @@ -464,7 +462,7 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t err_code = 0; + os_int32_t err_code = 0; sscanf(data, "+CSOERR: %d,%d", &connect_id, &err_code); @@ -490,7 +488,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; + os_int32_t data_size = 0; /* For ex: +CSONMI: 0,8,30313233 -- the actual data is "0123"*/ sscanf(data, "+CSONMI: %d,%d,", &connect_id, &data_size); diff --git a/components/molink/module/sim7020/source/sim7020_netserv.c b/components/molink/module/sim7020/source/sim7020_netserv.c index 21302f6a..8f614c29 100644 --- a/components/molink/module/sim7020/source/sim7020_netserv.c +++ b/components/molink/module/sim7020/source/sim7020_netserv.c @@ -58,7 +58,7 @@ os_err_t sim7020_get_attach(mo_object_t *self, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) { ERROR("Get %s module attach state failed", self->name); return OS_ERROR; diff --git a/components/molink/module/sim7020/source/sim7020_ping.c b/components/molink/module/sim7020/source/sim7020_ping.c index 0dbb4153..c4e5f762 100644 --- a/components/molink/module/sim7020/source/sim7020_ping.c +++ b/components/molink/module/sim7020/source/sim7020_ping.c @@ -36,11 +36,11 @@ os_err_t sim7020_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - os_int16_t req_time = -1; - os_int16_t replyid = -1; - os_int16_t ttl = -1; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; + os_int16_t req_time = -1; + os_int16_t replyid = -1; + os_int16_t ttl = -1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -53,9 +53,9 @@ os_err_t sim7020_ping(mo_object_t *self, const char *host, os_uint16_t len, os_u if (len > SIM7020_MAX_PING_PKG_LEN) { ERROR("SIM7020 ping: ping package len[%d] is out of range[%d, %d].", - len, - SIM7020_MIN_PING_PKG_LEN, - SIM7020_MAX_PING_PKG_LEN); + len, + SIM7020_MIN_PING_PKG_LEN, + SIM7020_MAX_PING_PKG_LEN); return OS_ERROR; } @@ -64,9 +64,9 @@ os_err_t sim7020_ping(mo_object_t *self, const char *host, os_uint16_t len, os_u if ((timeout < SIM7020_MIN_PING_TIMEOUT) || (timeout > SIM7020_MAX_PING_TIMEOUT)) { ERROR("SIM7020 ping: user set ping timeout value %ums is out of range[%dms, %dms].", - timeout * 100, - SIM7020_MIN_PING_TIMEOUT * 100, - SIM7020_MAX_PING_TIMEOUT * 100); + timeout * 100, + SIM7020_MIN_PING_TIMEOUT * 100, + SIM7020_MAX_PING_TIMEOUT * 100); return OS_ERROR; } @@ -74,10 +74,10 @@ os_err_t sim7020_ping(mo_object_t *self, const char *host, os_uint16_t len, os_u char resp_buff[256] = {0}; /* Need to wait for 2 lines response msg */ - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .line_num = 2, - .timeout = (5 + timeout / 10) * OS_TICK_PER_SECOND}; + .line_num = 2, + .timeout = (5 + timeout / 10) * OS_TICK_PER_SECOND}; /* Exec AT+CIPPING="www.baidu.com",4,64,50; def ping timeout: +CIPPING: 1,39.156.66.14,50,0 */ /* Success: +CIPPING: 1,39.156.66.14,84,52 */ @@ -88,7 +88,8 @@ os_err_t sim7020_ping(mo_object_t *self, const char *host, os_uint16_t len, os_u goto __exit; } - if (at_resp_get_data_by_kw(&at_resp, "+CIPPING", "+CIPPING: %d,%[^,],%d,%d", &replyid, ipaddr, &req_time, &ttl) <= 0) + if (at_resp_get_data_by_kw(&at_resp, "+CIPPING", "+CIPPING: %d,%[^,],%d,%d", &replyid, ipaddr, &req_time, &ttl) <= + 0) { ERROR("%s ping %s fail: check network status and try to set a longer timeout.", self->name, host); result = OS_ERROR; @@ -111,8 +112,8 @@ os_err_t sim7020_ping(mo_object_t *self, const char *host, os_uint16_t len, os_u { inet_aton(ipaddr, &(resp->ip_addr)); resp->data_len = len; - resp->ttl = ttl; - resp->time = (req_time * 100); + resp->ttl = ttl; + resp->time = (req_time * 100); } __exit: diff --git a/components/molink/module/sim7070x/include/sim7070x.h b/components/molink/module/sim7070x/include/sim7070x.h index f3a0fe4b..c697aec8 100644 --- a/components/molink/module/sim7070x/include/sim7070x.h +++ b/components/molink/module/sim7070x/include/sim7070x.h @@ -77,14 +77,14 @@ typedef struct mo_sim7070x mo_object_t parent; #ifdef SIM7070X_USING_NETCONN_OPS mo_netconn_t netconn[SIM7070X_NETCONN_NUM]; - os_event_t netconn_evt; - os_mutex_t netconn_lock; + os_event_t netconn_evt; + os_mutex_t netconn_lock; #endif /* SIM7070X_USING_NETCONN_OPS */ } mo_sim7070x_t; mo_object_t *module_sim7070x_create(const char *name, void *parser_config); -os_err_t module_sim7070x_destroy(mo_object_t *self); -os_err_t module_sim7070x_app_network_pdpidx0_init(mo_object_t *self); +os_err_t module_sim7070x_destroy(mo_object_t *self); +os_err_t module_sim7070x_app_network_pdpidx0_init(mo_object_t *self); #endif /* MOLINK_USING_SIM7070X */ diff --git a/components/molink/module/sim7070x/include/sim7070x_netconn.h b/components/molink/module/sim7070x/include/sim7070x_netconn.h index 09abab06..608f3274 100644 --- a/components/molink/module/sim7070x/include/sim7070x_netconn.h +++ b/components/molink/module/sim7070x/include/sim7070x_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef SIM7070X_USING_NETCONN_OPS -os_err_t sim7070x_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t sim7070x_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *sim7070x_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t sim7070x_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t sim7070x_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t sim7070x_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t sim7070x_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t sim7070x_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t sim7070x_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef SIM7070X_USING_DNS -os_err_t sim7070x_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t sim7070x_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* SIM7070X_USING_NETCONN_OPS */ diff --git a/components/molink/module/sim7070x/include/sim7070x_ping.h b/components/molink/module/sim7070x/include/sim7070x_ping.h index 2877c78a..faca600c 100644 --- a/components/molink/module/sim7070x/include/sim7070x_ping.h +++ b/components/molink/module/sim7070x/include/sim7070x_ping.h @@ -31,7 +31,8 @@ extern "C" { #ifdef SIM7070X_USING_PING_OPS -os_err_t sim7070x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); +os_err_t +sim7070x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); #endif /* SIM7070X_USING_PING_OPS */ diff --git a/components/molink/module/sim7070x/source/sim7070x.c b/components/molink/module/sim7070x/source/sim7070x.c index 6efb927c..c25b99fe 100644 --- a/components/molink/module/sim7070x/source/sim7070x.c +++ b/components/molink/module/sim7070x/source/sim7070x.c @@ -27,7 +27,7 @@ #include #define MO_LOG_TAG "sim7070x" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef MOLINK_USING_SIM7070X @@ -37,17 +37,17 @@ enum sim7070x_pdp_status { PDP_DEACTIVED = 0, - PDP_ACTIVED = 1, + PDP_ACTIVED = 1, }; #ifdef SIM7070X_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = sim7070x_at_test, - .get_imei = sim7070x_get_imei, - .get_imsi = sim7070x_get_imsi, + .at_test = sim7070x_at_test, + .get_imei = sim7070x_get_imei, + .get_imsi = sim7070x_get_imsi, .get_iccid = sim7070x_get_iccid, - .get_cfun = sim7070x_get_cfun, - .set_cfun = sim7070x_set_cfun, + .get_cfun = sim7070x_get_cfun, + .set_cfun = sim7070x_set_cfun, .get_firmware_version = sim7070x_get_firmware_version, }; #endif /* SIM7070X_USING_GENERAL_OPS */ @@ -56,11 +56,11 @@ static const struct mo_general_ops gs_general_ops = { static const struct mo_netserv_ops gs_netserv_ops = { .set_attach = sim7070x_set_attach, .get_attach = sim7070x_get_attach, - .set_reg = sim7070x_set_reg, - .get_reg = sim7070x_get_reg, - .set_cgact = sim7070x_set_cgact, - .get_cgact = sim7070x_get_cgact, - .get_csq = sim7070x_get_csq, + .set_reg = sim7070x_set_reg, + .get_reg = sim7070x_get_reg, + .set_cgact = sim7070x_set_cgact, + .get_cgact = sim7070x_get_cgact, + .get_csq = sim7070x_get_csq, }; #endif /* SIM7070X_USING_NETSERV_OPS */ @@ -72,7 +72,7 @@ static const struct mo_ping_ops gs_ping_ops = { #ifdef SIM7070X_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = sim7070x_ifconfig, + .ifconfig = sim7070x_ifconfig, .get_ipaddr = sim7070x_get_ipaddr, }; #endif /* SIM7070X_USING_IFCONFIG_OPS */ @@ -81,14 +81,14 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void sim7070x_netconn_init(mo_sim7070x_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = sim7070x_netconn_create, - .destroy = sim7070x_netconn_destroy, + .create = sim7070x_netconn_create, + .destroy = sim7070x_netconn_destroy, #ifdef SIM7070X_USING_DNS .gethostbyname = sim7070x_netconn_gethostbyname, #endif - .connect = sim7070x_netconn_connect, - .send = sim7070x_netconn_send, - .get_info = sim7070x_netconn_get_info, + .connect = sim7070x_netconn_connect, + .send = sim7070x_netconn_send, + .get_info = sim7070x_netconn_get_info, }; #endif /* SIM7070X_USING_NETCONN_OPS */ @@ -105,9 +105,7 @@ static os_err_t sim7070x_at_init(mo_object_t *self) char resp_buff[32] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 2 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * OS_TICK_PER_SECOND}; return at_parser_exec_cmd(parser, &resp, "ATE0"); } @@ -118,10 +116,10 @@ static os_err_t sim7070x_set_app_network_pdpidx0(mo_object_t *self) os_uint32_t cid = 0; os_uint32_t stat = 0; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[256] = {0}; - char temp[64] = {0}; + char temp[64] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 10 * OS_TICK_PER_SECOND}; @@ -149,7 +147,7 @@ static os_err_t sim7070x_set_app_network_pdpidx0(mo_object_t *self) os_task_msleep(5000); - /* PDP index0 config to ctnb (APN delivered by the CAT-M or NB-IOT network) */ + /* PDP index0 config to ctnb (APN delivered by the CAT-M or NB-IOT network) */ result = at_parser_exec_cmd(parser, &resp, "AT+CNCFG=0,1,\"ctnb\""); if (result != OS_EOK) { @@ -158,7 +156,7 @@ static os_err_t sim7070x_set_app_network_pdpidx0(mo_object_t *self) } resp.line_num = 2; - resp.timeout = 30 * OS_TICK_PER_SECOND; + resp.timeout = 30 * OS_TICK_PER_SECOND; /* APP network pdp index0 active */ result = at_parser_exec_cmd(parser, &resp, "AT+CNACT=0,1"); if (result != OS_EOK) @@ -174,7 +172,7 @@ static os_err_t sim7070x_set_app_network_pdpidx0(mo_object_t *self) } resp.line_num = 0; - resp.timeout = 3 * OS_TICK_PER_SECOND; + resp.timeout = 3 * OS_TICK_PER_SECOND; /* PDP context activate? */ for (int i = 0; i < SIM7070X_RETRY_TIMES; i++) { @@ -211,7 +209,7 @@ static os_err_t sim7070x_get_app_network_pdpidx0_status(mo_object_t *self, os_ui at_parser_t *parser = &self->parser; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; - char resp_buff[128] = {0}; + char resp_buff[128] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 3 * OS_TICK_PER_SECOND}; @@ -359,7 +357,7 @@ int sim7070x_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = SIM7070X_NAME, + mo_parser_config_t parser_config = {.parser_name = SIM7070X_NAME, .parser_device = device, .recv_buff_len = SIM7070X_RECV_BUFF_LEN}; @@ -375,7 +373,7 @@ int sim7070x_auto_create(void) return OS_EOK; } -OS_CMPOENT_INIT(sim7070x_auto_create,OS_INIT_SUBLEVEL_MIDDLE); +OS_CMPOENT_INIT(sim7070x_auto_create, OS_INIT_SUBLEVEL_MIDDLE); #endif /* SIM7070X_AUTO_CREATE */ diff --git a/components/molink/module/sim7070x/source/sim7070x_general.c b/components/molink/module/sim7070x/source/sim7070x_general.c index 6c8d102b..9c8b4d48 100644 --- a/components/molink/module/sim7070x/source/sim7070x_general.c +++ b/components/molink/module/sim7070x/source/sim7070x_general.c @@ -26,7 +26,7 @@ #include #define MO_LOG_TAG "sim7070x_general" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef SIM7070X_USING_GENERAL_OPS @@ -169,9 +169,7 @@ os_err_t sim7070x_get_firmware_version(mo_object_t *self, mo_firmware_version_t char resp_buff[256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = AT_RESP_TIMEOUT_DEF}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = AT_RESP_TIMEOUT_DEF}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CGMR"); if (result != OS_EOK) @@ -186,7 +184,7 @@ os_err_t sim7070x_get_firmware_version(mo_object_t *self, mo_firmware_version_t } const char *source_line = at_resp_get_line(&resp, 1); - os_size_t line_length = strlen(source_line); + os_size_t line_length = strlen(source_line); /* TODO test return line or set to dynamic dump */ char **dest_line = &version->ver_info[0]; diff --git a/components/molink/module/sim7070x/source/sim7070x_ifconfig.c b/components/molink/module/sim7070x/source/sim7070x_ifconfig.c index 71ee46a9..7e8479bc 100644 --- a/components/molink/module/sim7070x/source/sim7070x_ifconfig.c +++ b/components/molink/module/sim7070x/source/sim7070x_ifconfig.c @@ -31,7 +31,7 @@ #include "sim7070x_ifconfig.h" #define MO_LOG_TAG "sim7070x_ifconfid" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef SIM7070X_USING_IFCONFIG_OPS @@ -39,13 +39,13 @@ os_err_t sim7070x_ifconfig(mo_object_t *self) { char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; - char imei[MO_IMEI_LEN + 1] = {0}; - char iccid[MO_ICCID_LEN + 1] = {0}; + char imei[MO_IMEI_LEN + 1] = {0}; + char iccid[MO_ICCID_LEN + 1] = {0}; - os_err_t ret = OS_EOK; + os_err_t ret = OS_EOK; os_uint8_t rssi = 0; - os_uint8_t ber = 0; - os_int32_t i = 0; + os_uint8_t ber = 0; + os_int32_t i = 0; if (sim7070x_get_ipaddr(self, ipaddr) != OS_EOK) { @@ -68,7 +68,7 @@ os_err_t sim7070x_ifconfig(mo_object_t *self) if (sim7070x_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; ret = OS_ERROR; } @@ -97,7 +97,7 @@ os_err_t sim7070x_ifconfig(mo_object_t *self) os_err_t sim7070x_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t len = -1; + os_int8_t len = -1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; diff --git a/components/molink/module/sim7070x/source/sim7070x_netconn.c b/components/molink/module/sim7070x/source/sim7070x_netconn.c index 9fad00a6..5eb8ca95 100644 --- a/components/molink/module/sim7070x/source/sim7070x_netconn.c +++ b/components/molink/module/sim7070x/source/sim7070x_netconn.c @@ -29,11 +29,11 @@ #include #define MO_LOG_TAG "sim7070x_netconn" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" -#define SEND_DATA_MAX_SIZE (1316) -#define SEND_DATA_MIN_SIZE (1) +#define SEND_DATA_MAX_SIZE (1316) +#define SEND_DATA_MIN_SIZE (1) #define SIM7070X_NETCONN_MQ_NAME "sim7070x_nc_mq" @@ -42,7 +42,7 @@ #endif #ifndef SIM7070X_NETCONN_MQ_MSG_MAX -#define SIM7070X_NETCONN_MQ_MSG_MAX (5) +#define SIM7070X_NETCONN_MQ_MSG_MAX (5) #endif #ifdef SIM7070X_USING_NETCONN_OPS @@ -50,13 +50,13 @@ enum pdpid0_init_status { PDPIDX0_DISABLE = 0, - PDPIDX0_ENABLE = 1, + PDPIDX0_ENABLE = 1, }; enum link_close_reason { LINK_CLOSED_BY_REMOTE_OR_INTERNAL_ERR = 0, - LINK_CONNECT_OK = 1, + LINK_CONNECT_OK = 1, LINK_STATE_UNKNOWN, }; @@ -116,7 +116,7 @@ os_err_t sim7070x_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_sim7070x_t *sim7070x = os_container_of(module, mo_sim7070x_t, parent); info->netconn_array = sim7070x->netconn; - info->netconn_nums = sizeof(sim7070x->netconn) / sizeof(sim7070x->netconn[0]); + info->netconn_nums = sizeof(sim7070x->netconn) / sizeof(sim7070x->netconn[0]); return OS_EOK; } @@ -124,7 +124,7 @@ os_err_t sim7070x_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info) mo_netconn_t *sim7070x_netconn_create(mo_object_t *module, mo_netconn_type_t type) { mo_sim7070x_t *sim7070x = os_container_of(module, mo_sim7070x_t, parent); -// os_err_t result = OS_EOK; + // os_err_t result = OS_EOK; sim7070x_lock(&sim7070x->netconn_lock); @@ -136,9 +136,7 @@ mo_netconn_t *sim7070x_netconn_create(mo_object_t *module, mo_netconn_type_t typ return OS_NULL; } - netconn->mq = os_mq_create(SIM7070X_NETCONN_MQ_NAME, - SIM7070X_NETCONN_MQ_MSG_SIZE, - SIM7070X_NETCONN_MQ_MSG_MAX); + netconn->mq = os_mq_create(SIM7070X_NETCONN_MQ_NAME, SIM7070X_NETCONN_MQ_MSG_SIZE, SIM7070X_NETCONN_MQ_MSG_MAX); if (OS_NULL == netconn->mq) { ERROR("%s data queue create failed, no enough memory.", module->name); @@ -156,7 +154,7 @@ mo_netconn_t *sim7070x_netconn_create(mo_object_t *module, mo_netconn_type_t typ os_err_t sim7070x_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -176,8 +174,8 @@ os_err_t sim7070x_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) if (result != OS_EOK) { ERROR("Module %s destroy %s netconn failed", - module->name, - (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); + module->name, + (netconn->type == NETCONN_TYPE_TCP) ? "TCP" : "UDP"); return result; } break; @@ -195,11 +193,11 @@ os_err_t sim7070x_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn_id: %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; - netconn->local_port = 0; + netconn->local_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); return result; @@ -210,14 +208,14 @@ os_err_t sim7070x_netconn_gethostbyname(mo_object_t *self, const char *domain_na { at_parser_t *parser = &self->parser; - char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; + char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[128] = {0}; - at_resp_t resp = {.buff = resp_buff, + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .line_num = 2, - .timeout = 40 * OS_TICK_PER_SECOND}; + .line_num = 2, + .timeout = 40 * OS_TICK_PER_SECOND}; /* Activate the app network 0th PDP first */ os_err_t result = module_sim7070x_app_network_pdpidx0_init(self); @@ -264,15 +262,13 @@ os_err_t sim7070x_netconn_gethostbyname(mo_object_t *self, const char *domain_na os_err_t sim7070x_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port) { - mo_sim7070x_t *sim7070x = os_container_of(module, mo_sim7070x_t, parent); - at_parser_t *parser = &module->parser; - os_int32_t connect_id = netconn->connect_id; - os_err_t result = OS_ERROR; - char resp_buff[64] = {0}; + mo_sim7070x_t *sim7070x = os_container_of(module, mo_sim7070x_t, parent); + at_parser_t *parser = &module->parser; + os_int32_t connect_id = netconn->connect_id; + os_err_t result = OS_ERROR; + char resp_buff[64] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 30 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 30 * OS_TICK_PER_SECOND}; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -311,7 +307,7 @@ os_err_t sim7070x_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%u successfully!", module->name, remote_ip, port); @@ -327,23 +323,20 @@ __exit: return result; } - os_size_t sim7070x_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; + at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 15 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 15 * OS_TICK_PER_SECOND}; strncpy(remote_ip, inet_ntoa(netconn->remote_ip), IPADDR_MAX_STR_LEN); - //mo_sim7070x_t *sim7070x = os_container_of(module, mo_sim7070x_t, parent); + // mo_sim7070x_t *sim7070x = os_container_of(module, mo_sim7070x_t, parent); /* Protect the data sending process, prevent other threads to send AT commands */ at_parser_exec_lock(parser); @@ -356,12 +349,12 @@ os_size_t sim7070x_netconn_send(mo_object_t *module, mo_netconn_t *netconn, cons result = OS_ERROR; goto __exit; } - - if (size > SEND_DATA_MAX_SIZE || size < SEND_DATA_MIN_SIZE) + + if (size > SEND_DATA_MAX_SIZE || size < SEND_DATA_MIN_SIZE) { ERROR("Module %s send data len out of range [1,1316], send data fail", parser->name); result = OS_ERROR; - goto __exit; + goto __exit; } result = at_parser_exec_cmd(parser, &resp, "AT+CASEND=%d,%d,10000", netconn->connect_id, size); @@ -369,7 +362,7 @@ os_size_t sim7070x_netconn_send(mo_object_t *module, mo_netconn_t *netconn, cons { ERROR("Send data cmd exec fail: AT+CASEND=%d,%d,10000", netconn->connect_id, size); goto __exit; - } + } /* Sending the specified length of data context */ if (at_parser_send(parser, data, size) != size) @@ -377,7 +370,7 @@ os_size_t sim7070x_netconn_send(mo_object_t *module, mo_netconn_t *netconn, cons result = OS_ERROR; ERROR("Drv or hardware send data fail, some data is missing.\r\n"); goto __exit; - } + } __exit: @@ -387,10 +380,7 @@ __exit: at_parser_exec_unlock(parser); if (result != OS_EOK) { - ERROR("Module %s netconn %d send %d bytes data failed!", - parser->name, - netconn->connect_id, - size); + ERROR("Module %s netconn %d send %d bytes data failed!", parser->name, netconn->connect_id, size); return 0; } @@ -403,28 +393,24 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = -1; - os_int32_t state = -1; + os_int32_t state = -1; /* +CASTATE: , */ sscanf(data, "+CASTATE: %d,%d", &connect_id, &state); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = sim7070x_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) { - ERROR("Module %s recv link state urc msg of connect %d, but netconn is not exist", - module->name, - connect_id); + ERROR("Module %s recv link state urc msg of connect %d, but netconn is not exist", module->name, connect_id); return; } switch (state) { case LINK_CLOSED_BY_REMOTE_OR_INTERNAL_ERR: - DEBUG("Module %s connect %d is closed by remote server or internal error", - module->name, - connect_id); + DEBUG("Module %s connect %d is closed by remote server or internal error", module->name, connect_id); mo_netconn_pasv_close_notice(netconn); break; @@ -433,9 +419,7 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t break; default: - ERROR("Module %s recv link state urc msg of connect %d, but state is unkonwn", - module->name, - connect_id); + ERROR("Module %s recv link state urc msg of connect %d, but state is unkonwn", module->name, connect_id); break; } @@ -448,14 +432,14 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; - os_int32_t timeout = data_size > 10 ? data_size : 10; + os_int32_t data_size = 0; + os_int32_t timeout = data_size > 10 ? data_size : 10; /* For ex: +CAURC: "recv",0,10\r\n 0123456789 */ sscanf(data, "+CAURC: \"recv\",%d,%d", &connect_id, &data_size); DEBUG("Moudle %s netconn %d receive %d bytes data", parser->name, connect_id, data_size); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = sim7070x_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) { @@ -465,8 +449,8 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t if (netconn->stat == NETCONN_STAT_CONNECT) { - char *recv_buff = os_calloc(1, data_size + 1); - char temp_buff[8] = {0}; + char *recv_buff = os_calloc(1, data_size + 1); + char temp_buff[8] = {0}; if (recv_buff == OS_NULL) { @@ -510,8 +494,8 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t } static at_urc_t gs_urc_table[] = { - {.prefix = "+CASTATE:", .suffix = "\r\n", .func = urc_close_func}, - {.prefix = "+CAURC: \"recv\"", .suffix = "\r\n", .func = urc_recv_func}, + {.prefix = "+CASTATE:", .suffix = "\r\n", .func = urc_close_func}, + {.prefix = "+CAURC: \"recv\"", .suffix = "\r\n", .func = urc_recv_func}, }; void sim7070x_netconn_init(mo_sim7070x_t *module) diff --git a/components/molink/module/sim7070x/source/sim7070x_netserv.c b/components/molink/module/sim7070x/source/sim7070x_netserv.c index a7054eee..9d300655 100644 --- a/components/molink/module/sim7070x/source/sim7070x_netserv.c +++ b/components/molink/module/sim7070x/source/sim7070x_netserv.c @@ -28,7 +28,7 @@ #include #define MO_LOG_TAG "sim7070x_netserv" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #ifdef SIM7070X_USING_NETSERV_OPS @@ -58,7 +58,7 @@ os_err_t sim7070x_get_attach(mo_object_t *self, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) { ERROR("Get %s module attach state failed", self->name); return OS_ERROR; @@ -117,7 +117,7 @@ os_err_t sim7070x_get_cgact(mo_object_t *self, os_uint8_t *cid, os_uint8_t *act_ at_parser_t *parser = &self->parser; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - char tem_cgact[20] = {0}; + char tem_cgact[20] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 3 * OS_TICK_PER_SECOND}; @@ -135,7 +135,6 @@ os_err_t sim7070x_get_cgact(mo_object_t *self, os_uint8_t *cid, os_uint8_t *act_ *act_stat = tem_cgact[10] - '0'; - return OS_EOK; } diff --git a/components/molink/module/sim7070x/source/sim7070x_ping.c b/components/molink/module/sim7070x/source/sim7070x_ping.c index 0b616ebd..bf9d9cd7 100644 --- a/components/molink/module/sim7070x/source/sim7070x_ping.c +++ b/components/molink/module/sim7070x/source/sim7070x_ping.c @@ -25,7 +25,7 @@ #include "sim7070x_ping.h" #define MO_LOG_TAG "sim7070x_ping" -#define MO_LOG_LVL MO_LOG_INFO +#define MO_LOG_LVL MO_LOG_INFO #include "mo_log.h" #define SIM7070X_MIN_PING_PKG_LEN (1) @@ -35,14 +35,15 @@ #ifdef SIM7070X_USING_PING_OPS -os_err_t sim7070x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) +os_err_t +sim7070x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - os_int32_t req_time = -1; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; + os_int32_t req_time = -1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; - char resp_buff[256] = {0}; + char resp_buff[256] = {0}; if (parser == OS_NULL) { @@ -53,20 +54,20 @@ os_err_t sim7070x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ if ((len > SIM7070X_MAX_PING_PKG_LEN) || (len < SIM7070X_MIN_PING_PKG_LEN)) { ERROR("%s ping: ping package len[%d] is out of range[%d, %d].", - self->name, - len, - SIM7070X_MIN_PING_PKG_LEN, - SIM7070X_MAX_PING_PKG_LEN); + self->name, + len, + SIM7070X_MIN_PING_PKG_LEN, + SIM7070X_MAX_PING_PKG_LEN); return OS_ERROR; } if ((timeout > SIM7070X_MAX_PING_TIMEOUT) || (timeout == 0)) { ERROR("%s ping: user set ping timeout value %ums is out of range[%dms, %dms].", - self->name, - timeout, - SIM7070X_MIN_PING_TIMEOUT, - SIM7070X_MAX_PING_TIMEOUT); + self->name, + timeout, + SIM7070X_MIN_PING_TIMEOUT, + SIM7070X_MAX_PING_TIMEOUT); return OS_ERROR; } @@ -118,8 +119,8 @@ os_err_t sim7070x_ping(mo_object_t *self, const char *host, os_uint16_t len, os_ DEBUG("%s ping: resp parse ip[%s], req_time[%u]", self->name, ipaddr, req_time); inet_aton(ipaddr, &(resp->ip_addr)); resp->data_len = len; - resp->time = req_time; - result = OS_EOK; + resp->time = req_time; + result = OS_EOK; } __exit: diff --git a/components/molink/module/sim7600ce/include/sim7600ce.h b/components/molink/module/sim7600ce/include/sim7600ce.h index 838c01a7..78a9d24d 100644 --- a/components/molink/module/sim7600ce/include/sim7600ce.h +++ b/components/molink/module/sim7600ce/include/sim7600ce.h @@ -77,13 +77,13 @@ typedef struct mo_sim7600ce mo_object_t parent; #ifdef SIM7600CE_USING_NETCONN_OPS mo_netconn_t netconn[SIM7600CE_NETCONN_NUM]; - os_event_t netconn_evt; - os_mutex_t netconn_lock; + os_event_t netconn_evt; + os_mutex_t netconn_lock; #endif /* SIM7600CE_USING_NETCONN_OPS */ } mo_sim7600ce_t; mo_object_t *module_sim7600ce_create(const char *name, void *parser_config); -os_err_t module_sim7600ce_destroy(mo_object_t *self); +os_err_t module_sim7600ce_destroy(mo_object_t *self); #endif /* MOLINK_USING_SIM7600CE */ diff --git a/components/molink/module/sim7600ce/include/sim7600ce_netconn.h b/components/molink/module/sim7600ce/include/sim7600ce_netconn.h index 5163183f..978b1ebc 100644 --- a/components/molink/module/sim7600ce/include/sim7600ce_netconn.h +++ b/components/molink/module/sim7600ce/include/sim7600ce_netconn.h @@ -32,13 +32,13 @@ extern "C" { #ifdef SIM7600CE_USING_NETCONN_OPS -os_err_t sim7600ce_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); +os_err_t sim7600ce_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info); mo_netconn_t *sim7600ce_netconn_create(mo_object_t *module, mo_netconn_type_t type); -os_err_t sim7600ce_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); -os_err_t sim7600ce_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); -os_size_t sim7600ce_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); +os_err_t sim7600ce_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn); +os_err_t sim7600ce_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, ip_addr_t addr, os_uint16_t port); +os_size_t sim7600ce_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size); #ifdef SIM7600CE_USING_DNS -os_err_t sim7600ce_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); +os_err_t sim7600ce_netconn_gethostbyname(mo_object_t *self, const char *domain_name, ip_addr_t *addr); #endif #endif /* SIM7600CE_USING_NETCONN_OPS */ diff --git a/components/molink/module/sim7600ce/include/sim7600ce_ping.h b/components/molink/module/sim7600ce/include/sim7600ce_ping.h index 22a364d9..d50ea2a6 100644 --- a/components/molink/module/sim7600ce/include/sim7600ce_ping.h +++ b/components/molink/module/sim7600ce/include/sim7600ce_ping.h @@ -31,7 +31,8 @@ extern "C" { #ifdef SIM7600CE_USING_PING_OPS -os_err_t sim7600ce_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); +os_err_t +sim7600ce_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp); #endif /* SIM7600CE_USING_PING_OPS */ diff --git a/components/molink/module/sim7600ce/source/sim7600ce.c b/components/molink/module/sim7600ce/source/sim7600ce.c index 5f0d3175..01dfa4ce 100644 --- a/components/molink/module/sim7600ce/source/sim7600ce.c +++ b/components/molink/module/sim7600ce/source/sim7600ce.c @@ -36,12 +36,12 @@ #ifdef SIM7600CE_USING_GENERAL_OPS static const struct mo_general_ops gs_general_ops = { - .at_test = sim7600ce_at_test, - .get_imei = sim7600ce_get_imei, - .get_imsi = sim7600ce_get_imsi, + .at_test = sim7600ce_at_test, + .get_imei = sim7600ce_get_imei, + .get_imsi = sim7600ce_get_imsi, .get_iccid = sim7600ce_get_iccid, - .get_cfun = sim7600ce_get_cfun, - .set_cfun = sim7600ce_set_cfun, + .get_cfun = sim7600ce_get_cfun, + .set_cfun = sim7600ce_set_cfun, }; #endif /* SIM7600CE_USING_GENERAL_OPS */ @@ -49,11 +49,11 @@ static const struct mo_general_ops gs_general_ops = { static const struct mo_netserv_ops gs_netserv_ops = { .set_attach = sim7600ce_set_attach, .get_attach = sim7600ce_get_attach, - .set_reg = sim7600ce_set_reg, - .get_reg = sim7600ce_get_reg, - .set_cgact = sim7600ce_set_cgact, - .get_cgact = sim7600ce_get_cgact, - .get_csq = sim7600ce_get_csq, + .set_reg = sim7600ce_set_reg, + .get_reg = sim7600ce_get_reg, + .set_cgact = sim7600ce_set_cgact, + .get_cgact = sim7600ce_get_cgact, + .get_csq = sim7600ce_get_csq, }; #endif /* SIM7600CE_USING_NETSERV_OPS */ @@ -65,7 +65,7 @@ static const struct mo_ping_ops gs_ping_ops = { #ifdef SIM7600CE_USING_IFCONFIG_OPS static const struct mo_ifconfig_ops gs_ifconfig_ops = { - .ifconfig = sim7600ce_ifconfig, + .ifconfig = sim7600ce_ifconfig, .get_ipaddr = sim7600ce_get_ipaddr, }; #endif /* SIM7600CE_USING_IFCONFIG_OPS */ @@ -74,14 +74,14 @@ static const struct mo_ifconfig_ops gs_ifconfig_ops = { extern void sim7600ce_netconn_init(mo_sim7600ce_t *module); static const struct mo_netconn_ops gs_netconn_ops = { - .create = sim7600ce_netconn_create, - .destroy = sim7600ce_netconn_destroy, + .create = sim7600ce_netconn_create, + .destroy = sim7600ce_netconn_destroy, #ifdef SIM7600CE_USING_DNS .gethostbyname = sim7600ce_netconn_gethostbyname, #endif - .connect = sim7600ce_netconn_connect, - .send = sim7600ce_netconn_send, - .get_info = sim7600ce_netconn_get_info, + .connect = sim7600ce_netconn_connect, + .send = sim7600ce_netconn_send, + .get_info = sim7600ce_netconn_get_info, }; #endif /* SIM7600CE_USING_NETCONN_OPS */ @@ -98,9 +98,7 @@ static os_err_t sim7600ce_at_init(mo_object_t *self) char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 2 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 2 * OS_TICK_PER_SECOND}; return at_parser_exec_cmd(parser, &resp, "ATE0"); } @@ -200,7 +198,7 @@ int sim7600ce_auto_create(void) os_device_control(device, OS_DEVICE_CTRL_CONFIG, &uart_config); - mo_parser_config_t parser_config = {.parser_name = SIM7600CE_NAME, + mo_parser_config_t parser_config = {.parser_name = SIM7600CE_NAME, .parser_device = device, .recv_buff_len = SIM7600CE_RECV_BUFF_LEN}; diff --git a/components/molink/module/sim7600ce/source/sim7600ce_general.c b/components/molink/module/sim7600ce/source/sim7600ce_general.c index 5f1e363e..ef46f80c 100644 --- a/components/molink/module/sim7600ce/source/sim7600ce_general.c +++ b/components/molink/module/sim7600ce/source/sim7600ce_general.c @@ -29,7 +29,6 @@ #define MO_LOG_LVL MO_LOG_INFO #include - #ifdef SIM7600CE_USING_GENERAL_OPS os_err_t sim7600ce_at_test(mo_object_t *self) diff --git a/components/molink/module/sim7600ce/source/sim7600ce_ifconfig.c b/components/molink/module/sim7600ce/source/sim7600ce_ifconfig.c index 1cb8b7e5..89b2f494 100644 --- a/components/molink/module/sim7600ce/source/sim7600ce_ifconfig.c +++ b/components/molink/module/sim7600ce/source/sim7600ce_ifconfig.c @@ -38,14 +38,14 @@ os_err_t sim7600ce_ifconfig(mo_object_t *self) { char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; - char imei[MO_IMEI_LEN + 1] = {0}; - char iccid[MO_ICCID_LEN + 1] = {0}; - char imsi[MO_IMSI_LEN + 1] = {0}; + char imei[MO_IMEI_LEN + 1] = {0}; + char iccid[MO_ICCID_LEN + 1] = {0}; + char imsi[MO_IMSI_LEN + 1] = {0}; - os_err_t ret = OS_EOK; + os_err_t ret = OS_EOK; os_uint8_t rssi = 0; - os_uint8_t ber = 0; - os_int32_t i = 0; + os_uint8_t ber = 0; + os_int32_t i = 0; if (sim7600ce_get_ipaddr(self, ipaddr) != OS_EOK) { @@ -74,7 +74,7 @@ os_err_t sim7600ce_ifconfig(mo_object_t *self) if (sim7600ce_get_csq(self, &rssi, &ber) != OS_EOK) { rssi = 0; - ber = 0; + ber = 0; ret = OS_ERROR; } @@ -104,7 +104,7 @@ os_err_t sim7600ce_ifconfig(mo_object_t *self) os_err_t sim7600ce_get_ipaddr(mo_object_t *self, char ip[]) { at_parser_t *parser = &self->parser; - os_int8_t len = -1; + os_int8_t len = -1; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; diff --git a/components/molink/module/sim7600ce/source/sim7600ce_netconn.c b/components/molink/module/sim7600ce/source/sim7600ce_netconn.c index f08b280f..7c49a95e 100644 --- a/components/molink/module/sim7600ce/source/sim7600ce_netconn.c +++ b/components/molink/module/sim7600ce/source/sim7600ce_netconn.c @@ -32,7 +32,7 @@ #define MO_LOG_LVL MO_LOG_INFO #include -#define SEND_DATA_MAX_SIZE (1360) +#define SEND_DATA_MAX_SIZE (1360) #define SIM7600CE_NETCONN_MQ_NAME "sim7600ce_nc_mq" @@ -41,10 +41,10 @@ #endif #ifndef SIM7600CE_NETCONN_MQ_MSG_MAX -#define SIM7600CE_NETCONN_MQ_MSG_MAX (16) +#define SIM7600CE_NETCONN_MQ_MSG_MAX (16) #endif -#define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) +#define SET_EVENT(socket, event) (((socket + 1) << 16) | (event)) #define SIM7600CE_EVENT_NETCONN_OK (1L << 0) #define SIM7600CE_EVENT_NETCONN_FAIL (1L << 1) @@ -56,25 +56,25 @@ enum net_transfer_mode { NON_TRANSPARENT_MODE = 0, - TRANSPARENT_MODE = 1, + TRANSPARENT_MODE = 1, }; enum net_server_status { NET_SERVER_DISABLE = 0, - NET_SERVER_ENABLE = 1, + NET_SERVER_ENABLE = 1, }; enum netconn_send_status { - CONN_DISCONNECTED = -1, + CONN_DISCONNECTED = -1, CONN_SEND_BUFF_FULL = 0, }; enum link_close_reason { - LINK_CLOSED_BY_LOCAL = 0, - LINK_CLOSED_BY_REMOTE = 1, + LINK_CLOSED_BY_LOCAL = 0, + LINK_CLOSED_BY_REMOTE = 1, SEND_TIMEOUT_OR_DTR_OFF = 2, LINK_CLOSED_UNKNOWN, }; @@ -138,7 +138,7 @@ os_err_t sim7600ce_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info mo_sim7600ce_t *sim7600ce = os_container_of(module, mo_sim7600ce_t, parent); info->netconn_array = sim7600ce->netconn; - info->netconn_nums = sizeof(sim7600ce->netconn) / sizeof(sim7600ce->netconn[0]); + info->netconn_nums = sizeof(sim7600ce->netconn) / sizeof(sim7600ce->netconn[0]); return OS_EOK; } @@ -146,8 +146,8 @@ os_err_t sim7600ce_netconn_get_info(mo_object_t *module, mo_netconn_info_t *info static os_err_t sim7600ce_netconn_set_transfer_mode(mo_object_t *module) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_int32_t mode = -1; + os_err_t result = OS_EOK; + os_int32_t mode = -1; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -188,8 +188,8 @@ static os_err_t sim7600ce_netconn_set_transfer_mode(mo_object_t *module) static os_err_t sim7600ce_netconn_server_open(mo_object_t *module) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_int32_t stat = -1; + os_err_t result = OS_EOK; + os_int32_t stat = -1; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -230,7 +230,7 @@ static os_err_t sim7600ce_netconn_server_open(mo_object_t *module) static os_err_t sim7600ce_net_server_config(mo_object_t *module) { at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -282,7 +282,7 @@ static os_err_t sim7600ce_net_server_config(mo_object_t *module) mo_netconn_t *sim7600ce_netconn_create(mo_object_t *module, mo_netconn_type_t type) { mo_sim7600ce_t *sim7600ce = os_container_of(module, mo_sim7600ce_t, parent); - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; sim7600ce_lock(&sim7600ce->netconn_lock); @@ -322,7 +322,7 @@ mo_netconn_t *sim7600ce_netconn_create(mo_object_t *module, mo_netconn_type_t ty os_err_t sim7600ce_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) { at_parser_t *parser = &module->parser; - os_err_t result = OS_ERROR; + os_err_t result = OS_ERROR; char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; @@ -369,11 +369,11 @@ os_err_t sim7600ce_netconn_destroy(mo_object_t *module, mo_netconn_t *netconn) INFO("Module %s netconn_id: %d destroyed", module->name, netconn->connect_id); - netconn->connect_id = -1; - netconn->stat = NETCONN_STAT_NULL; - netconn->type = NETCONN_TYPE_NULL; + netconn->connect_id = -1; + netconn->stat = NETCONN_STAT_NULL; + netconn->type = NETCONN_TYPE_NULL; netconn->remote_port = 0; - netconn->local_port = 0; + netconn->local_port = 0; inet_aton("0.0.0.0", &netconn->remote_ip); sim7600ce_unlock(&sim7600ce->netconn_lock); @@ -386,12 +386,10 @@ os_err_t sim7600ce_netconn_gethostbyname(mo_object_t *self, const char *domain_n { at_parser_t *parser = &self->parser; - char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; + char recvip[IPADDR_MAX_STR_LEN + 1] = {0}; char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 20 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 20 * OS_TICK_PER_SECOND}; os_err_t result = at_parser_exec_cmd(parser, &resp, "AT+CDNSGIP=\"%s\"", domain_name); if (result < 0) @@ -440,18 +438,16 @@ __exit: static os_err_t sim7600ce_tcp_connect(mo_object_t *module, mo_netconn_t *netconn, char *ip_addr, os_uint16_t port) { mo_sim7600ce_t *sim7600ce = os_container_of(module, mo_sim7600ce_t, parent); - at_parser_t *parser = &module->parser; - os_int32_t connect_id = netconn->connect_id; - os_err_t result = OS_ERROR; - os_uint32_t event = SET_EVENT(netconn->connect_id, SIM7600CE_EVENT_NETCONN_OK | SIM7600CE_EVENT_NETCONN_FAIL); + at_parser_t *parser = &module->parser; + os_int32_t connect_id = netconn->connect_id; + os_err_t result = OS_ERROR; + os_uint32_t event = SET_EVENT(netconn->connect_id, SIM7600CE_EVENT_NETCONN_OK | SIM7600CE_EVENT_NETCONN_FAIL); - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; os_event_recv(&sim7600ce->netconn_evt, event, OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, OS_NO_WAIT, OS_NULL); - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 30 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 30 * OS_TICK_PER_SECOND}; sim7600ce_lock(&sim7600ce->netconn_lock); @@ -504,15 +500,10 @@ static os_err_t sim7600ce_udp_connect(mo_object_t *module, mo_netconn_t *netconn char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff), - .timeout = 30 * OS_TICK_PER_SECOND}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 30 * OS_TICK_PER_SECOND}; - os_err_t result = at_parser_exec_cmd(parser, - &resp, - "AT+CIPOPEN=%d,\"UDP\",,,%u", - netconn->connect_id, - netconn->local_port); + os_err_t result = + at_parser_exec_cmd(parser, &resp, "AT+CIPOPEN=%d,\"UDP\",,,%u", netconn->connect_id, netconn->local_port); if (result != OS_EOK) { ERROR("AT cmd exec failed: AT+CIPOPEN=%d,\"UDP\",,,%u", netconn->connect_id, netconn->local_port); @@ -559,7 +550,7 @@ os_err_t sim7600ce_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, i ip_addr_copy(netconn->remote_ip, addr); netconn->remote_port = port; - netconn->stat = NETCONN_STAT_CONNECT; + netconn->stat = NETCONN_STAT_CONNECT; DEBUG("Module %s connect to %s:%u successfully!", module->name, remote_ip, port); @@ -568,16 +559,16 @@ os_err_t sim7600ce_netconn_connect(mo_object_t *module, mo_netconn_t *netconn, i os_size_t sim7600ce_netconn_send(mo_object_t *module, mo_netconn_t *netconn, const char *data, os_size_t size) { - at_parser_t *parser = &module->parser; - os_err_t result = OS_EOK; - os_size_t sent_size = 0; - os_size_t cur_pkt_size = 0; - os_uint32_t event = 0; + at_parser_t *parser = &module->parser; + os_err_t result = OS_EOK; + os_size_t sent_size = 0; + os_size_t cur_pkt_size = 0; + os_uint32_t event = 0; mo_sim7600ce_t *sim7600ce = os_container_of(module, mo_sim7600ce_t, parent); sim7600ce_lock(&sim7600ce->netconn_lock); - char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; + char resp_buff[AT_RESP_BUFF_SIZE_DEF] = {0}; char remote_ip[IPADDR_MAX_STR_LEN + 1] = {0}; at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), .timeout = 60 * OS_TICK_PER_SECOND}; @@ -713,13 +704,13 @@ static void urc_tcp_connect_func(struct at_parser *parser, const char *data, os_ OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_sim7600ce_t *sim7600ce = os_container_of(module, mo_sim7600ce_t, parent); os_int32_t connect_id = -1; - os_int32_t result = -1; + os_int32_t result = -1; - sscanf(data, "+CIPOPEN: %d,%d", &connect_id , &result); + sscanf(data, "+CIPOPEN: %d,%d", &connect_id, &result); if (0 == result) { @@ -739,11 +730,11 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = -1; - os_int32_t closed_by = -1; + os_int32_t closed_by = -1; sscanf(data, "+IPCLOSE: %d,%d", &connect_id, &closed_by); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = sim7600ce_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) @@ -752,7 +743,7 @@ static void urc_close_func(struct at_parser *parser, const char *data, os_size_t return; } - switch(closed_by) + switch (closed_by) { case LINK_CLOSED_BY_LOCAL: DEBUG("Module %s connect %d, closed by local, active", module->name, connect_id); @@ -783,8 +774,8 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t OS_ASSERT(OS_NULL != data); os_int32_t connect_id = 0; - os_int32_t data_size = 0; - os_int32_t timeout = 0; + os_int32_t data_size = 0; + os_int32_t timeout = 0; /* For ex: +RECEIVE,0,10\r\n 0123456789 */ sscanf(data, "+RECEIVE,%d,%d,", &connect_id, &data_size); @@ -792,7 +783,7 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t timeout = data_size > 10 ? data_size : 10; - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_netconn_t *netconn = sim7600ce_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) { @@ -802,8 +793,8 @@ static void urc_recv_func(struct at_parser *parser, const char *data, os_size_t if (netconn->stat == NETCONN_STAT_CONNECT) { - char *recv_buff = os_calloc(1, data_size + 1); - char temp_buff[8] = {0}; + char *recv_buff = os_calloc(1, data_size + 1); + char temp_buff[8] = {0}; if (recv_buff == OS_NULL) { @@ -852,17 +843,17 @@ static void urc_send_msg_func(struct at_parser *parser, const char *data, os_siz OS_ASSERT(OS_NULL != parser); OS_ASSERT(OS_NULL != data); - os_int32_t connect_id = -1; - os_int32_t reqsend_len = -1; - os_int32_t cnfsend_len = -2; - os_err_t result = OS_EOK; + os_int32_t connect_id = -1; + os_int32_t reqsend_len = -1; + os_int32_t cnfsend_len = -2; + os_err_t result = OS_EOK; /* +CIPSEND: 0,1500,1500\r\n */ sscanf(data, "+CIPSEND: %d,%d,%d", &connect_id, &reqsend_len, &cnfsend_len); - mo_object_t *module = os_container_of(parser, mo_object_t, parser); + mo_object_t *module = os_container_of(parser, mo_object_t, parser); mo_sim7600ce_t *sim7600ce = os_container_of(module, mo_sim7600ce_t, parent); - mo_netconn_t *netconn = sim7600ce_get_netconn_by_id(module, connect_id); + mo_netconn_t *netconn = sim7600ce_get_netconn_by_id(module, connect_id); if (OS_NULL == netconn) { @@ -904,10 +895,10 @@ static void urc_send_msg_func(struct at_parser *parser, const char *data, os_siz } static at_urc_t gs_urc_table[] = { - {.prefix = "+CIPOPEN:", .suffix = "\r\n", .func = urc_tcp_connect_func}, - {.prefix = "+IPCLOSE:", .suffix = "\r\n", .func = urc_close_func}, - {.prefix = "+CIPSEND:", .suffix = "\r\n", .func = urc_send_msg_func}, - {.prefix = "+RECEIVE,", .suffix = "\r\n", .func = urc_recv_func}, + {.prefix = "+CIPOPEN:", .suffix = "\r\n", .func = urc_tcp_connect_func}, + {.prefix = "+IPCLOSE:", .suffix = "\r\n", .func = urc_close_func}, + {.prefix = "+CIPSEND:", .suffix = "\r\n", .func = urc_send_msg_func}, + {.prefix = "+RECEIVE,", .suffix = "\r\n", .func = urc_recv_func}, }; void sim7600ce_netconn_init(mo_sim7600ce_t *module) diff --git a/components/molink/module/sim7600ce/source/sim7600ce_netserv.c b/components/molink/module/sim7600ce/source/sim7600ce_netserv.c index 89905faf..495cd2eb 100644 --- a/components/molink/module/sim7600ce/source/sim7600ce_netserv.c +++ b/components/molink/module/sim7600ce/source/sim7600ce_netserv.c @@ -58,7 +58,7 @@ os_err_t sim7600ce_get_attach(mo_object_t *self, os_uint8_t *attach_stat) return OS_ERROR; } - if(at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) + if (at_resp_get_data_by_kw(&resp, "+CGATT:", "+CGATT: %hhu", attach_stat) <= 0) { ERROR("Get %s module attach state failed", self->name); return OS_ERROR; diff --git a/components/molink/module/sim7600ce/source/sim7600ce_ping.c b/components/molink/module/sim7600ce/source/sim7600ce_ping.c index 2f39733e..8801cd25 100644 --- a/components/molink/module/sim7600ce/source/sim7600ce_ping.c +++ b/components/molink/module/sim7600ce/source/sim7600ce_ping.c @@ -39,16 +39,17 @@ typedef enum sim7600ce_ping_ret_tpye PING_TIMEOUT, PING_SUMMARY, PING_UNKNOWN_RET -}sim7600ce_ping_ret_tpye_t; +} sim7600ce_ping_ret_tpye_t; -os_err_t sim7600ce_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) +os_err_t +sim7600ce_ping(mo_object_t *self, const char *host, os_uint16_t len, os_uint32_t timeout, struct ping_resp *resp) { - at_parser_t *parser = &self->parser; - os_err_t result = OS_EOK; - os_int16_t req_time = -1; - os_int16_t ttl = -1; - os_int16_t req_len = -1; - os_uint8_t ping_stat = 0; + at_parser_t *parser = &self->parser; + os_err_t result = OS_EOK; + os_int16_t req_time = -1; + os_int16_t ttl = -1; + os_int16_t req_len = -1; + os_uint8_t ping_stat = 0; char ipaddr[IPADDR_MAX_STR_LEN + 1] = {0}; @@ -94,10 +95,10 @@ os_err_t sim7600ce_ping(mo_object_t *self, const char *host, os_uint16_t len, os char resp_buff[AT_RESP_BUFF_SIZE_256] = {0}; /* Need to wait for 6 lines response msg */ - at_resp_t at_resp = {.buff = resp_buff, + at_resp_t at_resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff), - .line_num = 3, - .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; + .line_num = 3, + .timeout = (5 + timeout / 1000) * OS_TICK_PER_SECOND}; /* Exec AT+CPING="www.baidu.com",1,1,64,,10000; */ /* Def ping timeout: OK\r\n\r\n +CPING: 2\r\n\r\n +CPING: 3,1,0,1,0,0,0\r\n */ @@ -116,7 +117,7 @@ os_err_t sim7600ce_ping(mo_object_t *self, const char *host, os_uint16_t len, os goto __exit; } - switch(ping_stat) + switch (ping_stat) { case PING_OK: if (at_resp_get_data_by_line(&at_resp, 2, "+CPING: 1,%[^,],%d,%d,%d", ipaddr, &req_len, &req_time, &ttl) < 0) @@ -130,9 +131,9 @@ os_err_t sim7600ce_ping(mo_object_t *self, const char *host, os_uint16_t len, os DEBUG("%s ping: resp parse ip[%s], req_time[%d], ttl[%d]", self->name, ipaddr, req_time, ttl); inet_aton(ipaddr, &(resp->ip_addr)); resp->data_len = len; - resp->ttl = ttl; - resp->time = req_time; - result = OS_EOK; + resp->ttl = ttl; + resp->time = req_time; + result = OS_EOK; } break; diff --git a/components/molink/parser/include/at_parser.h b/components/molink/parser/include/at_parser.h index 774f68d0..a1e384d4 100644 --- a/components/molink/parser/include/at_parser.h +++ b/components/molink/parser/include/at_parser.h @@ -37,8 +37,6 @@ extern "C" { #endif /* __cplusplus */ - - #ifndef END_MARK_LEN #define END_MARK_LEN 2 #endif @@ -80,24 +78,24 @@ typedef struct at_urc typedef struct at_parser { #ifdef MOLINK_USING_MULTI_MODULES - os_slist_node_t list; /* at parser object manage list */ + os_slist_node_t list; /* at parser object manage list */ #endif char name[OS_NAME_MAX + 1]; /* The name of AT parser */ - os_device_t *device; /* The device used by AT parser */ - char *at_cmd_buff; /* The send buffer of cmd */ - char *recv_buff; /* The receive buffer of AT parser */ + os_device_t *device; /* The device used by AT parser */ + char *at_cmd_buff; /* The send buffer of cmd */ + char *recv_buff; /* The receive buffer of AT parser */ os_size_t recv_buff_len; /* The receive buffer length of AT parser */ os_size_t curr_recv_len; /* The current receive data length of AT parser */ os_event_t rx_notice_evt; /* The receive event of at parser */ - os_mutex_t exec_lock; /* The recursive lock that protects the execution of the AT command */ + os_mutex_t exec_lock; /* The recursive lock that protects the execution of the AT command */ os_sem_t resp_notice; /* the response notice semaphore */ - os_size_t end_mark_len; /* The special end mark length */ - char end_mark[END_MARK_LEN + 1]; /* The special end mark */ + os_size_t end_mark_len; /* The special end mark length */ + char end_mark[END_MARK_LEN + 1]; /* The special end mark */ at_resp_t *resp; /* AT command response object */ @@ -110,17 +108,17 @@ os_err_t at_parser_init(at_parser_t *parser, const char *name, os_device_t *devi os_err_t at_parser_startup(at_parser_t *parser); os_err_t at_parser_deinit(at_parser_t *parser); -os_err_t at_parser_exec_lock(at_parser_t *parser); -os_err_t at_parser_exec_unlock(at_parser_t *parser); -os_err_t at_parser_exec_cmd_valist(at_parser_t *parser, at_resp_t *resp, const char *cmd_expr, va_list args); -os_err_t at_parser_exec_cmd(at_parser_t *parser, at_resp_t *resp, const char *cmd_expr, ...); +os_err_t at_parser_exec_lock(at_parser_t *parser); +os_err_t at_parser_exec_unlock(at_parser_t *parser); +os_err_t at_parser_exec_cmd_valist(at_parser_t *parser, at_resp_t *resp, const char *cmd_expr, va_list args); +os_err_t at_parser_exec_cmd(at_parser_t *parser, at_resp_t *resp, const char *cmd_expr, ...); -os_err_t at_parser_connect(at_parser_t *parser, os_uint8_t retry_times); +os_err_t at_parser_connect(at_parser_t *parser, os_uint8_t retry_times); os_size_t at_parser_send(at_parser_t *parser, const char *buf, os_size_t size); os_size_t at_parser_recv(at_parser_t *parser, char *buf, os_size_t size, os_int32_t timeout); os_err_t at_parser_set_end_mark(at_parser_t *parser, const char *end_mark, os_size_t end_mark_len); -void at_parser_set_urc_table(at_parser_t *parser, at_urc_t urc_table[], os_size_t table_size); +void at_parser_set_urc_table(at_parser_t *parser, at_urc_t urc_table[], os_size_t table_size); #ifdef __cplusplus } diff --git a/components/molink/parser/include/at_resp.h b/components/molink/parser/include/at_resp.h index e6e9fc94..02f4b087 100644 --- a/components/molink/parser/include/at_resp.h +++ b/components/molink/parser/include/at_resp.h @@ -53,7 +53,7 @@ extern "C" { */ typedef enum resp_stat { - RESP_STAT_NULL = 0, /* Parser response end is NULL */ + RESP_STAT_NULL = 0, /* Parser response end is NULL */ RESP_STAT_OK, /* Parser response end is OK */ RESP_STAT_ERROR, /* Parser response end is ERROR */ RESP_STAT_TIMEOUT, /* Parser response is timeout */ @@ -69,21 +69,21 @@ typedef enum resp_stat */ typedef struct at_resp { - resp_stat_t stat; /* the status of current response */ + resp_stat_t stat; /* the status of current response */ - os_size_t line_num; /* the number of setting response lines */ - os_size_t line_counts; /* the count of received response lines */ - os_int32_t timeout; /* the maximum response time */ + os_size_t line_num; /* the number of setting response lines */ + os_size_t line_counts; /* the count of received response lines */ + os_int32_t timeout; /* the maximum response time */ - os_size_t curr_buff_len; /* the length of current response buffer */ - os_size_t buff_size; /* the maximum response buffer size */ - char *buff; /* response buffer */ + os_size_t curr_buff_len; /* the length of current response buffer */ + os_size_t buff_size; /* the maximum response buffer size */ + char *buff; /* response buffer */ } at_resp_t; const char *at_resp_get_line(at_resp_t *resp, os_size_t resp_line); const char *at_resp_get_line_by_kw(at_resp_t *resp, const char *keyword); -os_int32_t at_resp_get_data_by_line(at_resp_t *resp, os_size_t resp_line, const char *resp_expr, ...); -os_int32_t at_resp_get_data_by_kw(at_resp_t *resp, const char *keyword, const char *resp_expr, ...); +os_int32_t at_resp_get_data_by_line(at_resp_t *resp, os_size_t resp_line, const char *resp_expr, ...); +os_int32_t at_resp_get_data_by_kw(at_resp_t *resp, const char *keyword, const char *resp_expr, ...); #ifdef __cplusplus } diff --git a/components/molink/parser/source/at_parser.c b/components/molink/parser/source/at_parser.c index 0393a3db..379383e1 100644 --- a/components/molink/parser/source/at_parser.c +++ b/components/molink/parser/source/at_parser.c @@ -36,20 +36,19 @@ #include #define MO_LOG_TAG "at.parser" -#define MO_LOG_LVL MO_LOG_EMERG +#define MO_LOG_LVL MO_LOG_EMERG #include "mo_log.h" -#define AT_PARSER_PROTECT os_schedule_lock() -#define AT_PARSER_UNPROTECT os_schedule_unlock() +#define AT_PARSER_PROTECT os_schedule_lock() +#define AT_PARSER_UNPROTECT os_schedule_unlock() -#define AT_PARSER_RX_ARRIVE (1UL) +#define AT_PARSER_RX_ARRIVE (1UL) #ifdef MOLINK_USING_MULTI_MODULES /* AT Parser manage list */ static os_slist_node_t gs_parser_list = {0}; #endif - #ifdef MOLINK_USING_MULTI_MODULES static void at_parser_list_add(at_parser_t *parser) { @@ -69,8 +68,8 @@ static void at_parser_list_del(at_parser_t *parser) { OS_ASSERT(parser != OS_NULL); - os_slist_node_t *node = OS_NULL; - at_parser_t *entry = OS_NULL; + os_slist_node_t *node = OS_NULL; + at_parser_t *entry = OS_NULL; AT_PARSER_PROTECT; @@ -228,11 +227,11 @@ os_err_t at_parser_exec_cmd_valist(at_parser_t *parser, at_resp_t *resp, const c at_parser_exec_lock(parser); memset(resp->buff, 0, resp->buff_size); - resp->stat = RESP_STAT_NULL; + resp->stat = RESP_STAT_NULL; resp->curr_buff_len = 0; - resp->line_counts = 0; + resp->line_counts = 0; - parser->resp = resp; + parser->resp = resp; /* Send at command to module */ at_parser_vasprintfln(parser, cmd_expr, args); @@ -241,13 +240,13 @@ os_err_t at_parser_exec_cmd_valist(at_parser_t *parser, at_resp_t *resp, const c { ERROR("execute command (%s) timeout (%d ticks)!", parser->at_cmd_buff, resp->timeout); resp->stat = RESP_STAT_TIMEOUT; - result = OS_ETIMEOUT; + result = OS_ETIMEOUT; goto __exit; } if (resp->stat != RESP_STAT_OK) { - ERROR("execute command (%s) failed, parser->resp_status:%d",parser->at_cmd_buff, resp->stat); + ERROR("execute command (%s) failed, parser->resp_status:%d", parser->at_cmd_buff, resp->stat); result = OS_ERROR; goto __exit; } @@ -290,9 +289,8 @@ os_err_t at_parser_exec_cmd(at_parser_t *parser, at_resp_t *resp, const char *cm OS_ASSERT(resp->buff != OS_NULL); OS_ASSERT(cmd_expr != OS_NULL); - os_err_t result = OS_EOK; - va_list args = {0}; + va_list args = {0}; va_start(args, cmd_expr); result = at_parser_exec_cmd_valist(parser, resp, cmd_expr, args); @@ -349,10 +347,10 @@ static os_err_t at_parser_getchar(at_parser_t *parser, char *ch, os_int32_t time os_event_clear(&parser->rx_notice_evt, AT_PARSER_RX_ARRIVE); result = os_event_recv(&parser->rx_notice_evt, - AT_PARSER_RX_ARRIVE, - OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, - timeout, - OS_NULL); + AT_PARSER_RX_ARRIVE, + OS_EVENT_OPTION_OR | OS_EVENT_OPTION_CLEAR, + timeout, + OS_NULL); if (OS_EOK != result) { @@ -382,9 +380,9 @@ os_size_t at_parser_recv(at_parser_t *parser, char *buf, os_size_t size, os_int3 OS_ASSERT(parser != OS_NULL); OS_ASSERT(buf != OS_NULL); - char ch = 0; + char ch = 0; os_size_t read_idx = 0; - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; while (1) { @@ -431,8 +429,7 @@ os_err_t at_parser_connect(at_parser_t *parser, os_uint8_t retry_times) char resp_buff[32] = {0}; - at_resp_t resp = {.buff = resp_buff, - .buff_size = sizeof(resp_buff)}; + at_resp_t resp = {.buff = resp_buff, .buff_size = sizeof(resp_buff)}; at_parser_exec_lock(parser); @@ -492,9 +489,9 @@ static at_urc_t *at_parser_get_urc(at_parser_t *parser) return OS_NULL; } - char *buffer = parser->recv_buff; + char *buffer = parser->recv_buff; os_size_t buff_sz = parser->curr_recv_len; - at_urc_t *urc = OS_NULL; + at_urc_t *urc = OS_NULL; AT_PARSER_PROTECT; @@ -564,10 +561,10 @@ os_err_t at_parser_set_end_mark(at_parser_t *parser, const char *end_mark_str, o static int at_parser_readline(at_parser_t *parser) { - os_size_t read_len = 0; - os_bool_t is_full = OS_FALSE; - char prev_read_char = 0; - char curr_read_char = 0; + os_size_t read_len = 0; + os_bool_t is_full = OS_FALSE; + char prev_read_char = 0; + char curr_read_char = 0; memset(parser->recv_buff, 0x00, parser->recv_buff_len); parser->curr_recv_len = 0; @@ -579,7 +576,7 @@ static int at_parser_readline(at_parser_t *parser) if (read_len < parser->recv_buff_len) { parser->recv_buff[read_len++] = curr_read_char; - parser->curr_recv_len = read_len; + parser->curr_recv_len = read_len; } else { @@ -635,7 +632,8 @@ static void at_parser_resp_handle(at_parser_t *parser) if ('\n' == parser->recv_buff[parser->curr_recv_len - 1]) { /* skip the empty line */ - if (2 >= parser->curr_recv_len) return; + if (2 >= parser->curr_recv_len) + return; /* line end with "/r/n" */ parser->recv_buff[parser->curr_recv_len - 1] = '\0'; @@ -663,7 +661,8 @@ static void at_parser_resp_handle(at_parser_t *parser) } /* check response result */ - if (memcmp(parser->recv_buff, AT_RESP_OK, strlen(AT_RESP_OK)) == 0 && resp->line_num == 0 && parser->end_mark_len == 0) + if (memcmp(parser->recv_buff, AT_RESP_OK, strlen(AT_RESP_OK)) == 0 && resp->line_num == 0 && + parser->end_mark_len == 0) { /* get the end data by response result, return response state END_OK. */ resp->stat = RESP_STAT_OK; @@ -677,10 +676,9 @@ static void at_parser_resp_handle(at_parser_t *parser) /* get the end data by response line, return response state END_OK.*/ resp->stat = RESP_STAT_OK; } - else if (0 != parser->end_mark_len && - !memcmp(parser->recv_buff + parser->curr_recv_len - parser->end_mark_len - 1, - parser->end_mark, - parser->end_mark_len)) + else if (0 != parser->end_mark_len && !memcmp(parser->recv_buff + parser->curr_recv_len - parser->end_mark_len - 1, + parser->end_mark, + parser->end_mark_len)) { /* when process the end mark line, return response state END_OK. */ resp->stat = RESP_STAT_OK; @@ -732,7 +730,7 @@ static os_err_t at_parser_rx_indicate(os_device_t *dev, struct os_device_cb_info static os_err_t at_parser_device_open(at_parser_t *parser, os_device_t *device) { - os_err_t result = OS_EOK; + os_err_t result = OS_EOK; result = os_device_open(device); if (result != OS_EOK) @@ -746,7 +744,7 @@ static os_err_t at_parser_device_open(at_parser_t *parser, os_device_t *device) struct os_device_cb_info cb_info = { .type = OS_DEVICE_CB_TYPE_RX, .data = parser, /* The AT Parser operator is passed through a callback structure */ - .cb = at_parser_rx_indicate, + .cb = at_parser_rx_indicate, }; result = os_device_control(parser->device, OS_DEVICE_CTRL_SET_CB, &cb_info); @@ -930,7 +928,7 @@ os_err_t at_parser_deinit(at_parser_t *parser) at_parser_list_del(parser); #endif - if(parser->task != OS_NULL) + if (parser->task != OS_NULL) { os_task_destroy(parser->task); } diff --git a/components/molink/parser/source/at_resp.c b/components/molink/parser/source/at_resp.c index 01d20775..baeeba4d 100644 --- a/components/molink/parser/source/at_resp.c +++ b/components/molink/parser/source/at_resp.c @@ -27,7 +27,7 @@ #include #define MO_LOG_TAG "at.resp" -#define MO_LOG_LVL MO_LOG_EMERG +#define MO_LOG_LVL MO_LOG_EMERG #include "mo_log.h" /** @@ -111,7 +111,7 @@ const char *at_resp_get_line_by_kw(at_resp_t *resp, const char *keyword) * @param[in] resp_line The line number of response data, , start from '1 * @param[in] resp_expr The data parser expression * @param[in] ... The data parser arguments - * + * * @return Return get data nums *********************************************************************************************************************** */ @@ -146,7 +146,7 @@ os_int32_t at_resp_get_data_by_line(at_resp_t *resp, os_size_t resp_line, const * @param[in] keyword The keyword of response data * @param[in] resp_expr The data parser expression * @param[in] ... The data parser arguments - * + * * @return Return get data nums *********************************************************************************************************************** */ diff --git a/components/ota/cmiot/inc/cmiot_client.h b/components/ota/cmiot/inc/cmiot_client.h index b9a40f3d..f9e72cdf 100644 --- a/components/ota/cmiot/inc/cmiot_client.h +++ b/components/ota/cmiot/inc/cmiot_client.h @@ -36,9 +36,9 @@ extern "C" { typedef struct { - cmiot_char download_host[CMIOT_DOWNLOAD_HOST_MAX_LEN + 1]; - cmiot_char download_url[CMIOT_DOWNLOAD_URI_MAX_LEN + 1]; - cmiot_char download_md5[CMIOT_DOWNLOAD_MD5_LEN + 1]; + cmiot_char download_host[CMIOT_DOWNLOAD_HOST_MAX_LEN + 1]; + cmiot_char download_url[CMIOT_DOWNLOAD_URI_MAX_LEN + 1]; + cmiot_char download_md5[CMIOT_DOWNLOAD_MD5_LEN + 1]; cmiot_uint32 download_delta_id; cmiot_uint32 download_delta_size; cmiot_uint32 download_port; @@ -46,16 +46,16 @@ typedef struct #define DECLARE_VOID_FUNC(PREFIX, SUFFIX) cmiot_int8 PREFIX##_##SUFFIX(void); -cmiot_uint8 cmiot_get_current_state(void); -cmiot_uint8 cmiot_get_conn_try_count(void); -cmiot_char * cmiot_get_send_buf(void); -cmiot_uint16 cmiot_get_send_buf_len(void); -void cmiot_reset_send_buf(void); -cmiot_uint16 cmiot_get_recieve_buf_len(void); +cmiot_uint8 cmiot_get_current_state(void); +cmiot_uint8 cmiot_get_conn_try_count(void); +cmiot_char *cmiot_get_send_buf(void); +cmiot_uint16 cmiot_get_send_buf_len(void); +void cmiot_reset_send_buf(void); +cmiot_uint16 cmiot_get_recieve_buf_len(void); cmiot_download_uri_info_t *cmiot_get_download_uri_info(void); -cmiot_uint32 cmiot_get_download_index(void); -cmiot_uint32 cmiot_get_download_index_max(void); -cmiot_bool cmiot_get_domain(cmiot_char *server, cmiot_char *domain, cmiot_uint32 *port); +cmiot_uint32 cmiot_get_download_index(void); +cmiot_uint32 cmiot_get_download_index_max(void); +cmiot_bool cmiot_get_domain(cmiot_char *server, cmiot_char *domain, cmiot_uint32 *port); DECLARE_VOID_FUNC(cmiot_upgrade, coap) DECLARE_VOID_FUNC(cmiot_upgrade, http) diff --git a/components/ota/cmiot/inc/cmiot_coap.h b/components/ota/cmiot/inc/cmiot_coap.h index ba8e9822..43f377e7 100644 --- a/components/ota/cmiot/inc/cmiot_coap.h +++ b/components/ota/cmiot/inc/cmiot_coap.h @@ -61,26 +61,51 @@ typedef cmiot_uint8 coap_status_t; #define COAP_505_PROXYING_NOT_SUPPORTED (cmiot_uint8)0xA5 #define COAP_UNKOWN_ERROR (cmiot_uint8)0xC0 -#define STR_COAP_CODE(code) \ - ((code) == COAP_201_CREATED ? "COAP_201" : \ - ((code) == COAP_202_DELETED ? "COAP_202" : \ - ((code) == COAP_204_CHANGED ? "COAP_204" : \ - ((code) == COAP_205_CONTENT ? "COAP_205" : \ - ((code) == COAP_206_CONFORM ? "COAP_206" : \ - ((code) == COAP_231_CONTINUE ? "COAP_231" : \ - ((code) == COAP_400_BAD_REQUEST ? "COAP_400" : \ - ((code) == COAP_401_UNAUTHORIZED ? "COAP_401" : \ - ((code) == COAP_402_BAD_OPTION ? "COAP_402" : \ - ((code) == COAP_404_NOT_FOUND ? "COAP_404" : \ - ((code) == COAP_405_METHOD_NOT_ALLOWED ? "COAP_405" : \ - ((code) == COAP_406_NOT_ACCEPTABLE ? "COAP_406" : \ - ((code) == COAP_408_REQ_ENTITY_INCOMPLETE ? "COAP_408" : \ - ((code) == COAP_413_ENTITY_TOO_LARGE ? "COAP_413" : \ - ((code) == COAP_500_INTERNAL_SERVER_ERROR ? "COAP_500" : \ - ((code) == COAP_501_NOT_IMPLEMENTED ? "COAP_501" : \ - ((code) == COAP_503_SERVICE_UNAVAILABLE ? "COAP_503" : \ - ((code) == COAP_505_PROXYING_NOT_SUPPORTED ? "COAP_505" : \ - "Unknown")))))))))))))))))) +#define STR_COAP_CODE(code) \ + ((code) == COAP_201_CREATED \ + ? "COAP_201" \ + : ((code) == COAP_202_DELETED \ + ? "COAP_202" \ + : ((code) == COAP_204_CHANGED \ + ? "COAP_204" \ + : ((code) == COAP_205_CONTENT \ + ? "COAP_205" \ + : ((code) == COAP_206_CONFORM \ + ? "COAP_206" \ + : ((code) == COAP_231_CONTINUE \ + ? "COAP_231" \ + : ((code) == COAP_400_BAD_REQUEST \ + ? "COAP_400" \ + : ((code) == COAP_401_UNAUTHORIZED \ + ? "COAP_401" \ + : ((code) == COAP_402_BAD_OPTION \ + ? "COAP_402" \ + : ((code) == COAP_404_NOT_FOUND \ + ? "COAP_404" \ + : ((code) == COAP_405_METHOD_NOT_ALLOWED \ + ? "COAP_405" \ + : ((code) == COAP_406_NOT_ACCEPTABLE \ + ? "COAP_406" \ + : ((code) == \ + COAP_408_REQ_ENTITY_INCOMPLETE \ + ? "COAP_408" \ + : ((code) == \ + COAP_413_ENTITY_TOO_LARGE \ + ? "COAP_413" \ + : ((code) == \ + COAP_500_INTERNAL_SERVER_ERROR \ + ? "COAP_" \ + "500" \ + : ((code) == \ + COAP_501_NOT_IMPLEMENTED \ + ? "COAP_501" \ + : ((code) == \ + COAP_503_SERVICE_UNAVAILABLE \ + ? "COAP_503" \ + : ((code) == \ + COAP_505_PROXYING_NOT_SUPPORTED \ + ? "COAP_505" \ + : "Unknown")))))))))))))))))) #define COAP_HEADER_LEN 4 /* | version:0x03 type:0x0C tkl:0xF0 | code | mid:0x00FF | mid:0xFF00 | */ #define COAP_ETAG_LEN 8 /* The maximum number of bytes for the ETag */ @@ -123,24 +148,24 @@ typedef enum typedef enum { - COAP_OPTION_IF_MATCH = 1, /* 0-8 B */ - COAP_OPTION_URI_HOST = 3, /* 1-255 B */ - COAP_OPTION_ETAG = 4, /* 1-8 B */ - COAP_OPTION_IF_NONE_MATCH = 5, /* 0 B */ - COAP_OPTION_OBSERVE = 6, /* 0-3 B */ - COAP_OPTION_URI_PORT = 7, /* 0-2 B */ - COAP_OPTION_LOCATION_PATH = 8, /* 0-255 B */ - COAP_OPTION_URI_PATH = 11, /* 0-255 B */ - COAP_OPTION_CONTENT_TYPE = 12, /* 0-2 B */ - COAP_OPTION_MAX_AGE = 14, /* 0-4 B */ - COAP_OPTION_URI_QUERY = 15, /* 0-270 B */ - COAP_OPTION_ACCEPT = 17, /* 0-2 B */ - COAP_OPTION_TOKEN = 19, /* 1-8 B */ + COAP_OPTION_IF_MATCH = 1, /* 0-8 B */ + COAP_OPTION_URI_HOST = 3, /* 1-255 B */ + COAP_OPTION_ETAG = 4, /* 1-8 B */ + COAP_OPTION_IF_NONE_MATCH = 5, /* 0 B */ + COAP_OPTION_OBSERVE = 6, /* 0-3 B */ + COAP_OPTION_URI_PORT = 7, /* 0-2 B */ + COAP_OPTION_LOCATION_PATH = 8, /* 0-255 B */ + COAP_OPTION_URI_PATH = 11, /* 0-255 B */ + COAP_OPTION_CONTENT_TYPE = 12, /* 0-2 B */ + COAP_OPTION_MAX_AGE = 14, /* 0-4 B */ + COAP_OPTION_URI_QUERY = 15, /* 0-270 B */ + COAP_OPTION_ACCEPT = 17, /* 0-2 B */ + COAP_OPTION_TOKEN = 19, /* 1-8 B */ COAP_OPTION_LOCATION_QUERY = 20, /* 1-270 B */ - COAP_OPTION_BLOCK2 = 23, /* 1-3 B */ - COAP_OPTION_BLOCK1 = 27, /* 1-3 B */ - COAP_OPTION_SIZE = 28, /* 0-4 B */ - COAP_OPTION_PROXY_URI = 35, /* 1-270 B */ + COAP_OPTION_BLOCK2 = 23, /* 1-3 B */ + COAP_OPTION_BLOCK1 = 27, /* 1-3 B */ + COAP_OPTION_SIZE = 28, /* 0-4 B */ + COAP_OPTION_PROXY_URI = 35, /* 1-270 B */ } coap_option_t; #define CMIOT_COAP_OPTION_PROXY_URI 35 @@ -149,28 +174,28 @@ typedef enum /* CoAP Content-Types */ typedef enum { - TEXT_PLAIN = 0, - TEXT_XML = 1, /* Indented types are not in the initial registry. */ - TEXT_CSV = 2, - TEXT_HTML = 3, - IMAGE_GIF = 21, - IMAGE_JPEG = 22, - IMAGE_PNG = 23, - IMAGE_TIFF = 24, - AUDIO_RAW = 25, - VIDEO_RAW = 26, - APPLICATION_LINK_FORMAT = 40, - APPLICATION_XML = 41, - APPLICATION_OCTET_STREAM = 42, - APPLICATION_RDF_XML = 43, - APPLICATION_SOAP_XML = 44, - APPLICATION_ATOM_XML = 45, - APPLICATION_XMPP_XML = 46, - APPLICATION_EXI = 47, - APPLICATION_FASTINFOSET = 48, + TEXT_PLAIN = 0, + TEXT_XML = 1, /* Indented types are not in the initial registry. */ + TEXT_CSV = 2, + TEXT_HTML = 3, + IMAGE_GIF = 21, + IMAGE_JPEG = 22, + IMAGE_PNG = 23, + IMAGE_TIFF = 24, + AUDIO_RAW = 25, + VIDEO_RAW = 26, + APPLICATION_LINK_FORMAT = 40, + APPLICATION_XML = 41, + APPLICATION_OCTET_STREAM = 42, + APPLICATION_RDF_XML = 43, + APPLICATION_SOAP_XML = 44, + APPLICATION_ATOM_XML = 45, + APPLICATION_XMPP_XML = 46, + APPLICATION_EXI = 47, + APPLICATION_FASTINFOSET = 48, APPLICATION_SOAP_FASTINFOSET = 49, - APPLICATION_JSON = 50, - APPLICATION_X_OBIX_BINARY = 51, + APPLICATION_JSON = 50, + APPLICATION_X_OBIX_BINARY = 51, CONTENT_TYPE_MAX = 0xFFFF } coap_content_type_t; @@ -178,74 +203,74 @@ typedef enum typedef struct _multi_option_t { struct _multi_option_t *next; - cmiot_uint8 is_static; - cmiot_uint8 len; - cmiot_uint8 * data; + cmiot_uint8 is_static; + cmiot_uint8 len; + cmiot_uint8 *data; } multi_option_t; /* Parsed message struct */ typedef struct _coap_packet_t { struct _coap_packet_t *next; - cmiot_uint8 * buffer; /* pointer to CoAP header / incoming packet buffer / memory to serialize packet */ + cmiot_uint8 *buffer; /* pointer to CoAP header / incoming packet buffer / memory to serialize packet */ - cmiot_uint8 version; + cmiot_uint8 version; coap_message_type_t type; - cmiot_uint8 code; - cmiot_uint16 mid; + cmiot_uint8 code; + cmiot_uint16 mid; cmiot_uint8 options[CMIOT_COAP_OPTION_PROXY_URI / OPTION_MAP_SIZE + 1]; /* Bitmap to check if option is set */ coap_content_type_t content_type; /* Parse options once and store; allows setting options in random order */ - cmiot_uint32 max_age; - cmiot_uint32 proxy_uri_len; - const cmiot_uint8 * proxy_uri; - cmiot_uint8 etag_len; - cmiot_uint8 etag[COAP_ETAG_LEN]; - cmiot_uint32 uri_host_len; - const cmiot_uint8 * uri_host; - multi_option_t * location_path; - cmiot_uint16 uri_port; - cmiot_uint32 location_query_len; - cmiot_char * location_query; - multi_option_t * uri_path; - cmiot_uint32 observe; - cmiot_uint8 token_len; - cmiot_uint8 token[COAP_TOKEN_LEN]; - cmiot_uint8 accept_num; - cmiot_uint16 accept[COAP_MAX_ACCEPT_NUM]; - cmiot_uint8 if_match_len; - cmiot_uint8 if_match[COAP_ETAG_LEN]; - cmiot_uint32 block2_num; - cmiot_uint8 block2_more; - cmiot_uint16 block2_size; - cmiot_uint32 block2_offset; - cmiot_uint32 block1_num; - cmiot_uint8 block1_more; - cmiot_uint16 block1_size; - cmiot_uint32 block1_offset; - cmiot_uint32 size; - multi_option_t * uri_query; - cmiot_uint8 if_none_match; - cmiot_uint8 format; - cmiot_uint16 payload_len; - cmiot_uint8 * payload; + cmiot_uint32 max_age; + cmiot_uint32 proxy_uri_len; + const cmiot_uint8 *proxy_uri; + cmiot_uint8 etag_len; + cmiot_uint8 etag[COAP_ETAG_LEN]; + cmiot_uint32 uri_host_len; + const cmiot_uint8 *uri_host; + multi_option_t *location_path; + cmiot_uint16 uri_port; + cmiot_uint32 location_query_len; + cmiot_char *location_query; + multi_option_t *uri_path; + cmiot_uint32 observe; + cmiot_uint8 token_len; + cmiot_uint8 token[COAP_TOKEN_LEN]; + cmiot_uint8 accept_num; + cmiot_uint16 accept[COAP_MAX_ACCEPT_NUM]; + cmiot_uint8 if_match_len; + cmiot_uint8 if_match[COAP_ETAG_LEN]; + cmiot_uint32 block2_num; + cmiot_uint8 block2_more; + cmiot_uint16 block2_size; + cmiot_uint32 block2_offset; + cmiot_uint32 block1_num; + cmiot_uint8 block1_more; + cmiot_uint16 block1_size; + cmiot_uint32 block1_offset; + cmiot_uint32 size; + multi_option_t *uri_query; + cmiot_uint8 if_none_match; + cmiot_uint8 format; + cmiot_uint16 payload_len; + cmiot_uint8 *payload; } coap_packet_t; typedef struct { - cmiot_uint8 cmiot_coap[CMIOT_COAP_MAX_LEN]; + cmiot_uint8 cmiot_coap[CMIOT_COAP_MAX_LEN]; coap_packet_t cmiot_packet; } cmiot_coap_packet_t; -void * cmiot_parse_message(cmiot_char *p, cmiot_uint32 len); -cmiot_char * cmiot_coap_para_get(cmiot_uint32 index, const cmiot_char *get, cmiot_uint32 *data_len); +void *cmiot_parse_message(cmiot_char *p, cmiot_uint32 len); +cmiot_char *cmiot_coap_para_get(cmiot_uint32 index, const cmiot_char *get, cmiot_uint32 *data_len); cmiot_uint16 coap_get_msgid(void); -void coap_msgid_plus(void); -cmiot_char * cmiot_coap_make_data(cmiot_uint8 state, cmiot_uint16 *len); +void coap_msgid_plus(void); +cmiot_char *cmiot_coap_make_data(cmiot_uint8 state, cmiot_uint16 *len); cmiot_uint32 cmiot_coap_callback(cmiot_uint8 state, cmiot_char *data, cmiot_uint32 len); -cmiot_char * cmiot_get_coap_server_host(void); +cmiot_char *cmiot_get_coap_server_host(void); #ifdef __cplusplus } diff --git a/components/ota/cmiot/inc/cmiot_config.h b/components/ota/cmiot/inc/cmiot_config.h index 349c42f7..40a45280 100644 --- a/components/ota/cmiot/inc/cmiot_config.h +++ b/components/ota/cmiot/inc/cmiot_config.h @@ -78,7 +78,7 @@ extern "C" { #define CMIOT_SEND_BUF_MAXLEN (CMIOT_COAP_MAX_LEN) #endif -cmiot_char * cmiot_get_sdk_version(void); +cmiot_char *cmiot_get_sdk_version(void); cmiot_uint32 cmiot_get_down_start_time(void); cmiot_uint32 cmiot_get_down_end_time(void); cmiot_uint32 cmiot_get_data_max_len(void); diff --git a/components/ota/cmiot/inc/cmiot_hal.h b/components/ota/cmiot/inc/cmiot_hal.h index 196fc7d7..66521259 100644 --- a/components/ota/cmiot/inc/cmiot_hal.h +++ b/components/ota/cmiot/inc/cmiot_hal.h @@ -43,12 +43,12 @@ typedef enum typedef struct { - cmiot_uint8 inited; + cmiot_uint8 inited; cmiot_uint16 update_result; - cmiot_char mid[CMIOT_MID_MAXLEN + 1]; - cmiot_char code[32]; - cmiot_char device_id[CMIOT_DEVICEID_MAX_LEN + 1]; - cmiot_char device_secret[CMIOT_DEVICESECRET_MAX_LEN + 1]; + cmiot_char mid[CMIOT_MID_MAXLEN + 1]; + cmiot_char code[32]; + cmiot_char device_id[CMIOT_DEVICEID_MAX_LEN + 1]; + cmiot_char device_secret[CMIOT_DEVICESECRET_MAX_LEN + 1]; cmiot_uint32 index; cmiot_uint32 index_max; cmiot_uint32 delta_id; @@ -68,42 +68,42 @@ typedef enum typedef struct { - cmiot_uint8 result; + cmiot_uint8 result; cmiot_uint32 state; } CMIOT_ALIGN(1) cmiot_action_result_t; -void cmiot_hal_update_device(cmiot_char * mid, - cmiot_uint16 mid_len, - cmiot_char * device_id, - cmiot_uint16 device_id_len, - cmiot_char * device_secret, - cmiot_uint16 device_secret_len); -cmiot_int32 cmiot_hal_flash_read(cmiot_uint8 type, cmiot_uint32 addr, cmiot_char *buf, cmiot_uint32 size); -cmiot_int32 cmiot_hal_flash_write(cmiot_uint8 type, cmiot_uint32 addr, cmiot_char *buf, cmiot_uint32 size); -cmiot_int32 cmiot_hal_flash_erase(cmiot_uint8 type, cmiot_uint32 addr, cmiot_uint32 size); -cmiot_uint32 cmiot_hal_get_true_blocksize(cmiot_uint8 type); -cmiot_uint32 cmiot_hal_get_true_pagesize(cmiot_uint8 type); -cmiot_uint32 cmiot_hal_get_info_addr(void); -cmiot_uint32 cmiot_hal_get_backup_addr(void); -cmiot_uint32 cmiot_hal_get_app_addr(void); -cmiot_uint32 cmiot_hal_get_delta_addr(void); -cmiot_uint32 cmiot_hal_get_delta_size(void); -cmiot_uint32 cmiot_hal_get_download_size(void); -cmiot_bool cmiot_hal_write_delta(cmiot_uint16 index, cmiot_char *data, cmiot_uint16 len); -cmiot_bool cmiot_hal_erase_sector(cmiot_uint8 type, cmiot_uint32 addr); +void cmiot_hal_update_device(cmiot_char *mid, + cmiot_uint16 mid_len, + cmiot_char *device_id, + cmiot_uint16 device_id_len, + cmiot_char *device_secret, + cmiot_uint16 device_secret_len); +cmiot_int32 cmiot_hal_flash_read(cmiot_uint8 type, cmiot_uint32 addr, cmiot_char *buf, cmiot_uint32 size); +cmiot_int32 cmiot_hal_flash_write(cmiot_uint8 type, cmiot_uint32 addr, cmiot_char *buf, cmiot_uint32 size); +cmiot_int32 cmiot_hal_flash_erase(cmiot_uint8 type, cmiot_uint32 addr, cmiot_uint32 size); +cmiot_uint32 cmiot_hal_get_true_blocksize(cmiot_uint8 type); +cmiot_uint32 cmiot_hal_get_true_pagesize(cmiot_uint8 type); +cmiot_uint32 cmiot_hal_get_info_addr(void); +cmiot_uint32 cmiot_hal_get_backup_addr(void); +cmiot_uint32 cmiot_hal_get_app_addr(void); +cmiot_uint32 cmiot_hal_get_delta_addr(void); +cmiot_uint32 cmiot_hal_get_delta_size(void); +cmiot_uint32 cmiot_hal_get_download_size(void); +cmiot_bool cmiot_hal_write_delta(cmiot_uint16 index, cmiot_char *data, cmiot_uint16 len); +cmiot_bool cmiot_hal_erase_sector(cmiot_uint8 type, cmiot_uint32 addr); cmiot_update_t *cmiot_hal_init_update(void); cmiot_update_t *cmiot_hal_get_update(void); -cmiot_bool cmiot_hal_set_update(cmiot_update_t *cmiot_update); -cmiot_uint32 cmiot_hal_get_delta_id(void); -cmiot_char * cmiot_hal_get_device_id(void); -cmiot_char * cmiot_hal_get_device_secret(void); -cmiot_bool cmiot_hal_set_download_index(cmiot_uint32 index); -cmiot_uint32 cmiot_hal_get_download_index(void); -void cmiot_hal_reset_index_pos(void); +cmiot_bool cmiot_hal_set_update(cmiot_update_t *cmiot_update); +cmiot_uint32 cmiot_hal_get_delta_id(void); +cmiot_char *cmiot_hal_get_device_id(void); +cmiot_char *cmiot_hal_get_device_secret(void); +cmiot_bool cmiot_hal_set_download_index(cmiot_uint32 index); +cmiot_uint32 cmiot_hal_get_download_index(void); +void cmiot_hal_reset_index_pos(void); -cmiot_char * cmiot_hal_get_mid(void); +cmiot_char *cmiot_hal_get_mid(void); cmiot_uint16 cmiot_hal_get_update_result(void); -fal_part_t * cmiot_hal_get_device(cmiot_uint8 type); +fal_part_t *cmiot_hal_get_device(cmiot_uint8 type); #ifdef __cplusplus } diff --git a/components/ota/cmiot/inc/cmiot_hmd5.h b/components/ota/cmiot/inc/cmiot_hmd5.h index 24a33167..85423386 100644 --- a/components/ota/cmiot/inc/cmiot_hmd5.h +++ b/components/ota/cmiot/inc/cmiot_hmd5.h @@ -45,17 +45,17 @@ typedef struct { cmiot_md5_ctx_t ictx; cmiot_md5_ctx_t octx; - cmiot_char imd[MD5_DIGESTSIZE]; - cmiot_char omd[MD5_DIGESTSIZE]; - cmiot_char buf[MD5_BLOCKSIZE]; + cmiot_char imd[MD5_DIGESTSIZE]; + cmiot_char omd[MD5_DIGESTSIZE]; + cmiot_char buf[MD5_BLOCKSIZE]; } cmiot_hmd5_ctx_t; cmiot_char * - cmiot_get_signptr(cmiot_char *mid, cmiot_char *product_id, cmiot_char *product_secret, cmiot_uint32 utc_time); +cmiot_get_signptr(cmiot_char *mid, cmiot_char *product_id, cmiot_char *product_secret, cmiot_uint32 utc_time); cmiot_uint32 cmiot_md5_calc(void); cmiot_uint32 cmiot_get_md5_result(void); -void cmiot_set_md5_result(cmiot_uint32 result); -cmiot_int32 cmiot_md5_calc_internal(cmiot_uint32 buflen, cmiot_char *md5out); +void cmiot_set_md5_result(cmiot_uint32 result); +cmiot_int32 cmiot_md5_calc_internal(cmiot_uint32 buflen, cmiot_char *md5out); #ifdef __cplusplus } diff --git a/components/ota/cmiot/inc/cmiot_http.h b/components/ota/cmiot/inc/cmiot_http.h index e3abfdc4..3688e8e7 100644 --- a/components/ota/cmiot/inc/cmiot_http.h +++ b/components/ota/cmiot/inc/cmiot_http.h @@ -32,16 +32,16 @@ extern "C" { typedef struct { - cmiot_char type[32]; + cmiot_char type[32]; cmiot_uint16 content_len; - cmiot_char * content; + cmiot_char *content; } CMIOT_ALIGN(1) cmiot_http_parameter_t; -cmiot_char * cmiot_make_http_data(cmiot_uint8 state); -cmiot_bool cmiot_parse_http_data(cmiot_char *data, cmiot_http_parameter_t *http_parameter, cmiot_uint16 count); -cmiot_char * cmiot_is_http_data(cmiot_char *data, cmiot_uint16 len); +cmiot_char *cmiot_make_http_data(cmiot_uint8 state); +cmiot_bool cmiot_parse_http_data(cmiot_char *data, cmiot_http_parameter_t *http_parameter, cmiot_uint16 count); +cmiot_char *cmiot_is_http_data(cmiot_char *data, cmiot_uint16 len); cmiot_uint32 cmiot_http_callback(cmiot_uint8 state, cmiot_char *data); -cmiot_char * cmiot_get_http_server_host(void); +cmiot_char *cmiot_get_http_server_host(void); #ifdef __cplusplus } diff --git a/components/ota/cmiot/inc/cmiot_md5.h b/components/ota/cmiot/inc/cmiot_md5.h index 9104b054..e1c1f989 100644 --- a/components/ota/cmiot/inc/cmiot_md5.h +++ b/components/ota/cmiot/inc/cmiot_md5.h @@ -38,13 +38,13 @@ typedef struct { cmiot_uint32 count[2]; cmiot_uint32 state[4]; - cmiot_uint8 buffer[MD5_BLOCKSIZE]; + cmiot_uint8 buffer[MD5_BLOCKSIZE]; } cmiot_md5_ctx_t; typedef struct { - cmiot_uint8 content1; - cmiot_uint8 content2; + cmiot_uint8 content1; + cmiot_uint8 content2; cmiot_uint32 content3; } cmiot_md5_data_t; diff --git a/components/ota/cmiot/inc/cmiot_type.h b/components/ota/cmiot/inc/cmiot_type.h index 72e7f3a9..069c9631 100644 --- a/components/ota/cmiot/inc/cmiot_type.h +++ b/components/ota/cmiot/inc/cmiot_type.h @@ -74,22 +74,22 @@ typedef enum #define CMIOT_DEVICEID_MAX_LEN 31 #define CMIOT_DEVICESECRET_MAX_LEN 63 -typedef char cmiot_char; -typedef unsigned char cmiot_uint8; -typedef signed char cmiot_int8; +typedef char cmiot_char; +typedef unsigned char cmiot_uint8; +typedef signed char cmiot_int8; typedef unsigned short int cmiot_uint16; -typedef signed short int cmiot_int16; +typedef signed short int cmiot_int16; #ifdef CMIOT_8BIT -typedef unsigned long cmiot_uint32; -typedef signed long cmiot_int32; +typedef unsigned long cmiot_uint32; +typedef signed long cmiot_int32; typedef unsigned long long cmiot_uint64; -typedef signed long long cmiot_int64; +typedef signed long long cmiot_int64; #else -typedef unsigned int cmiot_uint32; -typedef signed int cmiot_int32; +typedef unsigned int cmiot_uint32; +typedef signed int cmiot_int32; typedef unsigned long long cmiot_uint64; -typedef signed long long cmiot_int64; +typedef signed long long cmiot_int64; #endif typedef enum diff --git a/components/ota/cmiot/inc/cmiot_user.h b/components/ota/cmiot/inc/cmiot_user.h index c2e7d5e8..20789ada 100644 --- a/components/ota/cmiot/inc/cmiot_user.h +++ b/components/ota/cmiot/inc/cmiot_user.h @@ -30,14 +30,14 @@ extern "C" { #endif -cmiot_char * cmiot_get_network_type(void); +cmiot_char *cmiot_get_network_type(void); cmiot_uint32 cmiot_get_try_time(void); -cmiot_uint8 cmiot_get_try_count(void); +cmiot_uint8 cmiot_get_try_count(void); cmiot_uint32 cmiot_get_utc_time(void); -void cmiot_get_uniqueid(cmiot_char *uid); -cmiot_char * cmiot_app_name(void); -cmiot_char * cmiot_download_name(void); -void cmiot_msleep(cmiot_uint32 time); +void cmiot_get_uniqueid(cmiot_char *uid); +cmiot_char *cmiot_app_name(void); +cmiot_char *cmiot_download_name(void); +void cmiot_msleep(cmiot_uint32 time); cmiot_int8 cmiot_upgrade(void); cmiot_int8 cmiot_report_upgrade(void); diff --git a/components/ota/cmiot/inc/cmiot_utils.h b/components/ota/cmiot/inc/cmiot_utils.h index 35c081cb..416268d4 100644 --- a/components/ota/cmiot/inc/cmiot_utils.h +++ b/components/ota/cmiot/inc/cmiot_utils.h @@ -31,11 +31,11 @@ extern "C" { #endif cmiot_char *cmiot_get_32bit_dec_tmp(cmiot_int32 number, cmiot_bool unsignedint); -void cmiot_byte2hexstr(const cmiot_uint8 *source, cmiot_char *dest, cmiot_uint32 source_len); -void cmiot_hexstr2byte(cmiot_char *dest, const cmiot_uint8 *source, cmiot_uint32 source_len); +void cmiot_byte2hexstr(const cmiot_uint8 *source, cmiot_char *dest, cmiot_uint32 source_len); +void cmiot_hexstr2byte(cmiot_char *dest, const cmiot_uint8 *source, cmiot_uint32 source_len); cmiot_int32 cmiot_hex2dec(cmiot_char *hex); cmiot_int32 cmiot_c2i(cmiot_char ch); -cmiot_bool cmiot_str_is_same_char(cmiot_char *str, cmiot_uint32 len, cmiot_char ch); +cmiot_bool cmiot_str_is_same_char(cmiot_char *str, cmiot_uint32 len, cmiot_char ch); #ifdef __cplusplus } diff --git a/components/ringbuf/include/option_parse.h b/components/ringbuf/include/option_parse.h index 1235f585..9d66e6ad 100644 --- a/components/ringbuf/include/option_parse.h +++ b/components/ringbuf/include/option_parse.h @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file option_parse.h @@ -26,22 +26,20 @@ #include -#define OPT_EOF (-1) -#define OPT_BADOPT (int)'?' -#define OPT_BADARG (int)':' +#define OPT_EOF (-1) +#define OPT_BADOPT (int)'?' +#define OPT_BADARG (int)':' struct opt_state { - os_int32_t opt_index; /* Index into parent argv vector */ - os_int32_t opt_char; /* Character checked for validity */ - char *opt_arg; /* Argument associated with option */ - char *opt_place; /* Additional persistent state */ + os_int32_t opt_index; /* Index into parent argv vector */ + os_int32_t opt_char; /* Character checked for validity */ + char *opt_arg; /* Argument associated with option */ + char *opt_place; /* Additional persistent state */ }; typedef struct opt_state opt_state_t; -extern void opt_init(opt_state_t *state, os_int32_t begin_index); -extern os_int32_t opt_get(os_int32_t argc, char * const argv[], const char *optstring, opt_state_t *state); - +extern void opt_init(opt_state_t *state, os_int32_t begin_index); +extern os_int32_t opt_get(os_int32_t argc, char *const argv[], const char *optstring, opt_state_t *state); #endif /* __OPTION_PARSE_H__ */ - diff --git a/components/ringbuf/include/ring_blk_buff.h b/components/ringbuf/include/ring_blk_buff.h index 55f9bd73..ba229c24 100644 --- a/components/ringbuf/include/ring_blk_buff.h +++ b/components/ringbuf/include/ring_blk_buff.h @@ -3,13 +3,13 @@ * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * Copyright (c) 2006-2018, RT-Thread Development Team. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file ring_blk_buff.h @@ -35,60 +35,56 @@ extern "C" { enum rbb_blk_status { - RBB_BLK_STATUS_UNUSED, /* Unused status when first initialize or after rbb_blk_free() */ - RBB_BLK_STATUS_INITED, /* Initialized status after rbb_blk_alloc() */ - RBB_BLK_STATUS_PUT, /* Put status after rbb_blk_put() */ - RBB_BLK_STATUS_GET, /* Get status after rbb_blk_get() */ + RBB_BLK_STATUS_UNUSED, /* Unused status when first initialize or after rbb_blk_free() */ + RBB_BLK_STATUS_INITED, /* Initialized status after rbb_blk_alloc() */ + RBB_BLK_STATUS_PUT, /* Put status after rbb_blk_put() */ + RBB_BLK_STATUS_GET, /* Get status after rbb_blk_get() */ }; typedef enum rbb_blk_status rbb_blk_status_t; /* The block of rbb */ struct rbb_blk { - os_list_node_t list_node; - - os_uint8_t *buf; - os_size_t buf_size; - - rbb_blk_status_t status; + os_list_node_t list_node; + + os_uint8_t *buf; + os_size_t buf_size; + + rbb_blk_status_t status; }; typedef struct rbb_blk rbb_blk_t; /* Ring block buffer ctrl info */ struct rbb_ctrl_info { - os_uint8_t *buf; - os_size_t buf_size; - - rbb_blk_t *blk_set; /* All of blocks */ - os_size_t blk_max_num; - - os_list_node_t blk_list_head; /* Saved the initialized and put status blocks */ - - os_spinlock_t rbb_locker; + os_uint8_t *buf; + os_size_t buf_size; + + rbb_blk_t *blk_set; /* All of blocks */ + os_size_t blk_max_num; + + os_list_node_t blk_list_head; /* Saved the initialized and put status blocks */ + + os_spinlock_t rbb_locker; }; typedef struct rbb_ctrl_info rbb_ctrl_info_t; -extern void rbb_init(rbb_ctrl_info_t *rbb, - os_uint8_t *buf, - os_size_t buf_size, - rbb_blk_t *block_set, - os_size_t blk_max_num); -extern os_size_t rbb_get_buf_size(rbb_ctrl_info_t *rbb); +extern void +rbb_init(rbb_ctrl_info_t *rbb, os_uint8_t *buf, os_size_t buf_size, rbb_blk_t *block_set, os_size_t blk_max_num); +extern os_size_t rbb_get_buf_size(rbb_ctrl_info_t *rbb); #ifdef OS_USING_SYS_HEAP extern rbb_ctrl_info_t *rbb_create(os_size_t buf_size, os_size_t blk_max_num); -extern void rbb_destroy(rbb_ctrl_info_t *rbb); +extern void rbb_destroy(rbb_ctrl_info_t *rbb); #endif /* rbb block API */ -extern rbb_blk_t *rbb_blk_alloc(rbb_ctrl_info_t *rbb, os_size_t blk_size); -extern void rbb_blk_put(rbb_blk_t *block); -extern rbb_blk_t *rbb_blk_get(rbb_ctrl_info_t *rbb); -extern void rbb_blk_free(rbb_ctrl_info_t *rbb, rbb_blk_t *block); +extern rbb_blk_t *rbb_blk_alloc(rbb_ctrl_info_t *rbb, os_size_t blk_size); +extern void rbb_blk_put(rbb_blk_t *block); +extern rbb_blk_t *rbb_blk_get(rbb_ctrl_info_t *rbb); +extern void rbb_blk_free(rbb_ctrl_info_t *rbb, rbb_blk_t *block); #ifdef __cplusplus } #endif #endif /* __RING_BLK_BUFF_H__ */ - diff --git a/components/ringbuf/include/ring_buff.h b/components/ringbuf/include/ring_buff.h index 2e1641f0..85f5521a 100644 --- a/components/ringbuf/include/ring_buff.h +++ b/components/ringbuf/include/ring_buff.h @@ -3,13 +3,13 @@ * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * Copyright (c) 2006-2018, RT-Thread Development Team. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file ring_buff.h @@ -37,43 +37,41 @@ extern "C" { *********************************************************************************************************************** * @struct rb_ring_buff * - * @brief Ring buffer control block + * @brief Ring buffer control block *********************************************************************************************************************** */ struct rb_ring_buff { - os_uint8_t *buff; /* The buffer */ - os_uint32_t buff_size; /* The buffer size */ + os_uint8_t *buff; /* The buffer */ + os_uint32_t buff_size; /* The buffer size */ - os_uint32_t read_index; /* Current read index */ - os_uint32_t write_index; /* Current write index */ - - os_bool_t read_mirror; /* Read mirror flag */ - os_bool_t write_mirror; /* Write mirror flag */ + os_uint32_t read_index; /* Current read index */ + os_uint32_t write_index; /* Current write index */ + + os_bool_t read_mirror; /* Read mirror flag */ + os_bool_t write_mirror; /* Write mirror flag */ }; typedef struct rb_ring_buff rb_ring_buff_t; - -extern void rb_ring_buff_init(rb_ring_buff_t *rb, os_uint8_t *pool, os_uint32_t pool_size); +extern void rb_ring_buff_init(rb_ring_buff_t *rb, os_uint8_t *pool, os_uint32_t pool_size); #ifdef OS_USING_SYS_HEAP extern rb_ring_buff_t *rb_ring_buff_create(os_uint32_t size); -extern void rb_ring_buff_destroy(rb_ring_buff_t *rb); +extern void rb_ring_buff_destroy(rb_ring_buff_t *rb); #endif -extern void rb_ring_buff_reset(rb_ring_buff_t *rb); -extern os_uint32_t rb_ring_buff_data_len(rb_ring_buff_t *rb); -extern os_uint32_t rb_ring_buff_space_len(rb_ring_buff_t *rb); -extern os_uint32_t rb_ring_buff_put(rb_ring_buff_t *rb, const os_uint8_t *buff, os_uint32_t buff_len); -extern os_uint32_t rb_ring_buff_put_force(rb_ring_buff_t *rb, const os_uint8_t *buff, os_uint32_t buff_len); -extern os_uint32_t rb_ring_buff_get(rb_ring_buff_t *rb, os_uint8_t *buff, os_uint32_t buff_len); -extern os_uint32_t rb_ring_buff_put_char(rb_ring_buff_t *rb, const os_uint8_t ch); -extern os_uint32_t rb_ring_buff_put_char_force(rb_ring_buff_t *rb, const os_uint8_t ch); -extern os_uint32_t rb_ring_buff_get_char(rb_ring_buff_t *rb, os_uint8_t *ch); +extern void rb_ring_buff_reset(rb_ring_buff_t *rb); +extern os_uint32_t rb_ring_buff_data_len(rb_ring_buff_t *rb); +extern os_uint32_t rb_ring_buff_space_len(rb_ring_buff_t *rb); +extern os_uint32_t rb_ring_buff_put(rb_ring_buff_t *rb, const os_uint8_t *buff, os_uint32_t buff_len); +extern os_uint32_t rb_ring_buff_put_force(rb_ring_buff_t *rb, const os_uint8_t *buff, os_uint32_t buff_len); +extern os_uint32_t rb_ring_buff_get(rb_ring_buff_t *rb, os_uint8_t *buff, os_uint32_t buff_len); +extern os_uint32_t rb_ring_buff_put_char(rb_ring_buff_t *rb, const os_uint8_t ch); +extern os_uint32_t rb_ring_buff_put_char_force(rb_ring_buff_t *rb, const os_uint8_t ch); +extern os_uint32_t rb_ring_buff_get_char(rb_ring_buff_t *rb, os_uint8_t *ch); #ifdef __cplusplus } #endif #endif /* __RING_BUFF_H__ */ - diff --git a/components/ringbuf/source/option_parse.c b/components/ringbuf/source/option_parse.c index eb350a49..af594d3a 100644 --- a/components/ringbuf/source/option_parse.c +++ b/components/ringbuf/source/option_parse.c @@ -2,20 +2,20 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file option_parse.c * * @brief This file implements command option parser. * - * @details This command option parser doesn't support "--" option. + * @details This command option parser doesn't support "--" option. * * @revision * Date Author Notes @@ -32,7 +32,7 @@ /** *********************************************************************************************************************** - * @brief Initialize command option parser. + * @brief Initialize command option parser. * * @attention . * @@ -47,8 +47,8 @@ void opt_init(opt_state_t *state, os_int32_t begin_index) OS_ASSERT(state); state->opt_index = begin_index; - state->opt_char = 0; - state->opt_arg = OS_NULL; + state->opt_char = 0; + state->opt_arg = OS_NULL; state->opt_place = OS_NULL; return; @@ -58,9 +58,9 @@ void opt_init(opt_state_t *state, os_int32_t begin_index) *********************************************************************************************************************** * @brief This function implements command option parser. * - * @details The function shall return the next option character (if one is found) from argv that matches a + * @details The function shall return the next option character (if one is found) from argv that matches a * character in optstring. If the option takes an argument, opt_get() shall set the variable - * state->opt_arg to point to the option-argument. + * state->opt_arg to point to the option-argument. * * @attention opt_init() must be called before using this function. * @@ -69,16 +69,16 @@ void opt_init(opt_state_t *state, os_int32_t begin_index) * @param[in] optstring Is a string of recognized option characters. * @param[in] state Option parser state. * - * @return Next option character (if one is found) from argv that matches a character in optstring. + * @return Next option character (if one is found) from argv that matches a character in optstring. * @retval OPT_EOF End options parsing. * @retval OPT_BADOPT Bad option. * @retval OPT_BADARG Bad argument. * @retval else The next option character. *********************************************************************************************************************** */ -os_int32_t opt_get(os_int32_t argc, char * const *argv, const char *optstring, opt_state_t *state) +os_int32_t opt_get(os_int32_t argc, char *const *argv, const char *optstring, opt_state_t *state) { - char *oli; /* Option letter list index */ + char *oli; /* Option letter list index */ if (state->opt_index >= argc) { @@ -93,7 +93,7 @@ os_int32_t opt_get(os_int32_t argc, char * const *argv, const char *optstring, o } if (state->opt_place[1]) - { + { if (state->opt_place[1] == '-') { /* Found "--" */ @@ -123,15 +123,15 @@ os_int32_t opt_get(os_int32_t argc, char * const *argv, const char *optstring, o if (*state->opt_place) { os_kprintf("Illegal option: %s\r\n", argv[state->opt_index]); - return OPT_BADOPT; + return OPT_BADOPT; } - + oli++; /* Don't need argument */ if (*oli != ':') { - state->opt_arg = OS_NULL; + state->opt_arg = OS_NULL; } /* Need an argument */ else @@ -144,11 +144,10 @@ os_int32_t opt_get(os_int32_t argc, char * const *argv, const char *optstring, o } state->opt_index++; - state->opt_arg = argv[state->opt_index]; + state->opt_arg = argv[state->opt_index]; } state->opt_index++; return state->opt_char; } - diff --git a/components/ringbuf/source/ring_blk_buff.c b/components/ringbuf/source/ring_blk_buff.c index 398da8d1..231ae9b3 100644 --- a/components/ringbuf/source/ring_blk_buff.c +++ b/components/ringbuf/source/ring_blk_buff.c @@ -3,13 +3,13 @@ * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * Copyright (c) 2006-2018, RT-Thread Development Team. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file ring_blk_buff.c @@ -38,8 +38,8 @@ static rbb_blk_t *rbb_find_empty_blk_in_set(rbb_ctrl_info_t *rbb) { - rbb_blk_t *unused_block; - os_size_t index; + rbb_blk_t *unused_block; + os_size_t index; unused_block = OS_NULL; for (index = 0; index < rbb->blk_max_num; index++) @@ -54,17 +54,14 @@ static rbb_blk_t *rbb_find_empty_blk_in_set(rbb_ctrl_info_t *rbb) return unused_block; } -static void rbb_do_init(rbb_ctrl_info_t *rbb, - os_uint8_t *buf, - os_size_t buf_size, - rbb_blk_t *block_set, - os_size_t blk_max_num) +static void +rbb_do_init(rbb_ctrl_info_t *rbb, os_uint8_t *buf, os_size_t buf_size, rbb_blk_t *block_set, os_size_t blk_max_num) { os_size_t index; - rbb->buf = buf; - rbb->buf_size = buf_size; - rbb->blk_set = block_set; + rbb->buf = buf; + rbb->buf_size = buf_size; + rbb->blk_set = block_set; rbb->blk_max_num = blk_max_num; os_list_init(&rbb->blk_list_head); @@ -79,11 +76,7 @@ static void rbb_do_init(rbb_ctrl_info_t *rbb, return; } -void rbb_init(rbb_ctrl_info_t *rbb, - os_uint8_t *buf, - os_size_t buf_size, - rbb_blk_t *block_set, - os_size_t blk_max_num) +void rbb_init(rbb_ctrl_info_t *rbb, os_uint8_t *buf, os_size_t buf_size, rbb_blk_t *block_set, os_size_t blk_max_num) { OS_ASSERT(OS_NULL != rbb); OS_ASSERT(OS_NULL != buf); @@ -100,11 +93,11 @@ void rbb_init(rbb_ctrl_info_t *rbb, rbb_ctrl_info_t *rbb_create(os_size_t buf_size, os_size_t blk_max_num) { rbb_ctrl_info_t *rbb; - os_uint8_t *buf; - rbb_blk_t *blk_set; + os_uint8_t *buf; + rbb_blk_t *blk_set; - rbb = (rbb_ctrl_info_t *)os_malloc(sizeof(rbb_ctrl_info_t)); - buf = (os_uint8_t *)os_malloc(buf_size); + rbb = (rbb_ctrl_info_t *)os_malloc(sizeof(rbb_ctrl_info_t)); + buf = (os_uint8_t *)os_malloc(buf_size); blk_set = (rbb_blk_t *)os_malloc(sizeof(rbb_blk_t) * blk_max_num); if ((OS_NULL == rbb) || (OS_NULL == buf) || (OS_NULL == blk_set)) @@ -157,8 +150,8 @@ os_size_t rbb_get_buf_size(rbb_ctrl_info_t *rbb) rbb_blk_t *rbb_blk_alloc(rbb_ctrl_info_t *rbb, os_size_t alloc_size) { os_ubase_t irq_save; - os_size_t empty1; - os_size_t empty2; + os_size_t empty1; + os_size_t empty2; rbb_blk_t *head; rbb_blk_t *tail; rbb_blk_t *new_blk; @@ -169,7 +162,7 @@ rbb_blk_t *rbb_blk_alloc(rbb_ctrl_info_t *rbb, os_size_t alloc_size) os_spin_lock_irqsave(&rbb->rbb_locker, &irq_save); new_blk = rbb_find_empty_blk_in_set(rbb); - + if (OS_NULL != new_blk) { if (!os_list_empty(&rbb->blk_list_head)) @@ -191,8 +184,8 @@ rbb_blk_t *rbb_blk_alloc(rbb_ctrl_info_t *rbb, os_size_t alloc_size) if (empty1 >= alloc_size) { - new_blk->status = RBB_BLK_STATUS_INITED; - new_blk->buf = tail->buf + tail->buf_size; + new_blk->status = RBB_BLK_STATUS_INITED; + new_blk->buf = tail->buf + tail->buf_size; new_blk->buf_size = alloc_size; os_list_add_tail(&rbb->blk_list_head, &new_blk->list_node); @@ -201,8 +194,8 @@ rbb_blk_t *rbb_blk_alloc(rbb_ctrl_info_t *rbb, os_size_t alloc_size) { if (empty2 >= alloc_size) { - new_blk->status = RBB_BLK_STATUS_INITED; - new_blk->buf = rbb->buf; + new_blk->status = RBB_BLK_STATUS_INITED; + new_blk->buf = rbb->buf; new_blk->buf_size = alloc_size; os_list_add_tail(&rbb->blk_list_head, &new_blk->list_node); @@ -224,11 +217,11 @@ rbb_blk_t *rbb_blk_alloc(rbb_ctrl_info_t *rbb, os_size_t alloc_size) * rbb->buf */ empty1 = head->buf - (tail->buf + tail->buf_size); - + if (empty1 >= alloc_size) { - new_blk->status = RBB_BLK_STATUS_INITED; - new_blk->buf = tail->buf + tail->buf_size; + new_blk->status = RBB_BLK_STATUS_INITED; + new_blk->buf = tail->buf + tail->buf_size; new_blk->buf_size = alloc_size; os_list_add_tail(&rbb->blk_list_head, &new_blk->list_node); @@ -244,8 +237,8 @@ rbb_blk_t *rbb_blk_alloc(rbb_ctrl_info_t *rbb, os_size_t alloc_size) { /* The list is empty */ os_list_add_tail(&rbb->blk_list_head, &new_blk->list_node); - new_blk->status = RBB_BLK_STATUS_INITED; - new_blk->buf = rbb->buf; + new_blk->status = RBB_BLK_STATUS_INITED; + new_blk->buf = rbb->buf; new_blk->buf_size = alloc_size; } } @@ -266,8 +259,8 @@ void rbb_blk_put(rbb_blk_t *block) rbb_blk_t *rbb_blk_get(rbb_ctrl_info_t *rbb) { - os_ubase_t irq_save; - rbb_blk_t *block; + os_ubase_t irq_save; + rbb_blk_t *block; OS_ASSERT(OS_NULL != rbb); @@ -313,4 +306,3 @@ void rbb_blk_free(rbb_ctrl_info_t *rbb, rbb_blk_t *block) return; } - diff --git a/components/ringbuf/source/ring_buff.c b/components/ringbuf/source/ring_buff.c index 2c2c031b..63b3a75e 100644 --- a/components/ringbuf/source/ring_buff.c +++ b/components/ringbuf/source/ring_buff.c @@ -3,13 +3,13 @@ * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * Copyright (c) 2006-2018, RT-Thread Development Team. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file ring_buff.c @@ -37,8 +37,8 @@ typedef enum { RB_RING_BUFF_EMPTY, RB_RING_BUFF_FULL, - RB_RING_BUFF_HALF_FULL, /* Half full is neither full nor empty */ -}rb_ring_buff_state_t; + RB_RING_BUFF_HALF_FULL, /* Half full is neither full nor empty */ +} rb_ring_buff_state_t; static rb_ring_buff_state_t rb_ring_buff_state(rb_ring_buff_t *rb) { @@ -53,7 +53,7 @@ static rb_ring_buff_state_t rb_ring_buff_state(rb_ring_buff_t *rb) return RB_RING_BUFF_FULL; } } - + return RB_RING_BUFF_HALF_FULL; } @@ -72,14 +72,14 @@ void rb_ring_buff_init(rb_ring_buff_t *rb, os_uint8_t *pool, os_uint32_t pool_si { OS_ASSERT(rb && pool && pool_size); - rb->read_index = 0; - rb->write_index = 0; - - rb->read_mirror = OS_FALSE; + rb->read_index = 0; + rb->write_index = 0; + + rb->read_mirror = OS_FALSE; rb->write_mirror = OS_FALSE; - - rb->buff = pool; - rb->buff_size = pool_size; + + rb->buff = pool; + rb->buff_size = pool_size; return; } @@ -97,13 +97,13 @@ void rb_ring_buff_reset(rb_ring_buff_t *rb) { OS_ASSERT(rb != OS_NULL); - rb->read_index = 0; - rb->write_index = 0; - - rb->read_mirror = OS_FALSE; + rb->read_index = 0; + rb->write_index = 0; + + rb->read_mirror = OS_FALSE; rb->write_mirror = OS_FALSE; - return; + return; } #ifdef OS_USING_SYS_HEAP @@ -121,13 +121,13 @@ void rb_ring_buff_reset(rb_ring_buff_t *rb) rb_ring_buff_t *rb_ring_buff_create(os_uint32_t size) { rb_ring_buff_t *rb; - os_uint8_t *pool; + os_uint8_t *pool; - OS_ASSERT(size > 0); + OS_ASSERT(size > 0); - rb = OS_NULL; + rb = OS_NULL; pool = OS_NULL; - + do { size = OS_ALIGN_DOWN(size, OS_ALIGN_SIZE); @@ -143,14 +143,14 @@ rb_ring_buff_t *rb_ring_buff_create(os_uint32_t size) { os_free(rb); rb = OS_NULL; - + break; } - + rb_ring_buff_init(rb, pool, size); - + } while (0); - + return rb; } @@ -186,12 +186,12 @@ void rb_ring_buff_destroy(rb_ring_buff_t *rb) os_uint32_t rb_ring_buff_data_len(rb_ring_buff_t *rb) { rb_ring_buff_state_t state; - os_uint32_t data_len; - + os_uint32_t data_len; + OS_ASSERT(rb != OS_NULL); data_len = 0; - + state = rb_ring_buff_state(rb); switch (state) { @@ -263,14 +263,14 @@ os_uint32_t rb_ring_buff_put(rb_ring_buff_t *rb, const os_uint8_t *buff, os_uint { return 0; } - + /* Drop some data */ if (size < buff_len) { buff_len = size; } - - if (rb->buff_size - rb->write_index > buff_len ) + + if (rb->buff_size - rb->write_index > buff_len) { memcpy(rb->buff + rb->write_index, buff, buff_len); rb->write_index += buff_len; @@ -278,9 +278,7 @@ os_uint32_t rb_ring_buff_put(rb_ring_buff_t *rb, const os_uint8_t *buff, os_uint } memcpy(rb->buff + rb->write_index, buff, rb->buff_size - rb->write_index); - memcpy(rb->buff, - buff + (rb->buff_size - rb->write_index), - buff_len - (rb->buff_size - rb->write_index)); + memcpy(rb->buff, buff + (rb->buff_size - rb->write_index), buff_len - (rb->buff_size - rb->write_index)); /* We are going into the other side of the mirror */ rb->write_mirror = !rb->write_mirror; @@ -320,7 +318,7 @@ os_uint32_t rb_ring_buff_put_force(rb_ring_buff_t *rb, const os_uint8_t *buff, o if (rb->buff_size - rb->write_index > buff_len) { - /* + /* * This should not cause overflow because there is enough space for * length of data in current mirror */ @@ -332,7 +330,7 @@ os_uint32_t rb_ring_buff_put_force(rb_ring_buff_t *rb, const os_uint8_t *buff, o { rb->read_index = rb->write_index; } - + return buff_len; } @@ -342,12 +340,12 @@ os_uint32_t rb_ring_buff_put_force(rb_ring_buff_t *rb, const os_uint8_t *buff, o /* We are going into the other side of the mirror */ rb->write_mirror = !rb->write_mirror; - rb->write_index = buff_len - (rb->buff_size - rb->write_index); + rb->write_index = buff_len - (rb->buff_size - rb->write_index); if (buff_len > space_len) { rb->read_mirror = !rb->read_mirror; - rb->read_index = rb->write_index; + rb->read_index = rb->write_index; } return buff_len; @@ -382,23 +380,21 @@ os_uint32_t rb_ring_buff_get(rb_ring_buff_t *rb, os_uint8_t *buff, os_uint32_t b /* Less data */ buff_len = size; } - + if (rb->buff_size - rb->read_index > buff_len) { - /* + /* * This should not cause overflow because there is enough space for * length of data in current mirror */ memcpy(buff, rb->buff + rb->read_index, buff_len); rb->read_index += buff_len; - + return buff_len; } memcpy(buff, rb->buff + rb->read_index, rb->buff_size - rb->read_index); - memcpy(buff + (rb->buff_size - rb->read_index), - rb->buff, - buff_len - (rb->buff_size - rb->read_index)); + memcpy(buff + (rb->buff_size - rb->read_index), rb->buff, buff_len - (rb->buff_size - rb->read_index)); /* We are going into the other side of the mirror */ rb->read_mirror = !rb->read_mirror; @@ -422,7 +418,7 @@ os_uint32_t rb_ring_buff_get(rb_ring_buff_t *rb, os_uint8_t *buff, os_uint32_t b os_uint32_t rb_ring_buff_put_char(rb_ring_buff_t *rb, const os_uint8_t ch) { os_uint32_t space_len; - + OS_ASSERT(rb != OS_NULL); /* Whether has enough space */ @@ -431,11 +427,11 @@ os_uint32_t rb_ring_buff_put_char(rb_ring_buff_t *rb, const os_uint8_t ch) { return 0; } - + rb->buff[rb->write_index] = ch; /* Flip mirror */ - if (rb->write_index == rb->buff_size-1) + if (rb->write_index == rb->buff_size - 1) { rb->write_mirror = !rb->write_mirror; rb->write_index = 0; @@ -471,11 +467,11 @@ os_uint32_t rb_ring_buff_put_char_force(rb_ring_buff_t *rb, const os_uint8_t ch) rb->buff[rb->write_index] = ch; /* Flip mirror */ - if (rb->write_index == rb->buff_size-1) + if (rb->write_index == rb->buff_size - 1) { rb->write_mirror = !rb->write_mirror; rb->write_index = 0; - + if (old_state == RB_RING_BUFF_FULL) { rb->read_mirror = !rb->read_mirror; @@ -485,7 +481,7 @@ os_uint32_t rb_ring_buff_put_char_force(rb_ring_buff_t *rb, const os_uint8_t ch) else { rb->write_index++; - + if (old_state == RB_RING_BUFF_FULL) { rb->read_index = rb->write_index; @@ -510,7 +506,7 @@ os_uint32_t rb_ring_buff_put_char_force(rb_ring_buff_t *rb, const os_uint8_t ch) os_uint32_t rb_ring_buff_get_char(rb_ring_buff_t *rb, os_uint8_t *ch) { os_uint32_t size; - + OS_ASSERT(rb && ch); /* Ring buffer is empty */ @@ -519,11 +515,11 @@ os_uint32_t rb_ring_buff_get_char(rb_ring_buff_t *rb, os_uint8_t *ch) { return 0; } - + /* Get character */ *ch = rb->buff[rb->read_index]; - if (rb->read_index == rb->buff_size-1) + if (rb->read_index == rb->buff_size - 1) { rb->read_mirror = !rb->read_mirror; rb->read_index = 0; @@ -535,4 +531,3 @@ os_uint32_t rb_ring_buff_get_char(rb_ring_buff_t *rb, os_uint8_t *ch) return 1; } - diff --git a/components/shell/include/shell.h b/components/shell/include/shell.h index 6066b09a..2c57abc6 100644 --- a/components/shell/include/shell.h +++ b/components/shell/include/shell.h @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file shell.h @@ -35,41 +35,33 @@ typedef os_err_t (*sh_cmd_func_t)(os_int32_t argc, char **argv); struct sh_cmd_entry { - const char* name; /* The name of system call */ + const char *name; /* The name of system call */ #if defined(SHELL_USING_DESCRIPTION) - const char* desc; /* Description of system call */ + const char *desc; /* Description of system call */ #endif - sh_cmd_func_t func; /* The function address of system call */ + sh_cmd_func_t func; /* The function address of system call */ }; typedef struct sh_cmd_entry sh_cmd_entry_t; #if (defined(__GNUC__) && defined(ARCH_X86_64)) - extern sh_cmd_entry_t *shell_cmd_entry_next(sh_cmd_entry_t *entry); - #define SH_NEXT_CMD_ENTRY(index) index=shell_cmd_entry_next(index) +extern sh_cmd_entry_t *shell_cmd_entry_next(sh_cmd_entry_t *entry); +#define SH_NEXT_CMD_ENTRY(index) index = shell_cmd_entry_next(index) #else - #define SH_NEXT_CMD_ENTRY(index) index++ +#define SH_NEXT_CMD_ENTRY(index) index++ #endif #ifdef SHELL_USING_DESCRIPTION -#define SH_FUNCTION_EXPORT_CMD(func, cmd, desc) \ - const char __fsym_##cmd##_name[] = #cmd; \ - const char __fsym_##cmd##_desc[] = desc; \ - OS_USED const sh_cmd_entry_t __fsym_##cmd OS_SECTION("FSymTab") = \ - { \ - __fsym_##cmd##_name, \ - __fsym_##cmd##_desc, \ - (sh_cmd_func_t)func \ - }; +#define SH_FUNCTION_EXPORT_CMD(func, cmd, desc) \ + const char __fsym_##cmd##_name[] = #cmd; \ + const char __fsym_##cmd##_desc[] = desc; \ + OS_USED const sh_cmd_entry_t __fsym_##cmd OS_SECTION( \ + "FSymTab") = {__fsym_##cmd##_name, __fsym_##cmd##_desc, (sh_cmd_func_t)func}; #else -#define SH_FUNCTION_EXPORT_CMD(func, cmd, desc) \ - const char __fsym_##cmd##_name[] = #cmd; \ - OS_USED const sh_cmd_entry_t __fsym_##cmd OS_SECTION("FSymTab")= \ - { \ - __fsym_##cmd##_name, \ - (sh_cmd_func_t)func \ - }; +#define SH_FUNCTION_EXPORT_CMD(func, cmd, desc) \ + const char __fsym_##cmd##_name[] = #cmd; \ + OS_USED const sh_cmd_entry_t __fsym_##cmd OS_SECTION("FSymTab") = {__fsym_##cmd##_name, (sh_cmd_func_t)func}; #endif /* SHELL_USING_DESCRIPTION */ /** @@ -83,10 +75,10 @@ typedef struct sh_cmd_entry sh_cmd_entry_t; * @param desc The description of command, which will show in help. *********************************************************************************************************************** */ -#define SH_CMD_EXPORT(cmd, func, desc) SH_FUNCTION_EXPORT_CMD(func, __cmd_##cmd, desc) +#define SH_CMD_EXPORT(cmd, func, desc) SH_FUNCTION_EXPORT_CMD(func, __cmd_##cmd, desc) -extern void sh_disconnect_console(void); -extern void sh_reconnect_console(void); +extern void sh_disconnect_console(void); +extern void sh_reconnect_console(void); extern os_err_t sh_exec(const char *cmd); #else @@ -94,4 +86,3 @@ extern os_err_t sh_exec(const char *cmd); #endif #endif /* __SHELL_H__ */ - diff --git a/components/shell/source/shell_buildin_cmd.c b/components/shell/source/shell_buildin_cmd.c index 16a09ab0..16b41eee 100644 --- a/components/shell/source/shell_buildin_cmd.c +++ b/components/shell/source/shell_buildin_cmd.c @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file shell_buildin_cmd.c @@ -42,7 +42,7 @@ static os_err_t sh_set_prompt(os_int32_t argc, char **argv) { os_kprintf("Wrong parameter, usage:\r\n"); os_kprintf("set_prompt \r\n"); - + ret = OS_EINVAL; } else @@ -100,4 +100,3 @@ static os_err_t sh_help(os_int32_t argc, char **argv) SH_CMD_EXPORT(help, sh_help, "Obtain help of commands"); #endif /* OS_USING_SHELL */ - diff --git a/components/shell/source/shell_internal.h b/components/shell/source/shell_internal.h index 33a7ef38..86abca0d 100644 --- a/components/shell/source/shell_internal.h +++ b/components/shell/source/shell_internal.h @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file shell_internal.h @@ -31,7 +31,7 @@ #include #include -#define SHELL_OPTION_ECHO 0x01 +#define SHELL_OPTION_ECHO 0x01 enum sh_input_stat { @@ -42,7 +42,6 @@ enum sh_input_stat typedef os_err_t (*cmd_function_t)(os_int32_t argc, char **argv); - /** *********************************************************************************************************************** * @struct shell_ctrl_info @@ -52,40 +51,38 @@ typedef os_err_t (*cmd_function_t)(os_int32_t argc, char **argv); */ struct shell_ctrl_info { - os_sem_t rx_sem; /* Semaphore use for receiving character */ + os_sem_t rx_sem; /* Semaphore use for receiving character */ - enum sh_input_stat stat; /* Receive character state */ + enum sh_input_stat stat; /* Receive character state */ - os_bool_t enable_echo; /* Whether enable echo */ - os_bool_t enable_prompt; /* Whether enable prompt */ + os_bool_t enable_echo; /* Whether enable echo */ + os_bool_t enable_prompt; /* Whether enable prompt */ #ifdef SHELL_USING_HISTORY - os_uint16_t current_history; /* Current history index */ - os_uint16_t history_count; /* The count for histories */ - char cmd_history[SHELL_HISTORY_LINES][SHELL_CMD_SIZE + 1]; /* History buffer */ + os_uint16_t current_history; /* Current history index */ + os_uint16_t history_count; /* The count for histories */ + char cmd_history[SHELL_HISTORY_LINES][SHELL_CMD_SIZE + 1]; /* History buffer */ #endif - char line[SHELL_CMD_SIZE + 1]; /* Command line buffer */ - os_uint8_t line_position; /* Current input character position */ - os_uint8_t line_curpos; /* Current cursor position. */ + char line[SHELL_CMD_SIZE + 1]; /* Command line buffer */ + os_uint8_t line_position; /* Current input character position */ + os_uint8_t line_curpos; /* Current cursor position. */ - os_device_t *device; /* Console device. */ - struct os_device_cb_info cb_info; - os_mutex_t dev_mutex; + os_device_t *device; /* Console device. */ + struct os_device_cb_info cb_info; + os_mutex_t dev_mutex; #ifdef SHELL_USING_AUTH - char password[SHELL_PASSWORD_MAX + 1]; /* Password string */ + char password[SHELL_PASSWORD_MAX + 1]; /* Password string */ #endif }; -typedef struct shell_ctrl_info shell_ctrl_info_t; +typedef struct shell_ctrl_info shell_ctrl_info_t; -extern void sh_init_cmd_table(const void *begin, const void *end); -extern void sh_get_cmd_table(sh_cmd_entry_t **table_begin, sh_cmd_entry_t **table_end); -extern void sh_auto_complete(char *prefix, os_size_t size); +extern void sh_init_cmd_table(const void *begin, const void *end); +extern void sh_get_cmd_table(sh_cmd_entry_t **table_begin, sh_cmd_entry_t **table_end); +extern void sh_auto_complete(char *prefix, os_size_t size); extern const char *sh_get_prompt(void); -extern os_err_t sh_do_set_prompt(const char *prompt); -extern os_err_t sh_do_exec(char *cmd, os_size_t length); - +extern os_err_t sh_do_set_prompt(const char *prompt); +extern os_err_t sh_do_exec(char *cmd, os_size_t length); #endif /* __SHELL_INTERNAL_H__ */ - diff --git a/components/shell/source/shell_main.c b/components/shell/source/shell_main.c index c668889b..a49807a2 100644 --- a/components/shell/source/shell_main.c +++ b/components/shell/source/shell_main.c @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file shell_main.c @@ -48,10 +48,10 @@ #endif static OS_TASK_STACK_DEFINE(shell_stack, SHELL_TASK_STACK_SIZE); -static os_task_t gs_shell_task = {0}; +static os_task_t gs_shell_task = {0}; -static shell_ctrl_info_t gs_shell = {0}; -static char *gs_shell_prompt_custom = OS_NULL; +static shell_ctrl_info_t gs_shell = {0}; +static char *gs_shell_prompt_custom = OS_NULL; #ifdef OS_USING_SYS_HEAP /** @@ -107,9 +107,9 @@ os_err_t sh_do_set_prompt(const char *prompt) */ const char *sh_get_prompt(void) { -#define _PROMPT "sh" +#define _PROMPT "sh" - os_int32_t resv_space; + os_int32_t resv_space; static char s_shell_prompt[SHELL_PROMPT_SIZE + 1]; /* check prompt mode */ @@ -120,7 +120,7 @@ const char *sh_get_prompt(void) else { #if defined(OS_USING_VFS) && defined(OS_USING_LIBC_ADAPTER) - resv_space = strlen(" ") + strlen(">") + 1; + resv_space = strlen(" ") + strlen(">") + 1; #else resv_space = strlen(">") + 1; #endif @@ -137,7 +137,7 @@ const char *sh_get_prompt(void) { (void)strncpy(s_shell_prompt, _PROMPT, sizeof(s_shell_prompt) - resv_space); } - + #if defined(OS_USING_VFS) && defined(OS_USING_LIBC_ADAPTER) (void)strcat(s_shell_prompt, " "); @@ -149,14 +149,15 @@ const char *sh_get_prompt(void) (void)strcat(s_shell_prompt, ">"); } - + return s_shell_prompt; } static os_err_t sh_rx_ind(os_device_t *dev, struct os_device_cb_info *info) { /* Release semaphore to let shell task rx data */ - (void)os_sem_post(&gs_shell.rx_sem);; + (void)os_sem_post(&gs_shell.rx_sem); + ; return OS_EOK; } @@ -164,9 +165,9 @@ static os_err_t sh_rx_ind(os_device_t *dev, struct os_device_cb_info *info) static os_err_t sh_do_connect_console(shell_ctrl_info_t *shell_info) { os_device_t *console; - os_err_t ret; + os_err_t ret; - ret = OS_EOK; + ret = OS_EOK; console = os_console_get_device(); if (OS_NULL == console) @@ -186,7 +187,7 @@ static os_err_t sh_do_connect_console(shell_ctrl_info_t *shell_info) /* Clear line buffer before switch to new device */ (void)memset(shell_info->line, 0, sizeof(shell_info->line)); - shell_info->line_curpos = 0; + shell_info->line_curpos = 0; shell_info->line_position = 0; shell_info->device = console; @@ -224,15 +225,15 @@ static void sh_connect_console(shell_ctrl_info_t *shell_info) static char sh_get_char(shell_ctrl_info_t *shell_info) { os_size_t size; - char ch; - os_err_t ret; + char ch; + os_err_t ret; while (1) { ret = OS_EOK; (void)os_mutex_lock(&shell_info->dev_mutex, OS_WAIT_FOREVER); - + if (OS_NULL != shell_info->device) { size = os_device_read_nonblock(shell_info->device, -1, &ch, 1U); @@ -245,7 +246,7 @@ static char sh_get_char(shell_ctrl_info_t *shell_info) { ret = OS_ENODEV; } - + (void)os_mutex_unlock(&shell_info->dev_mutex); if (OS_EOK != ret) @@ -257,8 +258,8 @@ static char sh_get_char(shell_ctrl_info_t *shell_info) break; } } - - return ch; + + return ch; } #ifdef SHELL_USING_HISTORY @@ -266,7 +267,7 @@ static void sh_print_history(const char *history) { os_kprintf("\033[2K\r"); os_kprintf("%s%s", sh_get_prompt(), history); - + return; } @@ -282,15 +283,13 @@ static void sh_push_history(shell_ctrl_info_t *shell_info) { /* Move history */ os_int32_t index; - + for (index = 0; index < SHELL_HISTORY_LINES - 1; index++) { - (void)strcpy(&shell_info->cmd_history[index][0], - &shell_info->cmd_history[index + 1][0]); + (void)strcpy(&shell_info->cmd_history[index][0], &shell_info->cmd_history[index + 1][0]); } - - (void)strcpy(&shell_info->cmd_history[SHELL_HISTORY_LINES - 1][0], - shell_info->line); + + (void)strcpy(&shell_info->cmd_history[SHELL_HISTORY_LINES - 1][0], shell_info->line); /* It's the maximum history */ shell_info->history_count = SHELL_HISTORY_LINES; @@ -299,17 +298,20 @@ static void sh_push_history(shell_ctrl_info_t *shell_info) else { /* If current cmd is same as last cmd, don't push */ - if ((0 == shell_info->history_count) - || strncmp(&shell_info->cmd_history[shell_info->history_count - 1][0], &shell_info->line[0], SHELL_CMD_SIZE + 1)) + if ((0 == shell_info->history_count) || strncmp(&shell_info->cmd_history[shell_info->history_count - 1][0], + &shell_info->line[0], + SHELL_CMD_SIZE + 1)) { - (void)strncpy(&shell_info->cmd_history[shell_info->history_count][0], shell_info->line, shell_info->line_position); + (void)strncpy(&shell_info->cmd_history[shell_info->history_count][0], + shell_info->line, + shell_info->line_position); /* increase count and set current history position */ shell_info->history_count++; } } } - + shell_info->current_history = shell_info->history_count; return; @@ -363,7 +365,7 @@ static void sh_copy_history_cmd(shell_ctrl_info_t *shell_info) static os_err_t sh_set_password(const char *password) { os_ubase_t irq_save; - os_size_t pw_len; + os_size_t pw_len; pw_len = strlen(password); @@ -372,7 +374,7 @@ static os_err_t sh_set_password(const char *password) os_kprintf("Invalid password length(%u) of shell\r\n", pw_len); return OS_EINVAL; } - + irq_save = os_irq_lock(); (void)strncpy(gs_shell.password, password, SHELL_PASSWORD_MAX); os_irq_unlock(irq_save); @@ -382,25 +384,25 @@ static os_err_t sh_set_password(const char *password) static void sh_wait_auth(shell_ctrl_info_t *shell_info) { - char ch; + char ch; os_bool_t input_shell; - char password[SHELL_PASSWORD_MAX]; + char password[SHELL_PASSWORD_MAX]; os_size_t cur_pos; (void)memset(password, 0, sizeof(password)); input_shell = OS_FALSE; - cur_pos = 0; + cur_pos = 0; /* Password not set */ if (!strlen(shell_info->password)) { return; } - + while (1) { os_kprintf("Password for login: "); - + while (!input_shell) { while (1) @@ -429,7 +431,7 @@ static void sh_wait_auth(shell_ctrl_info_t *shell_info) } } } - + if (!strncmp(shell_info->password, password, SHELL_PASSWORD_MAX)) { return; @@ -438,9 +440,9 @@ static void sh_wait_auth(shell_ctrl_info_t *shell_info) { /* Authentication failed, delay 2S for retry */ (void)os_task_msleep(2000); - + os_kprintf("Sorry, try again.\r\n"); - + cur_pos = 0; input_shell = OS_FALSE; (void)memset(password, 0, sizeof(password)); @@ -461,7 +463,7 @@ static void sh_auth(shell_ctrl_info_t *shell_info) os_kprintf("Shell password set failed.\r\n"); } } - + /* Waiting authenticate success */ sh_wait_auth(shell_info); @@ -470,7 +472,7 @@ static void sh_auth(shell_ctrl_info_t *shell_info) #endif /* SHELL_USING_AUTH */ static void sh_handle_left_key(shell_ctrl_info_t *shell_info) -{ +{ #ifdef SHELL_USING_HISTORY sh_copy_history_cmd(shell_info); #endif @@ -505,16 +507,16 @@ static void sh_handle_tab_key(shell_ctrl_info_t *shell_info) sh_auto_complete(&shell_info->line[0], sizeof(shell_info->line)); /* Re-calculate position */ - shell_info->line_curpos = strlen(shell_info->line); + shell_info->line_curpos = strlen(shell_info->line); shell_info->line_position = strlen(shell_info->line); - + return; } static void sh_handle_backspace_key(shell_ctrl_info_t *shell_info) { os_uint8_t pos; - + #ifdef SHELL_USING_HISTORY sh_copy_history_cmd(shell_info); #endif @@ -542,7 +544,7 @@ static void sh_handle_backspace_key(shell_ctrl_info_t *shell_info) shell_info->line[shell_info->line_position] = '\0'; } } - + return; } @@ -559,13 +561,13 @@ static void sh_handle_enter_key(shell_ctrl_info_t *shell_info) } (void)sh_do_exec(shell_info->line, shell_info->line_position); - + os_kprintf("%s", sh_get_prompt()); - + (void)memset(shell_info->line, 0, sizeof(shell_info->line)); - shell_info->line_curpos = 0U; + shell_info->line_curpos = 0U; shell_info->line_position = 0U; - + return; } @@ -573,9 +575,9 @@ static os_bool_t sh_handle_control_key(shell_ctrl_info_t *shell_info, char ch) { os_bool_t is_direction_key; os_bool_t is_char_handled; - + is_direction_key = OS_TRUE; - is_char_handled = OS_TRUE; + is_char_handled = OS_TRUE; /* * Direction key. @@ -604,13 +606,13 @@ static os_bool_t sh_handle_control_key(shell_ctrl_info_t *shell_info, char ch) { shell_info->stat = SHELL_WAIT_NORMAL; - if (ch == 0x41) /* Up key */ + if (ch == 0x41) /* Up key */ { #ifdef SHELL_USING_HISTORY sh_handle_up_key(shell_info); #endif } - else if (ch == 0x42) /* Down key */ + else if (ch == 0x42) /* Down key */ { #ifdef SHELL_USING_HISTORY sh_handle_down_key(shell_info); @@ -636,16 +638,16 @@ static os_bool_t sh_handle_control_key(shell_ctrl_info_t *shell_info, char ch) if (OS_FALSE == is_direction_key) { - if ((ch == '\0') || (ch == 0xFF)) /* Received null or error */ + if ((ch == '\0') || (ch == 0xFF)) /* Received null or error */ { /* Discard, do nothing. */ ; } - else if (ch == '\t') /* Handle tab key */ + else if (ch == '\t') /* Handle tab key */ { sh_handle_tab_key(shell_info); } - else if ((ch == 0x7f) || (ch == 0x08)) /* Handle backspace key */ + else if ((ch == 0x7f) || (ch == 0x08)) /* Handle backspace key */ { sh_handle_backspace_key(shell_info); } @@ -665,14 +667,14 @@ static os_bool_t sh_handle_control_key(shell_ctrl_info_t *shell_info, char ch) static void sh_handle_normal_character(shell_ctrl_info_t *shell_info, char ch) { os_uint8_t pos; - + #ifdef SHELL_USING_HISTORY sh_copy_history_cmd(shell_info); #endif if (shell_info->line_position < SHELL_CMD_SIZE) { - /* Normal character */ + /* Normal character */ if (shell_info->line_curpos < shell_info->line_position) { (void)memmove(&shell_info->line[shell_info->line_curpos + 1], @@ -680,12 +682,12 @@ static void sh_handle_normal_character(shell_ctrl_info_t *shell_info, char ch) shell_info->line_position - shell_info->line_curpos); shell_info->line[shell_info->line_curpos] = ch; - + if (shell_info->enable_echo) { os_kprintf("%s", &shell_info->line[shell_info->line_curpos]); } - + /* Move the cursor to new position */ for (pos = shell_info->line_curpos; pos < shell_info->line_position; pos++) { @@ -717,7 +719,7 @@ static void sh_task_entry(void *arg) { shell_ctrl_info_t *shell_info; os_bool_t is_char_handled; - char ch; + char ch; OS_ASSERT(OS_NULL != arg); @@ -744,31 +746,31 @@ static void sh_task_entry(void *arg) } } -#if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */ -#pragma section="FSymTab" +#if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */ +#pragma section = "FSymTab" #endif static os_err_t sh_system_init(void) { os_err_t ret; -#if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM C Compiler */ +#if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM C Compiler */ extern const int FSymTab$$Base; extern const int FSymTab$$Limit; sh_init_cmd_table(&FSymTab$$Base, &FSymTab$$Limit); - -#elif defined(__ICCARM__) || defined(__ICCRX__) /* for IAR Compiler */ + +#elif defined(__ICCARM__) || defined(__ICCRX__) /* for IAR Compiler */ sh_init_cmd_table(__section_begin("FSymTab"), __section_end("FSymTab")); - -#elif defined(__GNUC__) /* GNU GCC Compiler */ + +#elif defined(__GNUC__) /* GNU GCC Compiler */ extern const int __fsymtab_start; extern const int __fsymtab_end; sh_init_cmd_table(&__fsymtab_start, &__fsymtab_end); - + #else - #error "Not supported the tool chain." +#error "Not supported the tool chain." #endif - + ret = os_task_init(&gs_shell_task, SHELL_TASK_NAME, sh_task_entry, @@ -793,13 +795,13 @@ static os_err_t sh_system_init(void) OS_ASSERT_EX(0, "Init shdev mutex failed, ret(%d)", ret); } - gs_shell.device = OS_NULL; - gs_shell.cb_info.type = OS_DEVICE_CB_TYPE_RX; - gs_shell.cb_info.cb = sh_rx_ind; - gs_shell.cb_info.data = OS_NULL; - gs_shell.cb_info.size = 0; + gs_shell.device = OS_NULL; + gs_shell.cb_info.type = OS_DEVICE_CB_TYPE_RX; + gs_shell.cb_info.cb = sh_rx_ind; + gs_shell.cb_info.data = OS_NULL; + gs_shell.cb_info.size = 0; - gs_shell.stat = SHELL_WAIT_NORMAL; + gs_shell.stat = SHELL_WAIT_NORMAL; #ifndef SHELL_PROMPT_DISABLE gs_shell.enable_prompt = OS_TRUE; #else @@ -807,9 +809,9 @@ static os_err_t sh_system_init(void) #endif #ifndef SHELL_ECHO_DISABLE - gs_shell.enable_echo = OS_TRUE; + gs_shell.enable_echo = OS_TRUE; #else - gs_shell.enable_echo = OS_FALSE; + gs_shell.enable_echo = OS_FALSE; #endif ret = os_task_startup(&gs_shell_task); @@ -823,7 +825,7 @@ static os_err_t sh_system_init(void) OS_CMPOENT_INIT(sh_system_init, OS_INIT_SUBLEVEL_LOW); void sh_disconnect_console(void) -{ +{ os_err_t ret; (void)os_mutex_lock(&gs_shell.dev_mutex, OS_WAIT_FOREVER); @@ -835,10 +837,10 @@ void sh_disconnect_console(void) { OS_ASSERT_EX(0, "Why control console device(%s) failed?", device_name(gs_shell.device)); } - + gs_shell.device = OS_NULL; } - + (void)os_mutex_unlock(&gs_shell.dev_mutex); return; @@ -857,4 +859,3 @@ void sh_reconnect_console(void) return; } #endif /* OS_USING_SHELL */ - diff --git a/components/shell/source/shell_process.c b/components/shell/source/shell_process.c index 009490af..9fbe4a54 100644 --- a/components/shell/source/shell_process.c +++ b/components/shell/source/shell_process.c @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file shell_process.c @@ -40,14 +40,14 @@ static os_int32_t sh_split(char *cmd, os_size_t length, char *argv[SHELL_ARG_MAX]) { - char *ptr; - os_size_t position; - os_size_t argc; - os_size_t i; + char *ptr; + os_size_t position; + os_size_t argc; + os_size_t i; - ptr = cmd; + ptr = cmd; position = 0; - argc = 0; + argc = 0; while (position < length) { @@ -67,15 +67,15 @@ static os_int32_t sh_split(char *cmd, os_size_t length, char *argv[SHELL_ARG_MAX if (argc >= SHELL_ARG_MAX) { os_kprintf("Too many args ! We only Use:\r\n"); - for(i = 0; i < argc; i++) + for (i = 0; i < argc; i++) { os_kprintf("%s ", argv[i]); } os_kprintf("\r\n"); - + break; } - + /* Handle string */ if (*ptr == '"') { @@ -95,16 +95,16 @@ static os_int32_t sh_split(char *cmd, os_size_t length, char *argv[SHELL_ARG_MAX position++; } } - + ptr++; position++; } - + if (position >= length) { break; } - + /* Skip '"' */ *ptr = '\0'; ptr++; @@ -120,7 +120,7 @@ static os_int32_t sh_split(char *cmd, os_size_t length, char *argv[SHELL_ARG_MAX ptr++; position++; } - + if (position >= length) { break; @@ -136,8 +136,8 @@ static cmd_function_t sh_get_cmd_func(char *cmd, os_int32_t size) sh_cmd_entry_t *syscall_tmp; sh_cmd_entry_t *table_begin; sh_cmd_entry_t *table_end; - cmd_function_t cmd_func; - os_uint16_t cmd_prefix_len; + cmd_function_t cmd_func; + os_uint16_t cmd_prefix_len; cmd_func = OS_NULL; @@ -151,8 +151,8 @@ static cmd_function_t sh_get_cmd_func(char *cmd, os_int32_t size) continue; } - if (!strncmp(&syscall_tmp->name[cmd_prefix_len], cmd, size) - && (syscall_tmp->name[cmd_prefix_len + size] == '\0')) + if (!strncmp(&syscall_tmp->name[cmd_prefix_len], cmd, size) && + (syscall_tmp->name[cmd_prefix_len + size] == '\0')) { cmd_func = (cmd_function_t)syscall_tmp->func; break; @@ -164,16 +164,16 @@ static cmd_function_t sh_get_cmd_func(char *cmd, os_int32_t size) static os_err_t sh_do_exec_cmd(char *cmd, os_size_t length, os_err_t *retp) { - os_int32_t argc; - os_size_t cmd0_size; - cmd_function_t cmd_func; - char *argv[SHELL_ARG_MAX]; - os_err_t ret; + os_int32_t argc; + os_size_t cmd0_size; + cmd_function_t cmd_func; + char *argv[SHELL_ARG_MAX]; + os_err_t ret; OS_ASSERT(cmd); OS_ASSERT(retp); - ret = OS_EOK; + ret = OS_EOK; cmd0_size = 0U; /* Find the size of first command */ @@ -181,7 +181,7 @@ static os_err_t sh_do_exec_cmd(char *cmd, os_size_t length, os_err_t *retp) { cmd0_size++; } - + if (0U == cmd0_size) { os_kprintf("cmd 0 size \r\n"); @@ -191,18 +191,18 @@ static os_err_t sh_do_exec_cmd(char *cmd, os_size_t length, os_err_t *retp) { (void)memset(argv, 0, sizeof(argv)); cmd_func = sh_get_cmd_func(cmd, cmd0_size); - argc = sh_split(cmd, length, argv); + argc = sh_split(cmd, length, argv); if ((OS_NULL != cmd_func) && (0 != argc)) { - *retp = cmd_func(argc, argv); + *retp = cmd_func(argc, argv); } else { ret = OS_ERROR; } } - + return ret; } @@ -210,7 +210,7 @@ static os_err_t sh_do_exec_cmd(char *cmd, os_size_t length, os_err_t *retp) *********************************************************************************************************************** * @brief Execute command. * - * @param[in] cmd Command string, including command name and command arguments. + * @param[in] cmd Command string, including command name and command arguments. * @param[in] length Command string length. * * @return Execute command result. @@ -220,14 +220,14 @@ static os_err_t sh_do_exec_cmd(char *cmd, os_size_t length, os_err_t *retp) */ os_err_t sh_do_exec(char *cmd, os_size_t length) { - char *tcmd; - os_err_t cmd_ret; - os_err_t ret; + char *tcmd; + os_err_t cmd_ret; + os_err_t ret; ret = OS_EOK; /* Strim the beginning of command */ - while (((*cmd == ' ') || (*cmd == '\t')) && (length > 0)) + while (((*cmd == ' ') || (*cmd == '\t')) && (length > 0)) { cmd++; length--; @@ -241,7 +241,7 @@ os_err_t sh_do_exec(char *cmd, os_size_t length) ret = cmd_ret; } else - { + { /* Truncate the cmd at the first space. */ tcmd = cmd; while ((*tcmd != ' ') && (*tcmd != '\0')) @@ -249,23 +249,23 @@ os_err_t sh_do_exec(char *cmd, os_size_t length) tcmd++; } *tcmd = '\0'; - + os_kprintf("%s: command not found.\r\n", cmd); } } - + return ret; } os_err_t sh_exec(const char *cmd) { - char *cmd_str; + char *cmd_str; os_size_t cmd_length; - os_err_t ret; - + os_err_t ret; + OS_ASSERT(cmd != OS_NULL); - ret = OS_EOK; + ret = OS_EOK; cmd_length = strlen(cmd); /* 1 is used to reserve space for '\0' */ @@ -284,7 +284,7 @@ os_err_t sh_exec(const char *cmd) os_free(cmd_str); cmd_str = OS_NULL; } - + return ret; } @@ -305,14 +305,14 @@ static os_int32_t sh_string_same_part_length(const char *cmd_str1, const char *c #ifdef OS_USING_VFS static void sh_do_auto_complete_path(char *path, os_size_t size) { -#define FULL_PATH_LEN_MAX 256 +#define FULL_PATH_LEN_MAX 256 - DIR *dir = OS_NULL; + DIR *dir = OS_NULL; struct dirent *dirent = OS_NULL; - char *full_path; - char *ptr; - char *index; - char *end_addr = path + size; + char *full_path; + char *ptr; + char *index; + char *end_addr = path + size; OS_ASSERT(OS_NULL != path); @@ -329,7 +329,7 @@ static void sh_do_auto_complete_path(char *path, os_size_t size) if (*path != '/') { getcwd(full_path, FULL_PATH_LEN_MAX); - + if (full_path[strlen(full_path) - 1] != '/') { strcat(full_path, "/"); @@ -339,9 +339,9 @@ static void sh_do_auto_complete_path(char *path, os_size_t size) { *full_path = '\0'; } - + index = OS_NULL; - ptr = path; + ptr = path; for (;;) { @@ -349,12 +349,12 @@ static void sh_do_auto_complete_path(char *path, os_size_t size) { index = ptr + 1; } - + if (!(*ptr)) { break; } - + ptr++; } @@ -405,7 +405,7 @@ static void sh_do_auto_complete_path(char *path, os_size_t size) { break; } - + os_kprintf("%s\r\n", dirent->d_name); } } @@ -422,12 +422,12 @@ static void sh_do_auto_complete_path(char *path, os_size_t size) { break; } - + /* Matched the prefix string */ if (!strncmp(index, dirent->d_name, strlen(index))) { os_kprintf("%s\r\n", dirent->d_name); - + if (0 == min_length) { min_length = strlen(dirent->d_name); @@ -464,14 +464,14 @@ static void sh_do_auto_complete_path(char *path, os_size_t size) static os_bool_t sh_auto_complete_path(char *prefix, os_size_t size) { - char *ptr; - const char *end_addr; - os_bool_t is_complete_path; + char *ptr; + const char *end_addr; + os_bool_t is_complete_path; is_complete_path = OS_FALSE; end_addr = prefix + size; - ptr = prefix + strlen(prefix); + ptr = prefix + strlen(prefix); /* Check whether a space in the prefix */ while (ptr != prefix) @@ -497,26 +497,26 @@ static os_bool_t sh_auto_complete_path(char *prefix, os_size_t size) * * @param[in,out] prefix The prefix of path or command. * @param[in] size The size of buffer. - * + * * @return None. *********************************************************************************************************************** */ void sh_auto_complete(char *prefix, os_size_t size) { - os_int32_t length; - os_int32_t min_length; + os_int32_t length; + os_int32_t min_length; sh_cmd_entry_t *syscall_tmp; sh_cmd_entry_t *syscall_begin; sh_cmd_entry_t *syscall_end; - const char *name_ptr; - const char *cmd_name; - os_bool_t is_complete_path; - os_bool_t is_null_str; + const char *name_ptr; + const char *cmd_name; + os_bool_t is_complete_path; + os_bool_t is_null_str; os_kprintf("\r\n"); is_complete_path = OS_FALSE; - is_null_str = OS_FALSE; + is_null_str = OS_FALSE; if (*prefix == '\0') { @@ -531,11 +531,11 @@ void sh_auto_complete(char *prefix, os_size_t size) if ((OS_FALSE == is_null_str) && (OS_FALSE == is_complete_path)) { min_length = 0; - name_ptr = OS_NULL; + name_ptr = OS_NULL; /* Checks in internal command */ sh_get_cmd_table(&syscall_begin, &syscall_end); - + for (syscall_tmp = syscall_begin; syscall_tmp < syscall_end; SH_NEXT_CMD_ENTRY(syscall_tmp)) { /* Skip shell function */ @@ -543,7 +543,7 @@ void sh_auto_complete(char *prefix, os_size_t size) { continue; } - + cmd_name = &syscall_tmp->name[6]; if (!strncmp(prefix, cmd_name, strlen(prefix))) { @@ -551,7 +551,7 @@ void sh_auto_complete(char *prefix, os_size_t size) { /* Set name_ptr */ name_ptr = cmd_name; - + /* Set initial length */ min_length = strlen(name_ptr); @@ -565,7 +565,7 @@ void sh_auto_complete(char *prefix, os_size_t size) { min_length = length; } - + os_kprintf("%s\r\n", cmd_name); } } @@ -578,10 +578,9 @@ void sh_auto_complete(char *prefix, os_size_t size) strncpy(prefix, name_ptr, min_length); } } - + os_kprintf("%s%s", sh_get_prompt(), prefix); - + return; } #endif /* OS_USING_SHELL */ - diff --git a/components/shell/source/shell_symbol.c b/components/shell/source/shell_symbol.c index 8aa3d561..26c6f286 100644 --- a/components/shell/source/shell_symbol.c +++ b/components/shell/source/shell_symbol.c @@ -2,13 +2,13 @@ *********************************************************************************************************************** * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file shell_symbol.c @@ -31,7 +31,7 @@ #include "shell_internal.h" static sh_cmd_entry_t *gs_cmd_table_begin = OS_NULL; -static sh_cmd_entry_t *gs_cmd_table_end = OS_NULL; +static sh_cmd_entry_t *gs_cmd_table_end = OS_NULL; /** *********************************************************************************************************************** @@ -46,7 +46,7 @@ static sh_cmd_entry_t *gs_cmd_table_end = OS_NULL; void sh_init_cmd_table(const void *begin, const void *end) { gs_cmd_table_begin = (sh_cmd_entry_t *)begin; - gs_cmd_table_end = (sh_cmd_entry_t *)end; + gs_cmd_table_end = (sh_cmd_entry_t *)end; } /** @@ -62,7 +62,7 @@ void sh_init_cmd_table(const void *begin, const void *end) void sh_get_cmd_table(sh_cmd_entry_t **table_begin, sh_cmd_entry_t **table_end) { *table_begin = gs_cmd_table_begin; - *table_end = gs_cmd_table_end; + *table_end = gs_cmd_table_end; return; } @@ -71,16 +71,15 @@ void sh_get_cmd_table(sh_cmd_entry_t **table_begin, sh_cmd_entry_t **table_end) sh_cmd_entry_t *shell_cmd_entry_next(sh_cmd_entry_t *entry) { unsigned int *ptr; - ptr = (unsigned int*) (entry + 1); + ptr = (unsigned int *)(entry + 1); - while ((*ptr == 0) && ((unsigned int*)ptr < (unsigned int*) gs_cmd_table_end)) + while ((*ptr == 0) && ((unsigned int *)ptr < (unsigned int *)gs_cmd_table_end)) { ptr++; } - return (sh_cmd_entry_t*)ptr; + return (sh_cmd_entry_t *)ptr; } #endif #endif /* OS_USING_SHELL */ - diff --git a/components/socket/include/sys_socket/netdb.h b/components/socket/include/sys_socket/netdb.h index 4ac38ee0..cee1f405 100644 --- a/components/socket/include/sys_socket/netdb.h +++ b/components/socket/include/sys_socket/netdb.h @@ -20,9 +20,9 @@ * 2020-06-16 OneOS Team First Version *********************************************************************************************************************** */ - #ifndef __NETDB_H__ - #define __NETDB_H__ - +#ifndef __NETDB_H__ +#define __NETDB_H__ + #include #endif diff --git a/components/socket/include/sys_socket/sys/socket.h b/components/socket/include/sys_socket/sys/socket.h index 11fe90b3..124d88b8 100644 --- a/components/socket/include/sys_socket/sys/socket.h +++ b/components/socket/include/sys_socket/sys/socket.h @@ -58,14 +58,14 @@ int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, st #endif struct hostent *gethostbyname(const char *name); -int getaddrinfo(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res); +int getaddrinfo(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res); void freeaddrinfo(struct addrinfo *ai); -int getpeername(int fd, struct sockaddr *name, socklen_t *namelen); -int getsockname(int fd, struct sockaddr *name, socklen_t *namelen); +int getpeername(int fd, struct sockaddr *name, socklen_t *namelen); +int getsockname(int fd, struct sockaddr *name, socklen_t *namelen); #ifdef NET_USING_LWIP212 const char *inet_ntop(int af, const void *src, char *dst, int32_t size); -int inet_pton(int af, const char *src, void *dst); +int inet_pton(int af, const char *src, void *dst); #endif /* end of NET_USING_LWIP212 */ #endif /* end of __SOCKET_H__ */ diff --git a/components/socket/source/socket.c b/components/socket/source/socket.c index 2ddf22c0..bde17a1a 100644 --- a/components/socket/source/socket.c +++ b/components/socket/source/socket.c @@ -81,7 +81,7 @@ static const struct dev_file_ops gs_sockfs_fops = { return OS_ERROR; \ } \ struct socket_private *sock_private = FILE->private; \ - SOCKET = sock_private->socket_id; + SOCKET = sock_private->socket_id; #define GET_SOCKETID_SHUTDOWN_FROM_FILE(SOCKET, SHUTDOWN, FILE) \ if (FILE->private == NULL) \ @@ -89,8 +89,8 @@ static const struct dev_file_ops gs_sockfs_fops = { return OS_ERROR; \ } \ struct socket_private *sock_private = FILE->private; \ - SOCKET = sock_private->socket_id; \ - SHUTDOWN = sock_private->shutdown_how; + SOCKET = sock_private->socket_id; \ + SHUTDOWN = sock_private->shutdown_how; #define SET_SOCKETID_TO_FILE(SOCKET, FILE) \ if (FILE->private == NULL) \ @@ -98,7 +98,7 @@ static const struct dev_file_ops gs_sockfs_fops = { return OS_ERROR; \ } \ struct socket_private *sock_private = FILE->private; \ - sock_private->socket_id = SOCKET; + sock_private->socket_id = SOCKET; #define SET_SHUTDOWN_TO_FILE(SHUTDOWN, FILE) \ if (FILE->private == NULL) \ @@ -106,7 +106,7 @@ static const struct dev_file_ops gs_sockfs_fops = { return OS_ERROR; \ } \ struct socket_private *sock_private = FILE->private; \ - sock_private->shutdown_how = SHUTDOWN; + sock_private->shutdown_how = SHUTDOWN; #define GET_SOCKETID_FROM_FD(SOCKET, FD) \ struct vfs_file *file = fd_to_fp(FD); \ @@ -274,7 +274,7 @@ int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, st { memcpy(&exceptset_bak, exceptset, sizeof(fd_set)); } - int fd = 0; + int fd = 0; int socket = 0; // tansfor to socket id for (fd = 0; fd < maxfdp1; fd++) @@ -624,8 +624,8 @@ static int sockfs_adapter_close(struct vfs_file *file) OS_ASSERT(file != OS_NULL); OS_ASSERT(file->type == FT_DEVICE); - int ret = OS_ERROR; - int socket = -1; + int ret = OS_ERROR; + int socket = -1; int shutdown_how = 0; GET_SOCKETID_SHUTDOWN_FROM_FILE(socket, shutdown_how, file) if (shutdown_how) @@ -739,7 +739,7 @@ int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, st { memcpy(&exceptset_bak, exceptset, sizeof(fd_set)); } - int fd = 0; + int fd = 0; int socket = 0; // tansfor to socket id for (fd = 0; fd < maxfdp1; fd++) -- Gitee