idf overriding method to bring back SPDIF and fix SPI + new CSPOT (which crashes)

This commit is contained in:
Philippe G
2022-01-04 00:15:33 -08:00
parent cf1315e6a4
commit 06b637c55b
43 changed files with 2955 additions and 402 deletions

View File

@@ -6,6 +6,7 @@
#include <map>
#include <memory>
#include <functional>
#include <vector>
namespace bell {
@@ -16,6 +17,7 @@ class ResponseReader {
virtual size_t getTotalSize() = 0;
virtual size_t read(char *buffer, size_t size) = 0;
virtual void close() = 0;
};
class FileResponseReader : public ResponseReader {
@@ -34,6 +36,10 @@ class FileResponseReader : public ResponseReader {
return fread(buffer, 1, size, file);
}
void close() {
fclose(file);
}
size_t getTotalSize() { return fileSize; }
};
@@ -43,6 +49,7 @@ struct HTTPRequest {
std::map<std::string, std::string> urlParams;
std::map<std::string, std::string> queryParams;
std::string body;
std::string url;
int handlerId;
int connection;
};

View File

@@ -9,11 +9,13 @@ namespace bell {
Socket() {};
virtual ~Socket() = default;
virtual void open(std::string url) = 0;
void open(const std::string &url);
virtual void open(std::string host, uint16_t port) = 0;
virtual size_t poll() = 0;
virtual size_t write(uint8_t* buf, size_t len) = 0;
virtual size_t read(uint8_t* buf, size_t len) = 0;
virtual void close() = 0;
};
}
#endif
#endif

View File

@@ -17,6 +17,7 @@
#include <fstream>
#include <netinet/tcp.h>
#include <BellLogger.h>
#include <sys/ioctl.h>
namespace bell
{
@@ -32,50 +33,35 @@ namespace bell
close();
};
void open(std::string url)
void open(std::string host, uint16_t port)
{
// remove https or http from url
url.erase(0, url.find("://") + 3);
// split by first "/" in url
std::string hostUrl = url.substr(0, url.find('/'));
std::string pathUrl = url.substr(url.find('/'));
std::string portString = "80";
// check if hostUrl contains ':'
if (hostUrl.find(':') != std::string::npos)
{
// split by ':'
std::string host = hostUrl.substr(0, hostUrl.find(':'));
portString = hostUrl.substr(hostUrl.find(':') + 1);
hostUrl = host;
}
int err;
int domain = AF_INET;
int socketType = SOCK_STREAM;
addrinfo hints, *addr;
struct addrinfo hints{}, *addr;
//fine-tune hints according to which socket you want to open
hints.ai_family = domain;
hints.ai_socktype = socketType;
hints.ai_protocol = IPPROTO_IP; // no enum : possible value can be read in /etc/protocols
hints.ai_flags = AI_CANONNAME | AI_ALL | AI_ADDRCONFIG;
BELL_LOG(info, "http", "%s %s", hostUrl.c_str(), portString.c_str());
BELL_LOG(info, "http", "%s %d", host.c_str(), port);
if (getaddrinfo(hostUrl.c_str(), portString.c_str(), &hints, &addr) != 0)
{
BELL_LOG(error, "webradio", "DNS lookup error");
char portStr[6];
sprintf(portStr, "%u", port);
err = getaddrinfo(host.c_str(), portStr, &hints, &addr);
if (err != 0) {
throw std::runtime_error("Resolve failed");
}
sockFd = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
if (connect(sockFd, addr->ai_addr, addr->ai_addrlen) < 0)
err = connect(sockFd, addr->ai_addr, addr->ai_addrlen);
if (err < 0)
{
close();
BELL_LOG(error, "http", "Could not connect to %s", url.c_str());
BELL_LOG(error, "http", "Could not connect to %s. Error %d", host.c_str(), errno);
throw std::runtime_error("Resolve failed");
}
@@ -97,6 +83,12 @@ namespace bell
return send(sockFd, buf, len, 0);
}
size_t poll() {
int value;
ioctl(sockFd, FIONREAD, &value);
return value;
}
void close() {
if (!isClosed) {
::close(sockFd);
@@ -107,4 +99,4 @@ namespace bell
}
#endif
#endif

View File

@@ -58,10 +58,11 @@ public:
TLSSocket();
~TLSSocket() { close(); };
void open(std::string host);
void open(std::string host, uint16_t port);
size_t read(uint8_t *buf, size_t len);
size_t write(uint8_t *buf, size_t len);
size_t poll();
void close();
};