#!/usr/bin/perl use strict; use warnings; use Carp; use Data::Dumper; use Tie::IxHash; use Gschem 3; 3. Setup and initialize the global variables.



Similar documents

No Frills Command Line Magento

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

Fuse MQ Enterprise Broker Administration Tutorials

Using SNMP with OnGuard

Activelock Customer Management 1.0

Security whitepaper. CloudAnywhere.

GEO Sticky DNS. GEO Sticky DNS. Feature Description

Smart Trading Apps: Market Entry App User Guide

Software Package Document exchange (SPDX ) Tools. Version 1.2. Copyright The Linux Foundation. All other rights are expressly reserved.

Open Source Used In Cisco Instant Connect for ios Devices 4.9(1)

Architecting the Future of Big Data

Third Party Software Used In PLEK500 (Utility for Win) v1.x.xx.xxx

HIGHSEC eid App Administration User Manual

openssl egg Bindings to the OpenSSL SSL/TLS library Extension for Chicken Scheme Version Thomas Chust

EVault Endpoint Protection 7.0 Single Sign-On Configuration

PeopleSoft Red Paper Series. E-Learning. By: Gregory Sandford, Benjamin Harr, Leo Popov May 2006

Microsoft Windows PowerShell v2 For Administrators

Flask-SSO Documentation

etape Continuous Fluid Level Sensor Operating Instructions and Application Notes

Log Insight Manager. Deployment Guide

1. Install the SOAP Toolkit 3.0 on your computer. This is freely available from msdn.microsoft.com.

Self Help Guides. Create a New User in a Domain

idp Connect for OutSystems applications

Guide to Using DoD PKI Certificates in Outlook 2000

BlackBerry Enterprise Server Resource Kit BlackBerry Analysis, Monitoring, and Troubleshooting Tools Version: 5.0 Service Pack: 2.

[MD5 Message Digests] derived from the RSA Data Security, Inc. MD5 Message Digest Algorithm

AccuTerm 7 Cloud Edition Connection Designer Help. Copyright Zumasys, Inc.

fw1-loggrabber - a command line LEA-client for Checkpoint Firewall-1

Digger Solutions. Intranet Open Source. Administrator s Guide

Stone Edge Integration Guide

Release Notes for. CounterPath Bria iphone Edition CounterPath Bria ipad Edition Version 3.1.0

Integrated Citrix Servers

Installation Guide Supplement

Command Line Interface User Guide for Intel Server Management Software

Azure Multi-Factor Authentication. KEMP LoadMaster and Azure Multi- Factor Authentication. Technical Note

Shrew Soft VPN Client Configuration for GTA Firewalls

BlackBerry Business Cloud Services. Version: Release Notes

System Center Virtual Machine Manager 2012 R2 Plug-In. Feature Description

PetaLinux SDK User Guide. Application Development Guide

PHP Integration Kit. Version User Guide

CORPORATE HEADQUARTERS Elitecore Technologies Ltd. 904 Silicon Tower, Off. C.G. Road, Ahmedabad , INDIA

How To Use The Programs Of Ancient.Org

Radius Integration Guide Version 9

FortiAuthenticator Agent for Microsoft IIS/OWA. Install Guide

Setup Reset Password Portal. CloudAnywhere. Auteur Emmanuel Dreux

Adobe DNG Flat Field Plug-in (1.0) Software Notices and/or Additional Terms and Conditions

Microsoft SharePoint

Installing the Shrew Soft VPN Client

Enterprise Manager to Enterprise Console upgrade guide. Sophos Enterprise Manager version 4.7 Sophos Enterprise Console version 4.7.

8.7. Resource Kit User Guide

Port Following. Port Following. Feature Description

SDN Adaptive Load Balancing. Feature Description

Craig Pelkie Bits & Bytes Programming, Inc. craig@web400.com

Dell Unified Communications Command Suite - Diagnostics 8.0. Data Recorder User Guide

ios Team Administration Guide (Legacy)

Oracle Plug-in for Windows Agent 7.1 User Guide

Installation and Configuration Guide

ANZ TRANSACTIVE - MOBILE

Release Notes. BlackBerry Web Services. Version 12.1

TTL to RS232 Adapter User Guide

Information Assurance Directorate

Protecting Data with a Unified Platform

Oracle s PeopleSoft 9.0 Recruiting and Admissions Changes and Updates for CS Bundle #38

TECHILA INTERCONNECT END-USER GUIDE

EVault Software Microsoft SharePoint 2010/2013 Backup and Restore Guide 7.22

