int srv_prepare_resp(srv_t *srv) { base_req_t *req = (base_req_t *)srv->req; form_base_resp(srv->resp,req->no,req->fn,srv->fn_rv); if(srv->fn_rv==RRW_RV_BAD_REQ) { return (srv->resp_len = sizeof(base_resp_t)); } switch(req->fn) { case RRW_FN_STATUS: srv->resp_len = srv_prepare_status_resp(srv); break; case RRW_FN_MEAS_CTL: srv->resp_len = srv_prepare_meas_ctl_resp(srv); break; case RRW_FN_TEST: srv->resp_len = srv_prepare_test_resp(srv); break; case RRW_FN_DATA: srv->resp_len = srv_prepare_data_resp(srv); break; } return srv->resp_len; }
/**Prepare response in dependence of request type*/ int srv_prepare_resp(srv_t *srv) { base_req_t *req = (base_req_t *)srv->req; //fill base response fields form_base_resp(srv->resp,req->no,req->fn,srv->fn_rv); //stop further processing if bad request if(srv->fn_rv==RRW_RV_BAD_REQ) { printf("BAD REQUEST!\n"); return (srv->resp_len = sizeof(base_resp_t)); } //call response forming routines and calculate length of data to send back switch(req->fn) { case RRW_FN_STATUS: srv->resp_len = srv_prepare_status_resp(srv); int i; for(i=0; i<srv->resp_len; i++) { printf("%d ",srv->resp[i]); } printf("\n"); break; case RRW_FN_MEAS_CTL: srv->resp_len = srv_prepare_meas_ctl_resp(srv); break; // case RRW_FN_DATA: // srv->resp_len = srv_prepare_data_resp(srv); // break; case RRW_FN_DATA_ALT: srv->resp_len = srv_prepare_data_alt_resp(srv); break; case RRW_FN_GET_TH: case RRW_FN_SET_TH: srv->resp_len = srv_prepare_getth_resp(srv); break; } return srv->resp_len; }