{% extends "protocolTools/index.html" %}
{% block title %}carSimulater{% endblock %}
{% block content_01 %}
<script src="../../static/js/protocolTools/carsimulater.js"></script>
<style>
    .nav-pills li {
        margin-bottom:5px;
    }
    .form-control {
        display:inline;
        width:160px;
    }
    .protocol_content:after{
        clear:both;
        display:block;
        content:" ";
    }

    .protocol_content li {
        width:250px;
        _background:yellow;
        list-style:none;
        margin-top:5px;
        float:left;
    }
    .protocol_content label{
        width:90px;
        text-align:right;
    }
    button.btn.btn-primary {
        margin-bottom: 2px;
    }
    h1,h2,h3,h4,h5 {
        margin-top: 5px;
        margin-bottom: 5px;
    }
</style>
<div id="container2" style="width:83%;min-height:750px;float:left;_background:grey;margin-top:50px;">
    {% block content_02 %}
    <ul class="nav nav-pills" style="font-size:14px;">
        <li role="presentation"><a id="setting_tab" {% if arg.path[2]=="M_setting_page" %} class="link-tab" {% endif %} onclick="carSimulaterTab(this)">设置</b></a></li>
        <li role="presentation"><a id="carsimulater_tab" {% if arg.path[2]=="M_carSimulater_page" %} class="link-tab" {% endif %} onclick="carSimulaterTab(this)">模拟器</b></a></li>
        <li role="presentation"><a id="carsimulaterData_tab" {% if arg.path[2]=="M_carSimulaterData_page" %} class="link-tab" {% endif %} onclick="carSimulaterTab(this)">查询车数据</b></a></li>
    </ul>
    {% endblock %}
    {% block content_1 %}
    <div id="container3" style="width:100%;min-height:750px;float:left;_background:green;margin-top:10px;_border-top: 1px solid #eee;">
        <div style="width:100%;padding-bottom:10px;border-bottom: 1px solid #eee;">
            <span><label>车机Id:</label><input id="carId" type="text" class="form-control" value="M202008270001"></span>
            <span style="display:none;"><label>消息流水号:</label><input id="WATER_CODE" style="width:60px;" type="text" class="form-control" value="1"></span>
            <span><label>上报间隔(秒):</label><input id="durTime" style="width:60px;" type="text" class="form-control" value="5"></span>
            <span><label>设置超时时间:</label><input style="width:80px;" id="timeout" type="text" class="form-control" value="36000"></span>
            <span><label title="可填入正负数,表示发送的报文时间与当前的时间差距">报文时间差(秒):</label><input style="width:80px;" id="timeDif" type="text" class="form-control" value="0"></span>
        </div>
        <div style="display: block; width: 100%; border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px; padding: 2px; margin-top: 5px;">
            <h5><b>多人在线状态面板:</b></h5>
            <span><label>我的id:</label><input disabled=disabled type="text" id="curSession" class="form-control" style="display:inline;width:200px;" value=""/></span>
            <span><label>在线人数:</label><input disabled=disabled type="text" id="totalSessionNums" class="form-control" style="display:inline;width:80px;" value="1"/></span>
            <button id="sessionRefresh" type="button" class="btn btn-primary" onclick="getAllUsers(this)">刷新</button><label style="font-size:10px;width:100px;">刷新后,可在控制台查看在线用户详细信息</label>
        </div>
        <div style="width:100%;_padding-bottom:10px;border-bottom: 1px solid #eee;">
<!--            <h4>点击登录按钮发送报文:</h4>-->
            <div style="display: block; width: 100%; border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px; padding: 2px; margin-top: 5px;">
                <h5><b>登录报文数据:</b>
                    <span style="border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:1px 10px;">
                        <label><input name="login" type="radio" value="0" checked="checked" onclick="isShowLoginArea(this)"/>隐藏</label>
                        <label style="margin-left:10px;"><input name="login" type="radio" value="1" onclick="isShowLoginArea(this)"/>显示</label>
                    </span>
                </h5>
                <div id="login_area" style="display:none;">
                    <ul class="protocol_content" style="padding:0px;">
                        <li style="width:320px;"><label>CPU-ID:</label><input style="width:220px;" id="cpuId" type="text" class="form-control" value="CPU-ID001122334455667788"></li>
                        <li><label style="word-break:break-all;font-size:12px;">SIM卡IMSI号:</label><input id="imsi" type="text" class="form-control" value="IMSI13145678902"></li>
                        <li style="width:300px;"><label style="word-break:break-all;font-size:12px;">SIM卡CCID号:</label><input style="width:200px;" id="ccid" type="text" class="form-control" value="CCID1122334455667788"></li>
                        <li><label style="word-break:break-all;font-size:10px;">GSM模块IMEI码:</label><input id="imei" type="text" class="form-control" value="IMEI12233445566"></li>
                    </ul>

                    <ul class="protocol_content" style="padding:0px;">
                        <li style="width:320px;"><label style="word-break:break-all;font-size:12px;">车机版本信息:</label><input style="width:220px;" id="verInfo" type="text" class="form-control" value="M100AB01010.0000"></li>
                        <li><label>编译日期:</label><input id="compileDate" type="text" class="form-control" value="2020-03-23"></li>
                        <li style="width:300px;"><label style="word-break:break-all;font-size:12px;">GSM模块型号:</label><input style="width:200px;" id="GSM" type="text" class="form-control" value="GSM_123456"></li>
                    </ul>
                </div>
            </div>
        </div>
        <div style="display: block; width: 100%; border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px; padding: 2px; margin-top: 5px;">
            <h5><b>GPS行驶轨迹设置:</b></h5>
            <div class="input-group" style="width:380px;padding-bottom:10px;margin-left:10px;display:inline;">
                <form id="form" enctype="multipart/form-data">
                    <input type="file" id="fileAttach" name="file" class="form-control" style="display:inline;width:250px;"/>
                    <input type="button" onclick="uploadFile()" value="上传" class="form-control" style="display:inline;width:80px;font-weight: bolder;"/>
                </form>
            </div>
            <span style="margin-left:10px;"><label>选择轨迹:</label><select id="selectGPSLine" class="form-control" style="width:250px;">
                {% for key,value in arg["gpsLines"].items() %}
                <option value="{{ key }}">{{ value }}</option>
                {% endfor %}
            </select></span>
            <a style="margin-left:10px;font-weight:bold;" onclick="download_sample()">下载示例轨迹</a>
