Subversion Repositories HomeAutomation

Rev

Rev 2232 | Rev 2240 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1648 runge 1
 
2232 linlun 2
Sensor_ModuleNames    = [ "DS18x20", "FOST02", "BusVoltage", "SimpleDTMF", "DHT11", "VoltageCurrent", "ultrasonic" ];
2205 arune 3
SensorRf_ModuleNames    = [ "rfTransceive" ];
1648 runge 4
Sensor_Intervals      = function() { return [ 1, 5, 10, 15, 20 ]; };
5
Sensor_Aliases        = function() { return Module_GetAliasNames(Sensor_ModuleNames); };
6
Sensor_AvailableIds   = function() { return Module_GetAvailableIds(Sensor_ModuleNames); };
7
 
8
function Sensor_SetReportInterval(alias_name, interval)
9
{
10
    if (arguments.length < 2)
11
    {
1649 runge 12
        Log("\033[31mNot enough parameters given.\033[0m\n");
1648 runge 13
        return false;
14
    }
2091 runge 15
 
1648 runge 16
    var aliases_data = Module_ResolveAlias(alias_name, Sensor_ModuleNames);
17
    var found = false;
2091 runge 18
 
1648 runge 19
    for (var name in aliases_data)
20
    {
1765 linlun 21
        var variables = {"Time"     : interval };
1649 runge 22
        if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Report_Interval", variables))
23
        {
24
            Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n");
25
        }
26
        else
27
        {
28
            Log("\033[31mFailed to send command to " + name + ".\033[0m\n");
29
        }
2091 runge 30
 
1649 runge 31
        found = true;
32
    }
2091 runge 33
 
1649 runge 34
    if (!found)
35
    {
36
        Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n");
37
        return false;
38
    }
2091 runge 39
 
1649 runge 40
    return true;
41
}
42
Console_RegisterCommand(Sensor_SetReportInterval, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Sensor_Aliases(), Sensor_Intervals()); });
43
 
2091 runge 44
Sensor_OnNewPhonenumberFunctions = [];
2050 arune 45
 
46
function Sensor_RegisterToNewPhonenumber(alias_name, callback)
47
{
2091 runge 48
  if (!Sensor_OnNewPhonenumberFunctions[alias_name])
49
  {
50
    Sensor_OnNewPhonenumberFunctions[alias_name] = [];
51
  }
52
 
53
  Sensor_OnNewPhonenumberFunctions[alias_name].push(callback);
2050 arune 54
}
55
 
2207 arune 56
Sensor_OnDeviceStateChangeFunctions = [];
57
 
58
function Sensor_RegisterToDeviceStateChange(alias_name, callback)
59
{
60
  if (!Sensor_OnDeviceStateChangeFunctions[alias_name])
61
  {
62
    Sensor_OnDeviceStateChangeFunctions[alias_name] = [];
63
  }
64
 
65
  Sensor_OnDeviceStateChangeFunctions[alias_name].push(callback);
66
}
67
 
68
 
