Bläddra i källkod

修改好水机按键、增加bms复归键

yanglu 3 månader sedan
förälder
incheckning
8607615b4a
3 ändrade filer med 348 tillägg och 179 borttagningar
  1. 237 151
      examples/device-dashboard/appl.c
  2. 13 3
      examples/device-dashboard/appl.h
  3. 98 25
      examples/device-dashboard/net.c

+ 237 - 151
examples/device-dashboard/appl.c

@@ -3,7 +3,7 @@
3 3
 #define DIR_OUT "out"
4 4
 #define DIR_IN "in"
5 5
 
6
-char* VERSION = "南瑞电池包_英维克新水机 1.2";
6
+char* VERSION = "南瑞电池包_英维克新水机 1.3";
7 7
 
8 8
 struct appl_t APPL;
9 9
 struct mg_mgr mgr_mqtt1;  // thingsboard
@@ -932,6 +932,7 @@ static void* thrd_485_2(void* param)
932 932
   int step = 1;
933 933
   int i;
934 934
   int64_t startts;
935
+  int trycnt;
935 936
 
936 937
   MG_INFO(("%s ENTER",__func__));
937 938
 
@@ -994,6 +995,28 @@ static void* thrd_485_2(void* param)
994 995
         // syslog(LOG_INFO,"bms comm ok");
995 996
       }
996 997
 
998
+       if(ch->Cmd == CMD_485_BMS_RESET)
999
+      {
1000
+        ch->Cmd = CMD_485_DONE;
1001
+        trycnt = 3;
1002
+        while(trycnt-- > 0)
1003
+        {
1004
+          appl_chan485_lock(chidx);
1005
+          usleep(30000);
1006
+          modbus_set_slave(ctx,bms->Adr);
1007
+          rc = modbus_write_bit(ctx,0,1);
1008
+          appl_chan485_unlock(chidx);
1009
+          if(rc >= 0)
1010
+          {
1011
+            break;
1012
+          }
1013
+          else
1014
+          {
1015
+            modbus_flush(ctx);
1016
+          }
1017
+        }
1018
+      }
1019
+
997 1020
       appl_chan485_lock(chidx);
998 1021
       usleep(30000);
999 1022
       // 读取动作元件状态 (1-66)
@@ -1451,7 +1474,62 @@ static void* thrd_485_2(void* param)
1451 1474
         bms->MinCellSoh = data[65 - 1 - start];
1452 1475
         bms->MinCellSocIdx = data[66 - 1 - start];
1453 1476
 
1454
-        strcpy(bms->szBatState,"未知");
1477
+        if(bms->WorkState == 1)
1478
+        {
1479
+            strcpy(bms->szWorkState,"开路");
1480
+        }
1481
+        else if(bms->WorkState == 2)
1482
+        {
1483
+        strcpy(bms->szWorkState,"待机");
1484
+        } 
1485
+        else if(bms->WorkState == 3)
1486
+        {
1487
+        strcpy(bms->szWorkState,"充电");
1488
+        } 
1489
+         else if(bms->WorkState == 4)
1490
+        {
1491
+        strcpy(bms->szWorkState,"放电");
1492
+        } 
1493
+
1494
+
1495
+        if(bms->BatSelfSupervise == 1)
1496
+        {
1497
+           strcpy(bms->szBatSelfSupervise,"正常");
1498
+        } 
1499
+        else if(bms->BatSelfSupervise == 2)
1500
+        {
1501
+           strcpy(bms->szBatSelfSupervise,"预警");
1502
+        } 
1503
+        else if(bms->BatSelfSupervise == 3)
1504
+        {
1505
+           strcpy(bms->szBatSelfSupervise,"告警");
1506
+        } 
1507
+        else if(bms->BatSelfSupervise == 4)
1508
+        {
1509
+           strcpy(bms->szBatSelfSupervise,"保护");
1510
+        } 
1511
+
1512
+        if(bms->SysState == 1)
1513
+        {
1514
+          strcpy(bms->szSysState,"待机");
1515
+        }
1516
+        else if(bms->SysState == 2)
1517
+        {
1518
+          strcpy(bms->szSysState,"正常");
1519
+        }
1520
+        else if(bms->SysState == 3)
1521
+        {
1522
+          strcpy(bms->szSysState,"禁充");
1523
+        }
1524
+        else if(bms->SysState == 4)
1525
+        {
1526
+          strcpy(bms->szSysState,"禁放");
1527
+        }
1528
+        else if(bms->SysState == 5)
1529
+        {
1530
+          strcpy(bms->szSysState,"停机");
1531
+        }
1532
+
1455 1533
 
1456 1534
         // if(bms->BatState == 1)
1457 1535
         // {
@@ -2058,9 +2136,9 @@ static void* thrd_485_3(void* param)
2058 2136
       }
2059 2137
       else
