package com.imdroid.sideslope.sal;

import lombok.Data;

import java.time.LocalDateTime;

/**
 * 基站 & 测站设备
 *
 * @author Layton
 * @date 2023/2/3 20:39
 */
@Data
public class Device {

    /**
     * 基站
     */
    public static final int DEVICE_BASE_STATION = 1;

    /**
     * 测站
     */
    public static final int DEVICE_ROVER = 0;

    private String name;
    private Integer tenantId;

    private String deviceId;

    private String parentId;
    private String projectId;
    private String fwdId;

    private Integer deviceType;

    private Integer calcGroupId;
    private Short opMode;

    int d3xxCount = 0;
    int d3xxbytes = 0;
    int d341Count = 0;
    int d341bytes = 0;
    int d342Bytes = 0;
    int d342Count = 0;
    int d341In42Count = 0;
    int satelitesInUse = 0;//平均卫星数
    int sataStatCount = 0;

    Double latitude;
    Double longitude;
    Double altitude;

    Double iPose;
    Double iPosn;
    Double iPosd;

    LocalDateTime lastRxTime;
    int lastRxHead = 0;

    public void updateRx(int head, int bytes,int count){
        lastRxHead = head;
        lastRxTime = LocalDateTime.now();
        switch (head){
            case 0xd3f0:
                clearStat();
                break;
            case 0xd3f2:
                break;
            case 0xd331:
                d3xxCount+=count;
                d3xxbytes += bytes;
                break;
            case 0xd341:
                d341Count+=count;
                d341bytes += bytes;
                break;
            case 0xd342:
                d342Count ++;
                d342Bytes += bytes;
                d341In42Count += count;
                break;
        }
    }

    public void updateSatelitesNum(int num){
        if(num>0) {
            sataStatCount++;
            satelitesInUse = (satelitesInUse*(sataStatCount-1) + num) / sataStatCount;
        }
    }

    public void clearStat(){
        d3xxCount = 0;
        d3xxbytes = 0;
        d341Count = 0;
        d341bytes = 0;
        sataStatCount = 0;
        satelitesInUse = 0;
    }

    public void clearD342Stat(){
        d342Count = 0;
        d342Bytes = 0;
        d341In42Count = 0;
    }
}