1649 runge 69
function Sensor_OnMessage(module_name, module_id, command, variables)
70
{
2091 runge 71
  if (in_array(Sensor_ModuleNames, module_name))
72
  {
73
    var aliases_data = Module_LookupAliases({
74
      "module_name" : module_name,
75
      "module_id"   : module_id,
76
      "group"       : false
77
    });
1807 linlun 78
 
2091 runge 79
    switch (command)
80
    {
81
      case "Phonenumber":
82
      {
83
        for (var alias_name in aliases_data)
84
        {
85
          var number = variables["Number"];
86
          var incommingCall = true;
2098 runge 87
          var checkName = true;
1649 runge 88
 
2098 runge 89
          Log("received from DTMF:\"" + number + "\"");
90
 
2122 runge 91
          if (variables["Number"].length >= 6)
2091 runge 92
          {
2092 runge 93
            /* A seems to mean it is an incomming call! */
94
            if (number.charAt(0) === 'A' || number.charAt(0) === 'D')
2091 runge 95
            {
2092 runge 96
              incommingCall = true;
2091 runge 97
 
98
              /* Remove leading A */
99
              number = number.substring(1);
100
            }
2092 runge 101
            else /* Outgoing call */
2091 runge 102
            {
2092 runge 103
              incommingCall = false;
2091 runge 104
            }
105
 
106
            /* A number can have a trailing C */
107
            var endIndex = number.indexOf('C');
108
 
109
            if (endIndex !== -1)
110
            {
111
              /* Remove trailing C */
112
              number = number.substring(0, endIndex);
113
            }
114
          }
115
          else if (number == "B00C")
116
          {
117
            /* Unknown number */
118
            number = "Unknown";
119
            incommingCall = true;
2098 runge 120
            checkName = false;
2091 runge 121
          }
122
          else if (number == "B10C")
123
          {
124
            /* Secret/protected number */
125
            number = "Protected";
126
            incommingCall = true;
2098 runge 127
            checkName = false;
2091 runge 128
          }
129
          else
130
          {
131
            Log("DTMF decoded number is to short, number: \"" + number + "\", length: " + number.length);
132
            return;
133
          }
2181 arune 134
 
135
          /* Adding area code prefix if needed */
136
          if (number.charAt(0) != '0' && checkName)
137
          {
138
            if (typeof sensorDefaultPhoneAreaCode === 'undefined')
139
            {
140
              Log("\033[31mOnlinePhonebook: please add sensorDefaultPhoneAreaCode = yourAreaCode to autostart.js, defaulting to 031\033[0m\n");
141
              number = "031" + number;
142
            }
143
            else
144
            {
145
                number = sensorDefaultPhoneAreaCode + number;
146
            }
147
          }
2091 runge 148
 
149
          /* Store number and direction in last values */
150
          var lastValue = {};
151
          var lastValueString = Storage_GetParameter("LastValues", alias_name);
152
 
153
          if (lastValueString)
154
          {
155
            lastValue = JSON.parse(lastValueString);
156
          }
157
 
158
          var timestamp = get_time();
159
 
160
          lastValue["Phonenumber"] = { "value" : number, "timestamp" : timestamp };
161
          lastValue["Direction"] = { "value" : incommingCall ? "in" : "out", "timestamp" : timestamp };
162
 
163
          Storage_SetParameter("LastValues", alias_name, JSON.stringify(lastValue));
164
 
165
 
166
          /* Store number in phone call history */
167
          var newValue = { "number" : number, "direction" : incommingCall ? "in" : "out", "module" : alias_name, "names" : [], "timestamp" : timestamp };
168
 
169
          Storage_SetParameter("PhoneCalls", timestamp, JSON.stringify(newValue));
170
 
171
 
172
          /* Log the number */
173
          Log("New number: " + number + ", direction: " + (incommingCall ? "in" : "out"));
2152 arune 174
 
2091 runge 175
          /* Lookup name */
2098 runge 176
          if (checkName)
177
          {
2181 arune 178
            Sensor_StoreNumberInPhonebook(number, timestamp);
2098 runge 179
          }
2091 runge 180
 
2181 arune 181
          var phonebookNumbers = Storage_GetJsonParamter("PhoneBook", number);
2152 arune 182
          if (!phonebookNumbers)
183
          {
184
            phonebookNumbers = [];
185
          }
186
 
2091 runge 187
          /* Call any potential subscribers */
188
          if (Sensor_OnNewPhonenumberFunctions[alias_name])
189
          {
190
            for (var n in Sensor_OnNewPhonenumberFunctions[alias_name])
191
            {
2152 arune 192
              /* Call callback with arguments alias, number, direction */
193
              Sensor_OnNewPhonenumberFunctions[alias_name][n](alias_name, number, incommingCall ? "in" : "out", phonebookNumbers);
2091 runge 194
            }
195
          }
196
        }
197
        break;
198
      }
199
      case "Voltage":
200
      case "Temperature_Celsius":
201
      {
202
        if ((module_name == "DS18x20") && (variables["Value"] == 85))
203
        {
204
          Log("\033[31mDS18x20: Temperature conversion error: " + module_name + ":" + module_id + ", SensorId=" + variables["SensorId"] + "\033[0m");
205
          break;
206
        }
207
      }
208
      case "Humidity_Percent":
2232 linlun 209
      case "Percent":
210
      case "Distance":
2091 runge 211
      {
212
        for (var alias_name in aliases_data)
213
        {
214
          if (aliases_data[alias_name]["specific"]["SensorId"] != variables["SensorId"])
215
          {
216
            continue;
217
          }
218
 
219
          var last_value = {};
220
          var last_value_string = Storage_GetParameter("LastValues", alias_name);
221
 
222
          if (last_value_string)
223
          {
224
            last_value = eval("(" + last_value_string + ")");
225
          }
226
 
227
          last_value[command] = { "value" : variables["Value"], "timestamp" : get_time() };
228
 
229
          Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
230
        }
231
 
232
        break;
233
      }
234
    }
235
  }
1649 runge 236
}
237
Module_RegisterToOnMessage("all", Sensor_OnMessage);
1899 linlun 238
 
