Hey everyone,
Lately I’ve had a few requests for help from developers trying to get a connection up and running with the IF local API.
This is exciting since it means more add-ons are on the horizon! :-)
Best thing is to examine and learn from Cam’s awesome open source LiveFlight Connect (that’s how I learned back when I first wrote the first prototype of In-Flight Assistant):
As you can see, you will want to open a socket to localhost, port 10111 (if you’re going to be on the same device).
The key method is this one:
private void WriteObject<T>(T state) { var stateString = Serializer.SerializeJson(state); var data = UTF8Encoding.UTF8.GetBytes(stateString); byte[] size = BitConverter.GetBytes(data.Length); NetworkStream.Write(size, 0, size.Length); NetworkStream.Write(data, 0, data.Length); }
Note that you first need to send the LENGTH of the JSON’s content that you are trying to send. And THEN you send the JSON itself. The JSON depends on the command you are trying to send.
Note that you need to send the data in Little Endian format (the language you are writing in will have its own way of doing this). If you don’t know what that means, you’re perhaps not quite ready to be programming IF stuff yet (but maybe you can teach yourself!)…
Here’s the counterpart, the reading method:
private string ReadCommand() { var sizeToRead = ReadInt(); var buffer = new byte[sizeToRead]; var offset = 0; while (sizeToRead != 0) { var read = NetworkStream.Read(buffer, offset, sizeToRead); offset += read; sizeToRead -= read; } string str = Encoding.UTF8.GetString(buffer); return str; }
Pretty much the same thing just the other way around. The data will be coming in and you will need to parse it.
Any questions? Post them in here, that way everyone can see the answers. 🙂
Yep, there is, send the command “ListCommands” and you get the following list back:
Full command list: 105 commands
help: Show the help
listcommands: Lists all commands
airplane.getstate: Retrieves the full airplane state
airplane.getenginesstate: Retrieves the full airplane engines state
airplane.getfuelstate: Retrieves the full airplane engines state
airplane.getinfo: Retrieves the full airplane info
airplane.getlightsstate: Retrieves the full airplane lights state
airplane.setlightsstate: Set lights statestate
camera.virtualcockpit.setviewangle: Set the camera view angle (Radians)
camera.virtualcockpit.resetviewangle: Disabled the view angle override
va: Set the camera view angle (Radians) (Shortcut)
rv: Disabled the view angle override (Shortcut)
autopilot.getstate: Retrieves the AP State
infiniteflight.getstatus: Get the status of the application
networkjoystick.setaxisvalue: Lists all commands
networkjoystick.setbuttonstate: Lists all commands
networkjoystick.setpovstate: Lists all commands
networkjoystick.setnetworkjoystickaxes: Sets all the flight control axes to \"Network Joystick\".
live.getweather: Lists all commands
live.gettraffic: Lists all commands
live.atcfacilities: Lists all commands
live.getcurrentcomfrequencies: Lists all commands
live.tunetofrequency: Lists all commands
live.enableatcmessagelistupdated: Lists all commands
flightplan.get: Gets the Flight Plan Info
flightplan.load: Gets the Flight Plan Info
commands.elevatortrimup: Elevator Trim Up
commands.elevatortrimdown: Elevator Trim Down
commands.throttleupcommand: Throttle Up
commands.throttledowncommand: Throttle Down
commands.setcockpitcamera: Cockpit Camera
commands.setvirtualcockpitcameracommand: Virtual Cockpit Camera
commands.setfollowcameracommand: Follow Camera
commands.setflybycamera: Fly By Camera
commands.setonboardcameracommand: Onboard Camera
commands.settowercameracommand: Tower Camera
commands.nextcamera: Next Camera
commands.prevcamera: Previous Camera
commands.cameramoveleft: Move Camera Left
commands.cameramoveright: Move Camera Right
commands.cameramovedown: Move Camera Down
commands.cameramoveup: Move Camera Up
commands.cameramovehorizontal: Move Camera Left\/Right
commands.cameramovevertical: Move Camera Up\/Down
commands.camerazoomin: Zoom In
commands.camerazoomout: Zoom Out
commands.showatcwindowcommand: Toggle ATC Window
commands.atcentry1: Select ATC Entry 1
commands.atcentry2: Select ATC Entry 2
commands.atcentry3: Select ATC Entry 3
commands.atcentry4: Select ATC Entry 4
commands.atcentry5: Select ATC Entry 5
commands.atcentry6: Select ATC Entry 6
commands.atcentry7: Select ATC Entry 7
commands.atcentry8: Select ATC Entry 8
commands.atcentry9: Select ATC Entry 9
commands.atcentry10: Select ATC Entry 10
commands.live.setcomfrequencies: SetCOMFrequencies
commands.flightplan.addwaypoints:
commands.flightplan.clear:
commands.flightplan.activateleg:
commands.brakes: Brakes
commands.parkingbrakes: Parking Brakes
commands.flapsdown: Flaps Down (1 Step)
commands.flapsup: Flaps Up (1 Step)
commands.flapsfulldown: Flaps Down (Full)
commands.flapsfullup: Flaps Up (Full)
commands.aircraft.setflapstate:
commands.spoilers: Toggle Spoilers
commands.landinggear: Landing Gear
commands.pushback: Pushback
commands.fueldump: Fuel Dump
commands.reversethrust: ReverseThrust
commands.landinglights: Landing Lights
commands.taxilights: Taxi Lights
commands.strobelights: Strobes
commands.beaconlights: Beacon Lights
commands.navlights: Navigation Lights
commands.setlandinglightsstate:
commands.settaxilightsstate:
commands.setstrobelightsstate:
commands.setbeaconlightsstate:
commands.setnavlightsstate:
commands.autopilot.toggle: Engage\/Disengage Autopilot
commands.autopilot.setstate: SetState
commands.autopilot.setheading: SetHeading
commands.autopilot.setaltitude: SetAltitude
commands.autopilot.setvs: SetVS
commands.autopilot.setspeed: SetSpeed
commands.autopilot.setheadingstate: SetHeadingState
commands.autopilot.setaltitudestate: SetAltitudeState
commands.autopilot.setvsstate: SetVSState
commands.autopilot.setspeedstate: SetSpeedState
commands.autopilot.setapproachmodestate: SetApproachModeState
commands.togglehud: Toggle HUD
commands.togglepause: Pause
commands.start recording:
commands.stop recording:
commands.engine.start: Start Specified Engine
commands.engine.stop: Stop Specified Engine
a+: Increase altitude 1,000ft
a++: Increase altitude 10,000ft
recenter: Recenter World
fpl.add: Add Flight Plan Item
infiniteflight.state: Increase altitude 10,000ft