示例#1
0
 public static StatusRegister CreateStatusRegister(int devID, string alias, string description, int registerNumber, Signedness signedness)
 {
     using (var context = new DynapowerCloudMonitoringDbContext())
     {
         var dev = context.Devices.Find(devID);
         var statusRegister = new StatusRegister()
         {
             RegisterNumber = registerNumber,
             Alias = alias,
             Description=description,
             SignednessType = signedness
         };
         dev.Registers.Add(statusRegister);
         for (int i = 0; i < 16; i++)
         {
             statusRegister.StatusRegisterBits.Add(new StatusRegisterBit()
             {
                 Bit = i,
                 Alias = "NA",
                 Description = "NA",
                 Enabled = false,
                 RegisterId = statusRegister.Id
             });
         }
         context.SaveChanges();
         return statusRegister;
     }
 }
示例#2
0
 public ActionResult CreateStatus(StatusRegister register)
 {
     if (ModelState.IsValid)
     {
         RegisterFactory.CreateStatusRegister(register.DeviceId, register.Alias, register.Description, register.RegisterNumber, register.SignednessType);
         return RedirectToAction("Edit", "Device", new { id = register.DeviceId });
     }
     return View(register);
 }
示例#3
0
 private void checkStatusAlert(StatusRegisterBitAlert alert, StatusRegisterBit bit, StatusRegister register, RegisterFeedback feedback)
 {
     var isBitSet = bit.IsBitSet(register, feedback);
     var alarmAlerted = alert.Alerted;
     if (bit.ActiveType == ActiveType.ActiveHigh)
     {
         if (!alarmAlerted && isBitSet)
         {
             alert.Alerted = true;
             m_context.SaveChanges();
             sendEmail(alert.EmailSubject, buildStatusBody(alert, bit, register), alert.getEmailsList());
         }
         else if (alarmAlerted && !isBitSet)
         {
             alert.Alerted = false;
             m_context.SaveChanges();
             sendEmail(alert.EmailSubject, buildStatusBody(alert, bit, register), alert.getEmailsList());
         }
     }
     else if (bit.ActiveType == ActiveType.ActiveLow)
     {
         if (!alarmAlerted && !isBitSet)
         {
             alert.Alerted = true;
             m_context.SaveChanges();
             sendEmail(alert.EmailSubject, buildStatusBody(alert, bit, register), alert.getEmailsList());
         }
         else if (alarmAlerted && isBitSet)
         {
             alert.Alerted = false;
             m_context.SaveChanges();
             sendEmail(alert.EmailSubject, buildStatusBody(alert, bit, register), alert.getEmailsList());
         }
     }
 }
示例#4
0
 private string buildStatusBody(StatusRegisterBitAlert alert, StatusRegisterBit bit, StatusRegister register)
 {
     var builder = new StringBuilder();
     if (alert.Alerted)
     {
         builder.AppendLine(alert.EmailBody);
     }
     else
     {
         builder.AppendLine("No longer in an alerted state.");
     }
     builder.AppendLine("Device: ");
     builder.AppendLine(register.Device.SerialNumber);
     builder.AppendLine("Register: ");
     builder.AppendLine(register.Alias);
     builder.AppendLine("Bit: ");
     builder.AppendLine(bit.Alias);
     return builder.ToString();
 }
示例#5
0
 public ActionResult CreateStatus(int deviceID)
 {
     var sReg = new StatusRegister();
     sReg.DeviceId = deviceID;
     return redirectToEdit(sReg);
 }
示例#6
0
 public StatusRegisterFeedbackBitValue(RegisterFeedback feedback, StatusRegisterBit bit, StatusRegister reg)
 {
     this.Reg = reg;
     this.Feedback = feedback;
     this.Bit = bit;
     this.Value = this.Bit.IsBitSet(reg, feedback);
 }
示例#7
0
 private List<ChannelDataPoints> getStatusFeedbacks(StatusRegister reg, IEnumerable<RegisterFeedback> feedbacks)
 {
     var vals = new List<StatusRegisterFeedbackBitValue>();
     foreach (var feedback in feedbacks)
     {
         foreach (var bit in reg.StatusRegisterBits.Where(b => b.Enabled))
         {
             var val = new StatusRegisterFeedbackBitValue(feedback, bit, reg);
             vals.Add(val);
         }
     }
     var channelsAndPointsToSend = new List<ChannelDataPoints>();
     var bitGroups = vals.GroupBy(value => value.Bit);
     foreach(var values in bitGroups)
     {
         var valuesToSend = new List<SensorCloud.Point>(values.Count());
         foreach (var bit in values)
         {
             if (bit.Value)
             {
                 valuesToSend.Add(new SensorCloud.Point(bit.Feedback.ReadAt, (float)1.0));
             }
             else
             {
                 valuesToSend.Add(new SensorCloud.Point(bit.Feedback.ReadAt, (float)0.0));
             }
         }
         var channelId = reg.Id.ToString() + "Bit" + values.Key.Bit.ToString();
         var channelAndPoints = new ChannelDataPoints()
         {
             ChannelID=channelId,
             DataPoints = valuesToSend
         };
         channelsAndPointsToSend.Add(channelAndPoints);
     }
     return channelsAndPointsToSend;
 }