Assignment number 1 - ab-passos/MFES-Group1 GitHub Wiki
Assignment number 1
MFES-Group1 MFES - Design by contract
FIRST TASK: Define a contract and implementation for a simple sensor in C.
INTERFACE:
RESPONSE SENSOR_A_request_x(
const SENSOR_request_scan_x_t *params_p /* in */,
int *id_p /* out */);
RESPONSE SENSOR_A_get_result_scan_x(
int id /* in */,
SENSOR_A_get_result_x_t *params_p /* out */);
RESPONSE SENSOR_A_request_y(
const SENSOR_request_scan_y_t *params_p /* in */,
int *id_p /* out */);
RESPONSE SENSOR_A_get_result_scan_y(
int id /* in */,
SENSOR_A_get_result_y_t *params_p /* out */);
#define RESPONSE int
#define OK 0
#define ERROR_SCAN_A 1
#define ERROR_GET_SCAN_A 2
SENSOR_request_scan_x_t:
double from;
double to;
SENSOR_A_get_result_x_t:
double value1;
double value2;
SENSOR_request_scan_y_t:
double from;
double to;
double speed;
SENSOR_A_get_result_y_t:
double value1;
double value2;
double value3;
REQUIREMENTS on SENSOR A: -> Sensor A shall only handle 200 queued requests maximum; This means that if SENSOR_A_request_x is called 201 times without any get then it is violating the contract. The same if SENSOR_A_request_x is called 100 and SENSOR_A_request_y is called 101 without any get from both.
-> It shall only be possible to get_results from valid logic ids. It should not be possible to get a scan result from something that wansn't queued before. The following sequence is not allowed: SENSOR_A_request_x -> id 2 SENSOR_A_get_result_scan_y(id 2) because request was done in x and get is done in y even when id is valid.