11 |
andreas |
1 |
/*
|
21 |
andreas |
2 |
* Copyright (C) 2020, 2021 by Andreas Theofilu <andreas@theosys.at>
|
11 |
andreas |
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 3 of the License, or
|
|
|
7 |
* (at your option) 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, write to the Free Software Foundation,
|
|
|
16 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
#ifndef __TAMXCOMMANDS_H__
|
|
|
20 |
#define __TAMXCOMMANDS_H__
|
|
|
21 |
|
|
|
22 |
#include <string>
|
|
|
23 |
#include <vector>
|
|
|
24 |
#include <functional>
|
|
|
25 |
|
14 |
andreas |
26 |
#include "tbutton.h"
|
|
|
27 |
#include "tvalidatefile.h"
|
|
|
28 |
|
|
|
29 |
class TPage;
|
|
|
30 |
class TSubPage;
|
|
|
31 |
|
|
|
32 |
typedef struct PCHAIN_T
|
11 |
andreas |
33 |
{
|
14 |
andreas |
34 |
TPage *page{nullptr};
|
|
|
35 |
PCHAIN_T *next{nullptr};
|
|
|
36 |
}PCHAIN_T;
|
|
|
37 |
|
|
|
38 |
typedef struct SPCHAIN_T
|
|
|
39 |
{
|
|
|
40 |
TSubPage *page{nullptr};
|
|
|
41 |
SPCHAIN_T *next{nullptr};
|
|
|
42 |
}SPCHAIN_T;
|
|
|
43 |
|
|
|
44 |
// Pages with buttons
|
|
|
45 |
typedef struct MAP_T
|
|
|
46 |
{
|
|
|
47 |
int p{0}; // port number
|
|
|
48 |
int c{0}; // channel number
|
|
|
49 |
int ax{0}; // ??
|
|
|
50 |
int pg{0}; // page number
|
|
|
51 |
int bt{0}; // button number
|
|
|
52 |
std::string pn; // page name
|
|
|
53 |
std::string bn; // button name
|
|
|
54 |
}MAP_T;
|
|
|
55 |
|
|
|
56 |
// Images
|
|
|
57 |
typedef struct MAP_BM_T
|
|
|
58 |
{
|
|
|
59 |
std::string i; // image file name
|
|
|
60 |
int id{0};
|
|
|
61 |
int rt{0};
|
|
|
62 |
int pg{0}; // page number
|
|
|
63 |
int bt{0}; // button number
|
|
|
64 |
int st{0};
|
|
|
65 |
int sl{0};
|
|
|
66 |
std::string pn; // page name
|
|
|
67 |
std::string bn; // button name
|
|
|
68 |
}MAP_BM_T;
|
|
|
69 |
|
|
|
70 |
typedef struct MAP_PM_T
|
|
|
71 |
{
|
|
|
72 |
int a{0};
|
|
|
73 |
std::string t; // Group name
|
|
|
74 |
int pg{0}; // page number
|
|
|
75 |
int bt{0}; // button number
|
|
|
76 |
std::string pn; // page name
|
|
|
77 |
std::string bn; // button name
|
|
|
78 |
}MAP_PM_T;
|
|
|
79 |
|
|
|
80 |
typedef struct MAPS_T
|
|
|
81 |
{
|
|
|
82 |
std::vector<MAP_T> map_cm;
|
|
|
83 |
std::vector<MAP_T> map_am;
|
|
|
84 |
std::vector<MAP_T> map_lm;
|
|
|
85 |
std::vector<MAP_BM_T> map_bm; // Images
|
|
|
86 |
std::vector<std::string> map_sm; // sound file names
|
|
|
87 |
std::vector<MAP_T> map_strm; // System resources
|
|
|
88 |
std::vector<MAP_PM_T> map_pm; // Button -> text
|
|
|
89 |
}MAPS_T;
|
|
|
90 |
|
|
|
91 |
class TAmxCommands : public TValidateFile
|
|
|
92 |
{
|
11 |
andreas |
93 |
public:
|
|
|
94 |
typedef struct CMD_TABLE
|
|
|
95 |
{
|
|
|
96 |
std::string cmd; // The command (^TXT, ^BMP, ...)
|
|
|
97 |
std::vector<int> channels; // Channels the command affects (200&210, ...)
|
|
|
98 |
std::vector<std::string> pars; // Rest of parameters of the command
|
|
|
99 |
std::function<void (int port, std::vector<int>& channels, std::vector<std::string>& pars)> command{nullptr};
|
|
|
100 |
}CMD_TABLE;
|
|
|
101 |
|
19 |
andreas |
102 |
typedef enum MAP_TYPE
|
|
|
103 |
{
|
|
|
104 |
TYPE_CM = 1, // ON / OFF
|
|
|
105 |
TYPE_AM, // TXT, ...
|
|
|
106 |
TYPE_LM // Bargraphs
|
|
|
107 |
}MAP_TYPE;
|
|
|
108 |
|
11 |
andreas |
109 |
TAmxCommands();
|
|
|
110 |
~TAmxCommands();
|
|
|
111 |
|
14 |
andreas |
112 |
void setPChain(PCHAIN_T *ch) { mPChain = ch; }
|
|
|
113 |
void setSPChain(SPCHAIN_T *ch) { mSPChain = ch; }
|
11 |
andreas |
114 |
bool parseCommand(int device, int port, const std::string& cmd);
|
19 |
andreas |
115 |
std::vector<MAP_T> findButtons(int port, std::vector<int>& channels, MAP_TYPE mt = TYPE_AM);
|
97 |
andreas |
116 |
std::vector<MAP_T> findButtonByName(const std::string& name);
|
15 |
andreas |
117 |
std::vector<MAP_T> findBargraphs(int port, std::vector<int>& channels);
|
107 |
andreas |
118 |
std::vector<std::string> findSounds();
|
|
|
119 |
bool soundExist(const std::string sname);
|
11 |
andreas |
120 |
void registerCommand(std::function<void (int port, std::vector<int>& channels, std::vector<std::string>& pars)> command, const std::string& name);
|
|
|
121 |
|
14 |
andreas |
122 |
protected:
|
|
|
123 |
bool readMap();
|
|
|
124 |
|
11 |
andreas |
125 |
private:
|
|
|
126 |
bool extractChannels(const std::string& schan, std::vector<int> *ch);
|
14 |
andreas |
127 |
std::vector<std::string> getFields(std::string& msg, char sep);
|
11 |
andreas |
128 |
|
|
|
129 |
std::vector<CMD_TABLE> mCmdTable;
|
14 |
andreas |
130 |
PCHAIN_T *mPChain{nullptr};
|
|
|
131 |
SPCHAIN_T *mSPChain{nullptr};
|
|
|
132 |
MAPS_T mMap;
|
11 |
andreas |
133 |
};
|
|
|
134 |
|
|
|
135 |
#endif
|