Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
不穿格子衫的农民
TencentOS Tiny
提交
eb56d42f
T
TencentOS Tiny
项目概览
不穿格子衫的农民
/
TencentOS Tiny
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TencentOS Tiny
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
eb56d42f
编写于
10月 01, 2020
作者:
M
mculover666
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
improve air724 driver
上级
c3a78de9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
189 addition
and
40 deletion
+189
-40
devices/air724/air724.c
devices/air724/air724.c
+184
-40
devices/air724/air724.h
devices/air724/air724.h
+5
-0
未找到文件。
devices/air724/air724.c
浏览文件 @
eb56d42f
...
...
@@ -7,27 +7,75 @@
#include <stdbool.h>
#include <ctype.h>
typedef
struct
ip_addr_st
{
uint8_t
seg1
;
uint8_t
seg2
;
uint8_t
seg3
;
uint8_t
seg4
;
}
ip_addr_t
;
static
ip_addr_t
domain_parser_addr
=
{
0
};
static
k_sem_t
domain_parser_sem
;
static
int
air724_power_on
(
void
)
{
#if AIR724_USE_PWRKEY_GPIO
HAL_GPIO_WritePin
(
AIR724_PWR_GPIO_PORT
,
AIR724_PWR_GPIO_PIN
,
GPIO_PIN_RESET
);
tos_sleep_ms
(
1000
);
HAL_GPIO_WritePin
(
AIR724_PWR_GPIO_PORT
,
AIR724_PWR_GPIO_PIN
,
GPIO_PIN_SET
);
#else
tos_sleep_ms
(
1000
);
#endif
return
0
;
}
static
int
air724_check_ready
(
void
)
{
at_echo_t
echo
;
int
try
=
0
;
tos_at_echo_create
(
&
echo
,
NULL
,
0
,
NULL
);
while
(
try
++
<
10
)
{
tos_at_cmd_exec
(
&
echo
,
1000
,
"AT
\r\n
"
);
if
(
echo
.
status
==
AT_ECHO_STATUS_OK
)
{
return
0
;
}
}
return
-
1
;
}
static
int
air724_echo_close
(
void
)
{
at_echo_t
echo
;
int
try
=
0
;
tos_at_echo_create
(
&
echo
,
NULL
,
0
,
NULL
);
tos_at_cmd_exec
(
&
echo
,
300
,
"ATE0
\r\n
"
);
if
(
echo
.
status
==
AT_ECHO_STATUS_OK
)
{
return
0
;
while
(
try
++
<
10
)
{
tos_at_cmd_exec
(
&
echo
,
300
,
"ATE0
\r\n
"
);
if
(
echo
.
status
==
AT_ECHO_STATUS_OK
)
{
return
0
;
}
}
return
-
1
;
}
static
int
air724_cscon_close
(
void
)
{
at_echo_t
echo
;
int
try
=
0
;
tos_at_echo_create
(
&
echo
,
NULL
,
0
,
NULL
);
tos_at_cmd_exec
(
&
echo
,
300
,
"AT+CSCON=0
\r\n
"
);
if
(
echo
.
status
==
AT_ECHO_STATUS_OK
)
{
return
0
;
while
(
try
++
<
10
)
{
tos_at_cmd_exec
(
&
echo
,
300
,
"AT+CSCON=0
\r\n
"
);
if
(
echo
.
status
==
AT_ECHO_STATUS_OK
)
{
return
0
;
}
tos_sleep_ms
(
1000
);
}
return
-
1
;
}
...
...
@@ -49,6 +97,8 @@ static int air724_sim_card_check(void)
{
return
0
;
}
tos_sleep_ms
(
1000
);
}
return
-
1
;
...
...
@@ -79,6 +129,8 @@ static int air724_signal_quality_check(void)
if
(
rssi
!=
99
)
{
return
0
;
}
tos_sleep_ms
(
2000
);
}
return
-
1
;
...
...
@@ -109,6 +161,8 @@ static int air724_gsm_network_check(void)
{
return
0
;
}
tos_sleep_ms
(
1000
);
}
return
-
1
;
}
...
...
@@ -139,6 +193,8 @@ static int air724_gprs_network_check(void)
{
return
0
;
}
tos_sleep_ms
(
1000
);
}
return
-
1
;
...
...
@@ -156,6 +212,8 @@ static int air724_close_apn(void)
{
return
-
1
;
}
tos_sleep_ms
(
2000
);
return
0
;
}
...
...
@@ -209,13 +267,14 @@ static int air724_set_apn(void)
return
-
1
;
}
tos_at_cmd_exec
(
&
echo
,
3
000
,
"AT+CIICR
\r\n
"
);
tos_at_echo_create
(
&
echo
,
NULL
,
0
,
NULL
);
tos_at_cmd_exec
(
&
echo
,
50
000
,
"AT+CIICR
\r\n
"
);
if
(
echo
.
status
!=
AT_ECHO_STATUS_OK
)
{
return
-
1
;
}
tos_at_echo_create
(
&
echo
,
NULL
,
0
,
NULL
);
tos_at_cmd_exec
(
&
echo
,
300
,
"AT+CIFSR
\r\n
"
);
return
0
;
...
...
@@ -226,6 +285,15 @@ static int air724_set_apn(void)
static
int
air724_init
(
void
)
{
printf
(
"Init air724 ...
\n
"
);
air724_power_on
();
tos_sleep_ms
(
2000
);
printf
(
"module power on
\n
"
);
if
(
air724_check_ready
()
!=
0
)
{
printf
(
"wait module ready timeout, please check your module
\n
"
);
return
-
1
;
}
if
(
air724_echo_close
()
!=
0
)
{
...
...
@@ -322,10 +390,12 @@ static int air724_connect(const char *ip, const char *port, sal_proto_t proto)
return
id
;
}
#else
tos_at_echo_create
(
&
echo
,
NULL
,
0
,
"CONNECT OK"
);
tos_at_cmd_exec
(
&
echo
,
4000
,
"AT+CIPSTART=%d,%s,%s,%d
\r\n
"
,
char
result
[
20
];
sprintf
(
result
,
"%d, CONNECT OK"
,
id
);
tos_at_echo_create
(
&
echo
,
NULL
,
0
,
result
);
tos_at_cmd_exec_until
(
&
echo
,
8000
,
"AT+CIPSTART=%d,%s,%s,%d
\r\n
"
,
id
,
proto
==
TOS_SAL_PROTO_UDP
?
"UDP"
:
"TCP"
,
ip
,
atoi
(
port
));
if
(
echo
.
status
==
AT_ECHO_STATUS_
OK
)
{
if
(
echo
.
status
==
AT_ECHO_STATUS_
EXPECT
)
{
return
id
;
}
#endif
...
...
@@ -458,41 +528,23 @@ static int air724_close(int id)
static
int
air724_parse_domain
(
const
char
*
host_name
,
char
*
host_ip
,
size_t
host_ip_len
)
{
char
*
str
;
at_echo_t
echo
;
char
echo_buffer
[
128
];
tos_at_echo_create
(
&
echo
,
echo_buffer
,
sizeof
(
echo_buffer
),
"+CDNSGIP:"
);
tos_at_cmd_exec
(
&
echo
,
8000
,
"AT+CDNSGIP=
\"
%s
\"\r\n
"
,
host_name
);
tos_sem_create_max
(
&
domain_parser_sem
,
0
,
1
);
if
(
echo
.
status
!=
AT_ECHO_STATUS_OK
&&
echo
.
status
!=
AT_ECHO_STATUS_EXPECT
)
{
return
-
1
;
}
tos_at_echo_create
(
&
echo
,
NULL
,
0
,
NULL
);
tos_at_cmd_exec
(
&
echo
,
1000
,
"AT+CDNSGIP=
\"
%s
\"\r\n
"
,
host_name
);
/*
+CDNSGIP: 1,"domain","xxx.xxx.xxx.xxx"
*/
str
=
strstr
(
echo
.
buffer
,
":"
);
if
(
!
str
)
{
return
-
1
;
}
str
+=
1
;
if
(
*
str
==
'0'
)
if
(
echo
.
status
!=
AT_ECHO_STATUS_OK
)
{
/* parse fail */
return
-
1
;
}
str
+=
strlen
(
host_name
)
+
7
;
tos_sem_pend
(
&
domain_parser_sem
,
TOS_TIME_FOREVER
)
;
int
seg1
,
seg2
,
seg3
,
seg4
;
sscanf
(
str
,
"%d.%d.%d.%d"
,
&
seg1
,
&
seg2
,
&
seg3
,
&
seg4
);
snprintf
(
host_ip
,
host_ip_len
,
"%d.%d.%d.%d"
,
seg1
,
seg2
,
seg3
,
seg4
);
snprintf
(
host_ip
,
host_ip_len
,
"%d.%d.%d.%d"
,
domain_parser_addr
.
seg1
,
domain_parser_addr
.
seg2
,
domain_parser_addr
.
seg3
,
domain_parser_addr
.
seg4
);
host_ip
[
host_ip_len
-
1
]
=
'\0'
;
printf
(
"GOT IP: %s
\n
"
,
host_ip
);
return
0
;
...
...
@@ -574,8 +626,100 @@ __STATIC__ void air724_incoming_data_process(void)
return
;
}
__STATIC__
void
air724_domain_data_process
(
void
)
{
uint8_t
data
;
int
retcode
=
0
;
/*
+CDNSGIP: 1,"domain","xxx.xxx.xxx.xxx"
*/
if
(
tos_at_uart_read
(
&
data
,
1
)
!=
1
)
{
return
;
}
while
(
1
)
{
if
(
tos_at_uart_read
(
&
data
,
1
)
!=
1
)
{
return
;
}
if
(
data
==
','
)
{
break
;
}
retcode
=
retcode
*
10
+
(
data
-
'0'
);
}
if
(
retcode
!=
1
)
{
return
;
}
while
(
1
)
{
if
(
tos_at_uart_read
(
&
data
,
1
)
!=
1
)
{
return
;
}
if
(
data
==
','
)
{
break
;
}
}
if
(
tos_at_uart_read
(
&
data
,
1
)
!=
1
)
{
return
;
}
/* start parser domain */
while
(
1
)
{
if
(
tos_at_uart_read
(
&
data
,
1
)
!=
1
)
{
return
;
}
if
(
data
==
'.'
)
{
break
;
}
domain_parser_addr
.
seg1
=
domain_parser_addr
.
seg1
*
10
+
(
data
-
'0'
);
}
while
(
1
)
{
if
(
tos_at_uart_read
(
&
data
,
1
)
!=
1
)
{
return
;
}
if
(
data
==
'.'
)
{
break
;
}
domain_parser_addr
.
seg2
=
domain_parser_addr
.
seg2
*
10
+
(
data
-
'0'
);
}
while
(
1
)
{
if
(
tos_at_uart_read
(
&
data
,
1
)
!=
1
)
{
return
;
}
if
(
data
==
'.'
)
{
break
;
}
domain_parser_addr
.
seg3
=
domain_parser_addr
.
seg3
*
10
+
(
data
-
'0'
);
}
while
(
1
)
{
if
(
tos_at_uart_read
(
&
data
,
1
)
!=
1
)
{
return
;
}
if
(
data
==
'\"'
)
{
break
;
}
domain_parser_addr
.
seg4
=
domain_parser_addr
.
seg4
*
10
+
(
data
-
'0'
);
}
tos_sem_post
(
&
domain_parser_sem
);
return
;
}
at_event_t
air724_at_event
[]
=
{
{
"+RECEIVE,"
,
air724_incoming_data_process
},
{
"+CDNSGIP:"
,
air724_domain_data_process
},
};
sal_module_t
sal_module_air724
=
{
...
...
devices/air724/air724.h
浏览文件 @
eb56d42f
...
...
@@ -30,6 +30,11 @@ typedef enum air724_multilink_state {
AIR724_MULTILINK_STATE_DISABLE
,
}
air724_multilink_state_t
;
/* PWRKEY GPIO */
#define AIR724_USE_PWRKEY_GPIO 0
#define AIR724_PWR_GPIO_PORT GPIOB
#define AIR724_PWR_GPIO_PIN GPIO_PIN_5
int
air724_sal_init
(
hal_uart_port_t
uart_port
);
#endif
/* __AIR724_H__ */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录