Вы находитесь на странице: 1из 34

TRIANGLE MICROWORKS, INC.

IEC 61850 GOOSE


Source Code Library
User Manual

Version 10.5
September, 2014
Property of Triangle MicroWorks, Inc.

This Documentation and its associated distribution media contain proprietary information of Triangle
MicroWorks, Inc. and may not be copied or distributed in any form without the written permission of
Triangle MicroWorks, Inc.

Copies of the source code may be made only for backup purposes.

© 1994 - 2014 Triangle MicroWorks, Inc. All rights reserved.

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page ii
Table of Contents
1 Introduction ................................................................................................................................................. 1
2 Configuration............................................................................................................................................... 3
2.1 IGOOVEND.H ..................................................................................................................................... 3
3 Target Interface ........................................................................................................................................... 5
4 Application Interface ................................................................................................................................... 9
4.1 IEC Goose Administrative Functions ................................................................................................... 9
4.2 Goose Output Services ......................................................................................................................... 9
4.2.1 Goose Retransmission Strategies ..................................................................................................11
4.3 Goose Input Services ...........................................................................................................................12
4.4 Dataset Inquiry Functions ....................................................................................................................13
4.5 Goose Control Blocks ..........................................................................................................................15
4.6 Triggering Goose Transmissions .........................................................................................................16
4.7 Primary Data Structures .......................................................................................................................19
4.8 Function Call Details ...........................................................................................................................23
4.9 Administrative Functions ....................................................................................................................23
4.10 IEC Goose Output Functions .............................................................................................................23
4.11 IEC Goose Input Functions ...............................................................................................................24
4.12 Dataset Query Functions ...................................................................................................................26
4.13 Utility Functions ................................................................................................................................26
5 Example Implementation ............................................................................................................................27
6 Advanced Topics ........................................................................................................................................31
6.1 Goose Addresses in Substation Configuration Language (SCL) Files ................................................31

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page iii
1 Introduction

Congratulations on your purchase of a Triangle MicroWorks, Inc. (TMW) IEC 61850 Server Source Code
Library. This product is a member of a family of communication protocol libraries supported by Triangle
MicroWorks, Inc. These libraries were designed to be flexible, easy to use, and easily ported to a wide
variety of hardware and software platforms. For these reasons, the Triangle MicroWorks, Inc. Source Code
Libraries will provide an excellent solution to your communication protocol requirements.

Please Note
Your license agreement limits the installation of this source
code library to specific products. Before installing this source
code library in a new target application, check your license
agreement to verify that it allows use on that target
application. Contact Triangle MicroWorks, Inc. for
information about extending the number of target
applications that may use this source code library.

The TMW implementation of the IEC 61850 GOOSE services provides a mechanism for sending and
receiving the standardized messages. The IEC 61850 GOOSE services differ from the GSSE definitions in
that generalized data structures can be exchanged, rather than fixed bit strings. The APIs are quite similar.
The primary distinction is that the application software must handle the encoding and decoding of the
‘payload’ data – the contents of the dataset being exchanged. This TMW library will handle all header
encoding and decoding, retransmission and timeouts, as well as handling the interface to the 802.3 link
layer.

The programming interface is divided into five functional groups: Administrative Functions, Output
services, Input services, DataSet Query services, and Goose Control Block functions. These groups all
work off of a common information base, which is rooted at the IEC_Goose_Context record. The
IEC_Goose_Context record maintains lists of active GOOSE input and output streams, as well as a pointer
to the datalink (802.3) context. Pools of the dynamically allocated data structures (MMSd_Subscription
records) are created at startup and maintained by the TMW software. These records are used for status and
timers for both inputs and outputs.

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 1
Application

Goose Admin Goose Output Goose Input DataSet Inquiry


Services Services Services Services

TMW Library

Bind UnBind Transmit Receive

802.3 Interface

Figure 1 – IEC Goose Service Overview

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 2
2 Configuration
2.1 IGOOVEND.H

This header file contains definitions used to set the operational parameters of the IEC GOOSE package.

USE_MMSD_IN_IEC_GOOSE
Default: On, Range: n/a, DefValue: Ignored
Include this if the IEC Goose library will be used with an MMS server, and make use of MMS server
GOOSE control blocks and Data Sets. The switch allows the library to automatically resolve the query
services (GetGsReference and GetGsDataOffset) against the MMS server dictionary. If the application will
not use an MMS server, remove the definition and replace the following function pointers in the IEC Goose
Context with pointers to custom routines:

 getReferenceReqFcn;
 getReferenceResFcn;
 getElementNumReqFcn;
 getElementNumResFcn;

The standard functions which use the MMS server dictionary can be used as templates for the custom
versions.

IEC_MAX_IDENT
Default: On, Range: 1-66, DefValue: 66
Defines the maximum length of a DataSet member in the IEC Goose implementation of the query services
(GetGsReference and GetGsDataOffset).

MAX_IEC_GOOSE_PROFILES
Default: On, Range: 1-32767, DefValue: 20
Defines the maximum number of outgoing GOOSE Profiles that may be defined. Each Profile defines the
parameters for a single IEC GOOSE output stream retransmission sequence.

IEC_GOOSE_IDENT_SIZE
Default: On, Range: 1-128, DefValue: 65
Defines the maximum length of the gcRef, appId, and dataSetRef strings used in the IEC Goose library.

MAX_IEC_GOOSE_ENTRIES
Default: On, Range: 1-32767, DefValue: 40
Defines the total number of input and output IEC Goose streams that can be active at a given time (pool
size). This can be overridden if the application performs its own pool initialization.

IEC_HOLD_TIME_FUDGE
Default: On, Range: 1-65535, DefValue: 0
Defines the amount in milliseconds to add to IEC Goose retransmission times before timing out. This may
be required on some platforms, particularly of there is some polling loop involved in the IEC Goose
processing.

IEC_GOOSE_MAX_DATA_LEN
Default: On, Range: 1-1517, DefValue: 1517
Defines the maximum number of octets which may be contained in a GOOSE message. This parameter
defines how much storage to reserve for saving the goose messages for delivery/retransmission.

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 3
3 Target Interface
The Goose library requires an interface to access Ethernet services. A common data link interface which
isolates cross-platform differences has been developed which must be ported to support the library. The
interface is defined in the header file TAM_DL.H. Note that two example implementations (Windows and
Linux Ethernet) of this target interface are provided with the library package (in the ETH_WIN directory).

There are two primary data structures used within the common interface: TAM_DL_Context and
TAM_DL_Definition. The context data structure maintains the global information about a specific data
link. Note that each Goose context is associated with one data link context. The library, however, supports
multiple Goose contexts and hence multiple data link contexts operating simultaneously. The
TAM_DL_Context data structure is defined as:

