Merge commit '61740913fec4289924f5c485556b8af17bc44e1b'
This commit is contained in:
commit
779319c523
@ -2,6 +2,7 @@
|
|||||||
#if defined(ARDUINO)
|
#if defined(ARDUINO)
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <ESP8266httpUpdate.h>
|
||||||
|
|
||||||
bool StartWifi(const char *wifiSsid, const char *wifiPassword,
|
bool StartWifi(const char *wifiSsid, const char *wifiPassword,
|
||||||
bool hotspotFallback) {
|
bool hotspotFallback) {
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#if defined(ARDUINO)
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
bool StartWifi(const char *wifiSsid, const char *wifiPassword,
|
bool StartWifi(const char *wifiSsid, const char *wifiPassword,
|
||||||
bool hotspotFallback);
|
bool hotspotFallback);
|
||||||
|
|
||||||
|
void CheckFirmware(String url, String FIRMWARE_NAME, int FIRMWARE_VERSION);
|
||||||
|
|
||||||
|
#endif
|
91
Messages.cpp
91
Messages.cpp
@ -33,94 +33,3 @@ unsigned char *IMessage::ReceiveMsg(unsigned char packetSize) {
|
|||||||
|
|
||||||
// IMessage
|
// IMessage
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
#pragma region Investigate
|
|
||||||
|
|
||||||
InvestigateMsg::InvestigateMsg(char *buffer) {
|
|
||||||
unsigned ix = 1; // first byte is msgId
|
|
||||||
this->networkId = buffer[ix++];
|
|
||||||
this->thingId = buffer[ix++];
|
|
||||||
}
|
|
||||||
InvestigateMsg::InvestigateMsg(unsigned char networkId, unsigned char thingId) {
|
|
||||||
this->networkId = networkId;
|
|
||||||
this->thingId = thingId;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char InvestigateMsg::Serialize(char *buffer) {
|
|
||||||
unsigned char ix = 0;
|
|
||||||
buffer[ix++] = this->id;
|
|
||||||
buffer[ix++] = this->networkId;
|
|
||||||
buffer[ix++] = this->thingId;
|
|
||||||
return ix;
|
|
||||||
}
|
|
||||||
|
|
||||||
// bool InvestigateMsg::Send(Participant *participant, unsigned char networkId,
|
|
||||||
// unsigned char thingId) {
|
|
||||||
// InvestigateMsg msg = InvestigateMsg(networkId, thingId);
|
|
||||||
// return msg.Send(participant);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Investigate
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
#pragma region PoseMsg
|
|
||||||
|
|
||||||
PoseMsg::PoseMsg(unsigned char networkId, unsigned char thingId,
|
|
||||||
unsigned char poseType, Spherical16 position,
|
|
||||||
SwingTwist16 orientation, Spherical16 linearVelocity,
|
|
||||||
Spherical16 angularVelocity) {
|
|
||||||
this->networkId = networkId;
|
|
||||||
this->thingId = thingId;
|
|
||||||
|
|
||||||
this->poseType = poseType;
|
|
||||||
this->position = position;
|
|
||||||
this->orientation = orientation;
|
|
||||||
this->linearVelocity = linearVelocity;
|
|
||||||
this->angularVelocity = angularVelocity;
|
|
||||||
}
|
|
||||||
PoseMsg::PoseMsg(const char *buffer) {
|
|
||||||
unsigned char ix = 1; // First byte is msg id
|
|
||||||
this->networkId = buffer[ix++];
|
|
||||||
this->thingId = buffer[ix++];
|
|
||||||
this->poseType = buffer[ix++];
|
|
||||||
this->position = LowLevelMessages::ReceiveSpherical16(buffer, &ix);
|
|
||||||
this->orientation = LowLevelMessages::ReceiveQuat32(buffer, &ix);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char PoseMsg::Serialize(char *buffer) {
|
|
||||||
unsigned char ix = 0;
|
|
||||||
buffer[ix++] = PoseMsg::id;
|
|
||||||
buffer[ix++] = this->networkId;
|
|
||||||
buffer[ix++] = this->thingId;
|
|
||||||
buffer[ix++] = this->poseType;
|
|
||||||
if ((this->poseType & Pose_Position) != 0)
|
|
||||||
LowLevelMessages::SendSpherical16(buffer, &ix, this->position);
|
|
||||||
if ((this->poseType & Pose_Orientation) != 0)
|
|
||||||
LowLevelMessages::SendQuat32(buffer, &ix, this->orientation);
|
|
||||||
if ((this->poseType & Pose_LinearVelocity) != 0)
|
|
||||||
LowLevelMessages::SendSpherical16(buffer, &ix, this->linearVelocity);
|
|
||||||
if ((this->poseType & Pose_AngularVelocity) != 0)
|
|
||||||
LowLevelMessages::SendSpherical16(buffer, &ix, this->angularVelocity);
|
|
||||||
return ix;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pose
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
#pragma region DestroyMsg
|
|
||||||
|
|
||||||
DestroyMsg::DestroyMsg(unsigned char networkId, Thing *thing) {
|
|
||||||
this->networkId = networkId;
|
|
||||||
this->thingId = thing->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char DestroyMsg::Serialize(char *buffer) {
|
|
||||||
unsigned char ix = 0;
|
|
||||||
buffer[ix++] = this->id;
|
|
||||||
buffer[ix++] = this->networkId;
|
|
||||||
buffer[ix++] = this->thingId;
|
|
||||||
return ix;
|
|
||||||
}
|
|
||||||
|
|
||||||
// DestroyMsg
|
|
||||||
#pragma endregion
|
|
||||||
|
53
Messages.h
53
Messages.h
@ -21,59 +21,6 @@ public:
|
|||||||
// bool SendTo(Participant *participant);
|
// bool SendTo(Participant *participant);
|
||||||
};
|
};
|
||||||
|
|
||||||
class InvestigateMsg : public IMessage {
|
|
||||||
public:
|
|
||||||
static const unsigned char id = 0x81;
|
|
||||||
static const unsigned char length = 3;
|
|
||||||
unsigned char networkId;
|
|
||||||
unsigned char thingId;
|
|
||||||
|
|
||||||
InvestigateMsg(char *buffer);
|
|
||||||
InvestigateMsg(unsigned char networkId, unsigned char thingId);
|
|
||||||
|
|
||||||
virtual unsigned char Serialize(char *buffer) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class PoseMsg : public IMessage {
|
|
||||||
public:
|
|
||||||
static const unsigned char id = 0x10;
|
|
||||||
unsigned char length = 4 + 4 + 4;
|
|
||||||
|
|
||||||
unsigned char networkId;
|
|
||||||
unsigned char thingId;
|
|
||||||
|
|
||||||
unsigned char poseType;
|
|
||||||
static const unsigned char Pose_Position = 0x01;
|
|
||||||
static const unsigned char Pose_Orientation = 0x02;
|
|
||||||
static const unsigned char Pose_LinearVelocity = 0x04; // For future use
|
|
||||||
static const unsigned char Pose_AngularVelocity = 0x08; // For future use
|
|
||||||
|
|
||||||
Spherical16 position;
|
|
||||||
SwingTwist16 orientation;
|
|
||||||
Spherical16 linearVelocity;
|
|
||||||
Spherical16 angularVelocity;
|
|
||||||
|
|
||||||
PoseMsg(unsigned char networkId, unsigned char thingId,
|
|
||||||
unsigned char poseType, Spherical16 position,
|
|
||||||
SwingTwist16 orientation, Spherical16 linearVelocity = Spherical16(),
|
|
||||||
Spherical16 angularVelocity = Spherical16());
|
|
||||||
PoseMsg(const char *buffer);
|
|
||||||
|
|
||||||
virtual unsigned char Serialize(char *buffer) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class DestroyMsg : public IMessage {
|
|
||||||
public:
|
|
||||||
static const unsigned char id = 0x20;
|
|
||||||
static const unsigned length = 3;
|
|
||||||
unsigned char networkId;
|
|
||||||
unsigned char thingId;
|
|
||||||
|
|
||||||
DestroyMsg(unsigned char networkId, Thing *thing);
|
|
||||||
|
|
||||||
virtual unsigned char Serialize(char *buffer) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Control
|
} // namespace Control
|
||||||
} // namespace Passer
|
} // namespace Passer
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ ClientMsg::ClientMsg(char networkId) { this->networkId = networkId; }
|
|||||||
|
|
||||||
ClientMsg::ClientMsg(const char *buffer) { this->networkId = buffer[1]; }
|
ClientMsg::ClientMsg(const char *buffer) { this->networkId = buffer[1]; }
|
||||||
|
|
||||||
|
ClientMsg::~ClientMsg() {}
|
||||||
|
|
||||||
unsigned char ClientMsg::Serialize(char *buffer) {
|
unsigned char ClientMsg::Serialize(char *buffer) {
|
||||||
unsigned char ix = 0;
|
unsigned char ix = 0;
|
||||||
buffer[ix++] = this->id;
|
buffer[ix++] = this->id;
|
@ -16,6 +16,7 @@ public:
|
|||||||
|
|
||||||
ClientMsg(char networkId);
|
ClientMsg(char networkId);
|
||||||
ClientMsg(const char *buffer);
|
ClientMsg(const char *buffer);
|
||||||
|
virtual ~ClientMsg();
|
||||||
|
|
||||||
virtual unsigned char Serialize(char *buffer) override;
|
virtual unsigned char Serialize(char *buffer) override;
|
||||||
};
|
};
|
@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
CustomMsg(char *buffer);
|
CustomMsg(char *buffer);
|
||||||
CustomMsg(unsigned char networkId, Thing *thing);
|
CustomMsg(unsigned char networkId, Thing *thing);
|
||||||
~CustomMsg();
|
virtual ~CustomMsg();
|
||||||
|
|
||||||
virtual unsigned char Serialize(char *buffer) override;
|
virtual unsigned char Serialize(char *buffer) override;
|
||||||
|
|
||||||
|
22
Messages/DestroyMsg.cpp
Normal file
22
Messages/DestroyMsg.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include "DestroyMsg.h"
|
||||||
|
|
||||||
|
namespace Passer {
|
||||||
|
namespace Control {
|
||||||
|
|
||||||
|
DestroyMsg::DestroyMsg(unsigned char networkId, Thing *thing) {
|
||||||
|
this->networkId = networkId;
|
||||||
|
this->thingId = thing->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
DestroyMsg::~DestroyMsg() {}
|
||||||
|
|
||||||
|
unsigned char DestroyMsg::Serialize(char *buffer) {
|
||||||
|
unsigned char ix = 0;
|
||||||
|
buffer[ix++] = this->id;
|
||||||
|
buffer[ix++] = this->networkId;
|
||||||
|
buffer[ix++] = this->thingId;
|
||||||
|
return ix;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Control
|
||||||
|
} // namespace Passer
|
19
Messages/DestroyMsg.h
Normal file
19
Messages/DestroyMsg.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "Messages.h"
|
||||||
|
namespace Passer {
|
||||||
|
namespace Control {
|
||||||
|
|
||||||
|
class DestroyMsg : public IMessage {
|
||||||
|
public:
|
||||||
|
static const unsigned char id = 0x20;
|
||||||
|
static const unsigned length = 3;
|
||||||
|
unsigned char networkId;
|
||||||
|
unsigned char thingId;
|
||||||
|
|
||||||
|
DestroyMsg(unsigned char networkId, Thing *thing);
|
||||||
|
virtual ~DestroyMsg();
|
||||||
|
|
||||||
|
virtual unsigned char Serialize(char *buffer) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Control
|
||||||
|
} // namespace Passer
|
30
Messages/InvestigateMsg.cpp
Normal file
30
Messages/InvestigateMsg.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include "InvestigateMsg.h"
|
||||||
|
#pragma region Investigate
|
||||||
|
|
||||||
|
InvestigateMsg::InvestigateMsg(char *buffer) {
|
||||||
|
unsigned ix = 1; // first byte is msgId
|
||||||
|
this->networkId = buffer[ix++];
|
||||||
|
this->thingId = buffer[ix++];
|
||||||
|
}
|
||||||
|
InvestigateMsg::InvestigateMsg(unsigned char networkId, unsigned char thingId) {
|
||||||
|
this->networkId = networkId;
|
||||||
|
this->thingId = thingId;
|
||||||
|
}
|
||||||
|
|
||||||
|
InvestigateMsg::~InvestigateMsg() {}
|
||||||
|
unsigned char InvestigateMsg::Serialize(char *buffer) {
|
||||||
|
unsigned char ix = 0;
|
||||||
|
buffer[ix++] = this->id;
|
||||||
|
buffer[ix++] = this->networkId;
|
||||||
|
buffer[ix++] = this->thingId;
|
||||||
|
return ix;
|
||||||
|
}
|
||||||
|
|
||||||
|
// bool InvestigateMsg::Send(Participant *participant, unsigned char networkId,
|
||||||
|
// unsigned char thingId) {
|
||||||
|
// InvestigateMsg msg = InvestigateMsg(networkId, thingId);
|
||||||
|
// return msg.Send(participant);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Investigate
|
||||||
|
#pragma endregion
|
15
Messages/InvestigateMsg.h
Normal file
15
Messages/InvestigateMsg.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "Messages.h"
|
||||||
|
|
||||||
|
class InvestigateMsg : public IMessage {
|
||||||
|
public:
|
||||||
|
static const unsigned char id = 0x81;
|
||||||
|
static const unsigned char length = 3;
|
||||||
|
unsigned char networkId;
|
||||||
|
unsigned char thingId;
|
||||||
|
|
||||||
|
InvestigateMsg(char *buffer);
|
||||||
|
InvestigateMsg(unsigned char networkId, unsigned char thingId);
|
||||||
|
virtual ~InvestigateMsg();
|
||||||
|
|
||||||
|
virtual unsigned char Serialize(char *buffer) override;
|
||||||
|
};
|
@ -35,6 +35,8 @@ ModelUrlMsg::ModelUrlMsg(unsigned char networkId, Thing *thing) {
|
|||||||
this->url = thing->modelUrl; // dangerous!
|
this->url = thing->modelUrl; // dangerous!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ModelUrlMsg::~ModelUrlMsg() {}
|
||||||
|
|
||||||
unsigned char ModelUrlMsg::Serialize(char *buffer) {
|
unsigned char ModelUrlMsg::Serialize(char *buffer) {
|
||||||
if (this->urlLength == 0 || this->url == nullptr)
|
if (this->urlLength == 0 || this->url == nullptr)
|
||||||
return 0;
|
return 0;
|
@ -18,6 +18,7 @@ public:
|
|||||||
ModelUrlMsg(unsigned char networkId, Thing *thing);
|
ModelUrlMsg(unsigned char networkId, Thing *thing);
|
||||||
// ModelUrlMsg(unsigned char networkId, unsigned char thingId,
|
// ModelUrlMsg(unsigned char networkId, unsigned char thingId,
|
||||||
// unsigned char urlLegth, const char *url, float scale = 1);
|
// unsigned char urlLegth, const char *url, float scale = 1);
|
||||||
|
virtual ~ModelUrlMsg();
|
||||||
|
|
||||||
virtual unsigned char Serialize(char *buffer) override;
|
virtual unsigned char Serialize(char *buffer) override;
|
||||||
};
|
};
|
@ -32,6 +32,8 @@ NameMsg::NameMsg(unsigned char networkId, Thing *thing) {
|
|||||||
// this->nameLength = nameLength;
|
// this->nameLength = nameLength;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
NameMsg::~NameMsg() {}
|
||||||
|
|
||||||
unsigned char NameMsg::Serialize(char *buffer) {
|
unsigned char NameMsg::Serialize(char *buffer) {
|
||||||
if (this->nameLength == 0 || this->name == nullptr)
|
if (this->nameLength == 0 || this->name == nullptr)
|
||||||
return 0;
|
return 0;
|
@ -16,6 +16,7 @@ public:
|
|||||||
NameMsg(unsigned char networkId, Thing *thing);
|
NameMsg(unsigned char networkId, Thing *thing);
|
||||||
// NameMsg(unsigned char networkId, unsigned char thingId, const char *name,
|
// NameMsg(unsigned char networkId, unsigned char thingId, const char *name,
|
||||||
// unsigned char nameLength);
|
// unsigned char nameLength);
|
||||||
|
virtual ~NameMsg();
|
||||||
|
|
||||||
virtual unsigned char Serialize(char *buffer) override;
|
virtual unsigned char Serialize(char *buffer) override;
|
||||||
};
|
};
|
@ -9,6 +9,8 @@ NetworkIdMsg::NetworkIdMsg(unsigned char networkId) {
|
|||||||
this->networkId = networkId;
|
this->networkId = networkId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NetworkIdMsg::~NetworkIdMsg() {}
|
||||||
|
|
||||||
unsigned char NetworkIdMsg::Serialize(char *buffer) {
|
unsigned char NetworkIdMsg::Serialize(char *buffer) {
|
||||||
unsigned char ix = 0;
|
unsigned char ix = 0;
|
||||||
buffer[ix++] = this->id;
|
buffer[ix++] = this->id;
|
@ -11,6 +11,7 @@ public:
|
|||||||
|
|
||||||
NetworkIdMsg(const char *buffer);
|
NetworkIdMsg(const char *buffer);
|
||||||
NetworkIdMsg(unsigned char networkId);
|
NetworkIdMsg(unsigned char networkId);
|
||||||
|
virtual ~NetworkIdMsg();
|
||||||
|
|
||||||
virtual unsigned char Serialize(char *buffer) override;
|
virtual unsigned char Serialize(char *buffer) override;
|
||||||
// static NetworkIdMsg Receive(char *buffer, unsigned char bufferSize);
|
// static NetworkIdMsg Receive(char *buffer, unsigned char bufferSize);
|
43
Messages/PoseMsg.cpp
Normal file
43
Messages/PoseMsg.cpp
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#include "PoseMsg.h"
|
||||||
|
#include "LowLevelMessages.h"
|
||||||
|
|
||||||
|
PoseMsg::PoseMsg(unsigned char networkId, unsigned char thingId,
|
||||||
|
unsigned char poseType, Spherical16 position,
|
||||||
|
SwingTwist16 orientation, Spherical16 linearVelocity,
|
||||||
|
Spherical16 angularVelocity) {
|
||||||
|
this->networkId = networkId;
|
||||||
|
this->thingId = thingId;
|
||||||
|
|
||||||
|
this->poseType = poseType;
|
||||||
|
this->position = position;
|
||||||
|
this->orientation = orientation;
|
||||||
|
this->linearVelocity = linearVelocity;
|
||||||
|
this->angularVelocity = angularVelocity;
|
||||||
|
}
|
||||||
|
PoseMsg::PoseMsg(const char *buffer) {
|
||||||
|
unsigned char ix = 1; // First byte is msg id
|
||||||
|
this->networkId = buffer[ix++];
|
||||||
|
this->thingId = buffer[ix++];
|
||||||
|
this->poseType = buffer[ix++];
|
||||||
|
this->position = LowLevelMessages::ReceiveSpherical16(buffer, &ix);
|
||||||
|
this->orientation = LowLevelMessages::ReceiveQuat32(buffer, &ix);
|
||||||
|
}
|
||||||
|
|
||||||
|
PoseMsg::~PoseMsg() {}
|
||||||
|
|
||||||
|
unsigned char PoseMsg::Serialize(char *buffer) {
|
||||||
|
unsigned char ix = 0;
|
||||||
|
buffer[ix++] = PoseMsg::id;
|
||||||
|
buffer[ix++] = this->networkId;
|
||||||
|
buffer[ix++] = this->thingId;
|
||||||
|
buffer[ix++] = this->poseType;
|
||||||
|
if ((this->poseType & Pose_Position) != 0)
|
||||||
|
LowLevelMessages::SendSpherical16(buffer, &ix, this->position);
|
||||||
|
if ((this->poseType & Pose_Orientation) != 0)
|
||||||
|
LowLevelMessages::SendQuat32(buffer, &ix, this->orientation);
|
||||||
|
if ((this->poseType & Pose_LinearVelocity) != 0)
|
||||||
|
LowLevelMessages::SendSpherical16(buffer, &ix, this->linearVelocity);
|
||||||
|
if ((this->poseType & Pose_AngularVelocity) != 0)
|
||||||
|
LowLevelMessages::SendSpherical16(buffer, &ix, this->angularVelocity);
|
||||||
|
return ix;
|
||||||
|
}
|
30
Messages/PoseMsg.h
Normal file
30
Messages/PoseMsg.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include "Messages.h"
|
||||||
|
|
||||||
|
class PoseMsg : public IMessage {
|
||||||
|
public:
|
||||||
|
static const unsigned char id = 0x10;
|
||||||
|
unsigned char length = 4 + 4 + 4;
|
||||||
|
|
||||||
|
unsigned char networkId;
|
||||||
|
unsigned char thingId;
|
||||||
|
|
||||||
|
unsigned char poseType;
|
||||||
|
static const unsigned char Pose_Position = 0x01;
|
||||||
|
static const unsigned char Pose_Orientation = 0x02;
|
||||||
|
static const unsigned char Pose_LinearVelocity = 0x04; // For future use
|
||||||
|
static const unsigned char Pose_AngularVelocity = 0x08; // For future use
|
||||||
|
|
||||||
|
Spherical16 position;
|
||||||
|
SwingTwist16 orientation;
|
||||||
|
Spherical16 linearVelocity;
|
||||||
|
Spherical16 angularVelocity;
|
||||||
|
|
||||||
|
PoseMsg(unsigned char networkId, unsigned char thingId,
|
||||||
|
unsigned char poseType, Spherical16 position,
|
||||||
|
SwingTwist16 orientation, Spherical16 linearVelocity = Spherical16(),
|
||||||
|
Spherical16 angularVelocity = Spherical16());
|
||||||
|
PoseMsg(const char *buffer);
|
||||||
|
virtual ~PoseMsg();
|
||||||
|
|
||||||
|
virtual unsigned char Serialize(char *buffer) override;
|
||||||
|
};
|
@ -30,6 +30,8 @@ ThingMsg::ThingMsg(unsigned char networkId, Thing *thing) {
|
|||||||
// this->parentId = parentId;
|
// this->parentId = parentId;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
ThingMsg::~ThingMsg() {}
|
||||||
|
|
||||||
unsigned char ThingMsg::Serialize(char *buffer) {
|
unsigned char ThingMsg::Serialize(char *buffer) {
|
||||||
unsigned char ix = 0;
|
unsigned char ix = 0;
|
||||||
buffer[ix++] = this->id;
|
buffer[ix++] = this->id;
|
@ -16,6 +16,7 @@ public:
|
|||||||
ThingMsg(unsigned char networkId, Thing *thing);
|
ThingMsg(unsigned char networkId, Thing *thing);
|
||||||
// ThingMsg(unsigned char networkId, unsigned char thingId,
|
// ThingMsg(unsigned char networkId, unsigned char thingId,
|
||||||
// unsigned char thingType, unsigned char parentId);
|
// unsigned char thingType, unsigned char parentId);
|
||||||
|
virtual ~ThingMsg();
|
||||||
|
|
||||||
virtual unsigned char Serialize(char *buffer) override;
|
virtual unsigned char Serialize(char *buffer) override;
|
||||||
};
|
};
|
@ -31,7 +31,8 @@ Participant::Participant(int port) {
|
|||||||
this->participants.push_back(this);
|
this->participants.push_back(this);
|
||||||
|
|
||||||
int randomPort = (rand() % (65535 - 49152 + 1)) + 49152;
|
int randomPort = (rand() % (65535 - 49152 + 1)) + 49152;
|
||||||
SetupUDP(randomPort, ipAddress, port);
|
this->localPort = randomPort;
|
||||||
|
// SetupUDP(randomPort, ipAddress, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
Participant::Participant(const char *ipAddress, int port) {
|
Participant::Participant(const char *ipAddress, int port) {
|
||||||
@ -41,11 +42,15 @@ Participant::Participant(const char *ipAddress, int port) {
|
|||||||
this->participants.push_back(this);
|
this->participants.push_back(this);
|
||||||
|
|
||||||
int randomPort = (rand() % (65535 - 49152 + 1)) + 49152;
|
int randomPort = (rand() % (65535 - 49152 + 1)) + 49152;
|
||||||
SetupUDP(randomPort, ipAddress, port);
|
this->localPort = randomPort;
|
||||||
|
// SetupUDP(randomPort, ipAddress, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Passer::Control::Participant::SetupUDP(int localPort,
|
void Participant::begin() {
|
||||||
const char *remoteIpAddress,
|
SetupUDP(this->localPort, this->ipAddress, this->port);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Participant::SetupUDP(int localPort, const char *remoteIpAddress,
|
||||||
int remotePort) {
|
int remotePort) {
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
UdpWindows *thisWindows = static_cast<UdpWindows *>(this);
|
UdpWindows *thisWindows = static_cast<UdpWindows *>(this);
|
||||||
@ -57,6 +62,7 @@ void Passer::Control::Participant::SetupUDP(int localPort,
|
|||||||
UdpArduino *thisArduino = static_cast<UdpArduino *>(this);
|
UdpArduino *thisArduino = static_cast<UdpArduino *>(this);
|
||||||
thisArduino->Setup(localPort, remoteIpAddress, remotePort);
|
thisArduino->Setup(localPort, remoteIpAddress, remotePort);
|
||||||
#endif
|
#endif
|
||||||
|
this->connected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Participant::Update(unsigned long currentTimeMs) {
|
void Participant::Update(unsigned long currentTimeMs) {
|
||||||
@ -71,6 +77,9 @@ void Participant::Update(unsigned long currentTimeMs) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this->connected == false)
|
||||||
|
begin();
|
||||||
|
|
||||||
if (this->publishInterval > 0 && currentTimeMs > this->nextPublishMe) {
|
if (this->publishInterval > 0 && currentTimeMs > this->nextPublishMe) {
|
||||||
ClientMsg *msg = new ClientMsg(this->networkId);
|
ClientMsg *msg = new ClientMsg(this->networkId);
|
||||||
this->Publish(msg);
|
this->Publish(msg);
|
||||||
@ -115,15 +124,15 @@ Participant *Participant::AddParticipant(const char *ipAddress, int port) {
|
|||||||
|
|
||||||
void Participant::SendThingInfo(Thing *thing) {
|
void Participant::SendThingInfo(Thing *thing) {
|
||||||
std::cout << "Send thing info\n";
|
std::cout << "Send thing info\n";
|
||||||
IMessage *msg = new ThingMsg(this->networkId, thing);
|
ThingMsg *thingMsg = new ThingMsg(this->networkId, thing);
|
||||||
this->Send(msg);
|
this->Send(thingMsg);
|
||||||
delete msg;
|
delete thingMsg;
|
||||||
msg = new NameMsg(this->networkId, thing);
|
NameMsg *nameMsg = new NameMsg(this->networkId, thing);
|
||||||
this->Send(msg);
|
this->Send(nameMsg);
|
||||||
delete msg;
|
delete nameMsg;
|
||||||
msg = new ModelUrlMsg(this->networkId, thing);
|
ModelUrlMsg *modelMsg = new ModelUrlMsg(this->networkId, thing);
|
||||||
this->Send(msg);
|
this->Send(modelMsg);
|
||||||
delete msg;
|
delete modelMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Passer::Control::Participant::PublishThingInfo(Thing *thing) {
|
void Passer::Control::Participant::PublishThingInfo(Thing *thing) {
|
||||||
@ -245,8 +254,9 @@ void Participant::Process(ThingMsg *msg) {}
|
|||||||
void Participant::Process(NameMsg *msg) {
|
void Participant::Process(NameMsg *msg) {
|
||||||
Thing *thing = Thing::Get(msg->networkId, msg->thingId);
|
Thing *thing = Thing::Get(msg->networkId, msg->thingId);
|
||||||
if (thing != nullptr) {
|
if (thing != nullptr) {
|
||||||
thing->name = new char[strlen(msg->name)];
|
char *thingName = new char[strlen(msg->name)];
|
||||||
strcpy(thing->name, msg->name);
|
strcpy(thingName, msg->name);
|
||||||
|
thing->name = thingName;
|
||||||
std::cout << "thing name = " << thing->name << "\n";
|
std::cout << "thing name = " << thing->name << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ClientMsg.h"
|
|
||||||
#include "Messages.h"
|
#include "Messages.h"
|
||||||
|
#include "Messages/ClientMsg.h"
|
||||||
#include "Messages/CustomMsg.h"
|
#include "Messages/CustomMsg.h"
|
||||||
#include "ModelUrlMsg.h"
|
#include "Messages/InvestigateMsg.h"
|
||||||
#include "NameMsg.h"
|
#include "Messages/ModelUrlMsg.h"
|
||||||
#include "NetworkIdMsg.h"
|
#include "Messages/NameMsg.h"
|
||||||
#include "ThingMsg.h"
|
#include "Messages/NetworkIdMsg.h"
|
||||||
|
#include "Messages/PoseMsg.h"
|
||||||
|
#include "Messages/ThingMsg.h"
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
@ -35,6 +37,7 @@ public:
|
|||||||
|
|
||||||
const char *ipAddress = "0.0.0.0";
|
const char *ipAddress = "0.0.0.0";
|
||||||
int port = 0;
|
int port = 0;
|
||||||
|
int localPort = 0;
|
||||||
|
|
||||||
#if defined(ARDUINO)
|
#if defined(ARDUINO)
|
||||||
const char *remoteIpAddress = nullptr;
|
const char *remoteIpAddress = nullptr;
|
||||||
@ -62,6 +65,9 @@ public:
|
|||||||
// i.e.
|
// i.e.
|
||||||
// Participant p = Participant("127.0.0.1", 8000);
|
// Participant p = Participant("127.0.0.1", 8000);
|
||||||
|
|
||||||
|
void begin();
|
||||||
|
bool connected = false;
|
||||||
|
|
||||||
virtual void Update(unsigned long currentTimeMs = 0);
|
virtual void Update(unsigned long currentTimeMs = 0);
|
||||||
|
|
||||||
void SendThingInfo(Thing *thing);
|
void SendThingInfo(Thing *thing);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user