/*------------------------------------------------------------------------------ -- This file is a part of the SocExplorer Software -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 3 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -------------------------------------------------------------------------------*/ /*-- Author : Alexis Jeandet -- Mail : alexis.jeandet@lpp.polytechnique.fr ----------------------------------------------------------------------------*/ #include "memeditor.h" #include "malloc.h" memEditor::memEditor(QWidget *parent) : QWidget(parent) { this->verticalSpliter = new QSplitter; this->ctrlWidget = new QWidget; this->verticalSpliter->setOrientation(Qt::Horizontal); this->mainLayout = new QHBoxLayout; this->ctrlLayout = new QVBoxLayout; this->hexEditor = new QHexEdit; this->addressSpnBx = new QHexSpinBox; this->SizeWidget = new MemSizeWdgt(256); this->readMemQPb = new QPushButton(tr("Read Mem")); this->writeMemQPb = new QPushButton(tr("Write Mem")); this->ctrlLayout->addWidget(this->addressSpnBx); this->ctrlLayout->addWidget(this->SizeWidget); this->ctrlLayout->addWidget(this->readMemQPb); this->ctrlLayout->addWidget(this->writeMemQPb); this->ctrlWidget->setLayout(this->ctrlLayout); this->verticalSpliter->addWidget(this->hexEditor); this->verticalSpliter->addWidget(this->ctrlWidget); this->mainLayout->addWidget(this->verticalSpliter); this->setLayout(this->mainLayout); connect(this->readMemQPb,SIGNAL(clicked()),this,SLOT(readMemSlt())); connect(this->writeMemQPb,SIGNAL(clicked()),this,SLOT(writeMemSlt())); this->SizeWidget->setMaximum(16384); } void memEditor::writeMemSlt() { QByteArray data = this->hexEditor->data(); unsigned int length = data.length()/4; unsigned int* buffer=(unsigned int*)malloc(length*sizeof(int)); unsigned int address = this->hexEditor->addressOffset(); for(int i=0;(unsigned int)iWriteSig(buffer,length,address); free(buffer); } void memEditor::setAddress(quint32 address) { this->addressSpnBx->setValue(address); } void memEditor::setLength(quint32 length) { this->SizeWidget->setSizeValue(length); } void memEditor::readMemSlt() { this->SizeWidget->updateSizeValue(); unsigned int size = this->SizeWidget->getsize()/4; unsigned int buffer[16384]; unsigned char buffChar[16384*4]; unsigned int address = this->addressSpnBx->value(); if((emit this->ReadSig(buffer,size,address&(-4)))==size) { for(int i=0;(unsigned int)i>24)&0xFF; buffChar[(4*i)+1]=(buffer[i]>>16)&0xFF; buffChar[(4*i)+2]=(buffer[i]>>8)&0xFF; buffChar[(4*i)+3]=(buffer[i])&0xFF; } QByteArray data = QByteArray((char*)buffChar,size*4); this->hexEditor->setData(data); this->hexEditor->setAddressOffset(address&(-4)); this->addressSpnBx->setValue(address&(-4)); } }