Compare commits

..

No commits in common. "8.8Upgrade_version" and "7.11Upgrade" have entirely different histories.

3 changed files with 3826 additions and 2140 deletions

View File

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

1826
src/6.10main .cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -49,12 +49,6 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <mutex> #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" #define MSS_TEST_BUS_NAME "yolov5test"
static jbus_hdl_t g_jbus; static jbus_hdl_t g_jbus;
static jmss_hdl_t g_jmss; static jmss_hdl_t g_jmss;
@ -194,62 +188,17 @@ 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){ void* IO_serial_thread(void* args){
const int adc_threshold = 1000;
int adc_check_counter = 0; // 用于控制ADC检查频率
while (true) { while (true) {
this_thread::sleep_for(chrono::seconds(1)); 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) { for (int i = 0; i < 5; ++i) {
int Solenoid_valve = relay_state[i]; int Solenoid_valve = relay_state[i];
if (Solenoid_valve > 0) { if (Solenoid_valve > 0) {
if (Solenoid_valve == 1) { if (Solenoid_valve == 1) {
// 倒计时结束,关闭 IO // 倒计时结束,关闭 IO
reset_relay(i+1, 0); reset_relay(i+1, 0);
std::cout << "继电器" << (i+1) << " 已关闭" << std::endl; std::cout << " 已关闭" << std::endl;
} }
relay_state[i] = Solenoid_valve - 1; relay_state[i] = Solenoid_valve - 1;
} }
@ -257,6 +206,7 @@ void* IO_serial_thread(void* args){
} }
} }
// 播放音频的函数 // 播放音频的函数
void play_audio(const std::string& file_path, jspk_hdl_t jspk) { void play_audio(const std::string& file_path, jspk_hdl_t jspk) {
JES_SPK_PlayFile(jspk, file_path.c_str()); JES_SPK_PlayFile(jspk, file_path.c_str());
@ -620,7 +570,6 @@ int WARN_TEMPERATURE;
int MOVE_THRESHOLD; int MOVE_THRESHOLD;
int IGNORE_TEMPERATURE; int IGNORE_TEMPERATURE;
string ALARM_URL; string ALARM_URL;
string upload_url;
double Confidence_Threshold; double Confidence_Threshold;
vector<vector<int>> last_result; vector<vector<int>> last_result;
@ -731,7 +680,7 @@ bool _geturlFromfile(const char* filepath, char* url, int maxLength) {
while (*pline == ' ') { while (*pline == ' ') {
pline++; pline++;
} }
int pline_len = strlen(pline); int pline_len = strlen(pline) - 1;
int version_len = (pline_len > maxLength ? maxLength : pline_len); int version_len = (pline_len > maxLength ? maxLength : pline_len);
memcpy(url, pline, version_len); memcpy(url, pline, version_len);
printf("upload_url = %s\n", url); printf("upload_url = %s\n", url);
@ -1010,7 +959,7 @@ int main(int argc, char** argv)
MOVE_THRESHOLD = Config_jsonData["MOVE_THRESHOLD"]; MOVE_THRESHOLD = Config_jsonData["MOVE_THRESHOLD"];
IGNORE_TEMPERATURE = Config_jsonData["IGNORE_TEMPERATURE"]; IGNORE_TEMPERATURE = Config_jsonData["IGNORE_TEMPERATURE"];
Confidence_Threshold = Config_jsonData["Confidence_Threshold"]; Confidence_Threshold = Config_jsonData["Confidence_Threshold"];
// ALARM_URL = Config_jsonData["alarm_URL"]; ALARM_URL = Config_jsonData["alarm_URL"];
} }
catch (const json::parse_error& e) catch (const json::parse_error& e)
{ {
@ -1024,7 +973,7 @@ int main(int argc, char** argv)
cout << "配置 MOVE_THRESHOLD :" << MOVE_THRESHOLD << endl; cout << "配置 MOVE_THRESHOLD :" << MOVE_THRESHOLD << endl;
cout << "配置 IGNORE_TEMPERATURE :" << IGNORE_TEMPERATURE << endl; cout << "配置 IGNORE_TEMPERATURE :" << IGNORE_TEMPERATURE << endl;
cout << "配置 Confidence_Threshold :" << Confidence_Threshold << 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_INFRARED_SENSOR << endl;
cout << SERIAL_PORT_SOLENOID << endl; cout << SERIAL_PORT_SOLENOID << endl;
@ -1094,7 +1043,7 @@ int main(int argc, char** argv)
pthread_create(&fire_rknn_tidp, NULL, rkmedia_rknn_thread, model_fire); 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_t read_serial;
pthread_create(&read_serial, NULL, read_serial_thread, NULL); pthread_create(&read_serial, NULL, read_serial_thread, NULL);
@ -1578,12 +1527,11 @@ void* upload_message(void* args)
{ {
pthread_detach(pthread_self()); pthread_detach(pthread_self());
// 获取上报url // 获取上报url
char upload_url[200] = { 0 }; // char upload_url[200] = { 0 };
memset(upload_url,0,sizeof(upload_url)); // if (!_geturlFromfile(DOWNLOAD_VERSION_PATH, upload_url, sizeof(upload_url))) {
if (!_geturlFromfile(DOWNLOAD_VERSION_PATH, upload_url, sizeof(upload_url))) { // printf("结束进程\n");
printf("结束进程\n"); // return 0;
return 0; // }
}
Alarm* alarm = static_cast<Alarm*>(args); Alarm* alarm = static_cast<Alarm*>(args);
@ -1642,28 +1590,71 @@ void* upload_message(void* args)
if (curl) if (curl)
{ {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST"); // curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, upload_url); // // 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;
/* Now specify the POST data */ /* Now specify the POST data */
struct curl_slist* plist = nullptr; struct curl_slist* plist = nullptr;
plist = curl_slist_append(plist, "Content-Type:application/json;charset=UTF-8"); plist = curl_slist_append(plist, "Content-Type:application/json;charset=UTF-8");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, plist); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, plist);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, MessageString.c_str()); 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); 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); 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) { if (res != CURLE_OK) {
std::cerr << "Failed to perform cURL request: " << curl_easy_strerror(res) << std::endl; std::cerr << "controller: Failed to perform cURL request: " << (res) << std::endl;
} }
else { else {
std::cout << "Request successful!" << std::endl; std::cout << "controller: Request successful!" << std::endl;
std::cout << "Response: " << response << std::endl; // std::cout << "controller: Response: " << response << std::endl;
} }
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
} }
// curl_global_cleanup(); // curl_global_cleanup();
@ -1728,6 +1719,10 @@ void* upload_message_controller(void* args)
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, MessageString.c_str()); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, MessageString.c_str());
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L); 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); res = curl_easy_perform(curl);
/* Check for errors */ /* Check for errors */
// if(res != CURLE_OK) // if(res != CURLE_OK)
@ -1746,152 +1741,33 @@ void* upload_message_controller(void* args)
// curl_global_cleanup(); // curl_global_cleanup();
} }
void upload_WaterLevel(int _type,string msg)
{
char upload_url[200] = { 0 };
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();
std::string cameraId = DeviceID;
std::string type = std::to_string(_type);
std::cout << "cameraid: " << cameraId << " msg: " << msg << std::endl;
std::string MessageString =
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, "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);
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 << "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) { 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()); pthread_detach(pthread_self());
auto last_time = std::chrono::high_resolution_clock::now();// 记录开始时间 auto last_time = std::chrono::high_resolution_clock::now();// 记录开始时间
int time2run = 1; int time2run = 1;
while (!quit) { 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) { auto current_time = std::chrono::high_resolution_clock::now();
// last_time = current_time; auto elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(current_time - last_time);// 计算距离开始时间的时间差
// time2run = 1;
// }
// if (time2run) { if (elapsed_time.count() - 30000 > 0) {
last_time = current_time;
time2run = 1;
}
if (time2run) {
std::cout << "心跳上报" << std::endl; std::cout << "心跳上报" << std::endl;
std::string cameraId = DeviceID; std::string cameraId = DeviceID;
std::string IP = getEth0IPAddress(); std::string IP = "987654";
std::cout << "使用IP地址: " << IP << std::endl;
int state = 1; int state = 1;
std::string http_address = "http"; std::string http_address = "http";
std::string MessageString = std::string MessageString =
R"({ R"({
"ID": ")" + cameraId + R"(", "cameraId": ")" + cameraId + R"(",
"IP": ")" + IP + R"(" "IP": ")" + IP + R"(",
"state": )" + std::to_string(state) + R"(,
"http_address": ")" + http_address + R"("
})"; })";
CURL* curl; CURL* curl;
CURLcode res; CURLcode res;
@ -1899,9 +1775,8 @@ void* heart_beat(void* args) {
if (curl) if (curl)
{ {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, upload_url); curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.1.23:9527/device/heartbeat");
std::cout << "upload_url地址: " << upload_url << std::endl;
/* Now specify the POST data */ /* Now specify the POST data */
struct curl_slist* plist = nullptr; struct curl_slist* plist = nullptr;
plist = curl_slist_append(plist, "Content-Type:application/json;charset=UTF-8"); plist = curl_slist_append(plist, "Content-Type:application/json;charset=UTF-8");
@ -1909,17 +1784,16 @@ void* heart_beat(void* args) {
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, MessageString.c_str()); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, MessageString.c_str());
std::string response; std::string response;
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
/* Check for errors */ /* Check for errors */
// if(res != CURLE_OK) // if(res != CURLE_OK)
// fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res)); // fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
if (res != CURLE_OK) { if (res != CURLE_OK) {
std::cerr << "heart beat: Failed to perform cURL request: " << res << std::endl; std::cerr << "heart beat: Failed to perform cURL request: " << curl_easy_strerror(res) << std::endl;
} }
else { else {
std::cout << "heart beat: Request successful!" << std::endl; std::cout << "heart beat: Request successful!" << std::endl;
@ -1942,10 +1816,8 @@ void* heart_beat(void* args) {
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
} }
// curl_global_cleanup(); // curl_global_cleanup();
// } }
// time2run = 0; time2run = 0;
this_thread::sleep_for(chrono::seconds(30));
} }
} }