Reputation: 1323
Hi i wrote a user app that passes data to /dev/ttyS0
.. I used php to send the data to the user app then had an if else inside the user app then passes the new data to /dev/ttyS0
..
E.g.
PHP -> user app - > driver(/dev/ttyS0);
php pass "go up" to user app then user app then it does an if else for string comparison that when it's true passes the new data(eg.0xff) to the driver(dev/ttyS0);
I also wrote my very first char driver which reads and write.. this is the site that im following http://lwn.net/Kernel/LDD3/
Now the question is.. is it possible to open a driver inside a driver?.. I know it's very very wrong to do it.. but i want to make my own driver which does an if else comparison inside so no need for the user app so passing data would just be like this:
PHP - > mydriver(which translates the data like my user app does)..
Here's sample of my user app code..
int main(int argc,char *argv[])
{
unsigned char pCom[2][7]={{0xFF,0x01,0x00,0x08,0x00,0x3F,0x48},
{0xFF,0x01,0x00,0x10,0x00,0x3F,0x50}};
int fd;
int p;
fd=open("/dev/ttyS0",O_RDWR | O_NOCTTY | O_NDELAY);
if(fd<0) exit(1);
set_port(fd);
if(strcmp(argv[1], "go up")==0){
for(p=0; p<8; p++){
write(fd,pCom[0],8);
}
How can i modify my code so i can put in my char driver?.. eg. modify the ssize_t (*read)
or ssize_t (*write)
? or can i just write this directly inside module_init();
Can you show me sample of how can i do it?..
Thank you in advance..
Upvotes: 0
Views: 168
Reputation: 12176
Don't do that. As you yourself noted, it's not the way it's supposed to be done, and I can see no real benefits either:
Benefits:
Drawbacks:
On the other hand, you may want to create e.g. a fifo or a tcp socket so that the PHP application can easily communicate with your user application. Other option would be to code the if-else-code directly in PHP or as a library that could be called from PHP.
Upvotes: 1