Skip to content

Commit

Permalink
feat: simulate posllh
Browse files Browse the repository at this point in the history
  • Loading branch information
indriApollo committed Dec 30, 2024
1 parent 1e73ade commit 2d1294c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion UbloxSimulator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
var ubx = new UbloxSimulator.UbloxSimulator(portName, 38400);

Console.WriteLine("Running");
await ubx.Run(cts.Token);
ubx.Run(cts.Token);
52 changes: 48 additions & 4 deletions UbloxSimulator/UbloxSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,40 @@ public UbloxSimulator(string portName, int baudRate)
_port.WriteTimeout = 1000;
}

public async Task Run(CancellationToken cancellationToken)
public void Run(CancellationToken cancellationToken)
{
_port.Open();


var configured = false;
while (!cancellationToken.IsCancellationRequested)
{
if (configured)
{
byte[] posllh = [
UbxSyncChar1,
UbxSyncChar2,
(byte)UbxClass.UbxNav,
(byte)UbxId.UbxNavPosllh,
28, 0, // len
0, 0, 0, 0, // iTOW
1, 0, 0, 0, // lon
2, 0, 0, 0, // lat
3, 0, 0, 0, // height
4, 0, 0, 0, //hMSL
5, 0, 0, 0, // hAcc
6, 0, 0, 0, // vAcc
0x34, 0x86 // ck
];
Write(posllh);
}
else
{
var garbage = new byte[128];
Random.Shared.NextBytes(garbage);
Write(garbage);
}


byte[] data;
try
{
Expand All @@ -57,12 +85,28 @@ public async Task Run(CancellationToken cancellationToken)
continue;
}

byte[] valset = [UbxSyncChar1, UbxSyncChar2, (byte)UbxClass.UbxCfg, (byte)UbxId.UbxCfgValset];
byte[] valset = [
UbxSyncChar1,
UbxSyncChar2,
(byte)UbxClass.UbxCfg,
(byte)UbxId.UbxCfgValset
];
if (data[..4].SequenceEqual(valset))
{
Console.WriteLine("got valset");
byte[] ack = [UbxSyncChar1, UbxSyncChar2, (byte)UbxClass.UbxAck, 1, 2, 0, (byte)UbxClass.UbxCfg, (byte)UbxId.UbxCfgValset, 0x98, 0xc1];
byte[] ack = [
UbxSyncChar1,
UbxSyncChar2,
(byte)UbxClass.UbxAck,
1, // ack
2, 0, // len
(byte)UbxClass.UbxCfg,
(byte)UbxId.UbxCfgValset,
0x98, 0xc1
];
Write(ack);

configured = true;
}
}

Expand Down

0 comments on commit 2d1294c

Please sign in to comment.