[英]Own RS232 device as linux filesystem device
Is there a way to expose own RS232 AVR device as Linux file system device eg /dev/avr_device
? 有没有办法将自己的RS232 AVR设备公开为Linux文件系统设备,例如
/dev/avr_device
? The program must be written as kernel space module or in user space? 该程序必须作为内核空间模块或在用户空间中编写? Is this possible to do by
libfuse
? libfuse
可以做到吗? Maybe should I use FIFO pipes as communication channel with device? 也许我应该使用FIFO管道作为与设备的通信通道?
To be able to mount a device, in which you have installed a linux filesystem, you need that device to be a block device , but a serial tty device is a char device , incompatible with that. 为了能够挂载安装了Linux文件系统的设备,您需要将该设备作为块设备 ,而串行tty设备是与之不兼容的char设备 。
To be able to solve that problem in the classical view of the system, you need to develop a block device driver, that attaches to that char device (the serial port) and uses it to control de block device emulation protocol, this means to convert the block number and block data into packets to be sent over the serial line to a receiver at the other side an implement the block device details of being some kind of storage device. 为了能够在系统的经典视图中解决该问题,您需要开发一个块设备驱动程序,该驱动程序附加到该char设备(串行端口)并使用它来控制de块设备仿真协议,这意味着要进行转换将块号和块数据打包成数据包,然后通过串行线发送到另一侧的接收器,以实现作为某种存储设备的块设备详细信息。 This can be done with some effort.... the problem is if using a slow serial line will be of interest to simulate any kind of storage.
这可以通过一些努力来完成。...问题是,如果使用慢速串行线来模拟任何类型的存储是否会引起人们的兴趣。
The advantage of the last approach is that you only have to simulate a block device and will be able to create any local filesystem available for linux. 最后一种方法的优势在于,您只需模拟一个块设备,就可以创建可用于linux的任何本地文件系统。
On a higher level, you can implement a filesystem type, which is a higher level abstraction (fuse allows you for this) but this makes that a more difficult problem, as you have to implement every filesystem primitives (and believe me, there are far more primitives to emulate a filesystem than a block device) to implement every remote primitive as a set of local primitives (this can be unfeasible for a single programmer only) 在更高级别上,您可以实现文件系统类型,这是更高级别的抽象(保险丝允许您这样做),但这使问题变得更加棘手,因为您必须实现每个文件系统原语(并且相信我,比块设备更多的用于模拟文件系统的原语),以将每个远程原语实现为一组本地原语(仅对于单个程序员而言这是不可行的)
This second approach fixes completely the functionality of the filesystem, and fixes completely the set of operations you can do to files to the implemented primitives you write. 第二种方法完全修复了文件系统的功能,并且完全修复了可以对文件执行的一组操作,这些操作都已写入您编写的已实现原语。 It is far more difficult and normally lacks uniformity with the rest of the system, so I should not recommend you to follow this approach.
这要困难得多,并且通常与系统的其余部分缺乏统一性,因此,我不建议您采用这种方法。
The second approach has only one advantage, and it is: as the filesystem uses high level primitives, these can be encoded more compactly into network messages and be more efficiently transmitted over the line, giving more speed for a slow connection. 第二种方法仅具有一个优点,它是:由于文件系统使用高级原语,因此可以将它们更紧凑地编码为网络消息,并可以更有效地通过线路传输,从而为慢速连接提供了更高的速度。 But at the cost of having to implement all the filesystem functionality, and loosing uniformity on the use of these kind of filesystems (you have to implement user access, security, caching of requests, etc).
但是,这是以必须实现所有文件系统功能以及在使用这类文件系统上失去统一性为代价的(您必须实现用户访问,安全性,请求缓存等)。
In the first approach, you have only to implement 4 or 5 primitives, and you get all the functionality of any filesystem that can be installed on a block device. 在第一种方法中,您只需要实现4个或5个原语,就可以获得可以安装在块设备上的任何文件系统的所有功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.