@sailboat-computer/health-monitoring
Version:
Comprehensive health monitoring system for sailboat computer v3 with marine-specific health checks
147 lines • 6.65 kB
JavaScript
;
/**
* GPS Recalibration Recovery Action
* Demonstrates a concrete implementation of a recovery action for GPS systems
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createGPSRecalibrationAction = exports.GPSRecalibrationAction = void 0;
const RecoveryAction_1 = require("../RecoveryAction");
const types_1 = require("../../types");
/**
* GPS Recalibration Action
* Attempts to recalibrate a GPS system that is reporting poor quality data
*/
class GPSRecalibrationAction extends RecoveryAction_1.BaseRecoveryAction {
constructor(config, gpsInterface) {
super(config);
this.gpsInterface = gpsInterface;
}
/**
* Perform GPS recalibration
*/
async performRecovery(triggeringCheck, operationalContext, marineEnvironment) {
const params = this.config.parameters;
const startTime = new Date();
const details = {};
const steps = [];
try {
// Step 1: Reset satellite tracking if configured
if (params.resetSatelliteTracking) {
steps.push('Resetting satellite tracking');
const resetResult = await this.gpsInterface.resetSatelliteTracking();
details['resetSatelliteTracking'] = resetResult;
if (!resetResult) {
return this.createRecoveryResult(startTime, new Date(), false, 'Failed to reset satellite tracking', steps, details, operationalContext, marineEnvironment);
}
}
// Step 2: Clear almanac if configured
if (params.clearAlmanac) {
steps.push('Clearing almanac data');
const clearResult = await this.gpsInterface.clearAlmanac();
details['clearAlmanac'] = clearResult;
if (!clearResult) {
return this.createRecoveryResult(startTime, new Date(), false, 'Failed to clear almanac data', steps, details, operationalContext, marineEnvironment);
}
}
// Step 3: Reset HDOP thresholds if configured
if (params.resetHDOPThresholds) {
steps.push('Resetting HDOP thresholds');
const resetResult = await this.gpsInterface.resetHDOPThresholds();
details['resetHDOPThresholds'] = resetResult;
if (!resetResult) {
return this.createRecoveryResult(startTime, new Date(), false, 'Failed to reset HDOP thresholds', steps, details, operationalContext, marineEnvironment);
}
}
// Step 4: Force cold start if configured
if (params.forceColdStart) {
steps.push('Forcing cold start');
const coldStartResult = await this.gpsInterface.forceColdStart();
details['forceColdStart'] = coldStartResult;
if (!coldStartResult) {
return this.createRecoveryResult(startTime, new Date(), false, 'Failed to force cold start', steps, details, operationalContext, marineEnvironment);
}
}
// Step 5: Wait for satellites
steps.push('Waiting for satellite acquisition');
const satelliteCount = await this.gpsInterface.waitForSatellites(params.satelliteAcquisitionTimeout);
details['satelliteCount'] = satelliteCount;
// Check if we acquired enough satellites
const success = satelliteCount >= 4; // Minimum for 3D fix
const message = success
? `GPS recalibration successful, acquired ${satelliteCount} satellites`
: `GPS recalibration failed, only acquired ${satelliteCount} satellites`;
return this.createRecoveryResult(startTime, new Date(), success, message, steps, details, operationalContext, marineEnvironment);
}
catch (error) {
return this.createRecoveryResult(startTime, new Date(), false, `GPS recalibration error: ${error.message}`, steps, details, operationalContext, marineEnvironment);
}
}
/**
* Create a recovery result
*/
createRecoveryResult(startTime, endTime, success, message, steps, details, operationalContext, marineEnvironment) {
return {
actionId: this.config.actionId,
name: this.config.name,
type: this.config.type,
status: success ? RecoveryAction_1.RecoveryStatus.SUCCEEDED : RecoveryAction_1.RecoveryStatus.FAILED,
message,
startTime,
endTime,
duration: endTime.getTime() - startTime.getTime(),
retryCount: this.retryCount,
success,
error: success ? '' : message,
details: {
...details,
steps,
completedSteps: steps.length
},
marineContext: {
operationalContext,
environmentalConditions: marineEnvironment ? { ...marineEnvironment } : undefined
},
triggeringCheck: undefined
};
}
}
exports.GPSRecalibrationAction = GPSRecalibrationAction;
/**
* Create a GPS recalibration action with default configuration
*/
function createGPSRecalibrationAction(gpsInterface, customConfig) {
const defaultConfig = {
actionId: 'gps-recalibration',
name: 'GPS Recalibration',
type: RecoveryAction_1.RecoveryActionType.RECALIBRATE,
marineSystemType: types_1.MarineSystemType.NAVIGATION,
priority: RecoveryAction_1.RecoveryPriority.HIGH,
timeout: 60000, // 60 seconds
maxRetries: 1,
retryDelay: 5000,
requiresApproval: false,
automatedExecution: true,
marineSettings: {
allowedContexts: [
types_1.OperationalContext.DOCKED,
types_1.OperationalContext.ANCHORED,
types_1.OperationalContext.SAILING,
types_1.OperationalContext.MOTORING
],
allowInRoughSeas: false,
powerAware: true,
safetyImpact: true,
powerConsumption: 2 // 2 watts
},
parameters: {
resetSatelliteTracking: true,
clearAlmanac: false,
resetHDOPThresholds: true,
forceColdStart: false,
satelliteAcquisitionTimeout: 30 // 30 seconds
}
};
return new GPSRecalibrationAction({ ...defaultConfig, ...customConfig }, gpsInterface);
}
exports.createGPSRecalibrationAction = createGPSRecalibrationAction;
//# sourceMappingURL=GPSRecalibrationAction.js.map