117 lines
3.2 KiB
C
117 lines
3.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdarg.h>
|
|
#include <ctype.h>
|
|
|
|
// Get the PRIu64 macro for timestamps
|
|
#define __STDC_FORMAT_MACROS
|
|
#include <inttypes.h>
|
|
|
|
// Include icsneo/icsneoc.h to access library functions
|
|
#include "icsneo/icsneoc.h"
|
|
|
|
#define DEVICES_MAX 16
|
|
|
|
size_t numDevices = DEVICES_MAX;
|
|
neodevice_t devices[DEVICES_MAX];
|
|
|
|
neonetid_t netid = ICSNEO_NETID_HSCAN;
|
|
int64_t baudrate = 500000;
|
|
int64_t fdbaudrate = 500000;
|
|
|
|
const neodevice_t* selectedDevice = NULL;
|
|
|
|
int closeonfail(const neodevice_t* device) {
|
|
printf ("!!!!!!!\n");
|
|
if(icsneo_closeDevice(device)) {
|
|
printf("%s successfully closed!\n", device->serial);
|
|
} else {
|
|
printf("%s failed to close!\n", device->serial);
|
|
}
|
|
exit(1);
|
|
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
if (argc != 5) {
|
|
printf("Please check parameters!\n");
|
|
exit(1);
|
|
}
|
|
|
|
if(strcmp("hscan", argv[2]) == 0) {
|
|
netid = ICSNEO_NETID_HSCAN;
|
|
}
|
|
else if (strcmp("hscan2", argv[2]) == 0) {
|
|
netid = ICSNEO_NETID_HSCAN2;
|
|
}
|
|
else {
|
|
printf("Please check network\n");
|
|
exit(1);
|
|
}
|
|
|
|
baudrate = atoi(argv[3]);
|
|
if (baudrate < 20000 || baudrate > 1000000) {
|
|
printf("Please check range of reqeusted baud rate.\n");
|
|
exit(1);
|
|
}
|
|
fdbaudrate = atoi(argv[4]);
|
|
if (fdbaudrate < 20000 || fdbaudrate > 8000000) {
|
|
printf("Please check range of reqeusted baud rate.\n");
|
|
exit(1);
|
|
}
|
|
|
|
icsneo_findAllDevices(devices, &numDevices);
|
|
|
|
for(size_t i = 0; i < numDevices; i++) {
|
|
|
|
if(strcmp(devices[i].serial,argv[1]) == 0)
|
|
{
|
|
int result = icsneo_openDevice(&devices[i]);
|
|
if(result) {
|
|
printf("%s successfully opened!\n", devices[i].serial);
|
|
} else {
|
|
printf("%s failed to open! %d\n", devices[i].serial, result);
|
|
exit(1);
|
|
}
|
|
|
|
result = icsneo_setBaudrate(&devices[i], netid, baudrate);
|
|
if (result) {
|
|
printf("Successfully set %s baudrate for %s to %d!\n", argv[2], devices[i].serial, baudrate);
|
|
} else {
|
|
printf("FAILED to set %s baudrate for %s to %d! %d\n", argv[2], devices[i].serial, baudrate, result);
|
|
closeonfail(&devices[i]);
|
|
}
|
|
|
|
result = icsneo_setFDBaudrate(&devices[i], netid, fdbaudrate);
|
|
if (result) {
|
|
printf("Successfully set %s FD baudrate for %s to %d!\n", argv[2], devices[i].serial, fdbaudrate);
|
|
} else {
|
|
printf("FAILED to set %s FD baudrate for %s to %d! %d\n", argv[2], devices[i].serial, fdbaudrate, result);
|
|
closeonfail(&devices[i]);
|
|
}
|
|
|
|
result = icsneo_settingsApply(&devices[i]);
|
|
if (result) {
|
|
printf("Successfully applied settings!\n");
|
|
} else {
|
|
printf("FAILED apply settings! %d\n", result);
|
|
closeonfail(&devices[i]);
|
|
}
|
|
|
|
if(icsneo_closeDevice(&devices[i])) {
|
|
printf("%s successfully closed!\n", devices[i].serial);
|
|
} else {
|
|
printf("%s failed to close!\n", devices[i].serial);
|
|
exit(1);
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
}
|
|
|
|
printf("Something went wrong!!\n");
|
|
exit(1);
|
|
} |