Commit 29a8f66c by banice

添加ota升级

parent 033229d4
...@@ -81,8 +81,6 @@ class Events ...@@ -81,8 +81,6 @@ class Events
return; return;
} }
Log::debug($message);
$command = substr($message, 6, 2); $command = substr($message, 6, 2);
$api = new Api(); $api = new Api();
$api->boot(); $api->boot();
......
...@@ -48,6 +48,94 @@ class AccessController extends Controller ...@@ -48,6 +48,94 @@ class AccessController extends Controller
} }
private function test($mac)
{
Gateway::bindUid($this->clientId, $mac);
$_SESSION['gateway_mac'] = $mac;
$gatewayModel = new GatewayModel();
if (isset($_SESSION['gateway_mac'])) {
if ($_SESSION['gateway_mac'] != $mac) {
Gateway::closeClient($this->clientId);
}
$gatewayModelResult = $gatewayModel->getColumns([
'station_id',
'id',
'name',
'type_id'
], 'mac_address = ' . "'$mac'");
if ($gatewayModelResult == false) {
Gateway::closeClient($this->clientId);
return;
}
$stationId = $gatewayModelResult['station_id'];
$gatewayId = $gatewayModelResult['id'];
$_SESSION['gateway_name'] = $gatewayModelResult['name'];
$_SESSION['gateway_id'] = $gatewayModelResult['id'];
$_SESSION['gateway_type'] = $gatewayModelResult['type_id'];
$stationModel = new StationModel();
$stationData = $stationModel->getColumns([
'park_id',
'name',
], 'id = ' . $stationId);
if (isset($stationData['park_id']) && isset($stationData['name'])) {
$parkId = $stationData['park_id'];
$_SESSION['station_name'] = $stationData['name'];
if (isset($parkId)) {
$parkModel = new ParkModel();
$_SESSION['park_id'] = $parkId;
$agentId = $parkModel->getColumn('agent_id', 'id = ' . $parkId);
if (isset($agentId)) {
$_SESSION['agent_id'] = $agentId;
}
}
}
$deviceModel = new DeviceModel();
$deviceModelResult = $deviceModel->getAllColumns([
'id',
'device_mac',
'name',
], 'gateway_id = ' . $gatewayId);
$tmp = [];
$portsIdName = [];
foreach ($deviceModelResult as $item) {
$tmp[$item['device_mac']] = $item['id'];
$portsIdName[$item['id']] = $item['name'];
}
$_SESSION['port_id_name'] = $portsIdName;
$_SESSION['port_mac_id'] = $tmp;
$_SESSION['port_id_mac'] = array_flip($tmp);
$_SESSION['station_id'] = $stationId;
$_SESSION['gateway_id'] = $gatewayId;
$_SESSION['client_id'] = $this->clientId;
}
}
/** /**
* 请求入网 * 请求入网
* 网关下的所有端口id和mac写如session * 网关下的所有端口id和mac写如session
...@@ -56,6 +144,9 @@ class AccessController extends Controller ...@@ -56,6 +144,9 @@ class AccessController extends Controller
{ {
$mac = $this->request->get('mac'); $mac = $this->request->get('mac');
Gateway::bindUid($this->clientId, $mac);
$_SESSION['gateway_mac'] = $mac; $_SESSION['gateway_mac'] = $mac;
$gatewayModel = new GatewayModel(); $gatewayModel = new GatewayModel();
......
...@@ -11,6 +11,7 @@ namespace Application\controller\accept; ...@@ -11,6 +11,7 @@ namespace Application\controller\accept;
use Application\controller\Controller; use Application\controller\Controller;
use Application\model\DeviceModel; use Application\model\DeviceModel;
use Application\model\GatewayModel;
use Lib\Aes; use Lib\Aes;
use GatewayWorker\Lib\Gateway; use GatewayWorker\Lib\Gateway;
use Src\route\Route; use Src\route\Route;
...@@ -52,6 +53,28 @@ class CertifyController extends Controller ...@@ -52,6 +53,28 @@ class CertifyController extends Controller
$_SESSION['certified'] = true; $_SESSION['certified'] = true;
$gatewayModel = new GatewayModel();
$gatewayModelResult = $gatewayModel->getColumns([
'station_id',
'id',
'name',
'type_id'
], 'mac_address = ' . "'$mac'");
if ($gatewayModelResult == false) {
Gateway::closeClient($this->clientId);
return;
}
$stationId = $gatewayModelResult['station_id'];
$gatewayId = $gatewayModelResult['id'];
$_SESSION['station_id'] = $stationId;
$_SESSION['gateway_id'] = $gatewayId;
$productId = 'A22E4F4CDB05C460E450E46241DD6F89'; $productId = 'A22E4F4CDB05C460E450E46241DD6F89';
$sign = bin2hex(Aes::encrypt($nonce, $productId)); $sign = bin2hex(Aes::encrypt($nonce, $productId));
......
...@@ -50,6 +50,9 @@ class StartController extends Controller ...@@ -50,6 +50,9 @@ class StartController extends Controller
$this->logRecord->setOrderId($orderId); $this->logRecord->setOrderId($orderId);
$capacity = hexdec($this->getRequest()->get('capacity')); $capacity = hexdec($this->getRequest()->get('capacity'));
Log::debug($this->getRequest()->get('capacity'));
Log::debug('capacity-->' . $capacity);
if ($type == 1) { if ($type == 1) {
...@@ -77,7 +80,6 @@ class StartController extends Controller ...@@ -77,7 +80,6 @@ class StartController extends Controller
$clientsId = Gateway::getClientIdByUid($_SESSION['agent_id']); $clientsId = Gateway::getClientIdByUid($_SESSION['agent_id']);
$clientId = $clientsId[0]; $clientId = $clientsId[0];
$uIds = Gateway::getUidByClientId($clientId); $uIds = Gateway::getUidByClientId($clientId);
var_dump($uIds);
Gateway::sendToUid($_SESSION['agent_id'], json_encode($order->getOrderCache(\Events::getRedis()))); Gateway::sendToUid($_SESSION['agent_id'], json_encode($order->getOrderCache(\Events::getRedis())));
} else { } else {
...@@ -86,9 +88,6 @@ class StartController extends Controller ...@@ -86,9 +88,6 @@ class StartController extends Controller
} }
$lastState = $order->getStateCode(); $lastState = $order->getStateCode();
// switch ($lastState) {
// case StateCode::WAITING:
$orderState = new WaitingState($order); $orderState = new WaitingState($order);
// break; // break;
// case StateCode::PORT_CHARGER; // case StateCode::PORT_CHARGER;
......
...@@ -113,24 +113,34 @@ class PowerController extends Controller ...@@ -113,24 +113,34 @@ class PowerController extends Controller
$logicId = hexdec($this->request->get('logic_id')); $logicId = hexdec($this->request->get('logic_id'));
$startTime = hexdec($this->request->get('start_time')); $startTime = hexdec($this->request->get('start_time'));
$intervalTime = hexdec($this->request->get('interval_time')) * 60; $intervalTime = hexdec($this->request->get('interval_time'));
$count = hexdec($this->request->get('count')); $count = hexdec($this->request->get('count'));
$powers = substr($this->message, $this->plc, $count * 4); $powers = substr($this->message, $this->plc, $count * 4);
Log::debug($powers);
$this->plc += ($count * 4); $this->plc += ($count * 4);
$capacitys = substr($this->message, $this->plc, $count * 8); $capacitys = substr($this->message, $this->plc, $count * 8);
Log::debug($capacitys);
$powers = str_split($powers, 4); $powers = str_split($powers, 4);
$capacitys = str_split($capacitys, 8); $capacitys = str_split($capacitys, 8);
Log::debug('count -> ' . $count);
Log::debug('powers', $powers);
Log::debug('capacitys', $capacitys);
if (count($powers) != $count || count($capacitys) != $count) { if (count($powers) != $count || count($capacitys) != $count) {
Log::error('plural miss power or capacity,less than count '); Log::error('plural miss power or capacity,less than count ');
return; return;
} }
$portsLogicId = array_flip($_SESSION['port_logic_id']); $portsLogicId = $_SESSION['port_logic_id'];
if (isset($portsLogicId[$logicId])) { if (isset($portsLogicId[$logicId])) {
$portId = $portsLogicId[$logicId]; $portId = $portsLogicId[$logicId];
...@@ -148,18 +158,23 @@ class PowerController extends Controller ...@@ -148,18 +158,23 @@ class PowerController extends Controller
$this->logRecord->setPortId($portId); $this->logRecord->setPortId($portId);
$this->logRecord->setOrderId($orderId); $this->logRecord->setOrderId($orderId);
$orderPowerModel = new OrderPowerModel(); $orderPowerModel = new OrderPowerModel();
Log::debug('order_id->' . $orderId);
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$orderPowerModel->insertRow([ $orderPowerModel->insertRow([
'created_at' => date('Y-m-d H:i:s', $startTime), 'created_at' => date('Y-m-d H:i:s', $startTime),
'order_id' => $orderId, 'order_id' => $orderId,
'port_id' => $portId, 'port_id' => $portId,
'power' => $powers[$i], 'power' => hexdec($powers[$i]),
'capacity' => $capacitys[$i], 'capacity' => hexdec($capacitys[$i]),
]); ]);
$startTime += $intervalTime; $startTime += $intervalTime;
} }
} else {
Log::error('can not find port_id by logic_id from session', [$portsLogicId]);
} }
} }
......
...@@ -54,10 +54,12 @@ class QueryController extends Controller ...@@ -54,10 +54,12 @@ class QueryController extends Controller
} }
$gatewayUpdateModel = new GatewayUpdateModel(); $gatewayUpdateModel = new GatewayUpdateModel();
$updateInfo = $gatewayUpdateModel->getColumns(['hardware_version', 'software_version'], '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'];
$sign = $updateInfo['sign'];
// $updateSoftwareVersion = sprintf('%08x', $updateInfo['software_version']); // $updateSoftwareVersion = sprintf('%08x', $updateInfo['software_version']);
$updateSoftwareVersion = sprintf($updateInfo['software_version']); $updateSoftwareVersion = sprintf($updateInfo['software_version']);
...@@ -84,7 +86,7 @@ class QueryController extends Controller ...@@ -84,7 +86,7 @@ class QueryController extends Controller
} }
$this->response->send('d1', $returnCode . $updateHardwareVersion . $updateSoftwareVersion . $urlHex); $this->response->send('d1', $returnCode . $updateHardwareVersion . $updateSoftwareVersion . $sign . $urlHex);
} }
} }
......
...@@ -127,7 +127,7 @@ class Order ...@@ -127,7 +127,7 @@ class Order
/** /**
* @var int * @var int
*/ */
private $startCapacity = -1; private $startCapacity = -2;
/** /**
......
...@@ -86,7 +86,7 @@ class WaitingState extends State ...@@ -86,7 +86,7 @@ class WaitingState extends State
{ {
//订单已经退款则直接结束 //订单已经退款则直接结束
if ($this->order->getIsRefund() == 1) { if ($this->order->getIsRefund() == 1) {
//todo 下发结束充电命令 // 下发结束充电命令
$orderId = $this->order->getId(); $orderId = $this->order->getId();
$portLogic = $this->order->getPortLogicId(); $portLogic = $this->order->getPortLogicId();
$finishType = 43; $finishType = 43;
...@@ -230,8 +230,16 @@ class WaitingState extends State ...@@ -230,8 +230,16 @@ class WaitingState extends State
$orderSave->save(['stateCode']); $orderSave->save(['stateCode']);
$orderSave->deleteHashKey(['startTime', 'startCapacity']); $orderSave->deleteHashKey(['startTime', 'startCapacity']);
$orderModel = new OrderModel();
Log::debug('waiting to shed' . $this->order->getStartCapacity());
$orderModel->update([
'start_capacity' => (int)$this->order->getStartCapacity(),
], 'id = ' . $this->order->getId());
Log::debug('update shed start_capacity' . $this->order->getId());
Log::error('waiting state can not change to shed state');
} }
public function toShedTimeoutState() public function toShedTimeoutState()
......
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