I messed up the merge, so pushing it over to another repo so I don't lose it. Will tidy up and remove later

Dependencies:   BufferedSerial FatFileSystemCpp mbed

Files at this revision

API Documentation at this revision

Comitter:
AndyA
Date:
Mon Oct 25 09:04:21 2021 +0000
Parent:
61:e734e86661b0
Child:
63:11ee40ec32bd
Commit message:
First pass at adding Arri FIZ support

Changed in this revision

FIZ_readers/FIZ_ArriCmotion.cpp Show annotated file Show diff for this revision Revisions of this file
FIZ_readers/FIZ_ArriCmotion.h Show annotated file Show diff for this revision Revisions of this file
LTCApp.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FIZ_readers/FIZ_ArriCmotion.cpp	Mon Oct 25 09:04:21 2021 +0000
@@ -0,0 +1,110 @@
+#include "FIZ_ArriCmotion.h"
+#include "LTCApp.h"
+
+FIZ_ArriCmotion::FIZ_ArriCmotion(const PinName Tx, const PinName Rx) : FIZReader(Tx,Rx)
+{
+    inputPtr = 0;
+    newData = false;
+    _port.baud(38400);
+    _port.attach(callback(this, &FIZ_ArriCmotion::OnRx));
+}
+
+//  expect hex data format:
+//  0x02 [commandID] [LEN] [len-5 bytes data] [checksum] [0x33]
+// checksum is xor of all data bytes.
+#define HeaderByte 0x02
+#define FooterByte 0x33
+
+// some ambiguity as to how large the packets should be
+#define packetSizeToSend 12
+
+void FIZ_ArriCmotion::requestCurrent(void)
+{
+    _port.putc(HeaderByte);
+    _port.putc('O'); 
+    _port.putc(packetSizeToSend);
+    // value of 0 for the first byte indicates client device with invalid data.
+    // So shouldn't move the motor, only read the values. 
+    // may possibly need to change this to 0x40 0x00 0x00 0x00 for each axis
+    // (master but invalid data)
+    for (int i=0;i<packetSizeToSend;i++)
+      _port.putc(0);
+    
+    // checksum - if all data is 0 then cs is 0. If data above changes then change this.
+    _port.putc(0);
+    
+    _port.putc(FooterByte);
+}
+
+
+void FIZ_ArriCmotion::OnRx(void)
+{
+    uint8_t dIn = _port.getc();
+    inputBuffer[inputPtr] = dIn;
+    if (inputPtr==0) {
+        if (dIn == HeaderByte) {
+            inputPtr++;
+        }
+    } else if (inputPtr == 1) {
+        if ((dIn == 'o')||(dIn == 'O')) { // ID 'o' = Motor status. or 'O' = motor command
+            inputPtr++;
+        } else { // wrong ID
+            if (dIn == HeaderByte) {
+                inputBuffer[0] = HeaderByte;
+                inputPtr = 1;
+            } else {
+                inputPtr = 0;
+            }
+        }
+    } else { // waiting for data.
+        if (inputPtr == 2) { // just got length
+            if (inputBuffer[2]>20) // length is too high
+                inputPtr=0;
+            else
+                inputPtr++;
+        } else {
+            inputPtr++;
+            if ((inputPtr>4) && (inputPtr == (inputBuffer[2]+5))) {
+                parsePacket();
+                inputPtr = 0;
+            }
+        }
+    }
+}
+
+void FIZ_ArriCmotion::parsePacket()
+{
+    if (inputBuffer[0] != HeaderByte)
+        return;
+    if (inputBuffer[1] != 'o') // only parse status
+        return;
+    int DataLen = inputBuffer[2];    
+    if (inputBuffer[DataLen+4] != FooterByte)
+        return;
+    int checksum = inputBuffer[DataLen+3];
+    uint8_t *dataValues = inputBuffer+3; // ptr to data part of message
+    // checksum is xor of all bytes.
+    int cs = 0;
+    for (int i=0; i<DataLen; i++) {
+        cs ^= dataValues[i];
+    }
+    if (cs != checksum) {
+//       pc.printf("FIZ Checksum Fail 0x%04X\r\n",cs);
+        return;
+    }
+
+// format is 2 bytes status then 16 bit value, MSB first.
+// This is repeated for Motor (focus?), iris and zoom
+    uint16_t focus_Position = ((uint16_t)dataValues[2])<<8 | inputBuffer[3];
+
+    uint16_t iris_Position = ((uint16_t)inputBuffer[6])<<8 | inputBuffer[7];
+
+    uint16_t zoom_Position = ((uint16_t)inputBuffer[10])<<8 | inputBuffer[11];
+
+// MAY NEED TO SCALE THESE
+    _focus = focus_Position;
+    _iris = iris_Position;
+    _zoom = zoom_Position;
+
+    newData = true;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FIZ_readers/FIZ_ArriCmotion.h	Mon Oct 25 09:04:21 2021 +0000
@@ -0,0 +1,25 @@
+#ifndef __FIZArriCM_H__
+#define __FIZArriCM_H__
+#include "FIZReader.h"
+
+//FIZ protocol used for Arri C motion systems
+// this is listen only.
+
+class FIZ_ArriCmotion : public FIZReader {
+
+public:
+  FIZ_ArriCmotion(const PinName Tx, const PinName Rx);
+  virtual void requestCurrent();
+  
+  private:
+  static const int InBufferSize = 32;
+  
+  void OnRx(void);
+  void parsePacket();
+  
+  uint8_t inputBuffer[InBufferSize];
+  int inputPtr;
+  };
+
+
+#endif
\ No newline at end of file
--- a/LTCApp.h	Tue Oct 12 10:47:45 2021 +0000
+++ b/LTCApp.h	Mon Oct 25 09:04:21 2021 +0000
@@ -10,6 +10,7 @@
 #include "FIZ_digiPower.h"
 #include "FIZDigiPowerActive.h"
 #include "FIZCanon.h"
+#include "FIZ_ArriCmotion.h"
 #include "frameclock.h"
 #include "FreeD.h"
 #include <stdint.h>
--- a/main.cpp	Tue Oct 12 10:47:45 2021 +0000
+++ b/main.cpp	Mon Oct 25 09:04:21 2021 +0000
@@ -20,6 +20,7 @@
     n = 1 - Fuji passive listen mode (skycam)
     n = 2 - Fuji active mode
     n = 3 - Canon
+    n = 4 - Arri
 
 FreeD_Port=pppp
     Sets the UDP port for FreeD network output.
@@ -169,7 +170,7 @@
 bool ppmCorrection;
 
 enum SerialOutput {mode_VIPS, mode_FreeD};
-enum FIZFormats {formatPreston, formatFujiPassive, formatFujiActive, formatCanon};
+enum FIZFormats {formatPreston, formatFujiPassive, formatFujiActive, formatCanon, formatArri};
 
 UserSettings_t UserSettings;
 
@@ -991,9 +992,14 @@
             FIZPort = new FIZCanon(p9, p10);
             pc.printf("Set Canon\r\n");
             break;
+case formatArri:
+            FIZPort = new FIZ_ArriCmotion(p9, p10);
+            pc.printf("Set Arri\r\n");
+            break;
         default:
             FIZPort = new FIZDisney(p9, p10); //preston
             pc.printf("Set Default - Preston");
+
     }
 //    FIZPort = new FIZDigiPowerActive(p9, p10);
     COM1.baud(115200); // radio port