2205 arune 239
function SensorRf_OnMessage(module_name, module_id, command, variables)
240
{
241
    if (in_array(SensorRf_ModuleNames, module_name))
242
    {
243
        var aliases_data = Module_LookupAliases({
244
        "module_name" : module_name,
245
        "module_id"   : module_id,
246
        "group"       : false   });
2237 linlun 247
 
2211 arune 248
        /* Must check sensor here in case no alias is stored the adress needs to be printed */
2205 arune 249
        var VikingSuccess = "NoVikingSensor";
2237 linlun 250
        var VikingSteakSuccess = "NoVikingSteakSensor";
2211 arune 251
        if (variables["Protocol"] == "Viking")
252
        {
253
            /*
254
                              ??? aaaaaaaa sttttttttttt hhhhhhhh cccccccc
255
            341731651126    0b100 11111001 000011001011 00101110 00110110   20.3 46%
256
            a = address, s = sign, t = temperature, h = humidity, c = crc
257
            */
258
            var data = variables["IRdata"];
259
            var crc = data&0xFF;
260
            var humidity = (data>>>8)&0xFF;
261
            var temp = (data>>>16)&0xFFF;
262
            var addr = rshift(data,28)&0xFF;
263
            var unknown = rshift(data,36)&0xF;
264
            var calccrc=crc8(rshift(data,8), 32);
265
 
266
            var sign = (temp>>>11)&1;
267
            temp = temp&0x7FF;
268
            if (sign > 0)
269
            {
270
                temp = -temp;
271
            }
272
            temp = temp/10;
273
 
274
            VikingSuccess = "VikingNotFound";
275
 
276
            if (unknown != 4)
277
            {
278
                Log("\033[33mWarning: VikingSensor, unknown part="+unknown+", data="+data+"\033[0m");
279
            }
2237 linlun 280
        } else if (variables["Protocol"] == "VikingSteak")
281
        {
282
            var data = variables["IRdata"];
283
            var addr = (data>>>4)&0xFF;
284
            var byte0 = rshift(data,32)&0xF;
285
            var byte1 = rshift(data,28)&0xF;
286
            var byte2 = rshift(data,24)&0xF;
287
            var temp = Math.round((((((byte1^byte2)<<8)+((byte0^byte1)<<4)+byte0^10)-122)*5)/9);
288
            VikingSteakSuccess = "VikingNotFound";
2211 arune 289
        }
290
 
2205 arune 291
        loopAliases:    /* Label to break nested */
292
        for (var alias_name in aliases_data)
293
        {
294
            if (aliases_data[alias_name]["specific"]["Channel"] == variables["Channel"] &&
295
                aliases_data[alias_name]["specific"]["Proto"] == variables["Protocol"])
296
            {
297
                switch (variables["Protocol"])
298
                {
299
                    case "Viking":
2207 arune 300
                    {   /* Add alias with these specifics: Channel=0,Proto=Viking,Address=<address of sensor> */
2205 arune 301
                        if (crc != calccrc)
302
                        {
303
                            Log("\033[31mError: VikingSensor, incorrect CRC, data="+data+", CRC="+crc+", calcCRC="+calccrc+"\033[0m");
304
                            break loopAliases;
305
                        }
306
                        if (addr == aliases_data[alias_name]["specific"]["Address"])
307
                        {
308
                            VikingSuccess = "VikingFound";
309
 
310
                            var last_value = {};
311
                            var last_value_string = Storage_GetParameter("LastValues", alias_name);
312
 
313
                            if (last_value_string)
314
                            {
315
                                last_value = eval("(" + last_value_string + ")");
316
                            }
317
 
318
                            var timestamp = get_time();
319
                            last_value["Temperature_Celsius"] = { "value" : temp.toString(), "timestamp" : timestamp };
2218 arune 320
                            if (humidity<101)
321
                            {
322
                                last_value["Humidity_Percent"] = { "value" : humidity.toString(), "timestamp" : timestamp };
323
                            }
2205 arune 324
 
325
                            Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
326
 
327
                            break loopAliases;
328
                        }
329
                        break;
330
                    }
2237 linlun 331
                    case "VikingSteak":
332
                    {   /* Add alias with these specifics: Channel=0,Proto=VikingSteak,Address=<address of sensor> */
333
                        /* if no Address is added to the alias, all vikingSteaksensors will match*/
334
                        if (aliases_data[alias_name]["specific"]["Address"] == undefined)
335
                        {
336
                            VikingSteakSuccess = "VikingFound";
337
                            var last_value = {};
338
                            var last_value_string = Storage_GetParameter("LastValues", alias_name);
339
 
340
                            if (last_value_string)
341
                            {
342
                                last_value = eval("(" + last_value_string + ")");
343
                            }
344
 
345
                            var timestamp = get_time();
346
                            last_value["Temperature_Celsius"] = { "value" : temp.toString(), "timestamp" : timestamp };
347
                            last_value["Address"] = { "value" : addr, "timestamp" : timestamp };
348
                            Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
349
                            break loopAliases;
350
                        }
351
                        else if (addr == aliases_data[alias_name]["specific"]["Address"])
352
                        {
353
                            VikingSteakSuccess = "VikingFound";
354
                            var last_value = {};
355
                            var last_value_string = Storage_GetParameter("LastValues", alias_name);
356
 
357
                            if (last_value_string)
358
                            {
359
                                last_value = eval("(" + last_value_string + ")");
360
                            }
361
 
362
                            var timestamp = get_time();
363
                            last_value["Temperature_Celsius"] = { "value" : temp.toString(), "timestamp" : timestamp };
364
                            last_value["Address"] = { "value" : addr, "timestamp" : timestamp };
365
                            Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
366
 
367
                            break loopAliases;
368
                        }
369
                        break;
370
                    }
2207 arune 371
                    case "Nexa2":
2211 arune 372
                    {   /* Add alias with these specifics: Channel=0,Proto=Nexa2,OnData=<data for on>,OffData=<data for off> */
2207 arune 373
                        var deviceStateCommand = "";
374
                        if (variables["IRdata"] == aliases_data[alias_name]["specific"]["OnData"] && variables["Status"] == "Pressed")
375
                        {
376
                            deviceStateCommand = "On";
377
                        }
378
                        else if (variables["IRdata"] == aliases_data[alias_name]["specific"]["OffData"] && variables["Status"] == "Pressed")
379
                        {
380
                            deviceStateCommand = "Off";
381
                        }
382
                        else
383
                        {
384
                            break;
385
                        }
386
 
387
                        var last_value = {};
388
                        var last_value_string = Storage_GetParameter("LastValues", alias_name);
389
 
390
                        if (last_value_string)
391
                        {
392
                            last_value = eval("(" + last_value_string + ")");
393
                        }
394
 
395
                        if (( typeof(last_value["State"]) == "undefined" ) ||
396
                            ( deviceStateCommand == "Off" && last_value["State"]["value"] == "On" ) ||
397
                            ( deviceStateCommand == "On" && last_value["State"]["value"] == "Off" ))
398
                        {
399
                            last_value["State"] = { "value" : deviceStateCommand, "timestamp" : get_time() };
400
 
401
                            Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
402
 
403
                            /* Call any potential subscribers */
404
                            if (Sensor_OnDeviceStateChangeFunctions[alias_name])
405
                            {
406
                                for (var n in Sensor_OnDeviceStateChangeFunctions[alias_name])
407
                                {
408
                                    /* Call callback with arguments alias, state */
409
                                    Sensor_OnDeviceStateChangeFunctions[alias_name][n](alias_name, deviceStateCommand);
410
                                }
411
                            }
412
                        }
413
                        break;
414
                    }
2205 arune 415
                }
416
            }
417
        }
418
        if (VikingSuccess == "VikingNotFound")
419
        {
420
            Log("Found unknown vikingsensor address="+addr+" temperature="+temp+" humidity="+humidity+" unknown="+unknown);
421
        }
2237 linlun 422
        if (VikingSteakSuccess == "VikingNotFound")
423
        {
424
            Log("Found unknown vikingSteaksensor address="+addr+" temperature="+temp);
425
        }
2205 arune 426
    }
427
}
428
Module_RegisterToOnMessage("all", SensorRf_OnMessage);
429
 
