Smart Parking System Design Report
Smart Parking System Design Report
net/publication/334561019
CITATION READS
1 463
8 authors, including:
Adeeb Albukhari
The University of Queensland
7 PUBLICATIONS 2 CITATIONS
SEE PROFILE
All content following this page was uploaded by Adeeb Albukhari on 19 July 2019.
COE 400
SYSTEM DESIGN LABORATORY
Project # 1 Title:
Parking System
Design Report
Prepared for:
Dr. Abdulhafid Bouhraoua
By
Due Date
2010-02-03
TABLE OF CONTENTS
TABLE OF CONTENTS………………………………………………………………….2
LIST OF FIGURES……………………………………………………………………….3
LIST OF TABLES………………………………………………………………………..3
ABSTRACT………………………………………………………………………………4
1. INTRODUCTION………………………………………………………………...4
2. REQUIRMENTS………………………………………………………………….4
3. DESIGN…………………………………………………………………………...4
4. METHODOLOGY……………………………………………………………...13
5. IMPLEMENTATION……………………………………………………………14
7. CONCLUSIONS……………………………………………………………….25
REFERENCES……………………………………………………………………..27
APPENDICES………………………………………………………………………28
2
LIST OF FIGURES:
Figure1: MaxSonar-EZ1
Figure2: The inputs and outputs to and from the processing unit (the
interaction with the different modules)
Figure3: an example of a wooden gate.
Figure4: the integration of the GSM module and the mobile network
operator
Figure5: 7-segment display
Figure6: example of colored LEDs.
Figure7: PC/Microcontroller Serial Interface
Figure8: Sensors-Microcontroller & Central-Microcontroller Parallel
Interface
Figure9: Gate Module Pin Configuration
Figure10: Guidance Module Pin Configuration
Figure11: Sensing Mechanisim
Figure12: System Methodology
LIST OF TABLES:
Table 1: Web Server Prices
Table 2: GSM Prices
Table 3: Sensors Prices
Table 4: Display Information
Table 5: Sensors Distribution
3
ABSTRACT:
This project is mainly an implementation of a smart parking system. This system
consists of many blocks acting with each others using modern technology
communication to send, receive and process data. A microcontroller was used as the
central unit of the system and ultra sonic sensors were used to collect data regarding
the status of the parking system. Also, there is a web server used to display the status
of the parking system as well as a GSM module to use SMS massages for reservation
and status notification.
1. INTRODUCTION:
In an increasingly demanding world, the waste of time can have a serious effect on
people and business. The increase in population along with car production business
expanding has led to major cities in the world suffering from rush-hours where
parking has become a serious issue to face everyday. Many drivers find themselves
turning around in a parking lot and wasting their time without being able to find an
empty spot to park. A driver would be thankful to know in advance if the parking lot
is full. The driver will also appreciate a guidance mechanism that will guide him to
the nearest free parking line. This saves time and increases productivity for different
sectors including education.
The aim of this project is to solve the mentioned problem using means of technology
considering the ease of deploying such a system in real life. Also, additional features
such as remote reservation and getting information about the status of the lot from the
web are introduced.
2. REQUIRMENTS:
3. DESIGN:
We decide as a solution to the proposed problem to implement a Smart Parking
System. The system will be able to provide how many slots are empty and decide the
nearest parking slot and provide reservation system. In order to achieve these
requirements our system will consist of the following components:
4
a) Centralized control: responsible for data processing and giving orders
to the other components.
b) Gate control: responsible for closing and opening the gate based on the
information provided by the central unit.
c) Web server: for the ability to check the status remotely.
d) GSM module: for the SMS service that will allow reservation and
checking the status of the lot.
e) Guidance mechanism: to guide the driver to the nearest line containing
the empty slot.
f) Car movement detection sensors: to count the number of cars in each
line of the lot.
g) Display module: to display the number of available empty slots at the
entrance.
The stepper motor used for the prototype is SMCC-547 at a cost around 30 SR
(240 Thai Baht = $7.24 from [Link]). This motor allows 18 degree rotations and
thus 5 consecutive rotations are needed to close the gate (90 degrees/18 degrees =
5). Also, a decoder dual 2-line to-4 line (SN74155N at a cost of $50/186 decoders
sold in quantity from [Link] = $0.27 = 1 SR) is used. So, the total
cost is around 31 SR.
5
The well-known Apache is a good choice for a web server for many reasons. It is free
and requires no licensing. It is widely deployed with an active support and
development. It is also relatively easy to use. This reduces cost and system
development time.
Since the web server is mainly used for displaying current system status and is not
connected to a DBMS (Database Management System), using HTML for the website
is going to be sufficient for this purpose. HTML also allows for embedding high level
language applications (e.g. Java applet). This could useful to fetch current system
status information from the microcontroller, since HTML cannot be used to read data
using a serial interface/Ethernet. The figure below is an example of the to-be-
developed GUI.
6
In general, a GSM modem is recommended for use with a computer over the mobile
phones to send and receive messages. This is because some mobile phones have
certain limitations comparing to GSM modems. Some of the limitations are described
below:
However, there is not much difference between mobile phones and GSM modems in
terms of SMS transmission rate, since the determining factor for the SMS
transmission rate is the wireless network.
Even though GSM USB modems are less expensive (under $100) and in many cases
are faster than serial GSM modems, the serial connection RS232 is recommend for
the connection between GSM modem and the centralized control module for various
reasons. Mainly, the configurations and the initializations of RS232 for
communication are much easier and more flexible than the sophisticated ones used
for USB. For the sending rate, the performance of our system is not affected by the
connection speed between the computer and GSM modem i.e. the SMS sending rate
is about the same no matter the GSM modem is connected to the computer through a
serial cable or USB cable. This is because the determining factor for the SMS sending
rate is the wireless network as mentioned earlier. Furthermore, USB products are
being used now frequently in the industrial, but for our small project it is more than
enough to use RS232 for this simple communication.
Prices:
Item Price
GM862 Evaluation Board - RS232 $74.95
GM862 Cellular Quad Band Module $99.95
7
Table 2: GSM Prices
LEDs option is cheaper than using the monitor option and it is easy to
understand.
In maintenance, LEDs can be replaced easily.
LEDs option is easier to implement.
Monitor option may cause congestion at the entrance of the lot since a driver
may need some time to look at the monitor.
Since the prototype contains only two lines, only two LEDs are needed. The cost is
negligible ($0.03 for each LED from [Link]).
Figure1: MaxSonar-EZ1
The sensor is going to be used is MaxSonar-EZ1 (figure7)and will be connected
to another microcontroller. The properties of the sensor are:
Figure2: The inputs and outputs to and from the processing unit (the interaction
with the different modules)
The Centralized Control Unit is the brain of the system. All the other modules are
connected to it. Mainly, it consists of two parts: a microcontroller and a computer that
connect through a serial link. It receives different inputs from some modules, keeps
track of any changes in the system, analyzes this data, and executes different
algorithms to process it and outputs commands and data to other modules
accordingly. This unit will be flexible and generic. Flexible in terms of accepting
changes in the size of the system, i.e. it can adapt to any reduction or increase in the
size of a parking lot. Generic in terms of, for example, no matter what type of sensor
or what web server is used it can function flexibly.
9
3.3 Gate control:
In order to make it easier for the driver to know the availability of a free parking slot
in the parking area, a gate will be placed in the entrance. This gate will be closed only
when all the parking slots are full or reserved. In our project we make this gate a
wooden gate that is controlled by the centralized control unit (the microcontroller).
The connection between the gate and the centralized control unit is going to be wired.
Figure2 illustrates an example of a wooden gate.
The website will display the total free slots, total occupied slots and the total reserved
slots.
10
The chief goals of employing GSM modem module in this project are to aid the
driver to be acknowledged with the parking details as well as to implement his
request remotely i.e. while he is at home or driving to the parking and before his
arrival. The former is achieved by sending the word status by the driver as an SMS to
the GSM modem, and based on the information stored in the centralized control
module the following will be sent to the driver’s mobile phone: Total free, total
occupied, and total reserved slots.
The latter role is accomplished through the reservation feature. Whenever the driver
is willing to occupy a free parking slot, he just sends the word Reserve to the GSM
modem and the system will update the centralized control module accordingly. For
instance, the number of free slots will be decremented and the number of reserved
ones will be incremented. Finally, there is a case which the driver must send the word
open to the GSM modem so that he can enter the parking lot. This is when the
parking slots are all full and he has already reserved a free parking slot, because in
this case the gate will be closed. The following picture demonstrates the integration of
the GSM module and the mobile network operator.
Figure4: the integration of the GSM module and the mobile network operator
The display module is the main interest of a driver upon reaching the parking lot. The
module will show how many available slots in the parking in total (in 7-segment display,
figure4 shows an example of 7-segment display). An example of the display will look
similar to the following table:
11
7-Segment Available Lots
Main 5
Table4: display information
Guiding the driver to the nearest parking slot will save a lot of time and will not
congest the parking lot with many drivers looking for a parking slot. For this
reason, our system will be featured with guidance mechanism. The driver will be
guided by some LEDs that will guide him to the nearest line that has the empty
parking slot from the entrance of the parking lot. LEDs will be turned ON and
OFF by connecting them to the microcontroller, which will decide which one
goes ON or OFF according to the status of the lines. Figure5 shows an example of
colored LEDs.
12
4. METHODOLOGY:
13
5. IMPLEMENTATION:
5.1 CENTRALIZED CONTROL:
As previously mentioned in the report, the centralized control is the brain of the
system which takes inputs from detection sensors module & GSM module to update
its state which in turn affects gate module, web server module, display module, and
guidance mechanism.
Since the centralized control module is composed of three main parts, the
implementation steps can be divided into:
The main purpose of serial interfacing between the microcontroller and the PC is to
create an entity (PC) that can communicate with GSM and Web Server modules
easily using sockets without putting any burden on the microcontroller. So, the
microcontroller is still the brain of the system whereas the PC can be thought of as the
two way road that the microcontroller, GSM, and Web data move on.
This part started by testing the MAX233CPP chip which converts the microcontroller
5V data to PC's 12V data and vice versa. The following is a detailed diagram that
shows how the connection is done:
14
What happens here exactly is that the microcontroller uses Serial D pins (PC0 to
transmit and PC1 to receive) to communicate with PC through MAX233CPP. Some of
the pins (10 & 16, 11 & 15, 12 & 17) have to be connected together by default for the
proper operation of MAX233CPP. The PC communicates through serial pins (2 to
receive and 3 to transmit) with MAX233CPP's pins 4 (RX) and 5 (TX).
This block has been tested using the windows hyper-terminal with a dummy Dynamic
C application that simply uses the functions serDgetc() to get a character through serial
D and serDputc(X) to send a character X through serial D.
Regarding the PC/Microcontroller serial interface protocol, it works as follows:
If PC sends character '0' which is a status request, microcontroller
responds by sending two bytes (1st one representing total free parks and
the 2nd is by default 0).
If PC sends character '1' which is a reservation request, microcontroller
responds by sending two bytes (1st one representing total free parks and
the 2nd is either character 'E' if reservation is granted or character 'F' if
reservation is denied because total number of allowed slots for reservation
which is by default half of total slots is at its maximum).
If PC sends character '2' which is an open gate request – can only come
from GSM module, microcontroller opens the closed gate and responds by
sending two bytes (1st one representing total free parks and the 2nd is by
default character 'G'). This is assuming that no open gate request would be
received by microcontroller for a non-authorized user (checked by GSM
module).
If PC sends character '3' which is a reservation cancellation request, the
microcontroller decrements its number of reserved parking slots and does
not respond with anything.
During the integration part, since the sensing unit used three serial ports (namely B, C,
and D), and because many problems were faced in using more than these serial ports on
one microcontroller, it was decided to use two microcontrollers. One microcontroller is
dedicated for sensors and another one for this central unit. The sensors-microcontroller
outputs 5 bits (representing five sensors) to the central-microcontroller and receives 1
flushing bit in order to flush the values of the pins representing 5 bits that indicate a
sensor signal (0 for no car detection at the specific sensor and 1 for a single car
detection).
This is why there was a need to dedicate 6 ports (PB3-PB7) on central-microcontroller
to receive parallel data of sensors from sensors-microcontroller, and PB2 to send a
flushing signal during each iteration of the central unit sequential program to allow for
new signals to arrive (the central microcontroller detects the change in consecutive 1s
to update its counters since sensor unit sends a lot of 1s for 1 signal while the object is
still in front of the sensor).
15
Figure 8: Sensors-Microcontroller & Central-Microcontroller Parallel Interface
Microcontroller Programming:
This part contains the code of the brain of the system which is responsible for running
everything. There were two approaches that have been thought of:
Using a sequential program that initializes required ports and then enters an
infinite while loop which executes several procedures that are needed in every
iteration.
Using the concept of threads to keep things running in parallel.
The choice was to use a sequential program for the following reasons:
It has been tested that Dynamic C behaves differently than other high level
languages like C++ or even C in certain aspects (for example there are
problems nesting three block one inside another … etc). Therefore, the
concept of threading might have created problems that could not be debugged
easily.
For this system's purpose, there is no problem running sequentially and
keeping serial buffer receiving while the program is doing something else
because the data flow is not so fast to overflow the buffer.
The program runs fast enough to display two LEDs representing two lines
guidance such that the human eye cannot detect any change in the lighted
LED.
Therefore, the program used is sequential (see the code in Appendix 1) and does the
following:
Initializes all variables needed and serial/parallel ports to be used in at the
beginning of the main procedure.
Enters an infinite while loop which reads sensors signals from sensors-
microcontroller, updates its local counters which represent number of cars
in the parking lot (and for each line), updates gate, guidance, and display,
and then does the serial communication followed by sending a flush signal
to the sensors-microcontroller through pin PB2 at the end of the iterations.
The explanation of code for updating gate, guidance, and display is available in
the next sections of the report.
16
PC Programming:
UDP is used for the socket communication between PC and Web/GSM because it
requires no connection establishment. Although UDP is known to allow for no
compensation of lost packets, it is not a problem in this case since GSM, Web,
and PC application are all in on PC and running as different processes
communicating through sockets. The code used is available in Appendix 2
The main scenario of the system is clarified by explaining this code. The program
starts by initialization of serial connection parameters, sockets, and variables.
There are two sockets to be opened for sending: one for the GSM and the other
for the web server. The web server simply receives from PC central application
and therefore it is just updated with any changes regularly. However, GSM sends
and receives through sockets and therefore the central application is supposed to
listen to incoming data. The protocol between the central application and GSM is
the following:
If GSM sends character 'X', application sends a status getting request
through the serial connection (sends '0' to the microcontroller), and
then upon receiving required data, it is sent to the GSM using its
socket.
If GSM sends character 'R', application sends a reservation request
through serial connection (sends '1' to the microcontroller), and then
upon receiving this, the microcontroller arranges a reservation for this
user.
If GSM sends character 'O', application sends an open gate request
through the serial connection for an available reservation (sends '2' to
the microcontroller), and then upon receiving this, the microcontroller
opens the gate and deletes one reservation for the corresponding user.
If GSM sends character 'C', application sends a reservation
cancellation request (which the GSM sends if the user who reserved
has not arrived after a certain time) through the serial connection
(sends '3' to the microcontroller), and then upon receiving this, the
microcontroller simply updates its status by deleting a reservation.
17
The protocol works such that there is always data being sent between GSM and
the central application (along with web being updated in every such iteration) for
two purposes:
To always update GSM and Web with most recent data.
To prevent busy waiting while being idle waiting for a data to be
received on the socket (since no threads are used and the program runs
sequentially). This helps both central application and GSM to always
continue updating data while not locking the code execution.
This simply closes the gate with rotation of 18 degrees to one side if close gate
request is initiated and to the reverse side if open gate request is initiated by 18
degrees * 4 = 72 degrees total change for each case (open/close).
Note that between each consecutive writings to port PD0 and PD1 (i.e. 11, 01
…etc) there is a million iteration of code (outer loop of 1000 and inner loop of
1000) just to allow for the motor to interpret the data and does the mechanical
change accordingly. The following figure shows the pin configuration for the
gate, decoder and microcontroller:
18
5.3 WEB SERVER:
Parking status websites written using PHP language. Data received from the
microcontroller will be processed in this PHP web page. PHP website is executed on
client machine when it requests the web page. So, whenever the user request the PHP
web page (parking status) the page will be executed on his machine and the code of
the PHP will be in listening mode. It will be waiting for the data from the
microcontroller. The microcontroller is always sending the data to the Web Server
through loopback connection using UDP as the transport layer. So, the Web Server
will get fresh data about the status of the parking when needed at any time.
The code is combination of HTML and PHP and it shows how data are received and
processed in parking status PHP Web Page. In appendix3.
Regarding to the problem of the dynamic IP address of the internet, the web server
has a special script that is used to send the changed IP address to the dynamic DNS
server every time it changes. So, our domain name is pointing to the right IP address
of our web server. However, we are using a domain name ([Link])
because it is easier to remember and it is difficult to memories the dynamic IP address
of the web server.
Finally, we need to have access to the router that we are getting the internet
connection from. Because when user requests the status of the parking the request
goes to that router through port 80 and we need to forward this request to our web
server to reply to the received requests.
Next, the program enters an infinite loop polling and listening to the serial port to
read if the GSM sends something or not. In case of receiving new SMS, the GSM
sends the following to the PC: +CMTI: “SM”, N where N is the SMS number in
the GSM storage area. To read that message, the following is sent to the GSM
modem: AT+CMGR=N. Consequently, it sends me the sender mobile number, the
date and the time, and the message itself as shown here:
Therefore, the program always checks for specific words sent by GSM modem
like +CMTI and +CMGR and based on that, it does specific actions. For instance,
whenever the PC receives +CMTI, it directly does a String manipulation to take
the included message number N and then the request (AT+CMGR=N) to the GSM
to send back the SMS it has just received, as mentioned above. Moreover, when
the PC receives +CMGR, it does also a String manipulation to take the included
sender mobile number as well as the original message. After that the program
completes its execution normally and checks again if something is received by the
serial buffer.
Now the SMS sent by the user is checked to see what actions to be done by the
program e.g. sending the user back the requested information or updating the
main controller. Actually UDP socket programming is used for the
communication between this program and the main controller program. In the idle
state, the letter X is always being sent to the main controller to send me back the
status of the parking lots. So if the user has requested the status of the parking, the
program sends him back immediately. However, in case of receiving the word
Reserve by the user, the letter R is sent instead to the controller to check the
possibility of reservation and to update its status accordingly. Furthermore, the
letter O is sent to tell the controller to open the gate in case if the user has
reserved earlier and update its status too. The reasons of continuously sending the
main controller in the idle state are mentioned above in the PC programming
section.
Initially, the program was programmed in C# language and almost everything was
O.K and went smoothly. However, there was a problem when the user sends the
word Open. What was happening is that the program was reading this word twice
as if two users were sending at the same time. Consequently, actions done by the
main controller were executed twice and it was being updated by wrong
information. Two months were spent on this and the problem was not figured out.
Therefore, the program was written again perfectly in C++. The power of coding
using this language is that you know exactly what is going on in your program
and especially in the serial buffer, because sometime the GSM modem sends
rubbish to the PC and the manipulations then get messed up if you don’t deal with
this perfectly. This was not easy using C# as everything has been dealt with as
20
strings. On the other hand, C++ doesn’t have the capabilities as C# as it is
considered a low level language, the way it enabled sending character by
character and reads and sends the only needed commands and characters and
ignores anything else. Everything worked fine and that problem happening
initially was gone and it has never seen after coding in C++. Finally, I was
convinced that any low level application, like sending and receiving serially,
should be programmed in low level languages like C or C++.
21
if both lines are full, simply turn off both LEDs to reduce power
consumption while the gate is already closed and there is no need to guide
any driver for sure.
Two pins (PD2 and PD3) are used to turn on the LEDs by writing 1 to the pin in
every iteration. Note that the signal is not buffered but it is just being fed to the
LED in a very fast during each iteration such that the eye cannot detect the any
change.
The sensor team had the objective of detecting a car that entered the parking lot and
which lane it stopped. The sensors used to detect the presence of are LV-MaxSonar
EZ0 and EZ1. The EZ0 has more sensitivity than the EZ1. This sensor has three
interfaces: serial, analog and Pulse Width. Each gives a reading every 49mS. That
means, in every second the sensors sends at most 20 readings. In addition, the sensor
has a pin to enable its output.
In the project, five sensors were used distributed in the parking as described in the
following table:
Sensor Location
1 Lane 1 entrance
2 Lane 1 exit
3 Lane 2 entrance
4 Lane 2 exit
5 The entrance gate
Table 5: Sensors Distribution
At the beginning, only one sensor was interfaced to the microcontroller (Rabbit
5000). The pulse width interface was used first. The interface uses the factor 147µS
per inch. The problem faced was how to measure the time that this signal is kept high.
Cascaded counters from the microcontroller were used but the results were no as
expected.
The second interface used is the serial interface. As given in the MaxSonar datasheet,
the baud rate is 9600, 8 bits, no parity, with one stop bit. These are the settings used
to initialize the serial port in the microcontroller. The output of the serial interface is
an ASCII capital “R”, followed by three ASCII character digits representing the range
in inches up to a maximum of 255, followed by a carriage return (ASCII 13).
Therefore the mission was to detect the ASCII code for “R”.
To test the functionality of the sensor, it was connected directly to the COM1 serial
port of a PC. Then use HyperTerminal to see the output of the senor. Sample result is
(R008). That means, the distance to the closest object is 8 inches. This was a point of
satisfaction for the team.
When the sensor was connected directly to the microcontroller, the output was not as
expected. It contained many zeroes and some strange characters. This was fixed by
inverting the output of the sensor before going into the microcontroller. The problem
was that sensor and the microcontroller use different levels to represent logic 0 and
22
logic 1. Therefore, the microcontroller was not able to detect the start bit of the
sensor’s serial data.
The next step was how to get the data of all sensors to the microcontroller. An
assumption made is that a car takes about a second to pass over the sensor. Based on
that, all sensors should be swept in this interval of a second. Using one serial port,
only four readings from each sensor can be taken. This was not enough because some
readings were erroneous. Therefore, more serial ports were used.
Another approach was to connect each sensor on a separate serial port. This was
supported by the microcontroller which has six serial ports (serial A – F). Each serial
port (except serial port A) was functioning properly alone but when all are connected
together only three ports were performing well (Serial B, serial C, serial D).
To compromise, one sensor (sensor 5) was connected to one serial port and the other
four were divided into two groups. Each group contains two sensors representing the
entrance and exit of a lane. By this configuration, the number of readings per second
increased from four to ten for the multiplexed sensors and twenty for the non-
multiplexed one. More number of readings led to better accuracy.
Sensors 5, 2 and 4 are always on sensors because at any time a car is expected to
enter or leave the parking. Sensor 5 (the gate sensor) was elected to be the non-
multiplexed sensor while sensors 1 and 2 (entrance and exit of lane 1) are connected
to a multiplexer and 3 and 4 (entrance and exit of lane 2) are multiplexed. Switching
between 1 and 2 (as well as 3 and 4) will not occur until a car passes through sensor
5. After the car enters one of the two lanes switching will stop. This is illustrated in
the following figure:
23
Figure 11: Sensing Mechanisim
The detection mechanism is based on majority of the reading taken from a sensor.
The MaxSonar interprets an object in the range of 0 to six inches as six inches “006”.
For sensor 5 (and 2 and 4 if no switching), twenty reading are taken. If six of them are
“006” then it’s a hit. For 1 and 3 (and 2 and 4 if switching), ten readings (sum is 20/s)
are taken and the same rule applies.
Communication between the microcontroller driving the sensors and the main
microcontroller is done through parallel port B. If a sensor i detects a car it sets the
corresponding bit in port B (PBi) to 1. These bits are reset back to 0 when the main
microcontroller acknowledges the reading by setting the flush bit. Code is shown in
appendix5.
Our project will be very convenience to the society since it helps in saving time
and effort to find a free parking slot specially in large lots which can be found in
Malls, Parks or Airports. Furthermore, it helps in saving money!
24
Driving your car for sh
shorter
orter distance will reduce the amount of fuel consumption,
which means less money to pay for fuel. Not only that, the user friendly way of
displaying the status of the parking lot using cell phones, web site, or the monitor
at the entrance will make lookin
lookingg for a free parking slot funny rather than a
headache.
One of the most popular and important contemporary issue nowadays is How to
‘Green’ the environment. This project can be considered as a part of the solution
to this issue.
sue. Our project will help in decreasing the amount of harmful cars
emissions such as CO2, which will cause a lot of bad effects in our environment
see figure3.
CONCLUSION:
At the end of this project we learned a lot of concepts and skills that an engineer must
have in order to design and implement projects in an efficient way. Some of these
skills are team work, troubleshooting and solving problems with different solutions
and earned the ability
ity to choose the best fitting solution. Also, we have become able
to analyze problems and determine the required equipments to achieve each task.
Moreover, skills in writing specifications, design and implementation reports were
earned. One of the most important
portant skills learned is the ability of working on projects
with specified requirement and deadlines. The project has introduced us to a lot of
technologies that can be merged in order to build larger projects; some are GSM
25
module, microcontroller and sensors (Ultra sonic). This gives us the opportunity to
learn deeply about these technologies. Finally, the project was working according to
the specified requirements and a prototype is being built for a demo of the project
functionality.
26
References:
1) Max233CPP datasheet.
2) SN74155N datasheet.
3) SMCC-547 datasheet.
4) LTC-4727 datasheet.
5) 74LS48 datasheet.
6) COE400 Lab Manual.
7) Rabbit 3000 Microprocessor User Manual.
8) The TTL Data Book
9) [Link] - The C++ Resources Network
10) msdn - Windows API Reference
11) [Link] – php manual.
12) GM862 EVK V3RS-232 Evaluation Board datasheet.
13)
[Link]
14)
[Link]
15) [Link]
16) [Link]
17) [Link]
18) The MaxSonar®-EZ1™ High Performance Sonar Range Finder Data
[Link]
19) The MaxSonar®-EZ0™ High Performance Sonar Range Finder Data
[Link]
20) MiniCore™ RCM5700 Module Data [Link]
21) Rabbit® 5000 Microprocessor User’s Manual
27
APPENDICES
APPENDIX1:
Central Unit Microcontroller Code
#class auto
#define BD_RATE 2400
int totalFree;
int totalFreeL1;
int totalFreeL2;
char i;
char digit1;
char digit2;
long t;
int k;
int l;
int m;
int flushCounter;
int gateState;
int sensor1;
int sensor2;
int s1;
int s2;
int s3;
int s4;
int s5;
int s1prev;
int s2prev;
int s3prev;
int s4prev;
int s5prev;
int iflag;
int iflag2;
int counter;
int d1;
int d2;
int maxFree;
int expectedCar;
int crap;
//void scanSensors();
void updateGate();
void updateDisplay();
void updateGuidance();
void sndRcvSerial();
void scanSensors(int);
main()
{
28
// initialize serial
serDwrFlush();
serDdatabits(PARAM_8BIT);
serDflowcontrolOff();
serDparity(PARAM_NOPARITY);
if(serDopen(BD_RATE)==0)
printf("failed...!\n");
//serDrdFlush();
maxFree=6;
sensor1=0;
sensor2=0;
s1prev=0;
s2prev=0;
totalFree = maxFree;
totalFreeL1 = (maxFree/2);
totalFreeL2 = (maxFree/2);
gateState = 0;
flushCounter=2;
expectedCar=0;
// Gate ports
BitWrPortI(PDDDR, &PDDDRShadow, 1, 0);
BitWrPortI(PDDR, &PDDRShadow, 1, 0);
// parallel bits
BitWrPortI(PBDDR, &PBDDRShadow, 0, 3); //Input1
BitWrPortI(PBDDR, &PBDDRShadow, 0, 4); //Input2
BitWrPortI(PBDDR, &PBDDRShadow, 0, 5); //Input3
BitWrPortI(PBDDR, &PBDDRShadow, 0, 6); //Input4
BitWrPortI(PBDDR, &PBDDRShadow, 0, 7); //Input5
BitWrPortI(PBDDR, &PBDDRShadow, 1, 2); //Out1
// Guidance
BitWrPortI(PDDDR, &PDDDRShadow, 1, 2);
BitWrPortI(PDDDR, &PDDDRShadow, 1, 3);
//Display Pins
BitWrPortI(PEDDR, &PEDDRShadow, 1, 0);
BitWrPortI(PEDDR, &PEDDRShadow, 1, 1);
BitWrPortI(PEDDR, &PEDDRShadow, 1, 2);
29
BitWrPortI(PEDDR, &PEDDRShadow, 1, 3);
updateGuidance();
updateDisplay();
updateGate(0);
while(1){
//sensor1 = BitRdPortI(PBDR,5);
//sensor2 = BitRdPortI(PBDR,6);
////sensor1 = BitRdPortI(PBDR,3);
////sensor2 = BitRdPortI(PBDR,4);
//flushCounter=flushCounter-1;
s1 = BitRdPortI(PBDR,3);
s2 = BitRdPortI(PBDR,4);
s3 = BitRdPortI(PBDR,5);
s4 = BitRdPortI(PBDR,6);
s5 = BitRdPortI(PBDR,7);
//if((s1==1)||(s2==1)||(s3==1)||(s4==1)||(s5==1))
{
BitWrPortI(PBDR, &PBDRShadow, 1, 2);
for(d1=0; d1<1000; d1++);
//for(d2=0; d2<1000; d2++);
BitWrPortI(PBDR, &PBDRShadow, 0, 2);
flushCounter=2;
}
/*if((sensor1!=s1prev)&&(sensor1==1))
{
//sensor1 = 1;
printf("inside scanned_1 %d!!\n", sensor1);
}
//else
// s1prev= sensor1;
if((sensor2!=s2prev)&&(sensor2==1))
{
//sensor2 = 1;
printf("inside scanned_2 %d!!\n", sensor2);
}
*/
//else
// sensor2 =0;
//sensorSignals[1] = BitRdPortI(PBDR,1);
//printf("after scanned %d!!\n", sensor1);
////
/*
if ((sensor1==1)&&(totalFree>0)&&(sensor1!=s1prev))
{
totalFree=totalFree-1;
updateDisplay();
if((totalFree) == 0) ///////
{
updateGate(1); /// close gate
//updateDisplay();
}
}
30
if((sensor2==1)&&(totalFree<6)&&(sensor2!=s2prev))
{
totalFree=totalFree+1;
updateDisplay();
if((totalFree) == 1) ///////
{
updateGate(0); /// open gate
//updateDisplay();
}
}
////
*/
////s1prev= sensor1;
////s2prev = sensor2;
s1prev = s1;
s2prev = s2;
s3prev = s3;
s4prev = s4;
s5prev = s5;
31
updateGuidance();
sndRcvSerial();
}
/*void scanSensors()
{
printf("1!!\n");
sensor1 = BitRdPortI(PBDR,0);
printf("2!!\n");
sensor2 = BitRdPortI(PBDR,1);
printf("3!!\n");
}*/
void updateGuidance()
{
if(totalFreeL1>0)
{
BitWrPortI(PDDR, &PDDRShadow, 1, 2); // L1
BitWrPortI(PDDR, &PDDRShadow, 0, 3);
}
else
{
BitWrPortI(PDDR, &PDDRShadow, 0, 2);
if(totalFreeL2>0)
BitWrPortI(PDDR, &PDDRShadow, 1, 3); // L2
else
BitWrPortI(PDDR, &PDDRShadow, 0, 3);
}
}
void scanSensors(int s)
{
t = MS_TIMER;
while((MS_TIMER-t)<3000)
{
printf("Time = %d\n", MS_TIMER);
}
sensor1=0;
updateGate(1);
}
if(state == 1)
{
//BitWrPortI(PBDR, &PBDRShadow, 1, 7);
k = 1000;
l = 1000;
for (k;k > 0; k--)
for (l;l > 0; l--);
BitWrPortI(PDDR, &PDDRShadow, 1, 0);
BitWrPortI(PDDR, &PDDRShadow, 1, 1);
k = 1000;
l = 1000;
k = 1000;
l = 1000;
k = 1000;
l = 1000;
if(state == 0)
{
//BitWrPortI(PBDR, &PBDRShadow, 0, 7);
k = 1000;
l = 1000;
k = 1000;
l = 1000;
k = 1000;
l = 1000;
k = 1000;
l = 1000;
33
if(state == 1)
{
//BitWrPortI(PBDR, &PBDRShadow, 1, 7);
k = 1000;
l = 1000;
for (k;k > 0; k--)
for (l;l > 0; l--);
BitWrPortI(PDDR, &PDDRShadow, 1, 0);
BitWrPortI(PDDR, &PDDRShadow, 1, 1);
k = 1000;
l = 1000;
k = 1000;
l = 1000;
k = 1000;
l = 1000;
if(state == 0)
{
//BitWrPortI(PBDR, &PBDRShadow, 0, 7);
k = 1000;
l = 1000;
k = 1000;
l = 1000;
k = 1000;
l = 1000;
k = 1000;
l = 1000;
void updateDisplay()
{
printf("Total Free = %d\n", totalFree);
void sndRcvSerial()
{
iflag=0;
iflag2=0;
i = ';'ے
while(i == ')'ے
{
i = serDgetc();
if (i != ')'ے
iflag = 1;
if(iflag==1)
{
digit1 = (totalFree/10)+48;
digit2 = (totalFree%10)+48;
serDputc(digit1);
serDputc(digit2);
}
if(iflag==1)
{
if(i=='1') // reserve request
iflag2=1;
if(i=='0')
iflag2=0;
if(i=='3')
iflag2=3;
}
if(iflag2==1)
{
if(totalFree>=(maxFree/3))
{
totalFree--;
}
35
}
else if(iflag2==2)
{
sensor1 = 1;
if (gateState == 1)
{
while((sensor1 == 1))
{
updateGate(0);
scanSensors(0);
}
}
//serDputc(50); // gate opened
}
else if(iflag2==3)
totalFree=totalFree+1;
36
APPENDIX2:
PC CODE FOR SOCKETS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winsock.h>
#include <time.h>
#include <windows.h>
WSADATA w;
int send(char*);
int sendToPHP(char*);
int rcv(char*);
int sndRcvSerial();
char INBUFFER[2];
char OUTBUFFER = '0';
int totalFree;
unsigned short port_numberSnd = 11330; /* The port number to use for sending */
unsigned short port_numberRcv = 12000; /* Port number to use for receiving */
int main()
{
char send_buffer[BUFFER_SIZE];
char rcv_buffer[BUFFER_SIZE];
int i;
/* Open windows connection */
if (WSAStartup(0x0101, &w) != 0)
{
fprintf(stderr, "Could not open Windows connection.\n");
system("pause");
exit(0);
}
if ((comport =
CreateFile("\\\\.\\COM1", // open com5:
GENERIC_READ | GENERIC_WRITE, // for reading and writing
0, // exclusive access
NULL, // no security attributes
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL)) == INVALID_HANDLE_VALUE)
{
// error processing code goes here
}
// Set timeouts in milliseconds
[Link] = 0;
[Link] = 0;
[Link] = 100;
[Link] = 0;
[Link] = 100;
bStatus = SetCommTimeouts(comport,&CommTimeouts);
if (bStatus != 0)
{
// error processing code goes here
}
// Set Port parameters.
// Make a call to GetCommState() first in order to fill
// the comSettings structure with all the necessary values.
// Then change the ones you want and call SetCommState().
GetCommState(comport, &comSettings);
[Link] = 2400;
[Link] = ONESTOPBIT;
[Link] = 8;
[Link] = NOPARITY;
[Link] = FALSE;
bStatus = SetCommState(comport, &comSettings);
if (bStatus == 0)
{
// error processing code goes here
}
//////////
for(i=0;i<4096;i++)
{
send_buffer[i]=0;
rcv_buffer[i]=0;
40
}
send_buffer[0]='0';
send_buffer[1]='0';
send_buffer[2]='X';
send(send_buffer);
INBUFFER[1]='3';
while (1)
{
for(i=0;i<4096;i++)
{
send_buffer[i]=0;
rcv_buffer[i]=0;
}
rcv(rcv_buffer);
if(rcv_buffer[0]=='X')
{
OUTBUFFER = '0';
printf("Idle!!\n");
}
else if(rcv_buffer[0]=='R')
{
OUTBUFFER = '1';
printf("Reserving!!\n");
}
else if(rcv_buffer[0]=='O')
{
OUTBUFFER = '2';
printf("Opening!!\n");
}
else if(rcv_buffer[0]=='C')
{
OUTBUFFER = '3';
printf("Cancelling Reservation!!\n");
}
sndRcvSerial();
totalFree = (INBUFFER[0]-48)*10+(INBUFFER[1]-48);
while(totalFree<0)
{
sndRcvSerial();
totalFree = (INBUFFER[0]-48)*10+(INBUFFER[1]-48);
printf("in the red zone!!!!!\n");
}
closesocket(sd);
closesocket(sdReceiver);
WSACleanup();
41
}
//*******************************************************************
//*******************************************************************
if (bytes_received < 0)
{
fprintf(stderr, "Could not receive datagram.\n");
closesocket(sdReceiver);
WSACleanup();
system("pause");
exit(0);
}
return 0;
}
int sndRcvSerial()
{
//char INBUFFER[2];
//char OUTBUFFER = '0';
42
//strcpy(&OUTBUFFER[0], "The quick brown fox jumped over the lazy dog. \n\r\0");
// Open COM port
INBUFFER[0]=0;
INBUFFER[1]=0;
bStatus = WriteFile(comport, // Handle
&OUTBUFFER, // Outgoing data
1, // Number of bytes to write
&bytes_written, // Number of bytes written
NULL);
/*
OUTBUFFER++;
if(OUTBUFFER == '2')
OUTBUFFER = '0';
*/
if (bStatus != 0)
{
// error processing code here
}
bStatus = ReadFile(comport, // Handle
&INBUFFER, // Incoming data
2, // Number of bytes to read
&bytes_read, // Number of bytes read
NULL);
if (bStatus != 0)
{
// error processing code goes here
}
// code to do something with the data goes here
//printf("\n%c\n",OUTBUFFER);
43
APPENDIX3:
CODE FOR THE WEB SERVER
<?php
error_reporting(E_ALL | E_STRICT);
$from = '';
$port = 0;
socket_recvfrom($socket, $buf, 12, 0, $from, $port);
//echo "Received $buf from remote address $from and remote port $port" . PHP_EOL;
$data = $buf;
$free_slots = substr($buf,0,2);
$occupied_slots= 20 - $free_slots;
//Show time:
date_default_timezone_set('Asia/Riyadh');
$date = date('l dS \of F Y h:i:s A');
?>
<html>
<head>
<title>Smart Parking</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="keywords" content="Keywords here">
<meta name="description" content="Description here">
<meta name="Author" content="Adeeb Hassan">
<meta name="Publisher" content="[Link]">
<meta name="robots" content="index, follow"> <!-- (robot commands: all, none, index, no index, follow, no follow) -->
<meta name="revisit-after" content="30 days">
<meta name="distribution" content="global">
<meta name="rating" content="general">
<meta name="content-language" content="english">
<style type="text/css">
<!--
.basestyle {
color: #FFFFFF;
font-size: 10px;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
h1 {
font-size: 16px;
font-weight: bold;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
body, td, p, input {
font-size: 11px;
font-family: Verdana, Arial, Helvetica, sans-serif;
color: #333333;
}
.navlinks {
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
color: #FFFFFF;
}
-->
</style>
44
</head>
<body style="margin:0; ">
<table width=755 height="100%" border=0 align="center" cellpadding=0 cellspacing=0>
<tr align="center" valign="middle">
<td height="169" colspan="2"><a href="[Link]
<img src="../images/[Link]" width="216" height="155" border="0"></a><img
src="../images/[Link]" width="539" height="155"></td>
</tr>
<tr>
<td width="185" align="center" valign="top" bgcolor="#d80000"><h3>
<img src="../images/[Link]" width="185" height="14"></h3>
<table width="176" border="0" cellpadding="2" cellspacing="0">
<tr>
<td class="navlinks">
<font style="font-size: 16pt"><a href="[Link]">
<font color="#FFFFFF">::Home</font></a></font></td>
</tr>
<tr>
<td class="navlinks">
</td>
</tr>
<tr>
<td class="navlinks">
<font style="font-size: 16pt">::Parking Status</font></td>
</tr>
<tr>
<td class="navlinks"> </td>
</tr>
<tr>
<td class="navlinks"><a href="[Link]">
<font color="#FFFFFF" style="font-size: 16pt">::</font><font color="#FFFFFF" style="font-size: 13pt">About
This Project</font></a></td>
</tr>
<tr>
<td class="navlinks"> </td>
</tr>
<tr>
<td class="navlinks"><font style="font-size: 16pt">
<a href="[Link]"><font color="#FFFFFF">::Team Members</font></a></font></td>
</tr>
<tr>
<td class="navlinks"> </td>
</tr>
<td class="navlinks"><font style="font-size: 16pt">
<a href="[Link]"><font color="#FFFFFF">:: SMS</font></a></font></td>
</tr>
<tr>
<td class="navlinks"> </td>
</table>
<h3> </h3></td>
<td width="570" rowspan="2" valign="top" style="padding-left:20px; padding-top:25px; padding-right:40px;
padding-bottom:35px; ">
46
APPENDIX4:
CODE FOR THE GSM MODULE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winsock.h>
#include <time.h>
#include <windows.h>
WSADATA w;
int send(char*);
int rcv(char*);
void keepConAlive();
int checkTimeouts();
unsigned short port_numberSnd = 12000; /* The port number to use for sending */
unsigned short port_numberRcv = 11330; /* Port number to use for receiving */
char rcv_buffer[BUFFER_SIZE];
char send_buffer[BUFFER_SIZE];
time_t timeouts[10];
char confirmedReservations[10][15];
//strcpy(&OUTBUFFER[0], "The quick brown fox jumped over the lazy dog. \n\r\0");
// Open COM port
if ((comport =
CreateFile("\\\\.\\COM4", // open com5:
GENERIC_READ | GENERIC_WRITE, // for reading and writing
0, // exclusive access
NULL, // no security attributes
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL)) == INVALID_HANDLE_VALUE)
{
// error processing code goes here
}
// Set timeouts in milliseconds
[Link] = 0;
[Link] = 0;
[Link] = 100;
[Link] = 0;
[Link] = 100;
bStatus = SetCommTimeouts(comport,&CommTimeouts);
if (bStatus != 0)
{
// error processing code goes here
}
// Set Port parameters.
// Make a call to GetCommState() first in order to fill
// the comSettings structure with all the necessary values.
// Then change the ones you want and call SetCommState().
GetCommState(comport, &comSettings);
[Link] = 9600;
[Link] = ONESTOPBIT;
[Link] = 8;
[Link] = NOPARITY;
[Link] = FALSE;
49
bStatus = SetCommState(comport, &comSettings);
if (bStatus == 0)
{
// error processing code goes here
}
//printf("INBUFFER = %s", INBUFFER);
//printf("OUTBUFFER = %s", OUTBUFFER);
for(i = 0; i < 128; i++)
OUTBUFFER[i] = 0;
OUTBUFFER[0]='A';
OUTBUFFER[1]='T';
OUTBUFFER[2]=13;
//if(INBUFFER[0]!=0)
printf("INBUFFER = %s\n", INBUFFER);
Sleep(500);
OUTBUFFER[0]='A';
OUTBUFFER[1]='T';
OUTBUFFER[2]='+';
OUTBUFFER[3]='C';
OUTBUFFER[4]='P';
OUTBUFFER[5]='I';
OUTBUFFER[6]='N';
OUTBUFFER[7]='=';
OUTBUFFER[8]='5';
OUTBUFFER[9]='3';
OUTBUFFER[10]='6';
OUTBUFFER[11]='2';
50
OUTBUFFER[12]=13;
Sleep(500);
bStatus = ReadFile(comport, // Handle
&INBUFFER, // Incoming data
512, // Number of bytes to read
&bytes_read, // Number of bytes read
NULL);
if (bStatus != 0)
{
// error processing code goes here
}
//if(INBUFFER[0]!=0)
printf("INBUFFER = %s\n", INBUFFER);
Sleep(500);
/*
OUTBUFFER[0]='A';
OUTBUFFER[1]='T';
OUTBUFFER[2]='+';
OUTBUFFER[3]='C';
OUTBUFFER[4]='S';
OUTBUFFER[5]='C';
OUTBUFFER[6]='A';
OUTBUFFER[7]='=';
OUTBUFFER[8]=34;
OUTBUFFER[9]='+';
OUTBUFFER[10]='9';
OUTBUFFER[11]='6';
OUTBUFFER[12]='6';
OUTBUFFER[13]='5';
OUTBUFFER[14]='0';
OUTBUFFER[15]='5';
OUTBUFFER[16]='0';
OUTBUFFER[17]='3';
OUTBUFFER[18]='1';
OUTBUFFER[19]='9';
OUTBUFFER[20]='9';
OUTBUFFER[21]='9';
OUTBUFFER[22]=34;
OUTBUFFER[23]=13;
*/
OUTBUFFER[0]='A';
OUTBUFFER[1]='T';
OUTBUFFER[2]='+';
OUTBUFFER[3]='C';
OUTBUFFER[4]='S';
OUTBUFFER[5]='C';
OUTBUFFER[6]='A';
OUTBUFFER[7]='=';
OUTBUFFER[8]=34;
OUTBUFFER[9]='+';
OUTBUFFER[10]='9';
51
OUTBUFFER[11]='6';
OUTBUFFER[12]='6';
OUTBUFFER[13]='5';
OUTBUFFER[14]='9';
OUTBUFFER[15]='0';
OUTBUFFER[16]='1';
OUTBUFFER[17]='0';
OUTBUFFER[18]='0';
OUTBUFFER[19]='8';
OUTBUFFER[20]='8';
OUTBUFFER[21]='0';
OUTBUFFER[22]=34;
OUTBUFFER[23]=13;
Sleep(500);
bStatus = ReadFile(comport, // Handle
&INBUFFER, // Incoming data
512, // Number of bytes to read
&bytes_read, // Number of bytes read
NULL);
if (bStatus != 0)
{
// error processing code goes here
}
//if(INBUFFER[0]!=0)
printf("INBUFFER = %s\n", INBUFFER);
Sleep(500);
OUTBUFFER[0]='A';
OUTBUFFER[1]='T';
OUTBUFFER[2]='+';
OUTBUFFER[3]='C';
OUTBUFFER[4]='M';
OUTBUFFER[5]='G';
OUTBUFFER[6]='F';
OUTBUFFER[7]='=';
OUTBUFFER[8]='1';
OUTBUFFER[9]=13;
Sleep(1000);
bStatus = ReadFile(comport, // Handle
&INBUFFER, // Incoming data
512, // Number of bytes to read
&bytes_read, // Number of bytes read
NULL);
if (bStatus != 0)
52
{
// error processing code goes here
}
//if(INBUFFER[0]!=0)
printf("INBUFFER = %s\n", INBUFFER);
Sleep(500);
OUTBUFFER[0]='A';
OUTBUFFER[1]='T';
OUTBUFFER[2]='+';
OUTBUFFER[3]='C';
OUTBUFFER[4]='N';
OUTBUFFER[5]='M';
OUTBUFFER[6]='I';
OUTBUFFER[7]='=';
OUTBUFFER[8]='1';
OUTBUFFER[9]=',';
OUTBUFFER[10]='2';
OUTBUFFER[11]=',';
OUTBUFFER[12]='0';
OUTBUFFER[13]=',';
OUTBUFFER[14]='0';
OUTBUFFER[15]=',';
OUTBUFFER[16]='0';
OUTBUFFER[17]=13;
Sleep(500);
bStatus = ReadFile(comport, // Handle
&INBUFFER, // Incoming data
512, // Number of bytes to read
&bytes_read, // Number of bytes read
NULL);
if (bStatus != 0)
{
// error processing code goes here
}
//if(INBUFFER[0]!=0)
printf("INBUFFER = %s\n", INBUFFER);
Sleep(500);
OUTBUFFER[0]='A';
OUTBUFFER[1]='T';
OUTBUFFER[2]='+';
OUTBUFFER[3]='C';
OUTBUFFER[4]='M';
OUTBUFFER[5]='G';
OUTBUFFER[6]='D';
OUTBUFFER[7]='=';
OUTBUFFER[8]='0';
53
OUTBUFFER[9]=',';
OUTBUFFER[10]='4';
OUTBUFFER[11]=13;
Sleep(3000);
bStatus = ReadFile(comport, // Handle
&INBUFFER, // Incoming data
512, // Number of bytes to read
&bytes_read, // Number of bytes read
NULL);
if (bStatus != 0)
{
// error processing code goes here
}
//if(INBUFFER[0]!=0)
printf("INBUFFER = %s\n", INBUFFER);
Sleep(100);
rcv(rcv_buffer);
totalFree = (rcv_buffer[0]-48)*10+(rcv_buffer[1]-48);
cmd = rcv_buffer[2];
send_buffer[0] = 'X';
send(send_buffer);
while(1)
{
myInd = 0;
if(processing == 0)
{
//printf("inside WHILE\n");
rcv(rcv_buffer);
totalFree = (rcv_buffer[0]-48)*10+(rcv_buffer[1]-48);
cmd = rcv_buffer[2];
}
keepConAlive();
Sleep(100);
keepConAlive();
Sleep(100);
keepConAlive();
Sleep(100);
keepConAlive();
Sleep(100);
keepConAlive();
Sleep(100);
if(INBUFFER[0]!=0)
{
printf("INBUFFER = %s\n", INBUFFER);
for(i = 0; i<500; i++)
if(INBUFFER[i] == '+')
{
myInd = i;
//printf("index = %d\n", myInd);
break;
}
}
smsNum[0] = INBUFFER[14];
smsNum[1] = INBUFFER[13];
OUTBUFFER[0]='A';
OUTBUFFER[1]='T';
OUTBUFFER[2]='+';
OUTBUFFER[3]='C';
OUTBUFFER[4]='M';
OUTBUFFER[5]='G';
OUTBUFFER[6]='R';
OUTBUFFER[7]='=';
OUTBUFFER[8]=smsNum[0];
55
OUTBUFFER[9]=13;
printf("\nEnd CMTI\n");
printf("OUTBUFFER = %s\n", OUTBUFFER);
Sleep(500);
keepConAlive();
bStatus = ReadFile(comport, // Handle
&INBUFFER, // Incoming data
512, // Number of bytes to read
&bytes_read, // Number of bytes read
NULL);
if (bStatus != 0)
{
// error processing code goes here
}
smsC = INBUFFER[73];
OUTBUFFER[0]='A';
OUTBUFFER[1]='T';
OUTBUFFER[2]='+';
OUTBUFFER[3]='C';
OUTBUFFER[4]='M';
OUTBUFFER[5]='G';
OUTBUFFER[6]='S';
OUTBUFFER[7]='=';
for(h = 0; h < 15; h++)
OUTBUFFER[h+8] = mobNum[h];
OUTBUFFER[23] = 13;
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
/*keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
*/
if(totalFree>reservationLimit)
{
OUTBUFFER[0]='F';
OUTBUFFER[1]='r';
OUTBUFFER[2]='e';
OUTBUFFER[3]='e';
OUTBUFFER[4]='=';
OUTBUFFER[5]=(totalFree/10)+48;
OUTBUFFER[6]=(totalFree%10)+48;
OUTBUFFER[7]=' ';
OUTBUFFER[8]='R';
OUTBUFFER[9]='e';
OUTBUFFER[10]='s';
OUTBUFFER[11]='e';
OUTBUFFER[12]='r';
OUTBUFFER[13]='v';
OUTBUFFER[14]='a';
OUTBUFFER[15]='t';
57
OUTBUFFER[16]='i';
OUTBUFFER[17]='o';
OUTBUFFER[18]='n';
OUTBUFFER[19]='_';
OUTBUFFER[20]='P';
OUTBUFFER[21]='o';
OUTBUFFER[22]='s';
OUTBUFFER[23]='s';
OUTBUFFER[24]='i';
OUTBUFFER[25]='b';
OUTBUFFER[26]='l';
OUTBUFFER[27]='e';
lengthOfString = 28;
}
else
{
OUTBUFFER[0]='F';
OUTBUFFER[1]='r';
OUTBUFFER[2]='e';
OUTBUFFER[3]='e';
OUTBUFFER[4]='=';
OUTBUFFER[5]=(totalFree/10)+48;
OUTBUFFER[6]=(totalFree%10)+48;
OUTBUFFER[7]=' ';
OUTBUFFER[8]='R';
OUTBUFFER[9]='e';
OUTBUFFER[10]='s';
OUTBUFFER[11]='e';
OUTBUFFER[12]='r';
OUTBUFFER[13]='v';
OUTBUFFER[14]='a';
OUTBUFFER[15]='t';
OUTBUFFER[16]='i';
OUTBUFFER[17]='o';
OUTBUFFER[18]='n';
OUTBUFFER[19]='_';
OUTBUFFER[20]='N';
OUTBUFFER[21]='o';
OUTBUFFER[22]='t';
OUTBUFFER[23]='_';
OUTBUFFER[24]='P';
OUTBUFFER[25]='o';
OUTBUFFER[26]='s';
OUTBUFFER[27]='s';
OUTBUFFER[28]='i';
OUTBUFFER[29]='b';
OUTBUFFER[30]='l';
OUTBUFFER[31]='e';
lengthOfString = 32;
}
Sleep(500);
keepConAlive();
for(i = 0; i < 512; i++)
INBUFFER[i] = 0;
OUTBUFFER[0]=26;
Sleep(500);
keepConAlive();
for(i = 0; i < 512; i++)
INBUFFER[i] = 0;
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
}
else if((smsC == 'R')||(smsC == 'r'))
{
printf("\nReceived Reserve\n");
for(i = 0; i < 128; i++)
OUTBUFFER[i] = 0;
if(totalFree>=reservationLimit)
{
59
printf("\nReserving\n");
for(h = 0; h < 15; h++)
confirmedReservations[resIndex][h] = mobNum[h];
timeouts[resIndex]=time(NULL);
resIndex++;
OUTBUFFER[0]='R';
OUTBUFFER[1]='e';
OUTBUFFER[2]='s';
OUTBUFFER[3]='e';
OUTBUFFER[4]='r';
OUTBUFFER[5]='v';
OUTBUFFER[6]='a';
OUTBUFFER[7]='t';
OUTBUFFER[8]='i';
OUTBUFFER[9]='o';
OUTBUFFER[10]='n';
OUTBUFFER[11]='_';
OUTBUFFER[12]='C';
OUTBUFFER[13]='o';
OUTBUFFER[14]='n';
OUTBUFFER[15]='f';
OUTBUFFER[16]='i';
OUTBUFFER[17]='r';
OUTBUFFER[18]='m';
OUTBUFFER[19]='e';
OUTBUFFER[20]='d';
lengthOfString = 21;
cmdToSend='R';
}
else
{
printf("\nCan't Reserve\n");
OUTBUFFER[0]='R';
OUTBUFFER[1]='e';
OUTBUFFER[2]='s';
OUTBUFFER[3]='e';
OUTBUFFER[4]='r';
OUTBUFFER[5]='v';
OUTBUFFER[6]='a';
OUTBUFFER[7]='t';
OUTBUFFER[8]='i';
OUTBUFFER[9]='o';
OUTBUFFER[10]='n';
OUTBUFFER[11]='_';
OUTBUFFER[12]='I';
OUTBUFFER[13]='s';
OUTBUFFER[14]='_';
OUTBUFFER[15]='U';
OUTBUFFER[16]='n';
OUTBUFFER[17]='a';
OUTBUFFER[18]='v';
OUTBUFFER[19]='a';
OUTBUFFER[20]='i';
OUTBUFFER[21]='l';
OUTBUFFER[22]='a';
OUTBUFFER[23]='b';
OUTBUFFER[24]='l';
OUTBUFFER[25]='e';
OUTBUFFER[26]='_';
OUTBUFFER[27]='N';
OUTBUFFER[28]='o';
OUTBUFFER[29]='w';
lengthOfString = 30;
}
Sleep(500);
keepConAlive();
OUTBUFFER[0]=26;
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
61
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
}
else if((smsC == 'O')||(smsC == 'o'))
{
printf("\nReceived Open\n");
for(i = 0; i < 128; i++)
OUTBUFFER[i] = 0;
i = 0;
for(j = 0; j < resIndex; j++)
{
i = 0;
for(h = 0; h < 15; h++)
{
if(confirmedReservations[j][h] == mobNum[h])
i++;
}
if(i == 15)
{
//////
break;
}
}
if(i == 15)
{
//printf("\nI=15\n");
for(h = 0; h < 15; h++)
confirmedReservations[j][h] = 0;
resIndex--;
for(h = 0; h < 15; h++)
confirmedReservations[resIndex][h] = 0;
OUTBUFFER[0]='G';
OUTBUFFER[1]='a';
OUTBUFFER[2]='t';
OUTBUFFER[3]='e';
OUTBUFFER[4]='_';
OUTBUFFER[5]='O';
OUTBUFFER[6]='p';
OUTBUFFER[7]='e';
OUTBUFFER[8]='n';
OUTBUFFER[9]='i';
OUTBUFFER[10]='n';
OUTBUFFER[11]='g';
lengthOfString = 12;
cmdToSend='O';
}
else
{
printf("\nI!=15\n");
OUTBUFFER[0]='Y';
62
OUTBUFFER[1]='o';
OUTBUFFER[2]='u';
OUTBUFFER[3]='_';
OUTBUFFER[4]='D';
OUTBUFFER[5]='i';
OUTBUFFER[6]='d';
OUTBUFFER[7]='_';
OUTBUFFER[8]='N';
OUTBUFFER[9]='o';
OUTBUFFER[10]='t';
OUTBUFFER[11]='_';
OUTBUFFER[12]='R';
OUTBUFFER[13]='e';
OUTBUFFER[14]='s';
OUTBUFFER[15]='e';
OUTBUFFER[16]='r';
OUTBUFFER[17]='v';
OUTBUFFER[18]='e';
lengthOfString = 19;
}
Sleep(500);
keepConAlive();
OUTBUFFER[0]=26;
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
}
/////////////////////////////////////////////////////////////////////////
for(i = 0; i < 128; i++)
OUTBUFFER[i] = 0;
OUTBUFFER[0]='A';
OUTBUFFER[1]='T';
OUTBUFFER[2]='+';
OUTBUFFER[3]='C';
OUTBUFFER[4]='M';
OUTBUFFER[5]='G';
OUTBUFFER[6]='D';
OUTBUFFER[7]='=';
OUTBUFFER[8]='0';
OUTBUFFER[9]=',';
OUTBUFFER[10]='4';
OUTBUFFER[11]=13;
Sleep(500);
keepConAlive();
64
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
//if(INBUFFER[0]!=0)
printf("INBUFFER = %s\n", INBUFFER);
Sleep(500);
keepConAlive();
Sleep(500);
keepConAlive();
processing = 0;
/////////////////////////////////////////////////////////////////////////
if((resIndex>0)&&(cmdToSend=='X'))
if(checkTimeouts()==1)
cmdToSend = 'C';
//*******************************************************************
if (bytes_received < 0)
{
fprintf(stderr, "Could not receive datagram.\n");
closesocket(sdReceiver);
WSACleanup();
system("pause");
exit(0);
}
return 0;
}
void keepConAlive()
{
int i;
for(i = 0; i < BUFFER_SIZE; i++)
{
rcv_buffer[i] = 0;
send_buffer[i] = 0;
}
rcv(rcv_buffer);
totalFree = (rcv_buffer[0]-48)*10+(rcv_buffer[1]-48);
cmd = rcv_buffer[2];
send_buffer[0] = 'X';
send(send_buffer);
}
int checkTimeouts()
{
int i, j, h;
resIndex--;
for(h = 0; h < 15; h++)
confirmedReservations[resIndex][h] = 0;
66
timeouts[resIndex] = 0;
return 1;
}
return 0;
}
AT Commnds:
AT // to check the connectivity of the GSM modem with PC
AT+CMGF=1" // working in the text mode
AT+CSCA= “+966505031999” // Message Center Number (STC)
AT+CMGS=”+966xxxxxxxxx” // put the mobile number of the receiver
AT+ CPIN=xxxx // Set up the PIN number
AT+CMGR=N // Read the SMS number N
AT+CNMI=”1,2,0,0,0" // Set the receiving mode
AT+CMGD=0,4 // Delete all the sent and received SMS
67
APPENDIX5:
CODE FOR THE SENSOR MODULE
#class auto
#define BD_RATE 9600
#define DINBUFSIZE 255
#define DOUTBUFSIZE 255
int count5,count4,count3,count2,count1,ones5,ones4,ones3,ones2,ones1,flip;
char buf1[180];
char buf2[180];
char buf3[180];
int SENSORS[6];
char i1,i2,i3,i4,i5;
main() {
serBopen(BD_RATE);
serCopen(BD_RATE);
serDopen(BD_RATE);
wfd i5=cof_serBgetc();
}
if (ones5 >= 6) {
SENSORS[5] = 1;//ADD IN ARRAY
BitWrPortI(PBDR, &PBDRShadow, 1, 5);
flip=1;
// break ;
}
else
SENSORS[5] = 0;
}
//=============================SENSOR_1_AND_2================================
===
costate{
BitWrPortI(PBDR, &PBDRShadow, 1, 7); // CAN BE REMOVED
if (flip!=1){
wfd i2=cof_serDgetc();
68
count2=0;
ones2 =0;
while(count2<20){
if(i2==82){
wfd buf2[0]=cof_serDgetc();
wfd buf2[5]=cof_serDgetc();
wfd buf2[10]=cof_serDgetc();
wfd count1=cof_serDgetc();
if(buf2[0]=='0'&&buf2[5]=='0'&&buf2[10]=='6')
ones2++;
count2++;
wfd i2=cof_serDgetc();
} // While finisfing
if (ones2>=6){
SENSORS[2]++; //ADD IN ARRAY
BitWrPortI(PBDR, &PBDRShadow, 1, 2);
// break;
}
} // if finisfing
else{
// Now CHECKING FOR SENSOR 2
BitWrPortI(PBDR, &PBDRShadow, 1,7);// CHANGE THE SELECT BIT OF THE MUX
wfd i2=cof_serDgetc();
count2=0;
ones2 =0;
while(count2<10){
if(i2==82){
wfd buf2[0]=cof_serDgetc();
wfd buf2[5]=cof_serDgetc();
wfd buf2[10]=cof_serDgetc();
wfd count1=cof_serDgetc();
if(buf2[0]=='0'&&buf2[5]=='0'&&buf2[10]=='6')
ones2++;
count2++;
if (ones2 >=6){
SENSORS[2]++;//ADD IN ARRAY
BitWrPortI(PBDR, &PBDRShadow, 1, 2);
break;
}
}
wfd i2=cof_serDgetc();
} // While finisfing
BitWrPortI(PBDR, &PBDRShadow, 0, 7);// CHANGE THE SELECT BIT OF THE MUX
while(count3<10){
if(i3==82){
wfd buf2[0]=cof_serDgetc();
wfd buf2[5]=cof_serDgetc();
wfd buf2[10]=cof_serDgetc();
wfd cof_serDgetc();
if(buf2[0]=='0'&&buf2[5]=='0'&&buf2[10]=='6')
ones3++;
count3++;
if (ones3>=6) {
SENSORS[1]++;//ADD IN ARRAY
BitWrPortI(PBDR, &PBDRShadow, 1, 1);
flip=0;
break;
}
69
}
wfd i3=cof_serDgetc();
} // While finisfing
}
//=============================SENSOR_3_AND_4================================
===
costate {
BitWrPortI(PBDR, &PBDRShadow, 1, 6); // CAN BE REMOVED
if (flip!=1){
wfd i4=cof_serCgetc();
count4=0;
ones4 =0;
while(count4<20){
if(i4==82){
wfd buf3[0]=cof_serCgetc();
wfd buf3[5]=cof_serCgetc();
wfd buf3[10]=cof_serCgetc();
wfd count1 =cof_serCgetc();
if(buf3[0]=='0'&&buf3[5]=='0'&&buf3[10]=='6')
ones4++;
count4++;
}
wfd i4=cof_serCgetc();
} // While finisfing
if (ones4>=6){
SENSORS[4]++;//ADD IN ARRAY
BitWrPortI(PBDR, &PBDRShadow, 1, 4);
// break;
}
} // if finisfing
else{
// Now CHECKING FOR SENSOR 4
wfd i4=cof_serCgetc();
count4=0;
ones4 =0;
while(count4<10){
if(i4==82){
wfd buf3[0]=cof_serCgetc();
wfd buf3[5]=cof_serCgetc();
wfd buf3[10]=cof_serCgetc();
wfd count1 =cof_serCgetc();
if(buf3[0]=='0'&&buf3[5]=='0'&&buf3[10]=='6')
ones4++;
count4++;
if (ones4>=6){
SENSORS[4]++;//ADD IN ARRAY
BitWrPortI(PBDR, &PBDRShadow, 1, 4);
break;
}
}
wfd i4=cof_serCgetc();
} // While finisfing
BitWrPortI(PBDR, &PBDRShadow, 0, 6);// CHANGE THE SELECT BIT OF THE MUX
} // While finisfing
BitWrPortI(PBDR, &PBDRShadow, 1, 6);// CHANGE THE SELECT BIT OF THE MUX
}
//=============================Clear=========================================
costate{
if(BitRdPortI(PBDR, 0) == 1)
{
BitWrPortI(PBDR, &PBDRShadow, 0, 1);
BitWrPortI(PBDR, &PBDRShadow, 0, 2);
BitWrPortI(PBDR, &PBDRShadow, 0, 3);
BitWrPortI(PBDR, &PBDRShadow, 0, 4);
BitWrPortI(PBDR, &PBDRShadow, 0, 5);
}
}
//=========================================================================
=====
}
}
71