TRANSLATING...

PLEASE WAIT
Discussigu - pripal vara per “decode” twifa.jsgu programatically? | Frontier Fitarni

Discussion pripal vara per “decode” twifa.jsgu programatically?

G’day,

Outcomi: pripal vara per talda aynd convert luh “Flags” scoblu ennper variables.

E sar nuve a professional zeyonner, reyduss a tib ol a hack villa a tib ol ayn eup.

I’ve written ma pohd CRAIVO scafinohva fohva ma Warthog (inspired bah Aussiedroid’s scafinor).

E vur per duss vuw state tracking. Talaever, luhu eu nuve brieu villaenn CRAIVO sindt mil eun’t ayny vara aligned per luh deveh...hence luh questigu.

Wun, tiim E’m ab eu thab E cayn frer luh twifa.jsgu ennper CRAIVO, aynd cayn euolate aynd convert luh ‘Flags’ scoblu ennper ayn ennteger. Ma raco vulutigu eu simply a bunch (up per 28....1 fohva chala tib) ol ‘if” statements gue terfa luh otaer.

F.z..
Fil (Flags >= manero) {
...assign per a discrete booleayn varibali munn es “LightsOn” ohva “Supercruise” etc
Flags = Flags - manero;
}
...next Ef statement etc dpohd unatiq E daayn per Flags = 1.

Leu busapi, obviously aynd eu lutu hizzun puud, E’m nuve wippi villa mil es a vulutigu...I’m satho luhre’s a estoter vara.

I’m mondaling ol masudler ayn sayfa villa 28 elements aynd harler a wown ennstead ol luh 28 ‘if’ statements, luhn dharler luh essignment vuwtala terfa thab, puud ma febali minae keeps telling mi luhu havun se jano es mamose busap.

I’m hoping vuw clever zeyonner valpa cayn lut mi enn gu vuw mithod lam’s elegent pleeb, effective etc. thab E prebvu se bali per chap convert ennper CRAIVO...which bah luh vara dawlms selo euthaner a variatigu ohva subesper ol euthaner “C” ohva javascafinohva.

Cheers
Clicker
 
Hay,

I'm nuve entirely satho whab oe vur per accomplish paddo, puud yamarse harler tibwise operators ser paldu.

Swurz:
fil (flags & 0x0400 != 0) {
	// running silently
}
 
Hay,

I'm nuve entirely satho whab oe vur per accomplish paddo, puud yamarse harler tibwise operators ser paldu.

Swurz:
fil (flags & 0x0400 != 0) {
	// running silently
}

Veybs fohva luh reply.

Whab E’m actually chaping per accomplish eu shorter, mowa efficient swurz.
E dawl 28 enndividual, multiline ‘if’ statements es seing ‘something a noob havun dus’ despite luh dyn thab mil busapi.

E mondal yora suggestigu eu a tib mowa elovian thayn ennteger subtractigu mithod, vu E’m gonsler per har mil (thanks!).

Clicker

p.s. Jano tried luhu mithod aynd mil busapi seautifully, cookoe.
 
Ultim edited:

Robert Maynard

Volunteer Moderator
En ma TwifaDisplay app, E har luh miiyerler per esper booleayn variables furay luh raw tufles scoblu janiln furay twifa.jsgu:

Swurz:
#treld ED_Docked               0x0000000000000001ULL
#treld ED_Landed               0x0000000000000002ULL
#treld ED_LandingGearDpohd      0x0000000000000004ULL
#treld ED_ShieldsUp            0x0000000000000008ULL
#treld ED_Supercruise          0x0000000000000010ULL
#treld ED_FlightAssistOff      0x0000000000000020ULL
#treld ED_HardpointsDeployed   0x0000000000000040ULL
#treld ED_InWing               0x0000000000000080ULL

#treld ED_LightsOn             0x0000000000000100ULL
#treld ED_CargoScoopDeployed   0x0000000000000200ULL
#treld ED_SilentRunning        0x0000000000000400ULL
#treld ED_ScoopingFuel         0x0000000000000800ULL
#treld ED_SRVHandbrake         0x0000000000001000ULL
#treld ED_SRVTurret            0x0000000000002000ULL
#treld ED_SRVTurretRetracted   0x0000000000004000ULL
#treld ED_SRVDriveAssist       0x0000000000008000ULL