typedef struct TAM_DL_Context {


unsigned long fd; /* File descriptor */
char adapter_name[129]; /* Adapter name */
TAM_Mac_Address mac_address; /* Local address */
TAM_DL_Data_Ind data_indication; /* Indication callback */
TAM_DL_Mgmt_Ind mgmt_indication; /* Not used (was UCA TimeSync) */
TamPool *buffers; /* Points to buffer pool */
TamPool bindings; /* Pool of bind records */
Void *user_ptr; /* Available for custom use */
Int index; /* Identifies this context in lists */
unsigned long r_packet_serial; /* Next packet serial number */
TAM_DL_ContextPtr next; /* Next Datalink context */
TAM_DL_Definition *dl_def; /* Callbacks for services and indications */
TAM_DL_Binding *normal_binds; /* Not used (was OSI bind list) */
TAM_DL_Binding *goose_binds;
TAM_DL_Binding *mgmt_binds; /* Not used (was UCA TimeSync bind list) */
} TAM_DL_Context;

The data link context is returned by the open service function, and is passed to all other service requests
and service callback indication functions. If a data link implementation on a specific platform requires
additional data to be maintained, it can be added to the end of the data link context. In our data link
implementations, we create a platform-specific data link context with the common TAM_DL_Context data
as the header. For example:

typedef struct CUSTOM_DL_Context {


TAM_DL_Context generic; /* Standard header */
unsigned long my_specific_data;
} CUSTOM_DL_Context;

This allows all library routines to access the standard link context information in a standard position within
the data link context. The TAM_DL_Context pointers passed to all service and indication callback routines
can then be cast to the CUSTOM_DL_Context type to access the platform-specific data.

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 5
The data link definition structure (TAM_DL_Definition) contains a set of function pointers which define
the entry points used to invoke services. The structure is defined as:

typedef struct TAM_DL_Definition {


TAM_DL_Open TamDlOpen;
TAM_DL_Close TamDlClose;
TAM_DL_Bind TamDlBind;
TAM_DL_Service TamDlService;
TAM_DL_Receive TamDlReceive;
TAM_DL_Can_Send TamDlCanSend;
TAM_DL_Send TamDlSend;
TAM_DL_Send_Mgmt TamDlSendMgmt; /* Not used (was UCA TimeSync) */
TAM_DL_Connect TamDlConnect; /* Not used (Connection Oriented links) */
TAM_DL_Disconnect TamDlDisconnect; /* Not used (Connection Oriented links) */
TAM_DL_Wait_For_Poll TamDlWaitForPoll; /* Not used (Connection Oriented links) */
TAM_Mac_Address es_address; /* Not used (was OSI) */
TAM_Mac_Address is_address; /* Not used (was OSI) */
} TAM_DL_Definition;

The TAM_DL_Definition structure should be initialized with pointers to the platform specific routines
before linking into the TAM_DL_Context structure. The functions required to support Goose are:

TAM_DL_Context *TAM_DL_Open( char *adapter_name )


This function is called by the library to open the data link service. A text string containing the Ethernet
adapter name is passed. The function should return a pointer to the data link context.

int TAM_DL_Close( TAM_DL_Context *pDlContext )


The close function is used to terminate the data link service. The data link context structure is passed to
identify the data link to be closed. The data link context can safely be freed by the close function – it will
not be referenced again by the library.

int TAM_DL_Bind( TAM_DL_Context *pDlContext,


int nBindType,
TAM_Mac_Address *pMulticastAddress,
int nLsap,
TAM_DL_Ind *pIndicationCallback,
void *pIndicationData )
The bind function is used to associate a multicast address (at which the data link should receive packets)
with an indication function which will be called to accept packets. There are several forms of binding
operations defined for the data link interface, but only the TAM_BIND_GOOSE is required to support the
Goose protocol. The TAM_Mac_Address data structure allows for a wide range of address types. For this
target interface, all addresses will be 6 byte Ethernet MAC addresses.

The indication callback function provided in the call must be invoked when a packet is received which
meets the bind criteria (nBindType, pMulticastAddress, and nLsap). The indication data pointer will be
passed to the indication callback function to allow addressability of application data of the data link user.
The action and calling sequence of the indication function depends on the nBindType. The Goose protocol
is time critical, so that packets which match the Goose bind criteria are simply passed as raw buffers to the
indication callback. OSI binds (not needed for Goose implementations) are resolved by inserting the
packet into an input queue, then invoking the indication callback, which calls the TAM_DL_Receive
function to remove the next packet from the input queue.

Note that the code which maintains the list of binds is quite generic, so that it can generally be taken
directly from the Linux implementation of this routine provided with the library.

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 6
int TAM_DL_UnBind( TAM_DL_Context *pDlContext,
int nBindType,
TAM_Mac_Address *pMulticastAddress,
int nLsap,
TAM_DL_Ind *pIndicationCallback,
void *pIndicationData )
The unbind function is used to terminate the listening for packets at a multicast address. The parameters
must all match those given in the TAM_DL_Bind call.

int TAM_DL_Service( TAM_DL_Context *pDlContext )


The data link service routine is called periodically to allow for any localized processing and to check for
incoming packets. Incoming packets are checked against the list of active bindings. If the addressing
matches, the indication function supplied with the bind service must be called to deliver the packet.

int TAM_DL_Receive( TAM_Packet *pPacket,


TAM_Mac_Address *pMacAddress,
TAM_DL_Context *pDlContext )
This service call is used to remove the next packet from the input queue. It is not required for Goose
implementations, as the raw packet is instead delivered directly to the bound indication callback routine.

int TAM_DL_Can_Send ( TAM_Packet *pPacket,


TAM_Mac_Address *pMacAddress,
TAM_DL_Context *pDlContext )
The Can_Send service routine is called to test the ability of the data link implementation to transmit the
packet to the destination MAC address.

int TAM_DL_Send ( TAM_Packet *pPacket,


TAM_Mac_Address *mac,
TAM_DL_Context *pDlContext )
The TAM_DL_Send service routine is called to transmit the specified packet on the data link. It is the
responsibility of the called service routine to return the packet to the buffer pool when the transmission is
complete.

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 7
4 Application Interface
4.1 IEC Goose Administrative Functions

The Goose Administrative functions establish and manage the Goose context. Note that there can be more
than one Goose context, each associated with a different Ethernet adapter. The Administrative functions
include IEC_Goose_Initialize, IEC_Goose_Service, IEC_Goose_Service_Short and IEC_Goose_Close.

Application

Initialize Service

Tamarack Library

Figure 2 - Administrative Functions