<!--            <label><input style="margin-left:30px;" type="checkbox" id="ignition" />轨迹管理</label>-->
<!--            <div style="display: block;margin:10px; width: 95%; border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px; padding: 2px; margin-top: 5px;">-->
<!--            </div>-->
        </div>
        <div style="display: block; width: 100%; border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px; padding: 2px; margin-top: 5px;">
            <h5><b>行驶参数设置:</b></h5>
            <span><label>速度(Km/h):</label><input type="text" id="carSpeed" class="form-control" style="display:inline;width:80px;" value="60"/></span>
            <span><label>油耗(Km/L):</label><input type="text" id="oilExpend" class="form-control" style="display:inline;width:80px;" value="10"/></span>
            <span><label>是否循环行驶:</label><select style="width:80px;" id="travelLoop" class="form-control">
                <option value="0">否</option>
                <option value="1">是</option></select><label style="font-size:9px;width: 100px;">开启后会在所选择的轨迹上来回行驶</label></span>
        </div>
        <div style="width:100%;padding-bottom:10px;border-bottom: 1px solid #eee;">
            <h3>操作:</h3>
            <button id="connect_B" type="button" class="btn btn-primary" onclick="connect()">1、连网</button>
            <button id="fire_B" type="button" class="btn btn-primary" onclick="login()">2、登录</button>
            <button id="login_B" type="button" class="btn btn-primary" onclick="fire()">3、点火</button>
            <button id="run_B" type="button" class="btn btn-primary" onclick="startTravel()">4、行驶</button>
            <button id="stopRun_B" type="button" class="btn btn-primary" onclick="stopTravel()">5、停止行驶</button>
            <button id="unFire_B" type="button" class="btn btn-primary" onclick="unFire()">6、熄火</button>
            <button id="unConnect_B" type="button" class="btn btn-primary" onclick="stopConnect()">7、断网</button>
            <button id="unConnectAll_B" type="button" class="btn btn-danger" onclick="reset()">复位</button>
            <button id="clear_B" type="button" class="btn btn-warning" onclick="clearlog()">清空日志</button>
            <span style="margin-left:20px;"><label>当前状态:</label><input id="curStatus" value="断网" disabled="disabled" class="form-control" style="font-weight: bold;width:85px;color:red;border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px;"></span>
            <span style="width:80px;padding-left:10px;"><label style="width:70px"><input type="checkbox" id="ignition" onclick="isLogShow(this)"/>隐藏日志</label> </span>
            <span style="border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:1px 10px;">
                <label><input name="travelDirection" type="radio" value="0" checked="checked"/>正向</label>
                <label style="margin-left:10px;"><input name="travelDirection" type="radio" value="1"/>反向</label>
            </span>
        </div>
        <div style="display: block; width: 100%; border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px; padding: 2px; margin-top: 5px;">
            <h5><b>事件发送:</b>
                <span style="border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:1px 10px;">
                    <label><input name="eventshow" type="radio" value="0" checked="checked" onclick="isShowEventArea(this)"/>隐藏</label>
                    <label style="margin-left:10px;"><input name="eventshow" type="radio" value="1" onclick="isShowEventArea(this)"/>显示</label>
                </span>
            </h5>
            <div id="event_area" style="display:none;">
                <div style="margin-top:10px;width:100%;border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:2px;background:skyblue;">
                    <label style="padding: 0px 10px;"><input type="checkbox" id="insertAlarm_check" onclick="eventSelect(this)" checked />终端插入报警 </label>
                    <label style="padding: 0px 10px;"><input type="checkbox" id="pulloutAlarm_check" onclick="eventSelect(this)" checked />终端拔出报警 </label>
                    <label style="padding: 0px 10px;"><input type="checkbox" id="lowVoltage_check" onclick="eventSelect(this)" checked />汽车电瓶低电压报警 </label>
                    <label style="padding: 0px 10px;"><input type="checkbox" id="powerOff_check" onclick="eventSelect(this)" checked />终端主电断电报警 </label>
                    <label style="padding: 0px 10px;"><input type="checkbox" id="rapidlyAccelerateEvent_check" onclick="eventSelect(this)" checked />急加速 </label>
                    <label style="padding: 0px 10px;"><input type="checkbox" id="sharpSlowdownEvent_check" onclick="eventSelect(this)" checked />急减速 </label>
                    <label style="padding: 0px 10px;"><input type="checkbox" id="sharpTurnEvent_check" onclick="eventSelect(this)" checked />急转弯 </label>
                    <label style="padding: 0px 10px;"><input type="checkbox" id="collisionAlarmEvent_check" onclick="eventSelect(this)" checked />碰撞报警 </label>
                    <label style="padding: 0px 10px;"><input type="checkbox" id="setUpDefencesEvent_check" onclick="eventSelect(this)" checked />设防 </label>
                    <label style="padding: 0px 10px;"><input type="checkbox" id="setDownDefencesEvent_check" onclick="eventSelect(this)" checked />撤防 </label>
                    <label style="padding: 0px 10px;"><input type="checkbox" id="lowGearHighSpeed_check" onclick="eventSelect(this)" checked />低档高速报警 </label>
                    <label style="padding: 0px 10px;"><input type="checkbox" id="highGearLowSpeed_check" onclick="eventSelect(this)" checked />高档低速报警 </label>
                    <label style="padding: 0px 10px;"><input type="checkbox" id="surplusOil_check" onclick="eventSelect(this)" checked />剩余油量异常告警 </label>
                    <label style="padding: 0px 10px;"><input type="checkbox" id="overSpeed_check" onclick="eventSelect(this)" checked />超速报警 </label>
                    <label style="padding: 0px 10px;"><input type="checkbox" id="tiredDriving_check" onclick="eventSelect(this)" checked />疲劳驾驶 </label>
                    <label style="padding: 0px 10px;"><input type="checkbox" id="idlingOverTime_check" onclick="eventSelect(this)" checked />怠速过长 </label>
                    <label style="padding: 0px 10px;"><input type="checkbox" id="idlingOverTimeOver_check" onclick="eventSelect(this)" checked />怠速过长(解除) </label>
                </div>
                <div style="padding:10px;">
                    <span id="insertAlarm_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendInsertAlarmEvent(this)">终端插入报警</button></label></span>
                    <span id="pulloutAlarm_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendPulloutAlarmEvent(this)">终端拔出报警</button></label></span>
                    <span id="lowVoltage_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendLowVoltageEvent(this)">汽车电瓶低电压报警</button></label></span>
                    <span id="powerOff_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendPowerOffEvent(this)">终端主电断电报警</button></label></span>
                    <span id="rapidlyAccelerateEvent_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendRapidlyAccelerateEvent(this)">急加速</button></label></span>
                    <span id="sharpSlowdownEvent_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendSharpSlowdownEvent(this)">急减速</button></label></span>
                    <span id="sharpTurnEvent_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendSharpTurnEvent(this)">急转弯</button></label></span>
                    <span id="collisionAlarmEvent_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendCollisionAlarmEvent(this)">碰撞报警</button></label></span>
                    <span id="setUpDefencesEvent_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendSetUpDefencesEvent(this)">设防</button></label></span>
                    <span id="setDownDefencesEvent_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendSetDownDefencesEvent(this)">撤防</button></label></span>
                    <span id="lowGearHighSpeed_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendLowGearHighSpeedEvent(this)">低挡高速</button></label></span>
                    <span id="highGearLowSpeed_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendHighGearLowSpeedEvent(this)">高档低速</button></label></span>
                    <span id="surplusOil_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendSurplusOilAlarmEvent(this)">剩余油量异常</button></label></span>
                    <span id="overSpeed_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendOverSpeedEvent(this)">超速报警</button></label></span>
                    <span id="tiredDriving_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendTiredDrivingAlarmEvent(this)">疲劳驾驶</button></label></span>
                    <span id="idlingOverTime_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendIdlingOverTimeEvent(this)" title="300秒,300毫升">怠速过长</button></label></span>
                    <span id="idlingOverTimeOver_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendIdlingOverTimeOverEvent(this)" title="500秒,500毫升">怠速过长(解除)</button></label></span>
                </div>
            </div>
        </div>
        <div style="display: block; width: 100%; border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px; padding: 2px; margin-top: 5px;">
            <h5><b>实时控制:</b>
                <span style="border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:1px 10px;">
                    <label><input name="realtime" type="radio" value="0" checked="checked" onclick="isShowRealTimeCtrArea(this)"/>隐藏</label>
                    <label style="margin-left:10px;"><input name="realtime" type="radio" value="1" onclick="isShowRealTimeCtrArea(this)"/>显示</label>
                </span>
            </h5>
            <div id="realTimeCtl_area" style="display:none;">
                <div style="padding:10px;">
                    <span style="margin-left:10px;display: inline-block;"><label>车速度(Km/h):</label><input style="width:80px;margin-right:5px;" id="change_speed" type="text" class="form-control" value="60"><button type="button" class="btn btn-primary" onclick="changeSpeed()">改变车速</button></span>
                    <span style="margin-left:10px;display: inline-block;"><label>油耗(Km/L):</label><input style="width:80px;margin-right:5px;" id="change_oilExpend" type="text" class="form-control" value="10"><button type="button" class="btn btn-primary" onclick="changeOilExpend()">改变油耗</button></span>
                    <span style="margin-left:10px;display: inline-block;"><label>上报间隔(秒):</label><input style="width:80px;margin-right:5px;" id="change_durTime" type="text" class="form-control" value="5"><button type="button" class="btn btn-primary" onclick="changeDurTime()">改变上报间隔</button></span>
                    <span style="margin-left:10px;display: inline-block;"><button title="点击后,将会把上报的消息存到本地,不上报消息;用来模拟车机无信号的情况" type="button" class="btn btn-primary" onclick="storeMsg()" id="storeMsgBut">存储上报消息</button><label style="color:red;" id="storeMsgLab">未存储...</label></span>
                    <span style="margin-left:10px;display: inline-block;"><label>剩余油量(%):</label><input style="width:80px;margin-right:5px;" id="change_surplusOil" type="text" class="form-control" value="50.5"><button type="button" class="btn btn-primary" onclick="changeSurplusOil()">改变剩余油量</button></span>
                    <span style="margin-left:10px;display: inline-block;"><label>发动机转速:</label><input style="width:80px;margin-right:5px;" id="change_engineSpeed" type="text" class="form-control" value="3000"><button type="button" class="btn btn-primary" onclick="changeEngineSpeed()">改变发动机转速</button></span>
                    <span style="margin-top:10px;display:inline-block;border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:1px 10px;margin-left:10px;">
                        <label><input name="GPSValie" value="1" type="radio" onclick="changeGPSValid(this)" checked="checked">GPS有效</label>
                        <label style="margin-left:10px;color:red;"><input name="GPSValie" value="0" type="radio" onclick="changeGPSValid(this)">GPS无效</label>
                    </span>
                    <span style="margin-top:10px;display:inline-block;border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:1px 10px;margin-left:10px;">
                        <label><input name="lngLatIsOk" value="1" type="radio" onclick="changeLngLatIsOk(this)" checked="checked">经纬度正常</label>
                        <label style="margin-left:10px;color:red;"><input name="lngLatIsOk" value="0" type="radio" onclick="changeLngLatIsOk(this)">经纬度为0</label>
                    </span>
                    <span style="margin-left:10px;display: inline-block;"><button type="button" class="btn btn-primary" onclick="changeTravelDirection()">改变行驶方向</button></span>
                    <span style="margin-left:10px;display: inline-block;"><label>电瓶电压(v) :</label><input style="width:80px;margin-right:5px;" id="change_voltage" type="text" class="form-control" value="12"><button type="button" class="btn btn-primary" onclick="changeVoltage()">改变电瓶电压</button></span>
                    <span style="margin-left:10px;display: inline-block;"><button title="点击后,车机将会在当前位置发送gps和obd数据" type="button" class="btn btn-primary" onclick="fixCurPosition(this)">固定在当前位置</button></span>
                </div>
            </div>
        </div>
        <div style="display: block; width: 100%; border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px; padding: 2px; margin-top: 5px;">
            <h5><b>其他操作:</b>
                <span style="border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:1px 10px;">
                    <label><input name="otheroper" type="radio" value="0" checked="checked" onclick="isShowOtheroperCtrArea(this)"/>隐藏</label>
                    <label style="margin-left:10px;"><input name="otheroper" type="radio" value="1" onclick="isShowOtheroperCtrArea(this)"/>显示</label>
                </span>
            </h5>
            <div id="other_area" style="display:none;">
                <div style="border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:1px 10px;margin:0px 10px;">
                    <h5><i><b>故障码上报:</b></i></h5>
                    <label>故障码个数:</label><input style="width:80px;" id="troubleCodeNum" type="text" class="form-control" value="1">
                    <label>故障码类型:</label><select id="systemId" class="form-control">
                        <option value="00">发动机故障码</option>
                        <option value="01">变速箱故障码</option>
                        <option value="02">ABS 故障码</option>
                        <option value="03">安全气囊故障码</option>
                    </select>
                    <label>故障码状态:</label><select id="status" class="form-control" style="width:100px;">
                        <option value="0">未解决</option>
                        <option value="1">已解决</option>
                    </select>
                    <label>MIL状态:</label><select id="MILStatus" class="form-control" style="width:80px;">
                        <option value="0">ON</option>
                        <option value="1">OFF</option>
                    </select>
                    <button type="button" class="btn btn-primary" onclick="sendTroubleCode()">发送故障码</button>
                </div>
            </div>
        </div>
        <div style="width:100%;border-bottom: 1px solid #eee;">
            <h3>日志:</h3>
            <textarea id="showFeedback" style="width:100%;padding:5px;padding-bottom:60px;" rows="10"></textarea>
        </div>
        <div style="width:100%;padding-bottom:10px;border-bottom: 1px solid #eee;">
        <h4>数据查询</h4>
        <span>
            <button id="searchCarData" type="button" class="btn btn-primary">查询今日行驶数据</button>
            <button id="searchCarGPS" type="button" class="btn btn-primary">查询车辆当前GPS点</button>
        </span>
    </div>
    <H3 style="border-bottom: 1px solid #eee;">返回信息:</H3>
    <div style="width:100%;padding:5px;margin-top:10px;">
        <textarea id="searchCardataShow" style="width:100%;padding:5px;" rows="8"></textarea>
    </div>
    </div>
