Пример #1
0
struct DevPropDevice *devprop_add_device(struct DevPropString *string, char *path)
{
	struct DevPropDevice	*device;
	const char		pciroot_string[] = "PciRoot(0x";
	const char		pci_device_string[] = "Pci(0x";

	if (string == NULL || path == NULL) {
		return NULL;
	}
	device = malloc(sizeof(struct DevPropDevice));

	if (strncmp(path, pciroot_string, strlen(pciroot_string))) {
		printf("ERROR parsing device path\n");
		return NULL;
	}

	memset(device, 0, sizeof(struct DevPropDevice));
	device->acpi_dev_path._UID = getPciRootUID();

	int numpaths = 0;
	int		x, curr = 0;
	char	buff[] = "00";

	for (x = 0; x < strlen(path); x++) {
		if (!strncmp(&path[x], pci_device_string, strlen(pci_device_string))) {
			x+=strlen(pci_device_string);
			curr=x;
			while(path[++x] != ',');
			if(x-curr == 2)
				sprintf(buff, "%c%c", path[curr], path[curr+1]);
			else if(x-curr == 1)
				sprintf(buff, "%c", path[curr]);
			else 
			{
				printf("ERROR parsing device path\n");
				numpaths = 0;
				break;
			}
			device->pci_dev_path[numpaths].device =	ascii_hex_to_int(buff);
			
			x += 3; // 0x
			curr = x;
			while(path[++x] != ')');
			if(x-curr == 2)
				sprintf(buff, "%c%c", path[curr], path[curr+1]);
			else if(x-curr == 1)
				sprintf(buff, "%c", path[curr]);
			else
			{
				printf("ERROR parsing device path\n");
				numpaths = 0;
				break;
			}
			device->pci_dev_path[numpaths].function = ascii_hex_to_int(buff); // TODO: find dev from char *path
			
			numpaths++;
		}
	}
	
	if(!numpaths)
		return NULL;
	
	device->numentries = 0x00;
	
	device->acpi_dev_path.length = 0x0c;
	device->acpi_dev_path.type = 0x02;
	device->acpi_dev_path.subtype = 0x01;
	device->acpi_dev_path._HID = 0xd041030a;
	
	device->num_pci_devpaths = numpaths;
	device->length = 24 + (6*numpaths);
	
	int		i; 
	
	for(i = 0; i < numpaths; i++)
	{
		device->pci_dev_path[i].length = 0x06;
		device->pci_dev_path[i].type = 0x01;
		device->pci_dev_path[i].subtype = 0x01;
	}
	
	device->path_end.length = 0x04;
	device->path_end.type = 0x7f;
	device->path_end.subtype = 0xff;
	
	device->string = string;
	device->data = NULL;
	string->length += device->length;
	
	if(!string->entries)
		if((string->entries = (struct DevPropDevice**)malloc(sizeof(device)))== NULL)
			return 0;
	
	string->entries[string->numentries++] = (struct DevPropDevice*)malloc(sizeof(device));
	string->entries[string->numentries-1] = device;
	
	return device;
}
Пример #2
0
int main(
    int argc,
    char *argv[])
{
    unsigned long hThread = 0;
    uint32_t arg_value = 0;
    char lpBuf[1];
    DWORD dwRead = 0;
    unsigned i = 0, len = 0, count = 0;
    char hex_pair[5] = "0xff";
    char ch = ' ';
    int lsb = 0, msb = 0;
    long my_baud = 38400;
    uint8_t buffer[501] = { 0 };

    if (argc > 1) {
        RS485_Set_Interface(argv[1]);
    }
    if (argc > 2) {
        my_baud = strtol(argv[2], NULL, 0);
    }
    RS485_Set_Baud_Rate(my_baud);
    RS485_Initialize();
#if defined(_WIN32)
    SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_PROCESSED_INPUT);
    SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlCHandler, TRUE);
#endif
#ifdef TEST_RS485_TRANSMIT
    /* read a stream of characters from stdin or argument */
    if (argc > 3) {
        len = strlen(argv[3]);
        for (i = 0; i < len; i++) {
            /* grab pairs of hex characters, skip spaces */
            ch = argv[3][i];
            if (ch == ' ') {
                continue;
            }
            msb = ascii_hex_to_int(ch);
            if (msb >= 0) {
                i++;
                ch = argv[3][i];
                lsb = ascii_hex_to_int(ch);
                if (lsb >= 0) {
                    buffer[count] = msb << 4 | lsb;
                } else {
                    buffer[count] = msb;
                }
                count++;
                if (count >= sizeof(buffer)) {
                    break;
                }
            }
        }
        RS485_Send_Frame(NULL, buffer, count);
    }
#endif
#ifdef TEST_RS485_RECEIVE
    /* receive task */
    for (;;) {
        if (!ReadFile(RS485_Handle, lpBuf, sizeof(lpBuf), &dwRead, NULL)) {
            if (GetLastError() != ERROR_IO_PENDING) {
                RS485_Print_Error();
            }
        } else {
            /* print any characters received */
            if (dwRead) {
                for (i = 0; i < dwRead; i++) {
                    fprintf(stderr, "%02X ", lpBuf[i]);
                }
            }
            dwRead = 0;
        }
    }
#endif
}