Commit 11b90637 LN

rest/api/v1/shelf/allPosOff?color=green 指定灭灯的颜色,如果为空,所有灯全部熄灭

1 个父辈 9a53769b
......@@ -154,6 +154,7 @@ namespace SmartShelf.DeviceLibrary
public class Light
{
public static string defaultColor = "green";
public static byte defaultR = 0;
public static byte defaultG = 50;
public static byte defaultB = 0;
......
......@@ -13,24 +13,42 @@ namespace SmartShelf.DeviceLibrary
/// </summary>
public class BOXManager
{
private static int ServerPort = ConfigAppSettings.GetIntValue(Setting_Init.ServerPort);
private static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public static string BoxName = "单色灯料架";
public static string CID = "";
private static System.Timers.Timer timersTimer;
private static int ServerPort = ConfigAppSettings.GetIntValue(Setting_Init.ServerPort);
// private static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public static string BoxName = "单色灯料架";
public static string CID = "";
private static System.Timers.Timer timersTimer;
private static bool isInit = false;
public static string WarnMsg = "";
public static Dictionary<string, BoxPosition> PositionMap=null;
public static Dictionary<string, BoxPosition> PositionMap = null;
public static int BoxCount = 1;
public static Dictionary<string, int> StatusMap = new Dictionary<string, int>();
private static Dictionary<string, string> StatusColorMap = new Dictionary<string, string>();
public static bool IsRun = false;
public static string GetPosIdColor(string posId)
{
if (StatusColorMap.ContainsKey(posId))
{
return StatusColorMap[posId];
}
return "";
}
public static void UpdatePosIdColor(string posId, string color="")
{
if (StatusColorMap.ContainsKey(posId))
{
StatusColorMap[posId] = color;
}
else
{
StatusColorMap.Add(posId, color);
}
}
public static bool StartInit()
{
try
{
{
BoxCount = ConfigAppSettings.GetIntValue(Setting_Init.BoxCount);
string appPath = Application.StartupPath;
//加载位置
......@@ -39,7 +57,7 @@ namespace SmartShelf.DeviceLibrary
{
string fileSub = System.IO.Path.GetExtension(positionConfigFile);
for (int i = 1; i <= BoxCount; i++)
{
{
string fileName = positionConfigFile.Substring(0, positionConfigFile.Length - fileSub.Length) + "_" + i + fileSub;
CSVPositionReader<BoxPosition>.AddCSVFile(fileName);
}
......@@ -54,14 +72,14 @@ namespace SmartShelf.DeviceLibrary
return false;
}
LEDManager.deviceMap = new Dictionary<string, LEDBaseModule>();
StatusMap = new Dictionary<string, int>();
StatusColorMap = new Dictionary<string, string>();
foreach (BoxPosition box in PositionMap.Values)
{
if (!LEDManager.deviceMap.ContainsKey(box.DeviceIp))
{
LEDManager.deviceMap.Add(box.DeviceIp, LEDBaseModule.GetModule(box.DeviceIp));
}
StatusMap.Add(box.PositionNum, -1);
StatusColorMap.Add(box.PositionNum, "");
}
CID = ConfigAppSettings.GetValue(Setting_Init.Store_CID);
......@@ -80,57 +98,59 @@ namespace SmartShelf.DeviceLibrary
LogUtil.error(BoxName + "加载配置出错:" + ex.ToString());
}
return false;
}
}
protected static void Init()
{
if (!isInit)
{
{
timersTimer = new System.Timers.Timer();
timersTimer.Enabled = false;
timersTimer.Interval = 200;
timersTimer.Interval = 1000;
timersTimer.Elapsed += timersTimer_Elapsed;
timersTimer.AutoReset = true;
isInit = true;
isInit = true;
}
}
public static bool StartRun()
{
ServerPort = ConfigAppSettings.GetIntValue(Setting_Init.ServerPort);
LogUtil.info(LOGGER, BoxName + "开始启动:" + DateTime.Now.ToString() + "!");
timersTimer.Enabled = true;
LogUtil.info(BoxName + "开始启动:" + DateTime.Now.ToString() + "!");
timersTimer.Enabled = true;
IsRun = true;
LEDManager. OpenStatusLights("green");
LEDManager.OpenStatusLights("green");
HttpServer.Start(ServerOnReceived, ServerPort);
LogUtil.info("启动服务完成,ServerPort【" + ServerPort + "】");
return true;
}
}
public static void StopRun()
{
//关闭串口
timersTimer.Enabled = false;
foreach(LEDBaseModule led in LEDManager.deviceMap.Values)
{
//关闭串口
timersTimer.Enabled = false;
foreach (LEDBaseModule led in LEDManager.deviceMap.Values)
{
led.AllLightOff();
}
LEDManager.CloseStatusLights();
LEDManager.CloseStatusLights();
HttpServer.Stop();
IsRun = false;
LogUtil.info(LOGGER, BoxName + "停止运行,时间" + DateTime.Now.ToShortTimeString() + "!");
LogUtil.info(BoxName + "停止运行,时间" + DateTime.Now.ToShortTimeString() + "!");
}
protected static void timersTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
//判断是否需要亮黄灯
List<string> openLeds = new List<string>();
foreach (string key in StatusMap.Keys)
foreach (string key in StatusColorMap.Keys)
{
if (StatusMap[key].Equals(1))
string color = GetPosIdColor(key);
if (!String.IsNullOrEmpty(color))
{
openLeds.Add(key);
break;
}
}
if (openLeds.Count > 0)
......@@ -147,12 +167,12 @@ namespace SmartShelf.DeviceLibrary
LEDManager.OpenStatusLights("yellow");
}
}
}
catch (Exception ex)
{
LogUtil.error("timersTimer_Elapsed出错:" + ex.ToString());
}
}
}
public static string Path_LedOn = "/rest/api/v1/shelf/posOn";
public static string Path_LedOff = "/rest/api/v1/shelf/posOff";
......@@ -160,6 +180,7 @@ namespace SmartShelf.DeviceLibrary
public static string Path_ledOffAll = "/rest/api/v1/shelf/allPosOff";
public static string Param_posId = "posId";
public static string Param_color = "color";
public static char PosId_SpiltChar = ';';
public static char PosId_Color_SpiltChar = '@';
......@@ -167,14 +188,15 @@ namespace SmartShelf.DeviceLibrary
// 关灯:http:/localhost:80/rest/api/v1/shelf/posOff?posId=1_3_1;1_3_2;1_3_4
//关闭所有:http:/localhost:80/rest/api/v1/shelf/allPosOn
//打开所有:http:/localhost:80/rest/api/v1/shelf/allPosOff
private static string ServerOnReceived(string reqPath, string paramStr)
//rest/api/v1/shelf/allPosOff? color = green 指定灭灯的颜色,如果为空,所有灯全部熄灭
private static string ServerOnReceived(string reqPath, string paramStr)
{
try
{
Dictionary<string, string> paramMap = GetParam(paramStr);
string msg = ": conot find param " + Param_posId ;
string msg = ": conot find param " + Param_posId;
if (reqPath.Equals(Path_LedOn))
{
{
if (paramMap.ContainsKey(Param_posId))
{
string pos = paramMap[Param_posId];
......@@ -183,11 +205,11 @@ namespace SmartShelf.DeviceLibrary
}
else
{
return GetResult(false, "posOn")+ msg;
return GetResult(false, "posOn") + msg;
}
}
else if (reqPath.Equals(Path_LedOff))
{
{
if (paramMap.ContainsKey(Param_posId))
{
string pos = paramMap[Param_posId];
......@@ -205,8 +227,18 @@ namespace SmartShelf.DeviceLibrary
return GetResult(result, "allPosOn");
}
else if (reqPath.Equals(Path_ledOffAll))
{
bool result = ProcessCloseAll();
{
bool result = true;
string color = "";
if (paramMap.ContainsKey(Param_color) && (paramMap[Param_color] != ""))
{
color = paramMap[Param_color];
result = ProcessCloseByColor(color);
}
else
{
result = ProcessCloseAll();
}
return GetResult(result, "allPosOff");
}
else
......@@ -249,7 +281,7 @@ namespace SmartShelf.DeviceLibrary
}
private static string GetResult(bool result, string op)
private static string GetResult(bool result, string op)
{
if (result)
{
......@@ -284,16 +316,16 @@ namespace SmartShelf.DeviceLibrary
}
if (String.IsNullOrEmpty(ip) || pIP.Equals(ip))
{
StatusMap[key] = 1;
UpdatePosIdColor(key, Light.defaultColor);
}
}
return true;
}
public static bool ProcessCloseAll(string proMsg= "Revice ", string ip = "")
public static bool ProcessCloseAll(string proMsg = "Revice ", string ip = "")
{
LogUtil.info(BoxName + proMsg+ " closeAll命令:" );
LogUtil.info(BoxName + proMsg + " closeAll命令:");
List<string> posIdList = new List<string>(PositionMap.Keys);
foreach(LEDBaseModule led in LEDManager.deviceMap.Values)
foreach (LEDBaseModule led in LEDManager.deviceMap.Values)
{
if (String.IsNullOrEmpty(ip) || led.ModuleIP.Equals(ip))
{
......@@ -309,34 +341,59 @@ namespace SmartShelf.DeviceLibrary
}
if (String.IsNullOrEmpty(ip) || pIP.Equals(ip))
{
StatusMap[key] = 0;
UpdatePosIdColor(key);
}
}
return true;
}
public static bool ProcessOpenLed(string posids, string proMsg = "Revice ")
public static bool ProcessCloseByColor(string color, string proMsg = "Revice ", string ip = "")
{
LogUtil.info(BoxName + proMsg + " ProcessCloseByColor 命令:" + color);
List<string> posIdList = new List<string>(PositionMap.Keys);
foreach (LEDBaseModule led in LEDManager.deviceMap.Values)
{
if (String.IsNullOrEmpty(ip) || led.ModuleIP.Equals(ip))
{
led.AllLightOff();
}
}
foreach (string key in posIdList)
{
string status = GetPosIdColor(key);
if (status.ToLower().Equals(color.ToLower()))
{
BoxPosition position = PositionMap[key];
LEDManager.GetLedModule(position.DeviceIp).LightOff(Light.GetLights(position.DmxId, position.GetLedList(), 0));
UpdatePosIdColor(key);
}
}
return true;
}
public static bool ProcessOpenLed(string posids, string proMsg = "Revice ")
{
LogUtil.info(BoxName + proMsg + " open命令:" + posids);
string[] posArray = posids.Split(PosId_SpiltChar);
foreach (string posStr in posArray)
{
{
string posid = posStr;
string color = "Green";
string color = Light.defaultColor;
if (posStr.Contains(PosId_Color_SpiltChar))
{
string[] posInfos = posStr.Split(PosId_Color_SpiltChar);
posid = posInfos[0];
color = posInfos[1];
color = posInfos[1];
}
color = color.ToLower();
if (PositionMap.ContainsKey(posid))
{
{
BoxPosition position = PositionMap[posid];
Light[] lights = Light.GetLights(position.DmxId, color, position.GetLedList().ToArray());
LEDManager.GetLedModule(position.DeviceIp).LightOn(lights);
StatusMap[posid] = 1;
UpdatePosIdColor(posid, color);
}
else
{
......@@ -352,9 +409,9 @@ namespace SmartShelf.DeviceLibrary
}
return true;
}
public static bool ProcessCloseLed(string posids, string proMsg = "Revice ")
public static bool ProcessCloseLed(string posids, string proMsg = "Revice ")
{
LogUtil.info(BoxName + proMsg + " close命令:" + posids);
string[] posArray = posids.Split(PosId_SpiltChar);
......@@ -370,8 +427,9 @@ namespace SmartShelf.DeviceLibrary
if (PositionMap.ContainsKey(posName))
{
BoxPosition position = PositionMap[posName];
LEDManager.GetLedModule(position.DeviceIp).LightOff(Light.GetLights(position.DmxId,position.GetLedList(),0) );
StatusMap[posName] = 0;
LEDManager.GetLedModule(position.DeviceIp).LightOff(Light.GetLights(position.DmxId, position.GetLedList(), 0));
// StatusColorMap[posName] = "";
UpdatePosIdColor(posName);
}
else
{
......@@ -380,6 +438,6 @@ namespace SmartShelf.DeviceLibrary
}
return true;
}
}
}
......@@ -32,9 +32,7 @@
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmSMStore));
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.button5 = new System.Windows.Forms.Button();
this.btnCloseSLed = new System.Windows.Forms.Button();
this.btnOpenSLed = new System.Windows.Forms.Button();
this.lblAddr = new System.Windows.Forms.Label();
this.cmbNum = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.txtDmxId = new System.Windows.Forms.TextBox();
......@@ -48,6 +46,9 @@
this.label5 = new System.Windows.Forms.Label();
this.cmbPositionList = new System.Windows.Forms.ComboBox();
this.label10 = new System.Windows.Forms.Label();
this.button5 = new System.Windows.Forms.Button();
this.btnCloseSLed = new System.Windows.Forms.Button();
this.btnOpenSLed = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.numYu = new System.Windows.Forms.NumericUpDown();
......@@ -73,7 +74,6 @@
this.btOAll = new System.Windows.Forms.Button();
this.txtIp2 = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.lblAddr = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numYu)).BeginInit();
......@@ -116,38 +116,14 @@
this.groupBox2.TabStop = false;
this.groupBox2.Text = "库位操作测试";
//
// button5
//
this.button5.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button5.Location = new System.Drawing.Point(127, 21);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(95, 35);
this.button5.TabIndex = 112;
this.button5.Text = "亮黄灯";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// btnCloseSLed
//
this.btnCloseSLed.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnCloseSLed.Location = new System.Drawing.Point(228, 21);
this.btnCloseSLed.Name = "btnCloseSLed";
this.btnCloseSLed.Size = new System.Drawing.Size(95, 35);
this.btnCloseSLed.TabIndex = 111;
this.btnCloseSLed.Text = "关闭灯";
this.btnCloseSLed.UseVisualStyleBackColor = true;
this.btnCloseSLed.Click += new System.EventHandler(this.btnCloseSLed_Click);
//
// btnOpenSLed
// lblAddr
//
this.btnOpenSLed.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnOpenSLed.Location = new System.Drawing.Point(26, 21);
this.btnOpenSLed.Name = "btnOpenSLed";
this.btnOpenSLed.Size = new System.Drawing.Size(95, 35);
this.btnOpenSLed.TabIndex = 110;
this.btnOpenSLed.Text = "亮绿灯";
this.btnOpenSLed.UseVisualStyleBackColor = true;
this.btnOpenSLed.Click += new System.EventHandler(this.btnOpenSLed_Click);
this.lblAddr.AutoSize = true;
this.lblAddr.Location = new System.Drawing.Point(232, 112);
this.lblAddr.Name = "lblAddr";
this.lblAddr.Size = new System.Drawing.Size(0, 17);
this.lblAddr.TabIndex = 113;
this.lblAddr.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// cmbNum
//
......@@ -283,6 +259,39 @@
this.label10.Text = "库位列表:";
this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// button5
//
this.button5.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button5.Location = new System.Drawing.Point(127, 21);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(95, 35);
this.button5.TabIndex = 112;
this.button5.Text = "亮黄灯";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// btnCloseSLed
//
this.btnCloseSLed.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnCloseSLed.Location = new System.Drawing.Point(228, 21);
this.btnCloseSLed.Name = "btnCloseSLed";
this.btnCloseSLed.Size = new System.Drawing.Size(95, 35);
this.btnCloseSLed.TabIndex = 111;
this.btnCloseSLed.Text = "关闭灯";
this.btnCloseSLed.UseVisualStyleBackColor = true;
this.btnCloseSLed.Click += new System.EventHandler(this.btnCloseSLed_Click);
//
// btnOpenSLed
//
this.btnOpenSLed.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnOpenSLed.Location = new System.Drawing.Point(26, 21);
this.btnOpenSLed.Name = "btnOpenSLed";
this.btnOpenSLed.Size = new System.Drawing.Size(95, 35);
this.btnOpenSLed.TabIndex = 110;
this.btnOpenSLed.Text = "亮绿灯";
this.btnOpenSLed.UseVisualStyleBackColor = true;
this.btnOpenSLed.Click += new System.EventHandler(this.btnOpenSLed_Click);
//
// label3
//
this.label3.AutoSize = true;
......@@ -389,6 +398,7 @@
this.panel1.AutoScroll = true;
this.panel1.Controls.Add(this.lblLedInfo);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.panel1.Location = new System.Drawing.Point(3, 22);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(734, 772);
......@@ -396,14 +406,16 @@
//
// lblLedInfo
//
this.lblLedInfo.AutoSize = true;
this.lblLedInfo.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblLedInfo.ForeColor = System.Drawing.Color.Green;
this.lblLedInfo.Location = new System.Drawing.Point(12, 16);
this.lblLedInfo.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblLedInfo.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblLedInfo.ForeColor = System.Drawing.Color.Blue;
this.lblLedInfo.Location = new System.Drawing.Point(3, 6);
this.lblLedInfo.Name = "lblLedInfo";
this.lblLedInfo.Size = new System.Drawing.Size(51, 19);
this.lblLedInfo.Size = new System.Drawing.Size(728, 765);
this.lblLedInfo.TabIndex = 0;
this.lblLedInfo.Text = "label3";
this.lblLedInfo.Text = "?";
//
// groupTest
//
......@@ -574,15 +586,6 @@
this.label6.Text = "模块IP:";
this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// lblAddr
//
this.lblAddr.AutoSize = true;
this.lblAddr.Location = new System.Drawing.Point(232, 112);
this.lblAddr.Name = "lblAddr";
this.lblAddr.Size = new System.Drawing.Size(0, 17);
this.lblAddr.TabIndex = 113;
this.lblAddr.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// groupBox3
//
this.groupBox3.Controls.Add(this.btnOpenSLed);
......@@ -619,7 +622,6 @@
((System.ComponentModel.ISupportInitialize)(this.numYu)).EndInit();
this.groupBox1.ResumeLayout(false);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.groupTest.ResumeLayout(false);
this.groupTest.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBar3)).EndInit();
......
......@@ -98,19 +98,20 @@ namespace SmartShelf
foreach (BoxPosition p in positions)
{
int status = BOXManager.StatusMap[p.PositionNum];
string status = BOXManager.GetPosIdColor(p.PositionNum);
str += status.ToString();
if (status.Equals(1))
if (!String.IsNullOrEmpty(status))
{
num++;
int length = p.PositionNum.Length;
if ((num % 10).Equals(0))
int length = p.PositionNum.Length;
//if ((num % 10).Equals(0))
//{
// msg += p.PositionNum.PadLeft(24 - length, ' ') +"["+status+"]"+ "\r\n ";
//}
//else
{
msg += p.PositionNum.PadLeft(24- length, ' ') + "\r\n ";
}
else {
msg += p.PositionNum.PadLeft(24- length, ' ');
msg += p.PositionNum.PadLeft(20 - length, ' ')+"[" + status + "]";
}
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!