Skip to content

Commit

Permalink
MAVState: fix paramcache file sync issues
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed Jun 19, 2021
1 parent 031eca3 commit 1b687af
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions ExtLibs/ArduPilot/Mavlink/MAVState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Runtime.Serialization;
using MissionPlanner.ArduPilot.Mavlink;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace MissionPlanner
Expand Down Expand Up @@ -56,22 +57,37 @@ public MAVState(MAVLinkInterface mavLinkInterface, byte sysid, byte compid)
sendlinkid = (byte)(new Random().Next(256));
signing = false;
this.param = new MAVLinkParamList();
bool queuewrite = false;
this.param.PropertyChanged += (s, a) =>
{
Task.Run(() =>
lock (param)
{
if (queuewrite == true)
return;

queuewrite = true;
}

new Timer((o) =>
{
try
{
if (cs.uid2 == null || cs.uid2 == "" || aptype == null || sysid == 0)
return;
Directory.CreateDirectory(Path.GetDirectoryName(ParamCachePath));
File.WriteAllText(ParamCachePath, param.ToJSON());
if (!Directory.Exists(Path.GetDirectoryName(ParamCachePath)))
Directory.CreateDirectory(Path.GetDirectoryName(ParamCachePath));

lock (this.param)
File.WriteAllText(ParamCachePath, param.ToJSON());
}
catch (Exception e)
{
log.Error(e);
}
});

queuewrite = false;

}, null, 2000, -1);
};
this.packets = new Dictionary<uint, Queue<MAVLinkMessage>>(byte.MaxValue);
this.packetsLast = new Dictionary<uint, MAVLinkMessage>(byte.MaxValue);
Expand Down

0 comments on commit 1b687af

Please sign in to comment.