diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index bf8936f2..3b338038 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -18,6 +18,7 @@ jobs: dotnet-version: | 3.1.x 6.0.x + 8.0.x - name: Build library (.net core) run: dotnet build src/OpenProtocolInterpreter/OpenProtocolInterpreter.csproj --configuration release test: @@ -30,6 +31,7 @@ jobs: dotnet-version: | 3.1.x 6.0.x + 8.0.x - name: Test Mids run: | dotnet build src/MIDTesters.Core/MIDTesters.Core.csproj diff --git a/.github/workflows/net-framework.yml b/.github/workflows/net-standard.yml similarity index 93% rename from .github/workflows/net-framework.yml rename to .github/workflows/net-standard.yml index d90fb735..acd7e153 100644 --- a/.github/workflows/net-framework.yml +++ b/.github/workflows/net-standard.yml @@ -1,4 +1,4 @@ -name: .Net Framework +name: .Net Standard on: pull_request: @@ -13,7 +13,7 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@master - - name: Setup .Net Framework + - name: Setup .Net Standard uses: actions/setup-dotnet@master - name: build run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b734f0cf..eb70cfd2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,6 +16,7 @@ jobs: dotnet-version: | 3.1.x 6.0.x + 8.0.x - name: Build library (.net core) run: dotnet build src/OpenProtocolInterpreter/OpenProtocolInterpreter.csproj --configuration release test: @@ -28,6 +29,7 @@ jobs: dotnet-version: | 3.1.x 6.0.x + 8.0.x - name: Test Mids run: | dotnet build src/MIDTesters.Core/MIDTesters.Core.csproj diff --git a/OpenProtocolInterpreter.sln b/OpenProtocolInterpreter.sln index 8452c9a5..7139eada 100644 --- a/OpenProtocolInterpreter.sln +++ b/OpenProtocolInterpreter.sln @@ -7,22 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenProtocolInterpreter", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MIDTesters.Core", "src\MIDTesters.Core\MIDTesters.Core.csproj", "{478EE366-16EE-4B94-9E83-87E955A600F5}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution Files", "{889BF604-4813-4B35-A790-3170FF26F063}" - ProjectSection(SolutionItems) = preProject - .gitignore = .gitignore - LICENSE = LICENSE - README.md = README.md - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{BDBD675F-8C53-4422-B3EA-8087BF245AB5}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{CE8390CD-7EFE-43CC-A8DD-123F04D6045E}" - ProjectSection(SolutionItems) = preProject - .github\workflows\dotnetcore.yml = .github\workflows\dotnetcore.yml - .github\workflows\net-framework.yml = .github\workflows\net-framework.yml - .github\workflows\release.yml = .github\workflows\release.yml - EndProjectSection -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -41,10 +25,6 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {BDBD675F-8C53-4422-B3EA-8087BF245AB5} = {889BF604-4813-4B35-A790-3170FF26F063} - {CE8390CD-7EFE-43CC-A8DD-123F04D6045E} = {BDBD675F-8C53-4422-B3EA-8087BF245AB5} - EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4EEC9517-6E55-467A-A590-2AA2DC26D360} EndGlobalSection diff --git a/dist/lib/net6/OpenProtocolInterpreter.dll b/dist/lib/net6/OpenProtocolInterpreter.dll index 3aae255f..ac3c8b3d 100644 Binary files a/dist/lib/net6/OpenProtocolInterpreter.dll and b/dist/lib/net6/OpenProtocolInterpreter.dll differ diff --git a/dist/lib/net6/OpenProtocolInterpreter.xml b/dist/lib/net6/OpenProtocolInterpreter.xml index 4e97c136..29c2f0db 100644 --- a/dist/lib/net6/OpenProtocolInterpreter.xml +++ b/dist/lib/net6/OpenProtocolInterpreter.xml @@ -459,7 +459,7 @@ - Application Communication positive acknowledge + Application data message request Do a request for data. This message is used for ALL request handling. When used it substitutes the use of all MID special request messages. @@ -2439,6 +2439,15 @@ + + + The MID Revision is unique per MID and is used in case different versions are available for the same MID. + Using the revision number the integrator can subscribe or ask for different versions of the same MID. + + Note: Enforces the default MID Revision to 1 when it's either send three spaces or 000 or 001. + + + Define if subscriber will acknowledge each "push" message sent by controller (reliable mode) or just push without waiting for a receive acknowledgement from subscriber (unreliable mode) @@ -4046,6 +4055,18 @@ + + + Old Multi spindle result request + Request for an old multi spindle result. + Note: MID 0104 can’t be used if there is an active subscription for multiple spindle results. + Message sent by: Integrator + + Answer: Command accepted or + Command error, Multi spindle result subscription already exists + + + Template for implementers. @@ -4336,6 +4357,19 @@ + + + Tightening Program Delete + Message sent by: Integrator + + Answer: Command accepted or + Command error + + This message deletes one or all programs in controller. + Note: If a running program is included in MID 2506 deletion the program shall finish before deletion. + Note: Deleting programs included in other nodes may give unwanted behaviour. It will behave identical to a manual delete of the program. + + Template for implementers. @@ -4755,6 +4789,15 @@ Answer: None + + + Tightening Result DB Info Upload + This message contains information concerning the tightening result database on the controller. + Application Data Message Request shall be used for fetching this message + Message sent by: Controller + Answer: None + + Represents a Stage Result entity @@ -4950,6 +4993,21 @@ + + + Tool Data status reply with generic data + + Upload requested parameters from given tool. + + Message sent by: Controller + + Answer: None + + + The list will contain requested parameters from the tool. + + + Represents a Tool diff --git a/dist/lib/net8/OpenProtocolInterpreter.dll b/dist/lib/net8/OpenProtocolInterpreter.dll new file mode 100644 index 00000000..bfc362d6 Binary files /dev/null and b/dist/lib/net8/OpenProtocolInterpreter.dll differ diff --git a/dist/lib/net8/OpenProtocolInterpreter.xml b/dist/lib/net8/OpenProtocolInterpreter.xml new file mode 100644 index 00000000..29c2f0db --- /dev/null +++ b/dist/lib/net8/OpenProtocolInterpreter.xml @@ -0,0 +1,5243 @@ + + + + OpenProtocolInterpreter + + + + + Template for implementers. + + + + + Alarm message category. Every alarm mid must implement . + + + + + Alarm subscribe + A subscription for the alarms that can appear in the controller. + Message sent by Integrator + Answers: Command accepted or Command error, Alarm subscription already exists + + + + + Alarm + An alarm has appeared in the controller. The current alarm is uploaded from the controller to the integrator. + Message sent by: Controller + Answer: Alarm acknowledge + + + + + Alarm acknowledge + Acknowledgement for Alarm. + Message sent by: Integrator + Answer: None + + + + + Alarm unsubscribe + Reset the subscription for the controller alarms. + Message sent by: Integrator + Answer: Command accepted or Command error, Alarm subscription does not exist + + + + + Alarm acknowledged on controller + The message is sent by the controller to inform the integrator that the current alarm has been acknowledged. + Message sent by: Controller + Answer: Alarm acknowledged on controller acknowledge + + + + + Alarm acknowledged on controller acknowledge + Acknowledgement of MID 0074 Alarm acknowledged on controller. + Message sent by: Integrator + Answer : None + + + + + Alarm status + The alarm status is sent after an accepted subscription of the controller alarms. + This message is used to inform the integrator that an alarm is active on the controller at subscription time. + Message sent by: Controller + Answer: Alarm status acknowledge + + + + + Alarm status acknowledge + Acknowledgement of Alarm Status. + Message sent by: Integrator + Answer : None + + + + + Acknowledge alarm remotely on controller + The integrator can remotely acknowledge the current alarm on the controller by sending . + If no alarm is currently active when the controller receives the command, the command will be rejected. + Message sent by: Integrator + Answer : Command accepted or Command error, No alarm present or Invalid data + + + + + Template for implementers. + + + + + Application Controller message category. Every application controller mid must implement . + + + + + Controller reboot request + This message causes the controller to reboot after it has accepted the command. + + Warning 1: this MID requires programming control (see 4.4 Programming control). + Warning 2: the connection will be lost and will need to be reestablished after controller reboot! + + + Message sent by: Integrator + Answer: Command accepted or Command error, Programming control not granted + + + + + Template for implementers. + + + + + Application Selector message category. Every application selector mid must implement . + + + + + Selector socket info subscribe + + Subscribe for the socket information of all socket selectors (connected to the controller). + After subscription, every time a socket is lifted or put back, is sent to the subscriber + with the device ID of the selector and the current status of each one of the sockets, lifted or not. + + Message sent by: Integrator + Answer: Command accepted or Command error, The selector socket info subscription already exists + + + + + Selector socket info + + This message is sent each time a socket is lifted or put back in position. + This MID contains the device ID of the selector the information is coming from, + the number of sockets of the selector device, and the current status of each socket + (lifted or not lifted). + + Message sent by: Controller + Answer: , Selector socket info acknowledge + + + + + Selector socket info acknowledge + Acknowledgement of the Selector socket info. + Message sent by: Integrator + Answer: None + + + + + Selector socket info unsubscribe + Unsubscribe for the selector socket info. The subscription is reset for all selector devices. + Message sent by: Integrator + Answer: Command accepted or Command error, The selector socket info subscription does not exist + + + + + Selector control green lights + + This message controls the selector green lights. + The green light can be set (steady), reset (off) or flash. + A command must be sent for each one of the selector positions (1-8). + + + Note: This MID only works when the selector is put in external controlled mode and + this is only possible when the selector is loaded with software 1.20 or later. + + Message sent by: Integrator + Answer: Command accepted or Command error, Faulty IO device ID + + + + + Selector control red lights + + This message controls the selector red lights. + The green light can be set (steady), reset (off) or flash. + A command must be sent for each one of the selector positions (1-8). + + + Note: This MID only works when the selector is put in external controlled mode and + this is only possible when the selector is loaded with software 1.20 or later. + + Message sent by: Integrator + Answer: Command accepted or Command error, Faulty IO device ID + + + + + Template for implementers. + + + + + Application Tool Location System message category. Every application tool location system mid must implement . + + + + + Tool tag ID request + Used by the integrator to request Tool tag ID information. + Message sent by: Controller + Answer: Tool tag ID or Command error, Tool tag ID unknown or MID revision unsupported. + + + + + Tool tag ID subscribe + Used by the integrator to order a Tool tag ID subscription from the controller. + Message sent by: Controller + Answer: Tool tag ID or Command error, Tool tag ID unknown, Tool tag ID subscription already exist or MID revision unsupported. + + + + + Tool tag ID + Used by the controller to send a Tool tag ID to the integrator. + Message sent by: Controller + Answer: Tool tag ID acknowledge + + + + + Tool tag ID acknowledge + Acknowledgement of Tool tag ID. + Message sent by: Integrator + Answer: None + + + + + Tool tag ID unsubscribe + Used by the integrator to send a Tool tag ID unsubscription to the controller. + Message sent by: Integrator + Answer: Command accepted or Command error, Tool tag ID subscription does not exist or MID revision unsupported. + + + + + External Tool tag ID and status + Used by the controller to detect a Tool tag ID with its status from the integrator. + Message sent by: Integrator + Answer: Command accepted or Command error, MID revision unsupported. + + + + + Template for implementers. + + + + + Application Selector message category. Every application selector mid must implement . + + + + + Automatic/Manual mode subscribe + + A subscription for Automatic/Manual mode. When the mode changes the is sent to the integrator. + After a successful subscription the message upload with the current mode status is sent to the integrator. + + Message sent by: Integrator + + Answer: Command accepted or Command error, + Automatic/Manual mode subscribe already exists + + + + + + Automatic/Manual mode + + The operation mode in the controller has changed. + The message includes the new operational mode of the controller. + + Message sent by: Controller + Answer: Automatic/Manual mode acknowledge + + + + + Automatic Mode = false (0) + Manual Mode = true (1) + + + + + Automatic/Manual mode acknowledge + Acknowledgement of automatic/manual mode upload. + Message sent by: Integrator + Answer: None + + + + + Automatic/Manual mode unsubscribe + Reset the subscription for the automatic/manual mode. + Message sent by: Integrator + Answer: Command accepted or Command error, Automatic/Manual mode subscribe does not exist + + + + + AutoDisable settings request + + Request for AutoDisable settings. This request is intended to be used while + running single parameter sets with batch and does not provide batch information while running Job. + + Message sent by: Integrator + Answer: AutoDisable settings reply + + + + + AutoDisable settings reply + + Information about the setting of AutoDisable tightening in the controller. Also contains information about the currently running batch. + The settings are reserved for single parameter sets with batch and are not available while running Job. + + + Power Macs use: + “OKs to disable station” is a parameter in Tools Talk PowerMACS and specifies the number of cycles with status OK or OKR that may be run while in Automatic mode before the station is automatically disabled. It is sent as two ASCII digits, a 0 means the function is not in use. + “Current Batch” is two ASCII digits representing the number of OK cycles that have been run in the current batch.If the value is 0 no batch is running at the moment. + + + Power Focus use: + The “Current Batch” contains at which batch counter value/tightening the parameter set batch was + locked/finished if “batch count” and “lock at batch ok” parameters in Tools Talk PF was used, + otherwise it will contain 0 indicating function not used.If “lock at batch ok” parameter was not used + the “Current Batch” is just current. + + + The “Auto Disable” contains the parameter sets batch size if “batch count” and “lock at batch ok” + parameters was used indicating that Auto Disable function is used.If “batch count” or “lock at batch + ok” was not used the “Auto Disable” is 0. + + Message sent by: Controller + Answer: None + + + + + Template for implementers. + + + + + Communication message category. Every communication mid must implement . + + + + + Application communication start + This message enables the communication. The controller does not respond to any other command before this + Message sent by Integrator + Answers: Communication start acknowledge or Command error, Client already connected or MID revision unsupported + + + + + Application Communication start acknowledge + + When accepting the communication start the controller sends as reply, + a Communication start acknowledge. This message contains some basic information about the + controller, such as cell ID, channel ID, and name. + + Message sent by: Controller + Answer: None + + + + + If no subtype exists it will be set to 000 + For a Power Focus 4000 and PF 6000 system the valid subtypes are: + 001 = a normal tightening system + For a Power MACS 4000 system the valid subtypes are: + 001 = a normal tightening system + 002 = a system running presses instead of spindles. + + + + + Station ID for PF6000 + Cell ID for PF4000 + + + + + Station ID for PF6000 + Cell ID for PF4000 + + + + + False = Use Keep alive (Keep alive is mandatory) + True = Ignore Keep alive (Keep alive is optional) + + + + + Application Communication stop + + This message disables the communication. The controller will stop to respond to any commands + except for Communication start after receiving this command. + + Message sent by: Integrator + Answer: Command accepted + + + + + Application Communication negative acknowledge + + This message is used by the controller when a request, command or subscription for any reason has + not been performed. + The data field contains the message ID of the message request that failed as well as an error code. + It can also be used by the integrator to acknowledge received subscribed data/events upload and will + then do all the special subscription data acknowledges obsolete. + + + When using the communication acknowledgement of MID 0007 and together with sequence + numbering this is an application level message only. + + Message sent by: Controller + Answer: None + + + + + Application Communication positive acknowledge + + This message is used by the controller to confirm that the latest command, request or subscription sent + by the integrator was accepted.The data field contains the MID of the request accepted if the special + MIDs for request or subscription are used. + + + It can also be used by the integrator to acknowledge received subscribed data/events upload and will + then do all the special subscription data acknowledges obsolete. + + + When using the communication acknowledgement of MID 9997 and MID 9998 together with + sequence numbering this is an application level message only. + When using the GENERIC subscription MIDs and 0009 the data field contains the MID of + the subscribed MID. + + Message sent by: Controller + Answer: None + + + + + Application data message request + + Do a request for data. This message is used for ALL request handling. + When used it substitutes the use of all MID special request messages. + + + NOTE! The Header Revision field is the revision of the itself NOT + the revision of the data MID that is wanted to be uploaded. + + Message sent by: Integrator + Answer: MID Requested for or Command error. Error described at each MID description. + + + + + Application data message subscription + + Start a subscription of data. This message is used for ALL subscription handling. + When used it substitutes the use of all MID special subscription messages. + + + NOTE! The Header Revision field is the revision of the MID 0008 itself NOT the revision of the data + MID that is wanted to be subscribed for. + + Message sent by: Integrator + + Answer: Command accepted with the MID subscribed for or Command error, + MID revision unsupported or Invalid data code and the MID subscribed for + + + + + + Application Data Message unsubscribe + + Unsubscribe the data. This message is used for ALL unsubscribe. + When used it substitutes the use of all MID special subscription messages. + + + NOTE! The Header Revision field is the revision of the MID 0009 itself NOT the revision of the data + MID that is wanted to be subscribed for. + + Message sent by: Integrator + + Answer: Command accepted with the MID subscribed for or Command error, + MID revision unsupported or Invalid data code and the MID subscribed for + + + + + + Represents a single and raw Data Field in before being abstracted + to a typed field inside a mid entity + + + + + Represents a Data Field unit's type + + + + + Angle status. Used in . + + + + + Auto Select. Used in in . + + + + + Batch Mode. Used in + + + + + Batch Status. Used in and . + + + + /// + Batch Status at Increment. Used in in . + + + + + Calibration Units. Used in . + + + + + Current Batch Status. Used in in . + + + + + UI - The value is an unsigned integer. The number of digits are defined with the Length parameter + + + + + I - The value is a signed integer. The number of digits are defined with the Length parameter + + + + + F - The value is sent as a float value with the layout 12.12, 10025.1234 or -57.5. + It is up to the sender of the telegram to decide the number of decimals to send. + The number of characters sent varies depending on the size and resolution of the sent number. + + + + + S - The value is a string. Sent as ASCII characters, the length of the data fits the actual length of the string. + Note that the string may contain spaces (ASCII character 0x20) + + + + + S - A time specified by 19 ASCII characters (YYYY-MM-DD:HH:MM:SS) + + + + + B - A boolean value, one ASCII digit: + 0 = FALSE | 1 = TRUE + + + + + H - Hexadecimal value. Sent as ASCII characters, example: A24CD3. + + + + + PL1 - Plotting point consisting of a FA of one pair of float values where the first value is the Y and the second is the X within the pair. + + + + + PL2 - Plotting point consisting of a FA of two pairs of float values where the first value is the Y and the second is the X within a pair. + + + + + PL4 - Plotting point consisting of a FA of 4 pairs of float values where the first value is the Y and the second is the X within a pair. + + + + + FA - Array of Float. Each float value is sent as 8 ASCII characters. + Negative values start with a ‘-‘ sign. The precision of the values vary, for large values decimal point is omitted. + Valid values are for example -1234567, 001.1205, -123.789 + + + + + UA - Array of Unsigned integers. Each integer value is sent as 8 ASCII characters. + Valid values are for example 12345678, 00001234, 00200000 + + + + + IA - Array of Signed integers. Each integer value is sent as 8 ASCII characters. Negative values start with a ‘-‘ sign. + Valid values are for example 12345678, -1234567, 00200000, 10200000 + + + + + Newton meter + + + + + Foot-pound force + + + + + Centi Newton meter + + + + + Kilo Newton meter + + + + + Mega Newton meter + + + + + Inch-pound force + + + + + Kilo pound meter + + + + + Kilo centi force + + + + + Milli-newton meter + + + + + Kilogram force centimeter + + + + + Gram force centimeter + + + + + Ounce force foot + + + + + Hertz + + + + + Revolutions per minute + + + + + Newton meter / degree + + + + + Foot-pound force / degree + + + + + Centi Newton meter / degree + + + + + Kilo Newton meter / degree + + + + + Mega Newton meter / degree + + + + + Inch-pound force / degree + + + + + Newton meter / radian + + + + + Foot-pound force / radian + + + + + Centi Newton meter / radian + + + + + Newton + + + + + Kilo newton + + + + + Pound-force + + + + + Kilogram-force + + + + + Ounce-force + + + + + Mega newton + + + + + Newton / millimeter + + + + + Kilo newton / millimeter + + + + + Pound-force / inch + + + + + Kilogram-force / millimeter + + + + + Ounce-force / inch + + + + + Mega newton / millimeter + + + + + Kilogram + + + + + Pound + + + + + Kilo pascal + + + + + Y = Newton meter, X = milliseconds + + + + + Y = foot-pound force, X = milliseconds + + + + + Y = centi Newton meter, X = milliseconds + + + + + Y = kilo Newton meter, X = milliseconds + + + + + Y = mega Newton meter, X = milliseconds + + + + + Y = inch-pound force, X = milliseconds + + + + + Y = Degree, X = milliseconds + + + + + Y = Radian, X = milliseconds + + + + + Y = newton, X = milliseconds + + + + + Y = kilo newton, X = milliseconds + + + + + Y = pound-force, X = milliseconds + + + + + Y = kilogram-force, X = milliseconds + + + + + Y = ounce-force, X = milliseconds + + + + + Y = mega newton, X = milliseconds + + + + /// + Decrement batch after loosening/OK tightening. Used in in . + + + + + Digital Input Numbers. Used in , , + , and . + + + + + Disable types. Used in . + + + + + This is the same function as the revision 1 functionality. The tool is locked and cannot be started. + + + + + Will not run in the next tightening but will be included in the final result with status NOK + + + + + Will not run in the next tightening but will be included in the final result with status OK + + + + + Will not run in the next tightening and will not be included in the final result + + + + + possible errors. + + + + + Forced Orders. Used in and . + + + + + Histogram Types. Used in and . + + + + + Identifier parts. Used in . + + + + + Mid interpreter possible modes. + + + + + Job batch modes. Used in and . + + + + + Job Status. Used in . + + + + + Job tightening status. Used in . + + + + + Light commands. Used in and . + + + + + Error codes. Used in . + + + + + Motor rotations. Used in . + + + + + Operation Types. Used in . + + + + + Pairing handling types. Used in . + + + + + Pairing status. Used in . + + + + + Tool not mounted yet + + + + + Pairing allowed and started + + + + + Normal pairing sequence as OK + + + + + Normal pairing sequence as OK + + + + + Normal pairing sequence as OK + + + + + Normal pairing sequence as OK + + + + + Ongoing Pairing Aborted + + + + + Pairing not allowed. Program control. + + + + + Pairing attempt failed + + + + + Pairing never done before or disconnected + + + + + The overall status of all the tools in the tightening. + + + + + The station id is a unique id for each station. + + + + + The station name. + + + + + Additional information related to the Tightening Status + + + + + The VIN number for the tightening + + + + + Identifier 1 used for the tightening. + Could for example be a pallet number, identity of the operator, identification for the part, etc… + + + + + Identifier 2 used for the tightening. + Could for example be a pallet number, identity of the operator, identification for the part, etc… + + + + + Identifier 3 used for the tightening. + Could for example be a pallet number, identity of the operator, identification for the part, etc… + + + + + Identifier 4 used for the tightening. + Could for example be a pallet number, identity of the operator, identification for the part, etc… + + + + + Identifier 5 used for the tightening. + Could for example be a pallet number, identity of the operator, identification for the part, etc… + + + + + Identifier 6 used for the tightening. + Could for example be a pallet number, identity of the operator, identification for the part, etc… + + + + + Identifier 7 used for the tightening. + Could for example be a pallet number, identity of the operator, identification for the part, etc… + + + + + Identifier 8 used for the tightening. + Could for example be a pallet number, identity of the operator, identification for the part, etc… + + + + + Identifier 9 used for the tightening. + Could for example be a pallet number, identity of the operator, identification for the part, etc… + + + + + Identifier 10 used for the tightening. + Could for example be a pallet number, identity of the operator, identification for the part, etc… + + + + + Identifier for tightening 10 figures long. + + + + + Oldest result Id in a controller result database. 32 bit + + + + + Latest result Id in a controller result database. 32 bit + + + + + Oldest result Time in a controller result database. Unix time + + + + + Latest result Time in a controller result database. Unix time + + + + + System common. But content unique for each system. + + + + + This parameter gives the total number of tightenings in the batch. + Only used if this tightening was a part of a batch. + + + + + The number for this tightening in the batch. + Only used if this tightening was a part of a batch. + + + + + The current status of the batch. Only used if this tightening was a part of a batch. + + + + + The current status of the batch. + Only used if this tightening was a part of a batch. + + + + + The number or index of the tightening program or Pset that made the tightening + + + + + The name of the tightening program or Pset that made the tightening + + + + + The overall strategy used in the tightening program. + + + + + Date and time of last change in tightening program settings + + + + + The number of steps in the tightening program + + + + + Torque value from where the tightening cycle is considered as started. + + + + + Torque value for the limit at which the fastener shall be removed. + + + + + High limit for monitor Angle High Limit + + + + + Degree value for re-hit detection + + + + + Time after rundown done until result is sent, especially used when Multistage tightening is used + + + + + Time for slip off detection + + + + + When starting detection of End time. + + + + + Time out value in second before not finished Job is aborted. + + + + + Max number of coherent NOK results allowed + + + + + Speed in percent of tool max + + + + + Value in degrees for the interval of the first part of the rundown before snag + + + + + Acceleration factor in percent + + + + + Used strategies as a bit field. Measured value + + + + + The Id of a dynamic Pset + + + + + The name of a dynamic Pset + + + + + Device dependent tightening information. + See specific device specification and/or appendix + + + + + The name of the torque controller that made the tightening + + + + + The number of the torque controller that made the tightening. + + + + + The type name of the controller that made the tightening. + + + + + The article number of the torque controller that made the tightening. + + + + + The serial number of the torque controller that made the tightening. + + + + + The name of the bolt that was tightened + + + + + The number of the bolt that was tightened + + + + + The status of the bolt that was tightened + + + + + The total status of the tightening + + + + + Error codes from the tightening. Is defined by a bit field and sent as a hexadecimal value + i.e. Data Type will be set to H in the telegram. + The number of bits and their definition vary between the different systems. + + + + + The status of the Torque in the tightening + Based on the parameter 02001 + + + + + The status of the Angle in the tightening + Based on the parameter 02011 + + + + + The status of the Rundown monitoring in the tightening + Based on the parameter 02016-2018 + + + + + The status of the Current monitoring in the tightening + Based on the parameter 02020-02023 + + + + + The status of the Self tap monitoring in the tightening + Based on the parameter 02070-02071 + + + + + The status of the PVT monitoring in the tightening + Based on the parameter 02078 + + + + + The status of the PVT Comp monitoring in the tightening + Based on the parameter 02072-02073 + + + + + Additional information related to the Tightening Status + + + + + The primary error from the tightening. + The definition vary between the different systems + + + + + The number of the step that made the tightening NOK + + + + + ID of a Job + + + + + Job result sequence + + + + + Stage within an Job + + + + + The last time the Job configuration was changed + + + + + Id of a sync group or station. + + + + + Name of a sync group or station. + + + + + Status of a sync group or station + + + + + The Id of a result from an sync tightening + + + + + The time stamp of Job started + + + + + The Reference Mac address for Job result when cell is used + + + + + Identifier number of Job + + + + + Channel Id of Pset/Mset when cell is used + + + + + Time when the Job was ended or stopped + + + + + First NOK stage in Job + + + + + The target torque for the whole tightening program + + + + + The measured torque for the whole tightening. + + + + + The upper limit for the measured torque of the whole program. + + + + + The lower limit for the measured torque of the whole program. + + + + + The first target in a two step + + + + + Torque value where the tightening measurement starts after tightening start + + + + + Torque value where the tightening measurement starts before complete + + + + + The target angle for the whole tightening program + + + + + The measured angle for the whole tightening. + + + + + The upper limit for the measured angle, for the whole tightening + + + + + The lower limit for the measured angle, for the whole tightening + + + + + The torque value at which the angle measurement start at the cycle start + + + + + The torque value at which the angle measurement start at the cycle end + + + + + The max allowed angle value target measured according to parameter 2043 () + + + + + The min allowed angle value target measured according to parameter 2043 () + + + + + The max value of the angle to measure + + + + + The target current for the whole tightening program + + + + + The measured current for the whole tightening. + + + + + The upper limit for the measured current + + + + + The lower limit for the measured current + + + + + The measured torque for the whole tightening. Measured with a secondary torque transducer. + + + + + The upper limit for the measured torque 2nd. + + + + + The lower limit for the measured torque 2nd. + + + + + The measured angle for the whole tightening. Measured with a secondary angle transducer. + + + + + The upper limit for the measured angle 2nd + + + + + The lower limit for the measured angle 2nd + + + + + The target speed for the whole tightening program + + + + + The measured speed for the whole tightening program + + + + + The target speed for the each step + + + + + The time duration for the soft start in a tightening + + + + + The tightening speed during the soft start time duration either in ratio or percent of the tool max speed. + + + + + The tightening speed increase per time unit during the step. + + + + + Antinecking detection for angle control strategies. + + + + + At least 1 + + + + + The max tightening torque value for the self-tap measurement validation. + + + + + The min tightening torque value for the self-tap measurement validation. + + + + + The max tightening torque value for the prevail measurement validation. + + + + + The min tightening torque value for the prevail measurement validation. + + + + + Prevail on or off + + + + + Prevail Comp on or off + + + + + Angle value + + + + + At least 1 is required + + + + + Torque float value for the low limit in Torque trace + + + + + Torque float value for the high limit in Torque trace + + + + + The interval duration in degrees for self-tap measurements according to parameters 02070 () and 02071 () + + + + + Delay from cycle start to the start of Prevail Torque Monitor Interval + + + + + The interval duration in degrees for prevail measurements according to parameters 02072 () and 02073 () + + + + + Post View Torque in Angle trace + + + + + Post View Torque in Angle trace + + + + + Post View Torque in Angle trace + + + + + Post View Torque in Angle trace + + + + + Torque threshold for loosening detection + + + + + Speed according to parameter 02103 () + + + + + Ramp according to parameter 02103 () + + + + + The target force for the whole program + + + + + The measured force for the whole press. + + + + + The upper limit for the measured force, for the whole program + + + + + The lower limit for the measured force, for the whole program + + + + + The target stroke for the whole program + + + + + The measured stroke for the whole program. + + + + + The upper limit for the measured stroke, for the whole program + + + + + The lower limit for the measured stroke, for the whole program + + + + + User defined event text + + + + + The status for one stage torque of a four stage tightening. + + + + + Starting value in degrees for an four stage tightening + + + + + Max value for soft start torque in Nm during soft start + + + + + Min value in degrees for first target in an four stage tightening + + + + + Max value in degrees for first target in an four stage tightening + + + + + The measured torque for one stage of a four stage tightening + + + + + The measured angle for one stage of a four stage tightening + + + + + The status for one stage angle of a four stage tightening. + + + + + Gradient monitoring on or off + + + + + Torque Value in Nm + + + + + Torque Value in Nm + + + + + Angle value in degrees + + + + + Torque Value in Nm + + + + + Angle value in degrees + + + + + Torque Value in Nm + + + + + Angle value in degrees for one step + + + + + Angle value in degrees + + + + + In percent + + + + + Angle extra value for one step + + + + + Adjustable limit on or off + + + + + Value in Nm + + + + + Value in degrees + + + + + Value in torque Nm + + + + + Value in torque Nm + + + + + Value in degrees + + + + + Value in degrees + + + + + Value in degrees + + + + + Value in torque Nm + + + + + Value in torque Nm + + + + + Value in degrees + + + + + Min value in degrees for soft start angle in a four stage tightening + + + + + Max value in degrees for soft start angle in a four stage tightening + + + + + Min value in Nm for rundown torque in a four stage tightening + + + + + Max value in Nm for rundown torque in a four stage tightening + + + + + Min value in Nm for first torque in a four stage tightening + + + + + Max value in Nm for first torque in a four stage tightening + + + + + Min value for soft start torque in Nm during soft start + + + + + Total time to make the tightening [s] + + + + + Number of turns for rundown + + + + + Type of the trace curve + + + + + Coefficient to convert 2 byte binary data to real physical values. + Physical value = Binary value / Coefficient + + + + + Coefficient to convert 2 byte binary data to real physical values. + Physical value = Binary value * Coefficient + + + + + Number of samples for stage one at four stage tightening + + + + + Number of samples for stage two at four stage tightening + + + + + Number of samples for stage three at four stage tightening + + + + + Number of samples for stage four at four stage tightening + + + + + The target torque for the tightening program step + + + + + The measured torque for the tightening program step + + + + + The upper limit for the measured step torque. + + + + + The lower limit for the measured step torque. + + + + + The target angle for the tightening program step + + + + + The torque value there the angle measurement start + + + + + The measured angle for tightening program step + + + + + The upper limit for the measured step angle + + + + + The lower limit for the measured step angle + + + + + The target current for the tightening program step + + + + + The measured current for tightening program step + + + + + The upper limit for the measured step current + + + + + The lower limit for the measured step current + + + + + The target force for the tightening program step + + + + + The measured force for the tightening program step + + + + + The upper limit for the measured step force. + + + + + The lower limit for the measured step force. + + + + + The target stroke for the tightening program step + + + + + The force value there the stroke measurement start + + + + + The measured stroke for tightening program step + + + + + The upper limit for the measured step stroke + + + + + The lower limit for the measured step stroke + + + + + Calculated from the Time Stamp + + + + + Calculated from the Time Stamp + + + + + The measured shut off torque for the step + + + + + The measured torque rate for the step + + + + + The measured torque rate deviation for the step + + + + + The measured peak torque in angle window for the step + + + + + The measured low torque in angle window for the step + + + + + The measured post view torque high torque value for the step + + + + + The measured post view torque low torque value for the step + + + + + The measured yield point angle for the step + + + + + The measured prevailing torque for the step + + + + + The measured time for the step + + + + + Time needed to execute the step + + + + + The measured cross thread angle for the step + + + + + The measured angle at post view torque high + + + + + The measured angle at post view torque low + + + + + The type name of the tool that made the tightening. + + + + + The article number of the tool that made the tightening. + + + + + The serial number of the tool that made the tightening. + + + + + The index or number of the tool + + + + + The total number of tightenings made with the tool + + + + + The total number of tightenings made with the tool since last service + + + + + The total number of tightenings before the tool need to be serviced + + + + + To read out the different tool temperatures + + + + + To get the service interval + + + + + Post View Torque. Used in . + + + + + Power Macs status. Used in . + + + + + Primary tools. Used in and . + + + + + Relay Numbers. Used in , , and + + + + + Indicates that the connection to the Atlas Copco license server has been lost or the synchronization has failed. + The signal is cleared when the License manager synchronization has been done successfully + + + + + Tightening not disabled by external source + + + + + Tightening disabled by external source + + + + + Loosening not disabled by external source + + + + + Loosening disabled by external source + + + + + Multistep tightening program has ended, torque has fallen below Program end torque configured. + + + + + Oil level supervision configured in the tool maintenance to remind the users when it is time to fill up oil in a pulse tool. + + + + + Indicates high tightening time resulting in NOK tightening + + + + + Indicates low tightening time resulting in NOK tightening + + + + + Output signal tracking the function button state. The signal is set when the function button is pressed and is cleared when the function button is released. + + + + + Relay status. Used in . + + + + + Removal conditions. . + + + + + Reserved. Used in and . + + + + + Result types. Used in and . + + + + + Rotation directions. Used in and . + + + + + Status in work order. Used in . + + + + + Strategies. Used in and . + + + + + If no subtype exists it will be set to 000 + For a Power Focus 4000 and PF 6000 system the valid subtypes are: + 001 = a normal tightening system + For a Power MACS 4000 system the valid subtypes are: + + 001 = a normal tightening system + 002 = a system running presses instead of spindles. + + + + + + The system type of the controller. + Possible values are: + + 000 = System type not set + 001 = Power Focus 4000 + 002 = Power MACS 4000 + 003 = Power Focus 6000 + 004 = Micro Torque Focus 6000 + + + + + + Tightening Directions. Used in . + + + + + Tightening value status. Used in and . + + + + + Tool loosenings. Used in and . + + + + + Tool status. Used in . + + + + + Tool types. Used in . + + + + + Torque status. Used in . + + + + + Torque values unit. Used in and . + + + + + Represents a Mid header + + + + + Length of the header plus the data field excluding the NUL termination. + + + + + The MID describes how to interpret the message + + + + + The MID Revision is unique per MID and is used in case different versions are available for the same MID. + Using the revision number the integrator can subscribe or ask for different versions of the same MID. + + Note: The default MID Revision is 1. There is three different ways to get it, either send three spaces or 000 or 001. + + + + + + The MID Revision is unique per MID and is used in case different versions are available for the same MID. + Using the revision number the integrator can subscribe or ask for different versions of the same MID. + + Note: Enforces the default MID Revision to 1 when it's either send three spaces or 000 or 001. + + + + + + Define if subscriber will acknowledge each "push" message sent by controller (reliable mode) or just push without waiting for a receive acknowledgement from subscriber (unreliable mode) + Notes: + + Works only for subscription Mids + Not used when using sequence number handling + + + + + + The station the message is addressed to in the case of controller with multi-station configuration. + Note: Two spaces are considered as station 1 + + + + + The spindle the message is addressed to in the case several spindles are connected to the same controller. + Note: Two spaces are considered as spindle 1 + + + + + For acknowledging on "Link Level" with MIDs 0997 and 0998. + Note: Not used if space or zero + + + + + Linking function can be 1 to 9 (possible to send 9*9999 bytes messages). + Used when the message length is overflowing the max length of 9999. + Note: Not used if space or zero. + + + + + Linking function, can be 1 to 9 at message length > 9999. + Note: Not used if space or zero + + + + + Contract of every message that can be accepted with implements. + + + + + Contract which every acknowledge message implements. + + + + + Contract which every that might needs an acknowledge response implements. + + + + + Contract of every message that can be answered by another mid which is not classified as an acknowledge. + + + + + Contract which every controller message implements. + + + + + Contract which every message that can be declined with implements. + + + + + Contract which every integrator message implements. + + + + + Represents a single Digital Input. + + + + + IO interface message category. Every IO interface mid must implement . + + + + + Template for implementers. + + + + + Set externally controlled relays + + By using this message the integrator can control 10 relays (externally control relays). The station can + set, reset the relays or make them flashing. + + Message sent by: Integrator + Answer: Command accepted + + + + + Status externally monitored inputs subscribe + + By using this message the integrator can set a subscription to monitor the status + for the eight externally monitored digital inputs. After the subscription the station + will directly receive a status message and then every time the status of at least one of + the inputs has changed. + + Message sent by: Integrator + + Answer: Command accepted or + Command error, Status externally monitored inputs subscription already exists or + Status externally monitored inputs. + + + + + + Status externally monitored inputs + + Status for the eight externally monitored digital inputs. This message is sent to the subscriber every + time the status of at least one of the inputs has changed. + + Message sent by: Controller + Answer: Status externally monitored inputs acknowledge + + + + + Status externally monitored inputs acknowledge + Acknowledgement for the message status externally monitored inputs upload. + Message sent by: Integrator + Answer: None + + + + + Status externally monitored inputs unsubscribe + Unsubscribe for the Status externally monitored inputs. + Message sent by: Integrator + + Answer: Command accepted or Command error, + Status externally monitored inputs subscription does not exist + + + + + + IO device status request + + Request for the status of the relays and digital inputs at a device, e.g. an I/O expander. + The device is specified by a device number. + + Message sent by: Integrator + + Answer: IO device status or + Command error, Faulty IO device ID, or IO device not connected + + + + + + IO device status reply + + This message is sent as an answer to the IO device status request. + revision 1 should only be used to get the status of IO devices with max 8 relays/digital + inputs. + For external I/O devices each list contain up to 8 relays/digital inputs. For the internal device the lists + contain up to 4 relays/digital inputs and the remaining 4 will be empty. + revision 2 can be used to get the status of all types of IO devices with up to 48 relays/digital + inputs. + + Message sent by: Controller + Answer: None + + + + + Relay function subscribe + + Subscribe for one single relay function. The data field consists of three ASCII digits, the relay number, + which corresponds to the specific relay function.The relay numbers can be found in Table 101 above. + At a subscription of a tracking event, Relay function immediately returns the current relay + status to the subscriber. + can only subscribe for one single relay function at a time, but still, Open Protocol supports + keeping several relay function subscriptions simultaneously. + + Message sent by: Integrator + Answer: Command accepted or Command error, The relay function subscription already exists + + + + + Relay function + + Upload of one specific relay function status, see Table 101. + For tracking event functions, Relay function, is sent each time the relay status is changed. For + relay functions which are not tracking events, the upload is sent only when the relay is set high, i.e. the + data field “Relay function status” will always be 1 for such functions. + + Message sent by: Controller + Answer: Relay function acknowledge + + + + + Relay function acknowledge + Acknowledgement of relay function upload. + Message sent by: Integrator + Answer: None + + + + + Relay function unsubscribe + + Unsubscribe for a single relay function. The data field consists of three ASCII digits, + the relay number, which corresponds to the specific relay function. The relay numbers can be + found in Table 101. + + Message sent by: Integrator + Answer: Command accepted or Command error, The relay function subscription does not exist + + + + + Digital input function subscribe + + Subscribe for one single digital input function. The data field consists of three ASCII digits, + the digital input function number. The digital input function numbers can be found in Table 80 above. + At a subscription of a tracking event, Digital input function upload immediately returns the + current digital input function status to the subscriber. + + + can only subscribe for one single digital input function at a time, + but still, Open Protocol supports keeping several digital input function subscriptions simultaneously. + + Message sent by: Integrator + Answer: Command accepted or Command error, The digital input function subscription already exists + + + + + Digital input function + + Upload of one specific digital input function status. See Table 80. + For tracking event functions, Digital input function, is sent each time the digital input + function’s status (state) is changed. For digital input functions which are not tracking events, the + upload is sent only when the digital input function is set high, + i.e. the data field “Digital input function status” will always be 1 for such functions. + + Message sent by: Controller + Answer: Digital input function upload acknowledge + + + + + Digital input function acknowledge + Acknowledgement of the digital input function upload. + Message sent by: Integrator + Answer: None + + + + + Relay function unsubscribe + + Unsubscribe for a single relay function. The data field consists of three ASCII digits, + the relay number, which corresponds to the specific relay function. The relay numbers can be + found in Table 101. + + Message sent by: Integrator + Answer: Command accepted or Command error, The relay function subscription does not exist + + + + + Set digital input function + + Set the digital input function with the digital input number. + The digital input function numbers are defined in Table 80. + + Message sent by: Integrator + Answer: Command accepted or Command error, Invalid data + + + + + Reset digital input function + + Reset the digital input function with the digital input number. + The digital input function numbers are defined in Table 80. + + + This MID will only affect the digital input functions of tracking type. + The digital input functions with the type flank cannot be reset (for example reset the reset + batch digital input function will have no effect). + + Message sent by: Integrator + Answer: Command accepted or Command error, Invalid data + + + + + Represents a single Relay + + + + + Contract which every subscription message implements. + + + + + Contract which every unsubscription message implements. + + + + + Represents a advanced job entity + + + + + Template for implementers. + + + + + Advanced job message category. Every Advanced job mid must implement . + + + + + Job line control info subscribe + + A subscription for the Job line control information. + A message is sent to the integrator when the Job line control is started, for alert level 1, + for alert level 2, or when the Job is finished before the alert level 2 (Job line control done). + + Message sent by: Integrator + Answer: or Command error, Job line control info subscription already exists + + + + + Job line control started + This message tells the integrator that Job Line control start has been set in the controller. + Message sent by: Controller + Answer: Job line control info acknowledged + + + + + Job line control alert 1 + + This message tells the integrator that, for example, + a car has reached 80% of the station and that the + Job line control alert 1 is set in the controller. + + + Only available when a job has been selected. + + Message sent by: Controller + Answer: Job line control info acknowledged + + + + + Job line control alert 2 + This message tells the integrator that the Job line control alert 2 is set in the controller. + Only available when a job has been selected. + Message sent by: Controller + Answer: Job line control info acknowledged + + + + + Job line control done + This message tells the integrator that the Job has been completed before the alert level 2 was reached. + Message sent by: Controller + Answer: Job line control info acknowledged + + + + + Job line control info acknowledge + Acknowledgement of Job line control info messages , , , and . + Message sent by: Integrator + Answer: None + + + + + Job line control info unsubscribe + Unsubscribe for the Job line control info messages. + Message sent by: Integrator + Answer: Command accepted or Command error, Job line control info subscription does not exist + + + + + Abort Job + Abort the current running job if there is one. + Message sent by: Integrator + Answer: Command accepted + + + + + Job batch increment + Increment the Job batch if there is a current running Job. + Message sent by: Integrator + Answer: Command accepted + + + + + Job batch increment + + Decrement the Job batch if there is a current running Job. + Two revisions are available for this MID. + The default revision or revision 1 does not contain any argument and always decrement the last + tightening completed in a Job. + + The revision 2 contains two parameters; the channel ID and parameter set ID to be decremented. + The MID is always sent to the cell master/reference. + Message sent by: Integrator + Answer: Command accepted or Command error, Job batch decrement failed (only for MID revision 2) + + + + + Job off + Set the controller in Job off mode or reset the Job off mode. + Message sent by: Integrator + Answer: Command accepted + + + + + False => Set Job Off + True => Reset Job Off + + + + + Set Job line control start + The integrator can set the line control start in the controller with this message. + Message sent by: Integrator + Answer: Command accepted + + + + + Set Job line alert 1 + The integrator can set the line control alert 1 in the controller with this message. + Message sent by: Integrator + Answer: Command accepted + + + + + Set Job line alert 2 + The integrator can set the line control alert 2 in the controller with this message. + Message sent by: Integrator + Answer: Command accepted + + + + + Execute dynamic Job request + + The integrator requests a dynamical Job to be executed i.e. the Job sent from the integrator is + immediately executed(if possible) by the controller but not saved in the memory.A dynamical Job + lifetime is the time for the Job to be executed.If the controller is powered off before the completion of + the Job, the dynamical Job is lost. + + Do note the limitation when sending this message on a serial connection due to the size of the read buffer (256 bytes) in the controller. + In such case the number of programs in the Job list is limited. + Message sent by: Integrator + Answer: Command accepted + + + + + Job message category. Every job mid must implement . + + + + + Template for implementers. + + + + + Job ID upload request + + This is a request for a transmission of all the valid Job IDs of the controller. + The result of this command is a transmission of all the valid Job IDs. + + Message sent by: Integrator + Answer: Job ID upload reply + + + + + Job ID upload reply + + The transmission of all the valid Job IDs of the controller. + The data field contains the number of valid Jobs currently present in the controller, and the ID of each Job. + + Message sent by: Controller + Answer: None + + + + + Job data upload request + Request to upload the data for a specific Job from the controller. + Message sent by: Integrator + Answer: Job data upload or Command error, Job ID not present + + + + + Job data upload reply + This message is sent as a reply to the Job data request. + Message sent by: Controller + Answer: None + + + + + Job Info Subscribe + + A subscription for the Job info. Job info is sent to the integrator when a new Job is selected and after + each tightening performed during the Job. + + Message sent by: Integrator + Answer: Command Accepted or Command error, Job info subscription already exists + + + + + Revision 1 to 4 Constructor + + False=Ack needed, True=No Ack needed + Revision number (default = 4) + + + + Job info + The Job info subscriber will receive a Job info message after a Job has been selected and after each + tightening performed in the Job.The Job info consists of the ID of the currently running Job, the Job + status, the Job batch mode, the Job batch size and the Job batch counter. + Message sent by: Controller + Answer: + + + + + Job info acknowledge + Acknowledgement of a Job info message. + Message sent by: Integrator + Answer: None + + + + + Job info unsubscribe + Reset the subscription for a Job info message. + Message sent by: Integrator + Answer: Command accepted or Command error, Job info subscription does not exist + + + + + Select Job + Message to select Job. If the requested ID is not present in the controller, then the command will not be performed. + Message sent by: Integrator + Answer: Command accepted or Command error, Job can not be set, or Invalid data + + + + + Job restart + Job restart message. + Message sent by: Integrator + Answer: Command accepted or Command error, Job not running, or Invalid data + + + + + Parameter set entity. + + + + + Keep alive message + + The integrator sends a keep alive to the controller. The controller should only mirror and return the + received keep alive to the integrator. + + + The controller has a communication timeout equal to 15s. This means that if no message has been + exchanged between the integrator and the controller for the last 15s, then the controller considers + the connection lost and closes it; + + + In order to keep the communication alive the integrator must send a keep alive to the controller with a + time interval lower than 15s. + + + Note: An inactivity timeout is suggested to integrator i.e. if no message has been exchanged (sent or + received) during the last 10s, send a keep alive. + + Message sent by: Integrator + Answer: The same message () mirrored by the controller. + + + + + Communication acknowledge + This message is used in conjunction with the use of header sequence number. + Message sent by: Controller and Integrator: + + Is sent immediately after the message is received on application link level and if the check of the + header is found to be ok. + + + The acknowledge substitute the use of NoAck flag and all subscription data special acknowledging. + + + + + + Communication acknowledge error + This message is used in conjunction with the use of header sequence number. + Message sent by: Controller and Integrator: + + This message is sent immediately after the message is received on application link level and if the check of the header is found to be wrong in any way. + The acknowledge substitute the use of NoAck flag and all subscription data special acknowledging. + + + The acknowledge substitute the use of NoAck flag and all subscription data special acknowledging. + + + + + + Abstract class which every Mid should inherit, containing all of default data, such as data and methods. + + + + + Mid Extensions functions + + + + + then concatenate NUL charactor to it`s end + + Mid instance + Mid's package in string with NUL character + + + + then concatenate NUL charactor to it`s end + + Mid instance + Mid's package in bytes with NUL character + + + + Generates reply instance accordingly with a received mid. + + type of corresponding acknowledge + instance implementing IAcknowledgeable + A new instance of TMid type + + + + Generates reply instance accordingly with a received mid. + + type that is the answer to respective Mid + A new instance + + + + Generates reply instance accordingly with a received mid. + + type that is the answer to respective Mid + Desired reply revision + A new instance + + + + Generates a Communication positive acknowledge mid () instance for the accepted mid. + + instance and implementer + + A new instance + + + + Generates a Communication Negative Acknowledge mid () instance for the failed mid and with the informed error code. + + instance and implementer + Current failed mid + error code + A new instance + + + + Assert that error code is a possible error for the current failed mid and generates a Communication Negative Acknowledge mid () + instance for the failed mid and with the informed error code. + + instance and implementer + Current failed mid + error code + A new instance + Throws if error is not a possible error for the current failed Mid + + + + Responsible for building and parsing any incoming Mid. + Message templates initialization must be done with methods. + + + + + Mid Interpreter initialization functions + + + + + Configure MidInterpreter to parse all available Mids of a mode + Select Integrator if you're integrator or Controller if you're a controller + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Configure MidInterpreter to parse all specified Mids in IEnumerable + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add custom MIDs that are not specified in Open Protocol documentation. + Might be used for weird controllers + + MidInterpreter instance + Dictionary with Mid x your custom type + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Include MIDs into interpreter + + MidInterpreter instance + Are you the integrator or controller? + MidInterpreter instance + + + + Include only a specific collection of MIDs into interpreter + + MidInterpreter instance + Mids that you want to be available for parsing + MidInterpreter instance + + + + Add all if not added yet and override specified Mids + + MidInterpreter instance + Dictionary with Mid x your custom type to override + MidInterpreter instance + + + + Motor tuning message category. Every motor tuning mid must implement . + + + + + Motor tuning result data subscribe + + Sets the subscription for the motor tuning result. + The result of this command will be the transmission of the motor + tuning result after the motor tuning is performed. The MID revision in + the header is used to subscribe to different revisions of MID 0501 Motor + tuning result data upload reply. + + Message sent by: Integrator + Answer: Command error, Motor Tuning subscription already exists or MID revision not supported + + + + + Motor tuning result data + Upload the last motor tuning result. + Message sent by: Controller + Answer: Motor tuning result data acknowledge + + + + + Motor Tune Failed = false (0) + Motor Tune Success = true (1) + + + + + Motor tuning result data acknowledge + Acknowledgement of motor tuning result data. + Message sent by: Integrator + Answer: None + + + + + Motor tuning result data unsubscribe + Reset the motor tuning result subscription. + Message sent by: Integrator + Answer: Command accepted or Command error, Motor Tuning result subscription does not exist + + + + + Motor tuning request + Request the start of the motor tuning. + Warning!: This command must be implemented during hard restrictions and customer dependent requirements. + Message sent by: Integrator + Answer: Command accepted or Command error, Tool motor tuning failed + + + + + Template for implementers. + + + + + Represents an Identifier Status entity + + + + + Multiple identifier message category. Every multiple identifier mid must implement . + + + + + Identifier download request + Used by the integrator to send an identifier to the controller. + Message sent by: Integrator + Answer: Command accepted or Command error, Identifier input source not granted + + + + + Multiple identifier and result parts subscribe + + This message is used by the integrator to set a subscription for the work order status, optional + identifiers and result parts extracted from the identifiers received and accepted by the controller. + + + The identifiers may have been received by the controller from one + or several input sources (Serial, Ethernet, Field bus, ST scanner etc.). + + Message sent by: Integrator + Answer: Command accepted or + Command error, Multiple identifier and result parts subscription already exists + + + + + + Multiple identifier and result parts + + Transmission of the work order status, optional identifier and identifier result parts + by the controller to the subscriber. + + + The identifier contains the status of the maximum four identifier result parts that could + be extracted from one or more valid identifiers. + + Message sent by: Controller + Answer: Multiple identifiers and result parts acknowledge + + + + + Multiple identifiers and result parts acknowledge + Acknowledgement of multiple identifiers and result parts upload. + Message sent by: Integrator + Answer: None + + + + + Multiple identifier and result parts unsubscribe + Reset the subscription for the multiple identifiers and result parts. + Message sent by: Integrator + + Answer: Command accepted or + Command error, Multiple identifiers and result parts subscription does not exist + + + + + + Bypass Identifier + This message is used by the integrator to bypass the next identifier expected in the work order. + Message sent by: Integrator + Answer: Command accepted + + + + + Reset latest Identifier + + This message is used by the integrator to reset the latest identifier + or bypassed identifier in the work order. + + Message sent by: Integrator + Answer: Command accepted + + + + + Reset all Identifiers + This message is used by the integrator to reset all identifiers in the current work order. + Message sent by: Integrator + Answer: Command accepted + + + + + Template for implementers. + + + + + Multiple spindle message category. Every multiple spindle mid must implement . + + + + + Multi-spindle status subscribe + A subscription for the multi-spindle status. For Power Focus, the subscription must be addressed to the sync Master. + Message sent by: Integrator + + Answer: Command accepted or + Command error, Controller is not a sync master/station controller, + or Multi-spindle status subscription already exists + + + + + + Multi-spindle status + + The multi-spindle status is sent after each sync tightening. The multiple status contains the common + status of the multiple as well as the individual status of each spindle. + + Message sent by: Controller + Answer: Multi-spindle status acknowledge + + + + + Multi-spindle status acknowledge + Message sent by: Integrator + Answer : None + + + + + Multi-spindle status unsubscribe + Reset the subscription for the multi-spindle status. + Message sent by: Integrator + + Answer: Command accepted or + Command error, Multi-spindle status subscription does not exist + + + + + + Multi-spindle result subscribe + + A subscription for the multi-spindle status. For Power Focus, the subscription must + be addressed to a sync Master. + + + This telegram is also used for a PowerMACS 4000 system + running a press instead of a spindle. A press system only supports revision 4 and higher + of the telegram and will answer with , MID revision unsupported if a subscription + is made with a lower revision. + + Message sent by: Integrator + + Answer: Command accepted or + Command error, Controller is not a sync master/station controller, + Multi-spindle result subscription already exists or MID revision unsupported + + + + + + Multi-spindle result + + The multi-spindle result is sent after each sync tightening and if it is subscribed. The multiple results + contain the common status of the multiple as well as the individual tightening result(torque and angle) + of each spindle. + + + This telegram is also used for PowerMACS systems running a Press.The layout of the telegram is + exactly the same but some of the fields have slightly different definitions.The fields for Torque are + used for Force values and the fields for Angle are used for Stroke values. A press system always uses + revision 4 or higher of the telegram. + + Message sent by: Controller + Answer: Multi-spindle result acknowledge + + + + + Multi-spindle result acknowledge + Message sent by: Integrator + Answer: None + + + + + Multi-spindle result unsubscribe + Reset the subscription for the multi spindle result. + Message sent by: Integrator + + Answer: Command accepted or + Command error, Multi spindle result subscription does not exist + + + + + + Old Multi spindle result request + Request for an old multi spindle result. + Note: MID 0104 can’t be used if there is an active subscription for multiple spindle results. + Message sent by: Integrator + + Answer: Command accepted or + Command error, Multi spindle result subscription already exists + + + + + + Template for implementers. + + + + + Represents a Spindle or a Press status entity, depending on + + + + + Represents a Spindle Status entity + + + + + Open protocol commands disabled category. Every open protocol command disabled mid must implement . + + + + + Open Protocol commands disabled subscribe + + Set the subscription for the Open Protocol commands disable digital input. This command will result in + transmission of the Open Protocol commands disable input status.When a subscription is set the Open + Protocol commands disable digital input status is once uploaded() automatically.Thereafter, + the status is uploaded each time the digital input status changes(push function). + + Message sent by: Integrator + Answer: Command accepted or + Command error, Open Protocol commands disabled + subscription already exists + + + + + + Open Protocol commands disabled + + Upload the status of the Open Protocol commands disable digital input. + The data upload consists of one byte delivering the digital input status. + The status is uploaded each time the “Open Protocol commands disable” digital + input changes (push function). + + Message sent by: Controller + Answer: Open Protocol commands disabled acknowledge + + + + + Open Protocol commands disabled acknowledge + Acknowledgement of Open Protocol commands disabled upload. + Message sent by: Integrator + Answer: None + + + + + Open Protocol commands disabled unsubscribe + Reset the subscription for the Open Protocol commands disabled digital input. + Message sent by: Integrator + + Answer: Command accepted or + Command error, Open Protocol commands disabled + subscription does not exist + + + + + + Template for implementers. + + + + + Parameter set message category. Every parameter set mid must implement . + + + + + Parameter set ID upload request + A request to get the valid parameter set IDs from the controller. + Message sent by: Integrator + Answer: Parameter set ID upload reply + + + + + Parameter set ID upload reply + + The transmission of all the valid parameter set IDs of the controller. In the revision 000-001 the data + field contains the number of valid parameter sets currently present in the controller, and the ID of each + parameter set present.In revision 2 is the number of stages on each Pset/Mset added. + + Message sent by: Controller + Answer: None + + + + + Parameter set data upload request + Request to upload parameter set data from the controller. + Message sent by: Integrator + + Answer: Parameter set data upload reply, or + Command error, Parameter set not present + + + + + + Parameter set data upload reply + Upload of parameter set data reply. + Message sent by: Controller + Answer: None + + + + + Parameter set selected subscribe + + A subscription for the parameter set selection. Each time a new parameter set is selected the + Parameter set selected is sent to the integrator. + + + Note that the immediate response is Command + accepted and Parameter set selected with the current parameter set number selected. + + Message sent by: Integrator + Answer: Command accepted and Parameter set selected + + + + + Revision 1 Constructor + + False=Ack needed, True=No Ack needed + + + + Parameter set selected + + A new parameter set is selected in the controller. + The message includes the ID of the parameter set selected as well as the date and time of the + last change in the parameter set settings. This message is also sent as an immediate response to + Parameter set selected subscribe. + + Message sent by: Controller + Answer: New parameter set selected acknowledge + + + + + Constructor + + Range: 000-002 + + + + Parameter set selected acknowledge + Acknowledgement for a new parameter set selected. + Message sent by: Integrator + Answer: None + + + + + Parameter set selected unsubscribe + Reset the subscription for the parameter set selection. + Message sent by: Integrator + + Answer: Command accepted or + Command error, Parameter set subscription does not exist + + + + + + Select Parameter set + Message sent by: Integrator + + Answer: Command accepted or + Command error, Parameter set can not be set + + + + + + Set Parameter set batch size + This message gives the possibility to set the batch size of a parameter set at run time. + Message sent by: Integrator + + Answer: Command accepted or + Command error, Invalid data + + + + + + Reset Parameter set batch counter + This message gives the possibility to reset the batch counter of the running parameter set, at run time. + Message sent by: Integrator + + Answer: Command accepted or + Command error, Invalid data, or Parameter set not running + + + + + + Lock at batch done subscribe + A subscription for the Lock at batch done relay status. + Message sent by: Integrator + + Answer: Command accepted or + Command error + + Message: relay status immediately after Command accepted + + + + + Lock at batch done upload + This message gives the relay status for Lock at batch done. + Message sent by: Controller + Answer: Lock at batch done upload Ack + + + + + Lock at batch done upload Acknowledge + This message is an acknowledge to . + Message sent by: Integrator + Answer: Command accepted + + + + + Lock at batch done unsubscribe + Reset the subscription for Lock at batch done. + Message sent by: Integrator + + Answer: Command accepted or + Command error + + + + + + MID: Tightening Program Message download + Description: + Reset the subscription for Lock at batch done. + Message sent by: Integrator + Answer: MID 0005 Command accepted or MID 0004 Command error + + + + + MID: Tightening Program Message Upload + Description: + Reset the subscription for Lock at batch done. + Message sent by: Integrator + Answer: MID 0005 Command accepted or MID 0004 Command error + + + + + Select Parameter set, Dynamic Job Included + Message sent by: Integrator + + Answer: Command accepted or + Command error, Dynamic Job cannot be created, non-existing pset + + + + + + Select Parameter set dynamically. + Message sent by: Integrator + + Answer: Command accepted or + Command error, Dynamic Pset cannot be created, non-existing pset + + + A dynamic pset is created from a preexisting Pset in the Controller and selected for tightenings. + The message can substitute Pset selection, Set Identifier, Reset All Identifier, Reset Latest Identifier, Set Batch Size, Disable Tool and Enable Tool. + + + + + + Tightening Program Delete + Message sent by: Integrator + + Answer: Command accepted or + Command error + + This message deletes one or all programs in controller. + Note: If a running program is included in MID 2506 deletion the program shall finish before deletion. + Note: Deleting programs included in other nodes may give unwanted behaviour. It will behave identical to a manual delete of the program. + + + + + Template for implementers. + + + + + PLC user data message category. Every PLC user data mid must implement . + + + + + User data download + Used by the integrator to send user data input to the PLC. + Message sent by: Integrator + + Answer: Command accepted or + Command error, Invalid data, or Controller is not a sync master/station controller + + + + + + User data subscribe + + Subscribe for user data. This command will activate the User data message to be sent when a + change in the user data output has been detected. + + Message sent by: Integrator + + Answer: Command accepted or + Command error, Subscription already exists, or + Controller is not a sync master/station controller + + + + + + User data download + Used by the integrator to send user data input to the PLC. + Message sent by: Controller + Answer: User data acknowledge + + + + + User data acknowledge + Acknowledgement of user data. + Message sent by: Integrator + Answer: None + + + + + User data unsubscribe + Unsubscribe for the user data. + Message sent by: Integrator + + Answer: Command accepted or + Command error, Subscription already exists + + + + + + User data download with offset + + Used by the integrator to send user data input to the PLC. + The difference compared to User data download is that with this MID it is possible + to specify an offset for the data written in the PLC. This makes it possible to have more than + one device writing user data to the PLC on different data areas. + + + The available address range in the PLC is still 13 000 – 13 099, i.e. 100 bytes. The offset parameter in + this MID specify the start address for the data in the PLC, i.e.the start address is 13 000 + Offset. + Since the highest address is still 13 099 this means the number of data bytes to send will be limited by + the offset. The maximum size of the user data will be (100 – offset) bytes, or 2 * (100 – offset) ASCII + characters in the telegram. + + + Only data that is sent in the user data field will be written to the PLC, the remaining data will + be untouched. + + + This means for example that if the offset is 10 and the user data is 1234 the bytes with + address 13010 and 13011 will be updated (to 0x12 and 0x34) and the rest of the area will be + unchanged. + + Message sent by: Integrator + + Answer: Command accepted or + Command error, Invalid data, or + Controller is not a sync master/station controller or + MID revision not supported. + + + + + + Template for implementers. + + + + + Represents a Bolt entity + + + + + Represents a Bolt Result entity + + + + + PowerMACs message category. Every PowerMACs mid must implement . + + + + + Last PowerMACS tightening result data subscribe + + Set the subscription for the rundowns result. The result of this command will be the transmission of + the rundown result after the tightening is performed(push function). + + + This telegram is also used for a PowerMACS 4000 system running a press instead of a spindle.A + press system only supports revision 4 and higher of the telegram and will answer with , + MID revision unsupported if a subscription is made with a lower revision. + + Message sent by: Integrator + + Answer: Command accepted or + Command error, Subscription already exists or MID revision unsupported + + + + + + Last PowerMACS tightening result Station data + + This MID contains the station part and some of the Bolt data of the last result data. After this message + has been sent the integrator selects if it also wants to have the Bolt and step data.If this data is + requested, then the integrator sends the message Last PowerMACS tightening result data + acknowledge, with the parameter Bolt Data set to TRUE. If only the station data is wanted the + parameter Bolt Data is set to FALSE. + + + This telegram is also used for Power MACS systems running a Press. The layout of the telegram is + exactly the same but some of the fields have slightly different definitions. The fields for Torque are + used for Force values and the fields for Angle are used for Stroke values. Press systems also use + different identifiers for the optional data on bolt and step level. A press system always use revision 4 + or higher of the telegram + + + Note: All values that are undefined in the results will be sent as all spaces (ASCII 0x20). This will for + instance happen with the Torque Status if no measuring value for Bolt T was available for the + tightening. + + Message sent by: Controller + Answer: Last Power MACS tightening result data acknowledge + + + + + Last Power MACS tightening result Bolt data + + This message contains the cycle data for one Bolt, both Bolt data and step data. It is only sent if + the acknowledgement of the message Last PowerMACS tightening result station data had the parameter + Bolt Data set to TRUE. The next Bolt data is sent if the acknowledgement has the parameter Bolt Data set to TRUE. + This telegram is also used for Power MACS systems running a Press.The layout of the telegram is exactly the + same but some of the fields have slightly different definitions. The fields for Torque are used for Force values + and the fields for Angle are used for Stroke values. Press systems also use different identifiers for the optional + data on bolt and step level. Press systems always use revision 4 or higher of the telegram.Values in the fixed part + that are undefined in the results will be sent as all spaces (ASCII 0x20). + + + This can happen with the Customer Error Code if this function is not activated. + + + Note 2: The Bolt results and step results are only sent when the value exists in the result. This means, + for example, that if no high limit is programmed for Peak T, then the value Peak T + will not be sent + even if limits for Peak T are defined in the reporter. + + Message sent by: Controller + Answer: Last PowerMACS tightening result data acknowledge + + + + + Last Power MACS tightening result data acknowledge + + If Bolt Data is set to TRUE the next telegram with Bolt data is sent (if there are any left for this + tightening). Otherwise no more Bolt data is sent for this tightening. + + + If only the station data is wanted Bolt Data must be set to FALSE in the acknowledgement of + Last Power MACS tightening result Station data. + + Message sent by: Integrator + Answer: None + + + + + Last Power MACS tightening result data unsubscribe + Reset the last Power MACS tightening result subscription for the rundowns result. + Message sent by: Integrator + + Answer: Command accepted or + Command error, Subscription does not exist + + + + + + Template for implementers. + + + + + Represents a Special Value entity + + + + + Represents a Step Result entity + + + + + Result message category. Every result mid must implement . + + + + + Operation result Overall data + + This MID contains the overall result data and some of the object data of the last tightening. + In the subscription of this message it can be chosen to also start subscription of Operation result object data. + The user defined values is preconfigured in the controller via the configuration tool. + + Message sent by: Controller + + Answer: Operation result data acknowledge or + with in the data field. + + If the sequence number acknowledge functionality is used there is no need for these acknowledges. + + + + + Operation result object data + + This message contains the cycle data for one object, both data for the whole process and data related to + the different steps in the process.The user defined values are preconfigured in the controller via the + configuration tool. The message uses the Variable Parameter pattern for transmission of the values. + + + Note: Only values that exist in the result will be sent.So the actual data received may vary between + the cycles if the settings differ between different programs. + + Message sent by: Controller + + Answer: Operation result data acknowledge or + with in the data field. + + + If the sequence number acknowledge functionality is used there is no need for these acknowledges. + + + + + Operation result data acknowledge + Message sent by: Integrator + Answer: None + + + + + Represents an Object Data entity + + + + + Template for implementers. + + + + + Statistic message category. Every statistic mid must implement . + + + + + Histogram upload request + + Request to upload a histogram from the controller for a certain parameter set. + The histogram is calculated with all the tightening results currently present in + the controller’s memory and within the statistic acceptance window(statistic min and max limits) + for the requested parameter set. + + Message sent by: Integrator + + Answer: Histogram upload reply, or + Command error, No histogram available or Invalid data + + + + + + Histogram upload reply + + Histogram upload reply for the requested parameter set and for the requested histogram type. The + histogram uploaded is made of 9 bars according to Figure 22 Histogram example. + + Message sent by: Controller + Answer: None + + + + + X-BAR + + + + + Template for implementers. + + + + + Tightening message category. Every tightening mid must implement . + + + + + Last tightening result data subscribe + + Set the subscription for the result tightenings. The result of this command will be the transmission of + the tightening result after the tightening is performed(push function). The MID revision in the header + is used to subscribe to different revisions of Last tightening result data upload reply. + + Message sent by: Integrator + + Answer: Command accepted or + Command error, Last tightening subscription already exists or MID revision not supported + + + + + + Last tightening result data + Upload the last tightening result. + Message sent by: Controller + Answer: Last tightening result data acknowledge + + + + + Obtain which revision we will work with for shared properties + (since rev 1, 2 and 999 are way too different, they are processed in different datafields) + + Datafield Revision Index + + + + Last tightening result data acknowledge + Acknowledgement of last tightening result data. + Message sent by: Integrator + Answer: None + + + + + Last tightening result data unsubscribe + Reset the last tightening result subscription. + Message sent by: Integrator + + Answer: Command accepted or + Command error, Last tightening result subscription does not exist + + + + + + Old tightening result upload request + + This message is a request to upload a particular tightening result from the controller. The requested + result is specified by its unique ID(tightening ID). This message is useful after a failure of the + network in order to retrieve the missing result during the communication interruption.The integrator + can see the missing results by always comparing the last tightening IDs of the two last received + tightenings packets (parameter 23 in the result message). + + + Requesting tightening ID zero is the same as requesting the latest tightening performed. + + Message sent by: Integrator + + Answer: Old tightening result upload reply or + Command error, Tightening ID requested not found, or + MID revision not supported + + + + + + Old tightening result upload reply + Message sent by: Controller + Answer: None + + + + + Number of offline results + Number of results when offline + Message sent by: Controller + Answer: None + + + + + Tightening Result DB Info Upload + This message contains information concerning the tightening result database on the controller. + Application Data Message Request shall be used for fetching this message + Message sent by: Controller + Answer: None + + + + + Represents a Stage Result entity + + + + + Represents a Strategy Options entity + + + + + Represents a Tightening Error Status entity + + + + + Template for implementers. + + + + + Time message category. Every time mid must implement . + + + + + Read time upload request + Message sent by: Integrator + Answer: Read time upload reply + + + + + Read time upload reply + Time upload reply from the controller. + Message sent by: Controller + Answer: None + + + + + Set Time + Set the time in the controller. + Message sent by: Integrator + Answer: None + + + + + Template for implementers. + + + + + Tool message category. Every tool mid must implement . + + + + + Tool data upload request + + A request for some of the data stored in the tool. The result of this command + is the transmission of the tool data. + + Message sent by: Integrator + Answer: Tool data upload reply + + + + + Tool data upload reply + Upload of tool data from the controller. + Message sent by: Controller + Answer: None + + + + + Disable tool + Message sent by: Integrator + Answer: Command accepted + + + + + Enable tool + Message sent by: Integrator + Answer: Command accepted + + + + + Disconnect tool request + + This command is sent by the integrator in order to request the possibility to disconnect the tool from + the controller.The command is rejected if the tool is currently used. + + + When the command is accepted the operator can disconnect the tool and replace it (hot swap). + + Message sent by: Integrator + + Answer: Command accepted or + Command error, Tool currently in use + + + + + + Set calibration value request + + This message is sent by the integrator in order to set the calibration value of the tool. + + Message sent by: Integrator + + Answer: Command accepted or + Command error, Calibration failed + + + + + + Set primary tool request + This message is sent by the integrator in order to set tool data. + Warning 1: this MID requires programming control (see 4.4 Programming control). + Warning 2: the new configuration will not be active until the next controller reboot! + Message sent by: Integrator + + Answer: Command accepted or + Command error, Programming control not granted or + Invalid data (value not supported by controller) + + + + + + Tool Pairing handling + + This message is sent by the integrator in order to Pair tools, to abort ongoing pairing, + to Abort/Disconnect established connection and request for pairing status of the IRC-B or IRC-W tool types. + At pairing handling type, Start Pairing and Pairing Abort or Disconnect the controller must take program control + and release when finished. MID 0048 will be uploaded during the pairing process at each change of the pairing stage. + + Message sent by: Integrator + Answer: + Command accepted at pairing status ACCEPTED + Command error. See error codes. + Pairing status during the pairing process + + + + + Tool Pairing status + This message is sent by the controller in order to report the current status of the tool pairing. + Message sent by: Controller + Answer: None + + + + + Tightening data download status + Description: + Used by controller to upload the status of tightening data download to an radio connected tool. + Must be subscribed for by generic MID 0008 and unsubscribed for with generic MID 0009. + No extra data is needed and no historical data is applicable. + Message sent by: Controller + Answer: MID 0005 Command accepted + + + + + Tool list upload reply + + Upload a list of connected tools from controller. + + Message sent by: Controller + Answer: None + The list will contain all tools that are connected to the controller or station. + To request the data Application data message request without any extra data is used. + + + + + Set calibration value request with generic data + + This message is sent by the integrator in order to set the calibration value of the tool. + + Message sent by: Integrator + + Answer: Command accepted or + Command error, with code Calibration failed + + + + + + Tool Data status reply with generic data + + Upload requested parameters from given tool. + + Message sent by: Controller + + Answer: None + + + The list will contain requested parameters from the tool. + + + + + + Represents a Tool + + + + + Template for implementers. + + + + + User interface message category. Every user interface must implement . + + + + + Display user text on compact + + By sending this message the integrator can display a text on the compact display. The text must be maximum 4 bytes long. + The characters that can be displayed are limited due to the hardware of the compact display. + + + Each character must fit into seven segments. This means for example that it is not possible to display an M on the compact display. + The text will be displayed until next tightening, new parameter set or Job selection, or alarm code. + + Message sent by: Integrator + + Answer: Command accepted or + Command error, User text could not be displayed + + + + + + Display user text on graph + + By sending this message the integrator can display a text on the graphic display. + The user can furthermore set the time for the text to be displayed and if the text + should be acknowledged by the operator or not. + + + The text is divided into four lines with 25 ASCII characters each.If a line is shorter + than 25 characters it must be right padded with blanks(SPC 0x20). + + The first line is the text header and is in upper character. + Message sent by: Integrator + + Answer: Command accepted or + Command error, User text could not be displayed + + + + + + Flash green light on tool + + By sending this message the integrator can make the green light on the tool flash. + The light on the tool will flash until the operator pushes the tool trigger. + + Message sent by: Integrator + Answer: Command accepted + + + + + Template for implementers. + + + + + Represents a Variable Data entity + + + + + Vin message category. Every vin mid must implement . + + + + + Vehicle ID Number download request + + This message is replaced by . is still supported. + + Used by the integrator to send a VIN number to the controller. + Message sent by: Integrator + + Answer: Command accepted or + Command error, VIN input source not granted + + + + + + Vehicle ID Number subscribe + + This message is used by the integrator to set a subscription for the current + identifiers of the tightening result. + + The tightening result can be stamped with up to four identifiers: + + VIN number (identifier result part 1) + Identifier result part 2 + Identifier result part 3 + Identifier result part 4 + + + The identifiers are received by the controller from several input sources, + for example serial, Ethernet, or field bus. + + In revision 1 of the Vehicle ID Number, only the VIN number is transmitted. + In revision 2, all four possible identifiers are transmitted. + Message sent by: Integrator + + Answer: Command accepted or + Command error, VIN subscription already exists + + + + + + Vehicle ID Number + Transmission of the current identifiers of the tightening by the controller to the subscriber. + The tightening result can be stamped with up to four identifiers: + + VIN number (identifier result part 1) + Identifier result part 2 + Identifier result part 3 + Identifier result part 4 + + + The identifiers are received by the controller from several input sources, + for example serial, Ethernet, or field bus. + + Message sent by: Controller + Answer: Vehicle ID Number acknowledge + + + + + Vehicle ID Number acknowledge + Message sent by: Integrator + Answer: None + + + + + Vehicle ID Number unsubscribe + Reset the subscription for the current tightening identifiers. + Message sent by: Integrator + + Answer: Command accepted or + Command error, VIN subscription does not exist + + + + + + Template for implementers. + + + + + Templates for parsing packages and validating Mid assignability + + + + + Base class for all templates implementers + + + + + Initializes a new instance of class. + + + + + Check if mid number is assignable to this message template or not. + + Mid number + Is assignable or not + + + + Find out which Mid instance it should instantiate and parse all it's content. + + Mid number. + Package in ASCII string. + instance. + + + + Find out which Mid instance it should instantiate and parse all it's content + + Mid number + package in bytes + instance + + + + Update Mid instance it should instantiate + + Mid x Type key/value + + + + Filter dictionary to use only Mids from it's mode. + + Current mode if , or . + + + + Filter dictionary to use only selected Mids. + + Selected types. + + + + Remove unused/ignored from dictionary. + + Ignored mid instances + + + + Get from the dictionary based on mid number + + Mid number + Compiled instance + + + diff --git a/dist/lib/netstandard2.0/OpenProtocolInterpreter.dll b/dist/lib/netstandard2.0/OpenProtocolInterpreter.dll index 06303d92..b0852447 100644 Binary files a/dist/lib/netstandard2.0/OpenProtocolInterpreter.dll and b/dist/lib/netstandard2.0/OpenProtocolInterpreter.dll differ diff --git a/dist/lib/netstandard2.0/OpenProtocolInterpreter.xml b/dist/lib/netstandard2.0/OpenProtocolInterpreter.xml index 4e97c136..29c2f0db 100644 --- a/dist/lib/netstandard2.0/OpenProtocolInterpreter.xml +++ b/dist/lib/netstandard2.0/OpenProtocolInterpreter.xml @@ -459,7 +459,7 @@ - Application Communication positive acknowledge + Application data message request Do a request for data. This message is used for ALL request handling. When used it substitutes the use of all MID special request messages. @@ -2439,6 +2439,15 @@ + + + The MID Revision is unique per MID and is used in case different versions are available for the same MID. + Using the revision number the integrator can subscribe or ask for different versions of the same MID. + + Note: Enforces the default MID Revision to 1 when it's either send three spaces or 000 or 001. + + + Define if subscriber will acknowledge each "push" message sent by controller (reliable mode) or just push without waiting for a receive acknowledgement from subscriber (unreliable mode) @@ -4046,6 +4055,18 @@ + + + Old Multi spindle result request + Request for an old multi spindle result. + Note: MID 0104 can’t be used if there is an active subscription for multiple spindle results. + Message sent by: Integrator + + Answer: Command accepted or + Command error, Multi spindle result subscription already exists + + + Template for implementers. @@ -4336,6 +4357,19 @@ + + + Tightening Program Delete + Message sent by: Integrator + + Answer: Command accepted or + Command error + + This message deletes one or all programs in controller. + Note: If a running program is included in MID 2506 deletion the program shall finish before deletion. + Note: Deleting programs included in other nodes may give unwanted behaviour. It will behave identical to a manual delete of the program. + + Template for implementers. @@ -4755,6 +4789,15 @@ Answer: None + + + Tightening Result DB Info Upload + This message contains information concerning the tightening result database on the controller. + Application Data Message Request shall be used for fetching this message + Message sent by: Controller + Answer: None + + Represents a Stage Result entity @@ -4950,6 +4993,21 @@ + + + Tool Data status reply with generic data + + Upload requested parameters from given tool. + + Message sent by: Controller + + Answer: None + + + The list will contain requested parameters from the tool. + + + Represents a Tool diff --git a/docs/OpenProtocol_Specification.pdf b/docs/OpenProtocol_Specification.pdf index f78cac1f..b54533e4 100644 Binary files a/docs/OpenProtocol_Specification.pdf and b/docs/OpenProtocol_Specification.pdf differ diff --git a/src/MIDTesters.Core/Communication/TestMid0004.cs b/src/MIDTesters.Core/Communication/TestMid0004.cs index 67e97a3f..800a81b0 100644 --- a/src/MIDTesters.Core/Communication/TestMid0004.cs +++ b/src/MIDTesters.Core/Communication/TestMid0004.cs @@ -31,5 +31,30 @@ public void Mid0004ByteRevision1() Assert.IsNotNull(mid.ErrorCode); AssertEqualPackages(bytes, mid, true); } + + [TestMethod] + [TestCategory("Revision 2"), TestCategory("ASCII")] + public void Mid0004Revision2() + { + string pack = @"00270004002 0018021"; + var mid = _midInterpreter.Parse(pack); + + Assert.IsNotNull(mid.FailedMid); + Assert.IsNotNull(mid.ErrorCode); + AssertEqualPackages(pack, mid); + } + + [TestMethod] + [TestCategory("Revision 2"), TestCategory("ByteArray")] + public void Mid0004ByteRevision2() + { + string pack = @"00270004002 0018021"; + byte[] bytes = GetAsciiBytes(pack); + var mid = _midInterpreter.Parse(bytes); + + Assert.IsNotNull(mid.FailedMid); + Assert.IsNotNull(mid.ErrorCode); + AssertEqualPackages(bytes, mid); + } } } diff --git a/src/MIDTesters.Core/Job/Advanced/TestMid0140.cs b/src/MIDTesters.Core/Job/Advanced/TestMid0140.cs new file mode 100644 index 00000000..42ba4dec --- /dev/null +++ b/src/MIDTesters.Core/Job/Advanced/TestMid0140.cs @@ -0,0 +1,233 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenProtocolInterpreter; +using OpenProtocolInterpreter.Job.Advanced; +using System.Threading; + +namespace MIDTesters.Core.Job.Advanced +{ + [TestClass] + [TestCategory("Job"), TestCategory("Advanced Job")] + public class TestMid0140 : DefaultMidTests + { + [TestMethod] + [TestCategory("Revision 1"), TestCategory("ASCII")] + public void Mid0140Revision1() + { + string package = "01440140 01000102Job 1 03020414:045:0:22:02;01:013:1:10:01;0510610720810911011111201001310000140090151161171181191"; + var mid = _midInterpreter.Parse(package); + + Assert.AreEqual(typeof(Mid0140), mid.GetType()); + Assert.AreNotEqual(0, mid.JobId); + Assert.AreNotEqual(string.Empty, mid.JobName); + Assert.AreNotEqual(0, mid.NumberOfParameterSets); + Assert.IsNotNull(mid.JobList); + Assert.AreNotEqual(0, mid.JobList.Count); + Assert.AreEqual(ForcedOrder.ForcedOrder, mid.ForcedOrder); + Assert.IsTrue(mid.LockAtJobDone); + Assert.AreEqual(ToolLoosening.EnableOnlyOnNokTightenings, mid.ToolLoosening); + Assert.IsTrue(mid.RepeatJob); + Assert.AreEqual(BatchMode.BothOkAndNok, mid.BatchMode); + Assert.IsTrue(mid.DecrementBatchAtOkLoosening); + Assert.AreNotEqual(0, mid.MaxTimeForFirstTightening); + Assert.AreNotEqual(0, mid.MaxTimeToCompleteJob); + Assert.AreNotEqual(0, mid.DisplayResultAtAutoSelect); + Assert.IsTrue(mid.UsingLineControl); + Assert.AreEqual(IdentifierPart.Other, mid.IdentifierResultPart); + Assert.IsTrue(mid.ResultOfNonTightenings); + Assert.IsTrue(mid.ResetAllIdentifiersAtJobDone); + Assert.AreEqual(Reserved.G, mid.Reserved); + AssertEqualPackages(package, mid, true); + } + + [TestMethod] + [TestCategory("Revision 1"), TestCategory("ByteArray")] + public void Mid0140ByteRevision1() + { + string package = "01440140 01000102Job 1 03020414:045:0:22:02;01:013:1:10:01;0510610720810911011111201001310000140090151161171181191"; + byte[] bytes = GetAsciiBytes(package); + var mid = _midInterpreter.Parse(bytes); + + Assert.AreEqual(typeof(Mid0140), mid.GetType()); + Assert.AreNotEqual(0, mid.JobId); + Assert.AreNotEqual(string.Empty, mid.JobName); + Assert.AreNotEqual(0, mid.NumberOfParameterSets); + Assert.IsNotNull(mid.JobList); + Assert.AreNotEqual(0, mid.JobList.Count); + Assert.AreEqual(ForcedOrder.ForcedOrder, mid.ForcedOrder); + Assert.IsTrue(mid.LockAtJobDone); + Assert.AreEqual(ToolLoosening.EnableOnlyOnNokTightenings, mid.ToolLoosening); + Assert.IsTrue(mid.RepeatJob); + Assert.AreEqual(BatchMode.BothOkAndNok, mid.BatchMode); + Assert.IsTrue(mid.DecrementBatchAtOkLoosening); + Assert.AreNotEqual(0, mid.MaxTimeForFirstTightening); + Assert.AreNotEqual(0, mid.MaxTimeToCompleteJob); + Assert.AreNotEqual(0, mid.DisplayResultAtAutoSelect); + Assert.IsTrue(mid.UsingLineControl); + Assert.AreEqual(IdentifierPart.Other, mid.IdentifierResultPart); + Assert.IsTrue(mid.ResultOfNonTightenings); + Assert.IsTrue(mid.ResetAllIdentifiersAtJobDone); + Assert.AreEqual(Reserved.G, mid.Reserved); + AssertEqualPackages(bytes, mid, true); + } + + [TestMethod] + [TestCategory("Revision 2"), TestCategory("ASCII")] + public void Mid0140Revision2() + { + string package = "02250140002 01000102Job 1 03020415:045:0:22:02:10:0107:Job Action 1 :01;15:045:0:12:12:13:0407:Job Action 2 :02;05106107208109110111112010013100001400901511611711811912000120"; + var mid = _midInterpreter.Parse(package); + + Assert.AreEqual(typeof(Mid0140), mid.GetType()); + Assert.AreNotEqual(0, mid.JobId); + Assert.AreNotEqual(string.Empty, mid.JobName); + Assert.AreNotEqual(0, mid.NumberOfParameterSets); + Assert.IsNotNull(mid.JobList); + Assert.AreNotEqual(0, mid.JobList.Count); + Assert.AreEqual(ForcedOrder.ForcedOrder, mid.ForcedOrder); + Assert.IsTrue(mid.LockAtJobDone); + Assert.AreEqual(ToolLoosening.EnableOnlyOnNokTightenings, mid.ToolLoosening); + Assert.IsTrue(mid.RepeatJob); + Assert.AreEqual(BatchMode.BothOkAndNok, mid.BatchMode); + Assert.IsTrue(mid.DecrementBatchAtOkLoosening); + Assert.AreNotEqual(0, mid.MaxTimeForFirstTightening); + Assert.AreNotEqual(0, mid.MaxTimeToCompleteJob); + Assert.AreNotEqual(0, mid.DisplayResultAtAutoSelect); + Assert.IsTrue(mid.UsingLineControl); + Assert.AreEqual(IdentifierPart.Other, mid.IdentifierResultPart); + Assert.IsTrue(mid.ResultOfNonTightenings); + Assert.IsTrue(mid.ResetAllIdentifiersAtJobDone); + Assert.AreEqual(Reserved.G, mid.Reserved); + Assert.AreNotEqual(0, mid.JobSequenceNumber); + AssertEqualPackages(package, mid); + } + + [TestMethod] + [TestCategory("Revision 2"), TestCategory("ByteArray")] + public void Mid0140ByteRevision2() + { + string package = "02250140002 01000102Job 1 03020415:045:0:22:02:10:0107:Job Action 1 :01;15:045:0:12:12:13:0407:Job Action 2 :02;05106107208109110111112010013100001400901511611711811912000120"; + byte[] bytes = GetAsciiBytes(package); + var mid = _midInterpreter.Parse(bytes); + + Assert.AreEqual(typeof(Mid0140), mid.GetType()); + Assert.AreNotEqual(0, mid.JobId); + Assert.AreNotEqual(string.Empty, mid.JobName); + Assert.AreNotEqual(0, mid.NumberOfParameterSets); + AssertEqualPackages(bytes, mid); + } + + [TestMethod] + [TestCategory("Revision 3"), TestCategory("ASCII")] + public void Mid0140Revision3() + { + string package = "02350140003 01000102Job 1 03020415:045:10:22:02:10:0107:Job Action 1 :01:2:1:1:2:2;15:041:10:12:12:13:0407:Job Action 2 :02:2:1:1:2:2;05106107108010009009001000901111211311411511605000"; + var mid = _midInterpreter.Parse(package); + + Assert.AreEqual(typeof(Mid0140), mid.GetType()); + Assert.AreNotEqual(0, mid.JobId); + Assert.AreNotEqual(string.Empty, mid.JobName); + Assert.AreNotEqual(0, mid.NumberOfParameterSets); + Assert.IsNotNull(mid.JobList); + Assert.AreNotEqual(0, mid.JobList.Count); + Assert.AreEqual(ForcedOrder.ForcedOrder, mid.ForcedOrder); + Assert.IsTrue(mid.LockAtJobDone); + Assert.IsTrue(mid.RepeatJob); + Assert.AreNotEqual(0, mid.MaxTimeForFirstTightening); + Assert.AreNotEqual(0, mid.MaxTimeToCompleteJob); + Assert.AreNotEqual(0, mid.DisplayResultAtAutoSelect); + Assert.IsTrue(mid.UsingLineControl); + Assert.AreEqual(IdentifierPart.Other, mid.IdentifierResultPart); + Assert.IsTrue(mid.ResultOfNonTightenings); + Assert.IsTrue(mid.ResetAllIdentifiersAtJobDone); + Assert.AreEqual(Reserved.G, mid.Reserved); + Assert.AreNotEqual(0, mid.JobSequenceNumber); + AssertEqualPackages(package, mid); + } + + [TestMethod] + [TestCategory("Revision 3"), TestCategory("ByteArray")] + public void Mid0140ByteRevision3() + { + string package = "02350140003 01000102Job 1 03020415:045:10:22:02:10:0107:Job Action 1 :01:2:1:1:2:2;15:041:10:12:12:13:0407:Job Action 2 :02:2:1:1:2:2;05106107108010009009001000901111211311411511605000"; + byte[] bytes = GetAsciiBytes(package); + var mid = _midInterpreter.Parse(bytes); + + Assert.AreEqual(typeof(Mid0140), mid.GetType()); + Assert.AreNotEqual(0, mid.JobId); + Assert.AreNotEqual(string.Empty, mid.JobName); + Assert.AreNotEqual(0, mid.NumberOfParameterSets); + Assert.IsNotNull(mid.JobList); + Assert.AreNotEqual(0, mid.JobList.Count); + Assert.AreEqual(ForcedOrder.ForcedOrder, mid.ForcedOrder); + Assert.IsTrue(mid.LockAtJobDone); + Assert.IsTrue(mid.RepeatJob); + Assert.AreNotEqual(0, mid.MaxTimeForFirstTightening); + Assert.AreNotEqual(0, mid.MaxTimeToCompleteJob); + Assert.AreNotEqual(0, mid.DisplayResultAtAutoSelect); + Assert.IsTrue(mid.UsingLineControl); + Assert.AreEqual(IdentifierPart.Other, mid.IdentifierResultPart); + Assert.IsTrue(mid.ResultOfNonTightenings); + Assert.IsTrue(mid.ResetAllIdentifiersAtJobDone); + Assert.AreEqual(Reserved.G, mid.Reserved); + Assert.AreNotEqual(0, mid.JobSequenceNumber); + AssertEqualPackages(bytes, mid); + } + + [TestMethod] + [TestCategory("Revision 4"), TestCategory("ASCII")] + public void Mid0140Revision4() + { + string package = "02430140004 01000102Job 1 03020415:045:10:0022:02:0010:0107:Job Action 1 :01:2:1:1:2:2;15:041:10:0016:12:0013:0407:Job Action 2 :02:2:1:1:2:2;05106107108010009009001000901111211311411511605000"; + var mid = _midInterpreter.Parse(package); + + Assert.AreEqual(typeof(Mid0140), mid.GetType()); + Assert.AreNotEqual(0, mid.JobId); + Assert.AreNotEqual(string.Empty, mid.JobName); + Assert.AreNotEqual(0, mid.NumberOfParameterSets); + Assert.IsNotNull(mid.JobList); + Assert.AreNotEqual(0, mid.JobList.Count); + Assert.AreEqual(ForcedOrder.ForcedOrder, mid.ForcedOrder); + Assert.IsTrue(mid.LockAtJobDone); + Assert.IsTrue(mid.RepeatJob); + Assert.AreNotEqual(0, mid.MaxTimeForFirstTightening); + Assert.AreNotEqual(0, mid.MaxTimeToCompleteJob); + Assert.AreNotEqual(0, mid.DisplayResultAtAutoSelect); + Assert.IsTrue(mid.UsingLineControl); + Assert.AreEqual(IdentifierPart.Other, mid.IdentifierResultPart); + Assert.IsTrue(mid.ResultOfNonTightenings); + Assert.IsTrue(mid.ResetAllIdentifiersAtJobDone); + Assert.AreEqual(Reserved.G, mid.Reserved); + Assert.AreNotEqual(0, mid.JobSequenceNumber); + AssertEqualPackages(package, mid); + } + + [TestMethod] + [TestCategory("Revision 4"), TestCategory("ByteArray")] + public void Mid0140ByteRevision4() + { + string package = "02350140003 01000102Job 1 03020415:045:10:22:02:10:0107:Job Action 1 :01:2:1:1:2:2;15:041:10:12:12:13:0407:Job Action 2 :02:2:1:1:2:2;05106107108010009009001000901111211311411511605000"; + byte[] bytes = GetAsciiBytes(package); + var mid = _midInterpreter.Parse(bytes); + + Assert.AreEqual(typeof(Mid0140), mid.GetType()); + Assert.AreNotEqual(0, mid.JobId); + Assert.AreNotEqual(string.Empty, mid.JobName); + Assert.AreNotEqual(0, mid.NumberOfParameterSets); + Assert.IsNotNull(mid.JobList); + Assert.AreNotEqual(0, mid.JobList.Count); + Assert.AreEqual(ForcedOrder.ForcedOrder, mid.ForcedOrder); + Assert.IsTrue(mid.LockAtJobDone); + Assert.IsTrue(mid.RepeatJob); + Assert.AreNotEqual(0, mid.MaxTimeForFirstTightening); + Assert.AreNotEqual(0, mid.MaxTimeToCompleteJob); + Assert.AreNotEqual(0, mid.DisplayResultAtAutoSelect); + Assert.IsTrue(mid.UsingLineControl); + Assert.AreEqual(IdentifierPart.Other, mid.IdentifierResultPart); + Assert.IsTrue(mid.ResultOfNonTightenings); + Assert.IsTrue(mid.ResetAllIdentifiersAtJobDone); + Assert.AreEqual(Reserved.G, mid.Reserved); + Assert.AreNotEqual(0, mid.JobSequenceNumber); + AssertEqualPackages(bytes, mid); + } + } +} diff --git a/src/MIDTesters.Core/Job/TestMid0033.cs b/src/MIDTesters.Core/Job/TestMid0033.cs index 2ae25d47..30f02b58 100644 --- a/src/MIDTesters.Core/Job/TestMid0033.cs +++ b/src/MIDTesters.Core/Job/TestMid0033.cs @@ -194,5 +194,52 @@ public void Mid0033ByteRevision4() Assert.IsNotNull(mid.ParameterSetList); AssertEqualPackages(bytes, mid); } + + [TestMethod] + [TestCategory("Revision 5"), TestCategory("ASCII")] + public void Mid0033Revision5() + { + string package = "01950033005 01000402My Job 4 031045000057000406107108109110211112021315:011:1:0002:0002:Job Step 1 Name :03:05;11:015:1:0002:0001:Job Step 2 Name :05:02;"; + var mid = _midInterpreter.Parse(package); + + Assert.IsNotNull(mid.JobId); + Assert.IsNotNull(mid.JobName); + Assert.IsNotNull(mid.ForcedOrder); + Assert.IsNotNull(mid.MaxTimeForFirstTightening); + Assert.IsNotNull(mid.MaxTimeToCompleteJob); + Assert.IsNotNull(mid.JobBatchMode); + Assert.IsNotNull(mid.LockAtJobDone); + Assert.IsNotNull(mid.UseLineControl); + Assert.IsNotNull(mid.RepeatJob); + Assert.IsNotNull(mid.ToolLoosening); + Assert.IsNotNull(mid.Reserved); + Assert.IsNotNull(mid.NumberOfParameterSets); + Assert.IsNotNull(mid.ParameterSetList); + AssertEqualPackages(package, mid); + } + + [TestMethod] + [TestCategory("Revision 5"), TestCategory("ByteArray")] + public void Mid0033ByteRevision5() + { + string package = "01950033005 01000402My Job 4 031045000057000406107108109110211112021315:011:1:0002:0002:Job Step 1 Name :03:05;11:015:1:0002:0001:Job Step 2 Name :05:02;"; + byte[] bytes = GetAsciiBytes(package); + var mid = _midInterpreter.Parse(bytes); + + Assert.IsNotNull(mid.JobId); + Assert.IsNotNull(mid.JobName); + Assert.IsNotNull(mid.ForcedOrder); + Assert.IsNotNull(mid.MaxTimeForFirstTightening); + Assert.IsNotNull(mid.MaxTimeToCompleteJob); + Assert.IsNotNull(mid.JobBatchMode); + Assert.IsNotNull(mid.LockAtJobDone); + Assert.IsNotNull(mid.UseLineControl); + Assert.IsNotNull(mid.RepeatJob); + Assert.IsNotNull(mid.ToolLoosening); + Assert.IsNotNull(mid.Reserved); + Assert.IsNotNull(mid.NumberOfParameterSets); + Assert.IsNotNull(mid.ParameterSetList); + AssertEqualPackages(bytes, mid); + } } } diff --git a/src/MIDTesters.Core/MIDTesters.Core.csproj b/src/MIDTesters.Core/MIDTesters.Core.csproj index 73e72dfc..9bb6c4ba 100644 --- a/src/MIDTesters.Core/MIDTesters.Core.csproj +++ b/src/MIDTesters.Core/MIDTesters.Core.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 false diff --git a/src/MIDTesters.Core/MIDsTests.cs b/src/MIDTesters.Core/MIDsTests.cs index 47ba93c8..b3092e6d 100644 --- a/src/MIDTesters.Core/MIDsTests.cs +++ b/src/MIDTesters.Core/MIDsTests.cs @@ -7,10 +7,10 @@ namespace MIDTesters { - //[TestClass] + //[Microsoft.VisualStudio.TestTools.UnitTesting.TestClass] public class MIDsTests { - //[TestMethod] + //[Microsoft.VisualStudio.TestTools.UnitTesting.TestMethod] public void TestProcessingTime() { long total = 0; @@ -39,7 +39,7 @@ public void TestProcessingTime() for (int i = 0; i < 1000000; i++) { - watch.Start(); + watch.Restart(); var myMid106 = myTEmplate.Parse(mid61); watch.Stop(); total += watch.ElapsedTicks; @@ -49,14 +49,14 @@ public void TestProcessingTime() //All MIDs watch.Start(); - myTEmplate = new MidInterpreter(); + myTEmplate = new MidInterpreter().UseAllMessages(); watch.Stop(); Debug.WriteLine("[AllMIDs] Elapsed time to construct MidInterpreter: " + new TimeSpan(watch.ElapsedTicks)); total = 0; for (int i = 0; i < 1000000; i++) { - watch.Start(); + watch.Restart(); var myMid500 = myTEmplate.Parse(mid61); watch.Stop(); total += watch.ElapsedTicks; diff --git a/src/MIDTesters.Core/MultiSpindle/TestMid0101.cs b/src/MIDTesters.Core/MultiSpindle/TestMid0101.cs index 95c6ce7f..8e300f37 100644 --- a/src/MIDTesters.Core/MultiSpindle/TestMid0101.cs +++ b/src/MIDTesters.Core/MultiSpindle/TestMid0101.cs @@ -189,5 +189,70 @@ public void Mid0101ByteRevision5() Assert.IsNotNull(mid.JobSequenceNumber); AssertEqualPackages(bytes, mid); } + + [TestMethod] + [TestCategory("Revision 6"), TestCategory("ASCII")] + public void Mid0101Revision6() + { + var pack = "02040101006 010102BM3GA02111900601 030304003050001060001071080006800900092010000800110000012-00151300000142019-11-14:14:08:05152019-11-25:11:22:41160091317118010111000809100000190022000021"; + var mid = _midInterpreter.Parse(pack); + + Assert.AreEqual(typeof(Mid0101), mid.GetType()); + Assert.IsNotNull(mid.NumberOfSpindlesOrPresses); + Assert.IsNotNull(mid.VinNumber); + Assert.IsNotNull(mid.JobId); + Assert.IsNotNull(mid.ParameterSetId); + Assert.IsNotNull(mid.BatchSize); + Assert.IsNotNull(mid.BatchCounter); + Assert.IsNotNull(mid.BatchStatus); + Assert.IsNotNull(mid.TorqueOrForceMinLimit); + Assert.IsNotNull(mid.TorqueOrForceMaxLimit); + Assert.IsNotNull(mid.TorqueOrForceFinalTarget); + Assert.IsNotNull(mid.AngleOrStrokeMinLimit); + Assert.IsNotNull(mid.AngleOrStrokeMaxLimit); + Assert.IsTrue(mid.AngleOrStrokeMaxLimit < 0); + Assert.IsNotNull(mid.FinalAngleOrStrokeTarget); + Assert.IsNotNull(mid.LastChangeInParameterSet); + Assert.IsNotNull(mid.TimeStamp); + Assert.IsNotNull(mid.SyncTighteningId); + Assert.IsNotNull(mid.SyncOverallStatus); + Assert.IsNotNull(mid.SpindlesOrPressesStatus); + Assert.IsNotNull(mid.SystemSubType); + Assert.IsNotNull(mid.JobSequenceNumber); + AssertEqualPackages(pack, mid); + } + + [TestMethod] + [TestCategory("Revision 6"), TestCategory("ByteArray")] + public void Mid0101ByteRevision6() + { + var package = "02040101006 010102BM3GA02111900601 030304003050001060001071080006800900092010000800110000012-00151300000142019-11-14:14:08:05152019-11-25:11:22:41160091317118010111000809100000190022000021"; + byte[] bytes = GetAsciiBytes(package); + var mid = _midInterpreter.Parse(bytes); + + Assert.AreEqual(typeof(Mid0101), mid.GetType()); + Assert.IsNotNull(mid.NumberOfSpindlesOrPresses); + Assert.IsNotNull(mid.VinNumber); + Assert.IsNotNull(mid.JobId); + Assert.IsNotNull(mid.ParameterSetId); + Assert.IsNotNull(mid.BatchSize); + Assert.IsNotNull(mid.BatchCounter); + Assert.IsNotNull(mid.BatchStatus); + Assert.IsNotNull(mid.TorqueOrForceMinLimit); + Assert.IsNotNull(mid.TorqueOrForceMaxLimit); + Assert.IsNotNull(mid.TorqueOrForceFinalTarget); + Assert.IsNotNull(mid.AngleOrStrokeMinLimit); + Assert.IsNotNull(mid.AngleOrStrokeMaxLimit); + Assert.IsTrue(mid.AngleOrStrokeMaxLimit < 0); + Assert.IsNotNull(mid.FinalAngleOrStrokeTarget); + Assert.IsNotNull(mid.LastChangeInParameterSet); + Assert.IsNotNull(mid.TimeStamp); + Assert.IsNotNull(mid.SyncTighteningId); + Assert.IsNotNull(mid.SyncOverallStatus); + Assert.IsNotNull(mid.SpindlesOrPressesStatus); + Assert.IsNotNull(mid.SystemSubType); + Assert.IsNotNull(mid.JobSequenceNumber); + AssertEqualPackages(bytes, mid); + } } } diff --git a/src/MIDTesters.Core/MultiSpindle/TestMid0104.cs b/src/MIDTesters.Core/MultiSpindle/TestMid0104.cs new file mode 100644 index 00000000..e95ec455 --- /dev/null +++ b/src/MIDTesters.Core/MultiSpindle/TestMid0104.cs @@ -0,0 +1,33 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenProtocolInterpreter.MultiSpindle; + +namespace MIDTesters.Core.MultiSpindle +{ + [TestClass] + [TestCategory("MultiSpindle")] + public class TestMid0104 : DefaultMidTests + { + [TestMethod] + [TestCategory("Revision 1"), TestCategory("ASCII")] + public void Mid0104Revision1() + { + string pack = @"00320104 013009021015"; + var mid = _midInterpreter.Parse(pack); + + Assert.AreNotEqual(0, mid.RequestedResultIndex); + AssertEqualPackages(pack, mid, true); + } + + [TestMethod] + [TestCategory("Revision 1"), TestCategory("ByteArray")] + public void Mid0104ByteRevision1() + { + string package = @"00320104 013009021015"; + byte[] bytes = GetAsciiBytes(package); + var mid = _midInterpreter.Parse(bytes); + + Assert.AreNotEqual(0, mid.RequestedResultIndex); + AssertEqualPackages(bytes, mid, true); + } + } +} diff --git a/src/MIDTesters.Core/MultipleIdentifiers/TestMid0150.cs b/src/MIDTesters.Core/MultipleIdentifiers/TestMid0150.cs index 02e70789..45774ed2 100644 --- a/src/MIDTesters.Core/MultipleIdentifiers/TestMid0150.cs +++ b/src/MIDTesters.Core/MultipleIdentifiers/TestMid0150.cs @@ -41,7 +41,6 @@ public void Mid0150ShouldTruncateIdentifier() var mid0150 = new Mid0150() { IdentifierData = identifier }; Assert.IsNotNull(mid0150.IdentifierData); - Assert.AreEqual(identifier.Substring(0, 100), mid0150.IdentifierData); Assert.IsTrue(mid0150.Pack().Length == 120); } } diff --git a/src/MIDTesters.Core/PLCUserData/TestMid0240.cs b/src/MIDTesters.Core/PLCUserData/TestMid0240.cs index b2543a40..6ad4b586 100644 --- a/src/MIDTesters.Core/PLCUserData/TestMid0240.cs +++ b/src/MIDTesters.Core/PLCUserData/TestMid0240.cs @@ -38,7 +38,6 @@ public void Mid0240ShouldTrucanteUserData() var mid0240 = new Mid0240() { UserData = userData }; Assert.IsNotNull(mid0240.UserData); - Assert.AreEqual(userData.Substring(0, 200), mid0240.UserData); Assert.IsTrue(mid0240.Pack().Length == 220); } } diff --git a/src/MIDTesters.Core/PLCUserData/TestMid0245.cs b/src/MIDTesters.Core/PLCUserData/TestMid0245.cs index fe8d7eef..72f076af 100644 --- a/src/MIDTesters.Core/PLCUserData/TestMid0245.cs +++ b/src/MIDTesters.Core/PLCUserData/TestMid0245.cs @@ -41,7 +41,6 @@ public void Mid0245ShouldTruncateUserData() var mid0245 = new Mid0245(2) { Offset = 0, UserData = userData }; Assert.IsNotNull(mid0245.Offset); Assert.IsNotNull(mid0245.UserData); - Assert.AreEqual(userData.Substring(0, 200), mid0245.UserData); Assert.IsTrue(mid0245.Pack().Length == 223); } } diff --git a/src/MIDTesters.Core/ParameterSet/TestMid0019.cs b/src/MIDTesters.Core/ParameterSet/TestMid0019.cs index 5aa790f6..5750551e 100644 --- a/src/MIDTesters.Core/ParameterSet/TestMid0019.cs +++ b/src/MIDTesters.Core/ParameterSet/TestMid0019.cs @@ -31,5 +31,30 @@ public void Mid0019ByteRevision1() Assert.IsNotNull(mid.BatchSize); AssertEqualPackages(bytes, mid, true); } + + [TestMethod] + [TestCategory("Revision 2"), TestCategory("ASCII")] + public void Mid0019Revision2() + { + string package = "00270019002 7770050"; + var mid = _midInterpreter.Parse(package); + + Assert.IsNotNull(mid.ParameterSetId); + Assert.IsNotNull(mid.BatchSize); + AssertEqualPackages(package, mid); + } + + [TestMethod] + [TestCategory("Revision 2"), TestCategory("ByteArray")] + public void Mid0019ByteRevision2() + { + string package = "00270019002 7770050"; + byte[] bytes = GetAsciiBytes(package); + var mid = _midInterpreter.Parse(bytes); + + Assert.IsNotNull(mid.ParameterSetId); + Assert.IsNotNull(mid.BatchSize); + AssertEqualPackages(bytes, mid); + } } } diff --git a/src/MIDTesters.Core/ParameterSet/TestMid2506.cs b/src/MIDTesters.Core/ParameterSet/TestMid2506.cs new file mode 100644 index 00000000..3ee7b155 --- /dev/null +++ b/src/MIDTesters.Core/ParameterSet/TestMid2506.cs @@ -0,0 +1,35 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenProtocolInterpreter.ParameterSet; + +namespace MIDTesters.Core.ParameterSet +{ + [TestClass] + [TestCategory("ParameterSet")] + public class TestMid2506 : DefaultMidTests + { + [TestMethod] + [TestCategory("Revision 1"), TestCategory("ASCII")] + public void Mid2506Revision1() + { + string package = "00272506001 0030201"; + var mid = _midInterpreter.Parse(package); + + Assert.AreNotEqual(0, mid.ProgramId); + Assert.AreNotEqual(0, (int)mid.NodeType); + AssertEqualPackages(package, mid); + } + + [TestMethod] + [TestCategory("Revision 1"), TestCategory("ByteArray")] + public void Mid2506ByteRevision1() + { + string package = "00272506001 0030201"; + byte[] bytes = GetAsciiBytes(package); + var mid = _midInterpreter.Parse(bytes); + + Assert.AreNotEqual(0, mid.ProgramId); + Assert.AreNotEqual(0, (int)mid.NodeType); + AssertEqualPackages(bytes, mid); + } + } +} diff --git a/src/MIDTesters.Core/Result/TestMid1201.cs b/src/MIDTesters.Core/Result/TestMid1201.cs index 2d3faa24..2ab65e2a 100644 --- a/src/MIDTesters.Core/Result/TestMid1201.cs +++ b/src/MIDTesters.Core/Result/TestMid1201.cs @@ -27,5 +27,47 @@ public void Mid1201ByteRevision1() AssertEqualPackages(bytes, mid, true); } + + [TestMethod] + [TestCategory("Revision 2"), TestCategory("ASCII")] + public void Mid1201Revision2() + { + string package = "00731201002 00200100000001532022-11-14:09:35:10000000800100100000"; + var mid = _midInterpreter.Parse(package); + + AssertEqualPackages(package, mid); + } + + [TestMethod] + [TestCategory("Revision 2"), TestCategory("ByteArray")] + public void Mid1201ByteRevision2() + { + string package = "00731201002 00200100000001532022-11-14:09:35:10000000800100100000"; + byte[] bytes = GetAsciiBytes(package); + var mid = _midInterpreter.Parse(bytes); + + AssertEqualPackages(bytes, mid); + } + + [TestMethod] + [TestCategory("Revision 3"), TestCategory("ASCII")] + public void Mid1201Revision3() + { + string package = "00781201003 00200100000001532022-11-14:09:35:1000000080010010030092000"; + var mid = _midInterpreter.Parse(package); + + AssertEqualPackages(package, mid); + } + + [TestMethod] + [TestCategory("Revision 3"), TestCategory("ByteArray")] + public void Mid1201ByteRevision3() + { + string package = "00781201003 00200100000001532022-11-14:09:35:1000000080010010030092000"; + byte[] bytes = GetAsciiBytes(package); + var mid = _midInterpreter.Parse(bytes); + + AssertEqualPackages(bytes, mid); + } } } diff --git a/src/MIDTesters.Core/Tightening/TestMid0060.cs b/src/MIDTesters.Core/Tightening/TestMid0060.cs index 92bfd5c2..f84b15db 100644 --- a/src/MIDTesters.Core/Tightening/TestMid0060.cs +++ b/src/MIDTesters.Core/Tightening/TestMid0060.cs @@ -5,7 +5,7 @@ namespace MIDTesters.Tightening { [TestClass] [TestCategory("Tightening")] - public class TestMid0060 : MidTester + public class TestMid0060 : DefaultMidTests { [TestMethod] [TestCategory("ASCII")] diff --git a/src/MIDTesters.Core/Tightening/TestMid0061.cs b/src/MIDTesters.Core/Tightening/TestMid0061.cs index bdd7585a..700cae83 100644 --- a/src/MIDTesters.Core/Tightening/TestMid0061.cs +++ b/src/MIDTesters.Core/Tightening/TestMid0061.cs @@ -6,7 +6,7 @@ namespace MIDTesters.Tightening { [TestClass] [TestCategory("Tightening")] - public class TestMid0061 : MidTester + public class TestMid0061 : DefaultMidTests { [TestMethod] [TestCategory("Revision 1"), TestCategory("ASCII")] @@ -1216,6 +1216,643 @@ public void Mid0061ByteRevision8() AssertEqualPackages(bytes, mid); } + [TestMethod] + [TestCategory("Revision 9"), TestCategory("ASCII")] + public void Mid0061Revision9() + { + var pack = "05920061009 010000020003RA ST6.2 ETV100 04 05000006001070208000670900001000001101221301401501611711811912000000081942100340022004600230040002400050525000202600420270000028000002900100300085031000043200033150340003500000036999900370000003800000039000000400000004100001848874200000430000044 C0761275452020-06-25:01:04:39462020-06-24:10:48:5347Test Parameter Set 482490550Identifier result part 2 51Identifier result part 3 52Identifier result part 4 53E12454001500550000000042560010000570999900580010005926065214361005232620010063000506400150"; + var mid = _midInterpreter.Parse(pack); + + Assert.AreEqual(typeof(Mid0061), mid.GetType()); + Assert.IsNotNull(mid.CellId); + Assert.IsNotNull(mid.ChannelId); + Assert.IsNotNull(mid.TorqueControllerName); + Assert.IsNotNull(mid.VinNumber); + Assert.IsNotNull(mid.JobId); + Assert.IsNotNull(mid.ParameterSetId); + Assert.IsNotNull(mid.Strategy); + Assert.IsNotNull(mid.StrategyOptions); + Assert.IsNotNull(mid.BatchSize); + Assert.IsNotNull(mid.BatchCounter); + Assert.IsNotNull(mid.TighteningStatus); + Assert.IsNotNull(mid.BatchStatus); + Assert.IsNotNull(mid.TorqueStatus); + Assert.IsNotNull(mid.AngleStatus); + Assert.IsNotNull(mid.RundownAngleStatus); + Assert.IsNotNull(mid.CurrentMonitoringStatus); + Assert.IsNotNull(mid.SelftapStatus); + Assert.IsNotNull(mid.PrevailTorqueCompensateStatus); + Assert.IsNotNull(mid.TighteningErrorStatus); + Assert.IsNotNull(mid.TorqueMinLimit); + Assert.IsNotNull(mid.TorqueMaxLimit); + Assert.IsNotNull(mid.TorqueFinalTarget); + Assert.IsNotNull(mid.Torque); + Assert.IsNotNull(mid.AngleMinLimit); + Assert.IsNotNull(mid.AngleMaxLimit); + Assert.IsNotNull(mid.AngleFinalTarget); + Assert.IsNotNull(mid.Angle); + Assert.IsNotNull(mid.RundownAngle); + Assert.IsNotNull(mid.CurrentMonitoringMin); + Assert.IsNotNull(mid.CurrentMonitoringMax); + Assert.IsNotNull(mid.CurrentMonitoringValue); + Assert.IsNotNull(mid.SelftapMin); + Assert.IsNotNull(mid.SelftapMax); + Assert.IsNotNull(mid.SelftapTorque); + Assert.IsNotNull(mid.PrevailTorqueMonitoringMin); + Assert.IsNotNull(mid.PrevailTorqueMonitoringMax); + Assert.IsNotNull(mid.PrevailTorque); + Assert.IsNotNull(mid.TighteningId); + Assert.IsNotNull(mid.JobSequenceNumber); + Assert.IsNotNull(mid.SyncTighteningId); + Assert.IsNotNull(mid.ToolSerialNumber); + Assert.IsNotNull(mid.Timestamp); + Assert.IsNotNull(mid.LastChangeInParameterSet); + Assert.IsNotNull(mid.ParameterSetName); + Assert.IsNotNull(mid.TorqueValuesUnit); + Assert.IsNotNull(mid.ResultType); + Assert.IsNotNull(mid.IdentifierResultPart2); + Assert.IsNotNull(mid.IdentifierResultPart3); + Assert.IsNotNull(mid.IdentifierResultPart4); + Assert.IsNotNull(mid.CustomerTighteningErrorCode); + Assert.IsNotNull(mid.PrevailTorqueCompensateValue); + Assert.IsNotNull(mid.TighteningErrorStatus2); + Assert.IsNotNull(mid.CompensatedAngle); + Assert.IsNotNull(mid.FinalAngleDecimal); + Assert.AreNotEqual(0, mid.StartFinalAngle); + Assert.IsNotNull(mid.PostViewTorqueActivated); + Assert.AreNotEqual(0, mid.PostViewTorqueHigh); + Assert.AreNotEqual(0, mid.PostViewTorqueLow); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpere); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMin); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMax); + AssertEqualPackages(pack, mid); + } + + [TestMethod] + [TestCategory("Revision 9"), TestCategory("ByteArray")] + public void Mid0061ByteRevision9() + { + List bytes = new List(); + + var strategyOptions = new byte[] //5 bytes long + { + 0xAA, //1010 1010 + 0x03, //0000 0011 + 0x00, + 0x00, + 0x00 + }; + var tighteningErrorStatus = new byte[] //10 bytes long + { + 0xAA, //1010 1010 + 0x03, //0000 0011 + 0x0A, //0000 1010 + 0xD1, //1101 0001 + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00 + }; + + var tighteningErrorStatus2 = new byte[] //10 bytes long + { + 0xAA, //1010 1010 + 0x03, //0000 0011 + 0x02, //0000 0010 + 0x00, //Reserved from bit 19 to rest + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00 + }; + + string untilStrategyOptions = "05920061009 010001020103airbag7 04KPOL3456JKLO897 05000606003071208"; + bytes.AddRange(GetAsciiBytes(untilStrategyOptions)); + bytes.AddRange(GetAsciiBytes(strategyOptions, 5)); + + string untilTighteningErrorStatus = "09000010000011012013114015216117018219120"; + bytes.AddRange(GetAsciiBytes(untilTighteningErrorStatus)); + bytes.AddRange(GetAsciiBytes(tighteningErrorStatus, 10)); + + string untilTighteningErrorStatus2 = "2100084022001400230012002400073925000002609999270000028000002900000300999931050003200033050340453500001036000125370005483800001039999900405555004142949672954265500436053544ABCDEFG-123456452001-06-02:09:54:09462001-05-29:12:34:3347Test Parameter Set 482490550Identifier result part 2 51Identifier result part 3 52Identifier result part 4 53E1245400150055"; + bytes.AddRange(GetAsciiBytes(untilTighteningErrorStatus2)); + bytes.AddRange(GetAsciiBytes(tighteningErrorStatus2, 10)); + + string untilEnd = "560010000570999900580010005926065214361005232620010063000506400150"; + bytes.AddRange(GetAsciiBytes(untilEnd)); + + var mid = _midInterpreter.Parse(bytes.ToArray()); + + Assert.AreEqual(typeof(Mid0061), mid.GetType()); + Assert.IsNotNull(mid.CellId); + Assert.IsNotNull(mid.ChannelId); + Assert.IsNotNull(mid.TorqueControllerName); + Assert.IsNotNull(mid.VinNumber); + Assert.IsNotNull(mid.JobId); + Assert.IsNotNull(mid.ParameterSetId); + Assert.IsNotNull(mid.Strategy); + Assert.IsNotNull(mid.StrategyOptions); + Assert.IsNotNull(mid.BatchSize); + Assert.IsNotNull(mid.BatchCounter); + Assert.IsNotNull(mid.TighteningStatus); + Assert.IsNotNull(mid.BatchStatus); + Assert.IsNotNull(mid.TorqueStatus); + Assert.IsNotNull(mid.AngleStatus); + Assert.IsNotNull(mid.RundownAngleStatus); + Assert.IsNotNull(mid.CurrentMonitoringStatus); + Assert.IsNotNull(mid.SelftapStatus); + Assert.IsNotNull(mid.PrevailTorqueCompensateStatus); + Assert.IsNotNull(mid.TighteningErrorStatus); + Assert.IsNotNull(mid.TorqueMinLimit); + Assert.IsNotNull(mid.TorqueMaxLimit); + Assert.IsNotNull(mid.TorqueFinalTarget); + Assert.IsNotNull(mid.Torque); + Assert.IsNotNull(mid.AngleMinLimit); + Assert.IsNotNull(mid.AngleMaxLimit); + Assert.IsNotNull(mid.AngleFinalTarget); + Assert.IsNotNull(mid.Angle); + Assert.IsNotNull(mid.RundownAngle); + Assert.IsNotNull(mid.CurrentMonitoringMin); + Assert.IsNotNull(mid.CurrentMonitoringMax); + Assert.IsNotNull(mid.CurrentMonitoringValue); + Assert.IsNotNull(mid.SelftapMin); + Assert.IsNotNull(mid.SelftapMax); + Assert.IsNotNull(mid.SelftapTorque); + Assert.IsNotNull(mid.PrevailTorqueMonitoringMin); + Assert.IsNotNull(mid.PrevailTorqueMonitoringMax); + Assert.IsNotNull(mid.PrevailTorque); + Assert.IsNotNull(mid.TighteningId); + Assert.IsNotNull(mid.JobSequenceNumber); + Assert.IsNotNull(mid.SyncTighteningId); + Assert.IsNotNull(mid.ToolSerialNumber); + Assert.IsNotNull(mid.Timestamp); + Assert.IsNotNull(mid.LastChangeInParameterSet); + Assert.IsNotNull(mid.ParameterSetName); + Assert.IsNotNull(mid.TorqueValuesUnit); + Assert.IsNotNull(mid.ResultType); + Assert.IsNotNull(mid.IdentifierResultPart2); + Assert.IsNotNull(mid.IdentifierResultPart3); + Assert.IsNotNull(mid.IdentifierResultPart4); + Assert.IsNotNull(mid.CustomerTighteningErrorCode); + Assert.IsNotNull(mid.PrevailTorqueCompensateValue); + Assert.IsNotNull(mid.TighteningErrorStatus2); + Assert.IsNotNull(mid.CompensatedAngle); + Assert.IsNotNull(mid.FinalAngleDecimal); + Assert.AreNotEqual(0, mid.StartFinalAngle); + Assert.IsNotNull(mid.PostViewTorqueActivated); + Assert.AreNotEqual(0, mid.PostViewTorqueHigh); + Assert.AreNotEqual(0, mid.PostViewTorqueLow); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpere); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMin); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMax); + AssertEqualPackages(bytes, mid); + } + + [TestMethod] + [TestCategory("Revision 10"), TestCategory("ASCII")] + public void Mid0061Revision10() + { + var pack = "06620061010 010000020003RA ST6.2 ETV100 04 05000006001070208000670900001000001101221301401501611711811912000000081942100340022004600230040002400050525000202600420270000028000002900100300085031000043200033150340003500000036999900370000003800000039000000400000004100001848874200000430000044 C0761275452020-06-25:01:04:39462020-06-24:10:48:5347Test Parameter Set 482490550Identifier result part 2 51Identifier result part 3 52Identifier result part 4 53E124540015005500000000425600100005709999005800100059260652143610052326200100630005064001506500001660000167168-00206900100700012071003291720010057300011074009000"; + var mid = _midInterpreter.Parse(pack); + + Assert.AreEqual(typeof(Mid0061), mid.GetType()); + Assert.IsNotNull(mid.CellId); + Assert.IsNotNull(mid.ChannelId); + Assert.IsNotNull(mid.TorqueControllerName); + Assert.IsNotNull(mid.VinNumber); + Assert.IsNotNull(mid.JobId); + Assert.IsNotNull(mid.ParameterSetId); + Assert.IsNotNull(mid.Strategy); + Assert.IsNotNull(mid.StrategyOptions); + Assert.IsNotNull(mid.BatchSize); + Assert.IsNotNull(mid.BatchCounter); + Assert.IsNotNull(mid.TighteningStatus); + Assert.IsNotNull(mid.BatchStatus); + Assert.IsNotNull(mid.TorqueStatus); + Assert.IsNotNull(mid.AngleStatus); + Assert.IsNotNull(mid.RundownAngleStatus); + Assert.IsNotNull(mid.CurrentMonitoringStatus); + Assert.IsNotNull(mid.SelftapStatus); + Assert.IsNotNull(mid.PrevailTorqueCompensateStatus); + Assert.IsNotNull(mid.TighteningErrorStatus); + Assert.IsNotNull(mid.TorqueMinLimit); + Assert.IsNotNull(mid.TorqueMaxLimit); + Assert.IsNotNull(mid.TorqueFinalTarget); + Assert.IsNotNull(mid.Torque); + Assert.IsNotNull(mid.AngleMinLimit); + Assert.IsNotNull(mid.AngleMaxLimit); + Assert.IsNotNull(mid.AngleFinalTarget); + Assert.IsNotNull(mid.Angle); + Assert.IsNotNull(mid.RundownAngle); + Assert.IsNotNull(mid.CurrentMonitoringMin); + Assert.IsNotNull(mid.CurrentMonitoringMax); + Assert.IsNotNull(mid.CurrentMonitoringValue); + Assert.IsNotNull(mid.SelftapMin); + Assert.IsNotNull(mid.SelftapMax); + Assert.IsNotNull(mid.SelftapTorque); + Assert.IsNotNull(mid.PrevailTorqueMonitoringMin); + Assert.IsNotNull(mid.PrevailTorqueMonitoringMax); + Assert.IsNotNull(mid.PrevailTorque); + Assert.IsNotNull(mid.TighteningId); + Assert.IsNotNull(mid.JobSequenceNumber); + Assert.IsNotNull(mid.SyncTighteningId); + Assert.IsNotNull(mid.ToolSerialNumber); + Assert.IsNotNull(mid.Timestamp); + Assert.IsNotNull(mid.LastChangeInParameterSet); + Assert.IsNotNull(mid.ParameterSetName); + Assert.IsNotNull(mid.TorqueValuesUnit); + Assert.IsNotNull(mid.ResultType); + Assert.IsNotNull(mid.IdentifierResultPart2); + Assert.IsNotNull(mid.IdentifierResultPart3); + Assert.IsNotNull(mid.IdentifierResultPart4); + Assert.IsNotNull(mid.CustomerTighteningErrorCode); + Assert.IsNotNull(mid.PrevailTorqueCompensateValue); + Assert.IsNotNull(mid.TighteningErrorStatus2); + Assert.IsNotNull(mid.CompensatedAngle); + Assert.IsNotNull(mid.FinalAngleDecimal); + Assert.AreNotEqual(0, mid.StartFinalAngle); + Assert.IsNotNull(mid.PostViewTorqueActivated); + Assert.AreNotEqual(0, mid.PostViewTorqueHigh); + Assert.AreNotEqual(0, mid.PostViewTorqueLow); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpere); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMin); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMax); + Assert.AreNotEqual(0, mid.AngleNumeratorScaleFactor); + Assert.AreNotEqual(0, mid.AngleDenominatorScaleFactor); + Assert.IsNotNull(mid.OverallAngleStatus); + Assert.AreNotEqual(0, mid.OverallAngleMin); + Assert.AreNotEqual(0, mid.OverallAngleMax); + Assert.AreNotEqual(0, mid.OverallAngle); + Assert.AreNotEqual(0, mid.PeakTorque); + Assert.AreNotEqual(0, mid.ResidualBreakawayTorque); + Assert.AreNotEqual(0, mid.StartRundownAngle); + Assert.AreNotEqual(0, mid.RundownAngleComplete); + Assert.AreNotEqual(0, mid.OverallAngle); + + AssertEqualPackages(pack, mid); + } + + [TestMethod] + [TestCategory("Revision 10"), TestCategory("ByteArray")] + public void Mid0061ByteRevision10() + { + List bytes = new List(); + + var strategyOptions = new byte[] //5 bytes long + { + 0xAA, //1010 1010 + 0x03, //0000 0011 + 0x00, + 0x00, + 0x00 + }; + var tighteningErrorStatus = new byte[] //10 bytes long + { + 0xAA, //1010 1010 + 0x03, //0000 0011 + 0x0A, //0000 1010 + 0xD1, //1101 0001 + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00 + }; + + var tighteningErrorStatus2 = new byte[] //10 bytes long + { + 0xAA, //1010 1010 + 0x03, //0000 0011 + 0x02, //0000 0010 + 0x00, //Reserved from bit 19 to rest + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00 + }; + + string untilStrategyOptions = "06620061010 010001020103airbag7 04KPOL3456JKLO897 05000606003071208"; + bytes.AddRange(GetAsciiBytes(untilStrategyOptions)); + bytes.AddRange(GetAsciiBytes(strategyOptions, 5)); + + string untilTighteningErrorStatus = "09000010000011012013114015216117018219120"; + bytes.AddRange(GetAsciiBytes(untilTighteningErrorStatus)); + bytes.AddRange(GetAsciiBytes(tighteningErrorStatus, 10)); + + string untilTighteningErrorStatus2 = "2100084022001400230012002400073925000002609999270000028000002900000300999931050003200033050340453500001036000125370005483800001039999900405555004142949672954265500436053544ABCDEFG-123456452001-06-02:09:54:09462001-05-29:12:34:3347Test Parameter Set 482490550Identifier result part 2 51Identifier result part 3 52Identifier result part 4 53E1245400150055"; + bytes.AddRange(GetAsciiBytes(untilTighteningErrorStatus2)); + bytes.AddRange(GetAsciiBytes(tighteningErrorStatus2, 10)); + + string untilEnd = "5600100005709999005800100059260652143610052326200100630005064001506500001660000167168-00206900100700012071003291720010057300011074009000"; + bytes.AddRange(GetAsciiBytes(untilEnd)); + + var mid = _midInterpreter.Parse(bytes.ToArray()); + + Assert.AreEqual(typeof(Mid0061), mid.GetType()); + Assert.IsNotNull(mid.CellId); + Assert.IsNotNull(mid.ChannelId); + Assert.IsNotNull(mid.TorqueControllerName); + Assert.IsNotNull(mid.VinNumber); + Assert.IsNotNull(mid.JobId); + Assert.IsNotNull(mid.ParameterSetId); + Assert.IsNotNull(mid.Strategy); + Assert.IsNotNull(mid.StrategyOptions); + Assert.IsNotNull(mid.BatchSize); + Assert.IsNotNull(mid.BatchCounter); + Assert.IsNotNull(mid.TighteningStatus); + Assert.IsNotNull(mid.BatchStatus); + Assert.IsNotNull(mid.TorqueStatus); + Assert.IsNotNull(mid.AngleStatus); + Assert.IsNotNull(mid.RundownAngleStatus); + Assert.IsNotNull(mid.CurrentMonitoringStatus); + Assert.IsNotNull(mid.SelftapStatus); + Assert.IsNotNull(mid.PrevailTorqueCompensateStatus); + Assert.IsNotNull(mid.TighteningErrorStatus); + Assert.IsNotNull(mid.TorqueMinLimit); + Assert.IsNotNull(mid.TorqueMaxLimit); + Assert.IsNotNull(mid.TorqueFinalTarget); + Assert.IsNotNull(mid.Torque); + Assert.IsNotNull(mid.AngleMinLimit); + Assert.IsNotNull(mid.AngleMaxLimit); + Assert.IsNotNull(mid.AngleFinalTarget); + Assert.IsNotNull(mid.Angle); + Assert.IsNotNull(mid.RundownAngle); + Assert.IsNotNull(mid.CurrentMonitoringMin); + Assert.IsNotNull(mid.CurrentMonitoringMax); + Assert.IsNotNull(mid.CurrentMonitoringValue); + Assert.IsNotNull(mid.SelftapMin); + Assert.IsNotNull(mid.SelftapMax); + Assert.IsNotNull(mid.SelftapTorque); + Assert.IsNotNull(mid.PrevailTorqueMonitoringMin); + Assert.IsNotNull(mid.PrevailTorqueMonitoringMax); + Assert.IsNotNull(mid.PrevailTorque); + Assert.IsNotNull(mid.TighteningId); + Assert.IsNotNull(mid.JobSequenceNumber); + Assert.IsNotNull(mid.SyncTighteningId); + Assert.IsNotNull(mid.ToolSerialNumber); + Assert.IsNotNull(mid.Timestamp); + Assert.IsNotNull(mid.LastChangeInParameterSet); + Assert.IsNotNull(mid.ParameterSetName); + Assert.IsNotNull(mid.TorqueValuesUnit); + Assert.IsNotNull(mid.ResultType); + Assert.IsNotNull(mid.IdentifierResultPart2); + Assert.IsNotNull(mid.IdentifierResultPart3); + Assert.IsNotNull(mid.IdentifierResultPart4); + Assert.IsNotNull(mid.CustomerTighteningErrorCode); + Assert.IsNotNull(mid.PrevailTorqueCompensateValue); + Assert.IsNotNull(mid.TighteningErrorStatus2); + Assert.IsNotNull(mid.CompensatedAngle); + Assert.IsNotNull(mid.FinalAngleDecimal); + Assert.AreNotEqual(0, mid.StartFinalAngle); + Assert.IsNotNull(mid.PostViewTorqueActivated); + Assert.AreNotEqual(0, mid.PostViewTorqueHigh); + Assert.AreNotEqual(0, mid.PostViewTorqueLow); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpere); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMin); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMax); + Assert.AreNotEqual(0, mid.AngleNumeratorScaleFactor); + Assert.AreNotEqual(0, mid.AngleDenominatorScaleFactor); + Assert.IsNotNull(mid.OverallAngleStatus); + Assert.AreNotEqual(0, mid.OverallAngleMin); + Assert.AreNotEqual(0, mid.OverallAngleMax); + Assert.AreNotEqual(0, mid.OverallAngle); + Assert.AreNotEqual(0, mid.PeakTorque); + Assert.AreNotEqual(0, mid.ResidualBreakawayTorque); + Assert.AreNotEqual(0, mid.StartRundownAngle); + Assert.AreNotEqual(0, mid.RundownAngleComplete); + Assert.AreNotEqual(0, mid.OverallAngle); + AssertEqualPackages(bytes, mid); + } + + [TestMethod] + [TestCategory("Revision 11"), TestCategory("ASCII")] + public void Mid0061Revision11() + { + var pack = "06770061011 010000020003RA ST6.2 ETV100 04 05000006001070208000670900001000001101221301401501611711811912000000081942100340022004600230040002400050525000202600420270000028000002900100300085031000043200033150340003500000036999900370000003800000039000000400000004100001848874200000430000044 C0761275452020-06-25:01:04:39462020-06-24:10:48:5347Test Parameter Set 482490550Identifier result part 2 51Identifier result part 3 52Identifier result part 4 53E124540015005500000000425600100005709999005800100059260652143610052326200100630005064001506500001660000167168-00206900100700012071003291720010057300011074009000750001207600001"; + var mid = _midInterpreter.Parse(pack); + + Assert.AreEqual(typeof(Mid0061), mid.GetType()); + Assert.IsNotNull(mid.CellId); + Assert.IsNotNull(mid.ChannelId); + Assert.IsNotNull(mid.TorqueControllerName); + Assert.IsNotNull(mid.VinNumber); + Assert.IsNotNull(mid.JobId); + Assert.IsNotNull(mid.ParameterSetId); + Assert.IsNotNull(mid.Strategy); + Assert.IsNotNull(mid.StrategyOptions); + Assert.IsNotNull(mid.BatchSize); + Assert.IsNotNull(mid.BatchCounter); + Assert.IsNotNull(mid.TighteningStatus); + Assert.IsNotNull(mid.BatchStatus); + Assert.IsNotNull(mid.TorqueStatus); + Assert.IsNotNull(mid.AngleStatus); + Assert.IsNotNull(mid.RundownAngleStatus); + Assert.IsNotNull(mid.CurrentMonitoringStatus); + Assert.IsNotNull(mid.SelftapStatus); + Assert.IsNotNull(mid.PrevailTorqueCompensateStatus); + Assert.IsNotNull(mid.TighteningErrorStatus); + Assert.IsNotNull(mid.TorqueMinLimit); + Assert.IsNotNull(mid.TorqueMaxLimit); + Assert.IsNotNull(mid.TorqueFinalTarget); + Assert.IsNotNull(mid.Torque); + Assert.IsNotNull(mid.AngleMinLimit); + Assert.IsNotNull(mid.AngleMaxLimit); + Assert.IsNotNull(mid.AngleFinalTarget); + Assert.IsNotNull(mid.Angle); + Assert.IsNotNull(mid.RundownAngle); + Assert.IsNotNull(mid.CurrentMonitoringMin); + Assert.IsNotNull(mid.CurrentMonitoringMax); + Assert.IsNotNull(mid.CurrentMonitoringValue); + Assert.IsNotNull(mid.SelftapMin); + Assert.IsNotNull(mid.SelftapMax); + Assert.IsNotNull(mid.SelftapTorque); + Assert.IsNotNull(mid.PrevailTorqueMonitoringMin); + Assert.IsNotNull(mid.PrevailTorqueMonitoringMax); + Assert.IsNotNull(mid.PrevailTorque); + Assert.IsNotNull(mid.TighteningId); + Assert.IsNotNull(mid.JobSequenceNumber); + Assert.IsNotNull(mid.SyncTighteningId); + Assert.IsNotNull(mid.ToolSerialNumber); + Assert.IsNotNull(mid.Timestamp); + Assert.IsNotNull(mid.LastChangeInParameterSet); + Assert.IsNotNull(mid.ParameterSetName); + Assert.IsNotNull(mid.TorqueValuesUnit); + Assert.IsNotNull(mid.ResultType); + Assert.IsNotNull(mid.IdentifierResultPart2); + Assert.IsNotNull(mid.IdentifierResultPart3); + Assert.IsNotNull(mid.IdentifierResultPart4); + Assert.IsNotNull(mid.CustomerTighteningErrorCode); + Assert.IsNotNull(mid.PrevailTorqueCompensateValue); + Assert.IsNotNull(mid.TighteningErrorStatus2); + Assert.IsNotNull(mid.CompensatedAngle); + Assert.IsNotNull(mid.FinalAngleDecimal); + Assert.AreNotEqual(0, mid.StartFinalAngle); + Assert.IsNotNull(mid.PostViewTorqueActivated); + Assert.AreNotEqual(0, mid.PostViewTorqueHigh); + Assert.AreNotEqual(0, mid.PostViewTorqueLow); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpere); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMin); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMax); + Assert.AreNotEqual(0, mid.AngleNumeratorScaleFactor); + Assert.AreNotEqual(0, mid.AngleDenominatorScaleFactor); + Assert.IsNotNull(mid.OverallAngleStatus); + Assert.AreNotEqual(0, mid.OverallAngleMin); + Assert.AreNotEqual(0, mid.OverallAngleMax); + Assert.AreNotEqual(0, mid.OverallAngle); + Assert.AreNotEqual(0, mid.PeakTorque); + Assert.AreNotEqual(0, mid.ResidualBreakawayTorque); + Assert.AreNotEqual(0, mid.StartRundownAngle); + Assert.AreNotEqual(0, mid.RundownAngleComplete); + Assert.AreNotEqual(0, mid.OverallAngle); + Assert.AreNotEqual(0, mid.ClickTorque); + Assert.AreNotEqual(0, mid.ClickAngle); + AssertEqualPackages(pack, mid); + } + + [TestMethod] + [TestCategory("Revision 11"), TestCategory("ByteArray")] + public void Mid0061ByteRevision11() + { + List bytes = new List(); + + var strategyOptions = new byte[] //5 bytes long + { + 0xAA, //1010 1010 + 0x03, //0000 0011 + 0x00, + 0x00, + 0x00 + }; + var tighteningErrorStatus = new byte[] //10 bytes long + { + 0xAA, //1010 1010 + 0x03, //0000 0011 + 0x0A, //0000 1010 + 0xD1, //1101 0001 + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00 + }; + + var tighteningErrorStatus2 = new byte[] //10 bytes long + { + 0xAA, //1010 1010 + 0x03, //0000 0011 + 0x02, //0000 0010 + 0x00, //Reserved from bit 19 to rest + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00 + }; + + string untilStrategyOptions = "06770061011 010001020103airbag7 04KPOL3456JKLO897 05000606003071208"; + bytes.AddRange(GetAsciiBytes(untilStrategyOptions)); + bytes.AddRange(GetAsciiBytes(strategyOptions, 5)); + + string untilTighteningErrorStatus = "09000010000011012013114015216117018219120"; + bytes.AddRange(GetAsciiBytes(untilTighteningErrorStatus)); + bytes.AddRange(GetAsciiBytes(tighteningErrorStatus, 10)); + + string untilTighteningErrorStatus2 = "2100084022001400230012002400073925000002609999270000028000002900000300999931050003200033050340453500001036000125370005483800001039999900405555004142949672954265500436053544ABCDEFG-123456452001-06-02:09:54:09462001-05-29:12:34:3347Test Parameter Set 482490550Identifier result part 2 51Identifier result part 3 52Identifier result part 4 53E1245400150055"; + bytes.AddRange(GetAsciiBytes(untilTighteningErrorStatus2)); + bytes.AddRange(GetAsciiBytes(tighteningErrorStatus2, 10)); + + string untilEnd = "5600100005709999005800100059260652143610052326200100630005064001506500001660000167168-00206900100700012071003291720010057300011074009000750001207600001"; + bytes.AddRange(GetAsciiBytes(untilEnd)); + + var mid = _midInterpreter.Parse(bytes.ToArray()); + + Assert.AreEqual(typeof(Mid0061), mid.GetType()); + Assert.IsNotNull(mid.CellId); + Assert.IsNotNull(mid.ChannelId); + Assert.IsNotNull(mid.TorqueControllerName); + Assert.IsNotNull(mid.VinNumber); + Assert.IsNotNull(mid.JobId); + Assert.IsNotNull(mid.ParameterSetId); + Assert.IsNotNull(mid.Strategy); + Assert.IsNotNull(mid.StrategyOptions); + Assert.IsNotNull(mid.BatchSize); + Assert.IsNotNull(mid.BatchCounter); + Assert.IsNotNull(mid.TighteningStatus); + Assert.IsNotNull(mid.BatchStatus); + Assert.IsNotNull(mid.TorqueStatus); + Assert.IsNotNull(mid.AngleStatus); + Assert.IsNotNull(mid.RundownAngleStatus); + Assert.IsNotNull(mid.CurrentMonitoringStatus); + Assert.IsNotNull(mid.SelftapStatus); + Assert.IsNotNull(mid.PrevailTorqueCompensateStatus); + Assert.IsNotNull(mid.TighteningErrorStatus); + Assert.IsNotNull(mid.TorqueMinLimit); + Assert.IsNotNull(mid.TorqueMaxLimit); + Assert.IsNotNull(mid.TorqueFinalTarget); + Assert.IsNotNull(mid.Torque); + Assert.IsNotNull(mid.AngleMinLimit); + Assert.IsNotNull(mid.AngleMaxLimit); + Assert.IsNotNull(mid.AngleFinalTarget); + Assert.IsNotNull(mid.Angle); + Assert.IsNotNull(mid.RundownAngle); + Assert.IsNotNull(mid.CurrentMonitoringMin); + Assert.IsNotNull(mid.CurrentMonitoringMax); + Assert.IsNotNull(mid.CurrentMonitoringValue); + Assert.IsNotNull(mid.SelftapMin); + Assert.IsNotNull(mid.SelftapMax); + Assert.IsNotNull(mid.SelftapTorque); + Assert.IsNotNull(mid.PrevailTorqueMonitoringMin); + Assert.IsNotNull(mid.PrevailTorqueMonitoringMax); + Assert.IsNotNull(mid.PrevailTorque); + Assert.IsNotNull(mid.TighteningId); + Assert.IsNotNull(mid.JobSequenceNumber); + Assert.IsNotNull(mid.SyncTighteningId); + Assert.IsNotNull(mid.ToolSerialNumber); + Assert.IsNotNull(mid.Timestamp); + Assert.IsNotNull(mid.LastChangeInParameterSet); + Assert.IsNotNull(mid.ParameterSetName); + Assert.IsNotNull(mid.TorqueValuesUnit); + Assert.IsNotNull(mid.ResultType); + Assert.IsNotNull(mid.IdentifierResultPart2); + Assert.IsNotNull(mid.IdentifierResultPart3); + Assert.IsNotNull(mid.IdentifierResultPart4); + Assert.IsNotNull(mid.CustomerTighteningErrorCode); + Assert.IsNotNull(mid.PrevailTorqueCompensateValue); + Assert.IsNotNull(mid.TighteningErrorStatus2); + Assert.IsNotNull(mid.CompensatedAngle); + Assert.IsNotNull(mid.FinalAngleDecimal); + Assert.AreNotEqual(0, mid.StartFinalAngle); + Assert.IsNotNull(mid.PostViewTorqueActivated); + Assert.AreNotEqual(0, mid.PostViewTorqueHigh); + Assert.AreNotEqual(0, mid.PostViewTorqueLow); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpere); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMin); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMax); + Assert.AreNotEqual(0, mid.AngleNumeratorScaleFactor); + Assert.AreNotEqual(0, mid.AngleDenominatorScaleFactor); + Assert.IsNotNull(mid.OverallAngleStatus); + Assert.AreNotEqual(0, mid.OverallAngleMin); + Assert.AreNotEqual(0, mid.OverallAngleMax); + Assert.AreNotEqual(0, mid.OverallAngle); + Assert.AreNotEqual(0, mid.PeakTorque); + Assert.AreNotEqual(0, mid.ResidualBreakawayTorque); + Assert.AreNotEqual(0, mid.StartRundownAngle); + Assert.AreNotEqual(0, mid.RundownAngleComplete); + Assert.AreNotEqual(0, mid.OverallAngle); + Assert.AreNotEqual(0, mid.ClickTorque); + Assert.AreNotEqual(0, mid.ClickAngle); + AssertEqualPackages(bytes, mid); + } + [TestMethod] [TestCategory("Revision 998"), TestCategory("ASCII")] public void Mid0061Revision998() diff --git a/src/MIDTesters.Core/Tightening/TestMid0062.cs b/src/MIDTesters.Core/Tightening/TestMid0062.cs index 32947ea4..6a94ef1c 100644 --- a/src/MIDTesters.Core/Tightening/TestMid0062.cs +++ b/src/MIDTesters.Core/Tightening/TestMid0062.cs @@ -5,7 +5,7 @@ namespace MIDTesters.Tightening { [TestClass] [TestCategory("Tightening")] - public class TestMid0062 : MidTester + public class TestMid0062 : DefaultMidTests { [TestMethod] [TestCategory("ASCII")] diff --git a/src/MIDTesters.Core/Tightening/TestMid0063.cs b/src/MIDTesters.Core/Tightening/TestMid0063.cs index c2ff265c..5bd0437c 100644 --- a/src/MIDTesters.Core/Tightening/TestMid0063.cs +++ b/src/MIDTesters.Core/Tightening/TestMid0063.cs @@ -5,7 +5,7 @@ namespace MIDTesters.Tightening { [TestClass] [TestCategory("Tightening")] - public class TestMid0063 : MidTester + public class TestMid0063 : DefaultMidTests { [TestMethod] [TestCategory("ASCII")] diff --git a/src/MIDTesters.Core/Tightening/TestMid0064.cs b/src/MIDTesters.Core/Tightening/TestMid0064.cs index 9b464591..d34b0a55 100644 --- a/src/MIDTesters.Core/Tightening/TestMid0064.cs +++ b/src/MIDTesters.Core/Tightening/TestMid0064.cs @@ -5,7 +5,7 @@ namespace MIDTesters.Tightening { [TestClass] [TestCategory("Tightening")] - public class TestMid0064 : MidTester + public class TestMid0064 : DefaultMidTests { [TestMethod] [TestCategory("Revision 1"), TestCategory("ASCII")] @@ -31,5 +31,32 @@ public void Mid0064ByteRevision1() Assert.IsNotNull(mid.TighteningId); AssertEqualPackages(bytes, mid); } + + [TestMethod] + [TestCategory("Revision 10"), TestCategory("ASCII")] + public void Mid0064Revision10() + { + string package = "00310064010 01234567891"; + var mid = _midInterpreter.Parse(package); + + Assert.AreEqual(typeof(Mid0064), mid.GetType()); + Assert.IsNotNull(mid.TighteningId); + Assert.IsTrue(mid.OfflineResult); + AssertEqualPackages(package, mid); + } + + [TestMethod] + [TestCategory("Revision 10"), TestCategory("ByteArray")] + public void Mid0064ByteRevision10() + { + string package = "00310064010 01234567891"; + byte[] bytes = GetAsciiBytes(package); + var mid = _midInterpreter.Parse(bytes); + + Assert.AreEqual(typeof(Mid0064), mid.GetType()); + Assert.IsNotNull(mid.TighteningId); + Assert.IsTrue(mid.OfflineResult); + AssertEqualPackages(bytes, mid); + } } } diff --git a/src/MIDTesters.Core/Tightening/TestMid0065.cs b/src/MIDTesters.Core/Tightening/TestMid0065.cs index 5870b4e7..232307d5 100644 --- a/src/MIDTesters.Core/Tightening/TestMid0065.cs +++ b/src/MIDTesters.Core/Tightening/TestMid0065.cs @@ -6,7 +6,7 @@ namespace MIDTesters.Tightening { [TestClass] [TestCategory("Tightening")] - public class TestMid0065 : MidTester + public class TestMid0065 : DefaultMidTests { [TestMethod] [TestCategory("Revision 1"), TestCategory("ASCII")] @@ -963,5 +963,539 @@ public void Mid0065ByteRevision8() Assert.AreNotEqual(0, mid.PostViewTorqueLow); AssertEqualPackages(bytes, mid); } + + [TestMethod] + [TestCategory("Revision 9"), TestCategory("ASCII")] + public void Mid0065Revision9() + { + string package = @"04270065009 01012345678902AIRBAG 030001040020510060093807000008000009010011112013214115016217118000004189819001000200036021002502200223000215240010252500012266553527ABCDEFG-123 282019-01-05:09:00:05297300831Identifier result part 2 32Identifier result part 3 33Identifier result part 4 34E1243500510036000000004237429496729538Station Name 390010004024165214342005232430010044000504500150"; + var mid = _midInterpreter.Parse(package); + + Assert.AreEqual(typeof(Mid0065), mid.GetType()); + Assert.IsNotNull(mid.TighteningId); + Assert.IsNotNull(mid.VinNumber); + Assert.IsNotNull(mid.JobId); + Assert.IsNotNull(mid.ParameterSetId); + Assert.IsNotNull(mid.Strategy); + Assert.IsNotNull(mid.StrategyOptions); + Assert.IsNotNull(mid.BatchSize); + Assert.IsNotNull(mid.BatchCounter); + Assert.IsNotNull(mid.TighteningStatus); + Assert.IsNotNull(mid.BatchStatus); + Assert.IsNotNull(mid.TorqueStatus); + Assert.IsNotNull(mid.AngleStatus); + Assert.IsNotNull(mid.RundownAngleStatus); + Assert.IsNotNull(mid.CurrentMonitoringStatus); + Assert.IsNotNull(mid.SelftapStatus); + Assert.IsNotNull(mid.PrevailTorqueMonitoringStatus); + Assert.IsNotNull(mid.PrevailTorqueCompensateStatus); + Assert.IsNotNull(mid.TighteningErrorStatus); + Assert.IsNotNull(mid.Torque); + Assert.IsNotNull(mid.Angle); + Assert.IsNotNull(mid.RundownAngle); + Assert.IsNotNull(mid.CurrentMonitoringValue); + Assert.IsNotNull(mid.SelftapTorque); + Assert.IsNotNull(mid.JobSequenceNumber); + Assert.IsNotNull(mid.SyncTighteningId); + Assert.IsNotNull(mid.ToolSerialNumber); + Assert.IsNotNull(mid.Timestamp); + Assert.IsNotNull(mid.TorqueValuesUnit); + Assert.IsNotNull(mid.ResultType); + Assert.IsNotNull(mid.IdentifierResultPart2); + Assert.IsNotNull(mid.IdentifierResultPart3); + Assert.IsNotNull(mid.IdentifierResultPart4); + Assert.IsNotNull(mid.CustomerTighteningErrorCode); + Assert.IsNotNull(mid.PrevailTorqueCompensateValue); + Assert.IsNotNull(mid.TighteningErrorStatus2); + Assert.AreNotEqual(0, mid.StationId); + Assert.IsNotNull(mid.StationName); + Assert.AreNotEqual(0, mid.StartFinalAngle); + Assert.IsNotNull(mid.PostViewTorqueActivated); + Assert.AreNotEqual(0, mid.PostViewTorqueHigh); + Assert.AreNotEqual(0, mid.PostViewTorqueLow); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpere); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMin); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMax); + AssertEqualPackages(package, mid); + } + + [TestMethod] + [TestCategory("Revision 9"), TestCategory("ByteArray")] + public void Mid0065ByteRevision9() + { + List bytes = new List(); + + var strategyOptions = new byte[] //5 bytes long + { + 0xAA, //1010 1010 + 0x03, //0000 0011 + 0x00, + 0x00, + 0x00 + }; + + var tighteningErrorStatus = new byte[] //10 bytes long + { + 0xAA, //1010 1010 + 0x03, //0000 0011 + 0x0A, //0000 1010 + 0xD1, //1101 0001 + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00 + }; + + var tighteningErrorStatus2 = new byte[] //10 bytes long + { + 0x2A, //0010 1010 + 0x00, //Reserved from bit 7 to rest + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00 + }; + + string untilStrategy = @"04270065009 01012345678902AIRBAG 03000104002051006"; + bytes.AddRange(GetAsciiBytes(untilStrategy)); + bytes.AddRange(GetAsciiBytes(strategyOptions, 5)); + + string untilTighteningErrorStatus = "07000008000009010011112013214115016217118"; + bytes.AddRange(GetAsciiBytes(untilTighteningErrorStatus)); + bytes.AddRange(GetAsciiBytes(tighteningErrorStatus, 10)); + + string untilTighteningErrorStatus2 = "19001000200036021002502200223000215240010252500012266553527ABCDEFG-123 282019-01-05:09:00:05297300831Identifier result part 2 32Identifier result part 3 33Identifier result part 4 34E1243500510036"; + bytes.AddRange(GetAsciiBytes(untilTighteningErrorStatus2)); + bytes.AddRange(GetAsciiBytes(tighteningErrorStatus2, 10)); + + string untilEnd = "37429496729538Station Name 390010004024165214342005232430010044000504500150"; + bytes.AddRange(GetAsciiBytes(untilEnd)); + var mid = _midInterpreter.Parse(bytes.ToArray()); + + Assert.AreEqual(typeof(Mid0065), mid.GetType()); + Assert.IsNotNull(mid.TighteningId); + Assert.IsNotNull(mid.VinNumber); + Assert.IsNotNull(mid.JobId); + Assert.IsNotNull(mid.ParameterSetId); + Assert.IsNotNull(mid.Strategy); + Assert.IsNotNull(mid.StrategyOptions); + Assert.IsNotNull(mid.BatchSize); + Assert.IsNotNull(mid.BatchCounter); + Assert.IsNotNull(mid.TighteningStatus); + Assert.IsNotNull(mid.BatchStatus); + Assert.IsNotNull(mid.TorqueStatus); + Assert.IsNotNull(mid.AngleStatus); + Assert.IsNotNull(mid.RundownAngleStatus); + Assert.IsNotNull(mid.CurrentMonitoringStatus); + Assert.IsNotNull(mid.SelftapStatus); + Assert.IsNotNull(mid.PrevailTorqueMonitoringStatus); + Assert.IsNotNull(mid.PrevailTorqueCompensateStatus); + Assert.IsNotNull(mid.TighteningErrorStatus); + Assert.IsNotNull(mid.Torque); + Assert.IsNotNull(mid.Angle); + Assert.IsNotNull(mid.RundownAngle); + Assert.IsNotNull(mid.CurrentMonitoringValue); + Assert.IsNotNull(mid.SelftapTorque); + Assert.IsNotNull(mid.JobSequenceNumber); + Assert.IsNotNull(mid.SyncTighteningId); + Assert.IsNotNull(mid.ToolSerialNumber); + Assert.IsNotNull(mid.Timestamp); + Assert.IsNotNull(mid.TorqueValuesUnit); + Assert.IsNotNull(mid.ResultType); + Assert.IsNotNull(mid.IdentifierResultPart2); + Assert.IsNotNull(mid.IdentifierResultPart3); + Assert.IsNotNull(mid.IdentifierResultPart4); + Assert.IsNotNull(mid.CustomerTighteningErrorCode); + Assert.IsNotNull(mid.PrevailTorqueCompensateValue); + Assert.IsNotNull(mid.TighteningErrorStatus2); + Assert.AreNotEqual(0, mid.StationId); + Assert.IsNotNull(mid.StationName); + Assert.AreNotEqual(0, mid.StartFinalAngle); + Assert.IsNotNull(mid.PostViewTorqueActivated); + Assert.AreNotEqual(0, mid.PostViewTorqueHigh); + Assert.AreNotEqual(0, mid.PostViewTorqueLow); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpere); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMin); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMax); + AssertEqualPackages(bytes, mid); + } + + [TestMethod] + [TestCategory("Revision 10"), TestCategory("ASCII")] + public void Mid0065Revision10() + { + string pack = @"04970065010 01012345678902AIRBAG 030001040020510060093807000008000009010011112013214115016217118000004189819001000200036021002502200223000215240010252500012266553527ABCDEFG-123 282019-01-05:09:00:05297300831Identifier result part 2 32Identifier result part 3 33Identifier result part 4 34E1243500510036000000004237429496729538Station Name 3900100040241652143420052324300100440005045001504600001470000148149-00205000100510012052003291530010055400011055009000"; + var mid = _midInterpreter.Parse(pack); + + Assert.AreEqual(typeof(Mid0065), mid.GetType()); + Assert.IsNotNull(mid.TighteningId); + Assert.IsNotNull(mid.VinNumber); + Assert.IsNotNull(mid.JobId); + Assert.IsNotNull(mid.ParameterSetId); + Assert.IsNotNull(mid.Strategy); + Assert.IsNotNull(mid.StrategyOptions); + Assert.IsNotNull(mid.BatchSize); + Assert.IsNotNull(mid.BatchCounter); + Assert.IsNotNull(mid.TighteningStatus); + Assert.IsNotNull(mid.BatchStatus); + Assert.IsNotNull(mid.TorqueStatus); + Assert.IsNotNull(mid.AngleStatus); + Assert.IsNotNull(mid.RundownAngleStatus); + Assert.IsNotNull(mid.CurrentMonitoringStatus); + Assert.IsNotNull(mid.SelftapStatus); + Assert.IsNotNull(mid.PrevailTorqueMonitoringStatus); + Assert.IsNotNull(mid.PrevailTorqueCompensateStatus); + Assert.IsNotNull(mid.TighteningErrorStatus); + Assert.IsNotNull(mid.Torque); + Assert.IsNotNull(mid.Angle); + Assert.IsNotNull(mid.RundownAngle); + Assert.IsNotNull(mid.CurrentMonitoringValue); + Assert.IsNotNull(mid.SelftapTorque); + Assert.IsNotNull(mid.JobSequenceNumber); + Assert.IsNotNull(mid.SyncTighteningId); + Assert.IsNotNull(mid.ToolSerialNumber); + Assert.IsNotNull(mid.Timestamp); + Assert.IsNotNull(mid.TorqueValuesUnit); + Assert.IsNotNull(mid.ResultType); + Assert.IsNotNull(mid.IdentifierResultPart2); + Assert.IsNotNull(mid.IdentifierResultPart3); + Assert.IsNotNull(mid.IdentifierResultPart4); + Assert.IsNotNull(mid.CustomerTighteningErrorCode); + Assert.IsNotNull(mid.PrevailTorqueCompensateValue); + Assert.IsNotNull(mid.TighteningErrorStatus2); + Assert.AreNotEqual(0, mid.StationId); + Assert.IsNotNull(mid.StationName); + Assert.AreNotEqual(0, mid.StartFinalAngle); + Assert.IsNotNull(mid.PostViewTorqueActivated); + Assert.AreNotEqual(0, mid.PostViewTorqueHigh); + Assert.AreNotEqual(0, mid.PostViewTorqueLow); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpere); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMin); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMax); + Assert.AreNotEqual(0, mid.AngleNumeratorScaleFactor); + Assert.AreNotEqual(0, mid.AngleDenominatorScaleFactor); + Assert.IsNotNull(mid.OverallAngleStatus); + Assert.AreNotEqual(0, mid.OverallAngleMin); + Assert.AreNotEqual(0, mid.OverallAngleMax); + Assert.AreNotEqual(0, mid.OverallAngle); + Assert.AreNotEqual(0, mid.PeakTorque); + Assert.AreNotEqual(0, mid.ResidualBreakawayTorque); + Assert.AreNotEqual(0, mid.StartRundownAngle); + Assert.AreNotEqual(0, mid.RundownAngleComplete); + + AssertEqualPackages(pack, mid); + } + + [TestMethod] + [TestCategory("Revision 10"), TestCategory("ByteArray")] + public void Mid0065ByteRevision10() + { + List bytes = new List(); + + var strategyOptions = new byte[] //5 bytes long + { + 0xAA, //1010 1010 + 0x03, //0000 0011 + 0x00, + 0x00, + 0x00 + }; + + var tighteningErrorStatus = new byte[] //10 bytes long + { + 0xAA, //1010 1010 + 0x03, //0000 0011 + 0x0A, //0000 1010 + 0xD1, //1101 0001 + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00 + }; + + var tighteningErrorStatus2 = new byte[] //10 bytes long + { + 0x2A, //0010 1010 + 0x00, //Reserved from bit 7 to rest + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00 + }; + + string untilStrategy = @"04970065010 01012345678902AIRBAG 03000104002051006"; + bytes.AddRange(GetAsciiBytes(untilStrategy)); + bytes.AddRange(GetAsciiBytes(strategyOptions, 5)); + + string untilTighteningErrorStatus = "07000008000009010011112013214115016217118"; + bytes.AddRange(GetAsciiBytes(untilTighteningErrorStatus)); + bytes.AddRange(GetAsciiBytes(tighteningErrorStatus, 10)); + + string untilTighteningErrorStatus2 = "19001000200036021002502200223000215240010252500012266553527ABCDEFG-123 282019-01-05:09:00:05297300831Identifier result part 2 32Identifier result part 3 33Identifier result part 4 34E1243500510036"; + bytes.AddRange(GetAsciiBytes(untilTighteningErrorStatus2)); + bytes.AddRange(GetAsciiBytes(tighteningErrorStatus2, 10)); + + string untilEnd = "37429496729538Station Name 3900100040241652143420052324300100440005045001504600001470000148149-00205000100510012052003291530010055400011055009000"; + bytes.AddRange(GetAsciiBytes(untilEnd)); + var mid = _midInterpreter.Parse(bytes.ToArray()); + + Assert.AreEqual(typeof(Mid0065), mid.GetType()); + Assert.IsNotNull(mid.TighteningId); + Assert.IsNotNull(mid.VinNumber); + Assert.IsNotNull(mid.JobId); + Assert.IsNotNull(mid.ParameterSetId); + Assert.IsNotNull(mid.Strategy); + Assert.IsNotNull(mid.StrategyOptions); + Assert.IsNotNull(mid.BatchSize); + Assert.IsNotNull(mid.BatchCounter); + Assert.IsNotNull(mid.TighteningStatus); + Assert.IsNotNull(mid.BatchStatus); + Assert.IsNotNull(mid.TorqueStatus); + Assert.IsNotNull(mid.AngleStatus); + Assert.IsNotNull(mid.RundownAngleStatus); + Assert.IsNotNull(mid.CurrentMonitoringStatus); + Assert.IsNotNull(mid.SelftapStatus); + Assert.IsNotNull(mid.PrevailTorqueMonitoringStatus); + Assert.IsNotNull(mid.PrevailTorqueCompensateStatus); + Assert.IsNotNull(mid.TighteningErrorStatus); + Assert.IsNotNull(mid.Torque); + Assert.IsNotNull(mid.Angle); + Assert.IsNotNull(mid.RundownAngle); + Assert.IsNotNull(mid.CurrentMonitoringValue); + Assert.IsNotNull(mid.SelftapTorque); + Assert.IsNotNull(mid.JobSequenceNumber); + Assert.IsNotNull(mid.SyncTighteningId); + Assert.IsNotNull(mid.ToolSerialNumber); + Assert.IsNotNull(mid.Timestamp); + Assert.IsNotNull(mid.TorqueValuesUnit); + Assert.IsNotNull(mid.ResultType); + Assert.IsNotNull(mid.IdentifierResultPart2); + Assert.IsNotNull(mid.IdentifierResultPart3); + Assert.IsNotNull(mid.IdentifierResultPart4); + Assert.IsNotNull(mid.CustomerTighteningErrorCode); + Assert.IsNotNull(mid.PrevailTorqueCompensateValue); + Assert.IsNotNull(mid.TighteningErrorStatus2); + Assert.AreNotEqual(0, mid.StationId); + Assert.IsNotNull(mid.StationName); + Assert.AreNotEqual(0, mid.StartFinalAngle); + Assert.IsNotNull(mid.PostViewTorqueActivated); + Assert.AreNotEqual(0, mid.PostViewTorqueHigh); + Assert.AreNotEqual(0, mid.PostViewTorqueLow); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpere); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMin); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMax); + Assert.AreNotEqual(0, mid.AngleNumeratorScaleFactor); + Assert.AreNotEqual(0, mid.AngleDenominatorScaleFactor); + Assert.IsNotNull(mid.OverallAngleStatus); + Assert.AreNotEqual(0, mid.OverallAngleMin); + Assert.AreNotEqual(0, mid.OverallAngleMax); + Assert.AreNotEqual(0, mid.OverallAngle); + Assert.AreNotEqual(0, mid.PeakTorque); + Assert.AreNotEqual(0, mid.ResidualBreakawayTorque); + Assert.AreNotEqual(0, mid.StartRundownAngle); + Assert.AreNotEqual(0, mid.RundownAngleComplete); + + AssertEqualPackages(bytes, mid); + } + + [TestMethod] + [TestCategory("Revision 11"), TestCategory("ASCII")] + public void Mid0065Revision11() + { + string pack = @"05120065011 01012345678902AIRBAG 030001040020510060093807000008000009010011112013214115016217118000004189819001000200036021002502200223000215240010252500012266553527ABCDEFG-123 282019-01-05:09:00:05297300831Identifier result part 2 32Identifier result part 3 33Identifier result part 4 34E1243500510036000000004237429496729538Station Name 3900100040241652143420052324300100440005045001504600001470000148149-00205000100510012052003291530010055400011055009000560001205700001"; + var mid = _midInterpreter.Parse(pack); + + Assert.AreEqual(typeof(Mid0065), mid.GetType()); + Assert.IsNotNull(mid.TighteningId); + Assert.IsNotNull(mid.VinNumber); + Assert.IsNotNull(mid.JobId); + Assert.IsNotNull(mid.ParameterSetId); + Assert.IsNotNull(mid.Strategy); + Assert.IsNotNull(mid.StrategyOptions); + Assert.IsNotNull(mid.BatchSize); + Assert.IsNotNull(mid.BatchCounter); + Assert.IsNotNull(mid.TighteningStatus); + Assert.IsNotNull(mid.BatchStatus); + Assert.IsNotNull(mid.TorqueStatus); + Assert.IsNotNull(mid.AngleStatus); + Assert.IsNotNull(mid.RundownAngleStatus); + Assert.IsNotNull(mid.CurrentMonitoringStatus); + Assert.IsNotNull(mid.SelftapStatus); + Assert.IsNotNull(mid.PrevailTorqueMonitoringStatus); + Assert.IsNotNull(mid.PrevailTorqueCompensateStatus); + Assert.IsNotNull(mid.TighteningErrorStatus); + Assert.IsNotNull(mid.Torque); + Assert.IsNotNull(mid.Angle); + Assert.IsNotNull(mid.RundownAngle); + Assert.IsNotNull(mid.CurrentMonitoringValue); + Assert.IsNotNull(mid.SelftapTorque); + Assert.IsNotNull(mid.JobSequenceNumber); + Assert.IsNotNull(mid.SyncTighteningId); + Assert.IsNotNull(mid.ToolSerialNumber); + Assert.IsNotNull(mid.Timestamp); + Assert.IsNotNull(mid.TorqueValuesUnit); + Assert.IsNotNull(mid.ResultType); + Assert.IsNotNull(mid.IdentifierResultPart2); + Assert.IsNotNull(mid.IdentifierResultPart3); + Assert.IsNotNull(mid.IdentifierResultPart4); + Assert.IsNotNull(mid.CustomerTighteningErrorCode); + Assert.IsNotNull(mid.PrevailTorqueCompensateValue); + Assert.IsNotNull(mid.TighteningErrorStatus2); + Assert.AreNotEqual(0, mid.StationId); + Assert.IsNotNull(mid.StationName); + Assert.AreNotEqual(0, mid.StartFinalAngle); + Assert.IsNotNull(mid.PostViewTorqueActivated); + Assert.AreNotEqual(0, mid.PostViewTorqueHigh); + Assert.AreNotEqual(0, mid.PostViewTorqueLow); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpere); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMin); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMax); + Assert.AreNotEqual(0, mid.AngleNumeratorScaleFactor); + Assert.AreNotEqual(0, mid.AngleDenominatorScaleFactor); + Assert.IsNotNull(mid.OverallAngleStatus); + Assert.AreNotEqual(0, mid.OverallAngleMin); + Assert.AreNotEqual(0, mid.OverallAngleMax); + Assert.AreNotEqual(0, mid.OverallAngle); + Assert.AreNotEqual(0, mid.PeakTorque); + Assert.AreNotEqual(0, mid.ResidualBreakawayTorque); + Assert.AreNotEqual(0, mid.StartRundownAngle); + Assert.AreNotEqual(0, mid.RundownAngleComplete); + Assert.AreNotEqual(0, mid.ClickTorque); + Assert.AreNotEqual(0, mid.ClickAngle); + + AssertEqualPackages(pack, mid); + } + + [TestMethod] + [TestCategory("Revision 11"), TestCategory("ByteArray")] + public void Mid0065ByteRevision11() + { + List bytes = new List(); + + var strategyOptions = new byte[] //5 bytes long + { + 0xAA, //1010 1010 + 0x03, //0000 0011 + 0x00, + 0x00, + 0x00 + }; + + var tighteningErrorStatus = new byte[] //10 bytes long + { + 0xAA, //1010 1010 + 0x03, //0000 0011 + 0x0A, //0000 1010 + 0xD1, //1101 0001 + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00 + }; + + var tighteningErrorStatus2 = new byte[] //10 bytes long + { + 0x2A, //0010 1010 + 0x00, //Reserved from bit 7 to rest + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00 + }; + + string untilStrategy = @"05120065011 01012345678902AIRBAG 03000104002051006"; + bytes.AddRange(GetAsciiBytes(untilStrategy)); + bytes.AddRange(GetAsciiBytes(strategyOptions, 5)); + + string untilTighteningErrorStatus = "07000008000009010011112013214115016217118"; + bytes.AddRange(GetAsciiBytes(untilTighteningErrorStatus)); + bytes.AddRange(GetAsciiBytes(tighteningErrorStatus, 10)); + + string untilTighteningErrorStatus2 = "19001000200036021002502200223000215240010252500012266553527ABCDEFG-123 282019-01-05:09:00:05297300831Identifier result part 2 32Identifier result part 3 33Identifier result part 4 34E1243500510036"; + bytes.AddRange(GetAsciiBytes(untilTighteningErrorStatus2)); + bytes.AddRange(GetAsciiBytes(tighteningErrorStatus2, 10)); + + string untilEnd = "37429496729538Station Name 3900100040241652143420052324300100440005045001504600001470000148149-00205000100510012052003291530010055400011055009000560001205700001"; + bytes.AddRange(GetAsciiBytes(untilEnd)); + var mid = _midInterpreter.Parse(bytes.ToArray()); + + Assert.AreEqual(typeof(Mid0065), mid.GetType()); + Assert.IsNotNull(mid.TighteningId); + Assert.IsNotNull(mid.VinNumber); + Assert.IsNotNull(mid.JobId); + Assert.IsNotNull(mid.ParameterSetId); + Assert.IsNotNull(mid.Strategy); + Assert.IsNotNull(mid.StrategyOptions); + Assert.IsNotNull(mid.BatchSize); + Assert.IsNotNull(mid.BatchCounter); + Assert.IsNotNull(mid.TighteningStatus); + Assert.IsNotNull(mid.BatchStatus); + Assert.IsNotNull(mid.TorqueStatus); + Assert.IsNotNull(mid.AngleStatus); + Assert.IsNotNull(mid.RundownAngleStatus); + Assert.IsNotNull(mid.CurrentMonitoringStatus); + Assert.IsNotNull(mid.SelftapStatus); + Assert.IsNotNull(mid.PrevailTorqueMonitoringStatus); + Assert.IsNotNull(mid.PrevailTorqueCompensateStatus); + Assert.IsNotNull(mid.TighteningErrorStatus); + Assert.IsNotNull(mid.Torque); + Assert.IsNotNull(mid.Angle); + Assert.IsNotNull(mid.RundownAngle); + Assert.IsNotNull(mid.CurrentMonitoringValue); + Assert.IsNotNull(mid.SelftapTorque); + Assert.IsNotNull(mid.JobSequenceNumber); + Assert.IsNotNull(mid.SyncTighteningId); + Assert.IsNotNull(mid.ToolSerialNumber); + Assert.IsNotNull(mid.Timestamp); + Assert.IsNotNull(mid.TorqueValuesUnit); + Assert.IsNotNull(mid.ResultType); + Assert.IsNotNull(mid.IdentifierResultPart2); + Assert.IsNotNull(mid.IdentifierResultPart3); + Assert.IsNotNull(mid.IdentifierResultPart4); + Assert.IsNotNull(mid.CustomerTighteningErrorCode); + Assert.IsNotNull(mid.PrevailTorqueCompensateValue); + Assert.IsNotNull(mid.TighteningErrorStatus2); + Assert.AreNotEqual(0, mid.StationId); + Assert.IsNotNull(mid.StationName); + Assert.AreNotEqual(0, mid.StartFinalAngle); + Assert.IsNotNull(mid.PostViewTorqueActivated); + Assert.AreNotEqual(0, mid.PostViewTorqueHigh); + Assert.AreNotEqual(0, mid.PostViewTorqueLow); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpere); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMin); + Assert.AreNotEqual(0, mid.CurrentMonitoringAmpereMax); + Assert.AreNotEqual(0, mid.AngleNumeratorScaleFactor); + Assert.AreNotEqual(0, mid.AngleDenominatorScaleFactor); + Assert.IsNotNull(mid.OverallAngleStatus); + Assert.AreNotEqual(0, mid.OverallAngleMin); + Assert.AreNotEqual(0, mid.OverallAngleMax); + Assert.AreNotEqual(0, mid.OverallAngle); + Assert.AreNotEqual(0, mid.PeakTorque); + Assert.AreNotEqual(0, mid.ResidualBreakawayTorque); + Assert.AreNotEqual(0, mid.StartRundownAngle); + Assert.AreNotEqual(0, mid.RundownAngleComplete); + Assert.AreNotEqual(0, mid.ClickTorque); + Assert.AreNotEqual(0, mid.ClickAngle); + + AssertEqualPackages(bytes, mid); + } } } diff --git a/src/MIDTesters.Core/Tightening/TestMid0066.cs b/src/MIDTesters.Core/Tightening/TestMid0066.cs index 537e818d..028c59dd 100644 --- a/src/MIDTesters.Core/Tightening/TestMid0066.cs +++ b/src/MIDTesters.Core/Tightening/TestMid0066.cs @@ -5,13 +5,13 @@ namespace MIDTesters.Tightening { [TestClass] [TestCategory("Tightening")] - public class TestMid0066 : MidTester + public class TestMid0066 : DefaultMidTests { [TestMethod] [TestCategory("Revision 1"), TestCategory("ASCII")] public void Mid0066Revision1() { - string package = "00220066001 14"; + string package = "00240066001 0114"; var mid = _midInterpreter.Parse(package); Assert.AreEqual(typeof(Mid0066), mid.GetType()); @@ -24,7 +24,7 @@ public void Mid0066Revision1() [TestCategory("Revision 1"), TestCategory("ByteArray")] public void Mid0066ByteRevision1() { - string package = "00220066001 14"; + string package = "00240066001 0114"; byte[] bytes = GetAsciiBytes(package); var mid = _midInterpreter.Parse(bytes); @@ -33,5 +33,36 @@ public void Mid0066ByteRevision1() Assert.AreEqual(14, mid.NumberOfOfflineResults); AssertEqualPackages(package, mid); } + + [TestMethod] + [TestCategory("Revision 2"), TestCategory("ASCII")] + public void Mid0066Revision2() + { + string package = "00300066002 0101402011"; + var mid = _midInterpreter.Parse(package); + + Assert.AreEqual(typeof(Mid0066), mid.GetType()); + Assert.IsNotNull(mid.NumberOfOfflineResults); + Assert.IsNotNull(mid.NumberOfOfflineCurves); + Assert.AreEqual(14, mid.NumberOfOfflineResults); + Assert.AreEqual(11, mid.NumberOfOfflineCurves); + AssertEqualPackages(package, mid); + } + + [TestMethod] + [TestCategory("Revision 2"), TestCategory("ByteArray")] + public void Mid0066ByteRevision2() + { + string package = "00300066002 0101402011"; + byte[] bytes = GetAsciiBytes(package); + var mid = _midInterpreter.Parse(bytes); + + Assert.AreEqual(typeof(Mid0066), mid.GetType()); + Assert.IsNotNull(mid.NumberOfOfflineResults); + Assert.IsNotNull(mid.NumberOfOfflineCurves); + Assert.AreEqual(14, mid.NumberOfOfflineResults); + Assert.AreEqual(11, mid.NumberOfOfflineCurves); + AssertEqualPackages(package, mid); + } } } diff --git a/src/MIDTesters.Core/Tightening/TestMid0902.cs b/src/MIDTesters.Core/Tightening/TestMid0902.cs new file mode 100644 index 00000000..2817a036 --- /dev/null +++ b/src/MIDTesters.Core/Tightening/TestMid0902.cs @@ -0,0 +1,49 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenProtocolInterpreter.Tightening; + +namespace MIDTesters.Core.Tightening +{ + [TestClass] + [TestCategory("Tightening")] + public class TestMid0902 : DefaultMidTests + { + [TestMethod] + [TestCategory("Revision 1"), TestCategory("ASCII")] + public void Mid0902Revision1() + { + string package = "01450902001 000000213400000000012022-12-21:13:02:3300000058192023-12-10:12:28:54002000050010600000001000100190500000002023-11-09:18:48:14"; + var mid = _midInterpreter.Parse(package); + + Assert.AreEqual(typeof(Mid0902), mid.GetType()); + Assert.AreNotEqual(0, mid.Capacity); + Assert.AreNotEqual(0, mid.OldestSequenceNumber); + Assert.IsNotNull(mid.OldestTime); + Assert.AreNotEqual(0, mid.NewestSequenceNumber); + Assert.IsNotNull(mid.NewestTime); + Assert.AreNotEqual(0, mid.NumberOfPIDs); + Assert.IsNotNull(mid.VariableDataFields); + Assert.AreNotEqual(0, mid.VariableDataFields.Count); + AssertEqualPackages(package, mid); + } + + [TestMethod] + [TestCategory("Revision 1"), TestCategory("ByteArray")] + public void Mid0902ByteRevision1() + { + string package = "01450902001 000000213400000000012022-12-21:13:02:3300000058192023-12-10:12:28:54002000050010600000001000100190500000002023-11-09:18:48:14"; + byte[] bytes = GetAsciiBytes(package); + var mid = _midInterpreter.Parse(bytes); + + Assert.AreEqual(typeof(Mid0902), mid.GetType()); + Assert.AreNotEqual(0, mid.Capacity); + Assert.AreNotEqual(0, mid.OldestSequenceNumber); + Assert.IsNotNull(mid.OldestTime); + Assert.AreNotEqual(0, mid.NewestSequenceNumber); + Assert.IsNotNull(mid.NewestTime); + Assert.AreNotEqual(0, mid.NumberOfPIDs); + Assert.IsNotNull(mid.VariableDataFields); + Assert.AreNotEqual(0, mid.VariableDataFields.Count); + AssertEqualPackages(package, mid); + } + } +} diff --git a/src/MIDTesters.Core/Tool/TestMid0704.cs b/src/MIDTesters.Core/Tool/TestMid0704.cs new file mode 100644 index 00000000..09fc5eb5 --- /dev/null +++ b/src/MIDTesters.Core/Tool/TestMid0704.cs @@ -0,0 +1,37 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenProtocolInterpreter.Tool; + +namespace MIDTesters.Core.Tool +{ + [TestClass] + [TestCategory("Tool")] + public class TestMid0704 : DefaultMidTests + { + [TestMethod] + [TestCategory("Revision 1"), TestCategory("ASCII")] + public void Mid0704Revision1() + { + string package = "00700704001 00201200012040000000QST50-150CTT012150010200000003"; + var mid = _midInterpreter.Parse(package); + + Assert.AreNotEqual(0, mid.NumberOfDataFields); + Assert.IsNotNull(mid.VariableDataFields); + Assert.AreNotEqual(0, mid.VariableDataFields.Count); + AssertEqualPackages(package, mid); + } + + [TestMethod] + [TestCategory("Revision 1"), TestCategory("ByteArray")] + public void Mid0704ByteRevision1() + { + string package = "00700704001 00201200012040000000QST50-150CTT012150010200000003"; + byte[] bytes = GetAsciiBytes(package); + var mid = _midInterpreter.Parse(bytes); + + Assert.AreNotEqual(0, mid.NumberOfDataFields); + Assert.IsNotNull(mid.VariableDataFields); + Assert.AreNotEqual(0, mid.VariableDataFields.Count); + AssertEqualPackages(bytes, mid); + } + } +} diff --git a/src/OpenProtocolInterpreter/Alarm/Mid0071.cs b/src/OpenProtocolInterpreter/Alarm/Mid0071.cs index 5d19f702..65491f21 100644 --- a/src/OpenProtocolInterpreter/Alarm/Mid0071.cs +++ b/src/OpenProtocolInterpreter/Alarm/Mid0071.cs @@ -15,29 +15,29 @@ public class Mid0071 : Mid, IAlarm, IController, IAcknowledgeable public string ErrorCode { - get => GetField(1, (int)DataFields.ErrorCode).Value; - set => GetField(1, (int)DataFields.ErrorCode).SetValue(value); + get => GetField(1, DataFields.ErrorCode).Value; + set => GetField(1, DataFields.ErrorCode).SetValue(value); } public bool ControllerReadyStatus { - get => GetField(1, (int)DataFields.ControllerReadyStatus).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.ControllerReadyStatus).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ControllerReadyStatus).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.ControllerReadyStatus).SetValue(OpenProtocolConvert.ToString, value); } public bool ToolReadyStatus { - get => GetField(1, (int)DataFields.ToolReadyStatus).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.ToolReadyStatus).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ToolReadyStatus).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.ToolReadyStatus).SetValue(OpenProtocolConvert.ToString, value); } public DateTime Time { - get => GetField(1, (int)DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(1, (int)DataFields.Time).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(1, DataFields.Time).SetValue(OpenProtocolConvert.ToString, value); } //Rev 2 public string AlarmText { - get => GetField(2, (int)DataFields.AlarmText).Value; - set => GetField(2, (int)DataFields.AlarmText).SetValue(value); + get => GetField(2, DataFields.AlarmText).Value; + set => GetField(2, DataFields.AlarmText).SetValue(value); } public Mid0071() : this(DEFAULT_REVISION) @@ -74,16 +74,16 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ErrorCode, 20, 4, ' ', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ControllerReadyStatus, 26, 1), - new DataField((int)DataFields.ToolReadyStatus, 29, 1, ' '), - new DataField((int)DataFields.Time, 32, 19) + DataField.String(DataFields.ErrorCode, 20, 4, PaddingOrientation.LeftPadded), + DataField.Boolean(DataFields.ControllerReadyStatus, 26), + DataField.Boolean(DataFields.ToolReadyStatus, 29), + DataField.Timestamp(DataFields.Time, 32) } }, { 2, new List() { - new DataField((int)DataFields.AlarmText, 54, 50, ' '), + DataField.String(DataFields.AlarmText, 54, 50), } } }; @@ -102,7 +102,7 @@ private void HandleRevision() } int index = errorCodeField.Index + errorCodeField.Size; - for (int i = (int)DataFields.ControllerReadyStatus; i < RevisionsByFields[1].Count; i++) + for (int i = DataFields.ControllerReadyStatus.GetHashCode(); i < RevisionsByFields[1].Count; i++) { var field = GetField(1, i); field.Index = 2 + index; diff --git a/src/OpenProtocolInterpreter/Alarm/Mid0074.cs b/src/OpenProtocolInterpreter/Alarm/Mid0074.cs index b5fb2ee0..239f3eaf 100644 --- a/src/OpenProtocolInterpreter/Alarm/Mid0074.cs +++ b/src/OpenProtocolInterpreter/Alarm/Mid0074.cs @@ -15,8 +15,8 @@ public class Mid0074 : Mid, IAlarm, IController, IAcknowledgeable public string ErrorCode { - get => GetField(1, (int)DataFields.ErrorCode).Value; - set => GetField(1, (int)DataFields.ErrorCode).SetValue(value); + get => GetField(1, DataFields.ErrorCode).Value; + set => GetField(1, DataFields.ErrorCode).SetValue(value); } public Mid0074() : this(DEFAULT_REVISION) @@ -55,7 +55,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ErrorCode, 20, 4, ' ', PaddingOrientation.LeftPadded, false) + DataField.String(DataFields.ErrorCode, 20, 4, PaddingOrientation.LeftPadded, false) } } }; diff --git a/src/OpenProtocolInterpreter/Alarm/Mid0076.cs b/src/OpenProtocolInterpreter/Alarm/Mid0076.cs index 22d0a18e..1300d3fd 100644 --- a/src/OpenProtocolInterpreter/Alarm/Mid0076.cs +++ b/src/OpenProtocolInterpreter/Alarm/Mid0076.cs @@ -16,33 +16,33 @@ public class Mid0076 : Mid, IAlarm, IController, IAcknowledgeable public bool AlarmStatus { - get => GetField(1, (int)DataFields.AlarmStatus).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.AlarmStatus).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.AlarmStatus).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.AlarmStatus).SetValue(OpenProtocolConvert.ToString, value); } public string ErrorCode { - get => GetField(1, (int)DataFields.ErrorCode).Value; - set => GetField(1, (int)DataFields.ErrorCode).SetValue(value); + get => GetField(1, DataFields.ErrorCode).Value; + set => GetField(1, DataFields.ErrorCode).SetValue(value); } public bool ControllerReadyStatus { - get => GetField(1, (int)DataFields.ControllerReadyStatus).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.ControllerReadyStatus).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ControllerReadyStatus).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.ControllerReadyStatus).SetValue(OpenProtocolConvert.ToString, value); } public bool ToolReadyStatus { - get => GetField(1, (int)DataFields.ToolReadyStatus).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.ToolReadyStatus).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ToolReadyStatus).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.ToolReadyStatus).SetValue(OpenProtocolConvert.ToString, value); } public DateTime Time { - get => GetField(1, (int)DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(1, (int)DataFields.Time).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(1, DataFields.Time).SetValue(OpenProtocolConvert.ToString, value); } public ToolHealth ToolHealth { - get => (ToolHealth)GetField(3, (int)DataFields.ToolHealth).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(3, (int)DataFields.ToolHealth).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (ToolHealth)GetField(3, DataFields.ToolHealth).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(3, DataFields.ToolHealth).SetValue(OpenProtocolConvert.ToString, value); } public Mid0076() : this(DEFAULT_REVISION) @@ -79,17 +79,17 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.AlarmStatus, 20, 1), - new DataField((int)DataFields.ErrorCode, 23, 4, ' ', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ControllerReadyStatus, 29, 1), - new DataField((int)DataFields.ToolReadyStatus, 32, 1), - new DataField((int)DataFields.Time, 35, 19) + DataField.Boolean(DataFields.AlarmStatus, 20), + DataField.String(DataFields.ErrorCode, 23, 4, PaddingOrientation.LeftPadded), + DataField.Boolean(DataFields.ControllerReadyStatus, 29), + DataField.Boolean(DataFields.ToolReadyStatus, 32), + DataField.Timestamp(DataFields.Time, 35) } }, { 3, new List() { - new DataField((int)DataFields.ToolHealth, 57, 1), + DataField.Number(DataFields.ToolHealth, 57, 1), } } }; @@ -97,7 +97,7 @@ protected override Dictionary> RegisterDatafields() private void HandleRevision() { - var errorCodeField = GetField(1, (int)DataFields.ErrorCode); + var errorCodeField = GetField(1, DataFields.ErrorCode); errorCodeField.Size = Header.Revision > 1 ? 5 : 4; int index = errorCodeField.Index + errorCodeField.Size; diff --git a/src/OpenProtocolInterpreter/ApplicationSelector/Mid0251.cs b/src/OpenProtocolInterpreter/ApplicationSelector/Mid0251.cs index 4e1ad21c..cc713022 100644 --- a/src/OpenProtocolInterpreter/ApplicationSelector/Mid0251.cs +++ b/src/OpenProtocolInterpreter/ApplicationSelector/Mid0251.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Text; namespace OpenProtocolInterpreter.ApplicationSelector { @@ -19,13 +20,13 @@ public class Mid0251 : Mid, IApplicationSelector, IController, IAcknowledgeable< public int DeviceId { - get => GetField(1, (int)DataFields.DeviceId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.DeviceId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.DeviceId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.DeviceId).SetValue(OpenProtocolConvert.ToString, value); } public int NumberOfSockets { - get => GetField(1, (int)DataFields.NumberOfSockets).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.NumberOfSockets).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.NumberOfSockets).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.NumberOfSockets).SetValue(OpenProtocolConvert.ToString, value); } public List SocketStatus { get; set; } @@ -35,19 +36,18 @@ public Mid0251() : this(new Header() Revision = DEFAULT_REVISION }) { - + } public Mid0251(Header header) : base(header) { - if (SocketStatus == null) - SocketStatus = new List(); + SocketStatus ??= []; } public override string Pack() { - GetField(1, (int)DataFields.SocketStatus).Size = NumberOfSockets; - GetField(1, (int)DataFields.SocketStatus).Value = PackSocketStatus(); + GetField(1, DataFields.SocketStatus).Size = NumberOfSockets; + GetField(1, DataFields.SocketStatus).Value = PackSocketStatus(); return base.Pack(); } @@ -55,19 +55,19 @@ public override Mid Parse(string package) { Header = ProcessHeader(package); - GetField(1, (int)DataFields.SocketStatus).Size = Header.Length - 30; + GetField(1, DataFields.SocketStatus).Size = Header.Length - 30; ProcessDataFields(package); - SocketStatus = ParseSocketStatus(GetField(1, (int)DataFields.SocketStatus).Value); + SocketStatus = ParseSocketStatus(GetField(1, DataFields.SocketStatus).Value); return this; } protected virtual string PackSocketStatus() { - string pack = string.Empty; + var builder = new StringBuilder(SocketStatus.Count); foreach (var v in SocketStatus) - pack += OpenProtocolConvert.ToString(v); + builder.Append(OpenProtocolConvert.ToString(v)); - return pack; + return builder.ToString(); } protected virtual List ParseSocketStatus(string section) @@ -86,9 +86,9 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.DeviceId, 20, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.NumberOfSockets, 24, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.SocketStatus, 28, 0) + DataField.Number(DataFields.DeviceId, 20, 2), + DataField.Number(DataFields.NumberOfSockets, 24, 2), + DataField.Volatile(DataFields.SocketStatus, 28) } } }; diff --git a/src/OpenProtocolInterpreter/ApplicationSelector/Mid0254.cs b/src/OpenProtocolInterpreter/ApplicationSelector/Mid0254.cs index 808a4484..86a1b29e 100644 --- a/src/OpenProtocolInterpreter/ApplicationSelector/Mid0254.cs +++ b/src/OpenProtocolInterpreter/ApplicationSelector/Mid0254.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Text; namespace OpenProtocolInterpreter.ApplicationSelector { @@ -25,8 +26,8 @@ public class Mid0254 : Mid, IApplicationSelector, IIntegrator, IAcceptableComman public int DeviceId { - get => GetField(1, (int)DataFields.DeviceId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.DeviceId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.DeviceId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.DeviceId).SetValue(OpenProtocolConvert.ToString, value); } public List GreenLights { get; set; } @@ -41,30 +42,29 @@ public Mid0254() : this(new Header() public Mid0254(Header header) : base(header) { - if (GreenLights == null) - GreenLights = new List(); + GreenLights ??= []; } public override string Pack() { - GetField(1, (int)DataFields.GreenLightCommand).Value = PackGreenLights(); + GetField(1, DataFields.GreenLightCommand).Value = PackGreenLights(); return base.Pack(); } public override Mid Parse(string package) { base.Parse(package); - GreenLights = ParseGreenLights(GetField(1, (int)DataFields.GreenLightCommand).Value).ToList(); + GreenLights = ParseGreenLights(GetField(1, DataFields.GreenLightCommand).Value).ToList(); return this; } protected virtual string PackGreenLights() { - string pack = string.Empty; + var builder = new StringBuilder(GreenLights.Count); foreach (var e in GreenLights) - pack += OpenProtocolConvert.ToString((int)e); + builder.Append(OpenProtocolConvert.ToString((int)e)); - return pack; + return builder.ToString(); } protected virtual List ParseGreenLights(string value) @@ -83,8 +83,8 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.DeviceId, 20, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.GreenLightCommand, 24, 8) + DataField.Number(DataFields.DeviceId, 20, 2), + new(DataFields.GreenLightCommand, 24, 8) } } }; diff --git a/src/OpenProtocolInterpreter/ApplicationSelector/Mid0255.cs b/src/OpenProtocolInterpreter/ApplicationSelector/Mid0255.cs index fad47993..774aa843 100644 --- a/src/OpenProtocolInterpreter/ApplicationSelector/Mid0255.cs +++ b/src/OpenProtocolInterpreter/ApplicationSelector/Mid0255.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Text; namespace OpenProtocolInterpreter.ApplicationSelector { @@ -24,8 +25,8 @@ public class Mid0255 : Mid, IApplicationSelector, IIntegrator, IAcceptableComman public int DeviceId { - get => GetField(1, (int)DataFields.DeviceId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.DeviceId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.DeviceId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.DeviceId).SetValue(OpenProtocolConvert.ToString, value); } public List RedLights { get; set; } @@ -40,30 +41,29 @@ public Mid0255() : this(new Header() public Mid0255(Header header) : base(header) { - if (RedLights == null) - RedLights = new List(); + RedLights ??= []; } public override string Pack() { - GetField(1, (int)DataFields.RedLightCommand).Value = PackRedLights(); + GetField(1, DataFields.RedLightCommand).Value = PackRedLights(); return base.Pack(); } public override Mid Parse(string package) { base.Parse(package); - RedLights = ParseRedLights(GetField(1, (int)DataFields.RedLightCommand).Value); + RedLights = ParseRedLights(GetField(1, DataFields.RedLightCommand).Value); return this; } protected virtual string PackRedLights() { - string pack = string.Empty; + var builder = new StringBuilder(RedLights.Count); foreach (var e in RedLights) - pack += OpenProtocolConvert.ToString((int)e); + builder.Append(OpenProtocolConvert.ToString(e)); - return pack; + return builder.ToString(); } protected virtual List ParseRedLights(string value) @@ -82,8 +82,8 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.DeviceId, 20, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.RedLightCommand, 24, 8) + DataField.Number(DataFields.DeviceId, 20, 2), + new(DataFields.RedLightCommand, 24, 8) } } }; diff --git a/src/OpenProtocolInterpreter/ApplicationToolLocationSystem/Mid0262.cs b/src/OpenProtocolInterpreter/ApplicationToolLocationSystem/Mid0262.cs index f7f24a20..7406f2b4 100644 --- a/src/OpenProtocolInterpreter/ApplicationToolLocationSystem/Mid0262.cs +++ b/src/OpenProtocolInterpreter/ApplicationToolLocationSystem/Mid0262.cs @@ -14,8 +14,8 @@ public class Mid0262 : Mid, IApplicationToolLocationSystem, IController, IAcknow public string ToolTagId { - get => GetField(1,(int)DataFields.ToolTagId).Value; - set => GetField(1,(int)DataFields.ToolTagId).SetValue(value); + get => GetField(1, DataFields.ToolTagId).Value; + set => GetField(1, DataFields.ToolTagId).SetValue(value); } public Mid0262() : base(MID, DEFAULT_REVISION) @@ -35,7 +35,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ToolTagId, 20, 8) + DataField.String(DataFields.ToolTagId, 20, 8) } } }; diff --git a/src/OpenProtocolInterpreter/ApplicationToolLocationSystem/Mid0265.cs b/src/OpenProtocolInterpreter/ApplicationToolLocationSystem/Mid0265.cs index e4b7251c..cca95998 100644 --- a/src/OpenProtocolInterpreter/ApplicationToolLocationSystem/Mid0265.cs +++ b/src/OpenProtocolInterpreter/ApplicationToolLocationSystem/Mid0265.cs @@ -16,13 +16,13 @@ public class Mid0265 : Mid, IApplicationToolLocationSystem, IIntegrator, IAccept public string ToolTagId { - get => GetField(1,(int)DataFields.ToolTagId).Value; - set => GetField(1,(int)DataFields.ToolTagId).SetValue(value); + get => GetField(1, DataFields.ToolTagId).Value; + set => GetField(1, DataFields.ToolTagId).SetValue(value); } public ToolStatus ToolStatus { - get => (ToolStatus)GetField(1,(int)DataFields.ToolStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.ToolStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (ToolStatus)GetField(1, DataFields.ToolStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ToolStatus).SetValue(OpenProtocolConvert.ToString, value); } public Mid0265() : this(new Header() @@ -31,7 +31,7 @@ public Mid0265() : this(new Header() Revision = DEFAULT_REVISION }) { - + } public Mid0265(Header header) : base(header) @@ -46,8 +46,8 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ToolTagId, 20, 8), - new DataField((int)DataFields.ToolStatus, 30, 2, '0', PaddingOrientation.LeftPadded) + DataField.String(DataFields.ToolTagId, 20, 8), + DataField.Number(DataFields.ToolStatus, 30, 2) } } }; diff --git a/src/OpenProtocolInterpreter/AutomaticManualMode/Mid0401.cs b/src/OpenProtocolInterpreter/AutomaticManualMode/Mid0401.cs index 7127f691..e5273e59 100644 --- a/src/OpenProtocolInterpreter/AutomaticManualMode/Mid0401.cs +++ b/src/OpenProtocolInterpreter/AutomaticManualMode/Mid0401.cs @@ -21,8 +21,8 @@ public class Mid0401 : Mid, IAutomaticManualMode, IController, IAcknowledgeable< /// public bool ManualAutomaticMode { - get => GetField(1, (int)DataFields.ManualAutomaticMode).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.ManualAutomaticMode).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ManualAutomaticMode).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.ManualAutomaticMode).SetValue(OpenProtocolConvert.ToString, value); } public Mid0401() : this(new Header() @@ -45,7 +45,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ManualAutomaticMode, 20, 1, false) + DataField.Boolean(DataFields.ManualAutomaticMode, 20, false) } } }; diff --git a/src/OpenProtocolInterpreter/AutomaticManualMode/Mid0411.cs b/src/OpenProtocolInterpreter/AutomaticManualMode/Mid0411.cs index f8bdf2eb..0cf5e0e9 100644 --- a/src/OpenProtocolInterpreter/AutomaticManualMode/Mid0411.cs +++ b/src/OpenProtocolInterpreter/AutomaticManualMode/Mid0411.cs @@ -34,13 +34,13 @@ public class Mid0411 : Mid, IAutomaticManualMode, IController public int AutoDisableSetting { - get => GetField(1, (int)DataFields.AutoDisableSetting).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.AutoDisableSetting).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.AutoDisableSetting).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.AutoDisableSetting).SetValue(OpenProtocolConvert.ToString, value); } public int CurrentBatch { - get => GetField(1, (int)DataFields.CurrentBatch).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.CurrentBatch).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.CurrentBatch).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.CurrentBatch).SetValue(OpenProtocolConvert.ToString, value); } public Mid0411() : this(new Header() @@ -63,8 +63,8 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.AutoDisableSetting, 20, 2, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.CurrentBatch, 22, 2, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.AutoDisableSetting, 20, 2, false), + DataField.Number(DataFields.CurrentBatch, 22, 2, false) } } }; diff --git a/src/OpenProtocolInterpreter/Communication/Mid0001.cs b/src/OpenProtocolInterpreter/Communication/Mid0001.cs index 3269529e..5cb16c3f 100644 --- a/src/OpenProtocolInterpreter/Communication/Mid0001.cs +++ b/src/OpenProtocolInterpreter/Communication/Mid0001.cs @@ -16,8 +16,8 @@ public class Mid0001 : Mid, ICommunication, IIntegrator, IAnswerableBy, public bool OptionalKeepAlive { - get => GetField(7, (int)DataFields.UseKeepAlive).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(7, (int)DataFields.UseKeepAlive).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(7, DataFields.UseKeepAlive).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(7, DataFields.UseKeepAlive).SetValue(OpenProtocolConvert.ToString, value); } public Mid0001() : this(DEFAULT_REVISION) @@ -45,7 +45,7 @@ protected override Dictionary> RegisterDatafields() { 7, new List() { - new DataField((int)DataFields.UseKeepAlive, 20, 1) + DataField.Boolean(DataFields.UseKeepAlive, 20) } } }; diff --git a/src/OpenProtocolInterpreter/Communication/Mid0002.cs b/src/OpenProtocolInterpreter/Communication/Mid0002.cs index 0035eb07..d0d81c68 100644 --- a/src/OpenProtocolInterpreter/Communication/Mid0002.cs +++ b/src/OpenProtocolInterpreter/Communication/Mid0002.cs @@ -18,65 +18,65 @@ public class Mid0002 : Mid, ICommunication, IController public int CellId { - get => GetField(1, (int)DataFields.CellId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.CellId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.CellId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.CellId).SetValue(OpenProtocolConvert.ToString, value); } public int ChannelId { - get => GetField(1, (int)DataFields.ChannelId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ChannelId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ChannelId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ChannelId).SetValue(OpenProtocolConvert.ToString, value); } public string ControllerName { - get => GetField(1, (int)DataFields.ControllerName).Value; - set => GetField(1, (int)DataFields.ControllerName).SetValue(value); + get => GetField(1, DataFields.ControllerName).Value; + set => GetField(1, DataFields.ControllerName).SetValue(value); } //Rev 2 public string SupplierCode { - get => GetField(2, (int)DataFields.SupplierCode).Value; - set => GetField(2, (int)DataFields.SupplierCode).SetValue(value); + get => GetField(2, DataFields.SupplierCode).Value; + set => GetField(2, DataFields.SupplierCode).SetValue(value); } //Rev 3 public string OpenProtocolVersion { - get => GetField(3, (int)DataFields.OpenProtocolVersion).Value; - set => GetField(3, (int)DataFields.OpenProtocolVersion).SetValue(value); + get => GetField(3, DataFields.OpenProtocolVersion).Value; + set => GetField(3, DataFields.OpenProtocolVersion).SetValue(value); } public string ControllerSoftwareVersion { - get => GetField(3, (int)DataFields.ControllerSoftwareVersion).Value; - set => GetField(3, (int)DataFields.ControllerSoftwareVersion).SetValue(value); + get => GetField(3, DataFields.ControllerSoftwareVersion).Value; + set => GetField(3, DataFields.ControllerSoftwareVersion).SetValue(value); } public string ToolSoftwareVersion { - get => GetField(3, (int)DataFields.ToolSoftwareVersion).Value; - set => GetField(3, (int)DataFields.ToolSoftwareVersion).SetValue(value); + get => GetField(3, DataFields.ToolSoftwareVersion).Value; + set => GetField(3, DataFields.ToolSoftwareVersion).SetValue(value); } //Rev 4 public string RBUType { - get => GetField(4, (int)DataFields.RBUType).Value; - set => GetField(4, (int)DataFields.RBUType).SetValue(value); + get => GetField(4, DataFields.RBUType).Value; + set => GetField(4, DataFields.RBUType).SetValue(value); } public string ControllerSerialNumber { - get => GetField(4, (int)DataFields.ControllerSerialNumber).Value; - set => GetField(4, (int)DataFields.ControllerSerialNumber).SetValue(value); + get => GetField(4, DataFields.ControllerSerialNumber).Value; + set => GetField(4, DataFields.ControllerSerialNumber).SetValue(value); } //Rev 5 public SystemType SystemType { - get => (SystemType)GetField(5, (int)DataFields.SystemType).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(5, (int)DataFields.SystemType).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (SystemType)GetField(5, DataFields.SystemType).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(5, DataFields.SystemType).SetValue(OpenProtocolConvert.ToString, value); } /// @@ -89,21 +89,21 @@ public SystemType SystemType /// public SystemSubType SystemSubType { - get => (SystemSubType)GetField(5, (int)DataFields.SystemSubtype).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(5, (int)DataFields.SystemSubtype).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (SystemSubType)GetField(5, DataFields.SystemSubtype).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(5, DataFields.SystemSubtype).SetValue(OpenProtocolConvert.ToString, value); } //Rev 6 public bool SequenceNumberSupport { - get => GetField(6, (int)DataFields.SequenceNumberSupport).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(6, (int)DataFields.SequenceNumberSupport).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(6, DataFields.SequenceNumberSupport).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(6, DataFields.SequenceNumberSupport).SetValue(OpenProtocolConvert.ToString, value); } public bool LinkingHandlingSupport { - get => GetField(6, (int)DataFields.LinkingHandlingSupport).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(6, (int)DataFields.LinkingHandlingSupport).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(6, DataFields.LinkingHandlingSupport).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(6, DataFields.LinkingHandlingSupport).SetValue(OpenProtocolConvert.ToString, value); } /// @@ -112,8 +112,8 @@ public bool LinkingHandlingSupport /// public long StationCellId { - get => GetField(6, (int)DataFields.StationCellId).GetValue(OpenProtocolConvert.ToInt64); - set => GetField(6, (int)DataFields.StationCellId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(6, DataFields.StationCellId).GetValue(OpenProtocolConvert.ToInt64); + set => GetField(6, DataFields.StationCellId).SetValue(OpenProtocolConvert.ToString, value); } /// @@ -122,14 +122,14 @@ public long StationCellId /// public string StationCellName { - get => GetField(6, (int)DataFields.StationCellName).Value; - set => GetField(6, (int)DataFields.StationCellName).SetValue(value); + get => GetField(6, DataFields.StationCellName).Value; + set => GetField(6, DataFields.StationCellName).SetValue(value); } public string ClientId { - get => GetField(6, (int)DataFields.ClientId).Value; - set => GetField(6, (int)DataFields.ClientId).SetValue(value); + get => GetField(6, DataFields.ClientId).Value; + set => GetField(6, DataFields.ClientId).SetValue(value); } //Rev 7 @@ -139,8 +139,8 @@ public string ClientId /// public bool OptionalKeepAlive { - get => GetField(7, (int)DataFields.OptionalKeepAlive).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(7, (int)DataFields.OptionalKeepAlive).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(7, DataFields.OptionalKeepAlive).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(7, DataFields.OptionalKeepAlive).SetValue(OpenProtocolConvert.ToString, value); } public Mid0002() : this(DEFAULT_REVISION) @@ -169,53 +169,53 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.CellId, 20, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ChannelId, 26, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ControllerName, 30, 25, ' ') + DataField.Number(DataFields.CellId, 20, 4), + DataField.Number(DataFields.ChannelId, 26, 2), + DataField.String(DataFields.ControllerName, 30, 25) } }, { 2, new List() { - new DataField((int)DataFields.SupplierCode, 57, 3, ' ') + DataField.String(DataFields.SupplierCode, 57, 3) } }, { 3, new List() { - new DataField((int)DataFields.OpenProtocolVersion, 62, 19, ' '), - new DataField((int)DataFields.ControllerSoftwareVersion, 83, 19, ' '), - new DataField((int)DataFields.ToolSoftwareVersion, 104, 19, ' ') + DataField.String(DataFields.OpenProtocolVersion, 62, 19), + DataField.String(DataFields.ControllerSoftwareVersion, 83, 19), + DataField.String(DataFields.ToolSoftwareVersion, 104, 19) } }, { 4, new List() { - new DataField((int)DataFields.RBUType, 125, 24, ' '), - new DataField((int)DataFields.ControllerSerialNumber, 151, 10, ' ') + DataField.String(DataFields.RBUType, 125, 24), + DataField.String(DataFields.ControllerSerialNumber, 151, 10) } }, { 5, new List() { - new DataField((int)DataFields.SystemType, 163, 3, '0'), - new DataField((int)DataFields.SystemSubtype, 168, 3, '0') + DataField.Number(DataFields.SystemType, 163, 3), + DataField.Number(DataFields.SystemSubtype, 168, 3) } }, { 6, new List() { - new DataField((int)DataFields.SequenceNumberSupport, 173, 1), - new DataField((int)DataFields.LinkingHandlingSupport, 176, 1), - new DataField((int)DataFields.StationCellId, 179, 10, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.StationCellName, 191, 25), - new DataField((int)DataFields.ClientId, 218, 1) + DataField.Boolean(DataFields.SequenceNumberSupport, 173), + DataField.Boolean(DataFields.LinkingHandlingSupport, 176), + DataField.Number(DataFields.StationCellId, 179, 10), + DataField.String(DataFields.StationCellName, 191, 25), + DataField.String(DataFields.ClientId, 218, 1) } }, { 7, new List() { - new DataField((int)DataFields.OptionalKeepAlive, 221, 1) + DataField.Boolean(DataFields.OptionalKeepAlive, 221) } } }; diff --git a/src/OpenProtocolInterpreter/Communication/Mid0004.cs b/src/OpenProtocolInterpreter/Communication/Mid0004.cs index 5efe1136..b1878b3c 100644 --- a/src/OpenProtocolInterpreter/Communication/Mid0004.cs +++ b/src/OpenProtocolInterpreter/Communication/Mid0004.cs @@ -24,13 +24,13 @@ public class Mid0004 : Mid, ICommunication, IController public int FailedMid { - get => GetField(1, (int)DataFields.Mid).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.Mid).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Mid).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.Mid).SetValue(OpenProtocolConvert.ToString, value); } public Error ErrorCode { - get => (Error)GetField(1, (int)DataFields.ErrorCode).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ErrorCode).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (Error)GetField(1, DataFields.ErrorCode).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ErrorCode).SetValue(OpenProtocolConvert.ToString, value); } public Mid0004() : this(DEFAULT_REVISION) @@ -51,6 +51,26 @@ public Mid0004(int revision) : this(new Header() } + public override string Pack() + { + HandleRevision(); + return base.Pack(); + } + + public override Mid Parse(string package) + { + Header = ProcessHeader(package); + HandleRevision(); + ProcessDataFields(package); + return this; + } + + private void HandleRevision() + { + var errorCodeField = GetField(1, DataFields.ErrorCode); + errorCodeField.Size = Header.Revision > 1 ? 3 : 2; + } + protected override Dictionary> RegisterDatafields() { return new Dictionary>() @@ -58,8 +78,8 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.Mid, 20, 4, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.ErrorCode, 24, 2, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.Mid, 20, 4, false), + DataField.Number(DataFields.ErrorCode, 24, 2, false) } } }; diff --git a/src/OpenProtocolInterpreter/Communication/Mid0005.cs b/src/OpenProtocolInterpreter/Communication/Mid0005.cs index 2f41e955..994aee2e 100644 --- a/src/OpenProtocolInterpreter/Communication/Mid0005.cs +++ b/src/OpenProtocolInterpreter/Communication/Mid0005.cs @@ -28,8 +28,8 @@ public class Mid0005 : Mid, ICommunication, IController public int MidAccepted { - get => GetField(1, (int)DataFields.MidAccepted).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.MidAccepted).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.MidAccepted).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.MidAccepted).SetValue(OpenProtocolConvert.ToString, value); } public Mid0005() : this(DEFAULT_REVISION) @@ -57,7 +57,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.MidAccepted, 20, 4, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.MidAccepted, 20, 4, false) } } }; diff --git a/src/OpenProtocolInterpreter/Communication/Mid0006.cs b/src/OpenProtocolInterpreter/Communication/Mid0006.cs index b1e19959..dce6fd7e 100644 --- a/src/OpenProtocolInterpreter/Communication/Mid0006.cs +++ b/src/OpenProtocolInterpreter/Communication/Mid0006.cs @@ -3,7 +3,7 @@ namespace OpenProtocolInterpreter.Communication { /// - /// Application Communication positive acknowledge + /// Application data message request /// /// Do a request for data. This message is used for ALL request handling. /// When used it substitutes the use of all MID special request messages. @@ -19,25 +19,25 @@ public class Mid0006 : Mid, ICommunication, IIntegrator { public const int MID = 6; - public string RequestedMid + public int RequestedMid { - get => GetField(1, (int)DataFields.RequestedMid).Value; - set => GetField(1, (int)DataFields.RequestedMid).SetValue(value); + get => GetField(1, DataFields.RequestedMid).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.RequestedMid).SetValue(OpenProtocolConvert.ToString, value); } public int WantedRevision { - get => GetField(1, (int)DataFields.WantedRevision).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.WantedRevision).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.WantedRevision).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.WantedRevision).SetValue(OpenProtocolConvert.ToString, value); } public int ExtraDataLength { - get => GetField(1, (int)DataFields.ExtraDataLength).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ExtraDataLength).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ExtraDataLength).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ExtraDataLength).SetValue(OpenProtocolConvert.ToString, value); } public string ExtraData { - get => GetField(1, (int)DataFields.ExtraData).Value; - set => GetField(1, (int)DataFields.ExtraData).SetValue(value); + get => GetField(1, DataFields.ExtraData).Value; + set => GetField(1, DataFields.ExtraData).SetValue(value); } public Mid0006() : this(new Header() @@ -56,7 +56,7 @@ public Mid0006(Header header) : base(header) public override Mid Parse(string package) { Header = ProcessHeader(package); - GetField(1, (int)DataFields.ExtraData).Size = Header.Length - 29; + GetField(1, DataFields.ExtraData).Size = Header.Length - 29; ProcessDataFields(package); return this; } @@ -68,10 +68,10 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.RequestedMid, 20, 4, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.WantedRevision, 24, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.ExtraDataLength, 27, 2, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.ExtraData, 29, 0, ' ', PaddingOrientation.RightPadded, false) + DataField.Number(DataFields.RequestedMid, 20, 4, false), + DataField.Number(DataFields.WantedRevision, 24, 3, false), + DataField.Number(DataFields.ExtraDataLength, 27, 2, false), + DataField.Volatile(DataFields.ExtraData, 29, false) } } }; diff --git a/src/OpenProtocolInterpreter/Communication/Mid0008.cs b/src/OpenProtocolInterpreter/Communication/Mid0008.cs index 37b72367..7da632b7 100644 --- a/src/OpenProtocolInterpreter/Communication/Mid0008.cs +++ b/src/OpenProtocolInterpreter/Communication/Mid0008.cs @@ -24,23 +24,23 @@ public class Mid0008 : Mid, ICommunication, IIntegrator public string SubscriptionMid { - get => GetField(1, (int)DataFields.SubscriptionMid).Value; - set => GetField(1, (int)DataFields.SubscriptionMid).SetValue(value); + get => GetField(1, DataFields.SubscriptionMid).Value; + set => GetField(1, DataFields.SubscriptionMid).SetValue(value); } public int WantedRevision { - get => GetField(1, (int)DataFields.WantedRevision).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.WantedRevision).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.WantedRevision).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.WantedRevision).SetValue(OpenProtocolConvert.ToString, value); } public int ExtraDataLength { - get => GetField(1, (int)DataFields.ExtraDataLength).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ExtraDataLength).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ExtraDataLength).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ExtraDataLength).SetValue(OpenProtocolConvert.ToString, value); } public string ExtraData { - get => GetField(1, (int)DataFields.ExtraData).Value; - set => GetField(1, (int)DataFields.ExtraData).SetValue(value); + get => GetField(1, DataFields.ExtraData).Value; + set => GetField(1, DataFields.ExtraData).SetValue(value); } public Mid0008() : this(new Header() @@ -59,7 +59,7 @@ public Mid0008(Header header) : base(header) public override Mid Parse(string package) { Header = ProcessHeader(package); - GetField(1, (int)DataFields.ExtraData).Size = Header.Length - 29; + GetField(1, DataFields.ExtraData).Size = Header.Length - 29; ProcessDataFields(package); return this; } @@ -71,10 +71,10 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.SubscriptionMid, 20, 4, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.WantedRevision, 24, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.ExtraDataLength, 27, 2, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.ExtraData, 29, 0, ' ', PaddingOrientation.RightPadded, false) + DataField.Number(DataFields.SubscriptionMid, 20, 4, false), + DataField.Number(DataFields.WantedRevision, 24, 3, false), + DataField.Number(DataFields.ExtraDataLength, 27, 2, false), + DataField.Volatile(DataFields.ExtraData, 29, false) } } }; diff --git a/src/OpenProtocolInterpreter/Communication/Mid0009.cs b/src/OpenProtocolInterpreter/Communication/Mid0009.cs index 9f185b5e..de8d4f4a 100644 --- a/src/OpenProtocolInterpreter/Communication/Mid0009.cs +++ b/src/OpenProtocolInterpreter/Communication/Mid0009.cs @@ -24,23 +24,23 @@ public class Mid0009 : Mid, ICommunication, IIntegrator public string UnsubscriptionMid { - get => GetField(1, (int)DataFields.UnsubscriptionMid).Value; - set => GetField(1, (int)DataFields.UnsubscriptionMid).SetValue(value); + get => GetField(1, DataFields.UnsubscriptionMid).Value; + set => GetField(1, DataFields.UnsubscriptionMid).SetValue(value); } public int ExtraDataRevision { - get => GetField(1, (int)DataFields.ExtraDataRevision).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ExtraDataRevision).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ExtraDataRevision).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ExtraDataRevision).SetValue(OpenProtocolConvert.ToString, value); } public int ExtraDataLength { - get => GetField(1, (int)DataFields.ExtraDataLength).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ExtraDataLength).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ExtraDataLength).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ExtraDataLength).SetValue(OpenProtocolConvert.ToString, value); } public string ExtraData { - get => GetField(1, (int)DataFields.ExtraData).Value; - set => GetField(1, (int)DataFields.ExtraData).SetValue(value); + get => GetField(1, DataFields.ExtraData).Value; + set => GetField(1, DataFields.ExtraData).SetValue(value); } public Mid0009() : this(new Header() @@ -59,7 +59,7 @@ public Mid0009(Header header) : base(header) public override Mid Parse(string package) { Header = ProcessHeader(package); - GetField(1, (int)DataFields.ExtraData).Size = Header.Length - 29; + GetField(1, DataFields.ExtraData).Size = Header.Length - 29; ProcessDataFields(package); return this; } @@ -71,10 +71,10 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.UnsubscriptionMid, 20, 4, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.ExtraDataRevision, 24, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.ExtraDataLength, 27, 2, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.ExtraData, 29, 0, ' ', PaddingOrientation.RightPadded, false) + DataField.Number(DataFields.UnsubscriptionMid, 20, 4, false), + DataField.Number(DataFields.ExtraDataRevision, 24, 3, false), + DataField.Number(DataFields.ExtraDataLength, 27, 2, false), + DataField.Volatile(DataFields.ExtraData, 29, false) } } }; diff --git a/src/OpenProtocolInterpreter/DataField.cs b/src/OpenProtocolInterpreter/DataField.cs index ad21f316..55cb7765 100644 --- a/src/OpenProtocolInterpreter/DataField.cs +++ b/src/OpenProtocolInterpreter/DataField.cs @@ -1,4 +1,5 @@ using System; +using System.Drawing; using System.Linq; namespace OpenProtocolInterpreter @@ -13,12 +14,15 @@ public class DataField private readonly PaddingOrientation _paddingOrientation; private object CachedValue; + internal static DataField Default = new(-1, -1, -1); + public bool HasPrefix { get; set; } public int Field { get; set; } public int Index { get; set; } public int Size { get; set; } public string Value { get; set; } public byte[] RawValue { get; set; } + public int TotalSize => HasPrefix ? 2 + Size : Size; public DataField(int field, int index, int size, bool hasPrefix = true) { @@ -29,6 +33,12 @@ public DataField(int field, int index, int size, bool hasPrefix = true) _paddingChar = ' '; } + public DataField(Enum field, int index, int size, bool hasPrefix = true) + : this(field.GetHashCode(), index, size, hasPrefix) + { + + } + public DataField(int field, int index, int size, char paddingChar, PaddingOrientation paddingOrientation = PaddingOrientation.RightPadded, bool hasPrefix = true) { _paddingChar = paddingChar; @@ -39,6 +49,12 @@ public DataField(int field, int index, int size, char paddingChar, PaddingOrient Size = size; } + public DataField(Enum field, int index, int size, char paddingChar, PaddingOrientation paddingOrientation = PaddingOrientation.RightPadded, bool hasPrefix = true) + : this(field.GetHashCode(), index, size, paddingChar, paddingOrientation, hasPrefix) + { + + } + public virtual T GetValue(Func converter) { if (string.IsNullOrWhiteSpace(Value)) @@ -79,6 +95,40 @@ public virtual void SetValue(string value) SetValue(OpenProtocolConvert.TruncatePadded, value); } + public static DataField String(int field, int index, int size, bool hasPrefix = true) + => new(field, index, size, ' ', PaddingOrientation.RightPadded, hasPrefix); + public static DataField String(int field, int index, int size, PaddingOrientation paddingOrientation, bool hasPrefix = true) + => new(field, index, size, ' ', paddingOrientation, hasPrefix); + public static DataField String(Enum field, int index, int size, bool hasPrefix = true) + => new(field, index, size, ' ', PaddingOrientation.RightPadded, hasPrefix); + public static DataField String(Enum field, int index, int size, PaddingOrientation paddingOrientation, bool hasPrefix = true) + => new(field, index, size, ' ', paddingOrientation, hasPrefix); + + public static DataField Boolean(int field, int index, bool hasPrefix = true) + => new(field, index, 1, hasPrefix); + public static DataField Boolean(Enum field, int index, bool hasPrefix = true) + => new(field, index, 1, hasPrefix); + + public static DataField Timestamp(int field, int index, bool hasPrefix = true) + => new(field, index, 19, hasPrefix); + public static DataField Timestamp(Enum field, int index, bool hasPrefix = true) + => new(field, index, 19, hasPrefix); + + public static DataField Number(int field, int index, int size, bool hasPrefix = true) + => new(field, index, size, '0', PaddingOrientation.LeftPadded, hasPrefix); + public static DataField Number(Enum field, int index, int size, bool hasPrefix = true) + => new(field, index, size, '0', PaddingOrientation.LeftPadded, hasPrefix); + + public static DataField Volatile(int field, int index, bool hasPrefix = true) + => new(field, index, 0, hasPrefix); + public static DataField Volatile(Enum field, int index, bool hasPrefix = true) + => new(field, index, 0, hasPrefix); + + public static DataField Volatile(int field, bool hasPrefix = true) + => new(field, 0, 0, hasPrefix); + public static DataField Volatile(Enum field, bool hasPrefix = true) + => new(field, 0, 0, hasPrefix); + private bool IsValueNotCached() => CachedValue == null || IsNotTypeOf(); private bool IsNotTypeOf() => !CachedValue.GetType().Equals(typeof(T)); diff --git a/src/OpenProtocolInterpreter/DataTypes.cs b/src/OpenProtocolInterpreter/DataTypes.cs index 65a3c309..d758e8fb 100644 --- a/src/OpenProtocolInterpreter/DataTypes.cs +++ b/src/OpenProtocolInterpreter/DataTypes.cs @@ -10,8 +10,8 @@ namespace OpenProtocolInterpreter #pragma warning disable CS0661 // Type defines operator == or operator != but does not override Object.GetHashCode() public class DataType { - private static readonly List _dataTypesDefinition = new List() - { + private static readonly List _dataTypesDefinition = + [ new DataType(1, "UI", 0), new DataType(2, "I ", 0), new DataType(3, "F ", 0), @@ -25,7 +25,7 @@ public class DataType new DataType(50, "FA", 0), new DataType(51, "UA", 0), new DataType(52, "IA", 0) - }; + ]; private int _valueSent; diff --git a/src/OpenProtocolInterpreter/Enums/Error.cs b/src/OpenProtocolInterpreter/Enums/Error.cs index 1184d9eb..cfda5e50 100644 --- a/src/OpenProtocolInterpreter/Enums/Error.cs +++ b/src/OpenProtocolInterpreter/Enums/Error.cs @@ -95,6 +95,11 @@ public enum Error ClientAlreadyConnected = 96, MidRevisionUnsupported = 97, ControllerInternalRequestTimeout = 98, - UnknownMid = 99 + UnknownMid = 99, + IllegalPID = 100, + TighteningInProgress = 101, + DeleteOfObjectNotPossible = 102, + IllegalProgramId = 103, + IllegalNodeType = 104 } } diff --git a/src/OpenProtocolInterpreter/Enums/NodeType.cs b/src/OpenProtocolInterpreter/Enums/NodeType.cs new file mode 100644 index 00000000..0b75d494 --- /dev/null +++ b/src/OpenProtocolInterpreter/Enums/NodeType.cs @@ -0,0 +1,18 @@ +namespace OpenProtocolInterpreter +{ + public enum NodeType + { + ParameterSet = 1, + Multistage = 2, + Job = 3, + + TighteningProgram = 100, + TighteningStep = 101, + Restriction = 102, + Check = 103, + SpeedRamp = 104, + Monitoring = 105, + + MultistepTighteningProgram = 201 + } +} diff --git a/src/OpenProtocolInterpreter/Enums/ObjectType.cs b/src/OpenProtocolInterpreter/Enums/ObjectType.cs new file mode 100644 index 00000000..af92f737 --- /dev/null +++ b/src/OpenProtocolInterpreter/Enums/ObjectType.cs @@ -0,0 +1,12 @@ +namespace OpenProtocolInterpreter +{ + public enum ObjectType + { + Unknown = 0, + DualReading = 1, + TighteningProduction = 2, + TighteningSimulation = 3, + JointCheck = 4, + Dimensional = 5 + } +} diff --git a/src/OpenProtocolInterpreter/Header.cs b/src/OpenProtocolInterpreter/Header.cs index 93c37a78..c44e020e 100644 --- a/src/OpenProtocolInterpreter/Header.cs +++ b/src/OpenProtocolInterpreter/Header.cs @@ -1,10 +1,14 @@ -namespace OpenProtocolInterpreter +using System.Text; + +namespace OpenProtocolInterpreter { /// /// Represents a Mid header /// public sealed class Header { + public const int DefaultSize = 20; + /// /// Length of the header plus the data field excluding the NUL termination. /// @@ -24,6 +28,15 @@ public sealed class Header /// public int Revision { get; set; } + /// + /// The MID Revision is unique per MID and is used in case different versions are available for the same MID. + /// Using the revision number the integrator can subscribe or ask for different versions of the same MID. + /// + /// Note: Enforces the default MID Revision to 1 when it's either send three spaces or 000 or 001. + /// + /// + public int StandardizedRevision => Revision > 0 ? Revision : 1; + /// /// Define if subscriber will acknowledge each "push" message sent by controller (reliable mode) or just push without waiting for a receive acknowledgement from subscriber (unreliable mode) /// Notes: @@ -66,21 +79,24 @@ public sealed class Header public Header() { - Length = 20; //default length + Length = DefaultSize; //default length } + public void EnforceRevisionStandardization() + => Revision = StandardizedRevision; + public override string ToString() { - string header = Length.ToString().PadLeft(4, '0'); - header += Mid.ToString().PadLeft(4, '0'); - header += (Revision > 0) ? Revision.ToString().PadLeft(3, '0') : " "; - header += NoAckFlag ? "1" : " "; - header += (StationId != null) ? StationId.ToString().PadLeft(2, '0') : string.Empty.PadLeft(2, ' '); - header += (SpindleId != null) ? SpindleId.ToString().PadLeft(2, '0') : string.Empty.PadLeft(2, ' '); - header += (SequenceNumber > 0) ? SequenceNumber.ToString().PadLeft(2, '0') : string.Empty.PadLeft(2, ' '); - header += NumberOfMessages.ToString().PadLeft(1, ' '); - header += MessageNumber.ToString().PadLeft(1, ' '); - return header; + var builder = new StringBuilder(Length.ToString("D4")); + builder.Append(Mid.ToString("D4")); + builder.Append((Revision > 0) ? Revision.ToString("D3") : " "); + builder.Append(NoAckFlag ? "1" : " "); + builder.Append(StationId.HasValue ? StationId.Value.ToString("D2") : " "); + builder.Append(SpindleId.HasValue ? SpindleId.Value.ToString("D2") : " "); + builder.Append(SequenceNumber.HasValue ? SequenceNumber.Value.ToString("D2") : " "); + builder.Append(NumberOfMessages.HasValue ? NumberOfMessages.ToString() : " "); + builder.Append(MessageNumber.HasValue ? MessageNumber.ToString() : " "); + return builder.ToString(); } } } diff --git a/src/OpenProtocolInterpreter/IOInterface/Mid0200.cs b/src/OpenProtocolInterpreter/IOInterface/Mid0200.cs index 90b4648c..252a4489 100644 --- a/src/OpenProtocolInterpreter/IOInterface/Mid0200.cs +++ b/src/OpenProtocolInterpreter/IOInterface/Mid0200.cs @@ -17,62 +17,62 @@ public class Mid0200 : Mid, IIOInterface, IIntegrator, IAcceptableCommand public RelayStatus StatusRelayOne { - get => (RelayStatus)GetField(1,(int)DataFields.StatusRelay1).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.StatusRelay1).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (RelayStatus)GetField(1, DataFields.StatusRelay1).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.StatusRelay1).SetValue(OpenProtocolConvert.ToString, value); } public RelayStatus StatusRelayTwo { - get => (RelayStatus)GetField(1,(int)DataFields.StatusRelay2).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.StatusRelay2).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (RelayStatus)GetField(1, DataFields.StatusRelay2).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.StatusRelay2).SetValue(OpenProtocolConvert.ToString, value); } public RelayStatus StatusRelayThree { - get => (RelayStatus)GetField(1,(int)DataFields.StatusRelay3).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.StatusRelay3).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (RelayStatus)GetField(1, DataFields.StatusRelay3).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.StatusRelay3).SetValue(OpenProtocolConvert.ToString, value); } public RelayStatus StatusRelayFour { - get => (RelayStatus)GetField(1,(int)DataFields.StatusRelay4).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.StatusRelay4).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (RelayStatus)GetField(1, DataFields.StatusRelay4).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.StatusRelay4).SetValue(OpenProtocolConvert.ToString, value); } public RelayStatus StatusRelayFive { - get => (RelayStatus)GetField(1,(int)DataFields.StatusRelay5).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.StatusRelay5).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (RelayStatus)GetField(1, DataFields.StatusRelay5).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.StatusRelay5).SetValue(OpenProtocolConvert.ToString, value); } public RelayStatus StatusRelaySix { - get => (RelayStatus)GetField(1,(int)DataFields.StatusRelay6).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.StatusRelay6).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (RelayStatus)GetField(1, DataFields.StatusRelay6).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.StatusRelay6).SetValue(OpenProtocolConvert.ToString, value); } public RelayStatus StatusRelaySeven { - get => (RelayStatus)GetField(1,(int)DataFields.StatusRelay7).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.StatusRelay7).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (RelayStatus)GetField(1, DataFields.StatusRelay7).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.StatusRelay7).SetValue(OpenProtocolConvert.ToString, value); } public RelayStatus StatusRelayEight { - get => (RelayStatus)GetField(1,(int)DataFields.StatusRelay8).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.StatusRelay8).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (RelayStatus)GetField(1, DataFields.StatusRelay8).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.StatusRelay8).SetValue(OpenProtocolConvert.ToString, value); } public RelayStatus StatusRelayNine { - get => (RelayStatus)GetField(1,(int)DataFields.StatusRelay9).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.StatusRelay9).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (RelayStatus)GetField(1, DataFields.StatusRelay9).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.StatusRelay9).SetValue(OpenProtocolConvert.ToString, value); } public RelayStatus StatusRelayTen { - get => (RelayStatus)GetField(1,(int)DataFields.StatusRelay10).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.StatusRelay10).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (RelayStatus)GetField(1, DataFields.StatusRelay10).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.StatusRelay10).SetValue(OpenProtocolConvert.ToString, value); } public Mid0200() : this(new Header() { - Mid = MID, + Mid = MID, Revision = DEFAULT_REVISION }) { - + } public Mid0200(Header header) : base(header) @@ -86,16 +86,16 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.StatusRelay1, 20, 1, false), - new DataField((int)DataFields.StatusRelay2, 21, 1, false), - new DataField((int)DataFields.StatusRelay3, 22, 1, false), - new DataField((int)DataFields.StatusRelay4, 23, 1, false), - new DataField((int)DataFields.StatusRelay5, 24, 1, false), - new DataField((int)DataFields.StatusRelay6, 25, 1, false), - new DataField((int)DataFields.StatusRelay7, 26, 1, false), - new DataField((int)DataFields.StatusRelay8, 27, 1, false), - new DataField((int)DataFields.StatusRelay9, 28, 1, false), - new DataField((int)DataFields.StatusRelay10, 29, 1, false) + DataField.Number(DataFields.StatusRelay1, 20, 1, false), + DataField.Number(DataFields.StatusRelay2, 21, 1, false), + DataField.Number(DataFields.StatusRelay3, 22, 1, false), + DataField.Number(DataFields.StatusRelay4, 23, 1, false), + DataField.Number(DataFields.StatusRelay5, 24, 1, false), + DataField.Number(DataFields.StatusRelay6, 25, 1, false), + DataField.Number(DataFields.StatusRelay7, 26, 1, false), + DataField.Number(DataFields.StatusRelay8, 27, 1, false), + DataField.Number(DataFields.StatusRelay9, 28, 1, false), + DataField.Number(DataFields.StatusRelay10, 29, 1, false) } } }; diff --git a/src/OpenProtocolInterpreter/IOInterface/Mid0211.cs b/src/OpenProtocolInterpreter/IOInterface/Mid0211.cs index 10c02aca..22eb08c4 100644 --- a/src/OpenProtocolInterpreter/IOInterface/Mid0211.cs +++ b/src/OpenProtocolInterpreter/IOInterface/Mid0211.cs @@ -14,55 +14,55 @@ namespace OpenProtocolInterpreter.IOInterface public class Mid0211 : Mid, IIOInterface, IController, IAcknowledgeable { public const int MID = 211; - + public bool StatusDigInOne { - get => GetField(1,(int)DataFields.StatusDigIn1).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1,(int)DataFields.StatusDigIn1).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.StatusDigIn1).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.StatusDigIn1).SetValue(OpenProtocolConvert.ToString, value); } public bool StatusDigInTwo { - get => GetField(1,(int)DataFields.StatusDigIn2).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1,(int)DataFields.StatusDigIn2).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.StatusDigIn2).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.StatusDigIn2).SetValue(OpenProtocolConvert.ToString, value); } public bool StatusDigInThree { - get => GetField(1,(int)DataFields.StatusDigIn3).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1,(int)DataFields.StatusDigIn3).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.StatusDigIn3).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.StatusDigIn3).SetValue(OpenProtocolConvert.ToString, value); } public bool StatusDigInFour { - get => GetField(1,(int)DataFields.StatusDigIn4).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1,(int)DataFields.StatusDigIn4).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.StatusDigIn4).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.StatusDigIn4).SetValue(OpenProtocolConvert.ToString, value); } public bool StatusDigInFive { - get => GetField(1,(int)DataFields.StatusDigIn5).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1,(int)DataFields.StatusDigIn5).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.StatusDigIn5).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.StatusDigIn5).SetValue(OpenProtocolConvert.ToString, value); } public bool StatusDigInSix { - get => GetField(1,(int)DataFields.StatusDigIn6).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1,(int)DataFields.StatusDigIn6).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.StatusDigIn6).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.StatusDigIn6).SetValue(OpenProtocolConvert.ToString, value); } public bool StatusDigInSeven { - get => GetField(1,(int)DataFields.StatusDigIn7).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1,(int)DataFields.StatusDigIn7).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.StatusDigIn7).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.StatusDigIn7).SetValue(OpenProtocolConvert.ToString, value); } public bool StatusDigInEight { - get => GetField(1,(int)DataFields.StatusDigIn8).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1,(int)DataFields.StatusDigIn8).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.StatusDigIn8).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.StatusDigIn8).SetValue(OpenProtocolConvert.ToString, value); } public Mid0211() : this(new Header() { - Mid = MID, + Mid = MID, Revision = DEFAULT_REVISION }) { - + } public Mid0211(Header header) : base(header) @@ -76,14 +76,14 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.StatusDigIn1, 20, 1, false), - new DataField((int)DataFields.StatusDigIn2, 21, 1, false), - new DataField((int)DataFields.StatusDigIn3, 22, 1, false), - new DataField((int)DataFields.StatusDigIn4, 23, 1, false), - new DataField((int)DataFields.StatusDigIn5, 24, 1, false), - new DataField((int)DataFields.StatusDigIn6, 25, 1, false), - new DataField((int)DataFields.StatusDigIn7, 26, 1, false), - new DataField((int)DataFields.StatusDigIn8, 27, 1, false) + DataField.Boolean(DataFields.StatusDigIn1, 20, false), + DataField.Boolean(DataFields.StatusDigIn2, 21, false), + DataField.Boolean(DataFields.StatusDigIn3, 22, false), + DataField.Boolean(DataFields.StatusDigIn4, 23, false), + DataField.Boolean(DataFields.StatusDigIn5, 24, false), + DataField.Boolean(DataFields.StatusDigIn6, 25, false), + DataField.Boolean(DataFields.StatusDigIn7, 26, false), + DataField.Boolean(DataFields.StatusDigIn8, 27, false) } } }; diff --git a/src/OpenProtocolInterpreter/IOInterface/Mid0214.cs b/src/OpenProtocolInterpreter/IOInterface/Mid0214.cs index bd952e8a..c7c80ec1 100644 --- a/src/OpenProtocolInterpreter/IOInterface/Mid0214.cs +++ b/src/OpenProtocolInterpreter/IOInterface/Mid0214.cs @@ -22,8 +22,8 @@ public class Mid0214 : Mid, IIOInterface, IIntegrator, IAnswerableBy, I public int DeviceNumber { - get => GetField(1,(int)DataFields.DeviceNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.DeviceNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.DeviceNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.DeviceNumber).SetValue(OpenProtocolConvert.ToString, value); } public Mid0214() : this(DEFAULT_REVISION) @@ -49,7 +49,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.DeviceNumber, 20, 2, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.DeviceNumber, 20, 2, false) } } }; diff --git a/src/OpenProtocolInterpreter/IOInterface/Mid0215.cs b/src/OpenProtocolInterpreter/IOInterface/Mid0215.cs index c86899cf..1bdcbf0b 100644 --- a/src/OpenProtocolInterpreter/IOInterface/Mid0215.cs +++ b/src/OpenProtocolInterpreter/IOInterface/Mid0215.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Text; namespace OpenProtocolInterpreter.IOInterface { @@ -23,21 +24,21 @@ public class Mid0215 : Mid, IIOInterface, IController public int IODeviceId { - get => GetField(Header.Revision, (int)DataFields.IODeviceId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(Header.Revision, (int)DataFields.IODeviceId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.IODeviceId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.IODeviceId).SetValue(OpenProtocolConvert.ToString, value); } public List Relays { get; set; } public List DigitalInputs { get; set; } //rev 2 public int NumberOfRelays { - get => GetField(2, (int)DataFields.NumberOfRelays).GetValue(OpenProtocolConvert.ToInt32); - private set => GetField(2, (int)DataFields.NumberOfRelays).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.NumberOfRelays).GetValue(OpenProtocolConvert.ToInt32); + private set => GetField(2, DataFields.NumberOfRelays).SetValue(OpenProtocolConvert.ToString, value); } public int NumberOfDigitalInputs { - get => GetField(2, (int)DataFields.NumberOfDigitalInputs).GetValue(OpenProtocolConvert.ToInt32); - private set => GetField(2, (int)DataFields.NumberOfDigitalInputs).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.NumberOfDigitalInputs).GetValue(OpenProtocolConvert.ToInt32); + private set => GetField(2, DataFields.NumberOfDigitalInputs).SetValue(OpenProtocolConvert.ToString, value); } public Mid0215() : this(DEFAULT_REVISION) @@ -47,8 +48,8 @@ public Mid0215() : this(DEFAULT_REVISION) public Mid0215(Header header) : base(header) { - Relays = new List(); - DigitalInputs = new List(); + Relays = []; + DigitalInputs = []; } public Mid0215(int revision) : this(new Header() @@ -65,7 +66,7 @@ protected override string BuildHeader() if (RevisionsByFields.Any()) { Header.Length = 20; - var revision = Header.Revision > 0 ? Header.Revision : 1; + var revision = Header.StandardizedRevision; foreach (var dataField in RevisionsByFields[revision]) Header.Length += (dataField.HasPrefix ? 2 : 0) + dataField.Size; } @@ -79,46 +80,45 @@ public override string Pack() NumberOfRelays = Relays.Count; NumberOfDigitalInputs = DigitalInputs.Count; - var relayListField = GetField(2, (int)DataFields.RelayList); + var relayListField = GetField(2, DataFields.RelayList); relayListField.Size = NumberOfRelays * 4; relayListField.Value = PackRelays(); - GetField(2, (int)DataFields.NumberOfDigitalInputs).Index = relayListField.Index + relayListField.Size; + GetField(2, DataFields.NumberOfDigitalInputs).Index = relayListField.Index + relayListField.Size; - GetField(2, (int)DataFields.DigitalInputList).Index = GetField(2, (int)DataFields.NumberOfDigitalInputs).Index + 2; - GetField(2, (int)DataFields.DigitalInputList).Size = NumberOfDigitalInputs * 4; - GetField(2, (int)DataFields.DigitalInputList).Value = PackDigitalInputs(); + GetField(2, DataFields.DigitalInputList).Index = GetField(2, DataFields.NumberOfDigitalInputs).Index + 2; + GetField(2, DataFields.DigitalInputList).Size = NumberOfDigitalInputs * 4; + GetField(2, DataFields.DigitalInputList).Value = PackDigitalInputs(); } else { - Header.Revision = 1; - GetField(1, (int)DataFields.RelayList).Value = PackRelays(); - GetField(1, (int)DataFields.DigitalInputList).Value = PackDigitalInputs(); + GetField(1, DataFields.RelayList).Value = PackRelays(); + GetField(1, DataFields.DigitalInputList).Value = PackDigitalInputs(); } - string pkg = BuildHeader(); + var builder = new StringBuilder(BuildHeader()); int prefixIndex = 1; - foreach (var field in RevisionsByFields[Header.Revision]) + foreach (var field in RevisionsByFields[Header.StandardizedRevision]) { - pkg += prefixIndex.ToString().PadLeft(2, '0') + field.Value; + builder.Append(string.Concat(prefixIndex.ToString("D2"), field.Value)); prefixIndex++; } - return pkg; + return builder.ToString(); } public override Mid Parse(string package) { Header = ProcessHeader(package); - var revision = Header.Revision > 1 ? 2 : 1; + var revision = Header.StandardizedRevision; - var relayListField = GetField(revision, (int)DataFields.RelayList); - var digitalListField = GetField(revision, (int)DataFields.DigitalInputList); + var relayListField = GetField(revision, DataFields.RelayList); + var digitalListField = GetField(revision, DataFields.DigitalInputList); if (revision > 1) { - int numberOfRelays = OpenProtocolConvert.ToInt32(GetValue(GetField(2, (int)DataFields.NumberOfRelays), package)); + int numberOfRelays = OpenProtocolConvert.ToInt32(GetValue(GetField(2, DataFields.NumberOfRelays), package)); relayListField.Size = numberOfRelays * 4; - var numberOfDigitalInputsField = GetField(2, (int)DataFields.NumberOfDigitalInputs); + var numberOfDigitalInputsField = GetField(2, DataFields.NumberOfDigitalInputs); numberOfDigitalInputsField.Index = relayListField.Index + 2 + relayListField.Size; digitalListField.Index = numberOfDigitalInputsField.Index + 2 + numberOfDigitalInputsField.Size; @@ -128,26 +128,26 @@ public override Mid Parse(string package) ProcessDataFields(package); Relays = Relay.ParseAll(relayListField.Value).ToList(); - DigitalInputs =DigitalInput.ParseAll(digitalListField.Value).ToList(); + DigitalInputs = DigitalInput.ParseAll(digitalListField.Value).ToList(); return this; } protected virtual string PackRelays() { - string pack = string.Empty; + var value = new StringBuilder(); foreach (var relay in Relays) - pack += relay.Pack(); + value.Append(relay.Pack()); - return pack; + return value.ToString(); } protected virtual string PackDigitalInputs() { - string pack = string.Empty; + var value = new StringBuilder(); foreach (var digitalInput in DigitalInputs) - pack += digitalInput.Pack(); + value.Append(digitalInput.Pack()); - return pack; + return value.ToString(); } protected override Dictionary> RegisterDatafields() @@ -157,19 +157,19 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.IODeviceId, 20, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.RelayList, 24, 32), - new DataField((int)DataFields.DigitalInputList, 58, 32) + DataField.Number(DataFields.IODeviceId, 20, 2), + new(DataFields.RelayList, 24, 32), + new(DataFields.DigitalInputList, 58, 32) } }, { 2, new List() { - new DataField((int)DataFields.IODeviceId, 20, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.NumberOfRelays, 24, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.RelayList, 28, 0), - new DataField((int)DataFields.NumberOfDigitalInputs, 0, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.DigitalInputList, 0, 0) + DataField.Number(DataFields.IODeviceId, 20, 2), + DataField.Number(DataFields.NumberOfRelays, 24, 2), + DataField.Volatile(DataFields.RelayList, 28), + new(DataFields.NumberOfDigitalInputs, 0, 2, '0', PaddingOrientation.LeftPadded), + DataField.Volatile(DataFields.DigitalInputList) } } }; diff --git a/src/OpenProtocolInterpreter/IOInterface/Mid0216.cs b/src/OpenProtocolInterpreter/IOInterface/Mid0216.cs index e5d83148..786b8c04 100644 --- a/src/OpenProtocolInterpreter/IOInterface/Mid0216.cs +++ b/src/OpenProtocolInterpreter/IOInterface/Mid0216.cs @@ -23,8 +23,8 @@ public class Mid0216 : Mid, IIOInterface, IIntegrator, ISubscription, IAcceptabl public RelayNumber RelayNumber { - get => (RelayNumber)GetField(1,(int)DataFields.RelayNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.RelayNumber).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (RelayNumber)GetField(1, DataFields.RelayNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.RelayNumber).SetValue(OpenProtocolConvert.ToString, value); } public Mid0216() : this(false) @@ -53,7 +53,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.RelayNumber, 20, 3, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.RelayNumber, 20, 3, false) } } }; diff --git a/src/OpenProtocolInterpreter/IOInterface/Mid0217.cs b/src/OpenProtocolInterpreter/IOInterface/Mid0217.cs index 818c717b..ef8b8d1e 100644 --- a/src/OpenProtocolInterpreter/IOInterface/Mid0217.cs +++ b/src/OpenProtocolInterpreter/IOInterface/Mid0217.cs @@ -19,13 +19,13 @@ public class Mid0217 : Mid, IIOInterface, IController, IAcknowledgeable public RelayNumber RelayNumber { - get => (RelayNumber)GetField(1, (int)DataFields.RelayNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.RelayNumber).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (RelayNumber)GetField(1, DataFields.RelayNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.RelayNumber).SetValue(OpenProtocolConvert.ToString, value); } public bool RelayStatus { - get => GetField(1, (int)DataFields.RelayStatus).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.RelayStatus).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.RelayStatus).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.RelayStatus).SetValue(OpenProtocolConvert.ToString, value); } public Mid0217() : this(new Header() @@ -48,8 +48,8 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.RelayNumber, 20, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.RelayStatus, 25, 1) + DataField.Number(DataFields.RelayNumber, 20, 3), + DataField.Boolean(DataFields.RelayStatus, 25) } } }; diff --git a/src/OpenProtocolInterpreter/IOInterface/Mid0219.cs b/src/OpenProtocolInterpreter/IOInterface/Mid0219.cs index b7a900e2..e096f11c 100644 --- a/src/OpenProtocolInterpreter/IOInterface/Mid0219.cs +++ b/src/OpenProtocolInterpreter/IOInterface/Mid0219.cs @@ -20,8 +20,8 @@ public class Mid0219 : Mid, IIOInterface, IIntegrator, IUnsubscription, IAccepta public RelayNumber RelayNumber { - get => (RelayNumber)GetField(1, (int)DataFields.RelayNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.RelayNumber).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (RelayNumber)GetField(1, DataFields.RelayNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.RelayNumber).SetValue(OpenProtocolConvert.ToString, value); } public Mid0219() : this(new Header() @@ -44,7 +44,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.RelayNumber, 20, 3, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.RelayNumber, 20, 3, false) } } }; diff --git a/src/OpenProtocolInterpreter/IOInterface/Mid0220.cs b/src/OpenProtocolInterpreter/IOInterface/Mid0220.cs index dcdda097..94d3cead 100644 --- a/src/OpenProtocolInterpreter/IOInterface/Mid0220.cs +++ b/src/OpenProtocolInterpreter/IOInterface/Mid0220.cs @@ -25,8 +25,8 @@ public class Mid0220 : Mid, IIOInterface, IIntegrator, ISubscription, IAcceptabl public DigitalInputNumber DigitalInputNumber { - get => (DigitalInputNumber)GetField(1, (int)DataFields.DigitalInputNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.DigitalInputNumber).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (DigitalInputNumber)GetField(1, DataFields.DigitalInputNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.DigitalInputNumber).SetValue(OpenProtocolConvert.ToString, value); } public Mid0220() : this(false) @@ -55,7 +55,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.DigitalInputNumber, 20, 3, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.DigitalInputNumber, 20, 3, false) } } }; diff --git a/src/OpenProtocolInterpreter/IOInterface/Mid0221.cs b/src/OpenProtocolInterpreter/IOInterface/Mid0221.cs index 5ac8972e..3d63bfe2 100644 --- a/src/OpenProtocolInterpreter/IOInterface/Mid0221.cs +++ b/src/OpenProtocolInterpreter/IOInterface/Mid0221.cs @@ -20,13 +20,13 @@ public class Mid0221 : Mid, IIOInterface, IController, IAcknowledgeable public DigitalInputNumber DigitalInputNumber { - get => (DigitalInputNumber)GetField(1,(int)DataFields.DigitalInputNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.DigitalInputNumber).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (DigitalInputNumber)GetField(1, DataFields.DigitalInputNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.DigitalInputNumber).SetValue(OpenProtocolConvert.ToString, value); } public bool DigitalInputStatus { - get => GetField(1,(int)DataFields.DigitalInputStatus).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1,(int)DataFields.DigitalInputStatus).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.DigitalInputStatus).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.DigitalInputStatus).SetValue(OpenProtocolConvert.ToString, value); } public Mid0221() : this(new Header() @@ -48,8 +48,8 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.DigitalInputNumber, 20, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.DigitalInputStatus, 25, 1) + DataField.Number(DataFields.DigitalInputNumber, 20, 3), + DataField.Boolean(DataFields.DigitalInputStatus, 25) } } }; diff --git a/src/OpenProtocolInterpreter/IOInterface/Mid0223.cs b/src/OpenProtocolInterpreter/IOInterface/Mid0223.cs index d66788f9..539bb5c7 100644 --- a/src/OpenProtocolInterpreter/IOInterface/Mid0223.cs +++ b/src/OpenProtocolInterpreter/IOInterface/Mid0223.cs @@ -20,17 +20,17 @@ public class Mid0223 : Mid, IIOInterface, IIntegrator, IUnsubscription, IAccepta public DigitalInputNumber DigitalInputNumber { - get => (DigitalInputNumber)GetField(1,(int)DataFields.DigitalInputNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.DigitalInputNumber).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (DigitalInputNumber)GetField(1, DataFields.DigitalInputNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.DigitalInputNumber).SetValue(OpenProtocolConvert.ToString, value); } public Mid0223() : this(new Header() { - Mid = MID, + Mid = MID, Revision = DEFAULT_REVISION }) { - + } public Mid0223(Header header) : base(header) @@ -44,7 +44,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.DigitalInputNumber, 20, 3, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.DigitalInputNumber, 20, 3, false) } } }; diff --git a/src/OpenProtocolInterpreter/IOInterface/Mid0224.cs b/src/OpenProtocolInterpreter/IOInterface/Mid0224.cs index debb2655..e48f7f7c 100644 --- a/src/OpenProtocolInterpreter/IOInterface/Mid0224.cs +++ b/src/OpenProtocolInterpreter/IOInterface/Mid0224.cs @@ -19,8 +19,8 @@ public class Mid0224 : Mid, IIOInterface, IIntegrator, IAcceptableCommand, IDecl public DigitalInputNumber DigitalInputNumber { - get => (DigitalInputNumber)GetField(1,(int)DataFields.DigitalInputNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.DigitalInputNumber).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (DigitalInputNumber)GetField(1, DataFields.DigitalInputNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.DigitalInputNumber).SetValue(OpenProtocolConvert.ToString, value); } public Mid0224() : this(new Header() @@ -43,7 +43,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.DigitalInputNumber, 20, 3, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.DigitalInputNumber, 20, 3, false) } } }; diff --git a/src/OpenProtocolInterpreter/IOInterface/Mid0225.cs b/src/OpenProtocolInterpreter/IOInterface/Mid0225.cs index c369b17b..c4d8c82e 100644 --- a/src/OpenProtocolInterpreter/IOInterface/Mid0225.cs +++ b/src/OpenProtocolInterpreter/IOInterface/Mid0225.cs @@ -24,8 +24,8 @@ public class Mid0225 : Mid, IIOInterface, IIntegrator, IAcceptableCommand, IDecl public DigitalInputNumber DigitalInputNumber { - get => (DigitalInputNumber)GetField(1,(int)DataFields.DigitalInputNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.DigitalInputNumber).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (DigitalInputNumber)GetField(1, DataFields.DigitalInputNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.DigitalInputNumber).SetValue(OpenProtocolConvert.ToString, value); } public Mid0225() : this(new Header() @@ -48,7 +48,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.DigitalInputNumber, 20, 3, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.DigitalInputNumber, 20, 3, false) } } }; diff --git a/src/OpenProtocolInterpreter/Job/Advanced/AdvancedJob.cs b/src/OpenProtocolInterpreter/Job/Advanced/AdvancedJob.cs index dee10707..9a196bab 100644 --- a/src/OpenProtocolInterpreter/Job/Advanced/AdvancedJob.cs +++ b/src/OpenProtocolInterpreter/Job/Advanced/AdvancedJob.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; namespace OpenProtocolInterpreter.Job.Advanced { @@ -26,24 +27,25 @@ public class AdvancedJob public string Pack(int revision) { + var batchSizeFieldSize = revision > 3 && revision != 999 ? 4 : 2; var fields = new List { OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, ChannelId), - OpenProtocolConvert.ToString('0', 3, PaddingOrientation.LeftPadded, revision), - OpenProtocolConvert.ToString((int)revision), - OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, revision), - OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, revision) + OpenProtocolConvert.ToString('0', 3, PaddingOrientation.LeftPadded, ProgramId), + OpenProtocolConvert.ToString((int)AutoSelect), + OpenProtocolConvert.ToString('0', batchSizeFieldSize, PaddingOrientation.LeftPadded, BatchSize), + OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, MaxCoherentNok) }; if (revision > 1) { - fields.Add(OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, revision)); + fields.Add(OpenProtocolConvert.ToString('0', batchSizeFieldSize, PaddingOrientation.LeftPadded, BatchCounter)); if (revision != 999) { - fields.Add(OpenProtocolConvert.ToString('0', 4, PaddingOrientation.LeftPadded, revision)); + fields.Add(OpenProtocolConvert.ToString('0', 4, PaddingOrientation.LeftPadded, IdentifierNumber)); fields.Add(OpenProtocolConvert.TruncatePadded(' ', 25, PaddingOrientation.RightPadded, JobStepName)); - fields.Add(OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, revision)); - if (revision == 3) + fields.Add(OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, JobStepType)); + if (revision > 2) { fields.Add(OpenProtocolConvert.ToString((int)ToolLoosening)); fields.Add(OpenProtocolConvert.ToString((int)JobBatchMode)); @@ -77,7 +79,7 @@ public static AdvancedJob Parse(string section, int revision) obj.IdentifierNumber = OpenProtocolConvert.ToInt32(fields[6]); obj.JobStepName = fields[7]; obj.JobStepType = OpenProtocolConvert.ToInt32(fields[8]); - if (revision == 3) + if (revision > 2) { obj.ToolLoosening = (ToolLoosening)OpenProtocolConvert.ToInt32(fields[9]); obj.JobBatchMode = (BatchMode)OpenProtocolConvert.ToInt32(fields[10]); @@ -98,11 +100,24 @@ public static IEnumerable ParseAll(string section, int revision) yield break; } - var splitted = section.Split(';'); - foreach (var advancedJob in splitted) + var jobs = section.Split(';').ToList(); + jobs.RemoveAll(string.IsNullOrWhiteSpace); //remove last one which will probably be empty + foreach (var advancedJob in jobs) { yield return Parse(advancedJob, revision); } } + + internal static int GetDefaultSize(int revision) + { + return revision switch + { + 2 => 52, + 3 => 63, + 4 => 67, + 999 => 18, + _ => 15, + }; + } } } diff --git a/src/OpenProtocolInterpreter/Job/Advanced/Mid0129.cs b/src/OpenProtocolInterpreter/Job/Advanced/Mid0129.cs index 78cd9501..833064f4 100644 --- a/src/OpenProtocolInterpreter/Job/Advanced/Mid0129.cs +++ b/src/OpenProtocolInterpreter/Job/Advanced/Mid0129.cs @@ -23,13 +23,13 @@ public class Mid0129 : Mid, IAdvancedJob, IIntegrator, IAcceptableCommand, IDecl public int ChannelId { - get => GetField(2, (int)DataFields.ChannelId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.ChannelId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.ChannelId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.ChannelId).SetValue(OpenProtocolConvert.ToString, value); } public int ParameterSetId { - get => GetField(2, (int)DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); } public Mid0129() : this(DEFAULT_REVISION) @@ -57,8 +57,8 @@ protected override Dictionary> RegisterDatafields() { 2, new List() { - new DataField((int)DataFields.ChannelId, 20, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ParameterSetId, 24, 3, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.ChannelId, 20, 2), + DataField.Number(DataFields.ParameterSetId, 24, 3) } } }; diff --git a/src/OpenProtocolInterpreter/Job/Advanced/Mid0130.cs b/src/OpenProtocolInterpreter/Job/Advanced/Mid0130.cs index 04fd5af4..17d80b40 100644 --- a/src/OpenProtocolInterpreter/Job/Advanced/Mid0130.cs +++ b/src/OpenProtocolInterpreter/Job/Advanced/Mid0130.cs @@ -18,17 +18,17 @@ public class Mid0130 : Mid, IAdvancedJob, IIntegrator, IAcceptableCommand /// public bool JobOffStatus { - get => GetField(1,(int)DataFields.JobOffStatus).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1,(int)DataFields.JobOffStatus).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.JobOffStatus).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.JobOffStatus).SetValue(OpenProtocolConvert.ToString, value); } public Mid0130() : this(new Header() { - Mid = MID, + Mid = MID, Revision = DEFAULT_REVISION }) { - + } public Mid0130(Header header) : base(header) @@ -42,7 +42,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.JobOffStatus, 20, 1, false), + DataField.Boolean(DataFields.JobOffStatus, 20, false), } } }; diff --git a/src/OpenProtocolInterpreter/Job/Advanced/Mid0140.cs b/src/OpenProtocolInterpreter/Job/Advanced/Mid0140.cs index 46fe32a1..54fd75e3 100644 --- a/src/OpenProtocolInterpreter/Job/Advanced/Mid0140.cs +++ b/src/OpenProtocolInterpreter/Job/Advanced/Mid0140.cs @@ -22,100 +22,100 @@ public class Mid0140 : Mid, IAdvancedJob, IIntegrator, IAcceptableCommand public int JobId { - get => GetField(GetNormalizedRevision(), (int)DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetNormalizedRevision(), (int)DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); } public string JobName { - get => GetField(GetNormalizedRevision(), (int)DataFields.JobName).Value; - set => GetField(GetNormalizedRevision(), (int)DataFields.JobName).SetValue(value); + get => GetField(Header.StandardizedRevision, DataFields.JobName).Value; + set => GetField(Header.StandardizedRevision, DataFields.JobName).SetValue(value); } public int NumberOfParameterSets { - get => GetField(GetNormalizedRevision(), (int)DataFields.NumberOfParameterSets).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetNormalizedRevision(), (int)DataFields.NumberOfParameterSets).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.NumberOfParameterSets).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.NumberOfParameterSets).SetValue(OpenProtocolConvert.ToString, value); } public List JobList { get; set; } public ForcedOrder ForcedOrder { - get => (ForcedOrder)GetField(GetNormalizedRevision(), (int)DataFields.ForcedOrder).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetNormalizedRevision(), (int)DataFields.ForcedOrder).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (ForcedOrder)GetField(Header.StandardizedRevision, DataFields.ForcedOrder).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.ForcedOrder).SetValue(OpenProtocolConvert.ToString, value); } public bool LockAtJobDone { - get => GetField(GetNormalizedRevision(), (int)DataFields.LockAtJobDone).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(GetNormalizedRevision(), (int)DataFields.LockAtJobDone).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.LockAtJobDone).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(Header.StandardizedRevision, DataFields.LockAtJobDone).SetValue(OpenProtocolConvert.ToString, value); } public ToolLoosening ToolLoosening { - get => (ToolLoosening)GetField(GetNormalizedRevision(), (int)DataFields.ToolLoosening).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetNormalizedRevision(), (int)DataFields.ToolLoosening).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (ToolLoosening)GetField(Header.StandardizedRevision, DataFields.ToolLoosening).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.ToolLoosening).SetValue(OpenProtocolConvert.ToString, value); } public bool RepeatJob { - get => GetField(GetNormalizedRevision(), (int)DataFields.RepeatJob).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(GetNormalizedRevision(), (int)DataFields.RepeatJob).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.RepeatJob).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(Header.StandardizedRevision, DataFields.RepeatJob).SetValue(OpenProtocolConvert.ToString, value); } public BatchMode BatchMode { - get => (BatchMode)GetField(GetNormalizedRevision(), (int)DataFields.JobBatchDone).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetNormalizedRevision(), (int)DataFields.JobBatchDone).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (BatchMode)GetField(Header.StandardizedRevision, DataFields.JobBatchDone).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.JobBatchDone).SetValue(OpenProtocolConvert.ToString, value); } public bool BatchStatusAtIncrement { - get => GetField(GetNormalizedRevision(), (int)DataFields.BatchStatusAtIncrement).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(GetNormalizedRevision(), (int)DataFields.BatchStatusAtIncrement).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.BatchStatusAtIncrement).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(Header.StandardizedRevision, DataFields.BatchStatusAtIncrement).SetValue(OpenProtocolConvert.ToString, value); } public bool DecrementBatchAtOkLoosening { - get => GetField(GetNormalizedRevision(), (int)DataFields.DecrementBatchAtOkLoosening).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(GetNormalizedRevision(), (int)DataFields.DecrementBatchAtOkLoosening).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.DecrementBatchAtOkLoosening).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(Header.StandardizedRevision, DataFields.DecrementBatchAtOkLoosening).SetValue(OpenProtocolConvert.ToString, value); } public int MaxTimeForFirstTightening { - get => GetField(GetNormalizedRevision(), (int)DataFields.MaxTimeForFirstTightening).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetNormalizedRevision(), (int)DataFields.MaxTimeForFirstTightening).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.MaxTimeForFirstTightening).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.MaxTimeForFirstTightening).SetValue(OpenProtocolConvert.ToString, value); } public int MaxTimeToCompleteJob { - get => GetField(GetNormalizedRevision(), (int)DataFields.MaxTimeToCompleteJob).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetNormalizedRevision(), (int)DataFields.MaxTimeToCompleteJob).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.MaxTimeToCompleteJob).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.MaxTimeToCompleteJob).SetValue(OpenProtocolConvert.ToString, value); } public int DisplayResultAtAutoSelect { - get => GetField(GetNormalizedRevision(), (int)DataFields.DisplayResultAtAutoSelect).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetNormalizedRevision(), (int)DataFields.DisplayResultAtAutoSelect).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.DisplayResultAtAutoSelect).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.DisplayResultAtAutoSelect).SetValue(OpenProtocolConvert.ToString, value); } public bool UsingLineControl { - get => GetField(GetNormalizedRevision(), (int)DataFields.UseLineControl).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(GetNormalizedRevision(), (int)DataFields.UseLineControl).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.UseLineControl).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(Header.StandardizedRevision, DataFields.UseLineControl).SetValue(OpenProtocolConvert.ToString, value); } public IdentifierPart IdentifierResultPart { - get => (IdentifierPart)GetField(GetNormalizedRevision(), (int)DataFields.IdentifierResultPart).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetNormalizedRevision(), (int)DataFields.IdentifierResultPart).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (IdentifierPart)GetField(Header.StandardizedRevision, DataFields.IdentifierResultPart).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.IdentifierResultPart).SetValue(OpenProtocolConvert.ToString, value); } public bool ResultOfNonTightenings { - get => GetField(GetNormalizedRevision(), (int)DataFields.ResultOfNonTightenings).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(GetNormalizedRevision(), (int)DataFields.ResultOfNonTightenings).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.ResultOfNonTightenings).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(Header.StandardizedRevision, DataFields.ResultOfNonTightenings).SetValue(OpenProtocolConvert.ToString, value); } public bool ResetAllIdentifiersAtJobDone { - get => GetField(GetNormalizedRevision(), (int)DataFields.ResetAllIdentifiersAtJobDone).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(GetNormalizedRevision(), (int)DataFields.ResetAllIdentifiersAtJobDone).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.ResetAllIdentifiersAtJobDone).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(Header.StandardizedRevision, DataFields.ResetAllIdentifiersAtJobDone).SetValue(OpenProtocolConvert.ToString, value); } public Reserved Reserved { - get => (Reserved)GetField(GetNormalizedRevision(), (int)DataFields.Reserved).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetNormalizedRevision(), (int)DataFields.Reserved).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (Reserved)GetField(Header.StandardizedRevision, DataFields.Reserved).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.Reserved).SetValue(OpenProtocolConvert.ToString, value); } public int JobSequenceNumber { - get => GetField(GetNormalizedRevision(), (int)DataFields.JobSequenceNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetNormalizedRevision(), (int)DataFields.JobSequenceNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.JobSequenceNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.JobSequenceNumber).SetValue(OpenProtocolConvert.ToString, value); } public Mid0140() : this(DEFAULT_REVISION) @@ -125,7 +125,7 @@ public Mid0140() : this(DEFAULT_REVISION) public Mid0140(Header header) : base(header) { - JobList = new List(); + JobList = []; } public Mid0140(int revision) : this(new Header() @@ -136,141 +136,169 @@ public Mid0140(int revision) : this(new Header() { } + protected override string BuildHeader() + { + var revision = Header.StandardizedRevision; + Header.Length = 20 + RevisionsByFields[revision].Sum(x=> x.Size + (x.HasPrefix ? 2 : 0)); + return Header.ToString(); + } public override string Pack() { - var revision = GetNormalizedRevision(); - var jobListField = GetField(revision, (int)DataFields.JobList); - jobListField.Size = JobList.Count * GetJobListSize(); - AdjustDataFieldsIndexes(); - jobListField.Value = PackJobList(); - return base.Pack(); + var revision = Header.StandardizedRevision; + ResetDataFields(revision); + var jobListField = GetField(revision, DataFields.JobList); + jobListField.Size = JobList.Count * AdvancedJob.GetDefaultSize(revision); + AdjustDataFieldsIndexes(jobListField.Index + jobListField.Size + 2, revision); + jobListField.Value = PackJobList(revision); + int prefixIndex = 1; + return string.Concat(BuildHeader(), base.Pack(revision, ref prefixIndex)); } public override Mid Parse(string package) { Header = ProcessHeader(package); int length = Header.Length; - var revision = GetNormalizedRevision(); - foreach (var rev in RevisionsByFields[revision]) - length -= rev.Size; - - var jobListField = GetField(revision, (int)DataFields.JobList); - jobListField.Size = length; - AdjustDataFieldsIndexes(); - base.ProcessDataFields(package); - JobList = AdvancedJob.ParseAll(jobListField.Value, Header.Revision).ToList(); + var revision = Header.StandardizedRevision; + ResetDataFields(revision); + var numberOfParameterSetsField = RevisionsByFields[revision].First(x => x.Field == (int)DataFields.NumberOfParameterSets); + var numberOfParameterSets = int.Parse(package.Substring(numberOfParameterSetsField.Index + 2, numberOfParameterSetsField.Size)); + var jobListField = GetField(revision, DataFields.JobList); + jobListField.Size = numberOfParameterSets * AdvancedJob.GetDefaultSize(revision); + AdjustDataFieldsIndexes(jobListField.Index + jobListField.Size + 2, revision); + base.ProcessDataFields(revision, package); + JobList = AdvancedJob.ParseAll(jobListField.Value, revision).ToList(); return this; } - protected virtual string PackJobList() + protected virtual string PackJobList(int revision) { var advancedJobsList = new List(); foreach (var job in JobList) { - advancedJobsList.Add(job.Pack(Header.Revision)); + advancedJobsList.Add(job.Pack(revision)); } - return string.Join(";", advancedJobsList); + return string.Join(";", advancedJobsList) + ";"; } - private void AdjustDataFieldsIndexes() + private void AdjustDataFieldsIndexes(int currentIndex, int revision) { - var revision = GetNormalizedRevision(); - var jobListField = GetField(revision, (int)DataFields.JobList); - jobListField.Size = NumberOfParameterSets * GetJobListSize(); - int index = jobListField.Index + jobListField.Size + 2; - int startAt = revision != 2 ? (int)DataFields.ForcedOrder : (int)DataFields.JobSequenceNumber; foreach (var field in RevisionsByFields[revision]) { - if (field.Field >= startAt) + if (field.Field > (int)DataFields.JobList) { - field.Index = index; - index += 2 + field.Size; + field.Index = currentIndex; + currentIndex += 2 + field.Size; } } } - private int GetNormalizedRevision() - { - if (Header.Revision == 999) - { - return 1; - } - - return Header.Revision; - } - - private int GetJobListSize() + private void ResetDataFields(int revision) { - var revision = GetNormalizedRevision(); - switch (revision) - { - case 2: return 52; - case 3: return 63; - case 999: return 18; - default: return 15; - }; + //TODO: think of a better approach in case user repeats packing or parsing + var fields = RevisionsByFields[revision].Where(x => x.Field > (int)DataFields.JobList); + foreach (var field in fields) + field.Index = 0; } protected override Dictionary> RegisterDatafields() { + //All the workarounds are made due to inconsistent "additions" from protocol, since there are many fields moved + //to JobList/Parameter list, the DataFields start to shuffle every revision return new Dictionary>() { { 1, new List() { - new DataField((int)DataFields.JobId, 20, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.JobName, 26, 25, ' '), - new DataField((int)DataFields.NumberOfParameterSets, 53, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.JobList, 57, 0), - new DataField((int)DataFields.ForcedOrder, 0, 1), - new DataField((int)DataFields.LockAtJobDone, 0, 1), - new DataField((int)DataFields.ToolLoosening, 0, 1), - new DataField((int)DataFields.RepeatJob, 0, 1), - new DataField((int)DataFields.JobBatchDone, 0, 1), - new DataField((int)DataFields.BatchStatusAtIncrement, 0, 1), - new DataField((int)DataFields.DecrementBatchAtOkLoosening, 0, 1), - new DataField((int)DataFields.MaxTimeForFirstTightening, 0, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.MaxTimeToCompleteJob, 0, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.DisplayResultAtAutoSelect, 0, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.UseLineControl, 0, 1), - new DataField((int)DataFields.IdentifierResultPart, 0, 1), - new DataField((int)DataFields.ResultOfNonTightenings, 0, 1), - new DataField((int)DataFields.ResetAllIdentifiersAtJobDone, 0, 1), - new DataField((int)DataFields.Reserved, 0, 1) + DataField.Number(DataFields.JobId, 20, 4), + DataField.String(DataFields.JobName, 26, 25), + DataField.Number(DataFields.NumberOfParameterSets, 53, 2), + DataField.Volatile(DataFields.JobList, 57), + DataField.Number(DataFields.ForcedOrder, 0, 1), + DataField.Boolean(DataFields.LockAtJobDone, 0), + DataField.Number(DataFields.ToolLoosening, 0, 1), + DataField.Boolean(DataFields.RepeatJob, 0), + DataField.Number(DataFields.JobBatchDone, 0, 1), + DataField.Boolean(DataFields.BatchStatusAtIncrement, 0), + DataField.Boolean(DataFields.DecrementBatchAtOkLoosening, 0), + DataField.Number(DataFields.MaxTimeForFirstTightening, 0, 4), + DataField.Number(DataFields.MaxTimeToCompleteJob, 0, 5), + DataField.Number(DataFields.DisplayResultAtAutoSelect, 0, 4), + DataField.Boolean(DataFields.UseLineControl, 0), + DataField.Number(DataFields.IdentifierResultPart, 0, 1), + DataField.Boolean(DataFields.ResultOfNonTightenings, 0), + DataField.Boolean(DataFields.ResetAllIdentifiersAtJobDone, 0), + DataField.Number(DataFields.Reserved, 0, 1) } }, { 2, new List() { - new DataField((int)DataFields.JobId, 20, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.JobName, 26, 25, ' '), - new DataField((int)DataFields.NumberOfParameterSets, 53, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.JobList, 57, 0), - new DataField((int)DataFields.JobSequenceNumber, 0, 5), + DataField.Number(DataFields.JobId, 20, 4), + DataField.String(DataFields.JobName, 26, 25), + DataField.Number(DataFields.NumberOfParameterSets, 53, 2), + DataField.Volatile(DataFields.JobList, 57), + DataField.Number(DataFields.ForcedOrder, 0, 1), + DataField.Boolean(DataFields.LockAtJobDone, 0), + DataField.Number(DataFields.ToolLoosening, 0, 1), + DataField.Boolean(DataFields.RepeatJob, 0), + DataField.Number(DataFields.JobBatchDone, 0, 1), + DataField.Boolean(DataFields.BatchStatusAtIncrement, 0), + DataField.Boolean(DataFields.DecrementBatchAtOkLoosening, 0), + DataField.Number(DataFields.MaxTimeForFirstTightening, 0, 4), + DataField.Number(DataFields.MaxTimeToCompleteJob, 0, 5), + DataField.Number(DataFields.DisplayResultAtAutoSelect, 0, 4), + DataField.Boolean(DataFields.UseLineControl, 0), + DataField.Number(DataFields.IdentifierResultPart, 0, 1), + DataField.Boolean(DataFields.ResultOfNonTightenings, 0), + DataField.Boolean(DataFields.ResetAllIdentifiersAtJobDone, 0), + DataField.Number(DataFields.Reserved, 0, 1), + DataField.Number(DataFields.JobSequenceNumber, 0, 5), } }, { 3, new List() { - new DataField((int)DataFields.JobId, 20, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.JobName, 26, 25, ' '), - new DataField((int)DataFields.NumberOfParameterSets, 53, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.JobList, 57, 0), - new DataField((int)DataFields.ForcedOrder, 0, 1), - new DataField((int)DataFields.LockAtJobDone, 0, 1), - new DataField((int)DataFields.MaxTimeForFirstTightening, 0, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.MaxTimeToCompleteJob, 0, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.DisplayResultAtAutoSelect, 0, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.UseLineControl, 0, 1), - new DataField((int)DataFields.IdentifierResultPart, 0, 1), - new DataField((int)DataFields.ResultOfNonTightenings, 0, 1), - new DataField((int)DataFields.ResetAllIdentifiersAtJobDone, 0, 1), - new DataField((int)DataFields.Reserved, 0, 1), - new DataField((int)DataFields.JobSequenceNumber, 0, 5) + DataField.Number(DataFields.JobId, 20, 4), + DataField.String(DataFields.JobName, 26, 25), + DataField.Number(DataFields.NumberOfParameterSets, 53, 2), + DataField.Volatile(DataFields.JobList, 57), + DataField.Number(DataFields.ForcedOrder, 0, 1), + DataField.Boolean(DataFields.LockAtJobDone, 0), + DataField.Boolean(DataFields.RepeatJob, 0), + DataField.Number(DataFields.MaxTimeForFirstTightening, 0, 4), + DataField.Number(DataFields.MaxTimeToCompleteJob, 0, 5), + DataField.Number(DataFields.DisplayResultAtAutoSelect, 0, 4), + DataField.Boolean(DataFields.UseLineControl, 0), + DataField.Number(DataFields.IdentifierResultPart, 0, 1), + DataField.Boolean(DataFields.ResultOfNonTightenings, 0), + DataField.Boolean(DataFields.ResetAllIdentifiersAtJobDone, 0), + DataField.Number(DataFields.Reserved, 0, 1), + DataField.Number(DataFields.JobSequenceNumber, 0, 5) + } + }, + { + 4, new List() + { + DataField.Number(DataFields.JobId, 20, 4), + DataField.String(DataFields.JobName, 26, 25), + DataField.Number(DataFields.NumberOfParameterSets, 53, 2), + DataField.Volatile(DataFields.JobList, 57), + DataField.Number(DataFields.ForcedOrder, 0, 1), + DataField.Boolean(DataFields.LockAtJobDone, 0), + DataField.Boolean(DataFields.RepeatJob, 0), + DataField.Number(DataFields.MaxTimeForFirstTightening, 0, 4), + DataField.Number(DataFields.MaxTimeToCompleteJob, 0, 5), + DataField.Number(DataFields.DisplayResultAtAutoSelect, 0, 4), + DataField.Boolean(DataFields.UseLineControl, 0), + DataField.Number(DataFields.IdentifierResultPart, 0, 1), + DataField.Boolean(DataFields.ResultOfNonTightenings, 0), + DataField.Boolean(DataFields.ResetAllIdentifiersAtJobDone, 0), + DataField.Number(DataFields.Reserved, 0, 1), + DataField.Number(DataFields.JobSequenceNumber, 0, 5) } } }; diff --git a/src/OpenProtocolInterpreter/Job/Mid0031.cs b/src/OpenProtocolInterpreter/Job/Mid0031.cs index 3ab7a4bb..a4509c47 100644 --- a/src/OpenProtocolInterpreter/Job/Mid0031.cs +++ b/src/OpenProtocolInterpreter/Job/Mid0031.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Text; namespace OpenProtocolInterpreter.Job { @@ -19,8 +20,8 @@ public class Mid0031 : Mid, IJob, IController public int TotalJobs { - get => GetField(1, (int)DataFields.NumberOfJobs).GetValue(OpenProtocolConvert.ToInt32); - private set => GetField(1, (int)DataFields.NumberOfJobs).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.NumberOfJobs).GetValue(OpenProtocolConvert.ToInt32); + private set => GetField(1, DataFields.NumberOfJobs).SetValue(OpenProtocolConvert.ToString, value); } public List JobIds { get; set; } @@ -32,8 +33,7 @@ public Mid0031() : this(DEFAULT_REVISION) public Mid0031(Header header) : base(header) { - if (JobIds == null) - JobIds = new List(); + JobIds ??= []; HandleRevisions(); } @@ -50,7 +50,7 @@ public override string Pack() { TotalJobs = JobIds.Count; - var eachJobField = GetField(1, (int)DataFields.EachJobId); + var eachJobField = GetField(1, DataFields.EachJobId); eachJobField.Size = JobSize * TotalJobs; eachJobField.Value = PackJobIdList(); return base.Pack(); @@ -61,7 +61,7 @@ public override Mid Parse(string package) Header = ProcessHeader(package); HandleRevisions(); - var eachJobField = GetField(1, (int)DataFields.EachJobId); + var eachJobField = GetField(1, DataFields.EachJobId); eachJobField.Size = Header.Length - eachJobField.Index; base.Parse(package); JobIds = ParseJobIdList(eachJobField.Value); @@ -71,11 +71,11 @@ public override Mid Parse(string package) protected virtual string PackJobIdList() { - string pack = string.Empty; - foreach (var v in JobIds) - pack += OpenProtocolConvert.ToString('0', JobSize, PaddingOrientation.LeftPadded, v); + var builder = new StringBuilder(); + foreach (var jobId in JobIds) + builder.Append(OpenProtocolConvert.ToString('0', JobSize, PaddingOrientation.LeftPadded, jobId)); - return pack; + return builder.ToString(); } protected virtual List ParseJobIdList(string section) @@ -101,8 +101,8 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.NumberOfJobs, 20, 2, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.EachJobId, 22, 2, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.NumberOfJobs, 20, 2, false), + DataField.Number(DataFields.EachJobId, 22, 2, false) } }, }; @@ -112,12 +112,12 @@ private void HandleRevisions() { if (Header.Revision > 1) { - GetField(1, (int)DataFields.NumberOfJobs).Size = 4; - GetField(1, (int)DataFields.EachJobId).Index = 24; + GetField(1, DataFields.NumberOfJobs).Size = 4; + GetField(1, DataFields.EachJobId).Index = 24; } else { - GetField(1, (int)DataFields.NumberOfJobs).Size = GetField(1, (int)DataFields.EachJobId).Size = 2; + GetField(1, DataFields.NumberOfJobs).Size = GetField(1, DataFields.EachJobId).Size = 2; } } diff --git a/src/OpenProtocolInterpreter/Job/Mid0032.cs b/src/OpenProtocolInterpreter/Job/Mid0032.cs index ca004139..43831d93 100644 --- a/src/OpenProtocolInterpreter/Job/Mid0032.cs +++ b/src/OpenProtocolInterpreter/Job/Mid0032.cs @@ -16,8 +16,8 @@ public class Mid0032 : Mid, IJob, IIntegrator, IAnswerableBy, IDeclinab public int JobId { - get => GetField(1, (int)DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); } public Mid0032() : this(DEFAULT_REVISION) @@ -54,7 +54,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.JobId, 20, 2, '0', PaddingOrientation.LeftPadded, false), + DataField.Number(DataFields.JobId, 20, 2, false), } } }; @@ -63,9 +63,9 @@ protected override Dictionary> RegisterDatafields() private void HandleRevision() { if (Header.Revision == 1) - GetField(1, (int)DataFields.JobId).Size = 2; + GetField(1, DataFields.JobId).Size = 2; else - GetField(1, (int)DataFields.JobId).Size = 4; + GetField(1, DataFields.JobId).Size = 4; } protected enum DataFields diff --git a/src/OpenProtocolInterpreter/Job/Mid0033.cs b/src/OpenProtocolInterpreter/Job/Mid0033.cs index 9ab87031..dacce8e0 100644 --- a/src/OpenProtocolInterpreter/Job/Mid0033.cs +++ b/src/OpenProtocolInterpreter/Job/Mid0033.cs @@ -15,63 +15,63 @@ public class Mid0033 : Mid, IJob, IController public int JobId { - get => GetField(1, (int)DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); } public string JobName { - get => GetField(1, (int)DataFields.JobName).Value; - set => GetField(1, (int)DataFields.JobName).SetValue(value); + get => GetField(1, DataFields.JobName).Value; + set => GetField(1, DataFields.JobName).SetValue(value); } public ForcedOrder ForcedOrder { - get => (ForcedOrder)GetField(1, (int)DataFields.ForcedOrder).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ForcedOrder).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (ForcedOrder)GetField(1, DataFields.ForcedOrder).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ForcedOrder).SetValue(OpenProtocolConvert.ToString, value); } public int MaxTimeForFirstTightening { - get => GetField(1, (int)DataFields.MaxTimeForFirstTightening).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.MaxTimeForFirstTightening).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.MaxTimeForFirstTightening).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.MaxTimeForFirstTightening).SetValue(OpenProtocolConvert.ToString, value); } public int MaxTimeToCompleteJob { - get => GetField(1, (int)DataFields.MaxTimeToCompleteJob).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.MaxTimeToCompleteJob).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.MaxTimeToCompleteJob).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.MaxTimeToCompleteJob).SetValue(OpenProtocolConvert.ToString, value); } public JobBatchMode JobBatchMode { - get => (JobBatchMode)GetField(1, (int)DataFields.JobBatchDone).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.JobBatchDone).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (JobBatchMode)GetField(1, DataFields.JobBatchDone).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.JobBatchDone).SetValue(OpenProtocolConvert.ToString, value); } public bool LockAtJobDone { - get => GetField(1, (int)DataFields.LockAtJobDone).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.LockAtJobDone).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.LockAtJobDone).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.LockAtJobDone).SetValue(OpenProtocolConvert.ToString, value); } public bool UseLineControl { - get => GetField(1, (int)DataFields.UseLineControl).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.UseLineControl).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.UseLineControl).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.UseLineControl).SetValue(OpenProtocolConvert.ToString, value); } public bool RepeatJob { - get => GetField(1, (int)DataFields.RepeatJob).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.RepeatJob).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.RepeatJob).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.RepeatJob).SetValue(OpenProtocolConvert.ToString, value); } public ToolLoosening ToolLoosening { - get => (ToolLoosening)GetField(1, (int)DataFields.ToolLoosening).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ToolLoosening).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (ToolLoosening)GetField(1, DataFields.ToolLoosening).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ToolLoosening).SetValue(OpenProtocolConvert.ToString, value); } public Reserved Reserved { - get => (Reserved)GetField(1, (int)DataFields.Reserved).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.Reserved).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (Reserved)GetField(1, DataFields.Reserved).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.Reserved).SetValue(OpenProtocolConvert.ToString, value); } public int NumberOfParameterSets { - get => GetField(1, (int)DataFields.NumberOfParameterSets).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.NumberOfParameterSets).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.NumberOfParameterSets).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.NumberOfParameterSets).SetValue(OpenProtocolConvert.ToString, value); } public List ParameterSetList { get; set; } @@ -82,9 +82,7 @@ public Mid0033() : this(DEFAULT_REVISION) public Mid0033(Header header) : base(header) { - if (ParameterSetList == null) - ParameterSetList = new List(); - HandleRevisions(); + ParameterSetList ??= []; } public Mid0033(int revision) : this(new Header() @@ -100,8 +98,8 @@ public override string Pack() HandleRevisions(); NumberOfParameterSets = ParameterSetList.Count; - var psetListField = GetField(1, (int)DataFields.ParameterSetList); - psetListField.Size = ParameterSetList.Count * GetEachParameterSetSize(); + var psetListField = GetField(1, DataFields.ParameterSetList); + psetListField.Size = ParameterSetList.Count * ParameterSet.Size(Header.Revision); psetListField.Value = PackParameterSetList(); return base.Pack(); } @@ -110,7 +108,7 @@ public override Mid Parse(string package) { Header = ProcessHeader(package); HandleRevisions(); - var jobListField = GetField(1, (int)DataFields.ParameterSetList); + var jobListField = GetField(1, DataFields.ParameterSetList); jobListField.Size = Header.Length - jobListField.Index - 2; base.Parse(package); ParameterSetList = ParameterSet.ParseAll(jobListField.Value, Header.Revision).ToList(); @@ -135,19 +133,19 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.JobId, 20, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.JobName, 24, 25, ' '), - new DataField((int)DataFields.ForcedOrder, 51, 1), - new DataField((int)DataFields.MaxTimeForFirstTightening, 54, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.MaxTimeToCompleteJob, 60, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.JobBatchDone, 67, 1), - new DataField((int)DataFields.LockAtJobDone, 70, 1), - new DataField((int)DataFields.UseLineControl, 73, 1), - new DataField((int)DataFields.RepeatJob, 76, 1), - new DataField((int)DataFields.ToolLoosening, 79, 1), - new DataField((int)DataFields.Reserved, 82, 1), - new DataField((int)DataFields.NumberOfParameterSets, 85, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ParameterSetList, 89, 0) // defined at runtime + DataField.Number(DataFields.JobId, 20, 2), + DataField.String(DataFields.JobName, 24, 25), + DataField.Number(DataFields.ForcedOrder, 51, 1), + DataField.Number(DataFields.MaxTimeForFirstTightening, 54, 4), + DataField.Number(DataFields.MaxTimeToCompleteJob, 60, 5), + DataField.Number(DataFields.JobBatchDone, 67, 1), + DataField.Boolean(DataFields.LockAtJobDone, 70), + DataField.Boolean(DataFields.UseLineControl, 73), + DataField.Boolean(DataFields.RepeatJob, 76), + DataField.Number(DataFields.ToolLoosening, 79, 1), + DataField.Number(DataFields.Reserved, 82, 1), + DataField.Number(DataFields.NumberOfParameterSets, 85, 2), + DataField.Volatile(DataFields.ParameterSetList, 89) // defined at runtime } }, }; @@ -155,7 +153,7 @@ protected override Dictionary> RegisterDatafields() private void HandleRevisions() { - var jobIdField = GetField(1, (int)DataFields.JobId); + var jobIdField = GetField(1, DataFields.JobId); if (Header.Revision > 1) { jobIdField.Size = 4; @@ -174,15 +172,6 @@ private void HandleRevisions() } } - private int GetEachParameterSetSize() - { - switch (Header.Revision) - { - case 3: return 44; - case 4: return 49; - default: return 12; - }; - } protected enum DataFields { @@ -198,8 +187,7 @@ protected enum DataFields ToolLoosening, Reserved, NumberOfParameterSets, - ParameterSetList, - //rev 3 + ParameterSetList } } } \ No newline at end of file diff --git a/src/OpenProtocolInterpreter/Job/Mid0035.cs b/src/OpenProtocolInterpreter/Job/Mid0035.cs index 12908716..687db0eb 100644 --- a/src/OpenProtocolInterpreter/Job/Mid0035.cs +++ b/src/OpenProtocolInterpreter/Job/Mid0035.cs @@ -17,85 +17,85 @@ public class Mid0035 : Mid, IJob, IController, IAcknowledgeable public int JobId { - get => GetField(1, (int)DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); } public JobStatus JobStatus { - get => (JobStatus)GetField(1, (int)DataFields.JobStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.JobStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (JobStatus)GetField(1, DataFields.JobStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.JobStatus).SetValue(OpenProtocolConvert.ToString, value); } public JobBatchMode JobBatchMode { - get => (JobBatchMode)GetField(1, (int)DataFields.JobBatchMode).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.JobBatchMode).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (JobBatchMode)GetField(1, DataFields.JobBatchMode).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.JobBatchMode).SetValue(OpenProtocolConvert.ToString, value); } public int JobBatchSize { - get => GetField(1, (int)DataFields.JobBatchSize).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.JobBatchSize).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.JobBatchSize).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.JobBatchSize).SetValue(OpenProtocolConvert.ToString, value); } public int JobBatchCounter { - get => GetField(1, (int)DataFields.JobBatchCounter).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.JobBatchCounter).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.JobBatchCounter).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.JobBatchCounter).SetValue(OpenProtocolConvert.ToString, value); } public DateTime TimeStamp { - get => GetField(1, (int)DataFields.Timestamp).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(1, (int)DataFields.Timestamp).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Timestamp).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(1, DataFields.Timestamp).SetValue(OpenProtocolConvert.ToString, value); } //Rev 3 public int JobCurrentStep { - get => GetField(3, (int)DataFields.JobCurrentStep).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(3, (int)DataFields.JobCurrentStep).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(3, DataFields.JobCurrentStep).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(3, DataFields.JobCurrentStep).SetValue(OpenProtocolConvert.ToString, value); } public int JobTotalNumberOfSteps { - get => GetField(3, (int)DataFields.JobTotalNumberOfSteps).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(3, (int)DataFields.JobTotalNumberOfSteps).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(3, DataFields.JobTotalNumberOfSteps).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(3, DataFields.JobTotalNumberOfSteps).SetValue(OpenProtocolConvert.ToString, value); } public int JobStepType { - get => GetField(3, (int)DataFields.JobStepType).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(3, (int)DataFields.JobStepType).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(3, DataFields.JobStepType).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(3, DataFields.JobStepType).SetValue(OpenProtocolConvert.ToString, value); } //Rev 4 public JobTighteningStatus JobTighteningStatus { - get => (JobTighteningStatus)GetField(4, (int)DataFields.JobTighteningStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(4, (int)DataFields.JobTighteningStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (JobTighteningStatus)GetField(4, DataFields.JobTighteningStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(4, DataFields.JobTighteningStatus).SetValue(OpenProtocolConvert.ToString, value); } //Rev 5 public int JobSequenceNumber { - get => GetField(5, (int)DataFields.JobSequenceNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(5, (int)DataFields.JobSequenceNumber).SetValue(OpenProtocolConvert.ToString, (int)value); + get => GetField(5, DataFields.JobSequenceNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(5, DataFields.JobSequenceNumber).SetValue(OpenProtocolConvert.ToString, value); } public string VinNumber { - get => GetField(5, (int)DataFields.VinNumber).Value; - set => GetField(5, (int)DataFields.VinNumber).SetValue(value); + get => GetField(5, DataFields.VinNumber).Value; + set => GetField(5, DataFields.VinNumber).SetValue(value); } public string IdentifierResultPart2 { - get => GetField(5, (int)DataFields.IdentifierResultPart2).Value; - set => GetField(5, (int)DataFields.IdentifierResultPart2).SetValue(value); + get => GetField(5, DataFields.IdentifierResultPart2).Value; + set => GetField(5, DataFields.IdentifierResultPart2).SetValue(value); } public string IdentifierResultPart3 { - get => GetField(5, (int)DataFields.IdentifierResultPart3).Value; - set => GetField(5, (int)DataFields.IdentifierResultPart3).SetValue(value); + get => GetField(5, DataFields.IdentifierResultPart3).Value; + set => GetField(5, DataFields.IdentifierResultPart3).SetValue(value); } public string IdentifierResultPart4 { - get => GetField(5, (int)DataFields.IdentifierResultPart4).Value; - set => GetField(5, (int)DataFields.IdentifierResultPart4).SetValue(value); + get => GetField(5, DataFields.IdentifierResultPart4).Value; + set => GetField(5, DataFields.IdentifierResultPart4).SetValue(value); } public Mid0035() : this(DEFAULT_REVISION) @@ -112,8 +112,14 @@ public Mid0035(int revision) : this(new Header() Mid = MID, Revision = revision }) + { + + } + + public override string Pack() { HandleRevision(); + return base.Pack(); } public override Mid Parse(string package) @@ -131,36 +137,36 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.JobId, 20, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.JobStatus, 24, 1), - new DataField((int)DataFields.JobBatchMode, 27, 1), - new DataField((int)DataFields.JobBatchSize, 30, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.JobBatchCounter, 36, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Timestamp, 42, 19) + DataField.Number(DataFields.JobId, 20, 2), + DataField.Number(DataFields.JobStatus, 24, 1), + DataField.Number(DataFields.JobBatchMode, 27, 1), + DataField.Number(DataFields.JobBatchSize, 30, 4), + DataField.Number(DataFields.JobBatchCounter, 36, 4), + DataField.Timestamp(DataFields.Timestamp, 42) } }, { 3, new List() { - new DataField((int)DataFields.JobCurrentStep, 65, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.JobTotalNumberOfSteps, 70, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.JobStepType, 75, 2, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.JobCurrentStep, 65, 3), + DataField.Number(DataFields.JobTotalNumberOfSteps, 70, 3), + DataField.Number(DataFields.JobStepType, 75, 2) } }, { 4, new List() { - new DataField((int)DataFields.JobTighteningStatus, 79, 2, ' ', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.JobTighteningStatus, 79, 2) } }, { 5, new List() { - new DataField((int)DataFields.JobSequenceNumber, 83, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.VinNumber, 90 , 25, ' ', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.IdentifierResultPart2, 117, 25, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.IdentifierResultPart3, 144, 25, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.IdentifierResultPart4, 171, 25, '0', PaddingOrientation.LeftPadded), + DataField.Number(DataFields.JobSequenceNumber, 83, 5), + DataField.String(DataFields.VinNumber, 90, 25), + DataField.String(DataFields.IdentifierResultPart2, 117, 25), + DataField.String(DataFields.IdentifierResultPart3, 144, 25), + DataField.String(DataFields.IdentifierResultPart4, 171, 25), } } }; @@ -168,7 +174,7 @@ protected override Dictionary> RegisterDatafields() private void HandleRevision() { - var jobIdField = GetField(1, (int)DataFields.JobId); + var jobIdField = GetField(1, DataFields.JobId); if (Header.Revision > 1) { jobIdField.Size = 4; diff --git a/src/OpenProtocolInterpreter/Job/Mid0038.cs b/src/OpenProtocolInterpreter/Job/Mid0038.cs index a5199965..76665691 100644 --- a/src/OpenProtocolInterpreter/Job/Mid0038.cs +++ b/src/OpenProtocolInterpreter/Job/Mid0038.cs @@ -16,8 +16,8 @@ public class Mid0038 : Mid, IJob, IIntegrator, IAcceptableCommand, IDeclinableCo public int JobId { - get => GetField(1, (int)DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); } public Mid0038() : this(DEFAULT_REVISION) @@ -27,7 +27,7 @@ public Mid0038() : this(DEFAULT_REVISION) public Mid0038(Header header) : base(header) { - HandleRevision(); + } public Mid0038(int revision) : this(new Header() @@ -38,6 +38,12 @@ public Mid0038(int revision) : this(new Header() { } + public override string Pack() + { + HandleRevision(); + return base.Pack(); + } + public override Mid Parse(string package) { Header = ProcessHeader(package); @@ -53,7 +59,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.JobId, 20, 2, '0', PaddingOrientation.LeftPadded, false), + DataField.Number(DataFields.JobId, 20, 2, false), } } }; @@ -63,11 +69,11 @@ private void HandleRevision() { if (Header.Revision > 1) { - GetField(1, (int)DataFields.JobId).Size = 4; + GetField(1, DataFields.JobId).Size = 4; } else { - GetField(1, (int)DataFields.JobId).Size = 2; + GetField(1, DataFields.JobId).Size = 2; } } diff --git a/src/OpenProtocolInterpreter/Job/Mid0039.cs b/src/OpenProtocolInterpreter/Job/Mid0039.cs index a4cc5588..544ff06c 100644 --- a/src/OpenProtocolInterpreter/Job/Mid0039.cs +++ b/src/OpenProtocolInterpreter/Job/Mid0039.cs @@ -16,8 +16,8 @@ public class Mid0039 : Mid, IJob, IIntegrator, IAcceptableCommand, IDeclinableCo public int JobId { - get => GetField(1, (int)DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); } public Mid0039() : this(DEFAULT_REVISION) @@ -27,7 +27,7 @@ public Mid0039() : this(DEFAULT_REVISION) public Mid0039(Header header) : base(header) { - HandleRevisions(); + } public Mid0039(int revision) : this(new Header() @@ -38,6 +38,12 @@ public Mid0039(int revision) : this(new Header() { } + public override string Pack() + { + HandleRevisions(); + return base.Pack(); + } + public override Mid Parse(string package) { Header = ProcessHeader(package); @@ -53,7 +59,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.JobId, 20, 2, '0', PaddingOrientation.LeftPadded, false), + DataField.Number(DataFields.JobId, 20, 2, false), } } }; @@ -61,13 +67,13 @@ protected override Dictionary> RegisterDatafields() private void HandleRevisions() { - if (Header.Revision == 1) + if (Header.Revision > 1) { - GetField(1, (int)DataFields.JobId).Size = 2; + GetField(1, DataFields.JobId).Size = 4; } else { - GetField(1, (int)DataFields.JobId).Size = 4; + GetField(1, DataFields.JobId).Size = 2; } } diff --git a/src/OpenProtocolInterpreter/Job/ParameterSet.cs b/src/OpenProtocolInterpreter/Job/ParameterSet.cs index 49f2db68..813eb9eb 100644 --- a/src/OpenProtocolInterpreter/Job/ParameterSet.cs +++ b/src/OpenProtocolInterpreter/Job/ParameterSet.cs @@ -27,15 +27,19 @@ public string Pack(int revision) OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, ChannelId), OpenProtocolConvert.ToString('0', 3, PaddingOrientation.LeftPadded, TypeId), OpenProtocolConvert.ToString(AutoValue), - OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, BatchSize) + OpenProtocolConvert.ToString('0', revision > 4 ? 4 : 2, PaddingOrientation.LeftPadded, BatchSize) }; if (revision > 2) { - if (revision > 3) - values.Add(OpenProtocolConvert.ToString('0', 4, PaddingOrientation.LeftPadded, IdentifierNumber)); - else + if (revision == 3) + { values.Add(OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, Socket)); + } + else + { + values.Add(OpenProtocolConvert.ToString('0', 4, PaddingOrientation.LeftPadded, IdentifierNumber)); + } values.Add(JobStepName.PadRight(25)); values.Add(OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, JobStepType)); @@ -93,5 +97,14 @@ public static IEnumerable ParseAll(string section, int revision) yield return Parse(psetData, revision); } } + + public static int Size(int revision) + => revision switch + { + 3 => 44, + 4 => 49, + 5 => 51, + _ => 12, + }; } } diff --git a/src/OpenProtocolInterpreter/LinkCommunication/Mid9997.cs b/src/OpenProtocolInterpreter/LinkCommunication/Mid9997.cs index 5d32e792..61b8a32a 100644 --- a/src/OpenProtocolInterpreter/LinkCommunication/Mid9997.cs +++ b/src/OpenProtocolInterpreter/LinkCommunication/Mid9997.cs @@ -20,8 +20,8 @@ public class Mid9997 : Mid, ILinkCommunication, IIntegrator, IController public int MidNumber { - get => GetField(1, (int)DataFields.MidNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.MidNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.MidNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.MidNumber).SetValue(OpenProtocolConvert.ToString, value); } public Mid9997(Header header) : base(header) @@ -43,7 +43,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.MidNumber, 20, 4, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.MidNumber, 20, 4, false) } } }; diff --git a/src/OpenProtocolInterpreter/LinkCommunication/Mid9998.cs b/src/OpenProtocolInterpreter/LinkCommunication/Mid9998.cs index f6e715a0..372e133a 100644 --- a/src/OpenProtocolInterpreter/LinkCommunication/Mid9998.cs +++ b/src/OpenProtocolInterpreter/LinkCommunication/Mid9998.cs @@ -20,13 +20,13 @@ public class Mid9998 : Mid, ILinkCommunication, IController, IIntegrator public int MidNumber { - get => GetField(1, (int)DataFields.MidNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.MidNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.MidNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.MidNumber).SetValue(OpenProtocolConvert.ToString, value); } public LinkCommunicationError ErrorCode { - get => (LinkCommunicationError)GetField(1, (int)DataFields.ErrorCode).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ErrorCode).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (LinkCommunicationError)GetField(1, DataFields.ErrorCode).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ErrorCode).SetValue(OpenProtocolConvert.ToString, value); } public Mid9998() : this(new Header() @@ -49,8 +49,8 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.MidNumber, 20, 4, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.ErrorCode, 24, 4, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.MidNumber, 20, 4, false), + DataField.Number(DataFields.ErrorCode, 24, 4, false) } } }; diff --git a/src/OpenProtocolInterpreter/MID.cs b/src/OpenProtocolInterpreter/MID.cs index a54e170a..8bc55ee6 100644 --- a/src/OpenProtocolInterpreter/MID.cs +++ b/src/OpenProtocolInterpreter/MID.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; namespace OpenProtocolInterpreter @@ -21,14 +22,14 @@ public Mid(Header header) RevisionsByFields = new SafeAccessRevisionsFields(RegisterDatafields()); } - public Mid(int mid, int revision, bool noAckFlag = false): this(new Header() + public Mid(int mid, int revision, bool noAckFlag = false) : this(new Header() { Mid = mid, Revision = revision, NoAckFlag = noAckFlag }) { - + } protected virtual byte[] BuildRawHeader() => ToBytes(BuildHeader()); @@ -52,46 +53,55 @@ protected virtual string BuildHeader() public virtual string Pack() { + var header = BuildHeader(); if (!RevisionsByFields.Any()) - return BuildHeader(); + return header; - string package = BuildHeader(); + var builder = new StringBuilder(header); int prefixIndex = 1; - for (int i = 1; i <= (Header.Revision > 0 ? Header.Revision : 1); i++) + var revision = (Header.Revision > 0 ? Header.Revision : 1); + for (int i = 1; i <= revision; i++) { - if (RevisionsByFields.TryGetValue(i, out var dataFields)) - { - package += Pack(dataFields, ref prefixIndex); - } + builder.Append(Pack(i, ref prefixIndex)); } - return package; + return builder.ToString(); } public virtual byte[] PackBytes() => Encoding.ASCII.GetBytes(Pack()); + protected virtual string Pack(int revision, ref int prefixIndex) + { + if (!RevisionsByFields.TryGetValue(revision, out var dataFields)) + { + return string.Empty; + } + + return Pack(dataFields, ref prefixIndex); + } + protected virtual string Pack(List dataFields, ref int prefixIndex) { - string package = string.Empty; + var builder = new StringBuilder(); foreach (var dataField in dataFields) { if (dataField.HasPrefix) { - package += prefixIndex.ToString().PadLeft(2, '0') + dataField.Value; + builder.Append(prefixIndex.ToString("D2")); prefixIndex++; } - else - package += dataField.Value; + + builder.Append(dataField.Value); } - return package; + return builder.ToString(); } - protected virtual Dictionary> RegisterDatafields() => new Dictionary>(); + protected virtual Dictionary> RegisterDatafields() => new(); protected virtual Header ProcessHeader(string package) { - if(package.Length < 20) + if (package.Length < 20) { package = package.PadRight(20, ' '); } @@ -99,13 +109,13 @@ protected virtual Header ProcessHeader(string package) static bool IsNotEmptyOrZero(string package, out int value) { value = 0; - return !string.IsNullOrWhiteSpace(package) && (int.TryParse(package, out value) && value > 0); + return !string.IsNullOrWhiteSpace(package) && int.TryParse(package, out value) && value > 0; } var header = new Header { - Length = Convert.ToInt32(package.Substring(0, 4)), - Mid = Convert.ToInt32(package.Substring(4, 4)), + Length = int.Parse(package.Substring(0, 4)), + Mid = int.Parse(package.Substring(4, 4)), Revision = IsNotEmptyOrZero(package.Substring(8, 3), out var revision) ? revision : 1, NoAckFlag = !string.IsNullOrWhiteSpace(package.Substring(11, 1)), StationId = int.TryParse(package.Substring(12, 2), out var stationId) ? stationId : 1, @@ -139,10 +149,15 @@ protected virtual void ProcessDataFields(string package) int revision = Header.Revision > 0 ? Header.Revision : 1; for (int i = 1; i <= revision; i++) { - if (RevisionsByFields.TryGetValue(i, out var field)) - { - ProcessDataFields(field, package); - } + ProcessDataFields(i, package); + } + } + + protected virtual void ProcessDataFields(int revision, string package) + { + if (RevisionsByFields.TryGetValue(revision, out var fields)) + { + ProcessDataFields(fields, package); } } @@ -185,11 +200,22 @@ protected byte[] GetValue(DataField field, byte[] package) } } - protected DataField GetField(int revision, int field) => RevisionsByFields[revision].FirstOrDefault(x => x.Field == field); + protected DataField GetField(int revision, int field) + { + if (!RevisionsByFields.TryGetValue(revision, out var fields)) + { + return DataField.Default; + } + + return fields.FirstOrDefault(x => x.Field == field) ?? DataField.Default; + } + + protected DataField GetField(int revision, TEnum field) where TEnum : struct, Enum + => GetField(revision, field.GetHashCode()); - protected string ToAscii(byte[] bytes) => Encoding.ASCII.GetString(bytes); + protected static string ToAscii(byte[] bytes) => Encoding.ASCII.GetString(bytes); - protected byte[] ToBytes(string value) => Encoding.ASCII.GetBytes(value); + protected static byte[] ToBytes(string value) => Encoding.ASCII.GetBytes(value); } } diff --git a/src/OpenProtocolInterpreter/MidInterpreter.cs b/src/OpenProtocolInterpreter/MidInterpreter.cs index bd09143a..704497b7 100644 --- a/src/OpenProtocolInterpreter/MidInterpreter.cs +++ b/src/OpenProtocolInterpreter/MidInterpreter.cs @@ -12,18 +12,18 @@ namespace OpenProtocolInterpreter /// public class MidInterpreter { - private readonly IList _messagesTemplates; - private readonly IDictionary _fastAccessTemplate; + private readonly Dictionary> _messagesTemplates; + private readonly SortedDictionary _midTemplates; public MidInterpreter() { - _messagesTemplates = new List(); - _fastAccessTemplate = new Dictionary(); + _messagesTemplates = new Dictionary>(); + _midTemplates = new SortedDictionary(); } - public string Pack(Mid mid) => mid.Pack(); + public static string Pack(Mid mid) => mid.Pack(); - public byte[] PackBytes(Mid mid) => mid.PackBytes(); + public static byte[] PackBytes(Mid mid) => mid.PackBytes(); public Mid Parse(string package) { @@ -67,30 +67,40 @@ public ExpectedMid Parse(byte[] package) where ExpectedMid : Mid internal void UseTemplate(IMessagesTemplate template) { - if (!_messagesTemplates.Any(x => x.GetType().Equals(template.GetType()))) + var type = template.GetType(); + if (!_messagesTemplates.ContainsKey(type)) { - _messagesTemplates.Add(template); + _messagesTemplates.Add(type, new Lazy(() => template)); + } + } + + internal void UseTemplate(Type type, Lazy template) + { + if (!_messagesTemplates.ContainsKey(type)) + { + _messagesTemplates.Add(type, template); } } internal void UseTemplate() where T : IMessagesTemplate { - var instance = (IMessagesTemplate)Activator.CreateInstance(typeof(T)); - UseTemplate(instance); + UseTemplate(InterpreterMode.Both); } internal void UseTemplate(InterpreterMode mode) where T : IMessagesTemplate { - var instance = (IMessagesTemplate)Activator.CreateInstance(typeof(T), new object[] { mode }); - UseTemplate(instance); + var type = typeof(T); + var instance = new Lazy(() => (IMessagesTemplate)Activator.CreateInstance(type, [mode])); + UseTemplate(type, instance); } internal void UseTemplate(IEnumerable types) where T : IMessagesTemplate { if (types.Any()) { - var instance = (IMessagesTemplate)Activator.CreateInstance(typeof(T), new object[] { types }); - UseTemplate(instance); + var type = typeof(T); + var instance = new Lazy(() => (IMessagesTemplate)Activator.CreateInstance(type, [types])); + UseTemplate(type, instance); } } @@ -98,45 +108,42 @@ internal void UseTemplate(IDictionary types) where T : IMessagesTe { if (types.Any()) { - var instance = _messagesTemplates.FirstOrDefault(x => x.GetType().Equals(typeof(T))); - if(instance == default) + var type = typeof(T); + if (!_messagesTemplates.TryGetValue(type, out var instance)) { - instance = (IMessagesTemplate)Activator.CreateInstance(typeof(T), new object[] { types.Select(x=> x.Value) }); - UseTemplate(instance); + instance = new Lazy(() => (IMessagesTemplate)Activator.CreateInstance(type, [])); + UseTemplate(type, instance); } - instance.AddOrUpdateTemplate(types); + instance.Value.AddOrUpdateTemplate(types); } } private IMessagesTemplate GetMessageTemplate(int mid) { - if (!_fastAccessTemplate.TryGetValue(mid, out IMessagesTemplate template)) + if (!_midTemplates.TryGetValue(mid, out IMessagesTemplate template)) { - - template = _messagesTemplates.FirstOrDefault(x => x.IsAssignableTo(mid)); - if (template == null) + var lazy = _messagesTemplates.Values.FirstOrDefault(x => x.Value.IsAssignableTo(mid)); + if (lazy == null) { throw new NotImplementedException($@"Could not found a message parser for mid {mid}, please register it before using"); } - _fastAccessTemplate.Add(mid, template); + template = lazy.Value; + _midTemplates.Add(mid, template); } return template; } - private Mid TryParseStandaloneMid(int mid) + private static Mid TryParseStandaloneMid(int mid) { - switch (mid) + return mid switch { - case KeepAlive.Mid9999.MID: - return new KeepAlive.Mid9999(); - case ApplicationController.Mid0270.MID: - return new ApplicationController.Mid0270(); - } - - return default; + KeepAlive.Mid9999.MID => new KeepAlive.Mid9999(), + ApplicationController.Mid0270.MID => new ApplicationController.Mid0270(), + _ => default, + }; } } } diff --git a/src/OpenProtocolInterpreter/MotorTuning/Mid0501.cs b/src/OpenProtocolInterpreter/MotorTuning/Mid0501.cs index 7451176d..74a958c8 100644 --- a/src/OpenProtocolInterpreter/MotorTuning/Mid0501.cs +++ b/src/OpenProtocolInterpreter/MotorTuning/Mid0501.cs @@ -18,8 +18,8 @@ public class Mid0501 : Mid, IMotorTuning, IController, IAcknowledgeable /// public bool MotorTuneResult { - get => GetField(1, (int)DataFields.MotorTuneResult).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.MotorTuneResult).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.MotorTuneResult).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.MotorTuneResult).SetValue(OpenProtocolConvert.ToString, value); } public Mid0501() : this(new Header() @@ -41,7 +41,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.MotorTuneResult, 20, 1) + DataField.Boolean(DataFields.MotorTuneResult, 20) } } }; diff --git a/src/OpenProtocolInterpreter/MultiSpindle/Mid0091.cs b/src/OpenProtocolInterpreter/MultiSpindle/Mid0091.cs index 9c5b31e3..6f2fce75 100644 --- a/src/OpenProtocolInterpreter/MultiSpindle/Mid0091.cs +++ b/src/OpenProtocolInterpreter/MultiSpindle/Mid0091.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Text; namespace OpenProtocolInterpreter.MultiSpindle { @@ -18,23 +19,23 @@ public class Mid0091 : Mid, IMultiSpindle, IController, IAcknowledgeable GetField(1, (int)DataFields.NumberOfSpindles).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.NumberOfSpindles).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.NumberOfSpindles).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.NumberOfSpindles).SetValue(OpenProtocolConvert.ToString, value); } public int SyncTighteningId { - get => GetField(1, (int)DataFields.SyncTighteningId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.SyncTighteningId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.SyncTighteningId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.SyncTighteningId).SetValue(OpenProtocolConvert.ToString, value); } public DateTime Time { - get => GetField(1, (int)DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(1, (int)DataFields.Time).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(1, DataFields.Time).SetValue(OpenProtocolConvert.ToString, value); } public bool SyncOverallStatus { - get => GetField(1, (int)DataFields.SyncOverallStatus).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.SyncOverallStatus).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.SyncOverallStatus).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.SyncOverallStatus).SetValue(OpenProtocolConvert.ToString, value); } public List SpindlesStatus { get; set; } @@ -49,35 +50,35 @@ public Mid0091() : this(new Header() public Mid0091(Header header) : base(header) { - if (SpindlesStatus == null) - SpindlesStatus = new List(); + SpindlesStatus ??= []; } public override string Pack() { - GetField(1, (int)DataFields.SpindleStatus).Value = PackSpindlesStatus(); + GetField(1, DataFields.SpindleStatus).Value = PackSpindlesStatus(); return base.Pack(); } public override Mid Parse(string package) { Header = ProcessHeader(package); - var spindleField = GetField(1, (int)DataFields.SpindleStatus); + var spindleField = GetField(1, DataFields.SpindleStatus); spindleField.Size = Header.Length - spindleField.Index - 2; base.Parse(package); SpindlesStatus = ParseSpindlesStatus(spindleField.Value); return this; } + //TODO: move to SpindleStatus class protected virtual string PackSpindlesStatus() { - string pack = string.Empty; + var builder = new StringBuilder(); foreach (var spindle in SpindlesStatus) - pack += OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, spindle.SpindleNumber) + - OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, spindle.ChannelId) + - OpenProtocolConvert.ToString(spindle.SyncOverallStatus); + builder.Append(OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, spindle.SpindleNumber) + + OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, spindle.ChannelId) + + OpenProtocolConvert.ToString(spindle.SyncOverallStatus)); - return pack; + return builder.ToString(); } protected virtual List ParseSpindlesStatus(string section) @@ -105,11 +106,11 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.NumberOfSpindles, 20, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.SyncTighteningId, 24, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Time, 31, 19), - new DataField((int)DataFields.SyncOverallStatus, 52, 1), - new DataField((int)DataFields.SpindleStatus, 55, 5) + DataField.Number(DataFields.NumberOfSpindles, 20, 2), + DataField.Number(DataFields.SyncTighteningId, 24, 5), + DataField.Timestamp(DataFields.Time, 31), + DataField.Boolean(DataFields.SyncOverallStatus, 52), + new(DataFields.SpindleStatus, 55, 5) } } }; diff --git a/src/OpenProtocolInterpreter/MultiSpindle/Mid0100.cs b/src/OpenProtocolInterpreter/MultiSpindle/Mid0100.cs index f816acd3..b4d76698 100644 --- a/src/OpenProtocolInterpreter/MultiSpindle/Mid0100.cs +++ b/src/OpenProtocolInterpreter/MultiSpindle/Mid0100.cs @@ -34,14 +34,14 @@ public class Mid0100 : Mid, IMultiSpindle, IIntegrator, ISubscription, IAcceptab public long DataNumberSystem { - get => GetField(2, (int)DataFields.DataNumberSystem).GetValue(OpenProtocolConvert.ToInt64); - set => GetField(2, (int)DataFields.DataNumberSystem).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.DataNumberSystem).GetValue(OpenProtocolConvert.ToInt64); + set => GetField(2, DataFields.DataNumberSystem).SetValue(OpenProtocolConvert.ToString, value); } public bool SendOnlyNewData { - get => GetField(3, (int)DataFields.SendOnlyNewData).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(3, (int)DataFields.SendOnlyNewData).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(3, DataFields.SendOnlyNewData).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(3, DataFields.SendOnlyNewData).SetValue(OpenProtocolConvert.ToString, value); } public Mid0100() : this(DEFAULT_REVISION) @@ -74,13 +74,13 @@ protected override Dictionary> RegisterDatafields() { 2, new List() { - new DataField((int)DataFields.DataNumberSystem, 20, 10, '0', PaddingOrientation.LeftPadded, false), + DataField.Number(DataFields.DataNumberSystem, 20, 10, false), } }, { 3, new List() { - new DataField((int)DataFields.SendOnlyNewData, 30, 1, '0', PaddingOrientation.LeftPadded, false), + DataField.Boolean(DataFields.SendOnlyNewData, 30, false), } } }; diff --git a/src/OpenProtocolInterpreter/MultiSpindle/Mid0101.cs b/src/OpenProtocolInterpreter/MultiSpindle/Mid0101.cs index 4278b149..2620b3ab 100644 --- a/src/OpenProtocolInterpreter/MultiSpindle/Mid0101.cs +++ b/src/OpenProtocolInterpreter/MultiSpindle/Mid0101.cs @@ -25,99 +25,99 @@ public class Mid0101 : Mid, IMultiSpindle, IController, IAcknowledgeable GetField(1, (int)DataFields.NumberOfSpindlesOrPresses).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.NumberOfSpindlesOrPresses).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.NumberOfSpindlesOrPresses).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.NumberOfSpindlesOrPresses).SetValue(OpenProtocolConvert.ToString, value); } public string VinNumber { - get => GetField(1, (int)DataFields.VinNumber).Value; - set => GetField(1, (int)DataFields.VinNumber).SetValue(value); + get => GetField(1, DataFields.VinNumber).Value; + set => GetField(1, DataFields.VinNumber).SetValue(value); } public int JobId { - get => GetField(1, (int)DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); } public int ParameterSetId { - get => GetField(1, (int)DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); } public int BatchSize { - get => GetField(1, (int)DataFields.BatchSize).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.BatchSize).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.BatchSize).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.BatchSize).SetValue(OpenProtocolConvert.ToString, value); } public int BatchCounter { - get => GetField(1, (int)DataFields.BatchCounter).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.BatchCounter).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.BatchCounter).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.BatchCounter).SetValue(OpenProtocolConvert.ToString, value); } public BatchStatus BatchStatus { - get => (BatchStatus)GetField(1, (int)DataFields.BatchStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.BatchStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (BatchStatus)GetField(1, DataFields.BatchStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.BatchStatus).SetValue(OpenProtocolConvert.ToString, value); } public decimal TorqueOrForceMinLimit { - get => GetField(1, (int)DataFields.TorqueOrForceMinLimit).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(1, (int)DataFields.TorqueOrForceMinLimit).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(1, DataFields.TorqueOrForceMinLimit).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(1, DataFields.TorqueOrForceMinLimit).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal TorqueOrForceMaxLimit { - get => GetField(1, (int)DataFields.TorqueOrForceMaxLimit).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(1, (int)DataFields.TorqueOrForceMaxLimit).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(1, DataFields.TorqueOrForceMaxLimit).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(1, DataFields.TorqueOrForceMaxLimit).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal TorqueOrForceFinalTarget { - get => GetField(1, (int)DataFields.TorqueOrForceFinalTarget).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(1, (int)DataFields.TorqueOrForceFinalTarget).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(1, DataFields.TorqueOrForceFinalTarget).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(1, DataFields.TorqueOrForceFinalTarget).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal AngleOrStrokeMinLimit { - get => GetField(1, (int)DataFields.AngleOrStrokeMinLimit).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(1, (int)DataFields.AngleOrStrokeMinLimit).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(1, DataFields.AngleOrStrokeMinLimit).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(1, DataFields.AngleOrStrokeMinLimit).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal AngleOrStrokeMaxLimit { - get => GetField(1, (int)DataFields.AngleOrStrokeMaxLimit).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(1, (int)DataFields.AngleOrStrokeMaxLimit).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(1, DataFields.AngleOrStrokeMaxLimit).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(1, DataFields.AngleOrStrokeMaxLimit).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal FinalAngleOrStrokeTarget { - get => GetField(1, (int)DataFields.FinalAngleOrStrokeTarget).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(1, (int)DataFields.FinalAngleOrStrokeTarget).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(1, DataFields.FinalAngleOrStrokeTarget).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(1, DataFields.FinalAngleOrStrokeTarget).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public DateTime LastChangeInParameterSet { - get => GetField(1, (int)DataFields.LastChangeInParameterSet).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(1, (int)DataFields.LastChangeInParameterSet).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.LastChangeInParameterSet).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(1, DataFields.LastChangeInParameterSet).SetValue(OpenProtocolConvert.ToString, value); } public DateTime TimeStamp { - get => GetField(1, (int)DataFields.Timestamp).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(1, (int)DataFields.Timestamp).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Timestamp).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(1, DataFields.Timestamp).SetValue(OpenProtocolConvert.ToString, value); } public int SyncTighteningId { - get => GetField(1, (int)DataFields.SyncTighteningId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.SyncTighteningId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.SyncTighteningId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.SyncTighteningId).SetValue(OpenProtocolConvert.ToString, value); } public bool SyncOverallStatus { - get => GetField(1, (int)DataFields.SyncOverallStatus).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.SyncOverallStatus).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.SyncOverallStatus).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.SyncOverallStatus).SetValue(OpenProtocolConvert.ToString, value); } public List SpindlesOrPressesStatus { get; set; } public SystemSubType SystemSubType { - get => (SystemSubType)GetField(4, (int)DataFields.SystemSubType).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(4, (int)DataFields.SystemSubType).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (SystemSubType)GetField(4, DataFields.SystemSubType).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(4, DataFields.SystemSubType).SetValue(OpenProtocolConvert.ToString, value); } public int JobSequenceNumber { - get => GetField(5, (int)DataFields.JobSequenceNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(5, (int)DataFields.JobSequenceNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(5, DataFields.JobSequenceNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(5, DataFields.JobSequenceNumber).SetValue(OpenProtocolConvert.ToString, value); } public Mid0101() : this(DEFAULT_REVISION) @@ -140,7 +140,7 @@ public Mid0101(int revision) : this(new Header() public override string Pack() { - var spindesOrPressesStatusField = GetField(1, (int)DataFields.SpindesOrPressesStatus); + var spindesOrPressesStatusField = GetField(1, DataFields.SpindesOrPressesStatus); spindesOrPressesStatusField.Size = SpindlesOrPressesStatus.Count * 18; spindesOrPressesStatusField.Value = PackSpindlesOrPressesStatus(); return base.Pack(); @@ -149,17 +149,17 @@ public override string Pack() public override Mid Parse(string package) { Header = ProcessHeader(package); - var spindleOrPressesField = GetField(1, (int)DataFields.NumberOfSpindlesOrPresses); + var spindleOrPressesField = GetField(1, DataFields.NumberOfSpindlesOrPresses); int spindleOrPresses = OpenProtocolConvert.ToInt32(package.Substring(spindleOrPressesField.Index + 2, spindleOrPressesField.Size)); - var spindesOrPressesStatusField = GetField(1, (int)DataFields.SpindesOrPressesStatus); + var spindesOrPressesStatusField = GetField(1, DataFields.SpindesOrPressesStatus); spindesOrPressesStatusField.Size = spindleOrPresses * 18; if(Header.Revision > 3) { - var systemSubTypeField = GetField(4, (int)DataFields.SystemSubType); + var systemSubTypeField = GetField(4, DataFields.SystemSubType); systemSubTypeField.Index = spindesOrPressesStatusField.Index + spindesOrPressesStatusField.Size + 2; if(Header.Revision > 4) { - GetField(5, (int)DataFields.JobSequenceNumber).Index = systemSubTypeField.Index + systemSubTypeField.Size + 2; + GetField(5, DataFields.JobSequenceNumber).Index = systemSubTypeField.Index + systemSubTypeField.Size + 2; } } ProcessDataFields(package); @@ -167,6 +167,7 @@ public override Mid Parse(string package) return this; } + //TODO: move to SpindleOrPressStatus class protected virtual string PackSpindlesOrPressesStatus() { string package = string.Empty; @@ -175,7 +176,7 @@ protected virtual string PackSpindlesOrPressesStatus() package += OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, v.SpindleOrPressNumber) + OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, v.ChannelId) + OpenProtocolConvert.ToString(v.OverallStatus) + - OpenProtocolConvert.ToString((int)v.TorqueOrForceStatus) + + OpenProtocolConvert.ToString(v.TorqueOrForceStatus) + OpenProtocolConvert.TruncatedDecimalToString('0', 6, PaddingOrientation.LeftPadded, v.TorqueOrForce) + OpenProtocolConvert.ToString(v.AngleOrStrokeStatus) + OpenProtocolConvert.ToString('0', 5, PaddingOrientation.LeftPadded, v.AngleOrStroke); @@ -213,36 +214,36 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.NumberOfSpindlesOrPresses, 20, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.VinNumber, 24, 25, ' '), - new DataField((int)DataFields.JobId, 51, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ParameterSetId, 55, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.BatchSize, 60, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.BatchCounter, 66, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.BatchStatus, 72, 1), - new DataField((int)DataFields.TorqueOrForceMinLimit, 75, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TorqueOrForceMaxLimit, 83, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TorqueOrForceFinalTarget, 91, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.AngleOrStrokeMinLimit, 99, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.AngleOrStrokeMaxLimit, 106, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.FinalAngleOrStrokeTarget, 113, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.LastChangeInParameterSet, 120, 19), - new DataField((int)DataFields.Timestamp, 141, 19), - new DataField((int)DataFields.SyncTighteningId, 162, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.SyncOverallStatus, 169, 1), - new DataField((int)DataFields.SpindesOrPressesStatus, 172, 0) + DataField.Number(DataFields.NumberOfSpindlesOrPresses, 20, 2), + DataField.String(DataFields.VinNumber, 24, 25), + DataField.Number(DataFields.JobId, 51, 2), + DataField.Number(DataFields.ParameterSetId, 55, 3), + DataField.Number(DataFields.BatchSize, 60, 4), + DataField.Number(DataFields.BatchCounter, 66, 4), + DataField.Number(DataFields.BatchStatus, 72, 1), + DataField.Number(DataFields.TorqueOrForceMinLimit, 75, 6), + DataField.Number(DataFields.TorqueOrForceMaxLimit, 83, 6), + DataField.Number(DataFields.TorqueOrForceFinalTarget, 91, 6), + DataField.Number(DataFields.AngleOrStrokeMinLimit, 99, 5), + DataField.Number(DataFields.AngleOrStrokeMaxLimit, 106, 5), + DataField.Number(DataFields.FinalAngleOrStrokeTarget, 113, 5), + DataField.Timestamp(DataFields.LastChangeInParameterSet, 120), + DataField.Timestamp(DataFields.Timestamp, 141), + DataField.Number(DataFields.SyncTighteningId, 162, 5), + DataField.Boolean(DataFields.SyncOverallStatus, 169), + DataField.Volatile(DataFields.SpindesOrPressesStatus, 172) } }, { 4, new List() { - new DataField((int)DataFields.SystemSubType, 0, 3, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.SystemSubType, 0, 3) } }, { 5, new List() { - new DataField((int)DataFields.JobSequenceNumber, 0, 5, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.JobSequenceNumber, 0, 5) } } }; diff --git a/src/OpenProtocolInterpreter/MultiSpindle/Mid0104.cs b/src/OpenProtocolInterpreter/MultiSpindle/Mid0104.cs new file mode 100644 index 00000000..8c5e5b88 --- /dev/null +++ b/src/OpenProtocolInterpreter/MultiSpindle/Mid0104.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenProtocolInterpreter.MultiSpindle +{ + /// + /// Old Multi spindle result request + /// Request for an old multi spindle result. + /// Note: MID 0104 can’t be used if there is an active subscription for multiple spindle results. + /// Message sent by: Integrator + /// + /// Answer: Command accepted or + /// Command error, Multi spindle result subscription already exists + /// + /// + public class Mid0104 : Mid, IMultiSpindle, IIntegrator, IAnswerableBy, IDeclinableCommand + { + public const int MID = 104; + + public IEnumerable DocumentedPossibleErrors => new Error[] { Error.MultiSpindleResultSubscriptionAlreadyExists }; + + public long RequestedResultIndex + { + get => GetField(1, DataFields.RequestedResultIndex).GetValue(OpenProtocolConvert.ToInt64); + set => GetField(1, DataFields.RequestedResultIndex).SetValue(OpenProtocolConvert.ToString, value); + } + + public Mid0104() : base(MID, DEFAULT_REVISION) { } + + public Mid0104(Header header) : base(header) + { + } + + protected override Dictionary> RegisterDatafields() + { + return new Dictionary>() + { + { + 1, new List() + { + DataField.Number(DataFields.RequestedResultIndex, 20, 10), + } + } + }; + } + + protected enum DataFields + { + RequestedResultIndex + } + } +} diff --git a/src/OpenProtocolInterpreter/MultiSpindle/MultiSpindleMessages.cs b/src/OpenProtocolInterpreter/MultiSpindle/MultiSpindleMessages.cs index e4eadab7..a99f4f58 100644 --- a/src/OpenProtocolInterpreter/MultiSpindle/MultiSpindleMessages.cs +++ b/src/OpenProtocolInterpreter/MultiSpindle/MultiSpindleMessages.cs @@ -20,7 +20,8 @@ public MultiSpindleMessages() : base() { Mid0100.MID, new MidCompiledInstance(typeof(Mid0100)) }, { Mid0101.MID, new MidCompiledInstance(typeof(Mid0101)) }, { Mid0102.MID, new MidCompiledInstance(typeof(Mid0102)) }, - { Mid0103.MID, new MidCompiledInstance(typeof(Mid0103)) } + { Mid0103.MID, new MidCompiledInstance(typeof(Mid0103)) }, + { Mid0104.MID, new MidCompiledInstance(typeof(Mid0104)) }, }; } @@ -34,6 +35,6 @@ public MultiSpindleMessages(InterpreterMode mode) : this() FilterSelectedMids(mode); } - public override bool IsAssignableTo(int mid) => mid > 89 && mid < 104; + public override bool IsAssignableTo(int mid) => mid > 89 && mid < 105; } } diff --git a/src/OpenProtocolInterpreter/MultipleIdentifiers/Mid0150.cs b/src/OpenProtocolInterpreter/MultipleIdentifiers/Mid0150.cs index 0f57db0f..4b5268b9 100644 --- a/src/OpenProtocolInterpreter/MultipleIdentifiers/Mid0150.cs +++ b/src/OpenProtocolInterpreter/MultipleIdentifiers/Mid0150.cs @@ -16,13 +16,8 @@ public class Mid0150 : Mid, IMultipleIdentifier, IIntegrator, IAcceptableCommand public string IdentifierData { - get => GetField(1, (int)DataFields.IdentifierData).Value; - set - { - var field = GetField(1, (int)DataFields.IdentifierData); - field.Size = value.Length < 100 ? value.Length : 100; - field.SetValue(value); - } + get => GetField(1, DataFields.IdentifierData).Value; + set => GetField(1, DataFields.IdentifierData).SetValue(value); } public Mid0150() : this(new Header() @@ -37,10 +32,22 @@ public Mid0150(Header header) : base(header) { } + public override string Pack() + { + var identifierDataField = GetField(1, DataFields.IdentifierData); + if(identifierDataField.Value.Length > 100) + { + identifierDataField.Value = identifierDataField.Value.Substring(0, 100); + } + + identifierDataField.Size = identifierDataField.Value.Length; + return base.Pack(); + } + public override Mid Parse(string package) { Header = ProcessHeader(package); - GetField(1, (int)DataFields.IdentifierData).Size = Header.Length - 20; + GetField(1, DataFields.IdentifierData).Size = Header.Length - 20; ProcessDataFields(package); return this; } @@ -52,7 +59,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.IdentifierData, 20, 0, false) + DataField.Volatile(DataFields.IdentifierData, 20, false) } } }; diff --git a/src/OpenProtocolInterpreter/MultipleIdentifiers/Mid0152.cs b/src/OpenProtocolInterpreter/MultipleIdentifiers/Mid0152.cs index 28ab11c1..5310743b 100644 --- a/src/OpenProtocolInterpreter/MultipleIdentifiers/Mid0152.cs +++ b/src/OpenProtocolInterpreter/MultipleIdentifiers/Mid0152.cs @@ -39,10 +39,10 @@ public Mid0152(Header header) : base(header) public override string Pack() { - GetField(1, (int)DataFields.FirstIdentifierStatus).Value = FirstIdentifierStatus.Pack(); - GetField(1, (int)DataFields.SecondIdentifierStatus).Value = SecondIdentifierStatus.Pack(); - GetField(1, (int)DataFields.ThirdIdentifierStatus).Value = ThirdIdentifierStatus.Pack(); - GetField(1, (int)DataFields.FourthIdentifierStatus).Value = FourthIdentifierStatus.Pack(); + GetField(1, DataFields.FirstIdentifierStatus).Value = FirstIdentifierStatus.Pack(); + GetField(1, DataFields.SecondIdentifierStatus).Value = SecondIdentifierStatus.Pack(); + GetField(1, DataFields.ThirdIdentifierStatus).Value = ThirdIdentifierStatus.Pack(); + GetField(1, DataFields.FourthIdentifierStatus).Value = FourthIdentifierStatus.Pack(); return base.Pack(); } @@ -50,10 +50,10 @@ public override Mid Parse(string package) { base.Parse(package); - FirstIdentifierStatus = IdentifierStatus.Parse(GetField(1, (int)DataFields.FirstIdentifierStatus).Value); - SecondIdentifierStatus = IdentifierStatus.Parse(GetField(1, (int)DataFields.SecondIdentifierStatus).Value); - ThirdIdentifierStatus = IdentifierStatus.Parse(GetField(1, (int)DataFields.ThirdIdentifierStatus).Value); - FourthIdentifierStatus = IdentifierStatus.Parse(GetField(1, (int)DataFields.FourthIdentifierStatus).Value); + FirstIdentifierStatus = IdentifierStatus.Parse(GetField(1, DataFields.FirstIdentifierStatus).Value); + SecondIdentifierStatus = IdentifierStatus.Parse(GetField(1, DataFields.SecondIdentifierStatus).Value); + ThirdIdentifierStatus = IdentifierStatus.Parse(GetField(1, DataFields.ThirdIdentifierStatus).Value); + FourthIdentifierStatus = IdentifierStatus.Parse(GetField(1, DataFields.FourthIdentifierStatus).Value); return this; } @@ -65,10 +65,10 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.FirstIdentifierStatus, 20, 30), - new DataField((int)DataFields.SecondIdentifierStatus, 52, 30), - new DataField((int)DataFields.ThirdIdentifierStatus, 84, 30), - new DataField((int)DataFields.FourthIdentifierStatus, 116, 30) + new(DataFields.FirstIdentifierStatus, 20, 30), + new(DataFields.SecondIdentifierStatus, 52, 30), + new(DataFields.ThirdIdentifierStatus, 84, 30), + new(DataFields.FourthIdentifierStatus, 116, 30) } } }; diff --git a/src/OpenProtocolInterpreter/OpenProtocolCommandsDisabled/Mid0421.cs b/src/OpenProtocolInterpreter/OpenProtocolCommandsDisabled/Mid0421.cs index 97ca067a..8628a69e 100644 --- a/src/OpenProtocolInterpreter/OpenProtocolCommandsDisabled/Mid0421.cs +++ b/src/OpenProtocolInterpreter/OpenProtocolCommandsDisabled/Mid0421.cs @@ -16,16 +16,16 @@ namespace OpenProtocolInterpreter.OpenProtocolCommandsDisabled public class Mid0421 : Mid, IOpenProtocolCommandsDisabled, IController, IAcknowledgeable { public const int MID = 421; - + public bool DigitalInputStatus { - get => GetField(1,(int)DataFields.DigitalInputStatus).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1,(int)DataFields.DigitalInputStatus).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.DigitalInputStatus).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.DigitalInputStatus).SetValue(OpenProtocolConvert.ToString, value); } public Mid0421() : this(new Header() { - Mid = MID, + Mid = MID, Revision = DEFAULT_REVISION }) { @@ -42,7 +42,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.DigitalInputStatus, 20, 1, false) + DataField.Boolean(DataFields.DigitalInputStatus, 20, false) } } }; diff --git a/src/OpenProtocolInterpreter/OpenProtocolConvert.cs b/src/OpenProtocolInterpreter/OpenProtocolConvert.cs index 85f94fa4..a7336090 100644 --- a/src/OpenProtocolInterpreter/OpenProtocolConvert.cs +++ b/src/OpenProtocolInterpreter/OpenProtocolConvert.cs @@ -1,6 +1,8 @@ -using System; +using OpenProtocolInterpreter.Tightening; +using System; using System.Collections.Generic; using System.Globalization; +using System.Text; namespace OpenProtocolInterpreter { @@ -32,11 +34,11 @@ public static string ToString(char paddingChar, int size, PaddingOrientation ori public static DateTime ToDateTime(string value) { - var convertedValue = System.DateTime.Now; + var convertedValue = DateTime.Now; if (!string.IsNullOrWhiteSpace(value.ToString())) { var date = value.ToString(); - System.DateTime.TryParse(date.Substring(0, 10) + " " + date.Substring(11, 8), out convertedValue); + DateTime.TryParse($"{date.Substring(0, 10)} {date.Substring(11, 8)}", out convertedValue); } return convertedValue; @@ -56,7 +58,7 @@ public static string ToString(char paddingChar, int size, PaddingOrientation ori public static decimal ToDecimal(string value) { decimal decimalValue = 0; - if (value != null) + if (!string.IsNullOrWhiteSpace(value)) decimal.TryParse(value.Replace(',', '.'), NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, _formatProvider, out decimalValue); return decimalValue; @@ -76,25 +78,25 @@ public static string TruncatedDecimalToString(char paddingChar, int size, Paddin public static decimal ToTruncatedDecimal(string value) { - int intValue = 0; - if (value != null) - int.TryParse(value.ToString(), out intValue); - + int intValue = ToInt32(value); return intValue / 100m; } public static string ToString(int value) => value.ToString(); + public static string ToString(TEnum value) where TEnum : struct, Enum + => ToString(value.GetHashCode()); + public static string ToString(char paddingChar, int size, PaddingOrientation orientation, int value) => TruncatePadded(paddingChar, size, orientation, ToString(value)); + public static string ToString(char paddingChar, int size, PaddingOrientation orientation, TEnum value) where TEnum : struct, Enum + => TruncatePadded(paddingChar, size, orientation, ToString(value)); + public static int ToInt32(string value) { - int convertedValue = 0; - if (value != null) - int.TryParse(value.ToString(), out convertedValue); - + int.TryParse(value, out int convertedValue); return convertedValue; } @@ -106,21 +108,18 @@ public static string ToString(char paddingChar, int size, PaddingOrientation ori public static long ToInt64(string value) { - long convertedValue = 0; - if (value != null) - long.TryParse(value.ToString(), out convertedValue); - + long.TryParse(value.ToString(), out long convertedValue); return convertedValue; } public static string ToString(IEnumerable value) { - string pack = string.Empty; + var builder = new StringBuilder(); foreach (var v in value) { - pack += v.Pack(); + builder.Append(v.Pack()); } - return pack; + return builder.ToString(); } public static bool GetBit(byte b, int bitNumber) => (b & (1 << bitNumber - 1)) != 0; diff --git a/src/OpenProtocolInterpreter/OpenProtocolInterpreter.csproj b/src/OpenProtocolInterpreter/OpenProtocolInterpreter.csproj index a3862efd..fa2b1c32 100644 --- a/src/OpenProtocolInterpreter/OpenProtocolInterpreter.csproj +++ b/src/OpenProtocolInterpreter/OpenProtocolInterpreter.csproj @@ -1,11 +1,9 @@  - netstandard2.0;net6 + netstandard2.0;net6;net8 latest - 6.0.0.0 - 6.0.0.0 - 6.0.0 + 6.1.0 Converts the ugly package that came from Open Protocol to an object Copyright © 2023 Henrique Dal Bello Batista @@ -15,14 +13,7 @@ MIT CSharp Open Protocol Atlas Copco true - Improvements - - - Interface segregation to represent types of mid - - New Features - - - Along with interfaces, added easy-use extensions - - Added new Errors + See release notes at: https://github.com/Rickedb/OpenProtocolInterpreter/releases/tag/6.1.0 icon.png diff --git a/src/OpenProtocolInterpreter/PLCUserData/Mid0240.cs b/src/OpenProtocolInterpreter/PLCUserData/Mid0240.cs index af026d65..df0b690f 100644 --- a/src/OpenProtocolInterpreter/PLCUserData/Mid0240.cs +++ b/src/OpenProtocolInterpreter/PLCUserData/Mid0240.cs @@ -19,13 +19,8 @@ public class Mid0240 : Mid, IPLCUserData, IIntegrator, IAcceptableCommand, IDecl public string UserData { - get => GetField(1, (int)DataFields.UserData).Value; - set - { - var field = GetField(1, (int)DataFields.UserData); - field.Size = value.Length < 200 ? value.Length : 200; - field.SetValue(value); - } + get => GetField(1, DataFields.UserData).Value; + set => GetField(1, DataFields.UserData).SetValue(value); } public Mid0240() : base(MID, DEFAULT_REVISION) { } @@ -34,10 +29,22 @@ public Mid0240(Header header) : base(header) { } + public override string Pack() + { + var userDataField = GetField(1, DataFields.UserData); + if (userDataField.Value.Length > 200) + { + userDataField.Value = userDataField.Value.Substring(0, 200); + } + + userDataField.Size = userDataField.Value.Length; + return base.Pack(); + } + public override Mid Parse(string package) { Header = ProcessHeader(package); - GetField(1, (int)DataFields.UserData).Size = Header.Length - 20; + GetField(1, DataFields.UserData).Size = Header.Length - 20; ProcessDataFields(package); return this; } @@ -49,7 +56,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.UserData, 20, 200, ' ', PaddingOrientation.RightPadded, false) + DataField.Volatile(DataFields.UserData, 20, false) } } }; diff --git a/src/OpenProtocolInterpreter/PLCUserData/Mid0242.cs b/src/OpenProtocolInterpreter/PLCUserData/Mid0242.cs index d79ab0de..e6288ff6 100644 --- a/src/OpenProtocolInterpreter/PLCUserData/Mid0242.cs +++ b/src/OpenProtocolInterpreter/PLCUserData/Mid0242.cs @@ -14,8 +14,8 @@ public class Mid0242 : Mid, IPLCUserData, IController, IAcknowledgeable public string UserData { - get => GetField(1, (int)DataFields.UserData).Value; - set => GetField(1, (int)DataFields.UserData).SetValue(value); + get => GetField(1, DataFields.UserData).Value; + set => GetField(1, DataFields.UserData).SetValue(value); } public Mid0242() : base(MID, DEFAULT_REVISION) @@ -29,14 +29,14 @@ public Mid0242(Header header) : base(header) public override string Pack() { - GetField(1, (int)DataFields.UserData).Size = UserData.Length; + GetField(1, DataFields.UserData).Size = UserData.Length; return base.Pack(); } public override Mid Parse(string package) { Header = ProcessHeader(package); - GetField(1, (int)DataFields.UserData).Size = Header.Length - 20; + GetField(1, DataFields.UserData).Size = Header.Length - 20; ProcessDataFields(package); return this; } @@ -48,7 +48,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.UserData, 20, 200, ' ', PaddingOrientation.RightPadded, false) + DataField.Volatile(DataFields.UserData, 20, false) } } }; diff --git a/src/OpenProtocolInterpreter/PLCUserData/Mid0245.cs b/src/OpenProtocolInterpreter/PLCUserData/Mid0245.cs index b2b56f95..34260ec6 100644 --- a/src/OpenProtocolInterpreter/PLCUserData/Mid0245.cs +++ b/src/OpenProtocolInterpreter/PLCUserData/Mid0245.cs @@ -47,18 +47,13 @@ public class Mid0245 : Mid, IPLCUserData, IIntegrator, IAcceptableCommand, IDecl public int Offset { - get => GetField(1, (int)DataFields.Offset).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.Offset).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Offset).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.Offset).SetValue(OpenProtocolConvert.ToString, value); } public string UserData { - get => GetField(1, (int)DataFields.UserData).Value; - set - { - var field = GetField(1, (int)DataFields.UserData); - field.Size = value.Length < 200 ? value.Length : 200; - field.SetValue(value); - } + get => GetField(1, DataFields.UserData).Value; + set => GetField(1, DataFields.UserData).SetValue(value); } public Mid0245() : this(DEFAULT_REVISION) @@ -75,16 +70,29 @@ public Mid0245(int revision) : this(new Header() public Mid0245(Header header) : base(header) { - if (string.IsNullOrEmpty(UserData)) + + } + + public override string Pack() + { + var userDataField = GetField(1, DataFields.UserData); + if (string.IsNullOrEmpty(userDataField.Value)) + { + userDataField.Value = " "; + } + else if (userDataField.Value.Length > 200) { - UserData = string.Empty.PadRight(2); + userDataField.Value = userDataField.Value.Substring(0, 200); } + + userDataField.Size = userDataField.Value.Length; + return base.Pack(); } public override Mid Parse(string package) { Header = ProcessHeader(package); - GetField(1, (int)DataFields.UserData).Size = Header.Length - 23; + GetField(1, DataFields.UserData).Size = Header.Length - 23; ProcessDataFields(package); return this; } @@ -96,8 +104,8 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.Offset, 20, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.UserData, 23, 2, ' ', PaddingOrientation.RightPadded, false) + DataField.Number(DataFields.Offset, 20, 3, false), + DataField.Volatile(DataFields.UserData, 23, false) } } }; diff --git a/src/OpenProtocolInterpreter/ParameterSet/Mid0011.cs b/src/OpenProtocolInterpreter/ParameterSet/Mid0011.cs index 7441abd1..0a960eb7 100644 --- a/src/OpenProtocolInterpreter/ParameterSet/Mid0011.cs +++ b/src/OpenProtocolInterpreter/ParameterSet/Mid0011.cs @@ -34,14 +34,13 @@ public Mid0011() : this(new Header() public Mid0011(Header header) : base(header) { - if (ParameterSets == null) - ParameterSets = new List(); + ParameterSets ??= []; } public override string Pack() { - GetField(1, (int)DataFields.TotalParameterSets).SetValue(OpenProtocolConvert.ToString, TotalParameterSets); - var eachParameterField = GetField(1, (int)DataFields.EachParameterSet); + GetField(1, DataFields.TotalParameterSets).SetValue(OpenProtocolConvert.ToString, TotalParameterSets); + var eachParameterField = GetField(1, DataFields.EachParameterSet); eachParameterField.Value = PackParameterSetIdList(); eachParameterField.Size = eachParameterField.Value.Length; return base.Pack(); @@ -51,9 +50,9 @@ public override Mid Parse(string package) { Header = ProcessHeader(package); - GetField(1, (int)DataFields.EachParameterSet).Size = Header.Length - GetField(1, (int)DataFields.EachParameterSet).Index; + GetField(1, DataFields.EachParameterSet).Size = Header.Length - GetField(1, DataFields.EachParameterSet).Index; ProcessDataFields(package); - ParameterSets = ParseParameterSetIdList(GetField(1, (int)DataFields.EachParameterSet).Value).ToList(); + ParameterSets = ParseParameterSetIdList(GetField(1, DataFields.EachParameterSet).Value).ToList(); return this; } @@ -81,8 +80,8 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.TotalParameterSets, 20, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.EachParameterSet, 23, 3, false) + DataField.Number(DataFields.TotalParameterSets, 20, 3, false), + new(DataFields.EachParameterSet, 23, 3, false) } } }; diff --git a/src/OpenProtocolInterpreter/ParameterSet/Mid0012.cs b/src/OpenProtocolInterpreter/ParameterSet/Mid0012.cs index 43e59e4e..4ce48402 100644 --- a/src/OpenProtocolInterpreter/ParameterSet/Mid0012.cs +++ b/src/OpenProtocolInterpreter/ParameterSet/Mid0012.cs @@ -19,13 +19,13 @@ public class Mid0012 : Mid, IParameterSet, IIntegrator, IAnswerableBy, public int ParameterSetId { - get => GetField(1, (int)DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); } public int ParameterSetFileVersion { - get => GetField(3, (int)DataFields.PSetFileVersion).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(3, (int)DataFields.PSetFileVersion).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(3, DataFields.PSetFileVersion).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(3, DataFields.PSetFileVersion).SetValue(OpenProtocolConvert.ToString, value); } public Mid0012() : this(DEFAULT_REVISION) @@ -52,13 +52,13 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ParameterSetId, 20, 3, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.ParameterSetId, 20, 3, false) } }, { 3, new List() { - new DataField((int)DataFields.PSetFileVersion, 23, 8, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.PSetFileVersion, 23, 8, false) } }, }; diff --git a/src/OpenProtocolInterpreter/ParameterSet/Mid0013.cs b/src/OpenProtocolInterpreter/ParameterSet/Mid0013.cs index 67abbfc6..06bfba2f 100644 --- a/src/OpenProtocolInterpreter/ParameterSet/Mid0013.cs +++ b/src/OpenProtocolInterpreter/ParameterSet/Mid0013.cs @@ -15,70 +15,70 @@ public class Mid0013 : Mid, IParameterSet, IController public int ParameterSetId { - get => GetField(1, (int)DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); } public string ParameterSetName { - get => GetField(1, (int)DataFields.ParameterSetName).Value; - set => GetField(1, (int)DataFields.ParameterSetName).SetValue(value); + get => GetField(1, DataFields.ParameterSetName).Value; + set => GetField(1, DataFields.ParameterSetName).SetValue(value); } public RotationDirection RotationDirection { - get => (RotationDirection)GetField(1, (int)DataFields.RotationDirection).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.RotationDirection).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (RotationDirection)GetField(1, DataFields.RotationDirection).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.RotationDirection).SetValue(OpenProtocolConvert.ToString, value); } public int BatchSize { - get => GetField(1, (int)DataFields.BatchSize).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.BatchSize).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.BatchSize).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.BatchSize).SetValue(OpenProtocolConvert.ToString, value); } public decimal MinTorque { - get => GetField(1, (int)DataFields.MinTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(1, (int)DataFields.MinTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(1, DataFields.MinTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(1, DataFields.MinTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal MaxTorque { - get => GetField(1, (int)DataFields.MaxTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(1, (int)DataFields.MaxTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(1, DataFields.MaxTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(1, DataFields.MaxTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal TorqueFinalTarget { - get => GetField(1, (int)DataFields.TorqueFinalTarget).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(1, (int)DataFields.TorqueFinalTarget).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(1, DataFields.TorqueFinalTarget).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(1, DataFields.TorqueFinalTarget).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public int MinAngle { - get => GetField(1, (int)DataFields.MinAngle).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.MinAngle).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.MinAngle).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.MinAngle).SetValue(OpenProtocolConvert.ToString, value); } public int MaxAngle { - get => GetField(1, (int)DataFields.MaxAngle).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.MaxAngle).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.MaxAngle).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.MaxAngle).SetValue(OpenProtocolConvert.ToString, value); } public int AngleFinalTarget { - get => GetField(1, (int)DataFields.AngleFinalTarget).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.AngleFinalTarget).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.AngleFinalTarget).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.AngleFinalTarget).SetValue(OpenProtocolConvert.ToString, value); } //Rev 2 public decimal FirstTarget { - get => GetField(2, (int)DataFields.FirstTarget).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(2, (int)DataFields.FirstTarget).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(2, DataFields.FirstTarget).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(2, DataFields.FirstTarget).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal StartFinalAngle { - get => GetField(2, (int)DataFields.StartFinalTarget).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(2, (int)DataFields.StartFinalTarget).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(2, DataFields.StartFinalTarget).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(2, DataFields.StartFinalTarget).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } //Rev 5 public DateTime LastChangeInParameterSet { - get => GetField(5, (int)DataFields.LastChangeInParameterSet).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(5, (int)DataFields.LastChangeInParameterSet).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(5, DataFields.LastChangeInParameterSet).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(5, DataFields.LastChangeInParameterSet).SetValue(OpenProtocolConvert.ToString, value); } public Mid0013() : this(DEFAULT_REVISION) @@ -106,29 +106,29 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ParameterSetId, 20, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ParameterSetName, 25, 25, ' '), - new DataField((int)DataFields.RotationDirection, 52, 1, '0'), - new DataField((int)DataFields.BatchSize, 55, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.MinTorque, 59, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.MaxTorque, 67, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TorqueFinalTarget, 75, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.MinAngle, 83, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.MaxAngle, 90, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.AngleFinalTarget, 97, 5, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.ParameterSetId, 20, 3), + DataField.String(DataFields.ParameterSetName, 25, 25), + DataField.Number(DataFields.RotationDirection, 52, 1), + DataField.Number(DataFields.BatchSize, 55, 2), + DataField.Number(DataFields.MinTorque, 59, 6), + DataField.Number(DataFields.MaxTorque, 67, 6), + DataField.Number(DataFields.TorqueFinalTarget, 75, 6), + DataField.Number(DataFields.MinAngle, 83, 5), + DataField.Number(DataFields.MaxAngle, 90, 5), + DataField.Number(DataFields.AngleFinalTarget, 97, 5) } }, { 2, new List() { - new DataField((int)DataFields.FirstTarget, 104, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.StartFinalTarget, 112, 6, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.FirstTarget, 104, 6), + DataField.Number(DataFields.StartFinalTarget, 112, 6) } }, { 5, new List() { - new DataField((int)DataFields.LastChangeInParameterSet, 120, 19), + DataField.Timestamp(DataFields.LastChangeInParameterSet, 120), } } }; diff --git a/src/OpenProtocolInterpreter/ParameterSet/Mid0015.cs b/src/OpenProtocolInterpreter/ParameterSet/Mid0015.cs index 33d3e63f..f35bcbac 100644 --- a/src/OpenProtocolInterpreter/ParameterSet/Mid0015.cs +++ b/src/OpenProtocolInterpreter/ParameterSet/Mid0015.cs @@ -20,69 +20,69 @@ public class Mid0015 : Mid, IParameterSet, IController, IAcknowledgeable GetField(Header.Revision, (int)DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(Header.Revision, (int)DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); } public DateTime LastChangeInParameterSet { - get => GetField(Header.Revision, (int)DataFields.LastChangeInParameterSet).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(Header.Revision, (int)DataFields.LastChangeInParameterSet).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.LastChangeInParameterSet).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(Header.StandardizedRevision, DataFields.LastChangeInParameterSet).SetValue(OpenProtocolConvert.ToString, value); } //Rev 2 public string ParameterSetName { - get => GetField(2, (int)DataFields.ParameterSetName).Value; - set => GetField(2, (int)DataFields.ParameterSetName).SetValue(value); + get => GetField(2, DataFields.ParameterSetName).Value; + set => GetField(2, DataFields.ParameterSetName).SetValue(value); } public RotationDirection RotationDirection { - get => (RotationDirection)GetField(2, (int)DataFields.RotationDirection).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.RotationDirection).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (RotationDirection)GetField(2, DataFields.RotationDirection).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.RotationDirection).SetValue(OpenProtocolConvert.ToString, value); } public int BatchSize { - get => GetField(2, (int)DataFields.BatchSize).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.BatchSize).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.BatchSize).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.BatchSize).SetValue(OpenProtocolConvert.ToString, value); } public decimal MinTorque { - get => GetField(2, (int)DataFields.TorqueMin).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(2, (int)DataFields.TorqueMin).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(2, DataFields.TorqueMin).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(2, DataFields.TorqueMin).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal MaxTorque { - get => GetField(2, (int)DataFields.TorqueMax).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(2, (int)DataFields.TorqueMax).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(2, DataFields.TorqueMax).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(2, DataFields.TorqueMax).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal TorqueFinalTarget { - get => GetField(2, (int)DataFields.TorqueFinalTarget).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(2, (int)DataFields.TorqueFinalTarget).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(2, DataFields.TorqueFinalTarget).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(2, DataFields.TorqueFinalTarget).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public int MinAngle { - get => GetField(2, (int)DataFields.AngleMin).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.AngleMin).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.AngleMin).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.AngleMin).SetValue(OpenProtocolConvert.ToString, value); } public int MaxAngle { - get => GetField(2, (int)DataFields.AngleMax).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.AngleMax).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.AngleMax).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.AngleMax).SetValue(OpenProtocolConvert.ToString, value); } public int AngleFinalTarget { - get => GetField(2, (int)DataFields.FinalAngleTarget).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.FinalAngleTarget).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.FinalAngleTarget).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.FinalAngleTarget).SetValue(OpenProtocolConvert.ToString, value); } public decimal FirstTarget { - get => GetField(2, (int)DataFields.FirstTarget).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(2, (int)DataFields.FirstTarget).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(2, DataFields.FirstTarget).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(2, DataFields.FirstTarget).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal StartFinalAngle { - get => GetField(2, (int)DataFields.StartFinalAngle).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(2, (int)DataFields.StartFinalAngle).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(2, DataFields.StartFinalAngle).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(2, DataFields.StartFinalAngle).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public Mid0015() : this(DEFAULT_REVISION) @@ -109,7 +109,7 @@ public Mid0015(int revision) : this(new Header() protected override string BuildHeader() { Header.Length = 20; - foreach (var dataField in RevisionsByFields[Header.Revision]) + foreach (var dataField in RevisionsByFields[Header.StandardizedRevision]) Header.Length += (dataField.HasPrefix ? 2 : 0) + dataField.Size; return Header.ToString(); @@ -118,14 +118,13 @@ protected override string BuildHeader() public override string Pack() { int index = 1; - return BuildHeader() + base.Pack(RevisionsByFields[Header.Revision], ref index); + return BuildHeader() + base.Pack(Header.StandardizedRevision, ref index); } public override Mid Parse(string package) { Header = ProcessHeader(package); - Header.Revision = Header.Revision > 0 ? Header.Revision : 1; - ProcessDataFields(RevisionsByFields[Header.Revision], package); + ProcessDataFields(Header.StandardizedRevision, package); return this; } @@ -136,26 +135,26 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ParameterSetId, 20, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.LastChangeInParameterSet, 23, 19, false) + DataField.Number(DataFields.ParameterSetId, 20, 3, false), + DataField.Timestamp(DataFields.LastChangeInParameterSet, 23, false) } }, { 2, new List() { - new DataField((int)DataFields.ParameterSetId, 20, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ParameterSetName, 25, 25, ' '), - new DataField((int)DataFields.LastChangeInParameterSet, 52, 19), - new DataField((int)DataFields.RotationDirection, 73, 1), - new DataField((int)DataFields.BatchSize, 76, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TorqueMin, 80, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TorqueMax, 88, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TorqueFinalTarget, 96, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.AngleMin, 104, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.AngleMax, 111, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.FinalAngleTarget, 118, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.FirstTarget, 125, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.StartFinalAngle, 133, 6, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.ParameterSetId, 20, 3), + DataField.String(DataFields.ParameterSetName, 25, 25), + DataField.Timestamp(DataFields.LastChangeInParameterSet, 52), + DataField.Number(DataFields.RotationDirection, 73, 1), + DataField.Number(DataFields.BatchSize, 76, 2), + DataField.Number(DataFields.TorqueMin, 80, 6), + DataField.Number(DataFields.TorqueMax, 88, 6), + DataField.Number(DataFields.TorqueFinalTarget, 96, 6), + DataField.Number(DataFields.AngleMin, 104, 5), + DataField.Number(DataFields.AngleMax, 111, 5), + DataField.Number(DataFields.FinalAngleTarget, 118, 5), + DataField.Number(DataFields.FirstTarget, 125, 6), + DataField.Number(DataFields.StartFinalAngle, 133, 6) } } }; diff --git a/src/OpenProtocolInterpreter/ParameterSet/Mid0018.cs b/src/OpenProtocolInterpreter/ParameterSet/Mid0018.cs index 1c7db886..80eda582 100644 --- a/src/OpenProtocolInterpreter/ParameterSet/Mid0018.cs +++ b/src/OpenProtocolInterpreter/ParameterSet/Mid0018.cs @@ -18,8 +18,8 @@ public class Mid0018 : Mid, IParameterSet, IIntegrator, IAcceptableCommand, IDec public int ParameterSetId { - get => GetField(1,(int)DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); } public Mid0018() : this(new Header() @@ -41,7 +41,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ParameterSetId, 20, 3, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.ParameterSetId, 20, 3, false) } } }; diff --git a/src/OpenProtocolInterpreter/ParameterSet/Mid0019.cs b/src/OpenProtocolInterpreter/ParameterSet/Mid0019.cs index 642e8837..50af294a 100644 --- a/src/OpenProtocolInterpreter/ParameterSet/Mid0019.cs +++ b/src/OpenProtocolInterpreter/ParameterSet/Mid0019.cs @@ -19,18 +19,18 @@ public class Mid0019 : Mid, IParameterSet, IIntegrator, IAcceptableCommand, IDec public int ParameterSetId { - get => GetField(1,(int)DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); } public int BatchSize { - get => GetField(1,(int)DataFields.BatchSize).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.BatchSize).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.BatchSize).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.BatchSize).SetValue(OpenProtocolConvert.ToString, value); } public Mid0019() : this(new Header() { - Mid = MID, + Mid = MID, Revision = DEFAULT_REVISION }) { @@ -40,6 +40,33 @@ public Mid0019(Header header) : base(header) { } + public override string Pack() + { + HandleRevision(); + return base.Pack(); + } + + public override Mid Parse(string package) + { + Header = ProcessHeader(package); + HandleRevision(); + ProcessDataFields(package); + return this; + } + + private void HandleRevision() + { + var batchSizeField = GetField(1, DataFields.BatchSize); + if (Header.Revision > 1) + { + batchSizeField.Size = 4; + } + else + { + batchSizeField.Size = 2; + } + } + protected override Dictionary> RegisterDatafields() { return new Dictionary>() @@ -47,8 +74,8 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ParameterSetId, 20, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.BatchSize, 23, 2, '0', PaddingOrientation.LeftPadded, false), + DataField.Number(DataFields.ParameterSetId, 20, 3, false), + DataField.Number(DataFields.BatchSize, 23, 2, false), } } }; diff --git a/src/OpenProtocolInterpreter/ParameterSet/Mid0020.cs b/src/OpenProtocolInterpreter/ParameterSet/Mid0020.cs index 9023c86a..c50e0eaf 100644 --- a/src/OpenProtocolInterpreter/ParameterSet/Mid0020.cs +++ b/src/OpenProtocolInterpreter/ParameterSet/Mid0020.cs @@ -19,8 +19,8 @@ public class Mid0020 : Mid, IParameterSet, IIntegrator, IAcceptableCommand, IDec public int ParameterSetId { - get => GetField(1, (int)DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); } public Mid0020() : this(new Header() @@ -42,7 +42,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ParameterSetId, 20, 3, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.ParameterSetId, 20, 3, false) } } }; diff --git a/src/OpenProtocolInterpreter/ParameterSet/Mid0022.cs b/src/OpenProtocolInterpreter/ParameterSet/Mid0022.cs index ea97b7ea..5a1419b7 100644 --- a/src/OpenProtocolInterpreter/ParameterSet/Mid0022.cs +++ b/src/OpenProtocolInterpreter/ParameterSet/Mid0022.cs @@ -14,8 +14,8 @@ public class Mid0022 : Mid, IParameterSet, IController, IAcknowledgeable GetField(1, (int)DataFields.RelayStatus).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.RelayStatus).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.RelayStatus).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.RelayStatus).SetValue(OpenProtocolConvert.ToString, value); } public Mid0022() : this(new Header() @@ -37,7 +37,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.RelayStatus, 20, 1, false) + DataField.Boolean(DataFields.RelayStatus, 20, false) } } }; diff --git a/src/OpenProtocolInterpreter/ParameterSet/Mid2504.cs b/src/OpenProtocolInterpreter/ParameterSet/Mid2504.cs index eb87ce14..f71e07ef 100644 --- a/src/OpenProtocolInterpreter/ParameterSet/Mid2504.cs +++ b/src/OpenProtocolInterpreter/ParameterSet/Mid2504.cs @@ -18,8 +18,8 @@ public class Mid2504 : Mid, IParameterSet, IIntegrator, IAcceptableCommand, IDec public int ParameterSetId { - get => GetField(1,(int)DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); } public Mid2504() : this(new Header() @@ -42,7 +42,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ParameterSetId, 20, 3, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.ParameterSetId, 20, 3, false) } } }; diff --git a/src/OpenProtocolInterpreter/ParameterSet/Mid2505.cs b/src/OpenProtocolInterpreter/ParameterSet/Mid2505.cs index 7dec976c..61da610b 100644 --- a/src/OpenProtocolInterpreter/ParameterSet/Mid2505.cs +++ b/src/OpenProtocolInterpreter/ParameterSet/Mid2505.cs @@ -23,13 +23,13 @@ public class Mid2505 : Mid, IParameterSet, IIntegrator, IAcceptableCommand, IDec public int ParameterSetId { - get => GetField(1, (int)DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); } public int NumberOfParameterDataFields { - get => GetField(1, (int)DataFields.NumberOfParameterDataFields).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.NumberOfParameterDataFields).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.NumberOfParameterDataFields).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.NumberOfParameterDataFields).SetValue(OpenProtocolConvert.ToString, value); } public List VariableDataFields { get; set; } @@ -48,19 +48,19 @@ public Mid2505(int revision) : this(new Header() public Mid2505(Header header) : base(header) { - VariableDataFields = new List(); + VariableDataFields = []; } public override string Pack() { - GetField(1, (int)DataFields.DataFields).Value = OpenProtocolConvert.ToString(VariableDataFields); + GetField(1, DataFields.DataFields).Value = OpenProtocolConvert.ToString(VariableDataFields); return base.Pack(); } public override Mid Parse(string package) { Header = ProcessHeader(package); - var dataFieldsField = GetField(1, (int)DataFields.DataFields); + var dataFieldsField = GetField(1, DataFields.DataFields); dataFieldsField.Size = Header.Length - dataFieldsField.Index; ProcessDataFields(package); VariableDataFields = VariableDataField.ParseAll(dataFieldsField.Value).ToList(); @@ -74,9 +74,9 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ParameterSetId, 20, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.NumberOfParameterDataFields, 23, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.DataFields, 26, 0, false) + DataField.Number(DataFields.ParameterSetId, 20, 3, false), + DataField.Number(DataFields.NumberOfParameterDataFields, 23, 3, false), + DataField.Volatile(DataFields.DataFields, 26, false) } } }; diff --git a/src/OpenProtocolInterpreter/ParameterSet/Mid2506.cs b/src/OpenProtocolInterpreter/ParameterSet/Mid2506.cs new file mode 100644 index 00000000..8bdc6a40 --- /dev/null +++ b/src/OpenProtocolInterpreter/ParameterSet/Mid2506.cs @@ -0,0 +1,67 @@ +using System.Collections.Generic; + +namespace OpenProtocolInterpreter.ParameterSet +{ + /// + /// Tightening Program Delete + /// Message sent by: Integrator + /// + /// Answer: Command accepted or + /// Command error + /// + /// This message deletes one or all programs in controller. + /// Note: If a running program is included in MID 2506 deletion the program shall finish before deletion. + /// Note: Deleting programs included in other nodes may give unwanted behaviour. It will behave identical to a manual delete of the program. + /// + public class Mid2506 : Mid, IParameterSet, IIntegrator, IAcceptableCommand, IDeclinableCommand + { + public const int MID = 2506; + + public IEnumerable DocumentedPossibleErrors => []; + + public int ProgramId + { + get => GetField(1, DataFields.ProgramId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ProgramId).SetValue(OpenProtocolConvert.ToString, value); + } + public NodeType NodeType + { + get => (NodeType)GetField(1, DataFields.NodeType).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.NodeType).SetValue(OpenProtocolConvert.ToString, value); + } + + public Mid2506() : this(new Header() + { + Mid = MID, + Revision = DEFAULT_REVISION + }) + { + + } + + public Mid2506(Header header) : base(header) + { + + } + + protected override Dictionary> RegisterDatafields() + { + return new Dictionary>() + { + { + 1, new List() + { + DataField.Number(DataFields.ProgramId, 20, 4, false), + DataField.Number(DataFields.NodeType, 24, 3, false), + } + } + }; + } + + protected enum DataFields + { + ProgramId, + NodeType + } + } +} diff --git a/src/OpenProtocolInterpreter/ParameterSet/ParameterSetMessages.cs b/src/OpenProtocolInterpreter/ParameterSet/ParameterSetMessages.cs index a820fbe0..b5a16f0d 100644 --- a/src/OpenProtocolInterpreter/ParameterSet/ParameterSetMessages.cs +++ b/src/OpenProtocolInterpreter/ParameterSet/ParameterSetMessages.cs @@ -29,7 +29,8 @@ public ParameterSetMessages() : base() { Mid0023.MID, new MidCompiledInstance(typeof(Mid0023)) }, { Mid0024.MID, new MidCompiledInstance(typeof(Mid0024)) }, { Mid2504.MID, new MidCompiledInstance(typeof(Mid2504)) }, - { Mid2505.MID, new MidCompiledInstance(typeof(Mid2505)) } + { Mid2505.MID, new MidCompiledInstance(typeof(Mid2505)) }, + { Mid2506.MID, new MidCompiledInstance(typeof(Mid2506)) } }; } @@ -43,6 +44,6 @@ public ParameterSetMessages(InterpreterMode mode) : this() FilterSelectedMids(mode); } - public override bool IsAssignableTo(int mid) => mid > 9 && mid < 26 || mid > 2499 && mid < 2506; + public override bool IsAssignableTo(int mid) => mid > 9 && mid < 26 || mid > 2499 && mid < 2507; } } diff --git a/src/OpenProtocolInterpreter/PowerMACS/Mid0105.cs b/src/OpenProtocolInterpreter/PowerMACS/Mid0105.cs index b57655eb..13b2dc90 100644 --- a/src/OpenProtocolInterpreter/PowerMACS/Mid0105.cs +++ b/src/OpenProtocolInterpreter/PowerMACS/Mid0105.cs @@ -27,13 +27,13 @@ public class Mid0105 : Mid, IPowerMACS, IIntegrator, ISubscription, IAcceptableC public int DataNumberSystem { - get => GetField(2,(int)DataFields.DataNumberSystem).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2,(int)DataFields.DataNumberSystem).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.DataNumberSystem).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.DataNumberSystem).SetValue(OpenProtocolConvert.ToString, value); } public bool SendOnlyNewData { - get => GetField(3,(int)DataFields.SendOnlyNewData).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(3,(int)DataFields.SendOnlyNewData).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(3, DataFields.SendOnlyNewData).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(3, DataFields.SendOnlyNewData).SetValue(OpenProtocolConvert.ToString, value); } public Mid0105() : this(DEFAULT_REVISION) @@ -47,13 +47,13 @@ public Mid0105(Header header) : base(header) public Mid0105(bool noAckFlag = false) : this(DEFAULT_REVISION, noAckFlag) { - + } public Mid0105(int revision, bool noAckFlag = false) : this(new Header() { - Mid = MID, - Revision = revision, + Mid = MID, + Revision = revision, NoAckFlag = noAckFlag }) { @@ -66,13 +66,13 @@ protected override Dictionary> RegisterDatafields() { 2, new List() { - new DataField((int)DataFields.DataNumberSystem, 20, 10, '0', PaddingOrientation.LeftPadded, false), + DataField.Number(DataFields.DataNumberSystem, 20, 10, false), } }, { 3, new List() { - new DataField((int)DataFields.SendOnlyNewData, 30, 1, false) + DataField.Boolean(DataFields.SendOnlyNewData, 30, false) } }, }; diff --git a/src/OpenProtocolInterpreter/PowerMACS/Mid0106.cs b/src/OpenProtocolInterpreter/PowerMACS/Mid0106.cs index 6a11a62c..1e4346db 100644 --- a/src/OpenProtocolInterpreter/PowerMACS/Mid0106.cs +++ b/src/OpenProtocolInterpreter/PowerMACS/Mid0106.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; namespace OpenProtocolInterpreter.PowerMACS { @@ -34,75 +35,75 @@ public class Mid0106 : Mid, IPowerMACS, IController, IAcknowledgeable public int TotalNumberOfMessages { - get => GetField(1, (int)DataFields.TotalNumberOfMessages).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.TotalNumberOfMessages).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.TotalNumberOfMessages).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.TotalNumberOfMessages).SetValue(OpenProtocolConvert.ToString, value); } public int MessageNumber { - get => GetField(1, (int)DataFields.MessageNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.MessageNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.MessageNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.MessageNumber).SetValue(OpenProtocolConvert.ToString, value); } public int DataNumberSystem { - get => GetField(1, (int)DataFields.DataNumberSystem).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.DataNumberSystem).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.DataNumberSystem).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.DataNumberSystem).SetValue(OpenProtocolConvert.ToString, value); } public int StationNumber { - get => GetField(1, (int)DataFields.StationNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.StationNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.StationNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.StationNumber).SetValue(OpenProtocolConvert.ToString, value); } public string StationName { - get => GetField(1, (int)DataFields.StationName).Value; - set => GetField(1, (int)DataFields.StationName).SetValue(value); + get => GetField(1, DataFields.StationName).Value; + set => GetField(1, DataFields.StationName).SetValue(value); } public DateTime Time { - get => GetField(1, (int)DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(1, (int)DataFields.Time).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(1, DataFields.Time).SetValue(OpenProtocolConvert.ToString, value); } public int ModeNumber { - get => GetField(1, (int)DataFields.ModeNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ModeNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ModeNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ModeNumber).SetValue(OpenProtocolConvert.ToString, value); } public string ModeName { - get => GetField(1, (int)DataFields.ModeName).Value; - set => GetField(1, (int)DataFields.ModeName).SetValue(value); + get => GetField(1, DataFields.ModeName).Value; + set => GetField(1, DataFields.ModeName).SetValue(value); } public bool SimpleStatus { - get => GetField(1, (int)DataFields.SimpleStatus).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.SimpleStatus).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.SimpleStatus).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.SimpleStatus).SetValue(OpenProtocolConvert.ToString, value); } public PowerMacsStatus PMStatus { - get => (PowerMacsStatus)GetField(1, (int)DataFields.PMStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.PMStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (PowerMacsStatus)GetField(1, DataFields.PMStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.PMStatus).SetValue(OpenProtocolConvert.ToString, value); } public string WpId { - get => GetField(1, (int)DataFields.WPId).Value; - set => GetField(1, (int)DataFields.WPId).SetValue(value); + get => GetField(1, DataFields.WPId).Value; + set => GetField(1, DataFields.WPId).SetValue(value); } public int NumberOfBolts { - get => GetField(1, (int)DataFields.NumberOfBolts).GetValue(OpenProtocolConvert.ToInt32); - private set => GetField(1, (int)DataFields.NumberOfBolts).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.NumberOfBolts).GetValue(OpenProtocolConvert.ToInt32); + private set => GetField(1, DataFields.NumberOfBolts).SetValue(OpenProtocolConvert.ToString, value); } public List BoltsData { get; set; } public int TotalSpecialValues { - get => GetField(1, (int)DataFields.NumberOfSpecialValues).GetValue(OpenProtocolConvert.ToInt32); - private set => GetField(1, (int)DataFields.NumberOfSpecialValues).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.NumberOfSpecialValues).GetValue(OpenProtocolConvert.ToInt32); + private set => GetField(1, DataFields.NumberOfSpecialValues).SetValue(OpenProtocolConvert.ToString, value); } public List SpecialValues { get; set; } public SystemSubType SystemSubType { - get => (SystemSubType)GetField(4, (int)DataFields.SystemSubType).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(4, (int)DataFields.SystemSubType).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (SystemSubType)GetField(4, DataFields.SystemSubType).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(4, DataFields.SystemSubType).SetValue(OpenProtocolConvert.ToString, value); } public Mid0106() : this(DEFAULT_REVISION) @@ -112,10 +113,8 @@ public Mid0106() : this(DEFAULT_REVISION) public Mid0106(Header header) : base(header) { - if (BoltsData == null) - BoltsData = new List(); - if (SpecialValues == null) - SpecialValues = new List(); + BoltsData ??= []; + SpecialValues ??= []; } public Mid0106(int revision) : this(new Header() @@ -130,10 +129,10 @@ public override string Pack() { NumberOfBolts = BoltsData.Count; TotalSpecialValues = SpecialValues.Count; - GetField(1, (int)DataFields.BoltData).Value = PackBoltsData(); - GetField(1, (int)DataFields.SpecialValues).Value = PackSpecialValues(); + GetField(1, DataFields.BoltData).Value = PackBoltsData(); + GetField(1, DataFields.SpecialValues).Value = PackSpecialValues(); - string package = BuildHeader(); + var builder = new StringBuilder(BuildHeader()); int prefixIndex = 1; for (int i = 1; i <= (Header.Revision > 0 ? Header.Revision : 1); i++) foreach (var dataField in RevisionsByFields[i]) @@ -143,32 +142,32 @@ public override string Pack() if (dataField.HasPrefix) { - package += prefixIndex.ToString().PadLeft(2, '0') + dataField.Value; + builder.Append(prefixIndex.ToString("D2")); prefixIndex++; } - else - package += dataField.Value; + + builder.Append(dataField.Value); } - return package; + return builder.ToString(); } public override Mid Parse(string package) { Header = ProcessHeader(package); - int numberOfBolts = OpenProtocolConvert.ToInt32(package.Substring(GetField(1, (int)DataFields.NumberOfBolts).Index + 2, GetField(1, (int)DataFields.NumberOfBolts).Size)); - GetField(1, (int)DataFields.BoltData).Size *= numberOfBolts; + int numberOfBolts = OpenProtocolConvert.ToInt32(package.Substring(GetField(1, DataFields.NumberOfBolts).Index + 2, GetField(1, DataFields.NumberOfBolts).Size)); + GetField(1, DataFields.BoltData).Size *= numberOfBolts; - var numberOfSpecialValuesField = GetField(1, (int)DataFields.NumberOfSpecialValues); - numberOfSpecialValuesField.Index = GetField(1, (int)DataFields.BoltData).Index + GetField(1, (int)DataFields.BoltData).Size; + var numberOfSpecialValuesField = GetField(1, DataFields.NumberOfSpecialValues); + numberOfSpecialValuesField.Index = GetField(1, DataFields.BoltData).Index + GetField(1, DataFields.BoltData).Size; - var specialValues = GetField(1, (int)DataFields.SpecialValues); + var specialValues = GetField(1, DataFields.SpecialValues); specialValues.Index = numberOfSpecialValuesField.Index + numberOfSpecialValuesField.Size + 2; if (Header.Revision > 3) { - specialValues.Size = Header.Length - GetField(4, (int)DataFields.SystemSubType).Size - 2; - GetField(4, (int)DataFields.SystemSubType).Index = specialValues.Index + specialValues.Size; + specialValues.Size = Header.Length - GetField(4, DataFields.SystemSubType).Size - 2; + GetField(4, DataFields.SystemSubType).Index = specialValues.Index + specialValues.Size; } else { @@ -177,40 +176,40 @@ public override Mid Parse(string package) ProcessDataFields(package); - BoltsData = ParseBoltsData(GetField(1, (int)DataFields.BoltData).Value); - SpecialValues = SpecialValue.ParseAll(GetField(1, (int)DataFields.SpecialValues).Value, TotalSpecialValues, false).ToList(); + BoltsData = ParseBoltsData(GetField(1, DataFields.BoltData).Value); + SpecialValues = SpecialValue.ParseAll(GetField(1, DataFields.SpecialValues).Value, TotalSpecialValues, false).ToList(); return this; } protected virtual string PackBoltsData() { - string package = string.Empty; + var builder = new StringBuilder(); foreach (var bolt in BoltsData) { - package += $"13{OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, bolt.OrdinalBoltNumber)}"; - package += $"14{OpenProtocolConvert.ToString(bolt.SimpleBoltStatus)}"; - package += $"15{OpenProtocolConvert.ToString((int)bolt.TorqueStatus)}"; - package += $"16{OpenProtocolConvert.ToString((int)bolt.AngleStatus)}"; - package += $"17{OpenProtocolConvert.ToString('0', 7, PaddingOrientation.RightPadded, bolt.BoltTorque)}"; - package += $"18{OpenProtocolConvert.ToString('0', 7, PaddingOrientation.RightPadded, bolt.BoltAngle)}"; - package += $"19{OpenProtocolConvert.ToString('0', 7, PaddingOrientation.RightPadded, bolt.BoltTorqueHighLimit)}"; - package += $"20{OpenProtocolConvert.ToString('0', 7, PaddingOrientation.RightPadded, bolt.BoltTorqueLowLimit)}"; - package += $"21{OpenProtocolConvert.ToString('0', 7, PaddingOrientation.RightPadded, bolt.BoltAngleHighLimit)}"; - package += $"22{OpenProtocolConvert.ToString('0', 7, PaddingOrientation.RightPadded, bolt.BoltAngleLowLimit)}"; + builder.Append($"13{OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, bolt.OrdinalBoltNumber)}"); + builder.Append($"14{OpenProtocolConvert.ToString(bolt.SimpleBoltStatus)}"); + builder.Append($"15{OpenProtocolConvert.ToString(bolt.TorqueStatus)}"); + builder.Append($"16{OpenProtocolConvert.ToString(bolt.AngleStatus)}"); + builder.Append($"17{OpenProtocolConvert.ToString('0', 7, PaddingOrientation.RightPadded, bolt.BoltTorque)}"); + builder.Append($"18{OpenProtocolConvert.ToString('0', 7, PaddingOrientation.RightPadded, bolt.BoltAngle)}"); + builder.Append($"19{OpenProtocolConvert.ToString('0', 7, PaddingOrientation.RightPadded, bolt.BoltTorqueHighLimit)}"); + builder.Append($"20{OpenProtocolConvert.ToString('0', 7, PaddingOrientation.RightPadded, bolt.BoltTorqueLowLimit)}"); + builder.Append($"21{OpenProtocolConvert.ToString('0', 7, PaddingOrientation.RightPadded, bolt.BoltAngleHighLimit)}"); + builder.Append($"22{OpenProtocolConvert.ToString('0', 7, PaddingOrientation.RightPadded, bolt.BoltAngleLowLimit)}"); } - return package; + return builder.ToString(); } protected virtual string PackSpecialValues() { - string package = string.Empty; + var builder = new StringBuilder(); foreach (var v in SpecialValues) { - package += v.Pack(false); + builder.Append(v.Pack(false)); } - return package; + return builder.ToString(); } protected virtual List ParseBoltsData(string value) @@ -254,27 +253,27 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.TotalNumberOfMessages, 20, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.MessageNumber, 24, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.DataNumberSystem, 28, 10, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.StationNumber, 40, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.StationName, 44, 20, ' '), - new DataField((int)DataFields.Time, 66, 19), - new DataField((int)DataFields.ModeNumber, 87, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ModeName, 91, 20, ' '), - new DataField((int)DataFields.SimpleStatus, 113, 1), - new DataField((int)DataFields.PMStatus, 116, 1), - new DataField((int)DataFields.WPId, 119, 40, ' '), - new DataField((int)DataFields.NumberOfBolts, 161, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.BoltData, 165, 67, false), - new DataField((int)DataFields.NumberOfSpecialValues, 0, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.SpecialValues, 0, 0, false) + DataField.Number(DataFields.TotalNumberOfMessages, 20, 2), + DataField.Number(DataFields.MessageNumber, 24, 2), + DataField.Number(DataFields.DataNumberSystem, 28, 10), + DataField.Number(DataFields.StationNumber, 40, 2), + DataField.String(DataFields.StationName, 44, 20), + DataField.Timestamp(DataFields.Time, 66), + DataField.Number(DataFields.ModeNumber, 87, 2), + DataField.String(DataFields.ModeName, 91, 20), + DataField.Boolean(DataFields.SimpleStatus, 113), + DataField.Number(DataFields.PMStatus, 116, 1), + DataField.String(DataFields.WPId, 119, 40), + DataField.Number(DataFields.NumberOfBolts, 161, 2), + new(DataFields.BoltData, 165, 67, false), + DataField.Number(DataFields.NumberOfSpecialValues, 0, 2), + DataField.Volatile(DataFields.SpecialValues, false) } }, { 4, new List() { - new DataField((int)DataFields.SystemSubType, 0, 3, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.SystemSubType, 0, 3) } } }; diff --git a/src/OpenProtocolInterpreter/PowerMACS/Mid0107.cs b/src/OpenProtocolInterpreter/PowerMACS/Mid0107.cs index 40613a7e..c315a568 100644 --- a/src/OpenProtocolInterpreter/PowerMACS/Mid0107.cs +++ b/src/OpenProtocolInterpreter/PowerMACS/Mid0107.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; namespace OpenProtocolInterpreter.PowerMACS { @@ -33,80 +34,80 @@ public class Mid0107 : Mid, IPowerMACS, IController, IAcknowledgeable public int TotalNumberOfMessages { - get => GetField(1, (int)DataFields.TotalNumberOfMessages).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.TotalNumberOfMessages).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.TotalNumberOfMessages).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.TotalNumberOfMessages).SetValue(OpenProtocolConvert.ToString, value); } public int MessageNumber { - get => GetField(1, (int)DataFields.MessageNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.MessageNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.MessageNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.MessageNumber).SetValue(OpenProtocolConvert.ToString, value); } public int DataNumberSystem { - get => GetField(1, (int)DataFields.DataNumberSystem).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.DataNumberSystem).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.DataNumberSystem).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.DataNumberSystem).SetValue(OpenProtocolConvert.ToString, value); } public int StationNumber { - get => GetField(1, (int)DataFields.StationNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.StationNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.StationNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.StationNumber).SetValue(OpenProtocolConvert.ToString, value); } public DateTime Time { - get => GetField(1, (int)DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(1, (int)DataFields.Time).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(1, DataFields.Time).SetValue(OpenProtocolConvert.ToString, value); } public int BoltNumber { - get => GetField(1, (int)DataFields.BoltNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.BoltNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.BoltNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.BoltNumber).SetValue(OpenProtocolConvert.ToString, value); } public string BoltName { - get => GetField(1, (int)DataFields.BoltName).Value; - set => GetField(1, (int)DataFields.BoltName).SetValue(value); + get => GetField(1, DataFields.BoltName).Value; + set => GetField(1, DataFields.BoltName).SetValue(value); } public string ProgramName { - get => GetField(1, (int)DataFields.ProgramName).Value; - set => GetField(1, (int)DataFields.ProgramName).SetValue(value); + get => GetField(1, DataFields.ProgramName).Value; + set => GetField(1, DataFields.ProgramName).SetValue(value); } public PowerMacsStatus PowerMacsStatus { - get => (PowerMacsStatus)GetField(1, (int)DataFields.PMStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.PMStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (PowerMacsStatus)GetField(1, DataFields.PMStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.PMStatus).SetValue(OpenProtocolConvert.ToString, value); } public string Errors { - get => GetField(1, (int)DataFields.Errors).Value; - set => GetField(1, (int)DataFields.Errors).SetValue(value); + get => GetField(1, DataFields.Errors).Value; + set => GetField(1, DataFields.Errors).SetValue(value); } public string CustomerErrorCode { - get => GetField(1, (int)DataFields.CustomerErrorCode).Value; - set => GetField(1, (int)DataFields.CustomerErrorCode).SetValue(value); + get => GetField(1, DataFields.CustomerErrorCode).Value; + set => GetField(1, DataFields.CustomerErrorCode).SetValue(value); } public int NumberOfBoltResults { - get => GetField(1, (int)DataFields.NumberOfBoltResults).GetValue(OpenProtocolConvert.ToInt32); - private set => GetField(1, (int)DataFields.NumberOfBoltResults).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.NumberOfBoltResults).GetValue(OpenProtocolConvert.ToInt32); + private set => GetField(1, DataFields.NumberOfBoltResults).SetValue(OpenProtocolConvert.ToString, value); } public List BoltResults { get; set; } public int NumberOfStepResults { - get => GetField(1, (int)DataFields.NumberOfStepResults).GetValue(OpenProtocolConvert.ToInt32); - private set => GetField(1, (int)DataFields.NumberOfStepResults).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.NumberOfStepResults).GetValue(OpenProtocolConvert.ToInt32); + private set => GetField(1, DataFields.NumberOfStepResults).SetValue(OpenProtocolConvert.ToString, value); } public bool AllStepDataSent { - get => GetField(1, (int)DataFields.AllStepDataSent).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.AllStepDataSent).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.AllStepDataSent).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.AllStepDataSent).SetValue(OpenProtocolConvert.ToString, value); } public List StepResults { get; set; } public int NumberOfSpecialValues { - get => GetField(1, (int)DataFields.NumberOfSpecialValues).GetValue(OpenProtocolConvert.ToInt32); - private set => GetField(1, (int)DataFields.NumberOfSpecialValues).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.NumberOfSpecialValues).GetValue(OpenProtocolConvert.ToInt32); + private set => GetField(1, DataFields.NumberOfSpecialValues).SetValue(OpenProtocolConvert.ToString, value); } public List SpecialValues { get; set; } @@ -121,12 +122,9 @@ public Mid0107() : this(new Header() public Mid0107(Header header) : base(header) { - if (BoltResults == null) - BoltResults = new List(); - if (StepResults == null) - StepResults = new List(); - if (SpecialValues == null) - SpecialValues = new List(); + BoltResults ??= []; + StepResults ??= []; + SpecialValues ??= []; } public override string Pack() @@ -135,9 +133,9 @@ public override string Pack() NumberOfStepResults = StepResults.Count; NumberOfSpecialValues = SpecialValues.Count; - GetField(1, (int)DataFields.BoltResults).SetValue(PackBoltResultList()); - GetField(1, (int)DataFields.StepResults).SetValue(PackStepResults()); - GetField(1, (int)DataFields.SpecialValues).SetValue(PackSpecialValues()); + GetField(1, DataFields.BoltResults).SetValue(PackBoltResultList()); + GetField(1, DataFields.StepResults).SetValue(PackStepResults()); + GetField(1, DataFields.SpecialValues).SetValue(PackSpecialValues()); return base.Pack(); } @@ -146,26 +144,26 @@ public override Mid Parse(string package) { Header = ProcessHeader(package); - int numberOfBoltResults = OpenProtocolConvert.ToInt32(GetValue(GetField(1, (int)DataFields.NumberOfBoltResults), package)); - var boltResultField = GetField(1, (int)DataFields.BoltResults); + int numberOfBoltResults = OpenProtocolConvert.ToInt32(GetValue(GetField(1, DataFields.NumberOfBoltResults), package)); + var boltResultField = GetField(1, DataFields.BoltResults); boltResultField.Size = 29 * numberOfBoltResults; - var numberOfStepResultsField = GetField(1, (int)DataFields.NumberOfStepResults); + var numberOfStepResultsField = GetField(1, DataFields.NumberOfStepResults); numberOfStepResultsField.Index = boltResultField.Index + boltResultField.Size; - var allStepDataSentField = GetField(1, (int)DataFields.AllStepDataSent); + var allStepDataSentField = GetField(1, DataFields.AllStepDataSent); allStepDataSentField.Index = 2 + numberOfStepResultsField.Index + numberOfStepResultsField.Size; - var stepResultsField = GetField(1, (int)DataFields.StepResults); + var stepResultsField = GetField(1, DataFields.StepResults); stepResultsField.Index = 2 + allStepDataSentField.Index + allStepDataSentField.Size; int numberOfStepResults = OpenProtocolConvert.ToInt32(GetValue(numberOfStepResultsField, package)); stepResultsField.Size = 31 * numberOfStepResults; - var numberOfSpecialValuesField = GetField(1, (int)DataFields.NumberOfSpecialValues); + var numberOfSpecialValuesField = GetField(1, DataFields.NumberOfSpecialValues); numberOfSpecialValuesField.Index = stepResultsField.Index + stepResultsField.Size; - var specialValuesField = GetField(1, (int)DataFields.SpecialValues); + var specialValuesField = GetField(1, DataFields.SpecialValues); specialValuesField.Index = 2 + numberOfSpecialValuesField.Index + numberOfSpecialValuesField.Size; specialValuesField.Size = Header.Length - specialValuesField.Index; @@ -179,53 +177,54 @@ public override Mid Parse(string package) protected virtual string PackBoltResultList() { - string package = string.Empty; + var builder = new StringBuilder(); foreach (var bolt in BoltResults) { - package += OpenProtocolConvert.TruncatePadded(' ', 20, PaddingOrientation.RightPadded, bolt.VariableName); - package += bolt.Type.Type; + builder.Append(OpenProtocolConvert.TruncatePadded(' ', 20, PaddingOrientation.RightPadded, bolt.VariableName)); + builder.Append(bolt.Type.Type); if (bolt.Type.Type == DataType.DataTypes[1].Type) // Integer { - package += OpenProtocolConvert.ToString('0', 7, PaddingOrientation.LeftPadded, (int)bolt.Value); + builder.Append(OpenProtocolConvert.ToString('0', 7, PaddingOrientation.LeftPadded, (int)bolt.Value)); } else if (bolt.Type.Type == DataType.DataTypes[2].Type) // Decimal { - package += OpenProtocolConvert.ToString('0', 7, PaddingOrientation.LeftPadded, (decimal)bolt.Value); + builder.Append(OpenProtocolConvert.ToString('0', 7, PaddingOrientation.LeftPadded, (decimal)bolt.Value)); } } - return package; + return builder.ToString(); } protected virtual string PackStepResults() { - string package = string.Empty; + var builder = new StringBuilder(); foreach (var step in StepResults) { - package += OpenProtocolConvert.TruncatePadded(' ', 20, PaddingOrientation.RightPadded, step.VariableName); - package += step.Type.Type; + builder.Append(OpenProtocolConvert.TruncatePadded(' ', 20, PaddingOrientation.RightPadded, step.VariableName)); + builder.Append(step.Type.Type); if (step.Type.Type == DataType.DataTypes[1].Type) // Integer { - package += OpenProtocolConvert.ToString('0', 7, PaddingOrientation.LeftPadded, (int)step.Value); + builder.Append(OpenProtocolConvert.ToString('0', 7, PaddingOrientation.LeftPadded, (int)step.Value)); } else if (step.Type.Type == DataType.DataTypes[2].Type) // Decimal { - package += OpenProtocolConvert.ToString('0', 7, PaddingOrientation.LeftPadded, (decimal)step.Value); + builder.Append(OpenProtocolConvert.ToString('0', 7, PaddingOrientation.LeftPadded, (decimal)step.Value)); } - package += OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, step.StepNumber); + builder.Append(OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, step.StepNumber)); } - return package; + return builder.ToString(); } + protected virtual string PackSpecialValues() { - string package = string.Empty; + var builder = new StringBuilder(); foreach (var v in SpecialValues) { - package += v.Pack(true); + builder.Append(v.Pack(true)); } - return package; + return builder.ToString(); } protected virtual List ParseBoltResultList(string section) @@ -291,30 +290,30 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.TotalNumberOfMessages, 20, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.MessageNumber, 24, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.DataNumberSystem, 28, 10, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.StationNumber, 40, 2), - new DataField((int)DataFields.Time, 44, 19), - new DataField((int)DataFields.BoltNumber, 65, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.BoltName, 71, 20), - new DataField((int)DataFields.ProgramName, 93, 20), - new DataField((int)DataFields.PMStatus, 115, 1), - new DataField((int)DataFields.Errors, 118, 50), - new DataField((int)DataFields.CustomerErrorCode, 170, 4), - new DataField((int)DataFields.NumberOfBoltResults, 176, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.BoltResults, 180, 0, false), - new DataField((int)DataFields.NumberOfStepResults, 0, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.AllStepDataSent, 0, 1), - new DataField((int)DataFields.StepResults, 0, 0, false), - new DataField((int)DataFields.NumberOfSpecialValues, 0, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.SpecialValues, 0, 0, false) + DataField.Number(DataFields.TotalNumberOfMessages, 20, 2), + DataField.Number(DataFields.MessageNumber, 24, 2), + DataField.Number(DataFields.DataNumberSystem, 28, 10), + DataField.Number(DataFields.StationNumber, 40, 2), + DataField.Timestamp(DataFields.Time, 44), + DataField.Number(DataFields.BoltNumber, 65, 4), + DataField.String(DataFields.BoltName, 71, 20), + DataField.String(DataFields.ProgramName, 93, 20), + DataField.Number(DataFields.PMStatus, 115, 1), + DataField.String(DataFields.Errors, 118, 50), + DataField.String(DataFields.CustomerErrorCode, 170, 4), + DataField.Number(DataFields.NumberOfBoltResults, 176, 2), + DataField.Volatile(DataFields.BoltResults, 180, false), + DataField.Number(DataFields.NumberOfStepResults, 0, 3), + DataField.Boolean(DataFields.AllStepDataSent, 0), + DataField.Volatile(DataFields.StepResults, 0, false), + DataField.Number(DataFields.NumberOfSpecialValues, 0, 2), + DataField.Volatile(DataFields.SpecialValues, 0, false) } }, { 4, new List() { - new DataField((int)DataFields.SystemSubType, 0, 3, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.SystemSubType, 0, 3) } } }; diff --git a/src/OpenProtocolInterpreter/PowerMACS/Mid0108.cs b/src/OpenProtocolInterpreter/PowerMACS/Mid0108.cs index 7990f0c7..45cab4ed 100644 --- a/src/OpenProtocolInterpreter/PowerMACS/Mid0108.cs +++ b/src/OpenProtocolInterpreter/PowerMACS/Mid0108.cs @@ -21,8 +21,8 @@ public class Mid0108 : Mid, IPowerMACS, IIntegrator, IAcknowledge public bool BoltData { - get => GetField(1, (int)DataFields.BoltData).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.BoltData).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.BoltData).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(1, DataFields.BoltData).SetValue(OpenProtocolConvert.ToString, value); } public Mid0108() : this(DEFAULT_REVISION) @@ -49,7 +49,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.BoltData, 20, 1, false), + DataField.Boolean(DataFields.BoltData, 20, false), } }, }; diff --git a/src/OpenProtocolInterpreter/PowerMACS/SpecialValue.cs b/src/OpenProtocolInterpreter/PowerMACS/SpecialValue.cs index 6d3d42db..8a28d646 100644 --- a/src/OpenProtocolInterpreter/PowerMACS/SpecialValue.cs +++ b/src/OpenProtocolInterpreter/PowerMACS/SpecialValue.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Text; namespace OpenProtocolInterpreter.PowerMACS { @@ -15,15 +16,16 @@ public class SpecialValue public string Pack(bool useStepNumber) { - var package = VariableName.PadRight(20, ' ') + + var builder = new StringBuilder(); + builder.Append(VariableName.PadRight(20, ' ') + Type.Type.PadRight(2, ' ') + OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, Length) + - Value.ToString().PadRight(Length, ' '); + Value.ToString().PadRight(Length, ' ')); if (useStepNumber) - package += OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, StepNumber); + builder.Append(OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, StepNumber)); - return package; + return builder.ToString(); } public static SpecialValue Parse(string value, bool useStepNumber) diff --git a/src/OpenProtocolInterpreter/Result/Mid1201.cs b/src/OpenProtocolInterpreter/Result/Mid1201.cs index c80b738b..e1360e0b 100644 --- a/src/OpenProtocolInterpreter/Result/Mid1201.cs +++ b/src/OpenProtocolInterpreter/Result/Mid1201.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; namespace OpenProtocolInterpreter.Result { @@ -24,43 +25,48 @@ public class Mid1201 : Mid, IResult, IController, IAcknowledgeable, IAc public int TotalNumberOfMessages { - get => GetField(1, (int)DataFields.TotalMessages).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.TotalMessages).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.TotalMessages).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.TotalMessages).SetValue(OpenProtocolConvert.ToString, value); } public int MessageNumber { - get => GetField(1, (int)DataFields.MessageNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.MessageNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.MessageNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.MessageNumber).SetValue(OpenProtocolConvert.ToString, value); } public int ResultDataIdentifier { - get => GetField(1, (int)DataFields.ResultDataIdentifier).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ResultDataIdentifier).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.ResultDataIdentifier).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.ResultDataIdentifier).SetValue(OpenProtocolConvert.ToString, value); } public DateTime Time { - get => GetField(1, (int)DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(1, (int)DataFields.Time).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(Header.StandardizedRevision, DataFields.Time).SetValue(OpenProtocolConvert.ToString, value); } public bool ResultStatus { - get => GetField(1, (int)DataFields.ResultStatus).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(1, (int)DataFields.ResultStatus).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.ResultStatus).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(Header.StandardizedRevision, DataFields.ResultStatus).SetValue(OpenProtocolConvert.ToString, value); } public OperationType OperationType { - get => (OperationType)GetField(1, (int)DataFields.OperationType).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.OperationType).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (OperationType)GetField(Header.StandardizedRevision, DataFields.OperationType).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.OperationType).SetValue(OpenProtocolConvert.ToString, value); + } + public int RequestMid + { + get => GetField(Header.StandardizedRevision, DataFields.RequestMid).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.RequestMid).SetValue(OpenProtocolConvert.ToString, value); } public int NumberOfObjects { - get => GetField(1, (int)DataFields.NumberOfObjects).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.NumberOfObjects).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.NumberOfObjects).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.NumberOfObjects).SetValue(OpenProtocolConvert.ToString, value); } public int NumberOfDataFields { - get => GetField(1, (int)DataFields.NumberOfDataFields).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.NumberOfDataFields).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.NumberOfDataFields).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.NumberOfDataFields).SetValue(OpenProtocolConvert.ToString, value); } public List ObjectDataList { get; set; } public List VariableDataFields { get; set; } @@ -80,53 +86,64 @@ public Mid1201(int revision) : this(new Header() public Mid1201(Header header) : base(header) { - ObjectDataList = new List(); - VariableDataFields = new List(); + ObjectDataList = []; + VariableDataFields = []; + } + + protected override string BuildHeader() + { + Header.Length = 20 + RevisionsByFields[Header.StandardizedRevision].Sum(x => x.Size + (x.HasPrefix ? 2 : 0)); + return Header.ToString(); } public override string Pack() { NumberOfObjects = ObjectDataList.Count; NumberOfDataFields = VariableDataFields.Count; + var revision = Header.StandardizedRevision; + GetField(revision, DataFields.ObjectData).SetValue(PackObjectDataList()); + GetField(revision, DataFields.DataFieldList).SetValue(OpenProtocolConvert.ToString(VariableDataFields)); - GetField(1, (int)DataFields.ObjectData).SetValue(PackObjectDataList()); - GetField(1, (int)DataFields.DataFieldList).SetValue(OpenProtocolConvert.ToString(VariableDataFields)); - return base.Pack(); + var index = 1; + return string.Concat(BuildHeader(), base.Pack(revision, ref index)); } public override Mid Parse(string package) { Header = ProcessHeader(package); - var rawTotalObjectData = GetValue(GetField(1, (int)DataFields.NumberOfObjects), package); + + var revision = Header.StandardizedRevision; + var rawTotalObjectData = GetValue(GetField(revision, DataFields.NumberOfObjects), package); int totalObjectData = OpenProtocolConvert.ToInt32(rawTotalObjectData); - var objectDataField = GetField(1, (int)DataFields.ObjectData); - objectDataField.Size = totalObjectData * 5; + var objectDataField = GetField(revision, DataFields.ObjectData); + objectDataField.Size = totalObjectData * ObjectData.Size(Header.Revision); - var totalNumberDataField = GetField(1, (int)DataFields.NumberOfDataFields); + var totalNumberDataField = GetField(revision, DataFields.NumberOfDataFields); totalNumberDataField.Index = objectDataField.Index + objectDataField.Size; - var dataFieldListField = GetField(1, (int)DataFields.DataFieldList); + var dataFieldListField = GetField(revision, DataFields.DataFieldList); dataFieldListField.Index = totalNumberDataField.Index + totalNumberDataField.Size; dataFieldListField.Size = Header.Length - dataFieldListField.Index; - ProcessDataFields(package); - ObjectDataList = ObjectData.ParseAll(objectDataField.Value).ToList(); + ProcessDataFields(revision, package); + ObjectDataList = ObjectData.ParseAll(revision, objectDataField.Value).ToList(); VariableDataFields = VariableDataField.ParseAll(dataFieldListField.Value).ToList(); return this; } protected virtual string PackObjectDataList() { - string pack = string.Empty; + var builder = new StringBuilder(); foreach (var v in ObjectDataList) { - pack += v.Pack(); + builder.Append(v.Pack(Header.StandardizedRevision)); } - return pack; + return builder.ToString(); } + protected override Dictionary> RegisterDatafields() { return new Dictionary>() @@ -134,16 +151,48 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.TotalMessages, 20, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.MessageNumber, 23, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.ResultDataIdentifier, 26, 10, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.Time, 36, 19, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.ResultStatus, 55, 1, false), - new DataField((int)DataFields.OperationType, 56, 2, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.NumberOfObjects, 58, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.ObjectData, 61, 0, false), - new DataField((int)DataFields.NumberOfDataFields, 0, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.DataFieldList, 0, 0, false) + DataField.Number(DataFields.TotalMessages, 20, 3, false), + DataField.Number(DataFields.MessageNumber, 23, 3, false), + DataField.Number(DataFields.ResultDataIdentifier, 26, 10, false), + DataField.Timestamp(DataFields.Time, 36, false), + DataField.Boolean(DataFields.ResultStatus, 55, false), + DataField.Number(DataFields.OperationType, 56, 2, false), + DataField.Number(DataFields.NumberOfObjects, 58, 3, false), + DataField.Volatile(DataFields.ObjectData, 61, false), + DataField.Number(DataFields.NumberOfDataFields, 0, 3, false), + DataField.Volatile(DataFields.DataFieldList, 0, false) + } + }, + { + 2, new List() + { + DataField.Number(DataFields.TotalMessages, 20, 3, false), + DataField.Number(DataFields.MessageNumber, 23, 3, false), + DataField.Number(DataFields.ResultDataIdentifier, 26, 10, false), + DataField.Timestamp(DataFields.Time, 36, false), + DataField.Boolean(DataFields.ResultStatus, 55, false), + DataField.Number(DataFields.OperationType, 56, 2, false), + DataField.Number(DataFields.RequestMid, 58, 4, false), + DataField.Number(DataFields.NumberOfObjects, 62, 3, false), + DataField.Volatile(DataFields.ObjectData, 65, false), + DataField.Number(DataFields.NumberOfDataFields, 0, 3, false), + DataField.Volatile(DataFields.DataFieldList, 0, false) + } + }, + { + 3, new List() + { + DataField.Number(DataFields.TotalMessages, 20, 3, false), + DataField.Number(DataFields.MessageNumber, 23, 3, false), + DataField.Number(DataFields.ResultDataIdentifier, 26, 10, false), + DataField.Timestamp(DataFields.Time, 36, false), + DataField.Boolean(DataFields.ResultStatus, 55, false), + DataField.Number(DataFields.OperationType, 56, 2, false), + DataField.Number(DataFields.RequestMid, 58, 4, false), + DataField.Number(DataFields.NumberOfObjects, 62, 3, false), + DataField.Volatile(DataFields.ObjectData, 65, false), + DataField.Number(DataFields.NumberOfDataFields, 0, 3, false), + DataField.Volatile(DataFields.DataFieldList, 0, false) } } }; @@ -157,6 +206,7 @@ protected enum DataFields Time, ResultStatus, OperationType, + RequestMid, NumberOfObjects, ObjectData, // list of data NumberOfDataFields, diff --git a/src/OpenProtocolInterpreter/Result/Mid1202.cs b/src/OpenProtocolInterpreter/Result/Mid1202.cs index 993c62ce..f6afabe9 100644 --- a/src/OpenProtocolInterpreter/Result/Mid1202.cs +++ b/src/OpenProtocolInterpreter/Result/Mid1202.cs @@ -28,28 +28,33 @@ public class Mid1202 : Mid, IResult, IController, IAcknowledgeable, IAc public int TotalNumberOfMessages { - get => GetField(1, (int)DataFields.TOTAL_MESSAGES).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.TOTAL_MESSAGES).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.TotalMessages).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.TotalMessages).SetValue(OpenProtocolConvert.ToString, value); } public int MessageNumber { - get => GetField(1, (int)DataFields.MESSAGE_NUMBER).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.MESSAGE_NUMBER).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.MessageNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.MessageNumber).SetValue(OpenProtocolConvert.ToString, value); } - public int ResultDataIdentifier + public long ResultDataIdentifier { - get => GetField(1, (int)DataFields.RESULT_DATA_ID).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.RESULT_DATA_ID).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.ResultDataIdentifier).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.ResultDataIdentifier).SetValue(OpenProtocolConvert.ToString, value); } public int ObjectId { - get => GetField(1, (int)DataFields.OBJECT_ID).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.OBJECT_ID).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.ObjectId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.ObjectId).SetValue(OpenProtocolConvert.ToString, value); + } + public string NodeGuid + { + get => GetField(Header.StandardizedRevision, DataFields.NodeGuid).Value; + set => GetField(Header.StandardizedRevision, DataFields.NodeGuid).SetValue(value); } public int NumberOfDataFields { - get => GetField(1, (int)DataFields.NUMBER_DATA_FIELDS).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.NUMBER_DATA_FIELDS).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(Header.StandardizedRevision, DataFields.NumberOfDataFields).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(Header.StandardizedRevision, DataFields.NumberOfDataFields).SetValue(OpenProtocolConvert.ToString, value); } public List VariableDataFields { get; set; } @@ -64,22 +69,30 @@ public Mid1202() : this(new Header() public Mid1202(Header header) : base(header) { - VariableDataFields = new List(); + VariableDataFields = []; + } + protected override string BuildHeader() + { + Header.Length = 20 + RevisionsByFields[Header.StandardizedRevision].Sum(x => x.TotalSize); + return Header.ToString(); } public override string Pack() { NumberOfDataFields = VariableDataFields.Count; - GetField(1, (int)DataFields.VARIABLE_DATA_FIELDS).SetValue(OpenProtocolConvert.ToString(VariableDataFields)); - return base.Pack(); + var revision = Header.StandardizedRevision; + GetField(revision, DataFields.VariableDataFields).SetValue(OpenProtocolConvert.ToString(VariableDataFields)); + int prefixIndex = 0; + return string.Concat(BuildHeader(), base.Pack(revision, ref prefixIndex)); } public override Mid Parse(string package) { Header = ProcessHeader(package); - var variableDataField = GetField(1, (int)DataFields.VARIABLE_DATA_FIELDS); + var revision = Header.StandardizedRevision; + var variableDataField = GetField(revision, DataFields.VariableDataFields); variableDataField.Size = Header.Length - variableDataField.Index; - ProcessDataFields(package); + ProcessDataFields(revision, package); VariableDataFields = VariableDataField.ParseAll(variableDataField.Value).ToList(); return this; @@ -92,12 +105,24 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.TOTAL_MESSAGES, 20, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.MESSAGE_NUMBER, 23, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.RESULT_DATA_ID, 26, 10, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.OBJECT_ID, 36, 4, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.NUMBER_DATA_FIELDS, 40, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.VARIABLE_DATA_FIELDS, 43, 0, false) //defined at runtime + DataField.Number(DataFields.TotalMessages, 20, 3, false), + DataField.Number(DataFields.MessageNumber, 23, 3, false), + DataField.Number(DataFields.ResultDataIdentifier, 26, 10, false), + DataField.Number(DataFields.ObjectId, 36, 4, false), + DataField.Number(DataFields.NumberOfDataFields, 40, 3, false), + DataField.Volatile(DataFields.VariableDataFields, 43, false) //defined at runtime + } + }, + { + 2, new List() + { + DataField.Number(DataFields.TotalMessages, 20, 3, false), + DataField.Number(DataFields.MessageNumber, 23, 3, false), + DataField.Number(DataFields.ResultDataIdentifier, 26, 10, false), + DataField.Number(DataFields.ObjectId, 36, 4, false), + DataField.String(DataFields.NodeGuid, 40, 36, false), + DataField.Number(DataFields.NumberOfDataFields, 76, 3, false), + DataField.Volatile(DataFields.VariableDataFields, 79, false) //defined at runtime } } }; @@ -105,12 +130,13 @@ protected override Dictionary> RegisterDatafields() protected enum DataFields { - TOTAL_MESSAGES, - MESSAGE_NUMBER, - RESULT_DATA_ID, - OBJECT_ID, - NUMBER_DATA_FIELDS, - VARIABLE_DATA_FIELDS + TotalMessages, + MessageNumber, + ResultDataIdentifier, + ObjectId, + NodeGuid, + NumberOfDataFields, + VariableDataFields } } } diff --git a/src/OpenProtocolInterpreter/Result/ObjectData.cs b/src/OpenProtocolInterpreter/Result/ObjectData.cs index 2a85a31d..b56b75f7 100644 --- a/src/OpenProtocolInterpreter/Result/ObjectData.cs +++ b/src/OpenProtocolInterpreter/Result/ObjectData.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Text; namespace OpenProtocolInterpreter.Result { @@ -9,32 +10,58 @@ public class ObjectData { public int Id { get; set; } public bool Status { get; set; } + public ObjectType ObjectType { get; set; } + public int ReferenceObjectId { get; set; } public string Pack() + => Pack(1); + + public string Pack(int revision) { - string pack = string.Empty; - pack += OpenProtocolConvert.ToString('0', 4, PaddingOrientation.LeftPadded, Id); - pack += OpenProtocolConvert.ToString(Status); - return pack; + var package = OpenProtocolConvert.ToString('0', 4, PaddingOrientation.LeftPadded, Id) + OpenProtocolConvert.ToString(Status); + if(revision > 2) + { + return string.Concat(package, + OpenProtocolConvert.ToString((int)ObjectType), + OpenProtocolConvert.ToString('0', 4, PaddingOrientation.LeftPadded, ReferenceObjectId)); + } + + return package; } public static ObjectData Parse(string value) + => Parse(1, value); + + public static ObjectData Parse(int revision, string value) { - return new ObjectData() + var obj = new ObjectData() { Id = OpenProtocolConvert.ToInt32(value.Substring(0, 4)), Status = OpenProtocolConvert.ToBoolean(value.Substring(4, 1)) }; + + if (revision > 2) + { + obj.ObjectType = (ObjectType)OpenProtocolConvert.ToInt32(value.Substring(5, 1)); + obj.ReferenceObjectId = OpenProtocolConvert.ToInt32(value.Substring(6, 4)); + } + + return obj; } - public static IEnumerable ParseAll(string value) + public static IEnumerable ParseAll(int revision, string value) { - const int sectionSize = 5; + int sectionSize = Size(revision); for (int i = 0; i < value.Length; i += sectionSize) { var section = value.Substring(i, sectionSize); - yield return Parse(section); + yield return Parse(revision, section); } } + + public static IEnumerable ParseAll(string value) + => ParseAll(1, value); + + internal static int Size(int revision) => revision > 2 ? 10 : 5; } } diff --git a/src/OpenProtocolInterpreter/Statistic/Mid0300.cs b/src/OpenProtocolInterpreter/Statistic/Mid0300.cs index c9056087..8eed0132 100644 --- a/src/OpenProtocolInterpreter/Statistic/Mid0300.cs +++ b/src/OpenProtocolInterpreter/Statistic/Mid0300.cs @@ -24,18 +24,18 @@ public class Mid0300 : Mid, IStatistic, IIntegrator, IAnswerableBy, IDe public int ParameterSetId { - get => GetField(1,(int)DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); } public HistogramType HistogramType { - get => (HistogramType)GetField(1,(int)DataFields.HistogramType).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.HistogramType).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (HistogramType)GetField(1, DataFields.HistogramType).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.HistogramType).SetValue(OpenProtocolConvert.ToString, value); } public Mid0300() : this(new Header() { - Mid = MID, + Mid = MID, Revision = DEFAULT_REVISION }) { @@ -52,12 +52,12 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ParameterSetId, 20, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.HistogramType, 25, 2, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.ParameterSetId, 20, 3), + DataField.Number(DataFields.HistogramType, 25, 2) } } }; - } + } protected enum DataFields { diff --git a/src/OpenProtocolInterpreter/Statistic/Mid0301.cs b/src/OpenProtocolInterpreter/Statistic/Mid0301.cs index af8937ea..f6d0c1ac 100644 --- a/src/OpenProtocolInterpreter/Statistic/Mid0301.cs +++ b/src/OpenProtocolInterpreter/Statistic/Mid0301.cs @@ -17,78 +17,78 @@ public class Mid0301 : Mid, IStatistic, IController public int ParameterSetId { - get => GetField(1,(int)DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); } public HistogramType HistogramType { - get => (HistogramType)GetField(1,(int)DataFields.HistogramType).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.HistogramType).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (HistogramType)GetField(1, DataFields.HistogramType).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.HistogramType).SetValue(OpenProtocolConvert.ToString, value); } public decimal SigmaHistogram { - get => GetField(1,(int)DataFields.SigmaHistogram).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(1,(int)DataFields.SigmaHistogram).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(1, DataFields.SigmaHistogram).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(1, DataFields.SigmaHistogram).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal MeanValueHistogram { - get => GetField(1,(int)DataFields.MeanValueHistogram).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(1,(int)DataFields.MeanValueHistogram).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(1, DataFields.MeanValueHistogram).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(1, DataFields.MeanValueHistogram).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal ClassRange { - get => GetField(1,(int)DataFields.ClassRange).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(1,(int)DataFields.ClassRange).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(1, DataFields.ClassRange).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(1, DataFields.ClassRange).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public int FirstBar { - get => GetField(1,(int)DataFields.Bar1).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.Bar1).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Bar1).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.Bar1).SetValue(OpenProtocolConvert.ToString, value); } public int SecondBar { - get => GetField(1,(int)DataFields.Bar2).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.Bar2).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Bar2).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.Bar2).SetValue(OpenProtocolConvert.ToString, value); } public int ThirdBar { - get => GetField(1,(int)DataFields.Bar3).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.Bar3).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Bar3).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.Bar3).SetValue(OpenProtocolConvert.ToString, value); } public int FourthBar { - get => GetField(1,(int)DataFields.Bar4).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.Bar4).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Bar4).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.Bar4).SetValue(OpenProtocolConvert.ToString, value); } public int FifthBar { - get => GetField(1,(int)DataFields.Bar5).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.Bar5).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Bar5).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.Bar5).SetValue(OpenProtocolConvert.ToString, value); } public int SixthBar { - get => GetField(1,(int)DataFields.Bar6).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.Bar6).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Bar6).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.Bar6).SetValue(OpenProtocolConvert.ToString, value); } public int SeventhBar { - get => GetField(1,(int)DataFields.Bar7).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.Bar7).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Bar7).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.Bar7).SetValue(OpenProtocolConvert.ToString, value); } public int EighthBar { - get => GetField(1,(int)DataFields.Bar8).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.Bar8).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Bar8).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.Bar8).SetValue(OpenProtocolConvert.ToString, value); } public int NinethBar { - get => GetField(1,(int)DataFields.Bar9).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.Bar9).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Bar9).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.Bar9).SetValue(OpenProtocolConvert.ToString, value); } public Mid0301() : this(new Header() { - Mid = MID, + Mid = MID, Revision = DEFAULT_REVISION }) { @@ -105,20 +105,20 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ParameterSetId, 20, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.HistogramType, 25, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.SigmaHistogram, 29, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.MeanValueHistogram, 37, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ClassRange, 45, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Bar1, 53, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Bar2, 59, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Bar3, 65, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Bar4, 71, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Bar5, 77, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Bar6, 83, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Bar7, 89, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Bar8, 95, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Bar9, 101, 4, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.ParameterSetId, 20, 3), + DataField.Number(DataFields.HistogramType, 25, 2), + DataField.Number(DataFields.SigmaHistogram, 29, 6), + DataField.Number(DataFields.MeanValueHistogram, 37, 6), + DataField.Number(DataFields.ClassRange, 45, 6), + DataField.Number(DataFields.Bar1, 53, 4), + DataField.Number(DataFields.Bar2, 59, 4), + DataField.Number(DataFields.Bar3, 65, 4), + DataField.Number(DataFields.Bar4, 71, 4), + DataField.Number(DataFields.Bar5, 77, 4), + DataField.Number(DataFields.Bar6, 83, 4), + DataField.Number(DataFields.Bar7, 89, 4), + DataField.Number(DataFields.Bar8, 95, 4), + DataField.Number(DataFields.Bar9, 101, 4) } } }; diff --git a/src/OpenProtocolInterpreter/Tightening/Mid0061.cs b/src/OpenProtocolInterpreter/Tightening/Mid0061.cs index 98e4b977..50f02f32 100644 --- a/src/OpenProtocolInterpreter/Tightening/Mid0061.cs +++ b/src/OpenProtocolInterpreter/Tightening/Mid0061.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; namespace OpenProtocolInterpreter.Tightening { @@ -16,314 +17,392 @@ public class Mid0061 : Mid, ITightening, IController, IAcknowledgeable public int CellId { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.CellId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.CellId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.CellId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.CellId).SetValue(OpenProtocolConvert.ToString, value); } public int ChannelId { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.ChannelId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.ChannelId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.ChannelId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.ChannelId).SetValue(OpenProtocolConvert.ToString, value); } public string TorqueControllerName { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.TorqueControllerName).Value; - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.TorqueControllerName).SetValue(value); + get => GetField(GetCurrentRevisionIndex(), DataFields.TorqueControllerName).Value; + set => GetField(GetCurrentRevisionIndex(), DataFields.TorqueControllerName).SetValue(value); } public string VinNumber { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.VinNumber).Value; - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.VinNumber).SetValue(value); + get => GetField(GetCurrentRevisionIndex(), DataFields.VinNumber).Value; + set => GetField(GetCurrentRevisionIndex(), DataFields.VinNumber).SetValue(value); } public int JobId { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); } public int ParameterSetId { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); } public int BatchSize { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.BatchSize).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.BatchSize).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.BatchSize).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.BatchSize).SetValue(OpenProtocolConvert.ToString, value); } public int BatchCounter { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.BatchCounter).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.BatchCounter).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.BatchCounter).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.BatchCounter).SetValue(OpenProtocolConvert.ToString, value); } public bool TighteningStatus { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.TighteningStatus).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.TighteningStatus).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.TighteningStatus).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(GetCurrentRevisionIndex(), DataFields.TighteningStatus).SetValue(OpenProtocolConvert.ToString, value); } public TighteningValueStatus TorqueStatus { - get => (TighteningValueStatus)GetField(GetCurrentRevisionIndex(), (int)DataFields.TorqueStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.TorqueStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (TighteningValueStatus)GetField(GetCurrentRevisionIndex(), DataFields.TorqueStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.TorqueStatus).SetValue(OpenProtocolConvert.ToString, value); } public TighteningValueStatus AngleStatus { - get => (TighteningValueStatus)GetField(GetCurrentRevisionIndex(), (int)DataFields.AngleStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.AngleStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (TighteningValueStatus)GetField(GetCurrentRevisionIndex(), DataFields.AngleStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.AngleStatus).SetValue(OpenProtocolConvert.ToString, value); } public decimal TorqueMinLimit { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.TorqueMinLimit).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.TorqueMinLimit).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.TorqueMinLimit).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(GetCurrentRevisionIndex(), DataFields.TorqueMinLimit).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal TorqueMaxLimit { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.TorqueMaxLimit).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.TorqueMaxLimit).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.TorqueMaxLimit).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(GetCurrentRevisionIndex(), DataFields.TorqueMaxLimit).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal TorqueFinalTarget { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.TorqueFinalTarget).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.TorqueFinalTarget).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.TorqueFinalTarget).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(GetCurrentRevisionIndex(), DataFields.TorqueFinalTarget).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal Torque { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.Torque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.Torque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.Torque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(GetCurrentRevisionIndex(), DataFields.Torque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public int AngleMinLimit { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.AngleMinLimit).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.AngleMinLimit).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.AngleMinLimit).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.AngleMinLimit).SetValue(OpenProtocolConvert.ToString, value); } public int AngleMaxLimit { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.AngleMaxLimit).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.AngleMaxLimit).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.AngleMaxLimit).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.AngleMaxLimit).SetValue(OpenProtocolConvert.ToString, value); } public int AngleFinalTarget { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.AngleFinalTarget).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.AngleFinalTarget).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.AngleFinalTarget).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.AngleFinalTarget).SetValue(OpenProtocolConvert.ToString, value); } public int Angle { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.Angle).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.Angle).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.Angle).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.Angle).SetValue(OpenProtocolConvert.ToString, value); } public DateTime Timestamp { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.Timestamp).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.Timestamp).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.Timestamp).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(GetCurrentRevisionIndex(), DataFields.Timestamp).SetValue(OpenProtocolConvert.ToString, value); } public DateTime LastChangeInParameterSet { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.LastChangeInParameterSet).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.LastChangeInParameterSet).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.LastChangeInParameterSet).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(GetCurrentRevisionIndex(), DataFields.LastChangeInParameterSet).SetValue(OpenProtocolConvert.ToString, value); } public BatchStatus BatchStatus { - get => (BatchStatus)GetField(GetCurrentRevisionIndex(), (int)DataFields.BatchStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.BatchStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (BatchStatus)GetField(GetCurrentRevisionIndex(), DataFields.BatchStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.BatchStatus).SetValue(OpenProtocolConvert.ToString, value); } public long TighteningId { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.TighteningId).GetValue(OpenProtocolConvert.ToInt64); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.TighteningId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.TighteningId).GetValue(OpenProtocolConvert.ToInt64); + set => GetField(GetCurrentRevisionIndex(), DataFields.TighteningId).SetValue(OpenProtocolConvert.ToString, value); } //Rev 2 Addition public Strategy Strategy { - get => (Strategy)GetField(2, (int)DataFields.Strategy).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.Strategy).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (Strategy)GetField(2, DataFields.Strategy).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.Strategy).SetValue(OpenProtocolConvert.ToString, value); } public StrategyOptions StrategyOptions { get; set; } public TighteningValueStatus RundownAngleStatus { - get => (TighteningValueStatus)GetField(2, (int)DataFields.RundownAngleStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.RundownAngleStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (TighteningValueStatus)GetField(2, DataFields.RundownAngleStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.RundownAngleStatus).SetValue(OpenProtocolConvert.ToString, value); } public TighteningValueStatus CurrentMonitoringStatus { - get => (TighteningValueStatus)GetField(2, (int)DataFields.CurrentMonitoringStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.CurrentMonitoringStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (TighteningValueStatus)GetField(2, DataFields.CurrentMonitoringStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.CurrentMonitoringStatus).SetValue(OpenProtocolConvert.ToString, value); } public TighteningValueStatus SelftapStatus { - get => (TighteningValueStatus)GetField(2, (int)DataFields.SelftapStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.SelftapStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (TighteningValueStatus)GetField(2, DataFields.SelftapStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.SelftapStatus).SetValue(OpenProtocolConvert.ToString, value); } public TighteningValueStatus PrevailTorqueMonitoringStatus { - get => (TighteningValueStatus)GetField(2, (int)DataFields.PrevailTorqueMonitoringStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.PrevailTorqueMonitoringStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (TighteningValueStatus)GetField(2, DataFields.PrevailTorqueMonitoringStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.PrevailTorqueMonitoringStatus).SetValue(OpenProtocolConvert.ToString, value); } public TighteningValueStatus PrevailTorqueCompensateStatus { - get => (TighteningValueStatus)GetField(2, (int)DataFields.PrevailTorqueCompensateStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.PrevailTorqueCompensateStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (TighteningValueStatus)GetField(2, DataFields.PrevailTorqueCompensateStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.PrevailTorqueCompensateStatus).SetValue(OpenProtocolConvert.ToString, value); } public TighteningErrorStatus TighteningErrorStatus { get; set; } public int RundownAngleMin { - get => GetField(2, (int)DataFields.RundownAngleMin).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.RundownAngleMin).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.RundownAngleMin).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.RundownAngleMin).SetValue(OpenProtocolConvert.ToString, value); } public int RundownAngleMax { - get => GetField(2, (int)DataFields.RundownAngleMax).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.RundownAngleMax).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.RundownAngleMax).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.RundownAngleMax).SetValue(OpenProtocolConvert.ToString, value); } public int RundownAngle { - get => GetField(2, (int)DataFields.RundownAngle).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.RundownAngle).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.RundownAngle).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.RundownAngle).SetValue(OpenProtocolConvert.ToString, value); } public int CurrentMonitoringMin { - get => GetField(2, (int)DataFields.CurrentMonitoringMin).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.CurrentMonitoringMin).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.CurrentMonitoringMin).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.CurrentMonitoringMin).SetValue(OpenProtocolConvert.ToString, value); } public int CurrentMonitoringMax { - get => GetField(2, (int)DataFields.CurrentMonitoringMax).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.CurrentMonitoringMax).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.CurrentMonitoringMax).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.CurrentMonitoringMax).SetValue(OpenProtocolConvert.ToString, value); } public int CurrentMonitoringValue { - get => GetField(2, (int)DataFields.CurrentMonitoringValue).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.CurrentMonitoringValue).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.CurrentMonitoringValue).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.CurrentMonitoringValue).SetValue(OpenProtocolConvert.ToString, value); } public decimal SelftapMin { - get => GetField(2, (int)DataFields.SelftapMin).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(2, (int)DataFields.SelftapMin).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(2, DataFields.SelftapMin).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(2, DataFields.SelftapMin).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal SelftapMax { - get => GetField(2, (int)DataFields.SelftapMax).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(2, (int)DataFields.SelftapMax).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(2, DataFields.SelftapMax).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(2, DataFields.SelftapMax).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal SelftapTorque { - get => GetField(2, (int)DataFields.SelftapTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(2, (int)DataFields.SelftapTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(2, DataFields.SelftapTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(2, DataFields.SelftapTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal PrevailTorqueMonitoringMin { - get => GetField(2, (int)DataFields.PrevailTorqueMonitoringMin).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(2, (int)DataFields.PrevailTorqueMonitoringMin).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(2, DataFields.PrevailTorqueMonitoringMin).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(2, DataFields.PrevailTorqueMonitoringMin).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal PrevailTorqueMonitoringMax { - get => GetField(2, (int)DataFields.PrevailTorqueMonitoringMax).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(2, (int)DataFields.PrevailTorqueMonitoringMax).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(2, DataFields.PrevailTorqueMonitoringMax).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(2, DataFields.PrevailTorqueMonitoringMax).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal PrevailTorque { - get => GetField(2, (int)DataFields.PrevailTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(2, (int)DataFields.PrevailTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(2, DataFields.PrevailTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(2, DataFields.PrevailTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public int JobSequenceNumber { - get => GetField(2, (int)DataFields.JobSequenceNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.JobSequenceNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.JobSequenceNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.JobSequenceNumber).SetValue(OpenProtocolConvert.ToString, value); } public int SyncTighteningId { - get => GetField(2, (int)DataFields.SyncTighteningId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.SyncTighteningId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.SyncTighteningId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.SyncTighteningId).SetValue(OpenProtocolConvert.ToString, value); } public string ToolSerialNumber { - get => GetField(2, (int)DataFields.ToolSerialNumber).Value; - set => GetField(2, (int)DataFields.ToolSerialNumber).SetValue(value); + get => GetField(2, DataFields.ToolSerialNumber).Value; + set => GetField(2, DataFields.ToolSerialNumber).SetValue(value); } //Rev 3 Addition public string ParameterSetName { - get => GetField(3, (int)DataFields.ParameterSetName).Value; - set => GetField(3, (int)DataFields.ParameterSetName).SetValue(value); + get => GetField(3, DataFields.ParameterSetName).Value; + set => GetField(3, DataFields.ParameterSetName).SetValue(value); } public TorqueValuesUnit TorqueValuesUnit { - get => (TorqueValuesUnit)GetField(3, (int)DataFields.TorqueValuesUnit).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(3, (int)DataFields.TorqueValuesUnit).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (TorqueValuesUnit)GetField(3, DataFields.TorqueValuesUnit).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(3, DataFields.TorqueValuesUnit).SetValue(OpenProtocolConvert.ToString, value); } public ResultType ResultType { - get => (ResultType)GetField(3, (int)DataFields.ResultType).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(3, (int)DataFields.ResultType).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (ResultType)GetField(3, DataFields.ResultType).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(3, DataFields.ResultType).SetValue(OpenProtocolConvert.ToString, value); } //Rev 4 addition public string IdentifierResultPart2 { - get => GetField(4, (int)DataFields.IdentifierResultPart2).Value; - set => GetField(4, (int)DataFields.IdentifierResultPart2).SetValue(value); + get => GetField(4, DataFields.IdentifierResultPart2).Value; + set => GetField(4, DataFields.IdentifierResultPart2).SetValue(value); } public string IdentifierResultPart3 { - get => GetField(4, (int)DataFields.IdentifierResultPart3).Value; - set => GetField(4, (int)DataFields.IdentifierResultPart3).SetValue(value); + get => GetField(4, DataFields.IdentifierResultPart3).Value; + set => GetField(4, DataFields.IdentifierResultPart3).SetValue(value); } public string IdentifierResultPart4 { - get => GetField(4, (int)DataFields.IdentifierResultPart4).Value; - set => GetField(4, (int)DataFields.IdentifierResultPart4).SetValue(value); + get => GetField(4, DataFields.IdentifierResultPart4).Value; + set => GetField(4, DataFields.IdentifierResultPart4).SetValue(value); } //Rev 5 addition public string CustomerTighteningErrorCode { - get => GetField(5, (int)DataFields.CustomerTighteningErrorCode).Value; - set => GetField(5, (int)DataFields.CustomerTighteningErrorCode).SetValue(value); + get => GetField(5, DataFields.CustomerTighteningErrorCode).Value; + set => GetField(5, DataFields.CustomerTighteningErrorCode).SetValue(value); } //Rev 6 Addition public decimal PrevailTorqueCompensateValue { - get => GetField(6, (int)DataFields.PrevailTorqueCompensateValue).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(6, (int)DataFields.PrevailTorqueCompensateValue).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(6, DataFields.PrevailTorqueCompensateValue).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(6, DataFields.PrevailTorqueCompensateValue).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public TighteningErrorStatus2 TighteningErrorStatus2 { get; set; } //Rev 7 addition public decimal CompensatedAngle { - get => GetField(7, (int)DataFields.CompensatedAngle).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(7, (int)DataFields.CompensatedAngle).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(7, DataFields.CompensatedAngle).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(7, DataFields.CompensatedAngle).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal FinalAngleDecimal { - get => GetField(7, (int)DataFields.FinalAngleDecimal).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(7, (int)DataFields.FinalAngleDecimal).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(7, DataFields.FinalAngleDecimal).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(7, DataFields.FinalAngleDecimal).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } //Rev 8 addition public decimal StartFinalAngle { - get => GetField(8, (int)DataFields.StartFinalAngle).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(8, (int)DataFields.StartFinalAngle).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(8, DataFields.StartFinalAngle).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(8, DataFields.StartFinalAngle).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public PostViewTorque PostViewTorqueActivated { - get => (PostViewTorque)GetField(8, (int)DataFields.PostViewTorqueActivated).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(8, (int)DataFields.PostViewTorqueActivated).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (PostViewTorque)GetField(8, DataFields.PostViewTorqueActivated).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(8, DataFields.PostViewTorqueActivated).SetValue(OpenProtocolConvert.ToString, value); } public decimal PostViewTorqueHigh { - get => GetField(8, (int)DataFields.PostViewTorqueHigh).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(8, (int)DataFields.PostViewTorqueHigh).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(8, DataFields.PostViewTorqueHigh).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(8, DataFields.PostViewTorqueHigh).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal PostViewTorqueLow { - get => GetField(8, (int)DataFields.PostViewTorqueLow).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(8, (int)DataFields.PostViewTorqueLow).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(8, DataFields.PostViewTorqueLow).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(8, DataFields.PostViewTorqueLow).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } - //Rev 998 addition + //Rev 9 addition + public decimal CurrentMonitoringAmpere + { + get => GetField(9, DataFields.CurrentMonitoringAmp).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(9, DataFields.CurrentMonitoringAmp).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + } + public decimal CurrentMonitoringAmpereMin + { + get => GetField(9, DataFields.CurrentMonitoringAmpMin).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(9, DataFields.CurrentMonitoringAmpMin).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + } + public decimal CurrentMonitoringAmpereMax + { + get => GetField(9, DataFields.CurrentMonitoringAmpMax).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(9, DataFields.CurrentMonitoringAmpMax).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + } + //Rev 10 addition + public int AngleNumeratorScaleFactor + { + get => GetField(10, DataFields.AngleNumeratorScaleFactor).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(10, DataFields.AngleNumeratorScaleFactor).SetValue(OpenProtocolConvert.ToString, value); + } + public int AngleDenominatorScaleFactor + { + get => GetField(10, DataFields.AngleDenominatorScaleFactor).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(10, DataFields.AngleDenominatorScaleFactor).SetValue(OpenProtocolConvert.ToString, value); + } + public TighteningValueStatus OverallAngleStatus + { + get => (TighteningValueStatus)GetField(10, DataFields.OverallAngleStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(10, DataFields.OverallAngleStatus).SetValue(OpenProtocolConvert.ToString, value); + } + public int OverallAngleMin + { + get => GetField(10, DataFields.OverallAngleMin).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(10, DataFields.OverallAngleMin).SetValue(OpenProtocolConvert.ToString, value); + } + public int OverallAngleMax + { + get => GetField(10, DataFields.OverallAngleMax).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(10, DataFields.OverallAngleMax).SetValue(OpenProtocolConvert.ToString, value); + } + public int OverallAngle + { + get => GetField(10, DataFields.OverallAngle).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(10, DataFields.OverallAngle).SetValue(OpenProtocolConvert.ToString, value); + } + public decimal PeakTorque + { + get => GetField(10, DataFields.PeakTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(10, DataFields.PeakTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + } + public decimal ResidualBreakawayTorque + { + get => GetField(10, DataFields.ResidualBreakawayTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(10, DataFields.ResidualBreakawayTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + } + public decimal StartRundownAngle + { + get => GetField(10, DataFields.StartRundownAngle).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(10, DataFields.StartRundownAngle).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + } + public decimal RundownAngleComplete + { + get => GetField(10, DataFields.RundownAngleComplete).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(10, DataFields.RundownAngleComplete).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + } + //Rev 11 + public decimal ClickTorque + { + get => GetField(11, DataFields.ClickTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(11, DataFields.ClickTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + } + public int ClickAngle + { + get => GetField(11, DataFields.ClickAngle).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(11, DataFields.ClickAngle).SetValue(OpenProtocolConvert.ToString, value); + } + //Rev 998 addition public int NumberOfStagesInMultistage { - get => GetField(998, (int)DataFields.NumberOfStagesInMultistage).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(998, (int)DataFields.NumberOfStagesInMultistage).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(998, DataFields.NumberOfStagesInMultistage).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(998, DataFields.NumberOfStagesInMultistage).SetValue(OpenProtocolConvert.ToString, value); } public int NumberOfStageResults { - get => GetField(998, (int)DataFields.NumberOfStageResults).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(998, (int)DataFields.NumberOfStageResults).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(998, DataFields.NumberOfStageResults).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(998, DataFields.NumberOfStageResults).SetValue(OpenProtocolConvert.ToString, value); } public List StageResults { get; set; } @@ -338,7 +417,7 @@ public Mid0061(Header header) : base(header) public Mid0061(int revision) : this(new Header() { - Mid = MID, + Mid = MID, Revision = revision }) { @@ -365,7 +444,7 @@ protected override string BuildHeader() if (Header.Revision == 998) { - GetField(998, (int)DataFields.StageResult).Size = StageResults.Count * 11; + GetField(998, DataFields.StageResult).Size = StageResults.Count * 11; foreach (var dataField in RevisionsByFields[998]) Header.Length += (dataField.HasPrefix ? 2 : 0) + dataField.Size; } @@ -376,77 +455,77 @@ protected override string BuildHeader() public override string Pack() { - string package = string.Empty; + var builder = new StringBuilder(); int prefixIndex = 1; if (Header.Revision > 1 && Header.Revision != 999) { - GetField(2, (int)DataFields.StrategyOptions).SetValue(StrategyOptions.Pack()); - GetField(2, (int)DataFields.TighteningErrorStatus).SetValue(TighteningErrorStatus.Pack()); + GetField(2, DataFields.StrategyOptions).SetValue(StrategyOptions.Pack()); + GetField(2, DataFields.TighteningErrorStatus).SetValue(TighteningErrorStatus.Pack()); if (Header.Revision > 5) { - GetField(6, (int)DataFields.TighteningErrorStatus2).SetValue(TighteningErrorStatus2.Pack()); + GetField(6, DataFields.TighteningErrorStatus2).SetValue(TighteningErrorStatus2.Pack()); } if (Header.Revision == 998) { NumberOfStageResults = StageResults.Count; - var stageResultField = GetField(998, (int)DataFields.StageResult); + var stageResultField = GetField(998, DataFields.StageResult); stageResultField.Size = StageResults.Count * 11; stageResultField.SetValue(PackStageResults()); } - package = BuildHeader(); - int processUntil = Header.Revision != 998 ? Header.Revision : 6; - for (int i = 2; i <= processUntil; i++) + builder.Append(BuildHeader()); + int processUntilRevision = Header.Revision != 998 ? Header.Revision : 6; + for (int revision = 2; revision <= processUntilRevision; revision++) { - package += Pack(RevisionsByFields[i], ref prefixIndex); + builder.Append(Pack(revision, ref prefixIndex)); } if (Header.Revision == 998) { - package += Pack(RevisionsByFields[998], ref prefixIndex); + builder.Append(Pack(998, ref prefixIndex)); } } else { - package = BuildHeader(); - package += Pack(RevisionsByFields[Header.Revision], ref prefixIndex); + builder.Append(BuildHeader()); + builder.Append(Pack(Header.Revision, ref prefixIndex)); } - return package; + return builder.ToString(); } protected override void ProcessDataFields(string package) { if (Header.Revision == 1 || Header.Revision == 999) { - ProcessDataFields(RevisionsByFields[Header.Revision], package); + ProcessDataFields(Header.Revision, package); } else { - int processUntil = Header.Revision; + int processUntilRevision = Header.Revision; if (Header.Revision == 998) { - processUntil = 6; - var stageResultField = GetField(998, (int)DataFields.StageResult); + processUntilRevision = 6; + var stageResultField = GetField(998, DataFields.StageResult); stageResultField.Size = Header.Length - stageResultField.Index - 2; - ProcessDataFields(RevisionsByFields[998], package); + ProcessDataFields(998, package); StageResults = StageResult.ParseAll(stageResultField.Value).ToList(); } - for (int i = 2; i <= processUntil; i++) - ProcessDataFields(RevisionsByFields[i], package); + for (int revision = 2; revision <= processUntilRevision; revision++) + ProcessDataFields(revision, package); - var strategyOptionsField = GetField(2, (int)DataFields.StrategyOptions); + var strategyOptionsField = GetField(2, DataFields.StrategyOptions); StrategyOptions = StrategyOptions.Parse(strategyOptionsField.Value); - var tighteningErrorStatusField = GetField(2, (int)DataFields.TighteningErrorStatus); + var tighteningErrorStatusField = GetField(2, DataFields.TighteningErrorStatus); TighteningErrorStatus = TighteningErrorStatus.Parse(tighteningErrorStatusField.Value); if (Header.Revision > 5) { - var tighteningErrorStatus2Field = GetField(6, (int)DataFields.TighteningErrorStatus2); + var tighteningErrorStatus2Field = GetField(6, DataFields.TighteningErrorStatus2); TighteningErrorStatus2 = TighteningErrorStatus2.Parse(tighteningErrorStatus2Field.Value); } } @@ -454,13 +533,13 @@ protected override void ProcessDataFields(string package) protected virtual string PackStageResults() { - string pack = string.Empty; + var builder = new StringBuilder(); foreach (var v in StageResults) { - pack += v.Pack(); + builder.Append(v.Pack()); } - return pack; + return builder.ToString(); } protected override Dictionary> RegisterDatafields() @@ -471,152 +550,182 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.CellId, 20, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ChannelId, 26, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TorqueControllerName, 30, 25, ' '), - new DataField((int)DataFields.VinNumber, 57, 25, ' '), - new DataField((int)DataFields.JobId, 84, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ParameterSetId, 88, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.BatchSize, 93, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.BatchCounter, 99, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TighteningStatus, 105, 1), - new DataField((int)DataFields.TorqueStatus, 108, 1), - new DataField((int)DataFields.AngleStatus, 111, 1), - new DataField((int)DataFields.TorqueMinLimit, 114, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TorqueMaxLimit, 122, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TorqueFinalTarget, 130, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Torque, 138, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.AngleMinLimit, 146, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.AngleMaxLimit, 153, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.AngleFinalTarget, 160, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Angle, 167, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Timestamp, 174, 19), - new DataField((int)DataFields.LastChangeInParameterSet, 195, 19), - new DataField((int)DataFields.BatchStatus, 216, 1), - new DataField((int)DataFields.TighteningId, 219, 10, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.CellId, 20, 4), + DataField.Number(DataFields.ChannelId, 26, 2), + DataField.String(DataFields.TorqueControllerName, 30, 25), + DataField.String(DataFields.VinNumber, 57, 25), + DataField.Number(DataFields.JobId, 84, 2), + DataField.Number(DataFields.ParameterSetId, 88, 3), + DataField.Number(DataFields.BatchSize, 93, 4), + DataField.Number(DataFields.BatchCounter, 99, 4), + DataField.Number(DataFields.TighteningStatus, 105, 1), + DataField.Number(DataFields.TorqueStatus, 108, 1), + DataField.Number(DataFields.AngleStatus, 111, 1), + DataField.Number(DataFields.TorqueMinLimit, 114, 6), + DataField.Number(DataFields.TorqueMaxLimit, 122, 6), + DataField.Number(DataFields.TorqueFinalTarget, 130, 6), + DataField.Number(DataFields.Torque, 138, 6), + DataField.Number(DataFields.AngleMinLimit, 146, 5), + DataField.Number(DataFields.AngleMaxLimit, 153, 5), + DataField.Number(DataFields.AngleFinalTarget, 160, 5), + DataField.Number(DataFields.Angle, 167, 5), + DataField.Timestamp(DataFields.Timestamp, 174), + DataField.Timestamp(DataFields.LastChangeInParameterSet, 195), + DataField.Number(DataFields.BatchStatus, 216, 1), + DataField.Number(DataFields.TighteningId, 219, 10) } }, { 2, new List() { - new DataField((int)DataFields.CellId, 20, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ChannelId, 26, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TorqueControllerName, 30, 25, ' '), - new DataField((int)DataFields.VinNumber, 57, 25, ' '), - new DataField((int)DataFields.JobId, 84, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ParameterSetId, 90, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Strategy, 95, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.StrategyOptions, 99, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.BatchSize, 106, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.BatchCounter, 112, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TighteningStatus, 118, 1), - new DataField((int)DataFields.BatchStatus, 121, 1), - new DataField((int)DataFields.TorqueStatus, 124, 1), - new DataField((int)DataFields.AngleStatus, 127, 1), - new DataField((int)DataFields.RundownAngleStatus, 130, 1), - new DataField((int)DataFields.CurrentMonitoringStatus, 133, 1), - new DataField((int)DataFields.SelftapStatus, 136, 1), - new DataField((int)DataFields.PrevailTorqueMonitoringStatus, 139, 1), - new DataField((int)DataFields.PrevailTorqueCompensateStatus, 142, 1), - new DataField((int)DataFields.TighteningErrorStatus, 145, 10, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TorqueMinLimit, 157, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TorqueMaxLimit, 165, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TorqueFinalTarget, 173, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Torque, 181, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.AngleMinLimit, 189, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.AngleMaxLimit, 196, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.AngleFinalTarget, 203, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Angle, 210, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.RundownAngleMin, 217, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.RundownAngleMax, 224, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.RundownAngle, 231, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.CurrentMonitoringMin, 238, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.CurrentMonitoringMax, 243, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.CurrentMonitoringValue, 248, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.SelftapMin, 253, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.SelftapMax, 261, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.SelftapTorque, 269, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.PrevailTorqueMonitoringMin, 277, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.PrevailTorqueMonitoringMax, 285, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.PrevailTorque, 293, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TighteningId, 301, 10, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.JobSequenceNumber, 313, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.SyncTighteningId, 320, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ToolSerialNumber, 327, 14, ' '), - new DataField((int)DataFields.Timestamp, 343, 19), - new DataField((int)DataFields.LastChangeInParameterSet, 364, 19) + DataField.Number(DataFields.CellId, 20, 4), + DataField.Number(DataFields.ChannelId, 26, 2), + DataField.String(DataFields.TorqueControllerName, 30, 25), + DataField.String(DataFields.VinNumber, 57, 25), + DataField.Number(DataFields.JobId, 84, 4), + DataField.Number(DataFields.ParameterSetId, 90, 3), + DataField.Number(DataFields.Strategy, 95, 2), + new(DataFields.StrategyOptions, 99, 5, '0', PaddingOrientation.LeftPadded), + DataField.Number(DataFields.BatchSize, 106, 4), + DataField.Number(DataFields.BatchCounter, 112, 4), + DataField.Number(DataFields.TighteningStatus, 118, 1), + DataField.Number(DataFields.BatchStatus, 121, 1), + DataField.Number(DataFields.TorqueStatus, 124, 1), + DataField.Number(DataFields.AngleStatus, 127, 1), + DataField.Number(DataFields.RundownAngleStatus, 130, 1), + DataField.Number(DataFields.CurrentMonitoringStatus, 133, 1), + DataField.Number(DataFields.SelftapStatus, 136, 1), + DataField.Number(DataFields.PrevailTorqueMonitoringStatus, 139, 1), + DataField.Number(DataFields.PrevailTorqueCompensateStatus, 142, 1), + new(DataFields.TighteningErrorStatus, 145, 10, '0', PaddingOrientation.LeftPadded), + DataField.Number(DataFields.TorqueMinLimit, 157, 6), + DataField.Number(DataFields.TorqueMaxLimit, 165, 6), + DataField.Number(DataFields.TorqueFinalTarget, 173, 6), + DataField.Number(DataFields.Torque, 181, 6), + DataField.Number(DataFields.AngleMinLimit, 189, 5), + DataField.Number(DataFields.AngleMaxLimit, 196, 5), + DataField.Number(DataFields.AngleFinalTarget, 203, 5), + DataField.Number(DataFields.Angle, 210, 5), + DataField.Number(DataFields.RundownAngleMin, 217, 5), + DataField.Number(DataFields.RundownAngleMax, 224, 5), + DataField.Number(DataFields.RundownAngle, 231, 5), + DataField.Number(DataFields.CurrentMonitoringMin, 238, 3), + DataField.Number(DataFields.CurrentMonitoringMax, 243, 3), + DataField.Number(DataFields.CurrentMonitoringValue, 248, 3), + DataField.Number(DataFields.SelftapMin, 253, 6), + DataField.Number(DataFields.SelftapMax, 261, 6 ), + DataField.Number(DataFields.SelftapTorque, 269, 6), + DataField.Number(DataFields.PrevailTorqueMonitoringMin, 277, 6), + DataField.Number(DataFields.PrevailTorqueMonitoringMax, 285, 6), + DataField.Number(DataFields.PrevailTorque, 293, 6), + DataField.Number(DataFields.TighteningId, 301, 10), + DataField.Number(DataFields.JobSequenceNumber, 313, 5), + DataField.Number(DataFields.SyncTighteningId, 320, 5), + DataField.String(DataFields.ToolSerialNumber, 327, 14), + DataField.Timestamp(DataFields.Timestamp, 343), + DataField.Timestamp(DataFields.LastChangeInParameterSet, 364) } }, { 3, new List() { - new DataField((int)DataFields.ParameterSetName, 385, 25, ' '), - new DataField((int)DataFields.TorqueValuesUnit, 412, 1), - new DataField((int)DataFields.ResultType, 415, 2, '0', PaddingOrientation.LeftPadded) + DataField.String(DataFields.ParameterSetName, 385, 25), + DataField.Number(DataFields.TorqueValuesUnit, 412, 1), + DataField.Number(DataFields.ResultType, 415, 2) } }, { 4, new List() { - new DataField((int)DataFields.IdentifierResultPart2, 419, 25, ' '), - new DataField((int)DataFields.IdentifierResultPart3, 446, 25, ' '), - new DataField((int)DataFields.IdentifierResultPart4, 473, 25, ' ') + DataField.String(DataFields.IdentifierResultPart2, 419, 25), + DataField.String(DataFields.IdentifierResultPart3, 446, 25), + DataField.String(DataFields.IdentifierResultPart4, 473, 25) } }, { 5, new List() { - new DataField((int)DataFields.CustomerTighteningErrorCode, 500, 4, ' '), + DataField.String(DataFields.CustomerTighteningErrorCode, 500, 4) } }, { 6, new List() { - new DataField((int)DataFields.PrevailTorqueCompensateValue, 506, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TighteningErrorStatus2, 514, 10, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.PrevailTorqueCompensateValue, 506, 6), + new(DataFields.TighteningErrorStatus2, 514, 10, '0', PaddingOrientation.LeftPadded) } }, { 7, new List() { - new DataField((int)DataFields.CompensatedAngle, 526, 7, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.FinalAngleDecimal, 535, 7, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.CompensatedAngle, 526, 7), + DataField.Number(DataFields.FinalAngleDecimal, 535, 7) } }, { 8, new List() { - new DataField((int)DataFields.StartFinalAngle, 544, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.PostViewTorqueActivated, 552, 1), - new DataField((int)DataFields.PostViewTorqueHigh, 555, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.PostViewTorqueLow, 563, 6, '0', PaddingOrientation.LeftPadded), + DataField.Number(DataFields.StartFinalAngle, 544, 6), + DataField.Number(DataFields.PostViewTorqueActivated, 552, 1), + DataField.Number(DataFields.PostViewTorqueHigh, 555, 6), + DataField.Number(DataFields.PostViewTorqueLow, 563, 6) + } + }, + { + 9, new List() + { + DataField.Number(DataFields.CurrentMonitoringAmp, 571, 5), + DataField.Number(DataFields.CurrentMonitoringAmpMin, 578, 5), + DataField.Number(DataFields.CurrentMonitoringAmpMax, 585, 5) + } + }, + { + 10, new List() + { + DataField.Number(DataFields.AngleNumeratorScaleFactor, 592, 5), + DataField.Number(DataFields.AngleDenominatorScaleFactor, 599, 5), + DataField.Number(DataFields.OverallAngleStatus, 606, 1), + DataField.Number(DataFields.OverallAngleMin, 609, 5), + DataField.Number(DataFields.OverallAngleMax, 616, 5), + DataField.Number(DataFields.OverallAngle, 623, 5), + DataField.Number(DataFields.PeakTorque, 630, 6), + DataField.Number(DataFields.ResidualBreakawayTorque, 638, 6), + DataField.Number(DataFields.StartRundownAngle, 646, 6), + DataField.Number(DataFields.RundownAngleComplete, 654, 6) + } + }, + { + 11, new List() + { + DataField.Number(DataFields.ClickTorque, 662, 6), + DataField.Number(DataFields.ClickAngle, 670, 5), } }, { 998, new List() { - new DataField((int)DataFields.NumberOfStagesInMultistage, 526, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.NumberOfStageResults, 530, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.StageResult, 534, 11) + DataField.Number(DataFields.NumberOfStagesInMultistage, 526, 2), + DataField.Number(DataFields.NumberOfStageResults, 530, 2), + new(DataFields.StageResult, 534, 11) } }, { 999, new List() { - new DataField((int)DataFields.VinNumber, 20, 25, ' ', hasPrefix: false), - new DataField((int)DataFields.JobId, 45, 2, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.ParameterSetId, 47, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.BatchSize, 50, 4, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.BatchCounter, 54, 4, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.BatchStatus, 58, 1, false), - new DataField((int)DataFields.TighteningStatus, 59, 1, false), - new DataField((int)DataFields.TorqueStatus, 60, 1, false), - new DataField((int)DataFields.AngleStatus, 61, 1, false), - new DataField((int)DataFields.Torque, 62, 6, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.Angle, 68, 5, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.Timestamp, 73, 19, false), - new DataField((int)DataFields.LastChangeInParameterSet, 92, 19, false), - new DataField((int)DataFields.TighteningId, 111, 10, '0', PaddingOrientation.LeftPadded, false) + DataField.String(DataFields.VinNumber, 20, 25, false), + DataField.Number(DataFields.JobId, 45, 2, false), + DataField.Number(DataFields.ParameterSetId, 47, 3, false), + DataField.Number(DataFields.BatchSize, 50, 4, false), + DataField.Number(DataFields.BatchCounter, 54, 4, false), + DataField.Number(DataFields.BatchStatus, 58, 1, false), + DataField.Number(DataFields.TighteningStatus, 59, 1, false), + DataField.Number(DataFields.TorqueStatus, 60, 1, false), + DataField.Number(DataFields.AngleStatus, 61, 1, false), + DataField.Number(DataFields.Torque, 62, 6, false), + DataField.Number(DataFields.Angle, 68, 5, false), + DataField.Timestamp(DataFields.Timestamp, 73, false), + DataField.Timestamp(DataFields.LastChangeInParameterSet, 92, false), + DataField.Number(DataFields.TighteningId, 111, 10, false) } } }; @@ -634,6 +743,7 @@ private int GetCurrentRevisionIndex() if (Header.Revision > 1) return 2; + return 1; } @@ -707,7 +817,25 @@ protected enum DataFields PostViewTorqueActivated, PostViewTorqueHigh, PostViewTorqueLow, - //Rev 998 (Go over 7) + //Rev 9 + CurrentMonitoringAmp, + CurrentMonitoringAmpMin, + CurrentMonitoringAmpMax, + //Rev 10 + AngleNumeratorScaleFactor, + AngleDenominatorScaleFactor, + OverallAngleStatus, + OverallAngleMin, + OverallAngleMax, + OverallAngle, + PeakTorque, + ResidualBreakawayTorque, + StartRundownAngle, + RundownAngleComplete, + //Rev 11 + ClickTorque, + ClickAngle, + //Rev 998 (Go over rev 7) NumberOfStagesInMultistage, NumberOfStageResults, StageResult diff --git a/src/OpenProtocolInterpreter/Tightening/Mid0064.cs b/src/OpenProtocolInterpreter/Tightening/Mid0064.cs index f6560480..af2aebad 100644 --- a/src/OpenProtocolInterpreter/Tightening/Mid0064.cs +++ b/src/OpenProtocolInterpreter/Tightening/Mid0064.cs @@ -29,8 +29,13 @@ public class Mid0064 : Mid, ITightening, IIntegrator, IAnswerableBy, ID public long TighteningId { - get => GetField(1,(int)DataFields.TighteningId).GetValue(OpenProtocolConvert.ToInt64); - set => GetField(1,(int)DataFields.TighteningId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.TighteningId).GetValue(OpenProtocolConvert.ToInt64); + set => GetField(1, DataFields.TighteningId).SetValue(OpenProtocolConvert.ToString, value); + } + public bool OfflineResult + { + get => GetField(10, DataFields.OfflineResult).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(10, DataFields.OfflineResult).SetValue(OpenProtocolConvert.ToString, value); } public Mid0064() : this(DEFAULT_REVISION) @@ -58,15 +63,22 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.TighteningId, 20, 10, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.TighteningId, 20, 10, false) } }, + { + 10, new List() + { + DataField.Boolean(DataFields.OfflineResult, 30, false) + } + } }; } protected enum DataFields { - TighteningId + TighteningId, + OfflineResult } } } diff --git a/src/OpenProtocolInterpreter/Tightening/Mid0065.cs b/src/OpenProtocolInterpreter/Tightening/Mid0065.cs index 1941f4cb..8fbace3d 100644 --- a/src/OpenProtocolInterpreter/Tightening/Mid0065.cs +++ b/src/OpenProtocolInterpreter/Tightening/Mid0065.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; namespace OpenProtocolInterpreter.Tightening { @@ -15,208 +16,286 @@ public class Mid0065 : Mid, ITightening, IController public long TighteningId { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.TighteningId).GetValue(OpenProtocolConvert.ToInt64); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.TighteningId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.TighteningId).GetValue(OpenProtocolConvert.ToInt64); + set => GetField(GetCurrentRevisionIndex(), DataFields.TighteningId).SetValue(OpenProtocolConvert.ToString, value); } public string VinNumber { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.VinNumber).Value; - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.VinNumber).SetValue(value); + get => GetField(GetCurrentRevisionIndex(), DataFields.VinNumber).Value; + set => GetField(GetCurrentRevisionIndex(), DataFields.VinNumber).SetValue(value); } public int ParameterSetId { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.ParameterSetId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.ParameterSetId).SetValue(OpenProtocolConvert.ToString, value); } public int BatchCounter { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.BatchCounter).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.BatchCounter).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.BatchCounter).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.BatchCounter).SetValue(OpenProtocolConvert.ToString, value); } public bool TighteningStatus { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.TighteningStatus).GetValue(OpenProtocolConvert.ToBoolean); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.TighteningStatus).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.TighteningStatus).GetValue(OpenProtocolConvert.ToBoolean); + set => GetField(GetCurrentRevisionIndex(), DataFields.TighteningStatus).SetValue(OpenProtocolConvert.ToString, value); } public TighteningValueStatus TorqueStatus { - get => (TighteningValueStatus)GetField(GetCurrentRevisionIndex(), (int)DataFields.TorqueStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.TorqueStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (TighteningValueStatus)GetField(GetCurrentRevisionIndex(), DataFields.TorqueStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.TorqueStatus).SetValue(OpenProtocolConvert.ToString, value); } public TighteningValueStatus AngleStatus { - get => (TighteningValueStatus)GetField(GetCurrentRevisionIndex(), (int)DataFields.AngleStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.AngleStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (TighteningValueStatus)GetField(GetCurrentRevisionIndex(), DataFields.AngleStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.AngleStatus).SetValue(OpenProtocolConvert.ToString, value); } public decimal Torque { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.Torque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.Torque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.Torque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(GetCurrentRevisionIndex(), DataFields.Torque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public int Angle { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.Angle).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.Angle).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.Angle).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.Angle).SetValue(OpenProtocolConvert.ToString, value); } public DateTime Timestamp { - get => GetField(GetCurrentRevisionIndex(), (int)DataFields.Timestamp).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.Timestamp).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(GetCurrentRevisionIndex(), DataFields.Timestamp).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(GetCurrentRevisionIndex(), DataFields.Timestamp).SetValue(OpenProtocolConvert.ToString, value); } public BatchStatus BatchStatus { - get => (BatchStatus)GetField(GetCurrentRevisionIndex(), (int)DataFields.BatchStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(GetCurrentRevisionIndex(), (int)DataFields.BatchStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (BatchStatus)GetField(GetCurrentRevisionIndex(), DataFields.BatchStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(GetCurrentRevisionIndex(), DataFields.BatchStatus).SetValue(OpenProtocolConvert.ToString, value); } //Rev 2 public int JobId { - get => GetField(2, (int)DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.JobId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.JobId).SetValue(OpenProtocolConvert.ToString, value); } public Strategy Strategy { - get => (Strategy)GetField(2, (int)DataFields.Strategy).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.Strategy).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (Strategy)GetField(2, DataFields.Strategy).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.Strategy).SetValue(OpenProtocolConvert.ToString, value); } public StrategyOptions StrategyOptions { get; set; } public int BatchSize { - get => GetField(2, (int)DataFields.BatchSize).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.BatchSize).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.BatchSize).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.BatchSize).SetValue(OpenProtocolConvert.ToString, value); } public TighteningValueStatus RundownAngleStatus { - get => (TighteningValueStatus)GetField(2, (int)DataFields.RundownAngleStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.RundownAngleStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (TighteningValueStatus)GetField(2, DataFields.RundownAngleStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.RundownAngleStatus).SetValue(OpenProtocolConvert.ToString, value); } public TighteningValueStatus CurrentMonitoringStatus { - get => (TighteningValueStatus)GetField(2, (int)DataFields.CurrentMonitoringStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.CurrentMonitoringStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (TighteningValueStatus)GetField(2, DataFields.CurrentMonitoringStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.CurrentMonitoringStatus).SetValue(OpenProtocolConvert.ToString, value); } public TighteningValueStatus SelftapStatus { - get => (TighteningValueStatus)GetField(2, (int)DataFields.SelftapStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.SelftapStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (TighteningValueStatus)GetField(2, DataFields.SelftapStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.SelftapStatus).SetValue(OpenProtocolConvert.ToString, value); } public TighteningValueStatus PrevailTorqueMonitoringStatus { - get => (TighteningValueStatus)GetField(2, (int)DataFields.PrevailTorqueMonitoringStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.PrevailTorqueMonitoringStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (TighteningValueStatus)GetField(2, DataFields.PrevailTorqueMonitoringStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.PrevailTorqueMonitoringStatus).SetValue(OpenProtocolConvert.ToString, value); } public TighteningValueStatus PrevailTorqueCompensateStatus { - get => (TighteningValueStatus)GetField(2, (int)DataFields.PrevaiTorqueMonitoringStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.PrevaiTorqueMonitoringStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (TighteningValueStatus)GetField(2, DataFields.PrevaiTorqueMonitoringStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.PrevaiTorqueMonitoringStatus).SetValue(OpenProtocolConvert.ToString, value); } public TighteningErrorStatus TighteningErrorStatus { get; set; } public int RundownAngle { - get => GetField(2, (int)DataFields.RundownAngle).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.RundownAngle).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.RundownAngle).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.RundownAngle).SetValue(OpenProtocolConvert.ToString, value); } public int CurrentMonitoringValue { - get => GetField(2, (int)DataFields.CurrentMonitoringValue).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.CurrentMonitoringValue).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.CurrentMonitoringValue).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.CurrentMonitoringValue).SetValue(OpenProtocolConvert.ToString, value); } public decimal SelftapTorque { - get => GetField(2, (int)DataFields.SelftapTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(2, (int)DataFields.SelftapTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(2, DataFields.SelftapTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(2, DataFields.SelftapTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal PrevailTorque { - get => GetField(2, (int)DataFields.PrevailTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(2, (int)DataFields.PrevailTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(2, DataFields.PrevailTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(2, DataFields.PrevailTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public int JobSequenceNumber { - get => GetField(2, (int)DataFields.JobSequenceNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.JobSequenceNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.JobSequenceNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.JobSequenceNumber).SetValue(OpenProtocolConvert.ToString, value); } public int SyncTighteningId { - get => GetField(2, (int)DataFields.SyncTighteningId).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.SyncTighteningId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.SyncTighteningId).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.SyncTighteningId).SetValue(OpenProtocolConvert.ToString, value); } public string ToolSerialNumber { - get => GetField(2, (int)DataFields.ToolSerialNumber).Value; - set => GetField(2, (int)DataFields.ToolSerialNumber).SetValue(value); + get => GetField(2, DataFields.ToolSerialNumber).Value; + set => GetField(2, DataFields.ToolSerialNumber).SetValue(value); } //Rev 3 public TorqueValuesUnit TorqueValuesUnit { - get => (TorqueValuesUnit)GetField(3, (int)DataFields.TorqueValuesUnit).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(3, (int)DataFields.TorqueValuesUnit).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (TorqueValuesUnit)GetField(3, DataFields.TorqueValuesUnit).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(3, DataFields.TorqueValuesUnit).SetValue(OpenProtocolConvert.ToString, value); } public ResultType ResultType { - get => (ResultType)GetField(3, (int)DataFields.ResultType).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(3, (int)DataFields.ResultType).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (ResultType)GetField(3, DataFields.ResultType).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(3, DataFields.ResultType).SetValue(OpenProtocolConvert.ToString, value); } //Rev 4 public string IdentifierResultPart2 { - get => GetField(4, (int)DataFields.IdentifierResulPart2).Value; - set => GetField(4, (int)DataFields.IdentifierResulPart2).SetValue(value); + get => GetField(4, DataFields.IdentifierResulPart2).Value; + set => GetField(4, DataFields.IdentifierResulPart2).SetValue(value); } public string IdentifierResultPart3 { - get => GetField(4, (int)DataFields.IdentifierResulPart3).Value; - set => GetField(4, (int)DataFields.IdentifierResulPart3).SetValue(value); + get => GetField(4, DataFields.IdentifierResulPart3).Value; + set => GetField(4, DataFields.IdentifierResulPart3).SetValue(value); } public string IdentifierResultPart4 { - get => GetField(4, (int)DataFields.IdentifierResulPart4).Value; - set => GetField(4, (int)DataFields.IdentifierResulPart4).SetValue(value); + get => GetField(4, DataFields.IdentifierResulPart4).Value; + set => GetField(4, DataFields.IdentifierResulPart4).SetValue(value); } //Rev 5 public string CustomerTighteningErrorCode { - get => GetField(5, (int)DataFields.CustomerTighteningErrorCode).Value; - set => GetField(5, (int)DataFields.CustomerTighteningErrorCode).SetValue(value); + get => GetField(5, DataFields.CustomerTighteningErrorCode).Value; + set => GetField(5, DataFields.CustomerTighteningErrorCode).SetValue(value); } //Rev 6 public decimal PrevailTorqueCompensateValue { - get => GetField(6, (int)DataFields.PrevailTorqueCompensateValue).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(6, (int)DataFields.PrevailTorqueCompensateValue).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(6, DataFields.PrevailTorqueCompensateValue).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(6, DataFields.PrevailTorqueCompensateValue).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public TighteningErrorStatus2 TighteningErrorStatus2 { get; set; } //Rev 7 public long StationId { - get => GetField(7, (int)DataFields.StationId).GetValue(OpenProtocolConvert.ToInt64); - set => GetField(7, (int)DataFields.StationId).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(7, DataFields.StationId).GetValue(OpenProtocolConvert.ToInt64); + set => GetField(7, DataFields.StationId).SetValue(OpenProtocolConvert.ToString, value); } public string StationName { - get => GetField(7, (int)DataFields.StationName).Value; - set => GetField(7, (int)DataFields.StationName).SetValue(value); + get => GetField(7, DataFields.StationName).Value; + set => GetField(7, DataFields.StationName).SetValue(value); } //Rev 8 public decimal StartFinalAngle { - get => GetField(8, (int)DataFields.StartFinalAngle).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(8, (int)DataFields.StartFinalAngle).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(8, DataFields.StartFinalAngle).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(8, DataFields.StartFinalAngle).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public PostViewTorque PostViewTorqueActivated { - get => (PostViewTorque)GetField(8, (int)DataFields.PostViewTorqueActivated).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(8, (int)DataFields.PostViewTorqueActivated).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (PostViewTorque)GetField(8, DataFields.PostViewTorqueActivated).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(8, DataFields.PostViewTorqueActivated).SetValue(OpenProtocolConvert.ToString, value); } public decimal PostViewTorqueHigh { - get => GetField(8, (int)DataFields.PostViewTorqueHigh).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(8, (int)DataFields.PostViewTorqueHigh).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(8, DataFields.PostViewTorqueHigh).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(8, DataFields.PostViewTorqueHigh).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal PostViewTorqueLow { - get => GetField(8, (int)DataFields.PostViewTorqueLow).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(8, (int)DataFields.PostViewTorqueLow).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(8, DataFields.PostViewTorqueLow).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(8, DataFields.PostViewTorqueLow).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + } + //Rev 9 + public decimal CurrentMonitoringAmpere + { + get => GetField(9, DataFields.CurrentMonitoringAmp).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(9, DataFields.CurrentMonitoringAmp).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + } + public decimal CurrentMonitoringAmpereMin + { + get => GetField(9, DataFields.CurrentMonitoringAmpMin).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(9, DataFields.CurrentMonitoringAmpMin).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + } + public decimal CurrentMonitoringAmpereMax + { + get => GetField(9, DataFields.CurrentMonitoringAmpMax).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(9, DataFields.CurrentMonitoringAmpMax).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + } + //Rev 10 addition + public int AngleNumeratorScaleFactor + { + get => GetField(10, DataFields.AngleNumeratorScaleFactor).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(10, DataFields.AngleNumeratorScaleFactor).SetValue(OpenProtocolConvert.ToString, value); + } + public int AngleDenominatorScaleFactor + { + get => GetField(10, DataFields.AngleDenominatorScaleFactor).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(10, DataFields.AngleDenominatorScaleFactor).SetValue(OpenProtocolConvert.ToString, value); + } + public TighteningValueStatus OverallAngleStatus + { + get => (TighteningValueStatus)GetField(10, DataFields.OverallAngleStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(10, DataFields.OverallAngleStatus).SetValue(OpenProtocolConvert.ToString, value); + } + public int OverallAngleMin + { + get => GetField(10, DataFields.OverallAngleMin).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(10, DataFields.OverallAngleMin).SetValue(OpenProtocolConvert.ToString, value); + } + public int OverallAngleMax + { + get => GetField(10, DataFields.OverallAngleMax).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(10, DataFields.OverallAngleMax).SetValue(OpenProtocolConvert.ToString, value); + } + public int OverallAngle + { + get => GetField(10, DataFields.OverallAngle).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(10, DataFields.OverallAngle).SetValue(OpenProtocolConvert.ToString, value); + } + public decimal PeakTorque + { + get => GetField(10, DataFields.PeakTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(10, DataFields.PeakTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + } + public decimal ResidualBreakawayTorque + { + get => GetField(10, DataFields.ResidualBreakawayTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(10, DataFields.ResidualBreakawayTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + } + public decimal StartRundownAngle + { + get => GetField(10, DataFields.StartRundownAngle).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(10, DataFields.StartRundownAngle).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + } + public decimal RundownAngleComplete + { + get => GetField(10, DataFields.RundownAngleComplete).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(10, DataFields.RundownAngleComplete).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + } + //Rev 11 + public decimal ClickTorque + { + get => GetField(11, DataFields.ClickTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(11, DataFields.ClickTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + } + public int ClickAngle + { + get => GetField(11, DataFields.ClickAngle).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(11, DataFields.ClickAngle).SetValue(OpenProtocolConvert.ToString, value); } public Mid0065() : this(DEFAULT_REVISION) @@ -231,7 +310,7 @@ public Mid0065(Header header) : base(header) public Mid0065(int revision) : this(new Header() { - Mid = MID, + Mid = MID, Revision = revision }) { @@ -260,53 +339,53 @@ protected override string BuildHeader() public override string Pack() { - string package = BuildHeader(); + var builder = new StringBuilder(BuildHeader()); int prefixIndex = 1; if (Header.Revision > 1) { - GetField(2, (int)DataFields.StrategyOptions).SetValue(StrategyOptions.Pack()); - GetField(2, (int)DataFields.TighteningErrorStatus).SetValue(TighteningErrorStatus.Pack()); + GetField(2, DataFields.StrategyOptions).SetValue(StrategyOptions.Pack()); + GetField(2, DataFields.TighteningErrorStatus).SetValue(TighteningErrorStatus.Pack()); if (Header.Revision > 5) { - GetField(6, (int)DataFields.TighteningErrorStatus2).SetValue(TighteningErrorStatus2.Pack()); + GetField(6, DataFields.TighteningErrorStatus2).SetValue(TighteningErrorStatus2.Pack()); } int processUntil = Header.Revision; - for (int i = 2; i <= processUntil; i++) + for (int revision = 2; revision <= processUntil; revision++) { - package += Pack(RevisionsByFields[i], ref prefixIndex); + builder.Append(Pack(revision, ref prefixIndex)); } } else { - package += Pack(RevisionsByFields[Header.Revision], ref prefixIndex); + builder.Append(Pack(Header.Revision, ref prefixIndex)); } - return package; + return builder.ToString(); } protected override void ProcessDataFields(string package) { if (Header.Revision == 1) { - ProcessDataFields(RevisionsByFields[Header.Revision], package); + ProcessDataFields(Header.Revision, package); } else { int processUntil = Header.Revision; - for (int i = 2; i <= processUntil; i++) - ProcessDataFields(RevisionsByFields[i], package); + for (int revision = 2; revision <= processUntil; revision++) + ProcessDataFields(revision, package); - var strategyOptionsField = GetField(2, (int)DataFields.StrategyOptions); + var strategyOptionsField = GetField(2, DataFields.StrategyOptions); StrategyOptions = StrategyOptions.Parse(strategyOptionsField.Value); - var tighteningErrorStatusField = GetField(2, (int)DataFields.TighteningErrorStatus); + var tighteningErrorStatusField = GetField(2, DataFields.TighteningErrorStatus); TighteningErrorStatus = TighteningErrorStatus.Parse(tighteningErrorStatusField.Value); if (Header.Revision > 5) { - var tighteningErrorStatus2Field = GetField(6, (int)DataFields.TighteningErrorStatus2); + var tighteningErrorStatus2Field = GetField(6, DataFields.TighteningErrorStatus2); TighteningErrorStatus2 = TighteningErrorStatus2.Parse(tighteningErrorStatus2Field.Value); } } @@ -320,94 +399,124 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.TighteningId, 20, 10, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.VinNumber, 32, 25, ' '), - new DataField((int)DataFields.ParameterSetId, 59, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.BatchCounter, 64, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TighteningStatus, 70, 1), - new DataField((int)DataFields.TorqueStatus, 73, 1), - new DataField((int)DataFields.AngleStatus, 76, 1), - new DataField((int)DataFields.Torque, 79, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Angle, 87, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Timestamp, 94, 19), - new DataField((int)DataFields.BatchStatus, 115, 1) + DataField.Number(DataFields.TighteningId, 20, 10), + DataField.String(DataFields.VinNumber, 32, 25), + DataField.Number(DataFields.ParameterSetId, 59, 3), + DataField.Number(DataFields.BatchCounter, 64, 4), + DataField.Number(DataFields.TighteningStatus, 70, 1), + DataField.Number(DataFields.TorqueStatus, 73, 1), + DataField.Number(DataFields.AngleStatus, 76, 1), + DataField.Number(DataFields.Torque, 79, 6), + DataField.Number(DataFields.Angle, 87, 5), + DataField.Timestamp(DataFields.Timestamp, 94), + DataField.Number(DataFields.BatchStatus, 115, 1) } }, { 2, new List() { - new DataField((int)DataFields.TighteningId, 20, 10, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.VinNumber, 32, 25, ' '), - new DataField((int)DataFields.JobId, 59, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ParameterSetId, 65, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Strategy, 70, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.StrategyOptions, 74, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.BatchSize, 81, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.BatchCounter, 87, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TighteningStatus, 93, 1), - new DataField((int)DataFields.BatchStatus, 96, 1), - new DataField((int)DataFields.TorqueStatus, 99, 1), - new DataField((int)DataFields.AngleStatus, 102, 1), - new DataField((int)DataFields.RundownAngleStatus, 105, 1), - new DataField((int)DataFields.CurrentMonitoringStatus, 108, 1), - new DataField((int)DataFields.SelftapStatus, 111, 1), - new DataField((int)DataFields.PrevailTorqueMonitoringStatus, 114, 1), - new DataField((int)DataFields.PrevaiTorqueMonitoringStatus, 117, 1), - new DataField((int)DataFields.TighteningErrorStatus, 120, 10, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Torque, 132, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Angle, 140, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.RundownAngle, 147, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.CurrentMonitoringValue, 154, 3, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.SelftapTorque, 159, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.PrevailTorque, 167, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.JobSequenceNumber, 175, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.SyncTighteningId, 182, 5, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ToolSerialNumber, 189, 14, ' '), - new DataField((int)DataFields.Timestamp, 205, 19), + DataField.Number(DataFields.TighteningId, 20, 10), + DataField.String(DataFields.VinNumber, 32, 25), + DataField.Number(DataFields.JobId, 59, 4), + DataField.Number(DataFields.ParameterSetId, 65, 3), + DataField.Number(DataFields.Strategy, 70, 2), + new(DataFields.StrategyOptions, 74, 5, '0', PaddingOrientation.LeftPadded), + DataField.Number(DataFields.BatchSize, 81, 4), + DataField.Number(DataFields.BatchCounter, 87, 4), + DataField.Number(DataFields.TighteningStatus, 93, 1), + DataField.Number(DataFields.BatchStatus, 96, 1), + DataField.Number(DataFields.TorqueStatus, 99, 1), + DataField.Number(DataFields.AngleStatus, 102, 1), + DataField.Number(DataFields.RundownAngleStatus, 105, 1), + DataField.Number(DataFields.CurrentMonitoringStatus, 108, 1), + DataField.Number(DataFields.SelftapStatus, 111, 1), + DataField.Number(DataFields.PrevailTorqueMonitoringStatus, 114, 1), + DataField.Number(DataFields.PrevaiTorqueMonitoringStatus, 117, 1), + new(DataFields.TighteningErrorStatus, 120, 10, '0', PaddingOrientation.LeftPadded), + DataField.Number(DataFields.Torque, 132, 6), + DataField.Number(DataFields.Angle, 140, 5), + DataField.Number(DataFields.RundownAngle, 147, 5), + DataField.Number(DataFields.CurrentMonitoringValue, 154, 3), + DataField.Number(DataFields.SelftapTorque, 159, 6), + DataField.Number(DataFields.PrevailTorque, 167, 6), + DataField.Number(DataFields.JobSequenceNumber, 175, 5), + DataField.Number(DataFields.SyncTighteningId, 182, 5), + DataField.String(DataFields.ToolSerialNumber, 189, 14), + DataField.Timestamp(DataFields.Timestamp, 205), } }, { 3, new List() { - new DataField((int)DataFields.TorqueValuesUnit, 226, 1), - new DataField((int)DataFields.ResultType, 229, 2, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.TorqueValuesUnit, 226, 1), + DataField.Number(DataFields.ResultType, 229, 2) } }, { 4, new List() { - new DataField((int)DataFields.IdentifierResulPart2, 233, 25, ' '), - new DataField((int)DataFields.IdentifierResulPart3, 260, 25, ' '), - new DataField((int)DataFields.IdentifierResulPart4, 287, 25, ' ') + DataField.String(DataFields.IdentifierResulPart2, 233, 25), + DataField.String(DataFields.IdentifierResulPart3, 260, 25), + DataField.String(DataFields.IdentifierResulPart4, 287, 25) } }, { 5, new List() { - new DataField((int)DataFields.CustomerTighteningErrorCode, 314, 4, ' '), + DataField.String(DataFields.CustomerTighteningErrorCode, 314, 4), } }, { 6, new List() { - new DataField((int)DataFields.PrevailTorqueCompensateValue, 320, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.TighteningErrorStatus2, 328, 10, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.PrevailTorqueCompensateValue, 320, 6), + new(DataFields.TighteningErrorStatus2, 328, 10, '0', PaddingOrientation.LeftPadded) } }, { 7, new List() { - new DataField((int)DataFields.StationId, 340, 10, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.StationName, 352, 25) + DataField.Number(DataFields.StationId, 340, 10), + DataField.String(DataFields.StationName, 352, 25) } }, { 8, new List() { - new DataField((int)DataFields.StartFinalAngle, 379, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.PostViewTorqueActivated, 387, 1), - new DataField((int)DataFields.PostViewTorqueHigh, 390, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.PostViewTorqueLow, 398, 6, '0', PaddingOrientation.LeftPadded), + DataField.Number(DataFields.StartFinalAngle, 379, 6), + DataField.Number(DataFields.PostViewTorqueActivated, 387, 1), + DataField.Number(DataFields.PostViewTorqueHigh, 390, 6), + DataField.Number(DataFields.PostViewTorqueLow, 398, 6), + } + }, + { + 9, new List() + { + DataField.Number(DataFields.CurrentMonitoringAmp, 406, 5), + DataField.Number(DataFields.CurrentMonitoringAmpMin, 413, 5), + DataField.Number(DataFields.CurrentMonitoringAmpMax, 420, 5) + } + }, + { + 10, new List() + { + DataField.Number(DataFields.AngleNumeratorScaleFactor, 427, 5), + DataField.Number(DataFields.AngleDenominatorScaleFactor, 434, 5), + DataField.Number(DataFields.OverallAngleStatus, 441, 1), + DataField.Number(DataFields.OverallAngleMin, 444, 5), + DataField.Number(DataFields.OverallAngleMax, 451, 5), + DataField.Number(DataFields.OverallAngle, 458, 5), + DataField.Number(DataFields.PeakTorque, 465, 6), + DataField.Number(DataFields.ResidualBreakawayTorque, 473, 6), + DataField.Number(DataFields.StartRundownAngle, 481, 6), + DataField.Number(DataFields.RundownAngleComplete, 489, 6) + } + }, + { + 11, new List() + { + DataField.Number(DataFields.ClickTorque, 497, 6), + DataField.Number(DataFields.ClickAngle, 505, 5), } } }; @@ -465,7 +574,25 @@ protected enum DataFields StartFinalAngle, PostViewTorqueActivated, PostViewTorqueHigh, - PostViewTorqueLow - } + PostViewTorqueLow, + //Rev 9 + CurrentMonitoringAmp, + CurrentMonitoringAmpMin, + CurrentMonitoringAmpMax, + //Rev 10 + AngleNumeratorScaleFactor, + AngleDenominatorScaleFactor, + OverallAngleStatus, + OverallAngleMin, + OverallAngleMax, + OverallAngle, + PeakTorque, + ResidualBreakawayTorque, + StartRundownAngle, + RundownAngleComplete, + //Rev 11 + ClickTorque, + ClickAngle + } } } diff --git a/src/OpenProtocolInterpreter/Tightening/Mid0066.cs b/src/OpenProtocolInterpreter/Tightening/Mid0066.cs index 8b957c80..d85e3b60 100644 --- a/src/OpenProtocolInterpreter/Tightening/Mid0066.cs +++ b/src/OpenProtocolInterpreter/Tightening/Mid0066.cs @@ -14,13 +14,19 @@ public class Mid0066 : Mid, ITightening, IController public int NumberOfOfflineResults { - get => GetField(1, (int)DataFields.NumberOfOfflineResults).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.NumberOfOfflineResults).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.NumberOfOfflineResults).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.NumberOfOfflineResults).SetValue(OpenProtocolConvert.ToString, value); + } + + public int NumberOfOfflineCurves + { + get => GetField(2, DataFields.NumberOfOfflineCurves).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.NumberOfOfflineCurves).SetValue(OpenProtocolConvert.ToString, value); } public Mid0066() : this(new Header() { - Mid = MID, + Mid = MID, Revision = DEFAULT_REVISION }) { @@ -30,6 +36,25 @@ public Mid0066(Header header) : base(header) { } + public override Mid Parse(string package) + { + Header = ProcessHeader(package); + HandleRevisionSizes(); + ProcessDataFields(package); + return this; + } + + public override string Pack() + { + HandleRevisionSizes(); + return base.Pack(); + } + + private void HandleRevisionSizes() + { + GetField(1, DataFields.NumberOfOfflineResults).Size = Header.Revision > 1 ? 3 : 2; + } + protected override Dictionary> RegisterDatafields() { return new Dictionary>() @@ -37,7 +62,13 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.NumberOfOfflineResults, 20, 2, '0', PaddingOrientation.LeftPadded, false) + DataField.Number(DataFields.NumberOfOfflineResults, 20, 2) + } + }, + { + 2, new List() + { + DataField.Number(DataFields.NumberOfOfflineCurves, 25, 3), } } }; @@ -45,7 +76,8 @@ protected override Dictionary> RegisterDatafields() protected enum DataFields { - NumberOfOfflineResults + NumberOfOfflineResults, + NumberOfOfflineCurves } } } diff --git a/src/OpenProtocolInterpreter/Tightening/Mid0902.cs b/src/OpenProtocolInterpreter/Tightening/Mid0902.cs new file mode 100644 index 00000000..128091f2 --- /dev/null +++ b/src/OpenProtocolInterpreter/Tightening/Mid0902.cs @@ -0,0 +1,113 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenProtocolInterpreter.Tightening +{ + /// + /// Tightening Result DB Info Upload + /// This message contains information concerning the tightening result database on the controller. + /// Application Data Message Request shall be used for fetching this message + /// Message sent by: Controller + /// Answer: None + /// + public class Mid0902 : Mid, ITightening, IController + { + public const int MID = 902; + + public long Capacity + { + get => GetField(1, DataFields.Capacity).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.Capacity).SetValue(OpenProtocolConvert.ToString, value); + } + public long OldestSequenceNumber + { + get => GetField(1, DataFields.OldestSequenceNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.OldestSequenceNumber).SetValue(OpenProtocolConvert.ToString, value); + } + public DateTime OldestTime + { + get => GetField(1, DataFields.OldestTime).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(1, DataFields.OldestTime).SetValue(OpenProtocolConvert.ToString, value); + } + public long NewestSequenceNumber + { + get => GetField(1, DataFields.NewestSequenceNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.NewestTime).SetValue(OpenProtocolConvert.ToString, value); + } + public DateTime NewestTime + { + get => GetField(1, DataFields.NewestTime).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(1, DataFields.NewestTime).SetValue(OpenProtocolConvert.ToString, value); + } + public int NumberOfPIDs + { + get => GetField(1, DataFields.NumberOfPIDs).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.NumberOfPIDs).SetValue(OpenProtocolConvert.ToString, value); + } + public List VariableDataFields { get; set; } + + public Mid0902() : this(new Header() + { + Mid = MID, + Revision = DEFAULT_REVISION + }) + { + + } + + public Mid0902(Header header) : base(header) + { + } + + public override string Pack() + { + var revision = Header.StandardizedRevision; + GetField(revision, DataFields.VariableDataFields).SetValue(OpenProtocolConvert.ToString(VariableDataFields)); + + var index = 1; + return string.Concat(BuildHeader(), base.Pack(revision, ref index)); + } + + public override Mid Parse(string package) + { + Header = ProcessHeader(package); + + var field = GetField(1, DataFields.VariableDataFields); + field.Size = Header.Length - field.Index; + base.Parse(package); + VariableDataFields = VariableDataField.ParseAll(field.Value).ToList(); + return this; + } + + protected override Dictionary> RegisterDatafields() + { + return new Dictionary>() + { + { + 1, new List() + { + DataField.Number(DataFields.Capacity, 20, 10, false), + DataField.Number(DataFields.OldestSequenceNumber, 30, 10, false), + DataField.Timestamp(DataFields.OldestTime, 40, false), + DataField.Number(DataFields.NewestSequenceNumber, 59, 10, false), + DataField.Timestamp(DataFields.NewestTime, 69, false), + DataField.Number(DataFields.NumberOfPIDs, 88, 3, false), + DataField.Volatile(DataFields.VariableDataFields, 91, false) + } + } + }; + } + + protected enum DataFields + { + Capacity, + OldestSequenceNumber, + OldestTime, + NewestSequenceNumber, + NewestTime, + NumberOfPIDs, + VariableDataFields + } + } +} diff --git a/src/OpenProtocolInterpreter/Tightening/StageResult.cs b/src/OpenProtocolInterpreter/Tightening/StageResult.cs index 9c9afb95..1f69f45a 100644 --- a/src/OpenProtocolInterpreter/Tightening/StageResult.cs +++ b/src/OpenProtocolInterpreter/Tightening/StageResult.cs @@ -12,10 +12,8 @@ public class StageResult public string Pack() { - var pack = string.Empty; - pack += OpenProtocolConvert.TruncatedDecimalToString('0', 6, PaddingOrientation.LeftPadded, Torque); - pack += OpenProtocolConvert.ToString('0', 5, PaddingOrientation.LeftPadded, Angle); - return pack; + return OpenProtocolConvert.TruncatedDecimalToString('0', 6, PaddingOrientation.LeftPadded, Torque) + + OpenProtocolConvert.ToString('0', 5, PaddingOrientation.LeftPadded, Angle); } public static StageResult Parse(string value) diff --git a/src/OpenProtocolInterpreter/Tightening/StrategyOptions.cs b/src/OpenProtocolInterpreter/Tightening/StrategyOptions.cs index 552ae289..bc900ced 100644 --- a/src/OpenProtocolInterpreter/Tightening/StrategyOptions.cs +++ b/src/OpenProtocolInterpreter/Tightening/StrategyOptions.cs @@ -53,7 +53,7 @@ public byte[] PackBytes() false }); - var asciiInt = System.BitConverter.ToInt32(bytes, 0).ToString().PadLeft(5, '0'); + var asciiInt = System.BitConverter.ToInt32(bytes, 0).ToString("D5"); return Encoding.ASCII.GetBytes(asciiInt); } diff --git a/src/OpenProtocolInterpreter/Tightening/TighteningErrorStatus.cs b/src/OpenProtocolInterpreter/Tightening/TighteningErrorStatus.cs index 49b49ca2..57c6e0b3 100644 --- a/src/OpenProtocolInterpreter/Tightening/TighteningErrorStatus.cs +++ b/src/OpenProtocolInterpreter/Tightening/TighteningErrorStatus.cs @@ -53,8 +53,8 @@ public string Pack() public byte[] PackBytes() { byte[] bytes = new byte[10]; - bytes[0] = OpenProtocolConvert.ToByte(new bool[] - { + bytes[0] = OpenProtocolConvert.ToByte( + [ RundownAngleMaxShutOff, RundownAngleMinShutOff, TorqueMaxShutOff, @@ -63,9 +63,9 @@ public byte[] PackBytes() SelftapTorqueMinShutOff, PrevailTorqueMaxShutOff, PrevailTorqueMinShutOff - }); - bytes[1] = OpenProtocolConvert.ToByte(new bool[] - { + ]); + bytes[1] = OpenProtocolConvert.ToByte( + [ PrevailTorqueCompensateOverflow , CurrentMonitoringMaxShutOff, PostViewTorqueMinTorqueShutOff, @@ -74,9 +74,9 @@ public byte[] PackBytes() TriggerLost, TorqueLessThanTarget, ToolHot - }); - bytes[2] = OpenProtocolConvert.ToByte(new bool[] - { + ]); + bytes[2] = OpenProtocolConvert.ToByte( + [ MultistageAbort, Rehit, DsMeasureFailed, @@ -85,9 +85,9 @@ public byte[] PackBytes() RemoveFastenerLimitExceeded, DisableDrive, TransducerLost - }); - bytes[3] = OpenProtocolConvert.ToByte(new bool[] - { + ]); + bytes[3] = OpenProtocolConvert.ToByte( + [ TransducerShorted, TransducerCorrupt, SyncTimeout, @@ -96,9 +96,9 @@ public byte[] PackBytes() AngleMaxMonitor, YieldNutOff, YieldTooFewSamples - }); + ]); - var asciiLong = System.BitConverter.ToInt64(bytes, 0).ToString().PadLeft(10, '0'); + var asciiLong = System.BitConverter.ToInt64(bytes, 0).ToString("D10"); return Encoding.ASCII.GetBytes(asciiLong); } @@ -189,10 +189,10 @@ public string Pack() public byte[] PackBytes() { - byte[] bytes = new byte[] - { - OpenProtocolConvert.ToByte(new bool[] - { + byte[] bytes = + [ + OpenProtocolConvert.ToByte( + [ DriveDeactivated, ToolStall, DriveHot, @@ -201,9 +201,9 @@ public byte[] PackBytes() ReactionBarFailed, SnugMax, CycleAbort, - }), - OpenProtocolConvert.ToByte(new bool[] - { + ]), + OpenProtocolConvert.ToByte( + [ NeckingFailure, EffectiveLoosening, OverSpeed, @@ -212,9 +212,9 @@ public byte[] PackBytes() SnugMonLow, SnugMonHigh, DynamicMinCurrent, - }), - OpenProtocolConvert.ToByte(new bool[] - { + ]), + OpenProtocolConvert.ToByte( + [ DynamicMaxCurrent, LatentResult, OpenProtocolConvert.GetBit(Reserved[2], 3), @@ -223,7 +223,7 @@ public byte[] PackBytes() OpenProtocolConvert.GetBit(Reserved[2], 6), OpenProtocolConvert.GetBit(Reserved[2], 7), OpenProtocolConvert.GetBit(Reserved[2], 8) - }), + ]), Reserved[3], Reserved[4], Reserved[5], @@ -231,7 +231,7 @@ public byte[] PackBytes() Reserved[7], Reserved[8], Reserved[9] - }; + ]; var asciiLong = System.BitConverter.ToInt64(bytes, 0).ToString().PadLeft(10, '0'); return Encoding.ASCII.GetBytes(asciiLong); @@ -273,7 +273,7 @@ public static TighteningErrorStatus2 Parse(byte[] value) }; //set only 19 and 20 bytes to reserved - obj.Reserved[0] = OpenProtocolConvert.ToByte(new bool[] { OpenProtocolConvert.GetBit(value[2], 3), OpenProtocolConvert.GetBit(value[2], 4), false, false, false, false, false, false }); + obj.Reserved[0] = OpenProtocolConvert.ToByte([OpenProtocolConvert.GetBit(value[2], 3), OpenProtocolConvert.GetBit(value[2], 4), false, false, false, false, false, false]); return obj; } diff --git a/src/OpenProtocolInterpreter/Tightening/TighteningMessages.cs b/src/OpenProtocolInterpreter/Tightening/TighteningMessages.cs index 6958ae91..81ece324 100644 --- a/src/OpenProtocolInterpreter/Tightening/TighteningMessages.cs +++ b/src/OpenProtocolInterpreter/Tightening/TighteningMessages.cs @@ -19,7 +19,8 @@ public TighteningMessages() : base() { Mid0063.MID, new MidCompiledInstance(typeof(Mid0063)) }, { Mid0064.MID, new MidCompiledInstance(typeof(Mid0064)) }, { Mid0065.MID, new MidCompiledInstance(typeof(Mid0065)) }, - { Mid0066.MID, new MidCompiledInstance(typeof(Mid0066)) } + { Mid0066.MID, new MidCompiledInstance(typeof(Mid0066)) }, + { Mid0902.MID, new MidCompiledInstance(typeof(Mid0902)) } }; } @@ -33,6 +34,6 @@ public TighteningMessages(InterpreterMode mode) : this() FilterSelectedMids(mode); } - public override bool IsAssignableTo(int mid) => mid > 59 && mid < 67; + public override bool IsAssignableTo(int mid) => (mid > 59 && mid < 68) || (mid > 899 && mid < 903); } } diff --git a/src/OpenProtocolInterpreter/Time/Mid0081.cs b/src/OpenProtocolInterpreter/Time/Mid0081.cs index ec6ffea4..fe563f2e 100644 --- a/src/OpenProtocolInterpreter/Time/Mid0081.cs +++ b/src/OpenProtocolInterpreter/Time/Mid0081.cs @@ -15,8 +15,8 @@ public class Mid0081 : Mid, ITime, IController public DateTime Time { - get => GetField(1,(int)DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(1,(int)DataFields.Time).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(1, DataFields.Time).SetValue(OpenProtocolConvert.ToString, value); } public Mid0081() : this(new Header() @@ -38,7 +38,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.Time, 20, 19, false) + DataField.Timestamp(DataFields.Time, 20, false) } } }; diff --git a/src/OpenProtocolInterpreter/Time/Mid0082.cs b/src/OpenProtocolInterpreter/Time/Mid0082.cs index a3421f8e..ca7ebdc5 100644 --- a/src/OpenProtocolInterpreter/Time/Mid0082.cs +++ b/src/OpenProtocolInterpreter/Time/Mid0082.cs @@ -15,8 +15,8 @@ public class Mid0082 : Mid, ITime, IIntegrator public DateTime Time { - get => GetField(1,(int)DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(1,(int)DataFields.Time).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(1, DataFields.Time).SetValue(OpenProtocolConvert.ToString, value); } public Mid0082() : this(new Header() @@ -38,7 +38,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.Time, 20, 19, false) + DataField.Timestamp(DataFields.Time, 20, false) } } }; diff --git a/src/OpenProtocolInterpreter/Tool/Mid0040.cs b/src/OpenProtocolInterpreter/Tool/Mid0040.cs index 136d7bad..805e7e08 100644 --- a/src/OpenProtocolInterpreter/Tool/Mid0040.cs +++ b/src/OpenProtocolInterpreter/Tool/Mid0040.cs @@ -17,8 +17,8 @@ public class Mid0040 : Mid, ITool, IIntegrator, IAnswerableBy public int ToolNumber { - get => GetField(6, (int)DataFields.ToolNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(6, (int)DataFields.ToolNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(6, DataFields.ToolNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(6, DataFields.ToolNumber).SetValue(OpenProtocolConvert.ToString, value); } public Mid0040() : this(DEFAULT_REVISION) @@ -45,7 +45,7 @@ protected override Dictionary> RegisterDatafields() { 6, new List() { - new DataField((int)DataFields.ToolNumber, 20, 4, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.ToolNumber, 20, 4) } }, }; diff --git a/src/OpenProtocolInterpreter/Tool/Mid0041.cs b/src/OpenProtocolInterpreter/Tool/Mid0041.cs index 4372673e..31da0922 100644 --- a/src/OpenProtocolInterpreter/Tool/Mid0041.cs +++ b/src/OpenProtocolInterpreter/Tool/Mid0041.cs @@ -15,114 +15,114 @@ public class Mid0041 : Mid, ITool, IController public string ToolSerialNumber { - get => GetField(1, (int)DataFields.ToolSerialNumber).Value; - set => GetField(1, (int)DataFields.ToolSerialNumber).SetValue(value); + get => GetField(1, DataFields.ToolSerialNumber).Value; + set => GetField(1, DataFields.ToolSerialNumber).SetValue(value); } public long ToolNumberOfTightenings { - get => GetField(1, (int)DataFields.ToolNumberOfTightenings).GetValue(OpenProtocolConvert.ToInt64); - set => GetField(1, (int)DataFields.ToolNumberOfTightenings).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ToolNumberOfTightenings).GetValue(OpenProtocolConvert.ToInt64); + set => GetField(1, DataFields.ToolNumberOfTightenings).SetValue(OpenProtocolConvert.ToString, value); } public DateTime LastCalibrationDate { - get => GetField(1, (int)DataFields.LastCalibrationDate).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(1, (int)DataFields.LastCalibrationDate).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.LastCalibrationDate).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(1, DataFields.LastCalibrationDate).SetValue(OpenProtocolConvert.ToString, value); } public string ControllerSerialNumber { - get => GetField(1, (int)DataFields.ControllerSerialNumber).Value; - set => GetField(1, (int)DataFields.ControllerSerialNumber).SetValue(value); + get => GetField(1, DataFields.ControllerSerialNumber).Value; + set => GetField(1, DataFields.ControllerSerialNumber).SetValue(value); } //Rev 2 public decimal CalibrationValue { - get => GetField(2, (int)DataFields.CalibrationValue).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(2, (int)DataFields.CalibrationValue).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(2, DataFields.CalibrationValue).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(2, DataFields.CalibrationValue).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public DateTime LastServiceDate { - get => GetField(2, (int)DataFields.LastServiceDate).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(2, (int)DataFields.LastServiceDate).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.LastServiceDate).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(2, DataFields.LastServiceDate).SetValue(OpenProtocolConvert.ToString, value); } public long TighteningsSinceService { - get => GetField(2, (int)DataFields.TighteningsSinceService).GetValue(OpenProtocolConvert.ToInt64); - set => GetField(2, (int)DataFields.TighteningsSinceService).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.TighteningsSinceService).GetValue(OpenProtocolConvert.ToInt64); + set => GetField(2, DataFields.TighteningsSinceService).SetValue(OpenProtocolConvert.ToString, value); } public ToolType ToolType { - get => (ToolType)GetField(2, (int)DataFields.ToolType).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.ToolType).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (ToolType)GetField(2, DataFields.ToolType).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.ToolType).SetValue(OpenProtocolConvert.ToString, value); } public int MotorSize { - get => GetField(2, (int)DataFields.MotorSize).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.MotorSize).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.MotorSize).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.MotorSize).SetValue(OpenProtocolConvert.ToString, value); } public OpenEndData OpenEndData { - get => GetField(2, (int)DataFields.OpenEndData).GetValue(OpenEndData.Parse); - set => GetField(2, (int)DataFields.OpenEndData).SetValue(PackOpenEndData, value); + get => GetField(2, DataFields.OpenEndData).GetValue(OpenEndData.Parse); + set => GetField(2, DataFields.OpenEndData).SetValue(PackOpenEndData, value); } public string ControllerSoftwareVersion { - get => GetField(2, (int)DataFields.ControllerSoftwareVersion).Value; - set => GetField(2, (int)DataFields.ControllerSoftwareVersion).SetValue(value); + get => GetField(2, DataFields.ControllerSoftwareVersion).Value; + set => GetField(2, DataFields.ControllerSoftwareVersion).SetValue(value); } //Rev 3 public decimal ToolMaxTorque { - get => GetField(3, (int)DataFields.ToolMaxTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(3, (int)DataFields.ToolMaxTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(3, DataFields.ToolMaxTorque).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(3, DataFields.ToolMaxTorque).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal GearRatio { - get => GetField(3, (int)DataFields.GearRatio).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(3, (int)DataFields.GearRatio).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(3, DataFields.GearRatio).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(3, DataFields.GearRatio).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal ToolFullSpeed { - get => GetField(3, (int)DataFields.ToolFullSpeed).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(3, (int)DataFields.ToolFullSpeed).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(3, DataFields.ToolFullSpeed).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(3, DataFields.ToolFullSpeed).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } //Rev 4 public PrimaryTool PrimaryTool { - get => (PrimaryTool)GetField(4, (int)DataFields.PrimaryTool).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(4, (int)DataFields.PrimaryTool).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (PrimaryTool)GetField(4, DataFields.PrimaryTool).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(4, DataFields.PrimaryTool).SetValue(OpenProtocolConvert.ToString, value); } //Rev 5 public string ToolModel { - get => GetField(5, (int)DataFields.ToolModel).Value; - set => GetField(5, (int)DataFields.ToolModel).SetValue(value); + get => GetField(5, DataFields.ToolModel).Value; + set => GetField(5, DataFields.ToolModel).SetValue(value); } //Rev 6 public int ToolNumber { - get => GetField(6, (int)DataFields.ToolNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(6, (int)DataFields.ToolNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(6, DataFields.ToolNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(6, DataFields.ToolNumber).SetValue(OpenProtocolConvert.ToString, value); } public string ToolArticleNumber { - get => GetField(6, (int)DataFields.ToolArticleNumber).Value; - set => GetField(6, (int)DataFields.ToolArticleNumber).SetValue(value); + get => GetField(6, DataFields.ToolArticleNumber).Value; + set => GetField(6, DataFields.ToolArticleNumber).SetValue(value); } //Rev 7 public decimal RundownMinSpeed { - get => GetField(7, (int)DataFields.RundownMinSpeed).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(7, (int)DataFields.RundownMinSpeed).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(7, DataFields.RundownMinSpeed).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(7, DataFields.RundownMinSpeed).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal DownshiftMaxSpeed { - get => GetField(7, (int)DataFields.DownshiftMaxSpeed).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(7, (int)DataFields.DownshiftMaxSpeed).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(7, DataFields.DownshiftMaxSpeed).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(7, DataFields.DownshiftMaxSpeed).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public decimal DownshiftMinSpeed { - get => GetField(7, (int)DataFields.DownshiftMinSpeed).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(7, (int)DataFields.DownshiftMinSpeed).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(7, DataFields.DownshiftMinSpeed).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(7, DataFields.DownshiftMinSpeed).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public Mid0041() : this(DEFAULT_REVISION) @@ -153,57 +153,57 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ToolSerialNumber, 20, 14, ' '), - new DataField((int)DataFields.ToolNumberOfTightenings, 36, 10, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.LastCalibrationDate, 48, 19), - new DataField((int)DataFields.ControllerSerialNumber, 69, 10, ' ') + DataField.String(DataFields.ToolSerialNumber, 20, 14), + DataField.Number(DataFields.ToolNumberOfTightenings, 36, 10), + DataField.Timestamp(DataFields.LastCalibrationDate, 48), + DataField.String(DataFields.ControllerSerialNumber, 69, 10) } }, { 2, new List() { - new DataField((int)DataFields.CalibrationValue, 81, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.LastServiceDate, 89, 19), - new DataField((int)DataFields.TighteningsSinceService, 110, 10, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ToolType, 122, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.MotorSize, 126, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.OpenEndData, 130, 3), - new DataField((int)DataFields.ControllerSoftwareVersion, 135, 19, ' ') + DataField.Number(DataFields.CalibrationValue, 81, 6), + DataField.Timestamp(DataFields.LastServiceDate, 89), + DataField.Number(DataFields.TighteningsSinceService, 110, 10), + DataField.Number(DataFields.ToolType, 122, 2), + DataField.Number(DataFields.MotorSize, 126, 2), + new(DataFields.OpenEndData, 130, 3), + DataField.String(DataFields.ControllerSoftwareVersion, 135, 19) } }, { 3, new List() { - new DataField((int)DataFields.ToolMaxTorque, 156, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.GearRatio, 164, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ToolFullSpeed, 172, 6, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.ToolMaxTorque, 156, 6), + DataField.Number(DataFields.GearRatio, 164, 6), + DataField.Number(DataFields.ToolFullSpeed, 172, 6) } }, { 4, new List() { - new DataField((int)DataFields.PrimaryTool, 180, 2, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.PrimaryTool, 180, 2) } }, { 5, new List() { - new DataField((int)DataFields.ToolModel, 184, 12, ' ') + DataField.String(DataFields.ToolModel, 184, 12) } }, { 6, new List() { - new DataField((int)DataFields.ToolNumber, 198, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.ToolArticleNumber, 204, 30, ' ') + DataField.Number(DataFields.ToolNumber, 198, 4), + DataField.String(DataFields.ToolArticleNumber, 204, 30) } }, { 7, new List() { - new DataField((int)DataFields.RundownMinSpeed, 236, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.DownshiftMaxSpeed, 244, 6, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.DownshiftMinSpeed, 252, 6, '0', PaddingOrientation.LeftPadded), + DataField.Number(DataFields.RundownMinSpeed, 236, 6), + DataField.Number(DataFields.DownshiftMaxSpeed, 244, 6), + DataField.Number(DataFields.DownshiftMinSpeed, 252, 6), } } }; diff --git a/src/OpenProtocolInterpreter/Tool/Mid0042.cs b/src/OpenProtocolInterpreter/Tool/Mid0042.cs index 9c0ebb2a..e331063d 100644 --- a/src/OpenProtocolInterpreter/Tool/Mid0042.cs +++ b/src/OpenProtocolInterpreter/Tool/Mid0042.cs @@ -13,13 +13,13 @@ public class Mid0042 : Mid, ITool, IIntegrator, IAcceptableCommand public int ToolNumber { - get => GetField(2, (int)DataFields.ToolNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.ToolNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.ToolNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.ToolNumber).SetValue(OpenProtocolConvert.ToString, value); } public DisableType DisableType { - get => (DisableType)GetField(2, (int)DataFields.DisableType).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.DisableType).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (DisableType)GetField(2, DataFields.DisableType).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.DisableType).SetValue(OpenProtocolConvert.ToString, value); } public Mid0042() : this(DEFAULT_REVISION) @@ -45,8 +45,8 @@ protected override Dictionary> RegisterDatafields() { 2, new List() { - new DataField((int)DataFields.ToolNumber, 20, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.DisableType, 26, 2, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.ToolNumber, 20, 4), + DataField.Number(DataFields.DisableType, 26, 2) } }, }; diff --git a/src/OpenProtocolInterpreter/Tool/Mid0043.cs b/src/OpenProtocolInterpreter/Tool/Mid0043.cs index 2eddcf75..7fbd1a95 100644 --- a/src/OpenProtocolInterpreter/Tool/Mid0043.cs +++ b/src/OpenProtocolInterpreter/Tool/Mid0043.cs @@ -13,8 +13,8 @@ public class Mid0043 : Mid, ITool, IIntegrator, IAcceptableCommand public int ToolNumber { - get => GetField(2, (int)DataFields.ToolNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.ToolNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.ToolNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.ToolNumber).SetValue(OpenProtocolConvert.ToString, value); } public Mid0043() : this(DEFAULT_REVISION) @@ -41,7 +41,7 @@ protected override Dictionary> RegisterDatafields() { 2, new List() { - new DataField((int)DataFields.ToolNumber, 20, 4, '0', PaddingOrientation.LeftPadded), + DataField.Number(DataFields.ToolNumber, 20, 4), } }, }; diff --git a/src/OpenProtocolInterpreter/Tool/Mid0045.cs b/src/OpenProtocolInterpreter/Tool/Mid0045.cs index 6f5f85ab..7cca1a85 100644 --- a/src/OpenProtocolInterpreter/Tool/Mid0045.cs +++ b/src/OpenProtocolInterpreter/Tool/Mid0045.cs @@ -21,18 +21,18 @@ public class Mid0045 : Mid, ITool, IIntegrator, IAcceptableCommand, IDeclinableC public CalibrationUnit CalibrationValueUnit { - get => (CalibrationUnit)GetField(1, (int)DataFields.CalibrationValueUnit).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.CalibrationValueUnit).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (CalibrationUnit)GetField(1, DataFields.CalibrationValueUnit).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.CalibrationValueUnit).SetValue(OpenProtocolConvert.ToString, value); } public decimal CalibrationValue { - get => GetField(1, (int)DataFields.CalibrationValue).GetValue(OpenProtocolConvert.ToTruncatedDecimal); - set => GetField(1, (int)DataFields.CalibrationValue).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); + get => GetField(1, DataFields.CalibrationValue).GetValue(OpenProtocolConvert.ToTruncatedDecimal); + set => GetField(1, DataFields.CalibrationValue).SetValue(OpenProtocolConvert.TruncatedDecimalToString, value); } public int ChannelNumber { - get => GetField(2, (int)DataFields.ChannelNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(2, (int)DataFields.ChannelNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(2, DataFields.ChannelNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(2, DataFields.ChannelNumber).SetValue(OpenProtocolConvert.ToString, value); } public Mid0045() : this(DEFAULT_REVISION) @@ -58,14 +58,14 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.CalibrationValueUnit, 20, 1), - new DataField((int)DataFields.CalibrationValue, 23, 6, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.CalibrationValueUnit, 20, 1), + DataField.Number(DataFields.CalibrationValue, 23, 6) } }, { 2, new List() { - new DataField((int)DataFields.ChannelNumber, 31, 2, '0', PaddingOrientation.LeftPadded), + DataField.Number(DataFields.ChannelNumber, 31, 2), } } }; diff --git a/src/OpenProtocolInterpreter/Tool/Mid0046.cs b/src/OpenProtocolInterpreter/Tool/Mid0046.cs index cb9a4681..2dbf916d 100644 --- a/src/OpenProtocolInterpreter/Tool/Mid0046.cs +++ b/src/OpenProtocolInterpreter/Tool/Mid0046.cs @@ -22,13 +22,13 @@ public class Mid0046 : Mid, ITool, IIntegrator, IAcceptableCommand, IDeclinableC public PrimaryTool PrimaryTool { - get => (PrimaryTool)GetField(1,(int)DataFields.PrimaryTool).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.PrimaryTool).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (PrimaryTool)GetField(1, DataFields.PrimaryTool).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.PrimaryTool).SetValue(OpenProtocolConvert.ToString, value); } public Mid0046() : this(new Header() { - Mid = MID, + Mid = MID, Revision = DEFAULT_REVISION }) { @@ -45,7 +45,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.PrimaryTool, 20, 2, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.PrimaryTool, 20, 2) } } }; diff --git a/src/OpenProtocolInterpreter/Tool/Mid0047.cs b/src/OpenProtocolInterpreter/Tool/Mid0047.cs index 4cedb53a..d4841ebf 100644 --- a/src/OpenProtocolInterpreter/Tool/Mid0047.cs +++ b/src/OpenProtocolInterpreter/Tool/Mid0047.cs @@ -24,13 +24,13 @@ public class Mid0047 : Mid, ITool, IIntegrator, IAcceptableCommand, IDeclinableC public PairingHandlingType PairingHandlingType { - get => (PairingHandlingType)GetField(1,(int)DataFields.PairingHandlingType).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.PairingHandlingType).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (PairingHandlingType)GetField(1, DataFields.PairingHandlingType).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.PairingHandlingType).SetValue(OpenProtocolConvert.ToString, value); } public Mid0047() : this(new Header() { - Mid = MID, + Mid = MID, Revision = DEFAULT_REVISION }) { @@ -47,7 +47,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.PairingHandlingType, 20, 2, '0', PaddingOrientation.LeftPadded) + DataField.Number(DataFields.PairingHandlingType, 20, 2) } } }; diff --git a/src/OpenProtocolInterpreter/Tool/Mid0048.cs b/src/OpenProtocolInterpreter/Tool/Mid0048.cs index 997a3e37..6b062c32 100644 --- a/src/OpenProtocolInterpreter/Tool/Mid0048.cs +++ b/src/OpenProtocolInterpreter/Tool/Mid0048.cs @@ -15,13 +15,13 @@ public class Mid0048 : Mid, ITool, IController public PairingStatus PairingStatus { - get => (PairingStatus)GetField(1,(int)DataFields.PairingStatus).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.PairingStatus).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (PairingStatus)GetField(1, DataFields.PairingStatus).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.PairingStatus).SetValue(OpenProtocolConvert.ToString, value); } public DateTime TimeStamp { - get => GetField(1,(int)DataFields.Timestamp).GetValue(OpenProtocolConvert.ToDateTime); - set => GetField(1,(int)DataFields.Timestamp).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.Timestamp).GetValue(OpenProtocolConvert.ToDateTime); + set => GetField(1, DataFields.Timestamp).SetValue(OpenProtocolConvert.ToString, value); } public Mid0048() : this(new Header() @@ -43,8 +43,8 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.PairingStatus, 20, 2, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.Timestamp, 24, 19) + DataField.Number(DataFields.PairingStatus, 20, 2), + DataField.Timestamp(DataFields.Timestamp, 24) } } }; diff --git a/src/OpenProtocolInterpreter/Tool/Mid0701.cs b/src/OpenProtocolInterpreter/Tool/Mid0701.cs index 8ff20514..e18bcd16 100644 --- a/src/OpenProtocolInterpreter/Tool/Mid0701.cs +++ b/src/OpenProtocolInterpreter/Tool/Mid0701.cs @@ -30,16 +30,13 @@ public Mid0701() : this(new Header() public Mid0701(Header header) : base(header) { - if (Tools == null) - { - Tools = new List(); - } + Tools ??= []; } public override string Pack() { - GetField(1, (int)DataFields.TotalTools).SetValue(OpenProtocolConvert.ToString, TotalTools); - var eachToolField = GetField(1, (int)DataFields.EachTool); + GetField(1, DataFields.TotalTools).SetValue(OpenProtocolConvert.ToString, TotalTools); + var eachToolField = GetField(1, DataFields.EachTool); eachToolField.Value = PackTools(); eachToolField.Size = eachToolField.Value.Length; return base.Pack(); @@ -49,7 +46,7 @@ public override Mid Parse(string package) { Header = ProcessHeader(package); - var eachToolField = GetField(1, (int)DataFields.EachTool); + var eachToolField = GetField(1, DataFields.EachTool); eachToolField.Size = Header.Length - eachToolField.Index; ProcessDataFields(package); Tools = ToolData.ParseAll(eachToolField.Value).ToList(); @@ -74,8 +71,8 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.TotalTools, 20, 3, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.EachTool, 23, 3, false) + DataField.Number(DataFields.TotalTools, 20, 3, false), + new(DataFields.EachTool, 23, 3, false) } } }; diff --git a/src/OpenProtocolInterpreter/Tool/Mid0702.cs b/src/OpenProtocolInterpreter/Tool/Mid0702.cs index eaabaacd..2290aae8 100644 --- a/src/OpenProtocolInterpreter/Tool/Mid0702.cs +++ b/src/OpenProtocolInterpreter/Tool/Mid0702.cs @@ -9,8 +9,8 @@ public class Mid0702 : Mid, ITool, IController public int ToolNumber { - get => GetField(1, (int)DataFields.ToolNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ToolNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ToolNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ToolNumber).SetValue(OpenProtocolConvert.ToString, value); } public int NumberOfToolParameters => ToolDataUpload.Count; public List ToolDataUpload { get; set; } @@ -25,20 +25,20 @@ public Mid0702() : this(new Header() public Mid0702(Header header) : base(header) { - ToolDataUpload = new List(); + ToolDataUpload = []; } public override string Pack() { - GetField(1, (int)DataFields.NumberOfToolParameters).SetValue(OpenProtocolConvert.ToString, ToolDataUpload.Count); - GetField(1, (int)DataFields.EachToolDataUpload).Value = OpenProtocolConvert.ToString(ToolDataUpload); + GetField(1, DataFields.NumberOfToolParameters).SetValue(OpenProtocolConvert.ToString, ToolDataUpload.Count); + GetField(1, DataFields.EachToolDataUpload).Value = OpenProtocolConvert.ToString(ToolDataUpload); return base.Pack(); } public override Mid Parse(string package) { Header = ProcessHeader(package); - var dataFieldsField = GetField(1, (int)DataFields.EachToolDataUpload); + var dataFieldsField = GetField(1, DataFields.EachToolDataUpload); dataFieldsField.Size = Header.Length - dataFieldsField.Index; ProcessDataFields(package); ToolDataUpload = VariableDataField.ParseAll(dataFieldsField.Value).ToList(); @@ -52,9 +52,9 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ToolNumber, 20, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.NumberOfToolParameters, 26, 2, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.EachToolDataUpload, 28, 0, false) + DataField.Number(DataFields.ToolNumber, 20, 4), + DataField.Number(DataFields.NumberOfToolParameters, 26, 2, false), + new(DataFields.EachToolDataUpload, 28, 0, false) } } }; diff --git a/src/OpenProtocolInterpreter/Tool/Mid0703.cs b/src/OpenProtocolInterpreter/Tool/Mid0703.cs index 45441d10..eaa21f85 100644 --- a/src/OpenProtocolInterpreter/Tool/Mid0703.cs +++ b/src/OpenProtocolInterpreter/Tool/Mid0703.cs @@ -22,8 +22,8 @@ public class Mid0703 : Mid, ITool, IIntegrator, IAcceptableCommand, IDeclinableC public int ToolNumber { - get => GetField(1, (int)DataFields.ToolNumber).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1, (int)DataFields.ToolNumber).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.ToolNumber).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.ToolNumber).SetValue(OpenProtocolConvert.ToString, value); } public int NumberOfCalibrationParameters => CalibrationParameters.Count; public List CalibrationParameters { get; set; } @@ -38,20 +38,20 @@ public Mid0703() : this(new Header() public Mid0703(Header header) : base(header) { - CalibrationParameters = new List(); + CalibrationParameters = []; } public override string Pack() { - GetField(1, (int)DataFields.NumberOfCalibrationParameters).SetValue(OpenProtocolConvert.ToString, CalibrationParameters.Count); - GetField(1, (int)DataFields.EachCalibrationParameter).Value = OpenProtocolConvert.ToString(CalibrationParameters); + GetField(1, DataFields.NumberOfCalibrationParameters).SetValue(OpenProtocolConvert.ToString, CalibrationParameters.Count); + GetField(1, DataFields.EachCalibrationParameter).Value = OpenProtocolConvert.ToString(CalibrationParameters); return base.Pack(); } public override Mid Parse(string package) { Header = ProcessHeader(package); - var dataFieldsField = GetField(1, (int)DataFields.EachCalibrationParameter); + var dataFieldsField = GetField(1, DataFields.EachCalibrationParameter); dataFieldsField.Size = Header.Length - dataFieldsField.Index; ProcessDataFields(package); CalibrationParameters = VariableDataField.ParseAll(dataFieldsField.Value).ToList(); @@ -65,9 +65,9 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.ToolNumber, 20, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.NumberOfCalibrationParameters, 26, 2, '0', PaddingOrientation.LeftPadded, false), - new DataField((int)DataFields.EachCalibrationParameter, 28, 0, false) + DataField.Number(DataFields.ToolNumber, 20, 4), + DataField.Number(DataFields.NumberOfCalibrationParameters, 26, 2, false), + new(DataFields.EachCalibrationParameter, 28, 0, false) } } }; diff --git a/src/OpenProtocolInterpreter/Tool/Mid0704.cs b/src/OpenProtocolInterpreter/Tool/Mid0704.cs new file mode 100644 index 00000000..edfabba6 --- /dev/null +++ b/src/OpenProtocolInterpreter/Tool/Mid0704.cs @@ -0,0 +1,83 @@ +using System.Collections.Generic; +using System.Linq; + +namespace OpenProtocolInterpreter.Tool +{ + /// + /// Tool Data status reply with generic data + /// + /// Upload requested parameters from given tool. + /// + /// Message sent by: Controller + /// + /// Answer: None + /// + /// + /// The list will contain requested parameters from the tool. + /// + /// + public class Mid0704 : Mid, ITool, IController + { + public const int MID = 704; + + public int NumberOfDataFields + { + get => GetField(1, DataFields.NumberOfDataFields).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.NumberOfDataFields).SetValue(OpenProtocolConvert.ToString, value); + } + public List VariableDataFields { get; set; } + + public Mid0704() : this(new Header() + { + Mid = MID, + Revision = DEFAULT_REVISION + }) + { + + } + + public Mid0704(Header header) : base(header) + { + } + + public override string Pack() + { + var revision = Header.StandardizedRevision; + GetField(revision, DataFields.VariableDataFields).SetValue(OpenProtocolConvert.ToString(VariableDataFields)); + + var index = 1; + return string.Concat(BuildHeader(), base.Pack(revision, ref index)); + } + + public override Mid Parse(string package) + { + Header = ProcessHeader(package); + + var field = GetField(1, DataFields.VariableDataFields); + field.Size = Header.Length - field.Index; + base.Parse(package); + VariableDataFields = VariableDataField.ParseAll(field.Value).ToList(); + return this; + } + + protected override Dictionary> RegisterDatafields() + { + return new Dictionary>() + { + { + 1, new List() + { + DataField.Number(DataFields.NumberOfDataFields, 20, 3, false), + DataField.Volatile(DataFields.VariableDataFields, 23, false) + } + } + }; + } + + protected enum DataFields + { + NumberOfDataFields, + VariableDataFields + } + } +} diff --git a/src/OpenProtocolInterpreter/Tool/ToolMessages.cs b/src/OpenProtocolInterpreter/Tool/ToolMessages.cs index e1f28887..f95f2854 100644 --- a/src/OpenProtocolInterpreter/Tool/ToolMessages.cs +++ b/src/OpenProtocolInterpreter/Tool/ToolMessages.cs @@ -24,7 +24,8 @@ public ToolMessages() : base() { Mid0048.MID, new MidCompiledInstance(typeof(Mid0048)) }, { Mid0701.MID, new MidCompiledInstance(typeof(Mid0701)) }, { Mid0702.MID, new MidCompiledInstance(typeof(Mid0702)) }, - { Mid0703.MID, new MidCompiledInstance(typeof(Mid0703)) } + { Mid0703.MID, new MidCompiledInstance(typeof(Mid0703)) }, + { Mid0704.MID, new MidCompiledInstance(typeof(Mid0704)) } }; } @@ -38,6 +39,6 @@ public ToolMessages(InterpreterMode mode) : this() FilterSelectedMids(mode); } - public override bool IsAssignableTo(int mid) => (mid > 39 && mid < 49) || (mid > 699 && mid < 704); + public override bool IsAssignableTo(int mid) => (mid > 39 && mid < 49) || (mid > 699 && mid < 705); } } diff --git a/src/OpenProtocolInterpreter/UserInterface/Mid0110.cs b/src/OpenProtocolInterpreter/UserInterface/Mid0110.cs index c9c005e7..6d546095 100644 --- a/src/OpenProtocolInterpreter/UserInterface/Mid0110.cs +++ b/src/OpenProtocolInterpreter/UserInterface/Mid0110.cs @@ -26,8 +26,8 @@ public class Mid0110 : Mid, IUserInterface, IIntegrator, IAcceptableCommand, IDe public string UserText { - get => GetField(1,(int)DataFields.UserText).Value; - set => GetField(1,(int)DataFields.UserText).SetValue(value); + get => GetField(1, DataFields.UserText).Value; + set => GetField(1, DataFields.UserText).SetValue(value); } public Mid0110() : base(MID, DEFAULT_REVISION) @@ -46,7 +46,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.UserText, 20, 4, ' ', PaddingOrientation.RightPadded, false), + DataField.String(DataFields.UserText, 20, 4, false), } } }; diff --git a/src/OpenProtocolInterpreter/UserInterface/Mid0111.cs b/src/OpenProtocolInterpreter/UserInterface/Mid0111.cs index d44d9f00..4ee17c5c 100644 --- a/src/OpenProtocolInterpreter/UserInterface/Mid0111.cs +++ b/src/OpenProtocolInterpreter/UserInterface/Mid0111.cs @@ -28,38 +28,38 @@ public class Mid0111 : Mid, IUserInterface, IIntegrator, IAcceptableCommand, IDe public int TextDuration { - get => GetField(1,(int)DataFields.TextDuration).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.TextDuration).SetValue(OpenProtocolConvert.ToString, value); + get => GetField(1, DataFields.TextDuration).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.TextDuration).SetValue(OpenProtocolConvert.ToString, value); } public RemovalCondition RemovalCondition { - get => (RemovalCondition)GetField(1,(int)DataFields.RemovalCondition).GetValue(OpenProtocolConvert.ToInt32); - set => GetField(1,(int)DataFields.RemovalCondition).SetValue(OpenProtocolConvert.ToString, (int)value); + get => (RemovalCondition)GetField(1, DataFields.RemovalCondition).GetValue(OpenProtocolConvert.ToInt32); + set => GetField(1, DataFields.RemovalCondition).SetValue(OpenProtocolConvert.ToString, value); } public string Line1 { - get => GetField(1,(int)DataFields.Line1Header).Value; - set => GetField(1,(int)DataFields.Line1Header).SetValue(value); + get => GetField(1, DataFields.Line1Header).Value; + set => GetField(1, DataFields.Line1Header).SetValue(value); } public string Line2 { - get => GetField(1,(int)DataFields.Line2).Value; - set => GetField(1,(int)DataFields.Line2).SetValue(value); + get => GetField(1, DataFields.Line2).Value; + set => GetField(1, DataFields.Line2).SetValue(value); } public string Line3 { - get => GetField(1,(int)DataFields.Line3).Value; - set => GetField(1,(int)DataFields.Line3).SetValue(value); + get => GetField(1, DataFields.Line3).Value; + set => GetField(1, DataFields.Line3).SetValue(value); } public string Line4 { - get => GetField(1,(int)DataFields.Line4).Value; - set => GetField(1,(int)DataFields.Line4).SetValue(value); + get => GetField(1, DataFields.Line4).Value; + set => GetField(1, DataFields.Line4).SetValue(value); } public Mid0111() : this(new Header() { - Mid = MID, + Mid = MID, Revision = DEFAULT_REVISION }) { @@ -76,12 +76,12 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.TextDuration, 20, 4, '0', PaddingOrientation.LeftPadded), - new DataField((int)DataFields.RemovalCondition, 26, 1), - new DataField((int)DataFields.Line1Header, 29, 25, ' '), - new DataField((int)DataFields.Line2, 56, 25, ' '), - new DataField((int)DataFields.Line3, 83, 25, ' '), - new DataField((int)DataFields.Line4, 110, 25, ' ') + DataField.Number(DataFields.TextDuration, 20, 4), + DataField.Number(DataFields.RemovalCondition, 26, 1), + DataField.String(DataFields.Line1Header, 29, 25), + DataField.String(DataFields.Line2, 56, 25), + DataField.String(DataFields.Line3, 83, 25), + DataField.String(DataFields.Line4, 110, 25) } } }; diff --git a/src/OpenProtocolInterpreter/VariableDataField.cs b/src/OpenProtocolInterpreter/VariableDataField.cs index 46a2e222..8712e3ce 100644 --- a/src/OpenProtocolInterpreter/VariableDataField.cs +++ b/src/OpenProtocolInterpreter/VariableDataField.cs @@ -51,14 +51,12 @@ public object Convert() public string Pack() { - string pack = string.Empty; - pack += OpenProtocolConvert.ToString('0', 5, PaddingOrientation.LeftPadded, ParameterId); - pack += OpenProtocolConvert.ToString('0', 3, PaddingOrientation.LeftPadded, Length); - pack += OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, (int)DataType); - pack += OpenProtocolConvert.ToString('0', 3, PaddingOrientation.LeftPadded, (int)Unit); - pack += OpenProtocolConvert.ToString('0', 4, PaddingOrientation.LeftPadded, StepNumber); - pack += OpenProtocolConvert.TruncatePadded(' ', Length, PaddingOrientation.RightPadded, DataValue); - return pack; + return OpenProtocolConvert.ToString('0', 5, PaddingOrientation.LeftPadded, ParameterId) + + OpenProtocolConvert.ToString('0', 3, PaddingOrientation.LeftPadded, Length) + + OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, (int)DataType) + + OpenProtocolConvert.ToString('0', 3, PaddingOrientation.LeftPadded, (int)Unit) + + OpenProtocolConvert.ToString('0', 4, PaddingOrientation.LeftPadded, StepNumber) + + OpenProtocolConvert.TruncatePadded(' ', Length, PaddingOrientation.RightPadded, DataValue); } public static VariableDataField Parse(string value) diff --git a/src/OpenProtocolInterpreter/Vin/Mid0052.cs b/src/OpenProtocolInterpreter/Vin/Mid0052.cs index 002f23d9..e10244c4 100644 --- a/src/OpenProtocolInterpreter/Vin/Mid0052.cs +++ b/src/OpenProtocolInterpreter/Vin/Mid0052.cs @@ -25,23 +25,23 @@ public class Mid0052 : Mid, IVin, IController, IAcknowledgeable public string VinNumber { - get => GetField(1, (int)DataFields.VinNumber).Value; - set => GetField(1, (int)DataFields.VinNumber).SetValue(value); + get => GetField(1, DataFields.VinNumber).Value; + set => GetField(1, DataFields.VinNumber).SetValue(value); } public string IdentifierResultPart2 { - get => GetField(2, (int)DataFields.IdentifierResultPart2).Value; - set => GetField(2, (int)DataFields.IdentifierResultPart2).SetValue(value); + get => GetField(2, DataFields.IdentifierResultPart2).Value; + set => GetField(2, DataFields.IdentifierResultPart2).SetValue(value); } public string IdentifierResultPart3 { - get => GetField(2, (int)DataFields.IdentifierResultPart3).Value; - set => GetField(2, (int)DataFields.IdentifierResultPart3).SetValue(value); + get => GetField(2, DataFields.IdentifierResultPart3).Value; + set => GetField(2, DataFields.IdentifierResultPart3).SetValue(value); } public string IdentifierResultPart4 { - get => GetField(2, (int)DataFields.IdentifierResultPart4).Value; - set => GetField(2, (int)DataFields.IdentifierResultPart4).SetValue(value); + get => GetField(2, DataFields.IdentifierResultPart4).Value; + set => GetField(2, DataFields.IdentifierResultPart4).SetValue(value); } public Mid0052() : this(DEFAULT_REVISION) @@ -57,7 +57,7 @@ public Mid0052(int revision) : base(MID, revision) { } public override string Pack() { - var vinNumberField = GetField(1, (int)DataFields.VinNumber); + var vinNumberField = GetField(1, DataFields.VinNumber); if (Header.Revision > 1) vinNumberField.HasPrefix = true; @@ -71,19 +71,19 @@ public override Mid Parse(string package) Header = ProcessHeader(package); if (Header.Revision > 1) { - var vinNumberField = GetField(1, (int)DataFields.VinNumber); + var vinNumberField = GetField(1, DataFields.VinNumber); vinNumberField.HasPrefix = true; vinNumberField.Size = Header.Length - 103; if (vinNumberField.Size > 25) { int addedSize = vinNumberField.Size - 25; - GetField(2, (int)DataFields.IdentifierResultPart2).Index += addedSize; - GetField(2, (int)DataFields.IdentifierResultPart3).Index += addedSize; - GetField(2, (int)DataFields.IdentifierResultPart4).Index += addedSize; + GetField(2, DataFields.IdentifierResultPart2).Index += addedSize; + GetField(2, DataFields.IdentifierResultPart3).Index += addedSize; + GetField(2, DataFields.IdentifierResultPart4).Index += addedSize; } } else - GetField(1, (int)DataFields.VinNumber).Size = Header.Length - 20; + GetField(1, DataFields.VinNumber).Size = Header.Length - 20; ProcessDataFields(package); return this; } @@ -95,15 +95,15 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.VinNumber, 20, 25, ' ', PaddingOrientation.RightPadded, false) + DataField.String(DataFields.VinNumber, 20, 25, false) } }, { 2, new List() { - new DataField((int)DataFields.IdentifierResultPart2, 47, 25, ' '), - new DataField((int)DataFields.IdentifierResultPart3, 74, 25, ' '), - new DataField((int)DataFields.IdentifierResultPart4, 101, 25, ' ') + DataField.String(DataFields.IdentifierResultPart2, 47, 25), + DataField.String(DataFields.IdentifierResultPart3, 74, 25), + DataField.String(DataFields.IdentifierResultPart4, 101, 25) } } }; diff --git a/src/OpenProtocolInterpreter/_internals/Messages/MessagesTemplate.cs b/src/OpenProtocolInterpreter/_internals/Messages/MessagesTemplate.cs index 47b10d52..e03d607c 100644 --- a/src/OpenProtocolInterpreter/_internals/Messages/MessagesTemplate.cs +++ b/src/OpenProtocolInterpreter/_internals/Messages/MessagesTemplate.cs @@ -97,7 +97,7 @@ protected void FilterSelectedMids(IEnumerable mids) /// Ignored mid instances private void FilterSelectedMids(IEnumerable mids) { - var ignoredMids = _templates.Where(x => !mids.Contains(x.Value)).ToList(); + var ignoredMids = _templates.Where(x => !mids.Contains(x.Value)); foreach (var ignore in ignoredMids) _templates.Remove(ignore); } diff --git a/src/OpenProtocolInterpreter/_internals/SafeAccessRevisionsFields.cs b/src/OpenProtocolInterpreter/_internals/SafeAccessRevisionsFields.cs index a60452c0..e5a1fb83 100644 --- a/src/OpenProtocolInterpreter/_internals/SafeAccessRevisionsFields.cs +++ b/src/OpenProtocolInterpreter/_internals/SafeAccessRevisionsFields.cs @@ -11,7 +11,7 @@ internal class SafeAccessRevisionsFields : Dictionary> { if (!ContainsKey(index)) { - Add(index, new List()); + Add(index, []); } return this[index]; diff --git a/src/OpenProtocolInterpreter/vin/Mid0050.cs b/src/OpenProtocolInterpreter/vin/Mid0050.cs index 849361bf..ddcdd338 100644 --- a/src/OpenProtocolInterpreter/vin/Mid0050.cs +++ b/src/OpenProtocolInterpreter/vin/Mid0050.cs @@ -22,8 +22,8 @@ public class Mid0050 : Mid, IVin, IIntegrator, IAcceptableCommand, IDeclinableCo public string VinNumber { - get => GetField(1, (int)DataFields.VinNumber).Value; - set => GetField(1, (int)DataFields.VinNumber).SetValue(value); + get => GetField(1, DataFields.VinNumber).Value; + set => GetField(1, DataFields.VinNumber).SetValue(value); } public Mid0050() : base(MID, DEFAULT_REVISION) { } @@ -34,14 +34,14 @@ public Mid0050(Header header) : base(header) public override string Pack() { - GetField(1, (int)DataFields.VinNumber).Size = VinNumber.Length; + GetField(1, DataFields.VinNumber).Size = VinNumber.Length; return base.Pack(); } public override Mid Parse(string package) { Header = ProcessHeader(package); - GetField(1, (int)DataFields.VinNumber).Size = Header.Length - 20; + GetField(1, DataFields.VinNumber).Size = Header.Length - 20; ProcessDataFields(package); return this; } @@ -53,7 +53,7 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.VinNumber, 20, 0, false), //dynamic + DataField.Volatile(DataFields.VinNumber, 20, false), //dynamic } } }; diff --git a/src/OpenProtocolInterpreter/vin/Mid0052.cs b/src/OpenProtocolInterpreter/vin/Mid0052.cs index 002f23d9..e10244c4 100644 --- a/src/OpenProtocolInterpreter/vin/Mid0052.cs +++ b/src/OpenProtocolInterpreter/vin/Mid0052.cs @@ -25,23 +25,23 @@ public class Mid0052 : Mid, IVin, IController, IAcknowledgeable public string VinNumber { - get => GetField(1, (int)DataFields.VinNumber).Value; - set => GetField(1, (int)DataFields.VinNumber).SetValue(value); + get => GetField(1, DataFields.VinNumber).Value; + set => GetField(1, DataFields.VinNumber).SetValue(value); } public string IdentifierResultPart2 { - get => GetField(2, (int)DataFields.IdentifierResultPart2).Value; - set => GetField(2, (int)DataFields.IdentifierResultPart2).SetValue(value); + get => GetField(2, DataFields.IdentifierResultPart2).Value; + set => GetField(2, DataFields.IdentifierResultPart2).SetValue(value); } public string IdentifierResultPart3 { - get => GetField(2, (int)DataFields.IdentifierResultPart3).Value; - set => GetField(2, (int)DataFields.IdentifierResultPart3).SetValue(value); + get => GetField(2, DataFields.IdentifierResultPart3).Value; + set => GetField(2, DataFields.IdentifierResultPart3).SetValue(value); } public string IdentifierResultPart4 { - get => GetField(2, (int)DataFields.IdentifierResultPart4).Value; - set => GetField(2, (int)DataFields.IdentifierResultPart4).SetValue(value); + get => GetField(2, DataFields.IdentifierResultPart4).Value; + set => GetField(2, DataFields.IdentifierResultPart4).SetValue(value); } public Mid0052() : this(DEFAULT_REVISION) @@ -57,7 +57,7 @@ public Mid0052(int revision) : base(MID, revision) { } public override string Pack() { - var vinNumberField = GetField(1, (int)DataFields.VinNumber); + var vinNumberField = GetField(1, DataFields.VinNumber); if (Header.Revision > 1) vinNumberField.HasPrefix = true; @@ -71,19 +71,19 @@ public override Mid Parse(string package) Header = ProcessHeader(package); if (Header.Revision > 1) { - var vinNumberField = GetField(1, (int)DataFields.VinNumber); + var vinNumberField = GetField(1, DataFields.VinNumber); vinNumberField.HasPrefix = true; vinNumberField.Size = Header.Length - 103; if (vinNumberField.Size > 25) { int addedSize = vinNumberField.Size - 25; - GetField(2, (int)DataFields.IdentifierResultPart2).Index += addedSize; - GetField(2, (int)DataFields.IdentifierResultPart3).Index += addedSize; - GetField(2, (int)DataFields.IdentifierResultPart4).Index += addedSize; + GetField(2, DataFields.IdentifierResultPart2).Index += addedSize; + GetField(2, DataFields.IdentifierResultPart3).Index += addedSize; + GetField(2, DataFields.IdentifierResultPart4).Index += addedSize; } } else - GetField(1, (int)DataFields.VinNumber).Size = Header.Length - 20; + GetField(1, DataFields.VinNumber).Size = Header.Length - 20; ProcessDataFields(package); return this; } @@ -95,15 +95,15 @@ protected override Dictionary> RegisterDatafields() { 1, new List() { - new DataField((int)DataFields.VinNumber, 20, 25, ' ', PaddingOrientation.RightPadded, false) + DataField.String(DataFields.VinNumber, 20, 25, false) } }, { 2, new List() { - new DataField((int)DataFields.IdentifierResultPart2, 47, 25, ' '), - new DataField((int)DataFields.IdentifierResultPart3, 74, 25, ' '), - new DataField((int)DataFields.IdentifierResultPart4, 101, 25, ' ') + DataField.String(DataFields.IdentifierResultPart2, 47, 25), + DataField.String(DataFields.IdentifierResultPart3, 74, 25), + DataField.String(DataFields.IdentifierResultPart4, 101, 25) } } };