Fix VS2015 compile for LCDProc.

This commit is contained in:
Jonathan Naylor
2016-10-31 17:52:27 +00:00
parent 8303a940b1
commit 202764dedd
4 changed files with 42 additions and 57 deletions

View File

@@ -22,10 +22,10 @@
#include <cstdio> #include <cstdio>
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include <cstdlib>
#include <ctime>
#include <stdlib.h> #if !defined(_WIN32) && !defined(_WIN64)
#include <stdio.h>
#include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/select.h> #include <sys/select.h>
#include <sys/socket.h> #include <sys/socket.h>
@@ -35,6 +35,9 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <stdarg.h> #include <stdarg.h>
#else
#include <winsock.h>
#endif
#define BUFFER_MAX_LEN 128 #define BUFFER_MAX_LEN 128
@@ -117,6 +120,7 @@ bool CLCDproc::open()
} }
socketPrintf(m_socketfd, "hello"); // Login to the LCD server socketPrintf(m_socketfd, "hello"); // Login to the LCD server
return true; return true;
} }
@@ -188,14 +192,12 @@ void CLCDproc::writeDStarInt(const char* my1, const char* my2, const char* your,
*p = '_'; *p = '_';
} }
if (strcmp(reflector, " ") != 0) { if (strcmp(reflector, " ") != 0)
sprintf(m_displayBuffer2, " via %.8s", reflector); sprintf(m_displayBuffer2, " via %.8s", reflector);
} else { else
//bzero(m_displayBuffer2, BUFFER_MAX_LEN);
memset(m_displayBuffer2, 0, BUFFER_MAX_LEN); memset(m_displayBuffer2, 0, BUFFER_MAX_LEN);
}
if (m_rows == 2) { if (m_rows == 2U) {
socketPrintf(m_socketfd, "widget_set DStar Line2 1 2 %u 2 h 3 \"%.8s/%.4s to %s%s\"", m_cols - 1, my1, my2, m_displayBuffer1, m_displayBuffer2); socketPrintf(m_socketfd, "widget_set DStar Line2 1 2 %u 2 h 3 \"%.8s/%.4s to %s%s\"", m_cols - 1, my1, my2, m_displayBuffer1, m_displayBuffer2);
} else { } else {
socketPrintf(m_socketfd, "widget_set DStar Line2 1 2 %u 2 h 3 \"%.8s/%.4s\"", m_cols - 1, my1, my2); socketPrintf(m_socketfd, "widget_set DStar Line2 1 2 %u 2 h 3 \"%.8s/%.4s\"", m_cols - 1, my1, my2);
@@ -224,15 +226,13 @@ void CLCDproc::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro
socketPrintf(m_socketfd, "screen_set DMR -priority foreground"); socketPrintf(m_socketfd, "screen_set DMR -priority foreground");
if (m_duplex) { if (m_duplex) {
if (m_rows > 2U) { if (m_rows > 2U)
socketPrintf(m_socketfd, "widget_set DMR Mode 1 1 DMR"); socketPrintf(m_socketfd, "widget_set DMR Mode 1 1 DMR");
}
if (slotNo == 1U) { if (slotNo == 1U)
socketPrintf(m_socketfd, "widget_set DMR Slot2 3 %u %u %u h 3 \"Listening\"", m_rows / 2 + 1, m_cols - 1, m_rows / 2 + 1); socketPrintf(m_socketfd, "widget_set DMR Slot2 3 %u %u %u h 3 \"Listening\"", m_rows / 2 + 1, m_cols - 1, m_rows / 2 + 1);
} else { else
socketPrintf(m_socketfd, "widget_set DMR Slot1 3 %u %u %u h 3 \"Listening\"", m_rows / 2, m_cols - 1, m_rows / 2); socketPrintf(m_socketfd, "widget_set DMR Slot1 3 %u %u %u h 3 \"Listening\"", m_rows / 2, m_cols - 1, m_rows / 2);
}
} else { } else {
socketPrintf(m_socketfd, "widget_set DMR Slot1_ 1 %u \"\"", m_rows / 2); socketPrintf(m_socketfd, "widget_set DMR Slot1_ 1 %u \"\"", m_rows / 2);
socketPrintf(m_socketfd, "widget_set DMR Slot2_ 1 %u \"\"", m_rows / 2 + 1); socketPrintf(m_socketfd, "widget_set DMR Slot2_ 1 %u \"\"", m_rows / 2 + 1);
@@ -243,15 +243,13 @@ void CLCDproc::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro
} }
if (m_duplex) { if (m_duplex) {
if (m_rows > 2U) { if (m_rows > 2U)
socketPrintf(m_socketfd, "widget_set DMR Mode 1 1 DMR"); socketPrintf(m_socketfd, "widget_set DMR Mode 1 1 DMR");
}
if (slotNo == 1U) { if (slotNo == 1U)
socketPrintf(m_socketfd, "widget_set DMR Slot1 3 %u %u %u h 3 \"%s > %s%s\"", m_rows / 2, m_cols - 1, m_rows / 2, src.c_str(), group ? "TG" : "", dst.c_str()); socketPrintf(m_socketfd, "widget_set DMR Slot1 3 %u %u %u h 3 \"%s > %s%s\"", m_rows / 2, m_cols - 1, m_rows / 2, src.c_str(), group ? "TG" : "", dst.c_str());
} else { else
socketPrintf(m_socketfd, "widget_set DMR Slot2 3 %u %u %u h 3 \"%s > %s%s\"", m_rows / 2 + 1, m_cols - 1, m_rows / 2 + 1, src.c_str(), group ? "TG" : "", dst.c_str()); socketPrintf(m_socketfd, "widget_set DMR Slot2 3 %u %u %u h 3 \"%s > %s%s\"", m_rows / 2 + 1, m_cols - 1, m_rows / 2 + 1, src.c_str(), group ? "TG" : "", dst.c_str());
}
} else { } else {
socketPrintf(m_socketfd, "widget_set DMR Mode 1 1 DMR"); socketPrintf(m_socketfd, "widget_set DMR Mode 1 1 DMR");
@@ -271,11 +269,10 @@ void CLCDproc::clearDMRInt(unsigned int slotNo)
m_clockDisplayTimer.stop(); // Stop the clock display m_clockDisplayTimer.stop(); // Stop the clock display
if (m_duplex) { if (m_duplex) {
if (slotNo == 1U) { if (slotNo == 1U)
socketPrintf(m_socketfd, "widget_set DMR Slot1 3 %u %u %u h 3 \"Listening\"", m_rows / 2, m_cols - 1, m_rows / 2); socketPrintf(m_socketfd, "widget_set DMR Slot1 3 %u %u %u h 3 \"Listening\"", m_rows / 2, m_cols - 1, m_rows / 2);
} else { else
socketPrintf(m_socketfd, "widget_set DMR Slot2 3 %u %u %u h 3 \"Listening\"", m_rows / 2 + 1, m_cols - 1, m_rows / 2 + 1); socketPrintf(m_socketfd, "widget_set DMR Slot2 3 %u %u %u h 3 \"Listening\"", m_rows / 2 + 1, m_cols - 1, m_rows / 2 + 1);
}
} else { } else {
socketPrintf(m_socketfd, "widget_set DMR Slot1 1 2 15 2 h 3 Listening"); socketPrintf(m_socketfd, "widget_set DMR Slot1 1 2 15 2 h 3 Listening");
socketPrintf(m_socketfd, "widget_set DMR Slot2 1 3 15 3 h 3 \"\""); socketPrintf(m_socketfd, "widget_set DMR Slot2 1 3 15 3 h 3 \"\"");
@@ -360,11 +357,10 @@ void CLCDproc::clockInt(unsigned int ms)
struct tm *Time; struct tm *Time;
time(&currentTime); time(&currentTime);
if (m_utc) { if (m_utc)
Time = gmtime(&currentTime); Time = gmtime(&currentTime);
} else { else
Time = localtime(&currentTime); Time = localtime(&currentTime);
}
setlocale(LC_TIME, ""); setlocale(LC_TIME, "");
strftime(m_displayBuffer1, 128, "%X", Time); // Time strftime(m_displayBuffer1, 128, "%X", Time); // Time
@@ -385,7 +381,6 @@ void CLCDproc::clockInt(unsigned int ms)
// Then we put all the descriptors we want to wait for in a mask = m_readfds // Then we put all the descriptors we want to wait for in a mask = m_readfds
FD_SET(m_socketfd, &m_readfds); FD_SET(m_socketfd, &m_readfds);
FD_SET(STDIN_FILENO, &m_readfds); // STDIN_FILENO = 0 (standard input);
// Timeout, we will stop waiting for information // Timeout, we will stop waiting for information
m_timeout.tv_sec = 0; m_timeout.tv_sec = 0;
@@ -411,16 +406,14 @@ void CLCDproc::clockInt(unsigned int ms)
m_buffer[m_recvsize] = '\0'; m_buffer[m_recvsize] = '\0';
int i = 0;
char *argv[256]; char *argv[256];
int argc, newtoken; size_t len = strlen(m_buffer);
int len = strlen(m_buffer);
// Now split the string into tokens... // Now split the string into tokens...
argc = 0; int argc = 0;
newtoken = 1; int newtoken = 1;
for (i = 0; i < len; i++) { for (size_t i = 0U; i < len; i++) {
switch (m_buffer[i]) { switch (m_buffer[i]) {
case ' ': case ' ':
newtoken = 1; newtoken = 1;
@@ -485,23 +478,10 @@ void CLCDproc::clockInt(unsigned int ms)
} }
} }
if (!m_screensDefined && m_connected) { if (!m_screensDefined && m_connected)
defineScreens(); defineScreens();
} }
// Uncomment the next section of code to test server commands from STDIN
// only for debugging purposes!
/*
if (FD_ISSET(STDIN_FILENO, &m_readfds)) {
fgets(m_buffer, BUFFER_MAX_LEN, stdin);
if (send(m_socketfd, m_buffer, strlen(m_buffer) + 1, 0) == -1)
LogError("LCDproc, cannot send data");
}
*/
}
void CLCDproc::close() void CLCDproc::close()
{ {
} }
@@ -510,10 +490,9 @@ int CLCDproc::socketPrintf(int fd, const char *format, ...)
{ {
char buf[BUFFER_MAX_LEN]; char buf[BUFFER_MAX_LEN];
va_list ap; va_list ap;
unsigned int size = 0;
va_start(ap, format); va_start(ap, format);
size = vsnprintf(buf, sizeof(buf), format, ap); int size = vsnprintf(buf, BUFFER_MAX_LEN, format, ap);
va_end(ap); va_end(ap);
if (size < 0) { if (size < 0) {
@@ -521,7 +500,7 @@ int CLCDproc::socketPrintf(int fd, const char *format, ...)
return -1; return -1;
} }
if (size > sizeof(buf)) if (size > BUFFER_MAX_LEN)
LogWarning("LCDproc, socketPrintf: vsnprintf truncated message"); LogWarning("LCDproc, socketPrintf: vsnprintf truncated message");
FD_ZERO(&m_writefds); // empty writefds FD_ZERO(&m_writefds); // empty writefds
@@ -534,7 +513,7 @@ int CLCDproc::socketPrintf(int fd, const char *format, ...)
LogError("LCDproc, error on select"); LogError("LCDproc, error on select");
if (FD_ISSET(m_socketfd, &m_writefds)) { if (FD_ISSET(m_socketfd, &m_writefds)) {
if (send(m_socketfd, buf, strlen(buf) + 1, 0) == -1) { if (send(m_socketfd, buf, int(strlen(buf) + 1U), 0) == -1) {
LogError("LCDproc, cannot send data"); LogError("LCDproc, cannot send data");
return -1; return -1;
} }

View File

@@ -23,7 +23,6 @@
#include "Timer.h" #include "Timer.h"
#include <string> #include <string>
#include <vector>
class CLCDproc : public CDisplay class CLCDproc : public CDisplay
{ {
@@ -57,10 +56,6 @@ protected:
virtual void clockInt(unsigned int ms); virtual void clockInt(unsigned int ms);
virtual int socketPrintf(int fd, const char *format, ...);
virtual void defineScreens();
private: private:
std::string m_address; std::string m_address;
unsigned int m_port; unsigned int m_port;
@@ -73,6 +68,9 @@ private:
bool m_dimOnIdle; bool m_dimOnIdle;
bool m_dmr; bool m_dmr;
CTimer m_clockDisplayTimer; CTimer m_clockDisplayTimer;
int socketPrintf(int fd, const char *format, ...);
void defineScreens();
}; };
#endif #endif

View File

@@ -177,6 +177,7 @@
<ClInclude Include="Golay24128.h" /> <ClInclude Include="Golay24128.h" />
<ClInclude Include="Hamming.h" /> <ClInclude Include="Hamming.h" />
<ClInclude Include="DMRLookup.h" /> <ClInclude Include="DMRLookup.h" />
<ClInclude Include="LCDproc.h" />
<ClInclude Include="Log.h" /> <ClInclude Include="Log.h" />
<ClInclude Include="MMDVMHost.h" /> <ClInclude Include="MMDVMHost.h" />
<ClInclude Include="Modem.h" /> <ClInclude Include="Modem.h" />
@@ -243,6 +244,7 @@
<ClCompile Include="Golay2087.cpp" /> <ClCompile Include="Golay2087.cpp" />
<ClCompile Include="Golay24128.cpp" /> <ClCompile Include="Golay24128.cpp" />
<ClCompile Include="Hamming.cpp" /> <ClCompile Include="Hamming.cpp" />
<ClCompile Include="LCDproc.cpp" />
<ClCompile Include="Log.cpp" /> <ClCompile Include="Log.cpp" />
<ClCompile Include="MMDVMHost.cpp" /> <ClCompile Include="MMDVMHost.cpp" />
<ClCompile Include="Modem.cpp" /> <ClCompile Include="Modem.cpp" />

View File

@@ -212,6 +212,9 @@
<ClInclude Include="Mutex.h"> <ClInclude Include="Mutex.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="LCDproc.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="BPTC19696.cpp"> <ClCompile Include="BPTC19696.cpp">
@@ -394,5 +397,8 @@
<ClCompile Include="Mutex.cpp"> <ClCompile Include="Mutex.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="LCDproc.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>