int IEC_Goose_Initialize( IEC_Goose_Context *cntxt )

The IEC_Goose_Initialize function sets up the context record and allocates the pools of input and output
subscription records. This function also opens the 802.3 interface, and establishes the datalink context to
be used for all input and output messages. Note that the adapter name within the context must be initialized
before calling this routine.

void IEC_Goose_Service( IEC_Goose_Context *cntxt )

The IEC_Goose_Service function invokes the datalink service routine, and then scans the list of active
input list for timeouts (Goose hold times exceeded) and the active output list for scheduled retransmissions.
This function must be called periodically by the application software. The time interval between calls to
IEC_Goose_Service will determine the time ‘jitter’ on retransmissions and the latency to detecting timeouts
on received IEC Goose messages.

unsigned long IEC_Goose_Service_Short( IEC_Goose_Context *cntxt )

If the target application is multi-threaded, the datalink service routine is typically being driven from the
primary thread components (TAM_TASK library). In this case, the IEC_Goose_Service_Short is used
instead.

void IEC_Goose_Close( IEC_Goose_Context *cntxt )

The IEC_Goose_Close routine is used to provide a graceful close of the entire Goose context. This ceases
all Goose operations for the given context.

4.2 Goose Output Services


The Goose Output services are used to establish and maintain an output stream. The Goose context must
have been previously initialized before calling any of these functions.

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 9
Application

Create Publish Delete

Tamarack Library

Figure 3 – Goose Output Services

IEC_Goose_Error IEC_Goose_Create( IEC_Goose_Context *cntxt,


char *goID,
char *gocbRef,
char *dsRef,
TAM_Mac_Address *mac,
IEC_Goose_Strategy *strategy,
long confRev,
int numDataSetEntries,
unsigned char *buffer,
MMSd_length length,
void *handle,
unsigned int VLAN_AppID,
unsigned int VLAN_VID,
unsigned char VLAN_Priority )

The IEC_Goose_Create function is called with:

 the IEC_Goose_Context record,


 the gooseId identifier string,
 the full name of the Goose control block,
 the name of the dataset being sent,
 the multicast datalink destination address,
 the retransmission strategy (see below),
 the dataset configuration reference number,
 Number of dataset entries
 a buffer containing the encoded dataset values,
 the length of the encoded data,
 user specified (void *) handle for identifying the goose output stream in later function calls.
 the VLAN parameters (App ID, VLAN ID, Priority)

The function adds the output stream to the list of active outputs, sends the initial IEC goose messages, and
initializes the timer for retransmission.

IEC_Goose_Error IEC_Goose_CreateOut( IEC_Goose_Context *cntxt,


char *goID,
char *gocbRef,
char *dsRef,
TAM_Mac_Address *mac,
IEC_Goose_Strategy *strategy,
long confRev,

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 10
unsigned char ndsCom,
unsigned char test,
int numDataSetEntries,
unsigned char *buffer,
MMSd_length length,
void *handle,
unsigned int VLAN_AppID,
unsigned int VLAN_VID,
unsigned char VLAN_Priority )

The IEC_Goose_CreateOut function is the same as IEC_Goose_Create but adds support for the ndsCom
and test parameters.

int IEC_Goose_Delete( IEC_Goose_Context *cntxt,


void *handle )

The IEC_Goose_Delete function is called with the user-specified handle (as passed to the
IEC_Goose_Create function) to stop a goose output stream and free all associated storage.

int IEC_Goose_Publish( IEC_Goose_Context *cntxt,


void *handle,
int numDataSetEntries,
unsigned char *buffer,
int offset,
int length )

The IEC_Goose_Publish function is called with the user-specified handle (as passed to the
IEC_Goose_Create function) and a buffer containing the encoded dataset values to transmit. The
IEC_Goose_Publish function transmits the updated values, stores them for later retransmissions, and
restarts the retransmission sequence for the output stream.

4.2.1 Goose Retransmission Strategies


The Goose protocol as defined by IEC 61850 includes a retransmission scheme to enhance reliability, allow
for some level of connection maintenance, and to provide a mechanism for new subscribers to receive
initialization data. When a change of value is detected within the Goose output dataset, the publisher sends
a new Goose message containing the new dataset values, an incremented StNum value to signal the change,
and SqNum equal to zero. The publisher then begins a retransmission sequence, with each retransmission
containing the same data and StNum, with an increasing SqNum value. Each message contains a hold time,
which is an interval (milliseconds) during which subscribers should expect the next retransmission. This
allows the subscribers to sense a loss of connectivity. The times of retransmission are a local issue to the
publisher, but are typically determined by the types of applications the Goose output stream is intended to
support.

The initial retransmissions following a data change (and following the initial Goose enable or startup)
are used to enhance the reliability of the protocol. A typical connection-oriented communications protocol
involves the sender waiting for an acknowledgement from the receiver. If the acknowledgement doesn’t
come soon enough, the sender retransmits the message and again waits for an acknowledgement. This
introduces significant time loss due to errors, and is also complicated when using a multicast mechanism
such as Goose. The Goose protocol is based on the idea of assuming the acknowledgements did not come,
and so issues the retransmission in all cases. As time passes, however, the retransmissions become less
useful – either the receivers have all received the data, or they are likely too late to act on the change
anyway. This approach then is best with short retransmission intervals immediately after each data change,
with intervals increasing up to some maximum interval. The maximum interval is the maximum time that a
new subscriber will have to wait for its initial dataset values, and also defines the maximum interval that a
loss of connectivity will be detected.

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 11
The TMW Goose software includes a very flexible yet simple mechanism for defining the retransmission
schemes for Goose outputs. There are two Goose strategy types: arithmetic and profile. The arithmetic
scheme has three parameters: first interval, multiplier, and maximum interval. The first retransmission
occurs after the first interval time. Each subsequent interval is the product of the last interval times the
multiplier, until the maximum interval is reached. Thus, for first interval = 2, multiplier = 2, and maximum
interval = 30000, the retransmissions will occur at intervals beginning at 2, and doubling each time until the
maximum interval is reached (2, 4, 8, 16, 32, … 30,000).

The profile scheme allows for a specific set of intervals to be specified. Each interval (specified in
milliseconds) is used in sequence. When the last specified interval has been used, the parameters of the
arithmetic scheme are then used for subsequent intervals (including the maximum retransmission interval).

The data structure IEC_Goose_Strategy includes a strategyType (values are IEC_Goose_Arithmetic and
IEC_Goose_Profile), as well as the parameters for each strategy type. If the strategyType is
IEC_Goose_Arithmetic, then only that strategy is used and the profile parameters are ignored. If the
strategyType is IEC_Goose_Profile, then the profile values are used first, followed by the arithmetic
algorithm. A pointer to an IEC_Goose_Strategy must be passed to IEC_Goose_Create when initiating a
Goose output stream.