<script>
//通过函数获取页面参数
function getPageData(){
    var data = {};
    var carId = $("#carId").val()
    var WATER_CODE = $("#WATER_CODE").val()
    var durTime = $("#durTime").val()
    var timeout = $("#timeout").val()
    var timeDif = $("#timeDif").val()
    data["carId"] = carId
    data["WATER_CODE"] = WATER_CODE
    data["durTime"] = durTime
    data["timeout"] = timeout
    data["timeDif"] = timeDif
    //会话session数据
    data["session"] = {}
    var sessionId = $("#curSession").val()
    data["session"]["sessionId"] = sessionId
    //登录数据
    data["login"] = {}
    var cpuId = $("#cpuId").val()
    var imsi = $("#imsi").val()
    var ccid = $("#ccid").val()
    var imei = $("#imei").val()
    data["login"]["cpuId"] = cpuId
    data["login"]["imsi"] = imsi
    data["login"]["ccid"] = ccid
    data["login"]["imei"] = imei
    //版本数据
    data["version"] = {}
    var verInfo = $("#verInfo").val()
    var compileDate = $("#compileDate").val()
    var GSM = $("#GSM").val()
    data["version"]["verInfo"] = verInfo
    data["version"]["compileDate"] = compileDate
    data["version"]["GSM"] = GSM
    //GPS轨迹数据
    var gpsLine = $("#selectGPSLine").val()
    data["gpsLine"] = gpsLine
    //行驶参数数据
    data["travelData"] = {}
    var carSpeed = $("#carSpeed").val()
    var oilExpend = $("#oilExpend").val()
    var travelLoop = $("#travelLoop").val()
    var travelDirection = $("input[name='travelDirection']:checked").val()
    data["travelData"]["carSpeed"] = carSpeed
    data["travelData"]["oilExpend"] = oilExpend
    data["travelData"]["travelLoop"] = travelLoop
    data["travelData"]["travelDirection"] = travelDirection
    //其他默认数据
    data["other"] = {}
    var valtage = 1.2 * 10
    data["other"]["valtage"] = valtage
    return data;
}
//连接
function connect(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/createConect";
    var host = window.location.host;
    $.ajax({
        //url:"http://" + host + "/protocolTools/M_carSimulater_process/porcessSocketSetting",
        url:"http://" + host + url,
        type:"post",
        data:JSON.stringify(data),
        contentType:"application/json",
        dataType:"json",
        success:function(data){
            if(data.status == 200){
                //window.location.reload()
                var curTime = getCurTime();
                var txt = $("#showFeedback").val()
                txt = txt + "[" + curTime + "] " + data.message + "\n"
                $("#showFeedback").val(txt)
                WebSocketTest()
                $("#curStatus").val("连网")
                var userNums = parseInt($("#totalSessionNums").val()) + 1
                $("#totalSessionNums").val(userNums)
            }else{
                var curTime = getCurTime();
                var txt = $("#showFeedback").val()
                txt = txt + "[" + curTime + "] " + data.message + "\n"
                $("#showFeedback").val(txt)
                alert(data.message);
            }
        }
    });
}
//登录
function login(){
    var data = getPageData()
     $("#curStatus").val("登录")
    url = "/protocolTools/M_carSimulater_process/login";
    sendjson(data,url);
}
//点火
function fire(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/fire";
    sendjson(data,url);
     $("#curStatus").val("点火")
}
//行驶
function startTravel(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/startTravel";
    sendjson(data,url);
    $("#curStatus").val("行驶")
}
//停止行驶
function stopTravel(){
    var data = getPageData();
    url = "/protocolTools/M_carSimulater_process/stopTravel";
    sendjson(data,url);
    $("#curStatus").val("点火")
}
//熄火
function unFire(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/unFire";
    sendjson(data,url);
     $("#curStatus").val("熄火")
}
//断开连接
function stopConnect(){
    var data = getPageData();
    url = "/protocolTools/M_carSimulater_process/closeConect";
    var host = window.location.host;
    $.ajax({
        //url:"http://" + host + "/protocolTools/M_carSimulater_process/porcessSocketSetting",
        url:"http://" + host + url,
        type:"post",
        data:JSON.stringify(data),
        contentType:"application/json",
        dataType:"json",
        success:function(data){
            if(data.status == 200){
                var curTime = getCurTime();
                var txt = $("#showFeedback").val()
                txt = txt + "[" + curTime + "] " + data.message + "\n"
                $("#showFeedback").val(txt)
                //endService()
                 $("#curStatus").val("断网")
                var userNums = parseInt($("#totalSessionNums").val()) - 1
                $("#totalSessionNums").val(userNums)
                ws.close();
            }else{
                var curTime = getCurTime();
                var txt = $("#showFeedback").val()
                txt = txt + "[" + curTime + "] " + data.message + "\n"
                $("#showFeedback").val(txt)
                alert(data.message);
            }
        }
    });
}
//复位
function reset(){
    var res;
	res=confirm("复位后会影响其他在线用户的使用,你确定复位吗?");
	if(res == true){
	    var data =  getPageData();
        url = "/protocolTools/M_carSimulater_process/reset";
        sendjson(data,url);
        $("#showFeedback").val("")
        //endService()
         $("#curStatus").val("断网")
         $("#totalSessionNums").val(0)
         ws.close();
	}
}
//清空日志
function clearlog(){
    $("#showFeedback").val("")
}
//非json方式发送数据
function send(data,url){
    var host = window.location.host;
    $.ajax({
        //url:"http://" + host + "/protocolTools/M_carSimulater_process/porcessSocketSetting",
        url:"http://" + host + url,
        type:"post",
        data:data,
        dataType:"json",
        success:function(data){
            if(data.status == 200){
                //window.location.reload()
                var curTime = getCurTime();
                var txt = $("#showFeedback").val()
                txt = txt + "[" + curTime + "] " + data.message + "\n"
                $("#showFeedback").val(txt)
            }else{
            var curTime = getCurTime();
                var txt = $("#showFeedback").val()
                txt = txt + "[" + curTime + "] " + data.message + "\n"
                $("#showFeedback").val(txt)
                alert(data.message);
            }
        }
    });
}
//json方式发送数据
function sendjson(data,url){
    var host = window.location.host;
    $.ajax({
        //url:"http://" + host + "/protocolTools/M_carSimulater_process/porcessSocketSetting",
        url:"http://" + host + url,
        type:"post",
        data:JSON.stringify(data),
        contentType:"application/json",
        dataType:"json",
        success:function(data){
            if(data.status == 200){
                //window.location.reload()
                var curTime = getCurTime();
                var txt = $("#showFeedback").val()
                txt = txt + "[" + curTime + "] " + data.message + "\n"
                $("#showFeedback").val(txt)
            }else{
                var curTime = getCurTime();
                var txt = $("#showFeedback").val()
                txt = txt + "[" + curTime + "] " + data.message + "\n"
                $("#showFeedback").val(txt)
                alert(data.message);
            }
        }
    });
}

