Skip to content

Commit

Permalink
Merge branch 'master' into find-memory-leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tschak909 committed Jul 27, 2023
2 parents b74a617 + 50b0d5e commit 4b1328d
Show file tree
Hide file tree
Showing 95 changed files with 335 additions and 312 deletions.
12 changes: 6 additions & 6 deletions lib/EdUrlParser/EdUrlParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ EdUrlParser::~EdUrlParser() {



string EdUrlParser::urlDecode(string str) {
string EdUrlParser::urlDecode(const string &str) {
int _url_errorno = 0;
size_t pos = 0, per = 0;
size_t len = str.size();
Expand Down Expand Up @@ -72,7 +72,7 @@ string EdUrlParser::urlDecode(string str) {

}

string EdUrlParser::urlEncode(string s) {
string EdUrlParser::urlEncode(const string &s) {
const char *ptr = s.c_str();
string enc;
char c;
Expand Down Expand Up @@ -189,7 +189,7 @@ void EdUrlParser::parse() {
}
__END_IGNORE_UNUSEDVARS

EdUrlParser* EdUrlParser::parseUrl(string urlstr) {
EdUrlParser* EdUrlParser::parseUrl(const string &urlstr) {
EdUrlParser *url = new EdUrlParser;
url->mRawUrl = urlstr;
url->parse();
Expand All @@ -216,15 +216,15 @@ bool EdUrlParser::toChar(const char* hex, char *result) {
return true;
}

size_t EdUrlParser::parseKeyValueMap(unordered_map<string, string> *kvmap, string rawstr, bool strict) {
size_t EdUrlParser::parseKeyValueMap(unordered_map<string, string> *kvmap, const string &rawstr, bool strict) {
return parseKeyValue(rawstr, __kv_callback_map, kvmap, strict);
}

size_t EdUrlParser::parseKeyValueList(vector< query_kv_t > *kvvec, string rawstr, bool strict) {
size_t EdUrlParser::parseKeyValueList(vector< query_kv_t > *kvvec, const string &rawstr, bool strict) {
return parseKeyValue(rawstr, __kv_callback_vec, kvvec, strict);
}

size_t EdUrlParser::parseKeyValue(string rawstr, __kv_callback kvcb, void* obj, bool strict) {
size_t EdUrlParser::parseKeyValue(const string &rawstr, __kv_callback kvcb, void* obj, bool strict) {

int _url_errorno = 0;
const char *str = rawstr.c_str();
Expand Down
12 changes: 6 additions & 6 deletions lib/EdUrlParser/EdUrlParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class EdUrlParser {
EdUrlParser();
public:
virtual ~EdUrlParser();
static EdUrlParser* parseUrl(string urlstr);
static EdUrlParser* parseUrl(const string &urlstr);
static int parsePath(vector<string> *pdirlist, string pathstr);
static string urlDecode(string str);
static string urlDecode(const string &str);
static bool toChar(const char* hex, char *result);
static string urlEncode(string s);
static string urlEncode(const string &s);
static void toHex(char *desthex, char c);
static size_t parseKeyValueMap(unordered_map<string, string> *kvmap, string str, bool strict=true);
static size_t parseKeyValueList(vector< query_kv_t > *kvmap, string rawstr, bool strict=true);
static size_t parseKeyValue(string rawstr, __kv_callback kvcb, void* obj, bool strict);
static size_t parseKeyValueMap(unordered_map<string, string> *kvmap, const string &str, bool strict=true);
static size_t parseKeyValueList(vector< query_kv_t > *kvmap, const string &rawstr, bool strict=true);
static size_t parseKeyValue(const string &rawstr, __kv_callback kvcb, void* obj, bool strict);
bool isValidUrl();

private:
Expand Down
2 changes: 1 addition & 1 deletion lib/FileSystem/fnFsLittleFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class FileSystemLittleFS : public FileSystem
{
private:
DIR * _dir;
DIR * _dir = nullptr;
public:
FileSystemLittleFS();
bool start();
Expand Down
2 changes: 1 addition & 1 deletion lib/FileSystem/fnFsSPIFFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class FileSystemSPIFFS : public FileSystem
{
private:
DIR * _dir;
DIR * _dir = nullptr;
public:
FileSystemSPIFFS();
bool start();
Expand Down
2 changes: 1 addition & 1 deletion lib/FileSystem/fnFsTNFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class FileSystemTNFS : public FileSystem
{
private:
tnfsMountInfo _mountinfo;
unsigned long _last_dns_refresh;
unsigned long _last_dns_refresh = 0;
char _current_dirpath[TNFS_MAX_FILELEN];

public:
Expand Down
2 changes: 1 addition & 1 deletion lib/TNFSlib/tnfslib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ const char *tnfs_filepath(tnfsMountInfo *m_info, int16_t file_handle)
return nullptr;

// Find info on this handle
tnfsFileHandleInfo *pFileInf = m_info->get_filehandleinfo(file_handle);
const tnfsFileHandleInfo *pFileInf = m_info->get_filehandleinfo(file_handle);
if (pFileInf == nullptr)
return nullptr;

Expand Down
4 changes: 2 additions & 2 deletions lib/TNFSlib/tnfslibMountInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ tnfsMountInfo::tnfsMountInfo(const char *host_name, uint16_t host_port)
}

tnfsMountInfo::tnfsMountInfo(in_addr_t host_address, uint16_t host_port)
: host_ip(host_address)
, port(host_port)
{
host_ip = host_address;
port = host_port;
}

// Make sure to clean up any memory we allocated
Expand Down
2 changes: 1 addition & 1 deletion lib/bus/comlynx/comlynx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ void systemBus::disableDevice(uint8_t device_id)
void systemBus::setUDPHost(const char *hostname, int port)
{
// Turn off if hostname is STOP
if (!strcmp(hostname, "STOP"))
if (hostname != nullptr && !strcmp(hostname, "STOP"))
{
if (_udpDev->udpstreamActive)
_udpDev->comlynx_disable_udpstream();
Expand Down
2 changes: 1 addition & 1 deletion lib/bus/drivewire/drivewire.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class systemBus
/**
* @brief Current Baud Rate
*/
int _drivewireBaud;
int _drivewireBaud = 0;


// int readSector(struct dwTransferData *dp);
Expand Down
2 changes: 1 addition & 1 deletion lib/bus/iec/protocol/iecProtocolSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool IecProtocolSerial::sendByte(uint8_t data, bool eoi)

IEC.flags &= CLEAR_LOW;

if ( IEC.status ( PIN_IEC_ATN ) ) return -1;
if ( IEC.status ( PIN_IEC_ATN ) ) return false;

// Say we're ready
//wait( TIMING_STABLE );
Expand Down
2 changes: 1 addition & 1 deletion lib/bus/iwm/iwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class iwmBus
void handle_init();

int old_track = -1;
int new_track;
int new_track = -1;

public:
std::forward_list<iwmDevice *> _daisyChain;
Expand Down
12 changes: 6 additions & 6 deletions lib/bus/iwm/iwm_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ class iwm_sp_ll : public iwm_ll
void set_output_to_spi();

// SPI data handling
uint8_t *spi_buffer; //[8 * (BLOCK_PACKET_LEN+2)]; //smartport packet buffer
uint16_t spi_len;
uint8_t *spi_buffer = nullptr; //[8 * (BLOCK_PACKET_LEN+2)]; //smartport packet buffer
uint16_t spi_len = 0;
spi_bus_config_t bus_cfg;
spi_device_handle_t spi;
// SPI receiver
Expand All @@ -120,11 +120,11 @@ class iwm_sp_ll : public iwm_ll
const int halfwidth = pulsewidth / 2;

// SPI receiver data stream counters
int spirx_byte_ctr;
int spirx_bit_ctr;
int spirx_byte_ctr = 0;
int spirx_bit_ctr = 0;

//uint8_t packet_buffer[BLOCK_PACKET_LEN]; //smartport packet buffer
uint16_t packet_len;
uint16_t packet_len = 0;

public:
SemaphoreHandle_t spiMutex;
Expand Down Expand Up @@ -174,7 +174,7 @@ class iwm_diskii_ll : public iwm_ll
fn_rmt_config_t config;

// track bit information
uint8_t* track_buffer; //
uint8_t* track_buffer = nullptr; //
size_t track_numbits = 6400 * 8;
size_t track_numbytes = 6400;
size_t track_location = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/bus/rc2014bus/rc2014bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class systemBus

std::array<uint8_t, RC2014_RX_BUFFER_SIZE> _rx_buffer;
std::array<uint8_t, RC2014_TX_BUFFER_SIZE> _tx_buffer;
unsigned int _tx_buffer_index;
unsigned int _tx_buffer_index = 0;

public:
void setup();
Expand Down
4 changes: 2 additions & 2 deletions lib/bus/rs232/rs232.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ class systemBus
rs232Printer *_printerdev = nullptr;

int _rs232Baud = RS232_BAUDRATE;
int _rs232BaudHigh;
int _rs232BaudUltraHigh;
int _rs232BaudHigh = RS232_BAUDRATE;
int _rs232BaudUltraHigh = RS232_BAUDRATE;

bool useUltraHigh = false; // Use fujinet derived clock.

Expand Down
81 changes: 44 additions & 37 deletions lib/bus/sio/sio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,29 +209,24 @@ void systemBus::_sio_process_cmd()
if (tempFrame.device == SIO_DEVICEID_TYPE3POLL)
{
Debug_println("SIO TYPE3 POLL");
for (auto devicep : _daisyChain)
for (map<unsigned char, virtualDevice *>::iterator it=_daisyChain.begin(); it != _daisyChain.end(); ++it)
{
if (devicep->listen_to_type3_polls)
if (it->second->listen_to_type3_polls)
{
Debug_printf("Sending TYPE3 poll to dev %x\n", devicep->_devnum);
_activeDev = devicep;
// handle command
Debug_printf("Sending TYPE3 poll to dev %x\n",it->second->_devnum);
_activeDev = it->second;
_activeDev->sio_process(tempFrame.commanddata, tempFrame.checksum);
}
}
}
else
{
// find device, ack and pass control
// or go back to WAIT
for (auto devicep : _daisyChain)
std::map<unsigned char, virtualDevice *>::iterator it = _daisyChain.find(tempFrame.device);

if (it != _daisyChain.end())
{
if (tempFrame.device == devicep->_devnum)
{
_activeDev = devicep;
// handle command
_activeDev->sio_process(tempFrame.commanddata, tempFrame.checksum);
}
_activeDev = it->second;
it->second->sio_process(tempFrame.commanddata, tempFrame.checksum);
}
}
}
Expand Down Expand Up @@ -345,7 +340,7 @@ void systemBus::service()
{
_modemDev->sio_handle_modem();
}
else
else if (_modemDev != nullptr)
// Neither CMD nor active modem, so throw out any stray input data
{
_modemDev->get_uart()->flush_input();
Expand Down Expand Up @@ -434,44 +429,56 @@ void systemBus::addDevice(virtualDevice *pDevice, int device_id)

pDevice->_devnum = device_id;

_daisyChain.push_front(pDevice);
_daisyChain[device_id] = pDevice;
}

// Removes device from the SIO bus.
// Note that the destructor is called on the device!
void systemBus::remDevice(virtualDevice *p)
{
_daisyChain.remove(p);
std::map<unsigned char, virtualDevice *>::iterator it = _daisyChain.find(p->_devnum);

if (it == _daisyChain.end())
{
Debug_printv("Device not found in daisy chain.");
return;
}
else
{
int d = it->second->_devnum;

_daisyChain.erase(it);
Debug_printv("Device %u removed from daisy chain.",d);
}
}

// Should avoid using this as it requires counting through the list
int systemBus::numDevices()
{
int i = 0;
__BEGIN_IGNORE_UNUSEDVARS
for (auto devicep : _daisyChain)
i++;
return i;
__END_IGNORE_UNUSEDVARS
Debug_printv("# of devices in chain: %lu\n",_daisyChain.size());
return _daisyChain.size();
}

void systemBus::changeDeviceId(virtualDevice *p, int device_id)
{
for (auto devicep : _daisyChain)
{
if (devicep == p)
devicep->_devnum = device_id;
}
unsigned char old_id=0;

// This uses c++17's std::map.extract() to change the device key
// without re-allocation.
auto nh = _daisyChain.extract(p->_devnum);
old_id=p->_devnum;
p->_devnum = device_id;
nh.key() = device_id;
_daisyChain.insert(std::move(nh));
Debug_printv("Device id %u changed to %u",old_id,p->_devnum);
}

virtualDevice *systemBus::deviceById(int device_id)
{
for (auto devicep : _daisyChain)
{
if (devicep->_devnum == device_id)
return devicep;
}
return nullptr;
if (_daisyChain.find(device_id) == _daisyChain.end())
return nullptr;
else
return _daisyChain[device_id];
}

// Give devices an opportunity to clean up before a reboot
Expand All @@ -481,8 +488,8 @@ void systemBus::shutdown()

for (auto devicep : _daisyChain)
{
Debug_printf("Shutting down device %02x\n",devicep->id());
devicep->shutdown();
Debug_printf("Shutting down device %02x\n",devicep.second->id());
devicep.second->shutdown();
}
Debug_printf("All devices shut down.\n");
}
Expand Down Expand Up @@ -543,7 +550,7 @@ int systemBus::getHighSpeedBaud()
void systemBus::setUDPHost(const char *hostname, int port)
{
// Turn off if hostname is STOP
if (!strcmp(hostname, "STOP"))
if (hostname != nullptr && !strcmp(hostname, "STOP"))
{
if (_udpDev->udpstreamActive)
_udpDev->sio_disable_udpstream();
Expand Down
11 changes: 6 additions & 5 deletions lib/bus/sio/sio.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <freertos/FreeRTOS.h>
#include <freertos/queue.h>

#include <forward_list>

// #include <forward_list>
#include <map>

#define DELAY_T4 850
#define DELAY_T5 250
Expand Down Expand Up @@ -243,7 +243,8 @@ struct sio_message_t
class systemBus
{
private:
std::forward_list<virtualDevice *> _daisyChain;
//std::forward_list<virtualDevice *> _daisyChain;
std::map<unsigned char, virtualDevice *> _daisyChain;

int _command_frame_counter = 0;

Expand All @@ -258,8 +259,8 @@ class systemBus

int _sioBaud = SIO_STANDARD_BAUDRATE;
int _sioHighSpeedIndex = SIO_HISPEED_INDEX;
int _sioBaudHigh;
int _sioBaudUltraHigh;
int _sioBaudHigh = SIO_STANDARD_BAUDRATE;
int _sioBaudUltraHigh = SIO_STANDARD_BAUDRATE;

bool useUltraHigh = false; // Use fujinet derived clock.

Expand Down
Loading

0 comments on commit 4b1328d

Please sign in to comment.