4.3 Goose Input Services


The Goose Input Services are used to manage subscriptions to externally generated Goose streams.

Application

Subscribe Indicate Unsubscribe

Tamarack Library

Figure 4 – Goose Input Services

int IEC_Goose_Subscribe( IEC_Goose_Context *cntxt,


char *goID,
char *gocbRef,
TAM_Mac_Address *mac,
unsigned int AppID,
void *handle,
IEC_Goose_Indication callBack,
void *callBackData )

The IEC_Goose_Subscribe function is used to establish a goose input stream. The application code calls
the function with

 the IEC_Goose_Context record,


 the gooseId string identifier,
 the Goose control block reference string,
 the multicast data link destination address,

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 12
 the VLAN AppId, which identifies the application using the VLAN,
 a user specified (void *) handle for identifying the goose output stream in later function calls,
 an indication function to be called upon either receipt of new data or on timeout of the goose stream,
 a user specified (void *) parameter to be passed to the indication function.

The subscribe function sets up the multicast address binding in the data link interface and adds the input
stream to the list of active inputs. Upon receipt of the first goose message for the input stream (and
whenever a message with a new StNum parameter is received) the indication callback function is invoked
with the decoded message header and a pointer and length of the dataset values to be decoded in the
message. Upon timeout (expiration of the most recent holdTime interval without receipt of a new
message), the indication callback function will be invoked with the most recently decoded message header
and with a NULL data pointer.

int IEC_Goose_Unsubscribe( IEC_Goose_Context *cntxt,


void *handle )

The IEC_Goose_Unsubscribe function deletes the input stream, cancels the datalink binding, and frees all
memory associated with the input stream.

int IEC_Goose_SetInitialWait( IEC_Goose_Context *cntxt,


void *handle,
unsigned long timeToWait )

IEC_Goose_SetInitialWait function is used to set a maximum time (ms) to wait for the first message in a
subscribed Goose stream. The stream is identified by the handle as supplied to the IEC_Goose_Subscribe
function. If an input Goose message is not received before the timer expires, the callback function assigned
by IEC_Goose_Subscribe will be called with a timeout indication. Once the first Goose message is
received from a Goose input stream, timeouts will be signaled based on the hold times specified in each
Goose message.

4.4 Dataset Inquiry Functions


The Dataset Inquiry functions provide a simple mechanism to manage the exchange of dataset definitions
between IEC goose peers. These services are used to validate the local view of the dataset members against
the sender’s dataset definition. The services involve sending a single request message to the publisher of
the Goose stream to request information, and receiving and decoding the response message. The field
configuration of the datalink MAC addresses (which are tied to the specific Ethernet hardware used by the
devices) is a significant problem. To avoid this, the TMW software uses the source address from the last
received Goose message on the stream. This, however, means that at least one message must have been
received prior to invoking these requests. The response indications are signaled via callback functions
which are stored in the IEC_Goose_Context. The user must initialize the callback functions and callback
parameters after calling IEC_Goose_Initialize and before calling the request functions. Note that an
additional callback function (notSupportedResFcn and notSupportedResParam) is included in the
IEC_Goose_Context. These pointers should be initialized as well, as this callback function is called if the
remote Goose publisher does not support the DataSet Inquiry functions.

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 13
IEC_Goose_Error IEC_Goose_GetReference( IEC_Goose_Context *cntxt,
void *handle,
unsigned long stateId,
int *pElements,
int numElements )

The IEC_Goose_GetReference function is called with

 IEC_Goose_Context record,
 a user-supplied (void *) handle indicating which peer goose input stream is to be used for the inquiry,
 an arbitrary unsigned long integer identification number which will be used to resolve the response,
 an array of integer indexes of dataset members to be resolved,
 the number of integer indexes in the array,

A GetReferenceRequest message is encoded and sent to the datalink (directed) source address of the last
goose message received for the indicated stream. Upon receipt of a matching response message, the library
will invoke the callback indication function with the user-supplied parameter, both of which are maintained
in the IEC_Goose_Context (getReferenceResFcn, and getReferenceResParam). The callback function is
invoked with the unsigned long identification number (echoed from the request) Goose control block name,
the dataset name and configuration revision number, a pointer and length for the response data (ASN.1
encoding of a list of character strings) within the response message or an error code (if an error is received).
The data pointer and length can be inserted into an MMSd_descriptor, and the standard ASN.1 decode
functions (e.g. MMSd_fetchSTRING) can be used to retrieve the data. It is the responsibility of the
application code to manage timeouts and error recovery.

IEC_Goose_Error IEC_Goose_GetElementNumber( IEC_Goose_Context *cntxt,


void *handle,
unsigned long stateId,
char **Elnamelist )

The IEC_Goose_GetElementNumber function operates in the same way, except that the call includes an
array of character strings (NULL terminated), and the pointer passed to the callback indication function
will point to a list of integer member indices. The callback function and data pointer in the
IEC_Goose_Context for IEC_GooseElementNumber are getElementNumResFcn and
getElementNumResFcn.

Application
Subscriber Role Publisher Role

GetElem GetElem GetRefer GetRefer GetElem GetRefer


Request RespInd Request RespInd ReqInd ReqInd

Tamarack Library

Figure 5 – Dataset Inquiry Services


The server side of the Dataset Inquiry services is implemented using user-supplied callback indication
function pointers which are stored by the application in the IEC_Goose_Context record. The callback
indication function referenced by the getReferenceReq pointer is invoked when a GetReferenceRequest is

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 14
decoded, passing a user-supplied (void *) parameter, the VisibleString dataset reference, and a pointer to
the list of VisibleString names being queried. The callback indication function must return a static buffer
containing the encoded list of index numbers for the response, along with the datset configuration identifier
(unsigned long). The getElementNumReq callback indication function operates in a similar manner.

4.5 Goose Control Blocks


The Goose Control Block software interfaces the Goose package with the MMS model implemented in a
server. Some systems may not use this feature, since some devices may support Goose but not MMS. If
support for both is used in your device, this software provides for a very simple mechanism of tying the
two together.

Note that to use this software, you must still set up the IEC Goose context and configure the interface just
as before. This software rides on top of the rest of the Goose package. All of the routines described here
are implemented in IECGOOSE\IGOCB.C, with prototypes and constants defined in
IECGOOSE/IECGOOSE.H.

