243 lines
9.1 KiB
C
243 lines
9.1 KiB
C
/**
|
|
******************************************************************************
|
|
* @file dflash_sbs.c
|
|
* @author AMG Energy Solution Team
|
|
* @version V1.0.0
|
|
* @date 07-Feb-2022
|
|
* @brief This file provides all the codes of system parameter functions.
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
|
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
|
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
|
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
|
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
|
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
|
*
|
|
* <h2><center>© COPYRIGHT 2022 AMG</center></h2>
|
|
******************************************************************************
|
|
*/
|
|
|
|
/** @addtogroup mBMS2
|
|
* @{
|
|
*/
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "includes.h"
|
|
#include "dflash_sbs.h"
|
|
#include "console.h"
|
|
#include "asutil.h"
|
|
#include "device_param.h"
|
|
|
|
#ifdef CONSOLE_DEBUG
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
/* Private define ------------------------------------------------------------*/
|
|
/* Private macro -------------------------------------------------------------*/
|
|
/* Private variables ---------------------------------------------------------*/
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
uint8_t SSet_SbsCfg(uint8_t *text, uint8_t aDevice);
|
|
|
|
/* Private functions ---------------------------------------------------------*/
|
|
|
|
/* Command processing in SETTING STATE */
|
|
int8_t Process_DataSBSSet(uint8_t *text, uint16_t size)
|
|
{
|
|
uint16_t i, ret;
|
|
|
|
/* Invalid command if space is in first position */
|
|
if (size > 1) {if (text[1] != ' ') return(0);}
|
|
text[size] = 0x00;
|
|
ret = 1;
|
|
|
|
switch (text[0])
|
|
{
|
|
case 'o': /* Switch to operating mode */
|
|
screenmode = OP_MODE;
|
|
ViewScreen();
|
|
break;
|
|
case 's': /* Switch to setting status */
|
|
screenmode = SET_MODE;
|
|
ViewScreen();
|
|
break;
|
|
case 'd': /* Switch to diagnostic mode */
|
|
screenmode = DIAG_MODE;
|
|
ViewScreen();
|
|
break;
|
|
case '1': // SBS Data Parameter Setting
|
|
i = SSet_SbsCfg(&text[2],text[0]);
|
|
if (i == 0)
|
|
UserMessage("COMMAND COMPLETE");
|
|
else if (i == 1)
|
|
UserMessage("COMMAND FORMAT ERROR"); /* setting format error */
|
|
else
|
|
UserMessage("COMMAND LIMIT ERROR"); /* setting limit error */
|
|
break;
|
|
case 'I':
|
|
SBS_InitData();
|
|
Save_Param();
|
|
break;
|
|
default :
|
|
ret = 0;
|
|
break;
|
|
}
|
|
|
|
return(ret);
|
|
}
|
|
|
|
uint8_t SSet_SbsCfg(uint8_t *text, uint8_t aDevice)
|
|
{
|
|
uint16_t size, i, j;
|
|
int16_t aParam[4];
|
|
uint8_t temp[10];
|
|
uint8_t ret;
|
|
uint8_t cmd;
|
|
|
|
ret = 0;
|
|
size = 0;
|
|
|
|
while (text[size] != 0x00) size++; /* Measure total string length */
|
|
|
|
switch (aDevice)
|
|
{
|
|
case '1': // Data
|
|
i = 0;
|
|
if (size < 2 ) return(1);
|
|
|
|
j = FIND_CHAR((uint8_t *)&text[i], temp, size - i, ' ');
|
|
i = i + j + 1;
|
|
temp[j] = 0x00;
|
|
cmd = temp[0];
|
|
|
|
j = FIND_CHAR((uint8_t *)&text[i], temp, size - i, ' ');
|
|
i = i + j + 1;
|
|
temp[j] = 0x00;
|
|
|
|
switch (cmd)
|
|
{
|
|
case '1': aParam[0] = strtohex((char *)temp, j); break; /* Hex Value */
|
|
case '2': aParam[0] = StrToInt(temp, j); break; /* Int Value */
|
|
case '3': aParam[0] = strtohex((char *)temp, j); break; /* Hex Value */
|
|
case '4': aParam[0] = strtohex((char *)temp, j); break; /* Hex Value */
|
|
case '5': aParam[0] = strtohex((char *)temp, j); break; /* Hex Value */
|
|
case '6': aParam[0] = StrToInt(temp, j); break; /* Int Value */
|
|
case '7': aParam[0] = StrToInt(temp, j); break; /* Int Value */
|
|
case '8': aParam[0] = StrToInt(temp, j); break; /* Int Value */
|
|
case '9': aParam[0] = StrToInt(temp, j); break; /* Int Value */
|
|
case 'a': aParam[0] = StrToInt(temp, j); break; /* Int Value */
|
|
}
|
|
|
|
switch (cmd)
|
|
{
|
|
case '1': device_param.sbs.data.System_ID = aParam[0]; break;
|
|
case '2': device_param.sbs.data.Design_Voltage = aParam[0]; break;
|
|
case '3': device_param.sbs.data.Spec_Info = aParam[0]; break;
|
|
case '4': device_param.sbs.data.Manuf_Date = aParam[0]; break;
|
|
case '5': device_param.sbs.data.Ser_Num = aParam[0]; break;
|
|
case '6': device_param.sbs.data.Cycle_Count = aParam[0]; break;
|
|
case '7': device_param.sbs.data.CC_Threshold = aParam[0]; break;
|
|
case '8': device_param.sbs.data.Design_Capacity = aParam[0]; break;
|
|
case '9': device_param.sbs.data.Design_Energy = aParam[0]; break;
|
|
case 'a': device_param.sbs.data.Full_Charge_Capacity = aParam[0]; break;
|
|
default : return (1);
|
|
}
|
|
Save_Param();
|
|
break;
|
|
default:
|
|
ret = 1;
|
|
break;
|
|
}
|
|
return(ret); /* Setting value OK */
|
|
}
|
|
|
|
void SBSDisplayData(uint8_t p)
|
|
{
|
|
uint8_t text[20];
|
|
|
|
// Initial_Battery_Mode (Offset 0)
|
|
if (p || (dis_device_param.sbs.data.System_ID != device_param.sbs.data.System_ID)) {
|
|
sprintf((char *)text, "%04X", device_param.sbs.data.System_ID);
|
|
GreenOutXY(20, 3, text);
|
|
dis_device_param.sbs.data.System_ID = device_param.sbs.data.System_ID;
|
|
}
|
|
// Initial_Battery_Mode (Offset 2)
|
|
if (p || (dis_device_param.sbs.data.Design_Voltage != device_param.sbs.data.Design_Voltage)) {
|
|
sprintf((char *)text, "%5d", device_param.sbs.data.Design_Voltage);
|
|
GreenOutXY(19, 4, text);
|
|
dis_device_param.sbs.data.Design_Voltage = device_param.sbs.data.Design_Voltage;
|
|
}
|
|
// Spec_Info (Offset 4)
|
|
if (p || (dis_device_param.sbs.data.Spec_Info != device_param.sbs.data.Spec_Info)) {
|
|
sprintf((char *)text, "%04X", device_param.sbs.data.Spec_Info);
|
|
GreenOutXY(20, 5, text);
|
|
dis_device_param.sbs.data.Spec_Info = device_param.sbs.data.Spec_Info;
|
|
}
|
|
// Manuf_Date (Offset 6)
|
|
if (p || (dis_device_param.sbs.data.Manuf_Date != device_param.sbs.data.Manuf_Date)) {
|
|
sprintf((char *)text, "%04X", device_param.sbs.data.Manuf_Date);
|
|
GreenOutXY(20, 6, text);
|
|
dis_device_param.sbs.data.Manuf_Date = device_param.sbs.data.Manuf_Date;
|
|
}
|
|
// Ser_Num (Offset 8)
|
|
if (p || (dis_device_param.sbs.data.Ser_Num != device_param.sbs.data.Ser_Num)) {
|
|
sprintf((char *)text, "%04X", device_param.sbs.data.Ser_Num);
|
|
GreenOutXY(20, 7, text);
|
|
dis_device_param.sbs.data.Ser_Num = device_param.sbs.data.Ser_Num;
|
|
}
|
|
// Cycle_Count (Offset 10)
|
|
if (p || (dis_device_param.sbs.data.Cycle_Count != device_param.sbs.data.Cycle_Count)) {
|
|
sprintf((char *)text, "%5d", device_param.sbs.data.Cycle_Count);
|
|
GreenOutXY(19, 8, text);
|
|
dis_device_param.sbs.data.Cycle_Count = device_param.sbs.data.Cycle_Count;
|
|
}
|
|
// CC_Threshold (Offset 12)
|
|
if (p || (dis_device_param.sbs.data.CC_Threshold != device_param.sbs.data.CC_Threshold)) {
|
|
sprintf((char *)text, "%5d", device_param.sbs.data.CC_Threshold);
|
|
GreenOutXY(19, 9, text);
|
|
dis_device_param.sbs.data.CC_Threshold = device_param.sbs.data.CC_Threshold;
|
|
}
|
|
// Design_Capacity (Offset 16)
|
|
if (p || (dis_device_param.sbs.data.Design_Capacity != device_param.sbs.data.Design_Capacity)) {
|
|
sprintf((char *)text, "%6.2f", (float)device_param.sbs.data.Design_Capacity / 100);
|
|
GreenOutXY(18, 10, text);
|
|
dis_device_param.sbs.data.Design_Capacity = device_param.sbs.data.Design_Capacity;
|
|
}
|
|
// Design_Energy (Offset 18)
|
|
if (p || (dis_device_param.sbs.data.Design_Energy != device_param.sbs.data.Design_Energy)) {
|
|
sprintf((char *)text, "%7d", device_param.sbs.data.Design_Energy);
|
|
GreenOutXY(17, 11, text);
|
|
dis_device_param.sbs.data.Design_Energy = device_param.sbs.data.Design_Energy;
|
|
}
|
|
// Full_Charge_Capacity (Offset 20)
|
|
if (p || (dis_device_param.sbs.data.Full_Charge_Capacity != device_param.sbs.data.Full_Charge_Capacity)) {
|
|
sprintf((char *)text, "%6.2f", (float)device_param.sbs.data.Full_Charge_Capacity / 100);
|
|
GreenOutXY(18, 12, text);
|
|
dis_device_param.sbs.data.Full_Charge_Capacity = device_param.sbs.data.Full_Charge_Capacity;
|
|
}
|
|
}
|
|
|
|
void SBSDisplay(uint8_t p)
|
|
{
|
|
SBSDisplayData(p);
|
|
}
|
|
|
|
#endif // #ifdef CONSOLE_DEBUG
|
|
|
|
void SBS_InitData(void)
|
|
{
|
|
device_param.sbs.data.System_ID = 1;
|
|
device_param.sbs.data.Design_Voltage = 48000;
|
|
device_param.sbs.data.Spec_Info = 0x0000;
|
|
device_param.sbs.data.Manuf_Date = 0;
|
|
device_param.sbs.data.Ser_Num = 0;
|
|
device_param.sbs.data.Cycle_Count = 0;
|
|
|
|
device_param.sbs.data.CC_Threshold = 10000;
|
|
device_param.sbs.data.Design_Capacity = 10000;
|
|
device_param.sbs.data.Design_Energy = 0;
|
|
device_param.sbs.data.Full_Charge_Capacity = 10000;
|
|
}
|
|
|
|
/*******************(C)COPYRIGHT 2022 AMG ********************END OF FILE******/
|