App-KamstrupKemSplit

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

DESCRIPTION

    This script takes as input a delivery file from Kamstrup (encrypted,
    compressed KEM file), unpacks it and splits the file into different
    decoded XML files that can be further processed.

    Minimal input to the script are the encryption key and the input file.
    If no further configuration file is passed then all information in the
    input file is written to the output file.

    A configuration file consists of a CSV file with `;` as delimeter and
    the following columns:

    kamstrup_ordernr;kamstrup_serial_number_start;kamstrup_serial_number_end;number_of_devices;internal_batch_number

README  view on Meta::CPAN


      Read a CSV configuration file containing the various sub orders.

      CSV needs to be separated with ';' and needs to contain the headers
      'kamstrup_ordernr', 'kamstrup_serial_number_start',
      'kamstrup_serial_number_end', 'number_of_devices' and
      'internal_batch_number'.

    parse_cml_string_to_data

      Convert the XML from the decoded file into a Perl datastructure that
      can be processed programmatorically.

    write_xml_output

      Write the filtered XML to a file taking into account the required
      formatting.

      Takes as input the xml skeleton structure

    write_kem2_xml_output

bin/kamstrup-kem-split.pl  view on Meta::CPAN


kamstrup-kem-split - Splits an encrypted delivery file from Kamstrup into separate XML files with device information

=head1 SYNOPSIS

    ./kamstrup-kem-split.pl --key=<key> [--config=<configfile> --kem=1] inputfile_from_backend

=head1 DESCRIPTION

This script takes as input a delivery file from Kamstrup (encrypted, compressed KEM file), unpacks it and splits the file into different
decoded XML files that can be further processed.

Minimal input to the script are the encryption key and the input file. If no further configuration file is passed then all information
in the input file is written to the output file.

A configuration file consists of a CSV file with `;` as delimeter and the following columns:

C<kamstrup_ordernr;kamstrup_serial_number_start;kamstrup_serial_number_end;number_of_devices;internal_batch_number>

The output file name will be [kamstrup_ordernr]_[internal_batch_number].

lib/App/KamstrupKemSplit.pm  view on Meta::CPAN

use Archive::Zip qw(:ERROR_CODES);
use XML::Simple;
use Crypt::Rijndael;
use MIME::Base64;
use Exporter qw(import);
our @EXPORT = qw(split_order read_config unzip_kem decode_kem parse_xml_string_to_data write_xml_output write_kem2_xml_output);

=head1 DESCRIPTION

This script takes as input a delivery file from Kamstrup (encrypted, compressed KEM file), unpacks it and splits the file into different
decoded XML files that can be further processed.

Minimal input to the script are the encryption key and the input file. If no further configuration file is passed then all information
in the input file is written to the output file.

A configuration file consists of a CSV file with `;` as delimeter and the following columns:

C<kamstrup_ordernr;kamstrup_serial_number_start;kamstrup_serial_number_end;number_of_devices;internal_batch_number>

The output file name will be [kamstrup_ordernr]_[internal_batch_number].

lib/App/KamstrupKemSplit.pm  view on Meta::CPAN

		} else {
			WARN "Skipping line $. of input file because it does not contain the required fields";
		}
	}
	close($data);
	return $content;
}

=item parse_cml_string_to_data

Convert the XML from the decoded file into a Perl datastructure that can be processed programmatorically.

=cut
sub parse_xml_string_to_data {
	my $xml = shift();

	# Write XML to output in order to be able to read it back as data structure
	open( my $fh, '>', "decoded.xml" ) or die "Could not open output file: $!";
	print $fh $xml;
	close $fh;

	# Parse the written XML to data structure
	my $meters = XMLin( "decoded.xml", ForceArray => ['Meter'] );
	unlink 'decoded.xml';
	return $meters;
}

=item write_xml_output

Write the filtered XML to a file taking into account the required formatting.

Takes as input the xml skeleton structure

=cut

lib/App/KamstrupKemSplit.pm  view on Meta::CPAN

		
	}
	
	
	# Write the XML to file and stop
	my $fname = $ordercode . ".xml";
	open( my $fh, '>', $fname ) or die "Could not open output file: $!";
	print $fh $xml;
	close $fh;
	
	INFO "Wrote decoded KEM2 file output to $fname";
	
	return;
}


1;

=back

=head1 AUTHOR



( run in 0.390 second using v1.01-cache-2.11-cpan-26ccb49234f )