The assumption within the IEC 61850 specification is that each device supporting both Goose and MMS
will implement a Goose Control Block (GoCB), defined to be in functional component GO, under LLN0.
The IEC 61850 naming convention for GoCBs is unclear within the standard. For the example
applications, we have chosen to follow the same conventions for GoCBs as is used for Report Control
Blocks: rcbXX, where XX is derived from the name of the Datat Set associated with the control block at
boot time. Thus the name for the default Goose Control Object within LLN0 (which references is
LLN0$ST) is goST. When mapped to the MMS Named Variables, this becomes LLN0$GO$goST. When
generating MMS dictionaries, you can name them anything you wish – the software is driven by the class
of the object, not its name.

There is some question as to how many Goose Control Blocks can exist within a device. This software
allows for any number of Goose Control Blocks, each representing a distinct Goose Output stream.

The support for Goose Control Blocks includes the code for the read/write handlers of the attributes within
a Goose Control Block. The following primitive object classes have been defined within the file
CLASSLIB\GOCB.MMS:

MMSd_GoEna
MMSd_GoID
MMSd_GoDatSet
MMSd_GoConfRev
MMSd_GoNdsCo
MMSd_GoDstAddr
MMSd_GoPriority
MMSd_GoVid
MMSd_GoAppid

These correspond to the attributes of a GoCB. When the GoCB attribute GoEna is written with a value that
causes it to make the transition from FALSE to TRUE, the write handler automatically starts up a new
Goose output stream. When it makes the transition from TRUE to FALSE, the corresponding Goose
output stream is stopped and freed. All of these handlers assume that they are mapped to an instance of the
internal TMW control block structure for maintaining the status of the output stream.

Note that you may not want to grant write access to the Goose Control Blocks, requiring a re-configuration
to change the Goose parameters. This can be accomplished by setting the primitive classes to
READONLY, which clears the MMSd_OPT_read option bit for the class.

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 15
To use the Goose Control Block implementation, the file CLASSLIB\GOCB.MMS must be included in
your model files and the #define USE_MMSD_IN_IEC_GOOSE must be included in your
MAKE7\IGOOVEND.H file. In addition, the following logic must be done within your application code:

//After initializing your MMS dictionary:


#if defined(USE_MMSD_IN_IEC_GOOSE)
MMSd_GooseControlSetAllContext( &mms_context, (void *) &iec_goose_cntxt );
MMSd_GooseControlStartAll( &mms_context, iec_goose_buffer, iec_goose_buffer_len );
#endif

//During normal operation of the device:


Trigger Goose transmission (see discussion below)

//To stop all Goose transmissions before shutting down the Goose API:
#if defined(USE_MMSD_IN_IEC_GOOSE)
MMSd_GooseControlStopAll( &mms_context );
#endif

The buffer used in each of these calls should be the maximum size needed to encode the longest DataSet
used by any Goose Control Block. The maximum allowable size for the data portion of a Goose message is
defined by MAX_IEC_GOOSE_DATASET_BUFFER.

All of the prototypes and constant definitions used are defined in IECGOOSE\IECGOOSE.H. The routines
used are:

void MMSd_GooseControlSetAllContext( MMSd_context *pMmsContext,


void *pContext )

This routine goes through the list of Goose Control Blocks defined in the model and links them with the
IEC Goose context. This is required to allow them access to the Goose interface.

void MMSd_GooseControlStartAll( MMSd_context *pMmsContext,


unsigned char *buffer,
int bufferSize )

This routine goes through the list of Goose Control Blocks defined in the model and, if enabled with a valid
datSet configured, starts the Goose output stream for than control block.

void MMSd_GooseControlStopAll( MMSd_context *pMmsContext )

This routine goes through the list of Goose Control Blocks defined in the model and stops all active Goose
output streams.

The triggering of the Goose send messages can be done at any one of several levels, based on your
application requirements. The options for implementing the Goose triggers are discussed in the next
section.

4.6 Triggering Goose Transmissions


The Goose service is intended for highly time-critical critical applications, so that any time delay between a
change in the application data state and the actual transmission of the Goose update message must be
minimized. The Goose Control Block software allows you to work at any one of several levels, based on
your requirements and the architecture of your software. The simplest to implement (and the most
inefficient operationally) is to use MMSd_GooseControlScanAllData, which scans all data sets referenced
by Goose control blocks for changes by calling all evaluation functions.

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 16
If your software can detect directly when Goose messages are to be sent, then never call
MMSd_GooseControlScanAllData, but instead call MMSd_GooseControlReadDatSet followed by
MMSd_GooseControlReport whenever the Goose message needs to be sent. The following text describes
the interface to these routines and several support routines. Your code must be aware of changes to the
Goose Control Block parameters. Either make the control blocks READONLY, or have the control block
handlers notify your code of changes to the parameters. The DatSet and GoEna are the crucial ones that
must be respected.

void MMSd_GooseControlScanAllData( MMSd_context *pMmsContext,


unsigned char *buffer,
int length )

Scans all Goose Control Blocks within the entire model, executing each evaluation handler and transmitting
each goose that had at least one dataset member changed.

int MMSd_GooseControlReadDatSet( void *handle,


unsigned char *buffer,
int bufferSize,
int *dataOffset,
int *dataLength )

Encodes the data set referenced by the Goose Control Block identified by the handle into the buffer.
Returns the number of bytes encoded, or zero to signal failue. The encoded data resides in the buffer at
offset ‘dataOffset’, for length ‘dataLength’. The handle of a Goose Control Block can be retrieved using
MMSd_GooseControlGetHandle.

int MMSd_GooseControlReport( void *handle,


unsigned char *buffer,
int length )

Transmits the data within the buffer as the dataset for the Goose Control Block referenced by handle. The
handle of a Goose Control Block can be retrieved using MMSd_GooseControlGetHandle.

char * MMSd_GooseControlGetGcbName( void *handle )

Retrieves the name of the Goose Control Block referenced by handle.

void * MMSd_GooseControlGetHandle( MMSd_context *pMmsContext,


char *GcbName )

Retrieves the handle of the Goose Control Block named GcbName. Note that the name must be of the form
<domainName>/<controlBlockname>, where <domainName> is empty for VMD-specific control blocks.
The <controlBlockName> is the name of the MMS variable representing the control block (including
functional component name).

void * MMSd_GooseControlGetStrategy( void *handle )

Returns a pointer to the strategy definition for the Goose output stream. The pointer should be cast as
(IEC_Goose_Strategy *) to get access to the values. The strategy can be modified by your software, but it
is safest to disable and re-enable the goose using MMSd_GooseControlStop and
MMSd_GooseControlStart.

int MMSd_GooseControlSetStrategy( void *handle,


/* IEC_Goose_Strategy */ void *pStrategy )

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 17
Sets the IEC Goose strategy for the Goose Control Block referenced by handle to a new one. It is safest to
disable and re-enable the goose using MMSd_GooseControlStop and MMSd_GooseControlStart when
using this routine.

