static void _doTimedOff( iOFBack inst ) { iOFBackData data = Data(inst); if( data->timedoff > 0 ){ if( data->timer == 0 ) { iONode nodeD = NodeOp.inst( wFeedback.name(), NULL, ELEMENT_NODE ); data->state = False; data->timer = -1; TraceOp.trc( name, TRCLEVEL_USER1, __LINE__, 9999, "timed off event for %s", FBackOp.getId( inst )); if( data->listenerFun != NULL ) { data->listenerFun( data->listenerObj, data->state, FBackOp.getId( inst ), NULL, NULL, NULL, NULL, 0, 0, True ); } __ctcAction( inst ); __checkAction( inst, NULL ); /* Broadcast to clients. Node4 */ wFeedback.setid( nodeD, FBackOp.getId( inst ) ); wFeedback.setcounter( data->props, data->counter ); wFeedback.setcarcount( nodeD, data->carcount ); wFeedback.setcountedcars( nodeD, data->countedcars ); wFeedback.setstate( nodeD, data->state ); wFeedback.setaddr( nodeD, wFeedback.getaddr( data->props ) ); wFeedback.setbus( nodeD, wFeedback.getbus( data->props ) ); wFeedback.setfbtype( nodeD, wFeedback.getfbtype( data->props ) ); wFeedback.setload( nodeD, wFeedback.getload(data->props) ); wFeedback.setmaxload( nodeD, wFeedback.getmaxload(data->props) ); AppOp.broadcastEvent( nodeD ); { obj listener = ListOp.first( data->listeners ); wFeedback.setstate( data->props, data->state ); while( listener != NULL ) { TraceOp.trc( name, TRCLEVEL_USER1, __LINE__, 9999, "fb [%s](%s) val=%d count=%d call listener %X...", FBackOp.getId(inst), data->state?"ON":"OFF", wFeedback.getval(data->props), data->counter, listener ); listener->event( listener, data->props ); listener = ListOp.next( data->listeners ); }; } } else if( data->timer > 0 ) { data->timer--; } } }
static void _event( iOFBack inst, iONode nodeC ) { iOFBackData data = Data(inst); Boolean hasListener = False; Boolean state = wFeedback.isstate( nodeC ); if( TraceOp.getLevel(NULL) & TRCLEVEL_DEBUG ) { char* strNode = (char*)NodeOp.base.toString( nodeC ); TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "event %s", strNode ); StrOp.free( strNode ); } if( wFeedback.getcutoutaddr(data->props) > 0 && wFeedback.getaddr(nodeC) == wFeedback.getcutoutaddr(data->props) ) { data->shortcut = state; wFeedback.setshortcut(data->props, state); TraceOp.trc( name, state ? TRCLEVEL_EXCEPTION:TRCLEVEL_INFO, __LINE__, 9999, "Sensor [%s] report: %s", wFeedback.getid(data->props), state?"short circuit detected":"Cutout is OK" ); AppOp.broadcastEvent( (iONode)NodeOp.base.clone(data->props) ); nodeC->base.del(nodeC); return; } /* check for active low */ if( wFeedback.isactivelow( data->props ) ) state = !state; /* check for a timed off sensor */ if( data->timedoff > 0 ) { if( !state ) { data->timer = data->timedoff; /* Cleanup Node3 */ nodeC->base.del(nodeC); return; } } data->state = state; if( wFeedback.getfbtype(data->props) == wFeedback.fbtype_wheelcounter ) { if(wFeedback.getwheelcount(nodeC) == 0 && state) { /* using a HAL sensor for 'wheel'(Magnet) counting */ data->wheelcount++; } TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "[%s] COUNTING WHEELS: countedwheels=%d", FBackOp.getId(inst), wFeedback.getwheelcount(nodeC) + data->wheelcount ); /* the plus data->wheelcount is for simulation */ } if(data->state) { data->timer = -1; data->counter++; if( data->carcount > 0 ) { data->countedcars++; TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "[%s] COUNTING CARS: carcount=%d countedcars=%d", FBackOp.getId(inst), data->carcount, data->countedcars ); __checkAction( inst ); } } if( data->carcount > 0 && data->countedcars <= data->carcount ) { /* Cleanup Node3 */ TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "COUNTING CARS: fb[%s] state=%s ident=%d val=%d carcount=%d countedcars=%d", FBackOp.getId(inst), data->state?"ON":"OFF", wFeedback.getidentifier( nodeC ), wFeedback.getval( nodeC ), data->carcount, data->countedcars ); /* Broadcast to clients. Node4 */ if( data->state || data->timedoff == 0 ) { iONode nodeD = NodeOp.inst( wFeedback.name(), NULL, ELEMENT_NODE ); wFeedback.setid( nodeD, FBackOp.getId( inst ) ); wFeedback.setcounter( data->props, data->counter ); wFeedback.setcarcount( nodeD, data->carcount ); wFeedback.setcountedcars( nodeD, data->countedcars ); wFeedback.setstate( nodeD, data->state ); wFeedback.setval( nodeD, wFeedback.getval( nodeC ) ); wFeedback.setaddr( nodeD, wFeedback.getaddr( data->props ) ); wFeedback.setbus( nodeD, wFeedback.getbus( data->props ) ); wFeedback.setfbtype( nodeD, wFeedback.getfbtype( data->props ) ); wFeedback.setidentifier( nodeD, wFeedback.getidentifier( nodeC ) ); wFeedback.setwheelcount( nodeD, wFeedback.getwheelcount( nodeC ) + data->wheelcount ); wFeedback.setload( nodeD, wFeedback.getload(data->props) ); wFeedback.setmaxload( nodeD, wFeedback.getmaxload(data->props) ); AppOp.broadcastEvent( nodeD ); } nodeC->base.del(nodeC); return; } /* reset car counting */ data->carcount = 0; data->countedcars = 0; wFeedback.setstate( data->props, data->state ); wFeedback.setcounter( data->props, data->counter ); wFeedback.setidentifier( data->props, wFeedback.getidentifier( nodeC ) ); wFeedback.setdirection( data->props, wFeedback.isdirection( nodeC ) ); wFeedback.setload( data->props, wFeedback.getload( nodeC ) ); TraceOp.trc( name, TRCLEVEL_USER1, __LINE__, 9999, "fb[%s] state=%s ident=%s dir=%s val=%d count=%d", FBackOp.getId(inst), data->state?"ON":"OFF", wFeedback.getidentifier( nodeC ), wFeedback.isdirection( nodeC )?"fwd":"rev", wFeedback.getval( nodeC ), data->counter ); /* Call listener. */ if( data->listenerFun != NULL ) { data->listenerFun( data->listenerObj, data->state, FBackOp.getId( inst ), wFeedback.getidentifier( nodeC ), wFeedback.getidentifier2( nodeC ), wFeedback.getidentifier3( nodeC ), wFeedback.getidentifier4( nodeC ), wFeedback.getval( nodeC ), wFeedback.getwheelcount( nodeC ) + data->wheelcount, wFeedback.isdirection(nodeC) ); hasListener = True; } { obj listener = ListOp.first( data->listeners ); while( listener != NULL ) { hasListener = True; TraceOp.trc( name, TRCLEVEL_USER1, __LINE__, 9999, "fb [%s](%s) ident=%d val=%d count=%d call listener 0x%08X...", FBackOp.getId(inst), data->state?"ON":"OFF", wFeedback.getidentifier( nodeC ), wFeedback.getval( nodeC ), data->counter, listener ); listener->event( listener, data->props ); listener = ListOp.next( data->listeners ); }; } __ctcAction( inst ); __checkAction( inst ); if(!hasListener) { TraceOp.trc( name, TRCLEVEL_USER1, __LINE__, 9999, "fb[%s] (%s) ident=%s val=%d count=%d has no listener...", FBackOp.getId(inst), data->state?"ON":"OFF", wFeedback.getidentifier( nodeC ), wFeedback.getval( nodeC ), data->counter ); } /* Broadcast to clients. Node4 */ if( data->state || data->timedoff == 0 ) { iONode nodeD = NodeOp.inst( wFeedback.name(), NULL, ELEMENT_NODE ); wFeedback.setiid( nodeD, wFeedback.getiid( data->props ) ); wFeedback.setid( nodeD, FBackOp.getId( inst ) ); wFeedback.setstate( nodeD, data->state ); wFeedback.setval( nodeD, wFeedback.getval( nodeC ) ); wFeedback.setaddr( nodeD, wFeedback.getaddr( data->props ) ); wFeedback.setbus( nodeD, wFeedback.getbus( data->props ) ); wFeedback.setfbtype( nodeD, wFeedback.getfbtype( data->props ) ); wFeedback.setidentifier( nodeD, wFeedback.getidentifier( nodeC ) ); wFeedback.setcounter( nodeD, data->counter ); wFeedback.setcarcount( nodeD, data->carcount ); wFeedback.setcountedcars( nodeD, data->countedcars ); wFeedback.setwheelcount( nodeD, wFeedback.getwheelcount( nodeC ) + data->wheelcount ); wFeedback.setload( nodeD, wFeedback.getload(data->props) ); wFeedback.setmaxload( nodeD, wFeedback.getmaxload(data->props) ); AppOp.broadcastEvent( nodeD ); } if( data->state && wFeedback.getfbtype(data->props) == wFeedback.fbtype_lissy ) { /* timed off */ data->state = False; data->timer = data->timedoff; } /* Cleanup Node3 */ nodeC->base.del(nodeC); }