DuoFernGateway/module.php
/**
     * Receive data from parent
     * Will be called when receiving data from parent
     *
     * @param string $JSONString
     *            data json encoded
     */
Receive data from parent
Will be called when receiving data from parent

@param string $JSONString
data json encoded
Receive data from parent Will be called when receiving data from parent @param string $JSONString data json encoded
public function ReceiveData($JSONString)
    {
        $data = json_decode($JSONString);
        $receiveBuffer = $this->ReceiveBuffer;
        $lastReceiveTimestampBuffer = $this->LastReceiveTimestampBuffer;
        $lastReceiveSec = time() - $lastReceiveTimestampBuffer;
        if ($lastReceiveSec > 5 && $receiveBuffer != "") {
            $this->SendDebug("FLUSH RECEIVE BUFFER", $receiveBuffer, 1);
            $receiveBuffer = "";
        }
        $receiveBuffer .= utf8_decode($data->Buffer);
        if (strlen($receiveBuffer) >= 22) {
            $msg = substr($receiveBuffer, 0, 22);
            $displayMsg = $this->ConvertMsgToDisplay($msg);
            $receiveBuffer = substr($receiveBuffer, 22);
            if (preg_match(DuoFernRegex::DUOFERN_REGEX_ACK, $displayMsg)) {
                $waitForResponseBuffer = $this->WaitForResponseBuffer;
                $waitForResponseBuffer->Add($displayMsg);
                $this->WaitForResponseBuffer = $waitForResponseBuffer;
                $this->SendDebug("RECEIVED RESPONSE", $msg, 1);
            } else { 
                $this->SendDebug("RECEIVED", $msg, 1);
                $this->SendDataToChildren(json_encode(Array("DataID" => "{244143D3-BABA-44D4-8740-B997B8F09E50}",
                    "Buffer" => utf8_encode($msg), "DuoFernCode" => substr($displayMsg, 30, 6))));
                $this->SendDataToChildren(json_encode(Array("DataID" => "{15FD9630-BABA-4BCB-90E4-7DE815ECB79D}",
                    "Buffer" => utf8_encode($msg))));
            }
            if (strcmp($displayMsg, DuoFernMessage::DUOFERN_MSG_ACK) !== 0) {
                $this->SendMsg(DuoFernMessage::DUOFERN_MSG_ACK);
            }
        }
        $lastReceiveTimestampBuffer = time();
        $this->ReceiveBuffer = $receiveBuffer;
        $this->LastReceiveTimestampBuffer = $lastReceiveTimestampBuffer;
    }
public function ReceiveData ( $ JSONString ) { $ data = json_decode ( $ JSONString ) ; $ receiveBuffer = $ this -> ReceiveBuffer ; $ lastReceiveTimestampBuffer = $ this -> LastReceiveTimestampBuffer ; $ lastReceiveSec = time ( ) - $ lastReceiveTimestampBuffer ; if ( $ lastReceiveSec > 5 && $ receiveBuffer != " " ) { $ this -> SendDebug ( " FLUSH RECEIVE BUFFER " , $ receiveBuffer , 1 ) ; $ receiveBuffer = " " ; } $ receiveBuffer .= utf8_decode ( $ data -> Buffer ) ; if ( strlen ( $ receiveBuffer ) >= 22 ) { $ msg = substr ( $ receiveBuffer , 0 , 22 ) ; $ displayMsg = $ this -> ConvertMsgToDisplay ( $ msg ) ; $ receiveBuffer = substr ( $ receiveBuffer , 22 ) ; if ( preg_match ( DuoFernRegex :: DUOFERN_REGEX_ACK , $ displayMsg ) ) { $ waitForResponseBuffer = $ this -> WaitForResponseBuffer ; $ waitForResponseBuffer -> Add ( $ displayMsg ) ; $ this -> WaitForResponseBuffer = $ waitForResponseBuffer ; $ this -> SendDebug ( " RECEIVED RESPONSE " , $ msg , 1 ) ; } else { $ this -> SendDebug ( " RECEIVED " , $ msg , 1 ) ; $ this -> SendDataToChildren ( json_encode ( Array ( " DataID " => " {244143D3-BABA-44D4-8740-B997B8F09E50} " , " Buffer " => utf8_encode ( $ msg ) , " DuoFernCode " => substr ( $ displayMsg , 30 , 6 ) ) ) ) ; $ this -> SendDataToChildren ( json_encode ( Array ( " DataID " => " {15FD9630-BABA-4BCB-90E4-7DE815ECB79D} " , " Buffer " => utf8_encode ( $ msg ) ) ) ) ; } if ( strcmp ( $ displayMsg , DuoFernMessage :: DUOFERN_MSG_ACK ) !== 0 ) { $ this -> SendMsg ( DuoFernMessage :: DUOFERN_MSG_ACK ) ; } } $ lastReceiveTimestampBuffer = time ( ) ; $ this -> ReceiveBuffer = $ receiveBuffer ; $ this -> LastReceiveTimestampBuffer = $ lastReceiveTimestampBuffer ; }
Receive data from parent
 Will be called when receiving data from parent
Receive data from parent Will be called when receiving data from parent
// decode data // get buffers // check last receive timestamp, if last receive time > 5s flush buffer // add new data at end of receive buffer // if complete msg in receive buffer // get msg from buffer // remove msg from receive buffer // ack / response msg // normal msg // forward to devices // forward to configurator // send ack // set new last receive timestamp // set buffers