/*
 * value_struct.c
 *
 *  Created on: Dec 25, 2024
 *      Author: home
 */

#include "value_struct.h"
#include <stdio.h>
void printBinary(uint8_t byte) {
    for (int i = 7; i >= 0; --i) {
        printf("%d", (byte >> i) & 1);
    }
}
// Определение функции инициализации
void initValueStruct(value_Struct *vStruct) {
    if (vStruct == NULL) {
        return;
    }
    vStruct->HEAD_ID = 0;
    vStruct->CUR_VALUE = 0;
    vStruct->NEW_VALUE = 0;
    vStruct->TRANSACTION = 0;
    vStruct->COUTN_TRANS = 0;
    vStruct->PRINT = 1;

}


// Определение функции печати значений структуры
void printValueStruct(const value_Struct *vStruct) {
    if (vStruct == NULL) {
        return;
    }

    if (vStruct->PRINT == 0) {
            return;
    }
    printf("\n\rCUR_VALUE: %u\n\r", vStruct->CUR_VALUE);
    printf("NEW_VALUE: %u\n\r", vStruct->NEW_VALUE);
    //printf("TRANSACTION: %u\n\r", vStruct->TRANSACTION);
    uint8_t lowByte = vStruct->TRANSACTION & 0xFF;


    printf("TRANSACTION: ");
    printBinary(lowByte);
    printf("\n\r");
    printf("HEAD_ID: %x\n\r", vStruct->HEAD_ID);
    printf("COUTN_TRANS: %u\n\r", vStruct->COUTN_TRANS);

}

void printPackStruct(const pack_CAN *curPack, const pack_CAN *newPack, uint32_t trans) {
    if (newPack == NULL) {
        return;
    }

    printf("CUR_VALUE: %02x %02x %02x %02x %02x %02x %02x %02x\n\r", curPack->x0, curPack->x1, curPack->x2, curPack->x3,curPack->x4, curPack->x5,curPack->x6, curPack->x7);
    printf("NEW_VALUE: %02x %02x %02x %02x %02x %02x %02x %02x\n\r", newPack->x0, newPack->x1, newPack->x2, newPack->x3,newPack->x4, newPack->x5,newPack->x6, newPack->x7);


    //uint8_t lowByte = vStruct->TRANSACTION & 0xFF;


    printf("TRANS: %u\n\r", trans);
    //printBinary(lowByte);
    printf("\n\r");
    //printf("COUTN_TRANS: %u\n\r", trans);

}



