DuoFernGateway/module_private.php
/**
     * Initiates the duo fern connection
     *
     * @param int $retry
     *            count of retries
     * @return boolean true if success, false if fail
     */
Initiates the duo fern connection
@param int $retry
count of retries
@return boolean true if success, false if fail
Initiates the duo fern connection @param int $retry count of retries @return boolean true if success false if fail
private function Init($retry = 5)
    {
        $this->SetStatus(self::IS_INIT_PENDING);
        $gatewayDuoFernCode = $this->ReadPropertyString('duoFernCode');
        $deviceDuoFernCodes = $this->DeviceDuoFernCodes;
        for ($i = 0; $i < $retry; $i++) {
            $this->SendDebug("INIT START", $this->ConvertMsgToSend("00000000000000000000000000000000000000000000"), 1);
            $response = $this->SendMsg(DuoFernMessage::DUOFERN_MSG_INIT_1);
            if ($response !== $this->ExpectedResponse(DuoFernMessage::DUOFERN_MSG_INIT_1)) {
                $this->SendDebug("INIT FAIL", $this->ConvertMsgToSend($response), 1);
                continue;
            }
            $response = $this->SendMsg(DuoFernMessage::DUOFERN_MSG_INIT_2);
            if ($response !== $this->ExpectedResponse(DuoFernMessage::DUOFERN_MSG_INIT_2)) {
                $this->SendDebug("INIT FAIL", $this->ConvertMsgToSend($response), 1);
                continue;
            }
            $msg = DuoFernMessage::GenerateMessage(DuoFernMessage::DUOFERN_MSG_INIT_SERIAL, $gatewayDuoFernCode);
            $response = $this->SendMsg($msg);
            if ($response !== $this->ExpectedResponse($msg)) {
                $this->SendDebug("INIT FAIL", $this->ConvertMsgToSend($response), 1);
                continue;
            }
            $response = $this->SendMsg(DuoFernMessage::DUOFERN_MSG_INIT_3);
            if ($response !== $this->ExpectedResponse(DuoFernMessage::DUOFERN_MSG_INIT_3)) {
                $this->SendDebug("INIT FAIL", $this->ConvertMsgToSend($response), 1);
                continue;
            }
            $initFailedAtPairTable = false;
            foreach ($deviceDuoFernCodes as $number => $deviceDuoFernCode) {
                $msg = DuoFernMessage::GenerateMessage(DuoFernMessage::DUOFERN_MSG_INIT_PAIRTABLE, $deviceDuoFernCode, $number);
                $response = $this->SendMsg($msg);
                if ($response !== $this->ExpectedResponse($msg)) {
                    $initFailedAtPairTable = true;
                    break;
                }
                $this->SendPairTableNumber(utf8_encode($number), $deviceDuoFernCode);
            }
            if ($initFailedAtPairTable === true) {
                $this->SendDebug("INIT FAIL", $this->ConvertMsgToSend($response), 1);
                continue;
            }
            $response = $this->SendMsg(DuoFernMessage::DUOFERN_MSG_INIT_END);
            if ($response !== $this->ExpectedResponse(DuoFernMessage::DUOFERN_MSG_INIT_END)) {
                $this->SendDebug("INIT FAIL", $this->ConvertMsgToSend($response), 1);
                continue;
            }
            IPS_Sleep(5);
            $this->SendDebug("INIT SUCCESS", $this->ConvertMsgToSend("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"), 1);
            $n = 1;
            for ($i = 0; $i < $n; $i++) {
                $this->SendMsg(DuoFernMessage::DUOFERN_MSG_GET_ALL_DEVICES_STATUS);
            }
            $this->SetStatus(IS_ACTIVE);
            return true;
        }
        $this->ResetPairTableNumbersOnDevices($deviceDuoFernCodes);
        $this->SetStatus(self::IS_INIT_FAILED);
        return false;
    }
