Intial commit with original files, docs and modified Linux source.

This commit is contained in:
2019-04-13 00:24:49 -04:00
commit 754b8ccb3a
111 changed files with 13099 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
PROG = scwr
OBJS = $(PROG).o
include ../build/Makefile_hidprog.inc
+280
View File
@@ -0,0 +1,280 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <memory.h>
#include "../common/rawhid.h"
#include "../common/rawhid_defs.h"
typedef unsigned char u_char;
#define LSB(n) (u_char)((n) & 255)
#define MSB(n) (u_char)(((n) >> 8) & 255)
#define FILE_HEADER_LEN 2
#define WRITE_PACKET_HEADER_LEN 4
#define WRITE_PACKET_DATA_LEN (PACKET_LEN - WRITE_PACKET_HEADER_LEN)
#define EEPROM_HEADER_LEN 4
#define EEPROM_FOOTER_LEN 2
#define MAX_EEPROM_SIZE 8192
#define SETTINGS_HEADER_LEN 4
#define SETTINGS_MAX_LEN (MAX_EEPROM_SIZE - EEPROM_HEADER_LEN - EEPROM_FOOTER_LEN)
#define SETTINGS_FILE_MIN_LEN (FILE_HEADER_LEN + SETTINGS_HEADER_LEN)
#define SETTINGS_FILE_MAX_LEN (SETTINGS_MAX_LEN + FILE_HEADER_LEN)
#define FILE_BUF_LEN (SETTINGS_FILE_MAX_LEN + 1)
int do_compatibility_check(u_char ver_major, u_char ver_minor, int len)
{
u_char hbuf[64];
int err = 0;
if ( !err ) {
printf("scwr: sending info request: ");
hbuf[0] = RQ_INFO;
if ( 64 != rawhid_send(0, hbuf, 64, 100) ) {
err = 2;
printf("failed\n");
} else {
printf("ok\n");
}
}
if ( !err ) {
printf("device: ");
if ( 64 != rawhid_recv(0, hbuf, 64, 220) ) {
err = 3;
printf("failed to respond\n");
}
}
if ( !err ) {
if ( hbuf[0] != RC_OK ) {
err = 4;
printf("not ok\n");
} else {
printf("ok\n");
}
}
if ( !err ) {
u_char settings_max_ver_major = 0;
u_char settings_max_ver_minor = 0;
u_char protocol_ver_major = 0;
u_char protocol_ver_minor = 0;
int max_len = 0;
for ( int i = 1; i < 64; i += 3 ) {
u_char ic = hbuf[i];
if ( ic == IC_END ) {
break;
}
switch ( ic ) {
case IC_PROTOCOL_VERSION:
protocol_ver_major = hbuf[i+1];
protocol_ver_minor = hbuf[i+2];
break;
case IC_CONFIG_MAX_VERSION:
settings_max_ver_major = hbuf[i+1];
settings_max_ver_minor = hbuf[i+2];
break;
case IC_EEPROM_SIZE:
max_len = hbuf[i+1] + 256 * hbuf[i+2] - EEPROM_HEADER_LEN - EEPROM_FOOTER_LEN;
break;
}
}
printf("protocol version check: converter=%d.%02d, scwr=%d.%02d: ", protocol_ver_major, protocol_ver_minor, PROTOCOL_VERSION_MAJOR, PROTOCOL_VERSION_MINOR);
if ( protocol_ver_major != PROTOCOL_VERSION_MAJOR || protocol_ver_minor < PROTOCOL_VERSION_MINOR ) {
err = 12;
printf("failed\n");
} else {
printf("ok\n");
}
printf("settings version check: converter=%d.%02d, file=%d.%02d: ", settings_max_ver_major, settings_max_ver_minor, ver_major, ver_minor);
if ( settings_max_ver_major != ver_major || settings_max_ver_minor < ver_minor ) {
err = 12;
printf("failed\n");
} else {
printf("ok\n");
}
printf("settings length check: max=%d, file=%d bytes: ", max_len, len);
if ( len > max_len ) {
err = 12;
printf("failed\n");
} else {
printf("ok\n");
}
}
return err;
}
int do_write(const char* fname)
{
u_char fbuf[FILE_BUF_LEN];
size_t fbuflen = 0;
int err = 0;
if ( !err ) {
printf("scwr: reading file: ");
FILE* f = fopen(fname, "rb");
if ( f ) {
fbuflen = fread(fbuf, 1, FILE_BUF_LEN, f);
fclose(f);
printf("%u bytes: ", fbuflen);
} else {
printf("failed\n");
}
}
if ( !err ) {
if ( fbuflen < SETTINGS_FILE_MIN_LEN ) {
err = 1;
printf("too short\n");
}
if ( fbuflen > SETTINGS_FILE_MAX_LEN ) {
err = 1;
printf("too long\n");
}
}
if ( !err ) {
if ( fbuf[0] != 'S' ) {
err = 11;
}
if ( fbuf[1] != 'C' ) {
err = 11;
}
if ( err ) {
printf("bad signature\n");
} else {
printf("ok\n");
}
}
size_t remaining = fbuflen - FILE_HEADER_LEN;
if ( !err ) {
err = do_compatibility_check(fbuf[2], fbuf[3], (int)remaining);
}
u_char hbuf[PACKET_LEN];
if ( !err ) {
printf("scwr: sending write request for %u bytes: ", remaining);
hbuf[0] = RQ_WRITE;
hbuf[1] = LSB(remaining);
hbuf[2] = MSB(remaining);
if ( PACKET_LEN != rawhid_send(0, hbuf, PACKET_LEN, 100) ) {
err = 2;
printf("failed\n");
} else {
printf("ok\n");
}
}
if ( !err ) {
printf("device: ");
if ( PACKET_LEN != rawhid_recv(0, hbuf, PACKET_LEN, 220) ) {
err = 3;
printf("failed to respond\n");
}
}
if ( !err ) {
if ( hbuf[0] != RC_OK ) {
err = 4;
printf("not ok\n");
} else {
printf("ok\n");
}
}
u_char* p = fbuf + FILE_HEADER_LEN;
while ( !err && remaining ) {
if ( !err ) {
printf("device: ");
if ( PACKET_LEN != rawhid_recv(0, hbuf, PACKET_LEN, 2000) ) {
err = 5;
printf("failed to respond\n");
}
}
if ( !err ) {
if ( hbuf[0] != RC_READY ) {
err = 6;
printf("not ready\n");
} else {
printf("ready\n");
}
}
if ( !err ) {
// size_t len = remaining > 64 ? 64 : remaining;
size_t len = remaining > WRITE_PACKET_DATA_LEN ? WRITE_PACKET_DATA_LEN : remaining;
hbuf[0] = RQ_CONTINUATION | RQ_WRITE;
hbuf[1] = (u_char)len;
size_t ofs = p - fbuf + FILE_HEADER_LEN;
hbuf[2] = LSB(ofs);
hbuf[3] = MSB(ofs);
for ( size_t i = 0; i < len; ++i ) {
hbuf[i + WRITE_PACKET_HEADER_LEN] = p[i];
}
printf("scwr: sending %u bytes: ", len);
// if ( 64 != rawhid_send(0, p, 64, 100) ) {
if ( PACKET_LEN != rawhid_send(0, hbuf, PACKET_LEN, 100) ) {
err = 2;
printf("failed\n");
} else {
remaining -= len;
p += len;
printf("ok\n");
}
}
if ( !err ) {
printf("device: ");
if ( PACKET_LEN != rawhid_recv(0, hbuf, PACKET_LEN, 220) ) {
err = 3;
printf("failed to respond\n");
}
}
if ( !err ) {
if ( hbuf[0] != RC_OK ) {
err = 4;
printf("not ok\n");
} else {
printf("ok\n");
}
}
}
if ( !err ) {
printf("device: ");
if ( PACKET_LEN != rawhid_recv(0, hbuf, PACKET_LEN, 2000) ) {
err = 5;
printf("failed to respond\n");
}
}
if ( !err ) {
if ( hbuf[0] != RC_COMPLETED ) {
err = 7;
printf("not complete\n");
} else {
printf("complete\n");
}
}
return err;
}
int main(int argc, char** argv)
{
printf("scwr v1.10\n");
if ( argc != 2 ) {
fprintf(stderr, "usage: scwr <config_binary>\n");
return 0;
}
printf("scwr: looking for Soarer\'s Converter: ");
int r = rawhid_open(1, SC_VID, SC_PID, SC_USAGE_PAGE, SC_USAGE);
if (r <= 0) {
printf("not found\n");
return -1;
}
printf("found\n");
int err = do_write(argv[1]);
if ( err ) {
//printf("\nerror %d\n", err);
}
rawhid_close(0);
return 0;
}
+21
View File
@@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scwr", "scwr.vcproj", "{63366BE7-6C6E-43E0-A59B-16AFB7DDF369}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{63366BE7-6C6E-43E0-A59B-16AFB7DDF369}.Debug.ActiveCfg = Debug|Win32
{63366BE7-6C6E-43E0-A59B-16AFB7DDF369}.Debug.Build.0 = Debug|Win32
{63366BE7-6C6E-43E0-A59B-16AFB7DDF369}.Release.ActiveCfg = Release|Win32
{63366BE7-6C6E-43E0-A59B-16AFB7DDF369}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal
+150
View File
@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="scwr"
ProjectGUID="{63366BE7-6C6E-43E0-A59B-16AFB7DDF369}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/scwr.exe"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/scwr.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="../bin"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="4"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/scwr.exe"
LinkIncremental="1"
GenerateDebugInformation="FALSE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\scwr.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
CompileAs="2"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
CompileAs="2"/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath="..\common\rawhid_defs.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
</Filter>
<File
RelativePath="..\lib\rawhid.lib">
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>