예제 #1
0
        public static bool TryParseIEEEAddressResponse(EzspIncomingMessageHandlerResponse message, out EmberEui64 eui)
        {
            bool result = false;

            eui = null;

            if (message.ApsFrame.ProfileId == ZdoConstants.ZdoProfileId && message.ApsFrame.ClusterId == ZdoClusterIds.IEEEAddressResponse)
            {
                try
                {
                    var buffer = new CommandBuffer(message.MessageContents);
                    buffer.ReadByte(); // Read Sequence Number
                    buffer.ReadByte(); // Read Status

                    eui    = new EmberEui64(buffer.ReadArray(EUI_LENGTH).Reverse().ToArray());
                    result = true;
                }
                catch
                {
                    result = false;
                }
            }

            return(result);
        }
예제 #2
0
        public static bool TryParseImageBlockRequestCommand(EzspIncomingMessageHandlerResponse message,
                                                            out ushort mfgCode, out ushort imageType, out uint fileVersion, out uint fileOffset, out byte maxDataSize, out ushort blockRequestDelay)
        {
            bool result = false;

            mfgCode           = ushort.MaxValue;
            imageType         = ushort.MaxValue;
            fileVersion       = uint.MaxValue;
            fileOffset        = uint.MaxValue;
            maxDataSize       = byte.MaxValue;
            blockRequestDelay = ushort.MaxValue;

            if (message.ApsFrame.ProfileId == ZclConstants.HomeAutomationProfileId && message.ApsFrame.ClusterId == ClusterIds.OtaUpgradeCluster)
            {
                try
                {
                    var buffer  = new CommandBuffer(message.MessageContents);
                    var control = buffer.ReadByte();

                    buffer.ReadByte(); // Sequence Number
                    var command = buffer.ReadByte();

                    if (command == CommandIds.OtaUpgrade.ImageBlockRequest)
                    {
                        var fieldControl = buffer.ReadByte();
                        mfgCode     = buffer.ReadUInt16();
                        imageType   = buffer.ReadUInt16();
                        fileVersion = buffer.ReadUInt32();
                        fileOffset  = buffer.ReadUInt32();
                        maxDataSize = buffer.ReadByte();

                        EmberEui64 eui;
                        if ((fieldControl & ImageBlockRequestFieldControl.IEEEAddressPresent) != 0)
                        {
                            eui = new EmberEui64(buffer.ReadArray(EUI_LENGTH).Reverse().ToArray());
                        }

                        if ((fieldControl & ImageBlockRequestFieldControl.BlockRequestDelayPresent) != 0)
                        {
                            blockRequestDelay = buffer.ReadUInt16();
                        }

                        result = true;
                    }
                }
                catch
                {
                    result = false;
                }
            }

            return(result);
        }
예제 #3
0
        public static void WriteCieAddress(ushort address, EmberEui64 hostEui, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZclConstants.HomeAutomationProfileId, ClusterIds.IasZone, 1, 1, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add((byte)0x00);                            // Frame control
            buffer.Add((byte)0x00);                            // Sequence
            buffer.Add(CommandIds.Global.WriteAttributes);     // Command
            buffer.Add(AttributeIds.IasZoneServer.CieAddress); // Attribute Identifier
            buffer.Add(ZclDataTypes.IeeeAddress);              // Data Type
            buffer.Add(hostEui);                               // EUI to write

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, buffer.ToArray());
        }
예제 #4
0
        private bool VerifyEui(EmberEui64 eui)
        {
            bool result = false;

            using (var manufacturingStoreRepository = dataContextFactory.CreateManufacturingStoreRepository())
            {
                var euiString = eui.ToString();
                var dbEui     = manufacturingStoreRepository.EuiLists.AsNoTracking().FirstOrDefault(e => e.EUI == euiString);

                string dbEuiSKU = null;
                if (dbEui != null)
                {
                    dbEuiSKU = dbEui.TargetDevices.OrderByDescending(x => x.Id).FirstOrDefault()?.TestSession?.Product?.SKU;

                    if (dbEuiSKU == ValidProduct?.SKU)
                    {
                        result = true;
                    }
                    else
                    {
                        errorProducerService.AddMessage(new ErrorMessage(string.Format("SKU: {0} is invalid for the selected product", dbEuiSKU), ErrorType.Error));
                    }
                }
                else
                {
                    if (ValidProduct?.Board.ChipType.Name == EM250_CHIP)
                    {
                        // EM250 Chips do not have EUIs in DB since they are not coded in EBL
                        dbEui = new EuiList()
                        {
                            EUI = euiString,
                            ProductionSiteId = CurrentStationSite.ProductionSite.Id
                        };

                        manufacturingStoreRepository.EuiLists.Add(dbEui);
                        manufacturingStoreRepository.SaveChanges();

                        result = true;
                    }
                    else
                    {
                        errorProducerService.AddMessage(new ErrorMessage(string.Format("EUI: {0} could not be found in database", euiString), ErrorType.Error));
                    }
                }

                return(result);
            }
        }
예제 #5
0
        public static void SendOnOffClusterBindRequest(ushort address, EmberEui64 eui, byte endpointCount, IEzspService ezspService)
        {
            for (byte i = 1; i <= endpointCount; i++)
            {
                var frame = new EmberApsFrame(ZdoConstants.ZdoProfileId, ZdoClusterIds.BindRequest, i, 0, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

                var buffer = new CommandBuffer();
                buffer.Add((byte)0x00);          // Sequence
                buffer.Add(eui);                 // Device EUI
                buffer.Add(i);                   // Endpoint for device
                buffer.Add(ZCL.ClusterIds.OnOffCluster);
                buffer.Add((byte)0x03);          // Mode
                buffer.Add(ezspService.HostEui); // Host EUI
                buffer.Add((byte)0x01);          // Endpoint for host

                ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, buffer.ToArray());
            }
        }