Today's the day. Renamed platform to framework.

This commit is contained in:
Bastian Baetz
2016-06-15 23:48:41 +02:00
committed by Ulrich Mohr
parent 40987d0b27
commit 1d22a6c97e
356 changed files with 33946 additions and 3 deletions

22
serviceinterface/Makefile Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
#
# OSAL makefile
#
# Created on: Mar 04, 2010
# Author: ziemke
# Author: Claas Ziemke
# Copyright 2010, Claas Ziemke <claas.ziemke@gmx.net>
#
BASEDIR=../../
include $(BASEDIR)options.mk
OBJ = $(BUILDDIR)/OPUSLogger.o
all: $(OBJ)
$(BUILDDIR)/%.o: %.cpp %.h
$(CPP) $(CFLAGS) $(DEFINES) $(CCOPT) ${INCLUDE} -c $< -o $@
clean:
$(RM) *.o *.gcno *.gcda

View File

@ -0,0 +1,136 @@
/*
* ServiceInterfaceBuffer.cpp
*
* Created on: 06.08.2015
* Author: baetz
*/
#include <framework/osal/OSAL.h>
#include <framework/serviceinterface/ServiceInterfaceBuffer.h>
int ServiceInterfaceBuffer::overflow(int c) {
// Handle output
putChars(pbase(), pptr());
if (c != Traits::eof()) {
char c2 = c;
// Handle the one character that didn't fit to buffer
putChars(&c2, &c2 + 1);
}
// This tells that buffer is empty again
setp(buf, buf + BUF_SIZE - 1);
// I'm not sure about this return value!
return 0;
}
int ServiceInterfaceBuffer::sync(void) {
if (this->isActive) {
TimeOfDay_t loggerTime;
OSAL::getDateAndTime(&loggerTime);
char preamble[96] = { 0 };
sprintf(preamble, "%s: | %lu:%02lu:%02lu.%03lu | ",
this->log_message.c_str(), (unsigned long) loggerTime.hour,
(unsigned long) loggerTime.minute,
(unsigned long) loggerTime.second,
(unsigned long) loggerTime.ticks);
// Write log_message and time
this->putChars(preamble, preamble + sizeof(preamble));
// Handle output
this->putChars(pbase(), pptr());
}
// This tells that buffer is empty again
setp(buf, buf + BUF_SIZE - 1);
return 0;
}
#ifdef UT699
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);
#ifdef DEBUG
if (!OSAL::isInterruptInProgress()) {
std::cout << array;
} else {
//Uncomment the following line if you need ISR debug output.
// printk(array);
}
#else
#error Non-DEBUG out messages are not implemented. define DEBUG flag!
#endif
}
#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();
}
#ifdef DEBUG
if (udpSocket > 0) {
sendto(udpSocket, array, length, 0, (sockaddr*) &remoteAddress,
sizeof(remoteAddress));
}
#else
#error Non-DEBUG out messages are not implemented. define DEBUG flag!
#endif
}
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

View File

@ -0,0 +1,92 @@
/*
* ServiceInterfaceBuffer.h
*
* Created on: 06.08.2015
* Author: baetz
*/
#ifndef FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_
#define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_
#include <iostream>
#include <iosfwd>
#include <sstream>
#include <cstdio>
#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 <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/udp.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 /* FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_ */

View File

@ -0,0 +1,19 @@
/*
* ServiceInterfaceStream.cpp
*
* Created on: 06.08.2015
* Author: baetz
*/
#include <framework/serviceinterface/ServiceInterfaceStream.h>
void ServiceInterfaceStream::setActive( bool myActive) {
this->buf.isActive = myActive;
}
ServiceInterfaceStream::ServiceInterfaceStream(std::string set_message,
uint16_t port) :
std::basic_ostream<char, std::char_traits<char> >(&buf), buf(
set_message, port) {
}

View File

@ -0,0 +1,33 @@
/*
* ServiceInterfaceStream.h
*
* Created on: 06.08.2015
* Author: baetz
*/
#ifndef FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_
#define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_
#include <framework/serviceinterface/ServiceInterfaceBuffer.h>
#include <iostream>
#include <iosfwd>
#include <sstream>
#include <cstdio>
//Unfortunately, there must be a forward declaration of log_fe (MUST be defined in main), to let the system know where to write to.
extern std::ostream debug;
extern std::ostream info;
extern std::ostream warning;
extern std::ostream error;
class ServiceInterfaceStream : public std::basic_ostream< char, std::char_traits< char > > {
protected:
ServiceInterfaceBuffer buf;
public:
ServiceInterfaceStream( std::string set_message, uint16_t port = 1234 );
void setActive( bool );
};
#endif /* FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_ */