/****************************************************************************** * * Title : dataFileCreator.c * Version 0.0 * * Description: Binary file creator utility. * * * Author: Lukas Tomasek, tomasekl@fzu.cz * ******************************************************************************/ #include #include #include #include #include "dataFileCreator.h" #define DATA_SUBDIR "\\Data\\" #define DATA_FILE_CREATOR_SUBDIR "\\DataFileCreator\\" #define BIN_VIEWER "\\Witched\\Witched.exe " #define PATHNAME_LENGTH 300 typedef unsigned int UINT32; typedef unsigned char UINT8; typedef float FLOAT32; static int panelHandle; static UINT32 *tableBuffer=NULL; static UINT8 *tableBufferByte; static int wordSize_global=4; static currentBufferSize=0; static UINT32 totalBytes_global, totalWords_global; static unsigned int slideMax=1; static char mainDir[PATHNAME_LENGTH]; static char binViewerFileName[PATHNAME_LENGTH]; static char dataDir[PATHNAME_LENGTH]; int status; static void refreshTable(UINT32 startAddress, int panel); int main (int argc, char *argv[]) { if (InitCVIRTE (0, argv, 0) == 0) return -1; /* out of memory */ if ((panelHandle = LoadPanel (0, "dataFileCreator.uir", PANEL)) < 0) return -1; status=GetProjectDir(mainDir); /* remove Rcc subdirectory */ mainDir[strlen(mainDir)-strlen(DATA_FILE_CREATOR_SUBDIR)+1]=0; if(status!=0){ printf("Invalid project directory(%s)!!.", mainDir); printf("\nPress any key to quit."); getchar(); return(-1); } /* get file name */ strcpy(binViewerFileName, mainDir); strcat(binViewerFileName, BIN_VIEWER); strcpy(dataDir, mainDir); strcat(dataDir, DATA_SUBDIR); DisplayPanel (panelHandle); RunUserInterface (); DiscardPanel (panelHandle); if(tableBuffer!=NULL){ free(tableBuffer); } return 0; } int CVICALLBACK buttons (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { UINT32 dataSize; UINT32 value[2]; FLOAT32 floatValue; FLOAT32 floatIncrement; UINT8 *valueByte=(UINT8*)value; int dataType; UINT32 currentAddress; UINT32 words; int index, i, j; int transBit; int columnIndex, rowIndex; int tableAddress; unsigned int var; int status; char fileName[PATHNAME_LENGTH]; char viewFile[PATHNAME_LENGTH]; long fileSize; int increment; int intFloat; UINT8 tempByte; FILE *fileHandle; if(event==EVENT_COMMIT){ switch(control){ case PANEL_ADD_TO_TABLE: GetCtrlVal(panel, PANEL_WORD_SIZE, &wordSize_global); GetCtrlVal(panel, PANEL_DATA_TYPE, &dataType); GetCtrlVal(panel, PANEL_INIT_VALUE1, &value[1]); GetCtrlVal(panel, PANEL_WORDS, &words); GetCtrlVal(panel, PANEL_CURRENT_ADDR, ¤tAddress); GetCtrlVal(panel, PANEL_TABLE_ADDR, &tableAddress); GetCtrlVal(panel, PANEL_INT_FLOAT, &intFloat); if(intFloat) { GetCtrlVal(panel, PANEL_INIT_VALUE0, &value[0]); GetCtrlVal(panel, PANEL_INCREMENT, &increment); } else { GetCtrlVal(panel, PANEL_INIT_VALUE0, (FLOAT32 *)&value[0]); GetCtrlVal(panel, PANEL_INCREMENT, (FLOAT32 *)&increment); } totalBytes_global=currentAddress+4*((words*wordSize_global+3)/4); totalWords_global=totalBytes_global/wordSize_global; if(totalBytes_global==0) break; if(totalBytes_global>currentBufferSize){ if(tableBuffer==NULL){ tableBuffer=malloc(totalBytes_global); } tableBuffer=realloc(tableBuffer, totalBytes_global); currentBufferSize=totalBytes_global; } if(tableBuffer==NULL){ printf("ERROR - cannot allocate memory!!"); break; } SetCtrlAttribute (panel, PANEL_TABLE_SLIDE, ATTR_MAX_VALUE, totalBytes_global); SetCtrlVal(panel, PANEL_TABLE_SLIDE, slideMax); SetCtrlAttribute(panel, PANEL_TOTAL_WORDS, ATTR_MAX_VALUE, totalWords_global); SetCtrlAttribute(panel, PANEL_TABLE_ADDR, ATTR_MAX_VALUE, totalBytes_global-4); GetCtrlVal(panel, PANEL_TOTAL_WORDS, &var); if(var0){ valueByte[j]+=transBit; if((valueByte[j])>(0xFF-increment)){ valueByte[j]=0; transBit=1; }else{ if(j==0){ valueByte[0]+=increment; } transBit=0; } } tableBufferByte[wordSize_global*i+j]=valueByte[j]; } } } else //float { GetCtrlVal(panel, PANEL_INIT_VALUE0, &floatValue); GetCtrlVal(panel, PANEL_INCREMENT, &floatIncrement); valueByte = (UINT8 *) &floatValue; for(i=0; i0) valueByte[j]+=transBit; if(tempByte>=0x80){ transBit=1; }else{ transBit=0; } } } break; case 3: /* random */ srand((unsigned int)time(NULL)); index=currentAddress/4; tableBufferByte=(UINT8*)&tableBuffer[index]; if((wordSize_global==6)&&((index%6)!=0)){ tableBufferByte+=2; } for(i=0; itotalBytes_global){ totalBytes_global=var; } totalWords_global=totalBytes_global/wordSize_global; if(totalBytes_global==0) break; if(totalBytes_global>currentBufferSize){ if(tableBuffer==NULL){ tableBuffer=malloc(totalBytes_global); } tableBuffer=realloc(tableBuffer, totalBytes_global); currentBufferSize=totalBytes_global; } if(tableBuffer==NULL){ printf("ERROR - cannot allocate memory!!"); break; } SetCtrlAttribute (panel, PANEL_TABLE_SLIDE, ATTR_MAX_VALUE, totalBytes_global); SetCtrlVal(panel, PANEL_TABLE_SLIDE, slideMax); SetCtrlAttribute(panel, PANEL_TOTAL_WORDS, ATTR_MAX_VALUE, totalWords_global); SetCtrlAttribute(panel, PANEL_TABLE_ADDR, ATTR_MAX_VALUE, totalBytes_global-4); GetCtrlVal(panel, PANEL_TOTAL_WORDS, &var); if(var4)); break; case PANEL_DATA_TYPE: GetCtrlVal(panel, control, &dataType); SetInputMode(panel, PANEL_INCREMENT, (dataType==1)); break; case PANEL_TABLE_ADDR: GetCtrlVal(panel, control, &newAddr); tableAddress=newAddr&0xFFFFFFF0; SetCtrlVal(panel, control, tableAddress); slideValue=(totalBytes_global-tableAddress); SetCtrlVal(panel, PANEL_TABLE_SLIDE, slideValue); /* no break */ case PANEL_TABLE_SLIDE: if(tableBuffer==NULL){ break; } if(control==PANEL_TABLE_SLIDE){ GetCtrlVal(panel, control, &slideValue); tableAddress=(totalBytes_global-slideValue)&0xFFFFFFF0; if(tableAddress>=(totalBytes_global)) { tableAddress=(tableAddress-0x10)&0xFFFFFFF0; } SetCtrlVal(panel, PANEL_TABLE_ADDR, tableAddress); } /* fill table */ refreshTable(tableAddress, panel); if(control==PANEL_TABLE_ADDR){ SetActiveCtrl (panel, PANEL_TABLE); SetActiveTableCell(panel, PANEL_TABLE, MakePoint((newAddr-tableAddress)/4+2,1)); } break; case PANEL_TOTAL_WORDS: GetCtrlVal(panel, PANEL_TOTAL_WORDS, &totalWords_global); totalBytes_global= totalWords_global*wordSize_global; var=totalWords_global*wordSize_global; if(var>256){ var-=256; }else{ var=0; } tableAddress=var&0xFFFFFFF0; SetCtrlVal(panel, PANEL_TABLE_ADDR, tableAddress); slideValue=(totalBytes_global-tableAddress); SetCtrlVal(panel, PANEL_TABLE_SLIDE, slideValue); if(tableBuffer==NULL){ break; } /* fill table */ refreshTable(tableAddress, panel); break; case PANEL_INT_FLOAT: GetCtrlVal(panel, control, &intFloat); SetCtrlAttribute(panel, PANEL_INIT_VALUE0, ATTR_DATA_TYPE, intFloat ? VAL_UNSIGNED_INTEGER : VAL_FLOAT ); SetCtrlAttribute(panel, PANEL_INCREMENT, ATTR_DATA_TYPE, intFloat ? VAL_INTEGER : VAL_FLOAT ); SetCtrlVal(panel, PANEL_WORD_SIZE, 4); //set word length to 4 bytes SetInputMode(panel, PANEL_WORD_SIZE, intFloat); SetInputMode(panel, PANEL_INIT_VALUE1, 0); // if integer then anyway WORD_SIZE==4 => INIT_VALUE1 = DIMMED; if(intFloat) { GetNumListItems (panel, PANEL_DATA_TYPE, &count); if (count == 2) { InsertListItem (panel, PANEL_DATA_TYPE, 2, "LEFT SHIFT", 2); InsertListItem (panel, PANEL_DATA_TYPE, 3, "RANDOM", 3); } } else { SetCtrlVal (panel, PANEL_DATA_TYPE, 0); // CONSTANT SetInputMode(panel, PANEL_INCREMENT, 0); GetNumListItems (panel, PANEL_DATA_TYPE, &count); if (count == 4) DeleteListItem (panel, PANEL_DATA_TYPE, 2, 2); } break; } } return 0; } void CVICALLBACK menu (int menuBar, int menuItem, void *callbackData, int panel) { QuitUserInterface (0); } static void refreshTable(UINT32 startAddress, int panel){ int rowIndex, columnIndex; /* fill table */ for(rowIndex=1; rowIndex<=16;++rowIndex){ /* fill address */ SetTableCellVal (panel, PANEL_TABLE, MakePoint(1, rowIndex), startAddress); for(columnIndex=2; columnIndex<=5; ++columnIndex, startAddress+=0x4){ if(startAddress