Skip to content

Commit

Permalink
build: windows: fix posix windows incompatabilities
Browse files Browse the repository at this point in the history
Signed-off-by: Connor Rigby <[email protected]>
  • Loading branch information
ConnorRigby committed Oct 12, 2022
1 parent 4e01eb1 commit e2571e2
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 30 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Build output
/Debug
/Release

# visual studio (code) stuff
.vs
Expand All @@ -14,4 +15,5 @@ ecudump
*.log

# rom dump output
*.bin
*.bin

4 changes: 2 additions & 2 deletions J2534/J2534.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ J2534::J2534(void)
#elif __APPLE__
strcpy(dllName,"op20pt32.dylib");
#else
strcpy(dllName,"j2354.so");
strcpy(dllName,"j2354.so");
#endif
}

Expand Down Expand Up @@ -229,7 +229,7 @@ long J2534::LoadJ2534DLL(const char* szDLL)
strcpy(libPath,pathPtr);
strcat(libPath,"/Contents/Frameworks");
chdir(libPath); // change to this dir so J2534 .dylib can find any other needed dylibs in the same dir
strcat(libPath,"/"");
strcat(libPath,"/");
strcat(libPath,szDLL);

CFRelease(appUrlRef);
Expand Down
20 changes: 12 additions & 8 deletions ecudump.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<AdditionalIncludeDirectories>C:\Users\konno\Desktop\rx8\ecu\ecudump\J2534;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<OutputFile>$(OutDir)$(ProjectName).exe</OutputFile>
Expand All @@ -78,6 +79,7 @@
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<AdditionalIncludeDirectories>C:\Users\konno\Desktop\rx8\ecu\ecudump\J2534;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<OutputFile>$(OutDir)$(ProjectName).exe</OutputFile>
Expand All @@ -89,20 +91,22 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\common\J2534.cpp" />
<ClCompile Include="librx8.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="util.cpp" />
<ClCompile Include="J2534\J2534.cpp" />
<ClCompile Include="src\librx8.cpp" />
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\progressbar.cpp" />
<ClCompile Include="src\util.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="LICENSE.md" />
<None Include="README.md" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="librx8.h" />
<ClInclude Include="OBD2.h" />
<ClInclude Include="UDS.h" />
<ClInclude Include="util.h" />
<ClInclude Include="src\librx8.h" />
<ClInclude Include="src\OBD2.h" />
<ClInclude Include="src\UDS.h" />
<ClInclude Include="src\util.h" />
<ClInclude Include="src\progressbar.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
41 changes: 33 additions & 8 deletions ecudump.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="..\common\J2534.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="librx8.cpp" />
<ClCompile Include="util.cpp" />
<ClCompile Include="src\util.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="src\main.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="src\librx8.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="J2534\J2534.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="src\progressbar.cpp">
<Filter>Src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="Docs">
<UniqueIdentifier>{80505dd4-3aff-4e9d-b44f-43aaac66b754}</UniqueIdentifier>
</Filter>
<Filter Include="Src">
<UniqueIdentifier>{2f2a7131-6bb7-4371-b42c-5ef8a6b70870}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="LICENSE.md">
Expand All @@ -20,9 +34,20 @@
</None>
</ItemGroup>
<ItemGroup>
<ClInclude Include="librx8.h" />
<ClInclude Include="util.h" />
<ClInclude Include="UDS.h" />
<ClInclude Include="OBD2.h" />
<ClInclude Include="src\util.h">
<Filter>Src</Filter>
</ClInclude>
<ClInclude Include="src\UDS.h">
<Filter>Src</Filter>
</ClInclude>
<ClInclude Include="src\progressbar.h">
<Filter>Src</Filter>
</ClInclude>
<ClInclude Include="src\OBD2.h">
<Filter>Src</Filter>
</ClInclude>
<ClInclude Include="src\librx8.h">
<Filter>Src</Filter>
</ClInclude>
</ItemGroup>
</Project>
10 changes: 5 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.
#include <errno.h>
#include <time.h>

#ifdef WIN32
#if defined(_WIN32) || defined(WIN32) || defined (_WIN64) || defined (WIN64)
#include <tchar.h>
#include <windows.h>
#include <conio.h>
Expand Down Expand Up @@ -211,7 +211,7 @@ int main(int argc, char** argv)
}
}

dumpFile = fopen(dumpFileName, "wba+");
dumpFile = fopen(dumpFileName, "ab+");
if(!dumpFile) {
LOGE(TAG, "Failed to open dump file %s", strerror(errno));
dumpFile = NULL;
Expand Down Expand Up @@ -247,8 +247,8 @@ int main(int argc, char** argv)
LOGI(TAG, "Unlocked ECU");

LOGI(TAG, "Starting ROM dump, this will take a moment..");

time (&dumpStart);
time (&dumpStart);

for(address = 0; address < dumpSize; address+=chunkSize) {
if (ecu->readMem(address, chunkSize, &dump))
Expand All @@ -265,7 +265,7 @@ int main(int argc, char** argv)
fflush(dumpFile);
printProgress(dumpSize, dumpSize);

time(&dumpEnd);
time(&dumpEnd);
LOGI(TAG, "Successfully dumped ROM to %s Took %.0lf seconds", dumpFileName, difftime(dumpEnd,dumpStart));

cleanup:
Expand Down
12 changes: 7 additions & 5 deletions src/progressbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ The Inspired by https://github.com/rpm-software-management/rpm/blob/a7c3886b356c
#include <stdlib.h>
#include <stdint.h>

#ifdef __WIN32__
#error FIX PROGRESS BAR
#if defined(_WIN32) || defined(WIN32) || defined (_WIN64) || defined (WIN64)
#include <io.h>
#define isatty _isatty
#define fileno _fileno
#else
#include <unistd.h>
#endif
Expand All @@ -36,13 +38,13 @@ static size_t progressTotal = 0;
void printProgress(const size_t amount, const size_t total)
{
size_t charsNeeded;
charsTotal = (isatty (STDOUT_FILENO) ? 34 : 40);
charsTotal = (isatty(fileno(stdout)) ? 34 : 40);

if (charsCurrent != charsTotal) {
float pct = (total ? (((float) amount) / total) : 1.0);
charsNeeded = (charsTotal * pct) + 0.5;
while (charsNeeded > charsCurrent) {
if (isatty (STDOUT_FILENO)) {
if (isatty (fileno(stdout))) {
size_t i;
for (i = 0; i < charsCurrent; i++)
putchar ('#');
Expand All @@ -63,7 +65,7 @@ void printProgress(const size_t amount, const size_t total)
if (charsCurrent == charsTotal) {
size_t i;
progressCurrent++;
if (isatty(STDOUT_FILENO)) {
if (isatty(fileno(stdout))) {
for (i = 1; i < charsCurrent; i++) putchar ('#');
pct = (progressTotal ? (((float) progressCurrent) / progressTotal): 1);
fprintf(stdout, " [%3d%%]", (int)((100 * pct) + 0.5));
Expand Down
2 changes: 1 addition & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void dump_msg(PASSTHRU_MSG* msg)
if (msg->RxStatus & START_OF_MESSAGE)
return;

printf("[%lu] [%0b]", msg->Timestamp, msg->RxStatus);
printf("[%lu]", msg->Timestamp);
for (unsigned int i = 0; i < msg->DataSize; i++)
printf("%02X ", msg->Data[i]);
printf("\n");
Expand Down

0 comments on commit e2571e2

Please sign in to comment.