#include #include #include "serial_port.h" #define SET_BIT(variable, bitNumber) ((variable)|=(1<<(bitNumber))) #define CLEAR_BIT(variable, bitNumber) ((variable)&=(~(1<<(bitNumber)))) #define READ_BIT(variable, bitNumber) (((variable)>>(bitNumber)) & 1) static int panelHandle; int status; char fileName[300]; int analyze() { int i, j, tmp; int shiftLow, shiftHigh; int pos[8]; long int time = 0; /*[ms]*/ char c[300]; int hex; char first[10], second[10], third[10], fourth[10]; FILE *file_in; FILE *file_out[8]; unsigned int channel[8] = {0, 0, 0, 0, 0, 0, 0, 0}; GetCtrlVal (panelHandle, PANEL_CHAN0_3, &shiftLow ); GetCtrlVal (panelHandle, PANEL_CHAN4_8, &shiftHigh ); for ( i = 0; i < 4; i++ ) { pos[i] = 31 + shiftLow; } for ( i = 4; i < 8; i++ ) { pos[i] = 31 + shiftHigh; } file_in = fopen(fileName,"ra"); for ( i = 0; i < 8; i++ ) { sprintf(c, "output%d.bin", i); file_out[i] = fopen(c, "wb"); } for (i=0; i<17; i++) /*read leading text...*/ { fscanf(file_in, "%s", c); } i = 0; fscanf(file_in, "%s %s %s %s", first, second, third, fourth); // while(first[0]!='T') /* 'T'ime printed... (at the end of the file) */ while ( time < 2000 ) { i++; time += 4; if( fabs((time % 25) - 12.5) <= 2 ) { sscanf(second, "%x", &hex); if (time < 1000 ) printf("%x ", hex); for ( j = 0; j < 8; j++ ) { if ( pos[j] == -1 ) { pos[j] = 31; fwrite(&channel[j], 4, 1, file_out[j]); memset(&channel[j], 0, 4); } } for ( j = 0; j < 8; j++ ) // 8 { if (pos[j] <= 31) { if ( READ_BIT(hex, j) ) { SET_BIT( channel[j], pos[j]); } else { CLEAR_BIT(channel[j], pos[j]); } } pos[j]--; } } fscanf(file_in, "%s %s %s %s", first, second, third, fourth); } fclose(file_in); for ( i = 0; i < 8; i++ ) { if (pos[i] != 0) { fwrite(&channel[i], 4, 1, file_out[i]); } fclose(file_out[i]); } return 0; } int main() { if ((panelHandle = LoadPanel (0, "serial_port.uir", PANEL)) < 0) return -1; DisplayPanel (panelHandle); RunUserInterface (); DiscardPanel (panelHandle); } int CVICALLBACK inputFile (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_LEFT_CLICK: status=FileSelectPopup("", fileName, "*.bin", "Pick file", VAL_SELECT_BUTTON,0,0,1,1, fileName); if (status!=VAL_EXISTING_FILE_SELECTED) MessagePopup ("Choose file!", "Choose existing file!"); else analyze(); break; } return 0; } void CVICALLBACK MenuQuit (int menuBar, int menuItem, void *callbackData, int panel) { QuitUserInterface (0); }