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();
......
...@@ -32,7 +32,7 @@ class AccessController extends Controller ...@@ -32,7 +32,7 @@ class AccessController extends Controller
], ],
'03' => [ '03' => [
'logic_start' => 1, 'logic_start' => 1,
'count' => 1, 'count' => 1,
'total_count' => 1, 'total_count' => 1,
] ]
]; ];
...@@ -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;
......
...@@ -25,14 +25,14 @@ class PowerController extends Controller ...@@ -25,14 +25,14 @@ class PowerController extends Controller
'17' => [ '17' => [
'logic_id' => 1, 'logic_id' => 1,
'power' => 2, 'power' => 2,
'capacity' => 4, 'capacity' => 4,
], ],
'07' => [ '07' => [
'logic_id' => 1, 'logic_id' => 1,
'start_time' => 4, 'start_time' => 4,
'interval_time' => 1, 'interval_time' => 1,
'count' => 1, 'count' => 1,
] ]
]; ];
...@@ -91,10 +91,10 @@ class PowerController extends Controller ...@@ -91,10 +91,10 @@ class PowerController extends Controller
$orderPowerModel = new OrderPowerModel(); $orderPowerModel = new OrderPowerModel();
$orderPowerModel->insertRow([ $orderPowerModel->insertRow([
'order_id' => $orderId, 'order_id' => $orderId,
'capacity' => $capacity, 'capacity' => $capacity,
'power' => $power, 'power' => $power,
'port_id' => $portId, 'port_id' => $portId,
'created_at' => date('Y-m-d H:i:s'), 'created_at' => date('Y-m-d H:i:s'),
]); ]);
...@@ -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];
...@@ -141,25 +151,30 @@ class PowerController extends Controller ...@@ -141,25 +151,30 @@ class PowerController extends Controller
Log::error('power data can not find order_id', [ Log::error('power data can not find order_id', [
'logic_id' => $logicId, 'logic_id' => $logicId,
'message' => $this->message, 'message' => $this->message,
]); ]);
return; return;
} }
$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;
/** /**
......
...@@ -56,9 +56,9 @@ class WaitingState extends State ...@@ -56,9 +56,9 @@ class WaitingState extends State
$orderModel = new OrderModel(); $orderModel = new OrderModel();
$orderModel->update([ $orderModel->update([
'is_stop' => StateCode::FINISH_REFUND, 'is_stop' => StateCode::FINISH_REFUND,
'end_capacity' => $this->order->getEndCapacity(), 'end_capacity' => $this->order->getEndCapacity(),
'end_time' => date('Y-m-d H:i:s'), 'end_time' => date('Y-m-d H:i:s'),
], 'id = ' . $this->order->getId()); ], 'id = ' . $this->order->getId());
$port = new Port(); $port = new Port();
...@@ -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;
...@@ -133,8 +133,8 @@ class WaitingState extends State ...@@ -133,8 +133,8 @@ class WaitingState extends State
//更新订单状态 //更新订单状态
$update = [ $update = [
'is_charger' => StateCode::PORT_CHARGER, 'is_charger' => StateCode::PORT_CHARGER,
'start_time' => date('Y-m-d H:i:s', $this->order->getStartTime()), 'start_time' => date('Y-m-d H:i:s', $this->order->getStartTime()),
'start_capacity' => $this->order->getStartCapacity(), 'start_capacity' => $this->order->getStartCapacity(),
]; ];
$orderModel = new OrderModel(); $orderModel = new OrderModel();
...@@ -146,9 +146,9 @@ class WaitingState extends State ...@@ -146,9 +146,9 @@ class WaitingState extends State
//添加订单异常 //添加订单异常
$orderExceptionModel->insertRow([ $orderExceptionModel->insertRow([
'order_id' => $this->order->getId(), 'order_id' => $this->order->getId(),
'state' => '-1' . StateCode::PORT_CHARGER, 'state' => '-1' . StateCode::PORT_CHARGER,
'desc' => '开始充电', 'desc' => '开始充电',
'created_at' => date('Y-m-d H:i:s', $this->order->getStartTime()), 'created_at' => date('Y-m-d H:i:s', $this->order->getStartTime()),
]); ]);
...@@ -171,9 +171,9 @@ class WaitingState extends State ...@@ -171,9 +171,9 @@ class WaitingState extends State
$orderExceptionModel = new OrderExceptionModel(); $orderExceptionModel = new OrderExceptionModel();
$orderExceptionModel->insertRow([ $orderExceptionModel->insertRow([
'order_id' => $this->order->getId(), 'order_id' => $this->order->getId(),
'state' => '-1' . StateCode::PORT_EXCEPTION, 'state' => '-1' . StateCode::PORT_EXCEPTION,
'desc' => '打开口子失败', 'desc' => '打开口子失败',
'created_at' => date('Y-m-d H:i:s'), 'created_at' => date('Y-m-d H:i:s'),
]); ]);
//推送消息 //推送消息
...@@ -199,7 +199,7 @@ class WaitingState extends State ...@@ -199,7 +199,7 @@ class WaitingState extends State
$broadcastToAgent = new BroadcastToAgent(); $broadcastToAgent = new BroadcastToAgent();
$broadcastToAgent->broadcast([ $broadcastToAgent->broadcast([
'data' => $this->order->getOrderCache(\Events::getRedis()), 'data' => $this->order->getOrderCache(\Events::getRedis()),
'notice_exception_code' => StateCode::PORT_EXCEPTION, 'notice_exception_code' => StateCode::PORT_EXCEPTION,
]); ]);
...@@ -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