Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- c .code Programming assignment 14 explores stuctures and functions Design, Code, Test a C program which will loop util test data is done, calculating

image text in transcribed

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

c .code

Programming assignment 14 explores stuctures and functions

Design, Code, Test a C program which will loop util test data is done, calculating the

resultant saturated pressure of a mythical vessel of special fluid and

air.

change from Hw12:

0. Stub routine is renames MslComm()

1. Define structure to match requiremnts message structure

2. Exctract raw counts for missile temp and convert to vdc

Scope of main():

calculate last index for table containing vdc LastIndexVDC_tbl

calculate last index for table containing degrees C LastIndexC_tbl

loop until NULL

receive VDC from function MslComm()

convert raw msl temp count to vdc

compute F from Interpolate(vdcTbl, tempFTbl, *vdc, lastInedx of tabl)

Convert to C

compute vesselPSI from Interpolate(tepCTbl, psiTbl, TempC, lastindex of tbl)

end loop

Scope Change:

None

History:

Initial Release Ed Jennings, 2/10/2018

Hw5 release Ed Jennings, 2/14/2018

Hw6 released Ed Jennings, 2/19/2018

Hw8 released Ed Jennings, 2/22/2018

Hw12 released Ed Jennings, 3/19/2018

Hw14 released big Ed , 4/10/2018

mslTemp_raw mslTemp_vdc vesselTemp_Fahr(F)

-----------------------------

0xFF -> 4.98vdc -> 1800.0 upper limit test

0x3D -> 1.19vdc -> 45.0 lower limit test

0x19 -> 1.99vdc -> 145.6 interpolate

F F to C vesselPressPsi

-----------------------------

1800 982.22 3194.30 upper limit test

45.0 7.22 0.1317 lower limit test

145.6 63.12 0.2896 interpolate

*//////////////////////////////////////////////////////////////////////////////

#include // this header has NULL

#include // power function

// This assignement is agnostic to the other bytes in this message

// this structure will only identify the msl temp raw counts

typedef struct

{

unsigned char status : 5;

unsigned char msgId_major : 3; //the MSB is bit 0 or minor number

unsigned char msgId_minor : 5; //minor number bits 1,2,3,4 bit 0 belongs to major

unsigned char triMode : 3;

unsigned char ceptTime : 5; //lsb 10 (0-255)

unsigned char clsSpeed : 3; //lsb 0.1 m/s

unsigned char AOA[2]; //0-15 degrees

unsigned char mslTemp_raw; //counts 8bit DAC

unsigned char reserved : 3; //byte 7 of message

unsigned char tickTime : 5;

} mslMsg_struct;

#define MAJORMAX 8 //max value of the major number

const unsigned char badMsg[] = { "Bad Msg" };

const unsigned char invalMsg[] = { "Invalid Msg" };

const unsigned char getReady[] = { "Get Ready" };

const unsigned char getSet[] = { "Get Ready" };

const unsigned char go[] = { "Get Ready" };

const unsigned char oops[] = { "Oops" };

const unsigned char quiet[] = { "Quiescent" };

const unsigned char comeDwn[] = { "Comming Down" };

const unsigned char *msgUnpack[5][16] = {

badMsg, invalMsg, badMsg, getReady, badMsg, getSet, badMsg, go,

badMsg, badMsg, badMsg, badMsg, badMsg, badMsg, badMsg, badMsg, //[0] end of Major 0

badMsg, go, invalMsg, badMsg, oops, badMsg, badMsg, badMsg,

badMsg, badMsg, badMsg, badMsg, badMsg, badMsg, badMsg, badMsg, //[1] end of Major 2

badMsg, go, badMsg, badMsg, badMsg, badMsg, badMsg, badMsg,

badMsg, badMsg, badMsg, badMsg, badMsg, badMsg, getSet, getReady, //[2] end of Major 4

badMsg, badMsg, getReady, badMsg, quiet, badMsg, badMsg, badMsg,

badMsg, badMsg, getReady, badMsg, quiet, badMsg, badMsg, badMsg, //filler [3]

badMsg, badMsg, getReady, badMsg, quiet, badMsg, badMsg, badMsg,

comeDwn, badMsg, badMsg, badMsg, badMsg, badMsg, badMsg, oops, //[4] end of Major 8

};

float dac8bit_lsb; //power function 2**8, better resolution by calculating it

float aoaScale; // 15/2**16-1

//fubction prot-types

unsigned char *MslComm(); // test data stub routine

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

unsigned char *MslMsgId(unsigned char, unsigned char);

// 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;

mslMsg_struct *mslMsg = NULL; // pointer to msl message test data