//控制登录数据区域的显示与隐藏
function isShowLoginArea(e){
    var value = $(e).val()
    if(value == "0"){
        $("#login_area").css("display","none")
    }else{
        $("#login_area").css("display","block")
    }
}
///////////////////////////////// websocket 代码开始 /////////////////////////////////
client = "0"
ws = null;
i = 1;
showLog = true;   //设置日志是否显示
(function(){
     ws = null;
     i = 1;
})()

function WebSocketTest(){
      if ("WebSocket" in window){
          console.log("您的浏览器支持 WebSocket!");
          var domain = document.domain;
          ws = new WebSocket("ws://" + domain + ":5005");
          ws.onopen = function(){
                console.log("socket 已经连接上!")
          };
          ws.onmessage = function (evt) {
                var received_msg = JSON.parse(evt.data)
                var curTime = getCurTime();
                if(received_msg["code"] == "0001"){           //0001代表连接消息通信
                    client = received_msg["client"]
                }
                var text = $("#showFeedback").val()
                if(text == ""){
                    text = text + "[" + curTime + "] " + received_msg["msg"] + "\n";
                }else{
                    text = text + "[" + curTime + "] " + received_msg["msg"] + "\n";
                    $('#showFeedback').scrollTop($('#showFeedback')[0].scrollHeight);
                }
                if(showLog){
                    $("#showFeedback").val(text);
                }
          };
          ws.onclose = function(){
                alert("连接已关闭...");      // 关闭 websocket
          };
      }else{
                alert("您的浏览器不支持 WebSocket!");      // 浏览器不支持 WebSocket
      }
}

