Skip to content

Commit 378c83f

Browse files
committed
mio dlog
1 parent b2b8b56 commit 378c83f

File tree

6 files changed

+169
-54
lines changed

6 files changed

+169
-54
lines changed

src/eez/modules/dib-mio168/dib-mio168.cpp

+51-10
Original file line numberDiff line numberDiff line change
@@ -1692,8 +1692,7 @@ struct Mio168Module : public Module {
16921692
auto &dlogRecordingData = response.dlogRecordingData;
16931693

16941694
while (dlogDataRecordIndex < dlogRecordingData.recordIndex) {
1695-
float values[4] = { NAN, NAN, NAN, NAN };
1696-
dlog_record::log(values);
1695+
dlog_record::logInvalid();
16971696
dlogDataRecordIndex++;
16981697
}
16991698

@@ -1702,25 +1701,41 @@ struct Mio168Module : public Module {
17021701
uint32_t end = dlogRecordingData.recordIndex + dlogRecordingData.numRecords;
17031702

17041703
bool is24Bit = dlog_record::g_parameters.period >= 1.0f / 16000;
1704+
1705+
uint32_t logAin[4] = {
1706+
dlogRecordingStart.resources & (1 << (16 + 0)),
1707+
dlogRecordingStart.resources & (1 << (16 + 1)),
1708+
dlogRecordingStart.resources & (1 << (16 + 2)),
1709+
dlogRecordingStart.resources & (1 << (16 + 3))
1710+
};
17051711

17061712
while (dlogDataRecordIndex < end) {
17071713
float values[4];
17081714

1715+
int i = 0;
1716+
17091717
if (is24Bit) {
17101718
for (int j = 0; j < 4; j++) {
1711-
int32_t adcValue = ((int32_t)((rx[0] << 24) | (rx[1] << 16) | (rx[2] << 8))) >> 8;
1712-
values[j] = float(dlogDataConversionFactors[j] * adcValue / (1 << 23));
1719+
if (logAin[j]) {
1720+
int32_t adcValue = ((int32_t)((rx[0] << 24) | (rx[1] << 16) | (rx[2] << 8))) >> 8;
1721+
values[i++] = float(dlogDataConversionFactors[j] * adcValue / (1 << 23));
1722+
}
17131723
rx += 3;
17141724
}
17151725
} else {
17161726
for (int j = 0; j < 4; j++) {
1717-
int32_t adcValue = int16_t((rx[0] << 8) | rx[1]);
1718-
values[j] = float(dlogDataConversionFactors[j] * adcValue / (1 << 15));
1727+
if (logAin[j]) {
1728+
int32_t adcValue = int16_t((rx[0] << 8) | rx[1]);
1729+
values[i++] = float(dlogDataConversionFactors[j] * adcValue / (1 << 15));
1730+
}
17191731
rx += 2;
17201732
}
17211733
}
1734+
1735+
uint32_t bits = rx[0] | (rx[1] << 8);
1736+
rx += 2;
17221737

1723-
dlog_record::log(values);
1738+
dlog_record::log(values, bits);
17241739

17251740
dlogDataRecordIndex++;
17261741
}
@@ -2036,6 +2051,7 @@ struct Mio168Module : public Module {
20362051
response->getInfo.idw2 = 0;
20372052
response->getInfo.afeVersion = 1;
20382053
} else if (currentCommand->command == COMMAND_GET_STATE) {
2054+
memset(&response->getState, 0, sizeof(response->getState));
20392055
response->getState.flags |= GET_STATE_COMMAND_FLAG_SD_CARD_PRESENT;
20402056
} else if (currentCommand->command == COMMAND_DLOG_RECORDING_START) {
20412057
response->dlogRecordingStart.conversionFactors[0] = 2.4f;
@@ -2048,10 +2064,35 @@ struct Mio168Module : public Module {
20482064
(state == STATE_WAIT_DMA_TRANSFER_COMPLETED_FOR_REQUEST && isModuleControlledRecordingExecuting())
20492065
) {
20502066
response->command = 0x8000 | COMMAND_DLOG_RECORDING_DATA;
2067+
2068+
bool is24Bit = dlog_record::g_parameters.period >= 1.0f / 16000;
2069+
20512070
response->dlogRecordingData.recordIndex = dlogDataRecordIndex;
2052-
response->dlogRecordingData.numRecords = 8;
2053-
for (int i = 0; i < 3 * 4 * response->dlogRecordingData.numRecords; i++) {
2054-
response->dlogRecordingData.buffer[i] = rand() % 255;
2071+
response->dlogRecordingData.numRecords = (uint16_t)roundf(1.0f / dlog_record::g_parameters.period / 1000);
2072+
2073+
int32_t ain[4];
2074+
ain[0] = 0x7FFFFFFF / 5;
2075+
ain[1] = 0x7FFFFFFF / 5 * 2;
2076+
ain[2] = 0x7FFFFFFF / 5 * 3;
2077+
ain[3] = 0x7FFFFFFF / 5 * 4;
2078+
2079+
uint8_t *p = response->dlogRecordingData.buffer;
2080+
2081+
for (int i = 0; i < response->dlogRecordingData.numRecords; i++) {
2082+
if (is24Bit) {
2083+
for (int j = 0; j < 4; j++) {
2084+
*p++ = (ain[j] >> 24) & 0xFF;
2085+
*p++ = (ain[j] >> 16) & 0xFF;
2086+
*p++ = (ain[j] >> 8) & 0xFF;
2087+
}
2088+
} else {
2089+
for (int j = 0; j < 4; j++) {
2090+
*p++ = (ain[j] >> 24) & 0xFF;
2091+
*p++ = (ain[j] >> 16) & 0xFF;
2092+
}
2093+
}
2094+
*p++ = 0x55;
2095+
*p++ = 0xAA;
20552096
}
20562097
}
20572098
}

src/eez/modules/psu/dlog_record.cpp

+31-2
Original file line numberDiff line numberDiff line change
@@ -755,11 +755,40 @@ void tick() {
755755
}
756756
}
757757

758-
void log(float *values) {
758+
void log(float *values, uint32_t bits) {
759759
if (g_state == STATE_EXECUTING) {
760760
for (int yAxisIndex = 0; yAxisIndex < g_recording.parameters.numYAxes; yAxisIndex++) {
761-
g_writer.writeFloat(values[yAxisIndex]);
761+
if (g_recording.parameters.yAxes[yAxisIndex].unit == UNIT_BIT) {
762+
if (g_writer.getBitMask() == 0) {
763+
g_writer.writeBit(1); // mark as valid sample
764+
}
765+
if (bits & (1 << g_recording.parameters.yAxes[yAxisIndex].channelIndex)) {
766+
g_writer.writeBit(1);
767+
} else {
768+
g_writer.writeBit(0);
769+
}
770+
} else {
771+
g_writer.writeFloat(*values++);
772+
}
773+
}
774+
g_writer.flushBits();
775+
++g_recording.size;
776+
}
777+
}
778+
779+
void logInvalid() {
780+
if (g_state == STATE_EXECUTING) {
781+
for (int yAxisIndex = 0; yAxisIndex < g_recording.parameters.numYAxes; yAxisIndex++) {
782+
if (g_recording.parameters.yAxes[yAxisIndex].unit == UNIT_BIT) {
783+
if (g_writer.getBitMask() == 0) {
784+
g_writer.writeBit(0); // mark as invalid sample
785+
}
786+
g_writer.writeBit(0);
787+
} else {
788+
g_writer.writeFloat(NAN);
789+
}
762790
}
791+
g_writer.flushBits();
763792
++g_recording.size;
764793
}
765794
}

src/eez/modules/psu/dlog_record.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ void abortAfterMassStorageError();
7070
void reset();
7171

7272
void tick();
73-
void log(float *values);
73+
void log(float *values, uint32_t bits = 0);
74+
void logInvalid();
7475

7576
void fileWrite(bool flush = false);
7677
void stateTransition(int event, int *perr = nullptr);

src/eez/modules/psu/dlog_view.cpp

+75-40
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,34 @@ static bool g_wasExecuting;
8585

8686
////////////////////////////////////////////////////////////////////////////////
8787

88+
bool Parameters::isDlogItemAvailable(int slotIndex, int subchannelIndex, int resourceIndex) {
89+
if (numDlogItems >= dlog_file::MAX_NUM_OF_Y_AXES) {
90+
return false;
91+
}
92+
93+
if (getResourceMinPeriod(slotIndex, subchannelIndex, resourceIndex) > period) {
94+
return false;
95+
}
96+
97+
if (period < PERIOD_MIN) {
98+
if (numDlogItems > 0 && dlogItems[0].slotIndex != slotIndex) {
99+
return false;
100+
}
101+
}
102+
103+
return true;
104+
}
105+
106+
bool Parameters::isDlogItemAvailable(int slotIndex, int subchannelIndex, DlogResourceType resourceType) {
107+
int numResources = g_slots[slotIndex]->getNumDlogResources(subchannelIndex);
108+
for (int resourceIndex = 0; resourceIndex < numResources; resourceIndex++) {
109+
if (g_slots[slotIndex]->getDlogResourceType(subchannelIndex, resourceIndex) == resourceType) {
110+
return isDlogItemAvailable(slotIndex, subchannelIndex, resourceIndex);
111+
}
112+
}
113+
return false;
114+
}
115+
88116
eez_err_t Parameters::enableDlogItem(int slotIndex, int subchannelIndex, int resourceIndex, bool enable) {
89117
int dlogItemIndex;
90118
bool enabled = findDlogItemIndex(slotIndex, subchannelIndex, resourceIndex, dlogItemIndex);
@@ -99,6 +127,10 @@ eez_err_t Parameters::enableDlogItem(int slotIndex, int subchannelIndex, int res
99127
return SCPI_ERROR_HARDWARE_MISSING;
100128
}
101129

130+
if (!isDlogItemAvailable(slotIndex, subchannelIndex, resourceIndex)) {
131+
return SCPI_ERROR_HARDWARE_MISSING;
132+
}
133+
102134
if (dlogItemIndex < numDlogItems) {
103135
for (int i = numDlogItems - 1; i >= dlogItemIndex; i--) {
104136
memcpy(dlogItems + i + 1, dlogItems + i, sizeof(DlogItem));
@@ -208,6 +240,37 @@ bool Parameters::findDlogItemIndex(int slotIndex, int subchannelIndex, DlogResou
208240
return false;
209241
}
210242

243+
float Parameters::getResourceMinPeriod(int slotIndex, int subchannelIndex, int resourceIndex) {
244+
float minPeriod = g_slots[slotIndex]->getDlogResourceMinPeriod(subchannelIndex, resourceIndex);
245+
if (isNaN(minPeriod)) {
246+
return PERIOD_MIN;
247+
}
248+
return minPeriod;
249+
}
250+
251+
unsigned Parameters::setPeriod(float value) {
252+
period = value;
253+
254+
int numDisabled = 0;
255+
256+
for (int slotIndex = 0; slotIndex < NUM_SLOTS; slotIndex++) {
257+
int numSubchannels = g_slots[slotIndex]->getNumSubchannels();
258+
for (int subchannelIndex = 0; subchannelIndex < numSubchannels; subchannelIndex++) {
259+
int numResources = g_slots[slotIndex]->getNumDlogResources(subchannelIndex);
260+
for (int resourceIndex = 0; resourceIndex < numResources; resourceIndex++) {
261+
if (isDlogItemEnabled(slotIndex, subchannelIndex, resourceIndex)) {
262+
if (!isDlogItemAvailable(slotIndex, subchannelIndex, resourceIndex)) {
263+
enableDlogItem(slotIndex, subchannelIndex, resourceIndex, false);
264+
numDisabled++;
265+
}
266+
}
267+
}
268+
}
269+
}
270+
271+
return numDisabled;
272+
}
273+
211274
////////////////////////////////////////////////////////////////////////////////
212275

213276
State getState() {
@@ -602,7 +665,7 @@ void initDlogValues(Recording &recording) {
602665

603666
float div = (rangeMax - rangeMin) / NUM_VERT_DIVISIONS;
604667
recording.dlogValues[yAxisIndex].div = div;
605-
recording.dlogValues[yAxisIndex].offset = -div * NUM_VERT_DIVISIONS / 2;
668+
recording.dlogValues[yAxisIndex].offset = -rangeMin - div * NUM_VERT_DIVISIONS / 2;
606669
}
607670
}
608671

@@ -620,15 +683,15 @@ void calcColumnIndexes(Recording &recording) {
620683
for (int yAxisIndex = 0; yAxisIndex < recording.parameters.numYAxes; yAxisIndex++) {
621684
auto &yAxis = recording.parameters.yAxes[yAxisIndex];
622685

623-
recording.columnFloatIndexes[yAxisIndex] = columnIndex;
624-
625686
if (yAxis.unit == UNIT_BIT) {
626687
if (bitMask == 0) {
627688
bitMask = 0x4000;
628689
} else {
629690
bitMask >>= 1;
630691
}
631692

693+
recording.columnFloatIndexes[yAxisIndex] = columnIndex;
694+
632695
if (bitMask == 1) {
633696
columnIndex++;
634697
bitMask = 0;
@@ -639,6 +702,8 @@ void calcColumnIndexes(Recording &recording) {
639702
bitMask = 0;
640703
}
641704

705+
recording.columnFloatIndexes[yAxisIndex] = columnIndex;
706+
642707
columnIndex++;
643708
}
644709
}
@@ -733,7 +798,7 @@ void autoScale(Recording &recording) {
733798
dlogValueParams.offset = dlogValueParams.div * (NUM_VERT_DIVISIONS / 2 - (visibleDlogValueIndex + 1) * numDivisions);
734799
} else {
735800
dlogValueParams.div = (rangeMax - rangeMin) / numDivisions;
736-
dlogValueParams.offset = dlogValueParams.div * (NUM_VERT_DIVISIONS / 2 - (visibleDlogValueIndex + 1) * numDivisions);
801+
dlogValueParams.offset = -rangeMin + dlogValueParams.div * (NUM_VERT_DIVISIONS / 2 - (visibleDlogValueIndex + 1) * numDivisions);
737802
}
738803
}
739804
}
@@ -765,7 +830,7 @@ void scaleToFit(Recording &recording) {
765830
DlogValueParams &dlogValueParams = recording.dlogValues[dlogValueIndex];
766831
float numDivisions = 1.0f * NUM_VERT_DIVISIONS;
767832
dlogValueParams.div = (totalMax - totalMin) / numDivisions;
768-
dlogValueParams.offset = - dlogValueParams.div * NUM_VERT_DIVISIONS / 2;
833+
dlogValueParams.offset = -totalMin - dlogValueParams.div * NUM_VERT_DIVISIONS / 2;
769834
}
770835
}
771836

@@ -1099,33 +1164,12 @@ class DlogParamsPage : public SetPage {
10991164
}
11001165

11011166
static float getResourceMinPeriod(int slotIndex, int subchannelIndex, int resourceIndex) {
1102-
float minPeriod = g_slots[slotIndex]->getDlogResourceMinPeriod(subchannelIndex, resourceIndex);
1103-
if (isNaN(minPeriod)) {
1104-
return PERIOD_MIN;
1105-
}
1106-
return minPeriod;
1167+
return Parameters::getResourceMinPeriod(slotIndex, subchannelIndex, resourceIndex);
11071168
}
11081169

11091170
static void setPeriod(float value) {
11101171
g_parameters.period = value;
1111-
1112-
int numUnchecked = 0;
1113-
1114-
for (int slotIndex = 0; slotIndex < NUM_SLOTS; slotIndex++) {
1115-
int numSubchannels = g_slots[slotIndex]->getNumSubchannels();
1116-
for (int subchannelIndex = 0; subchannelIndex < numSubchannels; subchannelIndex++) {
1117-
int numResources = g_slots[slotIndex]->getNumDlogResources(subchannelIndex);
1118-
for (int resourceIndex = 0; resourceIndex < numResources; resourceIndex++) {
1119-
if (g_parameters.isDlogItemEnabled(slotIndex, subchannelIndex, resourceIndex)) {
1120-
if (getResourceMinPeriod(slotIndex, subchannelIndex, resourceIndex) - g_parameters.period >= 1E-6) {
1121-
g_parameters.enableDlogItem(slotIndex, subchannelIndex, resourceIndex, false);
1122-
numUnchecked++;
1123-
}
1124-
}
1125-
}
1126-
}
1127-
}
1128-
1172+
int numUnchecked = g_parameters.setPeriod(value);
11291173
if (numUnchecked > 0) {
11301174
psu::gui::infoMessage("Some resources unchecked.");
11311175
}
@@ -1293,8 +1337,8 @@ void data_dlog_period_has_predefined_values(DataOperationEnum operation, Cursor
12931337

12941338
void action_dlog_period_select_predefined_value() {
12951339
pushSelectFromEnumPage(g_predefinedDlogPeriodsEnumDefinition, 0, nullptr, [] (uint16_t value) {
1296-
DlogParamsPage::setPeriod(g_predefinedDlogPeriods[value]);
1297-
popPage();
1340+
popPage();
1341+
DlogParamsPage::setPeriod(g_predefinedDlogPeriods[value]);
12981342
}, true, false);
12991343
}
13001344

@@ -1399,16 +1443,7 @@ void data_dlog_item_is_available(DataOperationEnum operation, Cursor cursor, Val
13991443
int subchannelIndex;
14001444
int resourceIndex;
14011445
if (DlogParamsPage::findResource(cursor, slotIndex, subchannelIndex, resourceIndex)) {
1402-
bool enabled = DlogParamsPage::g_parameters.isDlogItemEnabled(slotIndex, subchannelIndex, resourceIndex);
1403-
if (!enabled && (
1404-
DlogParamsPage::g_parameters.numDlogItems >= dlog_file::MAX_NUM_OF_Y_AXES ||
1405-
DlogParamsPage::getResourceMinPeriod(slotIndex, subchannelIndex, resourceIndex)
1406-
> DlogParamsPage::g_parameters.period
1407-
)) {
1408-
value = 0;
1409-
} else {
1410-
value = 1;
1411-
}
1446+
value = DlogParamsPage::g_parameters.isDlogItemAvailable(slotIndex, subchannelIndex, resourceIndex);
14121447
} else {
14131448
value = 0;
14141449
}

src/eez/modules/psu/dlog_view.h

+9
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,22 @@ struct Parameters : public dlog_file::Parameters {
9292
DlogItem dlogItems[dlog_file::MAX_NUM_OF_Y_AXES];
9393
int numDlogItems = 0;
9494

95+
bool isDlogItemAvailable(int slotIndex, int subchannelIndex, int resourceIndex);
96+
bool isDlogItemAvailable(int slotIndex, int subchannelIndex, DlogResourceType resourceType);
97+
9598
eez_err_t enableDlogItem(int slotIndex, int subchannelIndex, int resourceIndex, bool enable);
9699
eez_err_t enableDlogItem(int slotIndex, int subchannelIndex, DlogResourceType resourceType, bool enable);
97100
bool isDlogItemEnabled(int slotIndex, int subchannelIndex, int resourceIndex);
98101
bool isDlogItemEnabled(int slotIndex, int subchannelIndex, DlogResourceType resourceType);
99102

100103
trigger::Source triggerSource = trigger::SOURCE_IMMEDIATE;
101104

105+
static float getResourceMinPeriod(int slotIndex, int subchannelIndex, int resourceIndex);
106+
107+
// returns the number of items that are disabled
108+
// because period is below min. period
109+
unsigned setPeriod(float value);
110+
102111
private:
103112
bool findDlogItemIndex(int slotIndex, int subchannelIndex, int resourceIndex, int &dlogItemIndex);
104113
bool findDlogItemIndex(int slotIndex, int subchannelIndex, DlogResourceType resourceType, int &dlogItemIndex);

src/eez/modules/psu/scpi/dlog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ scpi_result_t scpi_cmd_senseDlogPeriod(scpi_t *context) {
264264
period = (float)param.content.value;
265265
}
266266

267-
dlog_record::g_parameters.period = period;
267+
dlog_record::g_parameters.setPeriod(period);
268268

269269
return SCPI_RES_OK;
270270
}

0 commit comments

Comments
 (0)