private function Init ( $ retry = 5 ) { $ this -> SetStatus ( self :: IS_INIT_PENDING ) ; $ gatewayDuoFernCode = $ this -> ReadPropertyString ( 'duoFernCode' ) ; $ deviceDuoFernCodes = $ this -> DeviceDuoFernCodes ; for ( $ i = 0 ; $ i < $ retry ; $ i ++ ) { $ this -> SendDebug ( " INIT START " , $ this -> ConvertMsgToSend ( " 00000000000000000000000000000000000000000000 " ) , 1 ) ; $ response = $ this -> SendMsg ( DuoFernMessage :: DUOFERN_MSG_INIT_1 ) ; if ( $ response !== $ this -> ExpectedResponse ( DuoFernMessage :: DUOFERN_MSG_INIT_1 ) ) { $ this -> SendDebug ( " INIT FAIL " , $ this -> ConvertMsgToSend ( $ response ) , 1 ) ; continue ; } $ response = $ this -> SendMsg ( DuoFernMessage :: DUOFERN_MSG_INIT_2 ) ; if ( $ response !== $ this -> ExpectedResponse ( DuoFernMessage :: DUOFERN_MSG_INIT_2 ) ) { $ this -> SendDebug ( " INIT FAIL " , $ this -> ConvertMsgToSend ( $ response ) , 1 ) ; continue ; } $ msg = DuoFernMessage :: GenerateMessage ( DuoFernMessage :: DUOFERN_MSG_INIT_SERIAL , $ gatewayDuoFernCode ) ; $ response = $ this -> SendMsg ( $ msg ) ; if ( $ response !== $ this -> ExpectedResponse ( $ msg ) ) { $ this -> SendDebug ( " INIT FAIL " , $ this -> ConvertMsgToSend ( $ response ) , 1 ) ; continue ; } $ response = $ this -> SendMsg ( DuoFernMessage :: DUOFERN_MSG_INIT_3 ) ; if ( $ response !== $ this -> ExpectedResponse ( DuoFernMessage :: DUOFERN_MSG_INIT_3 ) ) { $ this -> SendDebug ( " INIT FAIL " , $ this -> ConvertMsgToSend ( $ response ) , 1 ) ; continue ; } $ initFailedAtPairTable = false ; foreach ( $ deviceDuoFernCodes as $ number => $ deviceDuoFernCode ) { $ msg = DuoFernMessage :: GenerateMessage ( DuoFernMessage :: DUOFERN_MSG_INIT_PAIRTABLE , $ deviceDuoFernCode , $ number ) ; $ response = $ this -> SendMsg ( $ msg ) ; if ( $ response !== $ this -> ExpectedResponse ( $ msg ) ) { $ initFailedAtPairTable = true ; break ; } $ this -> SendPairTableNumber ( utf8_encode ( $ number ) , $ deviceDuoFernCode ) ; } if ( $ initFailedAtPairTable === true ) { $ this -> SendDebug ( " INIT FAIL " , $ this -> ConvertMsgToSend ( $ response ) , 1 ) ; continue ; } $ response = $ this -> SendMsg ( DuoFernMessage :: DUOFERN_MSG_INIT_END ) ; if ( $ response !== $ this -> ExpectedResponse ( DuoFernMessage :: DUOFERN_MSG_INIT_END ) ) { $ this -> SendDebug ( " INIT FAIL " , $ this -> ConvertMsgToSend ( $ response ) , 1 ) ; continue ; } IPS_Sleep ( 5 ) ; $ this -> SendDebug ( " INIT SUCCESS " , $ this -> ConvertMsgToSend ( " FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF " ) , 1 ) ; $ n = 1 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ this -> SendMsg ( DuoFernMessage :: DUOFERN_MSG_GET_ALL_DEVICES_STATUS ) ; } $ this -> SetStatus ( IS_ACTIVE ) ; return true ; } $ this -> ResetPairTableNumbersOnDevices ( $ deviceDuoFernCodes ) ; $ this -> SetStatus ( self :: IS_INIT_FAILED ) ; return false ; }
Initiates the duo fern connection
 @param int $retry
            count of retries
 @return boolean true if success, false if fail
Initiates the duo fern connection @param int $retry count of retries @return boolean true if success false if fail
// set instance status to init pending // get gateway duo fern code // get device duo fern codes // init 1 // init 2 // init serial // init 3 // init pair table // init failed at pair table // forward to devices // init failed at pair table // init end // wait 5 ms and send init success debug msg // get status of all devices n times // get device status of each device /*
            foreach ($deviceDuoFernCodes as $number => $deviceDuoFernCode) {
                $this->SendMsg(DuoFernMessage::GenerateMessage(DuoFernMessage::DUOFERN_MSG_GET_DEVICE_STATUS, $deviceDuoFernCode));
            }
            */ // set instance status to active // reset pair table numbers at devices // set instance status to initialization failed