Subversion Repositories tpanel

Rev

Rev 92 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 92 Rev 93
Line 294... Line 294...
294
 
294
 
295
    if (mSocket)
295
    if (mSocket)
296
        mSocket->close();
296
        mSocket->close();
297
}
297
}
298
 
298
 
-
 
299
bool TAmxNet::reconnect()
-
 
300
{
-
 
301
    DECL_TRACER("TAmxNet::reconnect()");
-
 
302
 
-
 
303
    if (!mSocket || !__CommValid)
-
 
304
        return false;
-
 
305
 
-
 
306
    mSocket->close();
-
 
307
    initSend = false;
-
 
308
    ready = false;
-
 
309
    return true;
-
 
310
}
-
 
311
 
299
bool TAmxNet::isNetRun()
312
bool TAmxNet::isNetRun()
300
{
313
{
301
    return _netRunning;
314
    return _netRunning;
302
}
315
}
303
 
316
 
Line 334... Line 347...
334
 
347
 
335
    sendAllFuncNetwork(NSTATE_CONNECTING);
348
    sendAllFuncNetwork(NSTATE_CONNECTING);
336
 
349
 
337
    while (__CommValid && mSocket && isRunning())
350
    while (__CommValid && mSocket && isRunning())
338
    {
351
    {
-
 
352
        initSend = false;
-
 
353
        ready = false;
-
 
354
 
339
        if (__CommValid && mSocket && !mSocket->connect(TConfig::getController(), TConfig::getPort()))
355
        if (__CommValid && mSocket && !mSocket->connect(TConfig::getController(), TConfig::getPort()))
340
        {
356
        {
341
            MSG_DEBUG("Connection failed. Retrying ...");
357
            MSG_DEBUG("Connection failed. Retrying ...");
342
            sendAllFuncNetwork(NSTATE_OFFLINE);
358
            sendAllFuncNetwork(NSTATE_OFFLINE);
343
            std::this_thread::sleep_for(std::chrono::seconds(3));
359
            std::this_thread::sleep_for(std::chrono::seconds(mWaitTime));
-
 
360
            setWaitTime(WAIT_RESET);
344
            continue;
361
            continue;
345
        }
362
        }
346
        else if (!mSocket)
363
        else if (!mSocket)
347
            break;
364
            break;
348
 
365
 
349
        sendAllFuncNetwork(NSTATE_ONLINE);
366
        sendAllFuncNetwork(NSTATE_ONLINE);
350
        handle_connect();
367
        handle_connect();
351
        std::this_thread::sleep_for(std::chrono::seconds(3));
368
        std::this_thread::sleep_for(std::chrono::seconds(mWaitTime));
-
 
369
        setWaitTime(WAIT_RESET);
-
 
370
        MSG_INFO("Network will be reestablished ...");
352
    }
371
    }
353
 
372
 
354
    _netRunning = false;
373
    _netRunning = false;
355
}
374
}
356
 
375
 
Line 373... Line 392...
373
        if (!stopped_ && (killed || prg_stopped))
392
        if (!stopped_ && (killed || prg_stopped))
374
            stop();
393
            stop();
375
    }
394
    }
376
    catch (std::exception& e)
395
    catch (std::exception& e)
377
    {
396
    {
378
        sendAllFuncNetwork(NSTATE_CONNECTING);
-
 
379
        MSG_ERROR("Error: " << e.what());
397
        MSG_ERROR("Error: " << e.what());
380
 
398
 
381
        if (mSocket)
399
        if (mSocket)
382
            mSocket->close();
400
            mSocket->close();
383
    }
401
    }
384
    catch (TXceptNetwork& e)
402
    catch (TXceptComm& e)
385
    {
403
    {
386
        sendAllFuncNetwork(NSTATE_CONNECTING);
-
 
387
//        MSG_ERROR("Error: " << e.getMessage());
-
 
388
 
-
 
389
        if (mSocket)
404
        if (mSocket)
390
            mSocket->close();
405
            mSocket->close();
391
    }
406
    }
-
 
407
 
-
 
408
    sendAllFuncNetwork(NSTATE_CONNECTING);
-
 
409
    setWaitTime(WAIT_RECONNECT);
392
}
410
}
393
 
411
 
