From: SnickerSun Date: Fri, 24 May 2024 12:15:47 +0000 (+0800) Subject: 添加 lzma dec 解压缩接口,目前试过解压缩单个压缩表盘。 X-Git-Tag: release_V1.2.70_20241020_135402~1109 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.js?a=commitdiff_plain;h=db62fb50cb3185a135caaaae8161b885fb477a8e;p=mirrors%2FFD230.git 添加 lzma dec 解压缩接口,目前试过解压缩单个压缩表盘。 --- diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index 3ba4980e1..1bab20bbb 100755 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -166,6 +166,7 @@ target = { "audio_manager", "CustomUIcomponentTool", "custom_utils", + "custom_utilscpp", "rotary_encoder", #"nativelauncher", "fd230launcher", diff --git a/code/sdk/drivers/peripheral/CMakeLists.txt b/code/sdk/drivers/peripheral/CMakeLists.txt index af2060e59..12dda6189 100644 --- a/code/sdk/drivers/peripheral/CMakeLists.txt +++ b/code/sdk/drivers/peripheral/CMakeLists.txt @@ -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) diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 3827aa180..698408735 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -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 */ diff --git a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c index 56c3fcd5e..46ee8263e 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c @@ -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 index 000000000..e486901e3 --- /dev/null +++ b/code/sdk/drivers/peripheral/utilscpp/7zFile.cpp @@ -0,0 +1,286 @@ +/* 7zFile.c -- File IO +2017-04-03 : Igor Pavlov : Public domain */ + +#include "Precomp.h" + +#include "7zFile.h" + +#ifndef USE_WINDOWS_FILE + +#ifndef UNDER_CE +#include +#endif + +#else + +/* + ReadFile and WriteFile functions in Windows have BUG: + If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1) + from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES + (Insufficient system resources exist to complete the requested service). + Probably in some version of Windows there are problems with other sizes: + for 32 MB (maybe also for 16 MB). + And message can be "Network connection was lost" +*/ + +#define kChunkSizeMax (1 << 22) + +#endif + +void File_Construct(CSzFile *p) +{ + #ifdef USE_WINDOWS_FILE + p->handle = INVALID_HANDLE_VALUE; + #else + p->file = NULL; + #endif +} + +#if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE) +static WRes File_Open(CSzFile *p, const char *name, int writeMode) +{ + #ifdef USE_WINDOWS_FILE + p->handle = CreateFileA(name, + writeMode ? GENERIC_WRITE : GENERIC_READ, + FILE_SHARE_READ, NULL, + writeMode ? CREATE_ALWAYS : OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, NULL); + return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError(); + #else + p->file = fopen(name, writeMode ? "wb+" : "rb"); + return (p->file != 0) ? 0 : + #ifdef UNDER_CE + 2; /* ENOENT */ + #else + errno; + #endif + #endif +} + +WRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); } +WRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); } +#endif + +#ifdef USE_WINDOWS_FILE +static WRes File_OpenW(CSzFile *p, const WCHAR *name, int writeMode) +{ + p->handle = CreateFileW(name, + writeMode ? GENERIC_WRITE : GENERIC_READ, + FILE_SHARE_READ, NULL, + writeMode ? CREATE_ALWAYS : OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, NULL); + return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError(); +} +WRes InFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 0); } +WRes OutFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 1); } +#endif + +WRes File_Close(CSzFile *p) +{ + #ifdef USE_WINDOWS_FILE + if (p->handle != INVALID_HANDLE_VALUE) + { + if (!CloseHandle(p->handle)) + return GetLastError(); + p->handle = INVALID_HANDLE_VALUE; + } + #else + if (p->file != NULL) + { + int res = fclose(p->file); + if (res != 0) + return res; + p->file = NULL; + } + #endif + return 0; +} + +WRes File_Read(CSzFile *p, void *data, size_t *size) +{ + size_t originalSize = *size; + if (originalSize == 0) + return 0; + + #ifdef USE_WINDOWS_FILE + + *size = 0; + do + { + DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize; + DWORD processed = 0; + BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL); + data = (void *)((Byte *)data + processed); + originalSize -= processed; + *size += processed; + if (!res) + return GetLastError(); + if (processed == 0) + break; + } + while (originalSize > 0); + return 0; + + #else + + *size = fread(data, 1, originalSize, p->file); + if (*size == originalSize) + return 0; + return ferror(p->file); + + #endif +} + +WRes File_Write(CSzFile *p, const void *data, size_t *size) +{ + size_t originalSize = *size; + if (originalSize == 0) + return 0; + + #ifdef USE_WINDOWS_FILE + + *size = 0; + do + { + DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize; + DWORD processed = 0; + BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL); + data = (void *)((Byte *)data + processed); + originalSize -= processed; + *size += processed; + if (!res) + return GetLastError(); + if (processed == 0) + break; + } + while (originalSize > 0); + return 0; + + #else + + *size = fwrite(data, 1, originalSize, p->file); + if (*size == originalSize) + return 0; + return ferror(p->file); + + #endif +} + +WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin) +{ + #ifdef USE_WINDOWS_FILE + + LARGE_INTEGER value; + DWORD moveMethod; + value.LowPart = (DWORD)*pos; + value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */ + switch (origin) + { + case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break; + case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break; + case SZ_SEEK_END: moveMethod = FILE_END; break; + default: return ERROR_INVALID_PARAMETER; + } + value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod); + if (value.LowPart == 0xFFFFFFFF) + { + WRes res = GetLastError(); + if (res != NO_ERROR) + return res; + } + *pos = ((Int64)value.HighPart << 32) | value.LowPart; + return 0; + + #else + + int moveMethod; + int res; + switch (origin) + { + case SZ_SEEK_SET: moveMethod = SEEK_SET; break; + case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break; + case SZ_SEEK_END: moveMethod = SEEK_END; break; + default: return 1; + } + res = fseek(p->file, (long)*pos, moveMethod); + *pos = ftell(p->file); + return res; + + #endif +} + +WRes File_GetLength(CSzFile *p, UInt64 *length) +{ + #ifdef USE_WINDOWS_FILE + + DWORD sizeHigh; + DWORD sizeLow = GetFileSize(p->handle, &sizeHigh); + if (sizeLow == 0xFFFFFFFF) + { + DWORD res = GetLastError(); + if (res != NO_ERROR) + return res; + } + *length = (((UInt64)sizeHigh) << 32) + sizeLow; + return 0; + + #else + + long pos = ftell(p->file); + int res = fseek(p->file, 0, SEEK_END); + *length = ftell(p->file); + fseek(p->file, pos, SEEK_SET); + return res; + + #endif +} + + +/* ---------- FileSeqInStream ---------- */ + +static SRes FileSeqInStream_Read(const ISeqInStream *pp, void *buf, size_t *size) +{ + CFileSeqInStream *p = CONTAINER_FROM_VTBL(pp, CFileSeqInStream, vt); + return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ; +} + +void FileSeqInStream_CreateVTable(CFileSeqInStream *p) +{ + p->vt.Read = FileSeqInStream_Read; +} + + +/* ---------- FileInStream ---------- */ + +static SRes FileInStream_Read(const ISeekInStream *pp, void *buf, size_t *size) +{ + CFileInStream *p = CONTAINER_FROM_VTBL(pp, CFileInStream, vt); + return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ; +} + +static SRes FileInStream_Seek(const ISeekInStream *pp, Int64 *pos, ESzSeek origin) +{ + CFileInStream *p = CONTAINER_FROM_VTBL(pp, CFileInStream, vt); + return File_Seek(&p->file, pos, origin); +} + +void FileInStream_CreateVTable(CFileInStream *p) +{ + p->vt.Read = FileInStream_Read; + p->vt.Seek = FileInStream_Seek; +} + + +/* ---------- FileOutStream ---------- */ + +static size_t FileOutStream_Write(const ISeqOutStream *pp, const void *data, size_t size) +{ + CFileOutStream *p = CONTAINER_FROM_VTBL(pp, CFileOutStream, vt); + File_Write(&p->file, data, &size); + return size; +} + +void FileOutStream_CreateVTable(CFileOutStream *p) +{ + p->vt.Write = FileOutStream_Write; +} diff --git a/code/sdk/drivers/peripheral/utilscpp/7zStream.cpp b/code/sdk/drivers/peripheral/utilscpp/7zStream.cpp new file mode 100644 index 000000000..579741fad --- /dev/null +++ b/code/sdk/drivers/peripheral/utilscpp/7zStream.cpp @@ -0,0 +1,176 @@ +/* 7zStream.c -- 7z Stream functions +2017-04-03 : Igor Pavlov : Public domain */ + +#include "Precomp.h" + +#include + +#include "7zTypes.h" + +SRes SeqInStream_Read2(const ISeqInStream *stream, void *buf, size_t size, SRes errorType) +{ + while (size != 0) + { + size_t processed = size; + RINOK(ISeqInStream_Read(stream, buf, &processed)); + if (processed == 0) + return errorType; + buf = (void *)((Byte *)buf + processed); + size -= processed; + } + return SZ_OK; +} + +SRes SeqInStream_Read(const ISeqInStream *stream, void *buf, size_t size) +{ + return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF); +} + +SRes SeqInStream_ReadByte(const ISeqInStream *stream, Byte *buf) +{ + size_t processed = 1; + RINOK(ISeqInStream_Read(stream, buf, &processed)); + return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF; +} + + + +SRes LookInStream_SeekTo(const ILookInStream *stream, UInt64 offset) +{ + Int64 t = offset; + return ILookInStream_Seek(stream, &t, SZ_SEEK_SET); +} + +SRes LookInStream_LookRead(const ILookInStream *stream, void *buf, size_t *size) +{ + const void *lookBuf; + if (*size == 0) + return SZ_OK; + RINOK(ILookInStream_Look(stream, &lookBuf, size)); + memcpy(buf, lookBuf, *size); + return ILookInStream_Skip(stream, *size); +} + +SRes LookInStream_Read2(const ILookInStream *stream, void *buf, size_t size, SRes errorType) +{ + while (size != 0) + { + size_t processed = size; + RINOK(ILookInStream_Read(stream, buf, &processed)); + if (processed == 0) + return errorType; + buf = (void *)((Byte *)buf + processed); + size -= processed; + } + return SZ_OK; +} + +SRes LookInStream_Read(const ILookInStream *stream, void *buf, size_t size) +{ + return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF); +} + + + +#define GET_LookToRead2 CLookToRead2 *p = CONTAINER_FROM_VTBL(pp, CLookToRead2, vt); + +static SRes LookToRead2_Look_Lookahead(const ILookInStream *pp, const void **buf, size_t *size) +{ + SRes res = SZ_OK; + GET_LookToRead2 + size_t size2 = p->size - p->pos; + if (size2 == 0 && *size != 0) + { + p->pos = 0; + p->size = 0; + size2 = p->bufSize; + res = ISeekInStream_Read(p->realStream, p->buf, &size2); + p->size = size2; + } + if (*size > size2) + *size = size2; + *buf = p->buf + p->pos; + return res; +} + +static SRes LookToRead2_Look_Exact(const ILookInStream *pp, const void **buf, size_t *size) +{ + SRes res = SZ_OK; + GET_LookToRead2 + size_t size2 = p->size - p->pos; + if (size2 == 0 && *size != 0) + { + p->pos = 0; + p->size = 0; + if (*size > p->bufSize) + *size = p->bufSize; + res = ISeekInStream_Read(p->realStream, p->buf, size); + size2 = p->size = *size; + } + if (*size > size2) + *size = size2; + *buf = p->buf + p->pos; + return res; +} + +static SRes LookToRead2_Skip(const ILookInStream *pp, size_t offset) +{ + GET_LookToRead2 + p->pos += offset; + return SZ_OK; +} + +static SRes LookToRead2_Read(const ILookInStream *pp, void *buf, size_t *size) +{ + GET_LookToRead2 + size_t rem = p->size - p->pos; + if (rem == 0) + return ISeekInStream_Read(p->realStream, buf, size); + if (rem > *size) + rem = *size; + memcpy(buf, p->buf + p->pos, rem); + p->pos += rem; + *size = rem; + return SZ_OK; +} + +static SRes LookToRead2_Seek(const ILookInStream *pp, Int64 *pos, ESzSeek origin) +{ + GET_LookToRead2 + p->pos = p->size = 0; + return ISeekInStream_Seek(p->realStream, pos, origin); +} + +void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead) +{ + p->vt.Look = lookahead ? + LookToRead2_Look_Lookahead : + LookToRead2_Look_Exact; + p->vt.Skip = LookToRead2_Skip; + p->vt.Read = LookToRead2_Read; + p->vt.Seek = LookToRead2_Seek; +} + + + +static SRes SecToLook_Read(const ISeqInStream *pp, void *buf, size_t *size) +{ + CSecToLook *p = CONTAINER_FROM_VTBL(pp, CSecToLook, vt); + return LookInStream_LookRead(p->realStream, buf, size); +} + +void SecToLook_CreateVTable(CSecToLook *p) +{ + p->vt.Read = SecToLook_Read; +} + +static SRes SecToRead_Read(const ISeqInStream *pp, void *buf, size_t *size) +{ + CSecToRead *p = CONTAINER_FROM_VTBL(pp, CSecToRead, vt); + return ILookInStream_Read(p->realStream, buf, size); +} + +void SecToRead_CreateVTable(CSecToRead *p) +{ + p->vt.Read = SecToRead_Read; +} diff --git a/code/sdk/drivers/peripheral/utilscpp/CMakeLists.txt b/code/sdk/drivers/peripheral/utilscpp/CMakeLists.txt new file mode 100644 index 000000000..eb794f8a5 --- /dev/null +++ b/code/sdk/drivers/peripheral/utilscpp/CMakeLists.txt @@ -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 index 000000000..a96b0fbe4 --- /dev/null +++ b/code/sdk/drivers/peripheral/utilscpp/custom_utilscpp.cpp @@ -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 +#include +#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 index 000000000..58ab94353 --- /dev/null +++ b/code/sdk/drivers/peripheral/utilscpp/custom_utilscpp.h @@ -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 +#include + +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 diff --git a/code/sdk/open_source/7-zip-lzma-sdk/lzma_21.07/C/7zFile.h b/code/sdk/open_source/7-zip-lzma-sdk/lzma_21.07/C/7zFile.h index 788abb6b9..a7cfa063a 100755 --- a/code/sdk/open_source/7-zip-lzma-sdk/lzma_21.07/C/7zFile.h +++ b/code/sdk/open_source/7-zip-lzma-sdk/lzma_21.07/C/7zFile.h @@ -13,8 +13,8 @@ #include #else // note: USE_FOPEN mode is limited to 32-bit file size -// #define USE_FOPEN -// #include +#define USE_FOPEN +#include #endif #include "7zTypes.h"