/*
 * DataOperations.c
 *
 * Created: 25.2.2016 0:00:21
 *  Author: Chenda
 */ 

#include <inttypes.h>
#include <stdio.h>
#include <stdbool.h>

#include "DataOperations.h"

/************************************************************************/
/* Public functions                                                     */
/************************************************************************/

void DAT_OPS_MoveData (uint8_t *Src, uint8_t *Trg, uint8_t Len, bool ClrSrc)
{
	for (;Len>0;Len--) {
		*Trg++ = *Src++;
		if (ClrSrc) {
			*(Src-1) = 0;
		}
	}
}

uint8_t DAT_OPS_PutNumber (uint8_t *Buff, int16_t *IntNo, int16_t *TenthNo)
{
	if (Buff != NULL) {
		if (IntNo == NULL) {
			Buff[0] = 0;
			Buff[1] = 0;
		}
		else {
			Buff[0] = (uint8_t)(*IntNo>>8);
			Buff[1] = (uint8_t)(*IntNo>>0);
		}
		if (TenthNo == NULL) {
			Buff[2] = 0;
			Buff[3] = 0;
		}
		else {
			Buff[2] = (uint8_t)(*TenthNo>>8);
			Buff[3] = (uint8_t)(*TenthNo>>0);
		}	
	}
	return 4;
}

void DAT_OPS_GetNumber (uint8_t *Buff, int16_t *IntNo, int16_t *TenthNo)
{
	int16_t TempIntNo = 0;
	int16_t TempTenthNo = 0;
	if (Buff != NULL) {
		TempIntNo = (int16_t)(Buff[0]<<8);
		TempIntNo |= (int16_t)(Buff[1]<<0);
		TempTenthNo = (int16_t)(Buff[2]<<8);
		TempTenthNo |= (int16_t)(Buff[3]<<0);	
	}
	if (IntNo != NULL) {
		*IntNo = TempIntNo;
	}
	if (TenthNo != NULL) {
		*TenthNo = TempTenthNo;
	}
}