|
@@ -25,7 +25,7 @@
|
|
|
*/
|
|
|
use \GatewayWorker\Lib\Gateway;
|
|
|
//use \GatewayWorker\Lib\DbConnection;
|
|
|
-//use think\Db;
|
|
|
+use think\Db;
|
|
|
use think\App;
|
|
|
|
|
|
class Events
|
|
@@ -45,11 +45,27 @@ class Events
|
|
|
*/
|
|
|
public static function onMessage($client_id, $message)
|
|
|
{
|
|
|
- //echo $message.PHP_EOL;
|
|
|
- //file_put_contents('1.json',$message.PHP_EOL,FILE_APPEND);
|
|
|
- $info = Db::name('gateway_test')->insertGetId(['msg'=>$message,'datetime'=>date('Y-m-d H:i:s')]);
|
|
|
+ //echo $message.PHP_EOL;
|
|
|
+ //file_put_contents('1.json',$message.PHP_EOL,FILE_APPEND);
|
|
|
+ //Gateway::sendToAll($client_id.':'.$message);
|
|
|
|
|
|
- Gateway::sendToAll($client_id.':'.$message);
|
|
|
+ //php版本用7.3
|
|
|
+
|
|
|
+ try{
|
|
|
+
|
|
|
+ $data = self::get_data($message);
|
|
|
+ if(!empty($data)){
|
|
|
+ //file_put_contents('1.json',json_encode($data).PHP_EOL,FILE_APPEND);
|
|
|
+ $info = Db::name('gateway_test')->insert($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ }catch (\Exception $e)
|
|
|
+ {
|
|
|
+ //echo $e->getMessage();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //Gateway::sendToAll($client_id.':'.$message);
|
|
|
|
|
|
return;
|
|
|
|
|
@@ -115,6 +131,90 @@ class Events
|
|
|
Db::commit();
|
|
|
}
|
|
|
|
|
|
+ public static function test31(){
|
|
|
+ //血糖,5秒
|
|
|
+ $str = ' 7.2mmol/L (GLUC 2023/12/29 06:05 SN:PMA231223000006 )';
|
|
|
+ //尿酸,16秒
|
|
|
+ //$str = ' 381umol/L ( UA 2023/12/29 06:21 SN:PMA231223000006 )';
|
|
|
+ //胆总,26秒
|
|
|
+ //$str = ' 3.91mmol/L (CHOL 2023/12/29 06:25 SN:PMA231223000006 )';
|
|
|
+
|
|
|
+ $result = self::get_data($str);
|
|
|
+ dump($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static function get_data($str = ''){
|
|
|
+ $str = trim($str);
|
|
|
+
|
|
|
+ //判断为空
|
|
|
+ if(empty($str)){
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ //找到编号起始点
|
|
|
+ $SN_start = strpos($str,'SN:');
|
|
|
+ if($SN_start === false){
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ //编号
|
|
|
+ $SN = mb_substr($str,$SN_start+3,15);
|
|
|
+ if(empty($SN)){
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断类型
|
|
|
+ $type_gluc = strpos($str,'GLUC');
|
|
|
+ $type_ua = strpos($str,'UA');
|
|
|
+ $type_chol = strpos($str,'CHOL');
|
|
|
+ if($type_gluc === false && $type_ua === false && $type_chol === false){
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ //确认类型
|
|
|
+ $type = '';
|
|
|
+ $type_text = '';
|
|
|
+ if($type_gluc){
|
|
|
+ $type = 'GLUC';
|
|
|
+ $type_text = '血糖';
|
|
|
+ }
|
|
|
+ if($type_ua){
|
|
|
+ $type = 'UA';
|
|
|
+ $type_text = '尿酸';
|
|
|
+ }
|
|
|
+ if($type_chol){
|
|
|
+ $type = 'CHOL';
|
|
|
+ $type_text = '总胆固醇';
|
|
|
+ }
|
|
|
+ if(empty($type) || empty($type_text)){
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ //数值
|
|
|
+ $value_end = strpos($str,'/L');
|
|
|
+ if($value_end === false){
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ $value = mb_substr($str,0,$value_end+2);
|
|
|
+ if(empty($value)){
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ //返回
|
|
|
+ $data = [
|
|
|
+ 'msg' => $str,
|
|
|
+ 'datetime' =>date('Y-m-d H:i:s'),
|
|
|
+ 'createtime' =>time(),
|
|
|
+
|
|
|
+ 'sn' => $SN,
|
|
|
+ 'type' => $type,
|
|
|
+ 'type_text' => $type_text,
|
|
|
+ 'value' => $value,
|
|
|
+ ];
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 当客户端断开连接时
|