2060 2138
       {
2061
-        // t.tv_sec = 0;
2062
-        // t.tv_usec = 500000;
2063
-        // modbus_set_response_timeout(ctx,0,500000);
2139
+        t.tv_sec = 0;
2140
+        t.tv_usec = 500000;
2141
+        modbus_set_response_timeout(ctx,0,500000);
2064 2142
         ch->reqcnt = 0;
2065 2143
         ch->failcnt = 0;
2066 2144
         appl_485_set_state(chidx,ST_485_RUN,ERR_485_NONE);
@@ -2166,6 +2244,7 @@ static void* thrd_485_3(void* param)
2166 2244
           modbus_set_slave(ctx,ac->Adr);
2167 2245
           rc = modbus_write_register(ctx,0xE604,ch->CmdParam);
2168 2246
           appl_chan485_unlock(chidx);
2247
+          // syslog(LOG_INFO,"%s,set PumpShift:%d",__func__,ch->CmdParam);
2169 2248
           if(rc >= 0)
2170 2249
           {
2171 2250
            break;
@@ -2539,7 +2618,7 @@ static void* thrd_485_3(void* param)
2539 2618
             strcpy(ac->szCmpState,"开启");
2540 2619
           }
2541 2620
           
2542
-          sprintf(ac->szRunTime,"压缩机:%dh 水泵:%dh 风机:%dh 加热:%dh",data[0xE720  - start],data[0xE728 - start],data[0xE72C - start],data[0xE724 - start]);
2621
+          sprintf(ac->szRunTime,"压缩机:%d%dh 水泵:%d%dh 风机:%d%dh 加热:%d%dh",data[0xE721  - start],data[0xE720  - start],data[0xE729 - start],data[0xE728 - start],data[0xE72D - start],data[0xE72C - start],data[0xE725 - start],data[0xE724 - start]);
2543 2622
 
2544 2623
           ac->SysRunState = data[0xE730 -start];
2545 2624
           if(ac->SysRunState == 0)
@@ -2581,142 +2660,142 @@ static void* thrd_485_3(void* param)
2581 2660
         {
2582 2661
           break;
2583 2662
         }
2584
-        switch(*Step)
2585
-        {
2586
-        case 0:
2587
-          if(bms->AvgCellT < set->HeatTemp)
2588
-          {
2589
-
2590
-            // 设置制冷方式:加热
2591
-            appl_chan485_lock(chidx);
2592
-            usleep(30000);
2593
-            modbus_set_slave(ctx,ac->Adr);
2594
-            rc = modbus_write_register(ctx,0x0402,3);
2595
-            appl_chan485_unlock(chidx);
2596
-            // 设置加热点温度
2597
-            appl_chan485_lock(chidx);
2598
-            usleep(30000);
2599
-            modbus_set_slave(ctx,ac->Adr);
2600
-            rc = modbus_write_register(ctx,0xE601,set->HeatTempSet);
2601
-            appl_chan485_unlock(chidx);
2602
-            // 下发开机命令
2603
-            appl_chan485_lock(chidx);
2604
-            usleep(30000);
2605
-            modbus_set_slave(ctx,ac->Adr);
2606
-            rc = modbus_write_register(ctx,0x0400,1);
2607
-            appl_chan485_unlock(chidx);
2608
-            *Step = 1;
2609
-          }
2610
-          else if(bms->AvgCellT > set->CoolTemp)
2611
-          {
2612
-            // 设置制冷方式:制冷
2613
-            appl_chan485_lock(chidx);
2614
-            usleep(30000);
2615
-            modbus_set_slave(ctx,ac->Adr);
2616
-            rc = modbus_write_register(ctx,0x0402,2);
2617
-            appl_chan485_unlock(chidx);
2618
-            // 设置恒温方式预设温度
2619
-            appl_chan485_lock(chidx);
2620
-            usleep(30000);
2621
-            modbus_set_slave(ctx,ac->Adr);
2622
-            //rc = modbus_write_register( ctx, 0x1000 + 3, (ac->CoolTemp - ac->CoolGap)*10);
2623
-            rc = modbus_write_register(ctx,0xE600,set->CoolTempSet);
2624
-            appl_chan485_unlock(chidx);
2625
-            // 下发开机命令
2626
-            appl_chan485_lock(chidx);
2627
-            usleep(30000);
2628
-            modbus_set_slave(ctx,ac->Adr);
2629
-            rc = modbus_write_register(ctx,0x0400,1);
2630
-            appl_chan485_unlock(chidx);
2631
-            *Step = 2;
2632
-          }
2633
-          else
2634
-          {
2635
-            // // 下发关机命令
2636
-            // appl_chan485_lock(chidx);
2637
-            // usleep(30000);
2638
-            // modbus_set_slave(ctx, ac->Adr);
2639
-            // rc = modbus_write_register( ctx, 0x0300, 0x0002);
2640
-            // appl_chan485_unlock(chidx);
2663
+        // switch(*Step)
2664
+        // {
2665
+        // case 0:
2666
+        //   if(bms->AvgCellT < set->HeatTemp)
2667
+        //   {
2641 2668
 
2642
-            // 下发开机命令
2643
-            appl_chan485_lock(chidx);
2644
-            usleep(30000);
2645
-            modbus_set_slave(ctx,ac->Adr);
2646
-            rc = modbus_write_register(ctx,0x0400,1);
2647
-            appl_chan485_unlock(chidx);
2648
-            // 设置方式:自动
2649
-            appl_chan485_lock(chidx);
2650
-            usleep(30000);
2651
-            modbus_set_slave(ctx,ac->Adr);
2652
-            rc = modbus_write_register(ctx,0x0401,1);
2653
-            appl_chan485_unlock(chidx);
2654
-          }
2655
-          break;
2669
+        //     // 设置制冷方式:加热
2670
+        //     appl_chan485_lock(chidx);
2671
+        //     usleep(30000);
2672
+        //     modbus_set_slave(ctx,ac->Adr);
2673
+        //     rc = modbus_write_register(ctx,0x0402,3);
2674
+        //     appl_chan485_unlock(chidx);
2675
+        //     // 设置加热点温度
2676
+        //     appl_chan485_lock(chidx);
2677
+        //     usleep(30000);
2678
+        //     modbus_set_slave(ctx,ac->Adr);
2679
+        //     rc = modbus_write_register(ctx,0xE601,set->HeatTempSet);
2680
+        //     appl_chan485_unlock(chidx);
2681
+        //     // 下发开机命令
2682
+        //     appl_chan485_lock(chidx);
2683
+        //     usleep(30000);
2684
+        //     modbus_set_slave(ctx,ac->Adr);
2685
+        //     rc = modbus_write_register(ctx,0x0400,1);
2686
+        //     appl_chan485_unlock(chidx);
2687
+        //     *Step = 1;
2688
+        //   }
2689
+          // else if(bms->AvgCellT > set->CoolTemp)
2690
+          // {
2691
+          //   // 设置制冷方式:制冷
2692
+          //   appl_chan485_lock(chidx);
2693
+          //   usleep(30000);
2694
+          //   modbus_set_slave(ctx,ac->Adr);
2695
+          //   rc = modbus_write_register(ctx,0x0402,2);
2696
+          //   appl_chan485_unlock(chidx);
2697
+          //   // 设置恒温方式预设温度
2698
+          //   appl_chan485_lock(chidx);
2699
+          //   usleep(30000);
2700
+          //   modbus_set_slave(ctx,ac->Adr);
2701
+          //   //rc = modbus_write_register( ctx, 0x1000 + 3, (ac->CoolTemp - ac->CoolGap)*10);
2702
+          //   rc = modbus_write_register(ctx,0xE600,set->CoolTempSet);
2703
+          //   appl_chan485_unlock(chidx);
2704
+          //   // 下发开机命令
2705
+          //   appl_chan485_lock(chidx);
2706
+          //   usleep(30000);
2707
+          //   modbus_set_slave(ctx,ac->Adr);
2708
+          //   rc = modbus_write_register(ctx,0x0400,1);
2709
+          //   appl_chan485_unlock(chidx);
2710
+          //   *Step = 2;
2711
+          // }
2712
+          // else
2713
+          // {
2714
+          //   // // 下发关机命令
2715
+          //   // appl_chan485_lock(chidx);
2716
+          //   // usleep(30000);
2717
+          //   // modbus_set_slave(ctx, ac->Adr);
2718
+          //   // rc = modbus_write_register( ctx, 0x0300, 0x0002);
2719
+          //   // appl_chan485_unlock(chidx);
2720
+
2721
+          //   // 下发开机命令
2722
+          //   appl_chan485_lock(chidx);
2723
+          //   usleep(30000);
2724
+          //   modbus_set_slave(ctx,ac->Adr);
2725
+          //   rc = modbus_write_register(ctx,0x0400,1);
2726
+          //   appl_chan485_unlock(chidx);
2727
+          //   // 设置方式:自动
2728
+          //   appl_chan485_lock(chidx);
2729
+          //   usleep(30000);
2730
+          //   modbus_set_slave(ctx,ac->Adr);
2731
+          //   rc = modbus_write_register(ctx,0x0401,1);
2732
+          //   appl_chan485_unlock(chidx);
2733
+          // }
2734
+          // break;
2656 2735
 
2657
-        case 1: // heat
2658
-          if(bms->AvgCellT > set->HeatTemp + set->HeatGap)
2659
-          {
2660
-            *Step = 0;
2661
-          }
2662
-          else
2663
-          {
2664
-            // 设置制冷方式:加热
2665
-            appl_chan485_lock(chidx);
2666
-            usleep(30000);
2667
-            modbus_set_slave(ctx,ac->Adr);
2668
-            rc = modbus_write_register(ctx,0x0401,3);
2669
-            appl_chan485_unlock(chidx);
2670
-            // 设置恒温方式预设温度
2671
-            appl_chan485_lock(chidx);
2672
-            usleep(30000);
2673
-            modbus_set_slave(ctx,ac->Adr);
2674
-            //rc = modbus_write_register( ctx, 0x1000 + 3, (ac->HeatTemp + ac->HeatGap)*10);
2675
-            rc = modbus_write_register(ctx,0xE601,set->HeatTempSet);
2676
-            appl_chan485_unlock(chidx);
2677
-            // 下发开机命令
2678
-            appl_chan485_lock(chidx);
2679
-            usleep(30000);
2680
-            modbus_set_slave(ctx,ac->Adr);
2681
-            rc = modbus_write_register(ctx,0x0400,1);
2682
-            appl_chan485_unlock(chidx);
2736
+        // case 1: // heat
2737
+        //   if(bms->AvgCellT > set->HeatTemp + set->HeatGap)
2738
+        //   {
2739
+        //     *Step = 0;
2740
+        //   }
2741
+          // else
2742
+          // {
2743
+          //   // 设置制冷方式:加热
2744
+          //   appl_chan485_lock(chidx);
2745
+          //   usleep(30000);
2746
+          //   modbus_set_slave(ctx,ac->Adr);
2747
+          //   rc = modbus_write_register(ctx,0x0401,3);
2748
+          //   appl_chan485_unlock(chidx);
2749
+          //   // 设置恒温方式预设温度
2750
+          //   appl_chan485_lock(chidx);
2751
+          //   usleep(30000);
2752
+          //   modbus_set_slave(ctx,ac->Adr);
2753
+          //   //rc = modbus_write_register( ctx, 0x1000 + 3, (ac->HeatTemp + ac->HeatGap)*10);
2754
+          //   rc = modbus_write_register(ctx,0xE601,set->HeatTempSet);
2755
+          //   appl_chan485_unlock(chidx);
2756
+          //   // 下发开机命令
2757
+          //   appl_chan485_lock(chidx);
2758
+          //   usleep(30000);
2759
+          //   modbus_set_slave(ctx,ac->Adr);
2760
+          //   rc = modbus_write_register(ctx,0x0400,1);
2761
+          //   appl_chan485_unlock(chidx);
2683 2762
             
2684
-          }
2685
-          break;
2763
+          // }
2764
+          // break;
2686 2765
 
2687
-        case 2: // cool
2688
-          if(bms->AvgCellT < set->CoolTemp - set->CoolGap)
2689
-          {
2690
-            *Step = 0;
2691
-          }
2692
-          else
2693
-          {
2694
-            // 设置制冷方式:制冷
2695
-            appl_chan485_lock(chidx);
2696
-            usleep(30000);
2697
-            modbus_set_slave(ctx,ac->Adr);
2698
-            rc = modbus_write_register(ctx,0x0401,2);
2699
-            appl_chan485_unlock(chidx);
2700
-            // 设置恒温方式预设温度
2701
-            appl_chan485_lock(chidx);
2702
-            usleep(30000);
2703
-            modbus_set_slave(ctx,ac->Adr);
2704
-            //rc = modbus_write_register( ctx, 0x1000 + 3, (ac->CoolTemp - ac->CoolGap)*10);
2705
-            rc = modbus_write_register(ctx,0xE600,set->CoolTempSet);
2706
-            appl_chan485_unlock(chidx);
2707
-            // 下发开机命令
2708
-            appl_chan485_lock(chidx);
2709
-            usleep(30000);
2710
-            modbus_set_slave(ctx,ac->Adr);
2711
-            rc = modbus_write_register(ctx,0x0400,1);
2712
-            appl_chan485_unlock(chidx);
2713
-          }
2714
-          break;
2766
+        // case 2: // cool
2767
+        //   if(bms->AvgCellT < set->CoolTemp - set->CoolGap)
2768
+        //   {
2769
+        //     *Step = 0;
2770
+        //   }
2771
+          // else
2772
+          // {
2773
+          //   // 设置制冷方式:制冷
2774
+          //   appl_chan485_lock(chidx);
2775
+          //   usleep(30000);
2776
+          //   modbus_set_slave(ctx,ac->Adr);
2777
+          //   rc = modbus_write_register(ctx,0x0401,2);
2778
+          //   appl_chan485_unlock(chidx);
2779
+          //   // 设置恒温方式预设温度
2780
+          //   appl_chan485_lock(chidx);
2781
+          //   usleep(30000);
2782
+          //   modbus_set_slave(ctx,ac->Adr);
2783
+          //   //rc = modbus_write_register( ctx, 0x1000 + 3, (ac->CoolTemp - ac->CoolGap)*10);
2784
+          //   rc = modbus_write_register(ctx,0xE600,set->CoolTempSet);
2785
+          //   appl_chan485_unlock(chidx);
2786
+          //   // 下发开机命令
2787
+          //   appl_chan485_lock(chidx);
2788
+          //   usleep(30000);
2789
+          //   modbus_set_slave(ctx,ac->Adr);
2790
+          //   rc = modbus_write_register(ctx,0x0400,1);
2791
+          //   appl_chan485_unlock(chidx);
2792
+          // }
2793
+        //   break;
2715 2794
 
2716
-        default:
2717
-          // NEVER REACH HERE
2718
-          break;
2719
-        }
2795
+        // default:
2796
+        //   // NEVER REACH HERE
2797
+        //   break;
2798
+        // }
2720 2799
 
2721 2800
         break;
2722 2801
 
@@ -2735,13 +2814,20 @@ static void* thrd_485_3(void* param)
2735 2814
             rc = modbus_write_register(ctx,0xE60B ,0);
2736 2815
             appl_chan485_unlock(chidx);
2737 2816
 
2817
+            // // 485通讯
2818
+            // appl_chan485_lock(chidx);
2819
+            // usleep(30000);
2820
+            // modbus_set_slave(ctx,ac->Adr);
2821
+            // rc = modbus_write_register(ctx,0xE60A ,0);
2822
+            // appl_chan485_unlock(chidx);
2738 2823
 
2739
-             // 出水温度
2740
-            appl_chan485_lock(chidx);
2741
-            usleep(30000);
2742
-            modbus_set_slave(ctx,ac->Adr);
2743
-            rc = modbus_write_register(ctx,0x0402,1);
2744
-            appl_chan485_unlock(chidx);
2824
+
2825
+            //  // 出水温度
2826
+            // appl_chan485_lock(chidx);
2827
+            // usleep(30000);
2828
+            // modbus_set_slave(ctx,ac->Adr);
2829
+            // rc = modbus_write_register(ctx,0x0402,1);
2830
+            // appl_chan485_unlock(chidx);
2745 2831
 
2746 2832
 
2747 2833
             // 设置制冷方式预设温度
@@ -2774,12 +2860,12 @@ static void* thrd_485_3(void* param)
2774 2860
             rc = modbus_write_register(ctx,0xE603,(set->HeatGap)*10);
2775 2861
             appl_chan485_unlock(chidx);
2776 2862
             
2777
-            // 设置工作模式 自动
2778
-            appl_chan485_lock(chidx);
2779
-            usleep(30000);
2780
-            modbus_set_slave(ctx,ac->Adr);
2781
-            rc = modbus_write_register(ctx,0x0401,4);
2782
-            appl_chan485_unlock(chidx);
2863
+            // // 设置工作模式 自动
2864
+            // appl_chan485_lock(chidx);
2865
+            // usleep(30000);
2866
+            // modbus_set_slave(ctx,ac->Adr);
2867
+            // rc = modbus_write_register(ctx,0x0401,4);
2868
+            // appl_chan485_unlock(chidx);
2783 2869
 
2784 2870
 
2785 2871
 
@@ -3142,7 +3228,7 @@ static void* thrd_485_4(void* param)
3142 3228
       else
3143 3229
       {
3144 3230
         dh->TempInner = data[1 - start] * 0.1;
3145
-        dh->HumiInner = data[2 - start] ;
3231
+        dh->HumiInner = data[2 - start] * 0.1;
3146 3232
         dh->TempLenduan = data[3 - start] * 0.1;
3147 3233
         dh->HumiStart = data[4 - start];
3148 3234
         dh->TempOuter = data[5 - start]* 0.1;
@@ -9266,7 +9352,7 @@ void appl_start(void)
9266 9352
   APPL.Adl200.LastUpdate = 0;
9267 9353
   APPL.Adl200.CommFailTotalCnt = 0;
9268 9354
 
9269
-  // Dehumi
9355
+  // chushiji
9270 9356
   APPL.Dehumi.Adr = 1;
9271 9357
 
9272 9358
   // Co

+ 13 - 3
examples/device-dashboard/appl.h

@@ -67,6 +67,8 @@ enum chan485_cmd_t
67 67
   CMD_485_AC_SET_TEMP = 12,
68 68
   CMD_485_AC_SET_PUMP = 13,
69 69
   CMD_485_AC_SET_COMPRESS = 14,
70
+  
71
+  CMD_485_BMS_RESET =15,
70 72
 
71 73
   CMD_485_DH_SET_HUMISTART,
72 74
   CMD_485_DH_SET_HUMISTOP,
@@ -407,8 +409,11 @@ struct NanRuiBms_t
407 409
 {
408 410
   int Adr;
409 411
   int WorkState;
412
+  char szWorkState[16];
410 413
   int BatSelfSupervise;
414
+  char szBatSelfSupervise[16];
411 415
   int SysState;
416
+  char szSysState[16];
412 417
   int HvOnCondition;
413 418
   double PosRes;
414 419
   double NegRes;
@@ -619,6 +624,11 @@ enum AcCmd_t
619 624
   AC_CMD_COMPRESSSET = 12,
620 625
 };
621 626
 
627
+enum BmsCmd_t
628
+{
629
+  BMS_CMD_RESET = 0,
630
+};
631
+
622 632
 enum EnvCmd_t
623 633
 {
624 634
   ENV_CMD_SET_DH_HUMISTART = 0,
@@ -670,11 +680,11 @@ struct Envicool5kW_t
670 680
   char szWorkMode[32];
671 681
   int WaterTempTargetCtlTemp;
672 682
   char szWaterTempTargetCtlTemp[32];
673
-  int OutWaterTemp;
674
-  int InWaterTemp;
683
+  double OutWaterTemp;
684
+  double InWaterTemp;
675 685
   double OutWaterPre;
676 686
   double InWaterPre;
677
-  int EnvTemp;
687
+  double EnvTemp;
678 688
   int ErrCode;
679 689
   int ErrLevel;
680 690
   char szErrLevel[8];

+ 98 - 25
examples/device-dashboard/net.c

@@ -870,12 +870,48 @@ static void handle_pcs_set(struct mg_connection* c,struct mg_str body)
870 870
   }
871 871
 }
872 872
 
873
+static void handle_bms_set(struct mg_connection* c,struct mg_str body)
874
+{
875
+  long cmd;
876
+  long param;
877
+  bool ok = true;
878
+  struct chan485_t* ch = &APPL.chan485[2];
879
+  struct Settings_t* set = &APPL.Set.s;
880
+  cmd = mg_json_get_long(body,"$.cmd",-1);
881
+  param = mg_json_get_long(body,"$.param",-1);
882
+  if(cmd == -1 || param == -1)
883
+  {
884
+    ok = false;
885
+  }
886
+  else
887
+  {
888
+    switch(cmd)
889
+    {
890
+    case BMS_CMD_RESET:
891
+      ch->Cmd = CMD_485_BMS_RESET;
892
+      break;
893
+
894
+      default:
895
+      syslog(LOG_INFO,"%s, unknown cmd : %ld",__func__,cmd);
896
+      break;
897
+    }
898
+  }
899
+  if(ok)
900
+  {
901
+    mg_http_reply(c,200,s_json_header,"true\n");
902
+  }
903
+  else
904
+  {
905
+    mg_http_reply(c,200,s_json_header,"false\n");
906
+  }
907
+}
908
+
873 909
 static void handle_ac_set(struct mg_connection* c,struct mg_str body)
874 910
 {
875 911
   long cmd;
876 912
   long param;
877 913
   bool ok = true;
878
-  struct chan485_t* ch = &APPL.chan485[4];
914
+  struct chan485_t* ch = &APPL.chan485[3];
879 915
   struct Envicool5kW_t* ac = &APPL.Envicool5kW;
880 916
   struct Settings_t* set = &APPL.Set.s;
881 917
   cmd = mg_json_get_long(body,"$.cmd",-1);
@@ -911,6 +947,7 @@ static void handle_ac_set(struct mg_connection* c,struct mg_str body)
911 947
       // 英维克5kW立式 请求设定模式
912 948
       // 0:停机模式;1;制冷:2:加热;3:自循环;
913 949
     case AC_CMD_MODESET:
950
+      ch->Cmd = CMD_485_AC_SET_MODESET;
914 951
       set->SetMode = param;
915 952
       break;
916 953
 
@@ -920,9 +957,9 @@ static void handle_ac_set(struct mg_connection* c,struct mg_str body)
920 957
       //   ch->CmdParam = param;
921 958
       //   break;
922 959
       // 英维克5kW立式 设定温度
923
-    case AC_CMD_SET_TEMP:
924
-      set->SetTemp = param;
925
-      break;
960
+    // case AC_CMD_SET_TEMP:
961
+    //   set->SetTemp = param;
962
+    //   break;
926 963
 
927 964
       // // 同飞5kW LCI-50C-01SZ-1227 水温目标控制温度
928 965
       // // 0 出水水温控制 1 回水水温控制
@@ -1122,7 +1159,7 @@ static void handle_ctl_get(struct mg_connection* c)
1122 1159
 %m:%m,%m:%f,%m:%f,%m:%f,%m:%f,\
1123 1160
 %m:%f,%m:%f,%m:%f,\
1124 1161
 %m:%f,%m:%f,%m:%f,%m:%f,%m:%f,%m:%f,\
1125
-%m:%m,%m:%d,%m:%d,%m:%f,%m:%f,\
1162
+%m:%m,%m:%f,%m:%f,%m:%f,%m:%f,\
1126 1163
 %m:%m,%m:%m,%m:%m,\
1127 1164
 %m:%m,%m:%m,\
1128 1165
 %m:%m,%m:%m}\n",
@@ -1222,34 +1259,67 @@ static void handle_pcs_get(struct mg_connection* c)
1222 1259
 /*8*/MG_ESC("交流电容故障字"),MG_ESC(p->szAcCapFault),MG_ESC("系统故障字"),MG_ESC(p->szSysFault),MG_ESC("开关故障字"),MG_ESC(p->szOnOffFault),MG_ESC("其他故障字"),MG_ESC(p->szOtherFault));
