コード例 #1
2
 public function init()
 {
     if (preg_match('/COM[0-9]+/', $this->source)) {
         $this->_logger->log(__METHOD__ . ' Check Serial port');
         // else it is COM port connection: it can be DataLogger or GSM modem
         ListenerProcess::addComment($this->listener->listener_id, 'hardware_recognizing', SMSCOMPort::getLinuxComName($this->source) . ' is Serial port.');
         try {
             // try to send AT command
             // if script recieves "OK" - this is GSM modem. Else - it can be only DataLogger
             $serial = new PhpSerial($this->_logger);
             $this->_logger->log(__METHOD__ . $this->source);
             $serial->deviceSet($this->source);
             $serial->confFlowControl(Yii::app()->params['com_connect_params']['hardwareflowcontrol']);
             $serial->confBaudRate(Yii::app()->params['com_connect_params']['baudrate']);
             $serial->confParity(Yii::app()->params['com_connect_params']['parity']);
             $serial->confStopBits(Yii::app()->params['com_connect_params']['stopbits']);
             $serial->confCharacterLength(Yii::app()->params['com_connect_params']['databits']);
             $this->_connector = new GsmModemSerialConnector($this->_logger, $serial);
             $this->_connector->setParams(array('port' => $this->source));
             ListenerProcess::addComment($this->listener->listener_id, 'hardware_recognizing', 'Script started to recognize hardware connected to PC via Serial port');
             if ($this->listener->additional_param == 'SMS') {
                 while (1) {
                     if ($this->_connector->check()) {
                         $this->_logger->log(__METHOD__, array('hardware' => 'modem'));
                         $this->hardware = 'modem';
                         ListenerProcess::addComment($this->listener->listener_id, 'hardware_recognizing', 'Hardware connected to PC via Serial port - is GSM Modem');
                         $this->_logger->log(__METHOD__, array('hardware' => $this->hardware));
                         return true;
                     }
                     sleep(60);
                 }
             }
             $this->_connector = new DataLoggerSerialConnector($this->_logger, $serial);
             $this->_connector->setParams(array('port' => $this->source));
             if ($this->listener->additional_param == 'DIRECT') {
                 if ($this->_connector->check()) {
                     $this->_logger->log(__METHOD__, array('hardware' => 'datalogger'));
                     $this->hardware = 'dl';
                     ListenerProcess::addComment($this->listener->listener_id, 'hardware_recognizing', 'Hardware connected to PC via Serial port - is Datalogger');
                     $this->_logger->log(__METHOD__, array('hardware' => $this->hardware));
                     return true;
                 }
             }
         } catch (Exception $e) {
             $this->_logger->log(__METHOD__, array('ExceptionMessage' => $e->getMessage()));
         }
         $this->_logger->log(__METHOD__, array('hardware' => 'unknown'));
         $this->hardware = 'unknown';
         ListenerProcess::addComment($this->listener->listener_id, 'hardware_recognizing', 'No device found.');
         $this->_logger->log(__METHOD__, array('hardware' => $this->hardware));
         return false;
     }
 }
コード例 #2
0
 public function init()
 {
     $this->getFromMemory();
     $criteria = new CDbCriteria();
     $criteria->order = "communication_port asc, communication_type asc";
     $stations = Station::model()->findAll($criteria);
     if (count($stations) > 0) {
         foreach ($stations as $station) {
             $value_connetcion_type = false;
             switch ($station->communication_type) {
                 case 'direct':
                 case 'sms':
                     $value_connetcion_type = SMSCOMPort::getLinuxComName($station->communication_port);
                     $connection_type = $station->communication_port;
                     break;
                 case 'tcpip':
                     $connection_type = $station->communication_esp_ip . ':' . $station->communication_esp_port;
                     break;
                 case 'gprs':
                     $connection_type = 'poller:' . $station->station_id_code;
                     break;
                 case 'server':
                     $connection_type = 'tcp:' . $station->communication_esp_ip . ':' . $station->communication_esp_port;
                     break;
             }
             $this->all_sources[$connection_type] = $value_connetcion_type ? $value_connetcion_type : $connection_type;
         }
     }
     return parent::init();
 }
