123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- #include "tem.h"
- #include "usart.h"
- Tem_Inf tem_inf[SENSOR_DEEP];
- //extern void Pressure_state(uint16_t CangNum);
- void Tem_Init(void)
- {
- }
- uint8_t Parse_Tem(uint8_t* data, Tem_Tpye type)
- {
- uint8_t cang_id = data[0] - TEM_STARTADDR;
- uint8_t error = 0;
- uint16_t ModbusCRC;
- uint16_t ADC_Value1, ADC_Value2;
- float voltage1, voltage2;
- uint8_t i=0;
- typedef union{
- float value;
- uint8_t arr[4];
- }Hex_to_float;
-
- static Hex_to_float hex_to_float;
- //tem_inf[cang_id].RTData_Num = 1;//三点测温
- //tem_inf[cang_id].ErrorCnt = 0;
- if(Tem_FST100_611 == type){ //一次获取两个仓的温度数据
-
- ModbusCRC = data[7]<<8;
- ModbusCRC |= data[8];
-
- if(data[1]!=0x03) //校验读写属性
- {
- error = 1;
- }
- else if(data[2] != 0x04) //校验数据长度
- {
- error = 1;
- }
- else if(ModbusCRC != LIB_CRC_MODBUS(data,7)) //校验CRC
- {
- error = 1;
- }
- if(0 == error){
- tem_inf[cang_id].RTData_Num = 1;
- tem_inf[cang_id].ErrorCnt = 0;
- tem_inf[cang_id].Error = 0;
- tem_inf[cang_id+1].RTData_Num = 1;
- tem_inf[cang_id+1].ErrorCnt = 0;
- tem_inf[cang_id+1].Error = 0;
- ADC_Value1 = data[3]<<8|data[4];
- ADC_Value2 = data[5]<<8|data[6];
- voltage1 = ADC_Value1*(1.0)*5/4096; // 0-5V 12bit
- voltage2 = ADC_Value2*(1.0)*5/4096;
- tem_inf[cang_id].temperature1 = (voltage1-1.5)*(120+40)/(4.5-0.5);
- tem_inf[cang_id+1].temperature1 = (voltage2-1.5)*(120+40)/(4.5-0.5);
- }
- }else if(Tem_HUATIAN_THREE == type){
- if(data[1]!=0x03) //校验读写属性
- {
- error = 1;
- }
- else if(data[2] != 0x02) //校验数据长度
- {
- error = 1;
- }
- else if(ModbusCRC != LIB_CRC_MODBUS(data,5)) //校验CRC
- {
- error = 1;
- }
- if(0 == error){
- //do nothing
- }
- }else if(Tem_FST100_1007 == type){
- ModbusCRC = data[7]<<8;
- ModbusCRC |= data[8];
-
- if(data[1]!=0x03) //校验读写属性
- {
- error = 1;
- }
- else if(data[2] != 0x04) //校验数据长度
- {
- error = 1;
- }
- else if(ModbusCRC != LIB_CRC_MODBUS(data,7)) //校验CRC
- {
- error = 1;
- }
- if(0 == error){
- tem_inf[cang_id].ErrorCnt = 0;
- tem_inf[cang_id].Error = 0;
- tem_inf[cang_id].RTData_Num = 1;
-
-
- hex_to_float.arr[0] = data[6];
- hex_to_float.arr[1] = data[5];
- hex_to_float.arr[2] = data[4];
- hex_to_float.arr[3] = data[3];
- tem_inf[cang_id].temperature1 = hex_to_float.value;
-
- }else{
- Tem_Error(data[0]);
- }
- }
- return error;
-
- }
- void Tem_Error(uint8_t addr)
- {
- uint8_t id = addr - TEM_STARTADDR;
- Cang_Inf* pcang = &cang_inf;
-
- if(Tem_FST100_611 == pcang->Temperture){
- tem_inf[id].ErrorCnt++;
- tem_inf[id+1].ErrorCnt++;
-
- if (tem_inf[id].ErrorCnt > pcang->sensorBusMaxReTry)
- {
- tem_inf[id].ErrorCnt = pcang->sensorBusMaxReTry + 1;
- tem_inf[id].Error = 1;
- tem_inf[id+1].ErrorCnt = pcang->sensorBusMaxReTry + 1;
- tem_inf[id+1].Error = 1;
- }
- }
-
- }
|