123
Fork of LG by
Command.c@21:bc8c1cec3da6, 2016-02-03 (annotated)
- Committer:
- igor_v
- Date:
- Wed Feb 03 07:19:30 2016 +0000
- Revision:
- 21:bc8c1cec3da6
- Parent:
- 0:8ad47e2b6f00
- Child:
- 25:1a6798ccd3cd
?????????? ??????? ??????????, ???????? ??? ?????? ?????????? ??????????? ?????????.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 0:8ad47e2b6f00 | 1 | #include "stdlib.h" |
igor_v | 0:8ad47e2b6f00 | 2 | #include "LPC17xx.h" |
igor_v | 0:8ad47e2b6f00 | 3 | #include "Command.h" |
igor_v | 0:8ad47e2b6f00 | 4 | #include "el_lin.h" |
igor_v | 0:8ad47e2b6f00 | 5 | #include "vibro.h" |
igor_v | 0:8ad47e2b6f00 | 6 | #include "Global.h" |
igor_v | 0:8ad47e2b6f00 | 7 | #include "uart_m.h" |
igor_v | 0:8ad47e2b6f00 | 8 | #include "CntrlGLD.h" |
igor_v | 0:8ad47e2b6f00 | 9 | #include "QEI.h" |
igor_v | 0:8ad47e2b6f00 | 10 | #include "InputOutput.h" |
igor_v | 0:8ad47e2b6f00 | 11 | #include "SPI.h" |
igor_v | 0:8ad47e2b6f00 | 12 | unsigned int Rate_Flag; |
igor_v | 0:8ad47e2b6f00 | 13 | unsigned int PC_Comand; |
igor_v | 0:8ad47e2b6f00 | 14 | unsigned int n; |
igor_v | 0:8ad47e2b6f00 | 15 | unsigned int CountBuFFIn; |
igor_v | 0:8ad47e2b6f00 | 16 | unsigned int ParamIn; |
igor_v | 0:8ad47e2b6f00 | 17 | unsigned int Err; |
igor_v | 21:bc8c1cec3da6 | 18 | unsigned int N=0,CRC_N; |
igor_v | 21:bc8c1cec3da6 | 19 | unsigned int Param1=0; |
igor_v | 21:bc8c1cec3da6 | 20 | unsigned int Param2=0; |
igor_v | 21:bc8c1cec3da6 | 21 | unsigned int Param3=0; |
igor_v | 21:bc8c1cec3da6 | 22 | unsigned int Param4=0; |
igor_v | 21:bc8c1cec3da6 | 23 | |
igor_v | 0:8ad47e2b6f00 | 24 | /* |
igor_v | 21:bc8c1cec3da6 | 25 | void exec_CMD(void) //r. === процедура окончательной дешифрации и исполнения команды |
igor_v | 0:8ad47e2b6f00 | 26 | { |
igor_v | 0:8ad47e2b6f00 | 27 | unsigned int Comand_code; |
igor_v | 21:bc8c1cec3da6 | 28 | |
igor_v | 21:bc8c1cec3da6 | 29 | //rx_buf_copy = 1; //r. предустанов флага копирования приемного буфера |
igor_v | 0:8ad47e2b6f00 | 30 | |
igor_v | 0:8ad47e2b6f00 | 31 | Comand_code = (rcv_buf[2] & 0xFF) << 8; |
igor_v | 21:bc8c1cec3da6 | 32 | PC_Comand = Comand_code | (rcv_buf[3] & 0xFF); //e. save it in the memory for echo-transmission //r. сохранить его в памяти для обратной передачи |
igor_v | 0:8ad47e2b6f00 | 33 | }*/ |
igor_v | 0:8ad47e2b6f00 | 34 | void CMD_Maintenance(void) |
igor_v | 0:8ad47e2b6f00 | 35 | { |
igor_v | 21:bc8c1cec3da6 | 36 | BuffTemp[0] = Main.SOC_Out; |
igor_v | 21:bc8c1cec3da6 | 37 | BuffTemp[1] = Main.My_Addres; |
igor_v | 21:bc8c1cec3da6 | 38 | BuffTemp[2] = Main.Firmware_Version; |
igor_v | 21:bc8c1cec3da6 | 39 | BuffTemp[3] = Main.GLD_Serial; |
igor_v | 21:bc8c1cec3da6 | 40 | BuffTemp[4]=0x00; |
igor_v | 21:bc8c1cec3da6 | 41 | BuffTemp[5]=0x00; |
igor_v | 21:bc8c1cec3da6 | 42 | Check(BuffTemp, 8); |
igor_v | 21:bc8c1cec3da6 | 43 | WriteConN (BuffTemp,8); |
igor_v | 0:8ad47e2b6f00 | 44 | } |
igor_v | 0:8ad47e2b6f00 | 45 | |
igor_v | 0:8ad47e2b6f00 | 46 | void CMD_Rate(void) |
igor_v | 21:bc8c1cec3da6 | 47 | { |
igor_v | 21:bc8c1cec3da6 | 48 | |
igor_v | 21:bc8c1cec3da6 | 49 | unsigned int T_VibH , T_VibL; // Частота вибропривода. |
igor_v | 21:bc8c1cec3da6 | 50 | unsigned int Cnt_PlsL , Cnt_PlsH; // Счетчик +. |
igor_v | 21:bc8c1cec3da6 | 51 | unsigned int Cnt_MnsL , Cnt_MnsH; // Счетчик -. |
igor_v | 21:bc8c1cec3da6 | 52 | unsigned int Cnt_DifL , Cnt_DifH; // Разность счетчиков. |
igor_v | 21:bc8c1cec3da6 | 53 | unsigned int F_rasL , F_rasH; // Частота расщепления. |
igor_v | 21:bc8c1cec3da6 | 54 | |
igor_v | 21:bc8c1cec3da6 | 55 | unsigned int HF_regL , HF_regH; // Выход регулятора ГВЧ. НЕ СДЕЛАНО |
igor_v | 21:bc8c1cec3da6 | 56 | unsigned int HF_difL , HF_difH; // Сигнал ошибки регулячтора ГВЧ. НЕ СДЕЛАНО |
igor_v | 21:bc8c1cec3da6 | 57 | |
igor_v | 21:bc8c1cec3da6 | 58 | unsigned int WP_regL , WP_regH; |
igor_v | 21:bc8c1cec3da6 | 59 | |
igor_v | 21:bc8c1cec3da6 | 60 | unsigned int ADC1L, ADC2L, ADC3L, ADC4L, ADC5L; |
igor_v | 21:bc8c1cec3da6 | 61 | unsigned int ADC1H, ADC2H, ADC3H, ADC4H, ADC5H; |
igor_v | 21:bc8c1cec3da6 | 62 | |
igor_v | 21:bc8c1cec3da6 | 63 | |
igor_v | 21:bc8c1cec3da6 | 64 | LoopOn |
igor_v | 0:8ad47e2b6f00 | 65 | // Main.T_Vib=(unsigned int)((7680000*16/Main.Frq)*4096); |
igor_v | 21:bc8c1cec3da6 | 66 | Main.T_Vib=(unsigned int)((7680000*16/(Main.Frq>>12))); |
igor_v | 21:bc8c1cec3da6 | 67 | Main.Firmware_Version=0xff; /// промежуточная затычка |
igor_v | 21:bc8c1cec3da6 | 68 | |
igor_v | 21:bc8c1cec3da6 | 69 | T_VibH = ( Main.T_Vib>>8 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 70 | T_VibL = ( Main.T_Vib ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 71 | |
igor_v | 21:bc8c1cec3da6 | 72 | Cnt_PlsH = ( Main.Cnt_Pls>>8) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 73 | Cnt_PlsL = ( Main.Cnt_Pls ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 74 | |
igor_v | 21:bc8c1cec3da6 | 75 | Cnt_MnsH = ( Main.Cnt_Mns>>8) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 76 | Cnt_MnsL = ( Main.Cnt_Mns ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 77 | |
igor_v | 21:bc8c1cec3da6 | 78 | Cnt_DifH = ( Main.Cnt_Dif>>8) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 79 | Cnt_DifL = ( Main.Cnt_Dif ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 80 | |
igor_v | 21:bc8c1cec3da6 | 81 | F_rasH = ( Main.F_ras>>8 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 82 | F_rasL = ( Main.F_ras ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 83 | |
igor_v | 21:bc8c1cec3da6 | 84 | ADC1H = ( Spi.ADC1>>8 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 85 | ADC1L = ( Spi.ADC1 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 86 | |
igor_v | 21:bc8c1cec3da6 | 87 | ADC2H = ( Spi.ADC2>>8 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 88 | ADC2L = ( Spi.ADC2 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 89 | |
igor_v | 21:bc8c1cec3da6 | 90 | ADC3H = ( Spi.ADC3>>8 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 91 | ADC3L = ( Spi.ADC3 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 92 | |
igor_v | 21:bc8c1cec3da6 | 93 | ADC4H = ( Spi.ADC4>>8 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 94 | ADC4L = ( Spi.ADC4 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 95 | |
igor_v | 21:bc8c1cec3da6 | 96 | ADC5H = ( Spi.ADC5>>8 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 97 | ADC5L = ( Spi.ADC5 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 98 | |
igor_v | 21:bc8c1cec3da6 | 99 | WP_regH = ( Spi.DAC_B>>8 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 100 | WP_regL = ( Spi.DAC_B ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 101 | |
igor_v | 21:bc8c1cec3da6 | 102 | HF_regH=0xff; |
igor_v | 21:bc8c1cec3da6 | 103 | HF_regL=0xff; |
igor_v | 21:bc8c1cec3da6 | 104 | |
igor_v | 21:bc8c1cec3da6 | 105 | HF_difH=0xff; |
igor_v | 21:bc8c1cec3da6 | 106 | HF_difL=0xff; |
igor_v | 21:bc8c1cec3da6 | 107 | |
igor_v | 0:8ad47e2b6f00 | 108 | |
igor_v | 21:bc8c1cec3da6 | 109 | BuffTemp[ 0] = Main.SOC_Out; |
igor_v | 21:bc8c1cec3da6 | 110 | BuffTemp[ 1] = Main.My_Addres; |
igor_v | 21:bc8c1cec3da6 | 111 | |
igor_v | 21:bc8c1cec3da6 | 112 | BuffTemp[ 2] = Cnt_PlsH;//старший байт счетчика +. |
igor_v | 21:bc8c1cec3da6 | 113 | BuffTemp[ 3] = Cnt_PlsL;//младший байт счетчика +. |
igor_v | 21:bc8c1cec3da6 | 114 | |
igor_v | 21:bc8c1cec3da6 | 115 | BuffTemp[ 4] = Cnt_MnsH;//старший байт счетчика -. |
igor_v | 21:bc8c1cec3da6 | 116 | BuffTemp[ 5] = Cnt_MnsL;//младший байт счетчика -. |
igor_v | 21:bc8c1cec3da6 | 117 | |
igor_v | 21:bc8c1cec3da6 | 118 | BuffTemp[ 6] = Cnt_DifH;//старший байт разности счетчиков |
igor_v | 21:bc8c1cec3da6 | 119 | BuffTemp[ 7] = Cnt_DifL;//младший байт разности счетчиков |
igor_v | 21:bc8c1cec3da6 | 120 | |
igor_v | 21:bc8c1cec3da6 | 121 | BuffTemp[ 8] = F_rasH; |
igor_v | 21:bc8c1cec3da6 | 122 | BuffTemp[ 9] = F_rasL; |
igor_v | 21:bc8c1cec3da6 | 123 | |
igor_v | 21:bc8c1cec3da6 | 124 | BuffTemp[10] = HF_regH; |
igor_v | 21:bc8c1cec3da6 | 125 | BuffTemp[11] = HF_regL; |
igor_v | 21:bc8c1cec3da6 | 126 | |
igor_v | 21:bc8c1cec3da6 | 127 | BuffTemp[12] = HF_difH; |
igor_v | 21:bc8c1cec3da6 | 128 | BuffTemp[13] = HF_difL; |
igor_v | 21:bc8c1cec3da6 | 129 | |
igor_v | 21:bc8c1cec3da6 | 130 | BuffTemp[14] = T_VibH ;// |
igor_v | 21:bc8c1cec3da6 | 131 | BuffTemp[15] = T_VibL; //? |
igor_v | 21:bc8c1cec3da6 | 132 | |
igor_v | 21:bc8c1cec3da6 | 133 | BuffTemp[16] = Main.Firmware_Version;//ХЗ |
igor_v | 21:bc8c1cec3da6 | 134 | BuffTemp[17] = Main.Firmware_Version;//ХЗ |
igor_v | 21:bc8c1cec3da6 | 135 | |
igor_v | 21:bc8c1cec3da6 | 136 | BuffTemp[18] = T_VibH>>1; |
igor_v | 21:bc8c1cec3da6 | 137 | BuffTemp[19] = T_VibL; |
igor_v | 21:bc8c1cec3da6 | 138 | |
igor_v | 21:bc8c1cec3da6 | 139 | BuffTemp[20] = Main.Firmware_Version;//ХЗ |
igor_v | 21:bc8c1cec3da6 | 140 | BuffTemp[21] = Main.Firmware_Version;//ХЗ |
igor_v | 21:bc8c1cec3da6 | 141 | |
igor_v | 21:bc8c1cec3da6 | 142 | BuffTemp[22] = WP_regH; //СРП Spi.DAC_B |
igor_v | 21:bc8c1cec3da6 | 143 | BuffTemp[23] = WP_regL; //СРП |
igor_v | 21:bc8c1cec3da6 | 144 | |
igor_v | 21:bc8c1cec3da6 | 145 | BuffTemp[24] = Main.Firmware_Version;// ХЗ |
igor_v | 21:bc8c1cec3da6 | 146 | BuffTemp[25] = Main.Firmware_Version;// ХЗ |
igor_v | 21:bc8c1cec3da6 | 147 | |
igor_v | 21:bc8c1cec3da6 | 148 | BuffTemp[26] = ADC1H; |
igor_v | 21:bc8c1cec3da6 | 149 | BuffTemp[27] = ADC1L; |
igor_v | 21:bc8c1cec3da6 | 150 | |
igor_v | 21:bc8c1cec3da6 | 151 | BuffTemp[28] = ADC1H; |
igor_v | 21:bc8c1cec3da6 | 152 | BuffTemp[29] = ADC1L; |
igor_v | 21:bc8c1cec3da6 | 153 | |
igor_v | 21:bc8c1cec3da6 | 154 | BuffTemp[30] = ADC1H; |
igor_v | 21:bc8c1cec3da6 | 155 | BuffTemp[31] = ADC1L; |
igor_v | 21:bc8c1cec3da6 | 156 | |
igor_v | 21:bc8c1cec3da6 | 157 | BuffTemp[32] = ADC1H; |
igor_v | 21:bc8c1cec3da6 | 158 | BuffTemp[33] = ADC1L; |
igor_v | 21:bc8c1cec3da6 | 159 | |
igor_v | 21:bc8c1cec3da6 | 160 | BuffTemp[34] = ADC1H; |
igor_v | 21:bc8c1cec3da6 | 161 | BuffTemp[35] = ADC1L; |
igor_v | 21:bc8c1cec3da6 | 162 | |
igor_v | 21:bc8c1cec3da6 | 163 | BuffTemp[36] = 0x00;//ADC6 |
igor_v | 21:bc8c1cec3da6 | 164 | BuffTemp[37] = 0x00;//ADC6 |
igor_v | 21:bc8c1cec3da6 | 165 | |
igor_v | 21:bc8c1cec3da6 | 166 | BuffTemp[38] = Main.Firmware_Version; |
igor_v | 21:bc8c1cec3da6 | 167 | BuffTemp[39] = Main.Firmware_Version; |
igor_v | 21:bc8c1cec3da6 | 168 | BuffTemp[40] = Main.Firmware_Version; |
igor_v | 21:bc8c1cec3da6 | 169 | BuffTemp[41] = Main.Firmware_Version; |
igor_v | 21:bc8c1cec3da6 | 170 | |
igor_v | 21:bc8c1cec3da6 | 171 | |
igor_v | 21:bc8c1cec3da6 | 172 | Check(BuffTemp, 44); |
igor_v | 21:bc8c1cec3da6 | 173 | WriteConN (BuffTemp,44); |
igor_v | 21:bc8c1cec3da6 | 174 | LoopOff |
igor_v | 0:8ad47e2b6f00 | 175 | } |
igor_v | 0:8ad47e2b6f00 | 176 | |
igor_v | 21:bc8c1cec3da6 | 177 | void CMD_M_Control_D8()///установка\сброс регистров управления |
igor_v | 21:bc8c1cec3da6 | 178 | { |
igor_v | 21:bc8c1cec3da6 | 179 | int bit,NReg; |
igor_v | 21:bc8c1cec3da6 | 180 | BuffTemp[0] = Main.SOC_Out; //DD |
igor_v | 21:bc8c1cec3da6 | 181 | BuffTemp[1] = Main.My_Addres; //00 |
igor_v | 21:bc8c1cec3da6 | 182 | BuffTemp[2] = Main.CMD_In; //D8 |
igor_v | 21:bc8c1cec3da6 | 183 | //10? |
igor_v | 21:bc8c1cec3da6 | 184 | if((Param1&0x80)) { |
igor_v | 21:bc8c1cec3da6 | 185 | bit=1; |
igor_v | 21:bc8c1cec3da6 | 186 | } else { |
igor_v | 21:bc8c1cec3da6 | 187 | bit=0; |
igor_v | 21:bc8c1cec3da6 | 188 | } |
igor_v | 21:bc8c1cec3da6 | 189 | |
igor_v | 21:bc8c1cec3da6 | 190 | if ((Param1 & 0x10) == 0) { |
igor_v | 21:bc8c1cec3da6 | 191 | NReg=0; |
igor_v | 21:bc8c1cec3da6 | 192 | switch(Param1&0xf) { // Main.RgConA |
igor_v | 21:bc8c1cec3da6 | 193 | case 0x0: |
igor_v | 21:bc8c1cec3da6 | 194 | Main.RgConA|=bit; |
igor_v | 21:bc8c1cec3da6 | 195 | break; |
igor_v | 21:bc8c1cec3da6 | 196 | |
igor_v | 21:bc8c1cec3da6 | 197 | case 0x1: |
igor_v | 21:bc8c1cec3da6 | 198 | Main.RgConA|=bit<<0x1; |
igor_v | 21:bc8c1cec3da6 | 199 | break; |
igor_v | 21:bc8c1cec3da6 | 200 | |
igor_v | 21:bc8c1cec3da6 | 201 | case 0x2: |
igor_v | 21:bc8c1cec3da6 | 202 | Main.RgConA|=bit<<0x2; |
igor_v | 21:bc8c1cec3da6 | 203 | break; |
igor_v | 21:bc8c1cec3da6 | 204 | |
igor_v | 21:bc8c1cec3da6 | 205 | case 0x3: |
igor_v | 21:bc8c1cec3da6 | 206 | Main.RgConA|=bit<<0x3; |
igor_v | 21:bc8c1cec3da6 | 207 | break; |
igor_v | 21:bc8c1cec3da6 | 208 | |
igor_v | 21:bc8c1cec3da6 | 209 | case 0x4: |
igor_v | 21:bc8c1cec3da6 | 210 | Main.RgConA|=bit<<0x4; |
igor_v | 21:bc8c1cec3da6 | 211 | break; |
igor_v | 21:bc8c1cec3da6 | 212 | |
igor_v | 21:bc8c1cec3da6 | 213 | case 0x5: |
igor_v | 21:bc8c1cec3da6 | 214 | Main.RgConA|=bit<<0x5; |
igor_v | 21:bc8c1cec3da6 | 215 | break; |
igor_v | 21:bc8c1cec3da6 | 216 | |
igor_v | 21:bc8c1cec3da6 | 217 | case 0x6: |
igor_v | 21:bc8c1cec3da6 | 218 | Main.RgConA|=bit<<0x6; |
igor_v | 21:bc8c1cec3da6 | 219 | break; |
igor_v | 21:bc8c1cec3da6 | 220 | |
igor_v | 21:bc8c1cec3da6 | 221 | case 0x7: |
igor_v | 21:bc8c1cec3da6 | 222 | Main.RgConA|=bit<<0x7; |
igor_v | 21:bc8c1cec3da6 | 223 | break; |
igor_v | 21:bc8c1cec3da6 | 224 | } |
igor_v | 21:bc8c1cec3da6 | 225 | BuffTemp[3] = NReg<<4; |
igor_v | 21:bc8c1cec3da6 | 226 | BuffTemp[4] = (Main.RgConA>>8 )& 0xff; |
igor_v | 21:bc8c1cec3da6 | 227 | BuffTemp[5] = Main.RgConA & 0xff; |
igor_v | 21:bc8c1cec3da6 | 228 | } else { |
igor_v | 21:bc8c1cec3da6 | 229 | NReg=1; // Main.RgConB |
igor_v | 21:bc8c1cec3da6 | 230 | switch(Param1&0xf) { // Main.RgConB |
igor_v | 21:bc8c1cec3da6 | 231 | case 0x0: |
igor_v | 21:bc8c1cec3da6 | 232 | Main.RgConB|=bit; |
igor_v | 21:bc8c1cec3da6 | 233 | break; |
igor_v | 21:bc8c1cec3da6 | 234 | case 0x1: |
igor_v | 21:bc8c1cec3da6 | 235 | Main.RgConB|=bit<1; |
igor_v | 21:bc8c1cec3da6 | 236 | break; |
igor_v | 21:bc8c1cec3da6 | 237 | case 0x2: |
igor_v | 21:bc8c1cec3da6 | 238 | Main.RgConB|=bit<2; |
igor_v | 21:bc8c1cec3da6 | 239 | break; |
igor_v | 21:bc8c1cec3da6 | 240 | } |
igor_v | 21:bc8c1cec3da6 | 241 | BuffTemp[3] = NReg<<4; |
igor_v | 21:bc8c1cec3da6 | 242 | BuffTemp[4] = (Main.RgConB>>8 ) & 0xff; |
igor_v | 21:bc8c1cec3da6 | 243 | BuffTemp[5] = Main.RgConB & 0xff; |
igor_v | 21:bc8c1cec3da6 | 244 | } |
igor_v | 21:bc8c1cec3da6 | 245 | |
igor_v | 21:bc8c1cec3da6 | 246 | Check(BuffTemp, CRC_N); |
igor_v | 21:bc8c1cec3da6 | 247 | WriteConN (BuffTemp,CRC_N); |
igor_v | 0:8ad47e2b6f00 | 248 | } |
igor_v | 0:8ad47e2b6f00 | 249 | |
igor_v | 21:bc8c1cec3da6 | 250 | void CMD_M_Control_D9()///чтение регистров управления |
igor_v | 21:bc8c1cec3da6 | 251 | { |
igor_v | 21:bc8c1cec3da6 | 252 | int bit,NReg; |
igor_v | 21:bc8c1cec3da6 | 253 | BuffTemp[0] = Main.SOC_Out; //DD |
igor_v | 21:bc8c1cec3da6 | 254 | BuffTemp[1] = Main.My_Addres; //00 |
igor_v | 21:bc8c1cec3da6 | 255 | BuffTemp[2] = Main.CMD_In; //D9 |
igor_v | 21:bc8c1cec3da6 | 256 | if ((Param1 & 0x10) == 0) { |
igor_v | 21:bc8c1cec3da6 | 257 | BuffTemp[3]=0<<4; |
igor_v | 21:bc8c1cec3da6 | 258 | BuffTemp[4] = (Main.RgConA>>8 )& 0xff; |
igor_v | 21:bc8c1cec3da6 | 259 | BuffTemp[5] = Main.RgConA & 0xff; |
igor_v | 21:bc8c1cec3da6 | 260 | } else { |
igor_v | 21:bc8c1cec3da6 | 261 | BuffTemp[3]=1<<4; |
igor_v | 21:bc8c1cec3da6 | 262 | BuffTemp[4] = (Main.RgConB>>8 ) & 0xff; |
igor_v | 21:bc8c1cec3da6 | 263 | BuffTemp[5] = Main.RgConB & 0xff; |
igor_v | 21:bc8c1cec3da6 | 264 | } |
igor_v | 21:bc8c1cec3da6 | 265 | Check(BuffTemp, CRC_N); |
igor_v | 21:bc8c1cec3da6 | 266 | WriteConN (BuffTemp,CRC_N); |
igor_v | 21:bc8c1cec3da6 | 267 | } |
igor_v | 21:bc8c1cec3da6 | 268 | // (номер (код) ЦАПа 0...3, старший байт требуемого ЦАПа, младший байт треб ЦАПа) |
igor_v | 0:8ad47e2b6f00 | 269 | void CMD_M_Stymul() |
igor_v | 0:8ad47e2b6f00 | 270 | { |
igor_v | 21:bc8c1cec3da6 | 271 | int temp; |
igor_v | 21:bc8c1cec3da6 | 272 | temp =((BuffTemp[4]<<8) | BuffTemp[5]); |
igor_v | 21:bc8c1cec3da6 | 273 | // temp=0; |
igor_v | 21:bc8c1cec3da6 | 274 | temp=temp&0xFFFF; |
igor_v | 21:bc8c1cec3da6 | 275 | DACF =(temp*K_DAC)+deltaDAC; |
igor_v | 21:bc8c1cec3da6 | 276 | Spi.DAC_B =(unsigned int)(DACF) /*(unsigned int)(temp*K_DAC+deltaDAC)*/; // K_DAC); |
igor_v | 21:bc8c1cec3da6 | 277 | |
igor_v | 21:bc8c1cec3da6 | 278 | //int temp; |
igor_v | 0:8ad47e2b6f00 | 279 | // temp =((BuffTemp[4]<<8) | BuffTemp[5]); |
igor_v | 21:bc8c1cec3da6 | 280 | //temp = 65535 - temp; |
igor_v | 21:bc8c1cec3da6 | 281 | /*if(temp<1000) |
igor_v | 21:bc8c1cec3da6 | 282 | { |
igor_v | 21:bc8c1cec3da6 | 283 | temp=0; |
igor_v | 21:bc8c1cec3da6 | 284 | } |
igor_v | 21:bc8c1cec3da6 | 285 | else if(temp>60000) |
igor_v | 21:bc8c1cec3da6 | 286 | { |
igor_v | 21:bc8c1cec3da6 | 287 | temp=65535; |
igor_v | 21:bc8c1cec3da6 | 288 | }*/ |
igor_v | 21:bc8c1cec3da6 | 289 | //Spi.DAC_B =(((BuffTemp[4]<<8) | BuffTemp[5])*K_DAC+deltaDAC);/*((BuffTemp[4]<<8) | BuffTemp[5])-0xFFFF*///; //((rcv_buf[4] << 8) | (int)rcv_buf[5]);K_DAC+deltaDAC |
igor_v | 21:bc8c1cec3da6 | 290 | //BuffTemp[0] = temp; //DD |
igor_v | 21:bc8c1cec3da6 | 291 | //WriteConN (BuffTemp,1); |
igor_v | 0:8ad47e2b6f00 | 292 | } |
igor_v | 0:8ad47e2b6f00 | 293 | |
igor_v | 0:8ad47e2b6f00 | 294 | unsigned int Check(char *c, unsigned int Count) |
igor_v | 0:8ad47e2b6f00 | 295 | { |
igor_v | 21:bc8c1cec3da6 | 296 | int i=1; |
igor_v | 21:bc8c1cec3da6 | 297 | unsigned int temp,CRC; |
igor_v | 21:bc8c1cec3da6 | 298 | |
igor_v | 21:bc8c1cec3da6 | 299 | |
igor_v | 21:bc8c1cec3da6 | 300 | temp=1; |
igor_v | 21:bc8c1cec3da6 | 301 | CRC=0; |
igor_v | 21:bc8c1cec3da6 | 302 | |
igor_v | 21:bc8c1cec3da6 | 303 | |
igor_v | 21:bc8c1cec3da6 | 304 | for(; i<Count-2; i++) { |
igor_v | 21:bc8c1cec3da6 | 305 | CRC+=c[i]; |
igor_v | 21:bc8c1cec3da6 | 306 | } |
igor_v | 0:8ad47e2b6f00 | 307 | |
igor_v | 21:bc8c1cec3da6 | 308 | if(c[Count-2]!=((CRC>>8)&0xFF)) { |
igor_v | 21:bc8c1cec3da6 | 309 | temp=0; |
igor_v | 21:bc8c1cec3da6 | 310 | Main.RsErrLine = (Main.RsErrLine)&=0x2; |
igor_v | 21:bc8c1cec3da6 | 311 | } |
igor_v | 0:8ad47e2b6f00 | 312 | |
igor_v | 21:bc8c1cec3da6 | 313 | if(c[Count-1]!=((CRC>>0)&0xFF)) { |
igor_v | 21:bc8c1cec3da6 | 314 | temp=0; |
igor_v | 0:8ad47e2b6f00 | 315 | // Main.RsErrLine= (Main.RsErrLine)=0x2; |
igor_v | 21:bc8c1cec3da6 | 316 | } |
igor_v | 21:bc8c1cec3da6 | 317 | |
igor_v | 21:bc8c1cec3da6 | 318 | c[Count-2]=(CRC>>8)&0xFF; |
igor_v | 21:bc8c1cec3da6 | 319 | c[Count-1]=(CRC>>0)&0xFF; |
igor_v | 21:bc8c1cec3da6 | 320 | |
igor_v | 21:bc8c1cec3da6 | 321 | |
igor_v | 21:bc8c1cec3da6 | 322 | |
igor_v | 21:bc8c1cec3da6 | 323 | return temp; |
igor_v | 0:8ad47e2b6f00 | 324 | } |
igor_v | 0:8ad47e2b6f00 | 325 | |
igor_v | 0:8ad47e2b6f00 | 326 | int Getlengf(void) |
igor_v | 0:8ad47e2b6f00 | 327 | { |
igor_v | 21:bc8c1cec3da6 | 328 | unsigned int lengf=0; |
igor_v | 21:bc8c1cec3da6 | 329 | switch(Main.CMD_In) { |
igor_v | 21:bc8c1cec3da6 | 330 | case 0x99://maintainance |
igor_v | 21:bc8c1cec3da6 | 331 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 332 | CRC_N=8; |
igor_v | 21:bc8c1cec3da6 | 333 | break; |
igor_v | 0:8ad47e2b6f00 | 334 | |
igor_v | 21:bc8c1cec3da6 | 335 | case 0x0A: //m_stymul |
igor_v | 21:bc8c1cec3da6 | 336 | lengf=8; |
igor_v | 21:bc8c1cec3da6 | 337 | break; |
igor_v | 21:bc8c1cec3da6 | 338 | |
igor_v | 21:bc8c1cec3da6 | 339 | case 0xA5://DeviceMode |
igor_v | 21:bc8c1cec3da6 | 340 | |
igor_v | 21:bc8c1cec3da6 | 341 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 342 | CRC_N=8; |
igor_v | 21:bc8c1cec3da6 | 343 | break; |
igor_v | 21:bc8c1cec3da6 | 344 | |
igor_v | 21:bc8c1cec3da6 | 345 | case 0xDD://m_rate |
igor_v | 0:8ad47e2b6f00 | 346 | |
igor_v | 21:bc8c1cec3da6 | 347 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 348 | CRC_N=44; |
igor_v | 21:bc8c1cec3da6 | 349 | break; |
igor_v | 21:bc8c1cec3da6 | 350 | |
igor_v | 21:bc8c1cec3da6 | 351 | case 0xB0://DeviceMode |
igor_v | 21:bc8c1cec3da6 | 352 | |
igor_v | 21:bc8c1cec3da6 | 353 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 354 | CRC_N=8; |
igor_v | 21:bc8c1cec3da6 | 355 | break; |
igor_v | 21:bc8c1cec3da6 | 356 | |
igor_v | 21:bc8c1cec3da6 | 357 | case 0xD8://m_control |
igor_v | 0:8ad47e2b6f00 | 358 | |
igor_v | 21:bc8c1cec3da6 | 359 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 360 | CRC_N=8; |
igor_v | 21:bc8c1cec3da6 | 361 | break; |
igor_v | 21:bc8c1cec3da6 | 362 | |
igor_v | 21:bc8c1cec3da6 | 363 | case 0xD9://m_control |
igor_v | 0:8ad47e2b6f00 | 364 | |
igor_v | 21:bc8c1cec3da6 | 365 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 366 | CRC_N=8; |
igor_v | 21:bc8c1cec3da6 | 367 | break; |
igor_v | 21:bc8c1cec3da6 | 368 | } |
igor_v | 21:bc8c1cec3da6 | 369 | return lengf; |
igor_v | 0:8ad47e2b6f00 | 370 | } |
igor_v | 0:8ad47e2b6f00 | 371 | |
igor_v | 0:8ad47e2b6f00 | 372 | void Read_CMD(void) |
igor_v | 21:bc8c1cec3da6 | 373 | { |
igor_v | 21:bc8c1cec3da6 | 374 | Main.SOC_Out=0xDD; |
igor_v | 21:bc8c1cec3da6 | 375 | Main.RsErrLine = (Main.RsErrLine)& 0xffff; |
igor_v | 21:bc8c1cec3da6 | 376 | |
igor_v | 21:bc8c1cec3da6 | 377 | |
igor_v | 21:bc8c1cec3da6 | 378 | CountBuFFIn=ReadChekCon(BuffTemp); |
igor_v | 21:bc8c1cec3da6 | 379 | if(CountBuFFIn==1) { |
igor_v | 21:bc8c1cec3da6 | 380 | if (BuffTemp[0] != SOC_In) { |
igor_v | 21:bc8c1cec3da6 | 381 | ReadCon(BuffTemp); |
igor_v | 21:bc8c1cec3da6 | 382 | Main.RsErrLine += 0x100;//WriteCon("\n\r ...Error.... "); |
igor_v | 21:bc8c1cec3da6 | 383 | BuffTemp[99]=Main.RsErrLine; |
igor_v | 21:bc8c1cec3da6 | 384 | } |
igor_v | 21:bc8c1cec3da6 | 385 | } else if(CountBuFFIn==2) { |
igor_v | 21:bc8c1cec3da6 | 386 | if (BuffTemp[1] != Main.My_Addres) { |
igor_v | 21:bc8c1cec3da6 | 387 | ReadCon(BuffTemp); |
igor_v | 21:bc8c1cec3da6 | 388 | Main.RsErrLine += 0x1;//WriteCon("\n\r ...Error_ADDRES.... "); |
igor_v | 21:bc8c1cec3da6 | 389 | } |
igor_v | 21:bc8c1cec3da6 | 390 | } else if(CountBuFFIn==3) { |
igor_v | 21:bc8c1cec3da6 | 391 | Main.CMD_In=BuffTemp[2]; |
igor_v | 21:bc8c1cec3da6 | 392 | N=Getlengf(); |
igor_v | 21:bc8c1cec3da6 | 393 | } else if(CountBuFFIn==4 && N==6) { |
igor_v | 21:bc8c1cec3da6 | 394 | Param1=BuffTemp[3]; |
igor_v | 21:bc8c1cec3da6 | 395 | } else if((CountBuFFIn==5)&&(N==7)) { |
igor_v | 21:bc8c1cec3da6 | 396 | //LoopOn |
igor_v | 21:bc8c1cec3da6 | 397 | Param1=BuffTemp[3]; |
igor_v | 21:bc8c1cec3da6 | 398 | Param2=BuffTemp[4]; |
igor_v | 0:8ad47e2b6f00 | 399 | |
igor_v | 21:bc8c1cec3da6 | 400 | } else if((CountBuFFIn==6)&&(N==8)) { |
igor_v | 21:bc8c1cec3da6 | 401 | Param1=BuffTemp[3]; |
igor_v | 21:bc8c1cec3da6 | 402 | Param2=BuffTemp[4]; |
igor_v | 21:bc8c1cec3da6 | 403 | Param3=BuffTemp[5]; |
igor_v | 21:bc8c1cec3da6 | 404 | } else if(CountBuFFIn > (N-1)) { |
igor_v | 21:bc8c1cec3da6 | 405 | ReadCon(BuffTemp); |
igor_v | 21:bc8c1cec3da6 | 406 | if(Check(BuffTemp, CountBuFFIn)) { |
igor_v | 21:bc8c1cec3da6 | 407 | switch(Main.CMD_In) { |
igor_v | 21:bc8c1cec3da6 | 408 | case CMD_MAINT: |
igor_v | 21:bc8c1cec3da6 | 409 | CMD_Maintenance(); |
igor_v | 21:bc8c1cec3da6 | 410 | break; |
igor_v | 21:bc8c1cec3da6 | 411 | case 0xD8: |
igor_v | 21:bc8c1cec3da6 | 412 | CMD_M_Control_D8(); |
igor_v | 21:bc8c1cec3da6 | 413 | case 0xD9: |
igor_v | 21:bc8c1cec3da6 | 414 | CMD_M_Control_D9(); |
igor_v | 21:bc8c1cec3da6 | 415 | break; |
igor_v | 21:bc8c1cec3da6 | 416 | case 0x0A: |
igor_v | 21:bc8c1cec3da6 | 417 | CMD_M_Stymul(Param1,Param2,Param3); |
igor_v | 21:bc8c1cec3da6 | 418 | break; |
igor_v | 21:bc8c1cec3da6 | 419 | case 0xDD: |
igor_v | 21:bc8c1cec3da6 | 420 | Rate_Flag=1; |
igor_v | 21:bc8c1cec3da6 | 421 | break; |
igor_v | 21:bc8c1cec3da6 | 422 | Main.RsErrLine = 0; |
igor_v | 21:bc8c1cec3da6 | 423 | } |
igor_v | 21:bc8c1cec3da6 | 424 | |
igor_v | 0:8ad47e2b6f00 | 425 | } |
igor_v | 21:bc8c1cec3da6 | 426 | } |
igor_v | 0:8ad47e2b6f00 | 427 | } |
igor_v | 0:8ad47e2b6f00 | 428 | |
igor_v | 0:8ad47e2b6f00 | 429 | |
igor_v | 21:bc8c1cec3da6 | 430 |