Dmitry Kovalev / Mbed 2 deprecated LG2

Dependencies:   mbed

Fork of LG by igor Apu

Revision:
76:1c54a614564d
Parent:
75:cc1942179a2f
Child:
77:8d582faecf6b
--- a/DeviceProtocol.h	Sun Feb 28 06:07:22 2016 +0000
+++ b/DeviceProtocol.h	Mon Feb 29 02:43:14 2016 +0000
@@ -7,56 +7,57 @@
 #define BROADCAST_ADDRESS 0x1f
 #define BROADCAST_FRAME 100       //100 mks
 
-#define DELTA_PS        0xa0      //B_DeltaPS command code: output of accumulated pulses and ACS parameters as 22 indexed packets sequence
-#define DELTA_BINS      0xb0      //B_DeltaBINS command code: output of accumulated pulses and data validity attribute in one packet
-#define DELTA_SF        0xb2      //B_DeltaSF command code: scale factor measurement data output in one packet
-#define DEV_MODE        0xa5      //e. the code of the Device_Mode command //r. код команды Device_Mode
-#define BIT_MODE        0xa7      //e. the code of the B.I.T. command //r. код команды B.I.T.(встороенного тестирования)
-#define RATE            0x00      //e. the code of the Rate command //r. код команды Rate  
-#define DELTA           0x0f      //e. the code of the Delta command //r. код команды Delta
-#define D_PERIOD_W      0xf0      //e. the code of the D_Period_W command //r. код команды D_Period_W
+#define DELTA_PS        0xa000    //B_DeltaPS command code: output of accumulated pulses and ACS parameters as 22 indexed packets sequence
+#define DELTA_BINS      0xb000    //B_DeltaBINS command code: output of accumulated pulses and data validity attribute in one packet
+#define DELTA_SF        0xb200    //B_DeltaSF command code: scale factor measurement data output in one packet
+#define DEV_MODE        0xa500    //e. the code of the Device_Mode command //r. код команды Device_Mode
+#define BIT_MODE        0xa700    //e. the code of the B.I.T. command //r. код команды B.I.T.(встороенного тестирования)
+#define RATE            0x0000    //e. the code of the Rate command //r. код команды Rate  
+#define DELTA           0x0f00    //e. the code of the Delta command //r. код команды Delta
+#define D_PERIOD_W      0xf000    //e. the code of the D_Period_W command //r. код команды D_Period_W
 
-#define MAINTENANCE     0x99      //e. the code of the Maintenance mode command //r. код команды Maintenance mode
+#define MAINTENANCE     0x9900    //e. the code of the Maintenance mode command //r. код команды Maintenance mode
 //Maintenance command set versions
 #define   M0_MAINTENANCE  0x99    //: initial version 
 //Maintenance basic commands group
-#define   M0_BASIC        0xda    //Basic maintenance commands group code
-#define     M0_CLEAR        0x00      //group command select: e. reset of the register of errors of line 485 //r. очистка регистра ошибок линии 485
-#define     M0_MIRROR       0x01      //group command select: e. return previous contents of the receiver buffer //r. возврат предыдущего содержимого буфера приемника  
-#define     M0_LDPAR_F      0x02      //group command select: e. load GLD parameters from Flash-memory //r. загрузить параметры ГЛД из флэш-памяти
-#define     M0_LDPAR_D      0x03      //group command select: e. set GLD parameters by procedure of initialization //r. установить параметры ГЛД процедурой инициализации 
-#define     M0_START        0x04      //group command select: e. switch on the GLD //r. включить ГЛД          
-#define     M0_STOP         0x40      //group command select: e. switch off the GLD //r. выключить ГЛД
-#define     M0_PULSE        0x0a      //group command select: e. generation of the light-up pulse //r. генерация импульса поджига
+#define   M0_BASIC        0xda00  //Basic maintenance commands group code
+#define     M0_CLEAR        0xda00    //group command select: e. reset of the register of errors of line 485 //r. очистка регистра ошибок линии 485
+#define     M0_MIRROR       0xda01    //group command select: e. return previous contents of the receiver buffer //r. возврат предыдущего содержимого буфера приемника  
+#define     M0_LDPAR_F      0xda02    //group command select: e. load GLD parameters from Flash-memory //r. загрузить параметры ГЛД из флэш-памяти
+#define     M0_LDPAR_D      0xda03    //group command select: e. set GLD parameters by procedure of initialization //r. установить параметры ГЛД процедурой инициализации 
+#define     M0_START        0xda04    //group command select: e. switch on the GLD //r. включить ГЛД          
+#define     M0_STOP         0xda40    //group command select: e. switch off the GLD //r. выключить ГЛД
+#define     M0_PULSE        0xda0a    //group command select: e. generation of the light-up pulse //r. генерация импульса поджига
 //Maintenance rate commands group
