Skip to content

Commit ba6efd2

Browse files
committed
Allow capes to provide better labels for serial ports (Something like "DMX1" instead of "ttyS2")
1 parent 8b6cd76 commit ba6efd2

26 files changed

+253
-261
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@
140140
"htmlMeta.inc": "php",
141141
"footer.inc": "php",
142142
"menuHead.inc": "php",
143-
"shared_mutex": "cpp"
143+
"shared_mutex": "cpp",
144+
"forward_list": "cpp",
145+
"print": "cpp",
146+
"queue": "cpp"
144147
},
145148
"editor.formatOnSave": true,
146149
"cmake.configureOnOpen": false,

capes/drivers/bb64/fpp-reserve-memory.dts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,19 @@
1515
reg = <0x00 0x8f000000 0x00 0x00400000>;
1616
};
1717
};
18+
19+
&main_uart1 {
20+
status = "ok";
21+
};
22+
&main_uart2 {
23+
status = "ok";
24+
};
25+
&main_uart3 {
26+
status = "ok";
27+
};
28+
&main_uart4 {
29+
status = "ok";
30+
};
31+
&main_uart5 {
32+
status = "ok";
33+
};

src/channeloutput/GenericSerial.cpp

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,7 @@ FPPPlugins::Plugin* createPlugin() {
4343
*
4444
*/
4545
GenericSerialOutput::GenericSerialOutput(unsigned int startChannel, unsigned int channelCount) :
46-
ThreadedChannelOutput(startChannel, channelCount),
47-
m_deviceName("UNKNOWN"),
48-
m_fd(-1),
49-
m_speed(9600),
50-
m_headerSize(0),
51-
m_footerSize(0),
52-
m_packetSize(0),
53-
m_data(NULL) {
46+
ThreadedChannelOutput(startChannel, channelCount), SerialChannelOutput(), m_speed(9600), m_headerSize(0), m_footerSize(0), m_packetSize(0), m_data(NULL) {
5447
LogDebug(VB_CHANNELOUT, "GenericSerialOutput::GenericSerialOutput(%u, %u)\n",
5548
startChannel, channelCount);
5649

@@ -67,11 +60,6 @@ GenericSerialOutput::~GenericSerialOutput() {
6760
int GenericSerialOutput::Init(Json::Value config) {
6861
LogDebug(VB_CHANNELOUT, "GenericSerialOutput::Init()\n");
6962

70-
if (config.isMember("device")) {
71-
m_deviceName = config["device"].asString();
72-
LogDebug(VB_CHANNELOUT, "Using %s for Generic Serial output\n",
73-
m_deviceName.c_str());
74-
}
7563
if (config.isMember("speed")) {
7664
m_speed = config["speed"].asInt();
7765
}
@@ -98,13 +86,7 @@ int GenericSerialOutput::Init(Json::Value config) {
9886
memcpy(m_data + m_headerSize + m_channelCount,
9987
m_footer.c_str(), m_footerSize);
10088

101-
m_deviceName.insert(0, "/dev/");
102-
103-
m_fd = SerialOpen(m_deviceName.c_str(), m_speed, "8N1");
104-
105-
if (m_fd < 0) {
106-
LogErr(VB_CHANNELOUT, "Error %d opening %s: %s\n",
107-
errno, m_deviceName.c_str(), strerror(errno));
89+
if (!setupSerialPort(config, m_speed, "8N1")) {
10890
return 0;
10991
}
11092

@@ -120,11 +102,8 @@ void GenericSerialOutput::GetRequiredChannelRanges(const std::function<void(int,
120102
*/
121103
int GenericSerialOutput::Close(void) {
122104
LogDebug(VB_CHANNELOUT, "GenericSerialOutput::Close()\n");
123-
124-
SerialClose(m_fd);
125-
105+
closeSerialPort();
126106
delete[] m_data;
127-
128107
return ThreadedChannelOutput::Close();
129108
}
130109

@@ -149,9 +128,7 @@ int GenericSerialOutput::RawSendData(unsigned char* channelData) {
149128
*/
150129
void GenericSerialOutput::DumpConfig(void) {
151130
LogDebug(VB_CHANNELOUT, "GenericSerialOutput::DumpConfig()\n");
152-
153-
LogDebug(VB_CHANNELOUT, " Device Name: %s\n", m_deviceName.c_str());
154-
LogDebug(VB_CHANNELOUT, " fd : %d\n", m_fd);
131+
dumpSerialConfig();
155132
LogDebug(VB_CHANNELOUT, " Port Speed : %d\n", m_speed);
156133
LogDebug(VB_CHANNELOUT, " Header Size: %d\n", m_headerSize);
157134
LogDebug(VB_CHANNELOUT, " Header : '%s'\n", m_header.c_str());

src/channeloutput/GenericSerial.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313

1414
#include <string>
1515

16+
#include "SerialChannelOutput.h"
1617
#include "ThreadedChannelOutput.h"
1718

1819
#define GENERICSERIAL_MAX_CHANNELS 2048
1920

20-
class GenericSerialOutput : public ThreadedChannelOutput {
21+
class GenericSerialOutput : public ThreadedChannelOutput, SerialChannelOutput {
2122
public:
2223
GenericSerialOutput(unsigned int startChannel, unsigned int channelCount);
2324
virtual ~GenericSerialOutput();
@@ -31,8 +32,6 @@ class GenericSerialOutput : public ThreadedChannelOutput {
3132
virtual void GetRequiredChannelRanges(const std::function<void(int, int)>& addRange) override;
3233

3334
private:
34-
std::string m_deviceName;
35-
int m_fd;
3635
int m_speed;
3736
int m_headerSize;
3837
std::string m_header;

src/channeloutput/LOR.cpp

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "../common.h"
2121
#include "../log.h"
2222

23-
#include "serialutil.h"
23+
#include "SerialChannelOutput.h"
2424

2525
#include "LOR.h"
2626

@@ -30,21 +30,18 @@
3030

3131
/////////////////////////////////////////////////////////////////////////////
3232

33-
class LOROutputData {
33+
class LOROutputData : public SerialChannelOutput {
3434
public:
3535
LOROutputData() :
36-
fd(-1),
36+
SerialChannelOutput(),
3737
speed(19200),
3838
controllerOffset(0),
3939
lastHeartbeat(0) {
40-
filename[0] = 0;
4140
memset(lastValue, 0, LOR_MAX_CHANNELS);
4241
memset(intensityData, 0, LOR_INTENSITY_SIZE);
4342
memset(heartbeatData, 0, LOR_HEARTBEAT_SIZE);
4443
}
4544
~LOROutputData() {}
46-
char filename[1024];
47-
int fd;
4845
int speed;
4946
int controllerOffset;
5047
int maxIntensity;
@@ -105,17 +102,14 @@ static void LOR_SetupIntensityMap(LOROutputData* privData) {
105102

106103
int LOROutput::Close(void) {
107104
LogDebug(VB_CHANNELOUT, "LOROutput::Close()\n");
108-
109-
SerialClose(data->fd);
110-
data->fd = -1;
105+
data->closeSerialPort();
111106
return ChannelOutput::Close();
112107
}
113108

114109
void LOROutput::DumpConfig(void) {
115110
ChannelOutput::DumpConfig();
116111
if (data) {
117-
LogDebug(VB_CHANNELOUT, " filename : %s\n", data->filename);
118-
LogDebug(VB_CHANNELOUT, " fd : %d\n", data->fd);
112+
data->dumpSerialConfig();
119113
LogDebug(VB_CHANNELOUT, " port speed : %d\n", data->speed);
120114
LogDebug(VB_CHANNELOUT, " maxIntensity : %d\n", data->maxIntensity);
121115
LogDebug(VB_CHANNELOUT, " lastHeartbeat: %d\n", data->lastHeartbeat);
@@ -126,11 +120,6 @@ int LOROutput::Init(Json::Value config) {
126120
LogDebug(VB_CHANNELOUT, "LOROutput::Init()\n");
127121
data = new LOROutputData();
128122

129-
std::string deviceName = "UNKNOWN";
130-
if (config.isMember("device")) {
131-
deviceName = config["device"].asString();
132-
LogDebug(VB_CHANNELOUT, "Using %s for LOR output\n", deviceName.c_str());
133-
}
134123
if (config.isMember("speed")) {
135124
data->speed = config["speed"].asInt();
136125
}
@@ -141,21 +130,7 @@ int LOROutput::Init(Json::Value config) {
141130
data->controllerOffset -= 1;
142131
}
143132
}
144-
145-
if (deviceName == "UNKNOWN") {
146-
LogErr(VB_CHANNELOUT, "Missing Device Name\n");
147-
WarningHolder::AddWarning("LOR: Missing Device Name");
148-
return 0;
149-
}
150-
151-
strcpy(data->filename, "/dev/");
152-
strcat(data->filename, deviceName.c_str());
153-
154-
data->fd = SerialOpen(data->filename, data->speed, "8N1");
155-
if (data->fd < 0) {
156-
LogErr(VB_CHANNELOUT, "Error %d opening %s: %s\n",
157-
errno, data->filename, strerror(errno));
158-
WarningHolder::AddWarning("LOR: Error opening device: " + deviceName);
133+
if (!data->setupSerialPort(config, data->speed, "8N1")) {
159134
return 0;
160135
}
161136

@@ -188,8 +163,8 @@ static void LOR_SendHeartbeat(LOROutputData* privData) {
188163
if (privData->lastHeartbeat > (now - 300000))
189164
return;
190165

191-
if (privData->fd > 0) {
192-
write(privData->fd, privData->heartbeatData, LOR_HEARTBEAT_SIZE);
166+
if (privData->getFD() >= 0) {
167+
write(privData->getFD(), privData->heartbeatData, LOR_HEARTBEAT_SIZE);
193168
privData->lastHeartbeat = now;
194169
}
195170
}
@@ -215,7 +190,7 @@ int LOROutput::SendData(unsigned char* channelData) {
215190
data->intensityData[3] = data->intensityMap[channelData[i]];
216191
data->intensityData[4] = 0x80 | (i % 16);
217192

218-
write(data->fd, data->intensityData, LOR_INTENSITY_SIZE);
193+
write(data->getFD(), data->intensityData, LOR_INTENSITY_SIZE);
219194

220195
data->lastValue[i] = channelData[i];
221196
}

src/channeloutput/LOREnhanced.cpp

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020
#include "../common.h"
2121
#include "../log.h"
2222

23-
#include "serialutil.h"
24-
2523
#include "LOREnhanced.h"
24+
#include "SerialChannelOutput.h"
2625

2726
#define LORE_MAX_PIXELS_PER_UNIT 170
2827
#define LORE_MAX_CHANNELS_PER_UNIT LORE_MAX_PIXELS_PER_UNIT * 3
@@ -48,17 +47,15 @@ class LOREnhancedOutputUnit {
4847
unsigned char outputBuff[LORE_UNIT_MAX_PACKET];
4948
};
5049

51-
class LOREnhancedOutputData {
50+
class LOREnhancedOutputData : public SerialChannelOutput {
5251
public:
5352
LOREnhancedOutputData() :
54-
fd(-1),
53+
SerialChannelOutput(),
5554
speed(500000),
5655
lastHeartbeat(0) {
57-
filename[0] = 0;
5856
}
5957
~LOREnhancedOutputData() {}
60-
char filename[1024];
61-
int fd;
58+
6259
int speed;
6360
unsigned char intensityMap[256];
6461
long long lastHeartbeat;
@@ -111,17 +108,14 @@ static void LOREnhanced_SetupIntensityMap(LOREnhancedOutputData* privData) {
111108

112109
int LOREnhancedOutput::Close(void) {
113110
LogDebug(VB_CHANNELOUT, "LOREnhancedOutput::Close()\n");
114-
115-
SerialClose(data->fd);
116-
data->fd = -1;
111+
data->closeSerialPort();
117112
return ChannelOutput::Close();
118113
}
119114

120115
void LOREnhancedOutput::DumpConfig(void) {
121116
ChannelOutput::DumpConfig();
122117
if (data) {
123-
LogDebug(VB_CHANNELOUT, " filename : %s\n", data->filename);
124-
LogDebug(VB_CHANNELOUT, " fd : %d\n", data->fd);
118+
data->dumpSerialConfig();
125119
LogDebug(VB_CHANNELOUT, " port speed : %d\n", data->speed);
126120
LogDebug(VB_CHANNELOUT, " lastHeartbeat: %d\n", data->lastHeartbeat);
127121
}
@@ -137,11 +131,6 @@ int LOREnhancedOutput::Init(Json::Value config) {
137131
LogDebug(VB_CHANNELOUT, "LOREnhancedOutput::Init()\n");
138132
data = new LOREnhancedOutputData();
139133

140-
std::string deviceName = "UNKNOWN";
141-
if (config.isMember("device")) {
142-
deviceName = config["device"].asString();
143-
LogDebug(VB_CHANNELOUT, "Using %s for LOR output\n", deviceName.c_str());
144-
}
145134
if (config.isMember("speed")) {
146135
data->speed = config["speed"].asInt();
147136
}
@@ -165,21 +154,7 @@ int LOREnhancedOutput::Init(Json::Value config) {
165154
data->units.push_back(newUnit);
166155
}
167156
}
168-
169-
if (deviceName == "UNKNOWN") {
170-
LogErr(VB_CHANNELOUT, "Missing Device Name\n");
171-
WarningHolder::AddWarning("LOREnhanced: Missing Device Name");
172-
return 0;
173-
}
174-
175-
strcpy(data->filename, "/dev/");
176-
strcat(data->filename, deviceName.c_str());
177-
178-
data->fd = SerialOpen(data->filename, data->speed, "8N1");
179-
if (data->fd < 0) {
180-
LogErr(VB_CHANNELOUT, "Error %d opening %s: %s\n",
181-
errno, data->filename, strerror(errno));
182-
WarningHolder::AddWarning("LOREnhanced: Error opening device: " + deviceName);
157+
if (!data->setupSerialPort(config, data->speed, "8N1")) {
183158
return 0;
184159
}
185160

@@ -201,8 +176,8 @@ static void LOR_SendHeartbeat(LOREnhancedOutputData* privData) {
201176
if (privData->lastHeartbeat > (now - 300000))
202177
return;
203178

204-
if (privData->fd > 0) {
205-
write(privData->fd, privData->heartbeatData, LOR_HEARTBEAT_SIZE);
179+
if (privData->getFD() >= 0) {
180+
write(privData->getFD(), privData->heartbeatData, LOR_HEARTBEAT_SIZE);
206181
privData->lastHeartbeat = now;
207182
}
208183
}
@@ -288,7 +263,7 @@ void LOREnhancedOutput::SendUnitData(unsigned char* channelData, LOREnhancedOutp
288263
}
289264
}
290265

291-
write(data->fd, unit->outputBuff, bufAt + 1);
266+
write(data->getFD(), unit->outputBuff, bufAt + 1);
292267
}
293268

294269
int LOREnhancedOutput::SendData(unsigned char* channelData) {

0 commit comments

Comments
 (0)