int MMSd_GooseControlGetGoEna( void *handle )

Retrieves the value of the GoEna (Goose Enable) attribute of the Goose Control Block referenced by
handle. The returned value is zero if the block is currently disabled, non-zero oherwise.

int MMSd_GooseControlSetGoEna( void *handle,


char *DatSet )

Sets the value of the GoEna (Goose Enable) attribute of the Goose Control Block referenced by handle.
This will have the side-effect of starting up the Goose output stream, assuming all of the parameters (like
DatSet) have been properly initialized. This should NOT be called until after the call is made to
MMSd_GooseControlSetAllContexts.

int MMSd_GooseControlGetDataSet( void *handle,


char *DatSet )

Retrieves the name of the dataset configured for the Goose Control Block referenced by handle. The
dataset name is of the form <domainName>/<dataset>, and represents the name of the MMS Named
Variable List.

int MMSd_GooseControlSetDataSet( void *handle,


char *DatSet )

Sets the dataset configured for the Goose Control Block referenced by handle. The dataset name is of the
form <domainName>/<dataset>, and represents the name of the MMS Named Variable List.

int MMSd_GooseControlGetLanPars( void *handle,


TAM_Mac_Address *pAddress,
unsigned int *VLAN_AppID,
unsigned int *VLAN_VID,
unsigned char *VLAN_Priority )

Retrieves the LAN parameters (MAC Address and VLAN parameters) configured for the Goose Control
Block referenced by handle.

int MMSd_GooseControlSetLanPars( void *handle,


TAM_Mac_Address *pAddress,
unsigned int VLAN_AppID,
unsigned int VLAN_VID,
unsigned char VLAN_Priority )

Sets the LAN parameters (MAC Address and VLAN parameters) configured for the Goose Control Block
referenced by handle.

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 18
4.7 Primary Data Structures

The following data structures are used as part of the interface to the IEC Goose library.

typedef struct IEC_GooseHeader {


char gocbRef[IEC_GOOSE_IDENT_SIZE];
unsigned long HoldTim;
char datSet[IEC_GOOSE_IDENT_SIZE];
char goID[IEC_GOOSE_IDENT_SIZE];
MMSd_UtcBTime t;
unsigned long StNum;
unsigned long SqNum;
unsigned char test;
long confRev;
unsigned char ndsCom;
unsigned long numDataSetEntries;
unsigned int VLAN_AppID;
unsigned int VLAN_VID;
unsigned char VLAN_Priority;
unsigned char *pSecurity;
int nSecurityLen;
} IEC_GooseHeader;

typedef unsigned long IEC_GooseInterval;

/* Since its not standardized yet, we include various options for


* specifying the GOOSE time sequence:
*
* Arithmetic - next interval = last_interval * multiplier
* Profiles - user-specified intervals, after which one of the
other
* two types are used.
*/
typedef enum { GOOSE_Disabled, GOOSE_Arithmetic, GOOSE_Profile }
IEC_GooseType;

typedef struct { /* GOOSE_Arithmetic */


unsigned long multiplier;
IEC_GooseInterval firstInterval;
IEC_GooseInterval maxInterval;
} IEC_GooseAriPars;

typedef struct { /* GOOSE_Profile */


int numProfiles;
int currentIndex;
IEC_GooseInterval profiles[MAX_GOOSE_PROFILES];
} IEC_GooseProPars;

typedef struct {
IEC_GooseType strategyType;
IEC_GooseAriPars ari;
IEC_GooseProPars pro;
} IEC_Goose_Strategy;

typedef struct IEC_Goose_Context *IEC_Goose_ContextPtr;

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 19
typedef struct IEC_GooseStatus {
MMSd_time timeStarted;
MMSd_time timeLastSent;
MMSd_time timeNext;
IEC_GooseInterval currentInterval;
IEC_GooseInterval nextInterval;
TAM_Mac_Address address;
TAM_Mac_Address srcAddress;
IEC_Goose_Strategy strategy;
IEC_GooseHeader header;
IEC_Goose_ContextPtr goose_context;
unsigned char goose_data[ IEC_GOOSE_MAX_DATA_LEN ];
int goose_data_len;
} IEC_GooseStatus;

/* Goose indication callback function pointer */


typedef void (* IEC_Goose_Indication)( void *handle,
void *param,
IEC_GooseHeader *header,
unsigned char *dataPtr,
MMSd_length dataLength,
int timed_out );

typedef int (* IEC_Goose_GetReferenceReq_Indication)(


IEC_Goose_ContextPtr gseCntxt,
void *mms_cntxt,
void *param,
char *gocbRef,
unsigned char *dataPtr,
MMSd_length dataLen,
unsigned char *securityPtr,
MMSd_length securityLen,
char *dataSetName,
TAM_Packet *packet,
long *pConfRev,
int *pGblError );

typedef void (* IEC_Goose_GetReferenceRes_Indication)(


void *param,
unsigned char *dataPtr,
MMSd_length dataLen,
unsigned char *securityPtr,
MMSd_length securityLen,
unsigned long stateId,
char *gocbRef,
char *dataSetName,
unsigned long confRev,
int nGblError );

typedef int (* IEC_Goose_GetElementNumReq_Indication)(


IEC_Goose_ContextPtr gseCntxt,
void *mms_cntxt,
void *param,
char *gocbRef,
unsigned char *dataPtr,
MMSd_length dataLen,

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 20
unsigned char *securityPtr,
MMSd_length securityLen,
char *dataSetName,
TAM_Packet *packet,
long *pConfRev,
int *pGblError );

typedef void (* IEC_Goose_GetElementNumRes_Indication)(


void *param,
unsigned char *dataPtr,
MMSd_length dataLen,
unsigned char *securityPtr,
MMSd_length securityLen,
unsigned long stateId,
char *gocbRef,
char *dataSetName,
unsigned long confRev,
int nGblError );

typedef void (* IEC_Goose_NotSupportedRes_Indication)(


void *param,
unsigned long stateId,
unsigned char *securityPtr,
MMSd_length securityLen );

typedef struct IEC_Goose_Subscription *IEC_Goose_SubscriptionPtr;

typedef struct IEC_Goose_Subscription {


char goID[IEC_GOOSE_IDENT_SIZE];
char gocbRef[IEC_GOOSE_IDENT_SIZE];
char datSet[IEC_GOOSE_IDENT_SIZE];
void *handle;
int goID_sum;
unsigned int VLAN_AppID;
unsigned int VLAN_VID;
unsigned char VLAN_Priority;
IEC_Goose_Indication call_back;
void *call_back_data;
int have_received;
int initial_wait;
IEC_GooseStatus status;
IEC_Goose_SubscriptionPtr next;
} IEC_Goose_Subscription;

