⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nodeobject.nc

📁 这是应用SAM7X256做LonWorks网关的代码
💻 NC
字号:
//{{NodeBuilder Code Wizard Start <CodeWizard Timestamp>
// Run on Fri Dec 28 21:24:20 2007, version 3.10.56
//
//}}NodeBuilder Code Wizard End

//////////////////////////////////////////////////////////////////
// File: NodeObject.nc 
//
//
// Generated by NodeBuilder Code Wizard Version 3.10.56
// Copyright (c) 2001-2003 Echelon Corporation.  All rights reserved.
//                                                                                  
// ECHELON MAKES NO REPRESENTATION, WARRANTY, OR CONDITION OF
// ANY KIND, EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE OR IN
// ANY COMMUNICATION WITH YOU, INCLUDING, BUT NOT LIMITED TO,
// ANY IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY
// QUALITY, FITNESS FOR ANY PARTICULAR PURPOSE, 
// NONINFRINGEMENT, AND THEIR EQUIVALENTS.
//
//
// Written By: NodeBuilder Code Wizard  
//
// Description: Node Object functions
// This file contains functions that handle the node object. External 
// requests that relate to other objects are automatically routed to 
// the relevant director functions. 
// No changes are required to this file unless the set of supported 
// features and commands is to be changed. 
//
//////////////////////////////////////////////////////////////////////////////

#include "NodeObject.h"

// Task to handle object requests
//
when (nv_update_occurs(NBCW_NODE_REQUEST))
{

	// The SNVT_request input network variable receives commands (requests) for an individual object
	// (object_id > 0), or for the entire device (object_id == 0). This network variable update 
	// handler process the receipt of the requests and routes the command to the appropriate 
	// director function(s). There is not normally a need to change this pre-defined network variable
	// update handler. 
	// Make sure to review the default handling of commands in the director implementations provided.

	TFblockIndex		fblockRequested;
	object_request_t	objectRequest;
	SNVT_obj_status		*pStatus;

	if (NBCW_NODE_REQUEST.object_id >= get_fblock_count())  {
		// no such object:
		NBCW_NODE_STATUS.invalid_id = TRUE;

	} else {

		boolean  	 bPropagate;
		TFblockIndex fbIndex;

		fblockRequested = (unsigned)NBCW_NODE_REQUEST.object_id;  
		objectRequest = NBCW_NODE_REQUEST.object_request;  // get request code
		deviceState.FblockIndex = fblockRequested;

		pStatus = getObjStatus(fblockRequested);   // point to current status
		pStatus->invalid_request = FALSE;    // default
		bPropagate = TRUE;

		if (objectRequest == RQ_REPORT_MASK)  {
			// The fblock code must copy its report mask to NBCW_NODE_STATUS NV
			fblock_director(fblockRequested, FBC_REPORT_MASK);
			NBCW_NODE_STATUS.object_id = fblockRequested;
			propagate(NBCW_NODE_STATUS);
			bPropagate = FALSE;	// done that already

		}  else if (objectRequest == RQ_NORMAL ||
				objectRequest == RQ_DISABLED ||
				objectRequest == RQ_OVERRIDE ||
				objectRequest == RQ_ENABLE ||
				objectRequest == RQ_RMV_OVERRIDE ||
				objectRequest == RQ_CLEAR_STATUS ||
				objectRequest == RQ_SELF_TEST ||
				objectRequest == RQ_UPDATE_ALARM ||
				objectRequest == RQ_CLEAR_ALARM ||
				objectRequest == RQ_ALARM_NOTIFY_ENABLED ||
				objectRequest == RQ_ALARM_NOTIFY_DISABLED ||
				objectRequest == RQ_MANUAL_CTRL ||
				objectRequest == RQ_REMOTE_CTRL ||
				objectRequest == RQ_PROGRAM)  {

			if (fblockRequested == NODEOBJ_INDEX)  {
				// when enabling/disabling all objects on the node by enabling/disabling
				// the node object, we would possibly cause an ill-detected error condition
				// on the network manager due to some left-over bit from a previous transaction.
				// We do therefore prefer to call the objects "disabled" initially as a response
				// to an enable request, and vice versa. 
				// Note that this implementation assumes the nvoStatus network variable will
				// be polled.

				if (objectRequest == RQ_DISABLED)  {
					NBCW_NODE_STATUS.object_id = fblockRequested;
					NBCW_NODE_STATUS.disabled = 1;

				} else if (objectRequest == RQ_ENABLE)  {
					NBCW_NODE_STATUS.object_id = fblockRequested;
					NBCW_NODE_STATUS.disabled = 0;
				}

				// we apply the command to all objects, including the node object itself:
				for (fbIndex = 0; fbIndex < get_fblock_count(); ++fbIndex)  {
					// the fblock director must update its own status
					fblock_director(fbIndex, objectRequest);
				}

				// propagate the accumulated status with the node objects's ID.
				updateNode_Status();
			} else {
				fblock_director(fblockRequested, objectRequest);
			}
		} else if (objectRequest == RQ_UPDATE_STATUS)  {
			if (fblockRequested == NODEOBJ_INDEX)  {
				// collect the or'ed status of all objects:
				updateNode_Status();
				pStatus->invalid_request = FALSE;
			} else  {
				// reply with individual status:
				fblock_director(fblockRequested, objectRequest);
			}
		} else {
			// just update NBCW_NODE_STATUS
			pStatus->invalid_request = TRUE;
		}

		if (bPropagate) {
			NBCW_NODE_STATUS = *pStatus;	// propagate status variable
			NBCW_NODE_STATUS.object_id = fblockRequested;
		}
	}
}