-#define   M0_RATE         0xdd    //e. delivery of a stack of parameters M_Rate (Rate2, Rate3) //r. выдача набора параметров M_Rate  (Rate2, Rate3)
-#define     M0_RATE_0       0x00      //group command select: output parameters set 0?
-#define     M0_RATE_1       0x01      //group command select: output parameters set 1?
-#define     M0_RATE_2       0x02      //group command select: output parameters set 2
-#define     M0_RATE_3       0x03      //group command select: output parameters set 3
-#define     M0_RATE_4       0x04      //group command select: output parameters set 4
-#define     M0_RATE_7       0x07      //group command select: output parameters set 7
+#define   M0_RATE         0xdd00  //e. delivery of a stack of parameters M_Rate (Rate2, Rate3) //r. выдача набора параметров M_Rate  (Rate2, Rate3)
+#define     M0_RATE_0       0xdd00    //group command select: output parameters set 0?
+#define     M0_RATE_1       0xdd01    //group command select: output parameters set 1?
+#define     M0_RATE_2       0xdd02    //group command select: output parameters set 2
+#define     M0_RATE_3       0xdd03    //group command select: output parameters set 3
+#define     M0_RATE_4       0xdd04    //group command select: output parameters set 4
+#define     M0_RATE_7       0xdd07    //group command select: output parameters set 7
 
 //Other maintenance commands
-#define   M0_STIMUL       0x0a    //e. the code of the Stimul command //r. код команды Stimul    
-#define   M0_RESET        0x80    //e. software device reset(restart) //r. программный сброс (рестарт) прибора
+#define   M0_STIMUL       0x0a00  //e. the code of the Stimul command //r. код команды Stimul    
+#define   M0_RESET        0x8000  //e. software device reset(restart) //r. программный сброс (рестарт) прибора
 
-#define   M0_CTL_R        0xd9    //e. reading the control register of the device //r. чтение регистра управления устройства  
-#define   M0_CTL_M        0xd8    //e. modification of bit of the control register //r. модификация бита регистра управления 
+#define   M0_CTL_R        0xd900  //e. reading the control register of the device //r. чтение регистра управления устройства  
+#define   M0_CTL_M        0xd800  //e. modification of bit of the control register //r. модификация бита регистра управления 
 