RSA Two Factor Authentication

Installation and Configuration Guide Simba Technologies Inc.

IMX Mobile Proxy Administration

iscsi Quick-Connect Guide for Red Hat Linux

Pulse Redundancy. User Guide

CA DLP. Release Notes for Advanced Encryption. r12.0

Guide to Using DoD PKI Certificates in Outlook

Learn Perl by Example - Perl Handbook for Beginners - Basics of Perl Scripting Language

JP1/Automatic Job Management System 3 - Definition Assistant Description, Operator's Guide and Reference

Self Help Guides. Setup Exchange with Outlook

Hyper V Windows 2012 and 8. Virtual LoadMaster for Microsoft Hyper V on Windows Server 2012, 2012 R2 and Windows 8. Installation Guide

Oracle s PeopleSoft 9.0 Recruiting and Admissions Changes and Updates for CS Bundle #31

Secure Shell (SSH) Protocol

ANZ TRANSACTIVE MOBILE for ipad

Enterprise PeopleTools 8.48 PeopleBook: SQR for PeopleSoft Developers

MICR Check Printing. Quick Start Guide

Import Filter Editor User s Guide

Guide to Securing Microsoft Windows 2000 Encrypting File System

BlackBerry Professional Software For Microsoft Exchange Compatibility Matrix January 30, 2009

Microsoft Dynamics GP. Field Service - Preventive Maintenance

S CHEDULER U SER M ANUAL

Notification messages

Dell Spotlight on Active Directory Server Health Wizard Configuration Guide

[The BSD License] Copyright (c) Jaroslaw Kowalski

EVault Software Oracle Plug-In for Windows Agent 6.85 User Guide

Transcription:

1. Introduction. This program creates a Bill of Materials (BOM) by parsing a gschem schematic file and grouping components that have identical attributes (except for reference designator). Only components that have a reference designator (refdes) are included in the BOM. This program was built using a literate programming tool I am working on which is called pweb. My tool is modeled after the Knuth tool called cweb. Non-catastrophic infelicities should be considered bugs. Sections are numbered, hyperlinks to sections are in red and a list of sections is at the end of the document. 2. Shebang, a couple of my favorite pragmas, the usual suspects and the Gschem library. The Gschem library is used to parse the schematic and place component attributes in a hash. #!/usr/bin/perl use strict; use warnings; use Carp; use Data::Dumper; use Tie::IxHash; use Gschem 3; 3. Setup and initialize the global variables. There are three global variables %Opt, @Schs and %Cfg. %Opt contains key-value pairs for each command-line option that is retrieved by get command-line options. After the command-line options are removed the remaining arguments are treated as schematic filenames to be parsed. @Schs contains the names of the schematics to be parsed. If there were no schematic names on the command-line then @Schs will contain the names of all schematic files in the current directory. If @Schs is empty then the program will exit with an error message. %Cfg contains the configuration file options. Currently the only option is key_fields. The key_fields define the component attributes that will be used to group components. A default list is initialized but can be overwritten using the configuration file. my %Opt; get command-line options 7 ; my @Schs = @ARGV; @Schs = <*.sch> if $#Schs -1; croak "(bom) no schematics to parse" if $#Schs -1; my %Cfg; tie %Cfg, "Tie::IxHash"; %Cfg = (key fields [qw(manufacturer manufacturer part number value device footprint)]); initialize configuration options 8 ; 4. Main Program. After each schematic is read identical components are grouped. To group a component a key is built by concatanating the values for each of the key fields defined in $Cfg{key_fields. For each component with an identical key a refdes is added to %comp_group. For each unique key an entry is added to %first_comp that contains the key and all of the component attributes. Entries in %comp_group have the format: 1

