|
@@ -2,7 +2,7 @@
|
|
|
* Module_LcmControl.c
|
|
|
*
|
|
|
* Created on : 2020-10-20
|
|
|
- * Update on : 2021-02-20
|
|
|
+ * Update on : 2021-06-23
|
|
|
* Author : Folus Wen, Eason Yang
|
|
|
* Version : D0.01
|
|
|
*
|
|
@@ -12,6 +12,7 @@
|
|
|
#include "define.h"
|
|
|
#include "main.h"
|
|
|
#include "lcmComm_dgus.h"
|
|
|
+#include "cbmp.h"
|
|
|
|
|
|
//=======================================
|
|
|
// Declare share memory
|
|
@@ -68,7 +69,6 @@ void setEthernetIcon();
|
|
|
void setAlarmCodeAndIcon();
|
|
|
void setBillingFromWebsite();
|
|
|
|
|
|
-
|
|
|
//=======================================
|
|
|
// Declare Timer
|
|
|
//=======================================
|
|
@@ -116,7 +116,7 @@ uint8_t isCharging = YES;
|
|
|
//=======================================
|
|
|
// Record version and date
|
|
|
//=======================================
|
|
|
-char *FIRMWARE_UPDATE_IMAGE[3] = {"V0.17", "2021-04-28", "REV.01.00"};
|
|
|
+char *FIRMWARE_UPDATE_IMAGE[3] = {"V0.18", "2021-06-23", "REV.01.00"};
|
|
|
|
|
|
|
|
|
//=======================================
|
|
@@ -893,7 +893,7 @@ float getPresentFinalCost(uint8_t gun_index)
|
|
|
|
|
|
//=======================================
|
|
|
// Setting billing ( BACKEND )
|
|
|
-//=======================================-
|
|
|
+//=======================================
|
|
|
void setBillingFromBackend(uint8_t gun_index, uint8_t system_mode)
|
|
|
{
|
|
|
if((system("pidof -s OcppBackend > /dev/null") != 0))
|
|
@@ -1562,8 +1562,8 @@ void setBatteryAnimation(uint8_t gun_index, uint8_t system_mode)
|
|
|
{
|
|
|
// SET BATTERY PERCENTAGE TEXT TO DISAPPEAR
|
|
|
setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
|
|
|
-
|
|
|
- if(ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON)
|
|
|
+
|
|
|
+ if((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON))
|
|
|
{
|
|
|
// SET BATTERY ANIMATION
|
|
|
if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_5))
|
|
@@ -1702,7 +1702,8 @@ void setConnectionAnimation(uint8_t gun_index, uint8_t system_mode)
|
|
|
|
|
|
break;
|
|
|
case SYS_MODE_CHARGING:
|
|
|
- if(ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON)
|
|
|
+
|
|
|
+ if((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON))
|
|
|
{
|
|
|
if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
|
|
|
{
|
|
@@ -2061,6 +2062,186 @@ int InitComPort()
|
|
|
return fd;
|
|
|
}
|
|
|
|
|
|
+//=======================================
|
|
|
+// Download image
|
|
|
+//=======================================
|
|
|
+int downloadBMP(uint8_t picIdx, char *filename)
|
|
|
+{
|
|
|
+ int result = PASS;
|
|
|
+ BMP *bmp;
|
|
|
+ struct stat fileSt;
|
|
|
+ uint32_t pageSize = 0xf0;
|
|
|
+ uint32_t pixelSize;
|
|
|
+ uint32_t transferedByte=0;
|
|
|
+ uint16_t bufferRamAddr = 0x8000;
|
|
|
+
|
|
|
+ // Reset LCD
|
|
|
+ uint8_t cmd_reset[] = {0x55, 0xaa, 0x5a, 0xa5};
|
|
|
+ if(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0x04, cmd_reset, ARRAY_SIZE(cmd_reset)) == FAIL)
|
|
|
+ {
|
|
|
+ DEBUG_INFO("LCD reset fail.\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ // Get image file size
|
|
|
+ stat(filename, &fileSt);
|
|
|
+ bmp = bopen(filename);
|
|
|
+ uint8_t buf[bmp->width*bmp->height*2];
|
|
|
+
|
|
|
+ DEBUG_INFO("Image filename: %s\n", filename);
|
|
|
+ DEBUG_INFO("Image width: %d height: %d\n", bmp->width, bmp->height);
|
|
|
+ DEBUG_INFO("Image data size: %d\n", ARRAY_SIZE(buf));
|
|
|
+
|
|
|
+ // Get bmp pixel data and convert to 16 bit color
|
|
|
+ for(uint16_t idxY=0 ; idxY<bmp->height ; idxY++)
|
|
|
+ {
|
|
|
+ for(uint16_t idxX=0 ; idxX<bmp->width ; idxX++)
|
|
|
+ {
|
|
|
+ uint8_t r, g, b;
|
|
|
+ get_pixel_rgb(bmp, idxX, (bmp->height-idxY-1), &r, &g, &b);
|
|
|
+ buf[(2*((idxY*bmp->width) + idxX)) + 0] = ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3)) >> 8) & 0xff;
|
|
|
+ buf[(2*((idxY*bmp->width) + idxX)) + 1] = ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3)) >> 0) & 0xff;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bclose(bmp);
|
|
|
+
|
|
|
+ // Transfer pixel to screen page
|
|
|
+ pixelSize = ARRAY_SIZE(buf);
|
|
|
+ for(uint16_t idxSrcData=0;idxSrcData<(((pixelSize%pageSize)==0)?(pixelSize/pageSize):(pixelSize/pageSize)+1);idxSrcData++)
|
|
|
+ {
|
|
|
+ //DEBUG_INFO("Buffer start data address: 0x%08X\n", (idxSrcData*pageSize));
|
|
|
+ //DEBUG_INFO(" Image start ram address: 0x%08X\n", ((idxSrcData*pageSize) >> 1));
|
|
|
+ uint8_t display_cmd[] ={0x5a, (bufferRamAddr>>8)&0xff, (bufferRamAddr>>0)&0xff, 0x00, 0x00, 0x00, 0x00, 0x00};
|
|
|
+
|
|
|
+ if((idxSrcData+1) != (((pixelSize%pageSize)==0)?(pixelSize/pageSize):(pixelSize/pageSize)+1))
|
|
|
+ {
|
|
|
+ // Data transfer
|
|
|
+ while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr, &buf[(idxSrcData*pageSize)], pageSize) != PASS)
|
|
|
+ {
|
|
|
+ DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
|
|
|
+ }
|
|
|
+ transferedByte += pageSize;
|
|
|
+
|
|
|
+ display_cmd[3] = ((pageSize>>1) >> 8) & 0xff; // Data length high byte
|
|
|
+ display_cmd[4] = ((pageSize>>1) >> 0) & 0xff; // Data length low byte
|
|
|
+ display_cmd[5] = (((idxSrcData*pageSize)>>1) >> 16) & 0xff; // Screen on ram address 1st byte
|
|
|
+ display_cmd[6] = (((idxSrcData*pageSize)>>1) >> 8) & 0xff; // Screen on ram address 2nd byte
|
|
|
+ display_cmd[7] = (((idxSrcData*pageSize)>>1) >> 0) & 0xff; // Screen on ram address 3th byte
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Last data transfer
|
|
|
+ while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr, &buf[(idxSrcData*pageSize)], (pixelSize-(idxSrcData*pageSize))) != PASS)
|
|
|
+ {
|
|
|
+ DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
|
|
|
+ }
|
|
|
+ transferedByte += (pixelSize-(idxSrcData*pageSize));
|
|
|
+
|
|
|
+ display_cmd[3] = (((pixelSize-(idxSrcData*pageSize))>>1) >> 8) & 0xff; // Data length high byte
|
|
|
+ display_cmd[4] = (((pixelSize-(idxSrcData*pageSize))>>1) >> 0) & 0xff; // Data length low byte
|
|
|
+ display_cmd[5] = (((idxSrcData*pageSize)>>1) >> 16) & 0xff; // Screen on ram address 1st byte
|
|
|
+ display_cmd[6] = (((idxSrcData*pageSize)>>1) >> 8) & 0xff; // Screen on ram address 2nd byte
|
|
|
+ display_cmd[7] = (((idxSrcData*pageSize)>>1) >> 0) & 0xff; // Screen on ram address 3th byte
|
|
|
+ }
|
|
|
+
|
|
|
+ // Move data from ram to flash
|
|
|
+ while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0xa2, display_cmd, ARRAY_SIZE(display_cmd)) != PASS)
|
|
|
+ {
|
|
|
+ DEBUG_INFO("Write data to display buffer 0x%04X fail.\n", transferedByte);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Save image to target address
|
|
|
+ uint8_t save_cmd[] ={0x5a, 0x02, ((picIdx>>8)&0xff), (picIdx&0xff)};
|
|
|
+ while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0x84, save_cmd, ARRAY_SIZE(save_cmd)) != PASS)
|
|
|
+ {
|
|
|
+ DEBUG_INFO("Save image fail.\n");
|
|
|
+ }
|
|
|
+ DEBUG_INFO("Save image success.\n");
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+//=======================================
|
|
|
+// Download image
|
|
|
+//=======================================
|
|
|
+int downloadBIN(uint8_t targetAddr, char *filename)
|
|
|
+{
|
|
|
+ int result = PASS;
|
|
|
+ int fd;
|
|
|
+ struct stat fileSt;
|
|
|
+ uint32_t pageSize = 128;
|
|
|
+ uint32_t blocklSize = 32768;
|
|
|
+ uint32_t transferedByte=0;
|
|
|
+ uint16_t bufferRamAddr = 0x8000;
|
|
|
+
|
|
|
+ // Reset LCD
|
|
|
+ uint8_t cmd_reset[] = {0x55, 0xaa, 0x5a, 0xa5};
|
|
|
+ if(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0x04, cmd_reset, ARRAY_SIZE(cmd_reset)) == FAIL)
|
|
|
+ {
|
|
|
+ DEBUG_INFO("LCD reset fail.\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ // Get image file size
|
|
|
+ stat(filename, &fileSt);
|
|
|
+ uint8_t buf[(fileSt.st_size%32768==0?fileSt.st_size/32768:(fileSt.st_size/32768)+1)*32768];
|
|
|
+
|
|
|
+ DEBUG_INFO("Bin filename: %s\n", filename);
|
|
|
+ DEBUG_INFO("Bin data size: %d\n", fileSt.st_size);
|
|
|
+
|
|
|
+ fd = open(filename, O_RDWR);
|
|
|
+ if (fd < 0)
|
|
|
+ {
|
|
|
+ DEBUG_WARN("Bin can not be open.\n");
|
|
|
+ result = FAIL;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ for(uint8_t idxBinSrc=0;idxBinSrc<(fileSt.st_size%32768==0?fileSt.st_size/32768:(fileSt.st_size/32768)+1);idxBinSrc++)
|
|
|
+ {
|
|
|
+ // Read data from bin file
|
|
|
+ memset(buf, 0x00, ARRAY_SIZE(buf));
|
|
|
+ read(fd, buf, ARRAY_SIZE(buf));
|
|
|
+ close(fd);
|
|
|
+
|
|
|
+ // Transfer data to ram
|
|
|
+ for(uint16_t idxSrcData=0;idxSrcData<(((blocklSize%pageSize)==0)?(blocklSize/pageSize):(blocklSize/pageSize)+1);idxSrcData++)
|
|
|
+ {
|
|
|
+ //DEBUG_INFO("Buffer start data address: 0x%08X\n", (idxBinSrc*blocklSize)+(idxSrcData*pageSize));
|
|
|
+ //DEBUG_INFO(" Image start ram address: 0x%08X\n", ((idxSrcData*pageSize) >> 1));
|
|
|
+
|
|
|
+ if((idxSrcData+1) != (((blocklSize%pageSize)==0)?(blocklSize/pageSize):(blocklSize/pageSize)+1))
|
|
|
+ {
|
|
|
+ // Data transfer
|
|
|
+ while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr+((idxSrcData*pageSize)>>1), &buf[(idxBinSrc*blocklSize)+(idxSrcData*pageSize)], pageSize) != PASS)
|
|
|
+ {
|
|
|
+ DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
|
|
|
+ }
|
|
|
+ transferedByte += pageSize;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Last data transfer
|
|
|
+ while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr+((idxSrcData*pageSize)>>1), &buf[(idxBinSrc*blocklSize)+(idxSrcData*pageSize)], (blocklSize-(idxSrcData*pageSize)))!= PASS)
|
|
|
+ {
|
|
|
+ DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
|
|
|
+ }
|
|
|
+ transferedByte += (blocklSize-(idxSrcData*pageSize));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Move data from ram to flash
|
|
|
+ uint8_t save_cmd[] ={0x5a, 0x02, ((((targetAddr*8)+idxBinSrc)>>8)&0xff), ((((targetAddr*8)+idxBinSrc)>>0)&0xff), ((bufferRamAddr>>8)&0xff), ((bufferRamAddr>>0)&0xff), 0x00, 0x01, 0x00, 0x00, 0x00, 0x00};
|
|
|
+ while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0xaa, save_cmd, ARRAY_SIZE(save_cmd)) != PASS)
|
|
|
+ {
|
|
|
+ DEBUG_INFO("Save bin file to 0x%04X fail.\n", ((targetAddr*8)+idxBinSrc));
|
|
|
+ }
|
|
|
+ DEBUG_INFO("Save bin file on 0x%04X success.\n", ((targetAddr*8)+idxBinSrc));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
//=======================================
|
|
|
// Main process
|
|
|
//=======================================
|