Ejemplo n.º 1
0
/*
inline int find_nbr_index (Machine *m, uint16_t src_id) {
  int left  = 0;
  int right = m->n_hood-1;
  // POST("M%d LOOKING UP NBR %d N_HOOD %d: ", m->id, src_id, m->n_hood);
  // post_nbrs(m); POST("\n");
  while (left <= right) {
    int mid = (left + right)>>1;
    NBR *nbr = m->hood[mid];
    // POST("M%d LOOKING AT %d M%d\n", m->id, mid, nbr->id);
    if (nbr->id == src_id) {
      // POST("M%d FOUND NBR AT %d\n", m->id, mid);
      return mid;
    } else if (src_id < nbr->id)
      right = mid - 1;
    else
      left  = mid + 1;
  }
  // POST("M%d LOST NBR %d\n", m->id, src_id);
  return -1;
}
*/
void UnitDiscRadio::device_moved(Device* d) {
  // now do the actual neighborhood update
  disconnect_device(d); connect_device(d);
  if(is_fast_prune_hood) { // delete the VM hood entries that are lost
    for(NeighbourHood::iterator i = d->vm->hood.begin(); i != d->vm->hood.end(); i++){
      i->in_range = false;
    }
    d->vm->thisMachine().in_range = true;
    UnitDiscDevice* udd = (UnitDiscDevice*)d->layers[id];
    for(int i=0;i<udd->neighbors.max_id();i++) {
      NbrRecord* nr = (NbrRecord*)udd->neighbors.get(i);
      if(nr) {
        MachineId nid = nr->nbr->container->uid;
        NeighbourHood::iterator nbr = d->vm->hood.find(nid);
        if (nbr != d->vm->hood.end()) nbr->in_range = true;
      }
    }
    for(NeighbourHood::iterator i = d->vm->hood.begin(); i != d->vm->hood.end(); ){
      if (i->in_range) {
        i++;
      } else {
        i = d->vm->hood.remove(i);
      }
    }
  }
}
Ejemplo n.º 2
0
PROCESS_THREAD(application1,ev,data)
{
	PROCESS_BEGIN();

	printf("LAUNCH SUCCESS: %d\n",
		knot_register_controller(&application1,
								 NULL, 
								 1, "BOSS", SENSOR, LIGHT));

	
	
	/* Application do something? */
	while (1){
		PROCESS_WAIT_EVENT();
		if (ev == KNOT_EVENT_SERVICE_FOUND){
			memcpy(&sc,data,sizeof(ServiceRecord));
			printf("Service found: %s\n", sc.name); 
			if (!found){
				connect_device(&sc);
				found = 1;

			}
		}
		else if (ev == KNOT_EVENT_DATA_READY){
			callback(data);
		}
		else if (ev == KNOT_EVENT_CONNECTED_DEVICE){
			handle_new_device(data);
		}
	}

	PROCESS_END();
}
Ejemplo n.º 3
0
static void connect_service(int fd, void* cookie)
{
    char buf[4096];
    char resp[4096];
    char *host = cookie;

    reconnector *recon;
    recon = find_reconnector(host);
    /* if we're already reconnecting, skip the connection and just
    keep reconnecting */
    if (recon) {
        sendfailmsg(fd, "already reconnecting");
        return 0;
    }
    if (!strncmp(host, "emu:", 4)) {
        connect_emulator(host + 4, buf, sizeof(buf));
    } else {
        connect_device(host, buf, sizeof(buf));
    }

    // Send response for emulator and device
    snprintf(resp, sizeof(resp), "%04x%s",(unsigned)strlen(buf), buf);
    writex(fd, resp, strlen(resp));
    adb_close(fd);
}
Ejemplo n.º 4
0
static void connect_service(int fd, void* data) {
    char* host = reinterpret_cast<char*>(data);
    std::string response;
    if (!strncmp(host, "emu:", 4)) {
        connect_emulator(host + 4, &response);
    } else {
        connect_device(host, &response);
    }
    free(host);

    // Send response for emulator and device
    SendProtocolString(fd, response);
    adb_close(fd);
}
Ejemplo n.º 5
0
static void connect_service(int fd, void* cookie)
{
    char buf[4096];
    char resp[4096];
    char *host = cookie;

    if (!strncmp(host, "emu:", 4)) {
        connect_emulator(host + 4, buf, sizeof(buf));
    } else {
        connect_device(host, buf, sizeof(buf));
    }

    // Send response for emulator and device
    snprintf(resp, sizeof(resp), "%04x%s",(unsigned)strlen(buf), buf);
    writex(fd, resp, strlen(resp));
    adb_close(fd);
}
Ejemplo n.º 6
0
static void *reconnect_thread(void *vrecon)
{
    reconnector *recon = vrecon;
    while (1) {
        sleep_seconds(2);
        if (recon->reconnect_bail) {
            D("reconnect bail\n");
            break;
        }
        D("trying to reconnect to %s\n", recon->serial);
        errbuf[0] = '\0';
        if (connect_device(recon->serial, errbuf, ERRLEN) > 0) {
            D("reconnect success: %s\n", errbuf);
            break;
        } else {
            D("reconnect failed: %s\n", errbuf);
        }
    }

    D("exiting reconnect thread\n");
    remove_reconnector(recon);
    return 0;
}
Ejemplo n.º 7
0
int handle_host_request(char *service, transport_type ttype, char* serial, int reply_fd, asocket *s)
{
    atransport *transport = NULL;
    char buf[4096];

    if(!strcmp(service, "kill")) {
        fprintf(stderr,"adb server killed by remote request\n");
        fflush(stdout);
        adb_write(reply_fd, "OKAY", 4);
        usb_cleanup();
        exit(0);
    }

#if ADB_HOST
    // "transport:" is used for switching transport with a specified serial number
    // "transport-usb:" is used for switching transport to the only USB transport
    // "transport-local:" is used for switching transport to the only local transport
    // "transport-any:" is used for switching transport to the only transport
    if (!strncmp(service, "transport", strlen("transport"))) {
        char* error_string = "unknown failure";
        transport_type type = kTransportAny;

        if (!strncmp(service, "transport-usb", strlen("transport-usb"))) {
            type = kTransportUsb;
        } else if (!strncmp(service, "transport-local", strlen("transport-local"))) {
            type = kTransportLocal;
        } else if (!strncmp(service, "transport-any", strlen("transport-any"))) {
            type = kTransportAny;
        } else if (!strncmp(service, "transport:", strlen("transport:"))) {
            service += strlen("transport:");
            serial = strdup(service);
        }

        transport = acquire_one_transport(CS_ANY, type, serial, &error_string);

        if (transport) {
            s->transport = transport;
            adb_write(reply_fd, "OKAY", 4);
        } else {
            sendfailmsg(reply_fd, error_string);
        }
        return 1;
    }

    // return a list of all connected devices
    if (!strcmp(service, "devices")) {
        char buffer[4096];
        memset(buf, 0, sizeof(buf));
        memset(buffer, 0, sizeof(buffer));
        D("Getting device list \n");
        list_transports(buffer, sizeof(buffer));
        snprintf(buf, sizeof(buf), "OKAY%04x%s",(unsigned)strlen(buffer),buffer);
        D("Wrote device list \n");
        writex(reply_fd, buf, strlen(buf));
        return 0;
    }

    // add a new TCP transport, device or emulator
    if (!strncmp(service, "connect:", 8)) {
        char buffer[4096];
        char* host = service + 8;
        if (!strncmp(host, "emu:", 4)) {
            connect_emulator(host + 4, buffer, sizeof(buffer));
        } else {
            connect_device(host, buffer, sizeof(buffer));
        }
        // Send response for emulator and device
        snprintf(buf, sizeof(buf), "OKAY%04x%s",(unsigned)strlen(buffer), buffer);
        writex(reply_fd, buf, strlen(buf));
        return 0;
    }

    // remove TCP transport
    if (!strncmp(service, "disconnect:", 11)) {
        char buffer[4096];
        memset(buffer, 0, sizeof(buffer));
        char* serial = service + 11;
        if (serial[0] == 0) {
            // disconnect from all TCP devices
            unregister_all_tcp_transports();
        } else {
            char hostbuf[100];
            // assume port 5555 if no port is specified
            if (!strchr(serial, ':')) {
                snprintf(hostbuf, sizeof(hostbuf) - 1, "%s:5555", serial);
                serial = hostbuf;
            }
            atransport *t = find_transport(serial);

            if (t) {
                unregister_transport(t);
            } else {
                snprintf(buffer, sizeof(buffer), "No such device %s", serial);
            }
        }

        snprintf(buf, sizeof(buf), "OKAY%04x%s",(unsigned)strlen(buffer), buffer);
        writex(reply_fd, buf, strlen(buf));
        return 0;
    }

    // returns our value for ADB_SERVER_VERSION
    if (!strcmp(service, "version")) {
        char version[12];
        snprintf(version, sizeof version, "%04x", ADB_SERVER_VERSION);
        snprintf(buf, sizeof buf, "OKAY%04x%s", (unsigned)strlen(version), version);
        writex(reply_fd, buf, strlen(buf));
        return 0;
    }

    if(!strncmp(service,"get-serialno",strlen("get-serialno"))) {
        char *out = "unknown";
         transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
       if (transport && transport->serial) {
            out = transport->serial;
        }
        snprintf(buf, sizeof buf, "OKAY%04x%s",(unsigned)strlen(out),out);
        writex(reply_fd, buf, strlen(buf));
        return 0;
    }
    // indicates a new emulator instance has started
    if (!strncmp(service,"emulator:",9)) {
        int  port = atoi(service+9);
        local_connect(port);
        /* we don't even need to send a reply */
        return 0;
    }
#endif // ADB_HOST

    if(!strncmp(service,"forward:",8) || !strncmp(service,"killforward:",12)) {
        char *local, *remote, *err;
        int r;
        atransport *transport;

        int createForward = strncmp(service,"kill",4);

        local = service + (createForward ? 8 : 12);
        remote = strchr(local,';');
        if(remote == 0) {
            sendfailmsg(reply_fd, "malformed forward spec");
            return 0;
        }

        *remote++ = 0;
        if((local[0] == 0) || (remote[0] == 0) || (remote[0] == '*')){
            sendfailmsg(reply_fd, "malformed forward spec");
            return 0;
        }

        transport = acquire_one_transport(CS_ANY, ttype, serial, &err);
        if (!transport) {
            sendfailmsg(reply_fd, err);
            return 0;
        }

        if (createForward) {
            r = install_listener(local, remote, transport);
        } else {
            r = remove_listener(local, remote, transport);
        }
        if(r == 0) {
                /* 1st OKAY is connect, 2nd OKAY is status */
            writex(reply_fd, "OKAYOKAY", 8);
            return 0;
        }

        if (createForward) {
            sendfailmsg(reply_fd, (r == -1) ? "cannot rebind smartsocket" : "cannot bind socket");
        } else {
            sendfailmsg(reply_fd, "cannot remove listener");
        }
        return 0;
    }

    if(!strncmp(service,"get-state",strlen("get-state"))) {
        transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
        char *state = connection_state_name(transport);
        snprintf(buf, sizeof buf, "OKAY%04x%s",(unsigned)strlen(state),state);
        writex(reply_fd, buf, strlen(buf));
        return 0;
    }
    return -1;
}
Ejemplo n.º 8
0
int
main (int argc, char *argv[])
{
	gboolean ret;
	GError *error = NULL;
	GMainLoop *loop = NULL;
	GUsbContext *ctx;
	GUsbDevice *device = NULL;
	int retval = 0;
	GUsbDeviceList *list = NULL;
	ChDeviceQueue *device_queue;

	/* setup usb */
	g_type_init ();
	ctx = g_usb_context_new (&error);
	if (ctx == NULL) {
		g_warning ("Cannot connect to USB : %s", error->message);
		g_error_free (error);
		retval = 1;
		goto out;
	}
	list = g_usb_device_list_new (ctx);
	device_queue = ch_device_queue_new ();

	ret = connect_device (list, &device, &error);
	if (!ret) {
		g_warning ("Cannot connect to device : %s", error->message);
		g_error_free (error);
		retval = 1;
		goto out;
	}

	/* reset device so it boots back into bootloader mode */
	g_warning ("Switching to bootloader mode\n");
	ch_device_queue_reset (device_queue, device);
	ret = ch_device_queue_process (device_queue,
				       CH_DEVICE_QUEUE_PROCESS_FLAGS_NONE,
				       NULL,
				       &error);
	if (!ret) {
		g_warning ("Failed to reboot : %s", error->message);
		g_error_free (error);
		retval = 1;
		goto out;
	}

	/* wait for device to re-appear */
	loop = g_main_loop_new (NULL, FALSE);
	g_timeout_add (5000, quit_loop_cb, loop);
	g_main_loop_run (loop);
	g_object_unref (device);
	ret = connect_device (list, &device, &error);
	if (!ret) {
		g_warning ("Cannot connect to device : %s", error->message);
		g_error_free (error);
		retval = 1;
		goto out;
	}

	/* boot into firmware mode */
	g_warning ("Switching to firmware mode\n");
	ch_device_queue_boot_flash (device_queue, device);
	ret = ch_device_queue_process (device_queue,
				       CH_DEVICE_QUEUE_PROCESS_FLAGS_NONE,
				       NULL,
				       &error);
	if (!ret) {
		g_warning ("Failed to boot into firmware mode : %s", error->message);
		g_error_free (error);
		retval = 1;
		goto out;
	}

	/* wait for device to re-appear */
	g_timeout_add (5000, quit_loop_cb, loop);
	g_main_loop_run (loop);
	g_object_unref (device);
	ret = connect_device (list, &device, &error);
	if (!ret) {
		g_warning ("Cannot connect to device : %s", error->message);
		g_error_free (error);
		retval = 1;
		goto out;
	}

	/* turn on LEDs */
	g_warning ("Turning on LEDs\n");
	ch_device_queue_set_leds (device_queue, device, 3, 0, 0, 0);
	ret = ch_device_queue_process (device_queue,
				       CH_DEVICE_QUEUE_PROCESS_FLAGS_NONE,
				       NULL,
				       &error);
	if (!ret) {
		g_warning ("Failed to turn on LEDs : %s", error->message);
		g_error_free (error);
		retval = 1;
		goto out;
	}

	/* success */
	g_warning ("ALL OKAY\n");
out:
	if (loop != NULL)
		g_main_loop_unref (loop);
	if (ctx != NULL)
		g_object_unref (ctx);
	if (device_queue != NULL)
		g_object_unref (device_queue);
	if (device != NULL)
		g_object_unref (device);
	if (list != NULL)
		g_object_unref (list);
	return retval;
}
Ejemplo n.º 9
0
int handle_host_request(char *service, transport_type ttype, char* serial, int reply_fd, asocket *s)
{
    D("service=%s, ttype=%d, serial=%s, reply_fd=%d, asocket=?\n",
        service, ttype, serial, reply_fd);
    atransport *transport = NULL;
    char buf[4096];

    if(!strcmp(service, "kill")) {
        fprintf(stderr,"adb server killed by remote request\n");
        fflush(stdout);
        adb_write(reply_fd, "OKAY", 4);
        usb_cleanup();
        exit(0);
    }

#if ADB_HOST
    // "transport:" is used for switching transport with a specified serial number
    // "transport-usb:" is used for switching transport to the only USB transport
    // "transport-local:" is used for switching transport to the only local transport
    // "transport-any:" is used for switching transport to the only transport
    if (!strncmp(service, "transport", strlen("transport"))) {
        char* error_string = "unknown failure";
        transport_type type = kTransportAny;

        if (!strncmp(service, "transport-usb", strlen("transport-usb"))) {
            type = kTransportUsb;
        } else if (!strncmp(service, "transport-local", strlen("transport-local"))) {
            type = kTransportLocal;
        } else if (!strncmp(service, "transport-any", strlen("transport-any"))) {
            type = kTransportAny;
        } else if (!strncmp(service, "transport:", strlen("transport:"))) {
            service += strlen("transport:");
            serial = service;
        }

        transport = acquire_one_transport(CS_ANY, type, serial, &error_string);

        if (transport) {
            s->transport = transport;
            adb_write(reply_fd, "OKAY", 4);
        } else {
            sendfailmsg(reply_fd, error_string);
        }
        return 1;
    }

    // return a list of all connected devices
    if (!strncmp(service, "devices", 7)) {
        char buffer[4096];
        int use_long = !strcmp(service+7, "-l");
        if (use_long || service[7] == 0) {
            memset(buf, 0, sizeof(buf));
            memset(buffer, 0, sizeof(buffer));
            D("Getting device list \n");
            list_transports(buffer, sizeof(buffer), use_long);
            snprintf(buf, sizeof(buf), "OKAY%04x%s",(unsigned)strlen(buffer),buffer);
            D("Wrote device list \n");
            writex(reply_fd, buf, strlen(buf));
            return 0;
        }
    }

    // add a new TCP transport, device or emulator
    if (!strncmp(service, "connect:", 8)) {
        char buffer[4096];
        char* host = service + 8;
        if (!strncmp(host, "emu:", 4)) {
            connect_emulator(host + 4, buffer, sizeof(buffer));
        } else {
            connect_device(host, buffer, sizeof(buffer));
        }
        // Send response for emulator and device
        snprintf(buf, sizeof(buf), "OKAY%04x%s",(unsigned)strlen(buffer), buffer);
        writex(reply_fd, buf, strlen(buf));
        return 0;
    }

    // remove TCP transport
	// Disable the disconnect service to prevent complexity with Windows
  //
    // returns our value for ADB_SERVER_VERSION
    if (!strcmp(service, "version")) {
        printf("the version service is disabled.\n");
        return -1;
    }

    if(!strncmp(service,"get-serialno",strlen("get-serialno"))) {
        char *out = "unknown";
         transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
       if (transport && transport->serial) {
            out = transport->serial;
        }
        snprintf(buf, sizeof buf, "OKAY%04x%s",(unsigned)strlen(out),out);
        writex(reply_fd, buf, strlen(buf));
        return 0;
    }
    if(!strncmp(service,"get-devpath",strlen("get-devpath"))) {
        char *out = "unknown";
         transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
       if (transport && transport->devpath) {
            out = transport->devpath;
        }
        snprintf(buf, sizeof buf, "OKAY%04x%s",(unsigned)strlen(out),out);
        writex(reply_fd, buf, strlen(buf));
        return 0;
    }
    // indicates a new emulator instance has started
    if (!strncmp(service,"emulator:",9)) {
        int  port = atoi(service+9);
        local_connect(port);
        /* we don't even need to send a reply */
        return 0;
    }
#endif // ADB_HOST

    if(!strcmp(service,"list-forward")) {
        // Create the list of forward redirections.
        char header[9];
        int buffer_size = format_listeners(NULL, 0);
        // Add one byte for the trailing zero.
        char* buffer = (char*)malloc(buffer_size+1);
        (void) format_listeners(buffer, buffer_size+1);
        snprintf(header, sizeof header, "OKAY%04x", buffer_size);
        writex(reply_fd, header, 8);
        writex(reply_fd, buffer, buffer_size);
        free(buffer);
        return 0;
    }

    if (!strcmp(service,"killforward-all")) {
        remove_all_listeners();
        adb_write(reply_fd, "OKAYOKAY", 8);
        return 0;
    }

    if(!strncmp(service,"forward:",8) ||
       !strncmp(service,"killforward:",12)) {
        char *local, *remote, *err;
        int r;
        atransport *transport;

        int createForward = strncmp(service,"kill",4);
        int no_rebind = 0;

        local = strchr(service, ':') + 1;

        // Handle forward:norebind:<local>... here
        if (createForward && !strncmp(local, "norebind:", 9)) {
            no_rebind = 1;
            local = strchr(local, ':') + 1;
        }

        remote = strchr(local,';');

        if (createForward) {
            // Check forward: parameter format: '<local>;<remote>'
            if(remote == 0) {
                sendfailmsg(reply_fd, "malformed forward spec");
                return 0;
            }

            *remote++ = 0;
            if((local[0] == 0) || (remote[0] == 0) || (remote[0] == '*')){
                sendfailmsg(reply_fd, "malformed forward spec");
                return 0;
            }
        } else {
            // Check killforward: parameter format: '<local>'
            if (local[0] == 0) {
                sendfailmsg(reply_fd, "malformed forward spec");
                return 0;
            }
        }

        transport = acquire_one_transport(CS_ANY, ttype, serial, &err);
        if (!transport) {
            sendfailmsg(reply_fd, err);
            return 0;
        }

        if (createForward) {
            r = install_listener(local, remote, transport, no_rebind);
        } else {
            r = remove_listener(local, transport);
        }
        if(r == 0) {
                /* 1st OKAY is connect, 2nd OKAY is status */
            writex(reply_fd, "OKAYOKAY", 8);
            return 0;
        }

        if (createForward) {
            const char* message;
            switch (r) {
              case INSTALL_STATUS_CANNOT_BIND:
                message = "cannot bind to socket";
                break;
              case INSTALL_STATUS_CANNOT_REBIND:
                message = "cannot rebind existing socket";
                break;
              default:
                message = "internal error";
            }
            sendfailmsg(reply_fd, message);
        } else {
            sendfailmsg(reply_fd, "cannot remove listener");
        }
        return 0;
    }

    if(!strncmp(service,"get-state",strlen("get-state"))) {
        transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
        char *state = connection_state_name(transport);
        snprintf(buf, sizeof buf, "OKAY%04x%s",(unsigned)strlen(state),state);
        writex(reply_fd, buf, strlen(buf));
        return 0;
    }
    return -1;
}
Ejemplo n.º 10
0
void UnitDiscRadio::add_device(Device* d) {
  d->layers[id] = new UnitDiscDevice(this,d);
  connect_device(d);
}
Ejemplo n.º 11
0
/**
 * Main, startup
 */
