Information
We are currently investigating an issue with the editor of some pages. Please save your work and avoid to create new pages until this banner is gone.
In this section we will modify our smart bulb ACS component in order to make it BACI compliant. BACI is a control interface specification we use for ACS at ALMA. For more details this document is available. There is also another useful tutorial here. BACI is only available for C++ components.
From these different sources we can take some guidelines:
When we are defining actions, we must write its arguments and what it returns. Every asynchronous action must have "in ACS::CBvoid cb, in ACS:CBDescIn desc". Note that beside arguments there is also a word "in". Here is short explanation of all possibilities (from Advance CORBA programming with C++):
So, in short:
To make our component a BACI compliant code, we must perform the following modifications:
working_dir: /home/francisco/workspace prefix: ACSIOT module: acsiot component_name: TuyaBulbBaci functions: - 'void turnOn()' - 'void turnOff()' properties: - 'readonly attribute ACS::ROboolean status'
#ifndef _TUYABULBBACI_IDL_ #define _TUYABULBBACI_IDL_ #pragma prefix "ACSIOT" #include <baci.idl> module acsiot { interface TuyaBulbBaci : ACS::CharacteristicComponent { void turnOn(); void turnOff(); readonly attribute ACS::ROboolean status; }; }; #endif
#ifndef _TUYABULBBACI_IMPL_H #define _TUYABULBBACI_IMPL_H #ifndef __cplusplus #error This is a C++ include file and cannot be used from plain C #endif // Base component implementation, including container services and component lifecycle infrastructure #include <baciCharacteristicComponentImpl.h> #include <baciROboolean.h> // Skeleton interface for server implementation #include <TuyaBulbBaciS.h> // Error definitions for catching and raising exceptions class TuyaBulbBaciImpl : public virtual baci::CharacteristicComponentImpl, public virtual POA_acsiot::TuyaBulbBaci { public: TuyaBulbBaciImpl(const ACE_CString& name, maci::ContainerServices* containerServices); virtual ~TuyaBulbBaciImpl(); void turnOn(); void turnOff(); virtual ACS::ROboolean_ptr status(); private: const char* api_region; const char* api_key; const char* api_secret; const char* device_id; baci::ROboolean* status_p; }; #endif
#include <TuyaBulbBaciImpl.h> #include <stdexcept> TuyaBulbBaciImpl::TuyaBulbBaciImpl(const ACE_CString& name, maci::ContainerServices* containerServices) : CharacteristicComponentImpl(name, containerServices) { cout << "Constructing TuyaBulbBaciImpl object." << endl; this->api_region = "us"; this->api_key = "..."; this->api_secret = "..."; this->device_id = "..."; } TuyaBulbBaciImpl::~TuyaBulbBaciImpl() { } void TuyaBulbBaciImpl::turnOn() { cout << "Turning smart bulb ON..." << endl; cout << "API Region: " << this->api_region << endl; cout << "API Key: " << this->api_key << endl; cout << "API Secret: " << this->api_secret << endl; cout << "Device ID: " << this->device_id << endl; cout << "Done." << endl; } void TuyaBulbBaciImpl::turnOff() { cout << "Turning smart bulb OFF..." << endl; cout << "API Region: " << this->api_region << endl; cout << "API Key: " << this->api_key << endl; cout << "API Secret: " << this->api_secret << endl; cout << "Device ID: " << this->device_id << endl; cout << "Done." << endl; } ACS::ROboolean_ptr TuyaBulbBaciImpl::status () { cout << "Returning smart bulb status" << endl; return ACS::ROboolean::_nil(); } /* --------------- [ MACI DLL support functions ] -----------------*/ #include <maciACSComponentDefines.h> MACI_DLL_SUPPORT_FUNCTIONS(TuyaBulbBaciImpl) /* ----------------------------------------------------------------*/
from Acspy.Clients.SimpleClient import PySimpleClient client = PySimpleClient() bulb_comp = client.getComponent("TuyaBulbBaciCPP") bulb_comp.turnOn() bulb_comp.turnOff()