Vehicle Network Toolbox Value Table Use
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I have been decoding this CAN message using DBC file which contains meanings of each message; for example, 1 is on and 0 is off.
This information is under canDB (DBC file information) -> Message info -> signal info -> Value Table.
canDB = canDatabse (example_dbcfile)
There is a function to create a canMessageTimetable as in a timetable with only values (1 and 0) but don't see any functions or ways to create a timetable to saw (on or off) using the value table.
Is there a way to create a timetable using this value table automatically for each CAN message?
0 comentarios
Respuesta aceptada
Harimurali
el 6 de Feb. de 2024
Editada: Harimurali
el 6 de Feb. de 2024
Hi Min,
A timetable that shows "on" or "off" instead of 1 or 0 can be created using the value table defined in the DBC file by writing a MATLAB script. The script decodes the raw data based on the value table and then creates a new timetable with the decoded values. Here is an example MATLAB script to do the same:
% Load the DBC file
candb = canDatabase("example_dbcfile.dbc");
% Assume canMsgs is a variable containing your raw CAN messages
% Create a canMessageTimetable from the raw CAN messages
canTimetable = canMessageTimetable(canMsgs, candb);
% Initialize a cell array to hold the decoded messages
decodedMessages = cell(size(canTimetable, 1), 2);
decodedMessages(:, 1) = {candb.MessageInfo.Name};
for i = 1:numel(candb.Messages)
message = candb.MessageInfo(i);
signals = canTimetable.Signals{i};
% structure to store the decoded values for each signal for a given message
sigVal = struct();
for j = 1:numel(message.Signals)
signal = message.SignalInfo(j);
rawValues = num2cell(signals.(signal.Name));
if numel(rawValues) ~= 0
decodedValues = cell(numel(rawValues), 1);
else
decodedValues = cell(numel(rawValues) + 1, 1);
end
% Check if the signal has a value table
if ~isempty(signal.ValueTable)
for k = 1:length(rawValues)
% Decode based on value table
decodedValues{k} = signal.ValueTable(rawValues(k));
end
else
% If no value table, just copy the raw values
decodedValues = rawValues;
end
% Store the decoded values in the structue
sigVal.(signal.Name) = decodedValues;
end
decodedMessages{i, 2} = sigVal;
end
% Create a new timetable with the decoded values
decodedTimetable = array2timetable(decodedMessages, 'RowTimes', canTimetable.Time);
% Add variable names to the timetable
decodedTimetable.Properties.VariableNames = [, "MessageName", "SignalInfo"];
Refer the following documentation for more information on CAN "canMessageTimeTable" and it's format: https://www.mathworks.com/help/releases/R2023a/vnt/ug/canmessagetimetable.html
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Vehicle Network Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!