2091 runge 430
function Sensor_StoreNumberInPhonebook(number, timestamp)
1899 linlun 431
{
2152 arune 432
  var phonebookNumbers = Storage_GetJsonParamter("PhoneBook", number);
2091 runge 433
 
434
  if (!phonebookNumbers)
435
  {
436
    phonebookNumbers = [];
437
 
438
    url = "wap.eniro.se/query?search_word=" + number + "&what=mobwp";
439
    //Log("\033[31mURL: http://"+url+"\033[0m\n");
440
 
441
    Http_Request(url, function(socket_id, result, header, content_data)
442
    {
443
      //Log("\033[31mOnlinePhonebook-eniro: result was: " + result + "\033[0m\n");
444
      //Log("\033[31mOnlinePhonebook-eniro: content was: " + content_data + "\033[0m\n");
445
 
446
      if (result.indexOf("200 OK") != -1)
447
      {
448
 
449
        var lines = content_data.split("\n");
450
 
451
        var endString = "<anchor>Tillbaka<prev/></anchor>";
452
        var nameStartString = "<td class=\"hTd2\">";
453
        var nameEndString = "</table>";
454
 
455
        for (var n = 1; n < lines.length; n++)
456
        {
457
          var line = lines[n].trim("\n");
458
 
459
          if (line.indexOf(endString) != -1)
460
          {
461
            break;
462
          }
463
 
464
          if (line.indexOf(nameStartString) != -1)
465
          {
466
            line = lines[n + 1].trim("\n");
467
            splitted = line.split("b>");
468
 
469
            phonebookNumbers.push(splitted[1].substr(0, splitted[1].length - 2));
470
            break;
471
          }
472
        }
473
 
474
        //Log("\033[31mOnlinePhonebook: Line: " + lines[1] + "\033[0m\n");
475
        //Log("\033[31mOnlinePhonebook: Line: " + lines[2] + "\033[0m\n");
476
        //Log("\033[31mOnlinePhonebook: Line: " + lines[3] + "\033[0m\n");
477
        if (phonebookNumbers.length > 0)
478
        {
479
          Storage_SetJsonParameter("PhoneBook", number, phonebookNumbers);
480
 
481
          Sensor_UpdateNameInPhonecalls(timestamp, phonebookNumbers);
482
 
483
          Log("\033[31mOnlinePhonebook-eniro: Found: " + JSON.stringify(phonebookNumbers) + "\033[0m\n");
484
        }
485
      }
486
      else
487
      {
488
        Log("\033[31mOnlinePhonebook-eniro: Failed to do name lookup, result was: " + result + "\033[0m\n");
489
      }
490
 
2094 runge 491
      if (phonebookNumbers.length == 0)
2091 runge 492
      {
2094 runge 493
        if (typeof sensorRKSEEK_API !== 'undefined')
2091 runge 494
        {
2094 runge 495
          url = "rkseek.oblivioncreations.se/?client="+sensorRKSEEK_API+"&n=" + number + "&out=text";
496
          Log("\033[31mURL: http://"+url+"\033[0m\n");
2091 runge 497
 
2094 runge 498
          Http_Request(url, function(socket_id, result, header, content_data)
2091 runge 499
          {
2094 runge 500
            phonebookNumbers = [];
501
 
502
            if (result.indexOf("200 OK") != -1)
2091 runge 503
            {
2094 runge 504
              //Log("\033[31mOnlinePhonebook: result was: " + content_data + "\033[0m\n");
505
              var lines = content_data.split("\n");
506
              //Log("\033[31mOnlinePhonebook: Line: " + lines[1] + "\033[0m\n");
507
              //Log("\033[31mOnlinePhonebook: Line: " + lines[2] + "\033[0m\n");
508
              //Log("\033[31mOnlinePhonebook: Line: " + lines[3] + "\033[0m\n");
509
              if (lines[2].length > 0)
510
              {
511
                phonebookNumbers = [ lines[2] ]; // TODO Is this really correct?!
512
                Storage_SetJsonParameter("PhoneBook", number, phonebookNumbers);
513
 
514
                Sensor_UpdateNameInPhonecalls(timestamp, phonebookNumbers);
2152 arune 515
 
2094 runge 516
                Log("\033[31mOnlinePhonebook-rseek: Found: " + JSON.stringify(phonebookNumbers) + "\033[0m\n");
517
              }
2091 runge 518
            }
2094 runge 519
            else
520
            {
521
              Log("\033[31mOnlinePhonebook-rseek: Failed to do name lookup, result was: " + result + "\033[0m\n");
522
            }
523
          });
524
        }
2091 runge 525
      }
2094 runge 526
    });
2014 linlun 527
        /*
2091 runge 528
        Http_Request("wap.hitta.se/default.aspx?Who=" + number + "&Where=&PageAction=White",
1899 linlun 529
            function(socket_id, result, header, content_data) {
530
                var persons = new Array();
531
                if (result.indexOf("200 OK") != -1)
532
                {
533
                    var endString = "<anchor>Tillbaka<prev/></anchor>";
534
                    var nameStartString = " title=\"Link\">";
535
                    var nameEndString = "</a>";
2091 runge 536
 
1899 linlun 537
                    var lines = content_data.split("<br/>");
2091 runge 538
 
1899 linlun 539
                    for (var n = 1; n < lines.length; n++)
540
                    {
541
                        var line = lines[n].trim(" \n");
2091 runge 542
 
1899 linlun 543
                        if (line.indexOf(endString) != -1)
544
                        {
545
                            break;
546
                        }
547
                        var pos = line.indexOf(nameStartString + (persons.length+1) + ".");
2091 runge 548
 
1899 linlun 549
                        if (pos != -1)
550
                        {
551
                            pos += nameStartString.length + 2
552
                            persons[persons.length] = line.substr(pos, line.length-pos-nameEndString.length).html_entity_decode().replace("  ", " ");
553
                        }
554
                    }
555
                    if (persons.length > 0) {
556
                        Storage_SetJsonParameter("PhoneBook", number, persons);
2091 runge 557
 
1899 linlun 558
                        //CAll all listeners!
559
                        //....
2091 runge 560
 
1899 linlun 561
                        Log("\033[31mOnlinePhonebook: Found: " + JSON.stringify(persons) + "\033[0m\n");
562
                    }
563
                }
564
                else
565
                {
566
                    Log("\033[31mOnlinePhonebook: Failed to do name lookup, result was: " + result + "\033[0m\n");
2091 runge 567
                }
1899 linlun 568
            }
569
        );
2014 linlun 570
        */
2091 runge 571
 
572
  }
573
  else
574
  {
575
    //Log("Number already stored\n");
576
 
577
    Sensor_UpdateNameInPhonecalls(timestamp, phonebookNumbers);
578
  }
2152 arune 579
 
580
  return phonebookNumbers;
1899 linlun 581
}
582
Console_RegisterCommand(Sensor_StoreNumberInPhonebook, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args); });
583
 
