From 8fd363af5c1a20c36d3ed3a6bafcd458e8f3ea3f Mon Sep 17 00:00:00 2001 From: "DESKTOP-T3S0O41\\iris_lj" Date: Wed, 23 Sep 2026 14:04:22 +0800 Subject: [PATCH] v2.1.4 --- src/GSMMannager.h | 2 +- src/ds1302.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++ src/ds1302.h | 4 ++- src/main.cpp | 41 +++++++++++++++++++++------- 4 files changed, 104 insertions(+), 12 deletions(-) diff --git a/src/GSMMannager.h b/src/GSMMannager.h index 82b6012..cc98b0e 100644 --- a/src/GSMMannager.h +++ b/src/GSMMannager.h @@ -4,7 +4,7 @@ // #define TINY_GSM_MODEM_SIM800 #define TINY_GSM_MODEM_BG96 -#define SerialMon Serial0 +#define SerialMon Serial #include #include #include "log.h" diff --git a/src/ds1302.cpp b/src/ds1302.cpp index dc6a08a..a355732 100644 --- a/src/ds1302.cpp +++ b/src/ds1302.cpp @@ -33,6 +33,21 @@ Ds1302::Ds1302(uint8_t pin_ena, uint8_t pin_clk, uint8_t pin_dat) } + +void system_tiem_init(struct tm t) +{ + // struct tm t; + // t.tm_year = dt->year - 1900; + // t.tm_mon = dt->month - 1; + // t.tm_mday = dt->day; + // t.tm_hour = dt->hour; + // t.tm_min = dt->minute; + // t.tm_sec = dt->second; + + time_t sys_now = mktime(&t); + struct timeval tv = { sys_now, 0 }; + settimeofday(&tv, nullptr); // 设置系统时间 +} void Ds1302::init() { pinMode(_pin_ena, OUTPUT); @@ -41,6 +56,43 @@ void Ds1302::init() digitalWrite(_pin_ena, LOW); digitalWrite(_pin_clk, LOW); + + Ds1302::DateTime dt; + Ds1302::getDateTime(&dt); + // snprintf(,"init time: %d-%d-%d %d:%d:%d", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec); + String log = "init time:" + String(dt.year) + "-" + String(dt.month) + "-" + String(dt.day) + " " + String(dt.hour) + ":" + String(dt.minute) + ":" + String(dt.second); + write_log(log_path,log,10); + + if(dt.year < (2025 - 2000)) + { + dt = { + .year = 26, + .month = 6, + .day = 25, + .hour = 10, + .minute = 0, + .second = 0 + // .dow = 1 + }; + Ds1302::setDateTime(&dt); + } + else + { + struct tm t; + t.tm_year = dt.year - 1900; + t.tm_mon = dt.month - 1; + t.tm_mday = dt.day; + t.tm_hour = dt.hour; + t.tm_min = dt.minute; + t.tm_sec = dt.second; + + // time_t sys_now = mktime(&t); + // struct timeval tv = { sys_now, 0 }; + // settimeofday(&tv, nullptr); // 设置系统时间 + + system_tiem_init(t); + } + } @@ -63,6 +115,8 @@ void Ds1302::getDateTime(DateTime* dt) dt->month = _bcd2dec(_readByte() & 0b00011111); dt->dow = _bcd2dec(_readByte() & 0b00000111); dt->year = _bcd2dec(_readByte() & 0b11111111); + + _end(); } @@ -82,6 +136,21 @@ void Ds1302::setDateTime(DateTime* dt) _writeByte(_dec2bcd(dt->dow % 8 )); _writeByte(_dec2bcd(dt->year % 100)); _writeByte(0b10000000); + + struct tm t; + t.tm_year = dt->year - 1900; + t.tm_mon = dt->month - 1; + t.tm_mday = dt->day; + t.tm_hour = dt->hour; + t.tm_min = dt->minute; + t.tm_sec = dt->second; + + // time_t sys_now = mktime(&t); + // struct timeval tv = { sys_now, 0 }; + // settimeofday(&tv, nullptr); // 设置系统时间 + + system_tiem_init(t); + _end(); } diff --git a/src/ds1302.h b/src/ds1302.h index 84eba0d..138b937 100644 --- a/src/ds1302.h +++ b/src/ds1302.h @@ -13,7 +13,9 @@ #define _DS_1302_H #include - +#include +#include "time.h" +#include "log.h" class Ds1302 { public: diff --git a/src/main.cpp b/src/main.cpp index 6971f19..3bbccc3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -130,7 +130,6 @@ size_t serialread(u_char *data, size_t lenth) int lenthofread = IS1Serial->readBytes(data,lenth); return lenthofread; - } ////////////////////////////////AIR780EG/////////////////////////////////////////// @@ -220,17 +219,28 @@ void setup() // 初始化DS18b20 uint8_t temp_number = DS18b20_init(); + // servo_init(21,0); + // shutter_off(); + // int aaaaaa=0; // while(1) // { + // if(aaaaaa == 10) shutter_up(); + // if(aaaaaa == 20) shutter_down(); + // if(aaaaaa == 30) shutter_on(); + // if(aaaaaa == 40) shutter_off(); + // if(aaaaaa == 45) aaaaaa = 0; // ////排序时使用 - // float temp[8]; - // getall_temp(temp); - - // for(int i = 0;i<8;i++) - // { - // Serial.printf("temp[%d]: %f\n",i + 1,temp[i]); - // } - // vTaskDelay(500); + // // float temp[8]; + // // getall_temp(temp); + // // Serial.println("\n"); + // // for(int i = 0;i<8;i++) + // // { + // // Serial.printf("temp[%d]: %f\n",i + 1,temp[i]); + // // } + // // Serial.println("\n"); + // // vTaskDelay(500); + // aaaaaa ++; + // vTaskDelay(500); // } //ADC电压采集初始化 @@ -288,6 +298,11 @@ void setup() write_log(log_path,"IS_SN :" +STRSensorInfos_structure.serialnumber,20); + write_log(log_path,"IS_SN :" +String(STRSensorInfos_structure.a1),20); + write_log(log_path,"IS_SN :" +String(STRSensorInfos_structure.a2),20); + write_log(log_path,"IS_SN :" +String(STRSensorInfos_structure.a3),20); + write_log(log_path,"IS_SN :" +String(STRSensorInfos_structure.a4),20); + write_log(log_path,"IS_SN :" +String(STRSensorInfos_structure.BandNum),20); // is11Sensor->guangpu_bochang.a1 = 0.000000000000000; // is11Sensor->guangpu_bochang.a2 = 0.000000000; @@ -828,7 +843,6 @@ void Task2(void *pvParameters) save = false; xSemaphoreGive(xMutexInventory); } - } } } @@ -1127,6 +1141,13 @@ void receive_command_unpack(uint8_t * read_buf,uint16_t data_length,uint8_t port data[1] = STRSensorInfos_structure.a2; data[2] = STRSensorInfos_structure.a3; data[3] = STRSensorInfos_structure.a4; + + + // data[0] = is11Sensor->guangpu_bochang.a0; + // data[1] = is11Sensor->guangpu_bochang.a1; + // data[2] = is11Sensor->guangpu_bochang.a2; + // data[3] = is11Sensor->guangpu_bochang.a3; + send_lenth = IRIS_Protocol_Pack(0x61,16,(uint8_t *)data,send_buff);