Rise
The Vieneo Province
Loading...
Searching...
No Matches
scanDb.cpp
Go to the documentation of this file.
1#include "scanDb.h"
2
4{
5 logger = prmLogger;
6 Reset();
7}
8
10{
11 for (auto& scan : memory)
12 {
13 scan = Sscan();
14 }
15}
16
17void scanDb::ClearChildren(unsigned short parentId)
18{
19 for (int i = 0; i < MAX_SHIPINMEMORY; i++)
20 {
21 if (memory[i].initialized && memory[i].scandata.parentId == parentId)
23 }
24}
25
26void scanDb::InsertUpdateModeAC(USHORT vehicleId, SmodeAC modeAC)
27{
28 if (vehicleId >= MAX_SHIPINMEMORY)
29 {
30 logger->Log("InsertUpdateModeAC received out of range vehicleId", Logger::Error);
31 return;
32 }
33 if (memory[vehicleId].initialized)
34 {
35 // so if this is a ARJ that used to be a child of another record we can update his old parent as assume he is no longer a child!
36 const USHORT parentId = memory[vehicleId].scandata.parentId;
37 if (parentId != 0)
38 {
39 logger->Log("Got mode AC information for someone that used to have a parent, clearing...");
40 memory[vehicleId].scandata.parentId = 0;
41 UpdateChildren(parentId);
42 }
43 }
44 else
45 {
46 memory[vehicleId].initialized = true;
47 }
48
49 memory[vehicleId].scandata.modeAC = modeAC;
50}
51
52void scanDb::UpdateChildren(USHORT parentId)
53{
54 if (parentId >= MAX_SHIPINMEMORY)
55 {
56 logger->Log("UpdateChildren received out of range parentId", Logger::Error);
57 return;
58 }
59 auto& children = memory[parentId].children;
60 children.clear();
61
62 for (int i = 1; i < MAX_SHIPINMEMORY; i++) // for each vessel
63 {
64 if (i == parentId) continue; // except the parent
65
66 if (memory[i].scandata.parentId == parentId) // if this vehicle's parent is the one we are worried about
67 {
68 children.emplace_back(memory[i].scandata); // add to parent's child list
69 }
70 }
71}
72
73void scanDb::InsertUpdateModeX(USHORT vehicleId, SmodeX modeX)
74{
75 if (vehicleId >= MAX_SHIPINMEMORY)
76 {
77 logger->Log("InsertUpdateModeX received out of range vehicleId", Logger::Error);
78 return;
79 }
80 if (!memory[vehicleId].initialized)
81 {
82 logger->Log("Got mode X information before mode AC was received!", Logger::Warn);
83 }
84
85 memory[vehicleId].scandata.modeX = modeX;
86}
87
88void scanDb::InsertUpdateParent(USHORT vehicleId, USHORT parentId)
89{
90 if (vehicleId >= MAX_SHIPINMEMORY || parentId >= MAX_SHIPINMEMORY)
91 {
92 logger->Log("InsertUpdateParent received out of range id", Logger::Error);
93 return;
94 }
95 if (!memory[vehicleId].initialized)
96 {
97 logger->Log("Got mode S information before mode AC was received!", Logger::Warn);
98 }
99
100 if (memory[vehicleId].scandata.parentId == parentId) return;
101
102 const int oldParentId = memory[vehicleId].scandata.parentId;
103 memory[vehicleId].scandata.parentId = parentId;
104
105 if (oldParentId != 0) // had old parent
106 UpdateChildren(oldParentId);
107 if (parentId != 0) // has new parent
108 UpdateChildren(parentId);
109}
110
111Sscan scanDb::Get(USHORT vehicleId) const
112{
113 if (vehicleId >= MAX_SHIPINMEMORY)
114 {
115 logger->Log("Get received out of range vehicleId", Logger::Error);
116 return Sscan();
117 }
118 return memory[vehicleId];
119}
#define MAX_SHIPINMEMORY
void Log(const char *msg, Level level=Info, int errorCode=0)
Definition Logger.cpp:283
@ Warn
Definition Logger.h:26
@ Error
Definition Logger.h:28
void InsertUpdateParent(USHORT vehicleId, USHORT parentId)
Definition scanDb.cpp:88
scanDb()=default
void Reset()
Definition scanDb.cpp:9
Sscan memory[MAX_SHIPINMEMORY]
Definition scanDb.h:57
void InsertUpdateModeAC(USHORT vehicleId, SmodeAC modeAC)
Definition scanDb.cpp:26
void ClearChildren(unsigned short parentId)
Definition scanDb.cpp:17
void UpdateChildren(USHORT parentId)
Definition scanDb.cpp:52
void InsertUpdateModeX(USHORT vehicleId, SmodeX modeX)
Definition scanDb.cpp:73
Sscan Get(USHORT vehicleId) const
Definition scanDb.cpp:111
Logger * logger
Definition scanDb.h:55
Definition scanDb.h:47
bool initialized
Definition scanDb.h:48
std::vector< Sscandata > children
Definition scanDb.h:50
Sscandata scandata
Definition scanDb.h:49
SmodeAC modeAC
Definition scanDb.h:41
unsigned short parentId
Definition scanDb.h:42
SmodeX modeX
Definition scanDb.h:43