394
void TAmxNet::start_read()
412
void TAmxNet::start_read()
395
{
413
{
396
    DECL_TRACER("TAmxNet::start_read()");
414
    DECL_TRACER("TAmxNet::start_read()");
Line 411... Line 429...
411
        {
429
        {
412
            _message.append(" [RT_ID]");
430
            _message.append(" [RT_ID]");
413
            XCEPTCOMM(_message);
431
            XCEPTCOMM(_message);
414
        }
432
        }
415
        else
433
        else
-
 
434
        {
-
 
435
            setWaitTime(WAIT_RECONNECT);
416
            return;
436
            return;
-
 
437
        }
417
 
438
 
418
        if (mSocket->readAbsolut(buff_, 2) == 2)
439
        if (mSocket->readAbsolut(buff_, 2) == 2)
419
            handle_read(2, RT_LEN);
440
            handle_read(2, RT_LEN);
420
        else if (mSocket->isConnected())
441
        else if (mSocket->isConnected())
421
        {
442
        {
422
            _message.append(" [RT_LEN]");
443
            _message.append(" [RT_LEN]");
423
            XCEPTCOMM(_message);
444
            XCEPTCOMM(_message);
424
        }
445
        }
425
        else
446
        else
-
 
447
        {
-
 
448
            setWaitTime(WAIT_RECONNECT);
426
            return;
449
            return;
-
 
450
        }
427
 
451
 
428
        if (mSocket->readAbsolut(buff_, 1) == 1)
452
        if (mSocket->readAbsolut(buff_, 1) == 1)
429
            handle_read(1, RT_SEP1);
453
            handle_read(1, RT_SEP1);
430
        else if (mSocket->isConnected())
454
        else if (mSocket->isConnected())
431
        {
455
        {
432
            _message.append(" [RT_SEP1]");
456
            _message.append(" [RT_SEP1]");
433
            XCEPTCOMM(_message);
457
            XCEPTCOMM(_message);
434
        }
458
        }
435
        else
459
        else
-
 
460
        {
-
 
461
            setWaitTime(WAIT_RECONNECT);
436
            return;
462
            return;
-
 
463
        }
437
 
464
 
438
        if (mSocket->readAbsolut(buff_, 1) == 1)
465
        if (mSocket->readAbsolut(buff_, 1) == 1)
439
            handle_read(1, RT_TYPE);
466
            handle_read(1, RT_TYPE);
440
        else if (mSocket->isConnected())
467
        else if (mSocket->isConnected())
441
        {
468
        {
442
            _message.append(" [RT_TYPE]");
469
            _message.append(" [RT_TYPE]");
443
            XCEPTCOMM(_message);
470
            XCEPTCOMM(_message);
444
        }
471
        }
445
        else
472
        else
-
 
473
        {
-
 
474
            setWaitTime(WAIT_RECONNECT);
446
            return;
475
            return;
-
 
476
        }
447
 
477
 
448
        if (mSocket->readAbsolut(buff_, 2) == 2)
478
        if (mSocket->readAbsolut(buff_, 2) == 2)
449
            handle_read(2, RT_WORD1);
479
            handle_read(2, RT_WORD1);
450
        else if (mSocket->isConnected())
480
        else if (mSocket->isConnected())
451
        {
481
        {
452
            _message.append(" [RT_WORD1]");
482
            _message.append(" [RT_WORD1]");
453
            XCEPTCOMM(_message);
483
            XCEPTCOMM(_message);
454
        }
484
        }
455
        else
485
        else
-
 
486
        {
-
 
487
            setWaitTime(30);
456
            return;
488
            return;
-
 
489
        }
457
 
490
 
458
        if (mSocket->readAbsolut(buff_, 2) == 2)
491
        if (mSocket->readAbsolut(buff_, 2) == 2)
459
            handle_read(2, RT_DEVICE);
492
            handle_read(2, RT_DEVICE);
460
        else if (mSocket->isConnected())
493
        else if (mSocket->isConnected())
461
        {
494
        {
462
            _message.append(" [RT_DEVIVE]");
495
            _message.append(" [RT_DEVIVE]");
463
            XCEPTCOMM(_message);
496
            XCEPTCOMM(_message);
464
        }
497
        }
465
        else
498
        else
-
 
499
        {
-
 
500
            setWaitTime(WAIT_RECONNECT);
466
            return;
501
            return;
-
 
502
        }
467
 
503
 
468
        if (mSocket->readAbsolut(buff_, 2) == 2)
504
        if (mSocket->readAbsolut(buff_, 2) == 2)
469
            handle_read(2, RT_WORD2);
505
            handle_read(2, RT_WORD2);
470
        else if (mSocket->isConnected())
506
        else if (mSocket->isConnected())
471
        {
507
        {
472
            _message.append(" [RT_WORD2]");
508
            _message.append(" [RT_WORD2]");
473
            XCEPTCOMM(_message);
509
            XCEPTCOMM(_message);
474
        }
510
        }
475
        else
511
        else
-
 
512
        {
-
 
513
            setWaitTime(WAIT_RECONNECT);
476
            return;
514
            return;
-
 
515
        }
477
 
516
 
478
        if (mSocket->readAbsolut(buff_, 2) == 2)
517
        if (mSocket->readAbsolut(buff_, 2) == 2)
479
            handle_read(2, RT_WORD3);
518
            handle_read(2, RT_WORD3);
480
        else if (mSocket->isConnected())
519
        else if (mSocket->isConnected())
481
        {
520
        {
482
            _message.append(" [RT_WORD3]");
521
            _message.append(" [RT_WORD3]");
483
            XCEPTCOMM(_message);
522
            XCEPTCOMM(_message);
484
        }
523
        }
485
        else
524
        else
-
 
525
        {
-
 
526
            setWaitTime(WAIT_RECONNECT);
486
            return;
527
            return;
-
 
528
        }
487
 
529
 
488
        if (mSocket->readAbsolut(buff_, 2) == 2)
530
        if (mSocket->readAbsolut(buff_, 2) == 2)
489
            handle_read(2, RT_WORD4);
531
            handle_read(2, RT_WORD4);
490
        else if (mSocket->isConnected())
532
        else if (mSocket->isConnected())
491
        {
533
        {
492
            _message.append(" [RT_WORD4]");
534
            _message.append(" [RT_WORD4]");
493
            XCEPTCOMM(_message);
535
            XCEPTCOMM(_message);
494
        }
536
        }
495
        else
537
        else
-
 
538
        {
-
 
539
            setWaitTime(WAIT_RECONNECT);
496
            return;
540
            return;
-
 
541
        }
497
 
542
 
498
        if (mSocket->readAbsolut(buff_, 2) == 2)
543
        if (mSocket->readAbsolut(buff_, 2) == 2)
499
            handle_read(2, RT_WORD5);
544
            handle_read(2, RT_WORD5);
500
        else if (mSocket->isConnected())
545
        else if (mSocket->isConnected())
501
        {
546
        {
502
            _message.append(" [RT_WORD5]");
547
            _message.append(" [RT_WORD5]");
503
            XCEPTCOMM(_message);
548
            XCEPTCOMM(_message);
504
        }
549
        }
505
        else
550
        else
-
 
551
        {
-
 
552
            setWaitTime(WAIT_RECONNECT);
506
            return;
553
            return;
-
 
554
        }
507
 
555
 
508
        if (mSocket->readAbsolut(buff_, 1) == 1)
556
        if (mSocket->readAbsolut(buff_, 1) == 1)
509
            handle_read(1, RT_SEP2);
557
            handle_read(1, RT_SEP2);
510
        else if (mSocket->isConnected())
558
        else if (mSocket->isConnected())
511
        {
559
        {
512
            _message.append(" [RT_SEP2]");
560
            _message.append(" [RT_SEP2]");
513
            XCEPTCOMM(_message);
561
            XCEPTCOMM(_message);
514
        }
562
        }
515
        else
563
        else
-
 
564
        {
-
 
565
            setWaitTime(WAIT_RECONNECT);
516
            return;
566
            return;
-
 
567
        }
517
 
568
 
518
        if (mSocket->readAbsolut(buff_, 2) == 2)
569
        if (mSocket->readAbsolut(buff_, 2) == 2)
519
            handle_read(2, RT_COUNT);
570
            handle_read(2, RT_COUNT);
520
        else if (mSocket->isConnected())
571
        else if (mSocket->isConnected())
521
        {
572
        {
522
            _message.append(" [RT_COUNT]");
573
            _message.append(" [RT_COUNT]");
523
            XCEPTCOMM(_message);
574
            XCEPTCOMM(_message);
524
        }
575
        }
525
        else
576
        else
-
 
577
        {
-
 
578
            setWaitTime(WAIT_RECONNECT);
526
            return;
579
            return;
-
 
580
        }
527
 
581
 
528
        if (mSocket->readAbsolut(buff_, 2) == 2)
582
        if (mSocket->readAbsolut(buff_, 2) == 2)
529
            handle_read(2, RT_MC);
583
            handle_read(2, RT_MC);
530
        else if (mSocket->isConnected())
584
        else if (mSocket->isConnected())
531
        {
585
        {
532
            _message.append(" [RT_MC]");
586
            _message.append(" [RT_MC]");
533
            XCEPTCOMM(_message);
587
            XCEPTCOMM(_message);
534
        }
588
        }
535
        else
589
        else
-
 
590
        {
-
 
591
            setWaitTime(WAIT_RECONNECT);
536
            return;
592
            return;
-
 
593
        }
537
 
594
 
538
        // Calculate the length of the data block. This is the rest of the total length
595
        // Calculate the length of the data block. This is the rest of the total length
539
        size_t len = (comm.hlen + 3) - 0x0015;
596
        size_t len = (comm.hlen + 3) - 0x0015;
540
 
597
 
541
        if (mSocket->isConnected() && len > BUF_SIZE)
598
        if (mSocket->isConnected() && len > BUF_SIZE)
542
        {
599
        {
543
            _message = "Length to read is " + to_string(len) + " bytes, but the buffer is only " + to_string(BUF_SIZE) + " bytes!";
600
            _message = "Length to read is " + to_string(len) + " bytes, but the buffer is only " + to_string(BUF_SIZE) + " bytes!";
544
            XCEPTCOMM(_message);
601
            XCEPTCOMM(_message);
545
        }
602
        }
546
        else if (!mSocket->isConnected())
603
        else if (!mSocket->isConnected())
-
 
604
        {
-
 
605
            setWaitTime(WAIT_RECONNECT);
547
            return;
606
            return;
-
 
607
        }
548
 
608
 
549
        if (mSocket->readAbsolut(buff_, len) == len)
609
        if (mSocket->readAbsolut(buff_, len) == len)
550
            handle_read(len, RT_DATA);
610
            handle_read(len, RT_DATA);
551
        else if (mSocket->isConnected())
611
        else if (mSocket->isConnected())
552
        {
612
        {
Line 554... Line 614...
554
            XCEPTCOMM(_message);
614
            XCEPTCOMM(_message);
555
        }
615
        }
556
    }
616
    }
