libera/#maemo/ Thursday, 2021-09-23

joergaiui not only the interfaces differ but also the payload data aka protocol? Then it doesn't make much sense integrating it all into one blob, no?01:35
joergI'd probably implement a device driver for the rs232-spi converter that exposes a /dev/SPIrs232 device interface, Sort of similar to /dev/ttyUSB which hides the USB part of a USB<->rs232 dongle01:39
MaxdamantusI think you can already use socat over a serial port, just using the `fd:` address type.05:23
Maxdamantussocat readline fd:42 42</dev/ttyS005:23
MaxdamantusYou'd obviously need to set the parameters beforehand.05:23
Maxdamantusactually, < will probably open it O_RDONLY, should use <>05:24
Maxdamantussocat readline fd:42 42<>/dev/ttyS005:24
MaxdamantusOh, nvm. socat already has specific tty support, but you're wanting to not use socat.05:26
ceenejoerg: i've also thought about that... even a fuse driver would help, but... I don't know, maybe that's the way to go07:45
ceeneMaxdamantus: yep, I need it to be provide a C api, which socat doesn't do, and I need it to be propietary (or written by my in which case I grant permissions to the company to use it without restricting them to the open source license of my choice)07:46
KotCzarny..aand another binary tool is being born07:48
KotCzarny:)07:48
ceeneyeah... I really don't know if I want to do any of this lol07:48
MaxdamantusIf it's just meant to be called from C, presumably what you mainly want is simply something like: int socat(int a_in, int a_out, int b_in, int b_out);07:49
MaxdamantusWhich should just be a few lines of `poll`, `read` and `write`.07:50
Maxdamantusor if you want to be fancy, `read` and `write` can be replaced with `sendfile` on Linux.07:50
Maxdamantusanything else is just setting up those fds.07:50
KotCzarnyhe needs it to access different devices, not only serial07:51
ceenewell, I thought about socat not because it writes from fileno A to fileno B, but because it understands how to open lots of different destinations: a TCP socket is not opened like a file which is not opened like a serial port -which needs baud speed-, etc07:51
MaxdamantusRight, and since it's a library, it's generally pretty easy to set up those devices.07:51
KotCzarnyi would split the interfaces and commands parts and make them communicate, even internally07:51
Maxdamantusint tty = open("/dev/ttyS0", O_RDWR); socat(tty, tty, 0, 1);07:52
ceeneMaxdamantus: it's not as easy as that, see above about the rs232-spi converter07:52
ceeneI need an interface that can translate something like write_register(fd, 0x10, 0x44)07:53
KotCzarnyall in all, not hard to write07:53
ceenethat would be an ioctl call to /dev/spidevice, but it will be a binary protocol sent to the ttyS0 device07:53
ceenewell, it's not that it is hard07:53
ceeneit is that I don't want to do it :D07:53
KotCzarnyjust needs to be thought well before writing anything07:53
KotCzarnymake it opensource so you can reuse it for future projects07:54
KotCzarnythat way at least you will have something useful from it07:54
ceeneyeah, thankfully I can opensource a lots of things I do for the company, they just need an exclusive license for them too07:55
MaxdamantusWhy are you actually avoiding socat anyway? Are you specifically trying to make this solution as a single binary thing instead of just telling people to run `socat readline exec:'./spiserial /dev/spidevX'`?07:59
ceene"telling people"08:00
ceenethere's no people in any of this08:00
ceenewhat would socat accomplish for me, if socat doesn't speak linux's spidev protocol?08:01
MaxdamantusIt solves the socat part of the issue.08:01
ceenespidev cannot be write() too08:01
MaxdamantusThe spi to RS232 part is a separate issue.08:01
MaxdamantusIt can if you write that `spiserial` program that talks to your RSR232 device over SPI.08:02
ceenesame final device two interfaces: /dev/spidev, /dev/ttyS0 with an RS232 converter in the middle08:02
ceeneboth of them require custom code that I cannot introduce inside socat because then I would have to release that as GPL and I can't do that08:03
MaxdamantusSo do it outside of socat and call it using `exec`.08:03
ceenewhy would I call socat if I've already done the hard thing outside?08:03
MaxdamantusYou're talking about reinventing socat.08:04
ceeneeither you didn't undertand or I didn't explained myself08:04
ceene>> [07:51:10] <ceene> well, I thought about socat not because it writes from fileno A to fileno B, but because it understands how to open lots of different destinations: a TCP socket is not opened like a file which is not opened like a serial port -which needs baud speed-, etc08:04
ceeneI'm talking about a thint that understand how to talk to my final destination chip, even if there are several ways to access it: spidev, rs232-spi08:05
ceenes/thint/thing/08:05
ceeneso the "socat" part is about "socat" knowing how to open different devices and how to configure them08:05
ceeneand also socat doesn't have a concept of "spi registers"08:06
MaxdamantusRight .. so are you intending to reimplement all of those TCP, TLS, SOCKS, etc destinations that socat has?08:06
ceene>> [15:57:07] <ceene> but it'll probably be a very simple thing with just a couple of controllers: generic open, serial port, tcp client and the propietary code we use for the rs232-spi converter08:07
ceeneso no, of course not08:07
MaxdamantusDunno. Just seems a bit weird. In general I'd expect someone creating software for a specific device to just create something that behaves like netcat.08:08
Maxdamantusie, talk to the device, expose the interface over stdio.08:08
Maxdamantusand then you can obviously use something like socat to expose that device over all the protocols that it supports.08:09
Maxdamantussocat stdio exec:'nc google.com 80'08:09
ceeneso you'd like socat stdio exec:'spidev-talker /dev/spidev0' for the spidev and stdio exec:'rs232-spi-talker /dev/ttyS0'08:10
MaxdamantusYes.08:11
MaxdamantusOtherwise it's just going to seem like a half-useful version of socat.08:11
Maxdamantuswhich also supports some obscure device.08:11
ceenewell, that is totally and absolutly the point: to support some obscure device08:12
ceeneand so, if I have to write spidev-talker that know show to interact with /dev/spidev008:12
MaxdamantusRight, so you can do that without reimplementing the socat functionality.08:12
ceeneand I also have to write rs232-spi-talker that knows how to interact with /dev/ttyS008:12
ceenewhy do I want socat for?08:12
ceenebut I already said I don't want to, and I won't reimplement socat functionality!08:13
MaxdamantusYour original example used readline.08:13
Maxdamantusso `socat readline exec:'spidev-talker /dev/spidev0'`08:13
Maxdamantusand then you get a readline interface over your device, instead of having to ^U when you make a typo.08:14
ceeneI... didn't used readline for any example, did I'?08:14
Maxdamantus01:55:17 < ceene> but I'm gonna try to use the same addressing as socat, so this socat's example should work in the end $ socat readline /dev/ttyS0,raw,echo=0,crlf08:15
ceeneI did, I see08:15
ceenemaybe that wasn't a good example, I don't really need readline nor any interactivity at all, the part I was referring to was the second destination: /dev/ttyS0,raw,echo=0,crlf08:16
MaxdamantusThe `stdio` target in socat is not actually very useful when used in combination with `exec`.08:16
Maxdamantussince `socat stdio exec:./foo` is just the same as `./foo`08:16
Maxdamantusit's only there so you can access all the other socat targets over stdio.08:17
MaxdamantusSo if you're just trying to access your device using stdio, you'll just run your program directly, no need for socat.08:20
Maxdamantus$ spidev-talker /dev/spidev008:20
ceenethat's the poing I was trying to make!08:20
ceeneand now, replace spidev-talker and rs232-spi-talker with a single "my-obscure-device-talker"08:21
ceenewhich, if we keep insisting on a stdio interface, should be able to do echo -e "r00 0x23\n r01 0x33\n r02 0x11" | my-obscure-device-talker [SPIDEV:/dev/spidev0 | tty:/dev/ttyS0,raw,b9600]08:23
MaxdamantusSGTM08:23
ceeneand there you have the "socat-like functionality" that definitely is not socat but has lots of resemblance to it and could be expanded later to TCP4:192.168.1.2:540008:23
MaxdamantusLooks more like netcat functionality, since it's just a single target talking over stdio.08:25
ceenebut netcat doesn't know how to configure ttyS0 devices, nor how to speak to spidev, nor anything at all really...08:25
ceeneand now forget about stdio completely and think in terms of write_reg8 write_reg16 write_reg32 write_reg6408:26
ceeneas many different spi devices cannot be written to arbitrary word lengths08:26
ceeneso, this interface https://github.com/agamez/libARTio/blob/main/io.h08:26
ceeneof which, this is the simplest implementation, which just calls open() and only supports generic read/write https://github.com/agamez/libARTio/blob/main/io_open.c08:28
ceeneso now I need an io_spidev.c driver that implements those {read,write}_register functions08:28
ceeneand after that, I would need an rs232-spi.c driver that would talk to the converter08:29
ceeneand that's it08:29
MaxdamantusHm, so if it's really about connecting two targets together that talk in terms of `write32(int r, u32 v), write16(int r, u16 v), write8(int r, u8 v), read32(int r), ...` commands, I guess that's not covered by socat.08:51
ceenecorrect08:51
ceenespi devices can't just be written whatever08:51
Maxdamantus(unless you serialise the commands into the form above, in which case both targets can again be connected by sharding stdio)08:51
MaxdamantusSure.08:52
ceenethey almost always need a precise number of bytes, that may not be equal for all the registers it exposes, and Chip Select pin must be pulled up/down in the precise moment08:52
ceeneso a spi device will may need write8(0, 0x23), write8(1, 0x66), write16(2, 0x1133), and all of that can't be replaced by write32(0, 0x23661133)08:54
ceeneand this would be the initial driver for /dev/spidev: https://github.com/agamez/libARTio/blob/main/io_spidev.c09:14

Generated by irclog2html.py 2.17.0 by Marius Gedminas - find it at https://mg.pov.lt/irclog2html/!