Commit cd9c687b authored by Andrey Filippov's avatar Andrey Filippov

Fixing recording from Lepton

parent 36b9f027
...@@ -1630,104 +1630,108 @@ int listener_loop(camogm_state *state) ...@@ -1630,104 +1630,108 @@ int listener_loop(camogm_state *state)
ret = poll(&pfd,1,DEFAULT_POLL_TIMEOUT); ret = poll(&pfd,1,DEFAULT_POLL_TIMEOUT);
if (ret==0){ if (ret==0){
D6(fprintf(debug_file, "Waiting for commands...\n")); D6(fprintf(debug_file, "Waiting for commands..., state->prog_state = %d, pfd.revents=%d\n",state->prog_state, (int) pfd.revents));
} }
if (pfd.revents & POLLIN){ if (pfd.revents & POLLIN){
cmd = parse_cmd(state, cmd_file); cmd = parse_cmd(state, cmd_file);
if (cmd) { if (cmd) {
if (cmd < 0) D0(fprintf(debug_file, "Unrecognized command\n")); if (cmd < 0) D0(fprintf(debug_file, "Unrecognized command\n"));
} else if (state->prog_state == STATE_RUNNING) { // no commands in queue, started }
switch ((rslt = -sendImageFrame(state))) { } else if (state->prog_state == STATE_RUNNING) { // no commands in queue, started
case 0:
break; // frame sent OK, nothing to do (TODO: check file length/duration) D6(fprintf(debug_file, "state->prog_state == STATE_RUNNING "));
case CAMOGM_FRAME_NOT_READY: // just wait for the frame to appear at the current pointer switch ((rslt = -sendImageFrame(state))) {
// we'll wait for a frame, not to waste resources. But if the compressor is stopped this program will not respond to any commands D6(fprintf(debug_file, " ==> %d",rslt));
// TODO - add another wait with (short) timeout? case 0:
fp0 = lseek(state->fd_circ[curr_port], 0, SEEK_CUR); break; // frame sent OK, nothing to do (TODO: check file length/duration)
if (fp0 < 0) { case CAMOGM_FRAME_NOT_READY: // just wait for the frame to appear at the current pointer
D0(fprintf(debug_file, "%s:line %d got broken frame (%d) before waiting for ready\n", __FILE__, __LINE__, fp0)); // we'll wait for a frame, not to waste resources. But if the compressor is stopped this program will not respond to any commands
// TODO - add another wait with (short) timeout?
fp0 = lseek(state->fd_circ[curr_port], 0, SEEK_CUR);
if (fp0 < 0) {
D0(fprintf(debug_file, "%s:line %d got broken frame (%d) before waiting for ready\n", __FILE__, __LINE__, fp0));
rslt = CAMOGM_FRAME_BROKEN;
} else {
fp1 = lseek(state->fd_circ[curr_port], LSEEK_CIRC_WAIT, SEEK_END);
if (fp1 < 0) {
D0(fprintf(debug_file, "%s:line %d got broken frame (%d) while waiting for ready. Before that fp0=0x%x\n", __FILE__, __LINE__, fp1, fp0));
rslt = CAMOGM_FRAME_BROKEN; rslt = CAMOGM_FRAME_BROKEN;
} else { } else {
fp1 = lseek(state->fd_circ[curr_port], LSEEK_CIRC_WAIT, SEEK_END); break;
if (fp1 < 0) {
D0(fprintf(debug_file, "%s:line %d got broken frame (%d) while waiting for ready. Before that fp0=0x%x\n", __FILE__, __LINE__, fp1, fp0));
rslt = CAMOGM_FRAME_BROKEN;
} else {
break;
}
} }
// no break }
case CAMOGM_FRAME_CHANGED: // frame parameters have changed // no break
case CAMOGM_FRAME_NEXTFILE: // next file needed (need to switch to a new file (time/size exceeded limit) case CAMOGM_FRAME_CHANGED: // frame parameters have changed
case CAMOGM_FRAME_INVALID: // invalid frame pointer case CAMOGM_FRAME_NEXTFILE: // next file needed (need to switch to a new file (time/size exceeded limit)
case CAMOGM_FRAME_BROKEN: // frame broken (buffer overrun) case CAMOGM_FRAME_INVALID: // invalid frame pointer
// restart the file case CAMOGM_FRAME_BROKEN: // frame broken (buffer overrun)
D3(fprintf(debug_file,"%s:line %d - sendImageFrame() returned -%d\n", __FILE__, __LINE__, rslt)); // restart the file
camogm_stop(state); D3(fprintf(debug_file,"%s:line %d - sendImageFrame() returned -%d\n", __FILE__, __LINE__, rslt));
state->prog_state = STATE_RESTARTING; camogm_stop(state);
camogm_start(state); state->prog_state = STATE_RESTARTING;
break; camogm_start(state);
case CAMOGM_FRAME_FILE_ERR: // error with file I/O break;
case CAMOGM_FRAME_OTHER: // other errors case CAMOGM_FRAME_FILE_ERR: // error with file I/O
D0(fprintf(debug_file, "%s:line %d - error=%d\n", __FILE__, __LINE__, rslt)); case CAMOGM_FRAME_OTHER: // other errors
break; D0(fprintf(debug_file, "%s:line %d - error=%d\n", __FILE__, __LINE__, rslt));
default: break;
D0(fprintf(debug_file, "%s:line %d - should not get here (rslt=%d)\n", __FILE__, __LINE__, rslt)); default:
clean_up(state); D0(fprintf(debug_file, "%s:line %d - should not get here (rslt=%d)\n", __FILE__, __LINE__, rslt));
exit(-1); clean_up(state);
} // switch sendImageFrame() exit(-1);
} // switch sendImageFrame()
// collect error statistics
if (rslt > 0 && rslt < CAMOGM_ERRNUM) // collect error statistics
state->error_stat[curr_port][rslt]++; if (rslt > 0 && rslt < CAMOGM_ERRNUM)
state->error_stat[curr_port][rslt]++;
if ((rslt != 0) && (rslt != CAMOGM_FRAME_NOT_READY) && (rslt != CAMOGM_FRAME_CHANGED))
// add port number to error code to facilitate debugging if ((rslt != 0) && (rslt != CAMOGM_FRAME_NOT_READY) && (rslt != CAMOGM_FRAME_CHANGED))
state->last_error_code = rslt + 100 * state->port_num; // add port number to error code to facilitate debugging
} else if (state->prog_state == STATE_STARTING) { // no commands in queue,starting (but not started yet) state->last_error_code = rslt + 100 * state->port_num;
} else if (state->prog_state == STATE_STARTING) { // no commands in queue,starting (but not started yet)
// retry starting
switch ((rslt = -camogm_start(state))) { // retry starting
case 0: switch ((rslt = -camogm_start(state))) {
break; // file started OK, nothing to do case 0:
case CAMOGM_TOO_EARLY: break; // file started OK, nothing to do
lseek(state->fd_circ[curr_port], LSEEK_CIRC_TOWP, SEEK_END); // set pointer to the frame to wait for case CAMOGM_TOO_EARLY:
lseek(state->fd_circ[curr_port], LSEEK_CIRC_WAIT, SEEK_END); // It already passed CAMOGM_FRAME_NOT_READY, so compressor may be running already lseek(state->fd_circ[curr_port], LSEEK_CIRC_TOWP, SEEK_END); // set pointer to the frame to wait for
break; // no need to wait extra lseek(state->fd_circ[curr_port], LSEEK_CIRC_WAIT, SEEK_END); // It already passed CAMOGM_FRAME_NOT_READY, so compressor may be running already
case CAMOGM_FRAME_NOT_READY: // just wait for the frame to appear at the current pointer break; // no need to wait extra
// we'll wait for a frame, not to waste resources. But if the compressor is stopped this program will not respond to any commands case CAMOGM_FRAME_NOT_READY: // just wait for the frame to appear at the current pointer
// TODO - add another wait with (short) timeout? // we'll wait for a frame, not to waste resources. But if the compressor is stopped this program will not respond to any commands
case CAMOGM_FRAME_CHANGED: // frame parameters have changed // TODO - add another wait with (short) timeout?
case CAMOGM_FRAME_NEXTFILE: case CAMOGM_FRAME_CHANGED: // frame parameters have changed
case CAMOGM_FRAME_INVALID: // invalid frame pointer case CAMOGM_FRAME_NEXTFILE:
case CAMOGM_FRAME_BROKEN: // frame broken (buffer overrun) case CAMOGM_FRAME_INVALID: // invalid frame pointer
usleep(COMMAND_LOOP_DELAY); // it should be not too long so empty buffer will not be overrun case CAMOGM_FRAME_BROKEN: // frame broken (buffer overrun)
break; usleep(COMMAND_LOOP_DELAY); // it should be not too long so empty buffer will not be overrun
case CAMOGM_FRAME_FILE_ERR: // error with file I/O break;
case CAMOGM_FRAME_OTHER: // other errors case CAMOGM_FRAME_FILE_ERR: // error with file I/O
D0(fprintf(debug_file, "%s:line %d - error=%d\n", __FILE__, __LINE__, rslt)); case CAMOGM_FRAME_OTHER: // other errors
break; D0(fprintf(debug_file, "%s:line %d - error=%d\n", __FILE__, __LINE__, rslt));
default: break;
D0(fprintf(debug_file, "%s:line %d - should not get here (rslt=%d)\n", __FILE__, __LINE__, rslt)); default:
clean_up(state); D0(fprintf(debug_file, "%s:line %d - should not get here (rslt=%d)\n", __FILE__, __LINE__, rslt));
exit(-1); clean_up(state);
} // switch camogm_start() exit(-1);
} // switch camogm_start()
// collect error statistics
if (rslt > 0 && rslt < CAMOGM_ERRNUM) // collect error statistics
state->error_stat[curr_port][rslt]++; if (rslt > 0 && rslt < CAMOGM_ERRNUM)
state->error_stat[curr_port][rslt]++;
if ((rslt != 0) && (rslt != CAMOGM_TOO_EARLY) && (rslt != CAMOGM_FRAME_NOT_READY) && (rslt != CAMOGM_FRAME_CHANGED) )
// add port number to error code to facilitate debugging if ((rslt != 0) && (rslt != CAMOGM_TOO_EARLY) && (rslt != CAMOGM_FRAME_NOT_READY) && (rslt != CAMOGM_FRAME_CHANGED) )
state->last_error_code = rslt + 100 * state->port_num; // add port number to error code to facilitate debugging
} else if (state->prog_state == STATE_READING) { state->last_error_code = rslt + 100 * state->port_num;
usleep(COMMAND_LOOP_DELAY); } else if (state->prog_state == STATE_READING) {
} else { // not running, not starting usleep(COMMAND_LOOP_DELAY);
state->rawdev.thread_state = STATE_RUNNING; } else { // not running, not starting
usleep(COMMAND_LOOP_DELAY); // make it longer but interruptible by signals? state->rawdev.thread_state = STATE_RUNNING;
} usleep(COMMAND_LOOP_DELAY); // make it longer but interruptible by signals?
} // if pfd.revents & POLLIN }
// } // if pfd.revents & POLLIN
} // while (process) } // while (process)
// normally, we should not be here // normally, we should not be here
......
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