void NodeObjectDirector(unsigned uFblockIndex, int nCommand)
{

	// TODO: add code for other commands your node object should support. 
	// Note that the node object's director function should only handle
	// requests to the very node object itself; it should *not* forward
	// requests to other objects. Events triggered by the arrival of an 
	// update to nviNodeRequest get forwarded to each individual fblock
	// (and its director) by the appropriate when() task above already.

	SNVT_obj_status   *pStatus;
	pStatus = getObjStatus(uFblockIndex);   // point to current status

	pStatus->invalid_id = FALSE;
	pStatus->invalid_request = FALSE;

	if ((TFblock_command)nCommand == FBC_INITIALIZE_FB)  {

		// Add code to support the initialize command. Note this is not a standard
		// LonMark request. Instead, FBC_INITIALIZE_FB is provided and supported for the 
		// convenience of the application developer, and it may be used as a generic function
		// to intialize the device and its fblocks. The FBC_RESET command, below, provides
		// a special case of initialization (in response to a Neuron Chip reset), which in
		// turn could use the FBC_INITIALIZE_FB command. Other, application-specific, cases
		// may exist where a re-initialization is required.
		//
		// Typical initialization duties include the initialization of attached I/O circuitry, 
		// driving any physical controls into a well-defined state, initializing local variables, 
		// preparing fblock-specific I/O models (for example, by calling io_change_init()), and
		// many other, application-specific tasks.
		//
		// TODO: Add code to complete the initialization of the fblock.






	} else if ((TFblock_command)nCommand == FBC_WHEN_OFFLINE)  {		// raised by when (offline) task

		// Add code to respond to the offline command, if needed. Such code might
		// include action with regards to physically attached hardware, or some visible
		// indication showing that the device is currently offline. It is recommended the 
		// offline state freezes the fblock and preserves its most recent state, and that
		// the offline command therefore shall not automatically disable the fblock.
		//
		// TODO: Additional code to support this command is not normally required. 






	} else if ((TFblock_command)nCommand == FBC_WHEN_ONLINE)  {		// raised by when (online) task 

		// Add code to respond to the online command, if needed. Such code might
		// include action with regards to physically attached hardware, or some visible
		// indication showing that the device is currently online. It is recommended the 
		// offline state freezes the fblock and preserves its most recent state, and that
		// the online command therefore shall not alter any other state of the device or 
		// this fblock (such as the disabled state, or the override state).
		//
		// TODO: Additional code to support this command is not normally required. 






	} else if ((TFblock_command)nCommand == FBC_UPDATE_STATUS)  {	// raised by node object

		// Additional code to support this command is not normally required. The default
		// implementation for the Node Object contains code that correctly updates the device
		// and object status information, and other action is not normally required. 

	}

	// note the following commands RQ_NORMAL, RQ_DISABLED, RQ_ENABLED are dealt with
	// in the when (nv...) task above for the device. Here, in the node object's 
	// director function, we only handle requests locally to the node object.

	else if ((TFblock_command)nCommand == RQ_NORMAL)  {

		clearFblockStatus(uFblockIndex);
		setFblockDisable(uFblockIndex, FALSE);
		setFblockOverride(uFblockIndex, FALSE);

	} else if ((TFblock_command)nCommand == RQ_DISABLED) {

		setFblockDisable(uFblockIndex, TRUE);

	} else if ((TFblock_command)nCommand == RQ_ENABLE) {

		setFblockDisable(uFblockIndex, FALSE);

	} else if ((TFblock_command)nCommand == FBC_WHEN_RESET)  {	// raised by when (reset) task

		// get going:
		setFblockDisable(uFblockIndex, FALSE);
		setLockedOutBit(uFblockIndex, FALSE);

	} else if ((TFblock_command)nCommand == FBC_OVERRIDE)  {		// raised by the node object

		// TODO - add code to implement override behavior (or reset bit in xxxReportMask)

	} else if ((TFblock_command)nCommand == FBC_RMV_OVERRIDE)  {	// raised by the node object

		// TODO - add code to implement override behavior (or reset bit in xxxReportMask)

	} else if ((TFblock_command)nCommand == RQ_REPORT_MASK)  {	// raised by the node object  

		NBCW_NODE_STATUS = NodeObjectReportMask;

	} else if ((TFblock_command)nCommand == FBC_SEND_HEARTBEAT_TIMER) {

		// See the director function that is provided for all fblocks, with the exception of
		// this particular director function (which controls the Node Object alone), for details
		// about the FBC_SEND_HEARTBEAT_TIMER.

	} else {		

		// All commands must be dealt with. At a minimum, the fblock director must signal that the
		// command received is not supported:

		pStatus->invalid_request = TRUE;
	}
}

// This mask should be a bit-wise or of all the other report masks 
// on the node.
const SNVT_obj_status NodeObjectReportMask = {
    0,              // Object ID
    0,              // invalid_id
    0,              // invalid_request
    1,              // disabled
    0,              // out_of_limits
    0,              // open_circuit
    0,              // out_of_service
    0,              // mechanical_fault
    0,              // feedback_failure

    0,              // over_range
    0,              // under_range
    0,              // electrical_fault
    0,              // unable_to_measure
    1,              // comm_failure
    0,              // fail_self_test
    0,              // self_test_in_progress
    0,              // locked_out

    0,              // manual_control
    0,              // in_alarm
    0,              // in_override
    1,              // report_mask
    0,              // reserved1
    0,              // reserved2
};












⌨️ 快捷键说明

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