void APU_DX::Play(void) { HRESULT hr; LPBYTE lpbuf1 = NULL; LPBYTE lpbuf2 = NULL; DWORD dwsize1 = 0; DWORD dwsize2 = 0; DWORD dwbyteswritten1 = 0; DWORD dwbyteswritten2 = 0; // Lock the sound buffer hr = buffer->Lock (bufferOffset, (DWORD)(samples_read*2), (LPVOID *)&lpbuf1, &dwsize1, (LPVOID *)&lpbuf2, &dwsize2, 0); if (hr == DS_OK) { pOutBuffer = out_buf; if ((dwbyteswritten1 = CopyBuffer(lpbuf1, dwsize1)) == dwsize1) if (lpbuf2) dwbyteswritten2 = CopyBuffer(lpbuf2, dwsize2); // Update our buffer offset and unlock sound buffer bufferOffset = (bufferOffset + dwbyteswritten1 + dwbyteswritten2) % bufferdesc.dwBufferBytes; buffer->Unlock (lpbuf1, dwbyteswritten1, lpbuf2, dwbyteswritten2); } }
/** * @brief Main program * @param None * @retval None */ int main(void) { uint8_t lcd_status = LCD_OK; /* STM32F4xx HAL library initialization: - Configure the Flash prefetch, instruction and Data caches - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Set NVIC Group Priority to 4 - Low Level Initialization: global MSP (MCU Support Package) initialization */ HAL_Init(); /* Configure the system clock to 180 MHz */ SystemClock_Config(); /* Initialize the SDRAM */ BSP_SDRAM_Init(); /* Initialize the LCD */ lcd_status = LCD_Init(); OnError_Handler(lcd_status != LCD_OK); /* Initialize LTDC layer 0 iused for Hint */ BSP_LCD_LayerDefaultInit(0, LAYER0_ADDRESS); BSP_LCD_SelectLayer(0); /* Display example brief */ LCD_BriefDisplay(); /*Draw first image */ CopyBuffer((uint32_t *)Images[ImageIndex++], (uint32_t *)LAYER0_ADDRESS, 240, 160, 320, 240); pending_buffer = 0; /*Refresh the LCD display*/ HAL_DSI_Refresh(&hdsi_eval); /* Infinite loop */ while (1) { if(pending_buffer < 0) { CopyBuffer((uint32_t *)Images[ImageIndex++], (uint32_t *)LAYER0_ADDRESS, 240, 160, 320, 240); if(ImageIndex >= 2) { ImageIndex = 0; } pending_buffer = 0; HAL_DSI_Refresh(&hdsi_eval); } /* Wait some time before switching to next image */ HAL_Delay(2000); } }
/******************************************************************************* BiquadFilterUpdateKernel */ Error_t BiquadFilterUpdateKernel(BiquadFilter *filter, const float *bCoeff, const float *aCoeff) { CopyBuffer(filter->b, bCoeff, 3); CopyBuffer(filter->a, aCoeff, 2); return NOERR; }
/** * @brief Main program * @param None * @retval None */ int main(void) { uint8_t lcd_status = LCD_OK; /* STM32F4xx HAL library initialization: - Configure the Flash prefetch, instruction and Data caches - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Set NVIC Group Priority to 4 - Low Level Initialization: global MSP (MCU Support Package) initialization */ HAL_Init(); /* Configure the system clock to 180 MHz */ SystemClock_Config(); /* Initialize the LCD */ lcd_status = BSP_LCD_Init(); OnError_Handler(lcd_status != LCD_OK); BSP_LCD_LayerDefaultInit(0, LAYER0_ADDRESS); BSP_LCD_SelectLayer(0); /* Set LTDC Line Event */ HAL_LTDC_ProgramLineEvent(&hltdc_eval, 0); /* Display example brief */ LCD_BriefDisplay(); /* Copy Buffer 0 into buffer 1, so only image area to be redrawn later */ CopyBuffer((uint32_t *)Buffers[0], (uint32_t *)Buffers[1], 0, 0, 800, 480); /* Infinite loop */ while (1) { if(pend_buffer < 0) { /* Prepare back buffer */ CopyBuffer((uint32_t *)Images[ImageIndex++], (uint32_t *)Buffers[1- front_buffer], 240, 160, 320, 240); pend_buffer = 1- front_buffer; if(ImageIndex >= 2) { ImageIndex = 0; } /* Wait some time before switching to next stage */ HAL_Delay(2000); } } }
bool OverData::UnloadOverlay() { u32 i = 0; u32 j = 0; u32 newMap16 = 0; u32 oldMap16 = 0; // ----------------------- // figure out what the differences are between the map // with the overlay enabled and the overlay not enabled. for(i = 0; i < 0x40; ++i) { for(j = 0; j < 0x40; ++j) { newMap16 = GetMap16Tile(map16Buf, i, j); oldMap16 = GetMap16Tile(map16Backup, i, j); if(newMap16 == oldMap16) eOverlay->SetTile(0xFFFF, i, j); else eOverlay->SetTile(newMap16, i, j); } } // restore the map16 buffer to the way it was before the overlay was activated CopyBuffer(map16Buf, map16Backup, 0, 0, map16Backup->length); LoadMap8(); return true; }
void GeomX::CopyBuffers ( GeomX& src ) { FreeBuffers (); for (int n = 0; n < src.GetNumBuf(); n++) CopyBuffer ( n, n, src ); CopyHeap ( src ); }
bool OverData::LoadOverlay() { u32 i = 0; u32 j = 0; u32 map16Val = 0; // ----------------------- CopyBuffer(map16Backup, map16Buf, 0, 0, map16Buf->length); for(i = 0; i < 0x40; ++i) { for(j = 0; j < 0x40; ++j) { map16Val = eOverlay->GetTile(i, j); if(map16Val == 0xFFFF) continue; SetMap16Tile(map16Buf, map16Val, i, j); } } LoadMap8(); return true; }
int main() { logAppl.a=1; logAppl.b=0x01000002; CopyBuffer((unsigned char *)&logAppl); #ifdef BIG_ENDIAN assert(arrayTmp[0]==0); assert(arrayTmp[1]==0); assert(arrayTmp[2]==0); assert(arrayTmp[3]==1); assert(arrayTmp[4]==1); assert(arrayTmp[5]==0); assert(arrayTmp[6]==0); assert(arrayTmp[7]==2); #else // this is little endian assert(arrayTmp[0]==1); assert(arrayTmp[1]==0); assert(arrayTmp[2]==0); assert(arrayTmp[3]==0); assert(arrayTmp[4]==2); assert(arrayTmp[5]==0); assert(arrayTmp[6]==0); assert(arrayTmp[7]==1); #endif }
TEST(DSPSingle, TestCopyBuffer) { float out[10]; CopyBuffer(out, ones, 10); for (unsigned i = 0; i < 10; ++i) { ASSERT_FLOAT_EQ(ones[i], out[i]); } }
// ----------------------------------------------------------------------------- // CMccUlDataPath::BufferFilledL // Databuffer filled callback // ----------------------------------------------------------------------------- void CMccUlDataPath::BufferFilledL( CMMFBuffer* aBuffer ) { // Has the datapath stopped running, if so were not interested in any // callbacks. if( EStreaming == State() ) { if ( !aBuffer ) { ChangeDataPathTransferState( EEndOfData ); } else { // Sink buffer is with datapath, see if there is anything to send // to sink IsBufferSupportedL( aBuffer ); aBuffer->SetStatus( EFull ); if ( iSinkBuffer != aBuffer ) { CMMFDataBuffer* desBuffer = static_cast<CMMFDataBuffer*>(iSinkBuffer); if ( (TInt) aBuffer->BufferSize() > desBuffer->Data().MaxLength() ) { // if the buffer from source is too big, ignore it // ask next one __SUBCONTROLLER( "CMccUlDataPath::BufferFilledL, DATA IGNORED" ) __SUBCONTROLLER_INT1( "CMccUlDataPath::BufferFilledL, source", aBuffer->BufferSize() ) __SUBCONTROLLER_INT1( "CMccUlDataPath::BufferFilledL, dest", desBuffer->Data().MaxLength() ) iSinkBuffer->SetStatus( EAvailable ); aBuffer->SetStatus( EAvailable ); ChangeDataPathTransferState( ENeedSourceData ); return; } else { CopyBuffer( iSinkBuffer, aBuffer ); } } if( !aBuffer->BufferSize() || aBuffer->LastBuffer() ) { //ignore zero length buffer request for next buffer from AudioInput iSinkBuffer->SetStatus( EAvailable ); ChangeDataPathTransferState( ENeedSourceData, ETrue ); } else { ChangeDataPathTransferState( ESendDataToSink ); } } } else { User::Leave( KErrNotReady ); } }
/******************************************************************************* BiquadFilterInit */ BiquadFilter* BiquadFilterInit(const float *bCoeff, const float *aCoeff) { // Allocate Memory BiquadFilter* filter = (BiquadFilter*)malloc(sizeof(BiquadFilter)); if (filter) { // Initialize Buffers CopyBuffer(filter->b, bCoeff, 3); CopyBuffer(filter->a, aCoeff, 2); ClearBuffer(filter->x, 2); ClearBuffer(filter->y, 2); ClearBuffer(filter->w, 2); } return filter; }
/******************************************************************************* BiquadFilterProcess */ Error_t BiquadFilterProcess(BiquadFilter *filter, float *outBuffer, const float *inBuffer, unsigned n_samples) { #ifdef __APPLE__ // Use accelerate if we have it float coeffs[5] = { filter->b[0], filter->b[1], filter->b[2], filter->a[0], filter->a[1] }; float temp_in[n_samples + 2]; float temp_out[n_samples + 2]; // Put filter overlaps into beginning of input and output vectors cblas_scopy(2, filter->x, 1, temp_in, 1); cblas_scopy(2, filter->y, 1, temp_out, 1); cblas_scopy(n_samples, inBuffer, 1, (temp_in + 2), 1); // Process vDSP_deq22(temp_in, 1, coeffs, temp_out, 1, n_samples); // Write overlaps to filter x and y arrays cblas_scopy(2, (temp_in + n_samples), 1, filter->x, 1); cblas_scopy(2, (temp_out + n_samples), 1, filter->y, 1); // Write output cblas_scopy(n_samples, (temp_out + 2), 1, outBuffer, 1); #else float buffer[n_samples]; for (unsigned buffer_idx = 0; buffer_idx < n_samples; ++buffer_idx) { // DF-II Implementation buffer[buffer_idx] = filter->b[0] * inBuffer[buffer_idx] + filter->w[0]; filter->w[0] = filter->b[1] * inBuffer[buffer_idx] - filter->a[0] * \ buffer[buffer_idx] + filter->w[1]; filter->w[1] = filter->b[2] * inBuffer[buffer_idx] - filter->a[1] * \ buffer[buffer_idx]; } // Write output CopyBuffer(outBuffer, buffer, n_samples); #endif return NOERR; }
/*---------------------------------------------------------------------- | NPT_String::Assign +---------------------------------------------------------------------*/ void NPT_String::Assign(const char* str, NPT_Size length) { if (str == NULL || length == 0) { Reset(); } else { PrepareToWrite(length); CopyBuffer(m_Chars, str, length); m_Chars[length] = '\0'; } }
/* Serialize a string. Params: data: data to serialize dataSize: length which the serialized data should have (read from dataSize field of ebml element) buffer: store serialized bytes of data return length of serialized data in bytes if successful and 0 otherwise */ Uint64 SerializeString(std::string data, Uint64 dataSize, Byte*& buffer) { CopyBuffer((Byte*)data.c_str(), buffer, dataSize); if (buffer || buffer != nullptr) delete buffer; buffer = new Byte[dataSize + 1]; buffer[dataSize] = 0; for (int i = 0; i < dataSize; ++i) { buffer[i] = data[i]; } return dataSize; }
/* ============== idVertexCache::ActuallyAlloc ============== */ vertCacheHandle_t idVertexCache::ActuallyAlloc( geoBufferSet_t & vcs, const void * data, int bytes, cacheType_t type ) { if ( bytes == 0 ) { return (vertCacheHandle_t)0; } assert( ( ((UINT_PTR)(data)) & 15 ) == 0 ); assert( ( bytes & 15 ) == 0 ); // thread safe interlocked adds byte ** base = NULL; int endPos = 0; if ( type == CACHE_INDEX ) { base = &vcs.mappedIndexBase; endPos = vcs.indexMemUsed.Add( bytes ); if ( endPos > vcs.indexBuffer.GetAllocedSize() ) { idLib::Error( "Out of index cache" ); } } else if ( type == CACHE_VERTEX ) { base = &vcs.mappedVertexBase; endPos = vcs.vertexMemUsed.Add( bytes ); if ( endPos > vcs.vertexBuffer.GetAllocedSize() ) { idLib::Error( "Out of vertex cache" ); } } else if ( type == CACHE_JOINT ) { base = &vcs.mappedJointBase; endPos = vcs.jointMemUsed.Add( bytes ); if ( endPos > vcs.jointBuffer.GetAllocedSize() ) { idLib::Error( "Out of joint buffer cache" ); } } else { assert( false ); } vcs.allocations++; int offset = endPos - bytes; // Actually perform the data transfer if ( data != NULL ) { MapGeoBufferSet( vcs ); CopyBuffer( *base + offset, (const byte *)data, bytes ); } vertCacheHandle_t handle = ( (uint64)(currentFrame & VERTCACHE_FRAME_MASK ) << VERTCACHE_FRAME_SHIFT ) | ( (uint64)(offset & VERTCACHE_OFFSET_MASK ) << VERTCACHE_OFFSET_SHIFT ) | ( (uint64)(bytes & VERTCACHE_SIZE_MASK ) << VERTCACHE_SIZE_SHIFT ); if ( &vcs == &staticData ) { handle |= VERTCACHE_STATIC; } return handle; }
/* Serialize an float. Params: data: data to serialize buffer: store serialized bytes of data return length of serialized data in bytes */ Uint64 SerializeFloat(double data, Byte*& buffer) { union { double f_data; Uint64 uint_data; }; f_data = data; // 4 bytes Uint64 dataSize = 0; if ((uint_data & 0x00000000LL) == 0) dataSize = 4; else dataSize = 8; CopyBuffer((Byte*)&f_data, buffer, dataSize); return dataSize; }
/* Serialize a Uint. Params: data: data to serialize dataSize: length which the serialized data should have (read from dataSize field of ebml element) buffer: store serialized bytes of data return length of serialized data in bytes if successful and 0 otherwise */ Uint64 SerializeUint(Uint64 data, Byte*& buffer) { Byte* ptr = (Byte*)&data; Uint64 dataSize = 1; Uint64 maxLen = sizeof(Uint64); Uint64 mask = 0xFFLL; while (dataSize <= maxLen) { if ((mask & data) == 0) break; mask <<= 8; ++dataSize; } if (dataSize > maxLen) return 0; CopyBuffer(ptr, buffer, dataSize); return dataSize; }
/* Serialize an Ebml data size. Params: id: id to serialize buffer: store serialized bytes of id return length of serialized data in bytes */ Uint64 SerializeEbmlSize(Uint64 size, Byte*& buffer) { Uint64 vint_width = 0; Uint64 maxLen = sizeof(Uint64); // Uint64 vint_mark = 0; while (vint_width < maxLen) { vint_mark = 1LL << (vint_width + 1) * 7; if (size < vint_mark) break; ++vint_width; } if (vint_width >= maxLen) return 0; size |= vint_mark; CopyBuffer((Byte*)&size, buffer, vint_width + 1); return vint_width + 1; }
int main() { logAppl.a=1; // logAppl.b=0x010; CopyBuffer((unsigned char *)&logAppl); // this is little endian printf("arrayTmp[%d]: %d\n", 0, arrayTmp[0]); assert(arrayTmp[0]==1); // assert(arrayTmp[1]==0); // assert(arrayTmp[2]==0); // assert(arrayTmp[3]==0); // assert(arrayTmp[4]==2); // assert(arrayTmp[5]==0); // assert(arrayTmp[6]==0); // assert(arrayTmp[7]==1); // assert(0); }
/*---------------------------------------------------------------------- | NPT_String::Append +---------------------------------------------------------------------*/ void NPT_String::Append(const char* str, NPT_Size length) { // shortcut if (str == NULL || length == 0) return; // compute the new length NPT_Size old_length = GetLength(); NPT_Size new_length = old_length + length; // allocate enough space Reserve(new_length); // append the new string at the end of the current one CopyBuffer(m_Chars+old_length, str, length); m_Chars[new_length] = '\0'; // update the length GetBuffer()->SetLength(new_length); }
/* Serialize an Ebml ID. Params: id: id to serialize buffer: store serialized bytes of id return: length of serialized data in bytes if successfully 0 if failed */ Uint64 SerializeEbmlID(EbmlID id, Byte*& buffer) { Uint64 length = 0; Uint64 mask = 0xFF; short MaxLen = sizeof(Uint64); while (length <= MaxLen) { Uint64 tmp = id & mask; if (tmp == 0) break; mask <<= 8; // shift 1 byte ++length; } if (length > MaxLen) return 0; // error Byte* ptr = reinterpret_cast<Byte*>(&id); /* It is little-endianness in Windows so ptr now points to the most-least byte. */ CopyBuffer(ptr, buffer, length); return length; }
/*---------------------------------------------------------------------- | NPT_String::Insert +---------------------------------------------------------------------*/ const NPT_String& NPT_String::Insert(const char* str, NPT_Ordinal where) { // check args if (str == NULL || where > GetLength()) return *this; // measure the string to insert NPT_Size str_length = StringLength(str); if (str_length == 0) return *this; // compute the size of the new string NPT_Size old_length = GetLength(); NPT_Size new_length = str_length + GetLength(); // prepare to write the new string char* src = m_Chars; char* nst = Buffer::Create(new_length, new_length); char* dst = nst; // copy the beginning of the old string if (where > 0) { CopyBuffer(dst, src, where); src += where; dst += where; } // copy the inserted string CopyString(dst, str); dst += str_length; // copy the end of the old string if (old_length > where) { CopyString(dst, src); } // use the new string if (m_Chars) delete GetBuffer(); m_Chars = nst; return *this; }
/*---------------------------------------------------------------------- | NPT_String::Assign +---------------------------------------------------------------------*/ void NPT_String::Assign(const char* str, NPT_Size length) { if (str == NULL || length == 0) { Reset(); } else { for (unsigned int i=0; i<length-1; i++) { if (str[i] == '\0') { if (i == 0) { Reset(); return; } else { length = i; break; } } } PrepareToWrite(length); CopyBuffer(m_Chars, str, length); m_Chars[length] = '\0'; } }
//+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- Do we have enough bars to work with if(Bars(_Symbol,_Period)<60) // if total bars is less than 60 bars { Alert("We have less than 60 bars, EA will now exit!!"); return; } // We will use the static Old_Time variable to serve the bar time. // At each OnTick execution we will check the current bar time with the saved one. // If the bar time isn't equal to the saved time, it indicates that we have a new tick. static datetime Old_Time; datetime New_Time[1]; bool IsNewBar=false; // copying the last bar time to the element New_Time[0] int copied=CopyTime(_Symbol,_Period,0,1,New_Time); if(copied>0) // ok, the data has been copied successfully { if(Old_Time!=New_Time[0]) // if old time isn't equal to new bar time { IsNewBar=true; // if it isn't a first call, the new bar has appeared if(MQL5InfoInteger(MQL5_DEBUGGING)) Print("We have new bar here ",New_Time[0]," old time was ",Old_Time); Old_Time=New_Time[0]; // saving bar time } } else { Alert("Error in copying historical times data, error =",GetLastError()); ResetLastError(); return; } //--- EA should only check for new trade if we have a new bar if(IsNewBar==false) { return; } //--- Do we have enough bars to work with int Mybars=Bars(_Symbol,_Period); if(Mybars<60) // if total bars is less than 60 bars { Alert("We have less than 60 bars, EA will now exit!!"); return; } //--- Define some MQL5 Structures we will use for our trade MqlTick latest_price; // To be used for getting recent/latest price quotes MqlTradeRequest mrequest; // To be used for sending our trade requests MqlTradeResult mresult; // To be used to get our trade results MqlRates mrate[]; // To be used to store the prices, volumes and spread of each bar ZeroMemory(mrequest); // Initialization of mrequest structure /* Let's make sure our arrays values for the Rates, ADX Values and MA values is store serially similar to the timeseries array */ // the rates arrays ArraySetAsSeries(mrate,true); // the ADX DI+values array ArraySetAsSeries(plsDI,true); // the ADX DI-values array ArraySetAsSeries(minDI,true); // the ADX values arrays ArraySetAsSeries(adxVal,true); // the MA-8 values arrays ArraySetAsSeries(maVal,true); //--- Get the last price quote using the MQL5 MqlTick Structure if(!SymbolInfoTick(_Symbol,latest_price)) { Alert("Error getting the latest price quote - error:",GetLastError(),"!!"); return; } //--- Get the details of the latest 3 bars if(CopyRates(_Symbol,_Period,0,3,mrate)<0) { Alert("Error copying rates/history data - error:",GetLastError(),"!!"); ResetLastError(); return; } //--- Copy the new values of our indicators to buffers (arrays) using the handle if(CopyBuffer(adxHandle,0,0,3,adxVal)<0 || CopyBuffer(adxHandle,1,0,3,plsDI)<0 || CopyBuffer(adxHandle,2,0,3,minDI)<0) { Alert("Error copying ADX indicator Buffers - error:",GetLastError(),"!!"); ResetLastError(); return; } if(CopyBuffer(maHandle,0,0,3,maVal)<0) { Alert("Error copying Moving Average indicator buffer - error:",GetLastError()); ResetLastError(); return; } //--- we have no errors, so continue //--- Do we have positions opened already? bool Buy_opened=false; // variable to hold the result of Buy opened position bool Sell_opened=false; // variables to hold the result of Sell opened position if(PositionSelect(_Symbol)==true) // we have an opened position { if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) { Buy_opened=true; //It is a Buy } else if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) { Sell_opened=true; // It is a Sell } } // Copy the bar close price for the previous bar prior to the current bar, that is Bar 1 p_close=mrate[1].close; // bar 1 close price /* 1. Check for a long/Buy Setup : MA-8 increasing upwards, previous price close above it, ADX > 22, +DI > -DI */ //--- Declare bool type variables to hold our Buy Conditions bool Buy_Condition_1=(maVal[0]>maVal[1]) && (maVal[1]>maVal[2]); // MA-8 Increasing upwards bool Buy_Condition_2 = (p_close > maVal[1]); // previuos price closed above MA-8 bool Buy_Condition_3 = (adxVal[0]>Adx_Min); // Current ADX value greater than minimum value (22) bool Buy_Condition_4 = (plsDI[0]>minDI[0]); // +DI greater than -DI //--- Putting all together if(Buy_Condition_1 && Buy_Condition_2) { if(Buy_Condition_3 && Buy_Condition_4) { // any opened Buy position? if(Buy_opened) { Alert("We already have a Buy Position!!!"); return; // Don't open a new Buy Position } ZeroMemory(mrequest); mrequest.action = TRADE_ACTION_DEAL; // immediate order execution mrequest.price = NormalizeDouble(latest_price.ask,_Digits); // latest ask price mrequest.sl = NormalizeDouble(latest_price.ask - STP*_Point,_Digits); // Stop Loss mrequest.tp = NormalizeDouble(latest_price.ask + TKP*_Point,_Digits); // Take Profit mrequest.symbol = _Symbol; // currency pair mrequest.volume = Lot; // number of lots to trade mrequest.magic = EA_Magic; // Order Magic Number mrequest.type = ORDER_TYPE_BUY; // Buy Order mrequest.type_filling = ORDER_FILLING_FOK; // Order execution type mrequest.deviation=100; // Deviation from current price //--- send order OrderSend(mrequest,mresult); // get the result code if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed { Alert("A Buy order has been successfully placed with Ticket#:",mresult.order,"!!"); } else { Alert("The Buy order request could not be completed -error:",GetLastError()); ResetLastError(); return; } } } /* 2. Check for a Short/Sell Setup : MA-8 decreasing downwards, previous price close below it, ADX > 22, -DI > +DI */ //--- Declare bool type variables to hold our Sell Conditions bool Sell_Condition_1 = (maVal[0]<maVal[1]) && (maVal[1]<maVal[2]); // MA-8 decreasing downwards bool Sell_Condition_2 = (p_close <maVal[1]); // Previous price closed below MA-8 bool Sell_Condition_3 = (adxVal[0]>Adx_Min); // Current ADX value greater than minimum (22) bool Sell_Condition_4 = (plsDI[0]<minDI[0]); // -DI greater than +DI //--- Putting all together if(Sell_Condition_1 && Sell_Condition_2) { if(Sell_Condition_3 && Sell_Condition_4) { // any opened Sell position? if(Sell_opened) { Alert("We already have a Sell position!!!"); return; // Don't open a new Sell Position } ZeroMemory(mrequest); mrequest.action=TRADE_ACTION_DEAL; // immediate order execution mrequest.price = NormalizeDouble(latest_price.bid,_Digits); // latest Bid price mrequest.sl = NormalizeDouble(latest_price.bid + STP*_Point,_Digits); // Stop Loss mrequest.tp = NormalizeDouble(latest_price.bid - TKP*_Point,_Digits); // Take Profit mrequest.symbol = _Symbol; // currency pair mrequest.volume = Lot; // number of lots to trade mrequest.magic = EA_Magic; // Order Magic Number mrequest.type= ORDER_TYPE_SELL; // Sell Order mrequest.type_filling = ORDER_FILLING_FOK; // Order execution type mrequest.deviation=100; // Deviation from current price //--- send order OrderSend(mrequest,mresult); // get the result code if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed { Alert("A Sell order has been successfully placed with Ticket#:",mresult.order,"!!"); } else { Alert("The Sell order request could not be completed -error:",GetLastError()); ResetLastError(); return; } } } return; }
DPT_RTN_T CopyBuffer(const DPT_LoggerIDlist_C& src) { return(CopyBuffer((uCHAR *) src.id_P, src.numIDs)); }
static int CopyBuffers (MME_Command_t* commandInfo) { int res = 0; int i; unsigned nbufs = commandInfo->NumberInputBuffers + commandInfo->NumberOutputBuffers; unsigned bufferPtrSize = nbufs * sizeof(MME_DataBuffer_t*); MME_DataBuffer_t **dataBufferPtrs = NULL; MME_DataBuffer_t *dataBuffers = NULL; if (nbufs == 0) { /* No buffers with this command */ goto error; } /* Allocate a kernel array of buffer pointers */ dataBufferPtrs = _ICS_OS_MALLOC(bufferPtrSize); if (!dataBufferPtrs) { res = -ENOMEM; goto error; } /* Allocate a kernel array of buffer descriptors */ dataBuffers = _ICS_OS_MALLOC(sizeof(MME_DataBuffer_t) * nbufs); if (!dataBuffers) { res = -ENOMEM; goto error_free; } /* Get the array of pointers to data buffers */ if (copy_from_user(dataBufferPtrs, commandInfo->DataBuffers_p, bufferPtrSize)) { MME_EPRINTF(MME_DBG_COMMAND, "Failed to copy buffer ptrs \n" "Kernel 0x%08x, User 0x%08x, Size %d\n", (int)dataBufferPtrs, (int)commandInfo->DataBuffers_p, (int)bufferPtrSize); res = -EFAULT; goto error_free; } /* Point to the array in kernel space */ commandInfo->DataBuffers_p = dataBufferPtrs; MME_PRINTF(MME_DBG_COMMAND, "Buffer ptrs at 0x%08x\n", (int)commandInfo->DataBuffers_p); /* Iterate over all input and output buffers */ for (i = 0; i < nbufs; i++) { res = CopyBuffer(&dataBuffers[i], dataBufferPtrs[i]); if (res) { goto error_freeBufs; } /* Point to the kernel copy */ dataBufferPtrs[i] = (MME_DataBuffer_t*)(&dataBuffers[i]); MME_PRINTF(MME_DBG_COMMAND, "Done buffer[%d] at 0x%08x\n", i, (int)dataBufferPtrs[i]); } /* TODO - error cases */ /* TODO - deallocation */ /* TODO - remove hack */ return res; error_freeBufs: for ( i -= 1 ; i >= 0; i--) _ICS_OS_FREE(dataBuffers[i].ScatterPages_p); error_free: if (dataBuffers) _ICS_OS_FREE(dataBuffers); if (dataBufferPtrs) _ICS_OS_FREE(dataBufferPtrs); error: return res; }
void g2LabelEdit::KeyEvent(unsigned char key, bool IsSpecial) { // In OSX the backspace maps to DEL while DEL maps to backspace, need to swap #if __APPLE__ if(key == 127) key = 8; else if(key == 8) key = 127; #endif // Ignore all inputs if disabled if(GetDisabled()) return; /*** User Movement / Editing ***/ // If system key (i.e. left/right) else if(IsSpecial) { // Move far left/right if(key == GLUT_KEY_LEFT && glutGetModifiers() == GLUT_ACTIVE_CTRL) { CursorIndex = 0; ViewIndex = 0; } else if(key == GLUT_KEY_RIGHT && glutGetModifiers() == GLUT_ACTIVE_CTRL) { // Move the cursor to the far right and calculate // what is the best position for the view buffer to be moved to CursorIndex = (int)strlen(TextBuffer); // When something is written on-screen, check to see where our // left-view limit should be ViewIndex = (int)strlen(TextBuffer) - RenderableLeftChars(CursorIndex); } // If left/right, move the cursor if(key == GLUT_KEY_LEFT && CursorIndex > 0) { // Move cursor to left CursorIndex--; // Move view left if we can if(CursorIndex < ViewIndex) ViewIndex--; } else if(key == GLUT_KEY_RIGHT && CursorIndex < (int)strlen(TextBuffer)) { // Move cursor to right CursorIndex++; // If the movement will cause us to be offsreen.. while(LengthToCursor() > Width) ViewIndex++; } } // Backspace else if(key == 8) { // Is there anything to delete? if(strlen(TextBuffer) <= 0) return; // Ignore if we are at the 0 position else if(CursorIndex <= 0) return; else { // Delete this character by shifting everything from right to left by 1 // Note that this copies the null terminator for(size_t i = CursorIndex; i <= strlen(TextBuffer); i++) TextBuffer[i - 1] = TextBuffer[i]; // Decrease the cursor position CursorIndex--; // Is the cursor now smaller than the current view index // Move view left if we can while(CursorIndex < ViewIndex) { ViewIndex -= 5; if(ViewIndex < 0) ViewIndex = 0; } } } // Delete else if(key == 127) { // Is there anything to delete? if(CursorIndex >= (int)strlen(TextBuffer)) return; else { // Delete this character by shifting everything from right to left by 1 // Note that this copies the null terminator for(size_t i = CursorIndex; i < strlen(TextBuffer); i++) TextBuffer[i] = TextBuffer[i + 1]; // Cursor does not move } } // Commit / enter else if(key == '\r') { DidUserReturn = true; } /*** Cut, Copy, or Paste ***/ // Note that when doing a ctrl+key event, the given number // is offset from 'a', meaning true ascii = 'a' - key + 1 // Cut text else if(key == ('x' - 'a' + 1) && glutGetModifiers() == GLUT_ACTIVE_CTRL) { // Copy into buffer, then set text to empty CopyBuffer(); SetText(""); } // Copy text else if(key == ('c' - 'a' + 1) && glutGetModifiers() == GLUT_ACTIVE_CTRL) { // Direct copy CopyBuffer(); } // Paste text else if(key == ('v' - 'a' + 1) && glutGetModifiers() == GLUT_ACTIVE_CTRL) { // Direct paste PasteBuffer(); } /*** Regular User Input ***/ // Standard keyboard input; add character else if(isprint(key) != 0) { // Can we actually add anything? if(strlen(TextBuffer) < g2LabelEdit_TextBufferLength - 1 && !IsSpecial) { // Ignore if it isn't a valid character if(!InFilter(key)) return; // If we are writing to the end, make sure to string-cap if(CursorIndex == (int)strlen(TextBuffer)) { // Write to the old string-end and move the terminator a little further TextBuffer[CursorIndex + 0] = key; TextBuffer[CursorIndex + 1] = '\0'; } // Offset one char to the right, then set else { // Null-terminate the end of the string int Length = (int)strlen(TextBuffer); for(int i = Length; i > CursorIndex; i--) TextBuffer[i] = TextBuffer[i - 1]; TextBuffer[CursorIndex] = key; TextBuffer[Length + 1] = '\0'; } // Grow cursor position to be after the current char CursorIndex++; } // If the movement will cause us to be offsreen.. while(LengthToCursor() > Width) ViewIndex++; } // All done for each type of event }
bufPtr CompressStandard(bufPtr srcBuf, int flag) { if(!srcBuf) return NULL; // allocate a 2^12 sized buffer bufPtr destBuf = CreateBuffer(0x1000); if(!destBuf) return NULL; destBuf->wOffset = 0; int i = 0, j = 0, k = 0; int byte = 0; int highByte = 0; int remainder = 0; int word = 0; int identical = 0; int oldSize = srcBuf->length; comp_mode p = mode_no_compress; int n = 0; int x = 0, q = 0, r; // flag is an endianness flag as follows // flag ? bigEndian() : littleEndian(); // hence default behavior is littleEndian // int *size; this is the return size of the compressed data // after the routine has finished for(i = 0; i < oldSize; ) { byte = GetByte(srcBuf, i); // grab a char from the buffer. k = 0; // r = the same logical value (0 or 1) as q, but not the same value necesarily. r = !!q; // looking at the bytes from the start of the array up until the byte at i for some reason... for(j = 0; j < i - 1; j++) { // if( GetByte(srcBuf, j) == byte) { for(n = j; n < oldSize; n++) { if( GetByte(srcBuf, n) != GetByte(srcBuf, n + i) ) break; } if(n > k) k = n, word = j; } } identical = 0; // get the number of bytes starting at i that are identical to // the byte at i for( j = (i + 1); j < oldSize; j++ ) { if( GetByte(srcBuf, j) != byte ) break; identical++; } if( identical > (1 + r) ) p = mode_byte_repeat; else { // if looking for repeating bytes failed, we're going to try // to find a sequence of repeating words (16-bit) instead word = Get2Bytes(srcBuf, i); identical = 0; for(j = i + 2; j < oldSize; j++) { // while words are matched, the total number of actual bytes // matched is recorded, not the number of words if(Get2Bytes(srcBuf, j) != word) { if(GetByte(srcBuf, j) == byte) identical++; break; } else identical += 2; } if( identical > (2 + r) ) p = mode_word_repeat; else { // well that didn't work so we're going to try to // find an incrementing byte series // MON is iffy on how well this will actually work... // due to how the actual algorithm decompresses stuff... identical = 0; for(j = (i + 1); j < oldSize; j++) { if(GetByte(srcBuf, j) != (byte + j) ) break; identical++; } if( identical > (1 + r) ) p = mode_increment; else p = mode_no_compress; } } // what the f**k is this if( (k > r + 3) && (k > n + (p % 2)) ) { p = mode_copy; n = k; } if(!p) q++, i++; else { if(q) { q--; if(q > 0x1F) PutByte(destBuf, 0xE0 + (q >> 8) ); PutByte(destBuf, q); q++; CopyBuffer(destBuf, srcBuf, destBuf->wOffset, i - q, q); destBuf->wOffset += q; q = 0; } i += identical; identical--; if(identical > 0x1F) { PutByte(destBuf, 0xE0 + (identical >> 8) + (p << 2)); PutByte(destBuf, identical); } else PutByte(destBuf, ((p << 5)+ identical)); switch(p) { case mode_byte_repeat: case mode_increment: PutByte(destBuf, byte); break; case mode_word_repeat: Put2Bytes(destBuf, word); break; case mode_copy: if(flag) { PutByte(destBuf, word >> 8); PutByte(destBuf, word); } else { Put2Bytes(destBuf, word); } break; case mode_no_compress: default: break; }
// make this obj = to that obj void operator =(const DPT_LoggerIDlist_C& src) { CopyBuffer(src); }
void operator =( dptBuffer_S *src) { CopyBuffer(src); }