Power System Platform  2026w23a-beta
Loading...
Searching...
No Matches
ATPPSPBridge.h
1/*
2 * Copyright (C) 2026 Thales Lima Oliveira <thales@ufu.br>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#ifndef ATPPSPBRIDGE_H
19#define ATPPSPBRIDGE_H
20
21#include <cstdint>
22#include <wx/app.h>
23#include <wx/stopwatch.h>
24#include <wx/progdlg.h>
25#ifdef _WIN32
26#include <windows.h>
27#else
28#include <semaphore.h>
29#include <sys/mman.h>
30#include <fcntl.h>
31#include <unistd.h>
32#include <sys/stat.h>
33#include <errno.h>
34#include <cerrno>
35#endif
36
37enum class Mode
38{
39 RawCurrent = 0,
40 Phasor = 1,
41 Both = 2
42};
43
44struct Sample
45{
46 double current[3];
47};
48
49struct Phasor
50{
51 double Id[3];
52 double Iq[3];
53};
54
55struct SharedData
56{
57 std::uint32_t nPh;
58
59 double t;
60
61 double vrms;
62 double freq;
63 double theta;
64 double phase;
65
66 double stoptime;
67 double atpStepsize;
68 double pspStepsize;
69
70 Mode mode;
71 int terminate;
72
73 Phasor phasor;
74
75 std::uint32_t stepCount;
76 std::uint32_t syncSteps;
77
78 Sample samples[];
79};
80
82{
83public:
84
87
88 bool Connect(unsigned timeout, unsigned retryInterval);
89 void Disconnect();
90
91 bool WaitATP();
92 bool ReleaseATP();
93
94 //void SetProcessHandle(HANDLE hProcess) { m_hATPProcess = hProcess; }
95 void SetProcessId(long pid) { m_atpPid = pid; }
96
97 SharedData& GetSharedData() const;
98
99 bool IsConnected() const;
100
101private:
102
103#ifdef _WIN32
104 HANDLE m_hATPReady = nullptr;
105 HANDLE m_hPSPReady = nullptr;
106 HANDLE m_hMapFile = nullptr;
107#else
108 sem_t* m_hATPReady = SEM_FAILED;
109 sem_t* m_hPSPReady = SEM_FAILED;
110 int m_hMapFile = -1;
111#endif
112
113 long m_atpPid = 0;
114
115 SharedData* m_data = nullptr;
116};
117
118#endif