Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- using System.IO;
- using jnsoft.ASAP2;
- using jnsoft.ASAP2.Values;
- /// <summary>
- /// Merge data example.
- ///
- /// - Loading an A2L and it's corresponding datafile (HEX or S19)
- /// - Merging an INCA DCM file (.dcm)
- /// - Save the changed data file
- ///
- /// Usage: ASAP2MergeDataExample A2LFile.a2l DataFileIn.hex|.s19 ImportDataFile.DCM
- /// </summary>
- class Program
- {
- /// <summary>
- /// Main function.
- /// </summary>
- /// <param name="args">The commandline arguments</param>
- /// <returns>Console application exitcode (0 if successful)</returns>
- static int Main(string[] args)
- {
- if (args.Length != 3)
- { // no args -> present usage
- Console.Write($"{Application.ProductName}({Application.ProductVersion}) - ");
- Console.WriteLine("Merge data from a DCM file into a HEX/S19 file\n");
- Console.WriteLine("Required input: An A2L, a corresponding HEX/S19 file and a datafile (DCM) to merge");
- Console.WriteLine($"Usage: {Application.ProductName} A2LFile.a2l datafile.hex|.s19 datafile.dcm");
- Console.WriteLine($"Example: {Application.ProductName} ecu.a2l ecu.hex import.dcm");
- return -1;
- }
- try
- { // parse specified A2L file
- using (var a2lParser = new A2LParser())
- {
- if (!a2lParser.parse(args[0]))
- // not an a2l file
- return -2;
- // Get default memory
- var project = a2lParser.Project;
- var module = project.getNode<A2LMODULE>(true);
- var initialSegments = module.createInitialMemorySegments(false);
- // Parse the data file (HEX or S19)
- var dataFile = DataFile.open(args[1], initialSegments);
- // Parse the DCM file
- var dcmFile = DCMFile.open(args[2], module);
- if (dcmFile == null)
- // failed to open or read the DCM file
- return -3;
- // Importing the DCM file data into the hex file data
- var outFilename = Path.GetFileNameWithoutExtension(args[1]) + ".out" + Path.GetExtension(args[1]);
- dataFile.import(dcmFile.Values.ToArray());
- // save the result
- if (!dataFile.save(outFilename, false))
- // failed to save the resulting hex file
- return -4;
- Console.WriteLine("{0} merged data from {1} with {2}, written to {3}"
- , Application.ProductName
- , Path.GetFileName(args[2])
- , Path.GetFileName(args[1])
- , Path.GetFileName(outFilename)
- );
- return 0;
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Something failed {ex.Message}");
- return -5;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement