1. PURPOSE / DESCRIPTION
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.
2. TEST SET-UP
2.1 OCURA board
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: https://github.com/Vairdo/DRONA_firmware/blob/master/README.md)
2.4 Download source code:
2.4.1 Drona: https://github.com/Vairdo/DRONA_firmware, version: 816ee47
2.4.2 OCURA: Brainbox Application Apk.
3.1.1 Select a new PID (one byte) for the new packet.
22.214.171.124 You can check the command list table for reference (which PIDs are using) on Github
126.96.36.199 For the incoming packet (WiRa -> DRONA), add that definition to SDCommands.h
188.8.131.52 For the outgoing packet (DRONA -> WiRa), add that definition to SDPackets.h
3.1.2 Create a packet definition
184.108.40.206 For the incoming packet (WiRa -> DRONA), add that definition to SDCommands.h
220.127.116.11 For the outgoing packet (DRONA -> WiRa), add that definition to SDPackets.h
3.1.3 Add code to handle the packet to SDProtocol.c
18.104.22.168 For the incoming packet (WiRa -> DRONA), add that definition to SDP_Process_Command()
22.214.171.124 The function uses CID (PID) to determine what should be done for current request by switch-case statement
126.96.36.199 If the command requires sending a packet back, there are several steps should be done:
188.8.131.52.1 Create a new element in TXstate enum in SDCommands.h
184.108.40.206.2 Update PacketState variable when processing the incoming command
220.127.116.11.3 In function SDP_Continue(), it will build the packet according the current PacketState.
18.104.22.168.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.
3.2.1 Create a new class in lib/src/main/java/com/vairdo/dev/common/avionics/packets
22.214.171.124 Put the packet name as the class name (e.g. MotorControl)
126.96.36.199 The extends either Packet.Outgoing (Request to DRONA) or Packet.Incoming (Response from DRONA)
188.8.131.52 Specify a CID (an identifier for the packet), the used CIDs are listed in ETP-xxx.
184.108.40.206 Add the constructor for the class. Also set the parameters (e.g. float motorFL…) for this class.
220.127.116.11 Use put (short)/get (short) for outgoing/incoming packets, respectively.
18.104.22.168 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).
3.2.2 Create the same static packet class in a class container (\lib\src\main\java\com\vairdo\dev\common\communications\Packet.java)
22.214.171.124 Remember to specify which interface is implemented (e.g. DroneReceivable or ClientReceivable)
126.96.36.199 If there is a data field, use the constructor to pass the data through calling super class (the case here is TJPacket)
188.8.131.52 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.)
184.108.40.206 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
220.127.116.11 You can add some check conditions before the command is exactly sent to drone APP (e.g. writeCommand…)
18.104.22.168 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.
22.214.171.124 The function setMotors is called by onMotorControlPacket() which is defined in drone\src\main\java\com\vairdo\dev\drone\MainService.java
3.2.5 Add the callback function to \lib\src\main\java\com\vairdo\dev\common\communications\Callbacks.java
126.96.36.199 For packet received by drone: interface: drone, abstract class DroneCallbackAdapter
188.8.131.52 For packet received by client: interface: client, abstract class ClientCallbackAdapter
3.2.6 There are two approaches to initiate a packet transmission
184.108.40.206 From client APP:
220.127.116.11.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
18.104.22.168.2 In sendPacket, use the classes defined in Packet class to pass the packet content.
22.214.171.124.3 Then the corresponding callback function will be called.
126.96.36.199 From drone APP:
188.8.131.52.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