Modified: freeswitch/trunk/contrib/trixter/radio/morse.js (14815 => 14816)
--- freeswitch/trunk/contrib/trixter/radio/morse.js 2009-09-10 23:37:18 UTC (rev 14815)
+++ freeswitch/trunk/contrib/trixter/radio/morse.js 2009-09-11 01:17:01 UTC (rev 14816)
@@ -29,8 +29,8 @@
// supplied
//
// examples:
-// jsapi conference 123 morse code is great
-// jsapi uuid b0b05504-97be-11de-a116-611fa158f341 morse code is great
+// jsapi morse.js conference 123 CQ CQ CQ this is FreeSWITCH
+// jsapi morse.js uuid b0b05504-97be-11de-a116-611fa158f341 morse code is great
var cw_wpm=20;
var cw_freq=900; // in Hz
@@ -38,14 +38,16 @@
// you probably do not need to edit anything below here
-var cw_unit=parseInt(1000/cw_wpm);
+// international standard is 50 symbols per word - we need units in ms
+var cw_unit=parseInt(60000/(50*cw_wpm));
+
var DIT = "%("+cw_unit+","+cw_unit+","+cw_freq+");";
-var DAH = "%("+cw_unit*3+","+cw_unit*3+","+cw_freq+");";
+var DAH = "%("+cw_unit*3+","+cw_unit+","+cw_freq+");";
+var SYM_SPACE = "%(0,"+cw_unit*3+","+cw_freq+");";
+var WORD_SPACE = "%(0,"+cw_unit*7+","+cw_freq+");";
-// so far there are not any prosigns which are just made up from
-// the letters below, but the spacing needs to be adjusted
-// I also do not have the non-officially defined characters
+// I do not have the non-officially defined characters
var charCodes = new Array();
charCodes["a"]="._";
charCodes["b"]="_...";
@@ -92,6 +94,45 @@
}
+function makeMorse(c)
+{
+ var morseStr="";
+
+ if(c==" ") {
+ return WORD_SPACE;
+ }
+
+ if(typeof charCodes[c] == "undefined") {
+ console_log("DEBUG","Invalid character "+c+"\n");
+ return;
+ }
+
+ for(var j=0;j<charCodes[c].length;j++) {
+ if(charCodes[c][j] == ".") {
+ morseStr+=DIT;
+ } else {
+ morseStr+=DAH;
+ }
+ }
+
+ return morseStr;
+}
+
+
+function playMorse(command,target,message)
+{
+ var newStr="tone_stream://v="+cw_vol+";";
+ for(var i=0;i<message.length;i++) {
+ newStr+=makeMorse(message[i].toLowerCase());
+ if(i<(message.length-1) && message[i+1]!=" " && message[i]!=" ") {
+ newStr+=SYM_SPACE;
+ }
+ }
+ newStr+=WORD_SPACE;
+ apiExecute(command, target+newStr);
+}
+
+
if(typeof argv[2] == "undefined" || argv[2].length==0) {
usage();
}
@@ -112,22 +153,6 @@
}
-while(typeof argv[0] != "undefined") {
- var newStr="tone_stream://v="+cw_vol+";";
- for(var i=0;i<argv[0].length;i++) {
- for(var j=0;j<charCodes[argv[0][i]].length;j++) {
- if(charCodes[argv[0][i]][j] == ".") {
- newStr+=DIT;
- } else {
- newStr+=DAH;
- }
- }
- // symbol space
- newStr+="%(0,"+cw_unit*3+","+cw_freq+")";
- }
- // word space
- // we only do a cw_unit*4 here because we have a cw_unit*3 already
- newStr+="%(0,"+cw_unit*4+","+cw_freq+")";
- apiExecute(command, target+newStr);
- argv.shift();
+if(typeof argv[0] != "undefined") {
+ playMorse(command,target,argv.join(" "));
}