int main(int argc, const char *argv[]) { fake * fk = newfake(); // 解析参数 int parseret = parsearg(fk, argc, argv); if (parseret != 0) { return parseret; } if (g_iscompiled) { fksetargv(fk, argc - 1, argv + 1); } else { fksetargv(fk, argc - 2, argv + 2); } fkopenalllib(fk); fkseterrorfunc(fk, error_log); // for test fkreg(fk, "test_cfunc1", test_cfunc1); fkreg(fk, "new_test_class1", new_test_class1); test_class1 c1; fkreg(fk, "test_memfunc1", &test_class1::test_memfunc1); // 编译后文件 if (g_iscompiled) { // 打开自己 char * selftmpbuf = 0; int selfsize = 0; if (!readfile(g_selfname, 0, selftmpbuf, selfsize)) { return -1; } int startpos = 0; int size = 0; memcpy(&startpos, g_replacebuff, sizeof(startpos)); memcpy(&size, g_replacebuff + 4, sizeof(size)); if (fkloadfunc(fk, selftmpbuf + startpos, size) == -1) { printf("load func fail\n"); return -1; } free(selftmpbuf); } // 解析文件 else if (!g_isload) { fkparse(fk, argv[1]); if (fkerror(fk)) { return -1; } } // 读文件 else { // 读文件 char * tmpbuf = 0; int size = 0; if (!readfile(argv[1], 0, tmpbuf, size)) { return -1; } if (fkloadfunc(fk, tmpbuf, size) == -1) { printf("load func fail\n"); return -1; } free(tmpbuf); printf("load from %s ok, size %d\n", argv[1], size); } // 存文件 if (g_issave) { int tmpsize = 1024 * 1024; char * tmpbuf = (char *)malloc(tmpsize); int size = fksavefunc(fk, tmpbuf, tmpsize); if (size == -1) { printf("save func fail\n"); return -1; } const char * filename = "fake.bin"; if (!writefile(filename, tmpbuf, size)) { return -1; } free(tmpbuf); printf("save to %s ok, size %d\n", filename, size); return 0; } // 编译到一起 if (g_iscompile) { int tmpsize = 1024 * 1024; char * tmpbuf = (char *)malloc(tmpsize); int size = fksavefunc(fk, tmpbuf, tmpsize); if (size == -1) { printf("compile func fail\n"); return -1; } // 打开自己 char * selftmpbuf = 0; int selfsize = 0; if (!readfile(g_selfname, size, selftmpbuf, selfsize)) { return -1; } // 替换内存中的字符串 bool isfind = false; for (int i = 0; i < selfsize; i++) { if (memcmp(selftmpbuf + i, g_replacebuff, strlen(g_replacebuff)) == 0) { memcpy(selftmpbuf + i, &selfsize, sizeof(selfsize)); memcpy(selftmpbuf + i + 4, &size, sizeof(size)); isfind = true; break; } } if (!isfind) { printf("replace %s pos fail\n", argv[0]); return -1; } // 复制后面的 memcpy(selftmpbuf + selfsize, tmpbuf, size); free(tmpbuf); // 输出 const char * filename = "out.exe"; if (!writefile(filename, selftmpbuf, selfsize + size)) { return -1; } free(selftmpbuf); printf("compile to %s ok, size %d\n", filename, selfsize + size); return 0; } #ifndef WIN32 if (g_isopengoogleprofile) { ProfilerStart("fake.prof"); } #endif uint32_t begintime = time(0); int fkret = 0; // run for (int i = 0; i < g_testnum; i++) { if (!g_isopenjit) { if (g_isstep) { fkret = startdebug(fk); } else { fkret = fkrun<int>(fk, "main"); } } else { fkret = fkrunjit<int>(fk, "main"); } } uint32_t endtime = time(0); #ifndef WIN32 if (g_isopengoogleprofile) { ProfilerStop(); } #endif if (fkerror(fk)) { return -1; } if (g_isopenprofile) { printf("\n%s", fkdumpprofile(fk)); } if (g_isprintoutput) { printf("main return : %d, use time %d\n", fkret, endtime - begintime); } delfake(fk); return 0; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); pc_node = 0; plc_node=0; fins_sid = 0; retry_count=0; fins_handshake = { qToBigEndian<quint32>(FINSTCP_FINS_SELF),\ qToBigEndian<quint32>(FINSTCP_HANDSHAKE_LEN),\ qToBigEndian<quint32>(FINSTCP_CMD_HANDSHAKE),\ qToBigEndian<quint32>(FINSTCP_ERR_CODE_NULL),\ qToBigEndian<quint32>(FINSTCP_ASK_NODE_ADDR)\ }; tcp_send = new QTcpSocket(this); tcp_recv = new QTcpSocket(this); // QSettings plc_settings(QSettings::IniFormat, QSettings::UserScope, // "SHNU", "PLC_Trans"); QSettings plc_settings("./settings.ini",QSettings::IniFormat); ui->ip_lineEdit->setText(plc_settings.value("data_source_ip").toString()); ui->ip_port->setText(plc_settings.value("data_source_port").toString()); ui->plc_distance_address->setText(plc_settings.value("data_distance_pos").toString()); ui->plc_avg_address->setText(plc_settings.value("data_avg_pos").toString()); ui->plc_ip_address->setText(plc_settings.value("plc_ip").toString()); ui->plc_ip_port->setText(plc_settings.value("plc_port").toString()); connect(ui->ip_lineEdit,SIGNAL(textChanged(QString)), this, SLOT(savesettings())); connect(ui->ip_port,SIGNAL(textChanged(QString)), this, SLOT(savesettings())); connect(ui->plc_distance_address,SIGNAL(textChanged(QString)), this, SLOT(savesettings())); connect(ui->plc_avg_address,SIGNAL(textChanged(QString)), this, SLOT(savesettings())); connect(ui->plc_ip_address,SIGNAL(textChanged(QString)), this, SLOT(savesettings())); connect(ui->plc_ip_port,SIGNAL(textChanged(QString)), this, SLOT(savesettings())); connect(tcp_recv, SIGNAL(readyRead()), this, SLOT(data_coming()));//数据接收 connect(tcp_recv , SIGNAL(connected()) , this , SLOT(cli_connected())); connect(tcp_recv , SIGNAL(disconnected()) , this , SLOT(cli_disconnected())); connect(this , SIGNAL(readFromPLC_signal(plc_send_node)),this,SLOT(readFromPLC(plc_send_node))); connect(this , SIGNAL(writeToPLC_signal(plc_send_node)),this,SLOT(writeToPLC(plc_send_node))); ui->start_server_button->setEnabled(false); // ui->ip_lineEdit->setText("127.0.0.1"); // ui->ip_port->setText("4701"); connect(ui->start_client_button,SIGNAL(clicked()),this,SLOT(cli_connectToHost())); //for debug ui->debug_length->setText("2"); ui->debug_length->setEnabled(false); connect(ui->debug_start,SIGNAL(clicked()),this,SLOT(startdebug())); //for plc setting // ui->plc_ip_address->setText("192.168.11.5"); // ui->plc_ip_port->setText("9600"); // ui->plc_distance_address->setText("0"); // ui->plc_avg_address->setText("10"); //cli_connectToHost(); }