void IDocument::save() { QFile file(documentPath.c_str()); if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { auto data = getBinaryData(); file.write(data); file.close(); modifiedTime = getLastModifiedTime(); } this->onModified(); }
int main(int argc, char **argv) { #define MAX_BITS (49) // 49-bit word. #define MAX_DATA (1*1024) // 1 KB data buffer of 49-bit data words - ~70 seconds @ 1 kHz. char data[MAX_DATA*MAX_BITS], word[MAX_BITS]; //int (*data_ptr)[MAX_DATA][MAX_BITS] = &data, (*bit_ptr)[MAX_BITS] = data; int i = 0, j = 0, flag = 0, bit_cnt = 0, data_cnt = 0, zones, cmd; int data0,data1,data2,data3,data4,data5,data6; char year3[2],year4[2],month[2],day[2],hour[2],minute[2]; FILE *out_file; struct sched_param param; struct timespec t, tmark; char msg[100] = "", oldMsg[100] = ""; struct fifo dataFifo; /* Declare ourself as a real time task */ param.sched_priority = MY_PRIORITY; if(sched_setscheduler(0, SCHED_FIFO, ¶m) == -1) { perror("sched_setscheduler failed"); exit(-1); } /* Lock memory */ if(mlockall(MCL_CURRENT|MCL_FUTURE) == -1) { perror("mlockall failed"); exit(-2); } /* Pre-fault our stack */ stack_prefault(); for(i = 0; i < MAX_DATA*MAX_BITS; i++) data[i] = '0'; for(i = 0; i < MAX_BITS; i++) word[i] = '0'; // Set up gpio pointer for direct register access setup_io(); // Set up FIFO fifo_init(&dataFifo, data, MAX_DATA*MAX_BITS); // Set pin direction INP_GPIO(PI_DATA_OUT); // must use INP_GPIO before we can use OUT_GPIO OUT_GPIO(PI_DATA_OUT); INP_GPIO(PI_DATA_IN); INP_GPIO(PI_CLOCK_IN); // Set PI_DATA_OUT pin low. GPIO_CLR = 1<<PI_DATA_OUT; clock_gettime(CLOCK_MONOTONIC, &t); tmark = t; while (1) { //printf("pi_data:%i,data[%i][%i]:%i\n",GET_GPIO(PI_DATA_IN),data_cnt,bit_cnt,data[data_cnt][bit_cnt]); t.tv_nsec += INTERVAL; tnorm(&t); clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &t, NULL); if (GET_GPIO(PI_CLOCK_IN) == PI_CLOCK_HI) flag = 1; else if ((GET_GPIO(PI_CLOCK_IN) == PI_CLOCK_LO) && (flag == 1)) { if (ts_diff(&t, &tmark) > 1100000) { // new word bit_cnt = 0; // start new word fifo_write(&dataFifo, word, MAX_BITS); // write current word to FIFO /*printf("%04i: wrote ", data_cnt); for(i=0; i<MAX_BITS; i++) printf("%c", word[i]); printf(" to dataFifo\n");*/ data_cnt++; } tmark = t; flag = 0; t.tv_nsec += INTERVAL; tnorm(&t); t.tv_nsec += INTERVAL; tnorm(&t); t.tv_nsec += INTERVAL; tnorm(&t); t.tv_nsec += INTERVAL; tnorm(&t); t.tv_nsec += INTERVAL; tnorm(&t); /*t.tv_nsec += INTERVAL; tnorm(&t); t.tv_nsec += INTERVAL; tnorm(&t); t.tv_nsec += INTERVAL; tnorm(&t); t.tv_nsec += INTERVAL; tnorm(&t); t.tv_nsec += INTERVAL; tnorm(&t);*/ clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &t, NULL); // wait 50 uS for valid data word[bit_cnt++] = (GET_GPIO(PI_DATA_IN) == PI_DATA_HI) ? '0' : '1'; } if (data_cnt == MAX_DATA) break; } // decode and write to file if ( (out_file = fopen ("data", "w")) == NULL ) printf ("*** data could not be opened. \n" ); else for ( i = 0; i < MAX_DATA; i++ ) { strcpy(msg, ""); fifo_read(&dataFifo, word, MAX_BITS); /*printf("%04i: read ", i); for(j=0; j<MAX_BITS; j++) printf("%c", word[j]); printf(" from dataFifo\n");*/ cmd = getBinaryData(word,0,8); if (cmd == 0x05) { strcpy(msg, "LED Status: "); if (getBinaryData(word,12,1)) strcat(msg, "Error "); if (getBinaryData(word,13,1)) strcat(msg, "Bypass "); if (getBinaryData(word,14,1)) strcat(msg, "Memory "); if (getBinaryData(word,15,1)) strcat(msg, "Armed "); if (getBinaryData(word,16,1)) strcat(msg, "Ready "); } else if (cmd == 0xa5) { sprintf(year3, "%d", getBinaryData(word,9,4)); sprintf(year4, "%d", getBinaryData(word,13,4)); sprintf(month, "%d", getBinaryData(word,19,4)); sprintf(day, "%d", getBinaryData(word,23,5)); sprintf(hour, "%d", getBinaryData(word,28,5)); sprintf(minute, "%d", getBinaryData(word,33,6)); strcpy(msg, "Date: 20"); strcat(msg, year3); strcat(msg, year4); strcat(msg, "-"); strcat(msg, month); strcat(msg, "-"); strcat(msg, day); strcat(msg, " "); strcat(msg, hour); strcat(msg, ":"); strcat(msg, minute); } else if (cmd == 0x27) { strcpy(msg, "Zone1: "); zones = getBinaryData(word,41,8); if (zones & 1) strcat(msg, "1 "); if (zones & 2) strcat(msg, "2 "); if (zones & 4) strcat(msg, "3 "); if (zones & 8) strcat(msg, "4 "); if (zones & 16) strcat(msg, "5 "); if (zones & 32) strcat(msg, "6 "); if (zones & 64) strcat(msg, "7 "); if (zones & 128) strcat(msg, "8 "); } else if (cmd == 0x2d) { strcpy(msg, "Zone2: "); zones = getBinaryData(word,41,8); if (zones & 1) strcat(msg, "9 "); if (zones & 2) strcat(msg, "10 "); if (zones & 4) strcat(msg, "11 "); if (zones & 8) strcat(msg, "12 "); if (zones & 16) strcat(msg, "13 "); if (zones & 32) strcat(msg, "14 "); if (zones & 64) strcat(msg, "15 "); if (zones & 128) strcat(msg, "16 "); } else if (cmd == 0x34) { strcpy(msg, "Zone3: "); zones = getBinaryData(word,41,8); if (zones & 1) strcat(msg, "9 "); if (zones & 2) strcat(msg, "10 "); if (zones & 4) strcat(msg, "11 "); if (zones & 8) strcat(msg, "12 "); if (zones & 16) strcat(msg, "13 "); if (zones & 32) strcat(msg, "14 "); if (zones & 64) strcat(msg, "15 "); if (zones & 128) strcat(msg, "16 "); } else if (cmd == 0x3e) { strcpy(msg, "Zone4: "); zones = getBinaryData(word,41,8); if (zones & 1) strcat(msg, "9 "); if (zones & 2) strcat(msg, "10 "); if (zones & 4) strcat(msg, "11 "); if (zones & 8) strcat(msg, "12 "); if (zones & 16) strcat(msg, "13 "); if (zones & 32) strcat(msg, "14 "); if (zones & 64) strcat(msg, "15 "); if (zones & 128) strcat(msg, "16 "); } else strcpy(msg, "Unknown command."); data0 = getBinaryData(word,0,8); data1 = getBinaryData(word,8,8); data2 = getBinaryData(word,16,8); data3 = getBinaryData(word,24,8); data4 = getBinaryData(word,32,8); data5 = getBinaryData(word,40,8); data6 = getBinaryData(word,48,2); if (strcmp(msg, oldMsg) != 0) { fprintf (out_file, "data[%i],cmd:0x%02x,%s\n", i, cmd, msg); fprintf (out_file, "***data-all: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",data0,data1,data2,data3,data4,data5,data6); strcpy(oldMsg, msg); } } fclose (out_file); /* Unlock memory */ if(munlockall() == -1) { perror("munlockall failed"); exit(-2); } return 0; } // main