mirror of https://github.com/n7tae/new-xlxd.git
parent
004cea67a3
commit
1c9ee1b8c1
@ -0,0 +1,50 @@
|
||||
#copyright(C) 2020 by Thomas A. Early, N7TAE
|
||||
|
||||
# If you are going to change this path, you will
|
||||
# need to update the systemd service script
|
||||
BINDIR=/usr/local/bin
|
||||
|
||||
GCC=g++
|
||||
|
||||
# uncomment the next line to enable gdb debugging help
|
||||
#DEBUG=true
|
||||
|
||||
CFLAGS=-W -MMD -MD -std=c++11
|
||||
ifdef DEBUG
|
||||
CFLAGS+=-ggdb3
|
||||
endif
|
||||
|
||||
LDFLAGS=-pthread
|
||||
|
||||
SRCS=cagc.cpp cbuffer.cpp cfirfilter.cpp cip.cpp csignalprocessor.cpp cusb3003hrinterface.cpp cvocodecchannel.cpp cvoicepacket.cpp cambepacket.cpp ccallsign.cpp cfixedgain.cpp cpacket.cpp cstream.cpp cusb3000interface.cpp cusb3003interface.cpp cvocodecinterface.cpp main.cpp cambeserver.cpp ccontroller.cpp cftdidevicedescr.cpp cpacketqueue.cpp ctimepoint.cpp cusb3003df2etinterface.cpp cusb3xxxinterface.cpp cvocodecs.cpp cudpsocket.cpp
|
||||
|
||||
OBJS=$(SRCS:.cpp=.o)
|
||||
DEPS=$(SRCS:.cpp=.d)
|
||||
EXE=ambed
|
||||
|
||||
$(EXE) : $(OBJS)
|
||||
$(GCC) $(LDFLAGS) $(OBJS) -lftd2xx -Wl,-rpath,/usr/local/lib -o $@
|
||||
|
||||
%.o : %.cpp
|
||||
$(GCC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean :
|
||||
$(RM) $(EXE) *.o *.d
|
||||
|
||||
-include $(DEPS)
|
||||
|
||||
# The install and uninstall targets need to be run by root
|
||||
install : $(EXE) $(EXE).service
|
||||
cp $(EXE) $(BINDIR)
|
||||
cp $(EXE).service /etc/systemd/system/
|
||||
systemctl enable ambed
|
||||
systemctl daemon-reload
|
||||
systemctl start ambed
|
||||
|
||||
uninstall :
|
||||
systemctl stop ambed
|
||||
systemctl disable ambed
|
||||
systemctl daemon-reload
|
||||
rm -f /etc/systemd/system/ambed.service
|
||||
rm -f $(BINDIR)/ambed
|
||||
systemctl daemon-reload
|
||||
@ -1,200 +0,0 @@
|
||||
//
|
||||
// cbuffer.cpp
|
||||
// xlxd
|
||||
//
|
||||
// Created by Jean-Luc Deltombe (LX3JL) on 02/11/2015.
|
||||
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// This file is part of xlxd.
|
||||
//
|
||||
// xlxd is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// xlxd is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "main.h"
|
||||
#include <string.h>
|
||||
#include "cbuffer.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// constructor
|
||||
|
||||
CBuffer::CBuffer(uint8 *buffer, int len)
|
||||
{
|
||||
resize(len);
|
||||
::memcpy(data(), buffer, len);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// set
|
||||
|
||||
void CBuffer::Set(uint8 *buffer, int len)
|
||||
{
|
||||
resize(len);
|
||||
::memcpy(data(), buffer, len);
|
||||
}
|
||||
|
||||
void CBuffer::Set(const char *sz)
|
||||
{
|
||||
resize(::strlen(sz)+1);
|
||||
::strcpy((char *)data(), sz);
|
||||
}
|
||||
|
||||
void CBuffer::Append(uint8 *buffer, int len)
|
||||
{
|
||||
int n = (int)size();
|
||||
resize(n+len);
|
||||
::memcpy(&(data()[n]), buffer, len);
|
||||
}
|
||||
|
||||
void CBuffer::Append(uint8 ui, int len)
|
||||
{
|
||||
int n = (int)size();
|
||||
resize(n+len);
|
||||
::memset(&(data()[n]), ui, len);
|
||||
}
|
||||
|
||||
void CBuffer::Append(uint8 ui)
|
||||
{
|
||||
int n = (int)size();
|
||||
resize(n+sizeof(uint8));
|
||||
::memcpy(&(data()[n]), &ui, sizeof(uint8));
|
||||
}
|
||||
|
||||
void CBuffer::Append(uint16 ui)
|
||||
{
|
||||
int n = (int)size();
|
||||
resize(n+sizeof(uint16));
|
||||
::memcpy(&(data()[n]), &ui, sizeof(uint16));
|
||||
}
|
||||
|
||||
void CBuffer::Append(uint32 ui)
|
||||
{
|
||||
int n = (int)size();
|
||||
resize(n+sizeof(uint32));
|
||||
::memcpy(&(data()[n]), &ui, sizeof(uint32));
|
||||
}
|
||||
|
||||
void CBuffer::Append(const char *sz)
|
||||
{
|
||||
Append((uint8 *)sz, (int)strlen(sz));
|
||||
Append((uint8)0x00);
|
||||
}
|
||||
|
||||
void CBuffer::ReplaceAt(int i, uint8 ui)
|
||||
{
|
||||
if ( size() < (i+sizeof(uint8)) )
|
||||
{
|
||||
resize(i+sizeof(uint8));
|
||||
}
|
||||
*(uint8 *)(&(data()[i])) = ui;
|
||||
}
|
||||
|
||||
void CBuffer::ReplaceAt(int i, uint16 ui)
|
||||
{
|
||||
if ( size() < (i+sizeof(uint16)) )
|
||||
{
|
||||
resize(i+sizeof(uint16));
|
||||
}
|
||||
*(uint16 *)(&(data()[i])) = ui;
|
||||
}
|
||||
|
||||
void CBuffer::ReplaceAt(int i, uint32 ui)
|
||||
{
|
||||
if ( size() < (i+sizeof(uint32)) )
|
||||
{
|
||||
resize(i+sizeof(uint32));
|
||||
}
|
||||
*(uint32 *)(&(data()[i])) = ui;
|
||||
}
|
||||
|
||||
void CBuffer::ReplaceAt(int i, const uint8 *ptr, int len)
|
||||
{
|
||||
if ( size() < (i+len) )
|
||||
{
|
||||
resize(i+len);
|
||||
}
|
||||
::memcpy(&(data()[i]), ptr, len);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// operation
|
||||
|
||||
int CBuffer::Compare(uint8 *buffer, int len) const
|
||||
{
|
||||
int result = -1;
|
||||
if ( size() >= len )
|
||||
{
|
||||
result = ::memcmp(data(), buffer, len);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int CBuffer::Compare(uint8 *buffer, int off, int len) const
|
||||
{
|
||||
int result = -1;
|
||||
if ( size() >= (off+len) )
|
||||
{
|
||||
result = ::memcmp(&(data()[off]), buffer, len);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// operator
|
||||
|
||||
bool CBuffer::operator ==(const CBuffer &Buffer) const
|
||||
{
|
||||
if ( size() == Buffer.size() )
|
||||
{
|
||||
return (::memcmp((const char *)data(), (const char *)Buffer.data(), size()) == 0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CBuffer::operator ==(const char *sz) const
|
||||
{
|
||||
if ( size() == ::strlen(sz) )
|
||||
{
|
||||
return (::memcmp((const char *)data(), sz, size()) == 0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CBuffer::operator const char *() const
|
||||
{
|
||||
return (const char *)data();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// debug
|
||||
|
||||
void CBuffer::DebugDump(std::ofstream &debugout)
|
||||
{
|
||||
for ( int i = 0; i < size(); i++ )
|
||||
{
|
||||
char sz[16];
|
||||
sprintf(sz, "%02X", data()[i]);
|
||||
debugout << sz;
|
||||
if ( i == size()-1 )
|
||||
{
|
||||
debugout << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
debugout << ',';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1 @@
|
||||
../src/cbuffer.cpp
|
||||
@ -1,68 +0,0 @@
|
||||
//
|
||||
// cbuffer.h
|
||||
// xlxd
|
||||
//
|
||||
// Created by Jean-Luc Deltombe (LX3JL) on 02/11/2015.
|
||||
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// This file is part of xlxd.
|
||||
//
|
||||
// xlxd is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// xlxd is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef cbuffer_h
|
||||
#define cbuffer_h
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CBuffer : public std::vector<uint8>
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
CBuffer() {};
|
||||
CBuffer(uint8 *, int);
|
||||
|
||||
// destructor
|
||||
virtual ~CBuffer() {};
|
||||
|
||||
// set
|
||||
void Set(uint8 *, int);
|
||||
void Set(const char *);
|
||||
void Append(uint8 *, int);
|
||||
void Append(uint8, int);
|
||||
void Append(uint8);
|
||||
void Append(uint16);
|
||||
void Append(uint32);
|
||||
void Append(const char *);
|
||||
void ReplaceAt(int, uint8);
|
||||
void ReplaceAt(int, uint16);
|
||||
void ReplaceAt(int, uint32);
|
||||
void ReplaceAt(int, const uint8 *, int);
|
||||
|
||||
// operation
|
||||
int Compare(uint8 *, int) const;
|
||||
int Compare(uint8 *, int, int) const;
|
||||
|
||||
// operator
|
||||
bool operator ==(const CBuffer &) const;
|
||||
bool operator ==(const char *) const;
|
||||
operator const char *() const;
|
||||
|
||||
// debug
|
||||
void DebugDump(std::ofstream &);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
#endif /* cbuffer_h */
|
||||
@ -0,0 +1 @@
|
||||
../src/cbuffer.h
|
||||
@ -1,91 +0,0 @@
|
||||
//
|
||||
// cip.cpp
|
||||
// xlxd
|
||||
//
|
||||
// Created by Jean-Luc Deltombe (LX3JL) on 31/10/2015.
|
||||
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// This file is part of xlxd.
|
||||
//
|
||||
// xlxd is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// xlxd is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "main.h"
|
||||
#include <string.h>
|
||||
#include "cip.h"
|
||||
|
||||
#include <netdb.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// constructors
|
||||
|
||||
CIp::CIp()
|
||||
{
|
||||
::memset(&m_Addr, 0, sizeof(m_Addr));
|
||||
m_Addr.sin_family = AF_INET;
|
||||
}
|
||||
|
||||
CIp::CIp(const char *sz)
|
||||
{
|
||||
::memset(&m_Addr, 0, sizeof(m_Addr));
|
||||
m_Addr.sin_family = AF_INET;
|
||||
// try xxx.xxx.xxx.xxxx first
|
||||
m_Addr.sin_addr.s_addr = inet_addr(sz);
|
||||
if ( m_Addr.sin_addr.s_addr == INADDR_NONE )
|
||||
{
|
||||
// otherwise try to resolve via dns
|
||||
hostent *record = gethostbyname(sz);
|
||||
if( record != NULL )
|
||||
{
|
||||
m_Addr.sin_addr.s_addr = ((in_addr * )record->h_addr)->s_addr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CIp::CIp(const struct sockaddr_in *sa)
|
||||
{
|
||||
::memcpy(&m_Addr, sa, sizeof(m_Addr));
|
||||
}
|
||||
|
||||
|
||||
CIp::CIp(const CIp &ip)
|
||||
{
|
||||
::memcpy(&m_Addr, &ip.m_Addr, sizeof(m_Addr));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// set
|
||||
|
||||
void CIp::SetSockAddr(struct sockaddr_in *sa)
|
||||
{
|
||||
::memcpy(&m_Addr, sa, sizeof(m_Addr));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// operator
|
||||
|
||||
bool CIp::operator ==(const CIp &ip) const
|
||||
{
|
||||
return ( (ip.m_Addr.sin_family == m_Addr.sin_family) &&
|
||||
(ip.m_Addr.sin_addr.s_addr == m_Addr.sin_addr.s_addr) &&
|
||||
(ip.m_Addr.sin_port == m_Addr.sin_port)) ;
|
||||
}
|
||||
|
||||
CIp::operator const char *() const
|
||||
{
|
||||
return ::inet_ntoa(m_Addr.sin_addr);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1 @@
|
||||
../src/cip.cpp
|
||||
@ -1,59 +0,0 @@
|
||||
//
|
||||
// cip.h
|
||||
// xlxd
|
||||
//
|
||||
// Created by Jean-Luc Deltombe (LX3JL) on 31/10/2015.
|
||||
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// This file is part of xlxd.
|
||||
//
|
||||
// xlxd is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// xlxd is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef cip_h
|
||||
#define cip_h
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// class
|
||||
|
||||
class CIp
|
||||
{
|
||||
public:
|
||||
// constructors
|
||||
CIp();
|
||||
//CIp(uint8, uint8, uint8, uint8);
|
||||
CIp(const struct sockaddr_in *);
|
||||
CIp(const char *);
|
||||
CIp(const CIp &);
|
||||
|
||||
// destructor
|
||||
virtual ~CIp() {};
|
||||
|
||||
// sockaddr
|
||||
void SetSockAddr(struct sockaddr_in *);
|
||||
struct sockaddr_in *GetSockAddr(void) { return &m_Addr; }
|
||||
|
||||
// operator
|
||||
bool operator ==(const CIp &) const;
|
||||
operator const char *() const;
|
||||
|
||||
protected:
|
||||
// data
|
||||
struct sockaddr_in m_Addr;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
#endif /* cip_h */
|
||||
@ -0,0 +1 @@
|
||||
../src/cip.h
|
||||
@ -1,172 +0,0 @@
|
||||
//
|
||||
// cudpsocket.cpp
|
||||
// xlxd
|
||||
//
|
||||
// Created by Jean-Luc Deltombe (LX3JL) on 31/10/2015.
|
||||
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// This file is part of xlxd.
|
||||
//
|
||||
// xlxd is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// xlxd is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "main.h"
|
||||
#include <string.h>
|
||||
#include "cudpsocket.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// constructor
|
||||
|
||||
CUdpSocket::CUdpSocket()
|
||||
{
|
||||
m_Socket = -1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// destructor
|
||||
|
||||
CUdpSocket::~CUdpSocket()
|
||||
{
|
||||
if ( m_Socket != -1 )
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// open & close
|
||||
|
||||
bool CUdpSocket::Open(const CIp &ListenIp, uint16 uiPort)
|
||||
{
|
||||
bool open = false;
|
||||
|
||||
// create socket
|
||||
m_Socket = socket(PF_INET,SOCK_DGRAM,0);
|
||||
if ( m_Socket != -1 )
|
||||
{
|
||||
// initialize sockaddr struct
|
||||
::memset(&m_SocketAddr, 0, sizeof(struct sockaddr_in));
|
||||
m_SocketAddr.sin_family = AF_INET;
|
||||
m_SocketAddr.sin_port = htons(uiPort);
|
||||
m_SocketAddr.sin_addr.s_addr = inet_addr(ListenIp);
|
||||
|
||||
if ( bind(m_Socket, (struct sockaddr *)&m_SocketAddr, sizeof(struct sockaddr_in)) == 0 )
|
||||
{
|
||||
fcntl(m_Socket, F_SETFL, O_NONBLOCK);
|
||||
open = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
close(m_Socket);
|
||||
m_Socket = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// done
|
||||
return open;
|
||||
}
|
||||
|
||||
void CUdpSocket::Close(void)
|
||||
{
|
||||
if ( m_Socket != -1 )
|
||||
{
|
||||
close(m_Socket);
|
||||
m_Socket = -1;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// read
|
||||
|
||||
int CUdpSocket::Receive(CBuffer *Buffer, CIp *Ip, int timeout)
|
||||
{
|
||||
struct sockaddr_in Sin;
|
||||
fd_set FdSet;
|
||||
unsigned int uiFromLen = sizeof(struct sockaddr_in);
|
||||
int iRecvLen = -1;
|
||||
struct timeval tv;
|
||||
|
||||
// socket valid ?
|
||||
if ( m_Socket != -1 )
|
||||
{
|
||||
// control socket
|
||||
FD_ZERO(&FdSet);
|
||||
FD_SET(m_Socket, &FdSet);
|
||||
tv.tv_sec = timeout / 1000;
|
||||
tv.tv_usec = (timeout % 1000) * 1000;
|
||||
select(m_Socket + 1, &FdSet, 0, 0, &tv);
|
||||
|
||||
// allocate buffer
|
||||
Buffer->resize(UDP_BUFFER_LENMAX);
|
||||
|
||||
// read
|
||||
iRecvLen = (int)recvfrom(m_Socket,
|
||||
(void *)Buffer->data(), UDP_BUFFER_LENMAX,
|
||||
0, (struct sockaddr *)&Sin, &uiFromLen);
|
||||
|
||||
// handle
|
||||
if ( iRecvLen != -1 )
|
||||
{
|
||||
// adjust buffer size
|
||||
Buffer->resize(iRecvLen);
|
||||
|
||||
// get IP
|
||||
Ip->SetSockAddr(&Sin);
|
||||
}
|
||||
}
|
||||
|
||||
// done
|
||||
return iRecvLen;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// write
|
||||
|
||||
int CUdpSocket::Send(const CBuffer &Buffer, const CIp &Ip)
|
||||
{
|
||||
CIp temp(Ip);
|
||||
return (int)::sendto(m_Socket,
|
||||
(void *)Buffer.data(), Buffer.size(),
|
||||
0, (struct sockaddr *)temp.GetSockAddr(), sizeof(struct sockaddr_in));
|
||||
}
|
||||
|
||||
int CUdpSocket::Send(const char *Buffer, const CIp &Ip)
|
||||
{
|
||||
CIp temp(Ip);
|
||||
return (int)::sendto(m_Socket,
|
||||
(void *)Buffer, ::strlen(Buffer),
|
||||
0, (struct sockaddr *)temp.GetSockAddr(), sizeof(struct sockaddr_in));
|
||||
}
|
||||
|
||||
int CUdpSocket::Send(const CBuffer &Buffer, const CIp &Ip, uint16 destport)
|
||||
{
|
||||
CIp temp(Ip);
|
||||
temp.GetSockAddr()->sin_port = htons(destport);
|
||||
return (int)::sendto(m_Socket,
|
||||
(void *)Buffer.data(), Buffer.size(),
|
||||
0, (struct sockaddr *)temp.GetSockAddr(), sizeof(struct sockaddr_in));
|
||||
}
|
||||
|
||||
int CUdpSocket::Send(const char *Buffer, const CIp &Ip, uint16 destport)
|
||||
{
|
||||
CIp temp(Ip);
|
||||
temp.GetSockAddr()->sin_port = htons(destport);
|
||||
return (int)::sendto(m_Socket,
|
||||
(void *)Buffer, ::strlen(Buffer),
|
||||
0, (struct sockaddr *)temp.GetSockAddr(), sizeof(struct sockaddr_in));
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1 @@
|
||||
../src/cudpsocket.cpp
|
||||
@ -1,78 +0,0 @@
|
||||
//
|
||||
// cudpsocket.h
|
||||
// xlxd
|
||||
//
|
||||
// Created by Jean-Luc Deltombe (LX3JL) on 31/10/2015.
|
||||
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// This file is part of xlxd.
|
||||
//
|
||||
// xlxd is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// xlxd is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef cudpsocket_h
|
||||
#define cudpsocket_h
|
||||
|
||||
#include <sys/types.h>
|
||||
//#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "cip.h"
|
||||
#include "cbuffer.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// define
|
||||
|
||||
#define UDP_BUFFER_LENMAX 1024
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// class
|
||||
|
||||
class CUdpSocket
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
CUdpSocket();
|
||||
|
||||
// destructor
|
||||
~CUdpSocket();
|
||||
|
||||
// open & close
|
||||
bool Open(const CIp &, uint16);
|
||||
void Close(void);
|
||||
int GetSocket(void) { return m_Socket; }
|
||||
|
||||
// read
|
||||
int Receive(CBuffer *, CIp *, int);
|
||||
|
||||
// write
|
||||
int Send(const CBuffer &, const CIp &);
|
||||
int Send(const CBuffer &, const CIp &, uint16);
|
||||
int Send(const char *, const CIp &);
|
||||
int Send(const char *, const CIp &, uint16);
|
||||
|
||||
protected:
|
||||
// data
|
||||
int m_Socket;
|
||||
struct sockaddr_in m_SocketAddr;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
#endif /* cudpsocket_h */
|
||||
@ -0,0 +1 @@
|
||||
../src/cudpsocket.h
|
||||
@ -1,22 +0,0 @@
|
||||
CC=g++
|
||||
CFLAGS=-c -std=c++11 -pthread
|
||||
LDFLAGS=-std=c++11 -pthread
|
||||
SOURCES=$(wildcard *.cpp)
|
||||
OBJECTS=$(SOURCES:.cpp=.o)
|
||||
EXECUTABLE=ambed
|
||||
|
||||
all: $(SOURCES) $(EXECUTABLE)
|
||||
|
||||
$(EXECUTABLE): $(OBJECTS)
|
||||
$(CC) $(LDFLAGS) $(OBJECTS) -lftd2xx -Wl,-rpath,/usr/local/lib -o $@
|
||||
|
||||
.cpp.o:
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
|
||||
clean:
|
||||
$(RM) $(EXECUTABLE) *.o
|
||||
|
||||
install:
|
||||
mkdir -p /ambed
|
||||
cp $(EXECUTABLE) /ambed/
|
||||
cp ./run /ambed/
|
||||
@ -1,6 +0,0 @@
|
||||
#!/bin/bash
|
||||
# start ambed server
|
||||
|
||||
sudo rmmod ftdi_sio
|
||||
sudo rmmod usbserial
|
||||
sudo /ambed/ambed 127.0.0.1 &
|
||||
@ -1,96 +0,0 @@
|
||||
/*************************************************************************
|
||||
** Copyright (C) 2014 Jan Pedersen <jp@jp-embedded.com>
|
||||
**
|
||||
** This program is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef __syslog
|
||||
#define __syslog
|
||||
|
||||
#include <iostream>
|
||||
#include <streambuf>
|
||||
#include <string>
|
||||
namespace csyslog {
|
||||
#include <syslog.h>
|
||||
}
|
||||
|
||||
namespace syslog
|
||||
{
|
||||
struct level {
|
||||
enum pri {
|
||||
emerg = LOG_EMERG, // A panic condition
|
||||
alert = LOG_ALERT, // A condition that should be corrected
|
||||
critical= LOG_CRIT, // Critical condition, e.g, hard device error
|
||||
error = LOG_ERR, // Errors
|
||||
warning = LOG_WARNING, // Warning messages
|
||||
notice = LOG_NOTICE, // Possibly be handled specially
|
||||
info = LOG_INFO, // Informational
|
||||
debug = LOG_DEBUG // For debugging program
|
||||
};
|
||||
};
|
||||
|
||||
class streambuf : public std::streambuf
|
||||
{
|
||||
std::string _buf;
|
||||
int _level;
|
||||
|
||||
public:
|
||||
|
||||
streambuf() : _level(level::debug) { }
|
||||
void level(int level) { _level = level; }
|
||||
|
||||
protected:
|
||||
|
||||
int sync()
|
||||
{
|
||||
if (_buf.size()) {
|
||||
csyslog::syslog(_level, "%s", _buf.c_str());
|
||||
_buf.erase();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int_type overflow(int_type c)
|
||||
{
|
||||
if(c == traits_type::eof()) sync();
|
||||
else _buf += static_cast<char>(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class ostream : public std::ostream
|
||||
{
|
||||
streambuf _logbuf;
|
||||
public:
|
||||
ostream() : std::ostream(&_logbuf) {}
|
||||
ostream& operator<<(const level::pri lev) { _logbuf.level(lev); return *this; }
|
||||
};
|
||||
|
||||
class redirect
|
||||
{
|
||||
ostream dst;
|
||||
std::ostream &src;
|
||||
std::streambuf * const sbuf;
|
||||
|
||||
public:
|
||||
redirect(std::ostream & src) : src(src), sbuf(src.rdbuf(dst.rdbuf())) { dst << (&src == &std::cout ? level::info : level::error); }
|
||||
~redirect() { src.rdbuf(sbuf); }
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in new issue