Dmitry Kovalev / Mbed 2 deprecated LG2

Dependencies:   mbed

Fork of LG by igor Apu

DeviceProtocol.h

Committer:
Diletant
Date:
2016-02-14
Revision:
60:98eb64c0fda3
Parent:
59:daf3a8ed255e
Child:
61:1b76fe74a0d9

File content as of revision 60:98eb64c0fda3:

#ifndef __DEVICEPROTOCOL_H__
#define __DEVICEPROTOCOL_H__

#include "DeviceSettings.h"
#include "stdint.h"

/*Move this to uart_m.h when protocol completed*/
#define IOBufferSize        1024
typedef struct _IOCyclicBuffer {
    uint8_t buffer[IOBufferSize];
    int start; //first byte position
    int end;   //last byte position
} IOCyclicBuffer;

/*
typedef struct {
    uint8_t Offset;
    uint8_t Mask;
    uint8_t Value;
} DeviceMessageCheckPoint;

typedef enum{
  DMID_DeviceMode
} DeviceMessageID;

typedef struct {
    DeviceMessageID ID;
    uint8_t Size;
    uint8_t CheckPointCount;
    DeviceMessageCheckPoint *CheckPointList;
} DeviceMessageCheck;
*/
typedef enum {
  cmd_Delta_PS,
  cmd_Delta_BINS,
  cmd_Delta_SF,
  cmd_DeviceMode,
  cmd_BIT_Mode,
  cmd_Rate,
  cmd_Delta,
  cmd_D_Period_W,
  cmd_Maint
} DeviceCommands;
typedef enum {
  cmd_M_Stimul,  //e. the code of the Stimul command //r. код команды Stimul    
  cmd_M_Reset,   //e. software device reset(restart) //r. программный сброс (рестарт) прибора
  cmd_M_Clear,   //e. reset of the register of errors of line 485 //r. очистка регистра ошибок линии 485  
  cmd_M_Mirror,  //e. return previous contents of the receiver buffer //r. возврат предыдущего содержимого буфера приемника  
  cmd_M_LdPar_F, //e. load GLD parameters from Flash-memory //r. загрузить параметры ГЛД из флэш-памяти
  cmd_M_LdPar_D, //e. set GLD parameters by procedure of initialization //r. установить параметры ГЛД процедурой инициализации 
  cmd_M_Start,   //e. switch on the GLD //r. включить ГЛД          
  cmd_M_Stop,    //e. switch off the GLD //r. выключить ГЛД
  cmd_M_Pulse,   //e. generation of the light-up pulse //r. генерация импульса поджига
  cmd_M_Ctl_R,   //e. reading the control register of the device //r. чтение регистра управления устройства  
  cmd_M_Ctl_M,   //e. modification of bit of the control register //r. модификация бита регистра управления 
  cmd_M_Rate,    //e. delivery of a stack of parameters M_Rate (Rate2, Rate3) //r. выдача набора параметров M_Rate  (Rate2, Rate3)
  cmd_M_Tmp_W,   //e. writing to the AD7714 circuit (temperature sensors) //r. запись в схемы AD7714 (измерители температуры) 
  cmd_M_Tmp_R,   //e. reading from the AD7714 circuit (temperature sensors) //r. чтение из схем AD7714 (измерители температуры) 
  cmd_M_E5R_W,   //e. writing to the register of a mode of the Elio5 card //r. запись в регистр режима платы Elio5  
  cmd_M_ADC_R,   //e. reading data from the ADC of the Elio5 card //r. чтение данных из АЦП платы Elio5
  cmd_M_Vib_W,   //e. loading of the oscillation period of the dither drive //r. загрузка периода колебаний вибропривода  
  cmd_M_Cnt_R,   //e. reading data from the counters of the Elio5 card //r. чтение данных из счетчиков платы Elio5
  cmd_M_Gph_W,   //e. loading gain factors of photodetector channels //r. загрузка коэффициентов усиления каналов фотоприемника  
  cmd_M_Flg_R,   //e. reading data from the register of input flags  //r. чтение данных из регистра входных флагов
  cmd_M_Param_W, //e. writing working parameter to the data memory //r. запись рабочего параметра в память данных          
  cmd_M_Param_R, //e. reading working parameter of the GLD from the data memory //r. чтение рабочего параметра GLD из памяти данных 
  cmd_M_E5RA_W,  //e. writing in 1st additional (A) register of a mode of the Elio5 card //r. запись в 1-ый дополнительный (А) регистр режима платы Elio5  
} DeviceSubCommands;

//Command: DeviceMode
//DeviceMessageCheckPoint DeviceModeRequestCheck[] = {{0x00,0xff,0xcc},{0x02,0xff,0xcc},{0x03,0xf0,0x00}};
//DeviceMessageCheckPoint DeviceModeResponseCheck[] = {{0x00,0xff,0xcc},{0x02,0xff,0x00}};
typedef enum
{
  Reserved,
  DevModeLatch10kHz,         //internal latch with frequency 10 kHz (power on default mode)
  DevModeLatchMeander,       //internal latch by signed meander pulses
  DevModeLatchRS422PS,       //external latch by RS422 B_Delta_PS request with B_Delta_PS format response
  DevModeLatchRequestPS,     //external latch by pulse request with B_Delta_PS format response
  DevModeLatchRS422BINS,     //external latch by RS422 B_Delta_BINS request with B_Delta_BINS format response
  DevModeLatchRequestBINS    //external latch mode with B_Delta_BINS format data and latch pulse request
} DeviceModes;
typedef __packed struct {
    uint8_t SOC;          //Start Of Command: 0xCC
    uint8_t Address;      //Device address: 0x00, 0x01, 0x02, 0x1f
    uint8_t Cmd;          //Command code: 0xA5
    uint8_t Reserved : 4; //Reserved
    DeviceModes Mode : 4; //Device mode
    uint8_t ChecksumHi;   //Checksum Hi byte
    uint8_t ChecksumLo;   //Checksum Lo byte
} DeviceModeRequest;
typedef __packed struct {
    uint8_t SOC;          //Start Of Command: 0xCC
    uint8_t Address;      //Device address: 0x00, 0x01, 0x02, 0x1f
    uint8_t Zero;         //Reserved: 0x00
    uint8_t Mode;         //Device mode
    uint8_t RgRHi;        //Register RgR Hi byte
    uint8_t RgRLo;        //Register RgR Lo byte
    uint8_t ChecksumHi;   //Checksum Hi byte
    uint8_t ChecksumLo;   //Checksum Lo byte
} DeviceModeResponse;
/*
DeviceMessageCheck DeviceRequestChecks[] = {
   {DMID_DeviceMode, 6, 3, DeviceModeRequestCheck}
};

DeviceMessageCheck DeviceResponseChecks[] = {
   {DMID_DeviceMode, 8, 2, DeviceModeResponseCheck}
};
*/

int PullRequest(IOCyclicBuffer *b);

#endif  /* __DEVICEPROTOCOL_H__ */