Experiment 1
Experiment 1
Experiment 1
The Raspberry Pi is a low cost, credit-card sized computer that plugs into a computer monitor or TV,
and uses a standard keyboard and mouse. It is a capable little device that enables people of all ages to
explore computing, and to learn how to program in languages like Scratch and Python.
The Raspberry Pi device looks like a motherboard, with the mounted chips and ports exposed (something
you'd expect to see only if you opened up your computer and looked at its internal boards), but it has all
the components you need to connect input, output, and storage devices and start computing.
CD: Using cd changes the current directory to the one specified. You can use relative (i.e. cd
directoryA ) or absolute (i.e. cd /home/pi/directoryA ) paths.
cd [option] [directory]
ex: cd /usr/sbin
touch: It is used to create a file without any content. The file created using touch command is empty.
This command can be used when the user doesn’t have data to store at the time of file creation
syntax: touch [option] [file_name]
Touch Command options
-a, change the access time only
-c, if the file does not exist, do not create it
-d, update the access and modification times
-m, change the modification time only
-r, use the access and modification times of file
-t, creates a file using a specified time
mv: mv stands for move. mv is used to move one or more files or directories from one place to
another in file system.
Syntax: mv [Option] source destination
mv -f force move by overwriting destination file without prompt
mv -i interactive prompt before overwrite
mv -u update - move when source is newer than destination
mv -v verbose - print source and destination files
man mv help manual
Ex : $ mv a.txt geek.txt
rm : rm stands for ‘remove‘ as the name suggests rm command is used to delete or remove files and
directory
syntax: rm [options] [files]
remove command options
-f, --force
ignore nonexistent files, never prompt
-i
prompt before every removal
-I
prompt once before removing more than three files, or when removing recursively. Less intrusive
than -i, while still giving protection against most mistakes
--interactive[=WHEN]
prompt according to WHEN: never, once (-I), or always (-i). Without WHEN, prompt always
--one-file-system
when removing a hierarchy recursively, skip any directory that is on a file system different from
that of the corresponding command line argument
--no-preserve-root
do not treat '/' specially
--preserve-root
do not remove '/' (default)
-r, -R, --recursive
remove directories and their contents recursively
-v, --verbose
explain what is being done
--help
display this help and exit
--version
output version information and exit
man : man command in Linux is used to display the user manual of any command
ex: $ man - lsmkdir: You can use mkdir to create a new directory.
Syntax: mkdir [options...] [directories ...
Ex: $ mkdir mydir
rmdir: The rmdir command removes each directory specified on the command line, if they are
empty. That is, each directory removed must contain no files or directories, or it cannot be removed
by rmdir
syntax: rmdir [-p] [-v | --verbose] [--ignore-fail-on-non-empty] directory ...
tar: the Linux “tar” stands for tape archive
syntax: tar [options] [archive-file] [file or directory to be archived]
gZip: gzip command compresses files. Each single file is compressed into a single file. The compressed
file consists of a GNU zip header and deflated data.
Cat: Cat(concatenate) command is very frequently used in Linux. It reads data from the file and gives
their content as output. It helps us to create, view, concatenate files. So let us see some frequently used cat
commands.
Syntax: $cat filename
More: more command is used to view the text files in the command prompt, displaying one screen at a
time
Sytax: more [-options] [-num] [+/pattern] [+linenum] [file_name]
Less: Less command is linux utility which can be used to read contents of text file one page(one screen)
per time
Syntax: less filename
Ps: Linux provides us a utility called ps for viewing information related with the processes on a system
which stands as abbreviation for “Process Status”
Syntax: ps [options]
Sudo: sudo (Super User DO) command in Linux is generally used as a prefix of some command that
only superuser are allowed to run. If you prefix “sudo” with any command, it will run that command with
elevated privileges
Syntax: sudo -V | -h | -l | -v | -k | -K | -s | [ -H ] [-P ] [-S ] [ -b ] |
[ -p prompt ] [ -c class|- ] [ -a auth_type ] [-r role ] [-t type ]
[ -u username|#uid ] commandsudo -V | -h | -l | -L | -v | -k | -K | -s | [ -H ] [-P ] [-S ] [ -b ] |
[ -p prompt ] [ -c class|- ] [ -a auth_type ] [-r role ] [-t type ]
[ -u username|#uid ] command
Cron: The cron is a software utility, offered by Linux-like operating system which automates the
scheduled task at a predetermined time
Syntax: cron [-f] [-l] [-L loglevel]
Chgrp: chgrp command in Linux is used to change the group ownership of a file or directory. All files in
Linux belong to an owner and a group. You can set the owner by using “chown” command, and the group
by the “chgrp” command.
Syntax: chgrp [OPTION]… GROUP FILE…
chgrp [OPTION]… –reference=RFILE FILE…
Ping: PING (Packet Internet Groper) command is used to check the network connectivity between host
and server/host.
Syntax: To get ping version installed on your system.
sudo ping –
Experiment 2: Study and Install IDE of Arduino and different types of Arduino.
Arduino :
Arduino is a prototype platform (open-source) based on an easy-to-use hardware and software. It
consists of a circuit board, which can be programed (referred to as a microcontroller) and a ready-made
software called Arduino IDE (Integrated Development Environment), which is used to write and upload
the computer code to the physical board.
Arduino provides a standard form factor that breaks the functions of the micro-controller into a more
accessible package.
Step 1 − First you must have your Arduino board (you can choose your favorite board) and a USB cable.
In case you use Arduino UNO, Arduino Duemilanove, Nano, Arduino Mega 2560, or Diecimila, you
will need a standard USB cable (A plug to B plug), the kind you would connect to a USB printer as
shown in the following image.
In case you use Arduino Nano, you will need an A to Mini-B cable
Step 2 − Download Arduino IDE Software.
You must select your software, which is compatible with your operating system (Windows, IOS, or
Linux). After your file download is complete, unzip the file.
Step 3 − Power up your board.
The Arduino Uno, Mega, Duemilanove and Arduino Nano automatically draw power from either, the
USB connection to the computer or an external power supply. If you are using an Arduino Diecimila,
you have to make sure that the board is configured to draw power from the USB connection. The power
source is selected with a jumper, a small piece of plastic that fits onto two of the three pins between the
USB and power jacks. Check that it is on the two pins closest to the USB port.
Connect the Arduino board to your computer using the USB cable. The green power LED (labeled
PWR) should glow.
Step 4 − Launch Arduino IDE.
After your Arduino IDE software is downloaded, you need to unzip the folder. Inside the folder, you can
find the application icon with an infinity label (application.exe). Double-click the icon to start the IDE.
Step 5 − Open your first project.
Once the software starts, you have two options −
Create a new project.
Open an existing project example.
To create a new project, select File → New.
To open an existing project example, select File → Example → Basics → Blink.
Here, we are selecting just one of the examples with the name Blink. It turns the LED on and
off with some time delay. You can select any other example from the list.
Step 6 − Select your Arduino board.
To avoid any error while uploading your program to the board, you must select the correct
Arduino board name, which matches with the board connected to your computer.
Go to Tools → Board and select your board.
Here, we have selected Arduino Uno board according to our tutorial, but you must select the
name matching the board that you are using.
Step 7 − Select your serial port.
Select the serial device of the Arduino board. Go to Tools → Serial Port menu. This is likely to
be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find
out, you can disconnect your Arduino board and re-open the menu, the entry that disappears
should be of the Arduino board. Reconnect the board and select that serial port.
Step 8 − Upload the program to your board.
Before explaining how we can upload our program to the board, we must demonstrate the
function of each symbol appearing in the Arduino IDE toolbar.
ZigBee is a communication device used for the data transfer between the controllers, computers,
systems, really anything with a serial port. As it works with low power consumption, the transmission
distances is limited to 10–100 meters line-of-sight. ZigBee devices can transmit data over long distances
by passing data through a mesh network of intermediate devices to reach more distant ones. ZigBee is
typically used in low data rate applications that require long battery life and secure netwo
rking. Its main applications are in the field of wireless sensor network based on industries as it requires
short-range low-rate wireless data transfer. The technology defined by the ZigBee specification is
intended to be simpler and less expensive than other wireless networks.
Here we make use of an interface of Zigbee with Raspberry Pi2 for a proper wireless communication.
Raspberry Pi2 has got four USB ports, so it is better to use a Zigbee Dongle for this interface. Now we
want to check the communication between the two paired ZigBee modules.
Modules Needed :
1. Raspberry Pi2
2. XBee 1mW Wire Antenna- Series 1 (2 No:)
In the Raspberry Pi2 section open the LX terminal and type lsusb.
The response showed inside a red box indicates the presence of a usb device in the module. Write a
python script to perform Zigbee communication which is given below.
import serial
while True:
ser.write('Hello User \r\n') # write a Data
incoming = ser.readline().strip()
print 'Received Data : '+ incoming
The two zigbee must be in a line of sight and check the results in the Python shell
and in the hyperterminal of the computer.
The Communication could also be established with two Raspberry Pi or with another controller it self.
Experiment 6:
Write a program to Implement Bankers algorithm for Dead Lock Avoidance.
Program:
package computing;
import java.util.Scanner;
public class Bankers{
private int need[][],allocate[][],max[][],avail[][],np,nr;
sc.close();
}
return need;
}
return true;
}
Safely allocated
Experiment 7:
Write a program to Producer-consumer problem Using semaphores
Program:
package computing;
import java.util.concurrent.Semaphore;
class Q {
// an item
int item;
// Producer class
class Producer implements Runnable {
Q q;
Producer(Q q)
{
this.q = q;
new Thread(this, "Producer").start();
}
// Consumer class
class Consumer implements Runnable {
Q q;
Consumer(Q q)
{
this.q = q;
new Thread(this, "Consumer").start();
}
// Driver class
class PC {
public static void main(String args[])
{
// creating buffer queue
Q q = new Q();
import java.io.*;
}
private static boolean check(String s){
String s1 = "11111";
if(s.equals(s1))
return true;
else return false;
}
}
Output: ENTER THE DATA: 0111110
BIT STUFFING: 01111100
FINAL OUTPUT: 01111110 01111100 01111110
011111100111110001111110
Experiment 11:
Write a program to configure a Network using Distance Vector Routing protocol.
Program:
package computing;
import java.io.*;
public class DVR
{
static int graph[][];
static int via[][];
static int rt[][];
static int v;
static int e;
Output:
Please enter the Source Node for the edge whose cost has changed: 2
Please enter the Destination Node for the edge whose cost has changed: 4
Please enter the new cost: 10
#include "stdafx.h"
#include <stdio.h>
#include <math.h>
#include <iostream>
do {
puts("\nShow that (!(x < 5) && !(y >= 7)) and !((x < 5) || (y >= 7))
are logically equivalent\n\n"); // Part a
if (ch == 'n') {
do {
puts("\nShow that (!(a == b) || !(g != 5)) and !((a == b) && (g !=
5)) are logically equivalent\n\n");
if (ch == 'n') {
do {
puts("\nShow that !((x <= 8) && (y > 4)) and (!(x <= 8) || !(y > 4))
are logically equivalent\n\n");
if (ch == 'n') {
do {
puts("\nShow that !((i > 4) || (j <= 6)) and (!(i > 4) && !(j <= 6))
are logically equivalent\n\n");
if (ch == 'n') {
printf("\n%s", "Now you know DeMorgan's Laws!");
}
system("pause");
return 0;
}
Experiment 12:Write a program to perform the function oriented diagram: DFD and Structured
chart.
Data flow diagram is graphical representation of flow of data in an information system. It is capable of
depicting incoming data flow, outgoing data flow and stored data. The DFD does not mention anything
about how data flows through the system.
There is a prominent difference between DFD and Flowchart. The flowchart depicts flow of control in
program modules. DFDs depict flow of data in the system at various levels. DFD does not contain any
control or branch elements.
Types of DFD
Logical DFD - This type of DFD concentrates on the system process, and flow of data in the
system. For example in a Banking software system, how data is moved between different entities.
Physical DFD - This type of DFD shows how the data flow is actually implemented in the
system. It is more specific and close to the implementation.
DFD Components
DFD can represent Source, destination, storage and flow of data using the following set of components -
Entities - Entities are source and destination of information data. Entities are represented by a
rectangles with their respective names.
Process - Activities and action taken on the data are represented by Circle or Round-edged
rectangles.
Data Storage - There are two variants of data storage - it can either be represented as a rectangle
with absence of both smaller sides or as an open-sided rectangle with only one side missing.
Data Flow - Movement of data is shown by pointed arrows. Data movement is shown from the
base of arrow as its source towards head of the arrow as destination.
Levels of DFD
Level 0 - Highest abstraction level DFD is known as Level 0 DFD, which depicts the entire
information system as one diagram concealing all the underlying details. Level 0 DFDs are also
known as context level DFDs.
Level 1 - The Level 0 DFD is broken down into more specific, Level 1 DFD. Level 1 DFD
depicts basic modules in the system and flow of data among various modules. Level 1 DFD also
mentions basic processes and sources of information.
Level 2 - At this level, DFD shows how data flows inside the modules mentioned in Level 1.
Higher level DFDs can be transformed into more specific lower level DFDs with deeper level of
understanding unless the desired level of specification is achieved
Structure Charts
Structure chart is a chart derived from Data Flow Diagram. It represents the system in more detail than
DFD. It breaks down the entire system into lowest functional modules, describes functions and sub-
functions of each module of the system to a greater detail than DFD.
Structure chart represents hierarchical structure of modules. At each layer a specific task is performed.
Here are the symbols used in construction of structure charts -
Module - It represents process or subroutine or task. A control module branches to more than one
sub-module. Library Modules are re-usable and invokable from any module.
Condition - It is represented by small diamond at the base of module. It depicts that control
module can select any of sub-routine based on some condition.
Jump - An arrow is shown pointing inside the module to depict that the control will jump in the
execution of module.
Data flow - A directed arrow with empty circle at the end represents data flow.
Control flow - A directed arrow with filled circle at the end represents control flow.
Example
We take the same example of Customer Authentication in the online shopping environment. This
procedure to authenticate customer can be written in Structured English as:
Enter Customer_Name
ELSE
ENDIF
The code written in Structured English is more like day-to-day spoken English. It can not be
implemented directly as a code of software. Structured English is independent of programming
language.
Experiment 13:
Write a program to perform the system analysis: Requirement analysis, SRS.
Requirement Analysis
Gathering requirements from the user. Analysts and engineers communicate with the client and end-
users to know their ideas on what the software should provide and which features they want the software
to include.
SRS is a document created by system analyst after the requirements are collected from various
stakeholders.
SRS defines how the intended software will interact with hardware, external interfaces, speed of
operation, response time of system, portability of software across various platforms, maintainability,
speed of recovery after crashing, Security, Quality, Limitations etc.
The requirements received from client are written in natural language. It is the responsibility of system
analyst to document the requirements in technical language so that they can be comprehended and useful
by the software development team.
Requirements gathering - The developers discuss with the client and end users and know their
expectations from the software.
Organizing Requirements - The developers prioritize and arrange the requirements in order of
importance, urgency and convenience.
Negotiation & discussion - If requirements are ambiguous or there are some conflicts in
requirements of various stakeholders, if they are, it is then negotiated and discussed with
stakeholders. Requirements may then be prioritized and reasonably compromised.
The requirements come from various stakeholders. To remove the ambiguity and conflicts, they
are discussed for clarity and correctness. Unrealistic requirements are compromised reasonably.
Documentation - All formal & informal, functional and non-functional requirements are
documented and made available for next phase processing.
Experiment 14:
Write a program to draw the structural view diagram: Class diagram, object diagram.
Class Diagram:
Class diagram is a static diagram. It represents the static view of an application. Class diagram is not only used for
visualizing, describing, and documenting different aspects of a system but also for constructing executable code of
the software application .
Class diagram describes the attributes and operations of a class and also the constraints imposed on the
system. The class diagrams are widely used in the modeling of objectoriented systems because they are
the only UML diagrams, which can be mapped directly with object-oriented languages.
Class diagram shows a collection of classes, interfaces, associations, collaborations, and constraints. It is
also known as a structural diagram.
Object diagram:
Object diagrams are derived from class diagrams so object diagrams are dependent upon class diagrams.
Object diagrams represent an instance of a class diagram. The basic concepts are similar for class
diagrams and object diagrams. Object diagrams also represent the static view of a system but this static
view is a snapshot of the system at a particular moment.
Object diagrams are used to render a set of objects and their relationships as an instance.