I am new to Protocol buffer.  I have huge file that is in C# and I want to 
convert that to protocol buffer definition.  

How do I do that?  Do i need to write Protocol definition line by line?  

See attached file (Anything marked as non-serialized could be omitted; 
pretty much anything that’s a list can be skipped.) 

thanks in advance.


 

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Threading;
using System.Reflection;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using SOI;
using gtri_uav;
using System.Runtime.CompilerServices;

using LatLonAltTuple = System.Tuple<double, double, double>;
using LatLonAltRadiusTuple = System.Tuple<double, double, double, double>;
using IDRGBTuple = System.Tuple<int, int, int, int>;
using System.Threading.Tasks;
using System.ComponentModel;

namespace SOIComms
{
    public enum AutonomyMode
    {
        MANUAL = 0,
        PICCOLO = 1,
        PAYLOAD = 2,
        NOT_CONNECTED = 255
    }

    public enum UAVCondition
    {
        GOOD,
        CAUTION,
        ERROR,
        INVALID,
        UNKNOWN
    };

    [Serializable]
    public struct AutonomyVersions
    {
        public uint AutonomyVersionHash;
        public uint AutopilotBoardSerialNum;
        public byte AutopilotSoftwareVersionMajor;
        public byte AutopilotSoftwareVersionMinor;
        public byte AutopilotSoftwareVersionSubversion;
        public byte AutopilotSoftwareVersionPatch;

        public AutonomyVersions(uint autonomyVersionHash, uint autopilotBoardSerialNum, byte autopilotSoftwareVersionMajor, byte autopilotSoftwareVersionMinor,
            byte autopilotSoftwareVersionSubversion, byte autopilotSoftwareVersionPatch)
        {
            AutonomyVersionHash = autonomyVersionHash;
            AutopilotBoardSerialNum = autopilotBoardSerialNum;
            AutopilotSoftwareVersionMajor = autopilotSoftwareVersionMajor;
            AutopilotSoftwareVersionMinor = autopilotSoftwareVersionMinor;
            AutopilotSoftwareVersionSubversion = autopilotSoftwareVersionSubversion;
            AutopilotSoftwareVersionPatch = autopilotSoftwareVersionPatch;
        }

        public AutonomyVersions(AutonomyVersions a)
        {
            AutonomyVersionHash = a.AutonomyVersionHash;
            AutopilotBoardSerialNum = a.AutopilotBoardSerialNum;
            AutopilotSoftwareVersionMajor = a.AutopilotSoftwareVersionMajor;
            AutopilotSoftwareVersionMinor = a.AutopilotSoftwareVersionMinor;
            AutopilotSoftwareVersionSubversion = a.AutopilotSoftwareVersionSubversion;
            AutopilotSoftwareVersionPatch = a.AutopilotSoftwareVersionPatch;
        }
    }

    [Serializable]
    public class UAVState : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        // This method is called by the Set accessor of each property.
        // The CallerMemberName attribute that is applied to the optional propertyName
        // parameter causes the property name of the caller to be substituted as an argument.
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void setFlying()
        {
            if (RPM >= 0)
            {
                const int TIME_BETWEEN_STATE_CHANGE_AND_TAKEOFF_S = 9;
                LaunchTime = DateTime.Now.Subtract(new TimeSpan(0, 0, TIME_BETWEEN_STATE_CHANGE_AND_TAKEOFF_S));
                LaunchTimeSet = true;

                if (m_timerChangeDelegate != null)
                {
                    m_timerChangeDelegate(true, this);
                }
            }
        }

        public static float getPositionUpdatesPerSecond(float seconds, List<DateTime> positionUpdateTimes, DateTime serverTime)
        {
            List<DateTime> times = positionUpdateTimes.Where(d => serverTime.Subtract(d).TotalSeconds <= seconds).ToList();
            return times.Count / seconds;
        }
        public static float getPositionUpdatesPerSecond(float span, float divisor, List<DateTime> positionUpdateTimes, DateTime serverTime)
        {
            List<DateTime> times = positionUpdateTimes.Where(d => serverTime.Subtract(d).TotalSeconds <= span).ToList();
            return times.Count / divisor;
        }

        #region Member Vars

        #region Serialized Vars

        private int m_ID = 0;
        public int ID { get { return m_ID; } }

        private string m_tailNumber = "";
        public string TailNumber
        {
            get { return m_tailNumber; }
            set
            {
                LastUpdateTime = DateTime.Now;
                if (value != m_tailNumber)
                {
                    m_tailNumber = value;
                    NotifyPropertyChanged();
                }
            }
        }