557
    catch (TXceptNetwork& e)
617
    catch (TXceptNetwork& e)
558
    {
618
    {
559
//        MSG_ERROR(e.getMessage());
619
        setWaitTime(WAIT_RECONNECT);
560
    }
620
    }
561
}
621
}
562
 
622
 
563
void TAmxNet::handle_read(size_t n, R_TOKEN tk)
623
void TAmxNet::handle_read(size_t n, R_TOKEN tk)
564
{
624
{
Line 622... Line 682...
622
 
682
 
623
        case RT_DATA:
683
        case RT_DATA:
624
            if (protError || !isRunning())
684
            if (protError || !isRunning())
625
                break;
685
                break;
626
 
686
 
627
            MSG_TRACE("Received message type: 0x" << std::setw(4) << std::setfill('0') << std::hex << comm.MC);
687
            MSG_DEBUG("Received message type: 0x" << std::setw(4) << std::setfill('0') << std::hex << comm.MC);
628
 
688
 
629
            switch (comm.MC)
689
            switch (comm.MC)
630
            {
690
            {
631
                case 0x0001:    // ACK
691
                case 0x0001:    // ACK
632
                case 0x0002:    // NAK
692
                case 0x0002:    // NAK
Line 914... Line 974...
914
                    else
974
                    else
915
                        break;
975
                        break;
916
 
976
 
917
                    sendCommand(s);
977
                    sendCommand(s);
918
 
978
 
919
                    MSG_TRACE("S/N: " << comm.data.srDeviceInfo.serial << " | " << comm.data.srDeviceInfo.info);
979
                    MSG_DEBUG("S/N: " << comm.data.srDeviceInfo.serial << " | " << comm.data.srDeviceInfo.info);
920
                break;
980
                break;
921
 
981
 
922
                case 0x00a1:    // request status
982
                case 0x00a1:    // request status
923
                    reqDevStatus = makeWord(buff_[0], buff_[1]);
983
                    reqDevStatus = makeWord(buff_[0], buff_[1]);
924
                    comm.checksum = buff_[2];
984
                    comm.checksum = buff_[2];
Line 1113... Line 1173...
1113
            com.data.channel.device = com.device2;
1173
            com.data.channel.device = com.device2;
1114
            com.data.channel.port = s.port;
1174
            com.data.channel.port = s.port;
1115
            com.data.channel.system = com.system;
1175
            com.data.channel.system = com.system;
1116
            com.data.channel.channel = s.channel;
1176
            com.data.channel.channel = s.channel;
1117
            com.hlen = 0x0016 - 0x0003 + sizeof(ANET_CHANNEL);
1177
            com.hlen = 0x0016 - 0x0003 + sizeof(ANET_CHANNEL);
-
 
1178
            MSG_DEBUG("SEND: BUTTON PUSH-" << s.channel << ":" << s.port << ":" << com.device2);
1118
            comStack.push_back(com);
1179
            comStack.push_back(com);
1119
            mSendReady = true;
1180
            mSendReady = true;
1120
        break;
1181
        break;
1121
 
1182
 
1122
        case 0x0085:        // release button
1183
        case 0x0085:        // release button
1123
            com.data.channel.device = com.device2;
1184
            com.data.channel.device = com.device2;
1124
            com.data.channel.port = s.port;
1185
            com.data.channel.port = s.port;
1125
            com.data.channel.system = com.system;
1186
            com.data.channel.system = com.system;
1126
            com.data.channel.channel = s.channel;
1187
            com.data.channel.channel = s.channel;
1127
            com.hlen = 0x0016 - 0x0003 + sizeof(ANET_CHANNEL);
1188
            com.hlen = 0x0016 - 0x0003 + sizeof(ANET_CHANNEL);
-
 
1189
            MSG_DEBUG("SEND: BUTTON RELEASE-" << s.channel << ":" << s.port << ":" << com.device2);
1128
            comStack.push_back(com);
1190
            comStack.push_back(com);
1129
            mSendReady = true;
1191
            mSendReady = true;
1130
        break;
1192
        break;
1131
 
1193
 
1132
        case 0x0086:    // output channel on
1194
        case 0x0086:    // output channel on
Line 1134... Line 1196...
1134
            com.data.channel.device = com.device2;
1196
            com.data.channel.device = com.device2;
1135
            com.data.channel.port = s.port;
1197
            com.data.channel.port = s.port;
1136
            com.data.channel.system = com.system;
1198
            com.data.channel.system = com.system;
1137
            com.data.channel.channel = s.channel;
1199
            com.data.channel.channel = s.channel;
1138
            com.hlen = 0x0016 - 0x0003 + sizeof(ANET_CHANNEL);
1200
            com.hlen = 0x0016 - 0x0003 + sizeof(ANET_CHANNEL);
-
 
1201
            MSG_DEBUG("SEND: CHANNEL ON-" << s.channel << ":" << s.port << ":" << com.device2);
1139
            comStack.push_back(com);
1202
            comStack.push_back(com);
1140
            mSendReady = true;
1203
            mSendReady = true;
1141
        break;
1204
        break;
1142
 
1205
 
1143
        case 0x0087:    // output channel off
1206
        case 0x0087:    // output channel off
Line 1145... Line 1208...
1145
            com.data.channel.device = com.device2;
1208
            com.data.channel.device = com.device2;
1146
            com.data.channel.port = s.port;
1209
            com.data.channel.port = s.port;
1147
            com.data.channel.system = com.system;
1210
            com.data.channel.system = com.system;
1148
            com.data.channel.channel = s.channel;
1211
            com.data.channel.channel = s.channel;
1149
            com.hlen = 0x0016 - 0x0003 + sizeof(ANET_CHANNEL);
1212
            com.hlen = 0x0016 - 0x0003 + sizeof(ANET_CHANNEL);
-
 
1213
            MSG_DEBUG("SEND: CHANNEL OFF-" << s.channel << ":" << s.port << ":" << com.device2);
1150
            comStack.push_back(com);
1214
            comStack.push_back(com);
1151
            mSendReady = true;
1215
            mSendReady = true;
1152
        break;
1216
        break;
1153
 
1217
 
1154
        case 0x008a:        // level value changed
1218
        case 0x008a:        // level value changed
Line 1157... Line 1221...
1157
            com.data.message_value.system = com.system;
1221
            com.data.message_value.system = com.system;
1158
            com.data.message_value.value = s.level;
1222
            com.data.message_value.value = s.level;
1159
            com.data.message_value.type = 0x20;     // unsigned integer
1223
            com.data.message_value.type = 0x20;     // unsigned integer
1160
            com.data.message_value.content.integer = s.value;
1224
            com.data.message_value.content.integer = s.value;
1161
            com.hlen = 0x0016 - 0x0003 + 11;
1225
            com.hlen = 0x0016 - 0x0003 + 11;
-
 
1226
            MSG_DEBUG("SEND: LEVEL-" << s.value << "," << s.level << ":" << s.port << ":" << com.device2);
1162
            comStack.push_back(com);
1227
            comStack.push_back(com);
1163
            mSendReady = true;
1228
            mSendReady = true;
1164
        break;
1229
        break;
1165
 
1230
 
1166
        case 0x008b:        // string command
1231
        case 0x008b:        // string command
Line 1176... Line 1241...
1176
                len = s.msg.length();
1241
                len = s.msg.length();
1177
 
1242
 
1178
            com.data.message_string.length = len;
1243
            com.data.message_string.length = len;
1179
            strncpy((char *)&com.data.message_string.content[0], s.msg.c_str(), len);
1244
            strncpy((char *)&com.data.message_string.content[0], s.msg.c_str(), len);
1180
            com.hlen = 0x0016 - 3 + 9 + len;
1245
            com.hlen = 0x0016 - 3 + 9 + len;
-
 
1246
            MSG_DEBUG("SEND: STRING-'" << s.msg << "'," << s.port << ":" << com.device2);
1181
            comStack.push_back(com);
1247
            comStack.push_back(com);
1182
            mSendReady = true;
1248
            mSendReady = true;
1183
        break;
1249
        break;
1184
 
1250
 
1185
        case 0x008d:    // Custom event
1251
        case 0x008d:    // Custom event
Line 1383... Line 1449...
1383
        s.dtype = 0;                // ftype --> function type
1449
        s.dtype = 0;                // ftype --> function type
1384
        s.type = 0x0001;            // function
1450
        s.type = 0x0001;            // function
1385
        s.value1 = 0;               // 1st data byte 0x00
1451
        s.value1 = 0;               // 1st data byte 0x00
1386
        s.value2 = 0x10;            // 2nd data byte 0x10
1452
        s.value2 = 0x10;            // 2nd data byte 0x10
1387
        string f((char *)&ft.data);
1453
        string f((char *)&ft.data);
1388
        MSG_TRACE("0x0000/0x0105: Directory " << f << " exist?");
1454
        MSG_DEBUG("0x0000/0x0105: Directory " << f << " exist?");
1389
        string prjPath = TConfig::getProjectPath();
1455
        string prjPath = TConfig::getProjectPath();
1390
        string newPath;
1456
        string newPath;
1391
        dir::TDirectory dir;
1457
        dir::TDirectory dir;
1392
 
1458
 
1393
        if (f.compare(0, 8, "AMXPanel") == 0)
1459
        if (f.compare(0, 8, "AMXPanel") == 0)
Line 1460... Line 1526...
1460
 
1526
 
1461
            if (dr.isFile(realPath))
1527
            if (dr.isFile(realPath))
1462
                len = dr.getFileSize(realPath);
1528
                len = dr.getFileSize(realPath);
1463
        }
1529
        }
1464
 
1530
 
1465
        MSG_TRACE("0x0000/0x0100: Request directory " << fname);
1531
        MSG_DEBUG("0x0000/0x0100: Request directory " << fname);
1466
        snprintf((char *)&ftr.data.filetransfer.data[0], sizeof(ftr.data.filetransfer.data), "Syncing %d files ...", ftransfer.maxFiles);
1532
        snprintf((char *)&ftr.data.filetransfer.data[0], sizeof(ftr.data.filetransfer.data), "Syncing %d files ...", ftransfer.maxFiles);
1467
 
1533
 
1468
        if (callback)
1534
        if (callback)
1469
            callback(ftr);
1535
            callback(ftr);
1470
        else
1536
        else
Line 1517... Line 1583...
1517
            sendCommand(s);
1583
            sendCommand(s);
1518
        }
1584
        }
