#include "CSFIntferfaceObject.h"
#include "CSFPointMapping.h"
#include "RtdbAccess.h"
typedef ICSFUnknown * (PGETCSFUNKNOWN)();
CCSFIntferfaceObject::CCSFIntferfaceObject() : m_lib("appinter")
{
}
CCSFIntferfaceObject::~CCSFIntferfaceObject()
{
}
CCSFIntferfaceObject* CCSFIntferfaceObject::instance()
{
static CCSFIntferfaceObject* g_CSFObject = NULL;
if (g_CSFObject == NULL)
{
g_CSFObject = new CCSFIntferfaceObject();
g_CSFObject->Initialize();
}
return g_CSFObject;
}
bool CCSFIntferfaceObject::GetAppInter()
{
bool bRet = false;
PGETCSFUNKNOWN * pGetCSFUnknown = (PGETCSFUNKNOWN *)m_lib.resolve("GetCSFUnknown");
if(pGetCSFUnknown)
{
ICSFUnknown* pICSFUnknown = pGetCSFUnknown();
if(pICSFUnknown)
{
pICSFUnknown->QueryInterface("ICSF_APP_Interface",(void**)&m_pAppinterface);
if (m_pAppinterface)
{
bRet = true;
}
}
}
return bRet;
}
bool CCSFIntferfaceObject::Initialize()
{
bool bRet = false;
if (GetAppInter())
{
if (m_pAppinterface)
{
if (m_pAppinterface->Initialize(BUS_APPID) !=0)
{
return false;
}
m_pAppinterface->Advise(this);
bRet = true;
m_pAppinterface->SetAppWorkState(1);
}
}
return bRet;
}
void CCSFIntferfaceObject::LoginReturn(CSF_UINT8 nNode, CSF_UINT8 nProt, CSF_UINT8 nState)
{
}
void CCSFIntferfaceObject::SrcStateChanged(CSF_UINT32 nSrcId, CSF_UINT32 nCSFId, CSF_UINT32 nDpId, CSF_BOOLEAN bState)
{
}
CSF_INT32 CCSFIntferfaceObject::SubscriptionAck(CSF_UINT32 nSubscbID, CSF_UINT32 nApp, \
CSF_UINT32 nSrc, CCSFList<CSF_UCHAR>* pDOTypeList)
{
return 0;
}
CSF_INT32 CCSFIntferfaceObject::Issuance(CSF_UINT32 nIssueID, CSF_BOOLEAN bNeedAck, CSF_UINT32 nTimeout, \
CCSFTransBlock* pTransBlock)
{
return 0;
}
CSF_INT32 CCSFIntferfaceObject::GetReturn(CSF_BOOLEAN bRealData, CSF_UINT32 nResult,\
CSF_UINT32 nTimeout, CCSFTransBlock* pTransBlock)
{
int src = pTransBlock->m_nSrc;
OnStdSettingReturn(pTransBlock, nResult);
return 0;
}
int GetSettingCount(CCSFTransBlock* pTransBlock)
{
int count = 0;
CCSFList_Iterator<CCSF_Data> iter(&pTransBlock->m_DataObjList);
CCSF_Data* pData = iter.Do();
while (pData)
{
CSF_INT8 type = pData->GetType();
if (type == CSF_OBJTYPE_ISETTING || type == CSF_OBJTYPE_ASETTING)
{
count++;
}
++iter;
pData = iter.Do();
}
return count;
}
void GetSettingValues(CCSFTransBlock* pTransBlock, int* ids, double* values, int size)
{
int src = pTransBlock->m_nSrc;
CCSFList_Iterator<CCSF_Data> iter(&pTransBlock->m_DataObjList);
CCSF_Data* pData = iter.Do();
int index = 0;
CCSFPointMapping* pPointMap = CCSFPointMapping::instance();
while (pData && index < size)
{
CSF_INT8 type = pData->GetType();
if (type == CSF_OBJTYPE_ISETTING)
{
CCSF_SDO_ISetting* pISetting = (CCSF_SDO_ISetting*)pData;
MAPPINGPOINT* pPoint = pPointMap->FindSettingPointByCommSrc(src, pData->m_nAppId);
if (pPoint)
{
ids[index] = pPoint->m_iSCADAID;
values[index] = pISetting->m_nISValue;
}
index++;
}
else if (pData->GetType() == CSF_OBJTYPE_ASETTING)
{
pData->m_nAppId;
CCSF_SDO_ASetting* pASetting = (CCSF_SDO_ASetting*)pData;
MAPPINGPOINT* pPoint = pPointMap->FindSettingPointByCommSrc(src, pData->m_nAppId);
if (pPoint)
{
ids[index] = pPoint->m_iSCADAID;
values[index] = pASetting->m_fASValue;
}
index++;
}
++iter;
pData = iter.Do();
}
}
CSF_INT32 CCSFIntferfaceObject::SetReturn(CSF_UINT32 nResult, CSF_UINT32 nSetType, \
CSF_UINT32 nTimeout, CCSFTransBlock* pTransBlock)
{
int src = pTransBlock->m_nSrc;
switch (nSetType)
{
case CSF_SET_TYPE_PRESETSETTING: //预装定值返回
{
int count = GetSettingCount(pTransBlock);
if (count > 0)
{
int *ids = new int[count];
double* values = new double[count];
GetSettingValues(pTransBlock, ids, values, count);
OnModifySettingSel(src, 0, count, ids, values, (nResult == 0));
delete []ids;
delete []values;
}
}
break;
case CSF_SET_TYPE_SAVESETTING: //固化定值返回
OnModifySettingExe(src, 0, (nResult == 0));
break;
case CSF_SET_TYPE_CANCELSETTING: //取消预装返回
break;
case CSF_SET_TYPE_PRESETCALL: //预装召唤返回
OnCallSettingSel(src, 0, (nResult == 0));
break;
case CSF_SET_TYPE_SENDCALL: //下发召唤返回
{
int count = GetSettingCount(pTransBlock);
if (count > 0)
{
int *ids = new int[count];
double* values = new double[count];
GetSettingValues(pTransBlock, ids, values, count);
OnCallSettingExe(src, 0, count, ids, values, (nResult == 0));
delete []ids;
delete []values;
}
}
break;
case CSF_SET_TYPE_CANCELCALL: //取消召唤返回
break;
case CSF_SET_TYPE_SELECT:
case CSF_SET_TYPE_OPERATE:
case CSF_SET_TYPE_CANCEL:
{
CCSFList_Iterator<CCSF_Data> iter(&pTransBlock->m_DataObjList);
CCSF_Data* pData = iter.Do();
while (pData)
{
CSF_INT8 type = pData->GetType();
switch (type)
{
case CSF_OBJTYPE_ICONTROL:
{
CCSF_SDO_IControl* pIControl = (CCSF_SDO_IControl*)pData;
OnIControlReturn(src, pIControl, nSetType, nResult);
}
break;
case CSF_OBJTYPE_ACONTROL:
{
CCSF_SDO_AControl* pAControl = (CCSF_SDO_AControl*)pData;
OnAControlReurn(src, pAControl, nSetType, nResult);
}
break;
}
++iter;
pData = iter.Do();
}
}
break;
case CSF_SET_TYPE_SETPULSEPRICE: //设置电价返回
SetElecPriceReturn( pTransBlock, (nResult == 0) );
break;
case CSF_SET_TYPE_BATMTSETTING: //电池维护命令返回
OnBatMtCmdReturn(pTransBlock, nSetType, nResult);
break;
}
return 0;
}
void CCSFIntferfaceObject::OnIControlReturn(int src, CCSF_SDO_IControl* pIControl, CSF_UINT32 nSetType, CSF_UINT32 nResult)
{
CTRLPOINT* pPoint = CCSFPointMapping::instance()->FindControlPointByCommSrc(src, pIControl->m_nAppId);
if (pPoint)
{
int val = pIControl->m_nICValue;
double dt = pIControl->m_dTimeStamp;
switch (nSetType)
{
case CSF_SET_TYPE_SELECT:
OnICtrlSelectReturn(pPoint->m_iSCADAID, val, nResult == 0, dt);
break;
case CSF_SET_TYPE_OPERATE:
OnICtrlExecuteReturn(pPoint->m_iSCADAID, val, nResult == 0, dt);
break;
case CSF_SET_TYPE_CANCEL:
OnICtrlCancelReturn(pPoint->m_iSCADAID, val, nResult == 0, dt);
break;
}
}
}
void CCSFIntferfaceObject::OnAControlReurn( int src, CCSF_SDO_AControl* pAControl, CSF_UINT32 nSetType, CSF_UINT32 nResult )
{
CTRLPOINT* pPoint = CCSFPointMapping::instance()->FindControlPointByCommSrc(src, pAControl->m_nAppId);
if (pPoint)
{
double val = pAControl->m_fValue;
double dt = pAControl->m_dTimeStamp;
switch (nSetType)
{
case CSF_SET_TYPE_SELECT:
OnACtrlSelectReturn(pPoint->m_iSCADAID, val, nResult == 0, dt);
break;
case CSF_SET_TYPE_OPERATE:
OnACtrlExecuteReturn(pPoint->m_iSCADAID, val, nResult == 0, dt);
break;
case CSF_SET_TYPE_CANCEL:
OnACtrlCancelReturn(pPoint->m_iSCADAID, val, nResult == 0, dt);
break;
}
}
}
void CCSFIntferfaceObject::GetModeReturn(CSF_UINT8 nMode, CSF_UINT32 nNode,\
CSF_UINT32 nProt, CSF_UINT32 m_nApp)
{
}
void CCSFIntferfaceObject::ClearConfigReturn(CSF_UINT32 nResult, CSF_UINT32 nNode, \
CSF_UINT32 nProt, CSF_UINT32 nApp)
{
}
void CCSFIntferfaceObject::AddSrcReturn(CSF_UINT32 nResult)
{
}
void CCSFIntferfaceObject::DelSrcReturn(CSF_UINT32 nResult)
{
}
void CCSFIntferfaceObject::AddSrcChnlReturn(CSF_UINT32 nResult)
{
}
void CCSFIntferfaceObject::DelSrcChnlReturn(CSF_UINT32 nResult)
{
}
void CCSFIntferfaceObject::AddObjReturn(CSF_UINT32 nResult, CSF_UINT32 nNode,\
CSF_UINT32 nProt, CSF_UINT32 nApp)
{
}
void CCSFIntferfaceObject::Se