4848//
4949static DXLLibErrorCode_t parse_dxl1_0_packet (InfoToParseDXLPacket_t* p_parse_packet, uint8_t recv_data);
5050static DXLLibErrorCode_t parse_dxl2_0_packet (InfoToParseDXLPacket_t* p_parse_packet, uint8_t recv_data);
51- static DXLLibErrorCode_t fast_parse_dxl2_0_packet (InfoToParseDXLPacket_t* p_parse_packet, uint8_t recv_data, InfoFastSyncReadInst_t *sync_read, InfoFastBulkReadInst_t *bulk_read);
51+ static DXLLibErrorCode_t fast_parse_dxl2_0_packet (InfoToParseDXLPacket_t* p_parse_packet, uint8_t recv_data, InfoSyncReadInst_t *sync_read, InfoBulkReadInst_t *bulk_read);
5252
5353static DXLLibErrorCode_t add_param_to_dxl1_0_packet (InfoToMakeDXLPacket_t* p_make_packet, uint8_t *p_param, uint16_t param_len);
5454static DXLLibErrorCode_t add_param_to_dxl2_0_packet (InfoToMakeDXLPacket_t* p_make_packet, uint8_t *p_param, uint16_t param_len);
@@ -349,19 +349,14 @@ DXLLibErrorCode_t begin_parse_dxl_packet(InfoToParseDXLPacket_t* p_parse_packet,
349349 return DXL_LIB_OK;
350350}
351351
352- DXLLibErrorCode_t fast_begin_parse_dxl_packet (InfoToParseDXLPacket_t* p_parse_packet, uint8_t protocol_ver)// , uint8_t* p_param_buf, uint16_t param_buf_capacity, uint8_t xel_count)
352+ DXLLibErrorCode_t fast_begin_parse_dxl_packet (InfoToParseDXLPacket_t* p_parse_packet, uint8_t protocol_ver)
353353{
354- // if(param_buf_capacity > 0 && p_param_buf == NULL){
355- // return DXL_LIB_ERROR_NULLPTR;
356- // }
357-
358354 if (protocol_ver != 2 )
359355 return DXL_LIB_ERROR_INVAILD_PROTOCOL_VERSION;
360356
361357 p_parse_packet->protocol_ver = protocol_ver;
362- // p_parse_packet->p_param_buf = p_param_buf;
363- // p_parse_packet->param_buf_capacity = param_buf_capacity;
364- // p_parse_packet->xel_count = xel_count;
358+ p_parse_packet->p_param_buf = nullptr ;
359+ p_parse_packet->param_buf_capacity = 0 ;
365360 p_parse_packet->is_init = true ;
366361
367362 return DXL_LIB_OK;
@@ -389,7 +384,7 @@ DXLLibErrorCode_t parse_dxl_packet(InfoToParseDXLPacket_t* p_parse_packet, uint8
389384}
390385
391386DXLLibErrorCode_t fast_parse_dxl_packet (InfoToParseDXLPacket_t* p_parse_packet, uint8_t recv_data,
392- InfoFastSyncReadInst_t *sync_read, InfoFastBulkReadInst_t *bulk_read)
387+ InfoSyncReadInst_t *sync_read, InfoBulkReadInst_t *bulk_read)
393388{
394389 if (p_parse_packet == NULL )
395390 return DXL_LIB_ERROR_NULLPTR;
@@ -689,7 +684,7 @@ static DXLLibErrorCode_t parse_dxl2_0_packet(InfoToParseDXLPacket_t* p_parse_pac
689684
690685// fast_parse_dxl2_0_packet
691686static DXLLibErrorCode_t fast_parse_dxl2_0_packet (InfoToParseDXLPacket_t* p_parse_packet, uint8_t recv_data,
692- InfoFastSyncReadInst_t *sync_read, InfoFastBulkReadInst_t *bulk_read)
687+ InfoSyncReadInst_t *sync_read, InfoBulkReadInst_t *bulk_read)
693688{
694689 DXLLibErrorCode_t ret = DXL_LIB_PROCEEDING;
695690
@@ -762,25 +757,16 @@ static DXLLibErrorCode_t fast_parse_dxl2_0_packet(InfoToParseDXLPacket_t* p_pars
762757 update_dxl_crc (&p_parse_packet->calculated_crc , recv_data);
763758 p_parse_packet->err_idx = 0 ;
764759 p_parse_packet->recv_param_len = 0 ;
765- p_parse_packet->param_count = 0 ;
766- // p_parse_packet->check_xel_count = 0;
767760
768761 if (recv_data == DXL_INST_STATUS){
769762 p_parse_packet->parse_state = DXL2_0_PACKET_PARSING_STATE_ERROR;
770763 if (p_parse_packet->packet_len < 4 ){ // 4 = Instruction(1)+Error(1)+CRC(2)
771764 ret = DXL_LIB_ERROR_LENGTH;
772765 p_parse_packet->parse_state = DXL2_0_PACKET_PARSING_STATE_IDLE;
773- // }else if(p_parse_packet->packet_len > ((p_parse_packet->param_buf_capacity+4) * p_parse_packet->xel_count) + 1 ){ // 4 = Instruction(1)+Error(1)+CRC(2)
774- // ret = DXL_LIB_ERROR_BUFFER_OVERFLOW;
775- // p_parse_packet->parse_state = DXL2_0_PACKET_PARSING_STATE_IDLE;
776766 }else {
777767 p_parse_packet->parse_state = DXL2_0_PACKET_PARSING_STATE_ERROR;
778768 }
779769 }else {
780- // if(p_parse_packet->packet_len > p_parse_packet->param_buf_capacity+3){ // 3 = Instruction(1)+CRC(2)
781- // ret = DXL_LIB_ERROR_BUFFER_OVERFLOW;
782- // p_parse_packet->parse_state = DXL2_0_PACKET_PARSING_STATE_IDLE;
783- // }else
784770 if (p_parse_packet->packet_len == 3 ){ // 3 = Instruction(1)+CRC(2)
785771 p_parse_packet->parse_state = DXL2_0_PACKET_PARSING_STATE_CRC_L;
786772 }else {
@@ -797,55 +783,62 @@ static DXLLibErrorCode_t fast_parse_dxl2_0_packet(InfoToParseDXLPacket_t* p_pars
797783 break ;
798784 }
799785 p_parse_packet->parse_state = DXL2_0_PACKET_PARSING_STATE_PARAM;
786+
787+ // p_parse_packet->fast_param_state = DXL_FAST_PARAM_ERROR;
788+ p_parse_packet->xel_index = 0 ;
789+ p_parse_packet->buf_index = 0 ;
790+ if (nullptr != sync_read)
791+ sync_read->p_xels [0 ].error = recv_data;
792+ else if (nullptr != bulk_read)
793+ bulk_read->p_xels [0 ].error = recv_data;
794+ p_parse_packet->fast_param_state = DXL_FAST_PARAM_ID;
800795 break ;
801796
802797 case DXL2_0_PACKET_PARSING_STATE_PARAM:
803798 update_dxl_crc (&p_parse_packet->calculated_crc , recv_data);
804799 // https://emanual.robotis.com/docs/en/dxl/protocol2/#parameter
805800 if (nullptr != sync_read) {
806- int count = p_parse_packet->param_count + 1 ;
807- int size = sync_read->addr_length + 4 ; // 4 = Error(1) + ID(1) + CRC(2)
808- int xel_index = count / size;
809- int index = count % size;
810- if ((1 < index) && (index < (size - 2 ))) { // {Error(1), ID(1), Data(N), CRC(2)}
811- index = index - 2 ;
812- sync_read->p_xels [xel_index].p_recv_buf [index] = recv_data;
813- }
814- p_parse_packet->param_count += 1 ;
815- p_parse_packet->recv_param_len += 1 ;
816- int length = (sync_read->addr_length + 4 ) * sync_read->xel_count - 3 ; // 4 = Error(1) + ID(1) + CRC(2), 3 = Error(1) + CRC(2)
817- if (p_parse_packet->recv_param_len == length) {
818- p_parse_packet->parse_state = DXL2_0_PACKET_PARSING_STATE_CRC_L;
801+ if (DXL_FAST_PARAM_ERROR == p_parse_packet->fast_param_state ) {
802+ sync_read->p_xels [p_parse_packet->xel_index ].error = recv_data;
803+ p_parse_packet->fast_param_state = DXL_FAST_PARAM_ID;
804+ } else if (DXL_FAST_PARAM_ID == p_parse_packet->fast_param_state ) {
805+ sync_read->p_xels [p_parse_packet->xel_index ].id = recv_data;
806+ p_parse_packet->fast_param_state = DXL_FAST_PARAM_DATA;
807+ } else if (DXL_FAST_PARAM_DATA == p_parse_packet->fast_param_state ) {
808+ sync_read->p_xels [p_parse_packet->xel_index ].p_recv_buf [p_parse_packet->buf_index ] = recv_data;
809+ p_parse_packet->buf_index ++;
810+ if (sync_read->addr_length == p_parse_packet->buf_index )
811+ p_parse_packet->fast_param_state = DXL_FAST_PARAM_CRC_L;
812+ } else if (DXL_FAST_PARAM_CRC_L == p_parse_packet->fast_param_state ) {
813+ p_parse_packet->fast_param_state = DXL_FAST_PARAM_CRC_H;
814+ } else if (DXL_FAST_PARAM_CRC_H == p_parse_packet->fast_param_state ) {
815+ p_parse_packet->xel_index ++;
816+ p_parse_packet->buf_index = 0 ;
817+ p_parse_packet->fast_param_state = DXL_FAST_PARAM_ERROR;
819818 }
820819 } else if (nullptr != bulk_read) {
821- int count = p_parse_packet->param_count + 1 ;
822- int start = 0 ;
823- int end = 0 ;
824- int xel_index = -1 ;
825- int index = -1 ;
826- for (uint8_t i = 0 ; i < bulk_read->xel_count ; i++) {
827- start = end;
828- end += (bulk_read->p_xels [i].addr_length + 4 ); // 4 = Error(1) + ID(1) + CRC(2)
829- if (((start + 1 ) < count) && (count < (end - 2 ))) {
830- xel_index = i;
831- index = count - start - 2 ;
832- break ;
833- }
834- }
835- if (-1 != xel_index) {
836- bulk_read->p_xels [xel_index].p_recv_buf [index] = recv_data;
837- }
838- p_parse_packet->param_count += 1 ;
839- p_parse_packet->recv_param_len += 1 ;
840- int length = 0 ;
841- for (int i = 0 ; i < bulk_read->xel_count ; i++) {
842- length += (bulk_read->p_xels [i].addr_length + 4 ); // 4 = Error(1) + ID(1) + CRC(2)
843- }
844- length -= 3 ; // 3 = Error(1) + CRC(2)
845- if (p_parse_packet->recv_param_len == length) {
846- p_parse_packet->parse_state = DXL2_0_PACKET_PARSING_STATE_CRC_L;
820+ if (DXL_FAST_PARAM_ERROR == p_parse_packet->fast_param_state ) {
821+ bulk_read->p_xels [p_parse_packet->xel_index ].error = recv_data;
822+ p_parse_packet->fast_param_state = DXL_FAST_PARAM_ID;
823+ } else if (DXL_FAST_PARAM_ID == p_parse_packet->fast_param_state ) {
824+ bulk_read->p_xels [p_parse_packet->xel_index ].id = recv_data;
825+ p_parse_packet->fast_param_state = DXL_FAST_PARAM_DATA;
826+ } else if (DXL_FAST_PARAM_DATA == p_parse_packet->fast_param_state ) {
827+ bulk_read->p_xels [p_parse_packet->xel_index ].p_recv_buf [p_parse_packet->buf_index ] = recv_data;
828+ p_parse_packet->buf_index ++;
829+ if (bulk_read->p_xels [p_parse_packet->xel_index ].addr_length == p_parse_packet->buf_index )
830+ p_parse_packet->fast_param_state = DXL_FAST_PARAM_CRC_L;
831+ } else if (DXL_FAST_PARAM_CRC_L == p_parse_packet->fast_param_state ) {
832+ p_parse_packet->fast_param_state = DXL_FAST_PARAM_CRC_H;
833+ } else if (DXL_FAST_PARAM_CRC_H == p_parse_packet->fast_param_state ) {
834+ p_parse_packet->xel_index ++;
835+ p_parse_packet->buf_index = 0 ;
836+ p_parse_packet->fast_param_state = DXL_FAST_PARAM_ERROR;
847837 }
848838 }
839+ p_parse_packet->recv_param_len += 1 ;
840+ if (p_parse_packet->recv_param_len == p_parse_packet->param_length )
841+ p_parse_packet->parse_state = DXL2_0_PACKET_PARSING_STATE_CRC_L;
849842 break ;
850843
851844 case DXL2_0_PACKET_PARSING_STATE_CRC_L:
0 commit comments