75 lines
1.8 KiB
C++
75 lines
1.8 KiB
C++
#pragma once
|
|
#include <iostream>
|
|
|
|
namespace Passer {
|
|
namespace Control {
|
|
|
|
#define THING_STORE_SIZE 256
|
|
// IMPORTANT: values higher than 256 will need to change the CoreThing::id type
|
|
// to 16-bit or higher, breaking the networking protocol!
|
|
|
|
class CoreThing {
|
|
public:
|
|
// Participant *client;
|
|
unsigned char networkId;
|
|
/// @char The id of the thing
|
|
unsigned char id;
|
|
CoreThing *parent;
|
|
/// @brief The type of Thing
|
|
unsigned char type;
|
|
const char *name = nullptr;
|
|
const char *modelUrl = nullptr;
|
|
float modelScale = 1;
|
|
// protected Sensor sensor;
|
|
|
|
/// @brief Basic Thing types
|
|
enum class Type {
|
|
Undetermined,
|
|
// Sensor,
|
|
Switch,
|
|
DistanceSensor,
|
|
DirectionalSensor,
|
|
TemperatureSensor,
|
|
// Motor,
|
|
ControlledMotor,
|
|
UncontrolledMotor,
|
|
Servo,
|
|
// Other
|
|
Humanoid,
|
|
ExternalSensor,
|
|
};
|
|
|
|
public:
|
|
CoreThing(unsigned char networkId = 0,
|
|
unsigned char thingType = (unsigned char)Type::Undetermined);
|
|
/// @brief Terminated thins are no longer updated
|
|
void Terminate();
|
|
|
|
/// @brief Gets the parent Thing
|
|
/// @return The parent Thing
|
|
CoreThing *GetParent();
|
|
|
|
/// @brief Updates the state of the thing
|
|
/// @param currentTimeMs The current clock time in milliseconds
|
|
virtual void Update(unsigned long currentTimeMs) {};
|
|
|
|
virtual void SendBytes(unsigned char *buffer, unsigned char *ix) {};
|
|
virtual void ProcessBytes(unsigned char *bytes) {};
|
|
|
|
protected:
|
|
virtual void Init();
|
|
|
|
//------------ All things
|
|
public:
|
|
static CoreThing *Get(unsigned char networkId, unsigned char thingId);
|
|
static int Add(CoreThing *thing);
|
|
static void Remove(CoreThing *thing);
|
|
static void UpdateAll(unsigned long currentTimeMs);
|
|
|
|
private:
|
|
static CoreThing *allThings[];
|
|
};
|
|
|
|
} // namespace Control
|
|
} // namespace Passer
|
|
using namespace Passer::Control; |