Fix models conversions
Fix Osai ack/strobe bit indexes
This commit is contained in:
Binary file not shown.
@@ -264,7 +264,9 @@ namespace Step.Database.Controllers
|
||||
{
|
||||
DbNcToolModel tool = FindTool(toolId);
|
||||
|
||||
tool.Status = ((DbNcToolModel)dtoTool).Status;
|
||||
var shankId = tool.ShankId;
|
||||
|
||||
// Update db model
|
||||
SupportFunctions.CopyProperties(dtoTool, tool);
|
||||
tool.ShankId = shankId;
|
||||
@@ -303,6 +305,8 @@ namespace Step.Database.Controllers
|
||||
DbNcFamilyModel dbFamily = FindFamily(familyId);
|
||||
// Copy data from NewModel to DbModel
|
||||
SupportFunctions.CopyProperties(family, dbFamily);
|
||||
// Set cooling byte
|
||||
dbFamily.CoolingByte = ((DbNcFamilyModel)family).CoolingByte;
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
// Connect tools data
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace Step.Model.DTOModels.ToolModels
|
||||
public static explicit operator DTONewNcFamilyModel(DbNcFamilyModel obj)
|
||||
{
|
||||
// Get bit values
|
||||
BitArray coolingByte = new BitArray(obj.CoolingByte);
|
||||
BitArray coolingByte = new BitArray(new byte[] { obj.CoolingByte });
|
||||
bool[] bits = new bool[8];
|
||||
coolingByte.CopyTo(bits, 0);
|
||||
|
||||
@@ -121,10 +121,7 @@ namespace Step.Model.DTOModels.ToolModels
|
||||
{
|
||||
// Prepare status byte
|
||||
bool[] result = new bool[8] { obj.Cooling, obj.Cooling1, obj.Cooling2, obj.Cooling3, obj.Cooling4, obj.Cooling5, obj.Cooling6, obj.Cooling7 };
|
||||
byte coolingByte = 0;
|
||||
// Set each bit in the byte
|
||||
for (int i = 0; i < 8; i++)
|
||||
result[i] = (coolingByte & (1 << i)) == 0 ? false : true;
|
||||
byte coolingByte = ConvertArrayToByte(result);
|
||||
|
||||
return new DbNcFamilyModel()
|
||||
{
|
||||
@@ -148,6 +145,15 @@ namespace Step.Model.DTOModels.ToolModels
|
||||
ReviveDelta = obj.ReviveDelta,
|
||||
};
|
||||
}
|
||||
|
||||
protected static byte ConvertArrayToByte(bool[] bits)
|
||||
{
|
||||
BitArray bitField = new BitArray(bits); //BitArray takes a bool[]
|
||||
byte[] bytes = new byte[1];
|
||||
bitField.CopyTo(bytes, 0);
|
||||
|
||||
return bytes[0];
|
||||
}
|
||||
}
|
||||
|
||||
public class DTONcFamilyModel : DTONewNcFamilyModel
|
||||
@@ -167,7 +173,7 @@ namespace Step.Model.DTOModels.ToolModels
|
||||
}
|
||||
|
||||
// Get bit values
|
||||
BitArray coolingByte = new BitArray(obj.CoolingByte);
|
||||
BitArray coolingByte = new BitArray(new byte[] { obj.CoolingByte });
|
||||
bool[] bits = new bool[8];
|
||||
coolingByte.CopyTo(bits, 0);
|
||||
|
||||
@@ -207,10 +213,7 @@ namespace Step.Model.DTOModels.ToolModels
|
||||
{
|
||||
// Prepare status byte
|
||||
bool[] result = new bool[8] { obj.Cooling, obj.Cooling1, obj.Cooling2, obj.Cooling3, obj.Cooling4, obj.Cooling5, obj.Cooling6, obj.Cooling7 };
|
||||
byte coolingByte = 0;
|
||||
// Set each bit in the byte
|
||||
for (int i = 0; i < 8; i++)
|
||||
result[i] = (coolingByte & (1 << i)) == 0 ? false : true;
|
||||
byte coolingByte = ConvertArrayToByte(result);
|
||||
|
||||
return new DbNcFamilyModel()
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Step.Model.DatabaseModels;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using static CMS_CORE_Library.DataStructures;
|
||||
@@ -64,10 +65,7 @@ namespace Step.Model.DTOModels.ToolModels
|
||||
{
|
||||
// Prepare status byte
|
||||
bool[] result = new bool[8] { obj.Disabled, obj.Broken, obj.Measured, obj.ClockwiseRotation, obj.CounterClockwiseRotation, false, false, false };
|
||||
byte status = 0;
|
||||
// Set each bit in the byte
|
||||
for (int i = 0; i < 8; i++)
|
||||
result[i] = (status & (1 << i)) == 0 ? false : true;
|
||||
byte status = ConvertArrayToByte(result);
|
||||
|
||||
return new DbNcToolModel()
|
||||
{
|
||||
@@ -79,6 +77,15 @@ namespace Step.Model.DTOModels.ToolModels
|
||||
Status = status
|
||||
};
|
||||
}
|
||||
|
||||
protected static byte ConvertArrayToByte(bool[] bits)
|
||||
{
|
||||
BitArray bitField = new BitArray(bits); //BitArray takes a bool[]
|
||||
byte[] bytes = new byte[1];
|
||||
bitField.CopyTo(bytes, 0);
|
||||
|
||||
return bytes[0];
|
||||
}
|
||||
}
|
||||
|
||||
public class DTONcToolModel : DTONcTool
|
||||
@@ -94,7 +101,7 @@ namespace Step.Model.DTOModels.ToolModels
|
||||
public static explicit operator DTONcToolModel(DbNcToolModel obj)
|
||||
{
|
||||
// Get bit values
|
||||
var statusBits = new BitArray(obj.Status);
|
||||
var statusBits = new BitArray(new byte[] { obj.Status });
|
||||
bool[] bits = new bool[8];
|
||||
statusBits.CopyTo(bits, 0);
|
||||
|
||||
@@ -118,10 +125,7 @@ namespace Step.Model.DTOModels.ToolModels
|
||||
{
|
||||
// Prepare status byte
|
||||
bool[] result = new bool[8] { obj.Disabled, obj.Broken, obj.Measured, obj.ClockwiseRotation, obj.CounterClockwiseRotation, false, false, false };
|
||||
byte status = 0;
|
||||
// Set each bit in the byte
|
||||
for (int i = 0; i < 8; i++)
|
||||
result[i] = (status & (1 << i)) == 0 ? false : true;
|
||||
byte status = ConvertArrayToByte(result);
|
||||
|
||||
return new DbNcToolModel()
|
||||
{
|
||||
@@ -174,10 +178,7 @@ namespace Step.Model.DTOModels.ToolModels
|
||||
{
|
||||
// Prepare status byte
|
||||
bool[] result = new bool[8] { obj.Disabled, obj.Broken, obj.Measured, obj.ClockwiseRotation, obj.CounterClockwiseRotation, false, false, false};
|
||||
byte status = 0;
|
||||
// Set each bit in the byte
|
||||
for (int i = 0; i < 8; i++)
|
||||
result[i] = (status & (1 << i)) == 0 ? false : true;
|
||||
byte status = ConvertArrayToByte(result);
|
||||
|
||||
return new DbNcToolModel()
|
||||
{
|
||||
|
||||
@@ -54,6 +54,7 @@ namespace Step.Model.DatabaseModels
|
||||
FamilyId = obj.FamilyId,
|
||||
OffsetLength = (ushort)obj.OffsetLength,
|
||||
ResidualLife = (ushort)obj.ResidualLife,
|
||||
Status = obj.Status,
|
||||
ResidualRevive = (ushort)obj.ResidualRevive,
|
||||
ShankId = obj.ShankId == null ? 0 : obj.ShankId.Value,
|
||||
OffsetId1 = obj.OffsetId1 == null ? 0 : obj.OffsetId1.Value,
|
||||
|
||||
@@ -1572,7 +1572,7 @@ namespace Step.NC
|
||||
{
|
||||
updatedStatus = new Dictionary<int, byte>();
|
||||
updatedLives = new Dictionary<int, uint>();
|
||||
return numericalControl.TOOLS_RUpdatedToolsData(ref updatedStatus, ref updatedLives);
|
||||
return numericalControl.TOOLS_RUpdatedToolsData(ref updatedStatus, ref updatedLives);
|
||||
}
|
||||
|
||||
public CmsError CheckIfShankCanFit(int magazineId, int positionId, DbNcShankModel shankToBeLoaded)
|
||||
|
||||
Reference in New Issue
Block a user