Skip to content

Commit

Permalink
Complete rework of wireless configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
cor3ntin committed Aug 27, 2019
1 parent e4a7556 commit 1956f7e
Show file tree
Hide file tree
Showing 30 changed files with 752 additions and 605 deletions.
29 changes: 18 additions & 11 deletions aseba/flatbuffers/thymio.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ enum ErrorType : int {
node_busy = 3,

///Unsuported variable type - For SetVariables and Events
unsupported_variable_type
unsupported_variable_type = 4,

thymio2_pairing_write_dongle_failed = 5,
thymio2_pairing_write_robot_failed = 6,
}


Expand Down Expand Up @@ -380,19 +383,17 @@ table FirmwareUpgradeStatus {
}

table Thymio2WirelessDongle {
request_id : uint;
dongle_id:NodeId;
dongle_id : NodeId;
dongle_node : uint16;
network_id: uint16;
channel_id: uint8;
}

table Thymio2WirelessDonglesChanged {
dongles: [NodeId];
table EnableThymio2PairingMode {
}

table Thymio2WirelessDongleInfoRequest {
request_id:uint;
dongle_id:NodeId;
table Thymio2WirelessDonglesChanged {
dongles: [Thymio2WirelessDongle];
}

table Thymio2WirelessDonglePairingRequest {
Expand All @@ -403,6 +404,12 @@ table Thymio2WirelessDonglePairingRequest {
channel_id: uint8;
}

table Thymio2WirelessDonglePairingResponse{
request_id:uint;
network_id: uint16;
channel_id: uint8;
}

union AnyMessage {
ConnectionHandshake,
DeviceManagerShutdownRequest,
Expand Down Expand Up @@ -433,10 +440,10 @@ union AnyMessage {
FirmwareUpgradeRequest,
FirmwareUpgradeStatus,
Ping,
EnableThymio2PairingMode,
Thymio2WirelessDonglesChanged,
Thymio2WirelessDongleInfoRequest,
Thymio2WirelessDongle,
Thymio2WirelessDonglePairingRequest
Thymio2WirelessDonglePairingRequest,
Thymio2WirelessDonglePairingResponse
}

table Message {
Expand Down
132 changes: 41 additions & 91 deletions aseba/launcher/src/qml/wirelessconfigurator/WirelessConfigurator.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ Rectangle {

property bool valiseMode: false
property bool advancedMode: false
property var localEndpoint: client.localEndpoint
property var donglesManager: null
property var dongles: null
property var nodes: null
property var ready: false
property var waitingForUnplug: false

property var selectedDongleId: null
property var selectedRobotId: null
Expand Down Expand Up @@ -82,39 +80,6 @@ Rectangle {

const nodes = usbThymios()

if(waitingForUnplug) {
if(dongles.length === 0 || pairedDongleUUIDs.indexOf(dongles[0]) < 0 ) {
errorBanner.text = qsTr("Pairing successful")
nextButton.visible = true
pairButton.visible = false
waitingForUnplug = false
}
return
}

if(advancedMode && dongles.length === 1) {
let req = donglesManager.dongleInfo(dongles[0])
Request.onFinished(req, function(status, res) {
console.log("Info for dongle %1 : network %2 - channel : %3"
.arg(dongles[0])
.arg(res.networkId())
.arg(res.channel()))

selectedNetworkId = getNonDefaultNetworkId(res.networkId())
selectedChannel = getChannel()
})
}

//Dongles have a new UUID each time they are unplugged
//If we see a dongle we previously paired, ask the user to uplug it
if(dongles.length === 1 && pairedDongleUUIDs.indexOf(dongles[0]) >= 0) {
errorBanner.text = qsTr("Please unplug the dongle to complete the process")
nextButton.visible = false
pairButton.visible = false
waitingForUnplug = true
return
}

if(nextButton.visible)
return;

Expand Down Expand Up @@ -147,8 +112,10 @@ Rectangle {
}


selectedRobotId = nodes[0].id
selectedDongleId = dongles[0]
selectedRobotId = nodes[0].id
selectedDongleId = dongles[0].uuid
selectedNetworkId = dongles[0].networkId;
selectedChannel = dongles[0].channel;
ready = true
}

Expand All @@ -167,12 +134,20 @@ Rectangle {
pairedDongleNetworkIds.push(networkId)


Request.onFinished(request, function(status, res) {
Request.onFinished(request, function(success, res) {
if(!success) {
console.log("Pairing failed")
return;
}
console.log("Pairing complete: network %1 - channel %2"
.arg(res.networkId())
.arg(res.channel()))
robotCount ++
waitingForUnplug = true
errorBanner.text = qsTr("Pairing successful")

nextButton.visible = true
pairButton.visible = false

updateState()
})
}
Expand All @@ -190,64 +165,39 @@ Rectangle {
updateState()
if(!ready)
return
let req = donglesManager.dongleInfo(dongles[0])
Request.onFinished(req, function(status, res) {
console.log("Info for dongle %1 : network %2 - channel : %3"
.arg(selectedDongleId)
.arg(res.networkId())
.arg(res.channel()))
selectedNetworkId = getNonDefaultNetworkId(selectedNetworkId)
selectedChannel = getChannel()

selectedNetworkId = getNonDefaultNetworkId(res.networkId())
selectedChannel = getChannel()
if(valiseMode && pairedDongleNetworkIds.indexOf(selectedNetworkId) >= 0) {
ready = false
errorBanner.text = qsTr("You have alredy paired this dongle with another robot")
return
}
pairRobotAndDongle(selectedRobotId, selectedDongleId, selectedNetworkId, selectedChannel)
}

if(valiseMode && pairedDongleNetworkIds.indexOf(selectedNetworkId) >= 0) {
ready = false
errorBanner.text = qsTr("You have alredy paired this dongle with another robot")
return
}
pairRobotAndDongle(selectedRobotId, selectedDongleId, selectedNetworkId, selectedChannel)
function configure() {
if(!client.localEndpoint)
return;
client.localEndpoint.enableWirelessPairingMode();
donglesManager = client.localEndpoint.donglesManager
nodes = client.localEndpoint.nodes
donglesManager.donglesChanged.connect(function() {
console.log(donglesManager.dongles())
dongles = donglesManager.dongles()
updateState()
})
client.localEndpoint.nodesChanged.connect(function() {
nodes = client.localEndpoint.nodes
updateState()
})
dongles = donglesManager.dongles()
updateState()
}

Component.onCompleted: {
client.localEndpointChanged.connect(function () {
localEndpoint = client.localEndpoint
donglesManager = null
dongles = null
if(!localEndpoint) {
return
}

donglesManager = localEndpoint.donglesManager

if(!donglesManager) {
return
}

dongles = donglesManager.dongles
donglesManager.donglesChanged.connect(function() {
if(!wirelessConfigurator)
return;

wirelessConfigurator.dongles = donglesManager.dongles
console.log("Dongles connected: %1".arg(dongles.length))
updateState()
})

localEndpoint.nodesChanged.connect(function () {
if(!wirelessConfigurator)
return;
wirelessConfigurator.nodes = localEndpoint.nodes
updateState()
})
})
localEndpoint = client.localEndpoint
if(localEndpoint) {
donglesManager = localEndpoint.donglesManager
dongles = donglesManager.dongles
nodes = localEndpoint.nodes
updateState()
}
configure()
client.localEndpointChanged.connect(configure)
}

Item {
Expand Down
2 changes: 1 addition & 1 deletion aseba/qt-thymio-dm-client-lib/qml/quickrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ QtObject {
qmlRegisterSingletonType<QmlRequest>("org.mobsya", 1, 0, "Request", provider);
QmlRequest::registerType<SimpleRequestResult>();
QmlRequest::registerType<CompilationResult>();
QmlRequest::registerType<Thymio2WirelessDongleInfoResult>();
QmlRequest::registerType<Thymio2WirelessDonglePairingResult>();
qRegisterMetaType<Request>("Request");
qRegisterMetaType<CompilationError>();
qRegisterMetaType<SetBreakpointRequestResult>();
Expand Down
4 changes: 2 additions & 2 deletions aseba/qt-thymio-dm-client-lib/qml/quickrequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,5 @@ Q_DECLARE_METATYPE(mobsya::BreakpointsRequest)
Q_DECLARE_METATYPE(mobsya::SetBreakpointRequestResult)
Q_DECLARE_METATYPE(mobsya::AsebaVMDescriptionRequest)
Q_DECLARE_METATYPE(mobsya::AsebaVMDescriptionRequestResult)
Q_DECLARE_METATYPE(mobsya::Thymio2WirelessDongleInfoRequest)
Q_DECLARE_METATYPE(mobsya::Thymio2WirelessDongleInfoResult)
Q_DECLARE_METATYPE(mobsya::Thymio2WirelessDonglePairingRequest)
Q_DECLARE_METATYPE(mobsya::Thymio2WirelessDonglePairingResult)
14 changes: 5 additions & 9 deletions aseba/qt-thymio-dm-client-lib/request.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,12 @@ struct SimpleRequestResult {
};


struct Thymio2WirelessDongleInfoResult {
struct Thymio2WirelessDonglePairingResult {
Q_GADGET

public:
Thymio2WirelessDongleInfoResult() = default;
Thymio2WirelessDongleInfoResult(uint16_t network, uint8_t channel) : m_networkId(network), m_channel(channel) {}
Thymio2WirelessDonglePairingResult() = default;
Thymio2WirelessDonglePairingResult(uint16_t network, uint8_t channel) : m_networkId(network), m_channel(channel) {}

static constexpr quint32 type = 0x478fa12d;
Q_INVOKABLE quint16 networkId() const {
Expand Down Expand Up @@ -507,12 +507,8 @@ using Request = BasicRequest<SimpleRequestResult>;
using RequestWatcher = BasicRequestWatcher<SimpleRequestResult>;


using Thymio2WirelessDonglePairingRequest = BasicRequest<Thymio2WirelessDongleInfoResult>;
using Thymio2WirelessDonglePairingRequestWatcher = BasicRequestWatcher<Thymio2WirelessDongleInfoResult>;

using Thymio2WirelessDongleInfoRequest = BasicRequest<Thymio2WirelessDongleInfoResult>;
using Thymio2WirelessDongleInfoRequestWatcher = BasicRequestWatcher<Thymio2WirelessDongleInfoResult>;

using Thymio2WirelessDonglePairingRequest = BasicRequest<Thymio2WirelessDonglePairingResult>;
using Thymio2WirelessDonglePairingRequestWatcher = BasicRequestWatcher<Thymio2WirelessDonglePairingResult>;

using CompilationRequest = BasicRequest<CompilationResult>;
using CompilationRequestWatcher = BasicRequestWatcher<CompilationResult>;
Expand Down
2 changes: 2 additions & 0 deletions aseba/qt-thymio-dm-client-lib/thymio-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ void inline register_qml_types() {
qRegisterMetaType<mobsya::Thymio2WirelessDonglesManager*>("Thymio2WirelessDonglesManager*");
qRegisterMetaType<QQmlListProperty<mobsya::ThymioNode>>("QQmlListProperty<ThymioNode>");
qmlRegisterUncreatableType<mobsya::ThymioNode>("org.mobsya", 1, 0, "ThymioNode", "Enum");
qRegisterMetaType<mobsya::Thymio2WirelessDongle>("Thymio2WirelessDongle");
qRegisterMetaType<QList<mobsya::Thymio2WirelessDongle>>();
}
#endif

Expand Down
18 changes: 7 additions & 11 deletions aseba/qt-thymio-dm-client-lib/thymio2wirelessdongle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,27 @@ Thymio2WirelessDonglesManager::Thymio2WirelessDonglesManager(ThymioDeviceManager
: QObject(parent), m_ep(parent) {}


Thymio2WirelessDongleInfoRequest Thymio2WirelessDonglesManager::dongleInfo(const QUuid& uuid) {
return m_ep->requestDongleInfo(uuid);
}

Thymio2WirelessDonglePairingRequest Thymio2WirelessDonglesManager::pairThymio2Wireless(const QUuid& dongleId,
const QUuid& nodeId,
quint16 networkId,
quint8 channel) {
return m_ep->pairThymio2Wireless(dongleId, nodeId, networkId, channel);
}

QStringList Thymio2WirelessDonglesManager::qml_dongles() const {
QStringList lst;
for(auto&& d : m_dongles) {
lst.append(d.toString());
QVariantList Thymio2WirelessDonglesManager::dongles() const {
QVariantList v;
for(auto&& e : m_dongles.values()) {
v.append(QVariant::fromValue(e));
}
return lst;
return v;
}

void Thymio2WirelessDonglesManager::clear() {
m_dongles.clear();
Q_EMIT donglesChanged();
}
void Thymio2WirelessDonglesManager::updateDongle(const QUuid& id) {
m_dongles.insert(id);
void Thymio2WirelessDonglesManager::updateDongle(const Thymio2WirelessDongle& dongle) {
m_dongles.insert(dongle.uuid, dongle);
Q_EMIT donglesChanged();
}

Expand Down
Loading

0 comments on commit 1956f7e

Please sign in to comment.