Пример #1
0
        //Dictionary<int, DateTime> lastRecordTime = new Dictionary<int, DateTime>();

        //Dictionary<int, DateTime> lastRecordTime = new Dictionary<int, DateTime>();
        private void ManagedClient_ApplicationMessageReceived(object sender, MqttApplicationMessageReceivedEventArgs e)
        {
            try
            {
                //lastTime = DateTime.Now.Add(mqttOptions.RecordInterval);

                //byte[] pay_load = e.ApplicationMessage.Payload;
                //byte[] new_fileArray = new byte[pay_load.Length + 8];
                //Array.Copy(pay_load, new_fileArray, pay_load.Length);
                //File.WriteAllBytes($"{DateTime.Now.TimeOfDay}_dump.bin", e.ApplicationMessage.Payload);
                DaegunPacket packet = PacketParser.ByteToStruct <DaegunPacket>(e.ApplicationMessage.Payload);
                //if (lastRecordTime.ContainsKey(packet.sSiteId) == false)
                //    lastRecordTime.Add(packet.sSiteId, DateTime.MinValue);
                //if (DateTime.Now < lastRecordTime[packet.sSiteId])
                //    return;
                _logger.LogInformation($"RECEIVED DAEGUN : siteid({packet.sSiteId}) from({e.ClientId}) t({e.ApplicationMessage.Topic}) QoS({e.ApplicationMessage.QualityOfServiceLevel}) size({e.ApplicationMessage.Payload.Length})");
                //nLogger.Info($"RECEIVED DAEGUN : siteid({packet.sSiteId}) from({e.ClientId}) t({e.ApplicationMessage.Topic}) QoS({e.ApplicationMessage.QualityOfServiceLevel}) size({e.ApplicationMessage.Payload.Length})");
                //lastRecordTime[packet.sSiteId] = DateTime.Now.Add(mqttOptions.RecordInterval);
                //packet.timestamp = DateTime.Now;
                DateTime dt = DateTime.Now.Date
                              .AddHours(DateTime.Now.Hour)
                              .AddMinutes(DateTime.Now.Minute)
                              .AddSeconds(DateTime.Now.Second);

#if RASPIAN == false
                queue.QueueBackgroundWorkItem(new DaegunPacketClass(packet, dt));
#else
                NLog.LogEventInfo pcsEventInfo = LogEventMaker.CreateLogEvent(PCS_LOG, packet.Pcs);
                NLog.LogEventInfo bscEventInfo = LogEventMaker.CreateLogEvent(BSC_LOG, packet.Bsc);
                NLog.LogEventInfo pvEventInfo  = LogEventMaker.CreateLogEvent(PV_METER_LOG, packet.Pv);
                NLog.LogEventInfo essEventInfo = LogEventMaker.CreateLogEvent(BSC_METER_LOG, packet.Ess);
                //NLog.Logger logger =  NLog.LogManager.Configuration.LogFactory.GetLogger("record.pcs");
                //NLog.LogEventInfo logEvent = LogEventMaker.CreateLogEvent("record.pcs", pcsPacket);
                pcsEventInfo.Properties["SiteId"]             =
                    bscEventInfo.Properties["SiteId"]         =
                        pvEventInfo.Properties["SiteId"]      =
                            essEventInfo.Properties["SiteId"] = packet.sSiteId;
                pcsLogger.Log(pcsEventInfo);
                bscLogger.Log(bscEventInfo);
                pvMeterLogger.Log(pvEventInfo);
                bscMeterLogger.Log(essEventInfo);
                //logger.Log(logEvent);
#endif
                //logger.LogInformation("Store Daegun Packet");
                //if(lastRecordTime.ContainsKey(packet.sSiteId) == false)
                //{
                //    lastRecordTime.Add(packet.sSiteId, DateTime.MinValue);
                //}

                //if (DateTime.Now > lastRecordTime[packet.sSiteId])
                //{

                //    lastRecordTime[packet.sSiteId] = DateTime.Now.Add(mqttOptions.RecordInterval);
                //}
            }catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                _logger.LogError(ex, ex.Message);
            }
        }
