/* Check the slave it is addressed to, if the function code is correct and supported, if the registers are within the register map and if the CRC is correct. */
void modbus_check_request(struct modbus_slave *dev, uint8_t *req, uint16_t req_size)
/* Check the slave it is addressed to, if the function code is correct and supported, if the registers are within the register map and if the CRC is correct. */
void modbus_check_request(struct modbus_slave *dev, uint8_t *req, uint16_t req_size)
{
	if(req[MODBUS_ADDRESS_PLACE] != dev->slave_id) {
		dev->state = MBSLAVE_IDLE;
		return;
	}
	if(modbus_check_crc(req, req_size) == -1) {
		dev->state = MBSLAVE_IDLE;
		return;
	}
	modbus_check_illegal_func(dev, req, req_size);
	if(dev->exception != MODBUS_EXCEPTION_NO_PROBLEM)
		return;
	modbus_check_data_range(dev, req);
	if(dev->exception != MODBUS_EXCEPTION_NO_PROBLEM)
		return;
	dev->exception = MODBUS_EXCEPTION_NO_PROBLEM;
	dev->state = MBSLAVE_PROCESS;
}