function sendMsg(){
    var msg = $("#sendMsg").val()
    var data = {};
    data["code"] = "0002";                        //0002代表普通消息通信
    data["client"] = client;
    data["msg"] = msg;
    data = JSON.stringify(data)
    ws.send(data);
}

function endService(){
    var msg = ""
    var data = {};
    data["code"] = "0003";                        //0002代表普通消息通信
    data["client"] = client;
    data["msg"] = msg;
    data = JSON.stringify(data)
    ws.send(data);
}

function myclose(){
    var data = {};
    data["code"] = "0000";                      //0000代表关闭服务器套接字程序
    data["client"] = client;
    data["msg"] = "";
    data = JSON.stringify(data);
    ws.send(data);
    ws.close();
    console.log("执行了socket服务的关闭操作...");
}
///////////////////////////////// websocket 代码结束 /////////////////////////////////
function uploadFile(){
    var form = new FormData(document.getElementById("form"));
    var host = window.location.host;
    $.ajax({
        url:"http://" + host + "/protocolTools/M_carSimulater_process/fileUplad",
        type:"post",
        data:form,
        cache: false,
        processData: false,
        contentType: false,
        success:function(data){
            //提交成功
            if (data.status == "200") {
                $("#fileAttach").val("")
                $("#selectGPSLine").prepend("<option value=" + data.file.filenameOri + ">" + data.file.filename + "</option>")
                alert("sucess")
            }else{
                alert("fail")
            }
        },
        error:function(data){
            var result=document.getElementById("Result");
            result.innerHTML="服务器错误";
        }
    });
}

function download_sample(){
    var host = window.location.host;
    window.location.href = "http://" + host + "/protocolTools/M_carSimulater_process/sampleDowload"
}

//----------------------------------------数据查询代码块------------------------------------------
//查询车机今日行驶数据
$("#searchCarData").click(function(){
    var carId = $("#carId").val();
    var data = {};
    data["carId"] = carId;

    var host = window.location.host;
    $.ajax({
        url:"http://" + host + "/protocolTools/M_carSimulater_process/searchCarsimulaterData",
        type:"post",
        data:data,
        dataType:"json",
        success:function(data){
            if(data.status == 200){
                //window.location.reload()
                msg = data.message
                $("#searchCardataShow").val(msg)
            }else{
                $("#searchCardataShow").val(data.message)
                alert(data.message);
            }
        }
    });
});
//查询当前车辆GPS
$("#searchCarGPS").click(function(){
    var carId = $("#carId").val();
    var sessionId = $("#curSession").val()
    var data = {};
    data["carId"] = carId;
    data["sessionId"] = sessionId;

    var host = window.location.host;
    $.ajax({
        url:"http://" + host + "/protocolTools/M_carSimulater_process/searchCurCarGPS",
        type:"post",
        data:data,
        dataType:"json",
        success:function(data){
            if(data.status == 200){
                msg = data.message
                $("#searchCardataShow").val(msg)
            }else{
                $("#searchCardataShow").val(data.message)
                alert(data.message);
            }
        }
    });
});

