basic_xenpak.tcl

来自「smartbits二次开发示例代码」· TCL 代码 · 共 418 行 · 第 1/2 页

TCL
418 行
字号
###########################################################################################
# basic_xenpak.tcl                                                                        #
#                                                                                         #
# - Basic start, transmit, capture, display capture frames and profile for Xenpak cards   #
#                                                                                         #
# NOTE: This script works on the following cards:                                         #
#       - XLW-3720A                                                                       #
#       - XLW-3721A                                                                       #
#                                                                                         #
###########################################################################################


#############################################################################
# This proc checks the link LED .                               	    #
# CheckLink waits for 2 seconds or more, until the link is established.     #
# For other cards, CheckLink does not add any delay.                        #
#############################################################################
proc CheckLink {Hub Slot Port} {
    set Model ""
    set card_id [LIBCMD HTGetCardModel Model $Hub $Slot $Port]

    switch $card_id \
        $::CM_LAN_6301A { after 2000 } \
	$::CM_GX_1420B {
	    puts "Checking link status ..."
	    struct_new x Long
	    struct_new ExCardInfo ETHExtendedCardInfo

	    #a 2-second wait is necessary for GX-1420B
		after 2000

	    LIBCMD HTGetEnhancedStatus x $Hub $Slot $Port
	    while {![expr $x(l)&$::GIG_STATUS_LINK]} {
		LIBCMD HTGetStructure $::ETH_EXTENDED_CARD_INFO 0 0 0 ExCardInfo 0 $Hub $Slot $Port
		after 100
		LIBCMD HTGetEnhancedStatus x $Hub $Slot $Port
	    }
	    unset x
	    unset ExCardInfo
	} \
	default {
	    # Skip
	}
}

#############################################################################
# If smartlib.tcl is not loaded, attempt to locate it at the default location.
# The actual location is different on different platforms. 
#############################################################################
if  {$tcl_platform(platform) == "windows"} {
      set libPath "../../../../tcl/tclfiles/smartlib.tcl"
} else {
         set libPath "../../../../include/smartlib.tcl"
}
# if "smartlib.tcl" is not loaded, try to source it from the default path
if { ! [info exists __SMARTLIB_TCL__] } {
     if {[file exists $libPath]} {
          source $libPath
} else {   
               
         #Enter the location of the "smartlib.tcl" file or enter "Q" or "q" to quit
         while {1} {
         
                     puts "Could not find the file $libPath."
                     puts "Enter the path of smartlib.tcl, or q to exit." 
          
                     gets stdin libPath
                     if {$libPath == "q" || $libPath == "Q"} {
                          exit
                     } 
                     if {[file exists $libPath]} {
	                  source $libPath
                          break
                     } 
         } 
   }
}

#############################################################################
# If chassis is not currently linked prompt for IP and link  
#############################################################################
if {[ETGetLinkStatus] < 0} {
     puts "SmartBits not linked - Enter chassis IP address"
     gets stdin ipaddr
     set retval [NSSocketLink $ipaddr 16385 0]  
     if {$retval < 0 } {
	  puts "Unable to connect to $ipaddr. Please try again."
	  exit
     }
}
#############################################################################
# Set the default variables
#############################################################################
set iHub 	0
set iSlot 	0
set iPort 	0

set iHub2 	0
set iSlot2 	1
set iPort2 	0

set FRAME_LENGTH    	100
set PREAMBLE_LENGTH 	8
set FRAME_GAP       	96
set BURST_GAP       	96
set BG1_LENGTH      	0
set BURST_SIZE      	10
set MULTIBURST_SIZE 	5
set Loopback	 	0

#############################################################################
# reserve the cards
#############################################################################
LIBCMD HTSlotReserve $iHub $iSlot
LIBCMD HTSlotReserve $iHub2 $iSlot2
puts "\nReserve iHub $iHub, iSlot $iSlot"
puts "\nReserve iHub2 $iHub2, iSlot2 $iSlot2\n"

# Reset cards
LIBCMD HTResetPort $RESET_FULL $iHub $iSlot $iPort
LIBCMD HTResetPort $RESET_FULL $iHub2 $iSlot2 $iPort2
puts "\nReset iHub $iHub, iSlot $iSlot $iPort"
puts "\nReset iHub2 $iHub2, iSlot2 $iSlot2 $iPort2\n"