1223 1260
 }
1224 1261
 
1225
-static void handle_bms_get(struct mg_connection* c)
1262
+// static void handle_bms_get(struct mg_connection* c)
1263
+// {
1264
+//   struct NanRuiBms_t* bms = &APPL.NanRuiBms;
1265
+//   mg_http_reply(c,200,s_json_header,
1266
+//     "{"
1267
+//     "%m:%m,%m:%f,%m:%f,%m:%f,%m:%f,%m:%m," // 1
1268
+//     "%m:%f,%m:%f," // 2
1269
+//     "%m:%f,%m:%f,%m:%f," // 3
1270
+//     "%m:%f,%m:%f,%m:%f," // 4
1271
+//     "%m:%f,%m:%f," // 5
1272
+//     "%m:%m," // 6
1273
+//     "%m:%d,%m:%d,%m:%d,%m:%d," // 7
1274
+//     "%m:%f,%m:%f," // 8
1275
+//     "%m:%m,%m:%lld," // 9
1276
+//     "%m:%d,%m:%d,%m:%d,%m:%d," // 10
1277
+//     "%m:%m,%m:%m,%m:%m" // 11
1278
+//     "}\n",
1279
+//     /*1*/MG_ESC("通信状态"),MG_ESC(bms->szCommState),MG_ESC("总电压"),bms->BatV,MG_ESC("总电流"),bms->BatI,MG_ESC("SOC"),bms->Soc,MG_ESC("SOH"),bms->Soh,MG_ESC("电池状态"),MG_ESC(bms->szBatState),
1280
+//     /*2*/MG_ESC("绝缘电阻R+"),bms->PosRes,MG_ESC("绝缘电阻R-"),bms->NegRes,
1281
+//     /*3*/MG_ESC("最高电芯电压"),bms->MaxCellV,MG_ESC("平均电芯电压"),bms->AvgCellV,MG_ESC("最低电芯电压"),bms->MinCellV,
1282
+//     /*4*/MG_ESC("最高电芯温度"),bms->MaxCellT,MG_ESC("平均电芯温度"),bms->AvgCellT,MG_ESC("最低电芯温度"),bms->MinCellT,
1283
+//     /*5*/MG_ESC("压差"),bms->CellVDiff,MG_ESC("温差"),bms->CellTDiff,
1284
+//     /*6*/MG_ESC("高压状态"),MG_ESC(bms->szHvState),
1285
+//     /*7*/MG_ESC("最高温度位置"),bms->MaxCellTIdx,MG_ESC("最低温度位置"),bms->MinCellTIdx,MG_ESC("最高电压位置"),bms->MaxCellVIdx,MG_ESC("最低电压位置"),bms->MinCellVIdx,
1286
+//     /*8*/MG_ESC("最大可充电流"),bms->MaxChgCurr,MG_ESC("最大可放电流"),bms->MaxDhgCurr,
1287
+//     /*9*/MG_ESC("数据更新时间"),MG_ESC(bms->szLastUpdate),MG_ESC("通信失败次数"),bms->CommFailTotalCnt,
1288
+//     /*10*/MG_ESC("工作状态"),bms->WorkState,MG_ESC("电池自检"),bms->BatSelfSupervise,MG_ESC("系统状态"),bms->SysState,MG_ESC("上电条件"),bms->HvOnCondition,
1289
+//     /*11*/MG_ESC("动作元件状态"),MG_ESC(bms->szActionCompStatus),MG_ESC("装置自检状态"),MG_ESC(bms->szSelfCheckStatus),MG_ESC("遥信变位状态"),MG_ESC(bms->szRemoteSignal)
1290
+//   );
1291
+// }
1292
+
1293
+ static void handle_bms_get(struct mg_connection* c)
1226 1294
 {
1227 1295
   struct NanRuiBms_t* bms = &APPL.NanRuiBms;
1228 1296
   mg_http_reply(c,200,s_json_header,
1229 1297
     "{"
1230
-    "%m:%m,%m:%f,%m:%f,%m:%f,%m:%f,%m:%m," // 1
1231
-    "%m:%f,%m:%f," // 2
1298
+    "%m:%m,%m:%f,%m:%f,%m:%f,%m:%f," // 1
1299
+    "%m:%f,%m:%f,%m:%f,%m:%f,%m:%f," // 2
1232 1300
     "%m:%f,%m:%f,%m:%f," // 3
1233 1301
     "%m:%f,%m:%f,%m:%f," // 4
1234 1302
     "%m:%f,%m:%f," // 5
1235
-    "%m:%m," // 6
1303
+    "%m:%d,%m:%f," // 6
1236 1304
     "%m:%d,%m:%d,%m:%d,%m:%d," // 7
1237 1305
     "%m:%f,%m:%f," // 8
1238
-    "%m:%m,%m:%lld," // 9
1239
-    "%m:%d,%m:%d,%m:%d,%m:%d," // 10
1240
-    "%m:%m,%m:%m,%m:%m" // 11
1306
+    "%m:%f,%m:%d," //9
1307
+    "%m:%m,%m:%lld," // 10
1308
+    "%m:%m,%m:%m,%m:%m,%m:%d," // 11
1309
+    "%m:%m,%m:%m,%m:%m" // 12
1241 1310
     "}\n",
1242
-    /*1*/MG_ESC("通信状态"),MG_ESC(bms->szCommState),MG_ESC("总电压"),bms->BatV,MG_ESC("总电流"),bms->BatI,MG_ESC("SOC"),bms->Soc,MG_ESC("SOH"),bms->Soh,MG_ESC("电池状态"),MG_ESC(bms->szBatState),
1243
-    /*2*/MG_ESC("绝缘电阻R+"),bms->PosRes,MG_ESC("绝缘电阻R-"),bms->NegRes,
1311
+   /*1*/MG_ESC("通信状态"),MG_ESC(bms->szCommState),MG_ESC("总电压"),bms->BatV,MG_ESC("总电流"),bms->BatI,MG_ESC("SOC"),bms->Soc,MG_ESC("SOH"),bms->Soh,
1312
+    /*2*/MG_ESC("绝缘电阻R+"),bms->PosRes,MG_ESC("绝缘电阻R-"),bms->NegRes,MG_ESC("簇功率"),bms->BatPower,MG_ESC("可充电量"),bms->ChgableAmount,MG_ESC("可放电量"),bms->DhgableAmount,
1244 1313
     /*3*/MG_ESC("最高电芯电压"),bms->MaxCellV,MG_ESC("平均电芯电压"),bms->AvgCellV,MG_ESC("最低电芯电压"),bms->MinCellV,
1245 1314
     /*4*/MG_ESC("最高电芯温度"),bms->MaxCellT,MG_ESC("平均电芯温度"),bms->AvgCellT,MG_ESC("最低电芯温度"),bms->MinCellT,
1246 1315
     /*5*/MG_ESC("压差"),bms->CellVDiff,MG_ESC("温差"),bms->CellTDiff,
1247
-    /*6*/MG_ESC("高压状态"),MG_ESC(bms->szHvState),
1316
+    /*6*/MG_ESC("电池容量"),bms->BatCapacity,MG_ESC("母线总电压"),bms->BusV,
1248 1317
     /*7*/MG_ESC("最高温度位置"),bms->MaxCellTIdx,MG_ESC("最低温度位置"),bms->MinCellTIdx,MG_ESC("最高电压位置"),bms->MaxCellVIdx,MG_ESC("最低电压位置"),bms->MinCellVIdx,
1249 1318
     /*8*/MG_ESC("最大可充电流"),bms->MaxChgCurr,MG_ESC("最大可放电流"),bms->MaxDhgCurr,
1250
-    /*9*/MG_ESC("数据更新时间"),MG_ESC(bms->szLastUpdate),MG_ESC("通信失败次数"),bms->CommFailTotalCnt,
1251
-    /*10*/MG_ESC("工作状态"),bms->WorkState,MG_ESC("电池自检"),bms->BatSelfSupervise,MG_ESC("系统状态"),bms->SysState,MG_ESC("上电条件"),bms->HvOnCondition,
1252
-    /*11*/MG_ESC("动作元件状态"),MG_ESC(bms->szActionCompStatus),MG_ESC("装置自检状态"),MG_ESC(bms->szSelfCheckStatus),MG_ESC("遥信变位状态"),MG_ESC(bms->szRemoteSignal)
1319
+    /*9*/MG_ESC("模组最高电压"),bms->MaxCellVMod,MG_ESC("模组最高电压编号"),bms->MaxCellVModIdx,
1320
+    /*10*/MG_ESC("数据更新时间"),MG_ESC(bms->szLastUpdate),MG_ESC("通信失败次数"),bms->CommFailTotalCnt,
1321
+    /*11*/MG_ESC("工作状态"),MG_ESC(bms->szWorkState),MG_ESC("电池自检"),MG_ESC(bms->szBatSelfSupervise),MG_ESC("系统状态"),MG_ESC(bms->szSysState),MG_ESC("上电条件"),bms->HvOnCondition,
1322
+    /*12*/MG_ESC("动作元件状态"),MG_ESC(bms->szActionCompStatus),MG_ESC("装置自检状态"),MG_ESC(bms->szSelfCheckStatus),MG_ESC("遥信变位状态"),MG_ESC(bms->szRemoteSignal)
1253 1323
   );
1254 1324
 }
