Data_TPMS.c 15.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
#include "Application.h"
#include "Data_TPMS\Data_TPMS.h"

_TPMS_Display TPMS;
uint32_t LearnTime_Count = 0;
uint32_t LearnTime_Count1 = 0;
void Data_TPMS_KL30_Init ( void )
{
    uint8_t TPMS_L[2] = {0,0};
    Data_User_EEPROM_Read(EM_MenuData_TPMS_LEARN, (uint32_t*)TPMS_L, 1u);
    MenuData.TPMS_Front_Learn = TPMS_L[0];
    MenuData.TPMS_Rear_Learn  = TPMS_L[1];
    //MenuData.TPMS_Front_FirstLearn_Flag = TPMS_L[2];
    //MenuData.TPMS_Rear_FirstLearn_Flag  = TPMS_L[3];
    TPMS.Front_Press_Value = 0;
    TPMS.Rear_Press_Value  = 0;

    TPMS.Front_TPMS_Valid  = 0;
    TPMS.Rear_TPMS_Valid   = 0;
    TPMS.TPMS_Warning      = 0;
    TPMS.TPMS_Unit         = Get_Dis_Tpms_Unit();
    TPMS.TPMS_Front_Learn  = MenuData.TPMS_Front_Learn;
    TPMS.TPMS_Rear_Learn   = MenuData.TPMS_Rear_Learn;
    TPMS.TPMS_Front_FirstLearn_Flag  = MenuData.TPMS_Front_FirstLearn_Flag;
    TPMS.TPMS_Rear_FirstLearn_Flag   = MenuData.TPMS_Rear_FirstLearn_Flag;

    TPMS.TPMS_LOST = 0;
    LearnTime_Count = 6001;
    LearnTime_Count1 = 6001;
}
void Data_TPMS_KL15_WAKE_UP_Init ( void )
{
    uint8_t TPMS_L[2] = {0,0};
    Data_User_EEPROM_Read(EM_MenuData_TPMS_LEARN, (uint32_t*)TPMS_L, 1);
    MenuData.TPMS_Front_Learn = TPMS_L[0];
    MenuData.TPMS_Rear_Learn  = TPMS_L[1];
    //MenuData.TPMS_Front_FirstLearn_Flag = TPMS_L[2];
    //MenuData.TPMS_Rear_FirstLearn_Flag  = TPMS_L[3];
    TPMS.TPMS_Front_Learn     = MenuData.TPMS_Front_Learn;
    TPMS.TPMS_Rear_Learn      = MenuData.TPMS_Rear_Learn;
    TPMS.TPMS_Front_FirstLearn_Flag  = MenuData.TPMS_Front_FirstLearn_Flag;
    TPMS.TPMS_Rear_FirstLearn_Flag   = MenuData.TPMS_Rear_FirstLearn_Flag;

    TPMS.TPMS_LOST = 0;
    LearnTime_Count = 6001;
    LearnTime_Count1 = 6001;
}