typedef struct IEC_Goose_Context {


IEC_Goose_Subscription *avail_pool;
IEC_Goose_Subscription *active_in;
IEC_Goose_Subscription *active_out;
char adapter_name[129];
TAM_DL_Context *link_context;
IEC_Goose_Send_Ind send_indication;
IEC_Goose_SqStats_Ind SqStats_indication;
IEC_Goose_GetReferenceReq_Indication getReferenceReqFcn;
void *getReferenceReqParam;
IEC_Goose_GetReferenceRes_Indication getReferenceResFcn;
void *getReferenceResParam;

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 21
IEC_Goose_GetElementNumReq_Indication getElementNumReqFcn;
void *getElementNumReqParam;
IEC_Goose_GetElementNumRes_Indication getElementNumResFcn;
void *getElementNumResParam;
IEC_Goose_NotSupportedRes_Indication notSupportedResFcn;
void *notSupportedResParam;
#if defined(TAM_TP_Semaphore)
TAM_TP_Semaphore sem;
#endif
#if defined(TAM_TP_Event)
TAM_TP_Event eve;
#endif
/* NOTE: These are not used if USE_MMSD_IN_IEC_GOOSE is not defined */
void *directory;
int directorySize;
IEC_GooseSendType sendtype;
} IEC_Goose_Context;

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 22
4.8 Function Call Details

4.9 Administrative Functions


/* -- Returns TRUE if initialization succeeded */
int IEC_Goose_Initialize( IEC_Goose_Context *cntxt );

/* Drives the retransmission and timeouts - call it often */


unsigned long IEC_Goose_Service_Short( IEC_Goose_Context *cntxt );
void IEC_Goose_Service( IEC_Goose_Context *cntxt );

/* Added for graceful close of adapters */


void IEC_Goose_Close( IEC_Goose_Context *cntxt );

/* Called when a message is received over 802.3 which might be Goose */


/* -- Returns TRUE if valid goose message */
int IEC_Goose_Evaluate( TAM_DL_Context *dl_cntxt,
unsigned char *buffer, /* input data */
int length, /* input data length */
void *vcntxt );

int TAM_decode_VLAN_header( unsigned char *buffer,


int bufferLength,
int *offset,
int *length,
TAM_LanHeader *header );

int TAM_encode_VLAN_header( TAM_Packet *pPacket,


TAM_LanHeader *header );

4.10 IEC Goose Output Functions


/* Establishes a goose output stream */
/* -- Returns IEC_GOOSE_SUCCESS if creation succeeded */
IEC_Goose_Error IEC_Goose_Create(
IEC_Goose_Context *cntxt, /* context */
char *goID, /* goID */
char *gocbRef, /* goose control */
char *dsRef, /* DataSet */
TAM_Mac_Address *mac, /* multicast address */
IEC_Goose_Strategy *strategy, /* retrans strategy */
long confRev, /* dataset config */
int numDataSetEntries, /* objects in data */
unsigned char *buffer, /* initial data */
MMSd_length length, /* length of data */
void *handle, /* user handle */
unsigned int VLAN_AppID, /* VLAN App ID */
unsigned int VLAN_VID, /* VLAN Virtual LAN ID*/
unsigned char VLAN_Priority );/* VLAN Priority */

/* IEC_Goose_CreateOut (adds ndsCom and test to Create) */


IEC_Goose_Error IEC_Goose_CreateOut( IEC_Goose_Context *cntxt,
char *goID,
char *gocbRef,
char *dsRef,
TAM_Mac_Address *mac,
IEC_Goose_Strategy *strategy,
long confRev,

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 23
unsigned char ndsCom,
unsigned char test,
int numDataSetEntries,
unsigned char *buffer,
MMSd_length length,
void *handle,
unsigned int VLAN_AppID,
unsigned int VLAN_VID,
unsigned char VLAN_Priority );

/* Deletes a goose output stream */


/* -- Returns TRUE if deletion succeeded */
int IEC_Goose_Delete( IEC_Goose_Context *cntxt,
void *handle );

/* Publishes new data and restarts the retransmission scheme */


/* -- Returns TRUE if publish succeeded */
int IEC_Goose_Publish( IEC_Goose_Context *cntxt,
void *handle,
int numDataSetEntries,
unsigned char *buffer,
int offset,
int length );

4.11 IEC Goose Input Functions


/* Subscribes to a goose input stream */
/* -- Returns TRUE if subscription succeeded */
int IEC_Goose_Subscribe(
IEC_Goose_Context *cntxt, /* context */
char *goID, /* goID */
char *gocbRef, /* gocbRef */
TAM_Mac_Address *mac, /* multicast address */
unsigned int AppID, /* VLAN AppId */
void *handle, /* user handle */
IEC_Goose_Indication callBack, /* user callback fcn */
void *callBackData ); /* user callback data */

/* Goose indication callback function pointer */


typedef void (* IEC_Goose_Indication)( void *handle,
void *param,
IEC_GooseHeader *header,
unsigned char *dataPtr,
MMSd_length dataLength,
int timed_out );

typedef int (* IEC_Goose_GetReferenceReq_Indication)(


IEC_Goose_ContextPtr gseCntxt,
void *mms_cntxt,
void *param,
char *gocbRef,
unsigned char *dataPtr,
MMSd_length dataLen,
unsigned char securityPtr,
MMSd_length securityLen,
char *dataSetName,

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 24
TAM_Packet *packet,
long *pConfRev,
int *pGblError );

typedef void (* IEC_Goose_GetReferenceRes_Indication)(


void *param,
unsigned char *dataPtr,
MMSd_length dataLen,
unsigned char *securityPtr,
MMSd_length securityLen,
unsigned long stateId,
char *gocbRef,
char *dataSetName,
unsigned long confRev,
int nGblError );

typedef int (* IEC_Goose_GetElementNumReq_Indication)(


IEC_Goose_ContextPtr gseCntxt,
void *mms_cntxt,
void *param,
char *gocbRef,
unsigned char *dataPtr,
MMSd_length dataLen,
unsigned char *securityPtr,
MMSd_length securityLen,
char *dataSetName,
TAM_Packet *packet,
long *pConfRev,
int *pGblError );

typedef void (* IEC_Goose_GetElementNumRes_Indication)(


void *param,
unsigned char *dataPtr,
MMSd_length dataLen,
unsigned char *securityPtr,
MMSd_length securityLen,
unsigned long stateId,
char *gocbRef,
char *dataSetName,
unsigned long confRev,
int nGblError );

