Code: Select all
if(haveSDCard && fastLoggingEnabled && (startLogAttempt < 3) && (millis() > DELAY_VAL))
Code: Select all
if(haveSDCard && fastLoggingEnabled && (startLogAttempt < 3) && (millis() > DELAY_VAL))
Thought you would have checked but had to ask!Bigpie wrote: ↑Fri Oct 21, 2022 6:31 pm I've checked and double checked RX & TX and also tried swapping them over. I've soldered the same header as the olimex so I can just swap over.
It connects and page loads. I've not connected up a usb to the ESP32 while in the car, not sure if I'd need to disconnect the 3.3v from the inverter to do that but will do that in the morning
Code: Select all
#include <QCoreApplication>
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonValue>
#include <QDebug>
#include <QVector>
#include <QtMath>
#define MODMAX (((2U<<15)/1.732050807568877293527446315059) - 200)
struct varDefinitions {
QString name;
double scale;
int bits;
bool signExtend;
} ;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QVector<varDefinitions> varDefs;
QFile logFile("logfile.bin");
QFile outFile("decodedfile.csv");
QByteArray jsonHeader;
char val;
int paraCount = -1;
int messageBits = 0, messageBytes = 0;
char buffer[25];
int index = 0;
int bitsHave = 8;
uint32_t value = 0;
uint32_t bitStore = 0;
uint32_t mask = 0;
uint32_t messageCount = 0;
int haveAngle = -1, haveI1 = -1, haveI2= -1;
logFile.open(QFile::ReadOnly);
if(logFile.isOpen())
{
//read and save parameters
do logFile.read(&val, 1); while(val != '{');
if(val == '{')
{
paraCount=1;
jsonHeader.append(val);
do
{
if(logFile.read(&val, 1)==1)
{
jsonHeader.append(val);
if(val == '{')
paraCount++;
else if(val == '}')
paraCount--;
}
else
break;
}
while(paraCount > 0);
}
QFile paramFile("paramfile.json");
paramFile.open(QFile::WriteOnly);
if(paramFile.isOpen())
{
paramFile.write(jsonHeader);
paramFile.close();
qDebug("Param file written");
}
else
qDebug("Could not write param file");
jsonHeader.clear();
do logFile.read(&val, 1); while(val != '{');
if(val == '{')
{
paraCount=1;
jsonHeader.append(val);
do
{
if(logFile.read(&val, 1)==1)
{
jsonHeader.append(val);
if(val == '{')
paraCount++;
else if(val == '}')
paraCount--;
}
else
break;
}
while(paraCount > 0);
}
}
else
qDebug("Could not open input file");
if(paraCount == 0)
{
QJsonDocument jsonResponse = QJsonDocument::fromJson(jsonHeader);
QJsonObject jsonObject = jsonResponse.object();
varDefinitions def;
foreach(const QString& key, jsonObject.keys())
{
QJsonObject jsonObject2 = jsonObject[key].toObject();
foreach(const QString& key2, jsonObject2.keys())
{
if(key2 == "name")
def.name = jsonObject2[key2].toString();
else if(key2 == "scale")
def.scale = jsonObject2[key2].toDouble();
else if(key2 == "signed")
def.signExtend = jsonObject2[key2].toInt();
else if(key2 == "size")
{
def.bits = jsonObject2[key2].toInt();
messageBits += def.bits;
}
}
if(def.name == "angle")
haveAngle = varDefs.size();
else if(def.name == "i1")
haveI1 = varDefs.size();
else if(def.name == "i2")
haveI2 = varDefs.size();
varDefs.append(def);
}
outFile.open(QFile::WriteOnly);
if(outFile.isOpen())
{
QTextStream outStream(&outFile);
QVectorIterator<varDefinitions> i(varDefs);
while (i.hasNext())
outStream << i.next().name << ',';
if((haveAngle>=0) && (haveI1>=0) && (haveI2>=0))
{
outStream << "iq" << ',' << "id" << ',';
}
outStream << "\n";
messageBytes = (messageBits+7)/8;
if(messageBytes <=25)
{
while(logFile.peek(buffer, messageBytes)==messageBytes)
{
QVector<double> values(varDefs.size());
//is csum valid?
uint8_t csum = 0;
int i;
for(i=0;i<messageBytes-1;i++)
csum += (uint8_t)buffer[i];
if(csum == (uint8_t)buffer[i])
{ //match, we have a valid message so extract data
index = 0;
bitsHave = 8;
value = 0;
bitStore = (uint32_t)((uint8_t)buffer[index++]);
for(i=0;i<varDefs.size();i++)
{
int bitsNeeded = varDefs[i].bits;
while(bitsHave < bitsNeeded)
{
bitStore = (((uint32_t)((uint8_t)buffer[index++]))<<bitsHave) + bitStore;
bitsHave = bitsHave + 8;
}
mask = ~(0xffffffff<<bitsNeeded);
value = bitStore & mask;
if(varDefs[i].signExtend)
{
mask = 0x01<<(bitsNeeded-1);
if((value & mask) != 0) //msb set so extend
{
mask = 0xffffffff<<bitsNeeded;
value = value | mask;
values[i] = ((int32_t)value) * varDefs[i].scale;
}
else //not set do don't
values[i] = value * varDefs[i].scale;
}
else
values[i] = value * varDefs[i].scale;
if(varDefs[i].name == "angle")
values[i] = (360.0 * (values[i]/65535));
if((varDefs[i].name == "ud") || (varDefs[i].name == "uq"))
values[i] = (100.0 * (values[i]/MODMAX));
if((varDefs[i].name == "pwm1") || (varDefs[i].name == "pwm2") || (varDefs[i].name == "pwm3"))
values[i] = (100.0 * ((values[i]-8192)/8192));
bitStore = bitStore >> bitsNeeded;
bitsHave = bitsHave - bitsNeeded;
}
logFile.read(buffer, messageBytes); //discard the data
QVectorIterator<double> i(values);
while (i.hasNext())
outStream << i.next() << ',';
if((haveAngle>=0) && (haveI1>=0) && (haveI2>=0))
{
double angle = values[haveAngle];
double ia = values[haveI1];
double ib = ((values[haveI1]+(2.0*values[haveI2]))/qSqrt(3.0));
double id = (ia * qCos(qDegreesToRadians(angle))) + (ib * qSin(qDegreesToRadians(angle)));
double iq = (-ia * qSin(qDegreesToRadians(angle))) + (ib * qCos(qDegreesToRadians(angle)));
outStream << iq << ',' << id << ',';
}
outStream << "\n";
messageCount++;
if((messageCount%(8800*60))==0)
qDebug("Processed %i minutes of data",messageCount/(8800*60));
}
else //no match so throw a byte away and try again
{
logFile.read(buffer, 1);
qDebug("Mesage Lost");
}
}
qDebug("Processing Complete");
}
else
qDebug("Json header message length invalid");
}
else
qDebug("Could not open output file");
}
else
qDebug("Could not find json header");
logFile.close();
outFile.close();
return a.exec();
}
Code: Select all
//float maxThrot = throttleLimitController.RunProportionalOnly(Param::GetInt(Param::amp));
//if (torquePercent > 0)
// torquePercent = MIN(maxThrot, torquePercent);
//else
// torquePercent = -MIN(maxThrot, -torquePercent);
Absolutely!
Thinking the cut-outs were the PWM overflow, the symptoms would be right. Good if it's fixed
I'll have another look at the ESP code and see if I can add something to ensure it recovers from this state.Bigpie wrote: ↑Sat Oct 22, 2022 4:04 pm I think it's getting in to binaryLogging and the loading the webpage doesn't get it out of it, causing the params to not load so I'd assumed it wasn't working and switched the RX and TX over. Switched them back and the logs had data in.
If I want the params to load, I have to power up get my laptop to connect to the ESP32, then restart the inverter to get the params list to load.
How do I compile the application to convert to CSV to open in PusleView?
What would be useful in order to try and recreate the problem is a few more details on the network configuration when you had the problem. Are you using the ESP to provide the wifi network or is it connecting to the house or laptop network.Bigpie wrote: ↑Sat Oct 22, 2022 4:04 pm I think it's getting in to binaryLogging and the loading the webpage doesn't get it out of it, causing the params to not load so I'd assumed it wasn't working and switched the RX and TX over. Switched them back and the logs had data in.
If I want the params to load, I have to power up get my laptop to connect to the ESP32, then restart the inverter to get the params list to load.
Code: Select all
WiFi.mode(WIFI_AP_STA);