void Database::write(MAHandle h) const { maDestroyObject(h); maCreateData(h, calculateDatabaseSize()); DataHandler data(h); int nDevices = devices.size(); data.write(&nDevices, sizeof(int)); for(int i=0; i<nDevices; i++) { writeDevice(data, devices[i]); } }
static int getDeviceIdentity (char *buffer, int *length) { int result; { static const unsigned char data[1] = {0}; result = writeDevice(0X04, data, sizeof(data)); if (result == -1) return 0; } result = usbReadEndpoint(usbChannel->device, usbChannel->definition.inputEndpoint, buffer, *length, MT_REQUEST_TIMEOUT); if (result == -1) return 0; logMessage(LOG_INFO, "Device Identity: %.*s", result, buffer); *length = result; return 1; }
static void vioWriteDevice(FILE *file, struct vioDevice *dev) { writeDevice(file, (struct device *)dev); }
int main(int argc, char *argv[]){ /* Local vars */ char filename[MAX_FILENAME_LENGTH]; FILE* devFile = NULL; struct SWDeviceEntry newEntry; int devCnt = 0; struct SWDeviceEntry devices[MASTER_MAXDEVICES]; struct SWDeviceEntry* findDev = NULL; /* Handel Input */ (void) argc; (void) argv; /* Get Device Filename */ if(buildDevFileName(filename, MAX_FILENAME_LENGTH) <= 0){ fprintf(stderr, "masterTest: Could not create devFile name.\n"); exit(EXIT_FAILURE); } /* Open Device File */ devFile = openDevFile(filename); if(devFile == NULL){ fprintf(stderr, "masterTest: Could not open devFile.\n"); exit(EXIT_FAILURE); } /* Write Test record */ newEntry.devInfo.swAddr = 0x0003u; newEntry.ipAddr = 0x33333333u; newEntry.devInfo.devTypes = SW_TYPE_UNIVERSAL | SW_TYPE_OUTLET; newEntry.devInfo.numChan = 0x03u; newEntry.devInfo.groupID = 0x01u; newEntry.devInfo.version = SW_VERSION; newEntry.devInfo.uid = 0x3333333333333333ull; newEntry.lineNum = -1; if(fseek(devFile, 0, SEEK_END) != 0){ fprintf(stderr, "masterTest: Could not seek to end of devFile.\n"); exit(EXIT_FAILURE); } if(writeDevice(&newEntry, devFile) < 0){ fprintf(stderr, "masterTest: Error writing new device to devFile.\n"); exit(EXIT_FAILURE); } /* Get Device Array */ devCnt = getDevices(devices, MASTER_MAXDEVICES, devFile); if(devCnt < 0){ fprintf(stderr, "masterTest: " "Error getting device list: getDevices returned %d\n", devCnt); exit(EXIT_FAILURE); } /* Sort Device Array */ if(sortDevices(devices, devCnt) < 0){ fprintf(stderr, "masterTest: Error sorting device list.\n"); exit(EXIT_FAILURE); } /* Find new device in array */ findDev = findDevice(newEntry.devInfo.swAddr, devices, devCnt); if(findDev == NULL){ fprintf(stderr, "masterTest: Could not find new device.\n"); exit(EXIT_FAILURE); } /* Remove new device from devFile */ findDev->lineNum = -1; devFile = updateDevices(devices, &devCnt, devFile); if(devFile == NULL){ fprintf(stderr, "masterTest: Could not update devFile.\n"); exit(EXIT_FAILURE); } /* Close Device File */ if(closeDevFile(devFile) != 0){ fprintf(stderr, "masterTest: Could not close devFile.\n"); exit(EXIT_FAILURE); } devFile = NULL; return 0; }
static int setHighVoltage (int on) { const unsigned char data[1] = {on? 0XFF: 0X7F}; return writeDevice(0X01, data, sizeof(data)) != -1; }