Report

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1

20212408-20212412

Illuminance sensor simulation project report


Vu Dinh Khanh 20212412, Tran Dao Nguyen Giap 20212408

II. DESIGN PROGRAM


I. INTRODUCTION As figure 1 above, the study is divided into three parts. We

T he illuminance sensor, also known as a light sensor or


lux sensor, is a device that measures the amount of
light (illuminance) falling on a surface. It plays a
crucial role in various applications where control or
monitoring of light levels is essential. Illuminance sensors
will follow the flow chart in figure 2, which shows the main
idea of the whole study, and consider the design progress of
each part. Each progress contains the flow chart showing
structure of program and usage of each function defined in a
table.
measure the intensity of light falling on a surface in units of
lux (lx) or foot-candles (fc). It is used in various applications
to automate lighting systems, adjusting brightness based on
ambient light conditions.

The main goal of the study is to build a program on


Visual Studio Code with C++ language to respond to all the
objectives above in command lines, which is called a
simulator program for an illuminance sensor.

For the structure of coding, we will follow GNU style


and design a top-down structure. Three tasks of the study are
written in three separated files with guide of relationship. The
main structure of the project is mentioned in the chart below.

Fig. 2. Main idea of the project.

A. HEADER.h – create a data library file.

HEADER file declares and shares data structures, function


prototypes, macros, and constants across multiple source files.
They contribute to code organization, modularity, and the
overall maintainability of our project.
B. Task 1 - create and add into a CSV file.

In this task, we will design a program that allows users to


use command lines to add data into a CSV file. If the
command is in the correct format, it will create a CSV file
named “lux_sensor.csv” and randomly create data inner it. If
the command is incorrect, the program will return an error
report in a log file named “task1.log”.

Fig.1. Structure of project


2
20212408-20212412

C. Task 2 – process the data.


In this part, we will use the result of the previous part – the
CSV file created after using command-line. With this CSV
file, we will create a program that uses command-line to treat
the data. There will be some options for users to process data.:

- Validating data by a condition of the lux level in


range 1 ÷ 40000 lux. If the lux level is not in range,
that data will be considered as an outlier and stored in
a file name “lux_outlier.csv”.

- Identify the maximum (max), minimum (min) and the


average concentration values over all the time (mean)
measured by each sensor and store the results in a file
named “lux_summary.csv”.

- Calculate total number of hours for each pollution


Fig.3. Mainstream of program and main function level at each sensor and store the results in a file
named “lux_pcondition.csv”.
If errors exist, the program ends and returns an error report
in a log file named “task2.log”.
TABLE 1: LIST OF MAIN FUNCTIONS TASK 1

Function Usage

double Generate_Value
Generates a random
(double min, double decimal value for sensors
max) from 0.1 to 40000.

Generates simulation data


for the specified number
of sensors, sampling time,
and measurement
void Sensor_Simulation duration. It uses the
(int num_Sensors, int Generate_Value function
sampling, int interval) to generate random
illuminance concentration
values. The data is stored
in a CSV file named
"lux_sensor.csv". Fig.4. Mainstream of program and main function
Inputs and Outputs:
 Inputs: Command-line arguments (-n, -st, -si) allow
users to specify the number of sensors, sampling
time, and measurement duration.
 Outputs: The program outputs the generated sensor TABLE 2: LIST OF MAIN FUNCTIONS TASK 2
data on the console and writes it to the
Function Usage
"lux_sensor.csv" file.
Valid_sensor (const defines a function named
Pre-conditions and post-conditions: string filename, const Valid_sensor that reads
 Pre-conditions: The program requires valid sensor data from a file,
string locationdile) performs some validity
command-line arguments for the number of sensors,
sampling time, and measurement duration. checks on the data,
 Post-conditions: The program generates simulation separates valid and
data and saves it in the "lux_sensor.csv" file. outlier sensor readings,
writes the outlier readings
3
20212408-20212412

to a separate file, and


then calls another
function named
Sensor_location to
update the locations of
the valid sensors based on
the information in a
location file.
void File_avrvalue_perh Writes the information
(vector<Sensor>avr) about the average sensor
values per hour, including
the sensor ID, timestamp,
location, value, and
condition, to a file named Fig.5. Mainstream of program and main function
“lux_condition.csv”.
void Writes information about
File_parameter (vector parameters, including the
sensor ID, parameter TABLE 3: LIST OF MAIN FUNCTIONS TASK 3
<Sensor> para) type, timestamp, and
value, to a file named Function Usage
“lux_summary.csv”.
the purpose of
converting a value of
Inputs and Outputs any data type
Convert_Data (datatype (datatype) into a
 lux_outlier.csv: Contains the outlier data entries,
including the sensor ID, timestamp, and value. data) sequence of bytes
. represented by a
vector<unsigned
 lux_summary.csv: Contains summary
char>
information for each sensor, including the
sensor ID, parameter (max, min, mean), Output_DAT_file (string responsible for writing
timestamp, and corresponding value. datfile, vector<Sensor> a vector of Sensor
 lux_condition.csv: Contains statistics based objects into a binary
on pollution levels for each sensor, sensor) DAT file. It converts
including the sensor ID, lux level, and each Sensor object into
duration. a Pack_Sensor object,
formats the data in a
Function Call Syntax, Inputs, and Outputs specific way, and
The struct Sensor is used to represent information about a writes it to the file.
sensor, and instances of this struct will hold details such as the reads sensor data from
sensor's ID, timestamp, value, location, condition, and a CSV file and
parameter. performs various
Read_CSV_File (string checks on the data. It
D. Task 3 - create and add data into a CSV file. csvfile) stores the valid sensor
readings in a vector of
Sensor objects and
The main task is to convert sensor data between CSV
returns this vector.
(Comma-Separated Values) and DAT (Binary Data) formats.
The program reads sensor data from a file in one format,
performs the necessary conversions, and writes the data to a
file in the other format. The code also includes functions for
generating timestamps, calculating checksums, and III. RESULT
determining endianness.
4
20212408-20212412

exception. By the source code description and analysis above,


we can be sure that simulating the data is not hard. We can use
them in some cases such as designing electrical boards, data
analysis or data science.
Below is the task allocation table of our team:

Member/
Tasks Percentage
ID

Vũ Đình - Coding
80%
Khánh - Test result

- Reviewing and
Trần Đào writing reports.
Nguyên 20%
- Drawing flowcharts.
Giáp
- Test result

V. ACKNOWLEDGEMENTS
The authors would like to give special thanks to Mr. Hoang
Duc Chinh for teaching, supporting, and taking the time to
listen to our questions.

IV. CONCLUSION
C++ language is a strong tool to develop any programs and
applications. Simulating the lilluminance sensor is not an

You might also like