component group key refdes 1 Entries in %first_comp have the format: first refdes in component group list with component group key and component attributes foreach my $sch (@Schs) { my %comp group; my %first comp; tie %comp group, "Tie::IxHash"; tie %first comp, "Tie::IxHash"; $sch = s/\.sch$//; my $bom filename = "$sch.bom"; my $gschem = Gschem 3 new(); $gschem read sch(filename "$sch.sch"); group components with identical attribute values 6 ; output bom 5 ; 5. Output the Bill of Materials. For each component group the common attributes are output followed by a line for each refdes that is in the component group. The example below has two component groups. The first group is of capacitors that are 3900pF and have an 0805 footprint. The second group contains capacitors that are made by TDK and have a part number of C3216X7R1H105K. [bom] value=3900pf footprint=0805 refdes=c1 refdes=c5 manufacturer=tdk manufacturer_part_number=c3216x7r1h105k value=1uf footprint=1206 refdes=c4 refdes=c8 refdes=c40 refdes=c41 refdes=c44 refdes=c45 output bom 5 printf("(bom) creating $bom filename\n"); open(out, " $bom filename") die "Could not open $bom filename for output"; print OUT "[bom]\n"; foreach my $refdes (keys %first comp) { my ($key, @attribs) = @ { $first comp{$refdes ; while (@attribs) { printf(out "%s=%s\n", splice @attribs, 0, 2); 2

my @refdes = (keys % { $comp group{$key ); foreach (@refdes) { print OUT "refdes=$ \n"; print OUT "\n"; close(out) die "Could not close $bom filename"; 6. Group components. Components are grouped using a hash-key built with attribute values. The attribute names used to build the hash-key are in the list referenced by $Cfg{key_fields. The hash-key is a concatenation of attribute values separated by colons. If a required attribute does not have a value then an empty string is used in building the key. For each component a hash-key is built. group otherwise a new group is created. If the hash-key exists then its refdes is added to the component group components with identical attribute values 6 foreach my $refdes ($gschem refdes list) { my $c = $gschem get comp attribs(refdes $refdes); my @attribs; # names and values # Initialize undefined attribute values to an empty string # and save attribute names and values in @attribs foreach (@ { $Cfg{key fields ) { $c {$ = '' unless defined $c {$ ; push @attribs, $, $c {$ ; # Build the key my $key = join(':', map { $c {$ @ { $Cfg{key fields ); # If this is the first component with this key then initialize the # hash containing the refdes's for this component group. Since # the refdes's in this loop are already sorted making this group # hash indexed will preserve the sorting. # An easy way to retreive attribute values for a component group # is to save the attribute values (including refdes) for the first # component in each group. The attribute values and group key for # the first component in each group is saved in the %first comp # hash. unless (defined $comp group{$key) { my %h; tie %h, "Tie::IxHash"; $comp group{$key = \%h; $first comp{$refdes = [ $key, @attribs ]; $comp group{$key{$refdes = 1; 7. There are two command line options for this program cfgfile and debug. The cfgfile option is used to specify the name of a file containing configuration options. Currently the only configuration option is the attribute names that will be used to group identical components. The debug option is used to specify the amount of debugging messages to be printed. When debug is a positive number debugging messages will be output to STDOUT. 3

get command-line options 7 use Getopt::Long; GetOptions('cfgfile=s' \$Opt{cfgfile, 'debug=i' \$Opt{debug); $Opt{cfgfile = './bom.cfg' unless defined $Opt{cfgfile; $Opt{debug = 1 unless defined $Opt{debug; 8. Initialize the configuration options. Lines in the configuration file are in the following format: @ parameter name @ parameter value parameter value can be a single value or a list of values with values separated by vertical bars. initialize configuration options 8 if (-e $Opt{cfgfile) { @ARGV = $Opt{cfgfile; while (<>) { next unless s/ˆ\s*\@(.*?)\@\s*//; # skip lines without parameter names my $param = $1; # only accept parameter names that have already been # initialized in %Cfg. If the configuration parameter was a # scalar then rewrite a scalar value. If the configuration # parameter was an array then split the configuration line and # create an array. next unless defined $Cfg{$param; $Cfg{$param = $, next unless ref($cfg{$param); $Cfg{$param = [ split /\s*\ \s*/ ], next if ref($cfg{$param) eq 'ARRAY'; 9. Style. Adapted from the Perl Cookbook, First Edition, Recipe 12.4 Names of functions and local variables are all lowercase. The program s persistent variables (either file lexicals or package globals) are capitalized. Identifiers with multiple words have each of these separated by an underscore to make it easier to read. Constants are all uppercase. If the arrow operator (->) is followed by either a method name or a variable containing a method name then there is a space before and after the operator. 4

10. License. No-Fee Software License Version 0.2 Intent The intent of this license is to allow for distribution of this software without fee. Usage of this software other than distribution, is unrestricted. License Permission is granted to make and distribute verbatim copies of this software provided that (1) no fee is charged and (2) the original copyright notice and this license notice are preserved on all copies. Permission is granted to make and distribute modified versions of this software under the conditions for verbatim copying provided that the entire resulting derived work is distributed under terms of a license identical to this one. This software is provided by the author AS IS and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the author be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage. 11. Code Sections output bom 5 Used in section 4 group components with identical attribute values 6 Used in section 4 get command-line options 7 Used in section 3 initialize configuration options 8 Used in section 3 5