typedef void (* IEC_Goose_NotSupportedRes_Indication)(


void *param,
unsigned long stateId,
unsigned char *securityPtr,
MMSd_length securityLen );

/* Cancels a goose subscription */


/* -- Returns TRUE if unsubscribe succeeded */
int IEC_Goose_Unsubscribe( IEC_Goose_Context *cntxt,
void *handle );

/* Routine to handle initial timeout */


int IEC_Goose_SetInitialWait( IEC_Goose_Context *cntxt,
void *handle,
unsigned long timeToWait );

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 25
4.12 Dataset Query Functions

IEC_Goose_Error IEC_Goose_GetReference( IEC_Goose_Context *cntxt,


void *handle,
unsigned long stateId,
int *pElements,
int numElements );

IEC_Goose_Error IEC_Goose_GetElementNumber( IEC_Goose_Context *cntxt,


void *handle,
unsigned long stateId,
char **Elnamelist );

4.13 Utility Functions


IEC_Goose_Subscription *IEC_Goose_find_handle( void *handle,
IEC_Goose_Subscription **pool );

IEC_Goose_Subscription *IEC_Goose_find_entry( TAM_Mac_Address *mac,


char *goID, char *gcref,
IEC_Goose_Subscription **pool );

4.14 Simulate Functions


These functions provide the ability to send and respond to GOOSE simulate function:
Subscriber:
int TMW_GooseControlGetSimulate( void *handle,
unsigned char *pSimulateMode );
int TMW_GooseControlSetSimulate( void *handle,
unsigned char nSimulateMode );

void MMSd_GooseControlSetSimulateLD( MMSd_context *pMmsContext,


char *pLdName,
unsigned char nSimulateMode);

Publisher:
int IEC_Goose_SetTestMode( IEC_Goose_Context *cntxt,
void *handle,
unsigned char testMode );
int IEC_Goose_GetTestMode( IEC_Goose_Context *cntxt,
void *handle,
unsigned char *testMode );

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 26
5 Example Implementation
/* ######################################################
# #
# Main processing loop for Windows IEC Goose #
# (c) 2008 #
# Triangle MicroWorks #
# #
######################################################

This module contains an example of the initializion and


main processing loop to be used with the TMW IEC Goose
software.

This code has been written to run under DOS/Windows, although


in general it should run in most environments with minimal
changes for a single thread implementation.

Most of this code is concerned with keyboard and control-C


processing. The primary GOOSE code has been isolated to the
following routines:

start_goose()
stop_goose()
service_goose()

Hopefully this will make it simple to follow.


*/

/* Standard includes */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* TMW specific includes */


#include "tamvend.h"
#include "uca_time.h" /* Time definitions */
#include "tam.h" /* Utilities (fifos, etc.) */
#include "eth.h" /* Only for goose adapters */

/* These definitions were taken from MMSd/CONTEXT.H */


typedef unsigned short MMSd_ushort;
typedef MMSd_ushort MMSd_length;

/* IEC GOOSE specific includes */


#include "igoovend.h" /* Platform specific defines */
#include "iecgoose.h" /* Goose API */

IEC_Goose_Context iec_goose_cntxt;

/* Can be anything you want - passed by subscription to callback */


int MyCallBackData = 0;
/* Must be unique for each subscription
- passed tp calback, used to close, etc. */

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 27
int MyGooseHandle = 999;

/* Indication callback routine, called when an input Goose message


Has been received meeting the address/VLAN criteria */
void My_Goose_Indication( void *handle,
void *param,
IEC_GooseHeader *header,
unsigned char *dataPtr,
MMSd_length dataLength,
int timed_out )
{
if ( timed_out )
printf("Timed out!!\n" );
else
{
printf(" %s: ", header->gocbRef );
printf("%s ", header->datSet );
printf("%lu ", header->StNum );
printf("Received length %d\n", dataLength );
}
}

/* -------------------------------------------------------------- */
/* Main routine - initializes and enters service loop. If */
/* keyboard is input ready, it retrieves the characters. If a */
/* complete line has been entered, it passes it to the GOOSE test */
/* package as a command. */
/* -------------------------------------------------------------- */
int main(int argc, char **argv)
{
unsigned int VLAN_appID = 0;
TAM_Mac_Address SubscribeMacAddress =
{ 6, { 0x01, 0x0c, 0xcd, 0x01, 0x00, 0x01 } };

MMSd_start_clock();

argc--;
argv++;
while (argc > 0)
{
char *arg = *argv;
argv++;
argc--;
if (*arg == '-')
{
arg++;
switch (*arg)
{
case 'l':
arg++;
if (strlen(arg))
strcpy( iec_goose_cntxt.adapter_name, arg );
break;
default:

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 28
printf("Options are:\n");
printf(" -l<adapter name>\n");
return(1);
}
}
}

if (iec_goose_cntxt.adapter_name[0] == 0)
{
printf("Adapter must be specified (-l<adapter name>)\n");
return( 1 );
}

IEC_Goose_Initialize( &iec_goose_cntxt );

if ( !IEC_Goose_Subscribe( &iec_goose_cntxt,
"", /* goID
*/
"E1Rly1/LLN0$GO$gcSTa,
&SubscribeMacAddress,
VLAN_appID,
(void *) MyGooseHandle,
My_Goose_Indication,
(void *) &MyCallBackData ) )
{
printf("Goose subscription failed!\n" );
return( 1 );
}

while (TRUE)
{
/* This is OFTEN done in a different thread */
IEC_Goose_Service( &iec_goose_cntxt );
}

MMSd_stop_clock();
return( 0 );
}

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 29
6 Advanced Topics
6.1 Goose Addresses in Substation Configuration Language (SCL) Files

The IEC 61850 Substation Configuration Language is designed to include the configuration of all 61850
communications across the substation. This includes the assignment of Goose multicast addresses to Goose
Control Blocks.

The Communication section of an SCL file contains a set of <SubNetwork> definition elements. Each
<SubNetwork> element contains a set of <ConnectedAP> elements, representing the access points
associated with the subnetwork. Each <ConnectedAP> element contains and IED name and possibly an
<Address> , which corresponds to a server address of the IED on that subnetwork. The <ConnectedAP>
element may also contain a set of <GSE> and <SMV> elements, each of which must contain ldInst and
cbName attributes, and may contain an <Address> element. The cbName and ldInst attributes uniquely
identify a Goose control block within an IED server, and the <Address> within the <GSE> defines the
configured MAC address to which the Goose stream is published.

Triangle MicroWorks, Inc.


IEC 61850 Goose Source Code Library User Manual Version 10.5 Page 31

Вам также может понравиться