123
Fork of LG by
Command.c@108:030cdde08314, 2016-04-02 (annotated)
- Committer:
- Kovalev_D
- Date:
- Sat Apr 02 11:15:38 2016 +0000
- Revision:
- 108:030cdde08314
- Parent:
- 107:4d178bcc9d8a
- Child:
- 112:4a96133a1311
1;
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 "Global.h" |
Kovalev_D | 106:250ddd8629c6 | 4 | int tempNH,tempNL; |
igor_v | 0:8ad47e2b6f00 | 5 | unsigned int Rate_Flag; |
igor_v | 0:8ad47e2b6f00 | 6 | unsigned int CountBuFFIn; |
igor_v | 21:bc8c1cec3da6 | 7 | unsigned int N=0,CRC_N; |
igor_v | 21:bc8c1cec3da6 | 8 | unsigned int Param1=0; |
igor_v | 21:bc8c1cec3da6 | 9 | unsigned int Param2=0; |
igor_v | 21:bc8c1cec3da6 | 10 | unsigned int Param3=0; |
igor_v | 21:bc8c1cec3da6 | 11 | unsigned int Param4=0; |
Kovalev_D | 102:4270092be987 | 12 | unsigned int Consol=123; |
igor_v | 0:8ad47e2b6f00 | 13 | /* |
igor_v | 21:bc8c1cec3da6 | 14 | void exec_CMD(void) //r. === процедура окончательной дешифрации и исполнения команды |
igor_v | 0:8ad47e2b6f00 | 15 | { |
igor_v | 0:8ad47e2b6f00 | 16 | unsigned int Comand_code; |
igor_v | 21:bc8c1cec3da6 | 17 | |
igor_v | 21:bc8c1cec3da6 | 18 | //rx_buf_copy = 1; //r. предустанов флага копирования приемного буфера |
igor_v | 0:8ad47e2b6f00 | 19 | |
igor_v | 0:8ad47e2b6f00 | 20 | Comand_code = (rcv_buf[2] & 0xFF) << 8; |
igor_v | 21:bc8c1cec3da6 | 21 | PC_Comand = Comand_code | (rcv_buf[3] & 0xFF); //e. save it in the memory for echo-transmission //r. сохранить его в памяти для обратной передачи |
igor_v | 0:8ad47e2b6f00 | 22 | }*/ |
igor_v | 0:8ad47e2b6f00 | 23 | void CMD_Maintenance(void) |
igor_v | 0:8ad47e2b6f00 | 24 | { |
igor_v | 28:17c84ed091b3 | 25 | BuffTemp[0] = Gyro.SOC_Out; |
igor_v | 28:17c84ed091b3 | 26 | BuffTemp[1] = Gyro .My_Addres; |
igor_v | 28:17c84ed091b3 | 27 | BuffTemp[2] = Gyro .Firmware_Version; |
igor_v | 28:17c84ed091b3 | 28 | BuffTemp[3] = Gyro .GLD_Serial; |
igor_v | 21:bc8c1cec3da6 | 29 | BuffTemp[4]=0x00; |
igor_v | 21:bc8c1cec3da6 | 30 | BuffTemp[5]=0x00; |
igor_v | 21:bc8c1cec3da6 | 31 | Check(BuffTemp, 8); |
igor_v | 21:bc8c1cec3da6 | 32 | WriteConN (BuffTemp,8); |
igor_v | 0:8ad47e2b6f00 | 33 | } |
igor_v | 0:8ad47e2b6f00 | 34 | |
igor_v | 0:8ad47e2b6f00 | 35 | void CMD_Rate(void) |
igor_v | 21:bc8c1cec3da6 | 36 | { |
Kovalev_D | 107:4d178bcc9d8a | 37 | |
Kovalev_D | 108:030cdde08314 | 38 | unsigned int Temp; |
Kovalev_D | 108:030cdde08314 | 39 | |
igor_v | 21:bc8c1cec3da6 | 40 | unsigned int Cnt_PlsL , Cnt_PlsH; // Счетчик +. |
igor_v | 21:bc8c1cec3da6 | 41 | unsigned int Cnt_MnsL , Cnt_MnsH; // Счетчик -. |
igor_v | 21:bc8c1cec3da6 | 42 | unsigned int Cnt_DifL , Cnt_DifH; // Разность счетчиков. |
igor_v | 21:bc8c1cec3da6 | 43 | unsigned int F_rasL , F_rasH; // Частота расщепления. |
igor_v | 21:bc8c1cec3da6 | 44 | |
Kovalev_D | 106:250ddd8629c6 | 45 | unsigned int HF_regL , HF_regH; // Выход регулятора ГВЧ. |
Kovalev_D | 106:250ddd8629c6 | 46 | unsigned int HF_difL , HF_difH; // Сигнал ошибки регулячтора ГВЧ. |
igor_v | 21:bc8c1cec3da6 | 47 | |
igor_v | 21:bc8c1cec3da6 | 48 | unsigned int WP_regL , WP_regH; |
igor_v | 21:bc8c1cec3da6 | 49 | |
igor_v | 21:bc8c1cec3da6 | 50 | unsigned int ADC1L, ADC2L, ADC3L, ADC4L, ADC5L; |
igor_v | 21:bc8c1cec3da6 | 51 | unsigned int ADC1H, ADC2H, ADC3H, ADC4H, ADC5H; |
Kovalev_D | 106:250ddd8629c6 | 52 | |
Kovalev_D | 108:030cdde08314 | 53 | |
Kovalev_D | 107:4d178bcc9d8a | 54 | |
igor_v | 28:17c84ed091b3 | 55 | Gyro.Firmware_Version=0xff; /// промежуточная затычка |
igor_v | 21:bc8c1cec3da6 | 56 | |
Kovalev_D | 108:030cdde08314 | 57 | |
Kovalev_D | 108:030cdde08314 | 58 | |
Kovalev_D | 106:250ddd8629c6 | 59 | |
igor_v | 28:17c84ed091b3 | 60 | Cnt_PlsH = ( Gyro.Cnt_Pls>>8) TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 61 | Cnt_PlsL = Gyro.Cnt_Pls TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 62 | Gyro.Cnt_Pls= 0; |
Kovalev_D | 106:250ddd8629c6 | 63 | |
igor_v | 28:17c84ed091b3 | 64 | Cnt_MnsH = ( Gyro.Cnt_Mns>>8) TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 65 | Cnt_MnsL = Gyro.Cnt_Mns TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 66 | Gyro.Cnt_Mns=0; |
Kovalev_D | 106:250ddd8629c6 | 67 | |
Kovalev_D | 106:250ddd8629c6 | 68 | Cnt_DifH = ( Dif_QEI>>8) TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 69 | Cnt_DifL = ( Dif_QEI ) TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 70 | |
Kovalev_D | 106:250ddd8629c6 | 71 | //Spi.DAC_A |
igor_v | 28:17c84ed091b3 | 72 | F_rasH = ( Gyro.F_ras>>8 ) TakeByte; |
igor_v | 28:17c84ed091b3 | 73 | F_rasL = ( Gyro.F_ras ) TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 74 | |
Kovalev_D | 107:4d178bcc9d8a | 75 | HF_regL = ( Spi.DAC_A ) TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 76 | HF_regH = ( Spi.DAC_A>>8 ) TakeByte; |
Kovalev_D | 107:4d178bcc9d8a | 77 | |
Kovalev_D | 107:4d178bcc9d8a | 78 | WP_regH = ( Spi.DAC_A>>8 ) TakeByte; |
Kovalev_D | 107:4d178bcc9d8a | 79 | WP_regL = ( Spi.DAC_A ) TakeByte; |
Kovalev_D | 106:250ddd8629c6 | 80 | |
igor_v | 21:bc8c1cec3da6 | 81 | ADC1H = ( Spi.ADC1>>8 ) TakeByte; |
Kovalev_D | 45:cbc955aecebe | 82 | ADC1L = ( Spi.ADC1 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 83 | |
igor_v | 21:bc8c1cec3da6 | 84 | ADC2H = ( Spi.ADC2>>8 ) TakeByte; |
Kovalev_D | 45:cbc955aecebe | 85 | ADC2L = ( Spi.ADC2 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 86 | |
igor_v | 21:bc8c1cec3da6 | 87 | ADC3H = ( Spi.ADC3>>8 ) TakeByte; |
Kovalev_D | 45:cbc955aecebe | 88 | ADC3L = ( Spi.ADC3 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 89 | |
igor_v | 21:bc8c1cec3da6 | 90 | ADC4H = ( Spi.ADC4>>8 ) TakeByte; |
Kovalev_D | 45:cbc955aecebe | 91 | ADC4L = ( Spi.ADC4 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 92 | |
igor_v | 21:bc8c1cec3da6 | 93 | ADC5H = ( Spi.ADC5>>8 ) TakeByte; |
Kovalev_D | 45:cbc955aecebe | 94 | ADC5L = ( Spi.ADC5 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 95 | |
igor_v | 21:bc8c1cec3da6 | 96 | WP_regH = ( Spi.DAC_B>>8 ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 97 | WP_regL = ( Spi.DAC_B ) TakeByte; |
igor_v | 21:bc8c1cec3da6 | 98 | |
igor_v | 21:bc8c1cec3da6 | 99 | HF_regH=0xff; |
igor_v | 21:bc8c1cec3da6 | 100 | HF_regL=0xff; |
igor_v | 21:bc8c1cec3da6 | 101 | |
igor_v | 21:bc8c1cec3da6 | 102 | HF_difH=0xff; |
igor_v | 21:bc8c1cec3da6 | 103 | HF_difL=0xff; |
igor_v | 21:bc8c1cec3da6 | 104 | |
igor_v | 0:8ad47e2b6f00 | 105 | |
igor_v | 28:17c84ed091b3 | 106 | BuffTemp[ 0] = Gyro.SOC_Out; |
igor_v | 28:17c84ed091b3 | 107 | BuffTemp[ 1] = Gyro.My_Addres; |
igor_v | 21:bc8c1cec3da6 | 108 | |
Kovalev_D | 108:030cdde08314 | 109 | |
Kovalev_D | 108:030cdde08314 | 110 | BuffTemp[ 2] =(CaunPlus >> 8) & 0xff;//старший байт счетчика +. |
Kovalev_D | 108:030cdde08314 | 111 | BuffTemp[ 3] =(CaunPlus >> 0) & 0xff;//младший байт счетчика +. |
Kovalev_D | 108:030cdde08314 | 112 | |
Kovalev_D | 108:030cdde08314 | 113 | BuffTemp[ 4] =(CaunMin >> 8) & 0xff;//старший байт счетчика -. |
Kovalev_D | 108:030cdde08314 | 114 | BuffTemp[ 5] =(CaunMin >> 0) & 0xff;//младший байт счетчика -. |
Kovalev_D | 108:030cdde08314 | 115 | |
Kovalev_D | 108:030cdde08314 | 116 | |
Kovalev_D | 108:030cdde08314 | 117 | |
Kovalev_D | 108:030cdde08314 | 118 | Temp = Gyro.CuruAngle; |
Kovalev_D | 108:030cdde08314 | 119 | Gyro.CuruAngle = 0; |
Kovalev_D | 108:030cdde08314 | 120 | |
Kovalev_D | 108:030cdde08314 | 121 | |
Kovalev_D | 108:030cdde08314 | 122 | BuffTemp[ 6] =(Temp >> 8) & 0xff;//старший байт разности счетчиков |
Kovalev_D | 108:030cdde08314 | 123 | BuffTemp[ 7] =(Temp >> 0) & 0xff;//младший байт разности счетчиков |
Kovalev_D | 108:030cdde08314 | 124 | |
Kovalev_D | 108:030cdde08314 | 125 | |
Kovalev_D | 108:030cdde08314 | 126 | |
igor_v | 21:bc8c1cec3da6 | 127 | |
Kovalev_D | 106:250ddd8629c6 | 128 | BuffTemp[ 8] = F_rasH;//расщипление частота |
Kovalev_D | 106:250ddd8629c6 | 129 | BuffTemp[ 9] = F_rasL;// |
igor_v | 21:bc8c1cec3da6 | 130 | |
Kovalev_D | 108:030cdde08314 | 131 | BuffTemp[10] = (Temp >> 8) & 0xff;//выход регулятора гвч; |
Kovalev_D | 108:030cdde08314 | 132 | BuffTemp[11] = (Temp >> 0) & 0xff;; |
igor_v | 21:bc8c1cec3da6 | 133 | |
Kovalev_D | 108:030cdde08314 | 134 | BuffTemp[12]=(Temp >> 8) & 0xff;//// |
Kovalev_D | 108:030cdde08314 | 135 | BuffTemp[13]=(Temp >> 0) & 0xff;//// |
igor_v | 21:bc8c1cec3da6 | 136 | |
Kovalev_D | 108:030cdde08314 | 137 | |
Kovalev_D | 108:030cdde08314 | 138 | Temp = (unsigned int)((7680000*16/(Gyro.Frq>>12))); |
Kovalev_D | 108:030cdde08314 | 139 | BuffTemp[14] = (Temp >> 8) & 0xff; |
Kovalev_D | 108:030cdde08314 | 140 | BuffTemp[15] = (Temp >> 0) & 0xff; |
igor_v | 21:bc8c1cec3da6 | 141 | |
Kovalev_D | 107:4d178bcc9d8a | 142 | BuffTemp[16] = 0xf; |
Kovalev_D | 106:250ddd8629c6 | 143 | BuffTemp[17] = 0x02; |
Kovalev_D | 108:030cdde08314 | 144 | |
igor_v | 21:bc8c1cec3da6 | 145 | |
Kovalev_D | 108:030cdde08314 | 146 | Temp = (unsigned int)(((7680000*16/200) *Gyro.AmpPer /(Gyro.Frq>>12))); |
Kovalev_D | 108:030cdde08314 | 147 | BuffTemp[18] = (Temp >> 8) & 0xff; |
Kovalev_D | 108:030cdde08314 | 148 | BuffTemp[19] = (Temp >> 0) & 0xff; |
igor_v | 21:bc8c1cec3da6 | 149 | |
Kovalev_D | 106:250ddd8629c6 | 150 | BuffTemp[20] = 0x00; |
Kovalev_D | 106:250ddd8629c6 | 151 | BuffTemp[21] = 0x00; |
Kovalev_D | 108:030cdde08314 | 152 | Temp = Spi.DAC_B ; |
Kovalev_D | 108:030cdde08314 | 153 | BuffTemp[22] = (Temp >> 8) & 0xff; |
Kovalev_D | 108:030cdde08314 | 154 | BuffTemp[23] = (Temp >> 0) & 0xff; |
igor_v | 21:bc8c1cec3da6 | 155 | |
Kovalev_D | 106:250ddd8629c6 | 156 | BuffTemp[24] = 0x00; |
Kovalev_D | 106:250ddd8629c6 | 157 | BuffTemp[25] = 0x00;// ХЗ |
igor_v | 21:bc8c1cec3da6 | 158 | |
Kovalev_D | 106:250ddd8629c6 | 159 | BuffTemp[26] = ADC1H; |
Kovalev_D | 106:250ddd8629c6 | 160 | BuffTemp[27] = ADC1L; |
igor_v | 21:bc8c1cec3da6 | 161 | |
Kovalev_D | 106:250ddd8629c6 | 162 | BuffTemp[28] = ADC2H; |
Kovalev_D | 106:250ddd8629c6 | 163 | BuffTemp[29] = ADC2L; |
igor_v | 21:bc8c1cec3da6 | 164 | |
Kovalev_D | 106:250ddd8629c6 | 165 | BuffTemp[30] = ADC2H;//in1 |
Kovalev_D | 106:250ddd8629c6 | 166 | BuffTemp[31] = ADC2L; |
igor_v | 21:bc8c1cec3da6 | 167 | |
Kovalev_D | 106:250ddd8629c6 | 168 | BuffTemp[32] = ADC3H; |
Kovalev_D | 106:250ddd8629c6 | 169 | BuffTemp[33] = ADC3L;//in2 |
igor_v | 21:bc8c1cec3da6 | 170 | |
Kovalev_D | 106:250ddd8629c6 | 171 | BuffTemp[34] = ADC5H; |
Kovalev_D | 106:250ddd8629c6 | 172 | BuffTemp[35] = ADC5L; |
igor_v | 21:bc8c1cec3da6 | 173 | |
Kovalev_D | 106:250ddd8629c6 | 174 | BuffTemp[36] =0x00;//ADC6 |
Kovalev_D | 106:250ddd8629c6 | 175 | BuffTemp[37] =0x00;//ADC6 |
igor_v | 21:bc8c1cec3da6 | 176 | |
Kovalev_D | 106:250ddd8629c6 | 177 | BuffTemp[38] =0x00; |
Kovalev_D | 106:250ddd8629c6 | 178 | BuffTemp[39] =0x00; |
Kovalev_D | 106:250ddd8629c6 | 179 | BuffTemp[40] =0x00; |
Kovalev_D | 106:250ddd8629c6 | 180 | BuffTemp[41] =0x00; |
igor_v | 21:bc8c1cec3da6 | 181 | |
igor_v | 21:bc8c1cec3da6 | 182 | |
igor_v | 21:bc8c1cec3da6 | 183 | Check(BuffTemp, 44); |
igor_v | 21:bc8c1cec3da6 | 184 | WriteConN (BuffTemp,44); |
Kovalev_D | 92:c892f0311aa7 | 185 | |
igor_v | 0:8ad47e2b6f00 | 186 | } |
igor_v | 0:8ad47e2b6f00 | 187 | |
igor_v | 21:bc8c1cec3da6 | 188 | void CMD_M_Control_D8()///установка\сброс регистров управления |
igor_v | 21:bc8c1cec3da6 | 189 | { |
Kovalev_D | 104:ab1cb4ff56b2 | 190 | unsigned int bit,NReg,Pa; |
Kovalev_D | 104:ab1cb4ff56b2 | 191 | unsigned int SR,V,A,Bit_num; |
Kovalev_D | 104:ab1cb4ff56b2 | 192 | SR=0; |
Kovalev_D | 104:ab1cb4ff56b2 | 193 | V=0; |
Kovalev_D | 104:ab1cb4ff56b2 | 194 | A=0; |
Kovalev_D | 104:ab1cb4ff56b2 | 195 | Bit_num=0; |
Kovalev_D | 104:ab1cb4ff56b2 | 196 | |
igor_v | 28:17c84ed091b3 | 197 | BuffTemp[0] = Gyro.SOC_Out; //DD |
igor_v | 28:17c84ed091b3 | 198 | BuffTemp[1] = Gyro.My_Addres; //00 |
igor_v | 28:17c84ed091b3 | 199 | BuffTemp[2] = Gyro.CMD_In; //D8 |
Kovalev_D | 104:ab1cb4ff56b2 | 200 | |
Kovalev_D | 104:ab1cb4ff56b2 | 201 | /* |
Kovalev_D | 104:ab1cb4ff56b2 | 202 | |
Kovalev_D | 104:ab1cb4ff56b2 | 203 | FrqON |
Kovalev_D | 104:ab1cb4ff56b2 | 204 | PlcON |
Kovalev_D | 104:ab1cb4ff56b2 | 205 | HFOOFF |
Kovalev_D | 104:ab1cb4ff56b2 | 206 | HFOON |
igor_v | 21:bc8c1cec3da6 | 207 | |
Kovalev_D | 104:ab1cb4ff56b2 | 208 | PlcOFF |
Kovalev_D | 104:ab1cb4ff56b2 | 209 | PlcON |
Kovalev_D | 104:ab1cb4ff56b2 | 210 | */ |
Kovalev_D | 104:ab1cb4ff56b2 | 211 | Pa = BuffTemp[3]; |
Kovalev_D | 104:ab1cb4ff56b2 | 212 | |
Kovalev_D | 104:ab1cb4ff56b2 | 213 | SR = Pa >> 0x7; |
Kovalev_D | 104:ab1cb4ff56b2 | 214 | |
Kovalev_D | 104:ab1cb4ff56b2 | 215 | V = Pa >> 0x5; |
Kovalev_D | 104:ab1cb4ff56b2 | 216 | V = V & 0x3; |
Kovalev_D | 104:ab1cb4ff56b2 | 217 | |
Kovalev_D | 104:ab1cb4ff56b2 | 218 | A = Pa >> 0x4; |
Kovalev_D | 104:ab1cb4ff56b2 | 219 | A = A & 0x1; |
Kovalev_D | 104:ab1cb4ff56b2 | 220 | |
Kovalev_D | 104:ab1cb4ff56b2 | 221 | Bit_num = Pa & 0xf; |
Kovalev_D | 104:ab1cb4ff56b2 | 222 | |
Kovalev_D | 104:ab1cb4ff56b2 | 223 | if(SR) { |
Kovalev_D | 104:ab1cb4ff56b2 | 224 | switch (Bit_num){ |
Kovalev_D | 105:bd01d8d20fb6 | 225 | |
Kovalev_D | 104:ab1cb4ff56b2 | 226 | case 0x06: |
Kovalev_D | 104:ab1cb4ff56b2 | 227 | FrqON |
Kovalev_D | 105:bd01d8d20fb6 | 228 | break; |
Kovalev_D | 105:bd01d8d20fb6 | 229 | |
Kovalev_D | 104:ab1cb4ff56b2 | 230 | case 0x03: |
Kovalev_D | 105:bd01d8d20fb6 | 231 | HFOON |
Kovalev_D | 105:bd01d8d20fb6 | 232 | break; |
Kovalev_D | 105:bd01d8d20fb6 | 233 | |
Kovalev_D | 105:bd01d8d20fb6 | 234 | case 0x01: |
Kovalev_D | 105:bd01d8d20fb6 | 235 | PlcON |
Kovalev_D | 105:bd01d8d20fb6 | 236 | break; |
Kovalev_D | 104:ab1cb4ff56b2 | 237 | } |
Kovalev_D | 104:ab1cb4ff56b2 | 238 | } |
Kovalev_D | 104:ab1cb4ff56b2 | 239 | else{ |
Kovalev_D | 104:ab1cb4ff56b2 | 240 | switch (Bit_num){ |
Kovalev_D | 105:bd01d8d20fb6 | 241 | |
Kovalev_D | 105:bd01d8d20fb6 | 242 | case 0x06: |
Kovalev_D | 104:ab1cb4ff56b2 | 243 | FrqOff |
Kovalev_D | 105:bd01d8d20fb6 | 244 | break; |
Kovalev_D | 105:bd01d8d20fb6 | 245 | |
Kovalev_D | 105:bd01d8d20fb6 | 246 | case 0x03: |
Kovalev_D | 105:bd01d8d20fb6 | 247 | HFOOFF |
Kovalev_D | 105:bd01d8d20fb6 | 248 | break; |
Kovalev_D | 105:bd01d8d20fb6 | 249 | |
Kovalev_D | 105:bd01d8d20fb6 | 250 | case 0x01: |
Kovalev_D | 105:bd01d8d20fb6 | 251 | PlcOFF |
Kovalev_D | 105:bd01d8d20fb6 | 252 | break; |
Kovalev_D | 104:ab1cb4ff56b2 | 253 | } |
Kovalev_D | 104:ab1cb4ff56b2 | 254 | } |
igor_v | 21:bc8c1cec3da6 | 255 | |
igor_v | 0:8ad47e2b6f00 | 256 | } |
igor_v | 0:8ad47e2b6f00 | 257 | |
igor_v | 21:bc8c1cec3da6 | 258 | void CMD_M_Control_D9()///чтение регистров управления |
igor_v | 21:bc8c1cec3da6 | 259 | { |
igor_v | 21:bc8c1cec3da6 | 260 | int bit,NReg; |
igor_v | 28:17c84ed091b3 | 261 | BuffTemp[0] = Gyro.SOC_Out; //DD |
igor_v | 28:17c84ed091b3 | 262 | BuffTemp[1] = Gyro.My_Addres; //00 |
igor_v | 28:17c84ed091b3 | 263 | BuffTemp[2] = Gyro.CMD_In; //D9 |
igor_v | 21:bc8c1cec3da6 | 264 | if ((Param1 & 0x10) == 0) { |
igor_v | 21:bc8c1cec3da6 | 265 | BuffTemp[3]=0<<4; |
igor_v | 28:17c84ed091b3 | 266 | BuffTemp[4] = (Gyro.RgConA>>8 )& 0xff; |
igor_v | 28:17c84ed091b3 | 267 | BuffTemp[5] = Gyro.RgConA & 0xff; |
igor_v | 21:bc8c1cec3da6 | 268 | } else { |
igor_v | 21:bc8c1cec3da6 | 269 | BuffTemp[3]=1<<4; |
igor_v | 28:17c84ed091b3 | 270 | BuffTemp[4] = (Gyro.RgConB>>8 ) & 0xff; |
igor_v | 28:17c84ed091b3 | 271 | BuffTemp[5] = Gyro.RgConB & 0xff; |
igor_v | 21:bc8c1cec3da6 | 272 | } |
igor_v | 21:bc8c1cec3da6 | 273 | Check(BuffTemp, CRC_N); |
igor_v | 21:bc8c1cec3da6 | 274 | WriteConN (BuffTemp,CRC_N); |
igor_v | 21:bc8c1cec3da6 | 275 | } |
igor_v | 21:bc8c1cec3da6 | 276 | // (номер (код) ЦАПа 0...3, старший байт требуемого ЦАПа, младший байт треб ЦАПа) |
igor_v | 0:8ad47e2b6f00 | 277 | void CMD_M_Stymul() |
igor_v | 0:8ad47e2b6f00 | 278 | { |
igor_v | 21:bc8c1cec3da6 | 279 | int temp; |
Kovalev_D | 102:4270092be987 | 280 | int HFO; |
Kovalev_D | 102:4270092be987 | 281 | temp=BuffTemp[3]; |
Kovalev_D | 102:4270092be987 | 282 | Consol = temp&0x3; |
Kovalev_D | 103:e96f08947def | 283 | HFO = temp&0x3;// // (номер (код) ЦАПа 0...3, HFO - 3dac, PLC - 0DAC |
igor_v | 21:bc8c1cec3da6 | 284 | temp =((BuffTemp[4]<<8) | BuffTemp[5]); |
igor_v | 21:bc8c1cec3da6 | 285 | // temp=0; |
igor_v | 21:bc8c1cec3da6 | 286 | temp=temp&0xFFFF; |
Kovalev_D | 102:4270092be987 | 287 | |
Kovalev_D | 102:4270092be987 | 288 | if(HFO) |
Kovalev_D | 102:4270092be987 | 289 | { |
Kovalev_D | 102:4270092be987 | 290 | Spi.DAC_A=(unsigned int)temp; |
Kovalev_D | 102:4270092be987 | 291 | } |
Kovalev_D | 102:4270092be987 | 292 | else{ |
igor_v | 21:bc8c1cec3da6 | 293 | DACF =(temp*K_DAC)+deltaDAC; |
igor_v | 21:bc8c1cec3da6 | 294 | Spi.DAC_B =(unsigned int)(DACF) /*(unsigned int)(temp*K_DAC+deltaDAC)*/; // K_DAC); |
igor_v | 21:bc8c1cec3da6 | 295 | } |
igor_v | 0:8ad47e2b6f00 | 296 | } |
Kovalev_D | 103:e96f08947def | 297 | void Gph_W() |
Kovalev_D | 103:e96f08947def | 298 | { |
Kovalev_D | 108:030cdde08314 | 299 | Out_G_photo(BuffTemp[4],BuffTemp[5]); |
Kovalev_D | 103:e96f08947def | 300 | } |
igor_v | 0:8ad47e2b6f00 | 301 | |
Kovalev_D | 98:95b8e79f13e1 | 302 | void CMD_M_vib() |
Kovalev_D | 102:4270092be987 | 303 | { LoopOn |
Kovalev_D | 102:4270092be987 | 304 | unsigned int temp1,temp2; |
Kovalev_D | 102:4270092be987 | 305 | |
Kovalev_D | 102:4270092be987 | 306 | temp1 =((BuffTemp[4]<<8) | BuffTemp[5]); |
Kovalev_D | 102:4270092be987 | 307 | temp1=temp1&0xFFFF; |
Kovalev_D | 102:4270092be987 | 308 | |
Kovalev_D | 102:4270092be987 | 309 | temp2 =((BuffTemp[6]<<8) | BuffTemp[7]); |
Kovalev_D | 102:4270092be987 | 310 | temp2=temp2&0xFFFF; |
Kovalev_D | 102:4270092be987 | 311 | Gyro.Frq = ((unsigned int) ((7680000*16/temp1)))*16*16*16; |
Kovalev_D | 102:4270092be987 | 312 | Consol=Gyro.Frq ; |
Kovalev_D | 98:95b8e79f13e1 | 313 | } |
igor_v | 0:8ad47e2b6f00 | 314 | unsigned int Check(char *c, unsigned int Count) |
igor_v | 0:8ad47e2b6f00 | 315 | { |
igor_v | 21:bc8c1cec3da6 | 316 | int i=1; |
igor_v | 21:bc8c1cec3da6 | 317 | unsigned int temp,CRC; |
igor_v | 21:bc8c1cec3da6 | 318 | |
igor_v | 21:bc8c1cec3da6 | 319 | |
igor_v | 21:bc8c1cec3da6 | 320 | temp=1; |
igor_v | 21:bc8c1cec3da6 | 321 | CRC=0; |
igor_v | 21:bc8c1cec3da6 | 322 | |
igor_v | 21:bc8c1cec3da6 | 323 | |
igor_v | 21:bc8c1cec3da6 | 324 | for(; i<Count-2; i++) { |
igor_v | 21:bc8c1cec3da6 | 325 | CRC+=c[i]; |
igor_v | 21:bc8c1cec3da6 | 326 | } |
igor_v | 0:8ad47e2b6f00 | 327 | |
igor_v | 21:bc8c1cec3da6 | 328 | if(c[Count-2]!=((CRC>>8)&0xFF)) { |
igor_v | 21:bc8c1cec3da6 | 329 | temp=0; |
igor_v | 28:17c84ed091b3 | 330 | Gyro.RsErrLine = (Gyro.RsErrLine)&=0x2; |
igor_v | 21:bc8c1cec3da6 | 331 | } |
igor_v | 0:8ad47e2b6f00 | 332 | |
igor_v | 21:bc8c1cec3da6 | 333 | if(c[Count-1]!=((CRC>>0)&0xFF)) { |
igor_v | 21:bc8c1cec3da6 | 334 | temp=0; |
igor_v | 28:17c84ed091b3 | 335 | // Gyro.RsErrLine= (Gyro.RsErrLine)=0x2; |
igor_v | 21:bc8c1cec3da6 | 336 | } |
igor_v | 21:bc8c1cec3da6 | 337 | |
igor_v | 21:bc8c1cec3da6 | 338 | c[Count-2]=(CRC>>8)&0xFF; |
igor_v | 21:bc8c1cec3da6 | 339 | c[Count-1]=(CRC>>0)&0xFF; |
igor_v | 21:bc8c1cec3da6 | 340 | |
igor_v | 21:bc8c1cec3da6 | 341 | |
igor_v | 21:bc8c1cec3da6 | 342 | |
igor_v | 21:bc8c1cec3da6 | 343 | return temp; |
igor_v | 0:8ad47e2b6f00 | 344 | } |
igor_v | 0:8ad47e2b6f00 | 345 | |
igor_v | 0:8ad47e2b6f00 | 346 | int Getlengf(void) |
igor_v | 0:8ad47e2b6f00 | 347 | { |
igor_v | 21:bc8c1cec3da6 | 348 | unsigned int lengf=0; |
igor_v | 28:17c84ed091b3 | 349 | switch(Gyro.CMD_In) { |
igor_v | 28:17c84ed091b3 | 350 | case 0x99://Gyrotainance |
Kovalev_D | 92:c892f0311aa7 | 351 | |
igor_v | 21:bc8c1cec3da6 | 352 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 353 | CRC_N=8; |
igor_v | 21:bc8c1cec3da6 | 354 | break; |
igor_v | 0:8ad47e2b6f00 | 355 | |
igor_v | 21:bc8c1cec3da6 | 356 | case 0x0A: //m_stymul |
igor_v | 21:bc8c1cec3da6 | 357 | lengf=8; |
igor_v | 21:bc8c1cec3da6 | 358 | break; |
igor_v | 21:bc8c1cec3da6 | 359 | |
igor_v | 21:bc8c1cec3da6 | 360 | case 0xA5://DeviceMode |
igor_v | 21:bc8c1cec3da6 | 361 | |
igor_v | 21:bc8c1cec3da6 | 362 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 363 | CRC_N=8; |
igor_v | 21:bc8c1cec3da6 | 364 | break; |
igor_v | 21:bc8c1cec3da6 | 365 | |
igor_v | 21:bc8c1cec3da6 | 366 | case 0xDD://m_rate |
igor_v | 0:8ad47e2b6f00 | 367 | |
igor_v | 21:bc8c1cec3da6 | 368 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 369 | CRC_N=44; |
igor_v | 21:bc8c1cec3da6 | 370 | break; |
igor_v | 21:bc8c1cec3da6 | 371 | |
igor_v | 21:bc8c1cec3da6 | 372 | case 0xB0://DeviceMode |
igor_v | 21:bc8c1cec3da6 | 373 | |
igor_v | 21:bc8c1cec3da6 | 374 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 375 | CRC_N=8; |
igor_v | 21:bc8c1cec3da6 | 376 | break; |
igor_v | 21:bc8c1cec3da6 | 377 | |
igor_v | 21:bc8c1cec3da6 | 378 | case 0xD8://m_control |
igor_v | 0:8ad47e2b6f00 | 379 | |
igor_v | 21:bc8c1cec3da6 | 380 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 381 | CRC_N=8; |
igor_v | 21:bc8c1cec3da6 | 382 | break; |
igor_v | 21:bc8c1cec3da6 | 383 | |
igor_v | 21:bc8c1cec3da6 | 384 | case 0xD9://m_control |
igor_v | 0:8ad47e2b6f00 | 385 | |
igor_v | 21:bc8c1cec3da6 | 386 | lengf=6; |
igor_v | 21:bc8c1cec3da6 | 387 | CRC_N=8; |
igor_v | 21:bc8c1cec3da6 | 388 | break; |
Kovalev_D | 102:4270092be987 | 389 | |
Kovalev_D | 102:4270092be987 | 390 | case 0xE4: |
Kovalev_D | 98:95b8e79f13e1 | 391 | lengf=8; |
Kovalev_D | 98:95b8e79f13e1 | 392 | break; |
Kovalev_D | 103:e96f08947def | 393 | |
Kovalev_D | 103:e96f08947def | 394 | |
Kovalev_D | 103:e96f08947def | 395 | case 0xE6: |
Kovalev_D | 103:e96f08947def | 396 | lengf=8; |
Kovalev_D | 103:e96f08947def | 397 | break; |
Kovalev_D | 103:e96f08947def | 398 | |
igor_v | 21:bc8c1cec3da6 | 399 | } |
Kovalev_D | 98:95b8e79f13e1 | 400 | |
igor_v | 21:bc8c1cec3da6 | 401 | return lengf; |
igor_v | 0:8ad47e2b6f00 | 402 | } |
igor_v | 0:8ad47e2b6f00 | 403 | |
igor_v | 0:8ad47e2b6f00 | 404 | void Read_CMD(void) |
igor_v | 21:bc8c1cec3da6 | 405 | { |
Kovalev_D | 92:c892f0311aa7 | 406 | |
Kovalev_D | 45:cbc955aecebe | 407 | |
Kovalev_D | 45:cbc955aecebe | 408 | Gyro.RsErrLine = (Gyro.RsErrLine)& 0xffff;//для сброса ошибки |
igor_v | 21:bc8c1cec3da6 | 409 | |
Kovalev_D | 93:b3803774f110 | 410 | CountBuFFIn=ReadChekCon1(BuffTemp); // чтение данных из консоли |
igor_v | 42:6fc307c4963e | 411 | |
Kovalev_D | 92:c892f0311aa7 | 412 | if(CountBuFFIn==1) { // если есть первый байт |
igor_v | 21:bc8c1cec3da6 | 413 | if (BuffTemp[0] != SOC_In) { |
Kovalev_D | 93:b3803774f110 | 414 | ReadCon1(BuffTemp); |
igor_v | 28:17c84ed091b3 | 415 | Gyro.RsErrLine += 0x100;//WriteCon("\n\r ...Error.... "); |
Kovalev_D | 93:b3803774f110 | 416 | BuffTemp[99]=Gyro.RsErrLine; |
Kovalev_D | 102:4270092be987 | 417 | |
igor_v | 21:bc8c1cec3da6 | 418 | } |
Kovalev_D | 92:c892f0311aa7 | 419 | } else if(CountBuFFIn==2) { //если второй ,fqn |
igor_v | 28:17c84ed091b3 | 420 | if (BuffTemp[1] != Gyro.My_Addres) { |
Kovalev_D | 93:b3803774f110 | 421 | ReadCon1(BuffTemp); |
igor_v | 28:17c84ed091b3 | 422 | Gyro.RsErrLine += 0x1;//WriteCon("\n\r ...Error_ADDRES.... "); |
igor_v | 21:bc8c1cec3da6 | 423 | } |
igor_v | 42:6fc307c4963e | 424 | } else if(CountBuFFIn==3) { // если ьоетий байт |
igor_v | 28:17c84ed091b3 | 425 | Gyro.CMD_In=BuffTemp[2]; |
Kovalev_D | 92:c892f0311aa7 | 426 | N=Getlengf(); |
Kovalev_D | 92:c892f0311aa7 | 427 | } |
Kovalev_D | 92:c892f0311aa7 | 428 | else if(CountBuFFIn==4 && (N==6)) |
Kovalev_D | 92:c892f0311aa7 | 429 | { // N - длина посылки аскглд(для записи параметров). определяется по коду команды в Getlengf(); |
igor_v | 21:bc8c1cec3da6 | 430 | Param1=BuffTemp[3]; |
Kovalev_D | 92:c892f0311aa7 | 431 | } |
Kovalev_D | 92:c892f0311aa7 | 432 | else if((CountBuFFIn==5)&&(N==7)) |
Kovalev_D | 92:c892f0311aa7 | 433 | { |
Kovalev_D | 92:c892f0311aa7 | 434 | |
igor_v | 21:bc8c1cec3da6 | 435 | Param1=BuffTemp[3]; |
igor_v | 21:bc8c1cec3da6 | 436 | Param2=BuffTemp[4]; |
igor_v | 0:8ad47e2b6f00 | 437 | |
Kovalev_D | 92:c892f0311aa7 | 438 | } |
Kovalev_D | 92:c892f0311aa7 | 439 | else if((CountBuFFIn==6)&&(N==8)) |
Kovalev_D | 92:c892f0311aa7 | 440 | { |
igor_v | 21:bc8c1cec3da6 | 441 | Param1=BuffTemp[3]; |
igor_v | 21:bc8c1cec3da6 | 442 | Param2=BuffTemp[4]; |
igor_v | 21:bc8c1cec3da6 | 443 | Param3=BuffTemp[5]; |
Kovalev_D | 92:c892f0311aa7 | 444 | } |
Kovalev_D | 102:4270092be987 | 445 | else if((CountBuFFIn==8)&&(N==10)) |
Kovalev_D | 102:4270092be987 | 446 | { |
Kovalev_D | 102:4270092be987 | 447 | Param1=BuffTemp[4]; |
Kovalev_D | 102:4270092be987 | 448 | Param2=BuffTemp[5]; |
Kovalev_D | 102:4270092be987 | 449 | Param3=BuffTemp[6]; |
Kovalev_D | 102:4270092be987 | 450 | Param4=BuffTemp[7]; |
Kovalev_D | 102:4270092be987 | 451 | } |
Kovalev_D | 98:95b8e79f13e1 | 452 | |
Kovalev_D | 92:c892f0311aa7 | 453 | else if(CountBuFFIn > (N-1)) |
Kovalev_D | 92:c892f0311aa7 | 454 | { |
Kovalev_D | 93:b3803774f110 | 455 | ReadCon1(BuffTemp); |
igor_v | 28:17c84ed091b3 | 456 | switch(Gyro.CMD_In) { |
Kovalev_D | 92:c892f0311aa7 | 457 | case 0x99: |
igor_v | 21:bc8c1cec3da6 | 458 | CMD_Maintenance(); |
igor_v | 21:bc8c1cec3da6 | 459 | break; |
igor_v | 21:bc8c1cec3da6 | 460 | case 0xD8: |
igor_v | 21:bc8c1cec3da6 | 461 | CMD_M_Control_D8(); |
igor_v | 21:bc8c1cec3da6 | 462 | case 0xD9: |
igor_v | 21:bc8c1cec3da6 | 463 | CMD_M_Control_D9(); |
igor_v | 21:bc8c1cec3da6 | 464 | break; |
igor_v | 21:bc8c1cec3da6 | 465 | case 0x0A: |
Kovalev_D | 45:cbc955aecebe | 466 | CMD_M_Stymul(); |
igor_v | 21:bc8c1cec3da6 | 467 | break; |
igor_v | 21:bc8c1cec3da6 | 468 | case 0xDD: |
igor_v | 21:bc8c1cec3da6 | 469 | Rate_Flag=1; |
Kovalev_D | 102:4270092be987 | 470 | break; |
Kovalev_D | 102:4270092be987 | 471 | case 0xE4: |
Kovalev_D | 102:4270092be987 | 472 | CMD_M_vib(); |
Kovalev_D | 102:4270092be987 | 473 | break; |
Kovalev_D | 103:e96f08947def | 474 | case 0xE6: |
Kovalev_D | 103:e96f08947def | 475 | Gph_W(); |
Kovalev_D | 103:e96f08947def | 476 | break; |
Kovalev_D | 108:030cdde08314 | 477 | |
Kovalev_D | 103:e96f08947def | 478 | |
igor_v | 28:17c84ed091b3 | 479 | Gyro.RsErrLine = 0; |
Kovalev_D | 103:e96f08947def | 480 | |
Kovalev_D | 103:e96f08947def | 481 | |
Kovalev_D | 102:4270092be987 | 482 | } |
igor_v | 21:bc8c1cec3da6 | 483 | } |
igor_v | 0:8ad47e2b6f00 | 484 | } |
igor_v | 0:8ad47e2b6f00 | 485 | |
igor_v | 0:8ad47e2b6f00 | 486 | |
igor_v | 21:bc8c1cec3da6 | 487 |