Fast and Ugly solution; First commit; Tested and working.
parent
9b624565c4
commit
a0e7a15dc8
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
sudo gcc icsbaudset.c -licsneoc -o /usr/sbin/libicsneo-setbaud
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
#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 main(int argc, char *argv[]) {
|
||||
|
||||
if (argc != 5) {
|
||||
printf("Please check parameters!\n\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)
|
||||
{
|
||||
if(icsneo_openDevice(&devices[i])) {
|
||||
printf("%s successfully opened!\n\n", devices[i].serial);
|
||||
} else {
|
||||
printf("%s failed to open!\n\n", devices[i].serial);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(icsneo_setBaudrate(&devices[i], netid, baudrate) && icsneo_settingsApply(&devices[i])) {
|
||||
printf("Successfully set %s baudrate for %s to %d!\n\n", argv[2], devices[i].serial, baudrate);
|
||||
} else {
|
||||
printf("FAILED to set %s baudrate for %s to %d!\n\n", argv[2], devices[i].serial, baudrate);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(icsneo_setFDBaudrate(&devices[i], netid, fdbaudrate) && icsneo_settingsApply(&devices[i])) {
|
||||
printf("Successfully set %s FD baudrate for %s to %d!\n\n", argv[2], devices[i].serial, fdbaudrate);
|
||||
} else {
|
||||
printf("FAILED to set %s FD baudrate for %s to %d!\n\n", argv[2], devices[i].serial, fdbaudrate);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(icsneo_closeDevice(&devices[i])) {
|
||||
printf("%s successfully closed!\n\n", devices[i].serial);
|
||||
} else {
|
||||
printf("%s failed to close!\n\n", devices[i].serial);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
printf("Something went wrong!!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
sudo ip link set $1 down
|
||||
|
||||
ARGS=$(ip link | awk 'BEGIN{ORS=" "};/can.*/{ if(/can.*:/){print $2};if(/alias/){print $2,"\n"} }' | grep $1: | awk '{print $1,$2}' | awk 'BEGIN{FS="_"}{print $1,$2}' | awk '{print $3,$2}')
|
||||
|
||||
echo $1 $ARGS $2 $3
|
||||
|
||||
sudo libicsneo_setbaud $ARGS $2 $3
|
||||
|
||||
sudo ip link set $1 up
|
||||
|
||||
echo $ARGS
|
||||
|
||||
Loading…
Reference in New Issue