Friday, September 28, 2012

How GPS Work?

GPS applications are very popular today. Ever wondering how it works?

Here are simple explanation on how GPS works:

1. First we need GPS Satellites that orbit the earth and GPS Receiver / Device



2. GPS Satellites broadcast GPS Signals that contains Satellite ID and Time



3. From the Satellite ID and Time, the distance between receiver and the satellite can be determined
GPS Receiver will now know that it can be anywhere within X km distance from the satellite.


4. Now, GPS Receiver will calculate signal from 2nd satellite


5. Next, the 3rd satellite


6. GPS Receiver need at least 4 satellites to determine its location


How to ensure that the time is accurate?

The accuracy of the clock on the satellite and receiver is important. This is because the time is used to measure distance from the satellite to the receiver.

To ensure the accuracy of the time, an atomic clock is used on GPS Satellites. But expensive atomic clock is not practical for consumer GPS device.

GPS Receiver use normal inexpensive quartz clock. Therefore it need to periodically synchronize it's time. GPS Receiver calculate / estimate current time by comparing GPS Signal it received from several satellites. The correct time is the one that cause all the spheres (explained above) to align at a single point.

Type of data sent by GPS Satellite

Basically there are 3 types of data sent by GPS Satellites:

1. Almanac Data (sent every 12.5 minutes)

Tell us about approximate location of all satellites.
Tell the GPS Receiver which satellites it should expect to see from it's current location.

2. Ephemeris Data (sent every 30 seconds)

Contains detail satellite orbit information

3. Pseudo Random Code

Contains Satellite ID and Time

How long it took to get first fix?


1. Cold or Factory (15 mins)

Occurred when the last GPS Fix is more than 180 days.
The receiver need to download almanac data which is sent every 12.5 mins and valid for 180 days.

2. Warm or Normal (1 mins)

Occurred when the receiver has approximate time accuracy of ± 20 secs, position ± 100 km from the last GPS Fix, speed < 90 km/h, and a valid almanac data.
The receiver need to download ephemeris data which is sent every 30 secs and valid for 4 hours.

3. Hot or standby (<30 secs)  

The receiver has valid time, position, almanac, and ephemeris data.


How to improve the time to first fix?

Assisted GPS / AGPS that provide Almanac and Ephemeris Data on demand to the GPS Receiver.

Source of GPS Error

What cause the GPS location shown by the device to be inaccurate?

1. Multi-path effect

When the GPS Receiver is placed between tall buildings or urban canyon, the GPS Signal form satellite will hit the tall buildings and bounce before hitting the receiver. This will cause the time calculation to be inaccurate, therefore the location calculated will be inaccurate.

2. Atmospheric effect

Atmospheric condition may effect the GPS Signal travel time.

3. Clock inaccuracy

4. Rounding effect

How to improve GPS accuracy?

Generally, GPS accuracy is between 5-15m.

1. Differential GPS

Produce 3-5m accuracy.

2. Wide Area Augmentation System

Produce 1-3m accuracy.


Sunday, July 22, 2012

All Accounts Locked Due to Accessing User Account Manager from Control Panel in Server 2008

Just faced with interesting problem few days back. All user accounts on our Windows Server 2008 Standard Edition suddenly locked. After browsing through the Event Viewer Security logs, we noticed multiple Audit Failure entry for all user accounts with the following details:
- Event ID : 4625
- Caller Process Name : dllhost.exe
- Happened within the same seconds for all users

It is quite impossible for all users to coincidentally failed to log on at the same time. At first we thought of the possibility of denial of service attack on the servers. After some browsing on the Internet and thinking through what we have done before this incident happened, we suspect that this is due to Account Management feature accessible from Control Panel.

We did some simple test to confirm the root cause of this issue:

1. Add audit success and audit failure on the Audit Policy under Local Security Policy setting

2. Open Event Viewer, go to Windows Log, Security
Filter Event ID : 4625


3. Open User Accounts under Control Panel



4. Click Manage Another Accounts link
This action will trigger Audit Failure on the Event Viewer Log for all user accounts



5. Go back to Event Viewer and press Refresh
You will notice a lot of Audit Failure Entry which occurred at the same time.
This will trigger account lock out if Account Lockout Policy is configured



Tuesday, June 26, 2012

MySQL Spatial Query Example

CREATE TABLE Points (
NAME VARCHAR(16) PRIMARY KEY,
location POINT NOT NULL,
description VARCHAR(128),
SPATIAL INDEX(location)
) ENGINE = MYISAM;

INSERT INTO Points (NAME, location) VALUES ( 'point1' , GEOMFROMTEXT( ' POINT(31.5 42.2) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point2' , GEOMFROMTEXT( ' POINT(10 10) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point3' , GEOMFROMTEXT( ' POINT(20 10) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point4' , GEOMFROMTEXT( ' POINT(30 10) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point5' , GEOMFROMTEXT( ' POINT(40 10) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point6' , GEOMFROMTEXT( ' POINT(10 20) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point7' , GEOMFROMTEXT( ' POINT(20 20) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point8' , GEOMFROMTEXT( ' POINT(30 20) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point9' , GEOMFROMTEXT( ' POINT(40 20) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point10' , GEOMFROMTEXT( ' POINT(10 30) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point11' , GEOMFROMTEXT( ' POINT(20 30) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point12' , GEOMFROMTEXT( ' POINT(30 30) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point13' , GEOMFROMTEXT( ' POINT(40 30) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point14' , GEOMFROMTEXT( ' POINT(10 40) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point15' , GEOMFROMTEXT( ' POINT(20 40) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point16' , GEOMFROMTEXT( ' POINT(30 40) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point17' , GEOMFROMTEXT( ' POINT(40 40) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point18' , GEOMFROMTEXT( ' POINT(10 50) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point19' , GEOMFROMTEXT( ' POINT(20 50) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point20' , GEOMFROMTEXT( ' POINT(30 50) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point21' , GEOMFROMTEXT( ' POINT(40 50) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point22' , GEOMFROMTEXT( ' POINT(10 60) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point23' , GEOMFROMTEXT( ' POINT(20 60) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point24' , GEOMFROMTEXT( ' POINT(30 60) ' ) );
INSERT INTO Points (NAME, location) VALUES ( 'point25' , GEOMFROMTEXT( ' POINT(40 60) ' ) );

SELECT NAME, ASTEXT(location) FROM Points;

Query by Radius (10):

SET @center = GEOMFROMTEXT('POINT(25 25)');
SET @radius = 10;
SET @bbox = CONCAT('POLYGON((',
X(@center) - @radius, ' ', Y(@center) - @radius, ',',
X(@center) + @radius, ' ', Y(@center) - @radius, ',',
X(@center) + @radius, ' ', Y(@center) + @radius, ',',
X(@center) - @radius, ' ', Y(@center) + @radius, ',',
X(@center) - @radius, ' ', Y(@center) - @radius, '))'
);


SELECT NAME, ASTEXT(location)
FROM Points
WHERE INTERSECTS( location, GEOMFROMTEXT(@bbox) )
AND SQRT(POW( ABS( X(location) - X(@center)), 2) + POW( ABS(Y(location) - Y(@center)), 2 )) < @radius;


SELECT NAME, ASTEXT(location), SQRT(POW( ABS( X(location) - X(@center)), 2) + POW( ABS(Y(location) - Y(@center)), 2 )) AS distance
FROM Points
WHERE INTERSECTS( location, GEOMFROMTEXT(@bbox) )
AND SQRT(POW( ABS( X(location) - X(@center)), 2) + POW( ABS(Y(location) - Y(@center)), 2 )) < @radius
ORDER BY distance;