1519
    }
1585
    }
1520
    else if (ft.ftype == 4 && ft.function == 0x0100)    // Have more files to send.
1586
    else if (ft.ftype == 4 && ft.function == 0x0100)    // Have more files to send.
1521
    {
1587
    {
1522
        MSG_TRACE("0x0004/0x0100: Have more files to send.");
1588
        MSG_DEBUG("0x0004/0x0100: Have more files to send.");
1523
        s.channel = 0;
1589
        s.channel = 0;
1524
        s.level = 0;
1590
        s.level = 0;
1525
        s.port = 0;
1591
        s.port = 0;
1526
        s.value = 0;
1592
        s.value = 0;
1527
        s.MC = 0x0204;
1593
        s.MC = 0x0204;
Line 1580... Line 1646...
1580
            {
1646
            {
1581
                MSG_INFO("Writing file: " << rcvFileName);
1647
                MSG_INFO("Writing file: " << rcvFileName);
1582
            }
1648
            }
1583
        }
1649
        }
1584
 
1650
 
1585
        MSG_TRACE("0x0004/0x0102: Controller will send file " << rcvFileName);
1651
        MSG_DEBUG("0x0004/0x0102: Controller will send file " << rcvFileName);
1586
 
1652
 
1587
        ftransfer.actFileNum++;
