Commit 7105ff2d by 杨苏杭

硬件参数invertalTime取消固定1200

parent 390604ad
...@@ -24,13 +24,6 @@ class GatewayController extends Controller ...@@ -24,13 +24,6 @@ class GatewayController extends Controller
$gateway = new Gateway(); $gateway = new Gateway();
$port = new Port();
$redis = app('Redis');
if ($redis instanceof \Redis) {
$redis->multi(2);
}
foreach ($gatewaysId as $gatewayId) { foreach ($gatewaysId as $gatewayId) {
$deviceId = DB::table('gateways')->where('id', $gatewayId)->first([ $deviceId = DB::table('gateways')->where('id', $gatewayId)->first([
...@@ -43,8 +36,6 @@ class GatewayController extends Controller ...@@ -43,8 +36,6 @@ class GatewayController extends Controller
$gateway->offline($gatewayId); $gateway->offline($gatewayId);
} }
$redis->exec();
$broadcastToAgent = new BroadcastToAgent(); $broadcastToAgent = new BroadcastToAgent();
$broadcastToAgent->broadcast([ $broadcastToAgent->broadcast([
......
...@@ -29,10 +29,6 @@ class SendController extends Controller ...@@ -29,10 +29,6 @@ class SendController extends Controller
public function sendResult(Request $request) public function sendResult(Request $request)
{ {
Log::debug('send message back_message');
Log::debug($request->all());
$validator = Validator::make($request->all(), [ $validator = Validator::make($request->all(), [
'commandId' => 'required', 'commandId' => 'required',
'deviceId' => 'required', 'deviceId' => 'required',
...@@ -58,9 +54,6 @@ class SendController extends Controller ...@@ -58,9 +54,6 @@ class SendController extends Controller
} }
Log::debug('send result');
Log::debug($request->all());
} }
...@@ -81,8 +74,6 @@ class SendController extends Controller ...@@ -81,8 +74,6 @@ class SendController extends Controller
return; return;
} }
Log::debug($request->all());
$deviceId = $request->get('device_id'); $deviceId = $request->get('device_id');
$content = $request->get('content'); $content = $request->get('content');
$iotSend = new IotSend(); $iotSend = new IotSend();
......
...@@ -11,12 +11,16 @@ namespace App\Http\Controllers; ...@@ -11,12 +11,16 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Lib\Session;
class TestController extends Controller class TestController extends Controller
{ {
public function test(Request $request) public function test(Request $request)
{ {
Log::debug($request->all());
dd(json_decode(Session::all('8ee07038-920f-47f8-866d-40b62d43445e'), true));
} }
......
...@@ -44,12 +44,6 @@ class StateController extends Controller ...@@ -44,12 +44,6 @@ class StateController extends Controller
$gateway = new Gateway(); $gateway = new Gateway();
$redis = app('Redis');
if ($redis instanceof \Redis) {
$redis->multi(2);
}
foreach ($gatewayIds as $gatewayId) { foreach ($gatewayIds as $gatewayId) {
$gatewayDeviceId = DB::table('gateways')->where('id', $gatewayId)->first(['nb_device_id']); $gatewayDeviceId = DB::table('gateways')->where('id', $gatewayId)->first(['nb_device_id']);
...@@ -59,8 +53,5 @@ class StateController extends Controller ...@@ -59,8 +53,5 @@ class StateController extends Controller
} }
} }
$redis->exec();
} }
} }
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/12/23
* Time: 下午6:45
*/
namespace App\Http\Controllers\update;
use App\Http\Controllers\Controller;
use Lib\iot\AccessToken;
use Lib\iot\IotClient;
use Lib\iot\update\QuerySoftware;
use Lib\iot\update\Software;
use Illuminate\Support\Facades\Log;
class TestController extends Controller
{
public function index(Software $software, QuerySoftware $querySoftware)
{
$iotClient = new IotClient($software);
$iotClient = new IotClient($querySoftware);
$iotClient->setDefaultHeader();
$result = ($iotClient->request());
Log::debug('htlo');
dd(json_decode($iotClient->getResponse()->getBody(), true));
$software->setDevices(['8ee07038-920f-47f8-866d-40b62d43445e']);
$software->setFileId('239d01c0341fe786e924d073');
dd($iotClient->request());
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/12/23
* Time: 下午7:51
*/
namespace App\Http\Controllers\update;
use App\Http\Controllers\Controller;
use Application\Gateway;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Lib\Crc;
use Lib\iot\IotClient;
use Lib\iot\update\QuerySoftware;
use Lib\iot\update\Software;
use Illuminate\Support\Facades\Log;
class UpdateController extends Controller
{
public function update(Request $request, Software $software, QuerySoftware $querySoftware)
{
$validator = Validator::make($request->all(), [
'nb_device_id' => 'required',
'time' => 'required',
'hardware' => 'required',
'software' => 'required',
'sign' => 'required',
]);
if ($validator->fails()) {
abort(400, $validator->errors()->first());
}
$querySoftware = new QuerySoftware();
$iotClient = new IotClient($querySoftware);
$iotClient->setDefaultHeader();
$time = $request->get('time');
if ($iotClient->request() === true) {
$querySoftware->parseResponse($iotClient->getResponse());
$fileId = $querySoftware->getFileId();
$software = new Software();
if ($time != 0) {
$software->setIsRightNow(false);
$software->setStartTime($time - 60 * 60 * 8);
}
$software->setDevices([$request->get('nb_device_id')]);
$software->setFileId($fileId);
$iotClient->setRequest($software);
$iotClient->request();
$updateTime = sprintf('%08x', $time);
$hardware = $request->get('hardware');
$softwareName = $request->get('software');
$sign = $request->get('sign');
$body = $updateTime . $hardware . $softwareName . $sign;
$nonce = sprintf('%02x', rand(0, 100));
$length = sprintf('%04x', 36);
$message = strtoupper('FFAA04D2' . $length . $nonce . $body);
$crc = substr(sprintf('%08x', Crc::crc($message)), 0, 2);
$message .= $crc;
Gateway::sendToClient($request->get('nb_device_id'), strtoupper($message));
}
}
}
\ No newline at end of file
...@@ -66,7 +66,8 @@ class AccessController extends Controller ...@@ -66,7 +66,8 @@ class AccessController extends Controller
'station_id', 'station_id',
'id', 'id',
'name', 'name',
'type_id' 'type_id',
'nb_device_id'
], 'mac_address=' . $mac); ], 'mac_address=' . $mac);
if ($gatewayModelResult == false) { if ($gatewayModelResult == false) {
...@@ -74,9 +75,14 @@ class AccessController extends Controller ...@@ -74,9 +75,14 @@ class AccessController extends Controller
return; return;
} }
$stationId = $gatewayModelResult['station_id']; $stationId = $gatewayModelResult['station_id'];
$nbDeviceId = $gatewayModelResult['nb_device_id'];
$gatewayId = $gatewayModelResult['id']; $gatewayId = $gatewayModelResult['id'];
Session::clearByDeviceId($nbDeviceId);
Session::update('nb_device_id', $nbDeviceId);
Session::update('gateway_name', $gatewayModelResult['name']); Session::update('gateway_name', $gatewayModelResult['name']);
Session::update('gateway_id', $gatewayId); Session::update('gateway_id', $gatewayId);
Session::update('gateway_type', $gatewayModelResult['type_id']); Session::update('gateway_type', $gatewayModelResult['type_id']);
...@@ -107,7 +113,6 @@ class AccessController extends Controller ...@@ -107,7 +113,6 @@ class AccessController extends Controller
} }
$deviceModel = new DeviceModel(); $deviceModel = new DeviceModel();
$deviceModelResult = $deviceModel->getAllColumns([ $deviceModelResult = $deviceModel->getAllColumns([
'id', 'id',
'device_mac', 'device_mac',
'name', 'name',
...@@ -193,6 +198,7 @@ class AccessController extends Controller ...@@ -193,6 +198,7 @@ class AccessController extends Controller
$portsLogicId = []; $portsLogicId = [];
$portsId = []; $portsId = [];
foreach ($portMacState as $mac => $state) { foreach ($portMacState as $mac => $state) {
if (isset($portsMacId[$mac])) { if (isset($portsMacId[$mac])) {
array_push($portsId, $portsMacId[$mac]); array_push($portsId, $portsMacId[$mac]);
...@@ -215,6 +221,7 @@ class AccessController extends Controller ...@@ -215,6 +221,7 @@ class AccessController extends Controller
$port->setState($state); $port->setState($state);
$port->setGatewayId(Session::get('gateway_id')); $port->setGatewayId(Session::get('gateway_id'));
$port->setStationId(Session::get('station_id')); $port->setStationId(Session::get('station_id'));
Log::debug('update port state' . $portId);
$port->updatePortState(); $port->updatePortState();
$portsLogicId[$logicStartTmp++] = $portId; $portsLogicId[$logicStartTmp++] = $portId;
...@@ -283,6 +290,7 @@ class AccessController extends Controller ...@@ -283,6 +290,7 @@ class AccessController extends Controller
// $port->setState(StateCode::PORT_CHARGER); // $port->setState(StateCode::PORT_CHARGER);
$port->setState($order->getStateCode()); $port->setState($order->getStateCode());
Log::debug('update state ' . $order->getStateCode());
$port->updatePortState(); $port->updatePortState();
unset($order); unset($order);
......
...@@ -150,9 +150,17 @@ class OverController extends Controller ...@@ -150,9 +150,17 @@ class OverController extends Controller
case StateCode::CHANGE_PORT: case StateCode::CHANGE_PORT:
if (filled(Session::get('port_logic_id'))) { if (filled(Session::get('port_logic_id'))) {
Log::debug(Session::$deviceId);
$portLogicId = Session::get('port_logic_id'); $portLogicId = Session::get('port_logic_id');
Log::debug('change_port');
Log::debug($portLogicId);
$portId = isset($portLogicId[$logicId]) ? $portLogicId[$logicId] : 0; $portId = isset($portLogicId[$logicId]) ? $portLogicId[$logicId] : 0;
Log::debug($portId);
$port = new Port($portId); $port = new Port($portId);
$port->setState(StateCode::PORT_ONLINE); $port->setState(StateCode::PORT_ONLINE);
$port->setGatewayId($order->getGatewayId()); $port->setGatewayId($order->getGatewayId());
......
...@@ -44,10 +44,9 @@ class SettingController extends Controller ...@@ -44,10 +44,9 @@ class SettingController extends Controller
} }
$invertalTime = $idConfigsValue['5']; //设备上报数据间隔单位 秒 $invertalTime = $idConfigsValue['5']; //设备上报数据间隔单位 秒
$invertalTime = 60 * 20;
if (filled(Session::get('station_id')) === false) { if ( filled(Session::get('station_id')) === false ) {
Log::error('setting miss station_id'); Log::error('setting miss station_id');
return; return;
} }
......
...@@ -13,7 +13,11 @@ use Application\controller\Controller; ...@@ -13,7 +13,11 @@ use Application\controller\Controller;
use Application\model\DeviceModel; use Application\model\DeviceModel;
use Application\model\GatewayModel; use Application\model\GatewayModel;
use Application\model\GatewayUpdateModel; use Application\model\GatewayUpdateModel;
use GatewayWorker\Lib\Gateway; use Lib\iot\IotClient;
use Lib\iot\update\QuerySoftware;
use Lib\iot\update\Software;
use Lib\Session;
use Lib\station\gateway\Gateway;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
class QueryController extends Controller class QueryController extends Controller
...@@ -50,7 +54,7 @@ class QueryController extends Controller ...@@ -50,7 +54,7 @@ class QueryController extends Controller
$gatewayModel->update([ $gatewayModel->update([
'hardware_version' => $this->request->get('hardware_version'), 'hardware_version' => $this->request->get('hardware_version'),
'software_version' => $this->request->get('software_version'), 'software_version' => $this->request->get('software_version'),
], 'id = ' . $_SESSION['gateway_id']); ], 'id=' . Session::get('gateway_id'));
} }
...@@ -62,9 +66,8 @@ class QueryController extends Controller ...@@ -62,9 +66,8 @@ class QueryController extends Controller
$hardwareVersion = $this->request->get('hardware_version'); $hardwareVersion = $this->request->get('hardware_version');
$softwareVersion = $this->request->get('software_version'); $softwareVersion = $this->request->get('software_version');
$response = ''; $response = '';
Log::debug('session', Gateway::getSession($this->clientId));
$gatewayType = isset($_SESSION['gateway_type']) ? $_SESSION['gateway_type'] : false; $gatewayType = filled(Session::get('gateway_type')) ? Session::get('gateway_type') : false;
if ($gatewayType === false) { if ($gatewayType === false) {
Log::debug('can not find gateway type'); Log::debug('can not find gateway type');
...@@ -72,7 +75,7 @@ class QueryController extends Controller ...@@ -72,7 +75,7 @@ class QueryController extends Controller
} }
$gatewayUpdateModel = new GatewayUpdateModel(); $gatewayUpdateModel = new GatewayUpdateModel();
$updateInfo = $gatewayUpdateModel->getColumns(['hardware_version', 'software_version', 'sign'], 'gateway_type = ' . $gatewayType); $updateInfo = $gatewayUpdateModel->getColumns(['hardware_version', 'software_version', 'sign'], 'gateway_type=' . $gatewayType);
if (count($updateInfo) !== 0) { if (count($updateInfo) !== 0) {
$updateHardwareVersion = $updateInfo['hardware_version']; $updateHardwareVersion = $updateInfo['hardware_version'];
...@@ -89,32 +92,43 @@ class QueryController extends Controller ...@@ -89,32 +92,43 @@ class QueryController extends Controller
$returnCode = '12'; $returnCode = '12';
$host = getenv('DOWNLOAD_HOST'); $querySoftware = new QuerySoftware();
if ($host === false) {
throw new \Exception('can not find download host'); $iotClient = new IotClient($querySoftware);
}
$downloadUrl = $host . '/update/' . $updateHardwareVersion . $updateSoftwareVersion . '.bin'; $iotClient->setDefaultHeader();
$urlHex = ''; if ($iotClient->request() === true) {
for ($i = 0; $i < strlen($downloadUrl); $i++) {
$hex = sprintf('%02x', ord($downloadUrl[$i])); $querySoftware->parseResponse($iotClient->getResponse());
$urlHex .= $hex; $fileId = $querySoftware->getFileId();
$software = new Software();
$software->setDevices([Session::get('nb_device_id')]);
$software->setFileId($fileId);
$iotClient->setRequest($software);
$iotClient->request();
} }
Log::debug($updateSoftwareVersion); Log::debug($updateSoftwareVersion);
Log::debug($updateHardwareVersion); Log::debug($updateHardwareVersion);
Log::debug($sign); Log::debug($sign);
Log::debug($urlHex);
$this->response->send('d1', $returnCode . $updateHardwareVersion . $updateSoftwareVersion . $sign . $urlHex); $this->response->send('d1', $returnCode . $updateHardwareVersion . $updateSoftwareVersion . $sign);
return; return;
} }
$this->response->send('d1', $returnCode); $this->response->send('d1', $returnCode);
return; return;
} }
$this->response->send('d1', '11'); $this->response->send('d1', '11');
return; return;
......
...@@ -11,10 +11,10 @@ use \Exception; ...@@ -11,10 +11,10 @@ use \Exception;
* For full copyright and license information, please see the MIT-LICENSE.txt * For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @author walkor<walkor@workerman.net> * @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net> * @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/ * @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/ */
/** /**
...@@ -62,10 +62,10 @@ class Gateway ...@@ -62,10 +62,10 @@ class Gateway
/** /**
* 向所有客户端连接(或者 client_id_array 指定的客户端连接)广播消息 * 向所有客户端连接(或者 client_id_array 指定的客户端连接)广播消息
* *
* @param string $message 向客户端发送的消息 * @param string $message 向客户端发送的消息
* @param array $client_id_array 客户端 id 数组 * @param array $client_id_array 客户端 id 数组
* @param array $exclude_client_id 不给这些client_id发 * @param array $exclude_client_id 不给这些client_id发
* @param bool $raw 是否发送原始数据(即不调用gateway的协议的encode方法) * @param bool $raw 是否发送原始数据(即不调用gateway的协议的encode方法)
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
...@@ -146,7 +146,7 @@ class Gateway ...@@ -146,7 +146,7 @@ class Gateway
/** /**
* 向某个client_id对应的连接发消息 * 向某个client_id对应的连接发消息
* *
* @param int $client_id * @param int $client_id
* @param string $message * @param string $message
* @return void * @return void
*/ */
...@@ -798,7 +798,7 @@ class Gateway ...@@ -798,7 +798,7 @@ class Gateway
/** /**
* 踢掉某个客户端,并以$message通知被踢掉客户端 * 踢掉某个客户端,并以$message通知被踢掉客户端
* *
* @param int $client_id * @param int $client_id
* @param string $message * @param string $message
* @return void * @return void
*/ */
...@@ -872,7 +872,7 @@ class Gateway ...@@ -872,7 +872,7 @@ class Gateway
/** /**
* 将 client_id 与 uid 绑定 * 将 client_id 与 uid 绑定
* *
* @param int $client_id * @param int $client_id
* @param int|string $uid * @param int|string $uid
* @return void * @return void
*/ */
...@@ -884,7 +884,7 @@ class Gateway ...@@ -884,7 +884,7 @@ class Gateway
/** /**
* 将 client_id 与 uid 解除绑定 * 将 client_id 与 uid 解除绑定
* *
* @param int $client_id * @param int $client_id
* @param int|string $uid * @param int|string $uid
* @return void * @return void
*/ */
...@@ -896,7 +896,7 @@ class Gateway ...@@ -896,7 +896,7 @@ class Gateway
/** /**
* 将 client_id 加入组 * 将 client_id 加入组
* *
* @param int $client_id * @param int $client_id
* @param int|string $group * @param int|string $group
* @return void * @return void
*/ */
...@@ -909,7 +909,7 @@ class Gateway ...@@ -909,7 +909,7 @@ class Gateway
/** /**
* 将 client_id 离开组 * 将 client_id 离开组
* *
* @param int $client_id * @param int $client_id
* @param int|string $group * @param int|string $group
* *
* @return void * @return void
...@@ -942,7 +942,7 @@ class Gateway ...@@ -942,7 +942,7 @@ class Gateway
* 向所有 uid 发送 * 向所有 uid 发送
* *
* @param int|string|array $uid * @param int|string|array $uid
* @param string $message * @param string $message
* *
* @return void * @return void
*/ */
...@@ -964,10 +964,10 @@ class Gateway ...@@ -964,10 +964,10 @@ class Gateway
/** /**
* 向 group 发送 * 向 group 发送
* *
* @param int|string|array $group 组(不允许是 0 '0' false null array()等为空的值) * @param int|string|array $group 组(不允许是 0 '0' false null array()等为空的值)
* @param string $message 消息 * @param string $message 消息
* @param array $exclude_client_id 不给这些client_id发 * @param array $exclude_client_id 不给这些client_id发
* @param bool $raw 发送原始数据(即不调用gateway的协议的encode方法) * @param bool $raw 发送原始数据(即不调用gateway的协议的encode方法)
* *
* @return void * @return void
*/ */
...@@ -1028,7 +1028,7 @@ class Gateway ...@@ -1028,7 +1028,7 @@ class Gateway
/** /**
* 更新 session,框架自动调用,开发者不要调用 * 更新 session,框架自动调用,开发者不要调用
* *
* @param int $client_id * @param int $client_id
* @param string $session_str * @param string $session_str
* @return bool * @return bool
*/ */
...@@ -1040,7 +1040,7 @@ class Gateway ...@@ -1040,7 +1040,7 @@ class Gateway
/** /**
* 设置 session,原session值会被覆盖 * 设置 session,原session值会被覆盖
* *
* @param int $client_id * @param int $client_id
* @param array $session * @param array $session
* *
* @return void * @return void
...@@ -1057,7 +1057,7 @@ class Gateway ...@@ -1057,7 +1057,7 @@ class Gateway
/** /**
* 更新 session,实际上是与老的session合并 * 更新 session,实际上是与老的session合并
* *
* @param int $client_id * @param int $client_id
* @param array $session * @param array $session
* *
* @return void * @return void
...@@ -1098,8 +1098,8 @@ class Gateway ...@@ -1098,8 +1098,8 @@ class Gateway
/** /**
* 向某个用户网关发送命令和消息 * 向某个用户网关发送命令和消息
* *
* @param int $client_id * @param int $client_id
* @param int $cmd * @param int $cmd
* @param string $message * @param string $message
* @param string $ext_data * @param string $ext_data
* @return boolean * @return boolean
...@@ -1132,7 +1132,7 @@ class Gateway ...@@ -1132,7 +1132,7 @@ class Gateway
/** /**
* 发送数据并返回 * 发送数据并返回
* *
* @param int $address * @param int $address
* @param mixed $data * @param mixed $data
* @return bool * @return bool
* @throws Exception * @throws Exception
...@@ -1186,7 +1186,7 @@ class Gateway ...@@ -1186,7 +1186,7 @@ class Gateway
* 发送数据到网关 * 发送数据到网关
* *
* @param string $address * @param string $address
* @param array $gateway_data * @param array $gateway_data
* @return bool * @return bool
*/ */
protected static function sendToGateway($address, $gateway_data) protected static function sendToGateway($address, $gateway_data)
...@@ -1250,7 +1250,7 @@ class Gateway ...@@ -1250,7 +1250,7 @@ class Gateway
* 踢掉某个网关的 socket * 踢掉某个网关的 socket
* *
* @param string $address * @param string $address
* @param int $connection_id * @param int $connection_id
* @return bool * @return bool
*/ */
protected static function kickAddress($address, $connection_id, $message) protected static function kickAddress($address, $connection_id, $message)
...@@ -1266,7 +1266,7 @@ class Gateway ...@@ -1266,7 +1266,7 @@ class Gateway
* 销毁某个网关的 socket * 销毁某个网关的 socket
* *
* @param string $address * @param string $address
* @param int $connection_id * @param int $connection_id
* @return bool * @return bool
*/ */
protected static function destroyAddress($address, $connection_id) protected static function destroyAddress($address, $connection_id)
......
...@@ -27,6 +27,12 @@ class Session ...@@ -27,6 +27,12 @@ class Session
} }
public static function clearByDeviceId($deviceId)
{
Cache::forget($deviceId);
}
public static function clear() public static function clear()
{ {
$request = app('request'); $request = app('request');
...@@ -67,6 +73,10 @@ class Session ...@@ -67,6 +73,10 @@ class Session
} }
/**
* @param string $key
* @return mixed|string
*/
public static function get($key = '') public static function get($key = '')
{ {
static::init(); static::init();
......
...@@ -24,6 +24,7 @@ use Lib\remote\api\message\FinishByUserMessage; ...@@ -24,6 +24,7 @@ use Lib\remote\api\message\FinishByUserMessage;
use Lib\remote\api\message\PowerExceedMessage; use Lib\remote\api\message\PowerExceedMessage;
use Lib\remote\api\message\SendMessage; use Lib\remote\api\message\SendMessage;
use Lib\remote\api\message\ShedMessage; use Lib\remote\api\message\ShedMessage;
use Lib\Session;
use Lib\StateCode; use Lib\StateCode;
use Lib\station\gateway\port\Port; use Lib\station\gateway\port\Port;
use Src\BroadcastToAgent; use Src\BroadcastToAgent;
...@@ -49,6 +50,7 @@ class ChargerState extends State ...@@ -49,6 +50,7 @@ class ChargerState extends State
'updated_at' => $this->nowDate, 'updated_at' => $this->nowDate,
'end_time' => $this->nowDate, 'end_time' => $this->nowDate,
'state' => 1, 'state' => 1,
'is_exception' => 1,
], 'id=' . $this->order->getId()); ], 'id=' . $this->order->getId());
$port = new Port(); $port = new Port();
...@@ -129,6 +131,7 @@ class ChargerState extends State ...@@ -129,6 +131,7 @@ class ChargerState extends State
'end_capacity' => $this->order->getEndCapacity(), 'end_capacity' => $this->order->getEndCapacity(),
'end_time' => $this->nowDate, 'end_time' => $this->nowDate,
'state' => 1, 'state' => 1,
'is_exception' => 1,
], 'id=' . $this->order->getId()); ], 'id=' . $this->order->getId());
$orderExceptionModel = new OrderExceptionModel(); $orderExceptionModel = new OrderExceptionModel();
...@@ -196,6 +199,7 @@ class ChargerState extends State ...@@ -196,6 +199,7 @@ class ChargerState extends State
'end_time' => $this->nowDate, 'end_time' => $this->nowDate,
'end_capacity' => $this->order->getEndCapacity(), 'end_capacity' => $this->order->getEndCapacity(),
'state' => 1, 'state' => 1,
'is_exception' => 1,
], 'id=' . $this->order->getId()); ], 'id=' . $this->order->getId());
$orderExceptionModel = new OrderExceptionModel(); $orderExceptionModel = new OrderExceptionModel();
...@@ -253,8 +257,9 @@ class ChargerState extends State ...@@ -253,8 +257,9 @@ class ChargerState extends State
$orderModel = new OrderModel(); $orderModel = new OrderModel();
$orderModel->update([ $orderModel->update([
'updated_at' => $this->nowDate, 'updated_at' => $this->nowDate,
'shed_time' => $this->nowDate, 'shed_time' => $this->nowDate,
'is_exception' => 1,
], 'id=' . $this->order->getId()); ], 'id=' . $this->order->getId());
$orderExceptionModel = new OrderExceptionModel(); $orderExceptionModel = new OrderExceptionModel();
...@@ -308,7 +313,7 @@ class ChargerState extends State ...@@ -308,7 +313,7 @@ class ChargerState extends State
'gateway_mac' => $this->order->getGatewayMac(), 'gateway_mac' => $this->order->getGatewayMac(),
'check_times' => 1, 'check_times' => 1,
'gateway_id' => $this->order->getGatewayId(), 'gateway_id' => $this->order->getGatewayId(),
'station_id' => $_SESSION['station_id'], 'station_id' => Session::get('station_id'),
]); ]);
} catch (\Exception $exception) { } catch (\Exception $exception) {
......
...@@ -41,6 +41,7 @@ class ShedState extends State ...@@ -41,6 +41,7 @@ class ShedState extends State
'updated_at' => $this->nowDate, 'updated_at' => $this->nowDate,
'end_time' => $this->nowDate, 'end_time' => $this->nowDate,
'state' => 1, 'state' => 1,
'is_exception' => 1,
], 'id=' . $this->order->getId()); ], 'id=' . $this->order->getId());
$port = new Port(); $port = new Port();
...@@ -181,6 +182,7 @@ class ShedState extends State ...@@ -181,6 +182,7 @@ class ShedState extends State
'end_time' => $this->nowDate, 'end_time' => $this->nowDate,
'is_stop' => StateCode::FINISH_SHED_TIMEOUT, 'is_stop' => StateCode::FINISH_SHED_TIMEOUT,
'end_capacity' => $this->order->getEndCapacity(), 'end_capacity' => $this->order->getEndCapacity(),
'is_exception' => 1,
], 'id=' . $this->order->getId()); ], 'id=' . $this->order->getId());
......
...@@ -76,8 +76,10 @@ class AccessToken implements Request ...@@ -76,8 +76,10 @@ class AccessToken implements Request
// $redis->del(self::ACCESS_CACHE_KEY); // $redis->del(self::ACCESS_CACHE_KEY);
// $redis->del(self::REFRESH_ACCESS_CACHE_KEY); // $redis->del(self::REFRESH_ACCESS_CACHE_KEY);
if ($redis->exists(self::ACCESS_CACHE_KEY) == true) { if ($redis->exists(self::ACCESS_CACHE_KEY) == true) {
return $redis->get(self::ACCESS_CACHE_KEY); return $redis->get(self::ACCESS_CACHE_KEY);
} else if ($redis->exists(self::REFRESH_ACCESS_CACHE_KEY) === true) { } else if ($redis->exists(self::REFRESH_ACCESS_CACHE_KEY) === true) {
//todo refresh 换取token 并缓存新的token和新的refresh //todo refresh 换取token 并缓存新的token和新的refresh
...@@ -92,9 +94,13 @@ class AccessToken implements Request ...@@ -92,9 +94,13 @@ class AccessToken implements Request
} else { } else {
//todo 请求token //todo 请求token
$accessToken = new AccessToken(); $accessToken = new AccessToken();
$iotClient = new IotClient($accessToken); $iotClient = new IotClient($accessToken);
if ($iotClient->request() === true) { if ($iotClient->request() === true) {
$accessToken->parseResponse($iotClient->getResponse()); $accessToken->parseResponse($iotClient->getResponse());
return $accessToken->getAccessToken(); return $accessToken->getAccessToken();
......
...@@ -36,6 +36,8 @@ class IotClient ...@@ -36,6 +36,8 @@ class IotClient
public function setDefaultHeader() public function setDefaultHeader()
{ {
$this->headers = [ $this->headers = [
'app_key' => env('IOT_APP_ID'), 'app_key' => env('IOT_APP_ID'),
...@@ -64,6 +66,7 @@ class IotClient ...@@ -64,6 +66,7 @@ class IotClient
'IoM@1234', 'IoM@1234',
] ]
]; ];
if (filled($this->headers) === true) { if (filled($this->headers) === true) {
$request['headers'] = $this->headers; $request['headers'] = $this->headers;
} }
...@@ -74,8 +77,18 @@ class IotClient ...@@ -74,8 +77,18 @@ class IotClient
$this->response = $client->request($this->request->getMethod(), config('iot.host') . $this->request->getUrl(), $request); $this->response = $client->request($this->request->getMethod(), config('iot.host') . $this->request->getUrl(), $request);
} else { } else {
$request['json'] = $this->request->getFormData(); $request['json'] = $this->request->getFormData();
Log::debug($this->request->getFormData());
$this->response = $client->request($this->request->getMethod(), config('iot.host') . $this->request->getUrl(), $request); $this->response = $client->request($this->request->getMethod(), config('iot.host') . $this->request->getUrl(), $request);
} }
Log::debug('reponse');
Log::debug($this->response->getBody());
return $this->response->getStatusCode() === $returnCode; return $this->response->getStatusCode() === $returnCode;
} }
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/12/27
* Time: 下午6:21
*/
namespace Lib\iot\command;
class RemoteUpdate
{
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/12/23
* Time: 下午7:42
*/
namespace Lib\iot\update;
use Lib\iot\Request;
use Psr\Http\Message\ResponseInterface;
class QuerySoftware implements Request
{
private $version = '';
private $fileId = '';
public function getReturnCode(): int
{
return 200;
}
public function getUrl(): string
{
return 'iodm/northbound/v1.5.0/category';
}
public function getMethod(): string
{
return 'GET';
}
public function getFormData(): array
{
return [
'fileType' => 'softwarePackage'
];
}
public function parseResponse(ResponseInterface $response)
{
$body = json_decode($response->getBody(), true);
$this->version = isset($body['data'][0]['version']) ? $body['data'][0]['version'] : '';
$this->fileId = isset($body['data'][0]['fileId']) ? $body['data'][0]['fileId'] : '';
}
public function isJson(): bool
{
return false;
}
/**
* @return string
*/
public function getVersion(): string
{
return $this->version;
}
/**
* @param string $version
*/
public function setVersion(string $version): void
{
$this->version = $version;
}
/**
* @return string
*/
public function getFileId(): string
{
return $this->fileId;
}
/**
* @param string $fileId
*/
public function setFileId(string $fileId): void
{
$this->fileId = $fileId;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/12/23
* Time: 下午6:26
*/
namespace Lib\iot\update;
use Lib\iot\Request;
use Psr\Http\Message\ResponseInterface;
class Software implements Request
{
private $devices = [];
private $isRightNow = true;
private $startTime = 0;
private $fileId = '';
private $url = 'iodm/northbound/v1.5.0/operations/softwareUpgrade';
public function getReturnCode(): int
{
return 200;
}
public function getUrl(): string
{
return $this->url;
// TODO: Implement getUrl() method.
}
public function getMethod(): string
{
return 'POST';
// TODO: Implement getMethod() method.
}
public function getFormData(): array
{
$targets =
[
'devices' => $this->devices,
];
if ($this->isRightNow === true) {
$policy = [
'executeType' => 'now',
'retryType' => true,
'retryTimes' => 2,
];
} else {
$policy = [
'executeType' => 'custom',
'startTime' => date('Ymd\THis\Z', $this->startTime),
'endTime' => date('Ymd\THis\Z', $this->startTime + 3600),
'retryType' => true,
'retryTimes' => 2,
];
}
return [
'fileId' => $this->fileId,
'targets' => $targets,
'policy' => $policy,
];
}
public function parseResponse(ResponseInterface $response)
{
// TODO: Implement parseResponse() method.
}
public function isJson(): bool
{
return true;
}
/**
* @return array
*/
public function getDevices(): array
{
return $this->devices;
}
/**
* @param array $devices
*/
public function setDevices(array $devices): void
{
$this->devices = $devices;
}
/**
* @return string
*/
public function getFileId(): string
{
return $this->fileId;
}
/**
* @param string $fileId
*/
public function setFileId(string $fileId): void
{
$this->fileId = $fileId;
}
/**
* @return bool
*/
public function isRightNow(): bool
{
return $this->isRightNow;
}
/**
* @param bool $isRightNow
*/
public function setIsRightNow(bool $isRightNow): void
{
$this->isRightNow = $isRightNow;
}
/**
* @return int
*/
public function getStartTime(): int
{
return $this->startTime;
}
/**
* @param int $startTime
*/
public function setStartTime(int $startTime): void
{
$this->startTime = $startTime;
}
}
\ No newline at end of file
...@@ -62,9 +62,8 @@ class Gateway ...@@ -62,9 +62,8 @@ class Gateway
$port->updatePortState(); $port->updatePortState();
$usingOrderId = $port->getPortUsingOrderId(); $usingOrderId = $port->getPortUsingOrderId();
Log::debug($usingOrderId . 'using'); Log::debug($usingOrderId);
if (filled($usingOrderId) && $usingOrderId !== false) {
if (filled($usingOrderId)) {
$order = new Order($usingOrderId); $order = new Order($usingOrderId);
$order->setOfflineTime($offlineTime); $order->setOfflineTime($offlineTime);
$orderRedis = new OrderSaveRedis($order); $orderRedis = new OrderSaveRedis($order);
......
...@@ -118,7 +118,9 @@ class Port ...@@ -118,7 +118,9 @@ class Port
{ {
$redis = app('Redis'); $redis = app('Redis');
return $redis->hGet(self::USING_ORDER_ID, $this->portId); if ($redis instanceof \Redis) {
return $redis->hGet(self::USING_ORDER_ID, $this->portId);
}
} }
......
...@@ -48,6 +48,12 @@ $router->get('gateway', 'SessionController@getSession'); ...@@ -48,6 +48,12 @@ $router->get('gateway', 'SessionController@getSession');
$router->post('gateway/offline', ['uses' => 'device\StateController@offline', 'as' => 'deviceStateOffline']); $router->post('gateway/offline', ['uses' => 'device\StateController@offline', 'as' => 'deviceStateOffline']);
$router->post('gateway/update', 'update\UpdateController@update');
$router->get('test', 'TestController@test');
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/12/27
* Time: 下午6:27
*/
namespace Src\command;
class UpdateCommand implements Command
{
public function getMessage(): string
{
// TODO: Implement getMessage() method.
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment