Skip to content

Commit

Permalink
V1.58.5
Browse files Browse the repository at this point in the history
  • Loading branch information
bassmaster187 committed Jun 27, 2024
1 parent 33682c0 commit d958f1a
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 7 deletions.
8 changes: 8 additions & 0 deletions TeslaLogger/Car.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
Expand Down Expand Up @@ -397,6 +398,8 @@ private void Loop()
}
catch (Exception ex)
{
Log("LOOP: " + ex.ToString()); // xxx

SendException2Exceptionless(ex);

Logfile.ExceptionWriter(ex, "#" + CarInDB + ": main loop");
Expand Down Expand Up @@ -1100,6 +1103,11 @@ private void HandleState_Online()
Log("Stop sleep by DrivingOrChargingByStream");
break;
}
if (FleetAPI && (telemetry?.Driving == true || telemetry?.Charging == true))
{
Log("Stop sleep by telemetry");
break;
}
}
}
else
Expand Down
58 changes: 56 additions & 2 deletions TeslaLogger/DBHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using Newtonsoft.Json;
using System.Diagnostics;
using System.Data.Common;
using System.Runtime.InteropServices.ComTypes;
using Microsoft.VisualBasic.Logging;

namespace TeslaLogger
{
Expand Down Expand Up @@ -4442,7 +4444,21 @@ public void StartDriveState(DateTime now)
{
// driving means that charging must be over
UpdateUnplugDate();
int posID = GetMaxPosid();
int posID = 0;

if (car.FleetAPI) // maxpos in Fleetapi is useless because lat & lng = 0
{
posID = car.telemetry.lastposid;
if (posID > 0)
{
DBHelper.UpdateAddress(car, posID);
UpdatePosFromCurrentJSON(posID);
}
}

if (posID == 0)
posID = GetMaxPosid();

using (MySqlConnection con = new MySqlConnection(DBConnectionstring))
{
con.Open();
Expand Down Expand Up @@ -4472,10 +4488,41 @@ public void StartDriveState(DateTime now)
car.CurrentJSON.CreateCurrentJSON();
}

private void UpdatePosFromCurrentJSON(int posID)
{
car.Log("UpdatePosFromCurrentJSON " + posID);
using (MySqlConnection con = new MySqlConnection(DBConnectionstring))
{
con.Open();
using (MySqlCommand cmd = new MySqlCommand(@"
UPDATE
pos
SET
power = 1,
odometer = @odometer,
ideal_battery_range_km = @ideal_battery_range_km,
outside_temp = @outside_temp,
battery_level = @battery_level,
battery_range_km = @battery_range_km
WHERE
id = @id", con))
{
cmd.Parameters.AddWithValue("@id", posID);
cmd.Parameters.AddWithValue("@odometer", car.CurrentJSON.current_odometer);
cmd.Parameters.AddWithValue("@ideal_battery_range_km", car.CurrentJSON.current_ideal_battery_range_km);
cmd.Parameters.AddWithValue("@outside_temp", car.CurrentJSON.current_outside_temperature);
cmd.Parameters.AddWithValue("@battery_level", car.CurrentJSON.current_battery_level);
cmd.Parameters.AddWithValue("@battery_range_km", car.CurrentJSON.current_battery_range_km);
_ = SQLTracer.TraceNQ(cmd, out _);
}
}
}

int last_active_route_energy_at_arrival = int.MinValue;

public void InsertPos(string timestamp, double latitude, double longitude, int speed, decimal? power, double? odometer, double idealBatteryRangeKm, double batteryRangeKm, int batteryLevel, double? outsideTemp, string altitude)
public int InsertPos(string timestamp, double latitude, double longitude, int speed, decimal? power, double? odometer, double idealBatteryRangeKm, double batteryRangeKm, int batteryLevel, double? outsideTemp, string altitude)
{
int posid = 0;
double? inside_temp = car.CurrentJSON.current_inside_temperature;
using (MySqlConnection con = new MySqlConnection(DBConnectionstring))
{
Expand Down Expand Up @@ -4595,6 +4642,11 @@ public void InsertPos(string timestamp, double latitude, double longitude, int s

Insert_active_route_energy_at_arrival(posID);

using (MySqlCommand cmdid = new MySqlCommand("SELECT LAST_INSERT_ID()", con))
{
posid = Convert.ToInt32(cmdid.ExecuteScalar());
}

try
{
car.CurrentJSON.current_speed = (int)(speed * 1.609344M);
Expand Down Expand Up @@ -4642,6 +4694,8 @@ public void InsertPos(string timestamp, double latitude, double longitude, int s
}

car.CurrentJSON.CreateCurrentJSON();

return posid;
}

private void Insert_active_route_energy_at_arrival(long posID, bool force = false)
Expand Down
4 changes: 2 additions & 2 deletions TeslaLogger/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.58.4.0")]
[assembly: AssemblyFileVersion("1.58.4.0")]
[assembly: AssemblyVersion("1.58.5.0")]
[assembly: AssemblyFileVersion("1.58.5.0")]

[assembly: InternalsVisibleTo("UnitTestsTeslalogger")]
4 changes: 3 additions & 1 deletion TeslaLogger/TelemetryConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ internal class TelemetryConnection
public DateTime lastDriving = DateTime.MinValue;
public DateTime lastMessageReceived = DateTime.MinValue;

public int lastposid = 0;

void Log(string message)
{
car.Log("*** FT: " + message);
Expand Down Expand Up @@ -270,7 +272,7 @@ public void InsertLocation(dynamic j, DateTime d, string resultContent)
{
long ts= (long)(d.ToUniversalTime().Subtract(new DateTime(1970, 1, 1))).TotalSeconds*1000;
Log("Insert Location");
car.DbHelper.InsertPos(ts.ToString(), latitude.Value, longitude.Value, (int)speed.Value, null, null, -1, -1, -1, null, "");
lastposid = car.DbHelper.InsertPos(ts.ToString(), latitude.Value, longitude.Value, (int)speed.Value, null, null, -1, -1, -1, null, "");
}
}
catch (Exception ex)
Expand Down
Binary file modified TeslaLogger/bin/TeslaLogger.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions TeslaLogger/bin/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Version 1.58.4
- More logging
# Version 1.58.5
- Bugfixes

# Version 1.58.2
- Many improvements for Fleet API
Expand Down

0 comments on commit d958f1a

Please sign in to comment.