CANopen FD Master Library
Making your systems precise, reliable and high-quality - 5.10.01
com_demo_nmt.c

//============================================================================//
// File: com_demo_nmt.c //
// Description: Examples for NMT service in CANopen Master stack //
// //
// Copyright (C) MicroControl GmbH & Co. KG //
// 53844 Troisdorf - Germany //
// www.microcontrol.net //
// //
//----------------------------------------------------------------------------//
// The copyright to the computer program(s) herein is the property of //
// MicroControl GmbH & Co. KG, Germany. The program(s) may be used //
// and/or copied only with the written permission of MicroControl GmbH & //
// Co. KG or in accordance with the terms and conditions stipulated in //
// the agreement/contract under which the program(s) have been supplied. //
// //
//============================================================================//
#include <com_nmt.h> // CANopen Master NMT service
#include <stdio.h> // for sprintf() function
//----------------------------------------------------------------------------//
// DemoComNmtStartNet() //
// Start all nodes in the network //
//----------------------------------------------------------------------------//
ComStatus_tv DemoComNmtStartNodes(uint8_t ubNetV)
{
ComStatus_tv tvStatusT;
//----------------------------------------------------------------
// set NMT inhibit time to 500 ms
//
tvStatusT = ComNmtSetInhibit(eCOM_NET_1, 500000);
if(tvStatusT != eCOM_ERR_OK)
{
return(tvStatusT);
}
//----------------------------------------------------------------
// send "Reset all Nodes" command
//
//----------------------------------------------------------------
// now send "Operational" command, wait until inhibit time
// is over
//
do {
tvStatusT = ComNmtSetNodeState( ubNetV, 0,
} while (tvStatusT == eCOM_ERR_SERVICE_MODE);
return (tvStatusT);
} // DemoComNmtStartNodes
//----------------------------------------------------------------------------//
// DemoComNmtPrintNodeState() //
// Print node state in text buffer //
//----------------------------------------------------------------------------//
ComStatus_tv DemoComNmtPrintNodeState( uint8_t ubNetV, uint8_t ubNodeIdV,
char * szBufferV)
{
uint8_t ubNodeStateT;
ComStatus_tv tvStatusT;
tvStatusT = ComNmtGetNodeState(ubNetV, ubNodeIdV, &ubNodeStateT);
if(tvStatusT != eCOM_ERR_OK)
{
sprintf(szBufferV, "COM-ERR: %d", (int) tvStatusT);
return(tvStatusT);
}
switch(ubNodeStateT)
{
sprintf(szBufferV, "NID %d: %s", ubNodeIdV, "Stopped ");
break;
sprintf(szBufferV, "NID %d: %s", ubNodeIdV, "Pre-Op. ");
break;
sprintf(szBufferV, "NID %d: %s", ubNodeIdV, "Operational ");
break;
sprintf(szBufferV, "NID %d: %s", ubNodeIdV, "Reset ");
break;
sprintf(szBufferV, "NID %d: %s", ubNodeIdV, "Booted ");
break;
default:
sprintf(szBufferV, "NID %d: %s", ubNodeIdV, "Unknown ");
break;
}
return(eCOM_ERR_OK);
} // DemoComNmtPrintNodeState