# Establishing MVIP switching

The Switching service provides functions to control the underlying MVIP
switching device. It provides functions for:

- Making a connection between an input terminus
  and an output terminus.

- Sending a pattern from an output terminus.

- Breaking a connection between an input terminus and an output terminus and stopping the send pattern.

- Sampling data on an input terminus.

- Querying the board about its switching capabilities.

Use the Switching service functions as described in the following table:

To... | Use...
--- | ---
Reset specified switch block outputs to their idle state | swiDisableOutput
Retrieve the state of specified switch block outputs | swiGetOutputState
Query the device driver and return information about the capabilities of the device driver and the switch controlled by it | swiGetSwitchCaps
Connect inputs to outputs | swiMakeConnection
Connect inputs to outputs with identical throughput delay for all connections | swiMakeFramedConnection
Reset the entire switch block to the idle state | swiResetSwitch
Retrieve the current datum values present on specified switch block inputs | swiSampleInput
Assert fixed patterns on specified switch block outputs | swiSendPattern

Refer to the Switching application example for information on using Switching to develop a call center application.

## Making connections

The Switching service makes a connection between an input terminus and an output terminus with swiMakeConnection or swiMakeFramedConnection.

swiMakeConnection connects inputs to the switch block to outputs from the switch block. For example, it can be used to connect the voice paths of an incoming digital line and an operator station so that the caller and the operator can carry on a conversation.

swiMakeFramedConnection is identical to swiMakeConnection except that all connections made on the same switch device with this function have the same constant throughput delay. Use swiMakeFramedConnection to make a single high bandwidth connection using multiple timeslots
where the data is synchronized across the timeslots.

In the following illustration, the operator station voice signals are on local bus streams 0 and 1. They are connected to the MVIP bus on MVIP streams 0 and 1. To connect the voice streams on the incoming digital line to the operator station's voice streams, connect the incoming digital line's voice streams to MVIP bus streams 1 and 0.

The following example code connects the incoming digital line's voice streams to the operator station's voice streams over the MVIP bus:

/* Connect voice paths of the station interface and incoming call on the T1 interface */
void myConnectVoice(SWIHD t1hd, DWORD timeslot)
{
SWI_TERMINUS output, input;
/* Connect T1 local:0:timeslot to mvip:0:timeslot */
output.bus = MVIP95_MVIP_BUS;
output.stream = 0;
output.timeslot = timeslot;
input.bus = MVIP95_LOCAL_BUS;
input.stream = 0;
input.timeslot = timeslot;
swiMakeConnection(t1hd, &input, &output, 1);
/*
* Make a DUPLEX connection by also connecting
* mvip:1:timeslot to local:1:timeslot
*/
output.bus = MVIP95_LOCAL_BUS;
output.stream = 1;
output.timeslot = timeslot;
input.bus = MVIP95_MVIP_BUS;
input.stream = 1;
input.timeslot = timeslot;
swiMakeConnection(t1hd, &input, &output, 1);
}

## Sending a pattern

Use swiSendPattern to send a fixed eight-bit pattern to an output terminus of the switch block for testing and debugging. swiSendPattern also allows access to low-level signaling on boards that do not support protocols.

The following code issues a known pattern to MVIP:3:0..31:

/* Send a test pattern to 32 timeslots on the CT Bus */
void MySendPattern (SWIHD cxhd)
{
SWI_TERMINUS outputs[32];
BYTE patterns[32];
unsigned count;
/* SendPattern out to operator interfaces via local:3:timeslot */
for (count = 0; count < 32; count++)
{
outputs[count].bus = MVIP95_MVIP_BUS;
outputs[count].stream = 3;
outputs[count].timeslot = (DWORD)count;
patterns[count] = SWI_A_BIT_ON;
}
swiSendPattern(cxhd, patterns, outputs, count);
}

## Disabling output

If an input terminus is connected to an output terminus or if a pattern is being sent out of the output terminus, swiDisableOutput breaks the connection or stops sending the pattern.

For example, to break the connection from the incoming digital line's voice streams to the operator station's voice streams through the MVIP bus, disable the outputs from the incoming digital line's switch block.

Caution: | Disable an output when the connection or pattern is no longer required. Leftover connections or patterns can cause unpredictable behavior in the application.

The following code shows how to break the connection:

void myReconfigureT1Line(SWIHD t1hd, DWORD timeslot)
{
SWI_TERMINUS output;
/* Disable outputs of switch to mvip:0:timeslot */
output.bus = MVIP95_MVIP_BUS;
output.stream = 0;
output.timeslot = timeslot;
swiDisableOutput(t1hd, &output, 1);
/* Disable outputs of switch to local:1:timeslot */
output.bus = MVIP95_LOCAL_BUS;
output.stream = 1;
output.timeslot = timeslot;
swiDisableOutput(t1hd, &output, 1);
}

## Sampling data

To determine the data present on a switch block input terminus, use swiSampleInput.

For example, to read the bits on an incoming analog line, sample the data on the incoming line's timeslot.

The following example code reads the bits on a specified timeslot:

void myPrintInput(SWIHD hd, DWORD bus, DWORD stream, DWORD timeslot)
{
BYTE data;
SWI_TERMINUS input;
input.bus = bus;
input.stream = stream;
input.timeslot = timeslot;
swiSampleInput(hd, &input, &data, 1);
switch (input.bus)
{
case MVIP95_MVIP_BUS:
printf(" %s", " mvip");
break;
case MVIP95_LOCAL_BUS:
printf(" %s", "local");
break;
printf(":%2d:%02d=%02X\n", input.stream, input.timeslot, data);
}

## Querying switch capabilities

To query the device driver and return information about the capabilities of the device driver and the switch block, use swiGetSwitchCaps. For example:

void myPrintSwitchCaps(SWIHD hd)
{
SWI_SWITCHCAPS_ARGS cp;
SWI_LOCALDEV_DESC *localdevs;
swiGetSwitchCaps(hd, &cp, NULL, 0);
localdevs = (SWI_LOCALDEV_DESC *)malloc(
sizeof(SWI_LOCALDEV_DESC)*cp.numlocalstreams);
swiGetSwitchCaps(hd, &cp, localdevs, cp.numlocalstreams);
printf("Driver Software Std. %s Rev. %2.f\n",
((cp.swstandard == MVIP95_STANDARD_MVIP95)? "MVIP-95" :
"MVIP-90"),
(float)cp.swstdrevision/100.0);
printf("Hardware Std. %s Rev. %2.f.\n",
((cp.hwstandard == MVIP95_STANDARD_HMVIP)? "HMVIP" :
"MVIP-90"),
(float)cp.hwstdrevision/100.0);
printf("Driver Rev. %.2f\n", (float)cp.dvrrevision/100.0);
printf(" Domain %04X, Routing %04X, Blocking %04X.\n",
cp.domain, cp.routing, cp.blocking );
if( cp.numlocalstreams > 0 )
{
DWORD i;
printf("Supports %d local streams:\n\t",
cp.numlocalstreams );
for( i=0; i<cp.numlocalstreams; i++ )
printf( "%2d ", i+16 );
printf("with\n\t");
for( i=0; i<cp.numlocalstreams; i++ )
printf( "%2d ", localdevs[i].timeslots );
printf("timeslots respectively.\n");
}
free(localdevs);
}