Merge pull request 'remove bsp specific code' (#679) from mueller/remove-bsp-specific-code into development
Reviewed-on: fsfw/fsfw#679
This commit is contained in:
commit
aed30d54ef
@ -1,8 +1,8 @@
|
||||
#include "fsfw/serviceinterface/ServiceInterfaceBuffer.h"
|
||||
#include "ServiceInterfaceBuffer.h"
|
||||
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <cinttypes>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// to be implemented by bsp
|
||||
extern "C" void printChar(const char*, bool errStream);
|
||||
|
||||
#ifndef UT699
|
||||
|
||||
ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string setMessage, bool addCrToPreamble,
|
||||
bool buffered, bool errStream, uint16_t port)
|
||||
: isActive(true),
|
||||
@ -77,8 +75,6 @@ void ServiceInterfaceBuffer::putChars(char const* begin, char const* end) {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int ServiceInterfaceBuffer::overflow(int c) {
|
||||
if (not buffered and this->isActive) {
|
||||
if (c != Traits::eof()) {
|
||||
@ -172,89 +168,4 @@ void ServiceInterfaceBuffer::setAsciiColorPrefix(std::string colorPrefix) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef UT699
|
||||
#include "../osal/rtems/Interrupt.h"
|
||||
|
||||
ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string set_message, uint16_t port) {
|
||||
this->log_message = set_message;
|
||||
this->isActive = true;
|
||||
setp(buf, buf + BUF_SIZE);
|
||||
}
|
||||
|
||||
void ServiceInterfaceBuffer::putChars(char const* begin, char const* end) {
|
||||
char array[BUF_SIZE];
|
||||
uint32_t length = end - begin;
|
||||
if (length > sizeof(array)) {
|
||||
length = sizeof(array);
|
||||
}
|
||||
memcpy(array, begin, length);
|
||||
|
||||
if (!Interrupt::isInterruptInProgress()) {
|
||||
std::cout << array;
|
||||
} else {
|
||||
// Uncomment the following line if you need ISR debug output.
|
||||
// printk(array);
|
||||
}
|
||||
}
|
||||
#endif // UT699
|
||||
|
||||
#ifdef ML505
|
||||
#include <bsp_flp/network/networkconfig.h>
|
||||
ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string set_message, uint16_t port)
|
||||
: isActive(true),
|
||||
log_message(set_message),
|
||||
udpSocket(0),
|
||||
remoteAddressLength(sizeof(remoteAddress)) {
|
||||
setp(buf, buf + BUF_SIZE);
|
||||
memset((uint8_t*)&remoteAddress, 0, sizeof(remoteAddress));
|
||||
remoteAddress.sin_family = AF_INET;
|
||||
remoteAddress.sin_port = htons(port);
|
||||
remoteAddress.sin_addr.s_addr = htonl(inet_addr("192.168.250.100"));
|
||||
}
|
||||
|
||||
void ServiceInterfaceBuffer::putChars(char const* begin, char const* end) {
|
||||
char array[BUF_SIZE];
|
||||
uint32_t length = end - begin;
|
||||
if (length > sizeof(array)) {
|
||||
length = sizeof(array);
|
||||
}
|
||||
memcpy(array, begin, length);
|
||||
|
||||
if (udpSocket <= 0) {
|
||||
initSocket();
|
||||
}
|
||||
|
||||
if (udpSocket > 0) {
|
||||
sendto(udpSocket, array, length, 0, (sockaddr*)&remoteAddress, sizeof(remoteAddress));
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceInterfaceBuffer::initSocket() {
|
||||
sockaddr_in address;
|
||||
memset((uint8_t*)&address, 0, sizeof(address));
|
||||
address.sin_family = AF_INET;
|
||||
address.sin_port = htons(0);
|
||||
address.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
udpSocket = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
if (socket < 0) {
|
||||
printf("Error opening socket!\n");
|
||||
return;
|
||||
}
|
||||
timeval timeout = {0, 20};
|
||||
if (setsockopt(udpSocket, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0) {
|
||||
printf("Error setting SO_RCVTIMEO socket options!\n");
|
||||
return;
|
||||
}
|
||||
if (setsockopt(udpSocket, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)) < 0) {
|
||||
printf("Error setting SO_SNDTIMEO socket options!\n");
|
||||
return;
|
||||
}
|
||||
if (bind(udpSocket, (sockaddr*)&address, sizeof(address)) < 0) {
|
||||
printf("Error binding socket!\n");
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ML505
|
||||
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif
|
||||
|
@ -1,9 +1,8 @@
|
||||
#ifndef FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_
|
||||
#define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_
|
||||
|
||||
#include <FSFWConfig.h>
|
||||
|
||||
#include "../returnvalues/returnvalue.h"
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "fsfw/returnvalues/returnvalue.h"
|
||||
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
|
||||
@ -11,8 +10,6 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#ifndef UT699
|
||||
|
||||
/**
|
||||
* @brief This is the underlying stream buffer which implements the
|
||||
* streambuf class and overloads the overflow() and sync() methods
|
||||
@ -77,85 +74,6 @@ class ServiceInterfaceBuffer : public std::streambuf {
|
||||
bool crAdditionEnabled() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef UT699
|
||||
class ServiceInterfaceBuffer : public std::basic_streambuf<char, std::char_traits<char> > {
|
||||
friend class ServiceInterfaceStream;
|
||||
|
||||
public:
|
||||
ServiceInterfaceBuffer(std::string set_message, uint16_t port);
|
||||
|
||||
protected:
|
||||
bool isActive;
|
||||
// This is called when buffer becomes full. If
|
||||
// buffer is not used, then this is called every
|
||||
// time when characters are put to stream.
|
||||
virtual int overflow(int c = Traits::eof());
|
||||
|
||||
// This function is called when stream is flushed,
|
||||
// for example when std::endl is put to stream.
|
||||
virtual int sync(void);
|
||||
|
||||
private:
|
||||
// For additional message information
|
||||
std::string log_message;
|
||||
// For EOF detection
|
||||
typedef std::char_traits<char> Traits;
|
||||
|
||||
// Work in buffer mode. It is also possible to work without buffer.
|
||||
static size_t const BUF_SIZE = 128;
|
||||
char buf[BUF_SIZE];
|
||||
|
||||
// In this function, the characters are parsed.
|
||||
void putChars(char const* begin, char const* end);
|
||||
};
|
||||
#endif // UT699
|
||||
|
||||
#ifdef ML505
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
class ServiceInterfaceBuffer : public std::basic_streambuf<char, std::char_traits<char> > {
|
||||
friend class ServiceInterfaceStream;
|
||||
|
||||
public:
|
||||
ServiceInterfaceBuffer(std::string set_message, uint16_t port);
|
||||
|
||||
protected:
|
||||
bool isActive;
|
||||
// This is called when buffer becomes full. If
|
||||
// buffer is not used, then this is called every
|
||||
// time when characters are put to stream.
|
||||
virtual int overflow(int c = Traits::eof());
|
||||
|
||||
// This function is called when stream is flushed,
|
||||
// for example when std::endl is put to stream.
|
||||
virtual int sync(void);
|
||||
|
||||
private:
|
||||
// For additional message information
|
||||
std::string log_message;
|
||||
// For EOF detection
|
||||
typedef std::char_traits<char> Traits;
|
||||
|
||||
// Work in buffer mode. It is also possible to work without buffer.
|
||||
static size_t const BUF_SIZE = 128;
|
||||
char buf[BUF_SIZE];
|
||||
|
||||
// In this function, the characters are parsed.
|
||||
void putChars(char const* begin, char const* end);
|
||||
|
||||
int udpSocket;
|
||||
sockaddr_in remoteAddress;
|
||||
socklen_t remoteAddressLength;
|
||||
void initSocket();
|
||||
};
|
||||
#endif // ML505
|
||||
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
|
||||
#endif /* FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user