Commit b332cc9b authored by 957dd's avatar 957dd

加入了mqtt的设备更改,但是没有回退

parent 438d9a5e
log log
deviceback
loghttp loghttp
Deviceld.txt Deviceld.txt
\ No newline at end of file
...@@ -1265,6 +1265,7 @@ CMakeFiles/main.dir/src/download.c.o ...@@ -1265,6 +1265,7 @@ CMakeFiles/main.dir/src/download.c.o
/home/orangepi/car/master/src/download.c /home/orangepi/car/master/src/download.c
/usr/include/stdc-predef.h /usr/include/stdc-predef.h
/home/orangepi/car/master/include/download.h /home/orangepi/car/master/include/download.h
/home/orangepi/car/master/device_judg/device/device_change.h
/home/orangepi/car/master/include/common.h /home/orangepi/car/master/include/common.h
/usr/include/stdio.h /usr/include/stdio.h
/usr/include/aarch64-linux-gnu/bits/libc-header-start.h /usr/include/aarch64-linux-gnu/bits/libc-header-start.h
......
...@@ -1256,6 +1256,7 @@ CMakeFiles/main.dir/src/delay.c.o: ../src/delay.c \ ...@@ -1256,6 +1256,7 @@ CMakeFiles/main.dir/src/delay.c.o: ../src/delay.c \
CMakeFiles/main.dir/src/download.c.o: ../src/download.c \ CMakeFiles/main.dir/src/download.c.o: ../src/download.c \
/usr/include/stdc-predef.h \ /usr/include/stdc-predef.h \
../include/download.h \ ../include/download.h \
../device_judg/device/device_change.h \
../include/common.h \ ../include/common.h \
/usr/include/stdio.h \ /usr/include/stdio.h \
/usr/include/aarch64-linux-gnu/bits/libc-header-start.h \ /usr/include/aarch64-linux-gnu/bits/libc-header-start.h \
......
CMakeFiles/main.dir/src/download.c.o: \ CMakeFiles/main.dir/src/download.c.o: \
/home/orangepi/car/master/src/download.c /usr/include/stdc-predef.h \ /home/orangepi/car/master/src/download.c /usr/include/stdc-predef.h \
/home/orangepi/car/master/include/download.h \ /home/orangepi/car/master/include/download.h \
/home/orangepi/car/master/device_judg/device/device_change.h \
/home/orangepi/car/master/include/common.h /usr/include/stdio.h \ /home/orangepi/car/master/include/common.h /usr/include/stdio.h \
/usr/include/aarch64-linux-gnu/bits/libc-header-start.h \ /usr/include/aarch64-linux-gnu/bits/libc-header-start.h \
/usr/include/features.h /usr/include/features-time64.h \ /usr/include/features.h /usr/include/features-time64.h \
......
No preview for this file type
...@@ -4,15 +4,6 @@ ...@@ -4,15 +4,6 @@
#include "common.h" #include "common.h"
#include "device_change.h" #include "device_change.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <dirent.h>
#include <time.h>
#define BUFFER_SIZE 1024 #define BUFFER_SIZE 1024
// 判断文件是否存在 // 判断文件是否存在
...@@ -184,6 +175,9 @@ int write_device_id(const char *path, const char *device_id) { ...@@ -184,6 +175,9 @@ int write_device_id(const char *path, const char *device_id) {
fprintf(f, "%s", device_id); fprintf(f, "%s", device_id);
fclose(f); fclose(f);
my_zlog_debug("成功写入设备ID到 %s", path); my_zlog_debug("成功写入设备ID到 %s", path);
system("sudo reboot");
return 0; return 0;
} }
......
...@@ -5,4 +5,6 @@ ...@@ -5,4 +5,6 @@
#define DEVICE_NAME_DIR "/home/orangepi/car/master/deviceback" #define DEVICE_NAME_DIR "/home/orangepi/car/master/deviceback"
#define DEVICE_NAME_FILE "/home/orangepi/car/master/Deviceld.txt" #define DEVICE_NAME_FILE "/home/orangepi/car/master/Deviceld.txt"
int device_changename_back(const char *device_date, const char *device_id); int device_changename_back(const char *device_date, const char *device_id);
int file_exists(const char *path);
int create_directory_if_not_exists(const char *path);
#endif #endif
\ No newline at end of file
#include "download.h" #include "download.h"
#include "device_change.h"
#include "common.h" #include "common.h"
// 用于存储下载数据的结构体 // 用于存储下载数据的结构体
...@@ -26,43 +27,6 @@ static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, voi ...@@ -26,43 +27,6 @@ static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, voi
return realsize; return realsize;
} }
// 检查并创建日志目录
int create_directory_if_not_exists(const char *path) {
char temp[1024];
size_t len = strlen(path);
if (len >= sizeof(temp)) {
my_zlog_error("路径过长: %s", path);
return -1;
}
// 拷贝路径并保证以 '/' 结尾
strncpy(temp, path, sizeof(temp));
if (temp[len - 1] != '/') {
temp[len] = '/';
temp[len + 1] = '\0';
len++;
}
for (size_t i = 1; i < len; i++) {
if (temp[i] == '/') {
temp[i] = '\0';
if (access(temp, F_OK) != 0) {
if (mkdir(temp, 0755) != 0) {
my_zlog_error("创建目录失败: %s (%s)", temp, strerror(errno));
return -1;
} else {
my_zlog_debug("已创建目录: %s", temp);
}
}
temp[i] = '/';
}
}
return 0;
}
int download_file(const char *url,const char *target_dir ,const char *filename) { int download_file(const char *url,const char *target_dir ,const char *filename) {
// 创建目标目录(如果不存在) // 创建目标目录(如果不存在)
if (create_directory_if_not_exists(target_dir) == -1) { if (create_directory_if_not_exists(target_dir) == -1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment