Skip to content

Commit

Permalink
Added jls_wr_fsr_omit_data and jls_twr_fsr_omit_data.
Browse files Browse the repository at this point in the history
Read support NOT yet implemented.
  • Loading branch information
mliberty1 committed Sep 13, 2023
1 parent 5927ca7 commit 15d4c8b
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This file contains the list of changes made to the JLS project.
* Refactored reader and writer into new core to enable repairer.
* Added jls_twr_flags_get/set.
* Added JLS_TWR_FLAG_DROP_ON_OVERFLOW which drops samples on overflow.
* Added jls_wr_fsr_omit_data and jls_twr_fsr_omit_data.


## 0.7.3
Expand Down
15 changes: 15 additions & 0 deletions include/jls/threaded_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,21 @@ JLS_API int32_t jls_twr_fsr(struct jls_twr_s * self, uint16_t signal_id,
JLS_API int32_t jls_twr_fsr_f32(struct jls_twr_s * self, uint16_t signal_id,
int64_t sample_id, const float * data, uint32_t data_length);

/**
* @brief Omit level 0 data chunks from the signal's stream.
*
* @param self The JLS writer instance
* @param signal_id The signal id.
* @param enable 0 to disable (default), 1 to enable.
* @return 0 or error code.
*
* Enable is delayed by one sample block to ensure any pending
* data is writen. Disable takes effect immediately.
*
* On read, the level 0 data is reconstructed using the summaries.
*/
JLS_API int32_t jls_twr_fsr_omit_data(struct jls_twr_s * self, uint16_t signal_id, uint32_t enable);

/**
* @brief Add an annotation to a signal.
*
Expand Down
15 changes: 15 additions & 0 deletions include/jls/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ JLS_API int32_t jls_wr_fsr(struct jls_wr_s * self, uint16_t signal_id,
JLS_API int32_t jls_wr_fsr_f32(struct jls_wr_s * self, uint16_t signal_id,
int64_t sample_id, const float * data, uint32_t data_length);

/**
* @brief Omit level 0 data chunks from the signal's stream.
*
* @param self The JLS writer instance
* @param signal_id The signal id.
* @param enable 0 to disable (default), 1 to enable.
* @return 0 or error code.
*
* Enable is delayed by one sample block to ensure any pending
* data is writen. Disable takes effect immediately.
*
* On read, the level 0 data is reconstructed using the summaries.
*/
JLS_API int32_t jls_wr_fsr_omit_data(struct jls_wr_s * self, uint16_t signal_id, uint32_t enable);

/**
* @brief Add an annotation to a signal.
*
Expand Down
1 change: 1 addition & 0 deletions include_prv/jls/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ struct jls_core_fsr_s {
struct jls_fsr_data_s * data; // for level 0 sample data
double * data_f64; // for level 0 sample data summarization statistics computation
int64_t sample_id_offset;
uint8_t write_omit_data; // omit level 0 sample data. >1=enabled, else disabled
uint8_t shift_amount;
uint8_t shift_buffer;
uint64_t buffer_u64[4096]; // for shifting incoming sample data on skips & duplicates
Expand Down
8 changes: 8 additions & 0 deletions pyjls/binding.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,14 @@ cdef class Writer:
rc = c_jls.jls_twr_fsr(wr, signal_id_u16, sample_id_i64, &u8[0], length)
_handle_rc('fsr', rc)

def fsr_omit_data(self, signal_id, enable):
cdef c_jls.jls_twr_s * wr = self._wr
cdef uint16_t signal_id_u16 = signal_id
cdef uint32_t enable_u32 = 0 if bool(enable) else 1
cdef int32_t rc
rc = c_jls.jls_twr_fsr_omit_data(wr, signal_id_u16, enable_u32)
_handle_rc('fsr_omit_data', rc)

def annotation(self, signal_id, timestamp, y, annotation_type, group_id, data):
"""Add an annotation to a signal.
Expand Down
1 change: 1 addition & 0 deletions pyjls/c_jls.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ cdef extern from "jls/threaded_writer.h":
jls_storage_type_e storage_type, const uint8_t * data, uint32_t data_size) nogil
int32_t jls_twr_fsr(jls_twr_s * self, uint16_t signal_id,
int64_t sample_id, const void * data, uint32_t data_length) nogil
int32_t jls_twr_fsr_omit_data(jls_twr_s * self, uint16_t signal_id, uint32_t enable)
int32_t jls_twr_annotation(jls_twr_s * self, uint16_t signal_id,
int64_t timestamp,
float y,
Expand Down
24 changes: 24 additions & 0 deletions src/threaded_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ struct msg_header_fsr_s {
uint32_t sample_count;
};

struct msg_header_fsr_omit_s {
uint16_t signal_id;
int32_t enable;
};

struct msg_header_annotation_s {
uint16_t signal_id;
int64_t timestamp;
Expand All @@ -74,6 +79,7 @@ struct msg_header_s {
union {
struct msg_header_user_data_s user_data;
struct msg_header_fsr_s fsr;
struct msg_header_fsr_omit_s fsr_omit;
struct msg_header_annotation_s annotation;
struct msg_header_utc_s utc;
} h;
Expand All @@ -85,6 +91,7 @@ enum message_e {
MSG_FLUSH, // no header data, no args
MSG_USER_DATA, // hdr.user_data, user_data
MSG_FSR, // hdr.fsr_f32, data
MSG_FSR_OMIT, // hdr.fsr_omit, no args
MSG_ANNOTATION, // hdr.annotation, data
MSG_UTC, // hdr.utc, data
MSG_ITEM_COUNT,
Expand Down Expand Up @@ -156,6 +163,9 @@ int32_t jls_twr_run(struct jls_twr_s * self) {
case MSG_FSR:
rc = jls_wr_fsr(self->wr, hdr.h.fsr.signal_id, hdr.h.fsr.sample_id, payload, hdr.h.fsr.sample_count);
break;
case MSG_FSR_OMIT:
rc = jls_wr_fsr_omit_data(self->wr, hdr.h.fsr_omit.signal_id, hdr.h.fsr_omit.enable);
break;
case MSG_ANNOTATION:
rc = jls_wr_annotation(self->wr, hdr.h.annotation.signal_id, hdr.h.annotation.timestamp,
hdr.h.annotation.y,
Expand Down Expand Up @@ -359,6 +369,20 @@ int32_t jls_twr_fsr_f32(struct jls_twr_s * self, uint16_t signal_id,
return jls_twr_fsr(self, signal_id, sample_id, data, data_length);
}

int32_t jls_twr_fsr_omit_data(struct jls_twr_s * self, uint16_t signal_id, uint32_t enable) {
struct msg_header_s hdr = {
.msg_type = MSG_FSR_OMIT,
.h = {
.fsr_omit = {
.signal_id = signal_id,
.enable = enable,
}
},
.d = 0
};
return msg_send(self, &hdr, NULL, 0);
}

int32_t jls_twr_annotation(struct jls_twr_s * self, uint16_t signal_id, int64_t timestamp,
float y,
enum jls_annotation_type_e annotation_type,
Expand Down
9 changes: 7 additions & 2 deletions src/wr_fsr.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,16 @@ static int32_t wr_data(struct jls_core_fsr_s * self) {
+ (self->data->header.entry_count * sample_size_bits(self) + 7) / 8;
uint8_t * p_start = (uint8_t *) self->data;
int64_t pos = jls_raw_chunk_tell(self->parent->parent->raw);
ROE(jls_core_wr_data(self->parent->parent, self->parent->signal_def.signal_id, JLS_TRACK_TYPE_FSR, p_start,
payload_length));
if (self->write_omit_data > 1) {
pos = 0;
} else {
ROE(jls_core_wr_data(self->parent->parent, self->parent->signal_def.signal_id, JLS_TRACK_TYPE_FSR, p_start,
payload_length));
}
ROE(jls_core_fsr_summary1(self, pos));
self->data->header.timestamp += self->parent->signal_def.samples_per_data;
self->data->header.entry_count = 0;
self->write_omit_data = (self->write_omit_data << 1) | (self->write_omit_data & 1);
return 0;
}

Expand Down
15 changes: 13 additions & 2 deletions src/writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int32_t jls_wr_close(struct jls_wr_s * self) {
return 0;
}

JLS_API int32_t jls_wr_flush(struct jls_wr_s * self) {
int32_t jls_wr_flush(struct jls_wr_s * self) {
return jls_raw_flush(self->core.raw);
}

Expand Down Expand Up @@ -331,7 +331,7 @@ int32_t jls_wr_user_data(struct jls_wr_s * self, uint16_t chunk_meta,
return jls_core_update_item_head(&self->core, &self->core.user_data_head, &chunk);
}

JLS_API int32_t jls_wr_fsr(struct jls_wr_s * self, uint16_t signal_id,
int32_t jls_wr_fsr(struct jls_wr_s * self, uint16_t signal_id,
int64_t sample_id, const void * data, uint32_t data_length) {
ROE(jls_core_signal_validate(&self->core, signal_id));
struct jls_core_signal_s * info = &self->core.signal_info[signal_id];
Expand All @@ -348,6 +348,17 @@ int32_t jls_wr_fsr_f32(struct jls_wr_s * self, uint16_t signal_id,
return jls_wr_fsr_data(info->track_fsr, sample_id, data, data_length);
}

int32_t jls_wr_fsr_omit_data(struct jls_wr_s * self, uint16_t signal_id, uint32_t enable) {
ROE(jls_core_signal_validate(&self->core, signal_id));
struct jls_core_signal_s * info = &self->core.signal_info[signal_id];
if (enable) {
info->track_fsr->write_omit_data |= 1;
} else {
info->track_fsr->write_omit_data = 0;
}
return 0;
}

int32_t jls_wr_annotation(struct jls_wr_s * self, uint16_t signal_id, int64_t timestamp,
float y,
enum jls_annotation_type_e annotation_type,
Expand Down

0 comments on commit 15d4c8b

Please sign in to comment.