Recieve data throu usb or serial from pi instead of PWM, APM2.8


it is much information to understand the code without a schematic of all the code.
I wrote a program to send data with USB Wificards like a RC, with an linux PC as RX and TX.

Because of this i dont need the telemetry and normal RC remotecontroller. The next step is to connect the APM 2.8 via usb or serial to my pi, but i must replace all the PWM input with my reading routine for the digital data, like throttle or which flight mode ist anabled.
But where to start? Is the only function i must replace, the “rc_loop()” ?

Greetings, Rarebit.