コード例 #3
0
ファイル: ProcessListenDL.php プロジェクト: anton-itscript/WM
 public function run()
 {
     ListenerProcess::addComment($this->listener->listener_id, 'comment', 'going to start listening datalogger, source= ' . SMSCOMPort::getLinuxComName($this->source));
     $i = 0;
     while (true) {
         $this->listenDLTorrentTemp($i++);
     }
 }
コード例 #4
0
ファイル: connections.php プロジェクト: anton-itscript/WM
    ?>
    
    <table class="tablelist" width="100%">
    <tr>
        <th>Listen to</th>
        <th>Communication Type</th>
        <th>Stations sending messages<br/>via this connection</th>
        <th>Last Status</th>
        <th>Tools</th>
    </tr>
    <?php 
    foreach ($connections as $key => $params) {
        $connection_type = str_replace(array(':', '.'), array('__', '_'), $params['connection_type']);
        $communication_type = $connections[$key]['communication_type'];
        if (preg_match("/sms/i", $key, $matches1) or preg_match("/direct/i", $key, $matches2)) {
            $key = SMSCOMPort::getLinuxComName($connection_type);
        }
        ?>
    <tr class="<?php 
        echo fmod($i, 2) == 0 ? 'c' : '';
        ?>
" >
       <td><b><?php 
        echo CHtml::encode($key);
        ?>
</b></td>
       <td>
            <?php 
        foreach ($params['stations'] as $station => $value) {
            ?>
               <?php 
コード例 #5
0
ファイル: station_list.php プロジェクト: anton-itscript/WM
        echo CHtml::link($station->display_name, array('admin/StationSave', 'station_id' => $station->station_id), array('title' => 'Change Station Details'));
        ?>
</td>
			
			<td nowrap><?php 
        echo $station->timezone_id;
        ?>
 (GMT <?php 
        echo TimezoneWork::getOffsetFromUTC($station->timezone_id, 1);
        ?>
)</td>
            <td nowrap>
                <?php 
        echo Yii::app()->params['com_type'][$station->communication_type] . ' ';
        if ($station->communication_type === 'direct' || $station->communication_type === 'sms') {
            echo '(' . SMSCOMPort::getLinuxComName($station->communication_port) . ')';
        } else {
            if ($station->communication_type === 'tcpip') {
                echo '(' . $station->communication_esp_ip . ':' . $station->communication_esp_port . ')';
            } else {
                if ($station->communication_type === 'gprs') {
                    echo '(' . $station->communication_esp_ip . ':' . $station->communication_esp_port . ')';
                } else {
                    if ($station->communication_type === 'server') {
                        echo '(' . $station->communication_esp_ip . ':' . $station->communication_esp_port . ')';
                    }
                }
            }
        }
        ?>
            </td>
コード例 #6
0
ファイル: ProcessListen.php プロジェクト: anton-itscript/WM
 protected function _recognizeHardware()
 {
     $this->_logger->log(__CLASS__ . ' ' . __METHOD__, array('source' => $this->source));
     $matches = array();
     // Check IP_ADDRESS:PORT pattern
     if (preg_match('/^([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})\\:([0-9]{1,5})$/', $this->source, $matches)) {
         $this->_logger->log(__CLASS__ . ' ' . __METHOD__, array('hardware' => 'client'));
         $this->hardware = 'client';
         ListenerProcess::addComment($this->listener->listener_id, 'hardware_recognizing', $this->source . ' is IP address. Script supposes it is ESP.');
     } else {
         if (preg_match('/^POLLER\\:([a-zA-Z0-9]{1,5})$/i', $this->source, $matches)) {
             $this->_logger->log(__CLASS__ . ' ' . __METHOD__, array('hardware' => 'poller'));
             $this->hardware = 'poller';
         } else {
             if (preg_match('/^([a-zA-Z]{3,})\\:([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}|[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]+|localhost)\\:([0-9]{1,5})$/i', $this->source, $matches)) {
                 $this->_logger->log(__CLASS__ . ' ' . __METHOD__, array('hardware' => 'server'));
                 $this->hardware = 'server';
                 ListenerProcess::addComment($this->listener->listener_id, 'hardware_recognizing', $this->source . ' is IP address with protocol. Script supposes it is Server.');
             } else {
                 if (preg_match('/COM[0-9]+/', $this->source)) {
                     $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ' Check Serial port');
                     // else it is COM port connection: it can be DataLogger or GSM modem
                     ListenerProcess::addComment($this->listener->listener_id, 'hardware_recognizing', SMSCOMPort::getLinuxComName($this->source) . ' is Serial port.');
                     $this->hardware = 'com';
                 } else {
                     $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ' Source has no matches');
                 }
             }
         }
     }
 }
