113 lines
3.8 KiB
C++
113 lines
3.8 KiB
C++
![]() |
#include "host_iec101_balanced.h"
|
||
|
|
||
|
/***************************************************************************************/
|
||
|
//不平衡方式主协议接收到从站报文
|
||
|
BOOLEAN CIEC101PrimaryBalancedProcess::OnPreCreate(int id)
|
||
|
{
|
||
|
if (!CIEC101PrimaryProcess::OnPreCreate(id)) return FALSE;
|
||
|
int i;
|
||
|
int uid;
|
||
|
CIEC101PrimaryBalancedProcessItem* pItem;
|
||
|
for (i = 0; i < PROCESS_UNIT_NUM; i++)
|
||
|
{
|
||
|
pItem = (CIEC101PrimaryBalancedProcessItem *)GetItem(i);
|
||
|
if (NULL == pItem) continue;
|
||
|
uid = pItem->GetUnitID();
|
||
|
if (uid < 0 || uid >= UNIT_NUM) continue;
|
||
|
BYTE phy_addr[2];
|
||
|
GetUnitAddr(uid, phy_addr, 2);
|
||
|
pItem->Attach(uid, phy_addr[0], phy_addr[0], m_option.originatorAddress); //默认公共地址和物理地址一致
|
||
|
pItem->setAppLayerParameters(m_option.sizeOfCOT, m_option.sizeOfCA, m_option.sizeOfIOA, m_option.maxSizeOfASDU);
|
||
|
|
||
|
Master_setOwnAddress((CIEC101ProcessItem *)pItem, phy_addr[1]);
|
||
|
}
|
||
|
|
||
|
last_sec = (time_t)system32.timers;
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
BOOLEAN CIEC101PrimaryBalancedProcess::Run(void)
|
||
|
{
|
||
|
int uid;
|
||
|
|
||
|
if (!CIEC101PrimaryProcess::Run()) return FALSE;
|
||
|
|
||
|
FeedDog();
|
||
|
|
||
|
BOOLEAN sec_changed = FALSE;
|
||
|
if (last_sec != (time_t)system32.timers)
|
||
|
{
|
||
|
last_sec = (time_t)system32.timers;
|
||
|
sec_changed = TRUE;
|
||
|
}
|
||
|
if ((GetSpace() == MAX_PORT_BUFFER_SIZE))
|
||
|
{
|
||
|
CIEC101ProcessItem *pItem = (CIEC101ProcessItem *)GetNextItem();
|
||
|
if (NULL == pItem) return TRUE;
|
||
|
uid = pItem->GetUnitID();
|
||
|
if (uid < 0 || uid >= UNIT_NUM) return TRUE;
|
||
|
|
||
|
UnitFeedDog(uid);
|
||
|
//遥控报文
|
||
|
if (GetYKFrame(pItem));
|
||
|
//遥调报文
|
||
|
else if (GetYTFrame(pItem));
|
||
|
//时钟同步
|
||
|
else if (GetSetTimeGap() > 0)
|
||
|
{ //需要对时
|
||
|
if (!pItem->clock_synchronized_start && !pItem->clock_synchronized_finish)
|
||
|
{
|
||
|
pItem->clock_synchronized_start = TRUE;
|
||
|
Master_sendClockSyncCommand(pItem);
|
||
|
}
|
||
|
}
|
||
|
//是否需要总召唤
|
||
|
else if (!pItem->interrogation_start)
|
||
|
{
|
||
|
pItem->interrogation_start = TRUE;
|
||
|
//发送总召唤报文
|
||
|
Master_sendInterrogationCommand(pItem, IEC_101_104_COT_ACT, IEC60870_QOI_STATION);
|
||
|
}
|
||
|
//总召唤没有结束
|
||
|
else if (pItem->interrogation_finish)
|
||
|
{
|
||
|
if (sec_changed)
|
||
|
{
|
||
|
if (pItem->total_ym > 0)
|
||
|
{
|
||
|
if (apdu_t5_max > 0 && system32.timers > (pItem->apdu_t5_begin + apdu_t5_max)) //请求电度
|
||
|
{
|
||
|
pItem->apdu_t5_begin = system32.timers;
|
||
|
Master_sendCounterInterrogationCommand(pItem, IEC_101_104_COT_ACT, IEC60870_QCC_RQT_GENERAL);
|
||
|
}
|
||
|
}
|
||
|
if (use_cycle_interrogation_command)
|
||
|
{
|
||
|
if (apdu_t4_max > 0 && system32.timers > (pItem->apdu_t4_begin + apdu_t4_max)) //请求总召唤
|
||
|
{
|
||
|
pItem->apdu_t4_begin = system32.timers;
|
||
|
Master_sendInterrogationCommand(pItem, IEC_101_104_COT_ACT, IEC60870_QOI_STATION);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
/* run all the link layer state machines for the registered slaves */
|
||
|
LinkLayerPrimaryBalanced_runStateMachine(pItem);
|
||
|
}
|
||
|
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
BOOLEAN CIEC101PrimaryBalancedProcess::OnTimer(void)
|
||
|
{
|
||
|
if (!CIEC101PrimaryProcess::OnTimer()) return FALSE;
|
||
|
|
||
|
int time_gap = SetTimeGap();
|
||
|
if (time_gap != 0 &&(m_nCount % time_gap) == 0)
|
||
|
{
|
||
|
//Master_sendClockSyncCommand(pItem, system32.now);
|
||
|
}
|
||
|
return TRUE;
|
||
|
}
|
||
|
/***************************************************************************************/
|