mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-10-31 13:00:26 -04:00 
			
		
		
		
	Server: Web API: implemented /sdrangel/deviceset/{deviceSetIndex}/channel POST with bugs
This commit is contained in:
		
							parent
							
								
									e444a17fe5
								
							
						
					
					
						commit
						d4ca83ff61
					
				| @ -199,3 +199,21 @@ void PluginManager::createTxChannelInstance(int channelPluginIndex, DeviceUISet | ||||
|         pluginInterface->createTxChannelGUI(m_txChannelRegistrations[channelPluginIndex].m_channelIdURI, deviceUISet, txChannel); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void PluginManager::createRxChannelServerInstance(int channelPluginIndex, DeviceSourceAPI *deviceAPI) | ||||
| { | ||||
|     if (channelPluginIndex < m_rxChannelRegistrations.size()) | ||||
|     { | ||||
|         PluginInterface *pluginInterface = m_rxChannelRegistrations[channelPluginIndex].m_plugin; | ||||
|         pluginInterface->createRxChannel(m_rxChannelRegistrations[channelPluginIndex].m_channelIdURI, deviceAPI); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void PluginManager::createTxChannelServerInstance(int channelPluginIndex, DeviceSinkAPI *deviceAPI) | ||||
| { | ||||
|     if (channelPluginIndex < m_txChannelRegistrations.size()) | ||||
|     { | ||||
|         PluginInterface *pluginInterface = m_txChannelRegistrations[channelPluginIndex].m_plugin; | ||||
|         pluginInterface->createTxChannel(m_txChannelRegistrations[channelPluginIndex].m_channelIdURI, deviceAPI); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -57,9 +57,11 @@ public: | ||||
| 	PluginAPI::ChannelRegistrations *getTxChannelRegistrations() { return &m_txChannelRegistrations; } | ||||
| 
 | ||||
|     void createRxChannelInstance(int channelPluginIndex, DeviceUISet *deviceUISet, DeviceSourceAPI *deviceAPI); | ||||
|     void createRxChannelServerInstance(int channelPluginIndex, DeviceSourceAPI *deviceAPI); | ||||
|     void listRxChannels(QList<QString>& list); | ||||
| 
 | ||||
| 	void createTxChannelInstance(int channelPluginIndex, DeviceUISet *deviceUISet, DeviceSinkAPI *deviceAPI); | ||||
| 	void createTxChannelServerInstance(int channelPluginIndex, DeviceSinkAPI *deviceAPI); | ||||
| 	void listTxChannels(QList<QString>& list); | ||||
| 
 | ||||
| 	static const QString& getFileSourceDeviceId() { return m_fileSourceDeviceTypeID; } | ||||
|  | ||||
| @ -41,6 +41,7 @@ MESSAGE_CLASS_DEFINITION(MainCore::MsgDeletePreset, Message) | ||||
| MESSAGE_CLASS_DEFINITION(MainCore::MsgAddDeviceSet, Message) | ||||
| MESSAGE_CLASS_DEFINITION(MainCore::MsgRemoveLastDeviceSet, Message) | ||||
| MESSAGE_CLASS_DEFINITION(MainCore::MsgSetDevice, Message) | ||||
| MESSAGE_CLASS_DEFINITION(MainCore::MsgAddChannel, Message) | ||||
| 
 | ||||
| MainCore *MainCore::m_instance = 0; | ||||
| 
 | ||||
| @ -154,6 +155,13 @@ bool MainCore::handleMessage(const Message& cmd) | ||||
| 
 | ||||
|         return true; | ||||
|     } | ||||
|     else if (MsgAddChannel::match(cmd)) | ||||
|     { | ||||
|         MsgAddChannel& notif = (MsgAddChannel&) cmd; | ||||
|         addChannel(notif.getDeviceSetIndex(), notif.getChannelRegistrationIndex()); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     else | ||||
|     { | ||||
|         return false; | ||||
| @ -460,6 +468,23 @@ void MainCore::changeSampleSink(int deviceSetIndex, int selectedDeviceIndex) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void MainCore::addChannel(int deviceSetIndex, int selectedChannelIndex) | ||||
| { | ||||
|     if (deviceSetIndex >= 0) | ||||
|     { | ||||
|         DeviceSet *deviceSet = m_deviceSets[deviceSetIndex]; | ||||
| 
 | ||||
|         if (deviceSet->m_deviceSourceEngine) // source device => Rx channels
 | ||||
|         { | ||||
|             m_pluginManager->createRxChannelServerInstance(selectedChannelIndex, deviceSet->m_deviceSourceAPI); | ||||
|         } | ||||
|         else if (deviceSet->m_deviceSinkEngine) // sink device => Tx channels
 | ||||
|         { | ||||
|             m_pluginManager->createTxChannelServerInstance(selectedChannelIndex, deviceSet->m_deviceSinkAPI); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void MainCore::loadPresetSettings(const Preset* preset, int tabIndex) | ||||
| { | ||||
| 	qDebug("MainCore::loadPresetSettings: preset [%s | %s]", | ||||
|  | ||||
| @ -65,6 +65,7 @@ public: | ||||
|     void removeLastDevice(); | ||||
|     void changeSampleSource(int deviceSetIndex, int selectedDeviceIndex); | ||||
|     void changeSampleSink(int deviceSetIndex, int selectedDeviceIndex); | ||||
|     void addChannel(int deviceSetIndex, int selectedChannelIndex); | ||||
| 
 | ||||
|     friend class WebAPIAdapterSrv; | ||||
| 
 | ||||
| @ -217,6 +218,32 @@ private: | ||||
|         { } | ||||
|     }; | ||||
| 
 | ||||
|     class MsgAddChannel : public Message { | ||||
|         MESSAGE_CLASS_DECLARATION | ||||
| 
 | ||||
|     public: | ||||
|         int getDeviceSetIndex() const { return m_deviceSetIndex; } | ||||
|         int getChannelRegistrationIndex() const { return m_channelRegistrationIndex; } | ||||
|         bool isTx() const { return m_tx; } | ||||
| 
 | ||||
|         static MsgAddChannel* create(int deviceSetIndex, int channelRegistrationIndex, bool tx) | ||||
|         { | ||||
|             return new MsgAddChannel(deviceSetIndex, channelRegistrationIndex, tx); | ||||
|         } | ||||
| 
 | ||||
|     private: | ||||
|         int m_deviceSetIndex; | ||||
|         int m_channelRegistrationIndex; | ||||
|         bool m_tx; | ||||
| 
 | ||||
|         MsgAddChannel(int deviceSetIndex, int channelRegistrationIndex, bool tx) : | ||||
|             Message(), | ||||
|             m_deviceSetIndex(deviceSetIndex), | ||||
|             m_channelRegistrationIndex(channelRegistrationIndex), | ||||
|             m_tx(tx) | ||||
|         { } | ||||
|     }; | ||||
| 
 | ||||
|     static MainCore *m_instance; | ||||
|     MainSettings m_settings; | ||||
|     int m_masterTabIndex; | ||||
|  | ||||
| @ -35,6 +35,7 @@ | ||||
| #include "SWGPresets.h" | ||||
| #include "SWGPresetTransfer.h" | ||||
| #include "SWGDeviceSettings.h" | ||||
| #include "SWGChannelSettings.h" | ||||
| #include "SWGSuccessResponse.h" | ||||
| #include "SWGErrorResponse.h" | ||||
| 
 | ||||
| @ -923,6 +924,97 @@ int WebAPIAdapterSrv::devicesetDeviceSettingsPutPatch( | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| int WebAPIAdapterSrv::devicesetChannelPost( | ||||
|             int deviceSetIndex, | ||||
|             SWGSDRangel::SWGChannelSettings& query, | ||||
| 			SWGSDRangel::SWGSuccessResponse& response, | ||||
|             SWGSDRangel::SWGErrorResponse& error) | ||||
| { | ||||
|     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size())) | ||||
|     { | ||||
|         DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex]; | ||||
| 
 | ||||
|         if (query.getTx() == 0) // Rx
 | ||||
|         { | ||||
|             if (deviceSet->m_deviceSourceEngine == 0) | ||||
|             { | ||||
|                 error.init(); | ||||
|                 *error.getMessage() = QString("Device set at %1 is not a receive device set").arg(deviceSetIndex); | ||||
|                 return 400; | ||||
|             } | ||||
| 
 | ||||
|             PluginAPI::ChannelRegistrations *channelRegistrations = m_mainCore.m_pluginManager->getRxChannelRegistrations(); | ||||
|             int nbRegistrations = channelRegistrations->size(); | ||||
|             int index = 0; | ||||
|             for (; index < nbRegistrations; index++) | ||||
|             { | ||||
|                 if (channelRegistrations->at(index).m_channelId == *query.getChannelType()) { | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             if (index < nbRegistrations) | ||||
|             { | ||||
|                 MainCore::MsgAddChannel *msg = MainCore::MsgAddChannel::create(deviceSetIndex, index, false); | ||||
|                 m_mainCore.m_inputMessageQueue.push(msg); | ||||
| 
 | ||||
|                 response.init(); | ||||
|                 *response.getMessage() = QString("Message to add a channel (MsgAddChannel) was submitted successfully"); | ||||
| 
 | ||||
|                 return 202; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 error.init(); | ||||
|                 *error.getMessage() = QString("There is no receive channel with id %1").arg(*query.getChannelType()); | ||||
|                 return 404; | ||||
|             } | ||||
|         } | ||||
|         else // Tx
 | ||||
|         { | ||||
|             if (deviceSet->m_deviceSinkEngine == 0) | ||||
|             { | ||||
|                 error.init(); | ||||
|                 *error.getMessage() = QString("Device set at %1 is not a transmit device set").arg(deviceSetIndex); | ||||
|                 return 400; | ||||
|             } | ||||
| 
 | ||||
|             PluginAPI::ChannelRegistrations *channelRegistrations = m_mainCore.m_pluginManager->getTxChannelRegistrations(); | ||||
|             int nbRegistrations = channelRegistrations->size(); | ||||
|             int index = 0; | ||||
|             for (; index < nbRegistrations; index++) | ||||
|             { | ||||
|                 if (channelRegistrations->at(index).m_channelId == *query.getChannelType()) { | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             if (index < nbRegistrations) | ||||
|             { | ||||
|             	MainCore::MsgAddChannel *msg = MainCore::MsgAddChannel::create(deviceSetIndex, index, true); | ||||
|                 m_mainCore.m_inputMessageQueue.push(msg); | ||||
| 
 | ||||
|                 response.init(); | ||||
|                 *response.getMessage() = QString("Message to add a channel (MsgAddChannel) was submitted successfully"); | ||||
| 
 | ||||
|                 return 202; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 error.init(); | ||||
|                 *error.getMessage() = QString("There is no transmit channel with id %1").arg(*query.getChannelType()); | ||||
|                 return 404; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         error.init(); | ||||
|         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | ||||
|         return 404; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void WebAPIAdapterSrv::getDeviceSetList(SWGSDRangel::SWGDeviceSetList* deviceSetList) | ||||
| { | ||||
|     deviceSetList->init(); | ||||
|  | ||||
| @ -146,6 +146,12 @@ public: | ||||
|             SWGSDRangel::SWGDeviceSettings& response, | ||||
|             SWGSDRangel::SWGErrorResponse& error); | ||||
| 
 | ||||
|     virtual int devicesetChannelPost( | ||||
|             int deviceSetIndex, | ||||
|             SWGSDRangel::SWGChannelSettings& query, | ||||
| 			SWGSDRangel::SWGSuccessResponse& response, | ||||
|             SWGSDRangel::SWGErrorResponse& error); | ||||
| 
 | ||||
| private: | ||||
|     MainCore& m_mainCore; | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user