-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Network blocks in the visual language (#1795)
1. The `mailbox` entity has been taken to a higher level for use in visual language 2. Support for `TrikJoinNetwork`, `TrikWaitForMessage`, `TrikSendMessage` blocks in visual language 3. Cut out unnecessary functionality due to the use of the TrikJoinNetwork block
- Loading branch information
Showing
36 changed files
with
655 additions
and
74 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
plugins/robots/common/kitBase/include/kitBase/robotModel/robotParts/communicator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* Copyright 2024 CyberTech Labs Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. */ | ||
|
||
#pragma once | ||
|
||
#include "device.h" | ||
#include "kitBase/kitBaseDeclSpec.h" | ||
|
||
namespace kitBase { | ||
namespace robotModel { | ||
namespace robotParts { | ||
|
||
/// Base class for robot network communication. | ||
class ROBOTS_KIT_BASE_EXPORT Communicator : public Device | ||
{ | ||
Q_OBJECT | ||
Q_CLASSINFO("name", "communicator") | ||
Q_CLASSINFO("friendlyName", tr("Communicator")) | ||
Q_CLASSINFO("direction", "output") | ||
|
||
public: | ||
/// Constructor, takes device type info and port on which this device is configured. | ||
Communicator(const DeviceInfo &info, const PortInfo &port); | ||
|
||
/// Deinitializing a network communicator | ||
virtual void release() = 0; | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
plugins/robots/common/kitBase/src/robotModel/robotParts/communicator.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* Copyright 2024 CyberTech Labs Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. */ | ||
|
||
#include "kitBase/robotModel/robotParts/communicator.h" | ||
|
||
using namespace kitBase::robotModel; | ||
using namespace robotParts; | ||
|
||
Communicator::Communicator(const DeviceInfo &info, const PortInfo &port) | ||
: Device(info, port) | ||
{} |
50 changes: 50 additions & 0 deletions
50
plugins/robots/common/trikKit/include/trikKit/robotModel/parts/trikNetworkCommunicator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* Copyright 2024 CyberTech Labs Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. */ | ||
|
||
#pragma once | ||
#include <kitBase/robotModel/robotParts/communicator.h> | ||
|
||
namespace trik { | ||
namespace robotModel { | ||
namespace parts { | ||
|
||
/// Class for TRIK robot network communication. | ||
class TrikNetworkCommunicator : public kitBase::robotModel::robotParts::Communicator | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
TrikNetworkCommunicator(const kitBase::robotModel::DeviceInfo &info | ||
, const kitBase::robotModel::PortInfo &port); | ||
|
||
|
||
/// Send a message to a robot | ||
virtual void send(const QString& message, int hullNumber) = 0; | ||
|
||
/// Receive message from robot | ||
virtual QString receive(bool wait) = 0; | ||
|
||
/// Join the network with the specified hull number | ||
virtual void joinNetwork(const QString &ip, int port, int hullNumber) = 0; | ||
|
||
/// Send an interrupt to stop waiting for a message | ||
virtual void stopWaiting() = 0; | ||
|
||
/// Clean the incoming message queue | ||
virtual void clearQueue() = 0; | ||
}; | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
plugins/robots/common/trikKit/src/blocks/details/joinNetworkBlock.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* Copyright 2024 CyberTech Labs Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. */ | ||
|
||
|
||
#include "joinNetworkBlock.h" | ||
|
||
using namespace trik; | ||
using namespace blocks::details; | ||
|
||
JoinNetworkBlock::JoinNetworkBlock(kitBase::robotModel::RobotModelInterface &robotModel): | ||
kitBase::blocksBase::common::DeviceBlock<robotModel::parts::TrikNetworkCommunicator>(robotModel) | ||
{} | ||
|
||
void JoinNetworkBlock::doJob(robotModel::parts::TrikNetworkCommunicator &network) | ||
{ | ||
auto address = stringProperty("Address"); | ||
auto port = intProperty("IPPort"); | ||
auto hullNumber = intProperty("HullNumber"); | ||
network.joinNetwork(address, port, hullNumber); | ||
emit done(mNextBlockId); | ||
} |
36 changes: 36 additions & 0 deletions
36
plugins/robots/common/trikKit/src/blocks/details/joinNetworkBlock.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* Copyright 2024 CyberTech Labs Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. */ | ||
|
||
#pragma once | ||
|
||
#include <kitBase/blocksBase/common/deviceBlock.h> | ||
#include "trikKit/robotModel/parts/trikNetworkCommunicator.h" | ||
|
||
namespace trik { | ||
namespace blocks { | ||
namespace details { | ||
|
||
class JoinNetworkBlock: public kitBase::blocksBase::common::DeviceBlock<robotModel::parts::TrikNetworkCommunicator> | ||
{ | ||
Q_OBJECT | ||
public: | ||
JoinNetworkBlock(kitBase::robotModel::RobotModelInterface &robotModel); | ||
|
||
private: | ||
void doJob(robotModel::parts::TrikNetworkCommunicator &network) override; | ||
}; | ||
|
||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
plugins/robots/common/trikKit/src/blocks/details/sendMessageBlock.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* Copyright 2024 CyberTech Labs Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. */ | ||
|
||
#include "sendMessageBlock.h" | ||
|
||
using namespace trik; | ||
using namespace blocks::details; | ||
|
||
SendMessageBlock::SendMessageBlock(kitBase::robotModel::RobotModelInterface &robotModel): | ||
kitBase::blocksBase::common::DeviceBlock<robotModel::parts::TrikNetworkCommunicator>(robotModel) | ||
{} | ||
|
||
void SendMessageBlock::doJob(robotModel::parts::TrikNetworkCommunicator &network) | ||
{ | ||
auto message = stringProperty("Message"); | ||
auto hullNumber = intProperty("HullNumber"); | ||
network.send(message, hullNumber); | ||
emit done(mNextBlockId); | ||
} |
36 changes: 36 additions & 0 deletions
36
plugins/robots/common/trikKit/src/blocks/details/sendMessageBlock.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* Copyright 2024 CyberTech Labs Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. */ | ||
|
||
#pragma once | ||
|
||
#include <kitBase/blocksBase/common/deviceBlock.h> | ||
#include "trikKit/robotModel/parts/trikNetworkCommunicator.h" | ||
|
||
namespace trik { | ||
namespace blocks { | ||
namespace details { | ||
|
||
class SendMessageBlock: public kitBase::blocksBase::common::DeviceBlock<robotModel::parts::TrikNetworkCommunicator> | ||
{ | ||
Q_OBJECT | ||
public: | ||
SendMessageBlock(kitBase::robotModel::RobotModelInterface &robotModel); | ||
|
||
private: | ||
void doJob(robotModel::parts::TrikNetworkCommunicator &network) override; | ||
}; | ||
|
||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
plugins/robots/common/trikKit/src/blocks/details/waitForMessageBlock.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* Copyright 2024 CyberTech Labs Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. */ | ||
|
||
#include "waitForMessageBlock.h" | ||
#include "trikKit/robotModel/parts/trikNetworkCommunicator.h" | ||
#include <utils/abstractTimer.h> | ||
#include <qrutils/stringUtils.h> | ||
#include <kitBase/robotModel/robotModelInterface.h> | ||
#include <kitBase/robotModel/robotModelUtils.h> | ||
|
||
using namespace trik; | ||
using namespace blocks::details; | ||
using namespace kitBase::robotModel; | ||
|
||
WaitForMessageBlock::WaitForMessageBlock(kitBase::robotModel::RobotModelInterface &robotModel): | ||
WaitBlock(robotModel) | ||
{ | ||
mActiveWaitingTimer->setSingleShot(true); | ||
mActiveWaitingTimer->setInterval(100); | ||
} | ||
|
||
void WaitForMessageBlock::handle() | ||
{ | ||
evalCode(stringProperty("Variable") + " = " + mMessage); | ||
stop(); | ||
emit done(mNextBlockId); | ||
return; | ||
} | ||
|
||
void WaitForMessageBlock::run() | ||
{ | ||
mNetwork = RobotModelUtils::findDevice<robotModel::parts::TrikNetworkCommunicator>(mRobotModel, "CommunicatorPort"); | ||
|
||
if (!mNetwork) { | ||
error(tr("Device not found for port name CommunicatorPort")); | ||
return; | ||
} | ||
|
||
auto wait = boolProperty("Synchronized"); | ||
|
||
if (!wait) { | ||
mMessage = utils::StringUtils::wrap(utils::StringUtils::dequote(mNetwork->receive(wait))); | ||
handle(); | ||
return; | ||
} | ||
|
||
mActiveWaitingTimer->start(); | ||
} | ||
|
||
void WaitForMessageBlock::timerTimeout() | ||
{ | ||
auto message = mNetwork->receive(false); | ||
if (message != QString()) { | ||
mMessage = utils::StringUtils::wrap(utils::StringUtils::dequote(message)); | ||
handle(); | ||
return; | ||
} | ||
|
||
mActiveWaitingTimer->start(); | ||
} | ||
|
||
DeviceInfo WaitForMessageBlock::device() const | ||
{ | ||
return DeviceInfo::create<robotModel::parts::TrikNetworkCommunicator>(); | ||
} |
Oops, something went wrong.