Пример #2
0
        protected override Task OnMessageReceivedAsync(MqttApplicationMessageReceivedEventArgs e)
        {
            DaegunPacket packet = PacketParser.ByteToStruct <DaegunPacket>(e.ApplicationMessage.Payload);

            queue.QueueBackgroundWorkItem(packet);
            return(Task.CompletedTask);
        }
        private void ManagedClient_ApplicationMessageReceived(object sender, MqttApplicationMessageReceivedEventArgs e)
        {
            logger.LogInformation($"RECEIVED DAEGUN :from({e.ClientId}) t({e.ApplicationMessage.Topic}) QoS({e.ApplicationMessage.QualityOfServiceLevel}) size({e.ApplicationMessage.Payload.Length})");
            byte[] pay_load      = e.ApplicationMessage.Payload;
            byte[] new_fileArray = new byte[pay_load.Length + 8];
            Array.Copy(pay_load, new_fileArray, pay_load.Length);
            DaegunPacket packet = PacketParser.ByteToStruct <DaegunPacket>(new_fileArray);

            packet.timestamp = DateTime.Now;
            queue.QueueBackgroundWorkItem(packet);
            logger.LogInformation("Queuying Daegun Packet");
        }
 private void DaegunSubscriberWorker_MessageReceived(object sender, MQTTnet.MqttApplicationMessageReceivedEventArgs e)
 {
     try
     {
         DaegunPacket packet = PacketParser.ByteToStruct <DaegunPacket>(e.ApplicationMessage.Payload);
         queue.QueueBackgroundWorkItem(packet);
     }
     catch (Exception ex)
     {
         logger.LogError(ex, ex.Message);
     }
 }
Пример #5
0
        protected override async Task OnApplicationMessageReceived(string ClientId, string Topic, string ContentType, uint QosLevel, byte[] payload)
        {
            try
            {
                if (Topic.StartsWith("site"))
                {
                    DUT_MQTT_COMMON_HEADER header = PacketParser.ByteToStruct <DUT_MQTT_COMMON_HEADER>(payload);
                    switch (header.Category)
                    {
                    case PmsCategoryTypes.ESS:
                        DUT_MQTT_ESS ess = PacketParser.ByteToStruct <DUT_MQTT_ESS>(payload);
                        ModelConverter.DataProcessing(ess, _queues);
                        ModelConverter.EventProcessing(this, ess);
                        break;

                    case PmsCategoryTypes.TEMPERATUREANDHUMIDITY:
                        DUT_MQTT_TEMPHUMIDITY temp = PacketParser.ByteToStruct <DUT_MQTT_TEMPHUMIDITY>(payload);
                        ModelConverter.DataProcessing(temp, _queues);
                        break;
                    }
                }
                else if (Topic.EndsWith("control"))
                {
                    string                 msg      = Encoding.UTF8.GetString(payload);
                    ModbusControlModel     model    = JsonConvert.DeserializeObject <ModbusControlModel>(msg);
                    MqttApplicationMessage mqtt_msg = ConvertControlMessage(model);
                    await MqttClient.PublishAsync(mqtt_msg);

                    var logger = NLog.LogManager.GetLogger("control_logger");
                    logger.Info($"[{model.userid}] [DeviceIndex:{model.deviceindex}] {model.commandcode} REF:{model.commandvalue}");
                }

                //if(ModelConverter.TryConvertPcs(ess, DateTime.Now, out MqttApplicationMessage[] pcs_messages,
                //    out MqttApplicationMessage[] bat_messages))
                //{

                //}
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
            }
            //throw new NotImplementedException();
        }
Пример #6
0
        private void DaegunSubscriberWorker_MessageReceived(object sender, MQTTnet.MqttApplicationMessageReceivedEventArgs e)
        {
            DaegunPacket packet = PacketParser.ByteToStruct <DaegunPacket>(e.ApplicationMessage.Payload);

            queue.QueueBackgroundWorkItem(packet);
        }