Exemplo n.º 1
0
        public void onDpMessage(DpMessage msg)
        {
            switch (msg.type)
            {
            case DpMessageType.DP_MSG_DPINFO:
                lock (this)
                {
                    if (currDpInfoListener != null)
                    {
                        currDpInfoListener((DpInfo)msg);
                        currentTempOnDp = ((DpInfo)msg).CurrentTemp;
                        Monitor.Pulse(this);
                        currDpInfoListener = null;
                    }
                }

                break;

            case DpMessageType.DP_MSG_LICENSE_ACK:
                lock (this)
                {
                    if (licenseAckListener != null)
                    {
                        licenseAckListener((LicenseAck)msg);
                        Monitor.Pulse(this);
                        licenseAckListener = null;
                    }
                }
                break;

            default:
                break;
            }
        }
Exemplo n.º 2
0
        void analyzeIncomingCommunicationPacket(byte[] incomingData)
        {
            //check that received packet is legal
            //1) packet preamble byte is API_MSG_PREAMBLE
            //2) packet length is none zero
            //3) check sum is valid
            if ((incomingData[COM_PACKET_INDEX_START_BYTE] == API_MSG_PREAMBLE) &&
                (incomingData[COM_PACKET_INDEX_MESSAGE_SIZE] > 0) &&
                (incomingData[incomingData[COM_PACKET_INDEX_MESSAGE_SIZE] - 1] == CheckCum(incomingData, incomingData[COM_PACKET_INDEX_MESSAGE_SIZE])))
            {
                SendRxTxStringAsHex(incomingData, COM_PACKET_MESSAGE_RX, incomingData[COM_PACKET_INDEX_MESSAGE_SIZE]);
                incomingInfo.newControlReceiverMessage = true;


                int packetType;
                //initialize variable
                packetType = incomingData[COM_PACKET_INDEX_MESSAGE_TYPE];

                Console.WriteLine("\rRX Packet type " + incomingData[COM_PACKET_INDEX_MESSAGE_TYPE].ToString());

                communicationPacketTimeLast = DateTime.Now;

                switch (packetType)
                {
                case API_MSG_DP_ACK_OK:
                {
                    DpMessage msg = new DpMessage();

                    msg.type = DpMessageType.DP_MSG_ACK;

                    onDpMessage(msg);
                }
                break;

                case API_MSG_DP_SEND_PRESSURE_TO_DP:
                {
                }
                break;

                case API_MSG_DP_GET_DP_INFO:
                {
                    DpInfo dpInfo = new DpInfo();

                    dpInfo.DeviceBarcode    = "";
                    dpInfo.DeviceMacAddress = "";

                    string temSerialNumber = System.Text.Encoding.UTF8.GetString(incomingData, DEVICE_INFO_SERIAL_NUMBER_NUMBER_OFFSET, 10);
                    dpInfo.DeviseSerialNumber = temSerialNumber.Replace("\0", "");

                    dpInfo.CurrentTemp   = (SByte)incomingData[DEVICE_INFO_CURRENT_TEMP_OFFSET];
                    dpInfo.S1Pressure    = System.BitConverter.ToSingle(incomingData, DEVICE_INFO_S1_PRESSURE_OFFSET);
                    dpInfo.S2Pressure    = System.BitConverter.ToSingle(incomingData, DEVICE_INFO_S2_PRESSURE_OFFSET);
                    dpInfo.Calibrated    = incomingData[DEVICE_INFO_CALIBRATED_OFFSET];
                    dpInfo.DeviceBarcode = System.Text.Encoding.UTF8.GetString(incomingData, DEVICE_INFO_BARCODE_OFFSET, BARCODE_LENGTH);

                    dpInfo.LeftA2D  = BitConverter.ToUInt16(incomingData, DEVICE_INFO_A2D1_OFFSET);
                    dpInfo.RightA2D = BitConverter.ToUInt16(incomingData, DEVICE_INFO_A2D2_OFFSET);

                    Byte[] mac = new byte[6];
                    mac[0] = incomingData[DEVICE_INFO_MAC_ADDRESS_OFFSET];
                    mac[1] = incomingData[DEVICE_INFO_MAC_ADDRESS_OFFSET + 1];
                    mac[2] = incomingData[DEVICE_INFO_MAC_ADDRESS_OFFSET + 2];
                    mac[3] = incomingData[DEVICE_INFO_MAC_ADDRESS_OFFSET + 3];
                    mac[4] = incomingData[DEVICE_INFO_MAC_ADDRESS_OFFSET + 4];
                    mac[5] = incomingData[DEVICE_INFO_MAC_ADDRESS_OFFSET + 5];

                    dpInfo.DeviceMacAddress += String.Format("{0:X2}", mac[0]);
                    dpInfo.DeviceMacAddress += String.Format("{0:X2}", mac[1]);
                    dpInfo.DeviceMacAddress += String.Format("{0:X2}", mac[2]);
                    dpInfo.DeviceMacAddress += String.Format("{0:X2}", mac[3]);
                    dpInfo.DeviceMacAddress += String.Format("{0:X2}", mac[4]);
                    dpInfo.DeviceMacAddress += String.Format("{0:X2}", mac[5]);

                    _gui.UpdateTraceInfo("Got DP info " + dpInfo.DeviceMacAddress + " " + dpInfo.CurrentTemp + " " + dpInfo.LeftA2D + " " + dpInfo.RightA2D + " " + dpInfo.S1Pressure + " " + dpInfo.S2Pressure + "\r\n");

                    onDpMessage(dpInfo);
                }
                break;

                case API_MSG_DP_LICENSE_ACK:
                {
                    LicenseAck msg = new LicenseAck();
                    msg.res = incomingData[COM_PACKET_INDEX_MESSAGE_TYPE + 1] == 1 ? true : false;;
                    Console.WriteLine("Got license ack!!! " + msg.res);
                    onDpMessage(msg);
                }
                break;

                default:
                    break;
                }
            }
            else
            {
                _gui.UpdateTraceInfo("Invalid message CRS");
            }
        }