![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
fork
Fork of LG by
Command.c
- Committer:
- Kovalev_D
- Date:
- 2016-03-31
- Revision:
- 104:ab1cb4ff56b2
- Parent:
- 103:e96f08947def
- Child:
- 105:bd01d8d20fb6
File content as of revision 104:ab1cb4ff56b2:
#include "stdlib.h" #include "LPC17xx.h" #include "Global.h" unsigned int Rate_Flag; unsigned int CountBuFFIn; unsigned int N=0,CRC_N; unsigned int Param1=0; unsigned int Param2=0; unsigned int Param3=0; unsigned int Param4=0; unsigned int Consol=123; /* void exec_CMD(void) //r. === процедура окончательной дешифрации и исполнения команды { unsigned int Comand_code; //rx_buf_copy = 1; //r. предустанов флага копирования приемного буфера Comand_code = (rcv_buf[2] & 0xFF) << 8; PC_Comand = Comand_code | (rcv_buf[3] & 0xFF); //e. save it in the memory for echo-transmission //r. сохранить его в памяти для обратной передачи }*/ void CMD_Maintenance(void) { BuffTemp[0] = Gyro.SOC_Out; BuffTemp[1] = Gyro .My_Addres; BuffTemp[2] = Gyro .Firmware_Version; BuffTemp[3] = Gyro .GLD_Serial; BuffTemp[4]=0x00; BuffTemp[5]=0x00; Check(BuffTemp, 8); WriteConN (BuffTemp,8); } void CMD_Rate(void) { unsigned int T_VibH , T_VibL; // Частота вибропривода. unsigned int Cnt_PlsL , Cnt_PlsH; // Счетчик +. unsigned int Cnt_MnsL , Cnt_MnsH; // Счетчик -. unsigned int Cnt_DifL , Cnt_DifH; // Разность счетчиков. unsigned int F_rasL , F_rasH; // Частота расщепления. unsigned int HF_regL , HF_regH; // Выход регулятора ГВЧ. НЕ СДЕЛАНО unsigned int HF_difL , HF_difH; // Сигнал ошибки регулячтора ГВЧ. НЕ СДЕЛАНО unsigned int WP_regL , WP_regH; unsigned int ADC1L, ADC2L, ADC3L, ADC4L, ADC5L; unsigned int ADC1H, ADC2H, ADC3H, ADC4H, ADC5H; // Gyro .T_Vib=(unsigned int)((7680000*16/Gyro.Frq)*4096); Gyro.T_Vib=(unsigned int)((7680000*16/(Gyro.Frq>>12))); Gyro.Firmware_Version=0xff; /// промежуточная затычка T_VibH = ( Gyro.T_Vib>>8 ) TakeByte; T_VibL = ( Gyro.T_Vib ) TakeByte; Cnt_PlsH = ( Gyro.Cnt_Pls>>8) TakeByte; Cnt_PlsL = ( Gyro.Cnt_Pls ) TakeByte; Cnt_MnsH = ( Gyro.Cnt_Mns>>8) TakeByte; Cnt_MnsL = ( Gyro.Cnt_Mns ) TakeByte; Cnt_DifH = ( Gyro.Cnt_Dif>>8) TakeByte; Cnt_DifL = ( Gyro.Cnt_Dif ) TakeByte; F_rasH = ( Gyro.F_ras>>8 ) TakeByte; F_rasL = ( Gyro.F_ras ) TakeByte; ADC1H = ( Spi.ADC1>>8 ) TakeByte; ADC1L = ( Spi.ADC1 ) TakeByte; ADC2H = ( Spi.ADC2>>8 ) TakeByte; ADC2L = ( Spi.ADC2 ) TakeByte; ADC3H = ( Spi.ADC3>>8 ) TakeByte; ADC3L = ( Spi.ADC3 ) TakeByte; ADC4H = ( Spi.ADC4>>8 ) TakeByte; ADC4L = ( Spi.ADC4 ) TakeByte; ADC5H = ( Spi.ADC5>>8 ) TakeByte; ADC5L = ( Spi.ADC5 ) TakeByte; WP_regH = ( Spi.DAC_B>>8 ) TakeByte; WP_regL = ( Spi.DAC_B ) TakeByte; HF_regH=0xff; HF_regL=0xff; HF_difH=0xff; HF_difL=0xff; BuffTemp[ 0] = Gyro.SOC_Out; BuffTemp[ 1] = Gyro.My_Addres; BuffTemp[ 2] = Cnt_PlsH;//старший байт счетчика +. BuffTemp[ 3] = Cnt_PlsL;//младший байт счетчика +. BuffTemp[ 4] = Cnt_MnsH;//старший байт счетчика -. BuffTemp[ 5] = Cnt_MnsL;//младший байт счетчика -. BuffTemp[ 6] = Cnt_DifH;//старший байт разности счетчиков BuffTemp[ 7] = Cnt_DifL;//младший байт разности счетчиков BuffTemp[ 8] = F_rasH; BuffTemp[ 9] = F_rasL; BuffTemp[10] = HF_regH; BuffTemp[11] = HF_regL; BuffTemp[12] = HF_difH; BuffTemp[13] = HF_difL; BuffTemp[14] = T_VibH ;// BuffTemp[15] = T_VibL; //? BuffTemp[16] = Gyro.Firmware_Version;//ХЗ BuffTemp[17] = Gyro.Firmware_Version;//ХЗ BuffTemp[18] = T_VibH>>1; BuffTemp[19] = T_VibL; BuffTemp[20] = Gyro.Firmware_Version;//ХЗ BuffTemp[21] = Gyro.Firmware_Version;//ХЗ BuffTemp[22] = WP_regH; //СРП Spi.DAC_B BuffTemp[23] = WP_regL; //СРП BuffTemp[24] = Gyro.Firmware_Version;// ХЗ BuffTemp[25] = Gyro.Firmware_Version;// ХЗ BuffTemp[26] = ADC1H; BuffTemp[27] = ADC1L; BuffTemp[28] = ADC1H; BuffTemp[29] = ADC1L; BuffTemp[30] = ADC1H; BuffTemp[31] = ADC1L; BuffTemp[32] = ADC1H; BuffTemp[33] = ADC1L; BuffTemp[34] = ADC1H; BuffTemp[35] = ADC1L; BuffTemp[36] = 0x00;//ADC6 BuffTemp[37] = 0x00;//ADC6 BuffTemp[38] = Gyro.Firmware_Version; BuffTemp[39] = Gyro.Firmware_Version; BuffTemp[40] = Gyro.Firmware_Version; BuffTemp[41] = Gyro.Firmware_Version; Check(BuffTemp, 44); WriteConN (BuffTemp,44); } void CMD_M_Control_D8()///установка\сброс регистров управления { unsigned int bit,NReg,Pa; unsigned int SR,V,A,Bit_num; SR=0; V=0; A=0; Bit_num=0; BuffTemp[0] = Gyro.SOC_Out; //DD BuffTemp[1] = Gyro.My_Addres; //00 BuffTemp[2] = Gyro.CMD_In; //D8 /* FrqON PlcON HFOOFF HFOON PlcOFF PlcON */ Pa = BuffTemp[3]; SR = Pa >> 0x7; V = Pa >> 0x5; V = V & 0x3; A = Pa >> 0x4; A = A & 0x1; Bit_num = Pa & 0xf; if(SR) { switch (Bit_num){ case 0x06: //FrqOff FrqON case 0x03: //FrqOff // AHFOON } } else{ switch (Bit_num){ case 0x06: FrqOff } } } void CMD_M_Control_D9()///чтение регистров управления { int bit,NReg; BuffTemp[0] = Gyro.SOC_Out; //DD BuffTemp[1] = Gyro.My_Addres; //00 BuffTemp[2] = Gyro.CMD_In; //D9 if ((Param1 & 0x10) == 0) { BuffTemp[3]=0<<4; BuffTemp[4] = (Gyro.RgConA>>8 )& 0xff; BuffTemp[5] = Gyro.RgConA & 0xff; } else { BuffTemp[3]=1<<4; BuffTemp[4] = (Gyro.RgConB>>8 ) & 0xff; BuffTemp[5] = Gyro.RgConB & 0xff; } Check(BuffTemp, CRC_N); WriteConN (BuffTemp,CRC_N); } // (номер (код) ЦАПа 0...3, старший байт требуемого ЦАПа, младший байт треб ЦАПа) void CMD_M_Stymul() { int temp; int HFO; temp=BuffTemp[3]; Consol = temp&0x3; HFO = temp&0x3;// // (номер (код) ЦАПа 0...3, HFO - 3dac, PLC - 0DAC temp =((BuffTemp[4]<<8) | BuffTemp[5]); // temp=0; temp=temp&0xFFFF; if(HFO) { Spi.DAC_A=(unsigned int)temp; } else{ DACF =(temp*K_DAC)+deltaDAC; Spi.DAC_B =(unsigned int)(DACF) /*(unsigned int)(temp*K_DAC+deltaDAC)*/; // K_DAC); } } void Gph_W() { int Gain_A; int Gain_B; Gyro.Gain_A=BuffTemp[4]; Gyro.Gain_B=BuffTemp[5]; } void CMD_M_vib() { LoopOn unsigned int temp1,temp2; temp1 =((BuffTemp[4]<<8) | BuffTemp[5]); temp1=temp1&0xFFFF; temp2 =((BuffTemp[6]<<8) | BuffTemp[7]); temp2=temp2&0xFFFF; Gyro.Frq = ((unsigned int) ((7680000*16/temp1)))*16*16*16; Consol=Gyro.Frq ; } unsigned int Check(char *c, unsigned int Count) { int i=1; unsigned int temp,CRC; temp=1; CRC=0; for(; i<Count-2; i++) { CRC+=c[i]; } if(c[Count-2]!=((CRC>>8)&0xFF)) { temp=0; Gyro.RsErrLine = (Gyro.RsErrLine)&=0x2; } if(c[Count-1]!=((CRC>>0)&0xFF)) { temp=0; // Gyro.RsErrLine= (Gyro.RsErrLine)=0x2; } c[Count-2]=(CRC>>8)&0xFF; c[Count-1]=(CRC>>0)&0xFF; return temp; } int Getlengf(void) { unsigned int lengf=0; switch(Gyro.CMD_In) { case 0x99://Gyrotainance lengf=6; CRC_N=8; break; case 0x0A: //m_stymul lengf=8; break; case 0xA5://DeviceMode lengf=6; CRC_N=8; break; case 0xDD://m_rate lengf=6; CRC_N=44; break; case 0xB0://DeviceMode lengf=6; CRC_N=8; break; case 0xD8://m_control lengf=6; CRC_N=8; break; case 0xD9://m_control lengf=6; CRC_N=8; break; case 0xE4: lengf=8; break; case 0xE6: lengf=8; break; } return lengf; } void Read_CMD(void) { Gyro.RsErrLine = (Gyro.RsErrLine)& 0xffff;//для сброса ошибки CountBuFFIn=ReadChekCon1(BuffTemp); // чтение данных из консоли if(CountBuFFIn==1) { // если есть первый байт if (BuffTemp[0] != SOC_In) { ReadCon1(BuffTemp); Gyro.RsErrLine += 0x100;//WriteCon("\n\r ...Error.... "); BuffTemp[99]=Gyro.RsErrLine; } } else if(CountBuFFIn==2) { //если второй ,fqn if (BuffTemp[1] != Gyro.My_Addres) { ReadCon1(BuffTemp); Gyro.RsErrLine += 0x1;//WriteCon("\n\r ...Error_ADDRES.... "); } } else if(CountBuFFIn==3) { // если ьоетий байт Gyro.CMD_In=BuffTemp[2]; N=Getlengf(); } else if(CountBuFFIn==4 && (N==6)) { // N - длина посылки аскглд(для записи параметров). определяется по коду команды в Getlengf(); Param1=BuffTemp[3]; } else if((CountBuFFIn==5)&&(N==7)) { Param1=BuffTemp[3]; Param2=BuffTemp[4]; } else if((CountBuFFIn==6)&&(N==8)) { Param1=BuffTemp[3]; Param2=BuffTemp[4]; Param3=BuffTemp[5]; } else if((CountBuFFIn==8)&&(N==10)) { Param1=BuffTemp[4]; Param2=BuffTemp[5]; Param3=BuffTemp[6]; Param4=BuffTemp[7]; } else if(CountBuFFIn > (N-1)) { ReadCon1(BuffTemp); switch(Gyro.CMD_In) { case 0x99: CMD_Maintenance(); break; case 0xD8: CMD_M_Control_D8(); case 0xD9: CMD_M_Control_D9(); break; case 0x0A: CMD_M_Stymul(); break; case 0xDD: Rate_Flag=1; break; case 0xE4: CMD_M_vib(); break; case 0xE6: Gph_W(); break; Gyro.RsErrLine = 0; } } }