Question: #include // this header has NULL //fubction prot-types float *MslTemp(); // test data stub routine float Interpolate(float *, float *, float , int ); //

#include // this header has NULL

//fubction prot-types

float *MslTemp(); // test data stub routine

float Interpolate(float *, float *, float , int );

// Declare global variables

float vesselPressPsi; //R1.0 result PSI

float vesselTempFahr; //R1.1 Initial Temperature

// by making the following constants, the code execution does not have to

// repeatably keep calulating the same values

//R2.2 and R3.0

const float F2Cfactor=5.0/9.0; //make a const to reduce time of calulation of F to C, better resolution

#define F2C(f) F2Cfactor*(f-32.0) // another way with macro, "f" gets replace with vesselTempFahr in compiler

//R4.4 Define Temp F and corresponding Psi tables

float vesselTempC_table[] = { 10,30,60,70,80,90,110,130,140,160,190,220,240,250,260,270,

280,350,400,450,500,575,650,700,800,950 };

float vesselPressPsi_table[] = { 0.1317, 0.1881, 0.2563, 0.3631,0.5069,0.6979,0.9493,1.692,

2.888, 4.736, 7.507, 11.52, 14.69, 17.19, 24.97, 35.43,

49.20, 67.01, 134.60, 247.26, 422.55, 680.86, 1045.43,

1543.20, 2308.40, 3194.30 };

//R4.4 define analog voltage and corresponding Temp F tables

float vesselVDC_table[] = { 1.2, 1.5, 1.8, 2.1, 2.4, 2.7, 3.0, 3.4, 3.8, 4.4, 4.8 };

float vesselTempSensor_table[] = { 45, 85, 120, 160, 250, 340, 500, 600, 1024, 1542, 1800 };

// Main Routine

void main()

{

// Declare local variables

float vesselTempCelsius = 0; //R1.2

//R4.3 Table Maintenance/Operators

int LastIndexC_tbl = sizeof(vesselTempC_table) / sizeof(vesselTempC_table[0]) - 1;

//R5.1 Table sizeof get lastind

int LastIndexAI_tbl = sizeof(vesselVDC_table) / sizeof(vesselVDC_table[0]) - 1;

float *tempAnalogInput_ptr = NULL;

while (tempAnalogInput_ptr = MslTemp()) //R2.1

{

vesselTempFahr = Interpolate(vesselVDC_table, vesselTempSensor_table, *tempAnalogInput_ptr, LastIndexAI_tbl);

vesselTempCelsius = F2C(vesselTempFahr); // just showing two ways to use macros

vesselPressPsi = Interpolate(vesselTempC_table, vesselPressPsi_table, vesselTempCelsius, LastIndexC_tbl);

} // end of while loop

}//end main()

/*

Function MslTemp() :

Input : No input arguments and no global data references

Returns : Pointer to next test data, NULL when no more test data

Arguments : None

Description :

Defines and retains the test input data representing a thermocouple sensor through

and Analog Input(AI) port.The Thermocouple voltage is in units of degree Fahrenheit.

*/

float *MslTemp()

{

static float vdc[] = { 5.5, 5.0, -1.5, 0.0, 2.0 }; //test data

static unsigned int indx = 0;

if (indx > sizeof(vdc) / sizeof(vdc[0]) - 1)

return(NULL);

else

return(&vdc[indx++]);

}

/*

Function Interpolate():

Input: four arguments

Global Ref: None

Returns: Float value from the interpolation algorithm.

Arguments: Poniter to SetData, pointer to targetData, setPoint, size of Data

Description:

Calculates the resultant value from a set point and associated tables, limiter values,

through the use of lookup tables and interpolation.

Saturation (limitation) is based on the first and last table entries.

*/

float Interpolate(float *setData, float *targetData, float setPoint, int lstIndx)

{

unsigned char index; //index in to tables

float value; //the return value

if (setPoint >= setData[lstIndx]) //R5.0

value = targetData[lstIndx]; //upper bound limit

else if (setPoint <= setData[0]) //R5.0

value = targetData[0]; //lower bound limit

else //Computer linear Interpolation //R5.1

for (index = 1; index < lstIndx; index++) //fix requirements anal

{

if (targetData[index] == setPoint) //eqiv test

{

value = targetData[index];

break; //exit for-loop

}

if (setData[index] > setPoint) //found data pair

{

value = targetData[index - 1] +

((setPoint - setData[index - 1]) /

(setData[index] - setData[index - 1])) *

(targetData[index] - targetData[index - 1]);

break;

}

}//end for

return(value);

}

______________________________________________________________

*From the above code please do the following;

change all appropriate comments and assume ownership. This code will use a stub function which mimics an API to a sensor. A stub function is used for testing and is replaced after verification of the application code is completed. The function descriptions are as follows:

Function MslComm():

Input: No input arguments and no global data references

Returns: Pointer to next test data, NULL when no more test data

Arguments: None

Description:

Defines and retains the test input data representing a message from the missile.

Function Interpolate():

Input: There could be four arguments and no global data references Returns: Float value from the interpolation algorithm.

Arguments: You define the arguments for the function: at least two tables, a set point and

something else.

Description:

Calculates the resultant value from a set point and associated tables, limiter values,

through the use of lookup tables and interpolation. Saturation (limitation) is based on the first and last table entries.

The main() function will loop until MslComm() returns NULL. For each loop MslComm() returns the pointer to the message stream of bytes. The voltage needs to be extracted from the message and converted to correct engineering unit value then the newly acquired voltage and appropriate tables are passed through the arguments to the function Interpolate() which will return the resultant Fahrenheit temperature. The temperature is converted to Celsius and Celsius and appropriate tables are passed to Interpolate() which will return the resultant vesselPressPsi.

The test data for the function MslComm() is in Appendix C, must be referenced only in MslComm().

The code must perform Saturation testing. Provide your test plan for verifying Saturation testing in your header comment.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!