2182 arune 584
function Sensor_StoreNumberInPhonebookManual(number, name)
585
{
586
    if (arguments.length < 2)
587
    {
588
        Log("\033[31mNot enough parameters given.\033[0m\n");
589
        return false;
590
    }
591
 
592
    var completename = arguments[1];
593
    for (var i=2; i<arguments.length; i++)
594
    {
595
        completename = completename+" "+arguments[i];
596
    }
597
 
598
    phonebookNumbers = [];
599
    phonebookNumbers.push(completename);
600
    Storage_SetJsonParameter("PhoneBook", number, phonebookNumbers);
601
}
602
Console_RegisterCommand(Sensor_StoreNumberInPhonebookManual, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args); });
603
 
2091 runge 604
function Sensor_UpdateNameInPhonecalls(timestamp, numbers)
605
{
606
  if (numbers.length > 0)
607
  {
608
    var lastValueString = Storage_GetParameter("PhoneCalls", timestamp);
1899 linlun 609
 
2091 runge 610
    if (lastValueString)
611
    {
612
      var lastValue = JSON.parse(lastValueString);
1899 linlun 613
 
2091 runge 614
      lastValue.names = numbers;
615
 
616
      Storage_SetParameter("PhoneCalls", timestamp, JSON.stringify(lastValue));
617
    }
618
  }
619
}
620
 
2232 linlun 621
function Sensor_SetUltrasonicMode(alias_name, BottomLimit, TopLimit, mode)
622
{
623
    if (arguments.length < 4)
624
    {
625
        Log("\033[31mNot enough parameters given.\033[0m\n");
626
        return false;
627
    }
628
 
629
    var aliases_data = Module_ResolveAlias(alias_name, Sensor_ModuleNames);
630
    var found = false;
631
 
632
    for (var name in aliases_data)
633
    {
634
        var variables = {   "0Percent"     : BottomLimit,
635
                    "100Percent"   : TopLimit,
636
                    "SensorMode"   : mode,
637
                    "SensorId"  : aliases_data[name]["specific"]["Channel"],
638
        };
639
        if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "UltrasonicConfig", variables))
640
        {
641
            Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n");
642
        }
643
        else
644
        {
645
            Log("\033[31mFailed to send command to " + name + ".\033[0m\n");
646
        }
647
 
648
        found = true;
649
    }
650
 
651
    if (!found)
652
    {
653
        Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n");
654
        return false;
655
    }
656
 
657
    return true;
658
}
659
Console_RegisterCommand(Sensor_SetUltrasonicMode, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Sensor_Aliases()); });