Commit 1add24c0 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Prepare trace format for multiplexing.

Add 'channel' fields to trace stream headers of name and value packets.
(channel number must be zero for now)
parent c2e21364
......@@ -238,9 +238,12 @@ int trace_packet_value_add(struct trace_pkt *pkt, struct trace_value *value, enu
}
if (!pkt->len) {
trace_packet_resize(pkt, 1);
pkt->len = 1;
size_t len = sizeof(struct trace_header) +
sizeof(struct trace_ptype_value_header);
trace_packet_resize(pkt, len);
pkt->len = len;
pkt->data[0] = TRACE_PTYPE_DATA;
pkt->data[1] = 0;
}
trace_packet_resize(pkt, pkt->len + entry_size);
......@@ -317,12 +320,16 @@ int trace_packet_timestamp_set(struct trace_pkt *pkt,
int trace_packet_name_set(struct trace_pkt *pkt, char *name)
{
if (pkt->len < sizeof(struct trace_header) + strlen(name) + 1) {
pkt->len = strlen(name) + 1 + sizeof(struct trace_header);
size_t len = sizeof(struct trace_header) +
sizeof(struct trace_ptype_name_header) +
strlen(name) + 1;
if (pkt->len < len) {
pkt->len = len;
trace_packet_resize(pkt, pkt->len);
pkt->data[0] = TRACE_PTYPE_NAME;
pkt->data[1] = 0;
}
strcpy((char *)pkt->data + 1, name);
strcpy((char *)pkt->data + 2, name);
return 0;
}
......@@ -476,7 +483,9 @@ int trace_handle_recv(struct trace *trace)
case TRACE_PTYPE_NAME: {
char *name;
name = (void*)pkt->data + 1;
name = (void*)pkt->data +
sizeof(struct trace_ptype_name_header) +
sizeof(struct trace_header);
trace->name_set = true;
trace->name = strdup(name);
......@@ -487,7 +496,9 @@ int trace_handle_recv(struct trace *trace)
break;
}
case TRACE_PTYPE_DATA: {
size_t pos = 1;
/* ignore channel number for now (no multiplexing yet */
size_t pos = sizeof(struct trace_header) +
sizeof(struct trace_ptype_value_header);
struct trace_ptype_value *v;
while (pos < pkt->len) {
......
......@@ -54,15 +54,21 @@ struct trace_ptype_interval {
uint8_t type;
} __packed;
/* trace_ptype_name
null terminated string
struct trace_ptype_name_header {
uint8_t channel;
} __packed;
/*
followed by null terminated string
*/
struct trace_ptype_value_type {
uint8_t type;
} __packed;
struct trace_ptype_value_header {
uint8_t channel;
} __packed;
struct trace_ptype_value {
union {
uint32_t u32;
......
......@@ -315,7 +315,8 @@ trace_stream.prototype.handle = function() {
break;
case trace_ptype.NAME:
this.name = "";
for (j = 1; j < pkt_len - 1; j++) {
/* name string starts at 2, after header and channel nr. */
for (j = 2; j < pkt_len - 1; j++) {
this.name += String.fromCharCode(pkt.getUint8(j))
}
break;
......@@ -325,7 +326,7 @@ trace_stream.prototype.handle = function() {
this.interval.nsec = pkt.getUint32(9, false);
break;
case trace_ptype.DATA:
j = 1;
j = 2; /* header + channel number */
var datasize;
while (j < pkt_len) {
switch (this.type) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment