yosri ben salah Posted May 9, 2017 Report Share Posted May 9, 2017 hi all, can someone explain for me why my code display error when i instanciate module in main function thanks ystemc modules should include systemc.h header file #include "systemc.h" #include "stdio.h" #include "string.h" #include "stdio.h" #include"stdlib.h" #define _CRT_SECURE_NO_WARNINGS sc_out<bool> in; SC_MODULE(synchronous) { bool synchronization() { sc_out<bool> in; FILE *workspace = fopen("F:/yosri.txt", "r"); char buff[13]; fgets(buff, 12, workspace); int ret = 0; while (ret == 0) { cout << "Waiting for request...\n"; ret = strcmp(buff, "SWITCHCONTEXT"); printf("%d", ret); } //SWITCHCONTXT is a string written in a text file in = true; cout << "Establishing communication"; return(in); } }; SC_MODULE(imageProcess) { sc_in<bool> in; void MotionDetector(bool signal) { printf("\nCommuncation established"); char *mode1 = "r"; char *mode2 = "w"; int i, j, k; int C = 0; int rows1, cols1, rows2, cols2; bool fileFound = false; bool multiplcation = true; FILE *image1; FILE *image2; FILE *image3; int sum = 0; image3 = fopen("F:/image3.txt", mode2); do { char *mode1 = "r"; char *mode2 = "w"; image1 = fopen("F:/image1.txt", mode1); if (!image1) { printf("File Not Found!!\n"); fileFound = true; } else fileFound = false; } while (fileFound); do { image2 = fopen("F:/image2.txt", mode1); if (!image2) { cout << "File Not Found!!\n"; fileFound = true; } else fileFound = false; } while (fileFound); //allocate Matrcies rows1 = rows2 = 384; cols1 = cols2 = 512; int **mat1 = (int **)malloc(rows1 * sizeof(int*)); for (i = 0; i < rows1; i++) mat1 = (int *)malloc(cols1 * sizeof(int)); i = 0; int **mat2 = (int **)malloc(rows2 * sizeof(int*)); for (i = 0; i < rows2; i++) mat2 = (int *)malloc(cols2 * sizeof(int)); i = 0; while (!feof(image1)) { for (i = 0; i < rows1; i++) { for (j = 0; j < cols1; j++) fscanf(image1, "%d%", &mat1[j]); } } i = 0; j = 0; while (!feof(image2)) { for (i = 0; i < rows2; i++) { for (j = 0; j < cols2; j++) fscanf(image2, "%d%", &mat2[j]); } } i = 0; j = 0; printf("\n\n"); i = 0; k = 0; cout << "\n\n"; for (i = 0; i < rows1; i++) { for (j = 0; j < cols1; j++) { if (mat1[j] != mat2[j]) C++; } } i = j = 0; if (C > 20) { printf("MOTION...DETECTED\a \a"); for (i = 0; i < rows1; i++) { for (j = 0; j < cols1; j++) { fprintf(image3, "%d ", mat2[j]); } fprintf(image3, "\n"); } cout << "\n Image Saved...."; } fclose(image1); fclose(image2); fclose(image3); } }; // sc_main in top level function like in C++ main int sc_main(int argc, char* argv[]) { SC_CTOR(synchronous) { SC_METHOD(synchronization); } SC_CTOR(imageProcess) { SC_METHOD(MotionDetector); sensitive << in; } sc_start(); return(0); } Quote Link to comment Share on other sites More sharing options...
apfitch Posted May 11, 2017 Report Share Posted May 11, 2017 There's lots wrong with your code - did you look at the tutorial on www.doulos.com as someone suggested in the earlier thread? Any way, I've tried to add some comments in your code #include "systemc.h" #include "stdio.h" #include "string.h" #include "stdio.h" #include"stdlib.h" #define _CRT_SECURE_NO_WARNINGS sc_out<bool> in; // DON'T DECLARE A PORT OUTSIDE A MODULE SC_MODULE(synchronous) { bool synchronization() { sc_out<bool> in; // DON'T DECLARE A PORT INSIDE A FUNCTION FILE *workspace = fopen("F:/yosri.txt", "r"); char buff[13]; fgets(buff, 12, workspace); int ret = 0; while (ret == 0) { cout << "Waiting for request...\n"; ret = strcmp(buff, "SWITCHCONTEXT"); printf("%d", ret); } //SWITCHCONTXT is a string written in a text file in = true; cout << "Establishing communication"; return(in); // YOU CAN'T RETURN A PORT CLASS LIKE THIS } }; SC_MODULE(imageProcess) // WHY USE A MODULE HERE? I can't see what SystemC features you're using? { sc_in<bool> in; // WHAT'S THIS FOR? void MotionDetector(bool signal) { printf("\nCommuncation established"); char *mode1 = "r"; char *mode2 = "w"; int i, j, k; int C = 0; int rows1, cols1, rows2, cols2; bool fileFound = false; bool multiplcation = true; FILE *image1; FILE *image2; FILE *image3; int sum = 0; image3 = fopen("F:/image3.txt", mode2); do { char *mode1 = "r"; char *mode2 = "w"; image1 = fopen("F:/image1.txt", mode1); if (!image1) { printf("File Not Found!!\n"); fileFound = true; } else fileFound = false; } while (fileFound); do { image2 = fopen("F:/image2.txt", mode1); if (!image2) { cout << "File Not Found!!\n"; fileFound = true; } else fileFound = false; } while (fileFound); //allocate Matrcies rows1 = rows2 = 384; cols1 = cols2 = 512; int **mat1 = (int **)malloc(rows1 * sizeof(int*)); for (i = 0; i < rows1; i++) mat1 = (int *)malloc(cols1 * sizeof(int)); i = 0; int **mat2 = (int **)malloc(rows2 * sizeof(int*)); for (i = 0; i < rows2; i++) mat2 = (int *)malloc(cols2 * sizeof(int)); i = 0; while (!feof(image1)) { for (i = 0; i < rows1; i++) { for (j = 0; j < cols1; j++) fscanf(image1, "%d%", &mat1[j]); } } i = 0; j = 0; while (!feof(image2)) { for (i = 0; i < rows2; i++) { for (j = 0; j < cols2; j++) fscanf(image2, "%d%", &mat2[j]); } } i = 0; j = 0; printf("\n\n"); i = 0; k = 0; cout << "\n\n"; for (i = 0; i < rows1; i++) { for (j = 0; j < cols1; j++) { if (mat1[j] != mat2[j]) C++; } } i = j = 0; if (C > 20) { printf("MOTION...DETECTED\a \a"); for (i = 0; i < rows1; i++) { for (j = 0; j < cols1; j++) { fprintf(image3, "%d ", mat2[j]); } fprintf(image3, "\n"); } cout << "\n Image Saved...."; } fclose(image1); fclose(image2); fclose(image3); } }; // sc_main in top level function like in C++ main int sc_main(int argc, char* argv[]) { SC_CTOR(synchronous) // sc_main is not a class so you can't declare a constructor here. { SC_METHOD(synchronization); } SC_CTOR(imageProcess) // sc_main is not a class so you can't declare a constructor here. { SC_METHOD(MotionDetector); sensitive << in; } sc_start(); return(0); } Your code shows a lot of confusion between ports, modules, sc_main, and processes. I highly recommend going back to that tutorial and getting a very simple example running (perhaps an AND gate) and checking you understand that first, kind regards Alan Quote Link to comment Share on other sites More sharing options...
yosri ben salah Posted May 11, 2017 Author Report Share Posted May 11, 2017 Hi, i wanna thank you dr , i try to use port with the aim of automatng the second module (ImageProcess) the time the condition in first module is validated (string found in a text file). i dont succeeded on it, i dont know how to do it, i use intanciate module in SC_main following a suggestion of a member in the forum Quote Link to comment Share on other sites More sharing options...
yosri ben salah Posted May 11, 2017 Author Report Share Posted May 11, 2017 dr, this is my last attempt, the code is debugged but does not respect the condition( condition as i said iwant if the synchronous module find string in text file, it activates the second module) even i dont use port because i dont know how to use them, #include "systemC.h" #include "string.h" #include "stdio.h" #include"stdlib.h" #include <time.h> #include <fstream> #define _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_WARNINGS double elapsed; int in = false; SC_MODULE(synchronous) { SC_CTOR(synchronous) { SC_METHOD(synchronization); } void synchronization() { FILE *workspace = fopen("F:/yosri.txt", "r"); char buff[12]; fgets(buff, 12, workspace); int ret = 0; while (ret = 0) { printf("Waiting for request...\n"); ret = strcmp(buff, "SWITCHCONTEXT"); printf("%d", ret); } //SWITCHCONTXT is a string written in a text file in = true; printf("Establishing communication"); } }; clock_t start = clock(); SC_MODULE(imageProcess) { sc_in<bool>sig; SC_CTOR(imageProcess) { SC_METHOD(MotionDetector) sensitive(sig); } void MotionDetector() { if (in = true) { printf("\n...Communication established"); char *mode1 = "r"; char *mode2 = "w"; int i, j, k; int C = 0; int rows1, cols1, rows2, cols2; bool fileFound = false; bool multiplcation = true; FILE *image1; FILE *image2; FILE *image3; int sum = 0; image3 = fopen("F:/image3.txt", mode2); do { char *mode1 = "r"; char *mode2 = "w"; image1 = fopen("F:/image1.txt", mode1); if (!image1) { printf("File Not Found!!\n"); fileFound = true; } else fileFound = false; } while (fileFound); do { image2 = fopen("F:/image2.txt", mode1); if (!image2) { printf("File Not Found!!\n"); fileFound = true; } else fileFound = false; } while (fileFound); //allocate Matrcies rows1 = rows2 = 384; cols1 = cols2 = 512; int **mat1 = (int **)malloc(rows1 * sizeof(int*)); for (i = 0; i < rows1; i++) mat1 = (int *)malloc(cols1 * sizeof(int)); i = 0; int **mat2 = (int **)malloc(rows2 * sizeof(int*)); for (i = 0; i < rows2; i++) mat2 = (int *)malloc(cols2 * sizeof(int)); i = 0; while (!feof(image1)) { for (i = 0; i < rows1; i++) { for (j = 0; j < cols1; j++) fscanf(image1, "%d%", &mat1[j]); } } i = 0; j = 0; while (!feof(image2)) { for (i = 0; i < rows2; i++) { for (j = 0; j < cols2; j++) fscanf(image2, "%d%", &mat2[j]); } } ///////////////////////// i = 0; j = 0; printf("\n\n"); //print matrix 1 //for (i = 0; i<rows1; i++) //{ //for (j = 0; j<cols1; j++) //printf("%d\t", mat1[j]); //printf("\n"); //} //////////////////////////// i = 0; k = 0; printf("\n\n"); //for (i = 0; i < rows2; i++) //{ //for (j = 0; j < cols2; j++) //printf("%d\t", mat2[j]); //printf("\n"); //} ///////////////////////// for (i = 0; i < rows1; i++) { for (j = 0; j < cols1; j++) { if (mat1[j] != mat2[j]) C++; } } i = j = 0; if (C > 20) { printf("MOTION...DETECTED\a \a"); for (i = 0; i < rows1; i++) { for (j = 0; j < cols1; j++) { fprintf(image3, "%d ", mat2[j]); } fprintf(image3, "\n"); } printf("\n Image Saved...."); } fclose(image1); fclose(image2); fclose(image3); clock_t end = clock(); elapsed = ((double)end - start) / CLOCKS_PER_SEC; printf("time is %f", elapsed); std::ofstream mon_fichier("F:/toto.txt"); mon_fichier << "Une chaine\n"; mon_fichier << elapsed << '\n'; } } }; int sc_main(int argc, char* argv[]) { //synchronization(); synchronous yosri("e"); yosri.synchronization(); imageProcess master("EE2"); master.MotionDetector(); sc_start(); return(0); } Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted May 11, 2017 Report Share Posted May 11, 2017 Dear Yosri, There are so many issues in your code that it is very hard to discuss and fix it in this forum. Please start with learning some basics about SystemC and C++ first. The following tutorial (I mentioned this already earlier) is good as a starting point: https://www.doulos.com/knowhow/systemc/tutorial/ Many people like the following book to learn more: http://www.springer.com/de/book/9780387699578 For more general C++, you can find hundrefs of books and tutorials in the internet. Greetings Ralph Quote Link to comment Share on other sites More sharing options...
yosri ben salah Posted May 11, 2017 Author Report Share Posted May 11, 2017 dr ralph I do not have enough time yet for my project graduation i was stopped at this point posting a lot of topic in this forum, . if you can comment my code helping me to fix some issues and i will try to check some tutorials from doulos, the time i finish my project i will get a basic courses on systemC im really interrested by this language because it is necessaire for my future learning in embedded system field, thank you Quote Link to comment Share on other sites More sharing options...
yosri ben salah Posted May 25, 2017 Author Report Share Posted May 25, 2017 systemC detect motion.txt Quote Link to comment Share on other sites More sharing options...
AmeyaVS Posted May 26, 2017 Report Share Posted May 26, 2017 @yosri ben salah, Unable to open the attachment. Kindly provide the necessary context for the attachment. What exactly is it providing for this discussion? Regards, Ameya Vikram Singh Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.