added open flag indicator for FTDI

This commit is contained in:
2025-10-19 19:56:05 +02:00
parent bc15407cad
commit 65e2def501
3 changed files with 14 additions and 4 deletions

View File

@@ -232,10 +232,10 @@ func (f *FTDIFinder) scanPeripherals(ctx context.Context) error {
scanner := bufio.NewScanner(stdout)
for scanner.Scan() {
peripheralString := scanner.Text()
// The program output is like '0:1:2' where 0 is the location, 1 is the S/N and 2 is the name
// The program output is like '0:1:2:3' where 0 is the location, 1 is the S/N, 2 is the name and 3 is the open flag [O/C]
peripheralInfo := strings.Split(peripheralString, ":")
log.Trace().Str("file", "FTDIFinder").Str("scannedString", peripheralString).Str("peripheralName", peripheralInfo[2]).Str("peripheralSN", peripheralInfo[1]).Msg("new FTDI peripheral detected")
log.Trace().Str("file", "FTDIFinder").Str("scannedString", peripheralString).Str("peripheralOpenFlag", peripheralInfo[3]).Str("peripheralName", peripheralInfo[2]).Str("peripheralSN", peripheralInfo[1]).Msg("new FTDI peripheral detected")
// Convert the location to an integer
location, err := strconv.Atoi(peripheralInfo[0])
if err != nil {
@@ -246,6 +246,7 @@ func (f *FTDIFinder) scanPeripherals(ctx context.Context) error {
temporaryPeripherals[peripheralInfo[1]] = PeripheralInfo{
Name: peripheralInfo[2],
SerialNumber: peripheralInfo[1],
IsOpen: peripheralInfo[3] == "O",
ProtocolName: "FTDI",
}
@@ -253,7 +254,6 @@ func (f *FTDIFinder) scanPeripherals(ctx context.Context) error {
peripheral, registered := f.registeredPeripherals[peripheralInfo[1]]
if registered {
runtime.EventsEmit(ctx, string(PeripheralStatus), peripheral.info, "connecting")
time.Sleep(2 * time.Second)
err := peripheral.Connect(ctx, location)
if err != nil {
log.Err(err).Str("file", "FTDIFinder").Str("peripheralSN", peripheralInfo[1]).Msg("unable to connect the peripheral")

View File

@@ -20,6 +20,7 @@ type PeripheralInfo struct {
Name string `yaml:"name"` // Name of the peripheral
SerialNumber string `yaml:"sn"` // S/N of the peripheral
ProtocolName string `yaml:"protocol"` // Protocol name of the peripheral
IsOpen bool // Open flag for peripheral connection
Settings map[string]interface{} `yaml:"settings"` // Peripheral settings
}

View File

@@ -28,8 +28,17 @@ int main() {
for (int i = 0; i < numDevs; i++) {
if (devInfo[i].SerialNumber[0] != '\0') {
std::cout << i << ":" << devInfo[i].SerialNumber << ":" << devInfo[i].Description << std::endl;
std::cout << i << ":" << devInfo[i].SerialNumber << ":" << devInfo[i].Description << ":";
// Add information about the hardware open state
if (devInfo[i].Flags & FT_FLAGS_OPENED) {
std::cout << "O" << std::endl;
} else {
std::cout << "C" << std::endl;
}
}
}
free(devInfo);
}
}