diff --git a/graphviz/test.cpp b/graphviz/test.cpp new file mode 100644 index 00000000..a45bc82a --- /dev/null +++ b/graphviz/test.cpp @@ -0,0 +1,70 @@ +//clang++ -std=c++11 test.cpp && ./a.out && dot test.dot -Tpdf -otest.pdf && open test.pdf + +#include +#include +#include +#include +#include +#include + +using namespace std; + +typedef struct{ + vector inputs; + vector outputs; +}comp_t; + +int main(){ + map comps; + vector links; + ifstream halfile("test.hal", fstream::in); + ofstream dotfile("test.dot", fstream::out); + string s((std::istreambuf_iterator(halfile)), std::istreambuf_iterator()); + smatch m; + //m[] 1 2 3 4 5 + regex e("(\\w+).(\\w+) <= (\\w+).(\\w+) = (.+)"); + while(std::regex_search (s,m,e)){ + //if not connected to itself + if(m[1].str() != m[3].str() && m[2].str() != m[4].str()){ + comps[m[3].str()].outputs.push_back(m[4].str()); + comps[m[1].str()].inputs.push_back(m[2].str()); + string link; + link.append(m[3].str()); + link.append(":"); + link.append(m[4].str()); + link.append(" -> "); + link.append(m[1].str()); + link.append(":"); + link.append(m[2].str()); + link.append("[label=\""); + link.append(m[5].str()); + link.append("\"];"); + links.push_back(link); + } + s = m.suffix().str(); + } + + dotfile << "digraph G {" << endl; + dotfile << "graph [rankdir = LR];" << endl; + dotfile << "node[shape=record];" << endl; + + for(auto &comp:comps){ + dotfile << comp.first << "[label=\"{{"; + + for(auto &input:comp.second.inputs){ + dotfile << "<" << input << ">" << input << "|"; + } + dotfile << "}|" << comp.first << "|{"; + for(auto &output:comp.second.outputs){ + dotfile << "<" << output << ">" << output << "|"; + } + dotfile << "}}\"];" << endl; + } + + for(auto &link:links){ + dotfile << link << endl; + } + + dotfile << "}" << endl; + return 0; +} \ No newline at end of file diff --git a/graphviz/test.hal b/graphviz/test.hal new file mode 100644 index 00000000..427ab481 --- /dev/null +++ b/graphviz/test.hal @@ -0,0 +1,158 @@ +frt0.trg0 <= frt0.trg0 = 0.000000 +frt0.trg1 <= frt0.trg1 = 0.000000 +frt0.trg2 <= frt0.trg2 = 0.000000 +frt0.trg3 <= frt0.trg3 = 0.000000 +frt0.trg4 <= frt0.trg4 = 0.000000 +frt0.trg5 <= frt0.trg5 = 0.000000 +frt0.trg6 <= frt0.trg6 = 0.000000 +frt0.trg7 <= frt0.trg7 = 0.000000 +rt0.trg0 <= rt0.trg0 = 0.000000 +rt0.trg1 <= rt0.trg1 = 0.000000 +rt0.trg2 <= rt0.trg2 = 0.000000 +rt0.trg3 <= rt0.trg3 = 0.000000 +rt0.trg4 <= rt0.trg4 = 0.000000 +rt0.trg5 <= rt0.trg5 = 0.000000 +rt0.trg6 <= rt0.trg6 = 0.000000 +rt0.trg7 <= rt0.trg7 = 0.000000 +nrt0.trg0 <= nrt0.trg0 = 0.000000 +nrt0.trg1 <= nrt0.trg1 = 0.000000 +nrt0.trg2 <= nrt0.trg2 = 0.000000 +nrt0.trg3 <= nrt0.trg3 = 0.000000 +nrt0.trg4 <= nrt0.trg4 = 0.000000 +nrt0.trg5 <= nrt0.trg5 = 0.000000 +nrt0.trg6 <= nrt0.trg6 = 0.000000 +nrt0.trg7 <= nrt0.trg7 = 0.000000 +pos_minus0.in0 <= net0.cmd = 2.913000 +pos_minus0.in1 <= net0.fb = 2.837864 +pos_minus0.out <= pos_minus0.out = 0.071120 +p2uvw0.pwm <= cauto0.pwm_out = -0.728940 +p2uvw0.magpos <= cauto0.mag_pos_out = -2.942175 +p2uvw0.volt <= p2uvw0.volt = 130.000000 +p2uvw0.poles <= p2uvw0.poles = 1.000000 +p2uvw0.pwm_max <= p2uvw0.pwm_max = 0.900000 +p2uvw0.u <= p2uvw0.u = 38.788984 +p2uvw0.v <= p2uvw0.v = 119.271400 +p2uvw0.w <= p2uvw0.w = 56.419876 +p2uvw0.abpwm <= p2uvw0.abpwm = 0.000000 +pwm2uart0.u <= p2uvw0.u = 15.521914 +pwm2uart0.v <= p2uvw0.v = 92.122800 +pwm2uart0.w <= p2uvw0.w = 101.321298 +pwm2uart0.uout <= pwm2uart0.uout = 0.000000 +pwm2uart0.vout <= pwm2uart0.vout = 0.000000 +pwm2uart0.wout <= pwm2uart0.wout = 0.000000 +pwm2uart0.enable <= pwm2uart0.enable = 0.900000 +pwm2uart0.volt <= pwm2uart0.volt = 130.000000 +pwm2uart0.pwm_max <= pwm2uart0.pwm_max = 0.900000 +enc0.res0 <= enc0.res0 = 4096.000007 +enc0.pos0 <= enc0.pos0 = 1.047708 +enc0.reverse0 <= enc0.reverse0 = 0.000000 +enc0.res1 <= enc0.res1 = 4096.000007 +enc0.pos1 <= enc0.pos1 = 2.643049 +enc0.reverse1 <= enc0.reverse1 = 0.000000 +res0.pos <= res0.pos = 0.847776 +res0.amp <= res0.amp = 47330376.477777 +res0.s <= res0.s = -6728.941807 +res0.c <= res0.c = -6223.797887 +res0.reverse <= res0.reverse = 0.000000 +res0.enable <= res0.enable = 1.000000 +res0.error <= res0.error = 0.000000 +pid0.pos_error <= pos_minus0.out = 0.500155 +pid0.vel_cmd <= pid0.vel_cmd = -26.488356 +pid0.vel_ext_cmd <= net0.cmd_d = -43.214280 +pid0.vel_fb <= net0.fb_d = -38.350004 +pid0.vel_error <= pid0.vel_error = 11.491072 +pid0.acc_cmd <= pid0.acc_cmd = 18.848602 +pid0.acc_ext_cmd <= pid0.acc_ext_cmd = 0.000000 +pid0.force_cmd <= pid0.force_cmd = 0.956919 +pid0.force_ext_cmd <= pid0.force_ext_cmd = 0.000000 +pid0.cur_cmd <= pid0.cur_cmd = 0.866322 +pid0.cur_ext_cmd <= pid0.cur_ext_cmd = 0.000000 +pid0.cur_fb <= pid0.cur_fb = 0.000000 +pid0.cur_error <= pid0.cur_error = 0.776179 +pid0.volt_cmd <= pid0.volt_cmd = -65.166112 +pid0.pwm_cmd <= pid0.pwm_cmd = -0.900000 +pid0.enable <= cauto0.ready = 1.000000 +pid0.pos_en <= pid0.pos_en = 1.000000 +pid0.pos_p <= pid0.pos_p = 35.000000 +pid0.pos_lp <= pid0.pos_lp = 1.000000 +pid0.vel_en <= pid0.vel_en = 1.000000 +pid0.vel_p <= pid0.vel_p = 1.000000 +pid0.vel_i <= pid0.vel_i = 50.000000 +pid0.vel_d <= pid0.vel_d = 0.000000 +pid0.vel_ff <= pid0.vel_ff = 1.000000 +pid0.vel_lp <= pid0.vel_lp = 1.000000 +pid0.acc_en <= pid0.acc_en = 1.000000 +pid0.acc_p <= pid0.acc_p = 0.100000 +pid0.acc_ff <= pid0.acc_ff = 0.000000 +pid0.force_en <= pid0.force_en = 1.000000 +pid0.force_p <= pid0.force_p = 1.000000 +pid0.cur_p <= pid0.cur_p = 0.000000 +pid0.cur_ff <= pid0.cur_ff = 28.000000 +pid0.cur_d <= pid0.cur_d = 0.000000 +pid0.cur_ind <= pid0.cur_ind = 2.340000 +pid0.cur_lp <= pid0.cur_lp = 1.000000 +pid0.volt <= pid0.volt = 30.000000 +pid0.vel_max <= pid0.vel_max = 1361.356968 +pid0.vel_e_max <= pid0.vel_e_max = 1.250000 +pid0.acc_max <= pid0.acc_max = 272271.402777 +pid0.force_max <= pid0.force_max = 100.000000 +pid0.cur_max <= pid0.cur_max = 6.000000 +pid0.volt_max <= pid0.volt_max = 130.000000 +pid0.pwm_max <= pid0.pwm_max = 0.900000 +pid0.saturated <= pid0.saturated = 0.000000 +term0.wave0 <= net0.cmd = -2.536000 +term0.gain0 <= term0.gain0 = 10.000000 +term0.offset0 <= term0.offset0 = 0.000000 +term0.wave1 <= net0.fb = -3.133922 +term0.gain1 <= term0.gain1 = 10.000000 +term0.offset1 <= term0.offset1 = 0.000000 +term0.wave2 <= net0.cmd_d = -17.192756 +term0.gain2 <= term0.gain2 = 1.000000 +term0.offset2 <= term0.offset2 = 0.000000 +term0.wave3 <= net0.fb_d = -7.699728 +term0.gain3 <= term0.gain3 = 1.000000 +term0.offset3 <= term0.offset3 = 0.000000 +sim0.amp <= sim0.amp = 3.000000 +sim0.freq <= sim0.freq = 15.000000 +sim0.sin <= sim0.sin = -2.969000 +sim0.cos <= sim0.cos = -0.338999 +sim0.square <= sim0.square = -3.000000 +sim0.vel <= sim0.vel = -1.624185 +sim0.res <= sim0.res = 2000.000000 +pderiv0.in <= net0.cmd = -2.999500 +pderiv0.in_lp <= pderiv0.in_lp = 1.000000 +pderiv0.out <= pderiv0.out = 2.962924 +pderiv0.out_lp <= pderiv0.out_lp = 0.500000 +pderiv0.vel_max <= pderiv0.vel_max = 1361.356968 +pderiv0.acc_max <= pderiv0.acc_max = 272271.402777 +pderiv0.res <= pderiv0.res = 100000.000077 +pderiv1.in <= net0.fb = -2.925301 +pderiv1.in_lp <= pderiv1.in_lp = 1.000000 +pderiv1.out <= pderiv1.out = 22.999048 +pderiv1.out_lp <= pderiv1.out_lp = 1.000000 +pderiv1.vel_max <= pderiv1.vel_max = 1361.356968 +pderiv1.acc_max <= pderiv1.acc_max = 272271.402777 +pderiv1.res <= pderiv1.res = 100000.000077 +cauto0.pwm_in <= pid0.pwm_cmd = 0.695227 +cauto0.pwm_out <= cauto0.pwm_out = 0.542779 +cauto0.mag_pos_out <= cauto0.mag_pos_out = 0.532292 +cauto0.start <= cauto0.start = 1.000000 +cauto0.ready <= cauto0.ready = 1.000000 +cauto0.offset <= cauto0.offset = 1.495631 +cauto0.fb_in <= enc0.pos1 = -0.670349 +cauto0.fb_out <= cauto0.fb_out = -2.092349 +cauto0.pole_count <= cauto0.pole_count = 3.000000 +cauto0.scale <= cauto0.scale = 0.600000 +cauto0.time <= cauto0.time = 0.500000 +test0.test0 <= test0.test0 = 1.000000 +test0.test1 <= test0.test1 = 0.000000 +test0.test2 <= test0.test2 = 0.000000 +test0.start <= test0.start = 0.000000 +led0.r <= cauto0.start = 1.000000 +led0.g <= cauto0.ready = 1.000000 +led0.y <= led0.y = 0.000000 +net0.enable <= net0.enable = 1.000000 +net0.cmd <= sim0.sin = -1.636500 +net0.fb <= cauto0.fb_out = -1.055378 +net0.cmd_d <= pderiv0.out = 38.537812 +net0.fb_d <= pderiv1.out = 38.350224 \ No newline at end of file