Shih-Ho Hsieh / Mbed 2 deprecated Motor_XYZ_UI_SPI_8mag_encoder

Dependencies:   mbed

parse_array/envelopetracker.h

Committer:
hober
Date:
2019-01-07
Revision:
1:edc6b5cc7112
Parent:
0:9e6e3dc903c0

File content as of revision 1:edc6b5cc7112:

#ifndef ENVELOPETRACKER_H
#define ENVELOPETRACKER_H

#include "envelope.h"
#include <list>
class EnvelopeTracker
{
public:
    EnvelopeTracker();

    // parsing
    void parse(char *buf, int bufLength);

    Envelope* getEnvelope(){
        Envelope* ret = NULL;
        if(envelopeListIndexFront != -1){
            ret = envelopeList[envelopeListIndexFront++];
            envelopeListIndexFront %= envelopeListLength;
            if(envelopeListIndexFront == envelopeListIndex) envelopeListIndexFront = -1;
        }
        return ret;
    }
    int bufferDataLength();
    
    void resetBuffer();

    void setEnvelope(const Envelope &value);

    void setBufferLength(int value);
    ~EnvelopeTracker();

private:
    // check Header
    bool testHeader();

    // check Footer
    bool testFooter();

    // test XOR
    bool testXOR();// set xindex as headerIndex


    // current header index
    int currentHeaderIndex;
    // current footer index
    int currentFooterIndex;
    int currentDataIndex;
    // index
    int currentIndex;
    // array
    char * bufferArray;
    int bufferLength;
    int bufferTailIndex;

    Envelope** envelopeList;
    int envelopeListLength;
    int envelopeListIndex;
    int envelopeListIndexFront;
    Envelope envelope;
    int envelopeLength;
    int envelopeDataLength;
    int headerLength;
};

#endif // ENVELOPETRACKER_H