| | |
| | | #include "rs485_data_analysis_pro.h" |
| | | #include "rs485_read_data.h" |
| | | #include "mbcrc.h" |
| | | |
| | | FLOW_METER_DATA_T flow_meter_data_g; |
| | | |
| | | /************ͨÓÃmodbus¶Áȡ֡*************************/ |
| | | void sendModbusReadFrame(uint8_t slaveAddress,uint16_t dataAddress,uint8_t regNum) |
| | | { |
| | | uint16_t crc; |
| | | uint8_t sendFrame[8]; |
| | | |
| | | sendFrame[0] = slaveAddress; //´Ó»úµØÖ· |
| | | sendFrame[1] = 0x03; //¹¦ÄܺŠ|
| | | sendFrame[2] = dataAddress>>8; //Êý¾ÝµØÖ·¸ß8λ |
| | | sendFrame[3] = dataAddress&0x00FF; //Êý¾ÝµØÖ·µÍ8λ |
| | | sendFrame[4] = regNum>>8; //¶ÁÈ¡Êý¾Ý¸öÊý¸ß8λ |
| | | sendFrame[5] = regNum&0x00FF; //¶ÁÈ¡Êý¾Ý¸öÊýµÍ8λ |
| | | crc = usMBCRC16(0xFFFF,sendFrame,6); |
| | | sendFrame[6] = crc&0x00FF; //CRC16УÑéµÍ8λ |
| | | sendFrame[7] = crc>>8; //CRC16УÑé¸ß8λ |
| | | |
| | | //´®¿Ú·¢ËÍ |
| | | // RS485_Send_Data(sendFrame,8); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | //ÖØÖÃDMA½ÓÊÕ |
| | | |
| | | |
| | | } |
| | | |
| | | /************×Ô¶¨Òå¶Áȡ֡*************************/ |
| | | |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | /************¸÷ÐͺÅÊý¾Ý½âÎö*************************/ |
| | | //modbusÐÒé03¶ÁÈ¡ÏìÓ¦Êý¾Ýͳһ¼ì²é |
| | | ErrorStatus modbus03AnswerCheck(uint8_t * buf_p,uint8_t slaveAddress) |
| | | { |
| | | uint16_t crc; |
| | | uint8_t dataNum; |
| | | //Ö÷Òª¼ì²éCRC£¬¿¼ÂÇ´Ó»úµØÖ·ºÍ¹¦ÄÜÂëµÄ¼ì²é |
| | | if((slaveAddress!=buf_p[0])||(buf_p[1]!=0x03)) |
| | | return FAIL; |
| | | |
| | | |
| | | dataNum = buf_p[2]; |
| | | if(dataNum>250) |
| | | return FAIL; |
| | | crc = buf_p[3 + dataNum +1 ]; |
| | | crc = (crc<<8) +buf_p[3 + dataNum ]; |
| | | if(crc != usMBCRC16(0xFFFF,buf_p,3 + dataNum)) |
| | | return FAIL; |
| | | |
| | | return PASS; |
| | | } |
| | | |
| | | |
| | | ErrorStatus SIZHUMODBUSV2_0_dataAnalysis(uint8_t * buf_p,uint8_t slaveAddress) |
| | | { |
| | | uint32_t SC_Accumulation_zs; |
| | | uint16_t SC_Accumulation_xs; |
| | | uint32_t WC_Accumulation_zs; |
| | | uint16_t WC_Accumulation_xs; |
| | | uint32_t SC_Accumulation_zs_reverse; |
| | | uint16_t SC_Accumulation_xs_reverse; |
| | | uint32_t WC_Accumulation_zs_reverse; |
| | | uint16_t WC_Accumulation_xs_reverse; |
| | | |
| | | double WC_Accumulation_reverse; |
| | | double SC_Accumulation_reverse; |
| | | |
| | | if(modbus03AnswerCheck(buf_p,slaveAddress) == FAIL) |
| | | return FAIL; |
| | | |
| | | |
| | | arrayA_2_arrayB(buf_p + 3 , (uint8_t *)&WC_Accumulation_zs, 4, BIG_ENDIAN) ; |
| | | arrayA_2_arrayB(buf_p + 7 , (uint8_t *)&WC_Accumulation_xs, 2, BIG_ENDIAN) ; |
| | | arrayA_2_arrayB(buf_p + 14 , (uint8_t *)&WC_Accumulation_xs, 2, BIG_ENDIAN) ; |
| | | |
| | | return PASS; |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /**********************·µ»ØÊý¾Ý·ÖÎö*******************************/ |
| | | ErrorStatus rs485ComDataAnalysis(RS485_COM_UART_PARA_T * uart_para_p,uint16_t device_code,uint8_t slaveAddress) |
| | | { |
| | | uint8_t *buf_p; |
| | | if(uart_para_p->recv_length < 6) //ĿǰӦ¸ÃûÓöµ½¹ý·µ»ØÊý¾ÝÉÙÓÚ6×Ö½ÚµÄ |
| | | return FAIL; |
| | | |
| | | //ȥ0 |
| | | for(uint16_t count_i=0;count_i< RS485_COM_REC_BUF_LENGTH;count_i ++) |
| | | { |
| | | if(uart_para_p->recv_buf[count_i] !=0) |
| | | { |
| | | buf_p = &uart_para_p->recv_buf[count_i]; |
| | | break; |
| | | }else |
| | | { |
| | | if(count_i > (RS485_COM_REC_BUF_LENGTH >>2)) |
| | | { |
| | | //buf¹ý°ë¶¼ÊÇ0£¬Ö±½Ó·µ»ØFAIL£¬·ÀÖ¹ºóÃæÊý¾Ý´¦ÀíÔ½½ç |
| | | return FAIL; |
| | | } |
| | | } |
| | | } |
| | | |
| | | switch (device_code){ |
| | | |
| | | case SIZHUMODBUS1: return FAIL; |
| | | case SIZHUMODBUS2: return FAIL; |
| | | case SIZHUMODBUS3: return FAIL; |
| | | case SIZHUMODBUSV2_0: return SIZHUMODBUSV2_0_dataAnalysis(buf_p,slaveAddress); |
| | | case TIANXINCUSTOM: return FAIL; |
| | | case TIANXINMODBUS: return FAIL; |
| | | //ÐèÒª²¹³ä...... |
| | | default:return FAIL; |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |