forkd

Dependencies:   mbed

Fork of LG2 by Dmitry Kovalev

Committer:
Kovalev_D
Date:
Fri Apr 01 10:05:35 2016 +0000
Revision:
106:250ddd8629c6
Parent:
105:bd01d8d20fb6
Child:
107:4d178bcc9d8a
54

Who changed what in which revision?

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