1255 1325
 
@@ -1259,17 +1329,16 @@ static void handle_ac_get(struct mg_connection* c)
1259 1329
   struct Settings_t* set = &APPL.Set.s;
1260 1330
  mg_http_reply(c, 200, s_json_header, "{\
1261 1331
 %m:%m,%m:%m,%m:%m,%m:%m,\
1262
-%m:%d,%m:%d,%m:%d,\
1263
-%m:%.2lf,%m:%.2lf,\
1332
+%m:%f,%m:%f,%m:%f,\
1333
+%m:%f,%m:%f,\
1264 1334
 %m:%m,%m:%d,%m:%d,%m:%d,%m:%d,\
1265
-%m:%m,%m:%m,%m:%d,%m:%d,%m:%m,%m:%m,\
1335
+%m:%m,%m:%m,%m:%d,%m:%d,%m:%m,%m:%m,%m:%m,\
1266 1336
 %m:%m,%m:%m,%m:%m}\n",
1267 1337
 /*1*/MG_ESC("通信状态"), MG_ESC(ac->szCommState),MG_ESC("数据更新时间"), MG_ESC(ac->szLastUpdate1), MG_ESC("工作模式"),MG_ESC(ac->szWorkMode), MG_ESC("控制模式"),MG_ESC(ac->szCtlMode),