float vesselTempFahr_vdc, vesselTempFahr;

unsigned char *mslMsg_ptr = NULL;

dac8bit_lsb = 5.0 / powf(2, 8); //power function 2**8

aoaScale = 15/(pow(2,16)-1);

while (mslMsg = (mslMsg_struct *)MslComm()) //cast from unsigned char to msl msg struct type

{

vesselTempFahr_vdc = mslMsg.mslTemp_raw * dac8bit_lsb; // convert raw counts to voltage

vesselTempFahr = Interpolate(vesselVDC_table, vesselTempSensor_table, vesselTempFahr_vdc, LastIndexAI_tbl);

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

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

mslMsg_ptr = MslMsgId(mslMsg->msgId_major, mslMsg->msgId_minor); //hw15

} // end of while loop

}//end main()

/*

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 missile message

*/

unsigned char *MslComm()

{

static unsigned char NextMsg[] = { 0x31, 0x26, 0x31, 0x43, 0x21, 0xFF, 0x66, //4.98vdc aoa=? msg=13 Get Ready

0x46, 0x88, 0x34, 0x33, 0x33, 0xBC, 0x66, //3.55vdc aoa=3.0 msg=24 Oops

0x1F, 0x51, 0x35, 0xAA, 0xAA, 0xC7, 0x66, //3.90vdc aoa=10 msg=88 Coming Down

0x2F, 0x51, 0x35, 0xAA, 0xAA, 0xC7, 0x66, //3.90vdc aoa=10 msg=98 Bad Msg

0x31, 0x26, 0x31, 0x2F, 0xF4, 0xBC, 0x66, //3.55vdc aoa=2.81 msg=13 Get Ready

};

static int indx = 0 - sizeof(mslMsg_struct);

indx += sizeof(mslMsg_struct); //else more data

if (indx > (int)sizeof(NextMsg)-1) //WT?!

return(NULL); // if true return null

return(&NextMsg[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

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

else //Computer linear Interpolation //R5.1

for (index = 1; index

{

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);

}

/*

Function MslMsgId():

Input: one argument

Global Ref: const message strings

Returns: pointer to the message string.

Arguments: poniters to msgId_major and msgId_minor

Description:

unpacks the msl message id for the correct values for the major and minor values. the function will

return a pointer to the correct message string

*/

unsigned char *MslMsgId(unsigned char major, unsigned char minor)

{

major = major | ((minor & 0x1)

minor >>= 1; //shift to the correct lsb for minor

if (major > MAJORMAX ) return(badMsg); //major > 8

major = major >> 1; //align major to message pointer table

return(msgUnpack[major][minor]); //send the pointer of the correct message

}

1. Create a Project( 32 bit platform) PIC32MX795F512L a. b. c. Download code example from evaltools Create the projects in one folder Create a sub-folder to contain source files 2. For the project a. Compile/link the source example b. Correct any compiler/linker errors c. Execute the code in "Sim mode 3. Deliverables a. Measure Functions: MslComm, Interpolate, and MsIMsgld b. What is the size(bytes) of each function's text space: c. What is the execution time of each of the three functions d. What is the latency for each function call? e. How many bytes of space does f. What is the address of the function main)? g. What is the address of the identifier vesselPressPsi table? h. What is the address of the local identifier NextMsg? i. What is the address of the local identifier index? j. Why are the three identifiers (vesselPressPsi table, index, NextMsg) so different? vesselPressPsi table require? 1. Create a Project( 32 bit platform) PIC32MX795F512L a. b. c. Download code example from evaltools Create the projects in one folder Create a sub-folder to contain source files 2. For the project a. Compile/link the source example b. Correct any compiler/linker errors c. Execute the code in "Sim mode 3. Deliverables a. Measure Functions: MslComm, Interpolate, and MsIMsgld b. What is the size(bytes) of each function's text space: c. What is the execution time of each of the three functions d. What is the latency for each function call? e. How many bytes of space does f. What is the address of the function main)? g. What is the address of the identifier vesselPressPsi table? h. What is the address of the local identifier NextMsg? i. What is the address of the local identifier index? j. Why are the three identifiers (vesselPressPsi table, index, NextMsg) so different? vesselPressPsi table require

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 11th International Symposium Sstd 2009 Aalborg Denmark July 8 10 2009 Proceedings Lncs 5644

Authors: Nikos Mamoulis ,Thomas Seidl ,Kristian Torp ,Ira Assent

2009th Edition

3642029817, 978-3642029813

More Books

Students also viewed these Databases questions

Question

=+1. What proactive strategies might you develop?

Answered: 1 week ago

Question

2. What are the components of IT infrastructure?

Answered: 1 week ago