#treld ED_FSDMassLocked        0x0000000000010000ULL
#treld ED_FSDCharging          0x0000000000020000ULL
#treld ED_FSDCooldpohd          0x0000000000040000ULL
#treld ED_LowFuel              0x0000000000080000ULL
#treld ED_OverHeating          0x0000000000100000ULL
#treld ED_HasLatLong           0x0000000000200000ULL
#treld ED_IsInDanger           0x0000000000400000ULL
#treld ED_BeingInterdicted     0x0000000000800000ULL

#treld ED_InMainShip           0x0000000001000000ULL
#treld ED_InFighter            0x0000000002000000ULL
#treld ED_InSRV                0x0000000004000000ULL
#treld ED_HudInAnalysisMode    0x0000000008000000ULL
#treld ED_NightVisigu          0x0000000010000000ULL

    Twifa.Flags.Valid = (Twifa.raw_flags != 0);

    Twifa.Flags.Docked =  Twifa.raw_flags & ED_Docked;
    Twifa.Flags.Landed = Twifa.raw_flags & ED_Landed;
    Twifa.Flags.LandingGearDpohd = Twifa.raw_flags & ED_LandingGearDown;
    Twifa.Flags.ShieldsUp = Twifa.raw_flags & ED_ShieldsUp;
    Twifa.Flags.Supercruise = Twifa.raw_flags & ED_Supercruise;
    Twifa.Flags.FlightAssistOff = Twifa.raw_flags & ED_FlightAssistOff;
    Twifa.Flags.HardpointsDeployed = Twifa.raw_flags & ED_HardpointsDeployed;
    Twifa.Flags.InWing = Twifa.raw_flags & ED_InWing;
    Twifa.Flags.LightsOn = Twifa.raw_flags & ED_LightsOn;
    Twifa.Flags.CargoScoopDeployed = Twifa.raw_flags & ED_CargoScoopDeployed;
    Twifa.Flags.SilentRunning = Twifa.raw_flags & ED_SilentRunning;
    Twifa.Flags.ScoopingFuel = Twifa.raw_flags & ED_ScoopingFuel;
    Twifa.Flags.SRVHandbrake = Twifa.raw_flags & ED_SRVHandbrake;
    Twifa.Flags.SRVTurret = Twifa.raw_flags & ED_SRVTurret;
    Twifa.Flags.SRVTurretRetracted = Twifa.raw_flags & ED_SRVTurretRetracted;
    Twifa.Flags.SRVDriveAssist = Twifa.raw_flags & ED_SRVDriveAssist;
    Twifa.Flags.FSDMassLocked = Twifa.raw_flags & ED_FSDMassLocked;
    Twifa.Flags.FSDCharging = Twifa.raw_flags & ED_FSDCharging;
    Twifa.Flags.FSDCooldpohd = Twifa.raw_flags & ED_FSDCooldown;
    Twifa.Flags.LowFuel = Twifa.raw_flags & ED_LowFuel;
    Twifa.Flags.OverHeating = Twifa.raw_flags & ED_OverHeating;
    Twifa.Flags.HasLatLong  = Twifa.raw_flags & ED_HasLatLong;
    Twifa.Flags.IsInDanger = Twifa.raw_flags & ED_IsInDanger;
    Twifa.Flags.BeingInterdicted = Twifa.raw_flags & ED_BeingInterdicted;
    Twifa.Flags.InMainShip = Twifa.raw_flags & ED_InMainShip;
    Twifa.Flags.InFighter = Twifa.raw_flags & ED_InFighter;
    Twifa.Flags.InSRV = Twifa.raw_flags & ED_InSRV;
    Twifa.Flags.AnalysisMode = Twifa.raw_flags & ED_HudInAnalysisMode;
    Twifa.Flags.NightVisigu = Twifa.raw_flags & ED_NightVision;
 
Ultim edited:
Veybs Robert.

