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

📄 event.java

📁 Open DMT GPS server source code
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// ----------------------------------------------------------------------------// Copyright 2006-2008, Martin D. Flynn// All rights reserved// ----------------------------------------------------------------------------//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// // http://www.apache.org/licenses/LICENSE-2.0// // Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.//// ----------------------------------------------------------------------------// Change History://  2006/03/26  Martin D. Flynn//     -Initial release//  2006/04/02  Martin D. Flynn//     -Minor changes to 'toString()'//  2007/01/25  Martin D. Flynn//     -Added custom fields FIELD_ENTITY, FIELD_ENTITY_PAD, FIELD_STRING_PAD, //      and various FILED_OBJ_xxxx fields//     -Limit temperature ranges to -126/126 Low-Res, -3276.6/3276.6 High-Res//  2007/02/11  Martin D. Flynn//     -Added FIELD_OBC_COOLANT_LEVEL, FIELD_OBC_OIL_PRESSURE//     -Changed FIELD_OBC_ENGINE_TEMP to FIELD_OBC_COOLANT_TEMP and added hiRes mode//  2007/02/18  Martin D. Flynn//     -Changed FIELD_OBC_FAULT_CODE to FIELD_OBC_J1708_FAULT//  2007/02/25  Martin D. Flynn//     -Added support for PayloadTemplate.FIELD_ODOMETER//  2008/02/04  Martin D. Flynn//     -Added support for PayloadTemplate.[FIELD_OBC_FUEL_TOTAL|FIELD_OBC_FUEL_IDLE]// ----------------------------------------------------------------------------package org.opendmtp.server.base;import java.lang.*;import java.util.*;import java.io.*;import java.net.*;import java.sql.*;import org.opengts.util.*;import org.opendmtp.codes.*;import org.opendmtp.server.db.*;public class Event{        // ------------------------------------------------------------------------    private static final long INVALID_TEMPERATURE = -99999L;        // ------------------------------------------------------------------------    // types:    //      long    //      double    //      byte    //      GeoPoint    //      String    // ------------------------------------------------------------------------    // ------------------------------------------------------------------------    /* the fields that made up this object */    private Packet                packet        = null;    private PayloadTemplate       custTemplate  = null;    private int                   custFieldLen  = 0;    private DMTPGeoEvent          geoEvent      = null;    // ------------------------------------------------------------------------        public Event(Packet pkt)        throws PacketParseException    {        this(null, pkt);    }    public Event(String ipAddr, Packet pkt)        throws PacketParseException    {        super();        this.packet    = pkt;        this.geoEvent  = new DMTPGeoEvent();        /* Validate Packet */        if (this.packet == null) {            // no packet specified            // internal error (this should never happen)            throw new PacketParseException(ServerErrors.NAK_PACKET_LENGTH, this.packet); // errData ok        } else        if (!this.packet.isEventType()) {            // not an event packet            // internal error (this should never happen)            throw new PacketParseException(ServerErrors.NAK_PACKET_TYPE, this.packet); // errData ok        } else        if (!this.packet.hasPayload()) {            // client did not include payload            throw new PacketParseException(ServerErrors.NAK_PACKET_PAYLOAD, this.packet); // errData ok        }        /* get Event Payload Definition? */        this.custTemplate = this.packet.getPayloadTemplate();        if (this.custTemplate == null) {            int hdrType = (this.packet.getPacketHeader() << 8) | this.packet.getPacketType();            Print.logError("PayloadTemplate not found: 0x" + StringTools.toHexString(hdrType,16));            throw new PacketParseException(ServerErrors.NAK_FORMAT_NOT_RECOGNIZED, this.packet); // errData ok        }                /* save ip address */        this.setEventValue(DMTPGeoEvent.FLD_ipAddress, ((ipAddr!=null)?ipAddr:""));        /* parse */        this.custFieldLen = 0;        this._decodeEvent();    }    // ------------------------------------------------------------------------    public String getIPAddress()    {        return this.getGeoEvent().getIPAddress();    }    // ------------------------------------------------------------------------    public Packet getPacket()    {        return this.packet;    }        public DMTPGeoEvent getGeoEvent()    {        return this.geoEvent;    }        public long getSequence()    {        return this.getGeoEvent().getSequence();    }        public int getSequenceLength()    {        return this.getGeoEvent().getSequenceLength();    }    // ------------------------------------------------------------------------        private void setEventValue(String fldName, Object val, int ndx)     {        this.getGeoEvent().setEventValue(fldName, val, ndx);    }    private void setEventValue(String fldName, Object val)     {        this.getGeoEvent().setEventValue(fldName, val);    }    public void setEventValue(String fldName, long val, int ndx)     {        this.getGeoEvent().setEventValue(fldName, val, ndx);    }    public void setEventValue(String fldName, long val)     {        this.getGeoEvent().setEventValue(fldName, val);    }    public void setEventValue(String fldName, double val, int ndx)     {        this.getGeoEvent().setEventValue(fldName, val, ndx);    }    public void setEventValue(String fldName, double val)    {        this.getGeoEvent().setEventValue(fldName, val);    }    // ------------------------------------------------------------------------    public byte[] getByteValue(String fldName, byte[] dft)    {        return this.getGeoEvent().getByteValue(fldName, dft);    }    public  byte[] getByteValue(String fldName,  byte[] dft, int ndx)    {        return this.getGeoEvent().getByteValue(fldName, dft, ndx);    }    public String getStringValue(String fldName, String dft)    {        return this.getGeoEvent().getStringValue(fldName, dft);    }    public String getStringValue(String fldName, String dft, int ndx)    {        return this.getGeoEvent().getStringValue(fldName, dft, ndx);    }    public long getLongValue(String fldName, long dft)    {        return this.getGeoEvent().getLongValue(fldName, dft);    }    public long getLongValue(String fldName, long dft, int ndx)    {        return this.getGeoEvent().getLongValue(fldName, dft, ndx);    }        public double getDoubleValue(String fldName, double dft)    {        return this.getGeoEvent().getDoubleValue(fldName, dft);    }    public double getDoubleValue(String fldName, double dft, int ndx)    {        return this.getGeoEvent().getDoubleValue(fldName, dft, ndx);    }        public GeoPoint getGeoPointValue(String fldName, GeoPoint dft)    {        return this.getGeoEvent().getGeoPointValue(fldName, dft);    }    public GeoPoint getGeoPointValue(String fldName, GeoPoint dft, int ndx)    {        return this.getGeoEvent().getGeoPointValue(fldName, dft, ndx);    }    // ------------------------------------------------------------------------    private void _decodeEvent()        throws PacketParseException    {        Payload payload = this.packet.getPayload(true);                /* raw data */        this.setEventValue(DMTPGeoEvent.FLD_rawData   , this.packet.toString());        /* defaults */        this.setEventValue(DMTPGeoEvent.FLD_statusCode, StatusCodes.STATUS_NONE);        this.setEventValue(DMTPGeoEvent.FLD_timestamp , DateTime.getCurrentTimeSec());                /* parse payload */        boolean hasStatusCode = false;        boolean hasGeoPoint = false;        payload.resetIndex();        for (this.custFieldLen = 0; payload.hasAvailableRead(); this.custFieldLen++) {                        /* safety net */            if (this.custFieldLen >= PayloadTemplate.MAX_FIELD_COUNT) {                Print.logError("Invalid number of fields: " + this.custFieldLen);                Payload p = new Payload();                p.writeULong(this.packet.getPacketType(), 1);                byte errData[] = p.getBytes();                throw new PacketParseException(ServerErrors.NAK_FORMAT_DEFINITION_INVALID, this.packet, errData); // formatType, fieldIndex            }                        /* get field */            PayloadTemplate.Field field = this.custTemplate.getField(this.custFieldLen);            if (field == null) { break; }            int type      = field.getType();            boolean hiRes = field.isHiRes();            int ndx       = field.getIndex();            int length    = field.getLength();            if (length == 0) {                Print.logError("Invalid Field length: " + StringTools.toHexString(type,8));                Payload p = new Payload();

⌨️ 快捷键说明

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