Commit 74756dbf authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Change trace code some more. (hopefully last time the stream format is

broken)
parent 513d855e
......@@ -208,7 +208,8 @@ int trace_packet_list_add(struct trace_pkt *pkt,
return 0;
}
int trace_packet_value_add(struct trace_pkt *pkt, struct trace_value *value, enum trace_value_type type)
int trace_packet_value_add(struct trace_pkt *pkt, int channel,
struct trace_value *value, enum trace_value_type type)
{
size_t entry_size;
struct {
......@@ -223,31 +224,30 @@ int trace_packet_value_add(struct trace_pkt *pkt, struct trace_value *value, enu
case TRACE_VALUE_TYPE_BOOL:
case TRACE_VALUE_TYPE_UINT8:
case TRACE_VALUE_TYPE_SINT8:
entry_size = 1;
entry_size = 1+1;
break;
case TRACE_VALUE_TYPE_SINT16:
case TRACE_VALUE_TYPE_UINT16:
entry_size = 2;
entry_size = 2+1;
break;
case TRACE_VALUE_TYPE_UINT32:
case TRACE_VALUE_TYPE_SINT32:
case TRACE_VALUE_TYPE_FLOAT:
default:
entry_size = 4;
entry_size = 4+1;
break;
}
if (!pkt->len) {
size_t len = sizeof(struct trace_header) +
sizeof(struct trace_ptype_value_header);
size_t len = sizeof(struct trace_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);
entry = pkt->data + pkt->len;
pkt->data[pkt->len] = channel;
entry = pkt->data + pkt->len + 1;
switch (type) {
case TRACE_VALUE_TYPE_BOOL:
......@@ -350,7 +350,7 @@ int trace_packet_type_set(struct trace_pkt *pkt, enum trace_value_type type)
return 0;
}
int trace_packet_capabilities_set(struct trace_pkt *pkt, unsigned cap)
int trace_packet_capabilities_set(struct trace_pkt *pkt, unsigned long cap)
{
size_t len = sizeof(struct trace_header) +
sizeof(struct trace_ptype_capabilities);
......@@ -512,34 +512,42 @@ int trace_handle_recv(struct trace *trace)
break;
}
case TRACE_PTYPE_CAPABILITIES: {
/* ignore caps for now */
size_t pos = sizeof(struct trace_header);
struct trace_ptype_capabilities *ncaps = (void *)pkt->data + pos;
unsigned long caps = be32toh(ncaps->capabilities);
if (trace->handler_capabilities) {
trace->handler_capabilities(trace, caps);
}
break;
}
case TRACE_PTYPE_DATA: {
/* ignore channel number for now (no multiplexing yet */
size_t pos = sizeof(struct trace_header) +
sizeof(struct trace_ptype_value_header);
/* ignore channel number for now (no multiplexing yet) */
size_t pos = sizeof(struct trace_header);
struct trace_ptype_value *v;
uint8_t channel;
while (pos < pkt->len) {
v = (void *)pkt->data + pos;
channel = v->channel;
switch (trace->type) {
case TRACE_VALUE_TYPE_FLOAT:
case TRACE_VALUE_TYPE_UINT32:
case TRACE_VALUE_TYPE_SINT32:
trace->value.value.u32 = be32toh(v->u.u32);
pos+=4;
pos+=4+1;
break;
case TRACE_VALUE_TYPE_UINT16:
case TRACE_VALUE_TYPE_SINT16:
trace->value.value.u16 = be32toh(v->u.u16);
pos+=2;
pos+=2+1;
break;
case TRACE_VALUE_TYPE_BOOL:
case TRACE_VALUE_TYPE_UINT8:
case TRACE_VALUE_TYPE_SINT8:
trace->value.value.u8 = v->u.u8;
pos++;
pos+=1+1;
break;
}
......@@ -550,7 +558,7 @@ int trace_handle_recv(struct trace *trace)
}
trace->value_set = true;
if (trace->handler_value) {
trace->handler_value(trace, &trace->value);
trace->handler_value(trace, channel, &trace->value);
}
}
break;
......
......@@ -125,11 +125,12 @@ struct trace {
char *name, enum trace_value_type type, char *unit);
void (*handler_type)(struct trace *,
enum trace_value_type type);
void (*handler_value)(struct trace *,
void (*handler_value)(struct trace *, int channel,
struct trace_value *value);
void (*handler_name)(struct trace *, char *name);
void (*handler_close)(struct trace *);
size_t (*handler_read)(struct trace *, void *buf, size_t len);
void (*handler_capabilities)(struct trace *, unsigned long cap);
void *private;
};
......@@ -176,8 +177,9 @@ int trace_packet_timestamp_set(struct trace_pkt *pkt,
struct timespec *timestamp);
int trace_packet_name_set(struct trace_pkt *pkt, char *name);
int trace_packet_type_set(struct trace_pkt *pkt, enum trace_value_type type);
int trace_packet_value_add(struct trace_pkt *pkt, struct trace_value *value, enum trace_value_type type);
int trace_packet_capabilities_set(struct trace_pkt *pkt, unsigned cap);
int trace_packet_value_add(struct trace_pkt *pkt, int channel,
struct trace_value *value, enum trace_value_type type);
int trace_packet_capabilities_set(struct trace_pkt *pkt, unsigned long cap);
bool trace_check(struct trace *trace);
bool trace_fd_set(struct trace *trace, fd_set *set, int *high);
......
......@@ -65,11 +65,8 @@ struct trace_ptype_value_type {
uint8_t type;
} __packed;
struct trace_ptype_value_header {
uint8_t channel;
} __packed;
struct trace_ptype_value {
uint8_t channel;
union {
uint32_t u32;
uint16_t u16;
......
......@@ -47,7 +47,7 @@ static void handler_timestamp(struct trace *trace,
cnt = 0;
}
static void handler_value(struct trace *trace,
static void handler_value(struct trace *trace, int channel,
struct trace_value *value)
{
cnt++;
......
......@@ -39,7 +39,7 @@ static void handler_interval(struct trace *trace,
}
static void handler_value(struct trace *trace,
static void handler_value(struct trace *trace, int channel,
struct trace_value *value)
{
switch (trace->type) {
......
......@@ -144,7 +144,7 @@ static void print_value(FILE *fd,
}
}
static void handler_value(struct trace *trace,
static void handler_value(struct trace *trace, int channel,
struct trace_value *value)
{
struct trace_view *view;
......
......@@ -385,7 +385,7 @@ static int trace_remove(struct libwebsocket *wsi)
return 0;
}
static void handler_trace_value(struct trace *trace,
static void handler_trace_value(struct trace *trace, int channel,
struct trace_value *value)
{
struct libwebsocket *wsi;
......
......@@ -105,7 +105,7 @@ static void cleanup_command(struct plugin_private *priv)
priv->nr_commands = 0;
}
static void handler_trace_value(struct trace *trace,
static void handler_trace_value(struct trace *trace, int channel,
struct trace_value *value)
{
struct plugin_private *priv;
......
......@@ -269,7 +269,7 @@ static bool timespec_mod(struct timespec *t, struct timespec *tdiv)
return t64 % tdiv64;
}
static void server_value(struct trace *trace,
static void server_value(struct trace *trace, int channel,
struct trace_value *value)
{
struct trace_pkt *pkt;
......@@ -286,7 +286,7 @@ static void server_value(struct trace *trace,
priv->lastvalue.value.u32 = value->value.u32;
pkt = trace_packet_new();
trace_packet_value_add(pkt, value, trace->type);
trace_packet_value_add(pkt, 0, value, trace->type);
for (i = 0; i < priv->nr_clients; i++) {
bool send = false;
......@@ -494,7 +494,7 @@ static void client_add(struct trace *client)
struct trace_pkt *pkt;
pkt = trace_packet_new();
trace_packet_value_add(pkt, &trace->value, trace->type);
trace_packet_value_add(pkt, 0, &trace->value, trace->type);
trace_packet_write(client, pkt);
trace_packet_put(pkt);
}
......
......@@ -64,7 +64,7 @@ function load_trace(tracename)
var trace_data = new Array();
ts.handler_value = function(ts, value) {
ts.handler_value = function(ts, channel, value) {
var td = new trace_value();
td.set(value);
trace_data.push(td);
......
......@@ -256,7 +256,7 @@ function trace_stream()
this.rx_buffer = new ArrayBuffer(0);
this.handler_value = function(ts, value) { }
this.handler_value = function(ts, channel, value) { }
}
trace_stream.prototype.rx = function(bytearray) {
var length = this.rx_buffer.byteLength;
......@@ -330,9 +330,11 @@ trace_stream.prototype.handle = function() {
/* ignore capabilities for now */
break;
case trace_ptype.DATA:
j = 2; /* header + channel number */
j = 1; /* header + channel number */
var datasize;
while (j < pkt_len) {
while (j + 1 < pkt_len) {
var channel = pkt.getUint8(j);
j++;
switch (this.type) {
case trace_value_type.BOOL:
datasize = 1;
......@@ -374,7 +376,7 @@ trace_stream.prototype.handle = function() {
} else {
this.value.t.add(this.interval);
}
this.handler_value(this, this.value);
this.handler_value(this, channel, this.value);
j += datasize;
}
......
......@@ -264,7 +264,7 @@ static void *controller_trace_handle(void *arg)
}
if (sendval) {
trace_packet_value_add(pkt,
trace_packet_value_add(pkt, 0,
(void*)&trace_hdl[i].ctrace.buffer[rd_pos+j],
trace_hdl[i].trace.type);
}
......
Markdown is supported
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