1268 1338
 /*2*/MG_ESC("出水温度"),ac->OutWaterTemp, MG_ESC("回水温度"),ac->InWaterTemp, MG_ESC("环境温度"),ac->EnvTemp,
1269 1339
 /*3*/MG_ESC("回水压力"),ac->InWaterPre, MG_ESC("出水压力"),ac->OutWaterPre, 
1270 1340
 /*4*/MG_ESC("供回水控制目标"),MG_ESC(ac->szWaterTempTargetCtlTemp),MG_ESC("制冷温度设定"),ac->watercool,MG_ESC("制冷回差"),ac->watercoolgap,MG_ESC("加热温度设定"),ac->waterhot,MG_ESC("加热回差"),ac->waterhotgap,
1271
-/*5*/MG_ESC("水泵档位"),MG_ESC(ac->szPumpShift),MG_ESC("压缩机档位"),MG_ESC(ac->szPumpShift),MG_ESC("水泵转速"),ac->PumpRpm,MG_ESC("心跳"),ac->Heartbeat,MG_ESC("压缩机状态"),MG_ESC(ac->szCmpState),MG_ESC("运行时间"),MG_ESC(ac->szRunTime),
1272
-// /*5*/MG_ESC("水泵转速"),ac->PumpRpm,MG_ESC("心跳"),ac->Heartbeat,MG_ESC("压缩机状态"),MG_ESC(ac->szCmpState),MG_ESC("运行时间"),MG_ESC(ac->szRunTime),
1341
+/*5*/MG_ESC("水泵档位"),MG_ESC(ac->szPumpShift),MG_ESC("压缩机档位"),MG_ESC(ac->szCmpShift),MG_ESC("水泵转速"),ac->PumpRpm,MG_ESC("心跳"),ac->Heartbeat,MG_ESC("水泵状态"),MG_ESC(ac->szPumpState),MG_ESC("压缩机状态"),MG_ESC(ac->szCmpState),MG_ESC("运行时间"),MG_ESC(ac->szRunTime),
1273 1342
 /*6*/MG_ESC("液压水温故障"),MG_ESC(ac->szErrMsg1),MG_ESC("变频器故障"),MG_ESC(ac->szErrMsg2),MG_ESC("当前告警最高等级"),MG_ESC(ac->szErrMsg3));
