package com.sunzee.base;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.hboxs.serialport.SerialPortDevice;
import com.hboxs.serialport.SerialPortManager;
import com.orhanobut.hawk.Hawk;
import com.sunzee.model.Heartbeat;
import com.sunzee.model.domain.Name;
import com.sunzee.service.MyService;
import com.sunzee.utils.FileUtil;
import com.sunzee.utils.SharedPreferencesUtils;

/**
 * Created by MinKin.
 */
public class BaseApplication extends Application {

    public static Context mContext;


    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;
        Hawk.init(this).build();
        Heartbeat.deviceId = FileUtil.getDeviceId();
        Heartbeat.managerId = (String) SharedPreferencesUtils.getParam(Name.SYSTEM_ID, "");
        SerialPortDevice device = new SerialPortDevice("/dev/ttyS2", "9600");
        SerialPortManager.getInstance().open(device);
        startMyService();
        firstHeartbeat();
    }

    /**
     * 首次心跳
     */
    private void firstHeartbeat() {
        Intent intent = new Intent(this, MyService.class);
        Bundle bundle = new Bundle();
        bundle.putInt("first", 4);
        intent.putExtras(bundle);
        startService(intent);
    }

    private void startMyService() {
        Intent intentOne = new Intent(this, MyService.class);
        startService(intentOne);
    }

    public static Context getContext() {
        return mContext;
    }


}
