Arduino Ant now works.
This commit is contained in:
parent
d3cb4c1e47
commit
aebe4c0f8e
38
Client.cs
38
Client.cs
@ -10,7 +10,7 @@ namespace Passer.Control {
|
|||||||
public string ipAddress;
|
public string ipAddress;
|
||||||
public int port;
|
public int port;
|
||||||
|
|
||||||
public byte networkId;
|
public byte networkId = 0;
|
||||||
|
|
||||||
public readonly ConcurrentQueue<IMessage> messageQueue = new();
|
public readonly ConcurrentQueue<IMessage> messageQueue = new();
|
||||||
|
|
||||||
@ -23,20 +23,32 @@ namespace Passer.Control {
|
|||||||
}
|
}
|
||||||
static public List<Client> clients = new List<Client>();
|
static public List<Client> clients = new List<Client>();
|
||||||
|
|
||||||
public static Client NewClient() {
|
//// These static functions are deprecated
|
||||||
Client client = new();
|
//public static Client NewClient() {
|
||||||
clients.Add(client);
|
// Client client = new();
|
||||||
client.networkId = 0;
|
// clients.Add(client);
|
||||||
|
// client.networkId = 0;
|
||||||
|
|
||||||
return client;
|
// return client;
|
||||||
}
|
//}
|
||||||
|
|
||||||
public static Client NewUDPClient(UdpClient udpClient, string ipAddress, int port) {
|
//public static Client NewUDPClient(UdpClient udpClient, string ipAddress, int port) {
|
||||||
Client client = NewClient();
|
// Client client = NewClient();
|
||||||
client.ipAddress = null;
|
// client.ipAddress = null;
|
||||||
client.port = port;
|
// client.port = port;
|
||||||
client.udpClient = udpClient;
|
// client.udpClient = udpClient;
|
||||||
return client;
|
// return client;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//public Client() {
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
public Client(UdpClient udpClient, int port) {
|
||||||
|
this.udpClient = udpClient;
|
||||||
|
this.ipAddress = null;
|
||||||
|
this.port = port;
|
||||||
|
clients.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ProcessMessage(IMessage msg) {
|
public void ProcessMessage(IMessage msg) {
|
||||||
|
20
Messages.cs
20
Messages.cs
@ -195,15 +195,13 @@ namespace Passer.Control {
|
|||||||
#region Thing
|
#region Thing
|
||||||
|
|
||||||
public class ThingMsg : IMessage {
|
public class ThingMsg : IMessage {
|
||||||
public const byte length = 5;
|
public const byte length = 4;
|
||||||
public const byte Id = 0x80;
|
public const byte Id = 0x80;
|
||||||
public byte networkId;
|
|
||||||
public byte thingId;
|
public byte thingId;
|
||||||
public byte thingType;
|
public byte thingType;
|
||||||
public byte parentId;
|
public byte parentId;
|
||||||
|
|
||||||
public ThingMsg(byte networkId, byte thingId, byte thingType, byte parentId) {
|
public ThingMsg(byte thingId, byte thingType, byte parentId) {
|
||||||
this.networkId = networkId;
|
|
||||||
this.thingId = thingId;
|
this.thingId = thingId;
|
||||||
this.thingType = thingType;
|
this.thingType = thingType;
|
||||||
this.parentId = parentId;
|
this.parentId = parentId;
|
||||||
@ -212,23 +210,22 @@ namespace Passer.Control {
|
|||||||
|
|
||||||
public override byte[] Serialize() {
|
public override byte[] Serialize() {
|
||||||
byte[] data = new byte[ThingMsg.length];
|
byte[] data = new byte[ThingMsg.length];
|
||||||
data[0] = ThingMsg.Id;
|
byte ix = 0;
|
||||||
data[1] = this.networkId;
|
data[ix++] = ThingMsg.Id;
|
||||||
data[2] = this.thingId;
|
data[ix++] = this.thingId;
|
||||||
data[3] = this.thingType;
|
data[ix++] = this.thingType;
|
||||||
data[4] = this.parentId;
|
data[ix] = this.parentId;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
public override void Deserialize(byte[] data) {
|
public override void Deserialize(byte[] data) {
|
||||||
uint ix = 0;
|
uint ix = 0;
|
||||||
this.networkId = data[ix++];
|
|
||||||
this.thingId = data[ix++];
|
this.thingId = data[ix++];
|
||||||
this.thingType = data[ix++];
|
this.thingType = data[ix++];
|
||||||
this.parentId = data[ix];
|
this.parentId = data[ix];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Send(Client client, byte thingId, byte thingType, byte parentId) {
|
public static bool Send(Client client, byte thingId, byte thingType, byte parentId) {
|
||||||
ThingMsg msg = new(client.networkId, thingId, thingType, parentId);
|
ThingMsg msg = new(thingId, thingType, parentId);
|
||||||
return SendMsg(client, msg);
|
return SendMsg(client, msg);
|
||||||
}
|
}
|
||||||
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
public static async Task<bool> Receive(Stream dataStream, Client client, byte packetSize) {
|
||||||
@ -250,7 +247,6 @@ namespace Passer.Control {
|
|||||||
public class NameMsg : IMessage {
|
public class NameMsg : IMessage {
|
||||||
public const byte Id = 0x91; // 145
|
public const byte Id = 0x91; // 145
|
||||||
public const byte length = 3;
|
public const byte length = 3;
|
||||||
public byte networkId = 0;
|
|
||||||
public byte thingId;
|
public byte thingId;
|
||||||
public byte len;
|
public byte len;
|
||||||
public string name;
|
public string name;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -8,12 +7,9 @@ namespace Passer.Control {
|
|||||||
public static async Task ReceiveData(Stream dataStream, Client client) {
|
public static async Task ReceiveData(Stream dataStream, Client client) {
|
||||||
while (true) {
|
while (true) {
|
||||||
byte packetSize = (byte)dataStream.ReadByte();
|
byte packetSize = (byte)dataStream.ReadByte();
|
||||||
if (packetSize == 0xFF)
|
if (packetSize != 0xFF)
|
||||||
//Debug.Log("Receive timeout");
|
|
||||||
// Timeout
|
|
||||||
;
|
|
||||||
else
|
|
||||||
await ReceiveData(dataStream, client, packetSize);
|
await ReceiveData(dataStream, client, packetSize);
|
||||||
|
// else timeout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,55 +60,5 @@ namespace Passer.Control {
|
|||||||
await ReceiveData(dataStream, client, packetSize);
|
await ReceiveData(dataStream, client, packetSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//public static void ProcessMessage(ISiteServer site, Client client, IMessage msg) {
|
|
||||||
// client.ProcessMessage(site, client, msg);
|
|
||||||
// switch (msg) {
|
|
||||||
// case ClientMsg clientMsg:
|
|
||||||
// site.ProcessClient(client, clientMsg);
|
|
||||||
// break;
|
|
||||||
// case NetworkIdMsg networkId:
|
|
||||||
// site.ProcessNetworkId(client, networkId);
|
|
||||||
// break;
|
|
||||||
// case InvestigateMsg investigate:
|
|
||||||
// site.ProcessInvestigate(client, investigate);
|
|
||||||
// break;
|
|
||||||
// case ThingMsg thing:
|
|
||||||
// site.ProcessThing(client, thing);
|
|
||||||
// break;
|
|
||||||
// case NameMsg name:
|
|
||||||
// site.ProcessName(client, name);
|
|
||||||
// break;
|
|
||||||
// case ModelUrlMsg modelUrl:
|
|
||||||
// site.ProcessModelUrl(client, modelUrl);
|
|
||||||
// break;
|
|
||||||
// case PoseMsg pose:
|
|
||||||
// site.ProcessPose(client, pose);
|
|
||||||
// break;
|
|
||||||
// case CustomMsg custom:
|
|
||||||
// site.ProcessCustom(client, custom);
|
|
||||||
// break;
|
|
||||||
// case TextMsg text:
|
|
||||||
// site.ProcessText(client, text);
|
|
||||||
// break;
|
|
||||||
// case DestroyMsg destroy:
|
|
||||||
// site.ProcessDestroy(client, destroy);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//public interface ISiteServer {
|
|
||||||
|
|
||||||
// public void ProcessClient(Client client, ClientMsg clientMsg);
|
|
||||||
// public void ProcessNetworkId(Client client, NetworkIdMsg networkId);
|
|
||||||
// public void ProcessInvestigate(Client client, InvestigateMsg investigate);
|
|
||||||
// public void ProcessThing(Client client, ThingMsg thing);
|
|
||||||
// public void ProcessName(Client client, NameMsg name);
|
|
||||||
// public void ProcessModelUrl(Client client, ModelUrlMsg modelUrl);
|
|
||||||
// public void ProcessPose(Client client, PoseMsg pose);
|
|
||||||
// public void ProcessCustom(Client client, CustomMsg custom);
|
|
||||||
// public void ProcessText(Client client, TextMsg text);
|
|
||||||
// public void ProcessDestroy(Client client, DestroyMsg destroy);
|
|
||||||
//}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user