| @@ -4,6 +4,8 @@ file: carpark.php 停車管理 | |||||
| */ | */ | ||||
| if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | ||||
| require_once(MQ_CLASS_FILE); | |||||
| // ----- 定義常數(路徑, cache秒數) ----- | // ----- 定義常數(路徑, cache秒數) ----- | ||||
| define('APP_VERSION', '100'); // 版本號 | define('APP_VERSION', '100'); // 版本號 | ||||
| define('MAX_AGE', 604800); // cache秒數, 此定義1個月 | define('MAX_AGE', 604800); // cache秒數, 此定義1個月 | ||||
| @@ -17,8 +19,6 @@ define('WEB_LIB', SERVER_URL.'libs/'); // 網頁lib | |||||
| define('BOOTSTRAPS', WEB_LIB.'bootstrap_sb/'); // bootstrap lib | define('BOOTSTRAPS', WEB_LIB.'bootstrap_sb/'); // bootstrap lib | ||||
| define('LOG_PATH', FILE_BASE.APP_NAME.'/logs/'); // log path | define('LOG_PATH', FILE_BASE.APP_NAME.'/logs/'); // log path | ||||
| require_once(MQ_CLASS_FILE); | |||||
| class Carpark extends CI_Controller | class Carpark extends CI_Controller | ||||
| { | { | ||||
| var $vars = array(); // 共用變數 | var $vars = array(); // 共用變數 | ||||
| @@ -53,15 +53,15 @@ class Carpark extends CI_Controller | |||||
| $this->load->model('sync_data_model'); | $this->load->model('sync_data_model'); | ||||
| $this->sync_data_model->init($this->vars); // for memcache | $this->sync_data_model->init($this->vars); // for memcache | ||||
| // mqtt | |||||
| // mqtt subscribe | |||||
| $station_setting = $this->sync_data_model->station_setting_query(); | $station_setting = $this->sync_data_model->station_setting_query(); | ||||
| $mqtt_ip = isset($station_setting['mqtt_ip']) ? $station_setting['mqtt_ip'] : MQ_HOST; | $mqtt_ip = isset($station_setting['mqtt_ip']) ? $station_setting['mqtt_ip'] : MQ_HOST; | ||||
| $mqtt_port = isset($station_setting['mqtt_port']) ? $station_setting['mqtt_port'] : MQ_PORT; | $mqtt_port = isset($station_setting['mqtt_port']) ? $station_setting['mqtt_port'] : MQ_PORT; | ||||
| $this->vars['mqtt_ip'] = $mqtt_ip; | |||||
| $this->vars['mqtt_port'] = $mqtt_port; | |||||
| $this->vars['mqtt'] = new phpMQTT($mqtt_ip, $mqtt_port, uniqid()); | |||||
| $this->vars['mqtt']->connect(); | |||||
| // init sync model | |||||
| $this->sync_data_model->init($this->vars); | |||||
| // init again | |||||
| $this->sync_data_model->init($this->vars); // for mqtt | |||||
| // 產生 excel 報表 | // 產生 excel 報表 | ||||
| $this->load->model('excel_model'); | $this->load->model('excel_model'); | ||||
| @@ -201,7 +201,7 @@ class Carpark extends CI_Controller | |||||
| $this->load->model('cars_model'); | $this->load->model('cars_model'); | ||||
| $this->cars_model->init($this->vars); | $this->cars_model->init($this->vars); | ||||
| $this->cars_model->lprio($parms); | $this->cars_model->lprio($parms); | ||||
| $this->cars_model->stop(); | |||||
| echo 'ok'; | echo 'ok'; | ||||
| exit; | exit; | ||||
| } | } | ||||
| @@ -227,7 +227,7 @@ class Carpark extends CI_Controller | |||||
| $this->load->model('cars_model'); | $this->load->model('cars_model'); | ||||
| $this->cars_model->init($this->vars); | $this->cars_model->init($this->vars); | ||||
| $this->cars_model->opendoor_lprio($parms); | $this->cars_model->opendoor_lprio($parms); | ||||
| $this->cars_model->stop(); | |||||
| echo 'ok'; | echo 'ok'; | ||||
| exit; | exit; | ||||
| } | } | ||||
| @@ -256,20 +256,15 @@ class Carpark extends CI_Controller | |||||
| // 判斷會員身份 | // 判斷會員身份 | ||||
| $rows = $this->cars_model->get_member($lpr); | $rows = $this->cars_model->get_member($lpr); | ||||
| // 取得 ck | |||||
| $parms['ck'] = $this->cars_model->gen_opendoor_ck($parms); | |||||
| if ($rows['member_no'] == 0) | if ($rows['member_no'] == 0) | ||||
| { | { | ||||
| //$this->cars_model->mq_send_opendoor(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},TICKET,{$parms['lpr']}"); | |||||
| $this->cars_model->temp_opendoors($parms); // 臨停訊號 | |||||
| $this->cars_model->mq_send(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},TICKET,{$parms['lpr']}"); // 臨停訊號 | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| //$this->cars_model->mq_send_opendoor(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},OPEN,{$parms['lpr']}"); | |||||
| $this->cars_model->member_opendoors($parms); // 月租訊號 | |||||
| $this->cars_model->mq_send(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},OPEN,{$parms['lpr']}"); // 月租訊號 | |||||
| } | } | ||||
| $this->cars_model->stop(); | |||||
| echo 'ok'; | echo 'ok'; | ||||
| exit; | exit; | ||||
| } | } | ||||
| @@ -307,7 +302,6 @@ class Carpark extends CI_Controller | |||||
| if(sizeof($msg_arr) != 4) | if(sizeof($msg_arr) != 4) | ||||
| { | { | ||||
| $this->sync_data_model->stop(); | |||||
| trigger_error($LOG_FLAG . __FUNCTION__ . "..error_size.." . print_r($msg_arr, true)); | trigger_error($LOG_FLAG . __FUNCTION__ . "..error_size.." . print_r($msg_arr, true)); | ||||
| echo 'error_size'; | echo 'error_size'; | ||||
| exit; | exit; | ||||
| @@ -315,7 +309,6 @@ class Carpark extends CI_Controller | |||||
| if($msg_arr[0] != 'N888' || $msg_arr[3] != 'altob') | if($msg_arr[0] != 'N888' || $msg_arr[3] != 'altob') | ||||
| { | { | ||||
| $this->sync_data_model->stop(); | |||||
| trigger_error($LOG_FLAG . __FUNCTION__ . "..unknown_msg.." . print_r($msg_arr, true)); | trigger_error($LOG_FLAG . __FUNCTION__ . "..unknown_msg.." . print_r($msg_arr, true)); | ||||
| echo 'unknown_msg'; | echo 'unknown_msg'; | ||||
| exit; | exit; | ||||
| @@ -326,9 +319,8 @@ class Carpark extends CI_Controller | |||||
| $value = isset($msg_arr[2]) ? $msg_arr[2] : 0; | $value = isset($msg_arr[2]) ? $msg_arr[2] : 0; | ||||
| $result = $this->sync_data_model->force_sync_888($first_station_no, $group_id, $value); | $result = $this->sync_data_model->force_sync_888($first_station_no, $group_id, $value); | ||||
| trigger_error($LOG_FLAG . __FUNCTION__ . "..{$first_station_no}|{$group_id}|{$value}..result..{$result}.."); | trigger_error($LOG_FLAG . __FUNCTION__ . "..{$first_station_no}|{$group_id}|{$value}..result..{$result}.."); | ||||
| } | |||||
| } | |||||
| $this->sync_data_model->stop(); | |||||
| echo 'ok'; | echo 'ok'; | ||||
| exit; | exit; | ||||
| } | } | ||||
| @@ -345,7 +337,6 @@ class Carpark extends CI_Controller | |||||
| if(!$station_setting) | if(!$station_setting) | ||||
| { | { | ||||
| $this->sync_data_model->stop(); | |||||
| echo json_encode('fail', JSON_UNESCAPED_UNICODE); | echo json_encode('fail', JSON_UNESCAPED_UNICODE); | ||||
| exit; // 中斷 | exit; // 中斷 | ||||
| } | } | ||||
| @@ -376,15 +367,11 @@ class Carpark extends CI_Controller | |||||
| if(!$station_setting) | if(!$station_setting) | ||||
| { | { | ||||
| $this->sync_data_model->stop(); | |||||
| echo json_encode('fail', JSON_UNESCAPED_UNICODE); | echo json_encode('fail', JSON_UNESCAPED_UNICODE); | ||||
| exit; // 中斷 | exit; // 中斷 | ||||
| } | } | ||||
| } | } | ||||
| $this->sync_data_model->stop(); | |||||
| echo json_encode($station_setting, JSON_UNESCAPED_UNICODE); | echo json_encode($station_setting, JSON_UNESCAPED_UNICODE); | ||||
| exit; | |||||
| } | } | ||||
| // [排程 or 強制] 同步場站資訊 | // [排程 or 強制] 同步場站資訊 | ||||
| @@ -431,7 +418,6 @@ class Carpark extends CI_Controller | |||||
| $this->sync_data_model->sync_switch_lpr($switch_lpr_arr); | $this->sync_data_model->sync_switch_lpr($switch_lpr_arr); | ||||
| } | } | ||||
| $this->sync_data_model->stop(); | |||||
| } | } | ||||
| // [API] 取得最新未結清 | // [API] 取得最新未結清 | ||||
| @@ -452,7 +438,6 @@ class Carpark extends CI_Controller | |||||
| } | } | ||||
| $data = $this->sync_data_model->get_last_unbalanced_cario($lpr, $station_no); | $data = $this->sync_data_model->get_last_unbalanced_cario($lpr, $station_no); | ||||
| $this->sync_data_model->stop(); | |||||
| echo json_encode($data, JSON_UNESCAPED_UNICODE); | echo json_encode($data, JSON_UNESCAPED_UNICODE); | ||||
| } | } | ||||
| @@ -516,7 +501,6 @@ class Carpark extends CI_Controller | |||||
| public function sync_minutely() | public function sync_minutely() | ||||
| { | { | ||||
| $this->sync_data_model->sync_pks_groups(); // 同步在席現況 | $this->sync_data_model->sync_pks_groups(); // 同步在席現況 | ||||
| $this->sync_data_model->stop(); | |||||
| } | } | ||||
| // 20170816 手動新增入場資料 | // 20170816 手動新增入場資料 | ||||
| @@ -981,10 +965,7 @@ class Carpark extends CI_Controller | |||||
| $group_id = $this->uri->segment(3); // id | $group_id = $this->uri->segment(3); // id | ||||
| $value = $this->uri->segment(4, 0); // value | $value = $this->uri->segment(4, 0); // value | ||||
| $station_no = $this->uri->segment(5); // station_no | $station_no = $this->uri->segment(5); // station_no | ||||
| // 重新載入 | |||||
| $data = $this->sync_data_model->pks_availables_update($group_id, $value, true, $station_no); | $data = $this->sync_data_model->pks_availables_update($group_id, $value, true, $station_no); | ||||
| $this->sync_data_model->stop(); | |||||
| echo json_encode($data, JSON_UNESCAPED_UNICODE); | echo json_encode($data, JSON_UNESCAPED_UNICODE); | ||||
| } | } | ||||
| @@ -31,7 +31,7 @@ var ip='66.249.82.183';var clientid='565162cb67dfb';var mqtt_ip='192.168.51.11'; | |||||
| define('LOG_FILE', FILE_BASE.APP_NAME.'/logs/cario.'); // log file name | define('LOG_FILE', FILE_BASE.APP_NAME.'/logs/cario.'); // log file name | ||||
| require_once(MQ_CLASS_FILE); | require_once(MQ_CLASS_FILE); | ||||
| class Cars extends CI_Controller | class Cars extends CI_Controller | ||||
| { | { | ||||
| var $vars = array(); | var $vars = array(); | ||||
| @@ -103,13 +103,18 @@ class Cars extends CI_Controller | |||||
| $this->load->model('sync_data_model'); | $this->load->model('sync_data_model'); | ||||
| $this->sync_data_model->init($this->vars); // for memcache | $this->sync_data_model->init($this->vars); // for memcache | ||||
| // mqtt | |||||
| // mqtt subscribe | |||||
| $station_setting = $this->sync_data_model->station_setting_query(); | $station_setting = $this->sync_data_model->station_setting_query(); | ||||
| $mqtt_ip = isset($station_setting['mqtt_ip']) ? $station_setting['mqtt_ip'] : MQ_HOST; | $mqtt_ip = isset($station_setting['mqtt_ip']) ? $station_setting['mqtt_ip'] : MQ_HOST; | ||||
| $mqtt_port = isset($station_setting['mqtt_port']) ? $station_setting['mqtt_port'] : MQ_PORT; | $mqtt_port = isset($station_setting['mqtt_port']) ? $station_setting['mqtt_port'] : MQ_PORT; | ||||
| $this->vars['mqtt_ip'] = $mqtt_ip; | |||||
| $this->vars['mqtt_port'] = $mqtt_port; | |||||
| trigger_error(__FUNCTION__ . "..init mqtt..{$this->vars['mqtt_ip']}:{$this->vars['mqtt_port']}"); | |||||
| $this->vars['mqtt'] = new phpMQTT($mqtt_ip, $mqtt_port, uniqid()); | |||||
| $this->vars['mqtt']->connect(); | |||||
| // init again | |||||
| $this->sync_data_model->init($this->vars); // for mqtt | |||||
| $this->load->model('cars_model'); | |||||
| $this->cars_model->init($this->vars); | |||||
| } | } | ||||
| @@ -155,12 +160,7 @@ class Cars extends CI_Controller | |||||
| { | { | ||||
| $parms = $this->uri->uri_to_assoc(3); | $parms = $this->uri->uri_to_assoc(3); | ||||
| $parms['lpr'] = urldecode($parms['lpr']); // 中文車牌 | $parms['lpr'] = urldecode($parms['lpr']); // 中文車牌 | ||||
| // 載入 | |||||
| $this->load->model('cars_model'); | |||||
| $this->cars_model->init($this->vars); | |||||
| $this->cars_model->opendoor_lprio($parms); | $this->cars_model->opendoor_lprio($parms); | ||||
| $this->cars_model->stop(); | |||||
| } | } | ||||
| // IVS -> 車號, 影像 | // IVS -> 車號, 影像 | ||||
| @@ -189,9 +189,7 @@ http://192.168.10.201/cars.html/ipcam/sno/12119/ivsno/0/io/O/type/C/lpr/4750YC/c | |||||
| $parms['lpr'] = urldecode($parms['lpr']); // 中文車牌 | $parms['lpr'] = urldecode($parms['lpr']); // 中文車牌 | ||||
| // 同步並送出一次出入口 888 | // 同步並送出一次出入口 888 | ||||
| $this->sync_data_model->init($this->vars); | |||||
| $this->sync_data_model->sync_888($parms); | $this->sync_data_model->sync_888($parms); | ||||
| $this->sync_data_model->stop(); | |||||
| $pic_folder = CAR_PIC.$this->vars['date_num'].'/'; // 今日資料夾名(yyyymmdd) | $pic_folder = CAR_PIC.$this->vars['date_num'].'/'; // 今日資料夾名(yyyymmdd) | ||||
| if (!file_exists($pic_folder)) mkdir($pic_folder); // 如果資料夾不存在, 建立日期資料夾 | if (!file_exists($pic_folder)) mkdir($pic_folder); // 如果資料夾不存在, 建立日期資料夾 | ||||
| @@ -227,11 +225,7 @@ http://192.168.10.201/cars.html/ipcam/sno/12119/ivsno/0/io/O/type/C/lpr/4750YC/c | |||||
| $parms['curr_time_str'] = $this->vars['date_time']; // 現在時間, 例2015-09-21 15:36:47 | $parms['curr_time_str'] = $this->vars['date_time']; // 現在時間, 例2015-09-21 15:36:47 | ||||
| $parms['pic_name'] = $config['file_name']; // 圖片檔名 | $parms['pic_name'] = $config['file_name']; // 圖片檔名 | ||||
| // 載入 | |||||
| $this->load->model('cars_model'); | |||||
| $this->cars_model->init($this->vars); | |||||
| $this->cars_model->lprio($parms); // 測試eTag | $this->cars_model->lprio($parms); // 測試eTag | ||||
| $this->cars_model->stop(); | |||||
| } | } | ||||
| // 用車牌與eTag, 檢查資料庫 | // 用車牌與eTag, 檢查資料庫 | ||||
| @@ -240,45 +234,9 @@ http://192.168.10.201/cars.html/ipcam/sno/12119/ivsno/0/io/O/type/C/lpr/4750YC/c | |||||
| $lpr = $this->uri->segment(3); | $lpr = $this->uri->segment(3); | ||||
| $etag = $this->uri->segment(4); | $etag = $this->uri->segment(4); | ||||
| // 載入 | |||||
| $this->load->model('cars_model'); | |||||
| $this->cars_model->init($this->vars); | |||||
| $this->cars_model->check_lpr_etag($lpr, $etag); | |||||
| $this->cars_model->stop(); | |||||
| $this->cars_model->check_lpr_etag($lpr, $etag); | |||||
| exit; | exit; | ||||
| } | } | ||||
| // 開門 (臨停) | |||||
| public function temp_opendoors() | |||||
| { | |||||
| $parms['ivsno'] = $this->uri->segment(3); | |||||
| $parms['lpr'] = $this->uri->segment(4); | |||||
| $parms['ck'] = $this->uri->segment(5); | |||||
| // 載入 | |||||
| $this->load->model('cars_model'); | |||||
| $this->cars_model->init($this->vars); | |||||
| $this->cars_model->do_temp_opendoor($parms); | |||||
| $this->cars_model->stop(); | |||||
| exit; | |||||
| } | |||||
| // 開門 (臨停) | |||||
| public function member_opendoors() | |||||
| { | |||||
| $parms['ivsno'] = $this->uri->segment(3); | |||||
| $parms['lpr'] = $this->uri->segment(4); | |||||
| $parms['ck'] = $this->uri->segment(5); | |||||
| // 載入 | |||||
| $this->load->model('cars_model'); | |||||
| $this->cars_model->init($this->vars); | |||||
| $this->cars_model->do_member_opendoor($parms); | |||||
| $this->cars_model->stop(); | |||||
| exit; | |||||
| } | |||||
| public function test_now() | public function test_now() | ||||
| { | { | ||||
| @@ -93,10 +93,8 @@ class Pks extends CI_Controller | |||||
| $station_setting = $this->sync_data_model->station_setting_query(); | $station_setting = $this->sync_data_model->station_setting_query(); | ||||
| $mqtt_ip = isset($station_setting['mqtt_ip']) ? $station_setting['mqtt_ip'] : MQ_HOST; | $mqtt_ip = isset($station_setting['mqtt_ip']) ? $station_setting['mqtt_ip'] : MQ_HOST; | ||||
| $mqtt_port = isset($station_setting['mqtt_port']) ? $station_setting['mqtt_port'] : MQ_PORT; | $mqtt_port = isset($station_setting['mqtt_port']) ? $station_setting['mqtt_port'] : MQ_PORT; | ||||
| //$this->vars['mqtt'] = new phpMQTT($mqtt_ip, $mqtt_port, uniqid()); | |||||
| //$this->vars['mqtt']->connect(); | |||||
| $this->vars['mqtt_ip'] = $mqtt_ip; | |||||
| $this->vars['mqtt_port'] = $mqtt_port; | |||||
| $this->vars['mqtt'] = new phpMQTT($mqtt_ip, $mqtt_port, uniqid()); | |||||
| $this->vars['mqtt']->connect(); | |||||
| // init sync model | // init sync model | ||||
| $this->sync_data_model->init($this->vars); | $this->sync_data_model->init($this->vars); | ||||
| @@ -256,7 +254,6 @@ class Pks extends CI_Controller | |||||
| */ | */ | ||||
| $this->pks_model->pksio($parms); // 車輛進出車格資料庫處理 | $this->pks_model->pksio($parms); // 車輛進出車格資料庫處理 | ||||
| $this->pks_model->stop(); | |||||
| exit; | exit; | ||||
| } | } | ||||
| @@ -266,7 +263,6 @@ class Pks extends CI_Controller | |||||
| public function reculc() | public function reculc() | ||||
| { | { | ||||
| $this->pks_model->reculc(); | $this->pks_model->reculc(); | ||||
| $this->pks_model->stop(); | |||||
| } | } | ||||
| @@ -277,7 +273,6 @@ class Pks extends CI_Controller | |||||
| { | { | ||||
| $station_no = $this->uri->segment(3); | $station_no = $this->uri->segment(3); | ||||
| $data = $this->pks_model->query_station_status($station_no); | $data = $this->pks_model->query_station_status($station_no); | ||||
| $this->pks_model->stop(); | |||||
| echo json_encode($data, JSON_UNESCAPED_UNICODE); | echo json_encode($data, JSON_UNESCAPED_UNICODE); | ||||
| } | } | ||||
| @@ -287,7 +282,6 @@ class Pks extends CI_Controller | |||||
| $station_no = $this->uri->segment(3); | $station_no = $this->uri->segment(3); | ||||
| $pksno = $this->uri->segment(4); | $pksno = $this->uri->segment(4); | ||||
| $data = $this->pks_model->query_station_pks($station_no, $pksno); | $data = $this->pks_model->query_station_pks($station_no, $pksno); | ||||
| $this->pks_model->stop(); | |||||
| echo json_encode($data, JSON_UNESCAPED_UNICODE); | echo json_encode($data, JSON_UNESCAPED_UNICODE); | ||||
| } | } | ||||
| @@ -23,66 +23,67 @@ class Cars_model extends CI_Model | |||||
| public function init($vars) | public function init($vars) | ||||
| { | { | ||||
| $this->vars = $vars; | $this->vars = $vars; | ||||
| if(isset($this->vars['mqtt_ip']) && isset($this->vars['mqtt_port'])) | |||||
| { | |||||
| $this->vars['mqtt'] = new phpMQTT($this->vars['mqtt_ip'], $this->vars['mqtt_port'], uniqid()); | |||||
| if(!$this->vars['mqtt']->connect()) | |||||
| { | |||||
| trigger_error(__FUNCTION__ . '..mqtt fail..' . "{$this->vars['mqtt_ip']}:{$this->vars['mqtt_port']}"); | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| trigger_error(__FUNCTION__ . '..mqtt ip, port not found..'); | |||||
| } | |||||
| } | } | ||||
| // 結束 | |||||
| public function stop() | |||||
| { | |||||
| if(isset($this->vars['mqtt'])) | |||||
| { | |||||
| $this->vars['mqtt']->close(); | |||||
| } | |||||
| } | |||||
| // 開門, 字幕 | |||||
| // 車輛進出傳入車牌號碼 (2016/07/27) | |||||
| public function opendoor_lprio($parms) | public function opendoor_lprio($parms) | ||||
| { | { | ||||
| $parms['lpr'] = urldecode($parms['lpr']); | $parms['lpr'] = urldecode($parms['lpr']); | ||||
| trigger_error(__FUNCTION__ . '|車牌傳入 [開門]:' . print_r($parms, true)); | |||||
| $rows = array(); | |||||
| // $parms['ts'] = date('Y-m-d H:i:s', $parms['ts']); | |||||
| trigger_error(__FUNCTION__ . '|車牌傳入:' . print_r($parms, true)); | |||||
| if ($parms['etag'] != 'NONE') | |||||
| { | |||||
| if ($parms['lpr'] != 'NONE') | |||||
| { | |||||
| // do nothing | |||||
| } | |||||
| else // 車辨失敗但有eTag, 查詢是否有車號 | |||||
| { | |||||
| //$parms['lpr'] = $this->etag2lpr_2($parms['etag']); // 2017/01/10 預設都不用 ETAG 找車牌 | |||||
| } | |||||
| } | |||||
| $rows = $this->get_member($parms['lpr']); | $rows = $this->get_member($parms['lpr']); | ||||
| $this->save_db_io($parms, $rows, true); // 開門, 字幕 | |||||
| $this->save_db_io($parms, $rows, true); | |||||
| return true; | return true; | ||||
| } | } | ||||
| // 資料 | |||||
| // 車輛進出傳入車牌號碼 | |||||
| public function lprio($parms) | public function lprio($parms) | ||||
| { | { | ||||
| $parms['lpr'] = urldecode($parms['lpr']); | |||||
| //$parms['lpr'] = urldecode($parms['lpr']); | |||||
| trigger_error(__FUNCTION__ . '車牌傳入 [資料]:' . print_r($parms, true)); | |||||
| $rows = array(); | |||||
| // $parms['ts'] = date('Y-m-d H:i:s', $parms['ts']); | |||||
| trigger_error('車牌傳入:' . print_r($parms, true)); | |||||
| if ($parms['etag'] != 'NONE') | if ($parms['etag'] != 'NONE') | ||||
| { | { | ||||
| if ($parms['lpr'] != 'NONE') | if ($parms['lpr'] != 'NONE') | ||||
| { | { | ||||
| get_headers("http://localhost/cars.html/check_lpr_etag/{$parms['lpr']}/{$parms['etag']}"); | |||||
| // 有車牌有eTag, 檢查資料庫是否double驗證 | |||||
| //get_headers("http://192.168.10.201/cars.html/check_lpr_etag/{$parms['lpr']}/{$parms['etag']}"); | |||||
| get_headers("http://localhost/cars.html/check_lpr_etag/{$parms['lpr']}/{$parms['etag']}"); // update 2016/07/26 | |||||
| } | |||||
| else // 車辨失敗但有eTag, 查詢是否有車號 | |||||
| { | |||||
| // $parms['lpr'] = $this->etag2lpr_2($parms['etag']); // 2017/01/10 預設都不用 ETAG 找車牌 | |||||
| } | } | ||||
| } | } | ||||
| $rows = $this->get_member($parms['lpr']); | $rows = $this->get_member($parms['lpr']); | ||||
| $this->save_db_io($parms, $rows); // 資料 | |||||
| $this->save_db_io($parms, $rows); | |||||
| return true; | return true; | ||||
| } | } | ||||
| // 入出口異動cario | // 入出口異動cario | ||||
| function save_db_io($parms, $rows, $opendoor=false) | |||||
| public function save_db_io($parms, $rows, $opendoor=false) | |||||
| { | { | ||||
| if (!empty($rows['lpr_correct'])) $parms['lpr'] = $rows['lpr_correct']; | if (!empty($rows['lpr_correct'])) $parms['lpr'] = $rows['lpr_correct']; | ||||
| @@ -844,6 +845,21 @@ class Cars_model extends CI_Model | |||||
| return $rows; | return $rows; | ||||
| } | } | ||||
| // 開門 (月租) | |||||
| public function member_opendoors($parms) | |||||
| { | |||||
| $this->mq_send(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},OPEN,{$parms['lpr']}"); | |||||
| return true; | |||||
| } | |||||
| // 開門 (臨停) | |||||
| public function temp_opendoors($parms) | |||||
| { | |||||
| $this->mq_send(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},TICKET,{$parms['lpr']}"); | |||||
| return true; | |||||
| } | |||||
| // 用eTag讀出車號 | // 用eTag讀出車號 | ||||
| public function etag2lpr_2($etag) | public function etag2lpr_2($etag) | ||||
| { | { | ||||
| @@ -1147,59 +1163,11 @@ class Cars_model extends CI_Model | |||||
| // 送出至message queue(目前用mqtt) | // 送出至message queue(目前用mqtt) | ||||
| function mq_send($topic, $msg) | |||||
| public function mq_send($topic, $msg) | |||||
| { | { | ||||
| $this->vars['mqtt']->publish($topic, $msg, 0); | $this->vars['mqtt']->publish($topic, $msg, 0); | ||||
| trigger_error("mqtt:{$topic}|{$msg}"); | trigger_error("mqtt:{$topic}|{$msg}"); | ||||
| } | } | ||||
| // 產生 CK | |||||
| public function gen_opendoor_ck($parms) | |||||
| { | |||||
| return md5($parms['ivsno']. 'alt' . date('dmh') . 'ob' . $parms['lpr']); | |||||
| } | |||||
| // 開門 (月租) | |||||
| public function member_opendoors($parms) | |||||
| { | |||||
| //$this->mq_send_opendoor(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},OPEN,{$parms['lpr']}"); | |||||
| $ck = $this->gen_opendoor_ck($parms); | |||||
| get_headers("http://localhost/cars.html/member_opendoors/{$parms['ivsno']}/{$parms['lpr']}/{$ck}"); | |||||
| return true; | |||||
| } | |||||
| // 開門 (臨停) | |||||
| public function temp_opendoors($parms) | |||||
| { | |||||
| //$this->mq_send_opendoor(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},TICKET,{$parms['lpr']}"); | |||||
| $ck = $this->gen_opendoor_ck($parms); | |||||
| get_headers("http://localhost/cars.html/temp_opendoors/{$parms['ivsno']}/{$parms['lpr']}/{$ck}"); | |||||
| return true; | |||||
| } | |||||
| // 開門 (月租) | |||||
| public function do_member_opendoor($parms) | |||||
| { | |||||
| if($parms['ck'] != $this->cars_model->gen_opendoor_ck($parms)) | |||||
| { | |||||
| return 'ck_error'; // 中斷 | |||||
| } | |||||
| $this->mq_send(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},OPEN,{$parms['lpr']}"); | |||||
| return 'ok'; | |||||
| } | |||||
| // 開門 (臨停) | |||||
| public function do_temp_opendoor($parms) | |||||
| { | |||||
| if($parms['ck'] != $this->cars_model->gen_opendoor_ck($parms)) | |||||
| { | |||||
| return 'ck_error'; // 中斷 | |||||
| } | |||||
| $this->mq_send(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},TICKET,{$parms['lpr']}"); | |||||
| return 'ok'; | |||||
| } | |||||
| // 指派車位 | // 指派車位 | ||||
| @@ -16,31 +16,7 @@ class Pks_model extends CI_Model | |||||
| public function init($vars) | public function init($vars) | ||||
| { | { | ||||
| $this->vars = $vars; | $this->vars = $vars; | ||||
| if(isset($this->vars['mqtt_ip']) && isset($this->vars['mqtt_port'])) | |||||
| { | |||||
| // 一般 | |||||
| $this->vars['mqtt'] = new phpMQTT($this->vars['mqtt_ip'], $this->vars['mqtt_port'], uniqid(). 'mqtt'); | |||||
| if(!$this->vars['mqtt']->connect()) | |||||
| { | |||||
| trigger_error(__FUNCTION__ . '..mqtt connect fail..' . "{$this->vars['mqtt_ip']}:{$this->vars['mqtt_port']}"); | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| trigger_error(__FUNCTION__ . '..mqtt ip, port not found..'); | |||||
| } | |||||
| } | } | ||||
| // 結束 | |||||
| public function stop() | |||||
| { | |||||
| if(isset($this->vars['mqtt'])) | |||||
| { | |||||
| $this->vars['mqtt']->close(); | |||||
| } | |||||
| } | |||||
| // 車輛進出傳入車牌號碼 | // 車輛進出傳入車牌號碼 | ||||
| @@ -23,34 +23,8 @@ class Sync_data_model extends CI_Model | |||||
| public function init($vars) | public function init($vars) | ||||
| { | { | ||||
| $this->vars = $vars; | $this->vars = $vars; | ||||
| // 一般 | |||||
| if(isset($this->vars['mqtt_ip']) && isset($this->vars['mqtt_port'])) | |||||
| { | |||||
| $this->vars['mqtt'] = new phpMQTT($this->vars['mqtt_ip'], $this->vars['mqtt_port'], uniqid(). 'mqtt'); | |||||
| if(!$this->vars['mqtt']->connect()) | |||||
| { | |||||
| trigger_error(__FUNCTION__ . '..mqtt connect fail..' . "{$this->vars['mqtt_ip']}:{$this->vars['mqtt_port']}"); | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| trigger_error(__FUNCTION__ . '..mqtt ip, port not found..'); | |||||
| } | |||||
| } | } | ||||
| // 結束 | |||||
| public function stop() | |||||
| { | |||||
| if(isset($this->vars['mqtt'])) | |||||
| { | |||||
| $this->vars['mqtt']->close(); | |||||
| trigger_error(__FUNCTION__ . '..mqtt close..' . "{$this->vars['mqtt_ip']}:{$this->vars['mqtt_port']}"); | |||||
| } | |||||
| } | |||||
| // 送出至message queue(目前用mqtt) | // 送出至message queue(目前用mqtt) | ||||
| public function mq_send($topic, $msg) | public function mq_send($topic, $msg) | ||||
| { | { | ||||