Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BufferedSerial FatFileSystemCpp mbed
FIZ_readers/FIZCanon.cpp@66:066b16c6c34f, 2021-11-16 (annotated)
- Committer:
- JamieB
- Date:
- Tue Nov 16 19:01:34 2021 +0000
- Revision:
- 66:066b16c6c34f
- Parent:
- 39:3cd9e498b5c6
Changed Buffered Serial to Read Raw Serial in RX Interrupt
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| JamieB | 29:b0eaeefa4e63 | 1 | #include "FIZCanon.h" |
| JamieB | 29:b0eaeefa4e63 | 2 | #include "LTCApp.h" |
| JamieB | 29:b0eaeefa4e63 | 3 | FIZCanon::FIZCanon(const PinName Tx, const PinName Rx) : FIZReader(Tx,Rx) |
| JamieB | 29:b0eaeefa4e63 | 4 | { |
| JamieB | 29:b0eaeefa4e63 | 5 | inputPtr = 0; |
| JamieB | 29:b0eaeefa4e63 | 6 | newData = false; |
| JamieB | 29:b0eaeefa4e63 | 7 | _port.baud(19200); |
| JamieB | 29:b0eaeefa4e63 | 8 | _port.format(8, SerialBase::Even, 1); |
| JamieB | 29:b0eaeefa4e63 | 9 | _port.attach(callback(this, &FIZCanon::OnRx)); |
| JamieB | 29:b0eaeefa4e63 | 10 | missedPackets=0; |
| JamieB | 29:b0eaeefa4e63 | 11 | |
| JamieB | 29:b0eaeefa4e63 | 12 | } |
| JamieB | 29:b0eaeefa4e63 | 13 | |
| JamieB | 29:b0eaeefa4e63 | 14 | void FIZCanon::requestCurrent(void) |
| JamieB | 29:b0eaeefa4e63 | 15 | { |
| JamieB | 29:b0eaeefa4e63 | 16 | if (missedPackets>5) { |
| JamieB | 29:b0eaeefa4e63 | 17 | // configure output format |
| JamieB | 29:b0eaeefa4e63 | 18 | _port.putc(0x80); |
| JamieB | 29:b0eaeefa4e63 | 19 | _port.putc(0xC6); |
| JamieB | 29:b0eaeefa4e63 | 20 | _port.putc(0xBF); |
| JamieB | 29:b0eaeefa4e63 | 21 | // pc.printf("W"); |
| JamieB | 29:b0eaeefa4e63 | 22 | missedPackets = 0; |
| JamieB | 29:b0eaeefa4e63 | 23 | } |
| JamieB | 29:b0eaeefa4e63 | 24 | |
| JamieB | 29:b0eaeefa4e63 | 25 | _port.putc(0x94); |
| JamieB | 29:b0eaeefa4e63 | 26 | _port.putc(0xC1); |
| JamieB | 29:b0eaeefa4e63 | 27 | _port.putc(0xBF); |
| JamieB | 29:b0eaeefa4e63 | 28 | _port.putc(0x94); |
| JamieB | 29:b0eaeefa4e63 | 29 | _port.putc(0xC3); |
| JamieB | 29:b0eaeefa4e63 | 30 | _port.putc(0xBF); |
| JamieB | 29:b0eaeefa4e63 | 31 | _port.putc(0x94); |
| JamieB | 29:b0eaeefa4e63 | 32 | _port.putc(0xC5); |
| JamieB | 29:b0eaeefa4e63 | 33 | _port.putc(0xBF); |
| JamieB | 29:b0eaeefa4e63 | 34 | missedPackets++; |
| JamieB | 29:b0eaeefa4e63 | 35 | // pc.printf("T"); |
| JamieB | 29:b0eaeefa4e63 | 36 | } |
| JamieB | 29:b0eaeefa4e63 | 37 | |
| JamieB | 29:b0eaeefa4e63 | 38 | // expect hex data format: |
| JamieB | 29:b0eaeefa4e63 | 39 | // [dat len] [command] [data] [cs] |
| JamieB | 29:b0eaeefa4e63 | 40 | // only command we care about is multi reply which is 7 bytes of data - zoom, focus, iris, switch 4 |
| JamieB | 29:b0eaeefa4e63 | 41 | // 07 60 [zoom1][zoom2] .... [cs] |
| JamieB | 29:b0eaeefa4e63 | 42 | void FIZCanon::OnRx(void) |
| JamieB | 29:b0eaeefa4e63 | 43 | { |
| JamieB | 29:b0eaeefa4e63 | 44 | uint8_t dIn = _port.getc(); |
| JamieB | 29:b0eaeefa4e63 | 45 | // pc.putc('R'); |
| JamieB | 29:b0eaeefa4e63 | 46 | inputBuffer[inputPtr] = dIn; |
| JamieB | 29:b0eaeefa4e63 | 47 | if (inputPtr==0) { |
| JamieB | 29:b0eaeefa4e63 | 48 | if (dIn == 0x94) { // correct length |
| JamieB | 29:b0eaeefa4e63 | 49 | inputPtr++; |
| JamieB | 29:b0eaeefa4e63 | 50 | } |
| JamieB | 29:b0eaeefa4e63 | 51 | } else if (inputPtr > 30) { |
| JamieB | 29:b0eaeefa4e63 | 52 | inputPtr = 0; |
| JamieB | 29:b0eaeefa4e63 | 53 | } else { // waiting for data. |
| JamieB | 29:b0eaeefa4e63 | 54 | inputPtr++; |
| JamieB | 29:b0eaeefa4e63 | 55 | if (inputPtr == (18) && dIn == 0xBF) { // full packet = 2 byte header, 7 byte data, 1 byte cs |
| JamieB | 29:b0eaeefa4e63 | 56 | parsePacket(); |
| JamieB | 29:b0eaeefa4e63 | 57 | inputPtr = 0; |
| JamieB | 29:b0eaeefa4e63 | 58 | if (missedPackets) |
| JamieB | 29:b0eaeefa4e63 | 59 | missedPackets--; |
| JamieB | 29:b0eaeefa4e63 | 60 | } |
| JamieB | 29:b0eaeefa4e63 | 61 | } |
| JamieB | 29:b0eaeefa4e63 | 62 | } |
| JamieB | 29:b0eaeefa4e63 | 63 | |
| JamieB | 29:b0eaeefa4e63 | 64 | void FIZCanon::parsePacket() |
| JamieB | 29:b0eaeefa4e63 | 65 | { |
| JamieB | 39:3cd9e498b5c6 | 66 | // pc.puts("FIZ parse\r\n"); |
| JamieB | 39:3cd9e498b5c6 | 67 | // pc.putc('P'); |
| JamieB | 30:87810cae96ac | 68 | int read_pos = 0; |
| JamieB | 31:2eec69c777a7 | 69 | bool valid = false; |
| JamieB | 29:b0eaeefa4e63 | 70 | |
| JamieB | 30:87810cae96ac | 71 | while (read_pos != inputPtr) { |
| JamieB | 39:3cd9e498b5c6 | 72 | if (!valid) { |
| JamieB | 39:3cd9e498b5c6 | 73 | if (inputBuffer[read_pos] == CANON_START) { |
| JamieB | 31:2eec69c777a7 | 74 | valid = true; |
| JamieB | 39:3cd9e498b5c6 | 75 | } |
| JamieB | 39:3cd9e498b5c6 | 76 | } else { |
| JamieB | 39:3cd9e498b5c6 | 77 | switch(inputBuffer[read_pos]) { |
| JamieB | 39:3cd9e498b5c6 | 78 | case CANON_ZOOM: |
| JamieB | 39:3cd9e498b5c6 | 79 | // pc.putc('Z'); |
| JamieB | 39:3cd9e498b5c6 | 80 | _zoom = (((uint32_t)inputBuffer[read_pos+1])<<14 | inputBuffer[read_pos +2]<<7 | inputBuffer[read_pos +3])/60; |
| JamieB | 30:87810cae96ac | 81 | // pc.putc(0x01); |
| JamieB | 30:87810cae96ac | 82 | // pc.putc(inputBuffer[read_pos+1]); |
| JamieB | 30:87810cae96ac | 83 | // pc.putc(inputBuffer[read_pos+2]); |
| JamieB | 30:87810cae96ac | 84 | // pc.putc(inputBuffer[read_pos+3]); |
| JamieB | 39:3cd9e498b5c6 | 85 | read_pos += 4; // type + 3 BYTES OF DATA |
| JamieB | 39:3cd9e498b5c6 | 86 | break; |
| JamieB | 39:3cd9e498b5c6 | 87 | case CANON_FOCUS: |
| JamieB | 39:3cd9e498b5c6 | 88 | // pc.putc('F'); |
| JamieB | 39:3cd9e498b5c6 | 89 | _focus = 1000 - (((uint32_t)inputBuffer[read_pos+1])<<14 | inputBuffer[read_pos +2]<<7 | inputBuffer[read_pos +3])/60; |
| JamieB | 30:87810cae96ac | 90 | // pc.putc(0x02); |
| JamieB | 30:87810cae96ac | 91 | // pc.putc(inputBuffer[read_pos+1]); |
| JamieB | 30:87810cae96ac | 92 | // pc.putc(inputBuffer[read_pos+2]); |
| JamieB | 30:87810cae96ac | 93 | // pc.putc(inputBuffer[read_pos+3]); |
| JamieB | 39:3cd9e498b5c6 | 94 | read_pos += 4; |
| JamieB | 39:3cd9e498b5c6 | 95 | break; |
| JamieB | 39:3cd9e498b5c6 | 96 | case CANON_IRIS: |
| JamieB | 39:3cd9e498b5c6 | 97 | //IRIS NOT SCALED CORRECTLY -> 0x8000 - 0xD000, 0x1000 between FStops -> Fix Later |
| JamieB | 39:3cd9e498b5c6 | 98 | // pc.putc('I'); |
| JamieB | 31:2eec69c777a7 | 99 | _iris = (((uint32_t)inputBuffer[read_pos +1])<<14 | inputBuffer[read_pos +2]<<7 | inputBuffer[read_pos +3]); |
| JamieB | 30:87810cae96ac | 100 | // pc.putc(0x03); |
| JamieB | 30:87810cae96ac | 101 | // pc.putc(inputBuffer[read_pos+1]); |
| JamieB | 30:87810cae96ac | 102 | // pc.putc(inputBuffer[read_pos+2]); |
| JamieB | 30:87810cae96ac | 103 | // pc.putc(inputBuffer[read_pos+3]); |
| JamieB | 39:3cd9e498b5c6 | 104 | read_pos += 4; |
| JamieB | 39:3cd9e498b5c6 | 105 | break; |
| JamieB | 39:3cd9e498b5c6 | 106 | default: |
| JamieB | 39:3cd9e498b5c6 | 107 | //pc.putc('D'); |
| JamieB | 39:3cd9e498b5c6 | 108 | break; |
| JamieB | 39:3cd9e498b5c6 | 109 | } |
| JamieB | 39:3cd9e498b5c6 | 110 | valid = false; |
| JamieB | 39:3cd9e498b5c6 | 111 | } // if valid |
| JamieB | 39:3cd9e498b5c6 | 112 | read_pos++; |
| JamieB | 39:3cd9e498b5c6 | 113 | } // while |
| JamieB | 29:b0eaeefa4e63 | 114 | |
| JamieB | 30:87810cae96ac | 115 | //// MAY NEED TO SCALE THESE |
| JamieB | 30:87810cae96ac | 116 | // _focus = focus_Position; |
| JamieB | 30:87810cae96ac | 117 | // _iris = iris_Position; |
| JamieB | 30:87810cae96ac | 118 | // _zoom = zoom_Position; |
| JamieB | 30:87810cae96ac | 119 | // |
| JamieB | 39:3cd9e498b5c6 | 120 | |
| JamieB | 29:b0eaeefa4e63 | 121 | newData = true; |
| JamieB | 39:3cd9e498b5c6 | 122 | } |