You are on page 1of 6

HANOI UNIVERSITY OF SCIENCE AND FINAL EXAMS SEM 2021.

1
TECHNOLOGY Course: EE3490E – FUNDAMENTAL OF
SCHOOL OF ELECTRICAL – EMBEDDED PROGRAMMING
ELECTRONICS ENGINEERING Date: 07 – 15/02/2022
Duration: 4 days & 10 minutes
Paper: 01 Total number of pages: 06 (4 days of coding and writing report. 10 minutes of
oral defence)
Appr Group leader/Lecturer: Department:
over

Design a program with suitable functions and data structures to process sensing data.
1. Problem:
Students are required to write a program in C/C++ that should open a file and figure out if
it contains data acquired by sensors or binary data packets. It should then convert the file
to another format, i.e.:
o If the file contains sensing data in text format, the program should convert the data into
binary packets and save the result in another file.
o If the file consists of binary data packets, the program should parse the packet and store
the data in a csv file
a) The sensor data file (in csv format):
The file storing the sensing data is a comma-separated values (csv) file with the first row
is a header. Each following rows includes the sensor id, the timestamp in the format of
yyy-mm-dd hh:mm:ss, the temperature value and the relative humidity value. If the
temperature or humidity value is missing, the cell with respected to that field is blank.
Example of the csv file is shown below
id,time,temperature,humidity
2,2020-12-31 17:00:00,19.17,59
1,2020-12-31 17:00:02,36.83,82
3,2020-12-31 17:00:15,-9.83,84
3,2020-12-31 17:01:07,12.55,58
4,2020-12-31 17:01:47,,60
,,,
8,2020-12-31 17:03:23,50.61,88
9,2020-12-31 17:04:33,-8.5,90
10,2020-12-31 17:05:30,36.71,78
2,2020-12-31 17:06:21,35.28,89

1
b) The binary packet file (txt file):
The file storing binary packets is a txt file. Each row of this file includes a binary packet
with respect to each row in the sensing data file (csv file) if the data is valid. A complete
packet frame is described as the followings:
Start Packet ID Time Temperature Humidity Checksum Stop
byte Length byte
0x00 1 byte 1 byte 4 bytes 4 bytes 1 byte 1 byte 0xFF
(1 byte) (1 byte)
Each field in the packet must be a hex number or an array of hex numbers. Each byte is
separated by one space.
o Start byte (1 byte) is always 0x00.
o Stop byte (1 byte) is always 0xFF.
o Packet length is the length of the whole packet including the Start byte and the Stop
byte.
o Id is the identity byte of the sensor, must be greater than 0.
o Time is the timestamp as Unix time in second (hint: it should be a long integer and stored
as an array of 4 bytes).
o Temperature is the temperature value which is a real number and stored as an array of 4
bytes (using IEEE 754 standard for conversion). The valid temperature value should be
in the range of -10.0 °𝐶 to 51.0 °𝐶.
o Humidity is the humidity value which is an integer number. The valid humidity range is
40% to 95%.
o Checksum is a byte which is calculated to verify the data (excluding the start byte and
stop byte) in the packet, i.e., checksum byte is the two’s complement of the sum of
[packet length, id, time, temperature, humidity]
In case, temperature value or humidity value is missing, the packet can be shorter. If both
the values are missing, the packet is considered invalid.
o E.g.:
 The binary packet file can look like the followings
00 0e 02 5f ed a1 20 41 99 5c 29 3b 49 ff
00 0e 01 5f ed a1 22 42 13 51 ec 52 fe ff
00 0e 03 5f ed a1 2f c1 1d 47 ae 54 ac ff
00 0e 03 5f ed a1 63 41 48 cc cd 3a 43 ff
00 0a 04 5f ed a1 8b 3c 3e ff
00 0e 08 5f ed a1 eb 42 4a 70 a4 58 1a ff
00 0e 09 5f ed a2 31 c1 08 00 00 5a a7 ff
00 0e 0a 5f ed a2 6a 42 12 d7 0a 4e 0d ff
00 0e 02 5f ed a2 9d 42 0d 1e b8 59 e7 ff

