107 lines
3.6 KiB
C++
107 lines
3.6 KiB
C++
#pragma once
|
|
|
|
#include "NetworkPerception.h"
|
|
#include "Perception.h"
|
|
#include "Roboid.h"
|
|
#include "Types.h"
|
|
|
|
namespace Passer {
|
|
namespace RoboidControl {
|
|
|
|
/// @brief Interface for synchronizaing state between clients across a network
|
|
class NetworkSync {
|
|
public:
|
|
NetworkSync() {};
|
|
NetworkSync(Roboid *roboid);
|
|
|
|
unsigned char networkId = 0;
|
|
|
|
/// @brief Retreive and send the roboid state
|
|
/// @param roboid The roboid for which the state is updated
|
|
virtual void NetworkUpdate(Roboid *roboid) = 0;
|
|
/// @brief Inform that the given object is no longer being tracked
|
|
/// @param obj
|
|
virtual void SendDestroyThing(InterestingThing *obj);
|
|
|
|
void SendThingInfo(Thing *thing, bool recurse = false);
|
|
void SendThing(Thing *thing);
|
|
void SendName(Thing *roboid);
|
|
void SendModel(Thing *thing);
|
|
void SendCustom(Thing *thing);
|
|
|
|
/// @brief The id of a Pose message
|
|
static const unsigned char PoseMsg = 0x10;
|
|
static const unsigned char PoseTypeMsg = 0x11;
|
|
static const unsigned char RelativePoseMsg = 0x12;
|
|
static const unsigned char StateMsg = 0x18;
|
|
/// @brief A bit pattern for the pose, stating that this message contains a
|
|
/// position in world coordinates
|
|
static const unsigned char Pose_Position = 0x01;
|
|
/// @brief A bit pattern for the pose, stating that this message contains an
|
|
/// orientation in world coordinates
|
|
static const unsigned char Pose_Orientation = 0x02;
|
|
/// @brief A bit pattern for the pose, stating that this messsage contains a
|
|
/// linear velocity in world coordinates
|
|
static const unsigned char Pose_LinearVelocity = 0x04;
|
|
/// @brief A bit pattern for the pose, stating that this message contains an
|
|
/// angular velocity in world coordinates
|
|
static const char Pose_AngularVelocity = 0x08;
|
|
|
|
static const unsigned char DestroyMsg = 0x20;
|
|
|
|
static const unsigned char AngVelocity2DMsg = 0x46;
|
|
static const unsigned char Position2DMsg = 0x61;
|
|
static const unsigned char Velocity2DMsg = 0x62;
|
|
static const unsigned char ThingMsg = 0x80;
|
|
static const unsigned char InvestigateMsg = 0x81;
|
|
static const unsigned char ModelMsg = 0x90;
|
|
static const unsigned char NameMsg = 0x91;
|
|
static const unsigned char ClientMsg = 0xA0;
|
|
static const unsigned char NetworkIdMsg = 0xA1;
|
|
static const unsigned char CustomMsg = 0xB1;
|
|
|
|
typedef void (*Buffer)(UInt8 *buffer, UInt16 bufferSize);
|
|
|
|
void ReceiveMessage(Roboid *roboid, unsigned char bytecount);
|
|
|
|
void PublishState(Roboid *roboid);
|
|
|
|
void SendInvestigate(InterestingThing *thing);
|
|
|
|
void PublishPerception(Roboid *roboid);
|
|
void PublishTrackedObjects(Roboid *roboid, InterestingThing **objects);
|
|
|
|
virtual void SendPosition(Spherical16 worldPosition) {};
|
|
virtual void SendPose(Spherical16 worldPosition,
|
|
SwingTwist16 worldOrientation) {};
|
|
// void SendPose(Roboid* roboid, bool recurse = true);
|
|
void SendPose(Thing *thing, bool force = 0, bool recurse = true);
|
|
|
|
virtual void SendText(const char *s);
|
|
void SendInt(const int x);
|
|
|
|
virtual void Download(const char *url) {};
|
|
|
|
protected:
|
|
Roboid *roboid;
|
|
NetworkPerception *networkPerception;
|
|
|
|
void ReceiveNetworkId();
|
|
void ReceiveCustom(unsigned char packetSize);
|
|
|
|
void PublishState(Sensor *sensor);
|
|
|
|
void PublishTrackedObject(Roboid *roboid, InterestingThing *object);
|
|
// void PublishRelativeObject(Buffer sendBuffer,
|
|
// UInt8 parentId,
|
|
// InterestingThing* object);
|
|
|
|
unsigned char buffer[256];
|
|
virtual void SendBuffer(unsigned char bufferSize);
|
|
virtual void PublishBuffer(unsigned char bufferSize);
|
|
|
|
void PublishClient();
|
|
};
|
|
|
|
} // namespace RoboidControl
|
|
} // namespace Passer
|