Commit fa8cd04d by BANice

修改同步口子时同步订单完成,未测试,修改了口子状态脱落检测与上次脱落时间是否超过十分钟未完成

parent 19488bd7
...@@ -11,6 +11,7 @@ namespace Application\Controller; ...@@ -11,6 +11,7 @@ namespace Application\Controller;
use Application\Controller; use Application\Controller;
use Application\Model\GatewayModel; use Application\Model\GatewayModel;
use Application\Model\OrderModel;
use Application\Model\PortModel; use Application\Model\PortModel;
use Application\Model\StationModel; use Application\Model\StationModel;
use GatewayWorker\Lib\Gateway; use GatewayWorker\Lib\Gateway;
...@@ -129,9 +130,7 @@ class AccessController extends Controller ...@@ -129,9 +130,7 @@ class AccessController extends Controller
public function syncPort() public function syncPort()
{ {
Log::debug('端口同步', $this->getRequest()->getParameters()); Log::debug('端口同步');
Log::debug($this->message);
$startLogicNum = $this->get('start_num'); $startLogicNum = $this->get('start_num');
...@@ -157,6 +156,13 @@ class AccessController extends Controller ...@@ -157,6 +156,13 @@ class AccessController extends Controller
$portMacId = isset($_SESSION['port_mac_id']) ? $_SESSION['port_mac_id'] : []; $portMacId = isset($_SESSION['port_mac_id']) ? $_SESSION['port_mac_id'] : [];
//口子的逻辑地址和id映射缓存到session 中
foreach ($macLogicArray as $mac => $logic) {
if (isset($portMacId[$mac])) {
$_SESSION['logic_port_id'][$logic] = $portMacId[$mac];
}
}
$port = new port(); $port = new port();
$portIdState = []; $portIdState = [];
...@@ -170,6 +176,7 @@ class AccessController extends Controller ...@@ -170,6 +176,7 @@ class AccessController extends Controller
foreach ($macLogicArray as $mac => $logic)//将端口状态和端口逻辑地址更新至数据库中 foreach ($macLogicArray as $mac => $logic)//将端口状态和端口逻辑地址更新至数据库中
{ {
if (isset($portMacId[$mac])) { if (isset($portMacId[$mac])) {
$portId = $portMacId[$mac]; $portId = $portMacId[$mac];
$redis->hSet(RedisKey::PORT_ID_LOGIC_HASH, $portId, (int)$logic); $redis->hSet(RedisKey::PORT_ID_LOGIC_HASH, $portId, (int)$logic);
...@@ -192,6 +199,9 @@ class AccessController extends Controller ...@@ -192,6 +199,9 @@ class AccessController extends Controller
$redis->exec(); $redis->exec();
Log::debug('口子状态', $portIdState
);
$port->setPortState($portIdState); //改变口子状态 $port->setPortState($portIdState); //改变口子状态
...@@ -202,7 +212,74 @@ class AccessController extends Controller ...@@ -202,7 +212,74 @@ class AccessController extends Controller
} }
return $this->response->send('03', $startLogicNum . $count . $totalCount); $responseOrder = [];
$time = time();
foreach ($portIdState as $id => $state) {
$port->setId($id);
$orderId = $port->getPortUsingOrderId($redis, $id);
var_dump($orderId);
if (isset($orderId) === false || $orderId === false || $orderId == 0) {
continue;
} else {
$orderModel = new OrderModel();
$orderInfo = $orderModel->getColumns(['charger_time', 'created_at', 'logic_num'], 'id = ' . $orderId);
$createdTime = $orderInfo['created_at'];
$chargerTime = $orderInfo['charger_time'];
if (($chargerTime + strtotime($createdTime) < $time)) {
continue;
} else {
$chargerTime = ceil($chargerTime - ($time - strtotime($createdTime)));
$chargerTime = (int)$chargerTime;
if ($chargerTime > 0) {
array_push($responseOrder, [
sprintf('%02x', $orderInfo['logic_num']),
sprintf('%012x', $orderId),
sprintf('%04x', $chargerTime),
]);
}
}
}
}
$orderCount = sprintf('%02x',count($responseOrder));
$responseOrderMessage = '';
foreach ($responseOrder as $order) {
$responseOrderMessage.=implode('',$order);
}
Log::debug($orderCount);
Log::debug('order_using',$responseOrder);
Log::debug('response_order_message ->'.$responseOrderMessage);
return $this->response->send('03', $startLogicNum . $count . $totalCount.$orderCount.$responseOrderMessage);
} }
...@@ -225,6 +302,8 @@ class AccessController extends Controller ...@@ -225,6 +302,8 @@ class AccessController extends Controller
} }
Log::debug('mac => logic', $macLogic);
return $macLogic; return $macLogic;
} }
......
...@@ -19,18 +19,24 @@ class HeartController extends Controller ...@@ -19,18 +19,24 @@ class HeartController extends Controller
'00' => [ '00' => [
] ],
]; ];
public function heart() public function heart()
{ {
$time = sprintf('%08x',time()); $time = sprintf('%08x', time());
Log::debug("[heart]", [
Log::debug($time); 'gateway_id' => $_SESSION['gateway_id'],
'data' => $this->message,
'length' => hexdec(substr($this->message,4*2,4)),
$this->response->send('00',$time); ]);
$this->response->send('00', $time);
} }
......
...@@ -15,12 +15,16 @@ use Application\Model\OrderExceptionModel; ...@@ -15,12 +15,16 @@ use Application\Model\OrderExceptionModel;
use Application\Model\OrderModel; use Application\Model\OrderModel;
use Application\Model\PortModel; use Application\Model\PortModel;
use Application\Model\StationModel; use Application\Model\StationModel;
use function GuzzleHttp\Psr7\str;
use Lib\api\message\ChargerReloadMessage;
use Lib\api\message\ChargerStartMessage; use Lib\api\message\ChargerStartMessage;
use Lib\api\message\PortShedMessage; use Lib\api\message\PortShedMessage;
use Lib\api\message\Push; use Lib\api\message\Push;
use Lib\Gateway; use Lib\Gateway;
use Lib\Log; use Lib\Log;
use Lib\order_exception\OrderState;
use Lib\port\Port; use Lib\port\Port;
use Lib\rabbitmq\PublishPortShed;
use Lib\state\StateCode; use Lib\state\StateCode;
use Lib\wx\User; use Lib\wx\User;
...@@ -151,6 +155,8 @@ class PortController extends Controller ...@@ -151,6 +155,8 @@ class PortController extends Controller
public function portState() public function portState()
{ {
$nowTime = date('Y-m-d H:i:s');
Log::debug('口子状态改变', $this->getRequest()->getParameters()); Log::debug('口子状态改变', $this->getRequest()->getParameters());
$portMac = $this->get('mac'); $portMac = $this->get('mac');
...@@ -169,7 +175,7 @@ class PortController extends Controller ...@@ -169,7 +175,7 @@ class PortController extends Controller
$lastState = $port->getState($portId); $lastState = $port->getState($portId);
Log::debug('口子状态改变为脱落->原状态为' . $lastState . '更新->' . $state); Log::debug('口子状态改变-->原状态为->' . $lastState . '更新->' . $state);
if ($state === StateCode::PORT_EXCEPTION) { if ($state === StateCode::PORT_EXCEPTION) {
...@@ -177,6 +183,9 @@ class PortController extends Controller ...@@ -177,6 +183,9 @@ class PortController extends Controller
return; return;
} }
$orderId = $port->getPortUsingOrderId(\Events::getRedis(), $portId);
if ($lastState == -1 && $state === 12) { if ($lastState == -1 && $state === 12) {
try { try {
...@@ -184,9 +193,7 @@ class PortController extends Controller ...@@ -184,9 +193,7 @@ class PortController extends Controller
$update = ['is_charger' => $state]; $update = ['is_charger' => $state];
$update['start_time'] = date('Y-m-d H:i:s'); $update['start_time'] = $nowTime;
$orderId = $port->getPortUsingOrderId(\Events::getRedis(), $portId);
$row = $orderModel->update($update, 'id = ' . $orderId); $row = $orderModel->update($update, 'id = ' . $orderId);
...@@ -195,13 +202,38 @@ class PortController extends Controller ...@@ -195,13 +202,38 @@ class PortController extends Controller
Log::error($exception->getMessage()); Log::error($exception->getMessage());
} }
} else if ($state === StateCode::PORT_SHED) {
$orderModel = new OrderModel();
$lastShedTime = $orderModel->getColumn('shed_time', 'id = ' . $orderId);
$update = ['shed_time' => $nowTime];
$orderLastState = OrderState::getState($orderId);
if($orderLastState == StateCode::PORT_SHED) {
if (isset($lastShedTime)) {
$gapTime = strtotime($nowTime) - strtotime($lastShedTime);
if (($gapTime / 60) > 12) {
//口子距离上一次插口脱落时间超过了十分中,下发结束充电命令
//发送结束充电,结束状态为远程超时结束
Log::debug('todo 插口脱落超时10分钟');
}
} }
}
$orderModel->update($update, 'id = ' . $orderId);
$userId = $port->getPortUsingId(\Events::getRedis(), $portId); }
$orderId = $port->getPortUsingOrderId(\Events::getRedis(), $portId);
$userId = $port->getPortUsingId(\Events::getRedis(), $portId);
//服务器下发充电命令给下位机并将口子状态设置为-1,如果口子未插上下位机返回14,这种情况下口子依然被视为等待充电不改变状态,保持-1,但需要推送消息 //服务器下发充电命令给下位机并将口子状态设置为-1,如果口子未插上下位机返回14,这种情况下口子依然被视为等待充电不改变状态,保持-1,但需要推送消息
if ($lastState != -1 || $state != 14) { if ($lastState != -1 || $state != 14) {
...@@ -262,30 +294,30 @@ class PortController extends Controller ...@@ -262,30 +294,30 @@ class PortController extends Controller
switch ($state) { switch ($state) {
case StateCode::PORT_CHARGER: case StateCode::PORT_CHARGER:
if ($lastState == 14) {
$orderState = new OrderState($orderId);
$orderState->setState(12);
$orderModel = new OrderModel(); $orderModel = new OrderModel();
$result = $orderModel->getColumns(['port_name', 'station_name', 'created_at', 'charger_time', 'order_amount'], 'id = ' . $orderId); $result = $orderModel->getColumns(['port_name', 'station_name', 'created_at', 'charger_time', 'order_amount'], 'id = ' . $orderId);
if ($lastState == 14) {
if (count($result) !== 0) { if (count($result) !== 0) {
try { try {
$chargerReloadMessage = new ChargerReloadMessage();
$chargerStartMessage = new ChargerStartMessage(); $chargerReloadMessage->setStationName($result['station_name']);
$chargerStartMessage->setUserId($userId);
$chargerStartMessage->setStartTime($result['created_at']);
$chargerStartMessage->setAddress($result['station_name'] . '-' . $result['port_name']); $chargerReloadMessage->setPortName($result['port_name']);
$chargerStartMessage->setAmount(number_format($result['order_amount'] / 100, 2));
$push = new Push(); $push = new Push();
$push->push($chargerStartMessage, $userId); $push->push($chargerReloadMessage, $userId);
} catch (\Exception $exception) { } catch (\Exception $exception) {
Log::error($exception->getMessage()); Log::error($exception->getMessage());
...@@ -297,6 +329,19 @@ class PortController extends Controller ...@@ -297,6 +329,19 @@ class PortController extends Controller
} }
} else if ($lastState == -1) {
$chargerStartMessage = new ChargerStartMessage();
$chargerStartMessage->setStartTime($result['created_at']);
$chargerStartMessage->setAmount(number_format($result['order_amount'] / 100, 2));
$chargerStartMessage->setAddress($result['station_name'] . '(' . $result['port_name'] . ')');
$push = new Push();
$push->push($chargerStartMessage, $userId);
} }
break; break;
...@@ -327,7 +372,11 @@ class PortController extends Controller ...@@ -327,7 +372,11 @@ class PortController extends Controller
$portShedMessage->setStationName($stationName); $portShedMessage->setStationName($stationName);
$portShedMessage->setTime(10); $portShedMessage->setRemark('超时将关闭订单喔,请尽快重连插口');
$portShedMessage->setWaitingTime(10);
$portShedMessage->setTime(date('Y-m-d H:i:s'));
$push = new Push(); $push = new Push();
...@@ -345,6 +394,27 @@ class PortController extends Controller ...@@ -345,6 +394,27 @@ class PortController extends Controller
} }
//发送延迟任务
try {
$publishPortShedJob = new PublishPortShed();
} catch (\Exception $exception) {
Log::error($exception->getMessage());
}
$publishPortShedJob->publishOrder(
[
'order_id' => $orderId,
'time' => date('Y-m-d H:i:s'),
'gateway_mac' => $_SESSION['gateway_mac'],
]
);
} }
break; break;
......
...@@ -10,17 +10,30 @@ namespace Application\Controller; ...@@ -10,17 +10,30 @@ namespace Application\Controller;
use Application\Controller; use Application\Controller;
use Application\Model\ExceptionModel;
use Application\Model\OrderCapacityModel;
use Application\Model\OrderExceptionModel;
use Application\Model\OrderModel; use Application\Model\OrderModel;
use Lib\api\message\ChargerExceedMessage; use Lib\api\message\ChargerExceedMessage;
use Lib\api\message\ChargerExceptionMessage;
use Lib\api\message\ChargerExcessMessage;
use Lib\api\message\ChargerFailMessage;
use Lib\api\message\ChargerFinishMessage; use Lib\api\message\ChargerFinishMessage;
use Lib\api\message\ChargerRefundMessage; use Lib\api\message\ChargerRefundMessage;
use Lib\api\message\ChargerStartMessage; use Lib\api\message\ChargerStartMessage;
use Lib\api\message\MessageData;
use Lib\api\message\PortShedMessage; use Lib\api\message\PortShedMessage;
use Lib\api\message\Push; use Lib\api\message\Push;
use Lib\Gateway; use Lib\Gateway;
use Lib\Log; use Lib\Log;
use Lib\order_exception\OrderState;
use Lib\order_exception\OrderTrace;
use Lib\port\Port; use Lib\port\Port;
use Lib\rabbitmq\MyRabbitMq;
use Lib\send\command\StopChargerCommand;
use Lib\send\Send;
use Lib\state\StateCode; use Lib\state\StateCode;
use Workerman\Events\Event;
class PowerController extends Controller class PowerController extends Controller
{ {
...@@ -104,11 +117,11 @@ class PowerController extends Controller ...@@ -104,11 +117,11 @@ class PowerController extends Controller
$id = hexdec($orderId); $id = hexdec($orderId);
$_SESSION['current_order_id'] = $id;
$_SESSION['order_state'] = $state; $_SESSION['order_state'] = $state;
$orderCollection = $orderModel->getColumns(['wx_user_id', 'port_name', 'order_amount'], 'id = ' . $id); $orderCollection = $orderModel->getColumns(['wx_user_id', 'port_name', 'order_amount', 'port_id'], 'id = ' . $id);
$_SESSION['current_order_id'][strval($orderCollection['port_id'])] = $id;
$update = ['is_charger' => $state, 'start_capacity' => $power]; $update = ['is_charger' => $state, 'start_capacity' => $power];
...@@ -118,6 +131,8 @@ class PowerController extends Controller ...@@ -118,6 +131,8 @@ class PowerController extends Controller
$stationName = $_SESSION['station_name']; $stationName = $_SESSION['station_name'];
$orderState = new OrderState($orderId);
if ($state === StateCode::PORT_CHARGER) { if ($state === StateCode::PORT_CHARGER) {
$timeNow = date('Y-m-d H:i:s'); $timeNow = date('Y-m-d H:i:s');
...@@ -132,15 +147,24 @@ class PowerController extends Controller ...@@ -132,15 +147,24 @@ class PowerController extends Controller
$pushMessage->setAddress($stationName . '-' . $portName . '号'); $pushMessage->setAddress($stationName . '-' . $portName . '号');
} else if ($state === StateCode::PORT_SHED) { $orderState->setState($state);
} else if ($state === StateCode::PORT_EXCEPTION) {
$pushMessage = new ChargerExceptionMessage();
Log::debug('开始充电,口子未插上'); $pushMessage->setAddress($stationName . "($portName)");
$pushMessage = new PortShedMessage(); $orderAmount = number_format($orderCollection['order_amount'] / 100, 2);
$pushMessage->setStationName($stationName); $pushMessage->setAmount($orderAmount);
$pushMessage->setOrderId($orderId);
$orderState->setState($state);
$pushMessage->setPortName($portName);
} }
...@@ -158,8 +182,6 @@ class PowerController extends Controller ...@@ -158,8 +182,6 @@ class PowerController extends Controller
if (Gateway::isUidOnline($userId) === 1) { if (Gateway::isUidOnline($userId) === 1) {
Log::debug('webSocket', ['user_id' => $userId]);
Gateway::sendToUid($userId, json_encode(['code' => 10000])); Gateway::sendToUid($userId, json_encode(['code' => 10000]));
} else { } else {
...@@ -178,14 +200,15 @@ class PowerController extends Controller ...@@ -178,14 +200,15 @@ class PowerController extends Controller
} }
//记录订单的轨迹
$orderTrace = new OrderTrace($state);
//todo websocket推送给前段开始充电信息,如果未发现当前订单id连接则存入消息队列当中 $orderTrace->setOrderId($orderId);
$orderTrace->writeTrace();
} }
Log::debug('order_id ->'.$orderId);
$this->response->send('14', $orderId); $this->response->send('14', $orderId);
...@@ -231,6 +254,19 @@ class PowerController extends Controller ...@@ -231,6 +254,19 @@ class PowerController extends Controller
$portId = $port->getIdByLogic(); $portId = $port->getIdByLogic();
try {
//记录订单轨迹
$orderTrace = new OrderTrace($state);
$orderTrace->setOrderId($id);
$orderTrace->writeTrace();
} catch (\Exception $exception) {
Log::error($exception->getMessage());
}
// 发送微信消息给用户。 // 发送微信消息给用户。
// 充电结束时删除端口正在使用的hash表中的元素,删除充电用户正在充电订单中的本次订单 // 充电结束时删除端口正在使用的hash表中的元素,删除充电用户正在充电订单中的本次订单
...@@ -252,6 +288,11 @@ class PowerController extends Controller ...@@ -252,6 +288,11 @@ class PowerController extends Controller
$orderModel->update(['is_stop' => $state, 'state' => 1, 'end_capacity' => $capacity, 'end_time' => $time], ' id = ' . $id); $orderModel->update(['is_stop' => $state, 'state' => 1, 'end_capacity' => $capacity, 'end_time' => $time], ' id = ' . $id);
$orderState = new OrderState($orderId);
$orderState->setState($state);
} }
} }
...@@ -277,16 +318,26 @@ class PowerController extends Controller ...@@ -277,16 +318,26 @@ class PowerController extends Controller
case StateCode::FINISH_EXCEED: case StateCode::FINISH_EXCEED:
$finishMessage = new ChargerExceedMessage(); $finishMessage = new ChargerExceedMessage();
$finishMessage->setUserId($orderInfo['wx_user_id']); $finishMessage->setUserId($orderInfo['wx_user_id']);
$finishMessage->setStartTime($orderInfo['start_time']); $finishMessage->setStartTime($orderInfo['start_time']);
$finishMessage->setChargerTime($orderId['charger_time']); $finishMessage->setChargerTime($orderInfo['charger_time']);
$finishMessage->setEndTime($time); $finishMessage->setEndTime($time);
$orderExceptionModel = new OrderExceptionModel();
$orderExceptionModel->insertRow([
'order_id' => $orderId,
'state' => $state,
]);
break; break;
case StateCode::FINISH_REMOTE: case StateCode::FINISH_REMOTE:
...@@ -302,6 +353,32 @@ class PowerController extends Controller ...@@ -302,6 +353,32 @@ class PowerController extends Controller
$finishMessage->setUserId($orderInfo['wx_user_id']); $finishMessage->setUserId($orderInfo['wx_user_id']);
} else {
$finishMessage = new ChargerFinishMessage();
$finishMessage->setUserId($orderInfo['wx_user_id']);
$finishMessage->setEndTime($time);
$startTime = $orderInfo['start_time'];
$startTimeTimestamp = strtotime($startTime);
$now = time();
$first = $finishMessage->getFirst();
$first .= ' (远程关闭)';
$finishMessage->setFirst($first);
$finishMessage->setChargerTime(ceil(($now - $startTimeTimestamp) / 60));
$finishMessage->setChargerPlc($orderInfo['station_name'] . '-' . $orderInfo['port_id']);
$finishMessage->setOrderAmount($orderInfo['order_amount']);
} }
...@@ -322,6 +399,25 @@ class PowerController extends Controller ...@@ -322,6 +399,25 @@ class PowerController extends Controller
$finishMessage->setOrderAmount($orderInfo['order_amount']); $finishMessage->setOrderAmount($orderInfo['order_amount']);
break; break;
case StateCode::FINISH_FULL:
$finishMessage = new ChargerFinishMessage();
$finishMessage->setUserId($orderInfo['wx_user_id']);
$finishMessage->setEndTime($time);
$finishMessage->setChargerTime(ceil((time() - strtotime($orderInfo['charger_time']) / 60)));
$finishMessage->setChargerPlc($orderInfo['station_name'] . '-' . $orderInfo['port_id']);
$finishMessage->setOrderAmount($orderInfo['order_amount']);
break;
default: default:
break; break;
...@@ -332,9 +428,12 @@ class PowerController extends Controller ...@@ -332,9 +428,12 @@ class PowerController extends Controller
try { try {
if (isset($finishMessage) === true) { if (isset($finishMessage) == true) {
$push->push($finishMessage, $finishMessage->getUserId()); $push->push($finishMessage, $finishMessage->getUserId());
} }
} catch (\Exception $exception) { } catch (\Exception $exception) {
...@@ -342,6 +441,7 @@ class PowerController extends Controller ...@@ -342,6 +441,7 @@ class PowerController extends Controller
} }
unset($_SESSION['current_order_id']);
$this->response->send('15', $orderId); $this->response->send('15', $orderId);
...@@ -400,9 +500,54 @@ class PowerController extends Controller ...@@ -400,9 +500,54 @@ class PowerController extends Controller
$logicNum = $this->get('logic'); $logicNum = $this->get('logic');
$powerData = $this->get('power'); $powerData = hexdec($this->get('power'));
$capacity = hexdec($this->get('capacity'));
$port = new Port();
$port->setLogic($logicNum);
$capacity = $this->get('capacity');
if (isset($_SESSION['logic_port_id'][$logicNum])) {
$portId = $_SESSION['logic_port_id'][$logicNum];
} else {
$portId = $port->getIdByLogic();
}
if (isset($_SESSION['current_order_id'][$portId])) {
$orderId = $_SESSION['current_order_id'][$portId];
} else {
Log::info('gatway session 缺少当前订单id');
$orderId = $port->getPortUsingOrderId(\Events::getRedis(), $portId);
Log::info('从redis中获取当前订单 ->' . $orderId);
}
try {
$orderCapacityModel = new OrderCapacityModel();
$orderCapacityModel->insertRow([
'order_id' => $orderId,
'port_id' => $portId,
'capacity' => $capacity,
'power' => $powerData,
'created_at' => date('Y-m-d H:i:s'),
]);
} catch (\Exception $exception) {
Log::error($exception->getMessage());
}
} }
......
...@@ -11,6 +11,8 @@ namespace Application\Controller; ...@@ -11,6 +11,8 @@ namespace Application\Controller;
use Application\Controller; use Application\Controller;
use Application\Model\ConfigModel; use Application\Model\ConfigModel;
use Application\Model\StationModel;
use function Couchbase\defaultDecoder;
use Lib\Log; use Lib\Log;
class SettingController extends Controller class SettingController extends Controller
...@@ -31,19 +33,24 @@ class SettingController extends Controller ...@@ -31,19 +33,24 @@ class SettingController extends Controller
} }
Log::debug('config', $idConfigValue);
$invertalTime = $idConfigValue['5']; $invertalTime = $idConfigValue['5'];
$stationId = $_SESSION['station_id'];
$stationModel = new StationModel();
$stationMaxCep = $stationModel->getColumn('max_cep', 'id = ' . $stationId);
$powerUpperLimit = isset($stationMaxCep) ? $stationMaxCep : $idConfigValue['1'];
$getPriceConfig = $idConfigValue['6']; $getPriceConfig = $idConfigValue['6'];
$powerUpperLimit = $idConfigValue['1'];
$powerSaturateInvertalTime = $idConfigValue['7']; $powerSaturateInvertalTime = $idConfigValue['7'];
$extraTime = $idConfigValue['8']; $extraTime = $idConfigValue['8'];
$powerLowerLimit = 5; $powerLowerLimit = 120;
$detectTime = 5; $detectTime = 5;
...@@ -56,7 +63,6 @@ class SettingController extends Controller ...@@ -56,7 +63,6 @@ class SettingController extends Controller
[$powerLowerLimit, 2], [$powerLowerLimit, 2],
[$detectTime, 2], [$detectTime, 2],
]); ]);
Log::debug('afterFormat', $afterFormat);
$this->response->send('0a', implode($afterFormat)); $this->response->send('0a', implode($afterFormat));
......
...@@ -74,14 +74,10 @@ class Events ...@@ -74,14 +74,10 @@ class Events
public static function onMessage($clientId, $message) public static function onMessage($clientId, $message)
{ {
$crc = substr($message, -2); $crc = substr($message, -2);
$makeCrc = sprintf('%08x', (Crc::crc(substr($message, 0, -2)))); $makeCrc = sprintf('%08x', (Crc::crc(substr($message, 0, -2))));
if ($crc != mb_strtoupper(substr($makeCrc, 0, 2))) { if ($crc != mb_strtoupper(substr($makeCrc, 0, 2))) {
Log::error('crc 错误'); Log::error('crc 错误');
...@@ -90,8 +86,6 @@ class Events ...@@ -90,8 +86,6 @@ class Events
} else { } else {
$command = substr($message, 6, 2); $command = substr($message, 6, 2);
$route = Api::getRoute($command); $route = Api::getRoute($command);
...@@ -116,7 +110,6 @@ class Events ...@@ -116,7 +110,6 @@ class Events
if ($item instanceof \Application\Middleware) { if ($item instanceof \Application\Middleware) {
if ($item->handle($clientId, $message) === false) { if ($item->handle($clientId, $message) === false) {
try { try {
Gateway::closeCurrentClient(); Gateway::closeCurrentClient();
} catch (Exception $e) { } catch (Exception $e) {
...@@ -145,7 +138,6 @@ class Events ...@@ -145,7 +138,6 @@ class Events
} }
} }
...@@ -180,7 +172,7 @@ class Events ...@@ -180,7 +172,7 @@ class Events
$log = new \Lib\log\DeviceLog($gatewayMac); $log = new \Lib\log\DeviceLog($gatewayMac);
$log->setType('state'); $log->setType('offline');
$log->log(); $log->log();
...@@ -217,10 +209,9 @@ class Events ...@@ -217,10 +209,9 @@ class Events
$gatewayId = $_SESSION['gateway_id']; $gatewayId = $_SESSION['gateway_id'];
$insert = ['message' => '网关离线', 'gateway_id' => $gatewayId, 'type' => 1,'created_at' => date('Y-m-d H:i:s')]; $insert = ['message' => '网关离线', 'gateway_id' => $gatewayId, 'type' => 1, 'created_at' => date('Y-m-d H:i:s')];
if(isset($_SESSION['station_id'])) if (isset($_SESSION['station_id'])) {
{
$insert['station_id'] = $_SESSION['station_id']; $insert['station_id'] = $_SESSION['station_id'];
} }
...@@ -229,6 +220,10 @@ class Events ...@@ -229,6 +220,10 @@ class Events
Log::error($exception->getMessage()); Log::error($exception->getMessage());
} }
} }
public static function getRedis() public static function getRedis()
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/2
* Time: 上午10:17
*/
namespace Application\Model;
use Application\Model;
class OrderCapacityModel extends Model
{
protected $table = 'order_power_capacity';
}
\ No newline at end of file
...@@ -106,7 +106,7 @@ class Response ...@@ -106,7 +106,7 @@ class Response
if(strlen($exceptCrc)%2 != 0) if(strlen($exceptCrc)%2 != 0)
{ {
Log::error('length wrogn'); Log::error('length wrong');
} }
Log::debug('response'.$exceptCrc); Log::debug('response'.$exceptCrc);
......
...@@ -14,7 +14,7 @@ class ChargerExceedMessage extends MessageData ...@@ -14,7 +14,7 @@ class ChargerExceedMessage extends MessageData
/** /**
* @var string * @var string
*/ */
protected $templateId = 'IDrdzTNQ7t4uRXkP0SkuwW10WH77A_CIgYFiJykXJ0utU'; protected $templateId = 'rdzTNQ7t4uRXkP0SkuwW10WH77A_CIgYFiJykXJ0utU';
/** /**
* @var string * @var string
...@@ -57,14 +57,10 @@ class ChargerExceedMessage extends MessageData ...@@ -57,14 +57,10 @@ class ChargerExceedMessage extends MessageData
], ],
'keyword2' => [ 'keyword2' => [
'value' => $this->chargerTime, 'value' => $this->chargerTime.'分钟',
'color' => '#333', 'color' => '#333',
], ],
'keyword3' => [ 'keyword3' => [
'value' => $this->chargerTime,
'color' => '#333',
],
'keyword4' => [
'value' => $this->endTime, 'value' => $this->endTime,
'color' => '#333', 'color' => '#333',
], ],
...@@ -73,6 +69,7 @@ class ChargerExceedMessage extends MessageData ...@@ -73,6 +69,7 @@ class ChargerExceedMessage extends MessageData
'color' => '#333', 'color' => '#333',
], ],
]); ]);
} }
/** /**
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/10
* Time: 下午3:27
*/
namespace Lib\api\message;
class ChargerExceptionMessage extends MessageData
{
protected $templateId = '0al-a6kkNsdqFyXPEe97m4jjtbfOXjEC3eCjEsMHJdw';
protected $first = '充电口打开失败,已取消订单,退款稍后送达,请注意查收哟';
/**
* @var string
*/
private $orderId = '';
/**
* @var string
*/
private $address = '';
/**
* @var int
*/
private $amount;
/**
* @var string
*/
private $remark = '温馨提示:超时关闭此次交易,支付金额会在1个工作日内退回您的余额或零钱,请注意查看,若未收到请联系我们的客服为您处理。若为充电口异常,请您及时更换至其它充电口充电';
public function getPushDataJson(): string
{
// TODO: Implement getPushDataJson() method.
return json_encode([
'first' => [
'value' => $this->first,
'color' => '#333',
],
'keyword1' => [
'value' => $this->orderId,
'color' => '#333',
],
'keyword2' => [
'value' => $this->address,
'color' => '#333',
],
'keyword3' => [
'value' => $this->amount,
'color' => '#333',
],
'remark' => [
'value' => $this->remark,
'color' => '#333',
],
]);
}
/**
* @return string
*/
public function getOrderId(): string
{
return $this->orderId;
}
/**
* @param string $orderId
*/
public function setOrderId(string $orderId): void
{
$this->orderId = $orderId;
}
/**
* @return string
*/
public function getAddress(): string
{
return $this->address;
}
/**
* @param string $address
*/
public function setAddress(string $address): void
{
$this->address = $address;
}
/**
* @return int
*/
public function getAmount(): int
{
return $this->amount;
}
/**
* @param int $amount
*/
public function setAmount(int $amount): void
{
$this->amount = $amount;
}
/**
* @return string
*/
public function getRemark(): string
{
return $this->remark;
}
/**
* @param string $remark
*/
public function setRemark(string $remark): void
{
$this->remark = $remark;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/6
* Time: 上午11:45
*/
namespace Lib\api\message;
class ChargerExcessMessage extends MessageData
{
public function getPushDataJson(): string
{
return 'a';
// TODO: Implement getPushDataJson() method.
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/6/30
* Time: 下午4:13
*/
namespace Lib\api\message;
class ChargerFailMessage extends MessageData
{
/**
* @var string
*/
protected $templateId = 'C0LvfETe-1rCR_IhOydDGPTUwwYkrWZxgfwMsETrhw8';
/**
* @var string
*/
private $first = '尊敬的用户,我们检测的您的订单充电失败。
';
/**
* @var string
*/
private $portName = '';
/**
* @var string
*/
private $stationName = '';
/**
* @var string
*/
private $time = '';
/**
* @var string
*/
private $remark = '支付金额会在1个工作日内退回您的余额或零钱。';
public function getUserId(): int
{
// TODO: Implement getUserId() method.
}
/**
* @return string
*/
public function getPushDataJson(): string
{
return json_encode([
'first' => [
'value' => $this->first,
'color' => '#333',
],
'keyword1' => [
'value' => $this->stationName . "($this->portName)",
'color' => '#333',
],
'keyword2' => [
'value' => $this->time,
'color' => '#333',
],
'remark' => [
'value' => $this->remark,
'color' => '#333',
],
]);
// TODO: Implement getPushDataJson() method.
}
/**
* @return string
*/
public function getFirst(): string
{
return $this->first;
}
/**
* @param string $first
*/
public function setFirst(string $first): void
{
$this->first = $first;
}
/**
* @return string
*/
public function getPortName(): string
{
return $this->portName;
}
/**
* @param string $portName
*/
public function setPortName(string $portName): void
{
$this->portName = $portName;
}
/**
* @return string
*/
public function getStationName(): string
{
return $this->stationName;
}
/**
* @param string $stationName
*/
public function setStationName(string $stationName): void
{
$this->stationName = $stationName;
}
/**
* @return string
*/
public function getTime(): string
{
return $this->time;
}
/**
* @param string $time
*/
public function setTime(string $time): void
{
$this->time = $time;
}
/**
* @return string
*/
public function getRemark(): string
{
return $this->remark;
}
/**
* @param string $remark
*/
public function setRemark(string $remark): void
{
$this->remark = $remark;
}
}
\ No newline at end of file
...@@ -73,11 +73,11 @@ class ChargerFinishMessage extends MessageData ...@@ -73,11 +73,11 @@ class ChargerFinishMessage extends MessageData
'color' => '#333', 'color' => '#333',
], ],
'keyword3' => [ 'keyword3' => [
'value' => $this->chargerTime.' 分', 'value' => $this->chargerTime.'分钟',
'color' => '#333', 'color' => '#333',
], ],
'keyword4' => [ 'keyword4' => [
'value' => $this->orderAmount.' ¥', 'value' => '¥'.$this->orderAmount,
'color' => '#333', 'color' => '#333',
], ],
'remark' => [ 'remark' => [
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/7
* Time: 上午11:36
*/
namespace Lib\api\message;
class ChargerFullMessage extends MessageData
{
protected $templateId ='rdzTNQ7t4uRXkP0SkuwW10WH77A_CIgYFiJykXJ0utU';
private $first = '';
private $startTime = '';
public function getPushDataJson(): string
{
return '';
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/6
* Time: 上午9:45
*/
namespace Lib\api\message;
class ChargerReloadMessage extends MessageData
{
protected $templateId = 't_PyOGCKN_fmD0blw0EuIQs-8sS3qOTmpQay12haPZY';
private $first = '充电继续通知:';
private $stationName = '';
private $portName = '';
private $time = '';
private $remark = '';
/**
* @return string
*/
public function getFirst(): string
{
return $this->first;
}
/**
* @param string $first
*/
public function setFirst(string $first): void
{
$this->first = $first;
}
/**
* @return string
*/
public function getStationName(): string
{
return $this->stationName;
}
/**
* @param string $stationName
*/
public function setStationName(string $stationName): void
{
$this->stationName = $stationName;
}
/**
* @return string
*/
public function getPortName(): string
{
return $this->portName;
}
/**
* @param string $portName
*/
public function setPortName(string $portName): void
{
$this->portName = $portName;
}
/**
* @return string
*/
public function getTime(): string
{
return $this->time;
}
/**
* @param string $time
*/
public function setTime(string $time): void
{
$this->time = $time;
}
/**
* @return string
*/
public function getRemark(): string
{
return $this->remark;
}
/**
* @param string $remark
*/
public function setRemark(string $remark): void
{
$this->remark = $remark;
}
public function getPushDataJson(): string
{
return json_encode([
'first' => [
'value' => $this->first,
'color' => '#333',
],
'keyword1' => [
'value' => $this->stationName,
'color' => '#333',
],
'keyword2' => [
'value' => $this->portName,
'color' => '#333',
],
'keyword3' => [
'value' => date('Y-m-d H:i:s'),
'color' => '#333',
],
'remark' => [
'value' => '感谢你的使用',
'color' => '#333',
],
]);
// TODO: Implement getPushDataJson() method.
}
}
\ No newline at end of file
...@@ -38,7 +38,7 @@ abstract class MessageData ...@@ -38,7 +38,7 @@ abstract class MessageData
} }
protected function getUserId(): int public function getUserId(): int
{ {
return $this->userId; return $this->userId;
......
...@@ -20,7 +20,7 @@ class PortShedMessage extends MessageData ...@@ -20,7 +20,7 @@ class PortShedMessage extends MessageData
/** /**
* @var string * @var string
*/ */
private $first = '尊敬的用户,充电端未检测到插头,请您在%s分钟内接入
'; private $first = '尊敬的用户,充电端未检测到插头,请您在%s分钟内接入。';
/** /**
* @var string * @var string
...@@ -172,5 +172,23 @@ class PortShedMessage extends MessageData ...@@ -172,5 +172,23 @@ class PortShedMessage extends MessageData
$this->remark = $remark; $this->remark = $remark;
} }
/**
* @return int
*/
public function getWaitingTime(): int
{
return $this->waitingTime;
}
/**
* @param int $waitingTime
*/
public function setWaitingTime(int $waitingTime): void
{
$this->waitingTime = $waitingTime;
}
} }
\ No newline at end of file
...@@ -26,14 +26,15 @@ class Push ...@@ -26,14 +26,15 @@ class Push
* @return bool * @return bool
* @throws \GuzzleHttp\Exception\GuzzleException * @throws \GuzzleHttp\Exception\GuzzleException
*/ */
public function push(MessageData $messageData,string $userId) public function push(MessageData $messageData, string $userId)
{ {
$client = new Client([ $client = new Client([
'base_uri' => self::URI 'base_uri' => self::URI,
]); ]);
$response = $client->request('POST',self::PATH,[ $response = $client->request('POST', self::PATH, [
'form_params' => [ 'form_params' => [
...@@ -44,15 +45,14 @@ class Push ...@@ -44,15 +45,14 @@ class Push
'http_errors' => false, 'http_errors' => false,
]); ]);
if($response->getStatusCode() === 200) if ($response->getStatusCode() === 200) {
{
Log::debug('发送模版消息'.$messageData->getTemplateId(),json_decode($response->getBody(),true)); Log::debug('发送模版消息' . $messageData->getTemplateId(), json_decode($response->getBody(), true));
} }
Log::debug($response->getStatusCode());
Log::debug($response->getStatusCode());
return $response->getStatusCode() === 200; return $response->getStatusCode() === 200;
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/10
* Time: 上午10:57
*/
namespace Lib\order_exception;
class Exception
{
const STATE_MESSAGE = [
'12' => '开始充电',
'10' => '口子离线',
'11' => '口子上线',
'13' => '开始充电失败(异常)',
'14' => '插口脱落',
'30' => '充电计时结束',
'31' => '远程关闭',
'32' => '插口脱落结束充电',
'34' => '功率超限结束充电',
'99' => '下发开始充电命令',
'98' => '更换充电口',
'97' => '下发结束充电命令',
];
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/12
* Time: 上午10:24
*/
namespace Lib\order_exception;
use Lib\redis\RedisKey;
/**
* 设置订单的状态
* Class OrderState
* @package Lib\order_exception
*/
class OrderState
{
/**
* @var int
*/
private $orderId;
public function __construct(int $orderId)
{
$this->orderId = $orderId;
}
/**
* @param int $state
*/
public function setState(int $state)
{
$redis = \Events::getRedis();
$redis->zAdd(RedisKey::ORDER_STATE, $state, $this->orderId);
}
/**获取订单状态
* @param int $orderId
* @return float
*/
public static function getState(int $orderId)
{
$redis = \Events::getRedis();
return $redis->zScore(RedisKey::ORDER_STATE, $orderId);
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/10
* Time: 上午11:09
*/
namespace Lib\order_exception;
use Application\Model\OrderExceptionModel;
use Lib\Log;
class OrderTrace
{
/**
* @var string
*/
private $orderId ='';
/**
* @var string
*/
private $state = '';
/**
* @var OrderExceptionModel
*/
private $orderExceptionModel;
/**
* OrderTrace constructor.
* @param string $state
*/
public function __construct($state = '') {
$this->orderExceptionModel = new OrderExceptionModel();
$this->state = $state;
}
/**
* @return string
*/
public function getOrderId(): string
{
return $this->orderId;
}
/**
* @param string $orderId
*/
public function setOrderId(string $orderId): void
{
$this->orderId = $orderId;
}
/**
* 按照state记录订单异常
*/
public function writeTrace()
{
if (!isset(Exception::STATE_MESSAGE[$this->state]))
{
Log::error('记录订单异常无次state'."($this->state)");
return ;
}
try{
$this->orderExceptionModel->insertRow([
'state' => $this->state,
'desc' => Exception::STATE_MESSAGE[$this->state],
'created_at' => date('Y-m-d H:i:s'),
'order_id' => $this->orderId,
]);
}catch (\Exception $exception)
{
Log::error($exception->getMessage());
}
}
/**
* 记录订单异常
* @param int $state
* @param string $message
*/
public function writeRawTrace(int $state,string $message)
{
try{
$this->orderExceptionModel->insertRow([
'state' => $state,
'desc' => $message,
'created_at' => date('Y-m-d H:i:s'),
'order_id' => $this->orderId
]);
}catch (\Exception $exception)
{
Log::error($exception->getMessage());
}
}
}
...@@ -183,7 +183,10 @@ class Port ...@@ -183,7 +183,10 @@ class Port
*/ */
public function freePort() public function freePort()
{ {
//todo 口子充电结束,释放口子,删除正在使用的订单号和用户id,口子状态修改为1。 // 口子充电结束,释放口子,删除正在使用的订单号和用户id,口子状态修改为1。
Log::debug('释放口子id->'.$this->id);
$this->redis->hDel(RedisKey::PORT_USING_ORDER_ID,$this->id); $this->redis->hDel(RedisKey::PORT_USING_ORDER_ID,$this->id);
......
<?php
/**
* Created by PhpStorm.
* User: suhangyang
* Date: 2018/5/4
* Time: 上午9:36
*/
namespace Lib\rabbitmq;
use Log;
class MyRabbitMq
{
const CONNECTION = [
'host' => 'rabbitmq.default.svc.cluster.local',
'port' => '5672',
'login' => 'rabbitmq',
'password' => 'senthink123!',
'vhost' => 'cdz_gateway',
];
/**
* @var \AMQPConnection
*/
protected $connection;
/**
* @var \AMQPChannel
*/
protected $channel;
/**
* @var string
*/
protected $routeKey;
/**
* @var string
*/
protected $exchangeKey;
/**
* @var \AMQPExchange
*/
protected $exchange;
/**
* MyRabbitMq constructor.
* @throws \AMQPConnectionException
* @throws \AMQPExchangeException
*/
public function __construct()
{
$this->connection = new \AMQPConnection(self::CONNECTION);
if (!$this->connection->connect()) {
Log::error('rabbit mq connect fail');
throw new \Exception('amqp connect fail');
} else {
$this->channel = new \AMQPChannel($this->connection);
$this->exchange = new \AMQPExchange($this->channel);
}
}
/**
* @return \AMQPChannel
* @throws \AMQPConnectionException
*/
public function getChannel():\AMQPChannel
{
return $this->channel = new \AMQPChannel($this->connection);
}
/**
* @return \AMQPConnection
*/
public function getConnection(): \AMQPConnection
{
return $this->connection;
}
/**
* @param \AMQPConnection $connection
*/
public function setConnection(\AMQPConnection $connection)
{
$this->connection = $connection;
}
/**
* @return string
*/
public function getRouteKey(): string
{
return $this->routeKey;
}
/**
* @param string $routeKey
*/
public function setRouteKey(string $routeKey)
{
$this->routeKey = $routeKey;
}
/**
* @return string
*/
public function getExchangeKey(): string
{
return $this->exchangeKey;
}
/**
* @param string $exchangeKey
*/
public function setExchangeKey(string $exchangeKey)
{
$this->exchangeKey = $exchangeKey;
}
/**
* @return \AMQPExchange
*/
public function getExchange(): \AMQPExchange
{
return $this->exchange;
}
/**
* @param \AMQPExchange $exchange
*/
public function setExchange(\AMQPExchange $exchange)
{
$this->exchange = $exchange;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/5
* Time: 下午4:44
*/
namespace Lib\rabbitmq;
use Lib\Log;
class PublishPortShed
{
/**
* PublishPortShed constructor.
* @throws \AMQPConnectionException
* @throws \AMQPExchangeException
*/
public function __construct() {
$this->rabbitMq = new MyRabbitMq();
$this->exchange = $this->rabbitMq->getExchange();
$this->exchange->setName('cdz_gateway');
$this->exchange->setType(AMQP_EX_TYPE_DIRECT);
$this->exchange->setFlags(AMQP_DURABLE);
try {
$this->exchange->declareExchange();
} catch (\AMQPChannelException $e) {
Log::error($e->getMessage());
} catch (\AMQPConnectionException $e) {
Log::error($e->getMessage());
} catch (\AMQPExchangeException $e) {
Log::error($e->getMessage());
}
}
public function publishOrder(array $message, string $routeKey = 'delay_check_port_charger_state')
{
try {
return $this->exchange->publish(json_encode($message), $routeKey, AMQP_MANDATORY);
} catch (\AMQPChannelException $e) {
} catch (\AMQPConnectionException $e) {
} catch (\AMQPExchangeException $e) {
}
}
}
\ No newline at end of file
...@@ -46,5 +46,9 @@ class RedisKey ...@@ -46,5 +46,9 @@ class RedisKey
const PORT_MAC_ID = 'cdz:port:mac_id:hash'; const PORT_MAC_ID = 'cdz:port:mac_id:hash';
const ORDER_STATE = 'cdz:order:state:zset';
} }
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: suhangyang
* Date: 2018/5/7
* Time: 上午9:39
*/
namespace Lib\send;
abstract class Command
{
/**
* @var string
*/
protected $headerCtrl = '';
/**
* @var string
*/
protected $messageBody = '';
/**
* @var string
*/
protected $clientId = '';
/**
* @var string
*/
protected $clientUid = '';
abstract public function getMessageBody(): string;
abstract public function getClientId(): string;
abstract public function getClientUid(): string;
/**
* @return string
*/
public function getHeaderCtrl(): string
{
return $this->headerCtrl;
}
/**
* @param string $headerCtrl
*/
public function setHeadCtrl(string $headerCtrl)
{
$this->headerCtrl = $headerCtrl;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: suhangyang
* Date: 2018/5/7
* Time: 上午9:39
*/
namespace Lib\send;
use Lib\Gateway;
use Lib\tool\Crc;
use Lib\tool\StringTool;
use Lib\Log;
class Send
{
/**
* 数据头标识符
*/
const PREAMBLE = 'ffaa';
/**
* @var string
*/
private $headerFlag = '04';
/**
* @var string
*/
private $headerCtrl = '';
/**
* @var string
*/
private $length;
/**
* @var string
*/
private $nonce;
/**
* @var Command
*/
private $command;
/**
* Send constructor.
*
* @param Command $command
*/
public function __construct(Command $command)
{
$this->command = $command;
$this->headerCtrl = $command->getHeaderCtrl();
$this->nonce = StringTool::padded(rand(0, 255), 2);
}
/**
* @param Command $command
*/
public function setCommand(Command $command): void
{
$this->command = $command;
$this->headerCtrl = $command->getHeaderCtrl();
$this->nonce = StringTool::padded(rand(0, 255), 2);
}
/**
* 发送至下位机
* @return bool
*/
public function send()
{
$result = false;
$clientUid = $this->command->getClientUid();
$message = $this->makeMessage();
Log::debug('send messag'.$message);
if(strlen($message)%2 === 1)
{
Log::error('length wrong- '.$message);
}
//debug
if (Gateway::isUidOnline($clientUid) === 1) {
Gateway::sendToUid($clientUid, $message);
$result = true;
}
return $result;
}
/**
* 按命令生成发送的message
* @return string
*/
public function makeMessage()
{
$body = $this->command->getMessageBody();
$length = 8;
$length += strlen($body) / 2;
$this->length = StringTool::padded($length, 4);
$message = self::PREAMBLE . $this->headerFlag . $this->headerCtrl . $this->length . $this->nonce . $body;
$crc = Crc::crc($message);
$mic = substr($crc, 0, 2);
$message .= $mic;
return $message;
}
}
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/5/30
* Time: 下午4:52
*/
namespace Lib\send\command;
use Lib\balance\BalanceOrder;
use Lib\send\Command;
class BalanceChargerCommand extends Command
{
/**
* @var string
*/
protected $headerCtrl = '04';
/**
* @var BalanceOrder
*/
private $balanceOrder;
/**
* BalanceChargerCommand constructor.
* @param BalanceOrder $balanceOrder
*/
public function __construct(BalanceOrder $balanceOrder) {
$this->clientUid = $balanceOrder->getGatewayMac();
$this->balanceOrder = $balanceOrder;
}
/**
* @return string
*/
public function getMessageBody(): string
{
$portLogic = sprintf('%02x',$this->balanceOrder->getPortLogic());
$orderId = sprintf('%012x',$this->balanceOrder->getOrderId());
// $time = sprintf('%04x',$this->balanceOrder->getTime());
$time = sprintf('%04x',$this->balanceOrder->getTime());
return '01'.$portLogic.$orderId.$time;
}
public function getClientId(): string
{
// TODO: Implement getClientId() method.
}
public function getClientUid(): string
{
return $this->balanceOrder->getGatewayMac();
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: suhangyang
* Date: 2018/5/7
* Time: 上午9:41
*/
namespace Lib\send\command;
use Lib\send\Command;
use Lib\tool\StringTool;
use Lib\wx\pay_notify\order\ChargerOrder;
use Lib\wx\pay_notify\order\ChargerOrderTime;
use Log;
/**
* 充电命令
* Class ChargerCommand
* @package Lib\send\command
*/
class ChargerCommand extends Command
{
protected $headerCtrl = '04';
/**
* @var int
*/
private $type = 0;
/**
* @var int
*/
private $portLogicId;
/**l
* @var string
*/
private $outTradeNo;
/**
* @var int
*/
private $time;
/**
* ChargerCommand constructor.
* @param ChargerOrder $chargerOrder
* @throws \Exception
*/
public function __construct(ChargerOrder $chargerOrder)
{
$this->type = $chargerOrder->getChargerType();
// 获取端口的逻辑地址
$this->portLogicId = $chargerOrder->getPort()->getLogicNum();
$this->clientUid = $chargerOrder->getGateway()->getMacAddress();
$this->outTradeNo = $chargerOrder->getOrderId();
if ($this->type === 1) {
if ($chargerOrder instanceof ChargerOrderTime) {
$this->time = $chargerOrder->getChargerTime();
$this->clientUid = $chargerOrder->getGateway()->getMacAddress();
}
}
}
public function getMessageBody(): string
{
switch ($this->type) {
case 1 :
$this->messageBody = StringTool::padded($this->type, 2) . StringTool::padded($this->portLogicId, 2) . StringTool::padded($this->outTradeNo, 12) . StringTool::padded($this->time, 4);
break;
default:
break;
}
Log::debug('messageBody',[$this->messageBody]);
return $this->messageBody;
}
public function getClientId(): string
{
return $this->clientId;
}
public function getClientUid(): string
{
return $this->clientUid;
}
/**
* @return int
*/
public function getType(): int
{
return $this->type;
}
/**
* @param int $type
*/
public function setType(int $type)
{
$this->type = $type;
}
/**
* @return int
*/
public function getPortLogicId(): int
{
return $this->portLogicId;
}
/**
* @param int $portLogicId
*/
public function setPortLogicId(int $portLogicId)
{
$this->portLogicId = $portLogicId;
}
/**
* @return string
*/
public function getOutTradeNo(): string
{
return $this->outTradeNo;
}
/**
* @param string $outTradeNo
*/
public function setOutTradeNo(string $outTradeNo)
{
$this->outTradeNo = $outTradeNo;
}
/**
* @return int
*/
public function getTime(): int
{
return $this->time;
}
/**
* @param int $time
*/
public function setTime(int $time)
{
$this->time = $time;
}
/**
* @param mixed $sendContent
*/
public function setSendContent($sendContent)
{
$this->sendContent = $sendContent;
}
/**
* @param mixed $clientId
*/
public function setClientId($clientId)
{
$this->clientId = $clientId;
}
/**
* @param mixed $clientUid
*/
public function setClientUid($clientUid)
{
$this->clientUid = $clientUid;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/6/19
* Time: 下午3:15
*/
namespace Lib\send\command;
use Lib\send\Command;
use Lib\tool\StringTool;
class ConfirmChargerCommand extends Command
{
protected $headerCtrl = '14';
/**
* @var int
*/
private $orderId;
/**
* @var string
*/
private $gatewayMac;
public function getMessageBody(): string
{
return StringTool::padded($this->orderId,12);
}
public function getClientId(): string
{
return $this->gatewayMac;
}
public function getClientUid(): string
{
return $this->gatewayMac;
}
/**
* @return int
*/
public function getOrderId(): int
{
return $this->orderId;
}
/**
* @param int $orderId
*/
public function setOrderId(int $orderId): void
{
$this->orderId = $orderId;
}
/**
* @return string
*/
public function getGatewayMac(): string
{
return $this->gatewayMac;
}
/**
* @param string $gatewayMac
*/
public function setGatewayMac(string $gatewayMac): void
{
$this->gatewayMac = $gatewayMac;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/6/7
* Time: 上午10:41
*/
namespace Lib\send\command;
use Lib\tool\StringTool;
use Lib\send\Command;
class SimpleChargerCommand extends Command
{
protected $headerCtrl = '04';
/**
* @var string
*/
private $gatewayMac;
/**
* @var int
*/
private $orderId;
/**
* @var int
*/
private $chargerTime;
/**
* @var int
*/
private $logicNum;
/**
* @var int
*/
private $type = 1;
public function getMessageBody(): string
{
return $this->messageBody = StringTool::padded($this->type, 2) . StringTool::padded($this->logicNum, 2) . StringTool::padded($this->orderId
, 12) . StringTool::padded($this->chargerTime, 4);
}
public function getClientId(): string
{
// TODO: Implement getClientId() method.
}
public function getClientUid(): string
{
return $this->gatewayMac;
// TODO: Implement getClientUid() method.
}
/**
* @return string
*/
public function getGatewayMac(): string
{
return $this->gatewayMac;
}
/**
* @param string $gatewayMac
*/
public function setGatewayMac(string $gatewayMac): void
{
$this->gatewayMac = $gatewayMac;
}
/**
* @return int
*/
public function getOrderId(): int
{
return $this->orderId;
}
/**
* @param int $orderId
*/
public function setOrderId(int $orderId): void
{
$this->orderId = $orderId;
}
/**
* @return int
*/
public function getChargerTime(): int
{
return $this->chargerTime;
}
/**
* @param int $chargerTime
*/
public function setChargerTime(int $chargerTime): void
{
$this->chargerTime = $chargerTime;
}
/**
* @return int
*/
public function getLogicNum(): int
{
return $this->logicNum;
}
/**
* @param int $logicNum
*/
public function setLogicNum(int $logicNum): void
{
$this->logicNum = $logicNum;
}
/**
* @return int
*/
public function getType(): int
{
return $this->type;
}
/**
* @param int $type
*/
public function setType(int $type): void
{
$this->type = $type;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/5/30
* Time: 上午10:45
*/
namespace Lib\send\command;
use Lib\tool\Crc;
use Lib\send\Command;
class StopChargerCommand extends Command
{
/**
* @var int
*/
private $orderId;
/**
* @var int
*/
private $logicNum;
/**
* @var string
*/
private $gatewayMac;
protected $headerCtrl = '05';
public function getMessageBody(): string
{
$logicNum = sprintf('%02x', $this->logicNum);
$orderId = sprintf('%012x', $this->orderId);
return $this->messageBody = $logicNum . $orderId;
}
public function getClientId(): string
{
// TODO: Implement getClientId() method.
}
public function getClientUid(): string
{
return $this->gatewayMac;
}
/**
* @return int
*/
public function getOrderId(): int
{
return $this->orderId;
}
/**
* @param int $orderId
*/
public function setOrderId(int $orderId): void
{
$this->orderId = $orderId;
}
/**
* @return int
*/
public function getLogicNum(): int
{
return $this->logicNum;
}
/**
* @param int $logicNum
*/
public function setLogicNum(int $logicNum): void
{
$this->logicNum = $logicNum;
}
/**
* @return string
*/
public function getGatewayMac(): string
{
return $this->gatewayMac;
}
/**
* @param string $gatewayMac
*/
public function setGatewayMac(string $gatewayMac): void
{
$this->gatewayMac = $gatewayMac;
}
/**
* @return string
*/
public function getHeaderCtrl(): string
{
return $this->headerCtrl;
}
/**
* @param string $headerCtrl
*/
public function setHeaderCtrl(string $headerCtrl): void
{
$this->headerCtrl = $headerCtrl;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: suhangyang
* Date: 2018/5/1
* Time: 下午1:20
*/
namespace Lib\tool;
class ArrayToXml
{
/**
* @var array
*/
private $data;
/**
* @var string
*/
private $xml = '';
/**
* ArrayToXml constructor.
* @param array $data
*
*/
public function __construct(array $data =[])
{
$this->data = $data;
}
/**
* @param $data
* @return string
*/
public function arrayToXml($data)
{
foreach ($data as $key => $value)
{
if(blank($value))
{
continue;
}
$this->xml.="<$key>";
if(is_array($value))
{
$this->arrayToXml($value);
}else{
$this->xml.="<![CDATA[$value]]></$key>";
}
}
return '<xml>'.$this->xml.'</xml>';
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: suhangyang
* Date: 2018/4/25
* Time: 下午3:52
*/
namespace Lib\tool;
class Crc
{
const CRC_TABLE = [
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
];
/**
* @param $data
* @return int
*/
public static function crc($data)
{
$crc = 0xffffffff;
$size = strlen($data);
for($i=0;$i<$size;$i+=2)
{
$numHex = substr($data,$i,2);
$number = hexdec($numHex);
$tmp = ($crc^$number) & 0xff;
$crcRightMove = (hexdec(sprintf("%08x",$crc>>8)));
$crc = ($crcRightMove)^(self::CRC_TABLE[$tmp]);
}
$crc = $crc ^ 0xffffffff;
return sprintf('%08x',$crc);
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: suhangyang
* Date: 2018/5/7
* Time: 上午9:50
*/
namespace Lib\tool;
class StringTool
{
public static function padded(string $str,int $length,string $need = '0')
{
return sprintf("%0$length"."x",(int)$str);
}
}
\ No newline at end of file
# 7.12修订
# 7.12修订
## 网关连接初始化
![avatar](/Users/banice/ubuntu/senthink/cdz_gateway/bug_doc/guide/gateway_init.jpg)
## 开始充电
### 细节说明
* 口子从离线状态转为非离线状态之前需要先进行订单的同步(**网关离线则口子状态被视为离线**)
* 下位机需要判断服务器是否确认订单已开始充电,若没有应及时停止口子供电,进入订单取消。
* 服务器下发结束充电的命令需要添加一项新数据(结束方式)
![开始充电](/Users/banice/ubuntu/senthink/cdz_gateway/bug_doc/guide/charger.png)
## 议题
1. 为口子同步订单修改协议中的同步口子命令
2. 修改协议中的结束充电命令,增加结束方式
3. 由于粘包导致的更换口子问题是否解决?
4. 口子上报状态一直为离线的错误,注意上报状态应当是在状态改变事件发生时。
# 通讯协议v2(应用协议)
# 通讯协议v2(应用协议)
## 同步口子
1.下位机->服务器<font color='red'> 同步口子增加了订单的同步</font>
|preamble|headerFlag|headerCtrl|length|nonce|startNum|count|totalCount|portMac|portState|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---|:---|:---:|:---:|:---:|:---:|
|协议头|是否加密|03|包长|随机字符|口子起始逻辑号(1byte)|包中口子数(1byte)|网关下口子总数(1byte)|口子mac地址(8bytes*n)|口子状态(n bytes)|crc|
2.服务器->下位机
|preamble|headerFlag|headerCtrl|length|nonce|startNum|count|totalCount|order_count|logic_num|order_id|time|...|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|03|包长|随机字符|起始逻辑号|包中口子数|网关口子总数|订单数(1 byte)|口子逻辑号(1 byte)|订单号(6 bytes)|剩余充电时间(2 bytes)||crc|
## 开始充电(按时间充电)
1.服务器->下位机
|preamble|headerFlag|headerCtrl|length|nonce|type|port|outTradeNo|time|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|04|包长|随机字符|01|口子逻辑号(1byte)|订单号(6bytes)|充电时间(2bytes)|crc|
2.下位机->服务器修改状态字段位置
|preamble|headerFlag|headerCtrl|length|nonce|type|port|state|outTradeNo|power|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---|:---:|:---:|
|协议头|是否加密|04|包长|随机字符|01|口子逻辑号(1byte)|状态(1byte)|订单号(6bytes)|当前口子用电量(4bytes)|crc|
3.服务器->下位机
|preamble|headerFlag|headerCtrl|length|nonce|outTradeNo|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|14|包长|随机字符|订单号(6bytes)|crc|
## 结束充电
<font color ='red'>添加结束类型字段,finish_type默认为0,服务器远程结束时下位机原样返回给服务器,下位机自主结束返回00</font>
1.服务器->下位机
|preamble|headerFlag|headerCtrl|length|nonce|port|outTradeNo|finish_type|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|05|包长|随机字符|端口逻辑号|订单号(6bytes)|结束类型(1byte)|crc|
2.下位机->服务器修改状态字段位置
|preamble|headerFlag|headerCtrl|length|nonce|type|port|state|outTradeNo|power|finish_type|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---|:---:|:---:|:---:|
|协议头|是否加密|05|包长|随机字符|01|口子逻辑号(1byte)|状态(1byte)|订单号(6bytes)|当前口子用电量(4bytes)|结束类型(1byte)crc|
3.服务器->下位机
|preamble|headerFlag|headerCtrl|length|nonce|port|outTradeNo|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|15|包长|随机字符|口子逻辑号|订单号(6bytes)|crc|
## 上报电表电量
1.服务器->下位机
|preamble|headerFlag|headerCtrl|length|nonce|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|06|包长|随机字符|crc|
2.下位机->服务器
|preamble|headerFlag|headerCtrl|length|nonce|powerCapacity|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|06|包长|随机字符|电表用电量(4bytes)|crc|
## 上报充电功率
* 位机->服务器
以下二选一
|preamble|headerFlag|headerCtrl|length|nonce|port|startTime|intervalTime|count|powerData|powerCapacity|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|07|包长|随机字符|口子逻辑号(1byte)|起始时间(4bytes)|间隔时间(1byte)|功率数据个数(1byte)|功率数据(2*n bytes)|用电量(4*n bytes)|crc|
|preamble|headerFlag|headerCtrl|length|nonce|port|powerData|powerCapacity|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|17|包长|随机字符|口子逻辑号(1 byte)|功率数据(2bytes)|用电量(4bytes)|crc|
## 口子状态
* 下位机->服务器(口子上线)
|preamble|headerFlag|headerCtrl|length|nonce|count|port|mac|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|08|包长|随机字符|上报口子个数(1byte)|口子逻辑地址(1*n bytes)|口子mac地址(8*n bytes|crc|
* 下位机->服务器(口子离线)
|preamble|headerFlag|headerCtrl|length|nonce|count|port|mac|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|09|包长|随机字符|上报口子个数(1byte)|口子逻辑地址(1*n bytes)|mac地址|crc|
## 设置参数
* HeaderCtrl : 0a
|字段名|长度|说明|
|:---:|:---:|:---:|
|invertal_time|2|设备上报数据间隔(秒)|
|getpriceconfig|1|获取计价配置时间间隔(秒)|
|powerupperlimit|2|功率上限|
|powersaturateinvertal_time|1|充满自停功率检测|
|extra_time|1|充满自停额外供电时间(单位分钟)|
|powerlowerlimit|1|功率下限|
|detect_time|1|功率上限检测时间|
## 上报一口子状态
1.服务器->下位机
|preamble|headerFlag|headerCtrl|length|nonce|mac|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|0b|包长|随机字符|口子mac地址|crc|
2. 下位机->服务器
|preamble|headerFlag|headerCtrl|length|nonce|port|mac|state|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|0b|包长|随机字符|口子逻辑号(1byte)|口子mac地址(8bytes)|状态(1byte)|crc|
## 逻辑地址同步
1.服务器->下位机
|preamble|headerFlag|headerCtrl|length|nonce|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|0c|包长|随机字符|crc|
2.下位机->服务器
|preamble|headerFlag|headerCtrl|length|nonce|startNum|count|mac|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|0d|包长|随机字符|逻辑地址起始序号(1byte)|包中mac地址个数(1byte)|mac地址(n*8 bytes)|crc|
3.服务器->下位机
|preamble|headerFlag|headerCtrl|length|nonce|startNum|count|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|1d|包长|随机字符|逻辑起始序号|确认的口子数|crc|
## 状态位表(10进制)
<font color='red'>添加41,42状态码</font>
|state|说明|
|:---:|:---:|
|10|离线|
|11|空闲(在线)|
|12|正在充电|
|13|异常(充电失败)|
|14|插头脱落|
|30|计时结束|
|31|远程关闭|
|32|插头脱落|
|33|充满自停|
|34|功率超限|
|35|关闭失败|
|36|插头插上,正常充电|
|41|用户主动结束|
|42|插口脱落超时结束|
\ No newline at end of file
...@@ -25,6 +25,7 @@ class Bintohex ...@@ -25,6 +25,7 @@ class Bintohex
$data = $data[1]; $data = $data[1];
$packageLength = strlen($data); $packageLength = strlen($data);
$packageLength/=2; $packageLength/=2;
......
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