Commit 29a8f66c by banice

添加ota升级

parent 033229d4
......@@ -81,8 +81,6 @@ class Events
return;
}
Log::debug($message);
$command = substr($message, 6, 2);
$api = new Api();
$api->boot();
......
......@@ -32,7 +32,7 @@ class AccessController extends Controller
],
'03' => [
'logic_start' => 1,
'count' => 1,
'count' => 1,
'total_count' => 1,
]
];
......@@ -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
......@@ -56,6 +144,9 @@ class AccessController extends Controller
{
$mac = $this->request->get('mac');
Gateway::bindUid($this->clientId, $mac);
$_SESSION['gateway_mac'] = $mac;
$gatewayModel = new GatewayModel();
......
......@@ -11,6 +11,7 @@ namespace Application\controller\accept;
use Application\controller\Controller;
use Application\model\DeviceModel;
use Application\model\GatewayModel;
use Lib\Aes;
use GatewayWorker\Lib\Gateway;
use Src\route\Route;
......@@ -52,6 +53,28 @@ class CertifyController extends Controller
$_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';
$sign = bin2hex(Aes::encrypt($nonce, $productId));
......
......@@ -50,6 +50,9 @@ class StartController extends Controller
$this->logRecord->setOrderId($orderId);
$capacity = hexdec($this->getRequest()->get('capacity'));
Log::debug($this->getRequest()->get('capacity'));
Log::debug('capacity-->' . $capacity);
if ($type == 1) {
......@@ -77,7 +80,6 @@ class StartController extends Controller
$clientsId = Gateway::getClientIdByUid($_SESSION['agent_id']);
$clientId = $clientsId[0];
$uIds = Gateway::getUidByClientId($clientId);
var_dump($uIds);
Gateway::sendToUid($_SESSION['agent_id'], json_encode($order->getOrderCache(\Events::getRedis())));
} else {
......@@ -86,9 +88,6 @@ class StartController extends Controller
}
$lastState = $order->getStateCode();
// switch ($lastState) {
// case StateCode::WAITING:
$orderState = new WaitingState($order);
// break;
// case StateCode::PORT_CHARGER;
......
......@@ -25,14 +25,14 @@ class PowerController extends Controller
'17' => [
'logic_id' => 1,
'power' => 2,
'power' => 2,
'capacity' => 4,
],
'07' => [
'logic_id' => 1,
'start_time' => 4,
'logic_id' => 1,
'start_time' => 4,
'interval_time' => 1,
'count' => 1,
'count' => 1,
]
];
......@@ -91,10 +91,10 @@ class PowerController extends Controller
$orderPowerModel = new OrderPowerModel();
$orderPowerModel->insertRow([
'order_id' => $orderId,
'capacity' => $capacity,
'power' => $power,
'port_id' => $portId,
'order_id' => $orderId,
'capacity' => $capacity,
'power' => $power,
'port_id' => $portId,
'created_at' => date('Y-m-d H:i:s'),
]);
......@@ -113,24 +113,34 @@ class PowerController extends Controller
$logicId = hexdec($this->request->get('logic_id'));
$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'));
$powers = substr($this->message, $this->plc, $count * 4);
Log::debug($powers);
$this->plc += ($count * 4);
$capacitys = substr($this->message, $this->plc, $count * 8);
Log::debug($capacitys);
$powers = str_split($powers, 4);
$capacitys = str_split($capacitys, 8);
Log::debug('count -> ' . $count);
Log::debug('powers', $powers);
Log::debug('capacitys', $capacitys);
if (count($powers) != $count || count($capacitys) != $count) {
Log::error('plural miss power or capacity,less than count ');
return;
}
$portsLogicId = array_flip($_SESSION['port_logic_id']);
$portsLogicId = $_SESSION['port_logic_id'];
if (isset($portsLogicId[$logicId])) {
$portId = $portsLogicId[$logicId];
......@@ -141,25 +151,30 @@ class PowerController extends Controller
Log::error('power data can not find order_id', [
'logic_id' => $logicId,
'message' => $this->message,
'message' => $this->message,
]);
return;
}
$this->logRecord->setPortId($portId);
$this->logRecord->setOrderId($orderId);
$orderPowerModel = new OrderPowerModel();
Log::debug('order_id->' . $orderId);
for ($i = 0; $i < $count; $i++) {
$orderPowerModel->insertRow([
'created_at' => date('Y-m-d H:i:s', $startTime),
'order_id' => $orderId,
'port_id' => $portId,
'power' => $powers[$i],
'capacity' => $capacitys[$i],
'order_id' => $orderId,
'port_id' => $portId,
'power' => hexdec($powers[$i]),
'capacity' => hexdec($capacitys[$i]),
]);
$startTime += $intervalTime;
}
} else {
Log::error('can not find port_id by logic_id from session', [$portsLogicId]);
}
}
......
......@@ -54,10 +54,12 @@ class QueryController extends Controller
}
$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) {
$updateHardwareVersion = $updateInfo['hardware_version'];
$sign = $updateInfo['sign'];
// $updateSoftwareVersion = sprintf('%08x', $updateInfo['software_version']);
$updateSoftwareVersion = sprintf($updateInfo['software_version']);
......@@ -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
/**
* @var int
*/
private $startCapacity = -1;
private $startCapacity = -2;
/**
......
......@@ -56,9 +56,9 @@ class WaitingState extends State
$orderModel = new OrderModel();
$orderModel->update([
'is_stop' => StateCode::FINISH_REFUND,
'is_stop' => StateCode::FINISH_REFUND,
'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());
$port = new Port();
......@@ -86,7 +86,7 @@ class WaitingState extends State
{
//订单已经退款则直接结束
if ($this->order->getIsRefund() == 1) {
//todo 下发结束充电命令
// 下发结束充电命令
$orderId = $this->order->getId();
$portLogic = $this->order->getPortLogicId();
$finishType = 43;
......@@ -133,8 +133,8 @@ class WaitingState extends State
//更新订单状态
$update = [
'is_charger' => StateCode::PORT_CHARGER,
'start_time' => date('Y-m-d H:i:s', $this->order->getStartTime()),
'is_charger' => StateCode::PORT_CHARGER,
'start_time' => date('Y-m-d H:i:s', $this->order->getStartTime()),
'start_capacity' => $this->order->getStartCapacity(),
];
$orderModel = new OrderModel();
......@@ -146,9 +146,9 @@ class WaitingState extends State
//添加订单异常
$orderExceptionModel->insertRow([
'order_id' => $this->order->getId(),
'state' => '-1' . StateCode::PORT_CHARGER,
'desc' => '开始充电',
'order_id' => $this->order->getId(),
'state' => '-1' . StateCode::PORT_CHARGER,
'desc' => '开始充电',
'created_at' => date('Y-m-d H:i:s', $this->order->getStartTime()),
]);
......@@ -171,9 +171,9 @@ class WaitingState extends State
$orderExceptionModel = new OrderExceptionModel();
$orderExceptionModel->insertRow([
'order_id' => $this->order->getId(),
'state' => '-1' . StateCode::PORT_EXCEPTION,
'desc' => '打开口子失败',
'order_id' => $this->order->getId(),
'state' => '-1' . StateCode::PORT_EXCEPTION,
'desc' => '打开口子失败',
'created_at' => date('Y-m-d H:i:s'),
]);
//推送消息
......@@ -199,7 +199,7 @@ class WaitingState extends State
$broadcastToAgent = new BroadcastToAgent();
$broadcastToAgent->broadcast([
'data' => $this->order->getOrderCache(\Events::getRedis()),
'data' => $this->order->getOrderCache(\Events::getRedis()),
'notice_exception_code' => StateCode::PORT_EXCEPTION,
]);
......@@ -230,8 +230,16 @@ class WaitingState extends State
$orderSave->save(['stateCode']);
$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()
......
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