-#define   M0_TMP_W        0xe0    //e. writing to the AD7714 circuit (temperature sensors) //r. запись в схемы AD7714 (измерители температуры) 
-#define   M0_TMP_R        0xe1    //e. reading from the AD7714 circuit (temperature sensors) //r. чтение из схем AD7714 (измерители температуры) 
-#define   M0_E5R_W        0xe2    //e. writing to the register of a mode of the Elio5 card //r. запись в регистр режима платы Elio5  
-#define   M0_ADC_R        0xe3    //e. reading data from the ADC of the Elio5 card //r. чтение данных из АЦП платы Elio5
-#define   M0_VIB_W        0xe4    //e. loading of the oscillation period of the dither drive //r. загрузка периода колебаний вибропривода  
-#define   M0_CNT_R        0xe5    //e. reading data from the counters of the Elio5 card //r. чтение данных из счетчиков платы Elio5
-#define   M0_GPH_W        0xe6    //e. loading gain factors of photodetector channels //r. загрузка коэффициентов усиления каналов фотоприемника  
-#define   M0_FLG_R        0xe7    //e. reading data from the register of input flags  //r. чтение данных из регистра входных флагов
-#define   M0_PARAM_W      0xe8    //e. writing working parameter to the data memory //r. запись рабочего параметра в память данных          
-#define   M0_PARAM_R      0xe9    //e. reading working parameter of the GLD from the data memory //r. чтение рабочего параметра GLD из памяти данных 
-#define   M0_E5RA_W       0xea    //e. writing in 1st additional (A) register of a mode of the Elio5 card //r. запись в 1-ый дополнительный (А) регистр режима платы Elio5
+#define   M0_TMP_W        0xe000  //e. writing to the AD7714 circuit (temperature sensors) //r. запись в схемы AD7714 (измерители температуры) 
+#define   M0_TMP_R        0xe100  //e. reading from the AD7714 circuit (temperature sensors) //r. чтение из схем AD7714 (измерители температуры) 
+#define   M0_E5R_W        0xe200  //e. writing to the register of a mode of the Elio5 card //r. запись в регистр режима платы Elio5  
+#define   M0_ADC_R        0xe300  //e. reading data from the ADC of the Elio5 card //r. чтение данных из АЦП платы Elio5
+#define   M0_VIB_W        0xe400  //e. loading of the oscillation period of the dither drive //r. загрузка периода колебаний вибропривода  
+#define   M0_CNT_R        0xe500  //e. reading data from the counters of the Elio5 card //r. чтение данных из счетчиков платы Elio5
+#define   M0_GPH_W        0xe600  //e. loading gain factors of photodetector channels //r. загрузка коэффициентов усиления каналов фотоприемника  
+#define   M0_FLG_R        0xe700  //e. reading data from the register of input flags  //r. чтение данных из регистра входных флагов
+#define   M0_PARAM_W      0xe800  //e. writing working parameter to the data memory //r. запись рабочего параметра в память данных          
+#define   M0_PARAM_R      0xe900  //e. reading working parameter of the GLD from the data memory //r. чтение рабочего параметра GLD из памяти данных 
+#define   M0_E5RA_W       0xea00  //e. writing in 1st additional (A) register of a mode of the Elio5 card //r. запись в 1-ый дополнительный (А) регистр режима платы Elio5
 
 typedef enum _ResponseType {
+    RESPONSE_NONE,      //no sheduled response
     RESPONSE_IMMEDIATE, //immediate response for most of requests
     RESPONSE_DELAYED,   //delayed response for broadcast requests
     RESPONSE_PERIODIC   //periodic response for some of requests
@@ -77,8 +78,10 @@
 } DeviceOutputBuffer;
 
 typedef struct _DeviceResponse {
+  uint8_t enabled;   //
   ResponseType type; //how send: immediately/delayed/periodic
-  ResponseData data; //what send: buffer/Delta_BINS/Delta_PS/Delta_SF/M_Rate
+  //ResponseData data; //what send: buffer/Delta_BINS/Delta_PS/Delta_SF/M_Rate
+  uint16_t code;     //Request code
   uint32_t counter;  //time from: broadcast line request/latch pulse/last response; values in mks;
   uint32_t trigger;  //counter value to response; values in mks;
   uint32_t rate;     //response baud rate
@@ -99,11 +102,11 @@
 } DeviceRequest;
 
 typedef struct _DeviceProtocolDecoder {
-  uint8_t address;  //Decoded request address
-  uint8_t code;     //Decoded command code
-  uint8_t version;  //Decoded protocol version (currently only 0 version exist)
   uint8_t error;    //Decode error encountered
   uint8_t count;    //Decoded bytes count
+  uint8_t address;  //Decoded request address
+  uint8_t version;  //Decoded protocol version (currently only 0 version exist)
+  uint16_t code;     //Decoded command code
   uint16_t position;//Current decoder position in input buffer
   uint16_t CRC;     //Current/final CRC of decoded packet
 } DeviceProtocolDecoder;
@@ -126,14 +129,14 @@
 void DecodeCancel(void);
 void DecodeFail(void);
 void DecodeAddress(void);
+void DecodeCode(void);
+void DecodeCode2(void);
 void DecodeCRC(void);
 
 void DecodeDeviceMode(void);
-void DecodeDeltaBINS(void);
-void DecodeDeltaPS(void);
-void DecodeDelta(void); //Not used?
-void DecodeDPeriodW(void); //Not used?
+void DecodeDelta(void);
 void DecodeMaintenanceMode(void);
+void DecodeMBasic(void);
 void DecodeMStymul(void);
 void DecodeMADCR(void);
 void DecodeMTmpW(void);
@@ -162,10 +165,13 @@
 
 void EncodeStart(void);
 void EncodeEnd(void);
+void EncodeAddress(void);
+void EncodeCRC(void);
 
 void EncodeDeviceMode(void);
 void EncodeSysRgR(void);
 
-void EncodeCRC(void);
+void EncodeBINSDiff(void);
+void EncodeValidBINS(void);
 
 #endif  /* __DEVICEPROTOCOL_H__ */
\ No newline at end of file