Hello every, I'm here again :)
Problem appears when the phone is disconnected and reconnected:
If I disconnect the phone while celliax is running i have this debug output:
Nenormalno! Marking this serial_device %s as dead, andif it is owne....
and this is good...
Now if I reconnect the phone, the kernel see it as /dev/ttyACM1 instead of /dev/ttyACM0 and this untill i kill asterisk.
I've modified your source (I like to try to understand C) asking to close celliax if serial is disconnected:
diff -ruN celliax/celliax_stuff/chan_celliax.c test2/celliax_stuff/chan_celliax.c
--- celliax/celliax_stuff/chan_celliax.c 2007-05-13 20:58:44.755633132 +0200
+++ test2/celliax_stuff/chan_celliax.c 2007-05-13 16:56:12.543829142 +0200
@@ -4405,7 +4405,7 @@
UNLOCKA(&p->controldev_lock);
if (p->owner)
ast_queue_control(p->owner, AST_CONTROL_HANGUP);
- return -1;
+ exit(1); ///MIO
}
if (option_debug > 90) {
@@ -6328,7 +6328,7 @@
UNLOCKA(&p->controldev_lock);
if (p->owner)
ast_queue_control(p->owner, AST_CONTROL_HANGUP);
- return -1;
+ exit(1); //MIO
}
if (option_debug > 10) {
int c;
Now when serial is disconnected asterisk stops, and reconnecting the phone the kernel loads it as /dev/ttyACM0 as usual.
I placed the rcscript for launching * into inittab, so * restarts and all come up again.
Answer is:
Is it possible to set a config entry to choose if user want * stops if serial goes down?
And does exit(1) clear all the memory used by celliax? Can I stop more gracefully? I'm a little scared of what i did :)
welcome in the c-programming
welcome in the c-programming world!!!
Yeah, you very right to be scared ;-)
In this way, you just kill the whole asterisk program, and exit without cleaning, de-initializing, etc (you just nuke it, worst than kill -9 )
Also, take note that a user can have more than one cellphone connected (multiple lines), and if just one goes down, the others continue to work.
Also, maybe the user does not use asterisk only for chan_celliax (the most of users), so they do not want to have asterisk to go down with chan_celliax.
The general idea is:
1) You do not disconnect the phone if you want to continue using chan_celliax ;-)
2) the phone does not disconnect himself (it would be a bug, or in the phone, or in the hardware, or in the driver, or in chan_celliax). If this happens, this has to be fixed.
3) if you do disconnect the phone, you unload the chan_celliax module from asterisk before the disconnection
Your modification (ok, also if it would exit in a cleaner way) would give problems to other user :(.
Is in my list to try to react to the serial disconnection in a more active way than just marking the interface as dead and forget, but I've not yet done it ;-).
I think a better reaction would be to close the serial port filedescriptor, and periodically checking if the serial port is available to be reopened, and when it is, open it and restart that chan_celliax channel.
I'll give it a try in a while...
@@ -2637,6 +2636,30 @@
@@ -2637,6 +2636,30 @@
}
}
}
+
+ if (p->controldevprotocol != PROTOCOL_NO_SERIAL && p->controldev_dead) {
+
+ /* init the serial port */
+ p->controldevfd = serial_init(p, p->controldevice_speed);
+ if (p->controldevfd < 1) {
+ DEBUGA_SERIAL("serial_init failed\n", CELLIAX_P_LOG);
+ } else {
+
+ /* config the phone/modem on the serial port */
+ res = serial_config(p);
+ if (res) {
+ DEBUGA_SERIAL("serial_config failed\n", CELLIAX_P_LOG);
+ close(p->controldevfd);
+ } else {
+
+ NOTICA("Wow, the serial port has come back! Let's see if it will work\n",
+ CELLIAX_P_LOG);
+ p->controldev_dead = 0;
+ }
+
+ }
+
+ }
#ifdef CELLIAX_SKYPE
if (p->skype) {
if (FD_ISSET(p->AsteriskHandlesAst.fdesc[0], &rfds)) {
@@ -4402,6 +4425,7 @@
("read 0 bytes!!! Nenormalno! Marking this serial_device %s as dead, andif it is owned by a channel, hanging up. Maybe the phone is stuck, switched off, power down or battery exhausted\n",
CELLIAX_P_LOG, p->controldevice_name);
p->controldev_dead = 1;
+ close(p->controldevfd);
UNLOCKA(&p->controldev_lock);
if (p->owner)
ast_queue_control(p->owner, AST_CONTROL_HANGUP);
This way seems to work. Please test it from svn (you *first* do a 'svn revert chan_celliax.c' from the celliax_stuff dir, *then* an 'svn update').
What it do is basically:
1) when the interface is marked as dead, close the filedescriptor (the last added codeline)
2) during the do_monitor loop (that checks if something happens on the 'alive' interfaces that are not into a call) check if an interface marked as dead can be made 'alive' again. If the interface come alive, unset the 'dead' flag for it (so do_monitor next loop begin to check again if something happens in that interface)
Thank you for pointing out this one!!!
BTW: with svn you don't need to have a second source directory to experiment with. You just make your changes, compile, etc...
When you "svn update" to the latest sources if there is a conflict with some of your modification, it will be signaled to you (and you probably will have to "svn revert" the unmergeable file), but in most of the cases, your changes will be merged (in your computer only) to the changes that come from svn.
Also, when you want to have a diff from the last svn source you get and the working copy you modified, just "svn diff".
I'm happy to help you, I
I'm happy to help you, I like this project!
I used test2 only to see exacly what I did using diff, no other use.
I'll try tomorrow night for new version (too mutch work today).
Today i was using celliax and I got a problem: my voip account was out of credit mwahahaha, all was working!!!
Don't forget to "make clean"
Don't forget to "make clean" from the asterisk-1.2.XX directory after the "svn update", because I just renamed a couple of files, and you'll have problems without a "make clean"
As you should already seen,
As you should already seen, it's perfect.
Just recompiled and now usb serial returns up as how it should be.
Haha, nice:
[NOTICE 2674 ][nicephone ][-1, 0, 0, 0] Wow, the serial port has come back! Let's see if it will work
... It works!