<commit_before># ******************************************************************************
# Copyright (C) 2015 <NAME>, All rights reserved.
#
# Santa Rosa, CA 95404
# Tel:(707)536-1330
#

# Control USB Attenuator/Switch/Stacklight microcontroller
# via packet protocol over bulk channel
#
# code lives here: https://github.com/mikef5410/USB_Attenuator_Switch_Stacklight.git
#

package AttenSwitch;
use Device::USB;
use Moose;
use Moose::Exporter;
use MooseX::ClassAttribute;
use namespace::autoclean;
## no critic (BitwiseOperators)
## no critic (ValuesAndExpressions::ProhibitAccessOfPrivateData)
#

=head1 NAME

AttenSwitch - Communicate with USB Attenuator/Switch/Stacklight driver via packet protocol over bulk channel

=head1 VERSION

VERSION 0.01

=cut

our $VERSION = '0.01';

=head1 SYNOPSIS

=over 4

  use strict;
  use warnings;
  use feature qw(switch);
  no warnings 'experimental';

  #Where to find our library and auxiliary code.
  use FindBin qw($Bin);
  use lib $ENV{ATTENSW} || "/projects/usbAtten_controller/perl";

  use lib "$Bin/..";
  use lib "$Bin";

  my $att = shift(@ARGV);

  use AttenSwitch;

  my $dut    = AttenSwitch->new(PID => 0x0003, SERIAL => "138001F0" );
  my $result = $dut->connect();
  if ( $result == AttenSwitch::SUCCESS ) {
     print("Got device\n");
  }

  my $attSel;

  given ($att) {
    when (0)  { $attSel = AttenSwitch::ATTEN->ATT_0DB; }
    when (10) { $attSel = AttenSwitch::ATTEN->ATT_10DB; }
    when (20) { $attSel = AttenSwitch::ATTEN->ATT_20DB; }
    when (30) { $attSel = AttenSwitch::ATTEN->ATT_30DB; }
    when (40) { $attSel = AttenSwitch::ATTEN->ATT_40DB; }
    when (50) { $attSel = AttenSwitch::ATTEN->ATT_50DB; }
    when (60) { $attSel = AttenSwitch::ATTEN->ATT_60DB; }
    when (70) { $attSel = AttenSwitch::ATTEN->ATT_70DB; }
  }
  $dut->atten($attSel);
  printf("ok\n");
  exit;

=back

=head1 DESCRIPTION

This module actually implements three different devices, a Stacklight driver, a step-attenuator driver, and a combo SP8T + SPDT driver.
The drivers are custom designed STM32F411 usb devices that identify with VID:0x4161, and PID:0x0001 for stacklight, 0x0002 for SP8T+SPDT,
and 0x0003 for attenuator. The devices also implement a CDC-ACM device and have a debug monitor running on that interface. The protocol 
used by this module is a simple COMMAND-RESPONSE packet protocol implemented on bulk endpoints 0x1/0x81.

Sources and HW design files live here: https://github.com/mikef5410/USB_Attenuator_Switch_Stacklight.git


=head1 Class Atributes

=over 4

=item *

B<validVids> - An array ref of Vids this module will recognize. Defaults to [ 0x4161, ]

=item *

B<validPids> - An array ref of Pids this module will recognize, Defaults to  [ 0x00ff, 0x0003, 0x0001, 0x0002 ]

=back

=head1 Object Attributes

=over 4

=item *

B<dev> - The underlying USB device (Device::USB::Device)

=item *

B<usb> - The underlying USB bus (Device::USB)

=item *

B<VID> - A specific VID to which we want to connect

=item *

B<PID> - A specific PID to which we want to connect

=item *

B<SERIAL> - A specific USB serial number to which we want to connect

=item *

B<PRODINFO> - When connected, the device identity is queried, and this object reflects that info. It is
a AttenSwitch::ProdInfo object.

=item *

B<verbose> - Boolean, be talkative

=item *

B<timeout_ms> - Number, milliseconds of timeout. Defaults to 500ms

=item *

B<manufacturer> - Manufacturer string. My stuff returns "MF"

=item *

B<product> - Product string.


=back

=cut

# Class Attributes
class_has 'validVids' => (
  is      => 'ro',
  default => sub { [ 0x4161, ] }
);
class_has 'validPids' => (
  is      => 'ro',
  default => sub { [ 0x00ff, 0x0003, 0x0001, 0x0002 ] }
);
class_has 'SUCCESS'    => ( is => 'ro', default => 0 );
class_has 'FAIL'       => ( is => 'ro', default => -1 );
class_has 'CMD_OUT_EP' => ( is => 'rw', default => 0x1 );
class_has 'CMD_IN_EP'  => ( is => 'rw', default => 0x81 );
#<commit_msg>Add usb dual spdt to perl module<commit_after># ******************************************************************************
# Copyright (C) 2015 <NAME>, All rights reserved.
#
# Santa Rosa, CA 95404
# Tel:(707)536-1330
#

