Switch to MPU6050, finally getting good data
This commit is contained in:
parent
8901e6933a
commit
f20ebd7ad2
@ -118,32 +118,9 @@ RemoteParticipantUDP::RemoteParticipantUDP(const char* ipAddress, int port) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool RemoteParticipantUDP::Send(IMessage* msg) {
|
bool RemoteParticipantUDP::Send(IMessage* msg) {
|
||||||
int bufferSize = msg->Serialize(this->buffer);
|
// No message is actually sent, because this class has no networking
|
||||||
if (bufferSize <= 0)
|
// implementation
|
||||||
return true;
|
|
||||||
|
|
||||||
// std::cout << "send msg " << (static_cast<int>(this->buffer[0]) & 0xff)
|
|
||||||
// << " to " << this->ipAddress << std::endl;
|
|
||||||
|
|
||||||
// #if defined(_WIN32) || defined(_WIN64)
|
|
||||||
// Windows::ParticipantUDP* thisWindows =
|
|
||||||
// static_cast<Windows::ParticipantUDP*>(this);
|
|
||||||
// return thisWindows->SendTo(this, bufferSize);
|
|
||||||
// #elif defined(__unix__) || defined(__APPLE__)
|
|
||||||
// Posix::ParticipantUDP* thisPosix =
|
|
||||||
// static_cast<Posix::ParticipantUDP*>(this); return thisPosix->SendTo(this,
|
|
||||||
// bufferSize);
|
|
||||||
// #elif defined(ARDUINO)
|
|
||||||
// Arduino::ParticipantUDP* thisArduino =
|
|
||||||
// static_cast<Arduino::ParticipantUDP*>(this);
|
|
||||||
// return thisArduino->SendTo(this, bufferSize);
|
|
||||||
// #elif defined(IDF_VER)
|
|
||||||
// EspIdf::ParticipantUDP* thisEspIdf =
|
|
||||||
// static_cast<EspIdf::ParticipantUDP*>(this);
|
|
||||||
// return thisEspIdf->SendTo(this, bufferSize);
|
|
||||||
// #else
|
|
||||||
return false;
|
return false;
|
||||||
// #endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma region Init
|
#pragma region Init
|
||||||
@ -192,30 +169,6 @@ void ParticipantUDPGeneric::begin() {
|
|||||||
SetupUDP(this->port, this->remoteSite->ipAddress, this->remoteSite->port);
|
SetupUDP(this->port, this->remoteSite->ipAddress, this->remoteSite->port);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void ParticipantUDPGeneric::SetupUDP(int localPort,
|
|
||||||
const char* remoteIpAddress,
|
|
||||||
int remotePort) {
|
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
|
||||||
Windows::ParticipantUDP* thisWindows =
|
|
||||||
static_cast<Windows::ParticipantUDP*>(this);
|
|
||||||
thisWindows->Setup(localPort, remoteIpAddress, remotePort);
|
|
||||||
#elif defined(__unix__) || defined(__APPLE__)
|
|
||||||
Posix::ParticipantUDP* thisPosix = static_cast<Posix::ParticipantUDP*>(this);
|
|
||||||
thisPosix->Setup(localPort, remoteIpAddress, remotePort);
|
|
||||||
#elif defined(ARDUINO)
|
|
||||||
Arduino::ParticipantUDP* thisArduino =
|
|
||||||
static_cast<Arduino::ParticipantUDP*>(this);
|
|
||||||
thisArduino->Setup();
|
|
||||||
#elif defined(IDF_VER)
|
|
||||||
EspIdf::ParticipantUDP* thisEspIdf =
|
|
||||||
static_cast<EspIdf::ParticipantUDP*>(this);
|
|
||||||
thisEspIdf->Setup(localPort, remoteIpAddress, remotePort);
|
|
||||||
#endif
|
|
||||||
this->connected = true;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma endregion Init
|
#pragma endregion Init
|
||||||
|
|
||||||
#pragma region Update
|
#pragma region Update
|
||||||
@ -231,14 +184,9 @@ void ParticipantUDPGeneric::Update(bool recurse) {
|
|||||||
if (this->connected == false)
|
if (this->connected == false)
|
||||||
begin();
|
begin();
|
||||||
|
|
||||||
ParticipantUDP* thisEspIdf =
|
|
||||||
static_cast<ParticipantUDP*>(this);
|
|
||||||
// thisEspIdf->SendTest();
|
|
||||||
|
|
||||||
if (this->publishInterval > 0 && currentTimeMs > this->nextPublishMe) {
|
if (this->publishInterval > 0 && currentTimeMs > this->nextPublishMe) {
|
||||||
ParticipantMsg* msg = new ParticipantMsg(this->networkId);
|
ParticipantMsg* msg = new ParticipantMsg(this->networkId);
|
||||||
|
|
||||||
// thisEspIdf->SendTest();
|
|
||||||
if (this->remoteSite == nullptr)
|
if (this->remoteSite == nullptr)
|
||||||
this->Publish(msg);
|
this->Publish(msg);
|
||||||
else
|
else
|
||||||
@ -248,22 +196,19 @@ void ParticipantUDPGeneric::Update(bool recurse) {
|
|||||||
this->nextPublishMe = currentTimeMs + this->publishInterval;
|
this->nextPublishMe = currentTimeMs + this->publishInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this->ReceiveUDP();
|
this->ReceiveUDP();
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateMyThings();
|
UpdateMyThings();
|
||||||
// UpdateOtherThings();
|
UpdateOtherThings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticipantUDPGeneric::UpdateMyThings() {
|
void ParticipantUDPGeneric::UpdateMyThings() {
|
||||||
std::cout << "# things = " << this->things.size() << std::endl;
|
|
||||||
for (Thing* thing : this->things) {
|
for (Thing* thing : this->things) {
|
||||||
std::cout << ".\n";
|
|
||||||
if (thing == nullptr) // || thing->GetParent() != nullptr)
|
if (thing == nullptr) // || thing->GetParent() != nullptr)
|
||||||
continue;
|
continue;
|
||||||
std::cout << (int)this->root << std::endl;
|
|
||||||
std::cout << thing->name << std::endl;
|
// Why don't we do recursive?
|
||||||
// Why don't we do recursive?
|
|
||||||
// Because when a thing creates a thing in the update,
|
// Because when a thing creates a thing in the update,
|
||||||
// that new thing is not sent out (because of hierarchyChanged)
|
// that new thing is not sent out (because of hierarchyChanged)
|
||||||
// before it is updated itself: it is immediatedly updated!
|
// before it is updated itself: it is immediatedly updated!
|
||||||
@ -356,56 +301,11 @@ void ParticipantUDPGeneric::PublishThingInfo(Thing* thing) {
|
|||||||
delete customMsg;
|
delete customMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
bool ParticipantUDPGeneric::Publish(IMessage* msg) {
|
|
||||||
// std::cout << "publish msg\n";
|
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
|
||||||
Windows::ParticipantUDP* thisWindows =
|
|
||||||
static_cast<Windows::ParticipantUDP*>(this);
|
|
||||||
return thisWindows->Publish(msg);
|
|
||||||
#elif defined(__unix__) || defined(__APPLE__)
|
|
||||||
Posix::ParticipantUDP* thisPosix = static_cast<Posix::ParticipantUDP*>(this);
|
|
||||||
return thisPosix->Publish(msg);
|
|
||||||
#elif defined(ARDUINO)
|
|
||||||
Arduino::ParticipantUDP* thisArduino =
|
|
||||||
static_cast<Arduino::ParticipantUDP*>(this);
|
|
||||||
return thisArduino->Publish(msg);
|
|
||||||
#elif defined(IDF_VER)
|
|
||||||
EspIdf::ParticipantUDP* thisEspIdf =
|
|
||||||
static_cast<EspIdf::ParticipantUDP*>(this);
|
|
||||||
return thisEspIdf->Publish(msg);
|
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Send
|
// Send
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
#pragma region Receive
|
#pragma region Receive
|
||||||
|
|
||||||
/*
|
|
||||||
void ParticipantUDPGeneric::ReceiveUDP() {
|
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
|
||||||
Windows::ParticipantUDP* thisWindows =
|
|
||||||
static_cast<Windows::ParticipantUDP*>(this);
|
|
||||||
thisWindows->Receive();
|
|
||||||
#elif defined(__unix__) || defined(__APPLE__)
|
|
||||||
Posix::ParticipantUDP* thisPosix = static_cast<Posix::ParticipantUDP*>(this);
|
|
||||||
thisPosix->Receive();
|
|
||||||
#elif defined(ARDUINO)
|
|
||||||
Arduino::ParticipantUDP* thisArduino =
|
|
||||||
static_cast<Arduino::ParticipantUDP*>(this);
|
|
||||||
thisArduino->Receive();
|
|
||||||
#elif defined(IDF_VER)
|
|
||||||
EspIdf::ParticipantUDP* thisEspIdf =
|
|
||||||
static_cast<EspIdf::ParticipantUDP*>(this);
|
|
||||||
thisEspIdf->Receive();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void ParticipantUDPGeneric::ReceiveData(unsigned char packetSize,
|
void ParticipantUDPGeneric::ReceiveData(unsigned char packetSize,
|
||||||
char* senderIpAddress,
|
char* senderIpAddress,
|
||||||
unsigned int senderPort) {
|
unsigned int senderPort) {
|
||||||
|
@ -181,7 +181,7 @@ class ParticipantUDPGeneric : public RemoteParticipantUDP {
|
|||||||
void SendThingInfo(Participant* remoteParticipant, Thing* thing);
|
void SendThingInfo(Participant* remoteParticipant, Thing* thing);
|
||||||
void PublishThingInfo(Thing* thing);
|
void PublishThingInfo(Thing* thing);
|
||||||
|
|
||||||
virtual bool Send(IMessage* msg);
|
virtual bool Send(IMessage* msg) override;
|
||||||
virtual bool Publish(IMessage* msg) = 0;
|
virtual bool Publish(IMessage* msg) = 0;
|
||||||
|
|
||||||
#pragma endregion Send
|
#pragma endregion Send
|
||||||
|
Loading…
x
Reference in New Issue
Block a user