Steps towards using ContolCore
This commit is contained in:
parent
7e5876e2f8
commit
55b63f7c3e
@ -1,6 +0,0 @@
|
|||||||
#include "Client.h"
|
|
||||||
|
|
||||||
bool Passer::Control::ControlClient::SendMsg(unsigned char *buffer,
|
|
||||||
unsigned char bufferSize) {
|
|
||||||
return false;
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
namespace Passer::Control {
|
|
||||||
|
|
||||||
class ControlClient {
|
|
||||||
public:
|
|
||||||
unsigned char *buffer;
|
|
||||||
bool SendMsg(unsigned char *buffer, unsigned char bufferSize);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Passer::Control
|
|
38
ControlCore/CoreThing.cpp
Normal file
38
ControlCore/CoreThing.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include "CoreThing.h"
|
||||||
|
|
||||||
|
CoreThing::CoreThing(
|
||||||
|
// Participant *client,
|
||||||
|
unsigned char networkId, unsigned char thingId, unsigned char thingType) {
|
||||||
|
// this->client = client;
|
||||||
|
this->id = thingId;
|
||||||
|
this->type = thingType;
|
||||||
|
this->networkId = networkId;
|
||||||
|
this->Init();
|
||||||
|
// CoreThings::Add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreThing::Init() {}
|
||||||
|
|
||||||
|
// CoreThing *CoreThings::allThings[256] = {nullptr};
|
||||||
|
|
||||||
|
// CoreThing *CoreThings::Get(unsigned char networkId, unsigned char thingId) {
|
||||||
|
// for (unsigned char ix = 0; ix < 256; ix++) {
|
||||||
|
// CoreThing *thing = allThings[ix];
|
||||||
|
// if (thing == nullptr)
|
||||||
|
// continue;
|
||||||
|
// if (thing->networkId == networkId && thing->id == thingId)
|
||||||
|
// return thing;
|
||||||
|
// }
|
||||||
|
// return nullptr;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// bool CoreThings::Add(CoreThing *newThing) {
|
||||||
|
// for (unsigned char ix = 0; ix < 256; ix++) {
|
||||||
|
// CoreThing *thing = allThings[ix];
|
||||||
|
// if (thing == nullptr) {
|
||||||
|
// allThings[ix] = newThing;
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return false;
|
||||||
|
// }
|
41
ControlCore/CoreThing.h
Normal file
41
ControlCore/CoreThing.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Participant.h"
|
||||||
|
|
||||||
|
namespace Passer::Control {
|
||||||
|
|
||||||
|
class CoreThing {
|
||||||
|
public:
|
||||||
|
// Participant *client;
|
||||||
|
unsigned char networkId;
|
||||||
|
unsigned char id;
|
||||||
|
// CoreThing *parent;
|
||||||
|
unsigned char type;
|
||||||
|
const char *name;
|
||||||
|
const char *modelUrl;
|
||||||
|
// protected Sensor sensor;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CoreThing(
|
||||||
|
// Participant *client,
|
||||||
|
unsigned char networkId, unsigned char thingId,
|
||||||
|
unsigned char thingType = 0);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void Init();
|
||||||
|
|
||||||
|
// Things
|
||||||
|
};
|
||||||
|
|
||||||
|
// class CoreThings {
|
||||||
|
// friend class CoreThing;
|
||||||
|
|
||||||
|
// public:
|
||||||
|
// static CoreThing *allThings[];
|
||||||
|
|
||||||
|
// public:
|
||||||
|
// static CoreThing *Get(unsigned char networkId, unsigned char thingId);
|
||||||
|
// static bool Add(CoreThing *thing);
|
||||||
|
// };
|
||||||
|
|
||||||
|
} // namespace Passer::Control
|
@ -1,19 +1,15 @@
|
|||||||
#include "Messages.h"
|
#include "Messages.h"
|
||||||
|
|
||||||
#include "LowLevelMessages.h"
|
#include "LowLevelMessages.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
#pragma region IMessage
|
#pragma region IMessage
|
||||||
|
|
||||||
unsigned char IMessage::Serialize(unsigned char *buffer) { return 0; }
|
unsigned char IMessage::Serialize(unsigned char *buffer) { return 0; }
|
||||||
|
|
||||||
bool IMessage::SendMsg(ControlClient client, IMessage msg,
|
bool IMessage::SendMsg(Participant *client, IMessage msg) {
|
||||||
unsigned char bufferSize) {
|
// return SendMsg(client, client.buffer, );nameLength
|
||||||
return SendMsg(client, client.buffer, msg.Serialize(client.buffer));
|
return client->SendBuffer(msg.Serialize(client->buffer));
|
||||||
}
|
|
||||||
|
|
||||||
bool IMessage::SendMsg(ControlClient client, unsigned char *buffer,
|
|
||||||
unsigned char bufferSize) {
|
|
||||||
return false; // client.SendMsg(buffer, bufferSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
@ -33,10 +29,10 @@ unsigned char InvestigateMsg::Serialize(unsigned char *buffer) {
|
|||||||
return ix;
|
return ix;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InvestigateMsg::Send(ControlClient client, unsigned char networkId,
|
bool InvestigateMsg::Send(Participant *client, unsigned char networkId,
|
||||||
unsigned char thingId) {
|
unsigned char thingId) {
|
||||||
InvestigateMsg msg = InvestigateMsg(networkId, thingId);
|
InvestigateMsg msg = InvestigateMsg(networkId, thingId);
|
||||||
return SendMsg(client, msg, InvestigateMsg::length);
|
return SendMsg(client, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Investigate
|
// Investigate
|
||||||
@ -44,10 +40,8 @@ bool InvestigateMsg::Send(ControlClient client, unsigned char networkId,
|
|||||||
|
|
||||||
#pragma region Thing
|
#pragma region Thing
|
||||||
|
|
||||||
Passer::Control::ThingMsg::ThingMsg(unsigned char networkId,
|
ThingMsg::ThingMsg(unsigned char networkId, unsigned char thingId,
|
||||||
unsigned char thingId,
|
unsigned char thingType, unsigned char parentId) {
|
||||||
unsigned char thingType,
|
|
||||||
unsigned char parentId) {
|
|
||||||
this->networkId = networkId;
|
this->networkId = networkId;
|
||||||
this->thingId = thingId;
|
this->thingId = thingId;
|
||||||
this->thingType = thingType;
|
this->thingType = thingType;
|
||||||
@ -64,13 +58,11 @@ unsigned char ThingMsg::Serialize(unsigned char *buffer) {
|
|||||||
return ix;
|
return ix;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Passer::Control::ThingMsg::Send(ControlClient client,
|
bool ThingMsg::Send(Participant *client, unsigned char networkId,
|
||||||
unsigned char networkId,
|
unsigned char thingId, unsigned char thingType,
|
||||||
unsigned char thingId,
|
|
||||||
unsigned char thingType,
|
|
||||||
unsigned char parentId) {
|
unsigned char parentId) {
|
||||||
ThingMsg msg = ThingMsg(networkId, thingId, thingType, parentId);
|
ThingMsg msg = ThingMsg(networkId, thingId, thingType, parentId);
|
||||||
return SendMsg(client, msg, ThingMsg::length);
|
return SendMsg(client, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Thing
|
// Thing
|
||||||
@ -79,24 +71,37 @@ bool Passer::Control::ThingMsg::Send(ControlClient client,
|
|||||||
#pragma region Name
|
#pragma region Name
|
||||||
|
|
||||||
NameMsg::NameMsg(unsigned char networkId, unsigned char thingId,
|
NameMsg::NameMsg(unsigned char networkId, unsigned char thingId,
|
||||||
unsigned char nameLength, const char *name) {
|
const char *name, unsigned char nameLength) {
|
||||||
this->networkId = networkId;
|
this->networkId = networkId;
|
||||||
this->thingId = thingId;
|
this->thingId = thingId;
|
||||||
this->nameLength = nameLength;
|
|
||||||
this->name = name;
|
this->name = name;
|
||||||
|
this->nameLength = nameLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char Passer::Control::NameMsg::Serialize(unsigned char *buffer) {
|
unsigned char NameMsg::Serialize(unsigned char *buffer) {
|
||||||
unsigned char ix = 0;
|
unsigned char ix = 0;
|
||||||
buffer[ix++] = this->id;
|
buffer[ix++] = this->id;
|
||||||
buffer[ix++] = this->networkId;
|
buffer[ix++] = this->networkId;
|
||||||
buffer[ix++] = this->thingId;
|
buffer[ix++] = this->thingId;
|
||||||
buffer[ix++] = this->nameLength;
|
buffer[ix++] = this->nameLength;
|
||||||
for (int nameIx = 0; nameIx < this->nameLength; nameIx++)
|
for (int nameIx = 0; nameIx < this->nameLength; nameIx++)
|
||||||
buffer[ix++] = name[nameIx];
|
buffer[ix++] = this->name[nameIx];
|
||||||
|
|
||||||
return ix;
|
return ix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NameMsg::Send(Participant *client, CoreThing *thing,
|
||||||
|
unsigned char nameLength) {
|
||||||
|
if (thing->name == nullptr)
|
||||||
|
return true; // nothing sent, but still a success!
|
||||||
|
|
||||||
|
if (strlen(thing->name) == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
NameMsg msg = NameMsg(thing->networkId, thing->id, thing->name, nameLength);
|
||||||
|
return SendMsg(client, msg);
|
||||||
|
}
|
||||||
|
|
||||||
// Name
|
// Name
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
|
@ -1,19 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../float16/float16.h"
|
#include "../float16/float16.h"
|
||||||
#include "Client.h"
|
#include "CoreThing.h"
|
||||||
|
#include "Participant.h"
|
||||||
|
|
||||||
namespace Passer::Control {
|
namespace Passer::Control {
|
||||||
|
|
||||||
class IMessage {
|
class IMessage {
|
||||||
public:
|
public:
|
||||||
// static unsigned char buffer[256];
|
|
||||||
|
|
||||||
virtual unsigned char Serialize(unsigned char *buffer);
|
virtual unsigned char Serialize(unsigned char *buffer);
|
||||||
|
|
||||||
static bool SendMsg(ControlClient client, IMessage msg,
|
static bool SendMsg(Participant *client, IMessage msg);
|
||||||
unsigned char bufferSize);
|
|
||||||
static bool SendMsg(ControlClient client, unsigned char *buffer,
|
|
||||||
unsigned char bufferSize);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class InvestigateMsg : public IMessage {
|
class InvestigateMsg : public IMessage {
|
||||||
@ -27,7 +23,7 @@ public:
|
|||||||
|
|
||||||
virtual unsigned char Serialize(unsigned char *buffer) override;
|
virtual unsigned char Serialize(unsigned char *buffer) override;
|
||||||
|
|
||||||
static bool Send(ControlClient client, unsigned char networkId,
|
static bool Send(Participant *client, unsigned char networkId,
|
||||||
unsigned char thingId);
|
unsigned char thingId);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -45,7 +41,7 @@ public:
|
|||||||
|
|
||||||
virtual unsigned char Serialize(unsigned char *buffer) override;
|
virtual unsigned char Serialize(unsigned char *buffer) override;
|
||||||
|
|
||||||
static bool Send(ControlClient client, unsigned char networkId,
|
static bool Send(Participant *client, unsigned char networkId,
|
||||||
unsigned char thingId, unsigned char thingType,
|
unsigned char thingId, unsigned char thingType,
|
||||||
unsigned char parentId);
|
unsigned char parentId);
|
||||||
};
|
};
|
||||||
@ -59,10 +55,13 @@ public:
|
|||||||
unsigned char nameLength;
|
unsigned char nameLength;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
NameMsg(unsigned char networkId, unsigned char thingId,
|
NameMsg(unsigned char networkId, unsigned char thingId, const char *name,
|
||||||
unsigned char nameLength, const char *name);
|
unsigned char nameLength);
|
||||||
|
|
||||||
virtual unsigned char Serialize(unsigned char *buffer) override;
|
virtual unsigned char Serialize(unsigned char *buffer) override;
|
||||||
|
|
||||||
|
static bool Send(Participant *client, CoreThing *thing,
|
||||||
|
unsigned char nameLength);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ModelUrlMsg : public IMessage {
|
class ModelUrlMsg : public IMessage {
|
||||||
|
10
ControlCore/Participant.cpp
Normal file
10
ControlCore/Participant.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include "Participant.h"
|
||||||
|
|
||||||
|
// bool Passer::Control::ControlClient::SendMsg(unsigned char *buffer,
|
||||||
|
// unsigned char bufferSize) {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
bool Participant::SendBuffer(unsigned char bufferSize) { return false; }
|
||||||
|
|
||||||
|
bool Participant::PublishBuffer(unsigned char bufferSize) { return false; }
|
16
ControlCore/Participant.h
Normal file
16
ControlCore/Participant.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace Passer::Control {
|
||||||
|
|
||||||
|
class Participant {
|
||||||
|
public:
|
||||||
|
// unsigned char *buffer;
|
||||||
|
// bool SendMsg(unsigned char *buffer, unsigned char bufferSize);
|
||||||
|
|
||||||
|
unsigned char buffer[1024];
|
||||||
|
virtual bool SendBuffer(unsigned char bufferSize);
|
||||||
|
virtual bool PublishBuffer(unsigned char bufferSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Passer::Control
|
||||||
|
using namespace Passer::Control;
|
@ -166,9 +166,11 @@ void NetworkSync::SendName(Thing *thing) {
|
|||||||
|
|
||||||
// SendBuffer(ix);
|
// SendBuffer(ix);
|
||||||
Passer::Control::NameMsg msg =
|
Passer::Control::NameMsg msg =
|
||||||
Passer::Control::NameMsg(this->networkId, thing->id, len, thing->name);
|
Passer::Control::NameMsg(this->networkId, thing->id, thing->name, len);
|
||||||
SendBuffer(msg.Serialize(this->buffer));
|
SendBuffer(msg.Serialize(this->buffer));
|
||||||
|
|
||||||
|
// Passer::Control::NameMsg::Send(this, thing);
|
||||||
|
|
||||||
#ifdef RC_DEBUG
|
#ifdef RC_DEBUG
|
||||||
SERIALPORT.printf("Sent Name [%d/%d] %s\n", networkId, buffer[1],
|
SERIALPORT.printf("Sent Name [%d/%d] %s\n", networkId, buffer[1],
|
||||||
thing->name);
|
thing->name);
|
||||||
@ -406,9 +408,10 @@ void NetworkSync::SendInt(const int x) {
|
|||||||
|
|
||||||
// Low-level functions
|
// Low-level functions
|
||||||
|
|
||||||
void NetworkSync::SendBuffer(unsigned char bufferSize) {}
|
// bool NetworkSync::SendBuffer(unsigned char bufferSize) { return false; }
|
||||||
|
|
||||||
void NetworkSync::PublishBuffer(unsigned char bufferSize) {}
|
// bool NetworkSync::PublishBuffer(unsigned char bufferSize) { return false; }
|
||||||
|
|
||||||
void NetworkSync::SendCBuffer(unsigned char bufferSize, unsigned char *buffer) {
|
// void NetworkSync::SendCBuffer(unsigned char bufferSize, unsigned char
|
||||||
}
|
// *buffer) {
|
||||||
|
//}
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ControlCore/Messages.h"
|
#include "ControlCore/Messages.h"
|
||||||
|
#include "ControlCore/Participant.h"
|
||||||
#include "NetworkPerception.h"
|
#include "NetworkPerception.h"
|
||||||
#include "Perception.h"
|
#include "Perception.h"
|
||||||
#include "Roboid.h"
|
#include "Roboid.h"
|
||||||
@ -10,7 +11,7 @@ namespace Passer {
|
|||||||
namespace RoboidControl {
|
namespace RoboidControl {
|
||||||
|
|
||||||
/// @brief Interface for synchronizaing state between clients across a network
|
/// @brief Interface for synchronizaing state between clients across a network
|
||||||
class NetworkSync {
|
class NetworkSync : public Participant {
|
||||||
public:
|
public:
|
||||||
NetworkSync() {};
|
NetworkSync() {};
|
||||||
NetworkSync(Roboid *roboid);
|
NetworkSync(Roboid *roboid);
|
||||||
@ -97,11 +98,11 @@ protected:
|
|||||||
// UInt8 parentId,
|
// UInt8 parentId,
|
||||||
// InterestingThing* object);
|
// InterestingThing* object);
|
||||||
|
|
||||||
unsigned char buffer[256];
|
// unsigned char buffer[256];
|
||||||
virtual void SendBuffer(unsigned char bufferSize);
|
// virtual bool SendBuffer(unsigned char bufferSize);
|
||||||
virtual void PublishBuffer(unsigned char bufferSize);
|
// virtual bool PublishBuffer(unsigned char bufferSize);
|
||||||
|
|
||||||
virtual void SendCBuffer(unsigned char bufferSize, unsigned char *buffer);
|
// virtual void SendCBuffer(unsigned char bufferSize, unsigned char *buffer);
|
||||||
|
|
||||||
void PublishClient();
|
void PublishClient();
|
||||||
};
|
};
|
||||||
|
@ -15,7 +15,7 @@ Roboid::Roboid() : Thing(0) {
|
|||||||
#ifdef RC_DEBUG
|
#ifdef RC_DEBUG
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
#endif
|
#endif
|
||||||
this->type = RoboidType;
|
this->type = (unsigned char)RoboidType;
|
||||||
this->perception = new Perception();
|
this->perception = new Perception();
|
||||||
this->perception->roboid = this;
|
this->perception->roboid = this;
|
||||||
this->propulsion = new Propulsion();
|
this->propulsion = new Propulsion();
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include "Roboid.h"
|
#include "Roboid.h"
|
||||||
|
|
||||||
Sensor::Sensor() : Thing() { // for now, id should be set properly later
|
Sensor::Sensor() : Thing() { // for now, id should be set properly later
|
||||||
this->type = Thing::SensorType;
|
this->type = (unsigned char)Thing::SensorType;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sensor::SetParent(Thing *parent) {
|
void Sensor::SetParent(Thing *parent) {
|
||||||
|
@ -7,6 +7,7 @@ using namespace Passer::RoboidControl;
|
|||||||
int Thing::lastThingId = 1;
|
int Thing::lastThingId = 1;
|
||||||
|
|
||||||
Thing::Thing() {
|
Thing::Thing() {
|
||||||
|
//: CoreThing(0, lastThingId++, (unsigned char)Type::Undetermined) {
|
||||||
this->id = lastThingId++;
|
this->id = lastThingId++;
|
||||||
this->type = (unsigned int)Type::Undetermined;
|
this->type = (unsigned int)Type::Undetermined;
|
||||||
this->childCount = 0;
|
this->childCount = 0;
|
||||||
@ -14,7 +15,9 @@ Thing::Thing() {
|
|||||||
this->children = nullptr;
|
this->children = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Thing::Thing(unsigned char id) : id(id) {
|
Thing::Thing(unsigned char id) {
|
||||||
|
//: CoreThing(0, id, (unsigned char)Type::Undetermined) {
|
||||||
|
this->id = id;
|
||||||
// this->position = SphericalOf<signed short>::zero;
|
// this->position = SphericalOf<signed short>::zero;
|
||||||
this->type = (unsigned int)Type::Undetermined;
|
this->type = (unsigned int)Type::Undetermined;
|
||||||
this->childCount = 0;
|
this->childCount = 0;
|
||||||
|
3
Thing.h
3
Thing.h
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "ControlCore/CoreThing.h"
|
||||||
#include "LinearAlgebra/AngleAxis.h"
|
#include "LinearAlgebra/AngleAxis.h"
|
||||||
#include "LinearAlgebra/Quaternion.h"
|
#include "LinearAlgebra/Quaternion.h"
|
||||||
#include "LinearAlgebra/Spherical.h"
|
#include "LinearAlgebra/Spherical.h"
|
||||||
@ -9,7 +10,7 @@ namespace Passer {
|
|||||||
namespace RoboidControl {
|
namespace RoboidControl {
|
||||||
|
|
||||||
/// @brief A thing is a functional component on a robot
|
/// @brief A thing is a functional component on a robot
|
||||||
class Thing {
|
class Thing { //: public CoreThing {
|
||||||
public:
|
public:
|
||||||
Thing();
|
Thing();
|
||||||
/// @brief Default constructor for a Thing
|
/// @brief Default constructor for a Thing
|
||||||
|
Loading…
x
Reference in New Issue
Block a user