Commit 1e062fa5 authored by Mikhail Karpenko's avatar Mikhail Karpenko

Check compressors state before starting

parent 85935b34
......@@ -212,6 +212,21 @@ void put_uint64(void *buf, u_int64_t val)
tmp[7] = (val >>= 8) & 0xff;
}
/**
* @brief Detect running compressors and update active channels mask. This function should be
* called right after all driver files are opened.
* @param state pointer to #camogm_state structure containing program state
* @return none
*/
void check_compressors(camogm_state *state)
{
for (int i = 0; i < SENSOR_PORTS; i++) {
if (getGPValue(i, P_COMPRESSOR_RUN) != COMPRESSOR_RUN_STOP) {
state->active_chn |= 1 << i;
}
}
}
/**
* @brief Initialize the state of the program
* @param[in] state pointer to #camogm_state structure containing program state
......@@ -259,7 +274,7 @@ void camogm_init(camogm_state *state, char *pipe_name, uint16_t port_num)
state->rawdev.end_pos = state->rawdev.start_pos;
state->rawdev.curr_pos_w = state->rawdev.start_pos;
state->rawdev.curr_pos_r = state->rawdev.start_pos;
state->active_chn = ALL_CHN_ACTIVE;
state->active_chn = ALL_CHN_INACTIVE;
state->rawdev.mmap_default_size = MMAP_CHUNK_SIZE;
state->sock_port = port_num;
}
......@@ -378,7 +393,6 @@ int camogm_start(camogm_state *state)
memcpy(&(state->frame_params[chn]), (unsigned long* )&ccam_dma_buf[chn][state->metadata_start >> 2], 32);
state->jpeg_len = state->frame_params[chn].frame_length; // frame_params.frame_length are now the length of bitstream
if (state->frame_params[chn].signffff != 0xffff) {
D0(fprintf(debug_file, "%s:%d: wrong signature - %d\r\n", __FILE__, __LINE__, (int)state->frame_params[chn].signffff));
state->cirbuf_rp[chn] = -1;
......@@ -1902,6 +1916,7 @@ int main(int argc, char *argv[])
ret = open_files(&sstate);
if (ret < 0)
return ret;
check_compressors(&sstate);
if (pthread_create(&sstate.rawdev.tid, NULL, reader, &sstate) != 0 ||
pthread_detach(sstate.rawdev.tid) != 0) {
D0(fprintf(debug_file, "%s:line %d: Can not start reading thread in detached state\n", __FILE__, __LINE__));
......@@ -1955,7 +1970,7 @@ int waitDaemonEnabled(unsigned int port, int daemonBit) // <0 - use default
unsigned long this_frame = GLOBALPARS(port, G_THIS_FRAME);
// No semaphors, so it is possible to miss event and wait until the streamer will be re-enabled before sending message,
// but it seems not so terrible
lseek(state->fd_circ[state->port_num], LSEEK_DAEMON_CIRCBUF + lastDaemonBit[port], SEEK_END);
lseek(state->fd_circ[port], LSEEK_DAEMON_CIRCBUF + lastDaemonBit[port], SEEK_END);
if (this_frame == GLOBALPARS(port, G_THIS_FRAME)) return 1;
return 0;
}
......
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