Skip to content

Commit

Permalink
more gvret improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
markwj committed Jul 10, 2019
1 parent 61fa720 commit 5d8cb70
Showing 1 changed file with 74 additions and 2 deletions.
76 changes: 74 additions & 2 deletions vehicle/OVMS.V3/components/can/src/canformat_gvret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,80 @@ std::string canformat_gvret_ascii::get(CAN_log_message_t* message)

size_t canformat_gvret_ascii::put(CAN_log_message_t* message, uint8_t *buffer, size_t len)
{
return len;
size_t k;
char *b = (char*)buffer;

memset(message,0,sizeof(CAN_log_message_t));

for (k=0;k<len;k++)
{
if ((b[k]=='\r')||(b[k]=='\n'))
{
if (m_bufpos == 0)
continue;
else
break;
}
m_msg.m_buf[m_bufpos] = b[k];
if (m_bufpos < CANFORMAT_GVRET_MAXLEN) m_bufpos++;
}
if (k>=len) return len;

// OK. We have a buffer ready for decoding...
// buffer[Start .. k-1]
m_msg.m_buf[m_bufpos] = 0;
m_bufpos = 0; // Prepare for next message
b = (char*)m_msg.m_buf;

// We look for something like
// 1000 - 100 S 0 4 01 02 03 04
// timestamp, message ID (hex), S or X, length, data bytes

message->type = CAN_LogFrame_RX;

uint32_t timestamp = strtol(b,&b,10);
message->timestamp.tv_sec = timestamp % 1000000;
message->timestamp.tv_usec = timestamp / 1000000;

b += 2; // Skip the '-'

message->frame.MsgID = strtol(b,&b,16);
if (b[1] == 'S')
{
message->frame.FIR.B.FF = CAN_frame_std;
}
else if (b[1] == 'X')
{
message->frame.FIR.B.FF = CAN_frame_ext;
}
else
{
// Bad frame type - discard
return k+1;
}

b += 2; // Skip the frame type

uint32_t busnumber = strtol(b,&b,10);

message->frame.FIR.B.DLC = strtol(b,&b,10);
if (message->frame.FIR.B.DLC > 8)
{
// Bad frame length - discard
return k+1;
}

for (size_t x=0;x<message->frame.FIR.B.DLC;x++)
{
message->frame.data.u8[x] = strtol(b,&b,16);
}

char cbus[5] = "can";
cbus[3] = busnumber;
cbus[4] = 0;
message->origin = (canbus*)MyPcpApp.FindDeviceByName(cbus);

return k+1;
}

////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -149,7 +222,6 @@ std::string canformat_gvret_binary::get(CAN_log_message_t* message)
else
{ busnumber = "1"; }


frame.startbyte = GVRET_START_BYTE;
frame.command = BUILD_CAN_FRAME;
frame.microseconds = (uint32_t)((message->timestamp.tv_sec * 1000000) + message->timestamp.tv_usec);
Expand Down

0 comments on commit 5d8cb70

Please sign in to comment.