You are on page 1of 5

Objectives

incorporate data structures and pointers into their C programs. Also, you will practice reading / writing state
diagrams. The following concepts and skills are demonstrated through this process:

1. C-programming Skills
• Incorporate a linked list data structure into your programs
• Use pointers to interact with your linked list: insert / delete / print nodes
• Continue familiarizing yourself with your cross-compiling environment for the Raspberry PI 4

2. Interpret behavior of a stateful object from a state diagram


• Learn how to model system behaviors using finite state diagrams
• Use an online editor to create state diagrams

Introduction
For the remainder, we will make use of several data structures for handling a wide variety of embedded
system tasks related to software architecture and task management. As an advanced refresher in data structures,
you will program a framework for creating and working with a linked list. Additionally, you will practice
interpreting and modeling system behavior from a state diagram for a sub-system of the Radar system

Lab Activities
Please complete all lab activities (1 – 2) and submit your lab report to Canvas per the submission instructions
given at the end of this document.
Lab Activity 1 (15 points)
In this activity, you will create a C program to allow a user to work with a linked list data structure where each
node contains a single character. The user will be prompted to enter the initial number of nodes and then enter
the data for each initial node. Once the linked list has been initialized, present the user with a menu allowing
them to delete a node, insert a node, print the data contained in the linked list, or to exit the program.
Each menu option (except exit) should call a function to accomplish the specified functionality – you may
get specific information from the user before calling each function (e.g., index to delete / insert, data to insert,
etc.).
You may design your linked list as a single or double linked list, whatever your feel comfortable with. However,
a double linked list will probably be easier to work with in terms of deleting and inserting nodes.
To get you started, here is an example struct declaration for the linked list:

struct ListNode {
char data; /* node data */
struct ListNode *nextPtr; /* pointer to next node */
};
Don’t forget that you will need at least one typedef statement so that you don’t have to type struct ListNode
every time you reference a node. In my program, I have two typedef statements:

typedef struct ListNode ListNode;


typedef ListNode *ListNodePtr;

Below, I have included sample output of a working example to demonstrate program functionality.

Please enter the number of initial nodes: 3


Enter data for node 0: A
Enter data for node 1: B
Enter data for node 2: C
List 1 is: A B C *

Linked List Menu:


1. Insert Node.
2. Delete Node.
3. Print List.
4. Exit Program.
User Choice: 3
A B C *

Linked List Menu:


1. Insert Node.
2. Delete Node.
3. Print List.
4. Exit Program.
User Choice: 2
Index to delete: 0
Deleting index 0 from list ...

Linked List Menu:


1. Insert Node.
2. Delete Node.
3. Print List.
4. Exit Program.
User Choice: 3
B C *
Linked List Menu:
1. Insert Node.
2. Delete Node.
3. Print List.
4. Exit Program.
User Choice: 1
Index to insert: 2
Data to insert: C

Linked List Menu:


1. Insert Node.
2. Delete Node.
3. Print List.
4. Exit Program.
User Choice: 3
B C C *

Linked List Menu:


1. Insert Node.
2. Delete Node.
3. Print List.
4. Exit Program.
User Choice: 4

Thank you!

Lab Activity 1 – Questions


For your submission, please include the following items for Lab Activity 1:
1. Your C code.
2. An execution sample (console copy, screenshot, phone camera image, etc.) of your program running on
the Raspberry PI 4 (either remotely through Eclipse, or on the PI directly).
Lab Activity 2 (15 points)
In this activity, you will learn how to model system behaviors using finite state diagrams. Additionally, you will
practice drawing state diagrams in an editor of your choice, such as the following online editors:
1. Lucidchart - https://www.lucidchart.com/pages/
2. draw.io - https://www.draw.io/
In Module 04, we talked about the pulse-level communication behavior of the link driver object in a Radar system.
The class diagram and state diagram of Link Driver are given below, respectively:

The ReceivingMessage and TransmittingMessage states are both composite states. The details for the
ReceivingMessage state are given below – note, that 4 time-out constants are referenced:
• PULSE_TM: a time-out value for pulse levels – e.g., 5ms
• BIT_TM: a time-out value to separate two consecutive bits – e.g., 10ms
• BYTE_TM: a time-out value to separate two consecutive bytes – e.g., 20ms
• MSG_TM: a time-out value to separate two consecutive messages – e.g., 50ms
Lab Activity 2 – Questions
Please work out the details of the TransmittingMessage state. For your submission, please include the following:
3. Draw a state diagram for the TransmittingMessage state using one of the recommended online editors
4. A detailed description of each transition in your diagram.
To accomplish this task, you should study the diagram for the ReceivingMessage state - it essentially contains
the opposite order of operations that the TransmittingMessage state performs. Approach this in a similar fashion
as an algorithm design - draw a draft on a paper, refine it, and draw the finalized version in the chosen editor.
You may assume the following functions (actions) for the Link driver object:
• shiftLeft(Byte): return the most significant bit of Byte;
• convertBitToPulseCount (bit): return the number of pulses for encoding a bit;
• setVoltageHigh( ): transit signal state from low to high;
• setVoltageLow( ): transit signal state from high to low.

Submission
There is a MS-Word lab report template that you can download as a starting point for your lab
submission. There are two sections for you to fill in. Each section corresponds to the two Lab Activities for this
lab. For each section, please give a brief summary of what you did – feel free to include any thoughts / concerns
/ problems / etc. you encountered during the activities. Also, include your answers to the questions asked in
each Lab Activity.

You might also like