2
 The row “2,2020-12-31 17:00:00,19.17,59” in csv file can be converted as:
00 0e 02 5f ed a1 20 41 99 5c 29 3b 49 ff
2. Technical requirements:
The program should have the following features:
a) It should be run as command-line (using a terminal or command prompt applications),
e.g.:
C:\dataprocess <inputfile> <outputfile>
Input file and output file must have different name. If no other argument is provided,
the conversion is carried out by each line of the files. If other argument is included, the
conversion is described in the section b) below.
b) The optional commands are:
o –s: convert, sort data and store in the output file. It must be used as the following format
C:\dataprocess <inputfile> <outputfile> -s <type> <order>
 <inputfile> is a csv file and the <outputfile> is a binary packet file
 <type> must be provided and can be one of the followings:
 –id: data is sorted by id first; then it is sorted by time, i.e. data record with
the same id would be sorted by time
 –ti: data is sorted by time first; then it is sorted by id, i.e. data record with
the same time would be sorted by id
E.g: C:\dataprocess <inputfile> <outputfile> -s –ti
 The <order> is optional. By default, if it is not presented, the data is sorted by
ascending order, i.e. lowest value is in the first row, and so on. If it is presented,
it can be as the followings
 –asc: sorting by ascending order
 –des: sorting by descending order
E.g: C:\dataprocess <inputfile> <outputfile> -s –hu -asc
Requirement: Student must choose a sorting algorithm and implement himself/herself
rather than using one in any library.
Bonus point (1 point): Student can try more than one algorithm and report the
comparison of all the algorithms on the time taken to sort. However, there should be only
one output file even though multiple algorithms are used.
o –m: print out the manual for user on the screen.

c) The program should handle any errors which can happen by showing the suitable and
clear message with an error code. Student can define the error code yourself. The
format of the error message must be: “Error AB: error description”. Where AB is self-
defined error code, “error description” should present the error clearly.
A few errors can be listed here:

3
o The program cannot open the input file. Message can be: “Error AB: FILENAME could
not be opened”, FILENAME is the name of the file.
o If output file has been existed, the program should ask if user want to override it or not:
“Warning: FILENAME already exists. Do you wish to overwrite (y, n)?”. The answer
is “y” the program proceeds and overwritten the file, otherwise it does nothing and exits.
If the file with the same name is not allowed to access, an error message should be
shown.
o Unrecognized command
o Data error in csv file can be:
 All the data field in the row is blank.
 Id is blank or invalid.
 Time is blank or invalid.
 Both temperature and humidity are missing.
 Temperature value and/or humidity value are not in the valid range.
 Etc. (students can propose more)
The error message can be: “Error AB: Invalid data in row XX” XX is the row number.
Please note that:
 In csv file, the first row is the header and is counted as row 0; the next row after
the header row is the first data row and is row 1 and so on.
 In the txt file, there is no header row so the first row is row 1.
The row with error data in csv file is ignored for conversion.
o Error in packet (txt) file can be:
 Invalid packet format
 Invalid checksum
 Invalid hex symbol
 Etc. (students can propose more)
The error message can be: “Error AB: Invalid data in row XX” XX is the row number.
The row with error data in packet (txt) file is ignored for conversion.
o All the error messages should be written in a log file. Each messages should be in a
different line. The log file should be in text format and named as
<inputfile>_<outputfile>_<date>_<time>.log.
 <inputfile> and <outputfile> are input and output file names without their
extension. <date> và <time> is the date (in the form of YYYYMMDD) and time
(in the form of HHMMSS) when the conversion is completed. Eg.:
input_output_20220206_170005.log
 If the log file is existing, it should be overwritten with the new one.
 In case, <inputfile> and/or <outputfile> are not available or provided, the log file
