OpenCores

Subversion Repositories manchesterwireless

[/] [manchesterwireless/] [perlmodel/] [man_encode_decode.pl] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 thiagu_comp
#############################################################################
2
## This code is free software; you can redistribute it and/or
3
## modify it under the terms of the GNU Lesser General Public
4
## License as published by the Free Software Foundation; either
5
## version 2.1 of the License, or (at your option) any later version.
6
##
7
## This code is distributed in the hope that it will be useful,
8
## but WITHOUT ANY WARRANTY; without even the implied warranty of
9
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10
## Lesser General Public License for more details.
11
##
12
## This perl script will parse data in a file, do manchester encoding
13
## / decoding and write the encoded / decoded data in another file.
14
## This file can be executed from command line. The syntax of the
15
## command for encoding is "perl man_encode_decode.pl E". 'E' as an
16
## argument in the command denotes encoding.  The syntax of the
17
## command for decoding is "perl man_encode_decode.pl D". 'D' as an
18
## argument in the command denotes decoding.
19
##
20
##  Revision  Date        Author                Comment
21
##  ########  ##########  ####################  ################
22
##  1.0       26/06/09    M. Thiagarajan        Initial revision
23
##
24
##  Future revisions tracked in Subversion at OpenCores.org
25
##  under the manchesterwireless project
26
#############################################################################
27
#!usr/local/bin/perl
28
 
29
$IP_FILE = "./data_ip.txt";
30
$OP_FILE = "./data_op.txt";
31
 
32
$OPERATION = @ARGV[0];
33
 
34
open ($DATA_IP, "$IP_FILE") || die ("\n***Error: Input file not found");
35
 
36
!(-e $OP_FILE) || unlink $OP_FILE;  #If file found, delete it  
37
open ($DATA_OP,">>".$OP_FILE) || die ("\n***Error: Cannot create output file. Cehck folder permissions.\n");
38
 
39
if ($OPERATION eq "E")  #E - Encode
40
{
41
  $DATA = <$DATA_IP>;
42
  chop ($DATA);
43
  while ($DATA ne "")
44
  {
45
    $SIZE = length ($DATA);
46
    while ($SIZE > 0)
47
    {
48
       $IPBIT = substr ($DATA,($SIZE-1),1);
49
       $DATA =~ s/.$//;
50
       $SIZE--;
51
 
52
       if ($IPBIT == 0)
53
       {$OPBIT = "10";}
54
       elsif ($IPBIT == 1)
55
       {$OPBIT = "01";}
56
 
57
       print $DATA_OP "$OPBIT";
58
     }
59
    print $DATA_OP "\n";
60
    $DATA = <$DATA_IP>;
61
    chop ($DATA);
62
    #print ($DATA,"\n");
63
  }
64
}
65
elsif ($OPERATION eq "D")
66
{
67
  $DATA = <$DATA_IP>;
68
  chop ($DATA);
69
  while ($DATA ne "")
70
  {
71
    $SIZE = length ($DATA);
72
    if (($SIZE % 2) != 0)
73
    {
74
      print ("\n***Error: Improper Data width\n") && die;
75
    }
76
    else
77
    {
78
      while ($SIZE > 0)
79
      {
80
        $IPBIT = substr ($DATA,($SIZE-2),2);
81
        $DATA =~ s/..$//;
82
        $SIZE=$SIZE-2;
83
 
84
        if ($IPBIT == 10)
85
        {$OPBIT = "0";}
86
        elsif ($IPBIT == 01)
87
        {$OPBIT = "1";}
88
 
89
       print $DATA_OP "$OPBIT";
90
       }
91
     }
92
    print $DATA_OP "\n";
93
    $DATA = <$DATA_IP>;
94
    chop ($DATA);
95
  }
96
}
97
else
98
{
99
  print "\n***Error: No Valid arguments in the command\n";
100
  print "***Valid arguments are - 'E' for Encoding; 'D' for Decoding\n\n";
101
  print "***Usage Example:\t\"perl man_encode_decode.pl E\"\n";
102
}

powered by: WebSVN 2.1.0

© copyright 1999-2014 OpenCores.org, equivalent to ORSoC AB, all rights reserved. OpenCores®, registered trademark.