71 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /****************************************************************************
 | |
| 
 | |
| Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | |
| 
 | |
| This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | |
| be copied by any method or incorporated into another program without
 | |
| the express written consent of Aerospace C.Power. This Information or any portion
 | |
| thereof remains the property of Aerospace C.Power. The Information contained herein
 | |
| is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | |
| liability for its use in any way and conveys no license or title under
 | |
| any patent or copyright and makes no representation or warranty that this
 | |
| Information is free from patent or copyright infringement.
 | |
| 
 | |
| ****************************************************************************/
 | |
| 
 | |
| /* iot common header files */
 | |
| #include "os_types_api.h"
 | |
| 
 | |
| /* iot common header files */
 | |
| #include "iot_crc_api.h"
 | |
| #include "iot_io_api.h"
 | |
| 
 | |
| /* smart grid internal header files */
 | |
| #include "iot_sg_fr.h"
 | |
| #include "proto_acm.h"
 | |
| 
 | |
| #if (IOT_SMART_GRID_CCO_ACM_ENABLE)
 | |
| 
 | |
| void proto_acm_check_frame_handler(uint8_t *buffer, uint32_t buffer_len,
 | |
|     bool_t *is_frame)
 | |
| {
 | |
|     uint16_t frame_len;
 | |
|     uint16_t fcs, fcs_offset;
 | |
|     uint16_t frame_min_len;
 | |
| 
 | |
|     frame_min_len = sizeof(proto_acm_hdr_t) + sizeof(proto_acm_tail_t);
 | |
| 
 | |
|     if (buffer_len < frame_min_len) {
 | |
|         *is_frame = false;
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     if (buffer[0] != PROTO_ACM_SOF_BYTE
 | |
|         || buffer[buffer_len - 1] != PROTO_ACM_EOF_BYTE) {
 | |
|         *is_frame = false;
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     frame_len = (uint16_t)buffer[2];
 | |
|     frame_len = (frame_len << 8) | (uint16_t)buffer[1];
 | |
|     frame_len += frame_min_len;
 | |
| 
 | |
|     if (frame_len != buffer_len) {
 | |
|         *is_frame = false;
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     fcs_offset = (uint16_t)(buffer_len - sizeof(proto_acm_tail_t));
 | |
|     fcs = (uint16_t)buffer[fcs_offset + 1];
 | |
|     fcs = (fcs << 8) | (uint16_t)buffer[fcs_offset];
 | |
|     if (fcs != iot_getcrc16(&buffer[PROTO_ACM_SOF_BYTE_LEN],
 | |
|         buffer_len - PROTO_ACM_SOF_BYTE_LEN - sizeof(proto_acm_tail_t),
 | |
|         IOT_CRC16_TYPE_X25)) {
 | |
|         /* checksum failure */
 | |
|         *is_frame = false;
 | |
|         return;
 | |
|     }
 | |
|     *is_frame = true;
 | |
| }
 | |
| 
 | |
| #endif  /* IOT_SMART_GRID_CCO_ACM_ENABLE */ |