Merge #180 into xts_origin from refs/changes/180/head 181/target/1 182/target/1
authorsnickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Fri, 24 May 2024 13:58:36 +0000 (13:58 +0000)
committersnickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Fri, 24 May 2024 13:58:36 +0000 (13:58 +0000)
添加 lzma dec 解压缩接口,目前试过解压缩单个压缩表盘。

* refs/changes/180/head: (1 commits squashed)

  - 添加 lzma dec 解压缩接口,目前试过解压缩单个压缩表盘。

Signed-off-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Reviewed-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Merged-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/180
code/sdk/build/config/target_config/brandy/config.py
code/sdk/drivers/peripheral/CMakeLists.txt
code/sdk/drivers/peripheral/utils/custom_utils.h
code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c
code/sdk/drivers/peripheral/utilscpp/7zFile.cpp [new file with mode: 0644]
code/sdk/drivers/peripheral/utilscpp/7zStream.cpp [new file with mode: 0644]
code/sdk/drivers/peripheral/utilscpp/CMakeLists.txt [new file with mode: 0644]
code/sdk/drivers/peripheral/utilscpp/custom_utilscpp.cpp [new file with mode: 0644]
code/sdk/drivers/peripheral/utilscpp/custom_utilscpp.h [new file with mode: 0644]
code/sdk/open_source/7-zip-lzma-sdk/lzma_21.07/C/7zFile.h

