/* enable alert on motion detect */ int mxuvc_alert_motion_enable( void (*callback)(alert_motion_data*, void *data), /* callback with motion info */ void *data) { int ret = 0; alert_type type; CHECK_ERROR(check_alert_state() != 1, -1, "alert module is not initialized"); if(alert_enable == 0) alert_enable = 1; else { CHECK_ERROR(alert_enable == 1, -1, "Motion alert module is already initialized"); } type.b.audio_alert = 0; type.b.motion_alert = 1; ret = set_alert(type, ALARM_ACTION_ENABLE, 0, -1, 0, 0, 0, 0, 0, 0 ); CHECK_ERROR(ret != 0, -1, "set_alert failed"); motion_callback = callback; cb_muser_data = data; return ret; }
int mxuvc_alert_audio_set_threshold(unsigned int audioThresholdDB) { int ret = 0; alert_type type; float PowVal; unsigned int aud_threshold_val; CHECK_ERROR(check_alert_state() != 1, -1, "alert module is not initialized"); audio_threshold_dB = audioThresholdDB; if(alert_enable==0) return ret; type.d32 = 0; type.b.audio_alert = 1; //convert DB to Intensity PowVal = (float)(audio_threshold_dB/20.0); PowVal = pow(10, PowVal); aud_threshold_val = (unsigned int)(PowVal + 0.5); ret = set_alert(type, ALARM_ACTION_ENABLE, aud_threshold_val, NULL, 0, 0, 0); CHECK_ERROR(ret != 0, -1, "set_alert failed"); return ret; }
/** @return end() which is > pos */ int64_t wait_for( int64_t pos ) { try { return _end = _barrier.wait_for(pos) + 1; } catch ( const eof& ) { _cursor.set_eof(); throw; } catch ( ... ) { set_alert( std::current_exception() ); throw; } }
/** * We need to wait until the available space in * the ring buffer is pos - cursor which means that * all readers must be at least to pos - size_ and * that our new end is the min of the readers + size_ */ int64_t wait_for (int64_t pos) { try { // throws exception on error, returns 'short' on eof return end_ = barrier_.wait_for (pos - size_) + size_; } catch (...) { set_alert (std::current_exception ()); throw; } }
/** * @return end() which is > pos */ int64_t wait_for(int64_t pos) { try { return end_ = barrier_.wait_for(pos) + 1; } catch (const Eof&) { cursor_.set_eof(); throw; } catch (...) { set_alert(std::current_exception()); throw; } }
/* set a sensitivity and level */ int mxuvc_alert_motion_sensitivity_and_level( int reg_id, /* region number; used when alert is generated */ int sensitivity, int level ) { int ret = 0; alert_type type; CHECK_ERROR(alert_enable == 0, -1, "Motion alert module is not initialized"); if(ROI_MAX==reg_id+1) { ERROR(-1,"Reached Maximum Number of Region of Interest " "that can be added for the motion alert \n"); } type.b.audio_alert = 0; type.b.motion_alert = 1; if(sensitivity < MIN_SENSITIVITY) { sensitivity = MIN_SENSITIVITY; } else if(sensitivity > MAX_SENSITIVITY) { sensitivity = MAX_SENSITIVITY; } if(level < MIN_LEVEL) { level = MIN_LEVEL; } else if(level > MAX_LEVEL) { sensitivity = MAX_LEVEL; } region_params[reg_id].sensitivity = sensitivity; region_params[reg_id].level = level; ret = set_alert(type, ALARM_ACTION_ADD, 0, reg_id, region_params[reg_id].x_offset, region_params[reg_id].y_offset, region_params[reg_id].width, region_params[reg_id].height, region_params[reg_id].sensitivity, region_params[reg_id].level); CHECK_ERROR(ret != 0, -1, "set_alert failed"); return ret; }
/** * We need to wait until the available space in * the ring buffer is pos - cursor which means that * all readers must be at least to pos - _size and * that our new end is the min of the readers + _size */ int64_t wait_for( int64_t pos ) { try { // throws exception on error, returns 'short' on eof return _end = _barrier.wait_for( pos - _size ) + _size; } catch ( ... ) { set_alert( std::current_exception() ); throw; } }
void publish_after(int64_t pos, int64_t after_pos) { try { assert(pos > after_pos); barrier_.wait_for(after_pos); publish(pos); } catch (const Eof&) { cursor_.set_eof(); throw; } catch (...) { set_alert(std::current_exception()); throw; } }
/** * This method will block until 'after_pos' is the * current pos, then it will set pos to 'pos' */ void publish_after( int64_t pos, int64_t after_pos ) { try { assert( pos > after_pos ); while( _cursor.aquire() < after_pos ) { // TODO:... this is a spinlock, ease CPU HERE... } // _barrier.wait_for(after_pos); publish( pos ); } catch ( const eof& ) { _cursor.set_eof(); throw; } catch ( ... ) { set_alert( std::current_exception() ); throw; } }
/** * This method will block until 'after_pos' is the * current pos, then it will set pos to 'pos' */ void publish_after( int64_t pos, int64_t after_pos ) { try { assert( pos > after_pos ); // std::cerr<<"publish "<<pos<<" after " << after_pos << " current pos: "<<_cursor.aquire()<<"\n"; while( _cursor.aquire() != after_pos ) { // TODO:... this is a spinlock, ease CPU HERE... usleep(0); } // _barrier.wait_for(after_pos); publish( pos ); } catch ( const eof& ) { _cursor.set_eof(); throw; } catch ( ... ) { set_alert( std::current_exception() ); throw; } }
/* api to disable audio alarm */ int mxuvc_alert_audio_disable(void) { alert_type type; int ret = 0; CHECK_ERROR(alert_enable == 0, -1, "Audio alert module is not initialized"); if(alert_enable){ alert_enable = 0; type.d32 = 0; type.b.audio_alert = 1; ret = set_alert(type, ALARM_ACTION_DISABLE, 0, NULL, 0, 0, 0); CHECK_ERROR(ret != 0, -1, "set_alert failed"); } return ret; }
/* remove a region from motion detection */ int mxuvc_alert_motion_remove_region(int reg_id) { int ret = 0; alert_type type; CHECK_ERROR(alert_enable == 0, -1, "Motion alert module is not initialized"); type.b.audio_alert = 0; type.b.motion_alert = 1; ret = set_alert(type, ALARM_ACTION_REMOVE, 0, reg_id, region_params[reg_id].x_offset, region_params[reg_id].y_offset, region_params[reg_id].width, region_params[reg_id].height, 0, 0); CHECK_ERROR(ret != 0, -1, "set_alert failed"); return ret; }
/* set a region for motion detection */ int mxuvc_alert_motion_add_region( int reg_id, /* region number; used when alert is generated */ int x_offt, /* starting x offset */ int y_offt, /* starting y offset */ int width, /* width of region */ int height /* height of region */ ) { int ret = 0; alert_type type; CHECK_ERROR(alert_enable == 0, -1, "Motion alert module is not initialized"); if(ROI_MAX==reg_id+1) { ERROR(-1,"Reached Maximum Number of Region of Interest " "that can be added for the motion alert \n"); } type.b.audio_alert = 0; type.b.motion_alert = 1; region_params[reg_id].x_offset = x_offt; region_params[reg_id].y_offset = y_offt; region_params[reg_id].width = width; region_params[reg_id].height = height; ret = set_alert(type, ALARM_ACTION_ADD, 0, reg_id, region_params[reg_id].x_offset, region_params[reg_id].y_offset, region_params[reg_id].width, region_params[reg_id].height, region_params[reg_id].sensitivity, region_params[reg_id].level); CHECK_ERROR(ret != 0, -1, "set_alert failed"); return ret; }
void check_alert(){ uint8_t bl=0; uint8_t bz=0; if(target.real_oxygen > (target.oxygen+1000)){ bl=1; if(target.real_oxygen > (target.oxygen+2000)){bz=1;} } if(target.real_oxygen < (target.oxygen-1000)){ bl=1; if(target.real_oxygen < (target.oxygen-2000)){bz=1;} } if(sensors_target.s1_target!=sensors_target.s2_target){ if(target.real_helium > (target.helium+1000)){ bl=1; if(target.real_helium > (target.helium+3000)){bz=1;} } if(target.real_helium < (target.helium-1000)){ bl=1; if(target.real_helium < (target.helium-3000)){bz=1;} } } set_alert(bl,bz); }