1653
        ftransfer.actFileNum++;
1588
        ftransfer.lengthFile = ft.unk;
1654
        ftransfer.lengthFile = ft.unk;
1589
 
1655
 
1590
        if (ftransfer.actFileNum > ftransfer.maxFiles)
1656
        if (ftransfer.actFileNum > ftransfer.maxFiles)
Line 1633... Line 1699...
1633
        size_t pos = 0;
1699
        size_t pos = 0;
1634
 
1700
 
1635
        if ((pos = f.find("AMXPanel/")) == string::npos)
1701
        if ((pos = f.find("AMXPanel/")) == string::npos)
1636
            pos = f.find("__system/");
1702
            pos = f.find("__system/");
1637
 
1703
 
1638
        MSG_TRACE("0x0000/0x0104: Delete file " << f);
1704
        MSG_DEBUG("0x0000/0x0104: Delete file " << f);
1639
 
1705
 
1640
        if (pos != string::npos)
1706
        if (pos != string::npos)
1641
            f = TConfig::getProjectPath() + "/" + f.substr(pos + 9);
1707
            f = TConfig::getProjectPath() + "/" + f.substr(pos + 9);
1642
        else
1708
        else
1643
            f = TConfig::getProjectPath() + "/" + f;
1709
            f = TConfig::getProjectPath() + "/" + f;
