Exemple #1
0
        /// <summary>
        /// Check if a Tranport Address belongs to the same network as this one.
        /// </summary>
        public override bool IsSameNetwork(TransportAddress ta)
        {
            if (ta == null || GetType() != ta.GetType())
            {
                return(false);
            }
            SerialTransportAddress t = (SerialTransportAddress)ta;

            return(serialport == t.serialport);
        }
Exemple #2
0
        public virtual void Send(TransportAddress t, byte[] data)
        {
            byte[]       tmp;
            SerialHeader header;

            if (data.Length > ushort.MaxValue)
            {
                throw new ArgumentOutOfRangeException("there are too many bytes to transmit");
            }

            // Check if this message is going to use Acknowledgements
            if (((SerialTransportAddress)t).forceACK)
            {
                header = new SafeSerialHeader();
            }
            else
            {
                header = new SerialHeader();
            }

            header.length = (ushort)data.Length;
            if (header is SafeSerialHeader)
            {
                ((SafeSerialHeader)header).sequence = GetSequence();
            }
            tmp = new byte[header.size + data.Length];
            header.GetBytes().CopyTo(tmp, 0);
            data.CopyTo(tmp, header.size);

            header.CRC = SerialCRC.Calculate(tmp, (uint)tmp.Length);
            header.GetBytes().CopyTo(tmp, 0);

            if (header is SafeSerialHeader)
            {
                lock (SendBuffer)
                {
                    SendBuffer.Add(sequence, new SafeData(tmp));
                }
            }
            try
            {
                WriteToPort(tmp, 0, tmp.Length, header is SafeSerialHeader);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
 /// <summary>
 /// Check if a Tranport Address belongs to the same network
 /// </summary>
 public abstract bool IsSameNetwork(TransportAddress ta);
Exemple #4
0
        public void DataReceived(byte[] buffer, int offset, int length, TransportAddress t)
        {
            byte[] tmpBuff = new byte[length];
            for (int i = 0; i < length; i++)
            {
                tmpBuff[i] = buffer[offset + i];
            }

            switch ((char)tmpBuff[0])
            {
            case 'f':
                Engine.getInstance().ManualForward(ToShort(tmpBuff, 1));
                break;

            case 'b':
                Engine.getInstance().ManualBackward(ToShort(tmpBuff, 1));
                break;

            case 'r':
                Engine.getInstance().ManualRight();
                break;

            case 'l':
                Engine.getInstance().ManualLeft();
                break;

            case 's':
                Engine.getInstance().ManualStop();
                break;

            case 'm':
                Engine.getInstance().ManualMode();
                break;

            case 'M':
                Engine.getInstance().StopManualMode();
                break;

            case 'V':
                Engine.getInstance().ManualSpeed(ToShort(tmpBuff, 1));
                break;

            case 'v':
                Engine.getInstance().ManualTurningSpeed(ToShort(tmpBuff, 1));
                break;

            case 'p':
                int      readen = 1;
                int      temp;
                Position p = new Position();
                double   x = ToDouble(tmpBuff, readen, out temp);
                readen += temp;
                //Engine.getInstance().Debug("X: " + x.ToString());

                double y = ToDouble(tmpBuff, readen, out temp);
                readen += temp;

                double angle = ToDouble(tmpBuff, readen, out temp);
                readen += temp;

                p.x     = x;
                p.y     = y;
                p.angle = angle;

                Engine.getInstance().UpdatePosition(p);
                break;

            case 'c':
                short value = 0;
                switch ((char)tmpBuff[1])
                {
                case 'x':
                    value = ToShort(tmpBuff, 2);
                    Engine.getInstance().calibrarX(value);
                    break;

                case 'y':
                    value = ToShort(tmpBuff, 2);
                    Engine.getInstance().calibrarY(value);
                    break;
                }
                break;
            }
        }
Exemple #5
0
        public virtual void Send(TransportAddress t, byte[] data)
        {
            byte[] tmp;
            SerialHeader header;

            if (data.Length > ushort.MaxValue)
                throw new ArgumentOutOfRangeException("there are too many bytes to transmit");

            // Check if this message is going to use Acknowledgements
            if (((SerialTransportAddress)t).forceACK) { header = new SafeSerialHeader(); }
            else { header = new SerialHeader(); }

            header.length = (ushort)data.Length;
            if (header is SafeSerialHeader)
            {
                ((SafeSerialHeader)header).sequence = GetSequence();
            }
            tmp = new byte[header.size + data.Length];
            header.GetBytes().CopyTo(tmp, 0);
            data.CopyTo(tmp, header.size);

            header.CRC = SerialCRC.Calculate(tmp, (uint)tmp.Length);
            header.GetBytes().CopyTo(tmp, 0);

            if (header is SafeSerialHeader)
            {
                lock (SendBuffer)
                {
                    SendBuffer.Add(sequence, new SafeData(tmp));
                }
            }
            try
            {
                WriteToPort(tmp, 0, tmp.Length, header is SafeSerialHeader);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemple #6
0
 /// <summary>
 /// Check if a Tranport Address belongs to the same network
 /// </summary>
 abstract public bool IsSameNetwork(TransportAddress ta);
Exemple #7
0
        public void DataReceived(byte[] buffer, int offset, int length, TransportAddress t)
        {
            byte[] tmpBuff = new byte[length];
            for (int i = 0; i < length; i++)
            {
                tmpBuff[i] = buffer[offset + i];
            }

            switch ((char)tmpBuff[0])
            {
                case 'f':
                    Engine.getInstance().ManualForward(ToShort(tmpBuff, 1));
                    break;
                case 'b':
                    Engine.getInstance().ManualBackward(ToShort(tmpBuff, 1));
                    break;
                case 'r':
                    Engine.getInstance().ManualRight();
                    break;
                case 'l':
                    Engine.getInstance().ManualLeft();
                    break;
                case 's':
                    Engine.getInstance().ManualStop();
                    break;
                case 'm':
                    Engine.getInstance().ManualMode();
                    break;
                case 'M':
                    Engine.getInstance().StopManualMode();
                    break;

                case 'V':
                    Engine.getInstance().ManualSpeed(ToShort(tmpBuff, 1));
                    break;
                case 'v':
                    Engine.getInstance().ManualTurningSpeed(ToShort(tmpBuff, 1));
                    break;

                case 'p':
                    int readen = 1;
                    int temp;
                    Position p = new Position();
                    double x = ToDouble(tmpBuff, readen, out temp);
                    readen += temp;
                    //Engine.getInstance().Debug("X: " + x.ToString());

                    double y = ToDouble(tmpBuff, readen, out temp);
                    readen += temp;

                    double angle = ToDouble(tmpBuff, readen, out temp);
                    readen += temp;

                    p.x = x;
                    p.y = y;
                    p.angle = angle;

                    Engine.getInstance().UpdatePosition(p);
                    break;
                case 'c':
                    short value = 0;
                    switch ((char)tmpBuff[1])
                    {
                        case 'x':
                            value = ToShort(tmpBuff, 2);
                            Engine.getInstance().calibrarX(value);
                            break;
                        case 'y':
                            value = ToShort(tmpBuff, 2);
                            Engine.getInstance().calibrarY(value);
                            break;
                    }
                    break;

            }
        }
 /// <summary>
 /// Check if a Tranport Address belongs to the same network as this one.
 /// </summary>
 public override bool IsSameNetwork(TransportAddress ta)
 {
     if (ta == null || GetType() != ta.GetType()) return false;
     SerialTransportAddress t = (SerialTransportAddress)ta;
     return (serialport == t.serialport);
 }