Compare commits
2 Commits
ef4eae6128
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 9014267de0 | |||
| 12904d5507 |
@ -79,10 +79,25 @@ uint8_t DS18b20_init()
|
||||
void getall_temp(float *temp)
|
||||
{
|
||||
DS18b20.requestTemperatures(); // Send the command to get temperatures
|
||||
for(int8_t i ;i<temp_number;i++)
|
||||
// vTaskDelay(1000);
|
||||
|
||||
for(int8_t i =0 ;i<temp_number;i++)
|
||||
{
|
||||
temp[i] = DS18b20.getTempC(p[i]);
|
||||
// temp[i] = getone_temp(i);
|
||||
uint32_t n = 0;
|
||||
while(temp[i] < -110)
|
||||
{
|
||||
vTaskDelay(100);
|
||||
// temp[i] = DS18b20.getTempC(p[i]);
|
||||
temp[i] = getone_temp(i);
|
||||
n++;
|
||||
if (n>40)
|
||||
{
|
||||
write_log(log_path,"ds18b20 get temperature failed",10);
|
||||
// return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// write_log(log_path,"get temperatures ok",10);
|
||||
|
||||
@ -507,7 +507,7 @@ void SensorIS11::TakeOneJob1(bool dingbing)
|
||||
|
||||
index++;
|
||||
work_progress = 100 ;
|
||||
IS11_datastruct_fanshelv.NCa == 0;
|
||||
IS11_datastruct_fanshelv.NCa = 0;
|
||||
write_log(log_path,"take one job end.",20);
|
||||
}
|
||||
|
||||
@ -684,7 +684,7 @@ void SensorIS11::TakeOneJob()
|
||||
|
||||
|
||||
work_progress = 100;
|
||||
IS11_datastruct_fanshelv.NCa == 0;
|
||||
IS11_datastruct_fanshelv.NCa = 0;
|
||||
write_log(log_path,"take one job end.",10);
|
||||
}
|
||||
|
||||
@ -879,7 +879,7 @@ void SensorIS11::get_fanshelv()
|
||||
IS11_datastruct_fanshelv.NCa = IS11_datastruct_up.NCa;
|
||||
IS11_datastruct_fanshelv.NCb = IS11_datastruct_up.NCb;
|
||||
IS11_datastruct_fanshelv.NCc = IS11_datastruct_up.NCc;
|
||||
IS11_datastruct_fanshelv.NCc = 0;
|
||||
// IS11_datastruct_fanshelv.NCc = 0;
|
||||
IS11_datastruct_fanshelv.shutter_time = IS11_datastruct_up.shutter_time;
|
||||
IS11_datastruct_fanshelv.index = IS11_datastruct_up.index;
|
||||
for(int i = 0; i < 8;i++)
|
||||
@ -894,6 +894,9 @@ void SensorIS11::get_fanshelv()
|
||||
IS11_datastruct_fanshelv.data[i] =IS11_datastruct_fanshelv.data[i]*fanshelv_struct.gain[i];
|
||||
}
|
||||
}
|
||||
// Serial0.println("fanshelv");
|
||||
Serial0.printf("fanshelv_struct.data[%d] = %f\n",1,IS11_datastruct_fanshelv.data[0]);
|
||||
Serial0.printf("fanshelv_struct.data[%d] = %f\n",2047,IS11_datastruct_fanshelv.data[2047]);
|
||||
IS11_datastruct_fanshelv.NCa = 1;
|
||||
}
|
||||
|
||||
@ -1183,7 +1186,7 @@ void SensorIS11::advanced_mode(u_int32_t direction,u_int32_t shutter_time,u_int3
|
||||
}
|
||||
SetShutter(1);
|
||||
servo_off();
|
||||
IS11_datastruct_fanshelv.NCa == 0;
|
||||
IS11_datastruct_fanshelv.NCa = 0;
|
||||
work_progress = 100;
|
||||
}
|
||||
|
||||
|
||||
@ -244,6 +244,65 @@ String getnetData()
|
||||
xEventGroupSetBits(http_event_group, Http_stop_bit);
|
||||
return body;
|
||||
}
|
||||
|
||||
double convertDMSToDecimal(String dms) {
|
||||
if (dms.length() < 2) return 0;
|
||||
double val = dms.substring(0, dms.length() - 1).toDouble();
|
||||
char dir = dms.charAt(dms.length() - 1);
|
||||
|
||||
int degrees = int(val / 100);
|
||||
double minutes = val - degrees * 100;
|
||||
double decimal = degrees + minutes / 60.0;
|
||||
|
||||
if (dir == 'S' || dir == 'W') decimal = -decimal;
|
||||
return decimal;
|
||||
}
|
||||
|
||||
gps_struct parseQGPSLOCFull(String gpsStr) {
|
||||
gps_struct data;
|
||||
|
||||
// 1. 提取UTC时间
|
||||
int idx1 = gpsStr.indexOf(":") + 2;
|
||||
int idx2 = gpsStr.indexOf(",", idx1);
|
||||
String timeStr = gpsStr.substring(idx1, idx2);
|
||||
|
||||
if (timeStr.length() >= 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;
|
||||
}
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ void log_init()
|
||||
|
||||
void write_log(String path,String write_data,unsigned char level)
|
||||
{
|
||||
if(level <5) {
|
||||
if(level <50) {
|
||||
U0_Serial.println(write_data);
|
||||
// Serial0.println(write_data);
|
||||
}
|
||||
|
||||
118
src/main.cpp
118
src/main.cpp
@ -157,8 +157,8 @@ bool UpdateData(String path,uint8_t *data, size_t lenth, String Contenttype = ""
|
||||
|
||||
void setup()
|
||||
{
|
||||
sun_latitude = 39.6;
|
||||
sun_longitude = 116.3;
|
||||
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);
|
||||
@ -711,17 +726,17 @@ void Task1(void *pvParameters)
|
||||
|
||||
float temperature[8];
|
||||
getall_temp(temperature);
|
||||
vTaskDelay(100);
|
||||
getall_temp(temperature);
|
||||
vTaskDelay(100);
|
||||
getall_temp(temperature);
|
||||
// vTaskDelay(100);
|
||||
// getall_temp(temperature);
|
||||
// vTaskDelay(100);
|
||||
// getall_temp(temperature);
|
||||
for(uint8_t n=0; n<8 ;n++)
|
||||
{
|
||||
if(temperature[n] < -120) write_log(log_path,"temperature " + String(n+1) +":" + String(temperature[n])+"This sensor is broken.",20);
|
||||
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);
|
||||
}
|
||||
@ -853,9 +868,10 @@ void task_4G_mode(void *pvParameters)
|
||||
doc_4G["Voltage_value"] = Voltage;
|
||||
}
|
||||
|
||||
getall_temp(temperature);
|
||||
// getall_temp(temperature);
|
||||
for(uint8_t n=0; n<8 ;n++)
|
||||
{
|
||||
temperature[n] = IS11_datastruct_fanshelv.temprature[n];
|
||||
if((temperature[n] < -10) || (temperature[n] > 50))
|
||||
{
|
||||
warn_sta = true;
|
||||
@ -870,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)
|
||||
{
|
||||
@ -912,12 +929,44 @@ 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;
|
||||
Serial0.println("now_time " + String(now_time));
|
||||
Serial0.println("start_time " + String(start_time));
|
||||
Serial0.println("stop_time " + String(stop_time));
|
||||
// vTaskDelay(1000 * 1);
|
||||
if((now_time >= start_time) && (now_time < stop_time))
|
||||
{
|
||||
is11Sensor->TakeOneJob();
|
||||
@ -953,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);
|
||||
@ -1080,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);
|
||||
|
||||
@ -1169,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;
|
||||
@ -1206,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 = "";
|
||||
@ -2442,8 +2497,9 @@ void json_command(uint8_t port_type)
|
||||
file.close();
|
||||
save = false;
|
||||
}
|
||||
xSemaphoreGive(xMutexInventory);
|
||||
}
|
||||
xSemaphoreGive(xMutexInventory);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -2542,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;
|
||||
|
||||
Reference in New Issue
Block a user