// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool ConstantFolder::IsValidOffset(GlobalVariable* globalVar, const Type* loadType, __int64 offset) { __int64 loadSize = TypeInfo::GetSize(loadType, target_); __int64 initSize = TypeInfo::GetSize(globalVar->GetType(), target_); if(offset < 0) { return false; } if((offset + loadSize) > initSize) { // Make an exception for a char array initialized by a string. auto initializer = globalVar->GetInitializer(); if((initializer->Conversion() == InitConv_PointerToPointer) && (initializer->IsInitializerList() == false) && (initializer->Value()->IsStringConstant())) { // Make sure the offset is in the bounds of the string. auto stringConst = initializer->Value()->As<StringConstant>(); auto arrayType = stringConst->GetType()->As<ArrayType>(); if(offset < arrayType->Size()) { return true; } } return false; } return true; }
void Binary_Operator() /*双目运算*/ { char num[20]; strcpy(num, gtk_entry_get_text(GTK_ENTRY(entry)));/*取得文本框的内容*/ if (a == 0) /*如果没有第一个数,则存储为第一个数*/ { Conversion(num, principle, 10); //全部转为十进制 a = p; gtk_entry_set_text(GTK_ENTRY(entry), ""); /*清空文本框*/ } else /*如果已有第一个数,则应存储为第二个数*/ { Conversion(num, principle, 10); //全部转为十进制 b = p; } hasdot = 0; /*表示已经没有小数点*/ }
bool FWebSocket::Send(const FString &StringData) { #if UE_BUILD_DEBUG UE_LOG(LogROS, Log, TEXT("[WebSocket::Send] Output Message: %s"), *StringData); #endif FTCHARToUTF8 Conversion(*StringData); uint32 DestLen = Conversion.Length(); uint8* Data = (uint8*)Conversion.Get(); // Call FWebSocket::Send(uint8* Data, uint32 Size) return SendText(Data, DestLen); }
void Right_output() /*单目运算结果输出*/ { char num[20]; if (gcvt(a, 32, num) == NULL) /*运算结果转换成字符串*/ { perror("error:Right_output"); } Conversion(num, 10, principle); /*将运算结果(十进制字符串)转换成指定进制数*/ gtk_entry_set_text(GTK_ENTRY(entry), out); /*显示结果*/ a = 0; b = 0; method = 0; }
void ControlLoopCompass(void) { //printf("\n"); // for (i = 0; i < miterations; i++) // { // call sensor driver simulation to get accel and mag data in integer counts fSixDOFMyNEDSensorDrivers(); // update the magnetometer measurement buffer integer magnetometer data fUpdateMagnetometerBuffer(); // remove hard and soft iron terms from Bp (uT) to get calibrated data Bc (uT) fInvertMagCal(); // NED coordinate system feCompassNED(fBcx, fBcy, fBcz, fGpx, fGpy, fGpz); Conversion(); if (validmagcal !=0) { APhi6DOF = median(iPhi6DOF, &arr_medianas[0]); AThe6DOF = median(iThe6DOF, &arr_medianas[1]); APsi6DOF = median(iPsi6DOF, &arr_medianas[2]); // printf("Yaw =%4d Pitch =%4d Roll =%4d \r", APhi6DOF, AThe6DOF, APsi6DOF); APsi6DOF = 359 - APsi6DOF; sprintf(buffer,"%04d",APsi6DOF); vfnLCD_Write_Msg(buffer); //print when it is calibrated ecompass_direction = APsi6DOF; } // try to find an improved calibration if update is enabled else { fCalibrationUpdate(); } loopcounter++; // } }
//Main int main(void) { //Clock del Sistema a 40MHz SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); //Divisor PWM SysCtlPWMClockSet(SYSCTL_PWMDIV_64); //Habilitar Periferico PWM1 SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1); //Proveer Reloj al Puerto D y F SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //Periferico como tipo PWM GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0); GPIOPinConfigure(GPIO_PD0_M1PWM0); //Remover bloqueo del SW0 GPIO_PORTF_LOCK_R = GPIO_LOCK_KEY; // GPIO_PORTF_CR_R = 0x0f; //Switches como Entrada GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4); GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); //Llamar Metodo Conversion(Angulo); ConfiguracionPWM(Ancho); PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, Ancho * Load / 1000); while(1) { if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)==0x00) { Ancho--; if (Ancho < 40) { Ancho = 40; } PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, Ancho * Load / 1000); } if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)==0x00) { Ancho++; if (Ancho > 140) { Ancho = 140; } PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, Ancho * Load / 1000); } SysCtlDelay(100000); } }
void output() /*双目运算结果输出*/ { char num[20]; strcpy(num, gtk_entry_get_text(GTK_ENTRY(entry))); /* 取得文本框输入的内容*/ Conversion(num, principle, 10); /*将输入的进制数转换为十进制*/ b = p; switch (method) { case 0: a = a + b; Right_output(); break; case 1: a = a - b; Right_output(); break; case 2: a = a * b; Right_output(); break; case 3: if (b == 0) { error_handle("除数不能为零"); } else { a = a / b; Right_output(); } break; case 4: a = pow(a, b); Right_output(); break; case 5: a = ((int) a) & ((int) b); Right_output(); break; case 6: a = ((int) a) | ((int) b); Right_output(); break; case 7: a = ((int) a) ^ ((int) b); Right_output(); break; case 8: if (b == 0) { error_handle("除数不能为零"); } else { a = ((int) a) % ((int) b); Right_output(); } break; case 9: a = sin(b); Right_output(); break; case 10: a = cos(b); Right_output(); break; case 11: a = tan(b); Right_output(); break; case 12: a = exp(b); Right_output(); break; case 13: a = b * b * b; Right_output(); break; case 14: a = b * b; Right_output(); break; case 15: if (b <= 0) { error_handle("对数必须为正数"); } else { a = log(b); Right_output(); } break; case 16: if (b <= 0) { error_handle("对数必须为正数"); } else { a = log10(b); Right_output(); } break; case 17: if (b < 0) { error_handle("函数输入无效"); } else { a = fun((int) (b)); Right_output(); } break; case 18: if (b == 0) { error_handle("除数不能为零"); } else { a = 1 / b; Right_output(); } break; case 19: a = ~((int) b); Right_output(); break; case 20: a = floor(b); Right_output(); break; default: break; } }
mxArray *message_constructor(const MessagePtr& message, int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { mxArray *result = 0; // parse inputs if (nrhs > 0 && Options::isString(prhs[0])) { std::string option = Options::getString(prhs[0]); if (nrhs == 1 && boost::algorithm::iequals(option, "definition")) { result = mxCreateString(message->getDefinition()); return result; } if (nrhs == 1 && boost::algorithm::iequals(option, "md5sum")) { result = mxCreateString(message->getMD5Sum()); return result; } if (nrhs == 1 && boost::algorithm::iequals(option, "fields")) { result = mxCreateCellMatrix(1, message->getFieldNames().size()); for(std::size_t i = 0; i < message->getFieldNames().size(); ++i) { mxSetCell(result, i, mxCreateString(message->getFieldNames().at(i))); } return result; } if ((nrhs == 1 || nrhs == 2) && boost::algorithm::iequals(option, "default")) { if (nrhs == 2) { const mxArray *default_options = prhs[1]; Conversion::perMessageOptions(message).merge(ConversionOptions(1, &default_options)); } return Conversion::perMessageOptions(message).toMatlab(); } } // Check if a numeric argument (message count) has been given std::size_t count = 1; if (nrhs > 0 && (Options::isIntegerScalar(prhs[0]) || Options::isDoubleScalar(prhs[0]))) { count = Options::getIntegerScalar(prhs[0]); nrhs--; prhs++; } // Get conversion options ConversionOptions options; if (nrhs % 2 == 0) { options.init(nrhs, prhs); } else { options.init(nrhs - 1, prhs + 1); } // Is this a copy constructor? if (nrhs % 2 != 0) { Conversion conversion(message, options); V_Message copy(conversion.numberOfInstances(prhs[0])); for(std::size_t j = 0; j < copy.size(); j++) { copy[j] = conversion.fromMatlab(prhs[0], j); // std::cout << "Constructed a new " << copy[j]->getDataType() << " message: " << *boost::shared_static_cast<MessageType const>(copy[j]->getConstInstance()) << std::endl; result = Conversion(conversion, copy[j]).toMatlab(result, j, copy.size()); } // otherwise construct a new message } else { MessagePtr m = message->introspect(message->createInstance()); // std::cout << "Constructed a new " << m->getDataType() << " message: " << *boost::shared_static_cast<MessageType const>(m->getConstInstance()) << std::endl; Conversion conversion(m, options); result = conversion.toMatlab(); } // copy the contents of result if count > 1 if (count > 1) { // This seems to be a bit hacky. Is there a better solution? mxArray *repmatrhs[] = { result, mxCreateDoubleScalar(1), mxCreateDoubleScalar(count) }; mxArray *repmatlhs[] = { 0 }; mexCallMATLAB(1, repmatlhs, 3, repmatrhs, "repmat"); mxDestroyArray(repmatrhs[0]); mxDestroyArray(repmatrhs[1]); mxDestroyArray(repmatrhs[2]); result = repmatlhs[0]; } return result; }
/** reads the conversions file */ int readConversions(std::vector<ItemCategory> const& categories, std::vector<Conversion> &conversions) { std::ifstream in( conversion_file_name.c_str() ); // file could not be opened for some reason if (!in.is_open()) { QString error = "Error reading file \"" + QString::fromStdString(conversion_file_name) + "\"."; Utils::message(error); return 1; } std::string line (""); std::list<std::string> line_content; while ( getline(in, line) ) { // skip current line because it's empty or it's a comment if (line.compare("") == 0 || line[0] == '#') continue; line_content = Utils::splitString(line, '\t'); auto it = line_content.cbegin(); // more than six columns found in current line if (line_content.size() != 7) { Utils::message("File format error in conversions file."); return 2; } std::size_t const i_cat_idx (atoi((it++)->c_str())); if ( i_cat_idx >= categories.size()) { Utils::message("Undefined category in items file."); return 3; } std::size_t const i_item_idx (atoi((it++)->c_str())); if ( i_item_idx >= categories[i_cat_idx].size()) { Utils::message("Undefined item for category \"" + categories[i_cat_idx].name() + "\"."); return 4; } std::size_t const i_amount (atoi((it++)->c_str())); std::size_t const o_cat_idx (atoi((it++)->c_str())); if ( o_cat_idx >= categories.size()) { Utils::message("Undefined category in items file."); return 5; } std::size_t const o_item_idx (atoi((it++)->c_str())); if ( o_item_idx >= categories[o_cat_idx].size()) { Utils::message("Undefined item for category \"" + categories[i_cat_idx].name() + "\"."); return 6; } if (i_cat_idx == o_cat_idx && i_item_idx == o_item_idx) { Utils::message("Item-types can not be converted to themselves (" + categories[i_cat_idx].item(i_item_idx) + ")."); continue; } std::size_t const o_amount (atoi((it++)->c_str())); conversions.push_back(Conversion(i_cat_idx, i_item_idx, i_amount, o_cat_idx, o_item_idx, o_amount, atoi((it++)->c_str()))); } return 0; }
int main() { Conversion(12345,16); return 0; }
Timer::Timer(TIM_TypeDef *timer,u16 second,u16 millisecond,u16 microsecond,u8 Prioritygroup,u8 preemprionPriority,u8 subPriority) { //通过计算的出了ARR PSC uint8_t timerIrqChannel; TIM_TimeBaseInitTypeDef TIM_BaseInitStructure; mTempTimer=timer; NVIC_InitTypeDef NVIC_InitStructure; Conversion(second,millisecond,microsecond); if(timer==TIM1) { RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); timerIrqChannel=TIM1_UP_IRQn; } else if(timer==TIM2) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); timerIrqChannel=TIM2_IRQn; } else if(timer==TIM3) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); timerIrqChannel=TIM3_IRQn; } else if(timer==TIM4) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); timerIrqChannel=TIM4_IRQn; } else { } //TIM_InternalClockConfig(timer); // TIM_DeInit(timer);//将寄存器重设为缺省值 TIM_BaseInitStructure.TIM_Period = mArr-1; //设置初值 TIM_BaseInitStructure.TIM_Prescaler =mPsc-1;//设置预分频 TIM_BaseInitStructure.TIM_ClockDivision = 0;//设置时钟分割 TIM_BaseInitStructure.TIM_RepetitionCounter=0; TIM_BaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;//设置计数方式 TIM_TimeBaseInit(timer,&TIM_BaseInitStructure); TIM_ClearFlag(timer, TIM_FLAG_Update);//清空中断标识 写了就进不了中断了 TIM_ITConfig(timer, TIM_IT_Update, ENABLE); //使能中断 switch(Prioritygroup)//中断分组 { case 0: NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); break; case 1: NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); break; case 2: NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); break; default: NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3); break; case 4: NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); break; } NVIC_InitStructure.NVIC_IRQChannel =timerIrqChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = preemprionPriority; //先占优先 NVIC_InitStructure.NVIC_IRQChannelSubPriority = subPriority; //从优先 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道被使能 NVIC_Init(&NVIC_InitStructure); //初始化NVIC寄存器 TIM_Cmd(mTempTimer, ENABLE);//开启定时器 /**/ }
void CObject_Appletree::Render() { SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 255); Conversion(); if(GetHP() > 0) { if(b_Hit) { Hit->DrawSprite((int)fDrawX, (int)fDrawY, FALSE); Stand->SetCount(0); } else if(b_Attack) { Stand->DrawSprite((int)fDrawX, (int)fDrawY); Poison->DrawSprite((int)fDrawX-35, (int)fDrawY+115); } else { Stand->DrawSprite((int)fDrawX, (int)fDrawY); } if(!b_apple[0]) { Apple[0]->DrawSprite((int)fDrawX+35, (int)fDrawY+100, TRUE, 0); } else { tempY[0] += 11; if(tempY[0] > 420) { tempY[0] = 420; if(Break[0]->GetCount() != 5) { Break[0]->DrawSprite((int)fDrawX+35, (int)tempY[0]+100, FALSE); } else { } Boom[0]->DrawSprite((int)fDrawX-5, (int)tempY[0]-50, FALSE); } else { Apple[0]->DrawSprite((int)fDrawX+35, (int)tempY[0]+125, TRUE, 0); } } if(!b_apple[1]) { Apple[1]->DrawSprite((int)fDrawX+95, (int)fDrawY+120, TRUE, 0); } else { tempY[1] += 11; if(tempY[1] > 420) { tempY[1] = 420; if(Break[1]->GetCount() != 5) { Break[1]->DrawSprite((int)fDrawX+95, (int)tempY[1]+100, FALSE); } else { } Boom[1]->DrawSprite((int)fDrawX+55, (int)tempY[1]-50, FALSE); } else { Apple[1]->DrawSprite((int)fDrawX+95, (int)tempY[1]+145, TRUE, 0); } } /* // 데미지 출력 if(GetHit()) { Hit->DrawSprite((int)fDrawX, (int)fDrawY); SetDrawBlendMode(DX_BLENDMODE_ADD, 255-(10*KnockbackCount)); SetDrawBright(255, 255, 255); Func->DrawNum((int)fDrawX+140, (int)fDrawY-20-(KnockbackCount*2), (int)HeroForEnemy->GetDmg()); SetDrawBright(*Bright, *Bright, *Bright); } */ } else { SetDrawBlendMode(DX_BLENDMODE_ALPHA, Opacity); Death->DrawSprite((int)fDrawX, (int)fDrawY, FALSE); } SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 255); }