108 lines
3.3 KiB
C#
108 lines
3.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using SafeNetLib;
|
|
using System.Collections;
|
|
using System.Threading;
|
|
|
|
namespace ConnectPlus_SOC
|
|
{
|
|
class TestGPS
|
|
{
|
|
private int freq; // in seconds
|
|
private double latStart;
|
|
private double lngStart;
|
|
private static System.Threading.Timer tSim;
|
|
private DateTime gpsTime;
|
|
|
|
public TestGPS(int _freq, double _latStart, double _lngStart)
|
|
{
|
|
freq = _freq;
|
|
latStart = _latStart;
|
|
lngStart = _lngStart;
|
|
gpsTime = DateTime.UtcNow;
|
|
|
|
/*
|
|
for (int i = 0; i < 100; i++)
|
|
{
|
|
GPSpos pos = getLocation(lngStart, latStart, 30000);
|
|
}
|
|
*/
|
|
tSim = new System.Threading.Timer(Sim_callback, null, new TimeSpan(0, 0, 5), new TimeSpan(0, 0, freq));
|
|
|
|
|
|
}
|
|
|
|
private void Sim_callback(Object state)
|
|
{
|
|
try
|
|
{
|
|
gpsTime = DateTime.UtcNow;
|
|
foreach (DictionaryEntry entry in SN_Queues.ht_SUInfo)
|
|
{
|
|
SUinfo su = (SUinfo)entry.Value;
|
|
GPSpos pos = getLocation(lngStart, latStart, 30000);
|
|
|
|
htCell_t cell = new htCell_t();
|
|
|
|
cell.lat = pos.lat.ToString();
|
|
cell.d_lat = pos.lat;
|
|
cell.lng = pos.lng.ToString();
|
|
cell.d_lng = pos.lng;
|
|
cell.di = "0";
|
|
cell.suid = su.suid;
|
|
cell.location_time = gpsTime;
|
|
cell.activity_time = gpsTime;
|
|
cell.triggered = true;
|
|
cell.spd = "50";
|
|
|
|
SN_Queues.DBQueueLocation.PostItem(cell);
|
|
//LOGS.LOG(ConnectPlus_GW.cfg.gw_id + cell.suid + " Trig GPS<lat:" + cell.lat + "><lng:" + cell.lng + ">");
|
|
//su.suid;
|
|
//Console.WriteLine("{0}, {1}", entry.Key, entry.Value);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Utils.ConsWrite(DebugMSG_Type.test, "Sim_callback errot : " + ex.ToString());
|
|
}
|
|
}
|
|
|
|
//r is in meters
|
|
public GPSpos getLocation(double x0, double y0, int radius)
|
|
{
|
|
Random random = new Random();
|
|
|
|
// Convert radius from meters to degrees
|
|
double radiusInDegrees = radius / 111000f;
|
|
|
|
double u = random.NextDouble();
|
|
double v = random.NextDouble();
|
|
Thread.Sleep(10);
|
|
double w = radiusInDegrees * Math.Sqrt(u);
|
|
double t = 2 * Math.PI * v;
|
|
double x = w * Math.Cos(t);
|
|
double y = w * Math.Sin(t);
|
|
|
|
// Adjust the x-coordinate for the shrinking of the east-west distances
|
|
double new_x = x / Math.Cos(y0);
|
|
|
|
double foundLongitude = new_x + x0;
|
|
double foundLatitude = y + y0;
|
|
Utils.ConsWrite(DebugMSG_Type.test, "Longitude: " + foundLongitude + " Latitude: " + foundLatitude);
|
|
|
|
GPSpos pos = new GPSpos();
|
|
pos.lat = foundLatitude;
|
|
pos.lng = foundLongitude;
|
|
|
|
return pos;
|
|
}
|
|
|
|
public class GPSpos
|
|
{
|
|
public double lat;
|
|
public double lng;
|
|
}
|
|
}
|
|
}
|