Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CharlesGuo11
Heart-Rate Esp32s3-Box_AED
提交
fbf7df5f
H
Heart-Rate Esp32s3-Box_AED
项目概览
CharlesGuo11
/
Heart-Rate Esp32s3-Box_AED
通知
6
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
代码片段
项目成员
Pages
H
Heart-Rate Esp32s3-Box_AED
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
fbf7df5f
编写于
7月 16, 2022
作者:
honorifica
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
删掉了与AED无关的代码
上级
3e4b66d3
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
33 addition
and
206 deletion
+33
-206
.cproject
.cproject
+1
-0
.project
.project
+1
-1
main/app/app_player.c
main/app/app_player.c
+1
-0
main/app/app_sr.c
main/app/app_sr.c
+0
-3
main/app/app_sr.h
main/app/app_sr.h
+0
-2
main/app/app_sr_handler.c
main/app/app_sr_handler.c
+0
-87
main/main.c
main/main.c
+30
-113
未找到文件。
.cproject
浏览文件 @
fbf7df5f
...
...
@@ -13,4 +13,5 @@
<pathentry
excluding=
"**/CMakeFiles/**"
kind=
"out"
path=
"build"
/>
</storageModule>
<storageModule
moduleId=
"org.eclipse.cdt.core.LanguageSettingsProviders"
/>
<storageModule
moduleId=
"org.eclipse.cdt.make.core.buildtargets"
/>
</cproject>
\ No newline at end of file
.project
浏览文件 @
fbf7df5f
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>
factory_demo
</name>
<name>
heart-rate-esp32s3-box-aed
</name>
<comment></comment>
<projects>
</projects>
...
...
main/app/app_player.c
浏览文件 @
fbf7df5f
...
...
@@ -157,6 +157,7 @@ static esp_err_t play_mp3(const char *path)
/* Get MP3 frame info and configure I2S clock */
MP3GetLastFrameInfo
(
mp3_decoder
,
&
frame_info
);
/* Configure I2S clock if sample rate changed. Always reconfigure at first frame */
if
(
sample_rate
!=
frame_info
.
samprate
||
nChans
!=
frame_info
.
nChans
||
...
...
main/app/app_sr.c
浏览文件 @
fbf7df5f
...
...
@@ -74,9 +74,6 @@ static const sr_cmd_t g_default_cmd_info[] = {
{
SR_CMD_PLAY
,
SR_LANG_EN
,
0
,
"Play Music"
,
"PLd MYoZgK"
,
{
NULL
}},
{
SR_CMD_NEXT
,
SR_LANG_EN
,
0
,
"Next Song"
,
"NfKST Sel"
,
{
NULL
}},
{
SR_CMD_PAUSE
,
SR_LANG_EN
,
0
,
"Pause Playing"
,
"PeZ PLdgl"
,
{
NULL
}},
{
SR_CMD_REGIST
,
SR_LANG_EN
,
0
,
"regist yourself"
,
"RmqgST YkSfLF"
,{
NULL
}},
{
SR_CMD_REMOVE
,
SR_LANG_EN
,
0
,
"remove yourself"
,
"RmMoV YkSfLF"
,{
NULL
}},
{
SR_CMD_HELP
,
SR_LANG_EN
,
0
,
"call for help"
,
"KeL FeR hfLP;"
,{
NULL
}},
{
SR_CMD_ENDHELP
,
SR_LANG_EN
,
0
,
"end help"
,
"fND hfLP;"
,{
NULL
}},
// Chinese
#if SR_RUN_TEST
...
...
main/app/app_sr.h
浏览文件 @
fbf7df5f
...
...
@@ -51,8 +51,6 @@ typedef enum {
SR_CMD_PLAY
,
SR_CMD_PAUSE
,
SR_CMD_MAX
,
SR_CMD_REGIST
,
SR_CMD_REMOVE
,
SR_CMD_HELP
,
SR_CMD_ENDHELP
}
sr_user_cmd_t
;
...
...
main/app/app_sr_handler.c
浏览文件 @
fbf7df5f
...
...
@@ -23,20 +23,9 @@
#include <sys/socket.h>
#include <sys/wait.h>
#define AED_PORT 153
#define HELP_PORT 120
#define IMG_PORT 5555
#define REGIST_PORT 100
#define REMOVE_PORT 200
#define dataMaxLength 128
#define deviceID "5621564587648727"
#define SERVER_IP "139.9.142.29"
#define EYE_IP "192.168.0.109"
static
const
char
*
TAG
=
"sr_handler"
;
static
bool
b_audio_playing
=
false
;
extern
bool
isAed
;
typedef
enum
{
AUDIO_WAKE
,
...
...
@@ -212,82 +201,6 @@ void sr_handler_task(void *pvParam)
app_player_pause
();
last_player_state
=
PLAYER_STATE_PAUSE
;
break
;
case
SR_CMD_ENDHELP
:
app_player_pause
();
last_player_state
=
PLAYER_STATE_PAUSE
;
gpio_set_direction
(
41
,
GPIO_MODE_OUTPUT
);
gpio_set_level
(
GPIO_NUM_41
,
0
);
//1为高电平,0为低电平
break
;
case
SR_CMD_HELP
:
// ////sending information of the client////
// sr_echo_play(AUDIO_END);
// helpSocket=socket(AF_INET,SOCK_STREAM,0);/*建立socket*/
// if(helpSocket==-1){
// ESP_LOGE(TAG,"socket创建失败");
// break;
// }
// struct sockaddr_in dest_addr;
// char buf[dataMaxLength];
// for(int i=0;i<dataMaxLength;i++){
// buf[i]='\0';
// }
// dest_addr.sin_family=AF_INET;
// dest_addr.sin_port=htons(HELP_PORT);
// ESP_LOGE(TAG,"服务器地址:%s",SERVER_IP);
// if((dest_addr.sin_addr.s_addr=inet_addr(SERVER_IP))==INADDR_NONE) {
// ESP_LOGE(TAG,"地址解析失败");
// break;
// }
// bzero(&(dest_addr.sin_zero),8);
// if(connect(helpSocket,(struct sockaddr*)&dest_addr,sizeof(struct sockaddr))==-1){//连接方法,传入句柄,目标地址和大小
// ESP_LOGE(TAG,"服务器连接失败");
// break;
// } else{
// ESP_LOGI(TAG,"连接成功,发送求助设备编号 %s\n",deviceID);
// if(send(helpSocket,deviceID,17,0)==-1) {
// ESP_LOGE(TAG,"sending failed\n");
// break;
// }
// ESP_LOGI(TAG, "发送成功,等待应答\n");
// recv(helpSocket,buf,dataMaxLength,0);
// ESP_LOGI(TAG,"服务器应答 : %s",buf);
// }
// close(helpSocket);
////sending command to eye ////
if
(
isAed
!=
1
){
ESP_LOGI
(
TAG
,
"告知EYE进行图传"
);
int
imgSocket
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
if
(
imgSocket
==-
1
){
ESP_LOGE
(
TAG
,
"socket创建失败"
);
break
;
}
struct
sockaddr_in
eye_addr
;
char
flag
[
1
]
=
{
0
};
eye_addr
.
sin_family
=
AF_INET
;
eye_addr
.
sin_port
=
htons
(
IMG_PORT
);
if
((
eye_addr
.
sin_addr
.
s_addr
=
inet_addr
(
EYE_IP
))
==
INADDR_NONE
)
{
ESP_LOGE
(
TAG
,
"地址解析失败"
);
break
;
}
bzero
(
&
(
eye_addr
.
sin_zero
),
8
);
if
(
connect
(
imgSocket
,(
struct
sockaddr
*
)
&
eye_addr
,
sizeof
(
struct
sockaddr
))
==-
1
){
ESP_LOGE
(
TAG
,
"EYE连接失败"
);
break
;
}
else
{
const
char
*
req
=
"reqImg"
;
if
(
send
(
imgSocket
,
req
,
strlen
(
req
)
*
sizeof
(
char
),
0
)
==-
1
)
{
ESP_LOGE
(
TAG
,
"发送失败
\n
"
);
break
;
}
if
(
recv
(
imgSocket
,
flag
,
1
,
0
)
>
0
){
ESP_LOGI
(
TAG
,
"告知成功
\n
"
);
}
}
close
(
imgSocket
);
}
else
{
}
break
;
default:
ESP_LOGE
(
TAG
,
"Unknow cmd"
);
break
;
...
...
main/main.c
浏览文件 @
fbf7df5f
...
...
@@ -43,6 +43,7 @@
#include <string.h>
#include <sys/unistd.h>
#include <sys/stat.h>
extern
bool
s_connected
;
void
*
play_sound
(
const
char
*
path
);
static
QueueHandle_t
audio_event_queue
=
NULL
;
...
...
@@ -51,21 +52,16 @@ player_state_t g_player_state;
//gpio
#include "driver/gpio.h"
//AED(client)
bool
isAed
=
false
;
#define AED_PORT 153
#define SERVER_IP "139.9.142.29"
static
const
char
*
aedID
=
"1253467986534216"
;
bool
recv_warning_flag
=
0
;
//BOX(server)
static
int
isServerBox
=
0
;
#define SERVER_PORT 8800 //端口号
#define LENGTH_OF_LISTEN_QUEUE 20
static
const
char
*
TAG
=
"main"
;
#define IMG_PORT 5555
#define SERVER_IP "139.9.142.29"
bool
recv_warning_flag
=
0
;
//AED socket
void
*
aedSocketMonitorFunc
(
void
*
args
){
while
(
1
){
...
...
@@ -93,101 +89,33 @@ void * aedSocketMonitorFunc(void* args){
sleep
(
60
);
continue
;
}
else
{
if
(
isAed
){
printf
(
"正在注册为AED
\n
"
);
if
(
send
(
emergencyReponseSocket
,
aedID
,
16
,
0
)
==-
1
)
{
printf
(
"sending failed
\n
"
);
sleep
(
60
);
continue
;
}
recv
(
emergencyReponseSocket
,
buf
,
dataMaxLength
,
0
);
printf
(
"注册成功,等待唤醒
\n
"
);
for
(
int
i
=
0
;
i
<
dataMaxLength
;
i
++
)
buf
[
i
]
=
'\0'
;
recv
(
emergencyReponseSocket
,
buf
,
dataMaxLength
,
0
);
if
(
strcmp
(
buf
,
"abort"
)
==
0
){
printf
(
"服务器关闭,正在重置连接"
);
close
(
emergencyReponseSocket
);
continue
;
}
for
(
int
i
=
0
;
i
<
dataMaxLength
;
i
++
)
infor
[
i
]
=
buf
[
i
];
printf
(
"收到报警: %s
\n
"
,
buf
);
//gpio_set_direction(41, GPIO_MODE_OUTPUT);
//gpio_set_level(GPIO_NUM_41, 1);//1为高电平,0为低电平
recv_warning_flag
=
1
;
//to stimulate the text shown in the text box(information)
printf
(
"正在注册为AED
\n
"
);
if
(
send
(
emergencyReponseSocket
,
aedID
,
16
,
0
)
==-
1
)
{
printf
(
"sending failed
\n
"
);
sleep
(
60
);
continue
;
}
recv
(
emergencyReponseSocket
,
buf
,
dataMaxLength
,
0
);
printf
(
"注册成功,等待唤醒
\n
"
);
for
(
int
i
=
0
;
i
<
dataMaxLength
;
i
++
)
buf
[
i
]
=
'\0'
;
recv
(
emergencyReponseSocket
,
buf
,
dataMaxLength
,
0
);
if
(
strcmp
(
buf
,
"abort"
)
==
0
){
printf
(
"服务器关闭,正在重置连接"
);
close
(
emergencyReponseSocket
);
continue
;
}
for
(
int
i
=
0
;
i
<
dataMaxLength
;
i
++
)
infor
[
i
]
=
buf
[
i
];
printf
(
"收到报警: %s
\n
"
,
buf
);
//gpio_set_direction(41, GPIO_MODE_OUTPUT);
//gpio_set_level(GPIO_NUM_41, 1);//1为高电平,0为低电平
recv_warning_flag
=
1
;
//to stimulate the text shown in the text box(information)
}
close
(
emergencyReponseSocket
);
}
}
//Server socket
void
*
ServerBoxSocketMonitorFunc
(
void
*
args
){
// 设置一个socket地址结构server_addr,代表服务器internet的地址和端口
struct
sockaddr_in
server_addr
;
bzero
(
&
server_addr
,
sizeof
(
server_addr
));
server_addr
.
sin_family
=
AF_INET
;
server_addr
.
sin_addr
.
s_addr
=
htons
(
INADDR_ANY
);
server_addr
.
sin_port
=
htons
(
SERVER_PORT
);
// 创建用于internet的流协议(TCP)socket,用server_socket代表服务器向客户端提供服务的接口
int
server_socket
=
socket
(
PF_INET
,
SOCK_STREAM
,
0
);
if
(
server_socket
<
0
)
{
printf
(
"Create Socket Failed!
\n
"
);
exit
(
1
);
}
// 把socket和socket地址结构绑定
if
(
bind
(
server_socket
,
(
struct
sockaddr
*
)
&
server_addr
,
sizeof
(
server_addr
)))
{
printf
(
"Server Bind Port: %d Failed!
\n
"
,
SERVER_PORT
);
exit
(
1
);
}
// server_socket用于监听
if
(
listen
(
server_socket
,
LENGTH_OF_LISTEN_QUEUE
))
{
printf
(
"Server Listen Failed!
\n
"
);
exit
(
1
);
}
// 服务器端一直运行用以持续为客户端提供服务
while
(
1
)
{
// 定义客户端的socket地址结构client_addr,当收到来自客户端的请求后,调用accept
// 接受此请求,同时将client端的地址和端口等信息写入client_addr中
struct
sockaddr_in
client_addr
;
socklen_t
length
=
sizeof
(
client_addr
);
// 接受一个从client端到达server端的连接请求,将客户端的信息保存在client_addr中
// 如果没有连接请求,则一直等待直到有连接请求为止,这是accept函数的特性,可以
// 用select()来实现超时检测
// accpet返回一个新的socket,这个socket用来与此次连接到server的client进行通信
int
new_server_socket
=
accept
(
server_socket
,
(
struct
sockaddr
*
)
&
client_addr
,
&
length
);
if
(
new_server_socket
<
0
)
{
printf
(
"Server Accept Failed!
\n
"
);
break
;
}
char
flag
[
1
];
recv
(
new_server_socket
,
flag
,
1
,
0
);
if
(
flag
<
0
)
{
printf
(
"Server Recieve Data Failed!
\n
"
);
break
;
}
if
(
isalpha
(
flag
[
0
])){
ESP_LOGW
(
TAG
,
"sending warning flag"
);
play_sound
(
"/spiffs/mp3/warning_last.mp3"
);
printf
(
"sound_over
\n
"
);
}
close
(
new_server_socket
);
}
close
(
server_socket
);
return
0
;
}
//play_sound
void
*
play_sound
(
const
char
*
path
)
{
...
...
@@ -399,20 +327,9 @@ void app_main(void)
app_sr_start
(
false
);
app_rmaker_start
();
if
(
isAed
){
while
(
!
s_connected
);
pthread_t
aedMontorThread
;
pthread_create
(
&
aedMontorThread
,
NULL
,
aedSocketMonitorFunc
,
NULL
);
pthread_join
(
aedMontorThread
,
NULL
);
}
if
(
isServerBox
){
printf
(
"Getting into the second thread
\n
"
);
while
(
!
s_connected
);
printf
(
"waiting to hear from eye
\n
"
);
pthread_t
ServerBoxMontorThread
;
pthread_create
(
&
ServerBoxMontorThread
,
NULL
,
ServerBoxSocketMonitorFunc
,
NULL
);
pthread_join
(
ServerBoxMontorThread
,
NULL
);
}
while
(
!
s_connected
);
pthread_t
aedMontorThread
;
pthread_create
(
&
aedMontorThread
,
NULL
,
aedSocketMonitorFunc
,
NULL
);
pthread_join
(
aedMontorThread
,
NULL
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录