//设置隐藏或显示日志
function isLogShow(e){
    if($(e).is(':checked')){
        showLog = false;
    }else{
        showLog = true;
    }
}
// -------------------------------- session多人在线js代码-------------------------------------------
//获取水机session id
function getSessionId(){
    var sessionNum = parseInt(Math.random() * 100000);
    if(sessionNum < 100000){
        sessionNum = sessionNum + 100000;
    }
    var sessionStr = ""
    var strAll = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRETUVWXYZ";
    var strAllLen = strAll.length;
    for(var i = 0;i < 8;i++){
        var wh = parseInt(Math.random() * 100);
        if(wh >= strAllLen){
            wh = wh - strAllLen
        }
        sessionStr = sessionStr + strAll.charAt(wh)
    }
    session = sessionStr + "_" + sessionNum
    return session
}
//设置车机session Id
(function setSessionId(){
    var sessionId = getSessionId()
    $("#curSession").val(sessionId)
})()

//获取所有的使用用户
function getAllUsers(){
    var data = {};
    var host = window.location.host;
    $.ajax({
        url:"http://" + host + "/protocolTools/M_carSimulater_process/getConnects",
        type:"post",
        data:data,
        dataType:"json",
        success:function(data){
            if(data.status == 200){
                //window.location.reload()
                //obj = data.result
                obj = data.result.replace(/'service'(.*?)>,/g,"").replace(/'/g,"\"")
                obj = JSON.parse(obj)
                console.log(obj)
                $("#totalSessionNums").val(data.userCounts)
            }else{
                $("#searchCardataShow").val(data.message)
                alert(data.message);
            }
        }
    });
}
//获取所有的使用用户
(function(){
    var data = {};
    var host = window.location.host;
    $.ajax({
        url:"http://" + host + "/protocolTools/M_carSimulater_process/getConnects",
        type:"post",
        data:data,
        dataType:"json",
        success:function(data){
            if(data.status == 200){
                //window.location.reload()
                obj = data.result
                $("#totalSessionNums").val(data.userCounts)
            }else{

            }
        }
    });
})()

// -------------------------------- 事件控制js代码-------------------------------------------
//设置隐藏或显示事件控制区域
function isShowEventArea(e){
    var value = $(e).val()
    if(value == "0"){
        $("#event_area").css("display","none")
    }else{
        $("#event_area").css("display","block")
    }
}

//事件的选择与取消选择
function eventSelect(e){
    if($(e).is(':checked')){
        if($(e).attr("id") == "insertAlarm_check"){
            $("#insertAlarm_button").css("display","inline")
        }else if($(e).attr("id") == "pulloutAlarm_check"){
            $("#pulloutAlarm_button").css("display","inline")
        }else if($(e).attr("id") == "lowVoltage_check"){
            $("#lowVoltage_button").css("display","inline")
        }else if($(e).attr("id") == "powerOff_check"){
            $("#powerOff_button").css("display","inline")
        }else if($(e).attr("id") == "rapidlyAccelerateEvent_check"){
            $("#rapidlyAccelerateEvent_button").css("display","inline")
        }else if($(e).attr("id") == "sharpSlowdownEvent_check"){
            $("#sharpSlowdownEvent_button").css("display","inline")
        }else if($(e).attr("id") == "sharpTurnEvent_check"){
            $("#sharpTurnEvent_button").css("display","inline")
        }else if($(e).attr("id") == "collisionAlarmEvent_check"){
            $("#collisionAlarmEvent_button").css("display","inline")
        }else if($(e).attr("id") == "setUpDefencesEvent_check"){
            $("#setUpDefencesEvent_button").css("display","inline")
        }else if($(e).attr("id") == "setDownDefencesEvent_check"){
            $("#setDownDefencesEvent_button").css("display","inline")
        }else if($(e).attr("id") == "lowGearHighSpeed_check"){
            $("#lowGearHighSpeed_button").css("display","inline")
        }else if($(e).attr("id") == "highGearLowSpeed_check"){
            $("#highGearLowSpeed_button").css("display","inline")
        }else if($(e).attr("id") == "surplusOil_check"){
            $("#surplusOil_button").css("display","inline")
        }else if($(e).attr("id") == "overSpeed_check"){
            $("#overSpeed_button").css("display","inline")
        }else if($(e).attr("id") == "tiredDriving_check"){
            $("#tiredDriving_button").css("display","inline")
        }else if($(e).attr("id") == "idlingOverTime_check"){
            $("#idlingOverTime_button").css("display","inline")
        }else if($(e).attr("id") == "idlingOverTimeOver_check"){
            $("#idlingOverTimeOver_button").css("display","inline")
        }
    }else{
        if($(e).attr("id") == "insertAlarm_check"){
            $("#insertAlarm_button").css("display","none")
        }else if($(e).attr("id") == "pulloutAlarm_check"){
            $("#pulloutAlarm_button").css("display","none")
        }else if($(e).attr("id") == "lowVoltage_check"){
            $("#lowVoltage_button").css("display","none")
        }else if($(e).attr("id") == "powerOff_check"){
            $("#powerOff_button").css("display","none")
        }else if($(e).attr("id") == "rapidlyAccelerateEvent_check"){
            $("#rapidlyAccelerateEvent_button").css("display","none")
        }else if($(e).attr("id") == "sharpSlowdownEvent_check"){
            $("#sharpSlowdownEvent_button").css("display","none")
        }else if($(e).attr("id") == "sharpTurnEvent_check"){
            $("#sharpTurnEvent_button").css("display","none")
        }else if($(e).attr("id") == "collisionAlarmEvent_check"){
            $("#collisionAlarmEvent_button").css("display","none")
        }else if($(e).attr("id") == "setUpDefencesEvent_check"){
            $("#setUpDefencesEvent_button").css("display","none")
        }else if($(e).attr("id") == "setDownDefencesEvent_check"){
            $("#setDownDefencesEvent_button").css("display","none")
        }else if($(e).attr("id") == "lowGearHighSpeed_check"){
            $("#lowGearHighSpeed_button").css("display","none")
        }else if($(e).attr("id") == "highGearLowSpeed_check"){
            $("#highGearLowSpeed_button").css("display","none")
        }else if($(e).attr("id") == "surplusOil_check"){
            $("#surplusOil_button").css("display","none")
        }else if($(e).attr("id") == "overSpeed_check"){
            $("#overSpeed_button").css("display","none")
        }else if($(e).attr("id") == "tiredDriving_check"){
            $("#tiredDriving_button").css("display","none")
        }else if($(e).attr("id") == "idlingOverTime_check"){
            $("#idlingOverTime_button").css("display","none")
        }else if($(e).attr("id") == "idlingOverTimeOver_check"){
            $("#idlingOverTimeOver_button").css("display","none")
        }
    }
}
//发送终端插入报警
function sendInsertAlarmEvent(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/sendInsertAlarmEvent";
    sendjson(data,url);
}
//发送终端拔出报警
function sendPulloutAlarmEvent(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/sendPulloutAlarmEvent";
    sendjson(data,url);
}
//发送汽车电瓶低电压报警
function sendLowVoltageEvent(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/sendLowVoltageEvent";
    sendjson(data,url);
}
//发送汽车电瓶低电压报警
function sendPowerOffEvent(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/sendPowerOffEvent";
    sendjson(data,url);
}
//发送急加速事件消息
function sendRapidlyAccelerateEvent(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/sendRapidlyAccelerateEvent";
    sendjson(data,url);
}
//发送急减速事件消息
function sendSharpSlowdownEvent(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/sendSharpSlowdownEvent";
    sendjson(data,url);
}
//发送急转弯事件消息
function sendSharpTurnEvent(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/sendSharpTurnEvent";
    sendjson(data,url);
}
//发送碰撞告警事件
function sendCollisionAlarmEvent(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/sendCollisionAlarmEvent";
    sendjson(data,url);
}
//发送设防事件消息
function sendSetUpDefencesEvent(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/sendSetUpDefencesEvent";
    sendjson(data,url);
}
//发送撤防事件消息
function sendSetDownDefencesEvent(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/sendSetDownDefencesEvent";
    sendjson(data,url);
}
//发送低档高速报警事件消息
function sendLowGearHighSpeedEvent(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/sendLowGearHighSpeedEvent";
    sendjson(data,url);
}
//发送高档低速报警事件消息
function sendHighGearLowSpeedEvent(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/sendHighGearLowSpeedEvent";
    sendjson(data,url);
}
//发送剩余油量异常告警事件消息
function sendSurplusOilAlarmEvent(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/sendSurplusOilAlarmEvent";
    sendjson(data,url);
}
//发送超速告警事件消息
function sendOverSpeedEvent(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/sendOverSpeedAlarmEvent";
    sendjson(data,url);
}
//发送疲劳驾驶告警事件消息
function sendTiredDrivingAlarmEvent(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/sendTiredDrivingAlarmEvent";
    sendjson(data,url);
}
//怠速过长报警
function sendIdlingOverTimeEvent(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/sendIdlingOverTimeEvent";
    sendjson(data,url);
}
//怠速过长报警(解除)
function sendIdlingOverTimeOverEvent(){
    var data = getPageData()
    url = "/protocolTools/M_carSimulater_process/sendIdlingOverTimeOverEvent";
    sendjson(data,url);
}

// -------------------------------- 实时控制js代码-------------------------------------------
//设置隐藏或显示实时控制区域
function isShowRealTimeCtrArea(e){
    var value = $(e).val()
    if(value == "0"){
        $("#realTimeCtl_area").css("display","none")
    }else{
        $("#realTimeCtl_area").css("display","block")
    }
}
//改变车速
function changeSpeed(){
    var data = {}
    var carId = $("#carId").val()
    var speed = $("#change_speed").val()
    data["carId"] = carId
    data["speed"] = speed
    //会话session数据
    data["session"] = {}
    var sessionId = $("#curSession").val()
    data["session"]["sessionId"] = sessionId
    url = "/protocolTools/M_carSimulater_process/changeCarSpeed";
    $("#carSpeed").val(speed)
    sendjson(data,url);
}
//改变油耗
function changeOilExpend(){
    var data = {}
    var carId = $("#carId").val()
    var oilExpend = $("#change_oilExpend").val()
    data["carId"] = carId
    data["oilExpend"] = oilExpend
    //会话session数据
    data["session"] = {}
    var sessionId = $("#curSession").val()
    data["session"]["sessionId"] = sessionId
    url = "/protocolTools/M_carSimulater_process/changeOilExpend";
    sendjson(data,url);
}
//改变发动机转速
function changeEngineSpeed(){
    var data = {}
    var carId = $("#carId").val()
    var engineSpeed = $("#change_engineSpeed").val()
    data["carId"] = carId
    data["engineSpeed"] = engineSpeed
    //会话session数据
    data["session"] = {}
    var sessionId = $("#curSession").val()
    data["session"]["sessionId"] = sessionId
    url = "/protocolTools/M_carSimulater_process/changeEngineSpeed";
    sendjson(data,url);
}
//改变发送间隔
function changeDurTime(){
    var data = {}
    var carId = $("#carId").val()
    var durTime = $("#change_durTime").val()
    data["carId"] = carId
    data["durTime"] = durTime
    //会话session数据
    data["session"] = {}
    var sessionId = $("#curSession").val()
    data["session"]["sessionId"] = sessionId
    $("#durTime").val(durTime)
    url = "/protocolTools/M_carSimulater_process/changeDurTime";
    sendjson(data,url);
}
//改变剩余油耗
function changeSurplusOil(){
    var data = {}
    var carId = $("#carId").val()
    var surplusOil = parseInt(parseFloat($("#change_surplusOil").val()) * 10)
    data["carId"] = carId
    data["surplusOil"] = surplusOil
    //会话session数据
    data["session"] = {}
    var sessionId = $("#curSession").val()
    data["session"]["sessionId"] = sessionId
    url = "/protocolTools/M_carSimulater_process/changeSurplusOil";
    sendjson(data,url);
}
//控制发送数据是否保存到本地
function storeMsg(){
    var butTxt = $("#storeMsgBut").text()
    if(butTxt == "存储上报消息"){
        var data = {}
        var carId = $("#carId").val()
        data["carId"] = carId
        data["sendType"] = 1
        //会话session数据
        data["session"] = {}
        var sessionId = $("#curSession").val()
        data["session"]["sessionId"] = sessionId
        url = "/protocolTools/M_carSimulater_process/controlStoreMsg";
        var host = window.location.host;
        $.ajax({
            //url:"http://" + host + "/protocolTools/M_carSimulater_process/porcessSocketSetting",
            url:"http://" + host + url,
            type:"post",
            data:JSON.stringify(data),
            contentType:"application/json",
            dataType:"json",
            success:function(data){
                if(data.status == 200){
                    $("#storeMsgBut").text("取消存储上报消息")
                    $("#storeMsgLab").text("存储中...")
                    var curTime = getCurTime();
                    var txt = $("#showFeedback").val()
                    txt = txt + "[" + curTime + "] " + data.message + "\n"
                    $("#showFeedback").val(txt)
                }else{
                    var curTime = getCurTime();
                    var txt = $("#showFeedback").val()
                    txt = txt + "[" + curTime + "] " + data.message + "\n"
                    $("#showFeedback").val(txt)
                    alert(data.message);
                }
            }
        });
    }else{
        var data = {}
        var carId = $("#carId").val()
        data["carId"] = carId
        data["sendType"] = 0
        //会话session数据
        data["session"] = {}
        var sessionId = $("#curSession").val()
        data["session"]["sessionId"] = sessionId
        url = "/protocolTools/M_carSimulater_process/controlStoreMsg";
        var host = window.location.host;
        $.ajax({
            //url:"http://" + host + "/protocolTools/M_carSimulater_process/porcessSocketSetting",
            url:"http://" + host + url,
            type:"post",
            data:JSON.stringify(data),
            contentType:"application/json",
            dataType:"json",
            success:function(data){
                if(data.status == 200){
                    $("#storeMsgBut").text("存储上报消息")
                    $("#storeMsgLab").text("未存储...")
                    //window.location.reload()
                    var curTime = getCurTime();
                    var txt = $("#showFeedback").val()
                    txt = txt + "[" + curTime + "] " + data.message + "\n"
                    $("#showFeedback").val(txt)
                }else{
                    var curTime = getCurTime();
                    var txt = $("#showFeedback").val()
                    txt = txt + "[" + curTime + "] " + data.message + "\n"
                    $("#showFeedback").val(txt)
                    alert(data.message);
                }
            }
        });
    }
}
//控制GPS是否有效
function changeGPSValid(e){
    var data = {}
    var carId = $("#carId").val()
    var GPSValid = $(e).val()
    data["carId"] = carId
    data["GPSValid"] = GPSValid
    //会话session数据
    data["session"] = {}
    var sessionId = $("#curSession").val()
    data["session"]["sessionId"] = sessionId
    url = "/protocolTools/M_carSimulater_process/controlGPSValid";
    sendjson(data,url);
}
//控制经纬度为0还是正常
function changeLngLatIsOk(e){
    var data = {}
    var carId = $("#carId").val()
    var lngLatIsOk = $(e).val()
    data["carId"] = carId
    data["lngLatIsOk"] = lngLatIsOk
    //会话session数据
    data["session"] = {}
    var sessionId = $("#curSession").val()
    data["session"]["sessionId"] = sessionId
    url = "/protocolTools/M_carSimulater_process/controlLngLatIsOk";
    sendjson(data,url);
}
//改变行驶方向
function changeTravelDirection(){
    var data = {}
    var carId = $("#carId").val()
    data["carId"] = carId
    //会话session数据
    data["session"] = {}
    var sessionId = $("#curSession").val()
    data["session"]["sessionId"] = sessionId
    url = "/protocolTools/M_carSimulater_process/changeTravelDirection";
    sendjson(data,url);
}
//改变电瓶电压
function changeVoltage(){
    var data = {}
    var carId = $("#carId").val()
    data["carId"] = carId
    //会话session数据
    data["session"] = {}
    data["other"] = {}
    var sessionId = $("#curSession").val()
    var voltage = $("#change_voltage").val()
    data["session"]["sessionId"] = sessionId
    data["other"]["voltage"] = voltage
    url = "/protocolTools/M_carSimulater_process/changeValtage";
    sendjson(data,url);
}
//控制是否固定在当前位置
function fixCurPosition(e){
    var butTxt = $(e).text()
    if(butTxt == "固定在当前位置"){
        var data = {}
        var carId = $("#carId").val()
        data["carId"] = carId
        data["fixPosition"] = 1
        //会话session数据
        data["session"] = {}
        var sessionId = $("#curSession").val()
        data["session"]["sessionId"] = sessionId
        url = "/protocolTools/M_carSimulater_process/fixCurPosition";
        var host = window.location.host;
        sendjson(data,url);
        $(e).text("取消固定在当前位置")
    }else{
        var data = {}
        var carId = $("#carId").val()
        data["carId"] = carId
        data["fixPosition"] = 0
        //会话session数据
        data["session"] = {}
        var sessionId = $("#curSession").val()
        data["session"]["sessionId"] = sessionId
        url = "/protocolTools/M_carSimulater_process/fixCurPosition";
        var host = window.location.host;
        sendjson(data,url);
        $(e).text("固定在当前位置")
    }
}
// -------------------------------- 其他操作js代码-------------------------------------------
//设置隐藏或显示其他操作区域
function isShowOtheroperCtrArea(e){
    var value = $(e).val()
    if(value == "0"){
        $("#other_area").css("display","none")
    }else{
        $("#other_area").css("display","block")
    }
}
//发送故障码
function sendTroubleCode(){
    var data = {}
    var carId = $("#carId").val()
    data["carId"] = carId
    //会话session数据
    data["session"] = {}
    data["troubleCode"] = {}
    var sessionId = $("#curSession").val()
    data["session"]["sessionId"] = sessionId
    var troubleCodeNum = parseInt($("#troubleCodeNum").val())
    var systemId = $("#systemId").val()
    var status = $("#status").val()
    var troubleCode = []
    for(var i = 0;i < troubleCodeNum;i++){
        var temp = {}
        temp["systemId"] = systemId
        temp["content1"] = "00"
        temp["content2"] = "0" + (i + 1)
        temp["status"] = status
        troubleCode.push(temp)
    }
    var MILStatus = $("#MILStatus").val()
    data["troubleCode"]["troubleCodeNum"] = troubleCodeNum;
    data["troubleCode"]["troubleCode"] = troubleCode;
    data["troubleCode"]["MILStatus"] = MILStatus;
    url = "/protocolTools/M_carSimulater_process/porcessTroubleCodeMsg";
    sendjson(data,url);

}
</script>
    {% endblock %}
</div>
{% endblock %}