ETP 516 How to create new packet between DRONA and OCURA

Revision for “ETP 516 How to create new packet between DRONA and OCURA” created on December 19, 2015 @ 20:28:36

Title
ETP 516 How to create new packet between DRONA and OCURA
Content
<h6>1. PURPOSE / DESCRIPTION</h6> 1.1 To add a new packet for the communication between Marc and OCURA. 1.2 In this document, the procedure is explained with an example of set motors. <h6>2. TEST SET-UP</h6> 2.1 OCURA board 2.2 DRONA 2.3 Understand the communication protocol between DRONA and OCURA. More details have been published on Vairdo Github. You can read the README of DRONA_firmware repository. (URL: <a href="https://github.com/Vairdo/DRONA_firmware/blob/master/README.md">https://github.com/Vairdo/DRONA_firmware/blob/master/README.md</a>) 2.4 Download source code: 2.4.1 Drona: <a href="https://github.com/Vairdo/DRONA_firmware">https://github.com/Vairdo/DRONA_firmware</a>, version: 816ee47 2.4.2 OCURA: Brainbox Application Apk. <h6>3. PROCEDURE</h6> <strong>3.1 DRONA</strong> 3.1.1 Select a new PID (one byte) for the new packet. 3.1.1.1 You can check the command list table for reference (which PIDs are using) on Github (URL: <a href="https://github.com/Vairdo/DRONA_firmware/blob/master/README.md">https://github.com/Vairdo/DRONA_firmware/blob/master/README.md</a>) 3.1.1.2 For the incoming packet (WiRa -&gt; DRONA), add that definition to SDCommands.h 3.1.1.3 For the outgoing packet (DRONA -&gt; WiRa), add that definition to SDPackets.h <img class="alignnone size-full wp-image-453" src="http://wiki.vairdo.com/wp-content/uploads/2015/11/pic9.png" alt="pic9" width="351" height="128" /> 3.1.2 Create a packet definition 3.1.2.1 For the incoming packet (WiRa -&gt; DRONA), add that definition to SDCommands.h 3.1.2.2 For the outgoing packet (DRONA -&gt; WiRa), add that definition to SDPackets.h <img class="alignnone size-full wp-image-455" src="http://wiki.vairdo.com/wp-content/uploads/2015/11/pic11.png" alt="pic11" width="407" height="241" /> 3.1.3 Add code to handle the packet to SDProtocol.c 3.1.3.1 For the incoming packet (WiRa -&gt; DRONA), add that definition to SDP_Process_Command() 3.1.3.2 The function uses CID (PID) to determine what should be done for current request by switch-case statement <img class="alignnone size-full wp-image-454" src="http://wiki.vairdo.com/wp-content/uploads/2015/11/pic10.png" alt="pic10" width="602" height="185" /> 3.1.3.3 If the command requires sending a packet back, there are several steps should be done: 3.1.3.3.1 Create a new element in TXstate enum in SDCommands.h <img class="alignnone size-full wp-image-456" src="http://wiki.vairdo.com/wp-content/uploads/2015/11/pic12.png" alt="pic12" width="283" height="195" /> 3.1.3.3.2 Update PacketState variable when processing the incoming command <img class="alignnone size-full wp-image-457" src="http://wiki.vairdo.com/wp-content/uploads/2015/11/pic13.png" alt="pic13" width="365" height="82" /> 3.1.3.3.3 In function SDP_Continue(), it will build the packet according the current PacketState. <img class="alignnone size-full wp-image-458" src="http://wiki.vairdo.com/wp-content/uploads/2015/11/pic14.png" alt="pic14" width="464" height="184" /> 3.1.3.3.4 Create a function to build the packet to send back to drone APP on WiRa. You can check SDP_Build_State_Packet() for reference. <strong>3.2 OCURA</strong> 3.2.1 Create a new class in lib/src/main/java/com/vairdo/dev/common/avionics/packets 3.2.1.1 Put the packet name as the class name (e.g. MotorControl) 3.2.1.2 The extends either Packet.Outgoing (Request to DRONA) or Packet.Incoming (Response from DRONA) 3.2.1.3 Specify a CID (an identifier for the packet), the used CIDs are listed in ETP-xxx. 3.2.1.4 Add the constructor for the class. Also set the parameters (e.g. float motorFL…) for this class. 3.2.1.5 Use put (short)/get (short) for outgoing/incoming packets, respectively. 3.2.1.6 Note that the packet folder is for packet transmission between DRONA and drone APP. It’s not the same as that mentioned in later section (TJPacket). <img class="alignnone size-full wp-image-445" src="http://wiki.vairdo.com/wp-content/uploads/2015/11/pic1.jpg" alt="pic1" width="630" height="324" /> 3.2.2 Create the same static packet class in a class container (\lib\src\main\java\com\vairdo\dev\common\communications\Packet.java) <a href="http://wiki.vairdo.com/wp-content/uploads/2015/11/pic2.png"><img class="alignnone size-full wp-image-446" src="http://wiki.vairdo.com/wp-content/uploads/2015/11/pic2.png" alt="pic2" width="631" height="281" /></a> 3.2.2.1 Remember to specify which interface is implemented (e.g. DroneReceivable or ClientReceivable) 3.2.2.2 If there is a data field, use the constructor to pass the data through calling super class (the case here is TJPacket) 3.2.2.3 Declare a proper callback function in callCallback. (it will be called when the packet is received by client or drone. More details of callback function will be discussed later.) 3.2.2.4 Define the access level in getPermissions (You can check more details in \lib\src\main\java\com\vairdo\dev\common\communications\SecurityManager.java) 3.2.3 Create a new method in lib/src/main/java/com/vairdo/dev/common/avionics/Avionics.java <img class="alignnone size-full wp-image-459" src="http://wiki.vairdo.com/wp-content/uploads/2015/11/pic15.png" alt="pic15" width="668" height="213" /> 3.2.3.1 You can add some check conditions before the command is exactly sent to drone APP (e.g. writeCommand…) 3.2.3.2 In writeCommand function, create a new constructor as the parameter. The function writeCommand is used for send an SPI packet to DRONA without getting any packet back. In addition to writeCommand(), there is another function writePacket() that can get a packet back from DRONA after sending a packet to DRONA. 3.2.3.3 The function setMotors is called by onMotorControlPacket() which is defined in drone\src\main\java\com\vairdo\dev\drone\MainService.java <img class="alignnone size-full wp-image-447" src="http://wiki.vairdo.com/wp-content/uploads/2015/11/pic3.png" alt="pic3" width="552" height="307" /> 3.2.5 Add the callback function to \lib\src\main\java\com\vairdo\dev\common\communications\Callbacks.java 3.2.5.1 For packet received by drone: interface: drone, abstract class DroneCallbackAdapter 3.2.5.2 For packet received by client: interface: client, abstract class ClientCallbackAdapter <a href="http://wiki.vairdo.com/wp-content/uploads/2015/11/pic4.png"><img class="alignnone size-full wp-image-448" src="http://wiki.vairdo.com/wp-content/uploads/2015/11/pic4.png" alt="pic4" width="502" height="176" /></a> <img class="alignnone wp-image-449 size-full" src="http://wiki.vairdo.com/wp-content/uploads/2015/11/pic5.png" alt="pic5" width="558" height="389" /> 3.2.6 There are two approaches to initiate a packet transmission 3.2.6.1 From client APP: 3.2.6.1.1 The send packet process can be triggered in some events. The example of motor control here send the packet via onControlChange event in client\src\main\java\com\vairdo\dev\client\views\VideoStreamFragment.java 3.2.6.1.2 In sendPacket, use the classes defined in Packet class to pass the packet content. 3.2.6.1.3 Then the corresponding callback function will be called. <img class="alignnone wp-image-450 size-full" src="http://wiki.vairdo.com/wp-content/uploads/2015/11/pic6.png" alt="pic6" width="450" height="180" /> 3.2.6.2 From drone APP: 3.2.6.2.1 If you just want to test the SPI transmission between DRONA and drone app, then you can just create a thread in drone APP, directly call the function <a href="http://wiki.vairdo.com/wp-content/uploads/2015/11/pic7.png"><img class="alignnone size-full wp-image-451" src="http://wiki.vairdo.com/wp-content/uploads/2015/11/pic7.png" alt="pic7" width="680" height="181" /></a> &nbsp;
Excerpt


OldNewDate CreatedAuthorActions
December 19, 2015 @ 20:28:36 admin
December 19, 2015 @ 20:28:27 [Autosave] admin
November 22, 2015 @ 05:20:42 admin
November 18, 2015 @ 15:04:00 Wanchen
November 18, 2015 @ 05:13:15 admin
November 17, 2015 @ 20:59:13 [Autosave] Wanchen
November 17, 2015 @ 20:59:04 Wanchen