Warning
This page is located in archive. Go to the latest version of this course pages.

HW 03 - File Input/Output

This homework will cover reading and writing to a file based on this week's lecture (with some extra communication with the board!) Lab 4 covered using programs to communicate with the board (lab04_sender.cpp, etc).

I have some sample text in a file homework-t.txt from the Wikipedia page about the C programming language in uppercase. I want to send it to the Nucleo board; the Nucleo board should convert uppercase letters to lower case, except for the first letter of each sentence. The modified string should be transmitted back from Nucleo to pc and saved to a file in pc. What you should do is:

  • You should modify the sender file to read the file line by line and send the characters by USART to the board.
  • You should modify the code on the board to read the incoming characters till it detects the end of the sentence, the dot '.' character. Then you should make all characters lower case except the first one (which is the beginning of a sentence). Then send the modified string back to pc (the non-blocking communication may be helpful here).
  • You should modify the reader file from lab 4 to receive the incoming text and write it to a new file.

If complete, your code should produce a new file alongside the old one with the punctuation corrected.

Make sure to submit all required C files, but not the whole project!!

HINTS

1) Char data types are based on ASCII (https://en.wikipedia.org/wiki/ASCII#Printable_characters). For this reason(look at the table), you can treat any char as a number and subtract 32 from lower case letters to make them upper case, and likewise add 32 to upper-case letters to make them lower-case.

2) Modify lab06 board code for receiving data from the PC in a non-blocking matter. In the interrupt function, put the received character immediately inside the buffer. You would better send and receive data character by character.

3) Increase your receive buffer size on the board, #define cRECV_BUFF_MAX 255

4) In the Nucleo board, for the HAL_UART_Transmit function, give a larger timeout value (final parameter). Otherwise, your transmission will be incomplete from Nucleo to PC. Also, so far, for the third parameter of the HAL_UART_Transmit function, which is the length of the string that we want to send, we passed the sizeof(second_argument). But since your stack has a larger size now (255), and not all of it is full of characters, passing sizeof (oRecvBuff.chArrRecvBuff) as the third argument won't work correctly. Instead, you should pass the number of characters filled so far in the stack, which is oRecvBuff.iCnt. All in all, your transmit function should look like this: HAL_UART_Transmit(&huart2, oRecvBuff.chArrRecvBuff ,oRecvBuff.iCnt,100000000);

5) When you are running lab04_reciever.cpp to receive the data sent from Nucleo and write it to the board, make sure you set your stty flags properly.

stty -F /dev/ttyACM0 -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echoctl -echoke 115200 cat /dev/ttyACM0

6) When using lab04_sender.cpp to send the file to Nucleo board, make sure after sending a character, you wait for a while (recommended 10 ms) before you send the next character. Otherwise, if you send characters very fast, your Nucleo will not register it and stop responding, requiring a reset.

7) before running lab04_sender.cpp and lab04_reciever.cpp, make sure that these codes were successful in connecting to the board. Output an error if the Nucleo board was not found. It is not necessary to do this (no points for this) but strongly recommended.

8) Before sending the changed text from board to PC, send the number of lines that you will send to PC so that your receiver code will know when the transmission is over. For figuring out number of lines you can simply count the number of dot characters by Nucleo.

POINTS

3 points for reading the text file and sending it properly to Nculeo.

4 points for Nucleo board receiving data, processing it and sending it back.

3 points for receiving the data and outputting it as a txt file.

courses/be5b99cpl/hw/hw03c_-_lab06.txt · Last modified: 2021/11/30 17:00 by amjadara