Compare commits

...

3 Commits

View File

@ -123,7 +123,7 @@ namespace AppServer
while (line != default(string)) while (line != default(string))
{ {
BeforeWriteDB = true; BeforeWriteDB = true;
string[] tempArr = line.Split('#'); string[] tempArr = line.Split("#".ToCharArray());
//imei //imei
try try
{ {
@ -200,7 +200,7 @@ namespace AppServer
if (SpeedProccess != "") if (SpeedProccess != "")
{ {
string[] temp = SpeedProccess.Split('_'); string[] temp = SpeedProccess.Split("_".ToCharArray());
int speedT = (int)Convert.ToDouble(temp[0]); int speedT = (int)Convert.ToDouble(temp[0]);
string speedU = temp[1]; string speedU = temp[1];
processSpeedAlarm(radioID2, dec2.cell, speedT, speedU, alarm.Email, !prevGps); processSpeedAlarm(radioID2, dec2.cell, speedT, speedU, alarm.Email, !prevGps);
@ -288,37 +288,40 @@ namespace AppServer
//Calculate status //Calculate status
if (MainForm.VehicleHashStat.ContainsKey(radioID2.ToString()) && !prevGps) if (MainForm.VehicleHashStat.ContainsKey(radioID2.ToString()) && !prevGps)
{ {
VehicleStatus vehicleStatus = (VehicleStatus)MainForm.VehicleHashStat[radioID2];
//MADE ON status when is the case //MADE ON status when is the case
if ((((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus == Status_for_tab.MADEOFF) if ((vehicleStatus.curentStatus == Status_for_tab.MADEOFF)
|| (((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus == Status_for_tab.OFF)) || (vehicleStatus.curentStatus == Status_for_tab.OFF))
{ {
((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus = Status_for_tab.MADEON; vehicleStatus.curentStatus = Status_for_tab.MADEON;
PushStatus(radioID2, Status_for_tab.MADEON); PushStatus(radioID2, Status_for_tab.MADEON);
} }
// update last status location and position time // update last status location and position time
((VehicleStatus)MainForm.VehicleHashStat[radioID2]).lastPositionTime = DateTime.Now; vehicleStatus.lastPositionTime = DateTime.Now;
((VehicleStatus)MainForm.VehicleHashStat[radioID2]).lat = dec2.cell.d_lat; vehicleStatus.lat = dec2.cell.d_lat;
((VehicleStatus)MainForm.VehicleHashStat[radioID2]).lng = dec2.cell.d_lng; vehicleStatus.lng = dec2.cell.d_lng;
// do not push any status update if the current status is emergency // do not push any status update if the current status is emergency
if (((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus != Status_for_tab.EMERG) if (vehicleStatus.curentStatus != Status_for_tab.EMERG)
{ {
if (dec2.cell.lat != "0" && dec2.cell.lat != "0.00000") if (dec2.cell.lat != "0" && dec2.cell.lat != "0.00000")
{ {
if (((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus != Status_for_tab.GPS_ON) if (vehicleStatus.curentStatus != Status_for_tab.GPS_ON)
{ {
((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus = Status_for_tab.GPS_ON; vehicleStatus.curentStatus = Status_for_tab.GPS_ON;
//SM.Debug("Push Status GPS ON for radio:"+radioID2); //SM.Debug("Push Status GPS ON for radio:"+radioID2);
PushStatus(radioID2, Status_for_tab.GPS_ON); PushStatus(radioID2, Status_for_tab.GPS_ON);
} }
} }
else else
{ {
if (((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus != Status_for_tab.NOGPSFIX) if (vehicleStatus.curentStatus != Status_for_tab.NOGPSFIX)
{ {
((VehicleStatus)MainForm.VehicleHashStat[radioID2]).curentStatus = Status_for_tab.NOGPSFIX; vehicleStatus.curentStatus = Status_for_tab.NOGPSFIX;
PushStatus(radioID2, Status_for_tab.NOGPSFIX); PushStatus(radioID2, Status_for_tab.NOGPSFIX);
} }
} }
@ -407,7 +410,7 @@ namespace AppServer
try try
{ {
MailAddress from = new MailAddress(Program.cfg.emailAddress); MailAddress from = new MailAddress(Program.cfg.emailAddress);
String[] address = mailAdr.Split(';'); String[] address = mailAdr.Split(";".ToCharArray());
MailAddress to = new MailAddress(address[0]); MailAddress to = new MailAddress(address[0]);
MailMessage message = new MailMessage(from, to); MailMessage message = new MailMessage(from, to);
if (address.Count() > 1) if (address.Count() > 1)
@ -415,8 +418,10 @@ namespace AppServer
Boolean skipeFirst = true; Boolean skipeFirst = true;
foreach (String obj in address) foreach (String obj in address)
{ {
if (skipeFirst) { skipeFirst = false; } if (skipeFirst)
else message.To.Add(new MailAddress(obj)); { skipeFirst = false; }
else
message.To.Add(new MailAddress(obj));
} }
} }
message.Subject = subj; message.Subject = subj;
@ -497,15 +502,17 @@ namespace AppServer
else if ((obj2.AlarmType == 1) && (position == 2)) validAlarm = true; else if ((obj2.AlarmType == 1) && (position == 2)) validAlarm = true;
else if ((obj2.AlarmType == 2) && (position == 1)) validAlarm = true; else if ((obj2.AlarmType == 2) && (position == 1)) validAlarm = true;
else if (obj2.AlarmType == 4) validAlarm = false; else if (obj2.AlarmType == 4) validAlarm = false;
if (validAlarm) if (validAlarm)
{ {
Utils.WriteLine("Add new zone alarm"); Utils.WriteLine("Add new zone alarm");
DBalarm.Insert_Zone_Alarm(((Vehicle_Data)MainForm.VehList[radioID.ToString()]).sc_id, time, obj2.zone_id, obj2.action, true); DBalarm.Insert_Zone_Alarm(((Vehicle_Data)MainForm.VehList[radioID.ToString()]).sc_id, time, obj2.zone_id, obj2.action, true);
Utils.WriteLine("Done Add new zone alarm"); Utils.WriteLine("Done Add new zone alarm");
if (obj2.speedUnit.Equals("k"))
{
string speed_km_or_mph = obj2.speedUnit.Equals("k") ? $"{speed} km/h" : $"{speedMiles} mph";
string message = "Zone alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name + " " + tmpresp string message = "Zone alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name + " " + tmpresp
+ ". Unit speed " + speed + " km/h at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]"; + $". Unit speed {speed_km_or_mph} at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]";
string title = "Zone alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name; string title = "Zone alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name;
if (mailAdr != "") if (mailAdr != "")
@ -516,23 +523,8 @@ namespace AppServer
}); });
} }
}
else
{
string message = "Zone alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name + " " + tmpresp
+ ". Unit speed " + speedMiles + " mph at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]";
string title = "Zone alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name;
if (mailAdr != "")
{
Task.Factory.StartNew(() =>
{
sendAlarmMail(title, message, mailAdr);
});
}
}
String test = ""; String test = "";
if (sendOnMsgBus) if (sendOnMsgBus)
@ -548,14 +540,15 @@ namespace AppServer
{ {
String listOfUnits = obj2.unitids; String listOfUnits = obj2.unitids;
String listOfImeis = obj2.imeilist; String listOfImeis = obj2.imeilist;
String[] tmpunits = listOfUnits.Split(','); String[] tmpunits = listOfUnits.Split(",".ToCharArray());
String[] tmpimeis = listOfImeis.Split(','); String[] tmpimeis = listOfImeis.Split(",".ToCharArray());
Hashtable tmpHashName = new Hashtable(); Hashtable tmpHashName = new Hashtable();
if (tmpunits.Count() > 1) if (tmpunits.Count() > 1)
{ {
for (Int32 i = 0; i < tmpunits.Count() - 1; i++) for (Int32 i = 0; i < tmpunits.Count() - 1; i++)
tmpHashName.Add((String)tmpunits[i], (String)tmpimeis[i]); tmpHashName.Add((String)tmpunits[i], (String)tmpimeis[i]);
} }
foreach (String keyobj in tmpHashName.Keys) foreach (String keyobj in tmpHashName.Keys)
{ {
int obj = -1; int obj = -1;
@ -572,6 +565,7 @@ namespace AppServer
} }
} }
} }
if (obj2.sentmsg2 && sendOnMsgBus) if (obj2.sentmsg2 && sendOnMsgBus)
{ {
tmpX = dbvehs.getSystemPositionIMEI(radioID); tmpX = dbvehs.getSystemPositionIMEI(radioID);
@ -580,6 +574,7 @@ namespace AppServer
Utils.WriteLine($"Zone alert sms request [{obj2.msgbody2}] for unit {radioID} on gw [{(tmpX.Gw_id + "." + tmpX.R_gw_id)}]"); Utils.WriteLine($"Zone alert sms request [{obj2.msgbody2}] for unit {radioID} on gw [{(tmpX.Gw_id + "." + tmpX.R_gw_id)}]");
} }
//send Callout //send Callout
if(obj2.callout && tmpresp.ToString().Contains("IN ")) if(obj2.callout && tmpresp.ToString().Contains("IN "))
{ {
@ -590,6 +585,7 @@ namespace AppServer
callOutQueue.PostItem(new CallOut() { RadioID = radioID, Severity = obj2.calloutSeverity, Time = DateTime.Now}); callOutQueue.PostItem(new CallOut() { RadioID = radioID, Severity = obj2.calloutSeverity, Time = DateTime.Now});
Utils.WriteLine($"Zone CallOut request with Severity [{obj2.calloutSeverity}] for unit {radioID} on gw [{(tmpX.Gw_id + "." + tmpX.R_gw_id)}]"); Utils.WriteLine($"Zone CallOut request with Severity [{obj2.calloutSeverity}] for unit {radioID} on gw [{(tmpX.Gw_id + "." + tmpX.R_gw_id)}]");
} }
///send email ///send email
if (obj2.sentemail) if (obj2.sentemail)
{ {
@ -613,10 +609,11 @@ namespace AppServer
{ {
Utils.WriteLine("Insert Landmarks Alarm " + radioID.ToString() + " " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).sc_id); Utils.WriteLine("Insert Landmarks Alarm " + radioID.ToString() + " " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).sc_id);
DBalarm.Insert_Zone_Alarm(((Vehicle_Data)MainForm.VehList[radioID.ToString()]).sc_id, time, obj2.land_id, obj2.action, false); DBalarm.Insert_Zone_Alarm(((Vehicle_Data)MainForm.VehList[radioID.ToString()]).sc_id, time, obj2.land_id, obj2.action, false);
if (obj2.speedUnit.Equals("k"))
{
string speed_km_or_mph = obj2.speedUnit.Equals("k") ? $"{speed} km/h" : $"{speedMiles} mph";
string message = "Landmark alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name + " " + tmpresp string message = "Landmark alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name + " " + tmpresp
+ ". Unit speed " + speed + " km/h at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]"; + $". Unit speed {speed_km_or_mph} at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]";
string title = "Landmark alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name; string title = "Landmark alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name;
if (mailAdr != "") if (mailAdr != "")
{ {
@ -625,20 +622,8 @@ namespace AppServer
sendAlarmMail(title, message, mailAdr); sendAlarmMail(title, message, mailAdr);
}); });
} }
}
else
{
string message = "Landmark alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name + " " + tmpresp
+ ". Unit speed " + speedMiles + " mph at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]";
string title = "Landmark alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name;
if (mailAdr != "")
{
Task.Factory.StartNew(() =>
{
sendAlarmMail(title, message, mailAdr);
});
}
}
if (sendOnMsgBus) if (sendOnMsgBus)
{ {
@ -683,10 +668,17 @@ namespace AppServer
DBalarmManager DBalarm = new DBalarmManager(Program.cfg.DB_IP, Program.cfg.DB_schema, Program.cfg.DB_user, Program.cfg.DB_passwd, Program.cfg.DB_port); DBalarmManager DBalarm = new DBalarmManager(Program.cfg.DB_IP, Program.cfg.DB_schema, Program.cfg.DB_user, Program.cfg.DB_passwd, Program.cfg.DB_port);
int speed = (int)Convert.ToDouble(cell.spd); int speed = (int)Convert.ToDouble(cell.spd);
int treshold = (int)Convert.ToDouble(speedTreshold); int speedMiles = (int)Math.Round(speed * 0.621371192);
uint time = DateTo70Format(cell.location_time); uint time = DateTo70Format(cell.location_time);
string speed4send = speed.ToString() + "_" + speedUnits; string speed4send = speed.ToString() + "_" + speedUnits;
int treshold = (int)Convert.ToDouble(speedTreshold);
if (speedUnits == "m")
treshold = (int)(treshold * 1.609);
if (speedUnits != "m") if (speedUnits != "m")
{ {
if (speed >= treshold) if (speed >= treshold)
@ -694,8 +686,11 @@ namespace AppServer
Utils.WriteLine("Speed alarm detected!"); Utils.WriteLine("Speed alarm detected!");
DBalarm.Insert_Speed_Alarm(radioID, time, speed,cell.lat,cell.lng); DBalarm.Insert_Speed_Alarm(radioID, time, speed,cell.lat,cell.lng);
Utils.WriteLine("Done inserting speed alarm!"); Utils.WriteLine("Done inserting speed alarm!");
string speed_km_or_mph = (speedUnits != "m") ? $"{speed} km/h" : $"{speedMiles} mph";
string message = "Speed alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name string message = "Speed alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name
+ ". Unit speed " + speed + " km/h at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]"; + $". Unit speed {speed_km_or_mph} at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]";
string title = "Speed alarm for unit " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name; string title = "Speed alarm for unit " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name;
if (mailAdr != "") if (mailAdr != "")
{ {
@ -713,32 +708,6 @@ namespace AppServer
} }
} }
} }
else
{
if (speed >= (treshold * 1.609))
{
DBalarm.Insert_Speed_Alarm(radioID, time, speed, cell.lat, cell.lng);
String speedMiles = Convert.ToString((int)Math.Round(speed * 0.621371192));
SM.Debug("Speed alarm generated!");
string message = "Speed alarm for " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name
+ ". Unit speed " + speedMiles + " mph at time:" + Utils.UnixTimeStampToDateTime(time).ToLocalTime() + " [" + cell.lat + " , " + cell.lng + "]";
string title = "Speed alarm for unit " + ((Vehicle_Data)MainForm.VehList[radioID.ToString()]).Name;
if (mailAdr != "Speed alarm")
{
Task.Factory.StartNew(() =>
{
sendAlarmMail(title, message, mailAdr);
});
}
if (sendOnMsgBus)
{
//send alarm on message buss
string test = "#135#" + radioID.ToString() + "#" + speed4send + "#";
MainForm.udp.Send(SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test), SafeMobileLib.Utils.Convert_text_For_multicast("#0.0" + test).Length);
}
}
}
} }
#endregion #endregion