Пример #1
0
void driver::driver_prc() {
  sc_time apply_delay (5, SC_NS);

  // Open file and read from first line:
  while (infile >> t_a >> t_b >> t_cin) {
    d_a.write(t_a);
    d_b.write(t_b);
    d_cin.write(t_cin);

    wait (apply_delay);
  }
}
Пример #2
0
int main() {
    llist entries;
    int status;
    char error[128];

    mime_header("application/json");
    fflush(stdout);

    obj = json_object_new_object();

    status = read_cgi_input(&entries);

    char *act = cgi_val(entries, "act");
    if (!act) {
        sprintf(error, "%s", "act required!");
        json_object_object_add(obj, "error", json_object_new_string(error));
        goto end;
    }

    if (STRCMP(act, "apply_ping"))    apply_ping();



    char *dev = cgi_val(entries, "dev");
    if (!dev) {
        sprintf(error, "%s", "dev required!");
        json_object_object_add(obj, "error", json_object_new_string(error));
        goto end;
    }

    int dev_num = atoi(dev);
    if (dev_num < 0 || dev_num >= MAX_DEV_NUM) {
        sprintf(error, "dev_num(%d) out of reange!", dev_num);
        json_object_object_add(obj, "error", json_object_new_string(error));
        goto end;
    }

    if (STRCMP(act, "apply_on"))    apply_on(dev_num);
    if (STRCMP(act, "apply_off"))   apply_off(dev_num);
    if (STRCMP(act, "apply_query")) apply_query(dev_num);



    if (STRCMP(act, "apply_delay")) {
    char *delay = cgi_val(entries, "delay");
        if (!delay) {
            sprintf(error, "%s", "delay required!");
            json_object_object_add(obj, "error", json_object_new_string(error));
            goto end;
        }
        apply_delay(dev_num, atoi(delay));
    }



    if (STRCMP(act, "apply_time")) {

        char *year = cgi_val(entries, "year");
        if (!year) {
            sprintf(error, "%s", "year required!");
            json_object_object_add(obj, "error", json_object_new_string(error));
            goto end;
        }
        int _year = atoi(year);

        char *month = cgi_val(entries, "month");
        if (!month) {
            sprintf(error, "%s", "month required!");
            json_object_object_add(obj, "error", json_object_new_string(error));
            goto end;
        }
        int _month = atoi(month);

        char *day = cgi_val(entries, "day");
        if (!day) {
            sprintf(error, "%s", "day required!");
            json_object_object_add(obj, "error", json_object_new_string(error));
            goto end;
        }
        int _day = atoi(day);

        char *hour = cgi_val(entries, "hour");
        if (!hour) {
            sprintf(error, "%s", "hour required!");
            json_object_object_add(obj, "error", json_object_new_string(error));
            goto end;
        }
        int _hour = atoi(hour);

        char *minute = cgi_val(entries, "minute");
        if (!minute) {
            sprintf(error, "%s", "minute required!");
            json_object_object_add(obj, "error", json_object_new_string(error));
            goto end;
        }
        int _minute = atoi(minute);

        char *second = cgi_val(entries, "second");
        if (!second) {
            sprintf(error, "%s", "second required!");
            json_object_object_add(obj, "error", json_object_new_string(error));
            goto end;
        }
        int _second = atoi(second);

        apply_time(dev_num, _year, _month, _day, _hour, _minute, _second);
    }



    if (STRCMP(act, "apply_schedule")) {

        char *index = cgi_val(entries, "index");
        if (!index) {
            sprintf(error, "%s", "index required!");
            json_object_object_add(obj, "error", json_object_new_string(error));
            goto end;
        }
        int _index = atoi(index);

        char *hour_start = cgi_val(entries, "hour_start");
        if (!hour_start) {
            sprintf(error, "%s", "hour_start required!");
            json_object_object_add(obj, "error", json_object_new_string(error));
            goto end;
        }
        int _hour_start = atoi(hour_start);

        char *minute_start = cgi_val(entries, "minute_start");
        if (!minute_start) {
            sprintf(error, "%s", "minute_start required!");
            json_object_object_add(obj, "error", json_object_new_string(error));
            goto end;
        }
        int _minute_start = atoi(minute_start);

        char *hour_end = cgi_val(entries, "hour_end");
        if (!hour_end) {
            sprintf(error, "%s", "hour_end required!");
            json_object_object_add(obj, "error", json_object_new_string(error));
            goto end;
        }
        int _hour_end = atoi(hour_end);

        char *minute_end = cgi_val(entries, "minute_end");
        if (!minute_end) {
            sprintf(error, "%s", "minute_end required!");
            json_object_object_add(obj, "error", json_object_new_string(error));
            goto end;
        }
        int _minute_end = atoi(minute_end);

        apply_schedule(dev_num, _index, _hour_start, _minute_start, _hour_end, _minute_end);
    }






    if (STRCMP(act, "get_status"))  get_status(dev_num);

    sprintf(error, "act(%s) not support!", act);
    json_object_object_add(obj, "error", json_object_new_string(error));

end:
    printf("%s", json_object_to_json_string(obj));
    json_object_put(obj);
    return 0;
}