#include <stdio.h>
#include <inttypes.h>
#include <stdint.h>
#include "NVS_Test.h"

uint8_t CAN_Received = 0U;
uint32_t testnumhaha = 0U;
uint32_t LastNum = 0U;
uint32_t LastLastNum = 0U;
uint32_t ZhiXingCiShu = 0U;
uint8_t g_NVSTestStatus = 0U;
uint32_t NVSTestCountRead[1] = {0};
uint32_t BenCiXieRu[1] = {0};
uint32_t BenCiXieRuNum = 0U;
uint8_t ErrNum = 1U;
uint8_t ErrNumDisplay = 0U;
uint32_t ZhiXingCiShuDisplay = 0U;
uint8_t NVSReadInit = 0U;

void NVS_Init(void)
{
    CAN_Received = 0U;
    testnumhaha = 0U;
    LastNum = 0U;
    LastLastNum = 0U;
    ZhiXingCiShu = 0U;
    g_NVSTestStatus = 0U;
    NVSTestCountRead[0] = 0U;
    BenCiXieRu[0] = 0U;
    BenCiXieRuNum = 0U;
    ErrNum = 1U;
    ErrNumDisplay = 0U;
    ZhiXingCiShuDisplay = 0U;
    NVSReadInit = 0U;
}

void NVS_Test_Max_Write(void)
{
    uint32_t oeooeoe = 0u;

    // NVS_READ_And_Write_Record(2727U, BenCiXieRu, 4U, NVS_WRITE);
    EEPROM_Write_Data(EEPROM_BLOCK_UDS_FLAG, BenCiXieRu,1);

    oeooeoe = BenCiXieRu[0];

    printf("本次写入值为：%X\n\r",oeooeoe);

}

void NVS_Test_Max_Read(void)
{
    uint32_t duqudeshuju = 0u;

    // NVS_READ_And_Write_Record(2727U, NVSTestCountRead, 4U, NVS_READ);
    EEPROM_Read_Data(EEPROM_BLOCK_UDS_FLAG, NVSTestCountRead,1);

    duqudeshuju = NVSTestCountRead[0];

    printf("读取到的值为：%X\n\r",duqudeshuju);

}


// st_TestNVS_t TestNVSArray;
void NVS_Test_Max_Service(void)
{
    /*此处放从can接收的信号值*/

    if (BenCiXieRu[0] == 0U)
    {
        ;
    }
    else 
    {
        if(CAN_Received == 1U)
        {
            if((BenCiXieRu[0] == 0xFFFFEEEEU) && (ZhiXingCiShu == 0xFFFFEEEEU))
            {
                /*重发当前存储的值*/
                printf("**************jie shou dao qing qiu chong fa ********************\n\r");
                NVS_Test_Max_Read();

                printf("--------------qing qiu chong fa success --------------------\n\r");
                // stRS485TxData[RS485_Tx_ID60_Idx].u8TxEnable = 1;
                // R485_Received = 0U;
            }
            else 
            {
                NVS_Test_Max_Read();
                printf("zhi xing ci shu No. %d, du qu dao de zhi wei: %x \n\r",ZhiXingCiShu , NVSTestCountRead[0]);

                NVS_Test_Max_Write();
                printf("zhi xing ci shu No. %d, cheng gong xie ru de zhi wei: %x \n\r",ZhiXingCiShu , BenCiXieRu[0]);

            }

            CAN_Received = 2U;
        }
    }
}

