Hello Lego,
I do not use UDP , but TCP, and this is coded in python but maybe this can help u
1st my Generic Protocol File , for example :
- Code: Select all
<?xml version="1.0"?>
<PropertyList>
<generic>
<input>
<binary_mode>false</binary_mode>
<line_separator>newline</line_separator>
<var_separator>:</var_separator>
<chunk>
<name>On Off RMP Switch</name>
<node>/controls/radio/rmp[0]/on</node>
<type>integer</type>
</chunk>
<chunk>
<name>Channel Selection</name>
<node>/systems/radio/rmp[0]/sel_chan</node>
<type>string</type>
</chunk>
</input>
</generic>
</PropertyList>
My Python Code :
Opening, a connection to FG with
FGADDR : host where FG is executed
FGPORT : fgport listening
- Code: Select all
sockclient = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sockclient.connect((FGADDR, FGPORT))
<Code to manage Input / Ouput>
.....
Then Creating the "datastring" to be sent
- Code: Select all
datastr = str(data_tree['rmp0psw'])
datastr = datastr + ':' + str(data_tree['rmp0selchan'])
Then sending to FG ... if (and only if) something have change
- Code: Select all
cypher = hashlib.md5(datastr.encode('utf-8')).digest()
if cypher != oldcypher:
#print("DATA : {} | PROPS : {}".format(datastr, props_tree)) <=== Only to debug
sockclient.send(bytes(datastr, 'utf-8'))
sockclient.send(bytes("\n", 'utf8')) <== Don't forget to sent "end line" define in your generic protocol file
oldcypher = cypher <== oldcypher is init to '' when starting the loop
I ll post later how FG is startup (option to open listening connexion), i don't have acces to my FG computer a this time