Line 1689... Line 1755...
1689
    {
1755
    {
1690
        string f((char*)&ft.data);
1756
        string f((char*)&ft.data);
1691
        size_t pos;
1757
        size_t pos;
1692
        len = 0;
1758
        len = 0;
1693
        sndFileName.assign(TConfig::getProjectPath());
1759
        sndFileName.assign(TConfig::getProjectPath());
1694
        MSG_TRACE("0x0004/0x0104: Request file " << f);
1760
        MSG_DEBUG("0x0004/0x0104: Request file " << f);
1695
 
1761
 
1696
        if (f.find("AMXPanel") != string::npos)
1762
        if (f.find("AMXPanel") != string::npos)
1697
        {
1763
        {
1698
            pos = f.find_first_of("/");
1764
            pos = f.find_first_of("/");
1699
            sndFileName.append(f.substr(pos));
1765
            sndFileName.append(f.substr(pos));
Line 1716... Line 1782...
1716
        else if (sndFileName.find("/version.xma") > 0)
1782
        else if (sndFileName.find("/version.xma") > 0)
1717
            len = 0x0015;
1783
            len = 0x0015;
1718
        else
1784
        else
1719
            len = 0;
1785
            len = 0;
1720
 
1786
 
1721
        MSG_TRACE("0x0004/0x0104: (" << len << ") File: " << sndFileName);
1787
        MSG_DEBUG("0x0004/0x0104: (" << len << ") File: " << sndFileName);
1722
 
1788
 
1723
        s.channel = 0;
1789
        s.channel = 0;
1724
        s.level = 0;
1790
        s.level = 0;
1725
        s.port = 0;
1791
        s.port = 0;
1726
        s.value = 0;
1792
        s.value = 0;
Line 1731... Line 1797...
1731
        s.value2 = 0x00001388;      // ID for device when sending a file.
1797
        s.value2 = 0x00001388;      // ID for device when sending a file.
1732
        sendCommand(s);
1798
        sendCommand(s);
1733
    }
1799
    }
1734
    else if (ft.ftype == 4 && ft.function == 0x0106)    // Controller is ready for receiving file
1800
    else if (ft.ftype == 4 && ft.function == 0x0106)    // Controller is ready for receiving file
1735
    {
1801
    {
1736
        MSG_TRACE("0x0004/0x0106: Controller is ready for receiving file.");
1802
        MSG_DEBUG("0x0004/0x0106: Controller is ready for receiving file.");
1737
 
1803
 
1738
        if (!access(sndFileName.c_str(), R_OK))
1804
        if (!access(sndFileName.c_str(), R_OK))
1739
        {
1805
        {
1740
            struct stat st;
1806
            struct stat st;
1741
            stat(sndFileName.c_str(), &st);
1807
            stat(sndFileName.c_str(), &st);
Line 1790... Line 1856...
1790
        s.value1 = len;             // length of content to send
1856
        s.value1 = len;             // length of content to send
1791
        sendCommand(s);
1857
        sendCommand(s);
1792
    }
1858
    }
1793
    else if (ft.ftype == 4 && ft.function == 0x0002)    // request next part of file
1859
    else if (ft.ftype == 4 && ft.function == 0x0002)    // request next part of file
1794
    {
1860
    {
1795
        MSG_TRACE("0x0004/0x0002: Request next part of file.");
1861
        MSG_DEBUG("0x0004/0x0002: Request next part of file.");
1796
        s.channel = 0;
1862
        s.channel = 0;
1797
        s.level = 0;
1863
        s.level = 0;
1798
        s.port = 0;
1864
        s.port = 0;
1799
        s.value = 0;
1865
        s.value = 0;
1800
        s.MC = 0x0204;
1866
        s.MC = 0x0204;
Line 1827... Line 1893...
1827
 
1893
 
1828
        sendCommand(s);
1894
        sendCommand(s);
1829
    }
1895
    }
1830
    else if (ft.ftype == 4 && ft.function == 0x0003)    // File content
1896
    else if (ft.ftype == 4 && ft.function == 0x0003)    // File content
1831
    {
1897
    {
1832
        MSG_TRACE("0x0004/0x0003: Received (part of) file.");
1898
        MSG_DEBUG("0x0004/0x0003: Received (part of) file.");
1833
        len = ft.unk;
1899
        len = ft.unk;
1834
 
1900
 
1835
        if (isOpenRcv)
1901
        if (isOpenRcv)
1836
        {
1902
        {
1837
            fwrite(ft.data, 1, len, rcvFile);
1903
            fwrite(ft.data, 1, len, rcvFile);
Line 1862... Line 1928...
1862
                MSG_WARNING("Missing callback function!");
1928
                MSG_WARNING("Missing callback function!");
1863
        }
1929
        }
1864
    }
1930
    }
1865
    else if (ft.ftype == 4 && ft.function == 0x0004)    // End of file
1931
    else if (ft.ftype == 4 && ft.function == 0x0004)    // End of file
1866
    {
1932
    {
1867
        MSG_TRACE("0x0004/0x0004: End of file.");
1933
        MSG_DEBUG("0x0004/0x0004: End of file.");
1868
 
1934
 
1869
        if (isOpenRcv)
1935
        if (isOpenRcv)
1870
        {
1936
        {
1871
            unsigned char buf[8];
1937
            unsigned char buf[8];
1872
            fseek(rcvFile, 0, SEEK_SET);
1938
            fseek(rcvFile, 0, SEEK_SET);
Line 1900... Line 1966...
1900
        s.type = 0x0005;            // function: ACK, file received. No answer expected.
1966
        s.type = 0x0005;            // function: ACK, file received. No answer expected.
1901
        sendCommand(s);
1967
        sendCommand(s);
1902
    }
1968
    }
1903
    else if (ft.ftype == 4 && ft.function == 0x0005)    // ACK, controller received file, no answer
1969
    else if (ft.ftype == 4 && ft.function == 0x0005)    // ACK, controller received file, no answer
1904
    {
1970
    {
1905
        MSG_TRACE("0x0004/0x0005: Controller received file.");
1971
        MSG_DEBUG("0x0004/0x0005: Controller received file.");
1906
        posSnd = 0;
1972
        posSnd = 0;
1907
        lenSnd = 0;
1973
        lenSnd = 0;
1908
 
1974
 
1909
        if (isOpenSnd && sndFile != nullptr)
1975
        if (isOpenSnd && sndFile != nullptr)
1910
            fclose(sndFile);
1976
            fclose(sndFile);
Line 1912... Line 1978...
1912
        ftransfer.lengthFile = 0;
1978
        ftransfer.lengthFile = 0;
1913
        sndFile = nullptr;
1979
        sndFile = nullptr;
1914
    }
1980
    }
1915
    else if (ft.ftype == 4 && ft.function == 0x0006)    // End of directory transfer ACK
1981
    else if (ft.ftype == 4 && ft.function == 0x0006)    // End of directory transfer ACK
1916
    {
1982
    {
1917
        MSG_TRACE("0x0004/0x0006: End of directory transfer.");
1983
        MSG_DEBUG("0x0004/0x0006: End of directory transfer.");
1918
    }
1984
    }
1919
    else if (ft.ftype == 4 && ft.function == 0x0007)    // End of file transfer
1985
    else if (ft.ftype == 4 && ft.function == 0x0007)    // End of file transfer
1920
    {
1986
    {
1921
        MSG_TRACE("0x0004/0x0007: End of file transfer.");
1987
        MSG_DEBUG("0x0004/0x0007: End of file transfer.");
1922
 
1988
 
1923
        if (callback)
1989
        if (callback)
1924
            callback(ftr);
1990
            callback(ftr);
1925
        else
1991
        else
1926
            MSG_WARNING("Missing callback function!");
1992
            MSG_WARNING("Missing callback function!");
Line 2044... Line 2110...
2044
 
2110
 
2045
    for (size_t i = 0; i < len; i++)
2111
    for (size_t i = 0; i < len; i++)
2046
        sum += (unsigned long)(*(buffer + i)) & 0x000000ff;
2112
        sum += (unsigned long)(*(buffer + i)) & 0x000000ff;
2047
 
2113
 
2048
    sum &= 0x000000ff;
2114
    sum &= 0x000000ff;
2049
    MSG_TRACE("Checksum=" << std::setw(2) << std::setfill('0') << std::hex << sum << ", #bytes=" << len << " bytes.");
2115
    MSG_DEBUG("Checksum=" << std::setw(2) << std::setfill('0') << std::hex << sum << ", #bytes=" << len << " bytes.");
2050
    return (unsigned char)sum;
2116
    return (unsigned char)sum;
2051
}
2117
}
2052
 
2118
 
2053
uint16_t TAmxNet::makeWord(unsigned char b1, unsigned char b2)
2119
uint16_t TAmxNet::makeWord(unsigned char b1, unsigned char b2)
2054
{
2120
{
Line 2619... Line 2685...
2619
    map<ulong, FUNC_TIMER_t>::iterator iter;
2685
    map<ulong, FUNC_TIMER_t>::iterator iter;
2620
 
2686
 
2621
    for (iter = mFuncsTimer.begin(); iter != mFuncsTimer.end(); iter++)
2687
    for (iter = mFuncsTimer.begin(); iter != mFuncsTimer.end(); iter++)
2622
        iter->second.func(blink);
2688
        iter->second.func(blink);
2623
}
2689
}
-
 
2690
 
-
 
2691
void TAmxNet::setWaitTime(int secs)
-
 
2692
{
-
 
2693
    DECL_TRACER("TAmxNet::setWaitTime(int secs)");
-
 
2694
 
-
 
2695
    if (secs <= 0 || secs > 300)    // Maximal 5 minutes
-
 
2696
        return;
-
 
2697
 
-
 
2698
    mOldWaitTime = mWaitTime;
-
 
2699
    mWaitTime = secs;
-
 
2700
}
-
 
2701
 
-
 
2702
int TAmxNet::swapWaitTime()
-
 
2703
{
-
 
2704
    DECL_TRACER("TAmxNet::restoreWaitTime()");
-
 
2705
 
-
 
2706
    int wt = mWaitTime;
-
 
2707
 
-
 
2708
    mWaitTime = mOldWaitTime;
-
 
2709
    mOldWaitTime = wt;
-
 
2710
    return mWaitTime;
-
 
2711
}