        private int m_squadronID = 0;
        public int SquadronID 
        { 
            get { return m_squadronID; } 
            set 
            { 
                LastUpdateTime = DateTime.Now;
                if (value != m_squadronID)
                {
                    m_squadronID = value;
                    NotifyPropertyChanged();
                }
            } 
        }
        private double m_latDeg = 0;
        public double LatDeg
        {
            get { return m_latDeg; }
            set
            {
                LastUpdateTime = DateTime.Now;
                if (value != m_latDeg)
                {
                    m_latDeg = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private double m_lonDeg = 0;
        public double LonDeg 
        { 
            get { return m_lonDeg; }
            set
            {
                LastUpdateTime = DateTime.Now;
                if (value != m_lonDeg)
                {
                    m_lonDeg = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private double m_altM = 0;
        public double AltM 
        { 
            get { return m_altM; } 
            set 
            { 
                LastUpdateTime = DateTime.Now;
                if (value != m_altM)
                {
                    m_altM = value;
                    NotifyPropertyChanged();
                }
            } 
        }
        private double m_speedMS = 0;
        public double SpeedMS 
        { 
            get { return m_speedMS; }
            set
            {
                LastUpdateTime = DateTime.Now;
                if (value != m_speedMS)
                {
                    m_speedMS = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private double m_rollDeg = 0;
        public double RollDeg 
        { 
            get { return m_rollDeg; }
            set
            {
                LastUpdateTime = DateTime.Now;
                LastAttitudeTime = m_lastUpdateTime;
                if (value != m_rollDeg)
                {
                    m_rollDeg = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private double m_pitchDeg = 0;
        public double PitchDeg 
        { 
            get { return m_pitchDeg; }
            set
            {
                LastUpdateTime = DateTime.Now;
                LastAttitudeTime = m_lastUpdateTime;
                if (value != m_pitchDeg)
                {
                    m_pitchDeg = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private double m_yawDeg = 0;
        public double YawDeg 
        { 
            get { return m_yawDeg; }
            set
            {
                LastUpdateTime = DateTime.Now;
                LastYawTime = m_lastUpdateTime;
                if (value != m_yawDeg)
                {
                    m_yawDeg = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private string m_lastCommand = "";
        public string LastCommand 
        { 
            get { return m_lastCommand; }
            set
            {
                LastUpdateTime = DateTime.Now;
                if (value != m_lastCommand)
                {
                    m_lastCommand = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private UAVCondition m_condition = UAVCondition.UNKNOWN;
        public UAVCondition Condition   
        { 
            get { return m_condition; }
            set
            {
                LastUpdateTime = DateTime.Now;
                if (value != m_condition)
                {
                    m_condition = value;
                    NotifyPropertyChanged();
                }
            }
        }

        private int m_batteryCapacityPercent = 0;
        public int BatteryCapacityPercent 
        { 
            get { return m_batteryCapacityPercent; }
            set
            {
                LastUpdateTime = DateTime.Now;
                if (value != m_batteryCapacityPercent)
                {
                    m_batteryCapacityPercent = value;
                    NotifyPropertyChanged();
                }
            }
        }

        private int m_leaderID = 0;
        public int LeaderID 
        { 
            get { return m_leaderID; }
            set
            {
                LastUpdateTime = DateTime.Now;
                if (value != m_leaderID)
                {
                    m_leaderID = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private int m_stagingLeaderID = 0;
        public int StagingLeaderID 
        { 
            get { return m_stagingLeaderID; }
            set
            {
                LastUpdateTime = DateTime.Now;
                if (value != m_stagingLeaderID)
                {
                    m_stagingLeaderID = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private int m_waypointID = 0;
        public int WaypointID 
        { 
            get { return m_waypointID; }
            set
            {
                LastUpdateTime = DateTime.Now;
                if (value != m_waypointID)
                {
                    m_waypointID = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private int m_squadronPosition = 0;
        public int SquadronPosition 
        { 
            get { return m_squadronPosition; }
            set
            {
                LastUpdateTime = DateTime.Now;
                if (value != m_squadronPosition)
                {
                    m_squadronPosition = value;
                    NotifyPropertyChanged();
                }
            }
        }

        private uint m_gpsITOW = 0;
        public uint GPS_ITOW
        {
            get { return m_gpsITOW; }
            set
            {
                if(value != m_gpsITOW)
                {
                    m_gpsITOW = value;
                    NotifyPropertyChanged();
                }
            }
        }

        private DateTime? m_lastInvalidGPSTime = null;
        public DateTime? LastInvalidGPSTime
        {
            get
            { 
                return m_lastInvalidGPSTime; 
            }
            set 
            {
                if (value != m_lastInvalidGPSTime)
                {
                    m_lastInvalidGPSTime = value;
                    NotifyPropertyChanged();
                }
            }
        }

        private MAVLinkConstants.BehaviorState m_state = MAVLinkConstants.BehaviorState.STANDBY;
        public MAVLinkConstants.BehaviorState State
        {
            get
            {
                return m_state;
            }
            set
            {
                if ((value >= MAVLinkConstants.BehaviorState.STAGING) && !LaunchTimeSet && (LandedTime.Year != DateTime.Now.Year))
                {
                    setFlying();
                }

                LastUpdateTime = DateTime.Now;

                if (value != m_state)
                {
                    m_state = value;
                    NotifyPropertyChanged();
                }
            }
        }

        private MAVLinkConstants.APMode m_autopilotMode = MAVLinkConstants.APMode.UNKNOWN;
        public MAVLinkConstants.APMode AutopilotMode 
        { 
            get { return m_autopilotMode; } 
            set 
            { 
                LastUpdateTime = DateTime.Now;

                if (value != m_autopilotMode)
                {
                    m_autopilotMode = value;
                    NotifyPropertyChanged();
                }

                if ((value == MAVLinkConstants.APMode.FLYING) && !LaunchTimeSet && (LandedTime.Year != DateTime.Now.Year))
                {
                    setFlying();
                }
            }
        }

        private int m_gpsSatellites = 0;
        public int GPSSatellites
        {
            get { return m_gpsSatellites; }
            set
            {
                LastUpdateTime = DateTime.Now;

                if (value != m_gpsSatellites)
                {
                    m_gpsSatellites = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private int m_gpsSatellitesVisible = 0;
        public int GPSSatellitesVisible 
        { 
            get { return m_gpsSatellitesVisible; }
            set
            {
                LastUpdateTime = DateTime.Now;

                if (value != m_gpsSatellitesVisible)
                {
                    m_gpsSatellitesVisible = value;
                    NotifyPropertyChanged();

                    const int RED_SATELLITES = 5;
                    if (m_gpsSatellitesVisible < RED_SATELLITES)
                    {
                        LastInvalidGPSTime = DateTime.Now;
                    }
                }
            }
        }
        private float m_gpsPDOP = 0;
        public float GPS_PDOP 
        { 
            get { return m_gpsPDOP; }
            set
            {
                LastUpdateTime = DateTime.Now;

                if (value != m_gpsPDOP)
                {
                    m_gpsPDOP = value;
                    NotifyPropertyChanged("GPS_PDOP");

                    const float RED_PDOP = 3;
                    if(m_gpsPDOP >= RED_PDOP)
                    {
                        LastInvalidGPSTime = DateTime.Now;
                    }
                }
            }
        }

        private float m_autopilotBoardTempC = 0;
        public float AutopilotBoardTempC 
        { 
            get { return m_autopilotBoardTempC; }
            set
            {
                LastUpdateTime = DateTime.Now;

                if (value != m_autopilotBoardTempC)
                {
                    m_autopilotBoardTempC = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private float m_autopilotCPULoadPercent = 0;
        public float AutopilotCPULoadPercent 
        { 
            get { return m_autopilotCPULoadPercent; }
            set
            {
                LastUpdateTime = DateTime.Now;

                if (value != m_autopilotCPULoadPercent)
                {
                    m_autopilotCPULoadPercent = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private float m_payloadBoardTempC = 0;
        public float PayloadBoardTempC 
        { 
            get { return m_payloadBoardTempC; }
            set
            {
                LastUpdateTime = DateTime.Now;

                if (value != m_payloadBoardTempC)
                {
                    m_payloadBoardTempC = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private float m_payloadCPULoadPercent = 0;
        public float PayloadCPULoadPercent 
        { 
            get { return m_payloadCPULoadPercent; }
            set
            {
                LastUpdateTime = DateTime.Now;

                if (value != m_payloadCPULoadPercent)
                {
                    m_payloadCPULoadPercent = value;
                    NotifyPropertyChanged();
                }
            }
        }
        
        private AutonomyMode m_autonomousMode = AutonomyMode.MANUAL;
        public AutonomyMode AutonomousMode 
        { 
            get { return m_autonomousMode; }
            set
            {
                LastUpdateTime = DateTime.Now;

                if (value != m_autonomousMode)
                {
                    m_autonomousMode = value;
                    NotifyPropertyChanged();
                }
            }
        }

        private DateTime m_lastUpdateTime = DateTime.Now;
        public DateTime LastUpdateTime 
        { 
            get { return m_lastUpdateTime; }
            set
            {
                if (value != m_lastUpdateTime)
                {
                    m_lastUpdateTime = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private DateTime m_lastLocationUpdateTime = DateTime.Now;
        public DateTime LastLocationUpdateTime 
        { 
            get 
            { 
                return m_lastLocationUpdateTime; 
            }
            set
            {
                if(m_lastLocationUpdateTime != value)
                {
                    m_lastLocationUpdateTime = value;
                    NotifyPropertyChanged();
                }
            }
        }

        private float m_mainBatteryVoltage = 0;
        public float MainBatteryVoltage
        {
            get { return m_mainBatteryVoltage; }
            set
            {
                if (value != m_mainBatteryVoltage)
                {
                    m_mainBatteryVoltage = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private float m_avionicsBatteryVoltage = 0;
        public float AvionicsBatteryVoltage
        {
            get { return m_avionicsBatteryVoltage; }
            set
            {
                if (value != m_avionicsBatteryVoltage)
                {
                    m_avionicsBatteryVoltage = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private float m_servoVoltage = 0;
        public float ServoVoltage
        {
            get { return m_servoVoltage; }
            set
            {
                if (value != m_servoVoltage)
                {
                    m_servoVoltage = value;
                    NotifyPropertyChanged();
                }
            }
        }

        private float m_windNorthMS = 0;
        public float WindNorthMS
        {
            get { return m_windNorthMS; }
            set
            {
                if (value != m_windNorthMS)
                {
                    m_windNorthMS = value;
                    NotifyPropertyChanged();
                }
            }
        }
        private float m_windEastMS = 0;
        public float WindEastMS
        {
            get { return m_windEastMS; }
            set
            {
                if (value != m_windEastMS)
                {
                    m_windEastMS = value;
                    NotifyPropertyChanged();
                }
            }
        }

        int m_rpms = 0;
        public int RPM 
        { 
            get { return m_rpms; } 
            set 
            {
                if (value != m_rpms)
                {
                    m_rpms = value;
                    NotifyPropertyChanged();
                }
            } 
        }

        byte m_auxHealth = 0;
        public byte AuxHealth
        {
            get { return m_auxHealth; }
            set
            {
                if (value != m_auxHealth)
                {
                    m_auxHealth = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("AuxHealthVehicleGood");
                    NotifyPropertyChanged("AuxHealthSystemGood");
                    NotifyPropertyChanged("AuxHealthNavigationGood");
                    NotifyPropertyChanged("AuxHealthGPSGood");
                    NotifyPropertyChanged("AuxHealthMotorArmGood");
                    NotifyPropertyChanged("AuxHealthBatteryGood");
                }
            }
        }
        public bool AuxHealthVehicleGood
        {
            get
            {
                const byte VEHICLE_GOOD_BIT = 0x80;
                return ((AuxHealth & VEHICLE_GOOD_BIT) > 0);
            }
        }
        public bool AuxHealthSystemGood
        {
            get
            {
                const byte SYSTEM_GOOD_BIT = 0x40;
                return ((AuxHealth & SYSTEM_GOOD_BIT) > 0);
            }
        }
        public bool AuxHealthNavigationGood
        {
            get
            {
                const byte NAVIGATION_GOOD_BIT = 0x20;
                return ((AuxHealth & NAVIGATION_GOOD_BIT) > 0);
            }
        }
        public bool AuxHealthGPSGood
        {
            get
            {
                const byte GPS_GOOD_BIT = 0x10;
                return ((AuxHealth & GPS_GOOD_BIT) > 0);
            }
        }
        public bool AuxHealthMotorArmGood
        {
            get
            {
                const byte MOTOR_ARM_GOOD_BIT = 0x08;
                return ((AuxHealth & MOTOR_ARM_GOOD_BIT) > 0);
            }
        }
        public bool AuxHealthBatteryGood
        {
            get
            {
                const byte BATTERY_GOOD_BIT = 0x04;
                return ((AuxHealth & BATTERY_GOOD_BIT) > 0);
            }
        }

        int m_safeWaypointID = 0;
        public int SafeWaypointID
        { 
            get { return m_safeWaypointID; } 
            set 
            {
                if (value != m_safeWaypointID)
                {
                    m_safeWaypointID = value;
                    NotifyPropertyChanged();
                }
            } 
        }
        int m_lostCommsWaypointID = 0;
        public int LostCommsWaypointID
        { 
            get { return m_lostCommsWaypointID; } 
            set 
            {
                if (value != m_lostCommsWaypointID)
                {
                    m_lostCommsWaypointID = value;
                    NotifyPropertyChanged();
                }
            } 
        }
        int m_cmdSeqID = 0;
        public int CmdSeqID
        { 
            get { return m_cmdSeqID; } 
            set 
            {
                if (value != m_cmdSeqID)
                {
                    m_cmdSeqID = value;
                    NotifyPropertyChanged();
                }
            } 
        }

        long m_peerPose = 0;
        public long PeerPose
        {
            get { return m_peerPose; }
            set
            {
                if (value != m_peerPose)
                {
                    m_peerPose = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("PeerPoseBitString");
                }
            }
        }
        public string PeerPoseBitString
        {
            get
            {
                return Convert.ToString(PeerPose, 2).PadLeft(40, '0');
            }
        }

        float m_snr = 0;
        public float SNR
        { 
            get { return m_snr; } 
            set 
            {
                if (value != m_snr)
                {
                    m_snr = value;
                    NotifyPropertyChanged();
                }
            } 
        }

        bool m_launchTimeSet = false;
        public bool LaunchTimeSet
        { 
            get { return m_launchTimeSet; } 
            set 
            {
                if (value != m_launchTimeSet)
                {
                    m_launchTimeSet = value;
                    NotifyPropertyChanged();
                }
            } 
        }
        DateTime m_launchTime = new DateTime(1970, 1, 1);
        public DateTime LaunchTime
        { 
            get { return m_launchTime; } 
            set 
            {
                if (value != m_launchTime)
                {
                    m_launchTime = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("LaunchTimeString");
                }
            } 
        }
        public string LaunchTimeString
        {
            get
            {
                return LaunchTimeSet ? LaunchTime.ToString("T") : "N/A";
            }
        }

        DateTime m_landedTime = new DateTime(1970, 1, 1);
        public DateTime LandedTime
        { 
            get { return m_landedTime; } 
            set 
            {
                if (value != m_landedTime)
                {
                    m_landedTime = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("LandedTimeString");
                }
            } 
        }
        public string LandedTimeString
        {
            get
            {
                return LandedTime.Year == DateTime.Now.Year ? LandedTime.ToString("T") : "N/A";
            }
        }

        public enum PreflightStatusEnum { NONE = -1, SOME = 0, ALL = 1 }
        PreflightStatusEnum m_preflightStatus = PreflightStatusEnum.NONE;
        public PreflightStatusEnum PreflightStatus
        { 
            get { return m_preflightStatus; } 
            set 
            {
                if (value != m_preflightStatus)
                {
                    m_preflightStatus = value;
                    NotifyPropertyChanged();
                }
            } 
        }

        float m_latVelMS = 0;
        public float LatVelMS
        { 
            get { return m_latVelMS; } 
            set 
            {
                if (value != m_latVelMS)
                {
                    m_latVelMS = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("GroundSpeedMS");
                }
            } 
        }
        float m_lonVelMS = 0;
        public float LonVelMS
        { 
            get { return m_lonVelMS; } 
            set 
            {
                if (value != m_lonVelMS)
                {
                    m_lonVelMS = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("GroundSpeedMS");
                }
            } 
        }
        public float GroundSpeedMS
        {
            get { return (float)Math.Sqrt(m_latVelMS * m_latVelMS + m_lonVelMS * m_lonVelMS); }
        }
        float m_altVelMS = 0;
        public float AltVelMS
        { 
            get { return m_altVelMS; } 
            set 
            {
                if (value != m_altVelMS)
                {
                    m_altVelMS = value;
                    NotifyPropertyChanged();
                }
            } 
        }
        DateTime? m_lastAttitudeTime = null;
        public DateTime? LastAttitudeTime
        { 
            get { return m_lastAttitudeTime; } 
            set 
            {
                if (value != m_lastAttitudeTime)
                {
                    m_lastAttitudeTime = value;
                    NotifyPropertyChanged();
                }
            } 
        }
        float m_rollVelDegS = 0;
        public float RollVelDegS
        { 
            get { return m_rollVelDegS; } 
            set 
            {
                if (value != m_rollVelDegS)
                {
                    m_rollVelDegS = value;
                    NotifyPropertyChanged();
                }
            } 
        }
        float m_pitchVelDegS = 0;
        public float PitchVelDegS
        {
            get { return m_pitchVelDegS; } 
            set 
            {
                if (value != m_pitchVelDegS)
                {
                    m_pitchVelDegS = value;
                    NotifyPropertyChanged();
                }
            } 
        }
        DateTime? m_lastYawTime = null;
        public DateTime? LastYawTime
        {
            get { return m_lastYawTime; } 
            set 
            {
                if (value != m_lastYawTime)
                {
                    m_lastYawTime = value;
                    NotifyPropertyChanged();
                }
            } 
        }
        float m_yawVelDegS = 0;
        public float YawVelDegS
        {
            get { return m_yawVelDegS; } 
            set 
            {
                if (value != m_yawVelDegS)
                {
                    m_yawVelDegS = value;
                    NotifyPropertyChanged();
                }
            } 
        }

        MAVLinkConstants.AircraftType m_aircraftType = MAVLinkConstants.AircraftType.NOT_SPECIFIED;
        public MAVLinkConstants.AircraftType AircraftType
        {
            get { return m_aircraftType; }
            set
            {
                if (value != m_aircraftType)
                {
                    m_aircraftType = value;
                    NotifyPropertyChanged();
                }
            }
        }

        private List<DateTime> m_broadcastPositionUpdateTimes = new List<DateTime>();
        public List<DateTime> BroadcastPositionUpdateTimes
        {
            get { return m_broadcastPositionUpdateTimes; }
            set
            {
                if (value != null)
                {
                    m_broadcastPositionUpdateTimes = new List<DateTime>(value);
                }
                else
                {
                    m_broadcastPositionUpdateTimes = value;
                }
                NotifyPropertyChanged();
            }
        }
        private List<DateTime> m_relayPositionUpdateTimes = new List<DateTime>();
        public List<DateTime> RelayPositionUpdateTimes
        {
            get { return m_relayPositionUpdateTimes; }
            set
            {
                if (value != null)
                {
                    m_relayPositionUpdateTimes = new List<DateTime>(value);
                }
                else
                {
                    m_relayPositionUpdateTimes = value;
                }
                NotifyPropertyChanged();
            }
        }

        private float m_broadcastPositionUpdatesPerSecond = 0;
        public float BroadcastPositionUpdatesPerSecond 
        {
            get { return m_broadcastPositionUpdatesPerSecond; }
            set
            {
                m_broadcastPositionUpdatesPerSecond = value;
                NotifyPropertyChanged();
            }
        }
        private float m_relayPositionUpdatesPerSecond = 0;
        public float RelayPositionUpdatesPerSecond 
        {
            get { return m_relayPositionUpdatesPerSecond; }
            set
            {
                m_relayPositionUpdatesPerSecond = value;
                NotifyPropertyChanged();
            }
        }

        // These are bools the server maintains to indicate whether various
        //   flight plan components match what was pushed to the server.
        bool m_stagingOrbitsMatch = false;
        public bool StagingOrbitsMatch
        {
            get { return m_stagingOrbitsMatch; } 
            set 
            {
                if (value != m_stagingOrbitsMatch)
                {
                    m_stagingOrbitsMatch = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("SomeMatch");
                    NotifyPropertyChanged("AllMatch");
                }
            } 
        }
        bool m_flightPatternsMatch = false;
        public bool FlightPatternsMatch
        {
            get { return m_flightPatternsMatch; } 
            set 
            {
                if (value != m_flightPatternsMatch)
                {
                    m_flightPatternsMatch = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("SomeMatch");
                    NotifyPropertyChanged("AllMatch");
                }
            } 
        }
        bool m_landingPatternsMatch = false;
        public bool LandingPatternsMatch
        {
            get { return m_landingPatternsMatch; } 
            set 
            {
                if (value != m_landingPatternsMatch)
                {
                    m_landingPatternsMatch = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("SomeMatch");
                    NotifyPropertyChanged("AllMatch");
                }
            } 
        }
        bool m_safeWaypointMatch = false;
        public bool SafeWaypointMatch
        {
            get { return m_safeWaypointMatch; } 
            set 
            {
                if (value != m_safeWaypointMatch)
                {
                    m_safeWaypointMatch = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("SomeMatch");
                    NotifyPropertyChanged("AllMatch");
                }
            } 
        }
        bool m_lostCommsWaypointMatch = false;
        public bool LostCommsWaypointMatch
        {
            get { return m_lostCommsWaypointMatch; } 
            set 
            {
                if (value != m_lostCommsWaypointMatch)
                {
                    m_lostCommsWaypointMatch = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("SomeMatch");
                    NotifyPropertyChanged("AllMatch");
                }
            } 
        }
        bool m_missionLimitsMatch = false;
        public bool MissionLimitsMatch
        {
            get { return m_missionLimitsMatch; } 
            set 
            {
                if (value != m_missionLimitsMatch)
                {
                    m_missionLimitsMatch = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("SomeMatch");
                    NotifyPropertyChanged("AllMatch");
                }
            } 
        }
        bool m_squadronSizeMatch = false;
        public bool SquadronSizeMatch
        {
            get { return m_squadronSizeMatch; } 
            set 
            {
                if (value != m_squadronSizeMatch)
                {
                    m_squadronSizeMatch = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("SomeMatch");
                    NotifyPropertyChanged("AllMatch");
                }
            } 
        }
        bool m_versionsMatch = false;
        public bool VersionsMatch
        {
            get { return m_versionsMatch; } 
            set 
            {
                if (value != m_versionsMatch)
                {
                    m_versionsMatch = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("SomeMatch");
                    NotifyPropertyChanged("AllMatch");
                }
            } 
        }
        bool m_geofenceMatch = false;
        public bool GeofenceMatch
        {
            get { return m_geofenceMatch; } 
            set 
            {
                if (value != m_geofenceMatch)
                {
                    m_geofenceMatch = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("SomeMatch");
                    NotifyPropertyChanged("AllMatch");
                }
            } 
        }
        bool m_softGeofenceMatch = false;
        public bool SoftGeofenceMatch
        {
            get { return m_softGeofenceMatch; }
            set
            {
                if (value != m_softGeofenceMatch)
                {
                    m_softGeofenceMatch = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("SomeMatch");
                    NotifyPropertyChanged("AllMatch");
                }
            }
        }
        bool m_piccoloWaypointsMatch = false;
        public bool PiccoloWaypointsMatch
        {
            get { return m_piccoloWaypointsMatch; } 
            set 
            {
                if (value != m_piccoloWaypointsMatch)
                {
                    m_piccoloWaypointsMatch = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("SomeMatch");
                    NotifyPropertyChanged("AllMatch");
                }
            } 
        }
        bool m_routePatternsMatch = false;
        public bool RoutePatternsMatch
        {
            get { return m_routePatternsMatch; }
            set
            {
                if (value != m_routePatternsMatch)
                {
                    m_routePatternsMatch = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("SomeMatch");
                    NotifyPropertyChanged("AllMatch");
                }
            }
        }
        public bool AllMatch
        {
            get
            {
                return StagingOrbitsMatch && FlightPatternsMatch && LandingPatternsMatch && SafeWaypointMatch && LostCommsWaypointMatch &&
                    MissionLimitsMatch && SquadronSizeMatch && VersionsMatch && GeofenceMatch && SoftGeofenceMatch && PiccoloWaypointsMatch &&
                    RoutePatternsMatch;
            }
        }
        public bool SomeMatch
        {
            get
            {
                return StagingOrbitsMatch || FlightPatternsMatch || LandingPatternsMatch || SafeWaypointMatch || LostCommsWaypointMatch ||
                    MissionLimitsMatch || SquadronSizeMatch || VersionsMatch || GeofenceMatch || SoftGeofenceMatch || PiccoloWaypointsMatch ||
                    RoutePatternsMatch;
            }
        }

        public const float DEFAULT_ALTIMETER_INHG = 29.92f;
        float? m_altimeterInHg = null;
        public float? AltimeterInHg
        {
            get { return m_altimeterInHg; } 
            set 
            {
                if (value != m_altimeterInHg)
                {
                    m_altimeterInHg = value;
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("AltimeterInHgString");
                }
            } 
        }
        public string AltimeterInHgString
        {
            get
            {
                return AltimeterInHg.HasValue ? AltimeterInHg.Value.ToString("0.0") : "Unset";
            }
        }

        double m_trackErrorXM = 0;
        public double TrackErrorXM
        {
            get { return m_trackErrorXM; } 
            set 
            {
                if (value != m_trackErrorXM)
                {
                    m_trackErrorXM = value;
                    NotifyPropertyChanged();
                }
            } 
        }
        double m_trackErrorYM = 0;
        public double TrackErrorYM
        {
            get { return m_trackErrorYM; } 
            set 
            {
                if (value != m_trackErrorYM)
                {
                    m_trackErrorYM = value;
                    NotifyPropertyChanged();
                }
            } 
        }
        double m_trackErrorZM = 0;
        public double TrackErrorZM
        {
            get { return m_trackErrorZM; } 
            set 
            {
                if (value != m_trackErrorZM)
                {
                    m_trackErrorZM = value;
                    NotifyPropertyChanged();
                }
            } 
        }

        double m_commandedBankAngleDeg = 0;
        public double CommandedBankAngleDeg
        {
            get { return m_commandedBankAngleDeg; }
            set
            {
                if (value != m_commandedBankAngleDeg)
                {
                    m_commandedBankAngleDeg = value;
                    NotifyPropertyChanged();
                }
            }
        }
        double m_commandedAirSpeedMS = 0;
        public double CommandedAirSpeedMS
        {
            get { return m_commandedAirSpeedMS; }
            set
            {
                if (value != m_commandedAirSpeedMS)
                {
                    m_commandedAirSpeedMS = value;
                    NotifyPropertyChanged();
                }
            }
        }

        int m_squadronSize = 0;
        public int SquadronSize
        {
            get { return m_squadronSize; } 
            set 
            {
                if (value != m_squadronSize)
                {
                    m_squadronSize = value;
                    NotifyPropertyChanged();
                }
            } 
        }

        AutonomyVersions m_autonomyVersions = new AutonomyVersions(0, 0, 0, 0, 0, 0);
        public AutonomyVersions AutonomyVersions
        {
            get { return m_autonomyVersions; }
            set
            {
                if ((m_autonomyVersions.AutonomyVersionHash != value.AutonomyVersionHash) ||
                    (m_autonomyVersions.AutopilotBoardSerialNum != value.AutopilotBoardSerialNum) ||
                    (m_autonomyVersions.AutopilotSoftwareVersionMajor != value.AutopilotSoftwareVersionMajor) ||
                    (m_autonomyVersions.AutopilotSoftwareVersionMinor != value.AutopilotSoftwareVersionMinor) ||
                    (m_autonomyVersions.AutopilotSoftwareVersionPatch != value.AutopilotSoftwareVersionPatch) ||
                    (m_autonomyVersions.AutopilotSoftwareVersionSubversion != value.AutopilotSoftwareVersionSubversion))
                {
                    m_autonomyVersions = new AutonomyVersions(value);
                    NotifyPropertyChanged();
                    NotifyPropertyChanged("AutonomyVersionString");
                    NotifyPropertyChanged("AutonomyVersionHash");
                    NotifyPropertyChanged("AutopilotBoardSerialNum");
                }
            }
        }
        public string AutonomyVersionString
        {
            get
            {
                return AutonomyVersions.AutopilotSoftwareVersionMajor + "." + AutonomyVersions.AutopilotSoftwareVersionMinor + "." +
                    AutonomyVersions.AutopilotSoftwareVersionSubversion + "." + AutonomyVersions.AutopilotSoftwareVersionPatch;
            }
        }
        public uint AutonomyVersionHash
        {
            get
            {
                return AutonomyVersions.AutonomyVersionHash;
            }
        }
        public uint AutopilotBoardSerialNum
        {
            get
            {
                return AutonomyVersions.AutopilotBoardSerialNum;
            }
        }

        DateTime? m_pingTime = null;
        public DateTime? PingTime
        {
            get { return m_pingTime; }
            set
            {
                if (value != m_pingTime)
                {
                    m_pingTime = value;
                    NotifyPropertyChanged();
                }
            }
        }

        #endregion

        #region NonSerialized Members
        [NonSerialized]
        private List<Tuple<int, StagingOrbit>> m_stagingOrbits = null;
        public List<Tuple<int, StagingOrbit>> StagingOrbits 
        { 
            get 
            { 
                return m_stagingOrbits; 
            } 
            set 
            { 
                m_stagingOrbits = (value != null ? new List<Tuple<int,StagingOrbit>>(value) : value); 
            } 
        }
        [NonSerialized]
        private List<Tuple<int, RacetrackParams>> m_flightPatterns = null;
        public List<Tuple<int, RacetrackParams>> FlightPatterns 
        { 
            get 
            { 
                return m_flightPatterns; 
            } 
            set 
            {
                m_flightPatterns = (value != null ? new List<Tuple<int, RacetrackParams>>(value) : value);
            } 
        }
        [NonSerialized]
        private List<Tuple<int, LandingPattern>> m_landingPatterns = null;
        public List<Tuple<int, LandingPattern>> LandingPatterns 
        { 
            get 
            { 
                return m_landingPatterns; 
            } 
            set 
            { 
                m_landingPatterns = (value != null ? new List<Tuple<int,LandingPattern>>(value) : value); 
            } 
        }
        [NonSerialized]
        private StagingOrbit m_safeWaypoint = null;
        public StagingOrbit SafeWaypoint 
        { 
            get 
            { 
                return m_safeWaypoint; 
            } 
            set 
            { 
                m_safeWaypoint = (value != null ? new StagingOrbit(value) : value); 
            } 
        }
        [NonSerialized]
        private StagingOrbit m_lostCommsWaypoint = null;
        public StagingOrbit LostCommsWaypoint 
        { 
            get 
            { 
                return m_lostCommsWaypoint; 
            } 
            set 
            { 
                m_lostCommsWaypoint = (value != null ? new StagingOrbit(value) : value); 
            } 
        }
        [NonSerialized]
        private MissionLimits m_missionLimits = null;
        public MissionLimits MissionLimitSettings 
        { 
            get 
            { 
                return m_missionLimits; 
            } 
            set 
            { 
                m_missionLimits = (value != null ? new MissionLimits(value) : value); 
            } 
        }
        [NonSerialized]
        private Geofence m_geofence = null;
        public Geofence Geofence 
        { 
            get 
            { 
                return m_geofence; 
            } 
            set 
            { 
                m_geofence = (value != null ? new Geofence(value) : value);
            } 
        }
        [NonSerialized]
        private Geofence m_softGeofence = null;
        public Geofence SoftGeofence
        {
            get
            {
                return m_softGeofence;
            }
            set
            {
                m_softGeofence = (value != null ? new Geofence(value) : value);
            }
        }
        [NonSerialized]
        private List<RoutePattern> m_routePatterns = null;
        public List<RoutePattern> RoutePatterns
        {
            get
            {
                return m_routePatterns;
            }
            set
            {
                m_routePatterns = (value != null ? new List<RoutePattern>(value) : value);
            }
        }
        [NonSerialized]
        private List<PiccoloWaypoint> m_piccoloWaypoints = null;
        public List<PiccoloWaypoint> PiccoloWaypoints 
        { 
            get 
            { 
                return m_piccoloWaypoints; 
            } 
            set 
            { 
                m_piccoloWaypoints = (value != null ? new List<PiccoloWaypoint>(value) : value); 
            } 
        }

        public delegate void TimerChange(bool start, UAVState state);
        [NonSerialized]
        private TimerChange m_timerChangeDelegate = null;
        public TimerChange TimerChangeDelegate
        { 
            get 
            { 
                return m_timerChangeDelegate; 
            } 
            set 
            { 
                m_timerChangeDelegate = (value != null ? (TimerChange)value.Clone() : value); 
            } 
        }
        #endregion

        #endregion

        public UAVState(int squadronID, int uavID)
        {
            m_ID = uavID;
            m_squadronID = squadronID;
            LastUpdateTime = DateTime.Now;
            m_lastLocationUpdateTime = DateTime.Now;
        }

        public UAVState(UAVState uav)
        {
            loadFrom(uav);
        }

        public UAVState loadFrom(UAVState uav)
        {
            m_ID = uav.m_ID;

            foreach (var prop in typeof(UAVState).GetProperties())
            {
                try
                {
                    prop.SetValue(this, prop.GetValue(uav));
                }
                catch { }
            }
            return this;
        }

        private void updateAltVelocity(double altM)
        {
            if (LastLocationUpdateTime.Year == DateTime.Now.Year)
            {
                double elapsedSeconds = DateTime.Now.Subtract(LastLocationUpdateTime).TotalSeconds;

                if (elapsedSeconds > 0)
                {
                    AltVelMS = (float)((altM - m_altM) / elapsedSeconds);
                }
            }
        }

        private void updateVelocities(double latDeg, double lonDeg, double altM)
        {
            if (LastLocationUpdateTime.Year == DateTime.Now.Year)
            {
                double elapsedSeconds = DateTime.Now.Subtract(LastLocationUpdateTime).TotalSeconds;

                if (elapsedSeconds > 0)
                {
                    double latDistanceM, lonDistanceM, distanceM, headingDeg;
                    Utility.haversineRangeBearing(m_latDeg, m_lonDeg, latDeg, lonDeg, out latDistanceM, out lonDistanceM, out distanceM, out headingDeg);

                    LatVelMS = (float)(latDistanceM / elapsedSeconds);
                    LonVelMS = (float)(lonDistanceM / elapsedSeconds);
                    AltVelMS = (float)((altM - m_altM) / elapsedSeconds);
                }
            }
        }

        public void setLocation(double latDeg, double lonDeg, double altM, bool broadcast, bool updateVel = true)
        {
            if (updateVel)
            {
                updateVelocities(latDeg, lonDeg, altM);
            }

            LatDeg = latDeg;
            LonDeg = lonDeg;
            AltM = altM;
            DateTime currTime = DateTime.Now;
            LastUpdateTime = currTime;
            LastLocationUpdateTime = currTime;

            List<DateTime> updateTimes = broadcast ? m_broadcastPositionUpdateTimes : m_relayPositionUpdateTimes;

            lock (updateTimes)
            {
                updateTimes.Add(currTime);

                const int MAX_SECONDS = 30;
                while (currTime.Subtract(updateTimes[0]).TotalSeconds > MAX_SECONDS)
                {
                    updateTimes.RemoveAt(0);
                }
            }
        }

        public void setLocation(double latDeg, double lonDeg, double altM, bool broadcast, double speedMS, double headingDeg, double yawRateDegS, double vx, double vy)
        {
            LatVelMS = (float)vy;
            LonVelMS = (float)vx;
            updateAltVelocity(altM);

            YawVelDegS = (float)yawRateDegS;
            LastYawTime = DateTime.Now;

            SpeedMS = speedMS;
            YawDeg = headingDeg;
            setLocation(latDeg, lonDeg, altM, broadcast, false);
        }

        public void setAttitude(double rollDeg, double pitchDeg, double yawDeg)
        {
            DateTime currTime = DateTime.Now;

            double elapsedSeconds = LastAttitudeTime.HasValue ? currTime.Subtract(LastAttitudeTime.Value).TotalSeconds : 0;
            if (elapsedSeconds != 0)
            {
                RollVelDegS = (float)(Utility.angleDiff(rollDeg, m_rollDeg) / elapsedSeconds);
                PitchVelDegS = (float)(Utility.angleDiff(pitchDeg, m_pitchDeg) / elapsedSeconds);
                //YawVelDegS = (float)(Utility.angleDiff(yawDeg, m_yawDeg) / elapsedSeconds);
            }

            RollDeg = rollDeg;
            PitchDeg = pitchDeg;
            YawDeg = yawDeg;
            LastAttitudeTime = currTime;
            LastYawTime = currTime;
            LastUpdateTime = currTime;
        }

        public string serialize()
        {
            string returnString = "";
            //updatePositionsPerSecond();

            try
            {
                using(MemoryStream stream = new MemoryStream())
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(stream, this);
                    returnString = Convert.ToBase64String(stream.ToArray());
                    stream.Close();
                }
            }
            catch (Exception) { }
            return returnString;
        }

        public static UAVState deserialize(string uavString)
        {
            UAVState uav = null;

            try
            {
                using (MemoryStream stream = new MemoryStream(Convert.FromBase64String(uavString)))
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    uav = (UAVState)formatter.Deserialize(stream);
                    stream.Close();
                }
            }
            catch { }

            return uav;
        }
    }
}

Reply via email to