Compare commits

..

5 Commits

Author SHA1 Message Date
2cbc85b04b 上传文件至 / 2025-08-12 20:50:05 +08:00
727b5eb7f5 删除 NEWREADME.md 2025-08-12 20:47:11 +08:00
6e89206b26 删除 src/6.10main .cpp 2025-08-12 20:46:52 +08:00
cc35a6afb6 上传文件至 src 2025-08-12 20:46:36 +08:00
5de1b6a3ff 删除 src/main.cpp 2025-08-12 20:46:15 +08:00
3 changed files with 2140 additions and 3826 deletions

View File

@ -1,3 +1,15 @@
# 8.8升级
## 升级内容
### 增加消防水位检测功能
针对消防水位的的检测ADC文件路径/sys/bus/iio/devices/iio:device0/in_voltage2_raw设置ADC检测值为1000一小时检测一次如果超过便输出0小于1000则输出1
指定IP地址摄像头本身具有多个IP地址指定有线网络接口eth0并读取该IP地址
# 7.11升级
## 升级内容

File diff suppressed because it is too large Load Diff

View File

@ -49,6 +49,12 @@
#include <nlohmann/json.hpp>
#include <mutex>
#include <ifaddrs.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <sys/socket.h>
#include <unistd.h>
#define MSS_TEST_BUS_NAME "yolov5test"
static jbus_hdl_t g_jbus;
static jmss_hdl_t g_jmss;
@ -188,17 +194,62 @@ void reset_relay(int zone,int cone) {
}
}
//IO线程
// 添加ADC相关函数
int readADCValue() {
const std::string adc_path = "/sys/bus/iio/devices/iio:device0/in_voltage2_raw";
std::ifstream file(adc_path);
if (!file.is_open()) {
std::cerr << "无法打开ADC文件" << std::endl;
return -1;
}
int adc_value;
if (file >> adc_value) {
file.close();
return adc_value;
} else {
std::cerr << "读取ADC值失败" << std::endl;
file.close();
return -1;
}
}
void upload_WaterLevel(int _type,string msg);
// 修改后的IO线程集成ADC监控
void* IO_serial_thread(void* args){
const int adc_threshold = 1000;
int adc_check_counter = 0; // 用于控制ADC检查频率
while (true) {
this_thread::sleep_for(chrono::seconds(1));
// ADC监控 - 每秒检查一次(可调整频率)
adc_check_counter++;
if (adc_check_counter >= 3600) { // 每一小时检查一次ADC可修改频率
adc_check_counter = 0;
int adc_value = readADCValue();
if (adc_value != -1) {
std::cout << "ADC值: " << adc_value << std::endl;
if (adc_value >= adc_threshold) {
upload_WaterLevel(0,"Water_Normal");
}else{
upload_WaterLevel(1,"Water_Lower");
}
}
}
// 原有的继电器倒计时逻辑
for (int i = 0; i < 5; ++i) {
int Solenoid_valve = relay_state[i];
if (Solenoid_valve > 0) {
if (Solenoid_valve == 1) {
// 倒计时结束,关闭 IO
reset_relay(i+1, 0);
std::cout << " 已关闭" << std::endl;
std::cout << "继电器" << (i+1) << " 已关闭" << std::endl;
}
relay_state[i] = Solenoid_valve - 1;
}
@ -206,7 +257,6 @@ void* IO_serial_thread(void* args){
}
}
// 播放音频的函数
void play_audio(const std::string& file_path, jspk_hdl_t jspk) {
JES_SPK_PlayFile(jspk, file_path.c_str());
@ -570,6 +620,7 @@ int WARN_TEMPERATURE;
int MOVE_THRESHOLD;
int IGNORE_TEMPERATURE;
string ALARM_URL;
string upload_url;
double Confidence_Threshold;
vector<vector<int>> last_result;
@ -680,7 +731,7 @@ bool _geturlFromfile(const char* filepath, char* url, int maxLength) {
while (*pline == ' ') {
pline++;
}
int pline_len = strlen(pline) - 1;
int pline_len = strlen(pline);
int version_len = (pline_len > maxLength ? maxLength : pline_len);
memcpy(url, pline, version_len);
printf("upload_url = %s\n", url);
@ -959,7 +1010,7 @@ int main(int argc, char** argv)
MOVE_THRESHOLD = Config_jsonData["MOVE_THRESHOLD"];
IGNORE_TEMPERATURE = Config_jsonData["IGNORE_TEMPERATURE"];
Confidence_Threshold = Config_jsonData["Confidence_Threshold"];
ALARM_URL = Config_jsonData["alarm_URL"];
// ALARM_URL = Config_jsonData["alarm_URL"];
}
catch (const json::parse_error& e)
{
@ -973,7 +1024,7 @@ int main(int argc, char** argv)
cout << "配置 MOVE_THRESHOLD :" << MOVE_THRESHOLD << endl;
cout << "配置 IGNORE_TEMPERATURE :" << IGNORE_TEMPERATURE << endl;
cout << "配置 Confidence_Threshold :" << Confidence_Threshold << endl;
cout << "配置 ALARM_URL :" << ALARM_URL << endl;//加入这一行
// cout << "配置 ALARM_URL :" << ALARM_URL << endl;//加入这一行
cout << SERIAL_PORT_INFRARED_SENSOR << endl;
cout << SERIAL_PORT_SOLENOID << endl;
@ -1043,7 +1094,7 @@ int main(int argc, char** argv)
pthread_create(&fire_rknn_tidp, NULL, rkmedia_rknn_thread, model_fire);
// pthread_create(&heart_beat_tidp, NULL, heart_beat, NULL);
pthread_create(&heart_beat_tidp, NULL, heart_beat, NULL);
//串口读数据线程
pthread_t read_serial;
pthread_create(&read_serial, NULL, read_serial_thread, NULL);
@ -1527,11 +1578,12 @@ void* upload_message(void* args)
{
pthread_detach(pthread_self());
// 获取上报url
// char upload_url[200] = { 0 };
// if (!_geturlFromfile(DOWNLOAD_VERSION_PATH, upload_url, sizeof(upload_url))) {
// printf("结束进程\n");
// return 0;
// }
char upload_url[200] = { 0 };
memset(upload_url,0,sizeof(upload_url));
if (!_geturlFromfile(DOWNLOAD_VERSION_PATH, upload_url, sizeof(upload_url))) {
printf("结束进程\n");
return 0;
}
Alarm* alarm = static_cast<Alarm*>(args);
@ -1590,71 +1642,28 @@ void* upload_message(void* args)
if (curl)
{
// curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
// // curl_easy_setopt(curl, CURLOPT_URL, upload_url);
// curl_easy_setopt(curl, CURLOPT_URL,ALARM_URL);
// std::cout << "ALARM_URL: " << ALARM_URL << std::endl;
// /* Now specify the POST data */
// struct curl_slist* plist = nullptr;
// plist = curl_slist_append(plist, "Content-Type:application/json;charset=UTF-8");
// curl_easy_setopt(curl, CURLOPT_HTTPHEADER, plist);
// curl_easy_setopt(curl, CURLOPT_POSTFIELDS, MessageString.c_str());
// //std::cout << "MessageString: " << MessageString.c_str() << std::endl;
// // std::string response;
// // curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
// // curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
// curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
// res = curl_easy_perform(curl);
// /* Check for errors */
// // if(res != CURLE_OK)
// // fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
// if (res != CURLE_OK) {
// std::cerr << "Failed to perform cURL request: " << curl_easy_strerror(res) << std::endl;
// }
// else {
// std::cout << "Request successful!" << std::endl;
// // std::cout << "Response: " << response << std::endl;
// }
// curl_easy_cleanup(curl);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, ALARM_URL.c_str());
std::cout << "ALARM_URL: " << ALARM_URL << std::endl;
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, upload_url);
/* Now specify the POST data */
struct curl_slist* plist = nullptr;
plist = curl_slist_append(plist, "Content-Type:application/json;charset=UTF-8");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, plist);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, MessageString.c_str());
std::string response;
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
std::cout << "MessageString: " << MessageString.c_str() << std::endl;
// std::string response;
// curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
// curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
res = curl_easy_perform(curl);
/* Check for errors */
// if(res != CURLE_OK)
// fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
if (res != CURLE_OK) {
std::cerr << "controller: Failed to perform cURL request: " << (res) << std::endl;
std::cerr << "Failed to perform cURL request: " << curl_easy_strerror(res) << std::endl;
}
else {
std::cout << "controller: Request successful!" << std::endl;
// std::cout << "controller: Response: " << response << std::endl;
std::cout << "Request successful!" << std::endl;
std::cout << "Response: " << response << std::endl;
}
curl_easy_cleanup(curl);
}
// curl_global_cleanup();
@ -1719,10 +1728,6 @@ void* upload_message_controller(void* args)
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, MessageString.c_str());
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
// std::string response;
// curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
// curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
res = curl_easy_perform(curl);
/* Check for errors */
// if(res != CURLE_OK)
@ -1741,42 +1746,61 @@ void* upload_message_controller(void* args)
// curl_global_cleanup();
}
void* heart_beat(void* args) {
pthread_detach(pthread_self());
auto last_time = std::chrono::high_resolution_clock::now();// 记录开始时间
int time2run = 1;
while (!quit) {
void upload_WaterLevel(int _type,string msg)
{
char upload_url[200] = { 0 };
auto current_time = std::chrono::high_resolution_clock::now();
auto elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(current_time - last_time);// 计算距离开始时间的时间差
if (elapsed_time.count() - 30000 > 0) {
last_time = current_time;
time2run = 1;
memset(upload_url,0,sizeof(upload_url));
if (!_geturlFromfile(DOWNLOAD_VERSION_PATH, upload_url, sizeof(upload_url))) {
printf("结束进程\n");
}
// 获取当前系统时间
std::time_t alarmTime_std = std::time(nullptr);
// 将时间转换为本地时间
std::tm* localTime = std::localtime(&alarmTime_std);
// 从本地时间结构中获取时间信息
int year = localTime->tm_year + 1900;
int month = localTime->tm_mon + 1;
int day = localTime->tm_mday;
int hour = localTime->tm_hour;
int minute = localTime->tm_min;
int second = localTime->tm_sec;
// 拼接成字符串
std::ostringstream oss_alarmTime;
oss_alarmTime << std::setfill('0')
<< std::setw(4) << year << "-"
<< std::setw(2) << month << "-"
<< std::setw(2) << day << " "
<< std::setw(2) << hour << ":"
<< std::setw(2) << minute << ":"
<< std::setw(2) << second;
// 获取拼接后的字符串
std::string formattedTime = oss_alarmTime.str();
if (time2run) {
std::cout << "心跳上报" << std::endl;
std::string cameraId = DeviceID;
std::string IP = "987654";
int state = 1;
std::string http_address = "http";
std::string type = std::to_string(_type);
std::cout << "cameraid: " << cameraId << " msg: " << msg << std::endl;
std::string MessageString =
R"({
"cameraId": ")" + cameraId + R"(",
"IP": ")" + IP + R"(",
"state": )" + std::to_string(state) + R"(,
"http_address": ")" + http_address + R"("
R"({"cameraid": ")" + cameraId + R"(",
"msg": ")" + msg + R"(",
"type": ")" + type + R"(",
"time": ")" + formattedTime +R"("
})";
CURL* curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.1.23:9527/device/heartbeat");
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, upload_url);
/* Now specify the POST data */
struct curl_slist* plist = nullptr;
plist = curl_slist_append(plist, "Content-Type:application/json;charset=UTF-8");
@ -1784,16 +1808,118 @@ void* heart_beat(void* args) {
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, MessageString.c_str());
std::string response;
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
res = curl_easy_perform(curl);
/* Check for errors */
// if(res != CURLE_OK)
// fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
if (res != CURLE_OK) {
std::cerr << "heart beat: Failed to perform cURL request: " << curl_easy_strerror(res) << std::endl;
std::cerr << "WaterLevel: Failed to perform cURL request: " << curl_easy_strerror(res) << std::endl;
}
else {
std::cout << "Request successful!" << std::endl;
std::cout << "Response: " << response << std::endl;
}
curl_easy_cleanup(curl);
}
// curl_global_cleanup();
}
std::string getEth0IPAddress() {
struct ifaddrs *ifaddrs_ptr, *ifa;
// 获取所有网络接口信息
if (getifaddrs(&ifaddrs_ptr) == -1) {
std::cerr << "获取网络接口失败" << std::endl;
return "";
}
// 遍历所有网络接口
for (ifa = ifaddrs_ptr; ifa != nullptr; ifa = ifa->ifa_next) {
if (ifa->ifa_addr == nullptr) continue;
// 只处理eth0接口的IPv4地址
if (ifa->ifa_addr->sa_family == AF_INET &&
strcmp(ifa->ifa_name, "eth0") == 0) {
struct sockaddr_in* addr_in = (struct sockaddr_in*)ifa->ifa_addr;
char ip_str[INET_ADDRSTRLEN];
// 将IP地址转换为字符串
if (inet_ntop(AF_INET, &(addr_in->sin_addr), ip_str, INET_ADDRSTRLEN)) {
return std::string(ip_str);
}
}
}
freeifaddrs(ifaddrs_ptr);
return "";
}
//心跳
void* heart_beat(void* args) {
char upload_url[200] = { 0 };
memset(upload_url,0,sizeof(upload_url));
if (!_geturlFromfile(DOWNLOAD_VERSION_PATH, upload_url, sizeof(upload_url))) {
printf("结束进程\n");
}
pthread_detach(pthread_self());
auto last_time = std::chrono::high_resolution_clock::now();// 记录开始时间
int time2run = 1;
while (!quit) {
// auto current_time = std::chrono::high_resolution_clock::now();
// auto elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(current_time - last_time);// 计算距离开始时间的时间差
// if (elapsed_time.count() - 30000 > 0) {
// last_time = current_time;
// time2run = 1;
// }
// if (time2run) {
std::cout << "心跳上报" << std::endl;
std::string cameraId = DeviceID;
std::string IP = getEth0IPAddress();
std::cout << "使用IP地址: " << IP << std::endl;
int state = 1;
std::string http_address = "http";
std::string MessageString =
R"({
"ID": ")" + cameraId + R"(",
"IP": ")" + IP + R"("
})";
CURL* curl;
CURLcode res;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, upload_url);
std::cout << "upload_url地址: " << upload_url << std::endl;
/* Now specify the POST data */
struct curl_slist* plist = nullptr;
plist = curl_slist_append(plist, "Content-Type:application/json;charset=UTF-8");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, plist);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, MessageString.c_str());
std::string response;
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
res = curl_easy_perform(curl);
/* Check for errors */
// if(res != CURLE_OK)
// fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
if (res != CURLE_OK) {
std::cerr << "heart beat: Failed to perform cURL request: " << res << std::endl;
}
else {
std::cout << "heart beat: Request successful!" << std::endl;
@ -1816,8 +1942,10 @@ void* heart_beat(void* args) {
curl_easy_cleanup(curl);
}
// curl_global_cleanup();
}
time2run = 0;
// }
// time2run = 0;
this_thread::sleep_for(chrono::seconds(30));
}
}