1"use strict";(self.webpackChunkphpvms_docs=self.webpackChunkphpvms_docs||[]).push([[459],{15508(e,n,s){s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>r,metadata:()=>i,toc:()=>o});const i=JSON.parse('{"id":"acars/plugins/callbacks","title":"Callback Scripts","description":"Callback scripts","source":"@site/versioned_docs/version-v7.x/acars/plugins/callbacks.md","sourceDirName":"acars/plugins","slug":"/acars/plugins/callbacks","permalink":"/acars/plugins/callbacks","draft":false,"unlisted":false,"editUrl":"https://github.com/phpvms/docs/tree/master/versioned_docs/version-v7.x/acars/plugins/callbacks.md","tags":[],"version":"v7.x","frontMatter":{"id":"callbacks","title":"Callback Scripts"},"sidebar":"docs","previous":{"title":"Custom Rules","permalink":"/acars/plugins/rules"},"next":{"title":"Tutorial","permalink":"/acars/plugins/tutorial"}}');var t=s(74848),a=s(28453);const r={id:"callbacks",title:"Callback Scripts"},l=void 0,c={},o=[{value:"Callback scripts",id:"callback-scripts",level:2},{value:"Core Methods",id:"core-methods",level:2},{value:"1. <code>setup()</code>",id:"1-setup",level:3},{value:"Purpose",id:"purpose",level:4},{value:"When It Runs",id:"when-it-runs",level:4},{value:"Example Use Cases",id:"example-use-cases",level:4},{value:"Example",id:"example",level:4},{value:"2. <code>run()</code>",id:"2-run",level:3},{value:"Purpose",id:"purpose-1",level:4},{value:"When It Runs",id:"when-it-runs-1",level:4},{value:"Parameters",id:"parameters",level:4},{value:"Example Use Cases",id:"example-use-cases-1",level:4},{value:"Purpose",id:"purpose-2",level:4},{value:"When It Runs",id:"when-it-runs-2",level:4},{value:"Parameters",id:"parameters-1",level:4},{value:"Example Use Cases",id:"example-use-cases-2",level:4},{value:"Notes",id:"notes",level:4},{value:"Example",id:"example-1",level:4},{value:"Implementing Your Own Script",id:"implementing-your-own-script",level:2},{value:"Sounds",id:"sounds",level:3}];function d(e){const n={code:"code",h2:"h2",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.h2,{id:"callback-scripts",children:"Callback scripts"}),"\n",(0,t.jsx)(n.p,{children:"The CallbackHook interface provides a framework for creating scripts that\ninteract with the ACARS system. There are three core methods that every script\nimplementing this interface must provide."}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",metastring:"file=example.ts",children:"import {PirepState} from '../defs';\nimport {CallbackHook, Meta} from '../types/callback';\nimport {Pirep, Telemetry} from '../types/types';\n\n/**\n * This is an example script. It's not very useful, but it's a good example of\n * how to write a script and some of the functionality.\n */\nexport default class ExampleScript implements CallbackHook {\n meta: Meta = {\n id: 'example_script',\n name: 'Example Script',\n enabled: false,\n };\n\n setup() {\n Acars.Set('above_1k', false);\n Acars.Set('launched_message', false);\n }\n\n /**\n * This once a second.\n * @param pirep\n * @param data\n */\n run(pirep: Pirep, data: Telemetry): void {\n Acars.SetPirepField('Loaded', 'True');\n Acars.AddPirepLogOnce('loaded_msg', 'Example script loaded');\n\n // Example of setting a flag to check later on\n if (data.groundAltitude.Feet > 1000) {\n Acars.Set('above_1k', true);\n Acars.SetPirepField('Above 1000 feet', 'True');\n }\n\n /*\n * Just a silly example, if they crossed above 1000 feet and then they went\n * back below it, send a message about that\n */\n if (Acars.Get('above_1k') === true && data.groundAltitude.Feet < 1000) {\n Acars.AddPirepLog(\"Went above 1000', now back down\");\n }\n }\n\n /**\n * Called on phase changes\n */\n phaseChange(\n pirep: Pirep,\n data: Telemetry,\n newPhase: PirepState,\n oldPhase: PirepState,\n ) {\n Acars.AddPirepLog(`Phase changed from ${oldPhase} to ${newPhase}`);\n\n if (newPhase == PirepState.Pushback) {\n Acars.PlayAudio('departure.mp3');\n }\n }\n}\n"})}),"\n",(0,t.jsx)(n.h2,{id:"core-methods",children:"Core Methods"}),"\n",(0,t.jsxs)(n.h3,{id:"1-setup",children:["1. ",(0,t.jsx)(n.code,{children:"setup()"})]}),"\n",(0,t.jsx)(n.h4,{id:"purpose",children:"Purpose"}),"\n",(0,t.jsx)(n.p,{children:"The method is called once when your script is initially loaded. This is the\nideal place to initialize any variables, state, or settings that your script\nwill use."}),"\n",(0,t.jsx)(n.h4,{id:"when-it-runs",children:"When It Runs"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:"Executes exactly once at script initialization"}),"\n",(0,t.jsx)(n.li,{children:"Runs before any other methods in your script"}),"\n"]}),"\n",(0,t.jsx)(n.h4,{id:"example-use-cases",children:"Example Use Cases"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:["Setting initial state values using ",(0,t.jsx)(n.code,{children:"Acars.Set()"})]}),"\n",(0,t.jsx)(n.li,{children:"Initializing flags or counters"}),"\n",(0,t.jsx)(n.li,{children:"Setting up any pre-conditions required by your script"}),"\n"]}),"\n",(0,t.jsx)(n.h4,{id:"example",children:"Example"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"setup();
1\n{\n Acars.Set('above_1k', false);\n Acars.Set('launched_message', false);\n}\n"})}),"\n",(0,t.jsxs)(n.h3,{id:"2-run",children:["2. ",(0,t.jsx)(n.code,{children:"run()"})]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"run(pirep\n:\nPirep, data\n:\nTelemetry, previousData ? : Telemetry\n):\nvoid\n"})}),"\n",(0,t.jsx)(n.h4,{id:"purpose-1",children:"Purpose"}),"\n",(0,t.jsxs)(n.p,{children:["The ",(0,t.jsx)(n.code,{children:"run()"})," method is the heart of your script's functionality. It executes at\nregular intervals, allowing you to continuously monitor flight conditions and\nperform actions based on that data."]}),"\n",(0,t.jsx)(n.h4,{id:"when-it-runs-1",children:"When It Runs"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:"Executes approximately every 500ms (twice per second)"}),"\n",(0,t.jsx)(n.li,{children:"Continues to run throughout the duration of the flight"}),"\n"]}),"\n",(0,t.jsx)(n.h4,{id:"parameters",children:"Parameters"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[": Contains information about the current Pilot Report ",(0,t.jsx)(n.code,{children:"pirep"})]}),"\n",(0,t.jsxs)(n.li,{children:[": Contains the current telemetry data including altitude, speed, position,\netc. ",(0,t.jsx)(n.code,{children:"data"})]}),"\n",(0,t.jsxs)(n.li,{children:["(optional): Contains telemetry data from the previous execution ",(0,t.jsx)(n.code,{children:"previousData"})]}),"\n"]}),"\n",(0,t.jsx)(n.h4,{id:"example-use-cases-1",children:"Example Use Cases"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:"Monitoring altitude, speed, or position changes"}),"\n",(0,t.jsx)(n.li,{children:"Triggering events based on specific flight conditions"}),"\n",(0,t.jsx)(n.li,{children:"Updating flight logs"}),"\n",(0,t.jsx)(n.li,{children:"Playing audio cues at appropriate times"}),"\n"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{children:"### 3. `phaseChange()`\n``` typescript\nphaseChange(pirep: Pirep, data: Telemetry, newPhase: PirepState, oldPhase: PirepState): void\n"})}),"\n",(0,t.jsx)(n.h4,{id:"purpose-2",children:"Purpose"}),"\n",(0,t.jsxs)(n.p,{children:["The ",(0,t.jsx)(n.code,{children:"phaseChange()"})," method is triggered whenever the flight transitions between\ndifferent operational phases (such as boarding, taxiing, in-flight, approach,\netc.)."]}),"\n",(0,t.jsx)(n.h4,{id:"when-it-runs-2",children:"When It Runs"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:"Executes whenever the flight phase/state changes"}),"\n",(0,t.jsx)(n.li,{children:"May run multiple times during a flight, but only at phase transition points"}),"\n"]}),"\n",(0,t.jsx)(n.h4,{id:"parameters-1",children:"Parameters"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[": Contains information about the current Pilot Report ",(0,t.jsx)(n.code,{children:"pirep"})]}),"\n",(0,t.jsxs)(n.li,{children:[": Contains the current telemetry data at the moment of phase change ",(0,t.jsx)(n.code,{children:"data"})]}),"\n",(0,t.jsxs)(n.li,{children:[": The PirepState being transitioned to ",(0,t.jsx)(n.code,{children:"newPhase"})]}),"\n",(0,t.jsxs)(n.li,{children:[": The PirepState being transitioned from ",(0,t.jsx)(n.code,{children:"oldPhase"})]}),"\n"]}),"\n",(0,t.jsx)(n.h4,{id:"example-use-cases-2",children:"Example Use Cases"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:"Logging phase transitions"}),"\n",(0,t.jsx)(n.li,{children:"Playing specific audio for different flight phases"}),"\n",(0,t.jsx)(n.li,{children:"Performing checks or verification at critical flight stages"}),"\n",(0,t.jsx)(n.li,{children:"Triggering phase-specific behaviors or requirements"}),"\n"]}),"\n",(0,t.jsx)(n.h4,{id:"notes",children:"Notes"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:"Don't call any timer functions here, they won't properly trigger"}),"\n"]}),"\n",(0,t.jsx)(n.h4,{id:"example-1",children:"Example"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"phaseChange(pirep\n:\nPirep, data\n:\nTelemetry, newPhase\n:\nPirepState, oldPhase\n:\nPirepState\n)\n{\n Ac
1ars.AddPirepLog(`Phase changed from ${oldPhase} to ${newPhase}`)\n\n if (newPhase === PirepState.TaxiOut) {\n Acars.PlayAudio('departure.mp3')\n }\n\n if (newPhase === PirepState.Enroute) {\n Acars.SetPirepField('Reached Cruise', 'True')\n }\n}\n"})}),"\n",(0,t.jsx)(n.h2,{id:"implementing-your-own-script",children:"Implementing Your Own Script"}),"\n",(0,t.jsxs)(n.p,{children:["To create your own script, implement all three methods of the CallbackHook\ninterface, and don't forget to define the required property with a unique ID and\nname for your script in the ",(0,t.jsx)(n.code,{children:"meta"})," block"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"export default class MyScript implements CallbackHook {\n meta: Meta = {\n id: 'my_unique_script_id',\n name: 'My Script Name',\n enabled: true,\n };\n\n setup() {\n // Initialize your script\n }\n\n run(pirep: Pirep, data: Telemetry, previousData?: Telemetry) {\n // Regular processing\n }\n\n phaseChange(\n pirep: Pirep,\n data: Telemetry,\n newPhase: PirepState,\n oldPhase: PirepState,\n ) {\n // Handle phase transitions\n }\n}\n"})}),"\n",(0,t.jsx)(n.h3,{id:"sounds",children:"Sounds"}),"\n",(0,t.jsxs)(n.p,{children:["Place your sounds, in mp3, 44100hz stereo format in the ",(0,t.jsx)(n.code,{children:"src/sounds"})," directory (\ncreate it if it doesn't exist). When you call ",(0,t.jsx)(n.code,{children:"Acars.PlayAudio"}),", it will look in\nthis directory for them."]})]})}function p(e={}){const{wrapper:n}={...(0,a.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},28453(e,n,s){s.d(n,{R:()=>r,x:()=>l});var i=s(96540);const t={},a=i.createContext(t);function r(e){const n=i.useContext(a);return i.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:r(e.components),i.createElement(a.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.