Starting from:

$30

CPE 325- #8 Solved

 


Assignment                                                                              
1.      Implement the following functions in C:

void UART_initialize(); 
Configures UCI to work in the UART mode at the baud rate as follows: if your first name has

an even number of letters use 19200, otherwise use 115200.
void 

UART_sendCharacter(char c); 
Sends a character via UART
char UART_getCharacter(); 
Waits for a character from UART and returns it.
void UART_sendString(char* string); 
Sends a string via UART using

sendCharacter(char c)
void UART_getLine(char* buffer, int limit); 
Receives characters via UART using

UART_getCharacter()until it finds the new line character or until the limit of characters is exceeded. Writes that string (excluding the new line character) to the buffer allocated outside of the function.

Terminates the string with the null character.
Test your functions to make sure they work properly and none of them writes or reads nonallocated memory. Make sure that UART_getLine() inserts the null character at the end of your string, and does not exceed the limit, including the null character.

2.      Write a chat bot using functions from the previous part. When the user types “Hey, Bot!” and hits Enter, the bot greets the user and asks for their age. After age is entered, chat bot replies: “You are so young! I am 1<x years old!”, where <x is the age of the user.  If the user enters 1000, the bot should reply “This cannot be true!”. Make sure each message in the chat starts from a new line. Specify author of each message as it is shown on the screenshot below (colored names are necessary for bonus part only):

                                                                                                                                         
Notes: 

•       You can use snprintf function to concatenate strings, but make sure you do not overflow any buffers.

•       The bot should be ready to reply to the “Hey, Bot!” message again without resetting the board.

•        Use strcmp function to compare strings.

•       Echo characters back if you want to see what you type.

•       Use \r\n sequence to properly start a new line.

                                                                                       
3.    If the user has not communicated with your chat bot for longer than 15 seconds, the chatbot should send “Is anybody here?” to the terminal and repeat that message every 15 seconds until the user replies. Messages from the user should reset the wait time.

4. Use different colors for the names of authors.


More products