Esempio n. 1
0
        /// <summary>
        /// Process a server connection info message from the server.
        /// </summary>
        /// <param name="copyData">received message</param>
        /// <remarks>
        /// Returns the message contents to the client application by callback.
        /// </remarks>
        private void ProcessServerConnectionInfo(ref CopyData copyData)
        {
            // debug info
            OutputDebugString("processServerConnectionInfo");

            // message parsing variables
            byte[] buffer = null;
            buffer = this.GetBufferFromCopyData(ref copyData);
            int index = 0;

            // message format:
            // byte: connection type
            // byte: I2C address (for I2C connections)
            // UInt16: VID (for USB connections)
            // UInt16: PID (for USB connections)
            // string: bridge client name (for bridge connections)
            // string: bridge client version (for bridge connections)

            // parse message
            ConnectionInfo connectionInfo = new ConnectionInfo();
            byte connectionType = this.GetByte(ref buffer, ref index);
            connectionInfo.connectionType = (ConnectionType)connectionType;
            connectionInfo.i2cAddress = this.GetByte(ref buffer, ref index);

            // the original version of this message only returned the I2C address, so
            // don't try to parse the buffer if it's too short
            if (buffer.Length > 2)
            {
                connectionInfo.usbVid = this.GetUshort(ref buffer, ref index);
                connectionInfo.usbPid = this.GetUshort(ref buffer, ref index);
                connectionInfo.bridgeName = this.GetString(ref buffer, ref index);
                connectionInfo.bridgeVersion = this.GetString(ref buffer, ref index);
            }
            else
            {
                connectionInfo.usbVid = 0;
                connectionInfo.usbPid = 0;
                connectionInfo.bridgeName = string.Empty;
                connectionInfo.bridgeVersion = string.Empty;
            }

            // trigger server connection info event
            this.NotifyServerConnectionInfo(connectionInfo);
        }
Esempio n. 2
0
        /// <summary>
        /// Handler for client receiving a server connection info message.
        /// </summary>
        /// <param name="connectionInfo">information about the connection</param>
        private void Client_serverConnectionInfo(ConnectionInfo connectionInfo)
        {
            // user info
            this.textBoxInfo.AppendText("server connection info");
            this.textBoxInfo.AppendText(Environment.NewLine);
            this.textBoxInfo.AppendText("\tconnection type: ");
            switch (connectionInfo.connectionType)
            {
                case ConnectionType.CONNECTION_TYPE_NONE:
                    this.textBoxInfo.AppendText("none");
                    this.textBoxInfo.AppendText(Environment.NewLine);
                    break;

                case ConnectionType.CONNECTION_TYPE_I2C:
                    this.textBoxInfo.AppendText("I2C");
                    this.textBoxInfo.AppendText(Environment.NewLine);
                    this.textBoxInfo.AppendText("\tI2C address: 0x");
                    this.textBoxInfo.AppendText(connectionInfo.i2cAddress.ToString("X"));
                    this.textBoxInfo.AppendText(Environment.NewLine);
                    break;

                case ConnectionType.CONNECTION_TYPE_USB:
                    this.textBoxInfo.AppendText("USB");
                    this.textBoxInfo.AppendText(Environment.NewLine);
                    string msg = string.Format("\tVID: 0x{0,4:X4}", connectionInfo.usbVid);
                    this.textBoxInfo.AppendText(msg);
                    this.textBoxInfo.AppendText(Environment.NewLine);
                    msg = string.Format("\tPID: 0x{0,4:X4}", connectionInfo.usbPid);
                    this.textBoxInfo.AppendText(msg);
                    this.textBoxInfo.AppendText(Environment.NewLine);
                    break;

                case ConnectionType.CONNECTION_TYPE_BRIDGE:
                    this.textBoxInfo.AppendText("bridge");
                    this.textBoxInfo.AppendText(Environment.NewLine);
                    this.textBoxInfo.AppendText("\tname: ");
                    this.textBoxInfo.AppendText(connectionInfo.bridgeName);
                    this.textBoxInfo.AppendText(Environment.NewLine);
                    this.textBoxInfo.AppendText("\tversion: ");
                    this.textBoxInfo.AppendText(connectionInfo.bridgeVersion);
                    this.textBoxInfo.AppendText(Environment.NewLine);
                    break;

                default:
                    this.textBoxInfo.AppendText("unknown");
                    this.textBoxInfo.AppendText(Environment.NewLine);
                    break;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// handle server connection information events
 /// </summary>
 /// <param name="connectionInfo">the server connection information</param>
 private void NotifyServerConnectionInfo(ConnectionInfo connectionInfo)
 {
     if (this.serverConnectionInfo != null)
     {
         this.serverConnectionInfo(connectionInfo);
     }
 }