index db74354..7f71211 100755 (executable)
@@ -167,6 +167,7 @@ target = {
                           "audio_manager",
                           "CustomUIcomponentTool",
                           "custom_utils",
+                          "custom_utilscpp",
                           "rotary_encoder",
                           #"nativelauncher",
                            "fd230launcher",
index af2060e..12dda61 100644 (file)
@@ -13,6 +13,7 @@ add_subdirectory_if_exist(vibrator)
 add_subdirectory_if_exist(slip)
 add_subdirectory_if_exist(slip/cat1Service)
 add_subdirectory_if_exist(utils)
+add_subdirectory_if_exist(utilscpp)
 add_subdirectory_if_exist(rotary_encoder)
 add_subdirectory_if_exist(vibrator/service)
 add_subdirectory_if_exist(cywee)
index 3827aa1..6984087 100644 (file)
@@ -176,6 +176,11 @@ int custom_exit_lpm(void);
 void uapi_cywee_get_sleep_data(void);
 void uapi_cywee_set_user_info(int user_info[5]);
 void uapi_cywee_time_sync(void);
+
+
+#include "custom_utilscpp.h"
+
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 56c3fcd..46ee826 100644 (file)
@@ -432,6 +432,32 @@ static uint32_t custom_cywee_get_sleep_data(uint8_t *para, uint32_t paraLen, cha
 
     return ERRCODE_SUCC;
 }
+
+
+static uint32_t custom_utils_lzmadec(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    UNUSED(strCommonCmd);
+    uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 };
+    uint32_t argc = 0;
+
+    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
+    if (ret != CUSTOM_UTILS_SUCCESS) {
+        PRINT("CUSTOM_UTILSTEST ATCMD Convert Command Failed\n");
+        return ERRCODE_FAIL;
+    }
+
+    if (argc != 2) {
+        PRINT("CUSTOM_UTILSTEST ATCMD Set Parameter Failed argc %d\n",argc);
+        return ERRCODE_FAIL;
+    }
+    const char *infile = (const char*)argv[0];
+     char *outfile = ( char*)argv[1];
+    uint32_t rret = uapi_dial_pkg_decompress(infile,outfile);
+    PRINT("extract %s to %s , ret 0x%X\r\n",infile,outfile, rret);
+
+    return ERRCODE_SUCC;
+}
+
 static const at_cmd_table_t g_custom_utils_cmd[] = {
     { (char *)"AT^CUSTOM_SN",      custom_utils_setsn, (char *)"123456789ABCDEF2345678" },
     { (char *)"AT^CUSTOM_SN_REQ",  custom_utils_getsn, (char *)" " },
@@ -474,6 +500,7 @@ static const at_cmd_table_t g_custom_utils_cmd[] = {
     { (char *)"AT^CYWEETIMESYNC",      custom_cywee_time_sync, (char *)" " },
 
     { (char *)"AT^CYWEEGETSLEEPDATA",      custom_cywee_get_sleep_data, (char *)" " },
+    { (char *)"AT^LZMADEC",      custom_utils_lzmadec, (char *)" " },
 
 };
 
diff --git a/code/sdk/drivers/peripheral/utilscpp/7zFile.cpp b/code/sdk/drivers/peripheral/utilscpp/7zFile.cpp
new file mode 100644 (file)
index 0000000..e486901
--- /dev/null
@@ -0,0 +1,286 @@
+/* 7zFile.c -- File IO\r
+2017-04-03 : Igor Pavlov : Public domain */\r
+\r
+#include "Precomp.h"\r
+\r
+#include "7zFile.h"\r
+\r
+#ifndef USE_WINDOWS_FILE\r
+\r
+#ifndef UNDER_CE\r
+#include <errno.h>\r
+#endif\r
+\r
+#else\r
+\r
+/*\r
+   ReadFile and WriteFile functions in Windows have BUG:\r
+   If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)\r
+   from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES\r
+   (Insufficient system resources exist to complete the requested service).\r
+   Probably in some version of Windows there are problems with other sizes:\r
+   for 32 MB (maybe also for 16 MB).\r
+   And message can be "Network connection was lost"\r
+*/\r
+\r
+#define kChunkSizeMax (1 << 22)\r
+\r
+#endif\r
+\r
+void File_Construct(CSzFile *p)\r
+{\r
+  #ifdef USE_WINDOWS_FILE\r
+  p->handle = INVALID_HANDLE_VALUE;\r
+  #else\r
+  p->file = NULL;\r
+  #endif\r
+}\r
+\r
+#if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE)\r
+static WRes File_Open(CSzFile *p, const char *name, int writeMode)\r
+{\r
+  #ifdef USE_WINDOWS_FILE\r
+  p->handle = CreateFileA(name,\r
+      writeMode ? GENERIC_WRITE : GENERIC_READ,\r
+      FILE_SHARE_READ, NULL,\r
+      writeMode ? CREATE_ALWAYS : OPEN_EXISTING,\r
+      FILE_ATTRIBUTE_NORMAL, NULL);\r
+  return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();\r
+  #else\r
+  p->file = fopen(name, writeMode ? "wb+" : "rb");\r
+  return (p->file != 0) ? 0 :\r
+    #ifdef UNDER_CE\r
+    2; /* ENOENT */\r
+    #else\r
+    errno;\r
+    #endif\r
+  #endif\r
+}\r
+\r
+WRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); }\r
+WRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); }\r
+#endif\r
+\r
+#ifdef USE_WINDOWS_FILE\r
+static WRes File_OpenW(CSzFile *p, const WCHAR *name, int writeMode)\r
+{\r
+  p->handle = CreateFileW(name,\r
+      writeMode ? GENERIC_WRITE : GENERIC_READ,\r
+      FILE_SHARE_READ, NULL,\r
+      writeMode ? CREATE_ALWAYS : OPEN_EXISTING,\r
+      FILE_ATTRIBUTE_NORMAL, NULL);\r
+  return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();\r
+}\r
+WRes InFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 0); }\r
+WRes OutFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 1); }\r
+#endif\r
+\r
+WRes File_Close(CSzFile *p)\r
+{\r
+  #ifdef USE_WINDOWS_FILE\r
+  if (p->handle != INVALID_HANDLE_VALUE)\r
+  {\r
+    if (!CloseHandle(p->handle))\r
+      return GetLastError();\r
+    p->handle = INVALID_HANDLE_VALUE;\r
+  }\r
+  #else\r
+  if (p->file != NULL)\r
+  {\r
+    int res = fclose(p->file);\r
+    if (res != 0)\r
+      return res;\r
+    p->file = NULL;\r
+  }\r
+  #endif\r
+  return 0;\r
+}\r
+\r
+WRes File_Read(CSzFile *p, void *data, size_t *size)\r
+{\r
+  size_t originalSize = *size;\r
+  if (originalSize == 0)\r
+    return 0;\r
+\r
+  #ifdef USE_WINDOWS_FILE\r
+\r
+  *size = 0;\r
+  do\r
+  {\r
+    DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;\r
+    DWORD processed = 0;\r
+    BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);\r
+    data = (void *)((Byte *)data + processed);\r
+    originalSize -= processed;\r
+    *size += processed;\r
+    if (!res)\r
+      return GetLastError();\r
+    if (processed == 0)\r
+      break;\r
+  }\r
+  while (originalSize > 0);\r
+  return 0;\r
+\r
+  #else\r
+  \r
+  *size = fread(data, 1, originalSize, p->file);\r
+  if (*size == originalSize)\r
+    return 0;\r
+  return ferror(p->file);\r
+  \r
+  #endif\r
+}\r
+\r
+WRes File_Write(CSzFile *p, const void *data, size_t *size)\r
+{\r
+  size_t originalSize = *size;\r
+  if (originalSize == 0)\r
+    return 0;\r
+  \r
+  #ifdef USE_WINDOWS_FILE\r
+\r
+  *size = 0;\r
+  do\r
+  {\r
+    DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;\r
+    DWORD processed = 0;\r
+    BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL);\r
+    data = (void *)((Byte *)data + processed);\r
+    originalSize -= processed;\r
+    *size += processed;\r
+    if (!res)\r
+      return GetLastError();\r
+    if (processed == 0)\r
+      break;\r
+  }\r
+  while (originalSize > 0);\r
+  return 0;\r
+\r
+  #else\r
+\r
+  *size = fwrite(data, 1, originalSize, p->file);\r
+  if (*size == originalSize)\r
+    return 0;\r
+  return ferror(p->file);\r
+  \r
+  #endif\r
+}\r
+\r
+WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)\r
+{\r
+  #ifdef USE_WINDOWS_FILE\r
+\r
+  LARGE_INTEGER value;\r
+  DWORD moveMethod;\r
+  value.LowPart = (DWORD)*pos;\r
+  value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */\r
+  switch (origin)\r
+  {\r
+    case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;\r
+    case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;\r
+    case SZ_SEEK_END: moveMethod = FILE_END; break;\r
+    default: return ERROR_INVALID_PARAMETER;\r
+  }\r
+  value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);\r
+  if (value.LowPart == 0xFFFFFFFF)\r
+  {\r
+    WRes res = GetLastError();\r
+    if (res != NO_ERROR)\r
+      return res;\r
+  }\r
+  *pos = ((Int64)value.HighPart << 32) | value.LowPart;\r
+  return 0;\r
+\r
+  #else\r
+  \r
+  int moveMethod;\r
+  int res;\r
+  switch (origin)\r
+  {\r
+    case SZ_SEEK_SET: moveMethod = SEEK_SET; break;\r
+    case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;\r
+    case SZ_SEEK_END: moveMethod = SEEK_END; break;\r
+    default: return 1;\r
+  }\r
+  res = fseek(p->file, (long)*pos, moveMethod);\r
+  *pos = ftell(p->file);\r
+  return res;\r
+  \r
+  #endif\r
+}\r
+\r
+WRes File_GetLength(CSzFile *p, UInt64 *length)\r
+{\r
+  #ifdef USE_WINDOWS_FILE\r
+  \r
+  DWORD sizeHigh;\r
+  DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);\r
+  if (sizeLow == 0xFFFFFFFF)\r
+  {\r
+    DWORD res = GetLastError();\r
+    if (res != NO_ERROR)\r
+      return res;\r
+  }\r
+  *length = (((UInt64)sizeHigh) << 32) + sizeLow;\r
+  return 0;\r
+  \r
+  #else\r
+  \r
+  long pos = ftell(p->file);\r
+  int res = fseek(p->file, 0, SEEK_END);\r
+  *length = ftell(p->file);\r
+  fseek(p->file, pos, SEEK_SET);\r
+  return res;\r
+  \r
+  #endif\r
+}\r
+\r
+\r
+/* ---------- FileSeqInStream ---------- */\r
+\r
+static SRes FileSeqInStream_Read(const ISeqInStream *pp, void *buf, size_t *size)\r
+{\r
+  CFileSeqInStream *p = CONTAINER_FROM_VTBL(pp, CFileSeqInStream, vt);\r
+  return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ;\r
+}\r
+\r
+void FileSeqInStream_CreateVTable(CFileSeqInStream *p)\r
+{\r
+  p->vt.Read = FileSeqInStream_Read;\r
+}\r
+\r
+\r
+/* ---------- FileInStream ---------- */\r
+\r
+static SRes FileInStream_Read(const ISeekInStream *pp, void *buf, size_t *size)\r
+{\r
+  CFileInStream *p = CONTAINER_FROM_VTBL(pp, CFileInStream, vt);\r
+  return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ;\r
+}\r
+\r
+static SRes FileInStream_Seek(const ISeekInStream *pp, Int64 *pos, ESzSeek origin)\r
+{\r
+  CFileInStream *p = CONTAINER_FROM_VTBL(pp, CFileInStream, vt);\r
+  return File_Seek(&p->file, pos, origin);\r
+}\r
+\r
+void FileInStream_CreateVTable(CFileInStream *p)\r
+{\r
+  p->vt.Read = FileInStream_Read;\r
+  p->vt.Seek = FileInStream_Seek;\r
+}\r
+\r
+\r
+/* ---------- FileOutStream ---------- */\r
+\r
+static size_t FileOutStream_Write(const ISeqOutStream *pp, const void *data, size_t size)\r
+{\r
+  CFileOutStream *p = CONTAINER_FROM_VTBL(pp, CFileOutStream, vt);\r
+  File_Write(&p->file, data, &size);\r
+  return size;\r
+}\r
+\r
+void FileOutStream_CreateVTable(CFileOutStream *p)\r
+{\r
+  p->vt.Write = FileOutStream_Write;\r
+}\r
diff --git a/code/sdk/drivers/peripheral/utilscpp/7zStream.cpp b/code/sdk/drivers/peripheral/utilscpp/7zStream.cpp
new file mode 100644 (file)
index 0000000..579741f
--- /dev/null
@@ -0,0 +1,176 @@
+/* 7zStream.c -- 7z Stream functions\r
+2017-04-03 : Igor Pavlov : Public domain */\r
+\r
+#include "Precomp.h"\r
+\r
+#include <string.h>\r
+\r
+#include "7zTypes.h"\r
+\r
+SRes SeqInStream_Read2(const ISeqInStream *stream, void *buf, size_t size, SRes errorType)\r
+{\r
+  while (size != 0)\r
+  {\r
+    size_t processed = size;\r
+    RINOK(ISeqInStream_Read(stream, buf, &processed));\r
+    if (processed == 0)\r
+      return errorType;\r
+    buf = (void *)((Byte *)buf + processed);\r
+    size -= processed;\r
+  }\r
+  return SZ_OK;\r
+}\r
+\r
+SRes SeqInStream_Read(const ISeqInStream *stream, void *buf, size_t size)\r
+{\r
+  return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);\r
+}\r
+\r
+SRes SeqInStream_ReadByte(const ISeqInStream *stream, Byte *buf)\r
+{\r
+  size_t processed = 1;\r
+  RINOK(ISeqInStream_Read(stream, buf, &processed));\r
+  return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;\r
+}\r
+\r
+\r
+\r
+SRes LookInStream_SeekTo(const ILookInStream *stream, UInt64 offset)\r
+{\r
+  Int64 t = offset;\r
+  return ILookInStream_Seek(stream, &t, SZ_SEEK_SET);\r
+}\r
+\r
+SRes LookInStream_LookRead(const ILookInStream *stream, void *buf, size_t *size)\r
+{\r
+  const void *lookBuf;\r
+  if (*size == 0)\r
+    return SZ_OK;\r
+  RINOK(ILookInStream_Look(stream, &lookBuf, size));\r
+  memcpy(buf, lookBuf, *size);\r
+  return ILookInStream_Skip(stream, *size);\r
+}\r
+\r
+SRes LookInStream_Read2(const ILookInStream *stream, void *buf, size_t size, SRes errorType)\r
+{\r
+  while (size != 0)\r
+  {\r
+    size_t processed = size;\r
+    RINOK(ILookInStream_Read(stream, buf, &processed));\r
+    if (processed == 0)\r
+      return errorType;\r
+    buf = (void *)((Byte *)buf + processed);\r
+    size -= processed;\r
+  }\r
+  return SZ_OK;\r
+}\r
+\r
+SRes LookInStream_Read(const ILookInStream *stream, void *buf, size_t size)\r
+{\r
+  return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);\r
+}\r
+\r
+\r
+\r
+#define GET_LookToRead2 CLookToRead2 *p = CONTAINER_FROM_VTBL(pp, CLookToRead2, vt);\r
+\r
+static SRes LookToRead2_Look_Lookahead(const ILookInStream *pp, const void **buf, size_t *size)\r
+{\r
+  SRes res = SZ_OK;\r
+  GET_LookToRead2\r
+  size_t size2 = p->size - p->pos;\r
+  if (size2 == 0 && *size != 0)\r
+  {\r
+    p->pos = 0;\r
+    p->size = 0;\r
+    size2 = p->bufSize;\r
+    res = ISeekInStream_Read(p->realStream, p->buf, &size2);\r
+    p->size = size2;\r
+  }\r
+  if (*size > size2)\r
+    *size = size2;\r
+  *buf = p->buf + p->pos;\r
+  return res;\r
+}\r
+\r
+static SRes LookToRead2_Look_Exact(const ILookInStream *pp, const void **buf, size_t *size)\r
+{\r
+  SRes res = SZ_OK;\r
+  GET_LookToRead2\r
+  size_t size2 = p->size - p->pos;\r
+  if (size2 == 0 && *size != 0)\r
+  {\r
+    p->pos = 0;\r
+    p->size = 0;\r
+    if (*size > p->bufSize)\r
+      *size = p->bufSize;\r
+    res = ISeekInStream_Read(p->realStream, p->buf, size);\r
+    size2 = p->size = *size;\r
+  }\r
+  if (*size > size2)\r
+    *size = size2;\r
+  *buf = p->buf + p->pos;\r
+  return res;\r
+}\r
+\r
+static SRes LookToRead2_Skip(const ILookInStream *pp, size_t offset)\r
+{\r
+  GET_LookToRead2\r
+  p->pos += offset;\r
+  return SZ_OK;\r
+}\r
+\r
+static SRes LookToRead2_Read(const ILookInStream *pp, void *buf, size_t *size)\r
+{\r
+  GET_LookToRead2\r
+  size_t rem = p->size - p->pos;\r
+  if (rem == 0)\r
+    return ISeekInStream_Read(p->realStream, buf, size);\r
+  if (rem > *size)\r
+    rem = *size;\r
+  memcpy(buf, p->buf + p->pos, rem);\r
+  p->pos += rem;\r
+  *size = rem;\r
+  return SZ_OK;\r
+}\r
+\r
+static SRes LookToRead2_Seek(const ILookInStream *pp, Int64 *pos, ESzSeek origin)\r
+{\r
+  GET_LookToRead2\r
+  p->pos = p->size = 0;\r
+  return ISeekInStream_Seek(p->realStream, pos, origin);\r
+}\r
+\r
+void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead)\r
+{\r
+  p->vt.Look = lookahead ?\r
+      LookToRead2_Look_Lookahead :\r
+      LookToRead2_Look_Exact;\r
+  p->vt.Skip = LookToRead2_Skip;\r
+  p->vt.Read = LookToRead2_Read;\r
+  p->vt.Seek = LookToRead2_Seek;\r
+}\r
+\r
+\r
+\r
+static SRes SecToLook_Read(const ISeqInStream *pp, void *buf, size_t *size)\r
+{\r
+  CSecToLook *p = CONTAINER_FROM_VTBL(pp, CSecToLook, vt);\r
+  return LookInStream_LookRead(p->realStream, buf, size);\r
+}\r
+\r
+void SecToLook_CreateVTable(CSecToLook *p)\r
+{\r
+  p->vt.Read = SecToLook_Read;\r
+}\r
+\r
+static SRes SecToRead_Read(const ISeqInStream *pp, void *buf, size_t *size)\r
+{\r
+  CSecToRead *p = CONTAINER_FROM_VTBL(pp, CSecToRead, vt);\r
+  return ILookInStream_Read(p->realStream, buf, size);\r
+}\r
+\r
+void SecToRead_CreateVTable(CSecToRead *p)\r
+{\r
+  p->vt.Read = SecToRead_Read;\r
+}\r
diff --git a/code/sdk/drivers/peripheral/utilscpp/CMakeLists.txt b/code/sdk/drivers/peripheral/utilscpp/CMakeLists.txt
new file mode 100644 (file)
index 0000000..eb794f8
--- /dev/null
@@ -0,0 +1,57 @@
+#===============================================================================
+# @brief    cmake file
+# Copyright (c) @CompanyNameMagicTag 2022-2023. All rights reserved.
+#===============================================================================
+set(COMPONENT_NAME "custom_utilscpp")
+
+set(SOURCES
+    ${CMAKE_CURRENT_SOURCE_DIR}/custom_utilscpp.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/7zFile.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/7zStream.cpp
+)
+
+set(PUBLIC_HEADER
+    ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+set(PRIVATE_HEADER
+    ${CMAKE_SOURCE_DIR}/middleware/utils/update/inner_include
+)
+
+set(PRIVATE_DEFINES
+    TARGET_NAME="${TARGET_COMMAND}"
+    BUILD_TIME="${BUILD_TIME}"
+)
+
+set(PUBLIC_DEFINES
+)
+
+# use this when you want to add ccflags like -include xxx
+set(COMPONENT_PUBLIC_CCFLAGS
+)
+
+set(COMPONENT_CCFLAGS
+    -std=c++11
+    -Wno-error
+    -Wno-unused-parameter
+    -fno-exceptions
+    -fno-unwind-tables
+    -fno-asynchronous-unwind-tables
+    -Wno-undef
+    -Wno-bitwise-op-parentheses
+    -Wno-shift-op-parentheses
+    -nostdlibinc
+    -nostdinc
+    -nostdlib
+    -Wno-c++11-narrowing
+    -Wno-error=unused-function
+)
+set(WHOLE_LINK
+    true
+)
+
+set(MAIN_COMPONENT
+    false
+)
+
+build_component()
diff --git a/code/sdk/drivers/peripheral/utilscpp/custom_utilscpp.cpp b/code/sdk/drivers/peripheral/utilscpp/custom_utilscpp.cpp
new file mode 100644 (file)
index 0000000..a96b0fb
--- /dev/null
@@ -0,0 +1,236 @@
+/**
+ * Copyright (c) @CompanyNameMagicTag 2023-2023. All rights reserved. \n
+ *
+ * Description: Button driver source file \n
+ * Author: @CompanyNameTag \n
+ * History: \n
+ * 2023-02-24, Create file. \n
+ */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include "pinctrl.h"
+#include "button_porting.h"
+#include "platform_core.h"
+#include "gpio.h"
+#include "gpio_porting.h"
+#include "debug_print.h"
+#include "rtc.h"
+#include "timer.h"
+#include "systick.h"
+#include "chip_core_irq.h"
+#include "pwm.h"
+#include "pwm_porting.h"
+#include "pinctrl.h"
+#include "errcode.h"
+#include "power_display_service.h"
+
+#include <dirent.h>
+#include <unistd.h>
+#include "custom_runtime.h"
+#include "pm_definition.h"
+
+#include "sys/time.h"
+#include "time.h"
+
+#include "custom_utils.h"
+#include "cywee_service.h"
+
+#include "upg_lzmadec.h"
+#include "stdio.h"
+#include "dfx_file_operation.h"
+#include "sys/stat.h"
+#define CUSTOM_DIAL_PATH "/user/dial/custom_dial.bin"
+
+/***************************************************************************************************************/
+#include "7zFile.h"
+
+#include "upg_alloc.h"
+
+#define IN_BUF_SIZE (1 << 8)
+#define OUT_BUF_SIZE (1 << 8)
+
+
+static SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inStream,
+    UInt64 unpackSize)
+{
+  int thereIsSize = (unpackSize != (UInt64)(Int64)-1);
+  Byte inBuf[IN_BUF_SIZE];
+  Byte outBuf[OUT_BUF_SIZE];
+  size_t inPos = 0, inSize = 0, outPos = 0;
+  LzmaDec_Init(state);
+  for (;;)
+  {
+    if (inPos == inSize)
+    {
+      inSize = IN_BUF_SIZE;
+      RINOK(inStream->Read(inStream, inBuf, &inSize));
+      inPos = 0;
+    }
+    {
+      SRes res;
+      SizeT inProcessed = inSize - inPos;
+      SizeT outProcessed = OUT_BUF_SIZE - outPos;
+      ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
+      ELzmaStatus status;
+      if (thereIsSize && outProcessed > unpackSize)
+      {
+        outProcessed = (SizeT)unpackSize;
+        finishMode = LZMA_FINISH_END;
+      }
+      
+      res = LzmaDec_DecodeToBuf(state, outBuf + outPos, &outProcessed,
+        inBuf + inPos, &inProcessed, finishMode, &status);
+      inPos += inProcessed;
+      outPos += outProcessed;
+      unpackSize -= outProcessed;
+      
+      if (outStream)
+        if (outStream->Write(outStream, outBuf, outPos) != outPos)
+          return SZ_ERROR_WRITE;
+        
+      outPos = 0;
+      
+      if (res != SZ_OK || (thereIsSize && unpackSize == 0))
+        return res;
+      
+      if (inProcessed == 0 && outProcessed == 0)
+      {
+        if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)
+          return SZ_ERROR_DATA;
+        return res;
+      }
+    }
+  }
+}
+STATIC void *upg_lzma_alloc(const ISzAllocPtr unused, size_t size)
+{
+    unused(unused);
+    void *p;
+    p = upg_malloc((uint32_t)size);
+    if (p == NULL) {
+        printf("upg_lzma_alloc failed!!! size = ", size);
+        return NULL;
+    }
+    return p;
+}
+
+STATIC void upg_lzma_free(const ISzAllocPtr unused, void *address)
+{
+    unused(unused);
+    if (address == NULL) {
+        return;
+    }
+    upg_free(address);
+}
+
+static SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream)
+{
+  UInt64 unpackSize;
+  int i;
+  SRes res = 0;
+
+  CLzmaDec state;
+
+
+
+  ISzAlloc alloc;
+  alloc.Alloc = upg_lzma_alloc;
+  alloc.Free = upg_lzma_free;
+
+  /* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */
+  unsigned char header[LZMA_PROPS_SIZE + 8];
+
+  /* Read and parse header */
+
+  RINOK(SeqInStream_Read(inStream, header, sizeof(header)));
+
+  unpackSize = 0;
+  for (i = 0; i < 8; i++)
+    unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8);
+
+  LzmaDec_Construct(&state);
+  RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &alloc));
+  res = Decode2(&state, outStream, inStream, unpackSize);
+  LzmaDec_Free(&state, &alloc);
+  return res;
+}
+static const char * const kCantReadMessage = "Can not read input file\n";
+static const char * const kCantWriteMessage = "Can not write output file\n";
+static const char * const kCantAllocateMessage = "Can not allocate memory\n";
+static const char * const kDataErrorMessage = "Data error\n";
+
+errcode_t uapi_dial_pkg_decompress(const char* dial_pkg_path,char* dial_bin_path)
+{
+    CFileSeqInStream inStream;
+    CFileOutStream outStream;
+    char c;
+    int res;
+
+    FileSeqInStream_CreateVTable(&inStream);
+    File_Construct(&inStream.file);
+
+    FileOutStream_CreateVTable(&outStream);
+    File_Construct(&outStream.file);
+
+    size_t t4 = sizeof(UInt32);
+    size_t t8 = sizeof(UInt64);
+    if (t4 != 4 || t8 != 8)
+    {
+        printf("Incorrect UInt32 or UInt64");
+        return -2;
+    }  
+
+    if (InFile_Open(&inStream.file, dial_pkg_path) != 0)
+    {
+        printf( "Can not open input file");
+        return -2;
+    }
+    
+    if (OutFile_Open(&outStream.file, dial_bin_path) != 0)
+    {
+
+        printf( "Can not open output file");
+        return -2;
+    }   
+
+    res = Decode(&outStream.vt, &inStream.vt );
+
+    File_Close(&outStream.file);
+    File_Close(&inStream.file);
+
+    if (res != SZ_OK)
+    {
+        if (res == SZ_ERROR_MEM)
+        {
+            printf( kCantAllocateMessage);
+            return -2;
+        }
+        else if (res == SZ_ERROR_DATA)
+        {
+            printf( kDataErrorMessage);
+            return -2;
+        }
+        else if (res == SZ_ERROR_WRITE)
+        {
+            printf( kCantWriteMessage);
+            return -2;
+        }   
+        else if (res == SZ_ERROR_READ)
+        {
+            printf( kCantReadMessage);
+            return -2;
+        }   
+        printf("%d\n",res);
+        return -2;
+    }
+    return 0;
+}
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
\ No newline at end of file
diff --git a/code/sdk/drivers/peripheral/utilscpp/custom_utilscpp.h b/code/sdk/drivers/peripheral/utilscpp/custom_utilscpp.h
new file mode 100644 (file)
index 0000000..58ab943
--- /dev/null
@@ -0,0 +1,23 @@
+/**
+ * Copyright (c) @CompanyNameMagicTag 2023-2023. All rights reserved. \n
+ *
+ * Description: Button driver header file \n
+ * Author: @CompanyNameTag \n
+ * History: \n
+ * 2023-02-24, Create file. \n
+ */
+#ifndef CUSTOM_UTILS_CPP_H
+#define CUSTOM_UTILS_CPP_H
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#include <stdint.h>
+#include <errcode.h>
+
+errcode_t uapi_dial_pkg_decompress(const char* dial_pkg_path,char* dial_bin_path);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
\ No newline at end of file
index 788abb6..a7cfa06 100755 (executable)
@@ -13,8 +13,8 @@
 #include <windows.h>
 #else
 // note: USE_FOPEN mode is limited to 32-bit file size
-// #define USE_FOPEN
-// #include <stdio.h>
+#define USE_FOPEN
+#include <stdio.h>
 #endif
 
 #include "7zTypes.h"