package com.wdkl.app.ncs.callingbed.helper;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;

import com.wdkl.ncs.android.middleware.common.Constant;
import com.wdkl.ncs.android.middleware.tcp.channel.OtherUtil;


/*
 * 紧急按钮辅助类
 */
public class SOSHelper {

    private final static Handler handler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(Message msg) {
            sosStop();
        }
    };

    public static void sosStart() {
        SerialPortHelper.setSosLight("2");
        //如果该床位绑定了紧急按钮则直接通过紧急按钮设备id发送sos请求
        if (Constant.EMERGENCY_ID != -1) {
            OtherUtil.sendSosCall(Constant.EMERGENCY_ID);
        } else {
            OtherUtil.sendSosCall(Constant.DEVICE_ID);
        }

        //60s之后紧急按钮灯自动复位
        handler.removeCallbacksAndMessages(null);
        handler.sendEmptyMessageDelayed(110, 120000);
    }

    public static void sosStop() {
        handler.removeCallbacksAndMessages(null);
        if (Constant.day_state == 1) {
            SerialPortHelper.setSosLight("1");
        } else {
            SerialPortHelper.setSosLight("0");
        }
    }
}
