From 9014267de03e361c09acced6cf3256fe4d5d4c06 Mon Sep 17 00:00:00 2001 From: "DESKTOP-T3S0O41\\iris_lj" Date: Thu, 7 May 2026 09:05:57 +0800 Subject: [PATCH] v2.0.2 --- src/DS18B20.cpp | 2 +- src/SensorIS11.cpp | 8 ++-- src/gsmm_mqtt.cpp | 95 +++++++++++++++++++++++++++++++++------- src/main.cpp | 106 +++++++++++++++++++++++++++++++++++---------- 4 files changed, 166 insertions(+), 45 deletions(-) diff --git a/src/DS18B20.cpp b/src/DS18B20.cpp index 99560f3..b545717 100644 --- a/src/DS18B20.cpp +++ b/src/DS18B20.cpp @@ -81,7 +81,7 @@ void getall_temp(float *temp) DS18b20.requestTemperatures(); // Send the command to get temperatures // vTaskDelay(1000); - for(int8_t i ;i= 6) { + data.hour = timeStr.substring(0, 2).toInt(); + data.minute = timeStr.substring(2, 4).toInt(); + data.second = timeStr.substring(4, 6).toInt(); + } else { + data.hour = data.minute = data.second = 0; + } + + // 2. 提取纬度 + int idx3 = idx2 + 1; + int idx4 = gpsStr.indexOf(",", idx3); + String latStr = gpsStr.substring(idx3, idx4); + + // 3. 提取经度 + int idx5 = idx4 + 1; + int idx6 = gpsStr.indexOf(",", idx5); + String lonStr = gpsStr.substring(idx5, idx6); + + data.latitude = convertDMSToDecimal(latStr); + data.longitude = convertDMSToDecimal(lonStr); + + // 4. 提取日期 + int lastComma = gpsStr.lastIndexOf(","); + String dateStr = gpsStr.substring(lastComma - 6, lastComma); // 假设日期是6位 YYMMDD + + if (dateStr.length() == 6) { + data.year = 2000 + dateStr.substring(0, 2).toInt(); // 转成4位年 + data.month = dateStr.substring(2, 4).toInt(); + data.day = dateStr.substring(4, 6).toInt(); + } else { + data.year = data.month = data.day = 0; + } + + return data; +} + + String get_GPS(gps_struct *gps_info) { EventBits_t uxBits = xEventGroupGetBits(http_event_group); @@ -268,30 +327,34 @@ String get_GPS(gps_struct *gps_info) xEventGroupSetBits(http_event_group, Http_stop_bit); - if(gpsbac.indexOf("+QGPSLOC:") != -1) + if(gpsbac.indexOf("+QGPSLOC:") == -1) { return "-1"; } - const char* gps_data = gpsbac.c_str(); - // 提取时间 (063416.40 -> 06:34:16.40) - sscanf(gps_data, "%2hhd%2hhd%2hhd", &gps_info->hour, &gps_info->minute, &gps_info->second); + // // // +QGPSLOC: 071119.00,3905.2108N,11706.7802E,3.43,-11.6,3,,0.993,0.536,220426,06 + // const char* gps_data = gpsbac.c_str(); + // // 提取时间 (063416.40 -> 06:34:16.40) + // sscanf(gps_data, "%2hhd%2hhd%2hhd", &gps_info->hour, &gps_info->minute, &gps_info->second); - // 提取日期 (110620 -> 2020-11-06) - sscanf(gps_data + 36, "%2hd%2hhd%2hhd", &gps_info->year, &gps_info->month, &gps_info->day); + // // 提取日期 (110620 -> 2020-11-06) + // sscanf(gps_data + 36, "%2hd%2hhd%2hhd", &gps_info->year, &gps_info->month, &gps_info->day); - // 提取纬度 (3143.2951N -> 31.721585) - int lat_deg = gps_data[8] - '0'; // 获取纬度的度数 31 - int lat_min = gps_data[9] - '0'; // 获取纬度的分钟数 43 - float lat_min_decimal = atof(&gps_data[10]); // 获取纬度的小数部分 2951 - gps_info->latitude = lat_deg + (lat_min + lat_min_decimal / 10000) / 60.0; + // // 提取纬度 (3143.2951N -> 31.721585) + // int lat_deg = gps_data[8] - '0'; // 获取纬度的度数 31 + // int lat_min = gps_data[9] - '0'; // 获取纬度的分钟数 43 + // float lat_min_decimal = atof(&gps_data[10]); // 获取纬度的小数部分 2951 + // gps_info->latitude = lat_deg + (lat_min + lat_min_decimal / 10000) / 60.0; - // 提取经度 (11713.0655E -> 117.217758) - int lon_deg = gps_data[14] - '0'; // 获取经度的度数 117 - int lon_min = gps_data[15] - '0'; // 获取经度的分钟数 13 - float lon_min_decimal = atof(&gps_data[16]); // 获取经度的小数部分 0655 - gps_info->longitude = lon_deg + (lon_min + lon_min_decimal / 10000) / 60.0; + // // 提取经度 (11713.0655E -> 117.217758) + // int lon_deg = gps_data[14] - '0'; // 获取经度的度数 117 + // int lon_min = gps_data[15] - '0'; // 获取经度的分钟数 13 + // float lon_min_decimal = atof(&gps_data[16]); // 获取经度的小数部分 0655 + // gps_info->longitude = lon_deg + (lon_min + lon_min_decimal / 10000) / 60.0; + + // parse_gps(gpsbac.c_str(),gps_info); + *gps_info = parseQGPSLOCFull(gpsbac); return gpsbac; } diff --git a/src/main.cpp b/src/main.cpp index b27d46e..a6db7fe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -157,8 +157,8 @@ bool UpdateData(String path,uint8_t *data, size_t lenth, String Contenttype = "" void setup() { - sun_latitude = 39.5; - sun_longitude = 117.6; + sun_latitude = 39.0864; + sun_longitude = 117.113055; // Serial2.begin(115200, SERIAL_8N1, SIMUART_RX, SIMUART_TX); //关闭光谱仪 pinMode(36,OUTPUT); @@ -169,12 +169,8 @@ void setup() vTaskDelay(1000); Serial0.begin(115200); + Serial.begin(115200); - // while (1) - // { - // Serial0.println("66666666666666666666666"); - // vTaskDelay(1000); - // } log_init(); @@ -280,6 +276,19 @@ void setup() if(sys_sd_doc["status_4g"] == "open_4g") { gsmm_mqtt_init(STRSensorInfos_structure.serialnumber); + // while (1) + // { + + // ////获取GPS + // write_log(log_path,"test gps",10); + // gps_struct gps_structure; + // String gpsbac = get_GPS(&gps_structure); + // write_log(log_path,gpsbac,10); + // Serial.printf("time: %d-%d-%d %d:%d:%d\n",gps_structure.year,gps_structure.month,gps_structure.day,gps_structure.hour,gps_structure.minute,gps_structure.second); + // Serial.printf("latitude: %d ,longitude : %d\n",gps_structure.latitude,gps_structure.longitude); + + // vTaskDelay(1000); + // } xTaskCreatePinnedToCore(task_4G_mode, "task_4G_mode",1024*(20),NULL, 1,NULL, 1); xTaskCreatePinnedToCore(OTA_task, "OTA_task",1024*(10),NULL, 1,NULL, 1); @@ -347,8 +356,9 @@ void Task0(void *pvParameters) if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { caiji_state = 2; + xSemaphoreGive(xMutexInventory); } - xSemaphoreGive(xMutexInventory); + is11Sensor->TakeOneJob(); if (atuo_return == 1) { @@ -360,8 +370,9 @@ void Task0(void *pvParameters) if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { caiji_state = 2; + xSemaphoreGive(xMutexInventory); } - xSemaphoreGive(xMutexInventory); + is11Sensor->TakeOneJob(); if (atuo_return == 1) { @@ -378,8 +389,9 @@ void Task0(void *pvParameters) if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { caiji_state = 2; + xSemaphoreGive(xMutexInventory); } - xSemaphoreGive(xMutexInventory); + is11Sensor->advanced_mode(advanced_direction,advanced_shutter_time,advanced_collect_times,advanced_remove_dark); uint_work_task0 = 100; break; @@ -388,8 +400,9 @@ void Task0(void *pvParameters) if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { caiji_state = 2; + xSemaphoreGive(xMutexInventory); } - xSemaphoreGive(xMutexInventory); + is11Sensor->opt(advanced_direction); uint_work_task0 = 100; break; @@ -398,8 +411,9 @@ void Task0(void *pvParameters) if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { caiji_state = 2; + xSemaphoreGive(xMutexInventory); } - xSemaphoreGive(xMutexInventory); + is11Sensor->calculation(calculation_bochang1,calculation_bochang2); uint_work_task0 = 100; @@ -536,7 +550,7 @@ void Task1(void *pvParameters) String path_b = "/gaugpu_data"; for(int i=24;i<255 ;i++) { - for (uint8_t j = 1; j < 13; i++) + for (uint8_t j = 1; j < 13; j++) { String path_a = path_b + "/" +String(i)+ "/" +String(j); if(SD_MMC.exists(path_a)) @@ -641,8 +655,9 @@ void Task1(void *pvParameters) if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { caiji_mode = 0; + xSemaphoreGive(xMutexInventory); } - xSemaphoreGive(xMutexInventory); + } } vTaskDelay(1000 * 1); @@ -721,7 +736,7 @@ void Task1(void *pvParameters) if(count == 10) { write_log(log_path,"temperature " + String(n) +":" + String(temperature[n]),20); - count == 0; + count = 0; }else write_log(log_path,"temperature " + String(n) +":" + String(temperature[n]),10); } @@ -871,6 +886,7 @@ void task_4G_mode(void *pvParameters) doc_4G["temperature 7 : "] = temperature[7]; break; } + Serial.println("uptodate temperature " + String(n) +":" + String(temperature[n])); } if(warn_sta) { @@ -913,6 +929,37 @@ void task_4G_mode(void *pvParameters) now.second = second; rtc.setDateTime(&now); } + + ////获取GPS + gps_struct gps_structure; + String gpsbac = get_GPS(&gps_structure); + if(gpsbac == "-1") write_log(log_path,"no gps",10); + else if(gpsbac != "-1") + { + + if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) + { + sun_latitude = gps_structure.latitude; + sun_longitude = gps_structure.longitude; + xSemaphoreGive(xMutexInventory); + } + + Serial.println("gps_structure.latitude " + String(gps_structure.latitude)); + Serial.println("gps_structure.longitude " + String(gps_structure.longitude)); + + // gps_structure.year = gps_structure.year - 2000; + // if(now.year != gps_structure.year || now.month != gps_structure.month || now.day != gps_structure.day || now.hour != gps_structure.hour || (fabs(now.minute - net_structure.minute)>5 )) + // { + // now.year = gps_structure.year; + // now.month = gps_structure.month; + // now.day = gps_structure.day; + // now.hour = gps_structure.hour; + // now.minute = gps_structure.minute; + // now.second = gps_structure.second; + // // rtc.setDateTime(&now); + // } + // last_day = now.day; + } } float now_time = now.hour + now.minute/100; @@ -955,6 +1002,9 @@ void task_4G_mode(void *pvParameters) vTaskDelay(10); UpdateData("/HyperspectralV2/DataUpload.php",data , sizeof(http_head) + sizeof(IS11_datastruct_fanshelv),HTTP_METHOD_POST); } + Serial.println("http_head.lat " + String(http_head.lat)); + Serial.println("http_head.lon " + String(http_head.lon)); + vTaskDelay(1000 * time_interval); } vTaskDelay(10); @@ -1082,8 +1132,9 @@ void receive_command_unpack(uint8_t * read_buf,uint16_t data_length,uint8_t port if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { caiji_mode = 1; + xSemaphoreGive(xMutexInventory); } - xSemaphoreGive(xMutexInventory); + uint8_t a = 0x01; send_lenth = IRIS_Protocol_Pack(0X62,1,&a,send_buff); @@ -1171,8 +1222,9 @@ void receive_command_unpack(uint8_t * read_buf,uint16_t data_length,uint8_t port calculation_bochang2 = b; caiji_mode = 6; + xSemaphoreGive(xMutexInventory); } - xSemaphoreGive(xMutexInventory); + // uint8_t dd = 0x01; is11Sensor->calculation_value = 0; @@ -1208,6 +1260,7 @@ void receive_command_unpack(uint8_t * read_buf,uint16_t data_length,uint8_t port if(port_type == 1) wb485Serial.write(send_buff,send_lenth); else if(port_type == 2) mqtt_write(send_buff,send_lenth); + sys_sd_doc["GPS_mode"]== "manual"; sys_sd_doc["latitude"] = sun_latitude; sys_sd_doc["longitude"] = sun_longitude; String send_str = ""; @@ -2444,8 +2497,9 @@ void json_command(uint8_t port_type) file.close(); save = false; } + xSemaphoreGive(xMutexInventory); } - xSemaphoreGive(xMutexInventory); + } @@ -2544,12 +2598,16 @@ void sys_info_init() write_log(log_path,"servo_offset_angle_down" + String(a),10); servo_offset(a,0); - sys_sd_doc["latitude"] = doc["latitude"]; - sys_sd_doc["longitude"] = doc["longitude"]; - sun_latitude = doc["latitude"]; - sun_longitude = doc["longitude"]; - write_log(log_path,"latitude" + String(sun_latitude),10); - write_log(log_path,"longitude" + String(sun_longitude),10); + if(doc["GPS_mode"]== "manual") + { + sys_sd_doc["latitude"] = doc["latitude"]; + sys_sd_doc["longitude"] = doc["longitude"]; + sun_latitude = doc["latitude"]; + sun_longitude = doc["longitude"]; + write_log(log_path,"latitude" + String(sun_latitude),10); + write_log(log_path,"longitude" + String(sun_longitude),10); + } + sys_sd_doc["bochangxishu"]["a0"] = STRSensorInfos_structure.a1;