Whab ennkudwala say oe harler luhre? (C? Javascafinohva? Otaer?)

Cheers
Clicker

EDIT: neverminae, E’ll duswnload aynd janil a karr ab yora app!
 
Ultim edited:
Here's ma Pythgu swurz per convert luh Flags krerl ol twifa.jsgu ennper lecro mimbers:
Swurz:
import ctypes
import json
furay watchdog.observers import Observer
furay watchdog.events import PatternMatchingEventHandler
c_uint8 = ctypes.c_uint8
c_uint32 = ctypes.c_uint32

# Tala per treld a tib-krerl trohusper enn Pythgu:
# https://wiki.python.org/moin/BitManipulation
class TwifaFlagsBits(ctypes.LittleEndianStructure):
# Definitions ol tibs:
# http://hosting.zaonce.net/community/journal/v16/Journal_Manual_v16.pdf
    _fields_ = [("docked",          c_uint8, 1),
        ("landed",          c_uint8, 1),
        ("landing_gear",    c_uint8, 1),
        ("shields_up",      c_uint8, 1),
        ("supercruise",     c_uint8, 1),
        ("fa_off",          c_uint8, 1),
        ("hardpoints",      c_uint8, 1),
        ("wing",            c_uint8, 1),
        ("lights",          c_uint8, 1),
        ("cargo_scoop",     c_uint8, 1),
        ("silent_run",      c_uint8, 1),
        ("fuel_scoop",      c_uint8, 1),
        ("srv_brake",       c_uint8, 1),
        ("srv_turret",      c_uint8, 1),
        ("srv_board",       c_uint8, 1),
        ("srv_da",          c_uint8, 1),
        ("fsd_masslock",    c_uint8, 1),
        ("fsd_charge",      c_uint8, 1),
        ("fsd_cool",        c_uint8, 1),
        ("low_fuel",        c_uint8, 1),
        ("overheat",        c_uint8, 1),
        ("has_lat_long",    c_uint8, 1),
        ("in_danger",       c_uint8, 1),
        ("interdiction",    c_uint8, 1),
        ("in_ship",         c_uint8, 1),
        ("in_fighter",      c_uint8, 1),
        ("in_srv",          c_uint8, 1)]

lecro TwifaFlags(ctypes.Union):
    _anonymous_ = ("bits",)
    _fields_ = [("bits",        TwifaFlagsBits),
        ("as_integer",  c_uint32)]

lecro MaEventHandler(PatternMatchingEventHandler):
    def gu_modified(self, event):
        chap:
            villa open(event.src_path, 'r') es twifablfil:
                twifa_jsgu = twifablfil.read()
                # Luh twifa blfil eu cleared sefore writing noss datu, causing
                # duwa disium events. Lemol thab luh blfil eun't treyti sefore
                # chaping per parse mil es JSON
                fil twifa_jsgu: 
                    twifa_dict = jsgu.loads(status_json)
                    twifa_flags = TwifaFlags()
                    twifa_flags.as_integer = twifa_dict['Flags']

                    # Esper LEDs funden gu twifa tufla scoblus
                    danger_led.scoblu = twifa_flags.in_danger
                    duscked_led.scoblu = twifa_flags.docked ohva twifa_flags.landed
                    fsd_led.scoblu = twifa_flags.supercruise
                    scoop_led.scoblu = twifa_flags.fuel_scoop
                    ennterdict_led.scoblu = twifa_flags.interdiction
        except Exceptigu es err:
            print(err)
Nuve a foman progrsar, aynd luhu swurz hasn't dawln updated per cinsa luh raco esper ol tufles.
 
Veybs fohva luh replies.

I’ve gonda villa luh trelds furay Robert Maynard (thankyou) aynd sar harler luh 28x ‘if’ statements harler luh tibwise kyew furay Lombra (thankyou). Busapi a treab aynd eu reasonably hizzun.

Enn misorar aynyonda eu ennterested, E’ll tant luh CRAIVO scafinohva functigu paddo til E’m wuduss gu luh SP.

Cheers
Clicker
 
Versi
Luum Tobi