# Control USB Attenuator/Switch/Stacklight microcontroller
# via packet protocol over bulk channel
#
# code lives here: https://github.com/mikef5410/USB_Attenuator_Switch_Stacklight.git
#

package AttenSwitch;
use Device::USB;
use Moose;
use Moose::Exporter;
use MooseX::ClassAttribute;
use namespace::autoclean;
## no critic (BitwiseOperators)
## no critic (ValuesAndExpressions::ProhibitAccessOfPrivateData)
#

=head1 NAME

AttenSwitch - Communicate with USB Attenuator/Switch/Stacklight driver via packet protocol over bulk channel

=head1 VERSION

VERSION 0.01

=cut

our $VERSION = '0.01';

=head1 SYNOPSIS

=over 4

  use strict;
  use warnings;
  use feature qw(switch);
  no warnings 'experimental';

  #Where to find our library and auxiliary code.
  use FindBin qw($Bin);
  use lib $ENV{ATTENSW} || "/projects/usbAtten_controller/perl";

  use lib "$Bin/..";
  use lib "$Bin";

  my $att = shift(@ARGV);

  use AttenSwitch;

  my $dut    = AttenSwitch->new(PID => 0x0003, SERIAL => "138001F0" );
  my $result = $dut->connect();
  if ( $result == AttenSwitch::SUCCESS ) {
     print("Got device\n");
  }

  my $attSel;

  given ($att) {
    when (0)  { $attSel = AttenSwitch::ATTEN->ATT_0DB; }
    when (10) { $attSel = AttenSwitch::ATTEN->ATT_10DB; }
    when (20) { $attSel = AttenSwitch::ATTEN->ATT_20DB; }
    when (30) { $attSel = AttenSwitch::ATTEN->ATT_30DB; }
    when (40) { $attSel = AttenSwitch::ATTEN->ATT_40DB; }
    when (50) { $attSel = AttenSwitch::ATTEN->ATT_50DB; }
    when (60) { $attSel = AttenSwitch::ATTEN->ATT_60DB; }
    when (70) { $attSel = AttenSwitch::ATTEN->ATT_70DB; }
  }
  $dut->atten($attSel);
  printf("ok\n");
  exit;

=back

=head1 DESCRIPTION

This module actually implements three different devices, a Stacklight driver, a step-attenuator driver, and a combo SP8T + SPDT driver.
The drivers are custom designed STM32F411 usb devices that identify with VID:0x4161, and PID:0x0001 for stacklight, 0x0002 for SP8T+SPDT,
and 0x0003 for attenuator. The devices also implement a CDC-ACM device and have a debug monitor running on that interface. The protocol 
used by this module is a simple COMMAND-RESPONSE packet protocol implemented on bulk endpoints 0x1/0x81.

Sources and HW design files live here: https://github.com/mikef5410/USB_Attenuator_Switch_Stacklight.git


=head1 Class Atributes

=over 4

=item *

B<validVids> - An array ref of Vids this module will recognize. Defaults to [ 0x4161, ]

=item *

B<validPids> - An array ref of Pids this module will recognize, Defaults to  [ 0x00ff, 0x0003, 0x0001, 0x0002 ]

=back

=head1 Object Attributes

=over 4

=item *

B<dev> - The underlying USB device (Device::USB::Device)

=item *

B<usb> - The underlying USB bus (Device::USB)

=item *

B<VID> - A specific VID to which we want to connect

=item *

B<PID> - A specific PID to which we want to connect

=item *

B<SERIAL> - A specific USB serial number to which we want to connect

=item *

B<PRODINFO> - When connected, the device identity is queried, and this object reflects that info. It is
a AttenSwitch::ProdInfo object.

=item *

B<verbose> - Boolean, be talkative

=item *

B<timeout_ms> - Number, milliseconds of timeout. Defaults to 500ms

=item *

B<manufacturer> - Manufacturer string. My stuff returns "MF"

=item *

B<product> - Product string.


=back

=cut

# Class Attributes
class_has 'validVids' => (
  is      => 'ro',
  default => sub { [ 0x4161, ] }
);
class_has 'validPids' => (
  is      => 'ro',
  default => sub { [ 0x00ff, 0x0003, 0x0001, 0x0002, 0x0004 ] }
 );

# Known devices:
#  0x00ff - unconfigured
#  0x0001 - USB Stacklight
#  0x0002 - MapleOLT serdes RF mux
#  0x0003 - USB Attenuator controller
#  0x0004 - USB Dual SPDT
#  0x0005 - USB air pressure sensor


class_has 'SUCCESS'    => ( is => 'ro', default => 0 );
class_has 'FAIL'       => ( is => 'ro', default => -1 );
class_has 'CMD_OUT_EP' => ( is => 'rw', default => 0x1 );
class_has 'CMD_IN_EP'  => ( is => 'rw', default => 0x81 );
#
{'fraction_non_alphanumeric': 0.14100525865231747, 'fraction_numerical': 0.046104928457869634, 'mean_word_length': 3.9987775061124693, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 91, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6496627', 'n_tokens_mistral': 3158, 'n_tokens_neox': 2839, 'n_words': 888}