is just <date>_<time>.log where <date> and <time> represent the time when the
program is run.
 Do NOT generate log file if there is no error with the conversion.
3. Design:
Students can use top-down approach to design the program, i.e. it is required to provide
a diagram to illustrate the functions developed and their relationship. If the program is
written in multiple files, a diagram need to be provided to illustrate the relationship of the

4
files as well. What the structure is and how the files are designed and organized should
also be introduced.
Flowchart diagrams should be provided for important / main functions. Analysis of the
features, inputs and outputs of these functions should also be presented.
Important data structures used in the program should also be explained.
4. Coding style:
The coding style can follow GNU as described in this url:
https://www.gnu.org/prep/standards/html_node/Writing-C.html
In short, the code writing should be formatted well by using proper curly bracket,
indentation, line break to differentiate code blocks. Comments should be given to explain
the code clearly for the readers. Variables and functions should be named properly in
English, they should be concise and self-described. Hard-coding should be avoided.
Students should not use any non-standard libraries.
5. Tools:
The student must use the following tools to develop the program:
o Editor: Visual studio code (https://code.visualstudio.com/download)
o Compiler: gcc or g++ in MinGW-w64 (https://sourceforge.net/projects/mingw-w64/)
o Student should specify the operating system (Windows, Linux, MacOS) in the report as
well. The executable file should be able to run in Windows.
6. Report and Submission guidelines:
o Student must do the assignment individually.
o The assignment should be organized as one project folder.
o Students have to write a report of 2-4 A4 pages (do not include source codes in it) in
English using IEEE word template to present:
 A brief introduction of the main idea and the design including the top-down
diagram (must have) and a directory tree (if there are multiple source code files).
 The implementation of the program including the data structures, algorithms and
the source files/functions which should be presented with diagram/figures and
short description. At least one flow-chart diagram must be provided.
 Discussion and evaluation of the results.
 A conclusion to summarize what have been done and have not been done in your
work.
o The write-up should be structured and presented well as instructed in the template. The
template file is attached together in Team assignment.
o Information from any external sources used in the report must be cited and the source
must be listed in the References section.
o Students have to
 compress all the files including source codes, compile codes, input and output
files, log files, report (in Word) file in one zip file (do NOT use *.rar or other
compression format) and name it as “StudentID_final_project_20211.zip”, e.g.:
“20221234_finalproject_20211.zip” and submit via Teams assignment.

5
 Do NOT use any subfolders except the subfolder “.vscode” if any. If wrong file
name or wrong folder is in the submission or any file mentioned above is missing,
at least 0.5 points will be deducted.
o Optional documentation: the student can use doxygen to generate documentation from
source code comments which should be a single file (word file is recommended); the
generated documentation by doxygen can be attached to the report as appendix and is
not counted in the above 2-4 pages (1 bonus point will be given if it is done well).
7. Evaluation:
o The assignment will be marks as below (total 10 points):
 Complete program with all the requirements fulfilled creatively: 4 points
 Good design and proper coding style: 1 points
 Well written report in the correct format, content is consistent with the code: 2
points
 Clear answers in oral exams which are consistent with the source code and report:
3 points
 Late submission (after the due date): -2 points
 No submission and/or no source code in the submission file, the total score will
be 0.
 If the source code cannot be compiled or the executable file is not runnable, at
least 3 points will be deducted.
 Student may be given 0 in total score if the answers in oral exams, the report and
the source code are not related to each other at all.
o Students must do the assignment himself/herself.
 It is strictly prohibited to copy source code / report from other students / groups
or other sources.
 Plagiarism from external sources will result in a consequence of at least 5 points
deduction from the final exam scores, submission with serious plagiarism will be
given 0.
 If two or more submissions from different students are similar, all the students
will be given 0. It does not matter who copies from whom. Thus, students should
keep the work confidential.
The deadlines (due date and closing date) are specified in Teams Assignment. Submission
after the closing date is not accepted.
-------------------- End ------------------------

You might also like