1274 1343
 }
1275 1344
 
@@ -1329,9 +1398,9 @@ static void handle_env_get(struct mg_connection* c)
1329 1398
   struct Dehumi_t* dh = &APPL.Dehumi;
1330 1399
   struct Co_t* co = &APPL.Co;
1331 1400
   mg_http_reply(c,200,s_json_header,"{\
1332
-%m:{%m:%m,%m:%lf,%m:%lf,%m:%lf,%m:%lf,%m:%lf,%m:%m},\
1401
+%m:{%m:%m,%m:%f,%m:%f,%m:%f,%m:%f,%m:%f,%m:%m},\
1333 1402
 %m:{%m:%m,%m:%m,%m:%m,%m:%m,%m:%m,%m:%m,%m:%m,%m:%m,%m:%m},\
1334
-%m:{%m:%m,%m:%m,%m:%lf,%m:%lf,%m:%lf,%m:%lf,%m:%lf,%m:%lf,%m:%m,%m:%m,%m:%m,%m:%m,%m:%m,%m:%m},\
1403
+%m:{%m:%m,%m:%m,%m:%f,%m:%f,%m:%f,%m:%f,%m:%f,%m:%f,%m:%m,%m:%m,%m:%m,%m:%m,%m:%m,%m:%m},\
1335 1404
 %m:{%m:%m,%m:%m,%m:%d,%m:%m}}\n",
