src/hp34comm.h

Tue, 20 Sep 2016 23:50:45 +0200

author
David Douard <david.douard@logilab.fr>
date
Tue, 20 Sep 2016 23:50:45 +0200
changeset 5
f1c85c2500f2
child 8
55021f3f1929
permissions
-rw-r--r--

several improvements

- add (used parts of) unigraphics in repo
- extract hp communication protocol listener in a dedicated file

#ifndef HP34COMM_H
#define HP34COMM_H

#include "mbed.h"
#include "CircularBuffer.h"

/***** HP 34970A communication class ***/

#define MAX_ERRS 10
#define MAX_BUFF 32
#define BUF_SIZE 32

class HPSerial {

public:
  enum TrState {
        Idle = 0,
        Tx,
        Rx,
    };
  typedef struct _CMD
  {
    TrState direction;
    uint8_t cmd;
    uint8_t size;
    char value[MAX_BUFF+1];
    unsigned long id;
  } CMD;


  
  HPSerial();
  
  bool cmd_available(void);
  bool pop(CMD& cmd);
  bool cmd_buf_full(void);
  unsigned int nerrors(uint8_t errorno);
		     
  
private:
  void reset(uint8_t errorno=0xFF);
  void handleAck(uint8_t val);
  void pushCmd(TrState direction, uint8_t cmd, uint8_t size, char *payload);
  void handleChar(uint8_t val);
  void setstatedbg(void);    
  void rxIrq(void);
  void txIrq(void);
  void timeout(void);

 private:
  RawSerial serial_tx;
  RawSerial serial_rx;
  uint8_t buf[BUF_SIZE];
  uint8_t head;
  uint8_t tx_state;
  uint8_t tx_cmd;
  uint8_t tx_len;
  bool tx_ack;
  CircularBuffer<CMD, 32> cmdbuf;
  unsigned long ncmd;
  unsigned int errs[MAX_ERRS];
  Ticker timeouter;
};

#endif

mercurial