Skip to content

Commit 1cf0c2c

Browse files
feat: implement people tracking task
1 parent e3d58f2 commit 1cf0c2c

2 files changed

Lines changed: 103 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2023 Smart Operating Block
3+
*
4+
* Use of this source code is governed by an MIT-style
5+
* license that can be found in the LICENSE file or at
6+
* https://opensource.org/licenses/MIT.
7+
*/
8+
9+
#include "PeopleTracking.h"
10+
#include "../../../../utils/ArrayStream.h"
11+
12+
PeopleTracking::PeopleTracking(const int period, PeopleTrackingContext* const context): AbstractFsm(period) {
13+
this->changeState(new T(context));
14+
}
15+
16+
/*
17+
##############################################################################
18+
------------------State of LuminosityMonitoring FSM ---------------
19+
##############################################################################
20+
*/
21+
22+
PeopleTracking::T::T(PeopleTrackingContext* const context): context(context) {}
23+
24+
void PeopleTracking::T::run(Fsm* const parentFsm) {
25+
ArrayStream<PersonTracker*>(this->context->personTrackers, this->context->readerCount)
26+
.foreach([this](PersonTracker* tracker) {
27+
if(tracker->checkNewPerson()) {
28+
Person newPerson = tracker->getLastPersonDetected();
29+
Room* nextRoom = tracker->getNextRoom();
30+
Room* previousRoom = tracker->getPreviousRoom();
31+
if(ArrayStream<Pair<String, String>>(this->trackInfo.toArray(), this->trackInfo.size())
32+
.exist(Pair<String, String>(nextRoom->getId(), newPerson.getId()))) {
33+
this->trackInfo.deleteElement(Pair<String, String>(nextRoom->getId(), newPerson.getId()), true);
34+
if(previousRoom == nullptr) {
35+
this->context->eventList->add(new PersonTrackExit(newPerson));
36+
} else {
37+
this->trackInfo.add(Pair<String, String>(previousRoom->getId(), newPerson.getId()));
38+
this->context->eventList->add(new PersonTrack(newPerson, *previousRoom));
39+
}
40+
} else {
41+
if(previousRoom != nullptr) {
42+
this->trackInfo.deleteElement(Pair<String, String>(previousRoom->getId(), newPerson.getId()), true);
43+
}
44+
this->trackInfo.add(Pair<String, String>(nextRoom->getId(), newPerson.getId()));
45+
this->context->eventList->add(new PersonTrack(newPerson, *nextRoom));
46+
}
47+
}
48+
});
49+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2023 Smart Operating Block
3+
*
4+
* Use of this source code is governed by an MIT-style
5+
* license that can be found in the LICENSE file or at
6+
* https://opensource.org/licenses/MIT.
7+
*/
8+
9+
#ifndef __PEOPLE_TRACKING__
10+
#define __PEOPLE_TRACKING__
11+
12+
#include "../AbstractFsm.h"
13+
#include "../../../model/event/Event.h"
14+
#include "../../baseio/equipment/RoomEquipment.h"
15+
#include "../../baseio/PersonTracker.h"
16+
#include "../../../../utils/List.h"
17+
#include "../../../../utils/Pair.h"
18+
#include "Arduino.h"
19+
20+
struct PeopleTrackingContext {
21+
List<Event*>* const eventList;
22+
const int readerCount;
23+
PersonTracker** const personTrackers;
24+
};
25+
26+
/*
27+
People tracking task.
28+
Its main objective is to use the readers inside the
29+
different rooms to track person signalling movements to the system firing new events.
30+
*/
31+
class PeopleTracking: public AbstractFsm {
32+
public:
33+
/*
34+
Constructor.
35+
36+
@param period the period of the fsm.
37+
@param context the local context of the fsm.
38+
*/
39+
PeopleTracking(int period, PeopleTrackingContext* context);
40+
41+
private:
42+
class T: public State {
43+
public:
44+
T(PeopleTrackingContext* context);
45+
void run(Fsm* parentFsm);
46+
private:
47+
PeopleTrackingContext* const context;
48+
List<Pair<String, String>> trackInfo;
49+
};
50+
51+
};
52+
53+
54+
#endif

0 commit comments

Comments
 (0)