1336 1405
 /*1*/MG_ESC("辅助电表"),MG_ESC("通信状态"),MG_ESC(adl->szCommState),MG_ESC("正向有功总电能"),adl->PosAe,MG_ESC("反向有功总电能"),adl->NegAe,MG_ESC("有功功率"),adl->Ap,MG_ESC("无功功率"),adl->Rap,MG_ESC("功率因数"),adl->Pf,MG_ESC("数据更新时间"),MG_ESC(adl->szLastUpdate),
1337 1406
 /*2*/MG_ESC("DIDO"),MG_ESC("状态"),MG_ESC(dido->szState),MG_ESC("数据更新时间"),MG_ESC(dido->szLastUpdate),MG_ESC("1#水浸"),MG_ESC(dido->szWaterDec1),MG_ESC("2#水浸"),MG_ESC(dido->szWaterDec2),MG_ESC("前门"),MG_ESC(dido->szFrontDoor),MG_ESC("后门"),MG_ESC(dido->szBackDoor),MG_ESC("急停"),MG_ESC(dido->szEmgStop),MG_ESC("状态灯"),MG_ESC(dido->szLedMode),MG_ESC("消防喷发反馈"),MG_ESC(dido->szFeEruptFb),
@@ -1512,6 +1581,10 @@ static void fn(struct mg_connection* c,int ev,void* ev_data)
1512 1581
     {
1513 1582
       handle_bms_get(c);
1514 1583
     }
1584
+    else if(mg_http_match_uri(hm,"/api/bms/set"))
1585
+    {
1586
+      handle_bms_set(c,hm->body);
1587
+    }
1515 1588
     else if(mg_http_match_uri(hm,"/api/ac/get"))
1516 1589
     {
1517 1590
       handle_ac_get(c);