Subversion Repositories HomeAutomation

Rev

Rev 1952 | Rev 1959 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1952 Rev 1956
Line 27... Line 27...
27
    }
27
    }
28
    else if (event_string == "position")
28
    else if (event_string == "position")
29
    {
29
    {
30
      if (data.Position !== false && self.tracked_node_ids_[data.Info.Imei])
30
      if (data.Position !== false && self.tracked_node_ids_[data.Info.Imei])
31
      {
31
      {
-
 
32
        if (data.Position.Type != "NO")
-
 
33
        {
32
        var query  =  "INSERT INTO `Positions` (`node_id`, `source`, `latitude_longitude`, `datetime`, `hdop`, `satellites`, `altitude`, `height_of_goid`, `speed`, `angle`, `magnetic_declination`) VALUES (";
34
          var query  =  "INSERT INTO `Positions` (`node_id`, `source`, `type`, `latitude_longitude`, `datetime`, `pdop`, `hdop`, `vdop`, `satellites`, `altitude`, `height_of_geoid`, `speed`, `angle`) VALUES (";
33
        query     +=  self.tracked_node_ids_[data.Info.Imei] + ", ";
35
          query     +=  self.tracked_node_ids_[data.Info.Imei] + ", ";
34
        query     +=  "'gps', ";
36
          query     +=  "'gps', ";
-
 
37
          query     +=  "'" + data.Position.Type + "', ";
35
        query     +=  "GeomFromText('POINT(" + data.Position.Latitude + " " + data.Position.Longitude + ")'), ";
38
          query     +=  "GeomFromText('POINT(" + data.Position.Latitude + " " + data.Position.Longitude + ")'), ";
36
        query     +=  "'" + data.Position.Datetime + "', ";
39
          query     +=  "'" + data.Position.Datetime + "', ";
-
 
40
          query     +=  data.Position.Pdop + ", ";
37
        query     +=  data.Position.Hdop + ", ";
41
          query     +=  data.Position.Hdop + ", ";
-
 
42
          query     +=  data.Position.Vdop + ", ";
38
        query     +=  data.Position.Satellites + ", ";
43
          query     +=  data.Position.Satellites + ", ";
39
        query     +=  data.Position.Altitude + ", ";
44
          query     +=  data.Position.Altitude + ", ";
40
        query     +=  data.Position.HeightOfGeoid + ", ";
45
          query     +=  data.Position.HeightOfGeoid + ", ";
41
        query     +=  data.Position.Speed + ", ";
46
          query     +=  data.Position.Speed + ", ";
42
        query     +=  data.Position.Angle + ", ";
47
          query     +=  data.Position.Angle;
43
        query     += (data.Position.MagneticDeclination ? data.Position.MagneticDeclination : "NULL");
-
 
44
        query     +=  ");";
48
          query     +=  ");";
45
       
49
         
46
        MySql_Query(self.db_resource_, query);
50
          MySql_Query(self.db_resource_, query);
-
 
51
         
-
 
52
          /*query = "SELECT `node_id`, `source`, AsText(latitude_longitude), `created`, `datetime`, `hdop`, `satellites`, `altitude`, `height_of_geoid`, `speed`, `angle` FROM `Positions` WHERE `id` = " + MySql_InsertId(self.db_resource_) + " LIMIT 1";
-
 
53
         
-
 
54
          Log("From DB:" + JSON.stringify(MySql_Query(self.db_resource_, query)));*/
-
 
55
        }
47
       
56
       
48
        Log(JSON.stringify(data.Position));
57
        Log(JSON.stringify(data.Position));
49
      }
58
      }
50
    }
59
    }
51
  });
60
  });
Line 61... Line 70...
61
      Log("Unable to find a tracker with IMEI " + data.Info.Imei);
70
      Log("Unable to find a tracker with IMEI " + data.Info.Imei);
62
    }
71
    }
63
    else
72
    else
64
    {
73
    {
65
      var tracker_node_id = result[0]["id"];
74
      var tracker_node_id = result[0]["id"];
-
 
75
      var tracker_node_name = result[0]["name"];
66
     
76
     
67
      Log("Found tracker " + result[0]["name"] + " (NodeId " + result[0]["id"] + ") that corresponds to IMEI " + data.Info.Imei);
77
      Log("Found tracker \"" + tracker_node_name + "\" (NodeId " + tracker_node_id + ") that corresponds to IMEI " + data.Info.Imei);
68
       
78
       
69
      result = MySql_Query(self.db_resource_, "SELECT * FROM `Links` WHERE `node_id_down` = " + tracker_node_id + " AND `Role` = 'tracker'");
79
      result = MySql_Query(self.db_resource_, "SELECT * FROM `Links` WHERE `node_id_down` = " + tracker_node_id + " AND `Role` = 'tracker'");
70
     
80
     
71
      if (result === false || result.length == 0)
81
      if (result === false || result.length == 0)
72
      {
82
      {
Line 82... Line 92...
82
        {
92
        {
83
          Log("Failed to fetch the name of the tracked object (node_id " + result[0]["node_id_up"] + ")!");
93
          Log("Failed to fetch the name of the tracked object (node_id " + result[0]["node_id_up"] + ")!");
84
        }
94
        }
85
        else
95
        else
86
        {
96
        {
87
          Log("Found " + result[0]["name"] + " (node_id " + result[0]["id"] + ") which is being tracked by tracker with IMEI " + data.Info.Imei);
97
          Log("Found \"" + result[0]["name"] + "\" (node_id " + result[0]["id"] + ") which is being tracked by \"" + tracker_node_name + "\".");
88
 
98
 
89
          self.tracked_node_ids_[data.Info.Imei] = result[0]["id"];
99
          self.tracked_node_ids_[data.Info.Imei] = result[0]["id"];
90
        }
100
        }
91
      }
101
      }
92
    }
102
    }