tv commander added (basic navigation and remote keys like volume up/down, channels up/down, mute...)
TODO: find out why arrow keys will be pressed twice..hmmm
This commit is contained in:
parent
7890975ec6
commit
07ac559665
@ -26,6 +26,27 @@
|
||||
VendorId lgVendorId = VendorId("a9af9673-78db-4226-a16b-f34b304f7041");
|
||||
DeviceClassId lgSmartTvDeviceClassId = DeviceClassId("1d41b5a8-74ff-4a12-b365-c7bbe610848f");
|
||||
|
||||
StateTypeId tvReachableStateTypeId = StateTypeId("b056c36b-df87-4177-8d5d-1e7c1e8cdc7a");
|
||||
|
||||
ActionTypeId commandVolumeUpActionTypeId = ActionTypeId("ac5d7dcd-dfe8-4a94-9ab9-21b3f804b39e");
|
||||
ActionTypeId commandVolumeDownActionTypeId = ActionTypeId("62b17bec-f461-4ffa-93d1-67a9430d55e1");
|
||||
ActionTypeId commandMuteActionTypeId = ActionTypeId("1aa9d7f0-0f66-4b90-bb72-f6b7b2118221");
|
||||
ActionTypeId commandUnmuteActionTypeId = ActionTypeId("b7e31999-ba67-443d-8e5c-ec104af987bd");
|
||||
ActionTypeId commandChannelUpActionTypeId = ActionTypeId("acd1f6a0-2cfa-4665-9607-cf94245ec5a3");
|
||||
ActionTypeId commandChannelDownActionTypeId = ActionTypeId("6ea66772-0e6d-40b1-978c-a01fb53871dd");
|
||||
ActionTypeId commandPowerOffActionTypeId = ActionTypeId("cbe41134-ff11-4916-815b-3ac289c64090");
|
||||
ActionTypeId commandArrowUpActionTypeId = ActionTypeId("57c483b4-4ddf-4470-828c-8d8767e7a923");
|
||||
ActionTypeId commandArrowDownActionTypeId = ActionTypeId("614cf1af-5cf7-4bb2-885c-4414078d8899");
|
||||
ActionTypeId commandArrowLeftActionTypeId = ActionTypeId("916394dd-7833-4875-8d7a-49d7d24ceeb2");
|
||||
ActionTypeId commandArrowRightActionTypeId = ActionTypeId("01e3df1e-638b-4e14-ba85-660267766062");
|
||||
ActionTypeId commandOkActionTypeId = ActionTypeId("257dfa59-0d38-4e18-a3fc-213809fdb12f");
|
||||
ActionTypeId commandBackActionTypeId = ActionTypeId("ce4184b3-6b8e-4fc3-a4cb-7b8ec72f2ce9");
|
||||
ActionTypeId commandHomeActionTypeId = ActionTypeId("33f941c1-f5fc-4449-b6e3-93eafca493e0");
|
||||
ActionTypeId commandInputSourceActionTypeId = ActionTypeId("9a6e5111-95d3-49ac-8056-249e704b1509");
|
||||
ActionTypeId commandExitActionTypeId = ActionTypeId("d76efdb8-056e-4b39-a839-2ef6d6001b00");
|
||||
ActionTypeId commandInfoActionTypeId = ActionTypeId("9c1290d5-3135-4124-a576-fc7522cffdcf");
|
||||
ActionTypeId commandMyAppsActionTypeId = ActionTypeId("47d65cac-fe75-4c36-9dee-9862c1c1130e");
|
||||
ActionTypeId commandProgramListActionTypeId = ActionTypeId("9aa3a97e-505d-4906-9764-14b6dc4e31e8");
|
||||
|
||||
|
||||
DevicePluginLgSmartTv::DevicePluginLgSmartTv()
|
||||
@ -38,7 +59,7 @@ DevicePluginLgSmartTv::DevicePluginLgSmartTv()
|
||||
QList<Vendor> DevicePluginLgSmartTv::supportedVendors() const
|
||||
{
|
||||
QList<Vendor> ret;
|
||||
Vendor lgVendor(lgVendorId, "Lg");
|
||||
Vendor lgVendor(lgVendorId, "LG");
|
||||
ret.append(lgVendor);
|
||||
return ret;
|
||||
}
|
||||
@ -48,10 +69,12 @@ QList<DeviceClass> DevicePluginLgSmartTv::supportedDevices() const
|
||||
QList<DeviceClass> ret;
|
||||
|
||||
DeviceClass deviceClassLgSmartTv(pluginId(), lgVendorId, lgSmartTvDeviceClassId);
|
||||
deviceClassLgSmartTv.setName("Lg Smart Tv");
|
||||
deviceClassLgSmartTv.setName("LG Smart Tv");
|
||||
deviceClassLgSmartTv.setCreateMethod(DeviceClass::CreateMethodDiscovery);
|
||||
deviceClassLgSmartTv.setSetupMethod(DeviceClass::SetupMethodDisplayPin);
|
||||
//deviceClassLgSmartTv.setSetupMethod(DeviceClass::SetupMethodDisplayPin);
|
||||
// TODO: display pin...
|
||||
|
||||
// Params
|
||||
QList<ParamType> paramTypes;
|
||||
paramTypes.append(ParamType("name", QVariant::String));
|
||||
paramTypes.append(ParamType("uuid", QVariant::String));
|
||||
@ -63,8 +86,95 @@ QList<DeviceClass> DevicePluginLgSmartTv::supportedDevices() const
|
||||
|
||||
deviceClassLgSmartTv.setParamTypes(paramTypes);
|
||||
|
||||
ret.append(deviceClassLgSmartTv);
|
||||
// States
|
||||
QList<StateType> tvStates;
|
||||
|
||||
StateType reachableState(tvReachableStateTypeId);
|
||||
reachableState.setName("reachable");
|
||||
reachableState.setType(QVariant::Bool);
|
||||
reachableState.setDefaultValue(false);
|
||||
tvStates.append(reachableState);
|
||||
|
||||
deviceClassLgSmartTv.setStateTypes(tvStates);
|
||||
|
||||
// Actions
|
||||
QList<ActionType> tvActions;
|
||||
|
||||
ActionType commandVolumeUpAction(commandVolumeUpActionTypeId);
|
||||
commandVolumeUpAction.setName("volume up");
|
||||
tvActions.append(commandVolumeUpAction);
|
||||
|
||||
ActionType commandVolumeDownAction(commandVolumeDownActionTypeId);
|
||||
commandVolumeDownAction.setName("volume down");
|
||||
tvActions.append(commandVolumeDownAction);
|
||||
|
||||
ActionType commandMuteAction(commandMuteActionTypeId);
|
||||
commandMuteAction.setName("mute");
|
||||
tvActions.append(commandMuteAction);
|
||||
|
||||
ActionType commandChannelUpAction(commandChannelUpActionTypeId);
|
||||
commandChannelUpAction.setName("channel up");
|
||||
tvActions.append(commandChannelUpAction);
|
||||
|
||||
ActionType commandChannelDownAction(commandChannelDownActionTypeId);
|
||||
commandChannelDownAction.setName("channel down");
|
||||
tvActions.append(commandChannelDownAction);
|
||||
|
||||
ActionType commandPowerOffAction(commandPowerOffActionTypeId);
|
||||
commandPowerOffAction.setName("power");
|
||||
tvActions.append(commandPowerOffAction);
|
||||
|
||||
ActionType commandArrowUpAction(commandArrowUpActionTypeId);
|
||||
commandArrowUpAction.setName("arrow up");
|
||||
tvActions.append(commandArrowUpAction);
|
||||
|
||||
ActionType commandArrowDownAction(commandArrowDownActionTypeId);
|
||||
commandArrowDownAction.setName("arrow down");
|
||||
tvActions.append(commandArrowDownAction);
|
||||
|
||||
ActionType commandArrowLeftAction(commandArrowLeftActionTypeId);
|
||||
commandArrowLeftAction.setName("arrow left");
|
||||
tvActions.append(commandArrowLeftAction);
|
||||
|
||||
ActionType commandArrowRightAction(commandArrowRightActionTypeId);
|
||||
commandArrowRightAction.setName("arrow right");
|
||||
tvActions.append(commandArrowRightAction);
|
||||
|
||||
ActionType commandOkAction(commandOkActionTypeId);
|
||||
commandOkAction.setName("ok");
|
||||
tvActions.append(commandOkAction);
|
||||
|
||||
ActionType commandBackAction(commandBackActionTypeId);
|
||||
commandBackAction.setName("back");
|
||||
tvActions.append(commandBackAction);
|
||||
|
||||
ActionType commandHomeAction(commandHomeActionTypeId);
|
||||
commandHomeAction.setName("home");
|
||||
tvActions.append(commandHomeAction);
|
||||
|
||||
ActionType commandInputSourceAction(commandInputSourceActionTypeId);
|
||||
commandInputSourceAction.setName("input source");
|
||||
tvActions.append(commandInputSourceAction);
|
||||
|
||||
ActionType commandExitAction(commandExitActionTypeId);
|
||||
commandExitAction.setName("exit");
|
||||
tvActions.append(commandExitAction);
|
||||
|
||||
ActionType commandInfoAction(commandInfoActionTypeId);
|
||||
commandInfoAction.setName("info");
|
||||
tvActions.append(commandInfoAction);
|
||||
|
||||
ActionType commandMyAppsAction(commandMyAppsActionTypeId);
|
||||
commandMyAppsAction.setName("my apps");
|
||||
tvActions.append(commandMyAppsAction);
|
||||
|
||||
ActionType commandProgramListAction(commandProgramListActionTypeId);
|
||||
commandProgramListAction.setName("program list");
|
||||
tvActions.append(commandProgramListAction);
|
||||
|
||||
deviceClassLgSmartTv.setActions(tvActions);
|
||||
|
||||
ret.append(deviceClassLgSmartTv);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -76,14 +186,32 @@ QPair<DeviceManager::DeviceError, QString> DevicePluginLgSmartTv::discoverDevice
|
||||
return report(DeviceManager::DeviceErrorDeviceClassNotFound);
|
||||
}
|
||||
|
||||
m_discovery->discover(2000);
|
||||
m_discovery->discover(3000);
|
||||
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceSetupStatus, QString> DevicePluginLgSmartTv::setupDevice(Device *device)
|
||||
{
|
||||
return reportDeviceSetup();
|
||||
|
||||
device->setName("LG Smart Tv (" + device->paramValue("model").toString() + ")");
|
||||
|
||||
TvDevice *tvDevice = new TvDevice(this);
|
||||
tvDevice->setName(device->paramValue("name").toString());
|
||||
tvDevice->setUuid(device->paramValue("uuid").toString());
|
||||
tvDevice->setModelName(device->paramValue("model").toString());
|
||||
tvDevice->setHostAddress(QHostAddress(device->paramValue("host address").toString()));
|
||||
tvDevice->setLocation(QUrl(device->paramValue("location").toString()));
|
||||
tvDevice->setUuid(device->paramValue("manufacturer").toString());
|
||||
// key if there is one...
|
||||
|
||||
connect(tvDevice, &TvDevice::pairingFinished, this, &DevicePluginLgSmartTv::pairingFinished);
|
||||
connect(tvDevice, &TvDevice::sendCommandFinished, this, &DevicePluginLgSmartTv::sendingCommandFinished);
|
||||
|
||||
tvDevice->requestPairing();
|
||||
m_tvList.insert(tvDevice,device);
|
||||
|
||||
return reportDeviceSetup(DeviceManager::DeviceSetupStatusAsync);
|
||||
}
|
||||
|
||||
DeviceManager::HardwareResources DevicePluginLgSmartTv::requiredHardware() const
|
||||
@ -93,12 +221,98 @@ DeviceManager::HardwareResources DevicePluginLgSmartTv::requiredHardware() const
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginLgSmartTv::executeAction(Device *device, const Action &action)
|
||||
{
|
||||
return report();
|
||||
TvDevice * tvDevice = m_tvList.key(device);
|
||||
|
||||
if(action.actionTypeId() == commandVolumeUpActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::VolUp, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandVolumeDownActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::VolDown, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandMuteActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Mute, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandChannelUpActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::ChannelUp, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandChannelDownActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::ChannelDown, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandPowerOffActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Power, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandArrowUpActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Up, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandArrowDownActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Down, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandArrowLeftActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Left, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandArrowRightActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Right, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandOkActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Ok, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandBackActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Back, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandHomeActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Home, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandInputSourceActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::ExternalInput, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandExitActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Exit, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandInfoActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Info, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandMyAppsActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::MyApps, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandProgramListActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::ProgramList, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
|
||||
return report(DeviceManager::DeviceErrorActionTypeNotFound);
|
||||
}
|
||||
|
||||
void DevicePluginLgSmartTv::deviceRemoved(Device *device)
|
||||
{
|
||||
if (!m_tvList.values().contains(device)) {
|
||||
return;
|
||||
}
|
||||
|
||||
TvDevice *tvDevice= m_tvList.key(device);
|
||||
qDebug() << "remove LG Smart Tv " << tvDevice->modelName();
|
||||
m_tvList.remove(tvDevice);
|
||||
}
|
||||
|
||||
QString DevicePluginLgSmartTv::pluginName() const
|
||||
{
|
||||
return "Lg Smart Tv";
|
||||
return "LG Smart Tv";
|
||||
}
|
||||
|
||||
PluginId DevicePluginLgSmartTv::pluginId() const
|
||||
@ -123,10 +337,32 @@ void DevicePluginLgSmartTv::discoveryDone(QList<TvDevice*> tvList)
|
||||
params.append(Param("host address", device->hostAddress().toString()));
|
||||
params.append(Param("location", device->location().toString()));
|
||||
params.append(Param("manufacturer", device->manufacturer()));
|
||||
params.append(Param("key", device->key()));
|
||||
descriptor.setParams(params);
|
||||
deviceDescriptors.append(descriptor);
|
||||
}
|
||||
emit devicesDiscovered(lgSmartTvDeviceClassId, deviceDescriptors);
|
||||
}
|
||||
|
||||
void DevicePluginLgSmartTv::pairingFinished(const bool &success)
|
||||
{
|
||||
TvDevice *tvDevice = static_cast<TvDevice*>(sender());
|
||||
Device *device = m_tvList.value(tvDevice);
|
||||
|
||||
if(success){
|
||||
emit deviceSetupFinished(device,DeviceManager::DeviceSetupStatusSuccess,QString(""));
|
||||
}else{
|
||||
emit deviceSetupFinished(device,DeviceManager::DeviceSetupStatusFailure,QString("Could not pair with tv."));
|
||||
}
|
||||
}
|
||||
|
||||
void DevicePluginLgSmartTv::sendingCommandFinished(const bool &success, const ActionId &actionId)
|
||||
{
|
||||
if(success){
|
||||
emit actionExecutionFinished(actionId,DeviceManager::DeviceErrorNoError,QString());
|
||||
}else{
|
||||
emit actionExecutionFinished(actionId,DeviceManager::DeviceErrorActionTypeNotFound,QString("Could not send command"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -42,13 +42,19 @@ public:
|
||||
DeviceManager::HardwareResources requiredHardware() const override;
|
||||
QPair<DeviceManager::DeviceError, QString> executeAction(Device *device, const Action &action) override;
|
||||
|
||||
void deviceRemoved(Device *device) override;
|
||||
|
||||
QString pluginName() const override;
|
||||
PluginId pluginId() const override;
|
||||
|
||||
void guhTimer() override;
|
||||
|
||||
QHash<TvDevice*, Device*> m_tvList;
|
||||
|
||||
private slots:
|
||||
void discoveryDone(QList<TvDevice *> tvList);
|
||||
void pairingFinished(const bool &success);
|
||||
void sendingCommandFinished(const bool &success, const ActionId &actionId);
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
@ -5,8 +5,11 @@ TvDevice::TvDevice(QObject *parent) :
|
||||
{
|
||||
m_manager = new QNetworkAccessManager(this);
|
||||
|
||||
m_key = "539887";
|
||||
m_pairingStatus = false;
|
||||
m_reachable = false;
|
||||
|
||||
|
||||
connect(m_manager, &QNetworkAccessManager::finished, this, &TvDevice::replyFinished);
|
||||
}
|
||||
|
||||
void TvDevice::setLocation(const QUrl &location)
|
||||
@ -89,6 +92,16 @@ QString TvDevice::key() const
|
||||
return m_key;
|
||||
}
|
||||
|
||||
bool TvDevice::reachable() const
|
||||
{
|
||||
return m_reachable;
|
||||
}
|
||||
|
||||
bool TvDevice::paired() const
|
||||
{
|
||||
return m_pairingStatus;
|
||||
}
|
||||
|
||||
void TvDevice::showPairingKey()
|
||||
{
|
||||
qDebug() << "request show pairing key on screen...";
|
||||
@ -96,15 +109,114 @@ void TvDevice::showPairingKey()
|
||||
|
||||
QString urlString = "http://" + m_hostAddress.toString() + ":8080/udap/api/pairing";
|
||||
|
||||
QNetworkRequest pairingRequest;
|
||||
pairingRequest.setUrl(QUrl(urlString));
|
||||
pairingRequest.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("text/xml; charset=utf-8"));
|
||||
pairingRequest.setHeader(QNetworkRequest::UserAgentHeader,QVariant("UDAP/2.0"));
|
||||
QNetworkRequest request;
|
||||
request.setUrl(QUrl(urlString));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("text/xml; charset=utf-8"));
|
||||
request.setHeader(QNetworkRequest::UserAgentHeader,QVariant("UDAP/2.0 guh"));
|
||||
|
||||
QByteArray data = "<?xml version=\"1.0\" encoding=\"utf-8\"?><envelope><api type=\"pairing\"> <name>showKey</name></api></envelope>";
|
||||
|
||||
m_showKeyReplay = m_manager->post(pairingRequest,data);
|
||||
m_showKeyReplay = m_manager->post(request,data);
|
||||
}
|
||||
|
||||
void TvDevice::requestPairing()
|
||||
{
|
||||
if(m_key.isNull()){
|
||||
emit pairingFinished(false);
|
||||
}
|
||||
|
||||
QString urlString = "http://" + m_hostAddress.toString() +":8080/udap/api/pairing";
|
||||
|
||||
QNetworkRequest request;
|
||||
request.setUrl(QUrl(urlString));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("text/xml; charset=utf-8"));
|
||||
request.setHeader(QNetworkRequest::UserAgentHeader,QVariant("UDAP/2.0 guh"));
|
||||
|
||||
QByteArray data = "<?xml version=\"1.0\" encoding=\"utf-8\"?><envelope><api type=\"pairing\"><name>hello</name><value>" + m_key.toUtf8() + "</value><port>8080</port></api></envelope>";
|
||||
|
||||
m_requestPairingReplay = m_manager->post(request,data);
|
||||
}
|
||||
|
||||
void TvDevice::sendCommand(TvDevice::RemoteKey key, ActionId actionId)
|
||||
{
|
||||
m_actionId = actionId;
|
||||
|
||||
if(!m_pairingStatus){
|
||||
requestPairing();
|
||||
return;
|
||||
}
|
||||
|
||||
QString urlString = "http://" + m_hostAddress.toString() +":8080/udap/api/command";
|
||||
|
||||
QByteArray data;
|
||||
data.append("<?xml version=\"1.0\" encoding=\"utf-8\"?><envelope><api type=\"command\"><name>HandleKeyInput</name><value>");
|
||||
data.append(QString::number(key).toUtf8());
|
||||
data.append("</value></api></envelope>");
|
||||
|
||||
QNetworkRequest request;
|
||||
request.setUrl(QUrl(urlString));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("text/xml; charset=utf-8"));
|
||||
request.setHeader(QNetworkRequest::UserAgentHeader,QVariant("UDAP/2.0 guh"));
|
||||
|
||||
m_sendCommandReplay = m_manager->post(request,data);
|
||||
}
|
||||
|
||||
void TvDevice::finishingPairing()
|
||||
{
|
||||
QString urlString = "http://" + m_hostAddress.toString() +":8080/udap/api/pairing";
|
||||
|
||||
QNetworkRequest request;
|
||||
request.setUrl(QUrl(urlString));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("text/xml; charset=utf-8"));
|
||||
request.setHeader(QNetworkRequest::UserAgentHeader,QVariant("UDAP/2.0 guh"));
|
||||
|
||||
QByteArray data = "<?xml version=\"1.0\" encoding=\"utf-8\"?><envelope><api type=\"pairing\"><name>byebye</name><port>8080</port></api></envelope>";
|
||||
|
||||
m_finishingPairingReplay = m_manager->post(request,data);
|
||||
}
|
||||
|
||||
void TvDevice::replyFinished(QNetworkReply *reply)
|
||||
{
|
||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
|
||||
if(status != 200){
|
||||
m_reachable = false;
|
||||
}else{
|
||||
m_reachable = true;
|
||||
}
|
||||
|
||||
if(reply == m_showKeyReplay){
|
||||
if(status != 200){
|
||||
qWarning() << "ERROR: could not request to show pairing key on screen " << status;
|
||||
}
|
||||
}
|
||||
if(reply == m_requestPairingReplay){
|
||||
if(status != 200){
|
||||
m_pairingStatus = false;
|
||||
emit pairingFinished(false);
|
||||
qWarning() << "ERROR: could not pair with device" << status;
|
||||
}else{
|
||||
m_pairingStatus = true;
|
||||
qDebug() << "successfully paired with tv " << m_modelName;
|
||||
emit pairingFinished(true); }
|
||||
}
|
||||
|
||||
if(reply == m_finishingPairingReplay){
|
||||
if(status == 200){
|
||||
m_pairingStatus = false;
|
||||
qDebug() << "successfully unpaired from tv " << m_modelName;
|
||||
}
|
||||
}
|
||||
|
||||
if(reply == m_sendCommandReplay){
|
||||
if(status != 200){
|
||||
emit sendCommandFinished(false,m_actionId);
|
||||
qWarning() << "ERROR: could not send comand" << status;
|
||||
}else{
|
||||
m_pairingStatus = true;
|
||||
qDebug() << "successfully sent command to tv " << m_modelName;
|
||||
emit sendCommandFinished(true,m_actionId);
|
||||
}
|
||||
}
|
||||
emit statusChanged();
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include <QXmlStreamWriter>
|
||||
#include <QXmlStreamAttributes>
|
||||
|
||||
#include "plugin/deviceplugin.h"
|
||||
|
||||
class TvDevice : public QObject
|
||||
{
|
||||
@ -19,6 +20,75 @@ class TvDevice : public QObject
|
||||
public:
|
||||
explicit TvDevice(QObject *parent = 0);
|
||||
|
||||
enum RemoteKey{
|
||||
Power = 1,
|
||||
Num0 = 2,
|
||||
Num1 = 3,
|
||||
Num2 = 4,
|
||||
Num3 = 5,
|
||||
Num4 = 6,
|
||||
Num5 = 7,
|
||||
Num6 = 8,
|
||||
Num7 = 9,
|
||||
Num8 = 10,
|
||||
Num9 = 11,
|
||||
Up = 12,
|
||||
Down = 13,
|
||||
Left = 14,
|
||||
Right = 15,
|
||||
Ok = 20,
|
||||
Home = 21,
|
||||
Menu = 22,
|
||||
Back = 23,
|
||||
VolUp = 24,
|
||||
VolDown = 25,
|
||||
Mute = 26,
|
||||
ChannelUp = 27,
|
||||
ChannelDown = 28,
|
||||
Blue = 29,
|
||||
Green = 30,
|
||||
Red = 31,
|
||||
Yellow = 32,
|
||||
Play = 33,
|
||||
Pause = 34,
|
||||
Stop = 35,
|
||||
FastForward = 36,
|
||||
Rewind = 37,
|
||||
SkipForward = 38,
|
||||
SkipBackward = 39,
|
||||
Record = 40,
|
||||
RecrodList = 41,
|
||||
Repeat = 42,
|
||||
LiveTv = 43,
|
||||
EPG = 44,
|
||||
Info = 45,
|
||||
AspectRatio = 46,
|
||||
ExternalInput = 47,
|
||||
PIP = 48,
|
||||
ChangeSub = 49,
|
||||
ProgramList = 50,
|
||||
TeleText = 51,
|
||||
Mark = 52,
|
||||
Video3D = 400,
|
||||
LR_3D = 401,
|
||||
Dash = 402,
|
||||
PrevoiusChannel = 403,
|
||||
FavouritChannel = 404,
|
||||
QuickMenu = 405,
|
||||
TextOption = 406,
|
||||
AudioDescription= 407,
|
||||
NetCastKey = 408,
|
||||
EnergySaving = 409,
|
||||
AV_Mode = 410,
|
||||
SimpLink = 411,
|
||||
Exit = 412,
|
||||
ReservationList = 413,
|
||||
PipUp = 414,
|
||||
PipDown = 415,
|
||||
SwitchVideo = 416,
|
||||
MyApps = 417
|
||||
};
|
||||
|
||||
void setLocation(const QUrl &location);
|
||||
QUrl location() const;
|
||||
|
||||
@ -43,9 +113,12 @@ public:
|
||||
void setKey(const QString &key);
|
||||
QString key() const;
|
||||
|
||||
bool reachable() const;
|
||||
bool paired() const;
|
||||
|
||||
void showPairingKey();
|
||||
|
||||
|
||||
void requestPairing();
|
||||
void sendCommand(TvDevice::RemoteKey key, ActionId actionId);
|
||||
|
||||
private:
|
||||
QUrl m_location;
|
||||
@ -57,12 +130,26 @@ private:
|
||||
QString m_uuid;
|
||||
QString m_key;
|
||||
bool m_pairingStatus;
|
||||
bool m_reachable;
|
||||
|
||||
ActionId m_actionId;
|
||||
|
||||
QNetworkAccessManager *m_manager;
|
||||
QNetworkReply *m_showKeyReplay;
|
||||
QNetworkReply *m_requestPairingReplay;
|
||||
QNetworkReply *m_finishingPairingReplay;
|
||||
QNetworkReply *m_sendCommandReplay;
|
||||
|
||||
void finishingPairing();
|
||||
|
||||
signals:
|
||||
void pairingFinished(const bool &success);
|
||||
void statusChanged();
|
||||
void sendCommandFinished(const bool &succeeded, const ActionId &actionId);
|
||||
|
||||
private slots:
|
||||
void replyFinished(QNetworkReply *reply);
|
||||
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
@ -256,13 +256,12 @@ void TvDiscovery::parseDeviceInformation(QByteArray data)
|
||||
void TvDiscovery::discover(int timeout)
|
||||
{
|
||||
QString searchMessage("M-SEARCH * HTTP/1.1\r\n"
|
||||
"HOST: 239.255.255.250:1900\r\n"
|
||||
"MAN: \"ssdp:discover\"\r\n"
|
||||
"MX: 3\r\n"
|
||||
"ST: udap:rootservice\r\n"
|
||||
"HOST:239.255.255.250:1900\r\n"
|
||||
"MAN:\"ssdp:discover\"\r\n"
|
||||
"MX:2\r\n"
|
||||
"ST:udap:rootservice\r\n"
|
||||
"USER-AGENT: UDAP/2.0 \r\n\r\n");
|
||||
|
||||
|
||||
m_tvList.clear();
|
||||
writeDatagram(searchMessage.toUtf8(),m_host,m_port);
|
||||
m_timeout->start(timeout);
|
||||
|
||||
Reference in New Issue
Block a user