public static function getLogger() { if (self::$log == null) { if (self::$DEBUG) { self::$log = Logger::getLogger("db"); // self::$log = Logger::getLogger("console"); } else { self::$log = Logger::getLogger("custom"); } } return self::$log; }
/** * 当客户端发来消息时触发 * @param int $client_id 连接id * @param string $message 具体消息 * @link http://gatewayworker-doc.workerman.net/gateway-worker-development/onmessage.html */ public static function onMessage($client_id, $message) { // 向所有人发送 @see http://gatewayworker-doc.workerman.net/gateway-worker-development/send-to-all.html // Gateway::sendToAll("$client_id said $message"); CustomLogger::getLogger()->info("{$client_id} [RECV] {$message}"); $data = ProtocolParser::parseProtocolData($message); if (is_null($data)) { return; } Gateway::bindUid($client_id, $data->getDeviceSn()); $cmdParser = CmdFactory::createCMDParserFromProtocolData($data); $cmdParser->handleCmd(); }
public static function parseProtocolData($buf) { $buf = trim($buf); $parts = explode("*", $buf); if (count($parts) != ProtocolData::$PART_LEN) { CustomLogger::getLogger()->error("The Content[" . $buf . "] is not valid"); return null; } if (Utils::startsWith($parts[0], "[")) { $parts[0] = substr($parts[0], 1, strlen($parts[0]) - 1); } if (Utils::endsWith($parts[3], "]")) { $parts[3] = substr($parts[3], 0, strlen($parts[3]) - 1); } return new ProtocolData($parts[0], $parts[1], $parts[2], $parts[3]); }
public function parse() { $content = $this->_protocol_data->getContent(); CustomLogger::getLogger()->info("UD Command Parser handler data [" . $content . "]"); $parts = explode(",", $content); try { $report_time = $parts[1] . " " . $parts[2]; $flag = $parts[3]; //分析维度信息,如果是南纬,在数据前添加负号 $lat = $parts[4]; if ($parts[5] == "S") { $lat = "-" . $lat; } // 分析经度信息,如果是西经,则在前面添加负号 $long = $parts[6]; if ($parts[7] == "W") { $long = "-" . $parts[6]; } CustomLogger::getLogger()->info("[" . $report_time . "]" . " Update location [{$lat},{$long}]"); // save to the database DB::insert('db_location', array('sn' => $this->_protocol_data->getDeviceSn(), 'latitude' => $lat, 'longitude' => $long, 'report_time' => $report_time, 'record_time' => time(), 'flag' => $flag)); $speed = $parts[8]; $direction = $parts[9]; $height = $parts[10]; $num_starts = $parts[11]; $gsm_info = $parts[12]; $power = $parts[13]; $walk_num = $parts[14]; $rotate_num = $parts[15]; $device_status = $parts[16]; $num_bases = $parts[17]; $connect_base = $parts[18]; $contry_code = $parts[19]; $net_code = $parts[20]; $tmp = $parts[21]; $humi = $parts[22]; $bt_status = $parts[23]; // discard other info } catch (Exception $e) { CustomLogger::getLogger()->error($e->getMessage()); } }
public static function createCMDParserFromProtocolData($protocol_data) { $content = $protocol_data->getContent(); $parts = explode(",", $content); if ($parts[0] == "LK") { CustomLogger::getLogger()->info("Create the LKCmdParser"); return new LKCmdParser($protocol_data); } else { if ($parts[0] == "UD" || $parts[0] == "UD2") { CustomLogger::getLogger()->info("Create the UDCmdParser"); return new UDCmdParser($protocol_data); } else { if ($parts[0] == "AL") { CustomLogger::getLogger()->info("Create the ALCmdParser"); return new ALCmdParser($protocol_data); } else { CustomLogger::getLogger()->error("unknown command type" . $parts[0]); } } } }
public function reply() { CustomLogger::getLogger()->info("LKCmdParser reply the cmd"); Gateway::sendToUid($this->_protocol_data->getDeviceSn(), $this->format_reply_string()); }