Beispiel #1
0
//==============================================================================
void CC_UnitDriver::write_lock_to_info_page(uint8_t lock_byte)
{
    select_info_page_flash(true);

    ByteVector data;
    data.push_back(0xFF);
    data.push_back(lock_byte);

    DataSectionStore store;
    store.add_section(DataSection(0, data), true);
    write_flash_slow(store);

    select_info_page_flash(false);
}
/*----------------------------------------------------------------------------*/
void DDAProtocol :: pushData(unsigned char header, const DDAProtocol :: ByteVector &data)
{
  ByteVector txData;
  unsigned size = data.size();
  unsigned char crc = 0;
  txData.push_back(ENQ);
  txData.push_back(header);
  crc += header;
  txData.push_back(size + 3);
  crc += size + 3;
  for(unsigned i = 0; i < size; i++)
  {
    txData.push_back(data[i]);
    crc += data[i];
  }
  txData.push_back(crc);
  m_txData.push_back(txData);
}
Beispiel #3
0
void SoftwareBreakpointManager::getOpcode(uint32_t type,
                                          ByteVector &opcode) const {
#if defined(OS_WIN32) && defined(ARCH_ARM)
  if (type == 4) {
    static const uint32_t WinARMBPType = 2;
    DS2LOG(Warning,
           "requesting a breakpoint of size %u on Windows ARM, "
           "adjusting to type %u",
           type, WinARMBPType);
    type = WinARMBPType;
  }
#endif

  opcode.clear();

  // TODO: We shouldn't have preprocessor checks for ARCH_ARM vs ARCH_ARM64
  // because we might be an ARM64 binary debugging an ARM inferior.
  switch (type) {
#if defined(ARCH_ARM)
  case 2: // udf #1
    opcode.push_back('\xde');
#if defined(OS_POSIX)
    opcode.push_back('\x01');
#elif defined(OS_WIN32)
    opcode.push_back('\xfe');
#endif
    break;
  case 3: // udf.w #0
    opcode.push_back('\xa0');
    opcode.push_back('\x00');
    opcode.push_back('\xf7');
    opcode.push_back('\xf0');
    break;
  case 4: // udf #16
    opcode.push_back('\xe7');
    opcode.push_back('\xf0');
    opcode.push_back('\x01');
    opcode.push_back('\xf0');
    break;
#elif defined(ARCH_ARM64)
  case 4:
    opcode.push_back('\xd4');
    opcode.push_back('\x20');
    opcode.push_back('\x20');
    opcode.push_back('\x00');
    break;
#endif
  default:
    DS2LOG(Error, "invalid breakpoint type %d", type);
    DS2BUG("invalid breakpoint type");
    break;
  }

#if !(defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE))
#error "Target not supported."
#endif

#if defined(ENDIAN_LITTLE)
  std::reverse(opcode.begin(), opcode.end());
#endif
}
Byte calculateImageBrightnessFactor(const std::string& inImageFilePath)
{
    BrightnessState state;
    InputFile inputFile;
    ByteVector brightnessValues;
    DistanceAndBrightnessVector valuesForAverage;
    
    inputFile.OpenFile(inImageFilePath);
    
    state.mStream = inputFile.GetInputStream();
    InitializeDecodingState(state);
    StartRead(state);
    
    LongBufferSizeType samplesSkipping = 1; // max samples 20
    if(state.mJPGState.output_width > 500)
        samplesSkipping = state.mJPGState.output_width / 50; // max samples - 50
    else if(state.mJPGState.output_width > 20)
        samplesSkipping = 10; // max samples - 50
    
    LongBufferSizeType rowsSkipping = 1; // max samples 20
    if(state.mJPGState.output_height > 500)
        rowsSkipping = state.mJPGState.output_height / 50; // max samples - 50
    else if(state.mJPGState.output_height > 20)
        rowsSkipping = 10; // max samples - 50
    
    LongBufferSizeType rowCounter = 0;
    
    
    // read samples from image, converting to hsb and keeping the "b" component, as a brightness factor
    while(state.mJPGState.output_scanline < state.mJPGState.output_height)
    {
        try
        {
            state.mTotalSampleRows = jpeg_read_scanlines(&(state.mJPGState), state.mSamplesBuffer, state.mJPGState.rec_outbuf_height);
            ++rowCounter;
            if(rowCounter >= rowsSkipping)
                rowCounter = 0;
            else if(rowCounter != 1)
                continue;
        }
        catch(HummusJPGException)
        {
            state.mTotalSampleRows = 0;
        }
        state.mIndexInRow = 0;
        state.mCurrentSampleRow = 0;
        
        while(state.mCurrentSampleRow < state.mTotalSampleRows)
        {
            LongBufferSizeType row_stride = state.mJPGState.output_width * state.mJPGState.output_components;
            
            // convert samples to HSB (note that some samples are skipped)
            for(LongBufferSizeType i=0;i<row_stride;i+=(state.mJPGState.output_components*samplesSkipping))
            {
                // get rgb
                Byte r = state.mSamplesBuffer[state.mCurrentSampleRow][i];
                Byte g = state.mSamplesBuffer[state.mCurrentSampleRow][i+1];
                Byte b = state.mSamplesBuffer[state.mCurrentSampleRow][i+2];
                
                // calculate brightness [converting to HSB]
                brightnessValues.push_back(RGBtoHSVtoBrightness(r,g,b));
            }
            
            
            ++state.mCurrentSampleRow;
        }
    }
    FinalizeDecoding(state);
    
    // prepare distance data and sort, to remove extremes from calculation
    ByteVector::const_iterator it = brightnessValues.begin();
    for(;it!=brightnessValues.end();++it)
        valuesForAverage.push_back(DistanceAndBrightness(*it,calculateDistance(*it,brightnessValues)));
    
    std::sort(valuesForAverage.begin(),valuesForAverage.end(),DistanceAndBrightnessSort);
    
    
    // now simply calculate the average based on the first 2/3 of the vector, to reduce the effects of extremes
    double average = 0;
    DistanceAndBrightnessVector::const_iterator itCurrent = valuesForAverage.begin();
    unsigned long interestingItemsCount = floor(valuesForAverage.size()*2.0/3.0);
    DistanceAndBrightnessVector::const_iterator itEnd = valuesForAverage.begin()+interestingItemsCount;
    for(itCurrent = valuesForAverage.begin();itCurrent!=itEnd;++itCurrent)
        average+=(double)(itCurrent->brightness)/interestingItemsCount;
    return ceil(average);
}