コード例 #7
0
<div class="middlenarrow">
    <h1> Setup SMS Port </h1>


    <p><b>Selected Port:</b> <?php 
echo SMSCOMPort::getLinuxComName($SMSCOMPort->COM);
?>
</p> <br/>
    <form action="<?php 
echo Yii::app()->urlManager->createUrl('admin/smscommandsetup');
?>
" method="POST">
        <?php 
echo CHtml::DropDownList('setup_com', $SMSCOMPort->COM, SysFunc::getAvailableComPortsList());
?>
 <br> <br>
        <input type="submit" value="Apply"/>
    </form>

</div>
コード例 #8
0
ファイル: AdminController.php プロジェクト: anton-itscript/WM
 public function actionSMSCommandSetup()
 {
     $SMSCOMPort = new SMSCOMPort();
     if ($_POST['setup_com']) {
         $SMSCOMPort->COM = $_POST['setup_com'];
         $SMSCOMPort->save();
     }
     return $this->render('setup_sms_command', array('SMSCOMPort' => $SMSCOMPort));
 }
コード例 #9
0
 public function run()
 {
     ListenerProcess::addComment($this->listener->listener_id, 'comment', 'going to start listening for SMS messages, source= ' . SMSCOMPort::getLinuxComName($this->source));
     $this->_connector->onReceiveMessages = function ($messages) {
         ListenerProcess::addComment($this->listener->listener_id, 'comment', 'found ' . count($messages) . ' messages at modem');
     };
     $this->_connector->onReceiveMessage = function ($message, $stationId) {
         $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ' Found message at modem: ' . $message);
         /**
          * if message is not response by sms command
          * then use default function
          */
         if (is_null(SMSCommand::setResponse($message))) {
             $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ' Message type: ' . 'default');
             //                $messageId = ListenerLog::addNew($message, $this->listener->listener_id, $this->settings->overwrite_data_on_listening, $stationId);
             $messageId = ListenerLogTemp::addNew($message, $this->listener->listener_id, $this->settings->overwrite_data_on_listening, $stationId);
             ListenerProcess::addComment($this->listener->listener_id, 'comment', 'Found message at modem, message id:' . $messageId . ', message: ' . $message);
         } else {
             $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ' Message type: ' . 'sms command');
         }
     };
     $i = 0;
     $SMSCOMPort = new SMSCOMPort();
     // For send sms command
     //$SMSCOMPort->COM;
     //$com = yii::app()->params['com_for_send_sms_command'];
     if ($this->source == $SMSCOMPort->COM) {
         ListenerProcess::addComment($this->listener->listener_id, 'sms_command', 'going to start send SMS command, source= ' . SMSCOMPort::getLinuxComName($this->source));
         while (true) {
             if ($this->synchronization->isMaster()) {
                 $this->grabModemMessages($i++);
                 $this->sendSMSByModem($i);
             }
             sleep(20);
         }
     } else {
         while (true) {
             if ($this->synchronization->isMaster()) {
                 $this->grabModemMessages($i++);
             }
             sleep(20);
         }
     }
 }