Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1646 | runge | 1 | |
| 2 | Serial_ModuleName = "Serial"; |
||
| 3 | Serial_Aliases = function() { return Module_GetAliasNames([ Serial_ModuleName ]); }; |
||
| 4 | Serial_AvailableIds = function() { return Module_GetAvailableIds([ Serial_ModuleName ]); }; |
||
| 5 | |||
| 6 | function Serial_MessageAliasLookup(module_id, command, variables) |
||
| 7 | { |
||
| 8 | var aliases_data = {}; |
||
| 9 | |||
| 10 | aliases_data = Module_LookupAliases({ |
||
| 11 | "module_name" : Serial_ModuleName, |
||
| 12 | "module_id" : module_id |
||
| 13 | }); |
||
| 14 | |||
| 15 | return aliases_data; |
||
| 16 | } |
||
| 17 | Module_RegisterMessageAliasLookup(Serial_ModuleName, Serial_MessageAliasLookup); |
||
| 18 | |||
| 19 | function Serial_CreateAlias(alias_name, module_id, channel) |
||
| 20 | { |
||
| 21 | var alias_data = { |
||
| 22 | "group" : false, |
||
| 23 | "name" : alias_name, |
||
| 24 | "module_name" : Serial_ModuleName, |
||
| 25 | "module_id" : module_id |
||
| 26 | }; |
||
| 27 | |||
| 28 | return Storage_SetParameter("alias", alias_name, JSON.stringify(alias_data)); |
||
| 29 | } |
||
| 30 | Console_RegisterCommand(Serial_CreateAlias, function(args) { return Console_StandardAutocomplete(args, Serial_Aliases(), Serial_AvailableIds()); }); |
||
| 31 | |||
| 32 | |||
| 33 | function Serial_Configure(alias_name) |
||
| 34 | { |
||
| 35 | if (arguments.length < 1) |
||
| 36 | { |
||
| 37 | throw("Not enought parameters given"); |
||
| 38 | } |
||
| 39 | |||
| 40 | var result_text = ""; |
||
| 41 | var aliases_data = Module_ResolveAlias(alias_name, [ Serial_ModuleName ]); |
||
| 42 | |||
| 43 | for (var name in aliases_data) |
||
| 44 | { |
||
| 45 | var variables = { |
||
| 46 | "BaudRate" : "9600", |
||
| 47 | "PhysicalFormat" : "RS232", |
||
| 48 | "DataBits" : "8", |
||
| 49 | "StopBits" : "1", |
||
| 50 | "Parity" : "ParityNone" |
||
| 51 | }; |
||
| 52 | |||
| 53 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "SerialConfig", variables)) |
||
| 54 | { |
||
| 55 | result_text += "Configure sent successfully to " + name + "\n"; |
||
| 56 | } |
||
| 57 | else |
||
| 58 | { |
||
| 59 | result_text += "Configure failed to send to " + name + "\n"; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | if (result_text.length == 0) |
||
| 64 | { |
||
| 65 | result_text = "No aliases by the name " + alias_name + " were applicable to Configure."; |
||
| 66 | } |
||
| 67 | |||
| 68 | return result_text; |
||
| 69 | } |
||
| 70 | Console_RegisterCommand(Serial_Configure, function(args) { return Console_StandardAutocomplete(args, Serial_Aliases()); }); |
||
| 71 | |||
| 72 | function Serial_Send(alias_name) |
||
| 73 | { |
||
| 74 | if (arguments.length < 1) |
||
| 75 | { |
||
| 76 | throw("Not enought parameters given"); |
||
| 77 | } |
||
| 78 | |||
| 79 | var data = ""; |
||
| 80 | |||
| 81 | for (var n = 1; n < arguments.length; n++) |
||
| 82 | { |
||
| 83 | data += arguments[n] + " "; |
||
| 84 | } |
||
| 85 | |||
| 86 | data = data.trim(" ") + "\r"; |
||
| 87 | |||
| 88 | var result_text = ""; |
||
| 89 | var aliases_data = Module_ResolveAlias(alias_name, [ Serial_ModuleName ]); |
||
| 90 | |||
| 91 | for (var name in aliases_data) |
||
| 92 | { |
||
| 93 | var variables = { |
||
| 94 | "Text" : data |
||
| 95 | }; |
||
| 96 | |||
| 97 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "SerialData", variables)) |
||
| 98 | { |
||
| 99 | result_text += "Sent \"" + data + "\" successfully to " + name + "\n"; |
||
| 100 | } |
||
| 101 | else |
||
| 102 | { |
||
| 103 | result_text += "Send failed to send to " + name + "\n"; |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | if (result_text.length == 0) |
||
| 108 | { |
||
| 109 | result_text = "No aliases by the name " + alias_name + " were applicable to Send."; |
||
| 110 | } |
||
| 111 | |||
| 112 | return result_text; |
||
| 113 | } |
||
| 114 | Console_RegisterCommand(Serial_Send, function(args) { return Console_StandardAutocomplete(args, Serial_Aliases()); }); |
||
| 115 |