new function mbus_frame_direction to get the direction of a frame
(slave to master or vice versa) extended mbus_frame_data_parse to check the direction of a frame
This commit is contained in:
		@@ -300,6 +300,19 @@ mbus_frame_type(mbus_frame *frame)
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//------------------------------------------------------------------------------
 | 
			
		||||
/// Return the M-Bus frame direction 
 | 
			
		||||
//------------------------------------------------------------------------------
 | 
			
		||||
int
 | 
			
		||||
mbus_frame_direction(mbus_frame *frame)
 | 
			
		||||
{
 | 
			
		||||
    if (frame)
 | 
			
		||||
    {
 | 
			
		||||
        return (frame->control & MBUS_CONTROL_MASK_DIR);
 | 
			
		||||
    }
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//------------------------------------------------------------------------------
 | 
			
		||||
/// Verify that parsed frame is a valid M-bus frame. 
 | 
			
		||||
//
 | 
			
		||||
@@ -2713,7 +2726,23 @@ mbus_data_variable_parse(mbus_frame *frame, mbus_data_variable *data)
 | 
			
		||||
int
 | 
			
		||||
mbus_frame_data_parse(mbus_frame *frame, mbus_frame_data *data)
 | 
			
		||||
{
 | 
			
		||||
    if (frame && data)
 | 
			
		||||
    char direction;
 | 
			
		||||
 | 
			
		||||
    if (frame == NULL)
 | 
			
		||||
    {
 | 
			
		||||
        snprintf(error_str, sizeof(error_str), "Got null pointer to frame.");
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    if (data == NULL)
 | 
			
		||||
    {
 | 
			
		||||
        snprintf(error_str, sizeof(error_str), "Got null pointer to data.");
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    direction = (frame->control & MBUS_CONTROL_MASK_DIR);
 | 
			
		||||
    
 | 
			
		||||
    if (direction == MBUS_CONTROL_MASK_DIR_S2M)
 | 
			
		||||
    {
 | 
			
		||||
        if (frame->control_information == MBUS_CONTROL_INFO_ERROR_GENERAL)
 | 
			
		||||
        {
 | 
			
		||||
@@ -2761,9 +2790,13 @@ mbus_frame_data_parse(mbus_frame *frame, mbus_frame_data *data)
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    snprintf(error_str, sizeof(error_str), "Got null pointer to frame or data.");
 | 
			
		||||
 | 
			
		||||
    else
 | 
			
		||||
    { 
 | 
			
		||||
        snprintf(error_str, sizeof(error_str), "Wrong direction in frame (master to slave)");
 | 
			
		||||
            
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
        
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user