⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 payloadtemplate.java

📁 Open DMT GPS server source code
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if (this.fields == null) { this.fields = new Field[0]; }        return this.fields;    }        public boolean getRepeatLast()    {        return this.repeatLast;    }    // ------------------------------------------------------------------------    // ------------------------------------------------------------------------    // ------------------------------------------------------------------------    private static final char FIELD_VALUE_SEPARATOR = '|';    public static class Field    {        private boolean hiRes   = false;        private int     fldType = -1;        private int     fldNdx  = 0;        private int     fldLen  = 0;                public Field(int type, boolean hiRes, int index, int length) {            this.fldType = type;            this.hiRes   = hiRes;            this.fldNdx  = index;            this.fldLen  = length;        }                public Field(long mask) {            // 24 bits:            //   ABBBBBBB CCCCCCCC DDDDDDDD            //   A - hi/low resolution            //   B - type            //   C - index            //   D - length            this.fldType = (int)(mask >> 16) & 0x7F;            this.hiRes   = ((mask & 0x800000) != 0);            this.fldNdx  = (int)(mask >>  8) & 0xFF;            this.fldLen  = (int)mask & 0xFF;        }                public Field(String s) {            // "<type>|[H|L]|<index>|<length>"            String f[] = StringTools.parseString(s,FIELD_VALUE_SEPARATOR);            this.fldType = (f.length > 0)? StringTools.parseInt(f[1],-1) : -1;            this.hiRes   = (f.length > 1)? f[0].equalsIgnoreCase("H") : false;            this.fldNdx  = (f.length > 2)? StringTools.parseInt(f[2], 0) :  0;            this.fldLen  = (f.length > 3)? StringTools.parseInt(f[3], 0) :  0;        }                public int getType() {            return this.fldType;        }                public int getPrimitiveType() {            switch (this.fldType) {                case FIELD_GPS_POINT:    return PRIMITIVE_GPS;                case FIELD_STRING:       return PRIMITIVE_STRING;                case FIELD_STRING_PAD:   return PRIMITIVE_STRING;                case FIELD_ENTITY:       return PRIMITIVE_STRING;                case FIELD_ENTITY_PAD:   return PRIMITIVE_STRING;                case FIELD_BINARY:       return PRIMITIVE_BINARY;                default:                 return PRIMITIVE_LONG;            }        }                public boolean isValidType() {            return true;        }                public boolean isSigned() {            switch (this.fldType) {                case FIELD_GPS_MAG_VARIATION:                case FIELD_GPS_GEOID_HEIGHT:                case FIELD_ALTITUDE:                case FIELD_TEMP_LOW:                case FIELD_TEMP_HIGH:                case FIELD_TEMP_AVER:                    return true;                default:                    return false;            }        }                public boolean isHex() {            switch (this.fldType) {                case FIELD_HEADING:                    return !this.hiRes;                case FIELD_STATUS_CODE:                case FIELD_SEQUENCE:                case FIELD_INPUT_ID:                case FIELD_INPUT_STATE:                case FIELD_OUTPUT_ID:                case FIELD_OUTPUT_STATE:                case FIELD_GEOFENCE_ID:                    return true;                default:                    return false;            }        }        public boolean isHiRes() {            return this.hiRes;        }                public int getIndex() {            return this.fldNdx;        }                public int getLength() {            return this.fldLen;        }                public int parseString(String s[], int sndx, Payload payload) {            // NOTE: This should specifically set the index to the proper payload location!!            int length = this.getLength();            switch (this.getPrimitiveType()) {                case PRIMITIVE_GPS: {                    double lat = StringTools.parseDouble(s[sndx++], 0.0);                    double lon = (sndx < s.length)? StringTools.parseDouble(s[sndx++], 0.0) : 0.0;                    payload.writeGPS(new GeoPoint(lat,lon), length);                    break;                }                case PRIMITIVE_STRING: {                    payload.writeString(s[sndx++], length);                    break;                }                case PRIMITIVE_BINARY: {                    byte b[] = StringTools.parseHex(s[sndx++], new byte[0]);                    payload.writeBytes(b, length);                    break;                }                case PRIMITIVE_LONG:                default: {                    long val = s[sndx].startsWith("0x")?                        StringTools.parseHexLong(s[sndx++], 0L) :                        StringTools.parseLong(s[sndx++], 0L);                    if (this.isSigned()) {                        payload.writeLong(val, length);                    } else {                        payload.writeULong(val, length);                    }                    break;                }            }            return sndx;        }        public String toString() {            StringBuffer sb = new StringBuffer();            sb.append(this.getType());            sb.append(FIELD_VALUE_SEPARATOR);            sb.append(this.isHiRes()?"H":"L");            sb.append(FIELD_VALUE_SEPARATOR);            sb.append(this.getIndex());            sb.append(FIELD_VALUE_SEPARATOR);            sb.append(this.getLength());            return sb.toString();        }        public boolean equals(Object other) {            if (other instanceof Field) {                return this.toString().equals(other.toString());            } else {                return false;            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -