unsigned char ReadPms5003(void) //void DataReflash(void) // 数据解析 { uint16_t Buffer_Len; //缓冲区长度 unsigned int PM1_0_CF,PM2_5_CF,PM10_CF,PM1_0,PM2_5,PM10,Count0_3nm,PCount0_5nm,Count1_0nm,Count2_5nm,Count5_0nm,Count10nm; unsigned int temp; Buffer_Len = (uint16_t)((PM_Sensor_RxBuffer[2] << 8) | PM_Sensor_RxBuffer[3]); if(Buffer_Len == 28) //PMS1003/5003 { PM_Sensor_Data.Buffer_Len = 36; //2*17+2= //PM_Sensor_Data.Buffer_Len = 28; //2*13+2= PM1_0_CF = (uint16_t)((PM_Sensor_RxBuffer[4]<<8) | PM_Sensor_RxBuffer[5]); PM2_5_CF = (uint16_t)((PM_Sensor_RxBuffer[6]<<8) | PM_Sensor_RxBuffer[7]); PM10_CF = (uint16_t)((PM_Sensor_RxBuffer[8]<<8) | PM_Sensor_RxBuffer[9]); PM1_0 = (uint16_t)((PM_Sensor_RxBuffer[10]<<8) | PM_Sensor_RxBuffer[11]); PM2_5 = (uint16_t)((PM_Sensor_RxBuffer[12]<<8) | PM_Sensor_RxBuffer[13]); PM10 = (uint16_t)((PM_Sensor_RxBuffer[14]<<8) | PM_Sensor_RxBuffer[15]); Count0_3nm = (uint16_t)((PM_Sensor_RxBuffer[16]<<8) | PM_Sensor_RxBuffer[17]); PCount0_5nm = (uint16_t)((PM_Sensor_RxBuffer[18]<<8) | PM_Sensor_RxBuffer[19]); Count1_0nm = (uint16_t)((PM_Sensor_RxBuffer[20]<<8) | PM_Sensor_RxBuffer[21]); Count2_5nm = (uint16_t)((PM_Sensor_RxBuffer[22]<<8) | PM_Sensor_RxBuffer[23]); Count5_0nm = (uint16_t)((PM_Sensor_RxBuffer[24]<<8) | PM_Sensor_RxBuffer[25]); Count10nm = (uint16_t)((PM_Sensor_RxBuffer[26]<<8) | PM_Sensor_RxBuffer[27]); } temp=PM1_0_CF,PM2_5_CF,PM10_CF,PM1_0,PM2_5,PM10,Count0_3nm,PCount0_5nm,Count1_0nm,Count2_5nm,Count5_0nm,Count10nm; return temp; }
时间: 2024-02-26 08:54:37 浏览: 48
cls_multi_uchar.rar_Linux/Unix编程_Unix_Linux_
这段代码是一个函数,它的作用是读取 PMS5003 颗粒物传感器的数据,并把读取到的数据解析出来存储到相应的变量中。函数的返回值是一个 unsigned char 类型的变量 temp,但是在函数中没有对 temp 进行赋值,也没有对其它变量进行操作,所以该函数的实际作用并不明确。
另外,函数中的最后一行代码 "return temp;" 并没有正确地返回解析后的数据,因为 temp 是一个无符号整型变量,而函数的返回值类型是 unsigned char,存在类型转换问题。因此,如果需要正确返回解析后的数据,需要修改函数的返回值类型和返回值。
阅读全文