123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- #include "StdAfx.h"
- #include "PacketAnalizer.h"
- #include "WheelClient.h"
- WheelUnitLogicClient::WheelUnitLogicClient(void)
- {
- pLogicDeivce = (LogicDevice*)this;
- }
- WheelUnitLogicClient::~WheelUnitLogicClient(void)
- {
- }
- WheelUnitLogicClient& WheelUnitLogicClient::operator = (WheelUnitLogicClient &tValue)
- {
- //strongly recommended do not assign a client to another one
- if (this != &tValue)
- {
- m_FileFlags = tValue.m_FileFlags;
- (*m_pFilePath) = (*(tValue.m_pFilePath));
- //do open
- if (tValue.IsClosed() == false)
- {
- if (Open((tValue.m_pFilePath)->c_str(), (CCOS_FILE_FLAGS)tValue.m_FileFlags) <= 0)
- {
- //failed here
- //put some log
- printf("Thread:%d,Open Failed\n", GetCurrentThreadId());
- }
- }
- }
- return (*this);
- }
- RET_STATUS SYSTEM_CALL WheelUnitLogicClient::GetDeviceResource(ResDataObject PARAM_OUT *pDeviceResource)
- {
- if (IsClosed())
- {
- return RET_FAILED;
- }
- return ((LogicClient*)this)->GetDeviceResource(pDeviceResource);
- }
- int WheelUnitLogicClient::Open(const char *pPath, int flags, DWORD timeout)
- {
- RET_STATUS ret = (RET_STATUS)LogicClient::Open(pPath, flags, timeout);
- if (ret == RET_SUCCEED)
- {
- //need update local data!!!!
- bool sRet = true;
- ResDataObject Attribute;
- ResDataObject Temp;
- sRet &= TryGetValue(m_DeviceResource, "Attribute", Attribute);
- if (sRet)
- {
- sRet &= TryGetValue(Attribute, "WHELLSTATUS", Temp);
- if (sRet)
- {
- ret = (RET_STATUS)WheelUnitLogic::SetStatus((bool)Temp);
- }
- else
- {
- ret = RET_FAILED;
- }
- if (ret != RET_SUCCEED)
- {
- LogicClient::Close();
- }
- }
- sRet &= TryGetValue(m_DeviceResource, "Action", Attribute);
- }
- return ret;
- }
- //ResourceCommand Request In and Response Out
- RET_STATUS SYSTEM_CALL WheelUnitLogicClient::Request(ResDataObject PARAM_IN *pRequest, ResDataObject PARAM_OUT *pResponse)
- {
- //do nothing
- return RET_NOSUPPORT;
- }
- //notify to lower layer
- RET_STATUS SYSTEM_CALL WheelUnitLogicClient::CmdToLogicDev(ResDataObject PARAM_IN *pCmd)
- {
- //response and notify comes here
- PacketArrived(pCmd);
- return RET_SUCCEED;
- }
- PACKET_CMD WheelUnitLogicClient::ReadCmd(ResDataObject &CmdObject)
- {
- PACKET_CMD ret = PACKET_CMD_NONE;
- while (IsDataArrived())
- {
- ret = LogicClient::ReadCmd(CmdObject);
- if (ret == PACKET_CMD_UPDATE)
- {
- //only one update
- string key = PacketAnalizer::GetPacketKey(&CmdObject);
- assert(key == "WHELLSTATUS");
- ResDataObject Context;
- if (PacketAnalizer::GetPacketContext(&CmdObject, Context))
- {
- WheelUnitLogic::SetStatus((bool)Context);
- }
- return ret;
- }
- else if (ret != PACKET_CMD_NONE)
- {
- return ret;
- }
- }
- return ret;
- }
- //resource
- // DeviceType:GUID
- // attribute:{WHELLSTATUS:0}
- // action:StartRoll
- // action:StopRoll
- //Data Access
- int DATA_ACTION WheelUnitLogicClient::GetStatus(bool PARAM_OUT &status)
- {
- //use the request
- if (Support_GetStatus())
- {
- //pack get status
- ResDataObject req, res;
- RET_STATUS ret = (RET_STATUS)Action("GetStatus", req, res);
- if (ret == RET_SUCCEED && GetRequestSyncMode() == ACTION_SYNC)
- {
- try {
- status = res["P0"];
- }
- //catch (ResDataObjectExption &exp)
- //{
- // //exp.what();
- //}
- catch (...)
- {
- //exp
- }
- }
- return ret;
- }
- return RET_NOSUPPORT;
- }
- int DATA_ACTION WheelUnitLogicClient::SetStatus(bool PARAM_IN status)
- {
- //use the request
- if (Support_SetStatus())
- {
- //pack set status
- ResDataObject req, res;
- //put params here
- req.add("P0", status);
- //exec action here
- return (RET_STATUS)Action("SetStatus", req, res);
- }
- return RET_NOSUPPORT;
- }
- //Actions
- int DEVICE_ACTION WheelUnitLogicClient::StartRoll()
- {
- //use the request
- if (Support_StartRoll())
- {
- //pack set status
- ResDataObject req, res;
- //put params here
- //exec action here
- return Action("StartRoll", req, res);
- }
- return RET_NOSUPPORT;
- }
- int DEVICE_ACTION WheelUnitLogicClient::StopRoll()
- {
- //use the request
- if (Support_StopRoll())
- {
- //pack set status
- ResDataObject req, res;
- //put params here
- //exec action here
- return Action("StopRoll", req, res);
- }
- return RET_NOSUPPORT;
- }
- bool DEVICE_SUPPORT WheelUnitLogicClient::Support_GetStatus()
- {
- //use the resource of LogicDevice
- try{
- int idx = m_DeviceResource.GetFirstOf("Action");
- if (idx >= 0)
- {
- idx = m_DeviceResource[idx].GetFirstOf("GetStatus");
- return (idx >= 0);
- }
- }
- //catch (ResDataObjectExption &exp)
- //{
- // //log here
- // //exp.what();
- //}
- catch (...)
- {
- //log here
- }
- return false;
- }
- bool DEVICE_SUPPORT WheelUnitLogicClient::Support_SetStatus()
- {
- //use the resource of LogicDevice
- try{
- int idx = m_DeviceResource.GetFirstOf("Action");
- if (idx >= 0)
- {
- idx = m_DeviceResource[idx].GetFirstOf("SetStatus");
- return (idx >= 0);
- }
- }
- //catch (ResDataObjectExption &exp)
- //{
- // //log here
- // //exp.what();
- //}
- catch (...)
- {
- //log here
- }
- return false;
- }
- bool DEVICE_SUPPORT WheelUnitLogicClient::Support_StartRoll()
- {
- //use the resource of LogicDevice
- try{
- int idx = m_DeviceResource.GetFirstOf("Action");
- if (idx >= 0)
- {
- idx = m_DeviceResource[idx].GetFirstOf("StartRoll");
- return (idx >= 0);
- }
- }
- //catch (ResDataObjectExption &exp)
- //{
- // //log here
- // //exp.what();
- //}
- catch (...)
- {
- //log here
- }
- return false;
- }
- bool DEVICE_SUPPORT WheelUnitLogicClient::Support_StopRoll()
- {
- //use the resource of LogicDevice
- try{
- int idx = m_DeviceResource.GetFirstOf("Action");
- if (idx >= 0)
- {
- idx = m_DeviceResource[idx].GetFirstOf("StopRoll");
- return (idx >= 0);
- }
- }
- //catch (ResDataObjectExption &exp)
- //{
- // //log here
- // //exp.what();
- //}
- catch (...)
- {
- //log here
- }
- return false;
- }
- int SYSTEM_CALL WheelUnitLogicClient::GetLocalStatus(bool PARAM_OUT &status)
- {
- return WheelUnitLogic::GetStatus(status);
- }
|