void PMSensor_DataReflash(void) // PM传感器数据回流函数 解析函数 ¥¥重要函数¥¥ { uint16_t Buffer_Len; //缓冲区长度 memset(&PM_Sensor_Data,0,(sizeof(PM_Sensor_Data) - 2)); / /PM_Sensor_Data.PM2_5_Old should not set to zero Buffer_Len = (uint16_t)((PM_Sensor_RxBuffer[2] << 8) | PM_Sensor_RxBuffer[3]); if(Buffer_Len == 28) //PMS1003/5003 { PM_Sensor_Data.Buffer_Len = 28; PM_Sensor_Data.PM1_0_CF = (uint16_t)((PM_Sensor_RxBuffer[4]<<8) | PM_Sensor_RxBuffer[5]); PM_Sensor_Data.PM2_5_CF = (uint16_t)((PM_Sensor_RxBuffer[6]<<8) | PM_Sensor_RxBuffer[7]); PM_Sensor_Data.PM10_CF = (uint16_t)((PM_Sensor_RxBuffer[8]<<8) | PM_Sensor_RxBuffer[9]); PM_Sensor_Data.PM1_0 = (uint16_t)((PM_Sensor_RxBuffer[10]<<8) | PM_Sensor_RxBuffer[11]); PM_Sensor_Data.PM2_5 = (uint16_t)((PM_Sensor_RxBuffer[12]<<8) | PM_Sensor_RxBuffer[13]); PM_Sensor_Data.PM10 = (uint16_t)((PM_Sensor_RxBuffer[14]<<8) | PM_Sensor_RxBuffer[15]); PM_Sensor_Data.Count0_3nm = (uint16_t)((PM_Sensor_RxBuffer[16]<<8) | PM_Sensor_RxBuffer[17]); PM_Sensor_Data.Count0_5nm = (uint16_t)((PM_Sensor_RxBuffer[18]<<8) | PM_Sensor_RxBuffer[19]); PM_Sensor_Data.Count1_0nm = (uint16_t)((PM_Sensor_RxBuffer[20]<<8) | PM_Sensor_RxBuffer[21]); PM_Sensor_Data.Count2_5nm = (uint16_t)((PM_Sensor_RxBuffer[22]<<8) | PM_Sensor_RxBuffer[23]); PM_Sensor_Data.Count5_0nm = (uint16_t)((PM_Sensor_RxBuffer[24]<<8) | PM_Sensor_RxBuffer[25]); PM_Sensor_Data.Count10nm = (uint16_t)((PM_Sensor_RxBuffer[26]<<8) | PM_Sensor_RxBuffer[27]); }
时间: 2024-02-01 21:04:23 浏览: 76
这是一个 PM 传感器数据回流函数,用于解析从传感器接收到的数据。函数中首先通过 memset 函数将 PM_Sensor_Data 变量清零,然后根据从 PM 传感器接收到的数据解析出各个参数的值,并存储到 PM_Sensor_Data 变量中。其中,PM_Sensor_RxBuffer 是一个缓冲区,存储着从 PM 传感器接收到的原始数据。函数将缓冲区中的数据解析出来,分别赋值给 PM_Sensor_Data 变量的各个成员。函数中还包含了一些对 PM_Sensor_Data 变量成员的赋值操作,具体含义需要结合上下文来理解。
相关问题
void PMSensor_DataReflash(void) // PM传感器数据回流函数 解析函数 ¥¥重要函数¥¥ { uint16_t Buffer_Len; //缓冲区长度 memset(&PM_Sensor_Data,0,(sizeof(PM_Sensor_Data) - 2)); //PM_Sensor_Data.PM2_5_Old should not set to zero Buffer_Len = (uint16_t)((PM_Sensor_RxBuffer[2] << 8) | PM_Sensor_RxBuffer[3]); if(Buffer_Len == 28) //PMS1003/5003 { PM_Sensor_Data.Buffer_Len = 28; PM_Sensor_Data.PM1_0_CF = (uint16_t)((PM_Sensor_RxBuffer[4]<<8) | PM_Sensor_RxBuffer[5]); PM_Sensor_Data.PM2_5_CF = (uint16_t)((PM_Sensor_RxBuffer[6]<<8) | PM_Sensor_RxBuffer[7]); PM_Sensor_Data.PM10_CF = (uint16_t)((PM_Sensor_RxBuffer[8]<<8) | PM_Sensor_RxBuffer[9]); PM_Sensor_Data.PM1_0 = (uint16_t)((PM_Sensor_RxBuffer[10]<<8) | PM_Sensor_RxBuffer[11]); PM_Sensor_Data.PM2_5 = (uint16_t)((PM_Sensor_RxBuffer[12]<<8) | PM_Sensor_RxBuffer[13]); PM_Sensor_Data.PM10 = (uint16_t)((PM_Sensor_RxBuffer[14]<<8) | PM_Sensor_RxBuffer[15]); PM_Sensor_Data.Count0_3nm = (uint16_t)((PM_Sensor_RxBuffer[16]<<8) | PM_Sensor_RxBuffer[17]); PM_Sensor_Data.Count0_5nm = (uint16_t)((PM_Sensor_RxBuffer[18]<<8) | PM_Sensor_RxBuffer[19]); PM_Sensor_Data.Count1_0nm = (uint16_t)((PM_Sensor_RxBuffer[20]<<8) | PM_Sensor_RxBuffer[21]); PM_Sensor_Data.Count2_5nm = (uint16_t)((PM_Sensor_RxBuffer[22]<<8) | PM_Sensor_RxBuffer[23]); PM_Sensor_Data.Count5_0nm = (uint16_t)((PM_Sensor_RxBuffer[24]<<8) | PM_Sensor_RxBuffer[25]); PM_Sensor_Data.Count10nm = (uint16_t)((PM_Sensor_RxBuffer[26]<<8) | PM_Sensor_RxBuffer[27]); }
这是一个函数的具体实现,该函数的作用是解析从PM传感器接收到的数据,并将解析后的数据存储在PM_Sensor_Data结构体中。该函数首先将PM_Sensor_Data结构体中除了PM_Sensor_Data.PM2_5_Old之外的所有成员清零,然后根据接收到的数据长度(Buffer_Len)判断传感器类型,如果是PMS1003/5003,则将接收到的数据解析并存储在PM_Sensor_Data结构体中。具体来说,该函数将接收到的数据中每个数据点的数值提取出来,并存储在PM_Sensor_Data结构体的相应成员中。例如,PM_Sensor_Data.PM2_5_CF成员存储的是接收到的PM2.5的浓度值(单位:ug/m^3),PM_Sensor_Data.Count0_3nm成员存储的是0.3um以上颗粒物个数。
ErrorStatus Check_PMSensor_DataValid(void) // 检查数据有效函数 { uint16_t Cal_CheckSum; uint16_t Buffer_CheckSum; uint16_t Buffer_Len; uint8_t i; ErrorStatus Result = ERROR; if((PM_Sensor_RxBuffer[0] == 'B')&&(PM_Sensor_RxBuffer[1] == 'M')) { Buffer_Len = (uint16_t)((PM_Sensor_RxBuffer[2] << 8) | PM_Sensor_RxBuffer[3]); Buffer_CheckSum = (uint16_t)((PM_Sensor_RxBuffer[Buffer_Len + 2] << 8) | PM_Sensor_RxBuffer[Buffer_Len + 3]); Cal_CheckSum = 0; for(i=0;i<(Buffer_Len + 2);i++) { Cal_CheckSum += PM_Sensor_RxBuffer[i]; } if(Cal_CheckSum == Buffer_CheckSum) Result = SUCCESS; } return Result; }
这是一个函数的声明和实现,函数的作用是检查从PM传感器接收到的数据是否有效。该函数会计算接收到的数据的校验和和接收到的数据中的校验和是否相等,如果相等,则返回SUCCESS,否则返回ERROR。具体来说,该函数会检查接收到的数据头是否为“BM”,并获取接收到的数据长度(Buffer_Len)。然后,该函数会计算从数据头到数据尾(校验和之前)的所有数据的和(Cal_CheckSum),并将接收到的数据中的校验和(Buffer_CheckSum)与计算出的校验和(Cal_CheckSum)比较,判断接收到的数据是否有效。
阅读全文