void Data_TPMS_Processing_Service ( void )
{
    uint16_t Front_TPMS = 0;
    uint16_t Rear_TPMS  = 0;
    uint8_t  TPMS_L[2] = {0,0};
    
    if(CAN_MSG_Status(&CAN_CH0_CanMsgOp, CAN_CH0_ID_CAN_0x341_Msg_Count) != CAN_SIG_LOST) 
    {
        TPMS.TPMS_Front_Learn = Get_CAN_CH0_ID_341_Sig_Front_LearningStatus();
        TPMS.TPMS_Rear_Learn = Get_CAN_CH0_ID_341_Sig_Rear_LearningStatus();
        TPMS.TPMS_LOST = 1;
    }
    else
    {
        TPMS.TPMS_Front_Learn = MenuData.TPMS_Front_Learn;
        TPMS.TPMS_Rear_Learn = MenuData.TPMS_Rear_Learn;
        TPMS.TPMS_LOST = 0;
    }
       
    
    if(TPMS.TPMS_Front_Learn == 0x0)
    {        
        if(LearnTime_Count <= 6000)
        {
            LearnTime_Count++;
            TPMS.TPMS_Front_Learn = Unstudied;
        }
        else
        {
            if(TPMS.TPMS_Front_Timeclean == 1)
            {
                LearnTime_Count = 0;
            }
            TPMS.TPMS_Front_Timeclean = 0;  
            if ((MenuData.TPMS_Front_Learn != 0x2) && (MenuData.TPMS_Front_Learn != 0x3) ) 
            {
                if(CAN_MSG_Status(&CAN_CH0_CanMsgOp, CAN_CH0_ID_CAN_0x341_Msg_Count) != CAN_SIG_LOST) 
                {
                    TPMS.TPMS_Front_Learn = LearningFailure;
                }
                else
                {
                    TPMS.TPMS_Front_Learn = MenuData.TPMS_Front_Learn;
                }
                
            }
            else
            {
                TPMS.TPMS_Front_Learn = MenuData.TPMS_Front_Learn;
            }
        }
    }
    else if(TPMS.TPMS_Front_Learn == 0x1)
    { 
        if(TPMS.TPMS_Front_Timeclean == 0)
        {
            LearnTime_Count = 0;
        }
        TPMS.TPMS_Front_Timeclean = 1;        
        if(LearnTime_Count <= 6000)
        {
            LearnTime_Count++;
            TPMS.TPMS_Front_Learn = Learning;
        }
        else
        {
            if ((MenuData.TPMS_Front_Learn != 0x2) && (MenuData.TPMS_Front_Learn != 0x3) ) 
            {
                if(CAN_MSG_Status(&CAN_CH0_CanMsgOp, CAN_CH0_ID_CAN_0x341_Msg_Count) != CAN_SIG_LOST) 
                {
                    TPMS.TPMS_Front_Learn = LearningFailure;
                }
                else
                {
                    TPMS.TPMS_Front_Learn = MenuData.TPMS_Front_Learn;
                }
            }
            else
            {
                TPMS.TPMS_Front_Learn = MenuData.TPMS_Front_Learn;
            }
        }
    }
    else if (TPMS.TPMS_Front_Learn == 0x2)
    {
        LearnTime_Count = 0;
        if((Get_CAN_CH0_ID_373_Sig_Front_id() != 0) && (Get_CAN_CH0_ID_373_Sig_Front_id() != 0xFFFFFFFF))
        {
            TPMS.TPMS_Front_Learn = LearningCompletion;
        }
        else
        {
            ;
        }
        
    }
    else if (TPMS.TPMS_Front_Learn == 0x3)
    {
        LearnTime_Count = 0;
        TPMS.TPMS_Front_Learn = LearningFailure;
    }
    else
    {
        LearnTime_Count = 0;
        TPMS.TPMS_Front_Learn = MenuData.TPMS_Front_Learn;
    }

    if(TPMS.TPMS_Rear_Learn == 0x0)
    {        
        if(LearnTime_Count1 <= 6000)
        {
            LearnTime_Count1++;
            TPMS.TPMS_Rear_Learn = Unstudied;
        }
        else
        {
            if(TPMS.TPMS_Rear_Timeclean == 1)
            {
                LearnTime_Count1 = 0;
            }
            TPMS.TPMS_Rear_Timeclean = 0; 
            if ((MenuData.TPMS_Rear_Learn != 0x2) && (MenuData.TPMS_Rear_Learn != 0x3) ) 
            {
                if(CAN_MSG_Status(&CAN_CH0_CanMsgOp, CAN_CH0_ID_CAN_0x341_Msg_Count) != CAN_SIG_LOST) 
                {
                    TPMS.TPMS_Rear_Learn = LearningFailure;
                }
                else
                {
                    TPMS.TPMS_Rear_Learn = MenuData.TPMS_Rear_Learn;
                }
            }
            else
            {
                TPMS.TPMS_Rear_Learn = MenuData.TPMS_Rear_Learn;
            }
        }
    }
    else if(TPMS.TPMS_Rear_Learn == 0x1)
    {        
        if(LearnTime_Count1 <= 6000)
        {
            LearnTime_Count1++;
            TPMS.TPMS_Rear_Learn = Learning;
        }
        else
        {
            if(TPMS.TPMS_Rear_Timeclean == 0)
            {
                LearnTime_Count1 = 0;
            }
            TPMS.TPMS_Rear_Timeclean = 1; 
            if ((MenuData.TPMS_Rear_Learn != 0x2) && (MenuData.TPMS_Rear_Learn != 0x3) )
            {
                if(CAN_MSG_Status(&CAN_CH0_CanMsgOp, CAN_CH0_ID_CAN_0x341_Msg_Count) != CAN_SIG_LOST) 
                {
                    TPMS.TPMS_Rear_Learn = LearningFailure;
                }
                else
                {
                    TPMS.TPMS_Rear_Learn = MenuData.TPMS_Rear_Learn;
                }
            }
            else
            {
                TPMS.TPMS_Rear_Learn = MenuData.TPMS_Rear_Learn;
            }
        }
    }
    else if (TPMS.TPMS_Rear_Learn == 0x2)
    {
        LearnTime_Count1 = 0;
        if((Get_CAN_CH0_ID_373_Sig_Rear_id() != 0) && (Get_CAN_CH0_ID_373_Sig_Rear_id() != 0xFFFFFFFF))
        {
            TPMS.TPMS_Rear_Learn = LearningCompletion;
        }
        else
        {
            ;
        }
        
    }
    else if (TPMS.TPMS_Rear_Learn == 0x3)
    {
        LearnTime_Count1 = 0;
        TPMS.TPMS_Rear_Learn = LearningFailure;
    }
    else
    {
        LearnTime_Count1 = 0;
        TPMS.TPMS_Rear_Learn = MenuData.TPMS_Front_Learn;
    }
    

    if((TPMS.TPMS_Front_Learn != MenuData.TPMS_Front_Learn) || (TPMS.TPMS_Rear_Learn != MenuData.TPMS_Rear_Learn))
    {
        if(TPMS.TPMS_Front_Learn != MenuData.TPMS_Front_Learn)
        {
            TPMS.TPMS_Front_FirstLearn_Flag = 1;
        }
        if(TPMS.TPMS_Rear_Learn != MenuData.TPMS_Rear_Learn)
        {
            TPMS.TPMS_Rear_FirstLearn_Flag = 1;
        }
         
        if((TPMS.TPMS_Front_Learn == 0x2) || (TPMS.TPMS_Front_Learn == 0x3))
        {
            MenuData.TPMS_Front_Learn = TPMS.TPMS_Front_Learn;
        }
        if((TPMS.TPMS_Rear_Learn == 0x2) || (TPMS.TPMS_Rear_Learn == 0x3))
        {
            MenuData.TPMS_Rear_Learn  = TPMS.TPMS_Rear_Learn;
        }
        if((TPMS.TPMS_Front_Learn == 0x2) || (TPMS.TPMS_Front_Learn == 0x3) || (TPMS.TPMS_Rear_Learn == 0x2) || (TPMS.TPMS_Rear_Learn == 0x3))
        {
            TPMS_L[0] = MenuData.TPMS_Front_Learn;
            TPMS_L[1] = MenuData.TPMS_Rear_Learn;            
            Data_User_EEPROM_Write(EM_MenuData_TPMS_LEARN, (uint32_t*)TPMS_L, 1u); 
            
        }
        
    }

    TPMS.TPMS_Unit      = Get_Dis_Tpms_Unit();
    Front_TPMS          = Get_CAN_CH0_ID_341_Sig_Front_Pressure();
    Rear_TPMS           = Get_CAN_CH0_ID_341_Sig_Rear_Pressure();

    if ( Common_Get_IG_Sts() == COMMON_POWER_ON )
    {
        if(CAN_MSG_Status(&CAN_CH0_CanMsgOp, CAN_CH0_ID_CAN_0x341_Msg_Count) == CAN_SIG_LOST)
        {
            TPMS.Front_TPMS_Valid  = 0;  //信号掉线,显示--
            TPMS.Rear_TPMS_Valid   = 0;  //信号掉线,显示--
            TPMS.Front_Press_Value = 0;
            TPMS.Rear_Press_Value  = 0;
            TPMS.TPMS_Warning      = 0;  //白灯
        }
        else
        {            
            if((Front_TPMS == 0xFF) || (Rear_TPMS == 0xFF))
            {
                
                if((Front_TPMS == 0xFF) && (Rear_TPMS != 0xFF))
                {
                    TPMS.Front_TPMS_Valid  = 0;
                    TPMS.Rear_TPMS_Valid   = 1;
                    TPMS.Front_Press_Value = 990;
                    TPMS.Rear_Press_Value  = Rear_TPMS * 2750;
                    TPMS.Rear_Press_Value  /= 102 ;
                    if(TPMS.Rear_Press_Value > 9900)
                    {
                        TPMS.Rear_Press_Value = 9900;
                    }
                    if(((TPMS.Rear_Press_Value + 50)< 1700) || ((TPMS.Rear_Press_Value + 50) > 2500))
                    {
                        TPMS.TPMS_Warning = 1;
                    }
                    else
                    {
                        TPMS.TPMS_Warning = 0;
                    }
                }
                else if ((Front_TPMS != 0xFF) && (Rear_TPMS == 0xFF))
                {
                    TPMS.Front_TPMS_Valid  = 1;
                    TPMS.Rear_TPMS_Valid   = 0;
                    TPMS.Rear_Press_Value  = 990;
                    TPMS.Front_Press_Value = Front_TPMS *2750 ;
                    TPMS.Front_Press_Value  /= 102 ;
                    if(TPMS.Front_Press_Value > 9900)
                    {
                        TPMS.Front_Press_Value = 9900;
                    }
                    if(((TPMS.Front_Press_Value + 50) < 1700) || ((TPMS.Front_Press_Value + 50) > 2300))
                    {
                        TPMS.TPMS_Warning = 1;
                    }
                    else
                    {
                        TPMS.TPMS_Warning = 0;
                    }
                }
                else
                {
                    TPMS.Front_Press_Value = 9900;
                    TPMS.Rear_Press_Value = 9900;
                    TPMS.TPMS_Warning = 0;
                    TPMS.Front_TPMS_Valid  = 0;
                    TPMS.Rear_TPMS_Valid   = 0;
                }
            }
            else
            {
                TPMS.Front_TPMS_Valid  = 1;
                TPMS.Rear_TPMS_Valid   = 1;
                TPMS.Front_Press_Value = Front_TPMS * 2750 ;                
                TPMS.Front_Press_Value  /= 102 ;
                if(TPMS.Front_Press_Value > 9900)
                {
                    TPMS.Front_Press_Value = 9900;
                }

                TPMS.Rear_Press_Value  = Rear_TPMS * 2750;                
                TPMS.Rear_Press_Value  /= 102 ;
                if(TPMS.Rear_Press_Value > 9900)
                {
                    TPMS.Rear_Press_Value = 9900;
                }
                if (((TPMS.Front_Press_Value + 50) < 1700) || ((TPMS.Front_Press_Value + 50) > 2300) || ((TPMS.Rear_Press_Value + 50) < 1700) || ((TPMS.Rear_Press_Value + 50) > 2500))
                {
                    TPMS.TPMS_Warning = 1;
                }
                else
                {
                    TPMS.TPMS_Warning = 0;
                }
            }
            
        }
        if(TPMS.TPMS_Front_Learn == Unstudied)
        {
            TPMS.TPMS_Front_FirstLearn_Flag = Unstudied;            
        }
        else if(TPMS.TPMS_Front_Learn == Learning)
        {
            TPMS.TPMS_Front_FirstLearn_Flag = Learning;            
        }
        else if(TPMS.TPMS_Front_Learn == LearningCompletion)
        {
            TPMS.TPMS_Front_FirstLearn_Flag = LearningCompletion;
            
        }
        else if(TPMS.TPMS_Front_Learn == LearningFailure)
        {
            TPMS.TPMS_Front_FirstLearn_Flag = LearningFailure;
            TPMS.Front_Press_Value = 9900;
        }
        else
        {
            ;
        }

        if(TPMS.TPMS_Rear_Learn == Unstudied)
        {
            TPMS.TPMS_Rear_FirstLearn_Flag = Unstudied;
        }
        else if(TPMS.TPMS_Rear_Learn == Learning)
        {
            TPMS.TPMS_Rear_FirstLearn_Flag = Learning;
        }
        else if(TPMS.TPMS_Rear_Learn == LearningCompletion)
        {
            TPMS.TPMS_Rear_FirstLearn_Flag = LearningCompletion;
            
        }
        else if(TPMS.TPMS_Rear_Learn == LearningFailure)
        {
            TPMS.TPMS_Rear_FirstLearn_Flag = LearningFailure;
            TPMS.Rear_Press_Value = 9900;
        }
        else
        {
            ;
        }

        //if ((MenuData.TPMS_Rear_Learn != LearningCompletion) && (MenuData.TPMS_Front_Learn != LearningCompletion))
        //{
        //    TPMS.TPMS_Warning = 0;
        //}

    }
    else
    {
        TPMS.Front_TPMS_Valid  = 0;
        TPMS.Rear_TPMS_Valid   = 0; 
        TPMS.Front_Press_Value = 0;
        TPMS.Rear_Press_Value  = 0;
        TPMS.TPMS_Warning      = 0; 
    }
}
uint32_t Data_Bar_To_Psi (uint32_t bar)
{
    uint32_t Bar = 0;
    Bar = bar * 145;
    Bar /= 10;
    //Bar += 5;
    // bar *= 145;
    // bar /= 10;
    // bar += 5;    
    return Bar;
}

