コード例 #1
0
        public BPPacket(int LinkId, BPProtocolHeader BPProtocolHeader, byte[] BPProtocolHeaderData, byte[] Data, int ExpectedLength)
        {
            log.Debug("New packet with destination: " + LinkId.ToString() + " and data: " + Data.ToString());

            this.LinkId = (byte)LinkId;
            this.BPProtocolHeader = BPProtocolHeader;
            this.BPProtocolHeaderData = BPProtocolHeaderData;
            this.Data = Data;
            this.ExpectedLength = ExpectedLength;
        }
コード例 #2
0
        private void ProcessTableData(string OperationName, BPProtocolHeader lProtocolHeader, Byte lLinkId, object[] DeserializedData)
        {
            //We are dirty again, make another implementation!!!
            string TableName = OperationName.Substring(0, OperationName.Length - 5);

            bool ret = false;
            foreach (DataTable table in cDevices.Tables)
                if (table.TableName.StartsWith(TableName))
                {
                    TableName = table.TableName;
                    ret = true;
                    break;
                }

            if (!ret)
                return;

            DataRow[] BasysRows=cDevices.BASYS_ADDR.Select("IDChair=" + lLinkId);
            if (BasysRows.Count() == 0)
                return;

            Devices.BASYS_ADDRRow Basysrow = (Devices.BASYS_ADDRRow)BasysRows[0];
            int id = Basysrow.ZapNo;

            DataRow[] tableRows= cDevices.Tables[TableName].Select("@ZapNo=" + id.ToString());
            if (tableRows.Count() == 0)
                return;

            List<object> rowData = new List<object>();
            rowData.Add(id);
            rowData.AddRange(DeserializedData);

            cForm1.Invoke((MethodInvoker)delegate
            {
                tableRows[0].ItemArray = rowData.ToArray();
                cDevices.Tables[TableName].AcceptChanges();
            });
        }
コード例 #3
0
 private void ProcessNewPeer(string OperationName, BPProtocolHeader lProtocolHeader, Byte lLinkId, object[] DeserializedData)
 {
     log.Info("Processing new peer with LinkId "+ lLinkId);
     cForm1.Invoke((MethodInvoker)delegate
     {
         DataRow[] rows = cDevices.Device.Select("LinkId=" + lLinkId.ToString());
         if(rows.Count()>0)
             return;
         cDevices.Device.AddDeviceRow(lLinkId, (Byte)DeviceType.Unknown);
     });
 }
コード例 #4
0
 private void ProcessGetWeight(string OperationName, BPProtocolHeader lProtocolHeader, Byte lLinkId, object[] DeserializedData)
 {
     cForm1.Invoke((MethodInvoker)delegate
     {
         cForm1.SetStatusWeight((Int16)DeserializedData[0]);
         cForm1.SetWeight((Int16)DeserializedData[1]);
     });
 }
コード例 #5
0
 private void ProcessGetPeers(string OperationName, BPProtocolHeader lProtocolHeader, Byte lLinkId, object[] DeserializedData)
 {
     cForm1.Invoke((MethodInvoker)delegate
     {
         cDevices.Device.Clear();
         foreach (Byte LinkId in DeserializedData.Skip(1))
         {
             //Invoke all on gui thread, so working threa will have more time.
             cDevices.Device.AddDeviceRow(LinkId, (Byte)DeviceType.Unknown);
             cBPPRotocol.CallOperation(LinkId, "MGMT_GET_DEVICE_TYPE");
         }
     });
 }
コード例 #6
0
        private void ProcessDeviceType(string OperationName, BPProtocolHeader lProtocolHeader, Byte lLinkId, object[] DeserializedData)
        {
            log.Info("Processing device type of peer "+ lLinkId);
            log.Info("Device type is " + ((byte)DeserializedData[0]).ToString());
            cForm1.Invoke((MethodInvoker)delegate
            {
                //EnumerableRowCollection<Devices.DeviceRow> rows = (from n in cDevices.Device where n.DeviceAddress == lProtocolHeader.cLinkId select n);
                DataRow[] rows = cDevices.Device.Select("LinkId=" + lLinkId.ToString());
                if (rows.Count() == 0)
                    return;
                Devices.DeviceRow Row = (Devices.DeviceRow)rows[0];
                if (Row == null)
                    return;

                Row.DeviceType = (byte)DeserializedData[0];
                Row.AcceptChanges();
            });
        }
コード例 #7
0
 private void ProcessACK(string OperationName, BPProtocolHeader lProtocolHeader, Byte lLinkId, object[] DeserializedData)
 {
     ((BPSerial)cSerial).AckReceived();
 }
コード例 #8
0
 private void Callback1(string OperationName, BPProtocolHeader lProtocolHeader, Byte lLinkId, object[] DeserializedData)
 {
 }
コード例 #9
0
        public void CallOperation(int LinkId, string OperationName, object[] data=null)
        {
            MemoryStream StreamToWrite= new MemoryStream();
            BPOperation lOperation;
            try
            {
                lOperation = (from o in cOperations where o.cOperationName == OperationName select o).First();
            }
            catch { return; }

            if (lOperation.cSendCode == -1)
                return;

            //Serializes header data.
            BPProtocolHeader lBPProtocolHeader= new BPProtocolHeader((byte)lOperation.cSendCode);
            base.SerializeData(ref StreamToWrite, new object[] {lBPProtocolHeader});

            int ExpectedLength= lOperation.cDownlinkSerializer.GetSerializedDataLength();

            //It allows us to send only a command if data is not set.
            Byte[] SerializedData = new Byte[0];
            if (data != null && lOperation.cUplinkSerializer!=null)
            {
                SerializedData = lOperation.cUplinkSerializer.SerializeData(data);
                StreamToWrite.Write(SerializedData, 0, SerializedData.Count());
            }

            cLinkLayer.Write(new BPPacket( LinkId, lBPProtocolHeader, StreamToWrite.ToArray(), SerializedData, ExpectedLength);
        }