# Check the link
CheckLink $iHub $iSlot $iPort
CheckLink $iHub2 $iSlot2 $iPort2
              
# Create structures              
struct_new tx       	GIGTransmit
struct_new counter  	GIGCounterInfo
struct_new packet    	NSCaptureDataInfo
struct_new cap 		NSCaptureSetup
struct_new cap_count 	NSCaptureCountInfo
struct_new fill_pat 	UChar*$FRAME_LENGTH
struct_new Profile       XENPAKProfile

# transmit mode
puts "Transmit single burst mode\n"

# Setup the main background pattern
for {set i 0} {$i < $FRAME_LENGTH } {incr i} {
	set fill_pat($i) 0xAA
}
LIBCMD HTSetStructure $GIG_STRUC_FILL_PATTERN 0 0 0 fill_pat 0 $iHub\
       $iSlot $iPort
puts "Fill background pattern with 0xAA\n"

# Setup the transmit parameters
set tx(uiMainLength)            $FRAME_LENGTH
set tx(ucPreambleByteLength)    $PREAMBLE_LENGTH
set tx(ucFramesPerCarrier)      0
set tx(ulGap)                   $FRAME_GAP
set tx(ucMainRandomBackground)  0
set tx(ucBG1RandomBackground)   0
set tx(ucBG2RandomBackground)   0
set tx(ucMainCRCError)          0
set tx(ucBG1CRCError)           0
set tx(ucBG2CRCError)           0
set tx(ucJabberCount)           0
set tx(ucLoopback)              0
set tx(ulBG1Frequency)          0
set tx(ulBG2Frequency)          0
set tx(uiBG1Length)             0
set tx(uiBG2Length)             0
set tx(uiLinkConfiguration)     $GIG_AFN_FULL_DUPLEX
set tx(uiVFD1Offset)            0
set tx(iVFD1Range)              0
set tx(ucVFD1Mode)              $GIG_VFD_OFF
set tx(ulVFD1CycleCount)        0
for {set i 0} {$i < 8} {incr i} {
    set tx(ucVFD1Data.$i) [expr 0x00]
}
set tx(uiVFD2Offset)            0
set tx(iVFD2Range)              0
set tx(ucVFD2Mode)              $GIG_VFD_OFF
set tx(ulVFD2CycleCount)        0
for {set i 0} {$i < 8} {incr i} {
    set tx(ucVFD2Data.$i) [expr 0x00]
}
set tx(uiVFD3Offset)            0
set tx(uiVFD3Range)             0
set tx(ulVFD3Count)             0
set tx(ucVFD3Mode)              $GIG_VFD3_OFF
set tx(ulBurstCount)            $BURST_SIZE
set tx(ulMultiburstCount)       $MULTIBURST_SIZE
set tx(ulInterBurstGap)         $BURST_GAP
set tx(ucTransmitMode)          $GIG_SINGLE_BURST_MODE
set tx(ucEchoMode)              0
set tx(ucPeriodicGap)           0
set tx(ucCountRcverrOrOvrsz)    0
set tx(ucGapByBitTimesOrByRate) 0
set tx(ucRandomLengthEnable)    0
set tx(uiVFD1BlockCount)        0
set tx(uiVFD2BlockCount)        0
set tx(uiVFD3BlockCount)        0

# Set the transmitting card's transmit parameters
LIBCMD HTSetStructure $GIG_STRUC_TX 0 0 0 tx 0 $iHub $iSlot $iPort

# transmit mode
puts "Number of frames transmit $BURST_SIZE\n"

# Start capture
set cap(ulCaptureMode)   $CAPTURE_MODE_FILTER_ON_EVENTS
set cap(ulCaptureLength) $CAPTURE_LENGTH_ENTIRE_FRAME
set cap(ulCaptureEvents) $CAPTURE_EVENTS_ALL_FRAMES
LIBCMD HTSetStructure $NS_CAPTURE_SETUP 0 0 0 cap 0 $iHub2 $iSlot2 $iPort2

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?