int main(int argc, char *argv[]) {

    // Filename of the HEX File
    const char * hexfile = NULL;

    // 1 if verify, 2 if programm
    char verify = 0;

    // Serial device
    const char * device = "/dev/ttyS0";

    // Baudrate
    int baud = 4800;
    int baudid = -1;

    // if crc is supported (not supportet if 2)
    int crc_on;

    // The path to the binary (for finding devices.txt)
    readlink("/proc/self/exe", devices_file_p, 255); // symlink to this binary
    chp = strrchr (devices_file_p,'/');  // get the last path separator
    if (chp) strcpy (chp+1,DEVICES_FILE); // copy the device filename after the path separator


    // print header
    printf("\n");
    printf("=================================================\n");
    printf("|             BOOTLOADER, Target: V2.1          |\n");
    printf("=================================================\n");

    // Parsing / checking parameter
    int i;
    int type = 0;

    for(i = 1; i < argc; i++) {
        if(*argv[i] == '-') {
            type = argv[i][1];
        }
        else {
            switch(type) {
            case 'd':
                device = argv[i];
                break;
            case 'b':
                baud = atoi(argv[i]);
                break;
            case 'v':
                verify = 1;
                hexfile = argv[i];
                break;
            case 'p':
                verify = 2;
                hexfile = argv[i];
                break;
            default:
                printf("Wrong parameter!\n");
                usage();
            }
            type = 0;
        }
    }

    if(hexfile == NULL) {
        printf("No hexfile specified!\n");
        usage();
    }

    if(verify == 0) {
        printf("No Verify / Programm specified!\n");
        usage();
    }

    // Checking baudrate
    for(i = 0; i < BAUD_CNT; i++) {
        if (baud_value[i] == baud) {
            baudid = i;
            break;
        }
    }

    if(baudid == -1) {
        printf("Unknown baudrate (%i)!\n", baud);
        usage();
    }

    printf("Device   : %s\n", device);
    printf("Baudrate : %i\n", baud);
    printf("%s: %s\n", (verify == 1 ? "Verify   " : "Program  "), hexfile);
    printf("-------------------------------------------------\n");

    if(!com_open(device, baud_const[baudid])) {
        printf("Open com port failed!\n");
        exit(2);
    }

    connect_device();
    crc_on = check_crc();
    read_info();

    /*if(read_info()) {
    }
    else {
    	printf("Reading device information failed!\n");
    }*/

    if(crc_on != 2) {
        crc_on = check_crc();
        switch(crc_on) {
        case 2:
            printf("No CRC support.\n");
            break;
        case 0:
            printf("CRC enabled and OK.\n");
            break;
        case 3:
            printf("CRC check failed!\n");
            break;
        default:
            printf("Checking CRC Error (%i)!\n", crc_on);
            break;
        }
    }
    else {
        printf("No CRC support.\n");
    }

    flash(verify==1, hexfile);
    if( crc_on != 2 ) {
        if( check_crc() )
            printf( "CRC-Error !\n");
        else
            printf("CRC: o.k.\n");
    }

#ifdef SHOW_TIME_MS
    //time @ ms
    printf("Elapsed time: %d s\n", elapsed_msecs (&t_start));
#endif

#ifdef SHOW_TIME_S
    printf("Elapsed time: %.3f seconds\n", elapsed_secs (&t_start));
#endif

    printf("...starting application\n\n");
    sendcommand(START);//start application
    sendcommand(START);

    com_close();//close opened com port
    return 0;
}
Ejemplo n.º 12
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    port=new AbstractSerial(this);
    port->setTotalReadConstantTimeout(0);

    timer=new QTimer();
    settings_timer=new QTimer();

    connect(settings_timer,SIGNAL(timeout()),this,SLOT(on_set_all_calibrates_clicked()));

    p_uso=new proto_uso(this,port);
     QTextCodec::setCodecForTr(QTextCodec::codecForName("Windows-1251"));
    ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("Название канала")));
    ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Тип канала")));
    ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem(tr("Диапазон")));
    ui->tableWidget->setHorizontalHeaderItem(3, new QTableWidgetItem(tr("Фильтр")));
    ui->tableWidget->setHorizontalHeaderItem(4, new QTableWidgetItem(tr("Значение")));
    ui->tableWidget->setHorizontalHeaderItem(5, new QTableWidgetItem(tr("Калибровка 0")));
    ui->tableWidget->setHorizontalHeaderItem(6, new QTableWidgetItem(tr("Значение  0")));
    ui->tableWidget->setHorizontalHeaderItem(7, new QTableWidgetItem(tr("Калибровка 1")));
    ui->tableWidget->setHorizontalHeaderItem(8, new QTableWidgetItem(tr("Значение  1")));
    ui->tableWidget->setHorizontalHeaderItem(9, new QTableWidgetItem(tr("Калибр.")));
    ui->tableWidget->setHorizontalHeaderItem(10, new QTableWidgetItem(tr("Установить")));

    ui->tableWidget->setHorizontalHeaderItem(11, new QTableWidgetItem(tr("Разрядность")));
  //  ui->tableWidget->setHorizontalHeaderItem(12, new QTableWidgetItem(tr("Отключить канал")));
   // timer->start(1000);

    ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);


     connect(p_uso,SIGNAL(DEV_INFO_RESPONSED()),this,SLOT(on_dev_info_responsed()));
     connect(p_uso,SIGNAL(GET_ALL_DATA_RESPONSED()),this,SLOT(on_dev_get_data_responsed()));

     connect(ui->action_LOAD,SIGNAL(triggered()),this,SLOT(on_menu_load_settings_clicked()));
     connect(ui->action_SAVE,SIGNAL(triggered()),this,SLOT(on_menu_save_settings_clicked()));

     connect(timer,SIGNAL(timeout()),this,SLOT(Get_All_Data()));


     connect_dlg=new connect_dialog();
     connect(connect_dlg,SIGNAL(connect_device(quint8)),this,SLOT(on_connect_device(quint8)));


     for(quint8 i=0;i<20;i++)
     {
          chnl[i]=new CHANNEL();
     }

     strlist<<tr("0-2.56 В")<<tr("0-1.28 В")<<tr("0-640 мВ")<<tr("0-320 мВ")<<tr("0-160 мВ")<<tr("0-80 мВ")<<tr("0-40 мВ")<<tr("0-20 мВ");
     bitlist<<tr("24")<<tr("16");

     read_flag=false;


     d_info=new dev_info(this);//диалог информации об устройстве
     connect(d_info,SIGNAL(get_dev_info()),this,SLOT(on_dialog_get_dev_info()));
     connect(d_info,SIGNAL(set_dev_info()),this,SLOT(on_dialog_set_dev_info()));

     CalibrList.clear();

     connect(p_uso,SIGNAL(GET_CALIBRATE_RESPONSED(quint8,quint8,float,float)),this,SLOT(on_get_calibrate_responsed(quint8,quint8,float,float)));

     UnactiveInterface();
}