Question

Use Case: Collect lower level Motion events, correlate them to remove duplicates (e.g., a person walked around a house passes in front of one camera then another), then report the correlated Detection event.

Approach: (see pic) I initiate Motion Events from the video analytics and other sensors which are received and correlated by the AwarenessAnalytics component, which then raises a Detection Event to the Home Automation Main. It is similar to Chain-of-Responsibility pattern, though in reverse with events.

I have defined two completely separate event interfaces in separate files in the same package;

public interface MotionEventListener {
        public void motionDetected(MotionEvent event);
        public void motionLocation (MotionLocation location);
        public void motionCeased(MotionEvent event);
        public void eventVideoComplete(String eventId);
}

public interface DetectionEventListener {
    public void motionIsDetected(DetectionEvent event);
    public void motionAtLocation (MotionLocation location);
    public void motionHasCeased(DetectionEvent event);
    public void eventVideoNowComplete(String eventId);
}

I create the Motion Events in the VideoAnalytic thread;

private synchronized void fireDetectedEvent() {
  Object source = new Object();
  alertStartTime = getDateTime();
  eventId++;
  System.out.println("*** Motion Detected! ***" + alertStartTime + ", eventId = " + 
    eventId);       
  // Send alert to listener
  String details ="";
  MotionEvent event = new MotionEvent(source, alertActive, eventId, 
    Calendar.getInstance(), cameraId, Classification.unknown, details, alertStartTime);
  Iterator i = listeners.iterator();
  if (alertActive) {
    while(i.hasNext())  {
      ((MotionEventListener) i.next()).motionDetected(event);
    }
  } else {
    while(i.hasNext())  {
      ((MotionEventListener) i.next()).motionCeased(event);
    }
  resetVideoStreamEventCounter = 0;// keeps track of how many video resets occur from one 
                                   //event to another
  }
}

The Motion events are successfully caught in the AwarenessAnalytic layer, where I createa new Detection Event if there is not already an ongoing event;

public void motionDetected(MotionEvent e) {
  System.out.println("Motion Detected Listener activated " + e.getCameraId());
  if (alertCounter == 0) {
    Object source = new Object();
    System.out.println("*** Motion Detected! ***" );
    // Send alert to listener
    alertCounter++;
    alertId++;
    alertActive = true;
    DetectionEvent event = new DetectionEvent(
      source, 
      alertActive, 
      alertId, 
      e.getEventDateTime(), 
      e.getCameraId(), 
      e.getEventType(), 
      e.getKnownDetails(), 
      e.getEventSubdirectory());
    Iterator i = listeners.iterator();
    if (alertActive) {
      while(i.hasNext())  {
    ((DetectionEventListener) i.next()).motionDetected(event);
      }
     } else {
       alertCounter++;
     }
   }
   System.out.println("Motion Detected event received by AA from " + e.getCameraId());
}

Design pictorial:

Problem:

I've tried to catch the events in Home Automation Main as follows;

AwarenessAnalytics awarenessAnalytic = new AwarenessAnalytics();
        
// establish the listener set
awarenessAnalytic.addListener(this);

However, this results in a compilation error "Cannot use this in a static context"

Do I need a separate listener class for this? Or something else?

Was it helpful?

Solution

@Kon provided the clues needed to solve this problem (he is the one who deserves the credit). I created a separated DetectionListener class that implemented DetectionEventListener;

public class DetectionListener implements DetectionEventListener {
  public DetectionListener() {
    super();
  }

  public void motionIsDetected(DetectionEvent e) {
    System.out.println("Motion Detected Awareness Listener test driver activated " +    
       e.getCameraId());
   }

  public void motionAtLocation (MotionLocation  e) {
    System.out.println("Test driver Motion location = " + e.getX() + ", " + e.getY());
  }

  public void motionHasCeased(DetectionEvent  e) {
    System.out.println("Motion Ceased Listener test driver activated from " + 
      e.getCameraId());
  }

  public void eventVideoNowComplete (String eventId) {
    System.out.println("Event Video test driver activated");
  }
} 

And then in the Home Automation Main set up the AwarenessAnalytics instance, the DetectionListener instance, and add it to the AwarenessAnalytics instance;

AwarenessAnalytics awarenessAnalytic = new AwarenessAnalytics();
// establish the listener set
DetectionEventListener Del = new DetectionListener();
awarenessAnalytic.addListener(Del);

Now I need to call the main from the DetectionListener to complete the circle and take action on the events.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top