/*指示灯报警信号  0:白色常亮   1:黄色常亮*/
uint8_t Get_Led_TPMS_Waring (void)
{
    return TPMS.TPMS_Warning;
}

/*0:无效,常显--  1:有效,按实际胎压数值显示  */
uint8_t Get_Front_TPMS_Sig_Vaild (void)
{
    return TPMS.Front_TPMS_Valid;
}
uint8_t Get_Rear_TPMS_Sig_Vaild (void)
{
    return TPMS.Rear_TPMS_Valid;
}
//10倍
uint16_t Get_Front_TPMS_Sig_Value (void)
{
    uint16_t value = 0;
    if (TPMS.TPMS_Unit == 1)
    {
        value = (Data_Bar_To_Psi(TPMS.Front_Press_Value) + 500) / 1000;
        if(value > 99)
        {
            value = 99;
        }
    }
    else
    {        
        value = TPMS.Front_Press_Value + 50;        
        value = value / 100;
    }
    return value;
}
uint16_t Get_Rear_TPMS_Sig_Value (void)
{
    uint16_t value = 0;
    if (TPMS.TPMS_Unit == 1)
    {
        value = (Data_Bar_To_Psi(TPMS.Rear_Press_Value) + 500) / 1000;
        if(value > 99)
        {
            value = 99;
        }
        
    }
    else
    {        
        value = TPMS.Rear_Press_Value + 50;        
        value = value / 100;        
    }
    return value;    
}
uint16_t Get_Rear_TPMS_TX (void)
{
    uint16_t value = 0;
    value = Data_Bar_To_Psi(TPMS.Rear_Press_Value) / 100;
    if(value > 990)
    {
        value = 990;
    }
    return value;
}
uint16_t Get_Front_TPMS_TX (void)
{
    uint16_t value = 0;
    value = Data_Bar_To_Psi(TPMS.Front_Press_Value) / 100;
    if(value > 990)
    {
        value = 990;
    }
    return value;
}

/*前轮胎压学习结果 0-未学习“--”常显  1-学习中“--”闪烁  2-学习成功,正常显示数值  3-学习失败,闪烁显示最大值99*/
uint8_t Get_Front_FirstLearn_Flag (void)
{
    return TPMS.TPMS_Front_FirstLearn_Flag;
}
/*后轮胎压学习结果 0-未学习“--”常显  1-学习中“--”闪烁  2-学习成功,正常显示数值  3-学习失败,闪烁显示最大值99*/
uint8_t Get_Rear_FirstLearn_Flag (void)
{
    return TPMS.TPMS_Rear_FirstLearn_Flag;
}

/*获取0x341是否掉线  0-掉线  “--”闪烁   1-在线  获取学习结果进行显示*/
uint8_t Get_TPMS_CAN_LOST (void)
{
    return TPMS.TPMS_LOST ;
}