Commit ffd9d7da authored by David Košenina's avatar David Košenina

FirmwareID, eeprom read, callibration save

parent d8570479
......@@ -239,6 +239,9 @@ int clientMessageHeader(messageHeader* dest, EMessage message)
case mHardwareEepromRead:
dest->size = sizeof(csHardwareEepromRead);
break;
case mHardwareEepromReadFirmwareID:
dest->size = sizeof(csHardwareEepromReadFirmwareID);
break;
case mHardwareEepromWrite:
dest->size = sizeof(csHardwareEepromWrite);
break;
......@@ -312,6 +315,9 @@ int serverMessageHeader(messageHeader* dest, EMessage message)
case mHardwareEepromRead:
dest->size = sizeof(scHardwareEepromRead);
break;
case mHardwareEepromReadFirmwareID:
dest->size = sizeof(scHardwareEepromReadFirmwareID);
break;
case mHardwareEepromWrite:
dest->size = sizeof(scHardwareEepromWrite);
break;
......@@ -417,6 +423,11 @@ int isClientHeaderOk(messageHeader* header)
{
return SCOPEFUN_SUCCESS;
}
case mHardwareEepromReadFirmwareID:
if (header->size == sizeof(csHardwareEepromReadFirmwareID))
{
return SCOPEFUN_SUCCESS;
}
case mHardwareEepromWrite:
if(header->size == sizeof(csHardwareEepromWrite))
{
......@@ -527,6 +538,11 @@ int isServerHeaderOk(messageHeader* header)
{
return SCOPEFUN_SUCCESS;
}
case mHardwareEepromReadFirmwareID:
if (header->size == sizeof(scHardwareEepromReadFirmwareID))
{
return SCOPEFUN_SUCCESS;
}
case mHardwareEepromWrite:
if(header->size == sizeof(scHardwareEepromWrite))
{
......@@ -1347,6 +1363,42 @@ SCOPEFUN_API int netHardwareEepromRead(SFContext* ctx, SEeprom* data, int size,
apiUnlock(ctx);
return result;
}
SCOPEFUN_API int netHardwareEepromReadFirmwareID(SFContext* ctx, SEeprom* data, int size, int adress)
{
int result = SCOPEFUN_FAILURE;
apiLock(ctx);
struct SocketContext* pSocketCtx = (SocketContext*)ctx->net;
if (pSocketCtx->socket > 0 && ctx->api.active > 0)
{
int ret = 0;
int sent = 0;
int received = 0;
// message
csHardwareEepromReadFirmwareID message = { 0 };
clientMessageHeader(&message.header, mHardwareEepromReadFirmwareID);
message.size = size;
message.address = adress;
ret = socketSend(pSocketCtx, (char*)&message, sizeof(message), 0, &sent);
if (ret == PURESOCKET_SUCCESS && sent == sizeof(csHardwareEepromReadFirmwareID))
{
// response
messageHeader header = { 0 };
ret = socketRecv(pSocketCtx, (char*)&header, sizeof(messageHeader), 0, &received);
if (ret == PURESOCKET_SUCCESS && received == sizeof(messageHeader) && isServerHeaderOk((messageHeader*)&header) == SCOPEFUN_SUCCESS)
{
ret = socketRecv(pSocketCtx, (char*)data, sizeof(SEeprom), 0, &received);
if (ret == PURESOCKET_SUCCESS && received == sizeof(SEeprom))
{
result = apiResult(ret);
}
}
}
}
apiUnlock(ctx);
return result;
}
SCOPEFUN_API int netHardwareEepromWrite(SFContext* ctx, SEeprom* data, int size, int adress)
{
int result = SCOPEFUN_FAILURE;
......@@ -1643,12 +1695,36 @@ SCOPEFUN_API int usbHardwareEepromRead(SFContext* ctx, SEeprom* buffer, int size
if(pUsbCtx->version == HARDWARE_VERSION_2)
{
int ret = usbFx3ReadEEPROM(pUsbCtx, (byte*)&buffer->data.bytes[0], size, adress);
result = apiResult(ret);
result = apiResult(ret);
}
}
apiUnlock(ctx);
return result;
}
SCOPEFUN_API int usbHardwareEepromReadFirmwareID(SFContext* ctx, SEeprom* buffer, int size, int adress)
{
int result = SCOPEFUN_FAILURE;
apiLock(ctx);
if (ctx->api.active > 0)
{
struct UsbContext* pUsbCtx = (struct UsbContext*)ctx->usb;
if (pUsbCtx->version == HARDWARE_VERSION_1)
{
int ret = usbFx3ReadEEPROMFirmwareID(pUsbCtx, (byte*)&buffer->data.bytes[0], SCOPEFUN_EEPROM_FIRMWARE_NAME_BYTES, adress);
result = apiResult(ret);
}
if (pUsbCtx->version == HARDWARE_VERSION_2)
{
int ret = usbFx3ReadEEPROMFirmwareID(pUsbCtx, (byte*)&buffer->data.bytes[0], SCOPEFUN_EEPROM_FIRMWARE_NAME_BYTES, adress);
result = apiResult(ret);
}
}
apiUnlock(ctx);
return result;
}
SCOPEFUN_API int usbHardwareEepromWrite(SFContext* ctx, SEeprom* buffer, int size, int address)
{
int result = SCOPEFUN_FAILURE;
......@@ -1853,6 +1929,19 @@ SCOPEFUN_API int sfHardwareEepromRead(SFContext* ctx, SEeprom* eeprom, int size,
}
return ret;
}
SCOPEFUN_API int sfHardwareEepromReadFirmwareID(SFContext* ctx, SEeprom* eeprom, int size, int adress)
{
int ret = 0;
if (sfIsUsb(ctx))
{
ret = usbHardwareEepromReadFirmwareID(ctx, eeprom, size, adress);
}
if (sfIsNetwork(ctx))
{
ret = netHardwareEepromReadFirmwareID(ctx, eeprom, size, adress);
}
return ret;
}
SCOPEFUN_API int sfHardwareEepromWrite(SFContext* ctx, SEeprom* eeprom, int size, int adress)
{
int ret = 0;
......
......@@ -68,6 +68,7 @@ typedef unsigned long long ularge;
#define SCOPEFUN_FIRMWARE_FX2 16384
#define SCOPEFUN_FIRMWARE_FPGA (4*1024*1024)
#define SCOPEFUN_EEPROM_BYTES (256*1024)
#define SCOPEFUN_EEPROM_FIRMWARE_NAME_BYTES (16)
#define SCOPEFUN_GENERATOR 32768
/*----------------------------------------
......@@ -531,6 +532,7 @@ typedef enum _EMessage
mHardwareUploadFpga,
mHardwareUploadGenerator,
mHardwareEepromRead,
mHardwareEepromReadFirmwareID,
mHardwareEepromWrite,
mHardwareEepromErase,
mHardwareClose,
......@@ -661,6 +663,14 @@ typedef struct
uint reserved;
} csHardwareEepromRead;
typedef struct
{
messageHeader header;
uint size;
uint address;
uint reserved;
} csHardwareEepromReadFirmwareID;
typedef struct
{
messageHeader header;
......@@ -795,6 +805,12 @@ typedef struct
SEeprom eeprom;
} scHardwareEepromRead;
typedef struct
{
messageHeader header;
SEeprom eeprom;
} scHardwareEepromReadFirmwareID;
typedef struct
{
messageHeader header;
......@@ -1005,6 +1021,7 @@ SCOPEFUN_DELETE(SActiveClients)
SCOPEFUN_API int sfHardwareUploadFpga(SFContext* INPUT, SFpga* INPUT);
SCOPEFUN_API int sfHardwareUploadGenerator(SFContext* INPUT, SGenerator* INPUT);
SCOPEFUN_API int sfHardwareEepromRead(SFContext* INPUT, SEeprom* INOUT, int INPUT, int INPUT);
SCOPEFUN_API int sfHardwareEepromReadFirmwareID(SFContext* INPUT, SEeprom* INOUT, int INPUT, int INPUT);
SCOPEFUN_API int sfHardwareEepromWrite(SFContext* INPUT, SEeprom* INPUT, int INPUT, int INPUT);
SCOPEFUN_API int sfHardwareEepromErase(SFContext* INPUT);
SCOPEFUN_API int sfHardwareClose(SFContext* INPUT);
......@@ -1108,6 +1125,7 @@ SCOPEFUN_DELETE(SActiveClients)
SCOPEFUN_API int sfHardwareUploadFpga(SFContext* ctx, SFpga* fpgs);
SCOPEFUN_API int sfHardwareUploadGenerator(SFContext* ctx, SGenerator* gen);
SCOPEFUN_API int sfHardwareEepromRead(SFContext* ctx, SEeprom* eeprom, int size, int adrees);
SCOPEFUN_API int sfHardwareEepromReadFirmwareID(SFContext* ctx, SEeprom* eeprom, int size, int adrees);
SCOPEFUN_API int sfHardwareEepromWrite(SFContext* ctx, SEeprom* eeprom, int size, int adress);
SCOPEFUN_API int sfHardwareEepromErase(SFContext* ctx);
SCOPEFUN_API int sfHardwareClose(SFContext* ctx);
......
......@@ -113,6 +113,7 @@ SCOPEFUN_DISPLAY = _scopefunapi.SCOPEFUN_DISPLAY
SCOPEFUN_FIRMWARE_FX2 = _scopefunapi.SCOPEFUN_FIRMWARE_FX2
SCOPEFUN_FIRMWARE_FPGA = _scopefunapi.SCOPEFUN_FIRMWARE_FPGA
SCOPEFUN_EEPROM_BYTES = _scopefunapi.SCOPEFUN_EEPROM_BYTES
SCOPEFUN_EEPROM_FIRMWARE_NAME_BYTES = _scopefunapi.SCOPEFUN_EEPROM_FIRMWARE_NAME_BYTES
SCOPEFUN_GENERATOR = _scopefunapi.SCOPEFUN_GENERATOR
SCOPEFUN_CAPTURE_TYPE_NONE = _scopefunapi.SCOPEFUN_CAPTURE_TYPE_NONE
SCOPEFUN_CAPTURE_TYPE_HEADER = _scopefunapi.SCOPEFUN_CAPTURE_TYPE_HEADER
......@@ -1880,6 +1881,7 @@ mHardwareUploadFx2 = _scopefunapi.mHardwareUploadFx2
mHardwareUploadFpga = _scopefunapi.mHardwareUploadFpga
mHardwareUploadGenerator = _scopefunapi.mHardwareUploadGenerator
mHardwareEepromRead = _scopefunapi.mHardwareEepromRead
mHardwareEepromReadFirmwareID = _scopefunapi.mHardwareEepromReadFirmwareID
mHardwareEepromWrite = _scopefunapi.mHardwareEepromWrite
mHardwareEepromErase = _scopefunapi.mHardwareEepromErase
mHardwareClose = _scopefunapi.mHardwareClose
......@@ -2336,6 +2338,40 @@ class csHardwareEepromRead(_object):
csHardwareEepromRead_swigregister = _scopefunapi.csHardwareEepromRead_swigregister
csHardwareEepromRead_swigregister(csHardwareEepromRead)
class csHardwareEepromReadFirmwareID(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, csHardwareEepromReadFirmwareID, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, csHardwareEepromReadFirmwareID, name)
__repr__ = _swig_repr
__swig_setmethods__["header"] = _scopefunapi.csHardwareEepromReadFirmwareID_header_set
__swig_getmethods__["header"] = _scopefunapi.csHardwareEepromReadFirmwareID_header_get
if _newclass:
header = _swig_property(_scopefunapi.csHardwareEepromReadFirmwareID_header_get, _scopefunapi.csHardwareEepromReadFirmwareID_header_set)
__swig_setmethods__["size"] = _scopefunapi.csHardwareEepromReadFirmwareID_size_set
__swig_getmethods__["size"] = _scopefunapi.csHardwareEepromReadFirmwareID_size_get
if _newclass:
size = _swig_property(_scopefunapi.csHardwareEepromReadFirmwareID_size_get, _scopefunapi.csHardwareEepromReadFirmwareID_size_set)
__swig_setmethods__["address"] = _scopefunapi.csHardwareEepromReadFirmwareID_address_set
__swig_getmethods__["address"] = _scopefunapi.csHardwareEepromReadFirmwareID_address_get
if _newclass:
address = _swig_property(_scopefunapi.csHardwareEepromReadFirmwareID_address_get, _scopefunapi.csHardwareEepromReadFirmwareID_address_set)
__swig_setmethods__["reserved"] = _scopefunapi.csHardwareEepromReadFirmwareID_reserved_set
__swig_getmethods__["reserved"] = _scopefunapi.csHardwareEepromReadFirmwareID_reserved_get
if _newclass:
reserved = _swig_property(_scopefunapi.csHardwareEepromReadFirmwareID_reserved_get, _scopefunapi.csHardwareEepromReadFirmwareID_reserved_set)
def __init__(self):
this = _scopefunapi.new_csHardwareEepromReadFirmwareID()
try:
self.this.append(this)
except __builtin__.Exception:
self.this = this
__swig_destroy__ = _scopefunapi.delete_csHardwareEepromReadFirmwareID
__del__ = lambda self: None
csHardwareEepromReadFirmwareID_swigregister = _scopefunapi.csHardwareEepromReadFirmwareID_swigregister
csHardwareEepromReadFirmwareID_swigregister(csHardwareEepromReadFirmwareID)
class csHardwareEepromWrite(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, csHardwareEepromWrite, name, value)
......@@ -2832,6 +2868,32 @@ class scHardwareEepromRead(_object):
scHardwareEepromRead_swigregister = _scopefunapi.scHardwareEepromRead_swigregister
scHardwareEepromRead_swigregister(scHardwareEepromRead)
class scHardwareEepromReadFirmwareID(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, scHardwareEepromReadFirmwareID, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, scHardwareEepromReadFirmwareID, name)
__repr__ = _swig_repr
__swig_setmethods__["header"] = _scopefunapi.scHardwareEepromReadFirmwareID_header_set
__swig_getmethods__["header"] = _scopefunapi.scHardwareEepromReadFirmwareID_header_get
if _newclass:
header = _swig_property(_scopefunapi.scHardwareEepromReadFirmwareID_header_get, _scopefunapi.scHardwareEepromReadFirmwareID_header_set)
__swig_setmethods__["eeprom"] = _scopefunapi.scHardwareEepromReadFirmwareID_eeprom_set
__swig_getmethods__["eeprom"] = _scopefunapi.scHardwareEepromReadFirmwareID_eeprom_get
if _newclass:
eeprom = _swig_property(_scopefunapi.scHardwareEepromReadFirmwareID_eeprom_get, _scopefunapi.scHardwareEepromReadFirmwareID_eeprom_set)
def __init__(self):
this = _scopefunapi.new_scHardwareEepromReadFirmwareID()
try:
self.this.append(this)
except __builtin__.Exception:
self.this = this
__swig_destroy__ = _scopefunapi.delete_scHardwareEepromReadFirmwareID
__del__ = lambda self: None
scHardwareEepromReadFirmwareID_swigregister = _scopefunapi.scHardwareEepromReadFirmwareID_swigregister
scHardwareEepromReadFirmwareID_swigregister(scHardwareEepromReadFirmwareID)
class scHardwareEepromWrite(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, scHardwareEepromWrite, name, value)
......@@ -3455,6 +3517,10 @@ def sfHardwareEepromRead(arg1, INOUT, arg3, arg4):
return _scopefunapi.sfHardwareEepromRead(arg1, INOUT, arg3, arg4)
sfHardwareEepromRead = _scopefunapi.sfHardwareEepromRead
def sfHardwareEepromReadFirmwareID(arg1, INOUT, arg3, arg4):
return _scopefunapi.sfHardwareEepromReadFirmwareID(arg1, INOUT, arg3, arg4)
sfHardwareEepromReadFirmwareID = _scopefunapi.sfHardwareEepromReadFirmwareID
def sfHardwareEepromWrite(arg1, arg2, arg3, arg4):
return _scopefunapi.sfHardwareEepromWrite(arg1, arg2, arg3, arg4)
sfHardwareEepromWrite = _scopefunapi.sfHardwareEepromWrite
......
This diff is collapsed.
......@@ -197,6 +197,27 @@ int usbFx3UploadFirmwareToFpga(UsbContext* ctx, unsigned char* buffer, int size,
return PUREUSB_FAILURE;
}
int usbFx3ReadEEPROMFirmwareID(UsbContext* ctx, unsigned char* buffer, int size, int readadress)
{
int transfered = 0;
if (usbFxxIsConnected(ctx))
{
// bReqType: 0xC0, bRequest : 0xB0, wLength - MAX : 0x1000
int read = libusb_control_transfer((libusb_device_handle*)ctx->device,
0xC0,
0xB0,
(readadress >> 16) & 0xffff,
(readadress) & 0xffff,
buffer,
size,
100000);
if (read == size)
{
return PUREUSB_SUCCESS;
}
}
return PUREUSB_FAILURE;
}
int usbFx3ReadEEPROM(UsbContext* ctx, unsigned char* buffer, int size, int readadress)
{
int transfered = 0;
......
......@@ -96,6 +96,7 @@ int usbFx3CheckFirmwareID(UsbContext* ctx, char* data);
int usbFx3UploadFirmwareToFx3(UsbContext* ctx, const char* path);
int usbFx3UploadFirmwareToFpga(UsbContext* ctx, unsigned char* buffer, int size, int swapBits);
int usbFx3ReadEEPROM(UsbContext* ctx, unsigned char* buffer, int size, int adress);
int usbFx3ReadEEPROMFirmwareID(UsbContext* ctx, unsigned char* buffer, int size, int adress);
int usbFx3WriteEEPROM(UsbContext* ctx, unsigned char* buffer, int size, int adress);
int usbFx3Reset(UsbContext* ctx);
......
......@@ -2197,22 +2197,34 @@ void OsciloskopOsciloskop::m_menuItemClipboardAllOnMenuSelection(wxCommandEvent&
void OsciloskopOsciloskop::m_menuItemReadEEPROMOnMenuSelection(wxCommandEvent& event)
{
// pause
wxCommandEvent evt;
m_buttonPauseOnButtonClick(evt);
// firmware id
String ID;
SEeprom eeprom;
int size = 0;
int offset = 0;
memset(eeprom.data.bytes, 0xdd, sizeof(SEeprom));
memset(eeprom.data.bytes, 0x00, sizeof(SEeprom));
pOsciloscope->thread.readFirmwareIDFromEEPROM(pOsciloscope->settings.getHardware());
pOsciloscope->thread.getEEPROM(&eeprom, &size, &offset);
ID = (char*)&eeprom.data.bytes[0];
pOsciloscope->thread.readUsbFromEEPROM(pOsciloscope->settings.getHardware());
// data
memset(eeprom.data.bytes, 0x00, sizeof(SEeprom));
pOsciloscope->thread.readUsbFromEEPROM(pOsciloscope->settings.getHardware(), (16*EEPROM_BYTE_COUNT) );
pOsciloscope->thread.getEEPROM(&eeprom,&size,&offset);
// debug
wxCommandEvent et;
m_menuItemDebugOnMenuSelection(et);
if(pDebug && pDebug->IsShown())
{
pDebug->Clear();
FORMAT_BUFFER();
FORMAT("%s \n", (char*)ID.asChar() );
pDebug->AppendText(wxString::FromAscii(formatBuffer));
int count = min(16,size / EEPROM_BYTE_COUNT);
for(int i=0;i<count;i++)
{
......@@ -3251,27 +3263,43 @@ void OsciloskopOsciloskop::m_menuItemAutoCallibrateOnMenuSelection(wxCommandEven
}
void OsciloskopOsciloskop::m_menuItemReadCallibrateOnMenuSelection(wxCommandEvent& event)
{
// pause
wxCommandEvent evt;
m_buttonPauseOnButtonClick(evt);
// read
SEeprom eeprom;
int size = 0;
int offset = 0;
memset(eeprom.data.bytes, 0xdd, sizeof(SEeprom));
pOsciloscope->thread.readCallibrateSettingsFromEEPROM(pOsciloscope->settings.getHardware());
pOsciloscope->thread.getEEPROM(&eeprom, &size, &offset);
// save
OscHardware* save = pOsciloscope->settings.getHardware();
cJSON* json = save->json;
save->load();
SDL_memcpy(save, &eeprom, size);
save->json - json;
save->save();
// debug
wxCommandEvent et;
m_menuItemDebugOnMenuSelection(et);
if (pDebug && pDebug->IsShown())
{
pDebug->Clear();
FORMAT_BUFFER();
for (int i = 0; i < EEPROM_BYTE_COUNT; i++)
int count = min(16, size / EEPROM_BYTE_COUNT);
for (int i = 0; i < count; i++)
{
byte byteToPrint = eeprom.data.bytes[i];
FORMAT("%02x ", byteToPrint);
pDebug->AppendText(wxString::FromAscii(formatBuffer));
for (int j = 0; j < EEPROM_BYTE_COUNT; j++)
{
byte byteToPrint = eeprom.data.bytes[i*EEPROM_BYTE_COUNT + j];
FORMAT("%02x ", byteToPrint);
pDebug->AppendText(wxString::FromAscii(formatBuffer));
}
pDebug->AppendText(wxString::FromAscii("\n"));
}
}
}
......
......@@ -94,32 +94,36 @@ Osciloskop::Osciloskop( wxWindow* parent, wxWindowID id, const wxString& title,
m_menu5 = new wxMenu();
wxMenuItem* m_menuItemReadEEPROM;
m_menuItemReadEEPROM = new wxMenuItem( m_menu5, wxID_ANY, wxString( _("Read EEPROM") ) , wxEmptyString, wxITEM_NORMAL );
m_menuItemReadEEPROM = new wxMenuItem( m_menu5, wxID_ANY, wxString( _("Read FX3") ) , wxEmptyString, wxITEM_NORMAL );
m_menu5->Append( m_menuItemReadEEPROM );
wxMenuItem* m_menuItemWriteEEPROM;
m_menuItemWriteEEPROM = new wxMenuItem( m_menu5, wxID_ANY, wxString( _("Write EEPROM") ) , wxEmptyString, wxITEM_NORMAL );
m_menuItemWriteEEPROM = new wxMenuItem( m_menu5, wxID_ANY, wxString( _("Write FX3") ) , wxEmptyString, wxITEM_NORMAL );
m_menu5->Append( m_menuItemWriteEEPROM );
wxMenuItem* m_menuItemResetEEPROM;
m_menuItemResetEEPROM = new wxMenuItem( m_menu5, wxID_ANY, wxString( _("Erase EEPROM") ) , wxEmptyString, wxITEM_NORMAL );
m_menu5->Append( m_menuItemResetEEPROM );
m_menu5->AppendSeparator();
wxMenuItem* m_menuItem12;
m_menuItem12 = new wxMenuItem( m_menu5, wxID_ANY, wxString( _("Auto Callibrate") ) , wxEmptyString, wxITEM_NORMAL );
m_menuItem12 = new wxMenuItem( m_menu5, wxID_ANY, wxString( _("Auto Callibrate ( save to EEPROM and hardware2.json )") ) , wxEmptyString, wxITEM_NORMAL );
m_menu5->Append( m_menuItem12 );
m_menu5->AppendSeparator();
wxMenuItem* m_menuItemWriteCallibrate;
m_menuItemWriteCallibrate = new wxMenuItem( m_menu5, wxID_ANY, wxString( _("Write Callibration") ) , wxEmptyString, wxITEM_NORMAL );
m_menuItemWriteCallibrate = new wxMenuItem( m_menu5, wxID_ANY, wxString( _("Write Callibration ( load from hardware2.json )") ) , wxEmptyString, wxITEM_NORMAL );
m_menu5->Append( m_menuItemWriteCallibrate );
wxMenuItem* m_menuItemReadCallibrate;
m_menuItemReadCallibrate = new wxMenuItem( m_menu5, wxID_ANY, wxString( _("Read Callibration") ) , wxEmptyString, wxITEM_NORMAL );
m_menuItemReadCallibrate = new wxMenuItem( m_menu5, wxID_ANY, wxString( _("Read Callibration ( save to hardware2.json )") ) , wxEmptyString, wxITEM_NORMAL );
m_menu5->Append( m_menuItemReadCallibrate );
m_menubar1->Append( m_menu5, _("Hardware") );
m_menu5->AppendSeparator();
wxMenuItem* m_menuItemResetEEPROM;
m_menuItemResetEEPROM = new wxMenuItem( m_menu5, wxID_ANY, wxString( _("Erase") ) , wxEmptyString, wxITEM_NORMAL );
m_menu5->Append( m_menuItemResetEEPROM );
m_menubar1->Append( m_menu5, _("EEPROM") );
m_menu8 = new wxMenu();
wxMenuItem* m_menuItem15;
......@@ -1639,10 +1643,10 @@ Osciloskop::Osciloskop( wxWindow* parent, wxWindowID id, const wxString& title,
m_menu4->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( Osciloskop::m_menuItem11OnMenuSelection ), this, m_menuItem11->GetId());
m_menu5->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( Osciloskop::m_menuItemReadEEPROMOnMenuSelection ), this, m_menuItemReadEEPROM->GetId());
m_menu5->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( Osciloskop::m_menuItemWriteEEPROMOnMenuSelection ), this, m_menuItemWriteEEPROM->GetId());
m_menu5->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( Osciloskop::m_menuItemResetEEPROMOnMenuSelection ), this, m_menuItemResetEEPROM->GetId());
m_menu5->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( Osciloskop::m_menuItem12OnMenuSelection ), this, m_menuItem12->GetId());
m_menu5->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( Osciloskop::m_menuItemWriteCallibrateOnMenuSelection ), this, m_menuItemWriteCallibrate->GetId());
m_menu5->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( Osciloskop::m_menuItemReadCallibrateOnMenuSelection ), this, m_menuItemReadCallibrate->GetId());
m_menu5->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( Osciloskop::m_menuItemResetEEPROMOnMenuSelection ), this, m_menuItemResetEEPROM->GetId());
m_menu8->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( Osciloskop::m_menuItem15OnMenuSelection ), this, m_menuItem15->GetId());
m_menu9->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( Osciloskop::m_menuItemSlot1OnMenuSelection ), this, m_menuItemSlot1->GetId());
m_menu9->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( Osciloskop::m_menuItemSlot2OnMenuSelection ), this, m_menuItemSlot2->GetId());
......
......@@ -298,10 +298,10 @@ class Osciloskop : public wxFrame
virtual void m_menuItem11OnMenuSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void m_menuItemReadEEPROMOnMenuSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void m_menuItemWriteEEPROMOnMenuSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void m_menuItemResetEEPROMOnMenuSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void m_menuItem12OnMenuSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void m_menuItemWriteCallibrateOnMenuSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void m_menuItemReadCallibrateOnMenuSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void m_menuItemResetEEPROMOnMenuSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void m_menuItem15OnMenuSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void m_menuItemSlot1OnMenuSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void m_menuItemSlot2OnMenuSelection( wxCommandEvent& event ) { event.Skip(); }
......
......@@ -321,7 +321,7 @@
</object>
</object>
<object class="wxMenu" expanded="0">
<property name="label">Hardware</property>
<property name="label">EEPROM</property>
<property name="name">m_menu5</property>
<property name="permission">protected</property>
<object class="wxMenuItem" expanded="0">
......@@ -331,7 +331,7 @@
<property name="help"></property>
<property name="id">wxID_ANY</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">Read EEPROM</property>
<property name="label">Read FX3</property>
<property name="name">m_menuItemReadEEPROM</property>
<property name="permission">none</property>
<property name="shortcut"></property>
......@@ -345,13 +345,17 @@
<property name="help"></property>
<property name="id">wxID_ANY</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">Write EEPROM</property>
<property name="label">Write FX3</property>
<property name="name">m_menuItemWriteEEPROM</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
<event name="OnMenuSelection">m_menuItemWriteEEPROMOnMenuSelection</event>
</object>
<object class="separator" expanded="0">
<property name="name">m_separator4</property>
<property name="permission">none</property>
</object>
<object class="wxMenuItem" expanded="0">
<property name="bitmap"></property>
<property name="checked">0</property>
......@@ -359,15 +363,15 @@
<property name="help"></property>
<property name="id">wxID_ANY</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">Erase EEPROM</property>
<property name="name">m_menuItemResetEEPROM</property>
<property name="label">Auto Callibrate ( save to EEPROM and hardware2.json )</property>
<property name="name">m_menuItem12</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
<event name="OnMenuSelection">m_menuItemResetEEPROMOnMenuSelection</event>
<event name="OnMenuSelection">m_menuItem12OnMenuSelection</event>
</object>
<object class="separator" expanded="0">
<property name="name">m_separator4</property>
<property name="name">m_separator42</property>
<property name="permission">none</property>
</object>
<object class="wxMenuItem" expanded="0">
......@@ -377,12 +381,12 @@
<property name="help"></property>
<property name="id">wxID_ANY</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">Auto Callibrate</property>
<property name="name">m_menuItem12</property>
<property name="label">Write Callibration ( load from hardware2.json )</property>
<property name="name">m_menuItemWriteCallibrate</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
<event name="OnMenuSelection">m_menuItem12OnMenuSelection</event>
<event name="OnMenuSelection">m_menuItemWriteCallibrateOnMenuSelection</event>
</object>
<object class="wxMenuItem" expanded="0">
<property name="bitmap"></property>
......@@ -391,12 +395,16 @@
<property name="help"></property>
<property name="id">wxID_ANY</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">Write Callibration</property>
<property name="name">m_menuItemWriteCallibrate</property>
<property name="label">Read Callibration ( save to hardware2.json )</property>
<property name="name">m_menuItemReadCallibrate</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
<event name="OnMenuSelection">m_menuItemWriteCallibrateOnMenuSelection</event>
<event name="OnMenuSelection">m_menuItemReadCallibrateOnMenuSelection</event>
</object>
<object class="separator" expanded="0">
<property name="name">m_separator41</property>
<property name="permission">none</property>
</object>
<object class="wxMenuItem" expanded="0">
<property name="bitmap"></property>
......@@ -405,12 +413,12 @@
<property name="help"></property>
<property name="id">wxID_ANY</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">Read Callibration</property>
<property name="name">m_menuItemReadCallibrate</property>
<property name="label">Erase</property>
<property name="name">m_menuItemResetEEPROM</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
<event name="OnMenuSelection">m_menuItemReadCallibrateOnMenuSelection</event>
<event name="OnMenuSelection">m_menuItemResetEEPROMOnMenuSelection</event>
</object>
</object>
<object class="wxMenu" expanded="0">
......@@ -267,6 +267,11 @@ void ThreadApi::update()
iret += sfHardwareEepromRead(getCtx(), &eepromData, eepromSize, eepromOffset);
SDL_AtomicUnlock(&lock);
break;
case afEEPROMReadFirmwareID:
SDL_AtomicLock(&lock);
iret += sfHardwareEepromReadFirmwareID(getCtx(), &eepromData, eepromSize, eepromOffset);
SDL_AtomicUnlock(&lock);
break;
case afEEPROMWrite:
SDL_AtomicLock(&lock);
iret += sfHardwareEepromWrite(getCtx(), &eepromData, eepromSize, eepromOffset);
......@@ -530,23 +535,23 @@ int ThreadApi::writeFpgaToArtix7(SHardware1* ctrl1, SHardware2* ctrl2, OscHardwa
{
SDL_AtomicLock(&lock);
// usb
usbData = hw->getUSB();
usbSize = sizeof(SUsb);
// usb
usbData = hw->getUSB();
usbSize = sizeof(SUsb);
// fx2
fx2Size = (uint)SDL_strlen(hw->usbFirmware.asChar());
fx2Data.size = fx2Size;
SDL_memcpy(fx2Data.data.bytes, hw->usbFirmware.asChar(), fx2Size);
fx2Data.data.bytes[fx2Size] = 0;
// fx2
fx2Size = (uint)SDL_strlen(hw->usbFirmware.asChar());
fx2Data.size = fx2Size;
SDL_memcpy(fx2Data.data.bytes, hw->usbFirmware.asChar(), fx2Size);
fx2Data.data.bytes[fx2Size] = 0;
// fpga
char* buffer = 0;
ilarge bufferSize = 0;
int fret = fileLoad(hw->fpgaFirmware.asChar(), &buffer, &bufferSize);
fpgaData.size = fpgaSize = bufferSize;
SDL_memcpy(fpgaData.data.bytes, buffer, fpgaSize);
pMemory->free(buffer);
// fpga
char* buffer = 0;
ilarge bufferSize = 0;
int fret = fileLoad(hw->fpgaFirmware.asChar(), &buffer, &bufferSize);
fpgaData.size = fpgaSize = bufferSize;
SDL_memcpy(fpgaData.data.bytes, buffer, fpgaSize);
pMemory->free(buffer);
SDL_AtomicUnlock(&lock);
......@@ -568,6 +573,25 @@ int ThreadApi::writeFpgaToArtix7(SHardware1* ctrl1, SHardware2* ctrl2, OscHardwa
function(afOpenUsb);
wait();
// callibration
if (SDL_AtomicGet(&open) == 1)
{
SDL_AtomicLock(&lock);
eepromSize = sizeof(OscHardware);
eepromOffset = 256000;
SDL_AtomicUnlock(&lock);
function(afEEPROMRead);
wait();
// use callibration from eeprom
if (result(afEEPROMRead) == 0)
{
cJSON* json = hw->json;
SDL_memcpy(hw, &eepromData, eepromSize);
hw->json = json;
}
}
// fpga
function(afUploadFpga);
wait();
......@@ -579,6 +603,7 @@ int ThreadApi::writeFpgaToArtix7(SHardware1* ctrl1, SHardware2* ctrl2, OscHardwa
hardwareControlFunction(ctrl1,ctrl2);
wait();
// ret
return result(afUploadFpga);
}
......@@ -660,7 +685,48 @@ int ThreadApi::writeUsbToEEPROM(OscHardware* hw)
return iret;
}
int ThreadApi::readUsbFromEEPROM(OscHardware* hw)
int ThreadApi::readFirmwareIDFromEEPROM(OscHardware* hw)
{
int iversion = SDL_AtomicGet(&version);
if (iversion == HARDWARE_VERSION_1)
{
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Error", "This function is supported only with hardware version 2 and above.", 0);
return SCOPEFUN_FAILURE;
}
openUSB(hw);
if (SDL_AtomicGet(&open) > 0)
{
SDL_AtomicLock(&lock);