Skip to content

Commit

Permalink
Adding COM emulator (Suunto Vyper and Mares Nemo Excel)
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalm committed Dec 26, 2010
1 parent d401a8a commit bdc1f0d
Show file tree
Hide file tree
Showing 19 changed files with 898 additions and 0 deletions.
2 changes: 2 additions & 0 deletions COMputer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ipch
Debug
Binary file added COMputer/COMputer.sdf
Binary file not shown.
20 changes: 20 additions & 0 deletions COMputer/COMputer.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "COMputer", "COMputer\COMputer.vcxproj", "{D43443E2-5AA5-493A-B1C7-E8047F3B92C7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D43443E2-5AA5-493A-B1C7-E8047F3B92C7}.Debug|Win32.ActiveCfg = Debug|Win32
{D43443E2-5AA5-493A-B1C7-E8047F3B92C7}.Debug|Win32.Build.0 = Debug|Win32
{D43443E2-5AA5-493A-B1C7-E8047F3B92C7}.Release|Win32.ActiveCfg = Release|Win32
{D43443E2-5AA5-493A-B1C7-E8047F3B92C7}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file added COMputer/COMputer.suo
Binary file not shown.
2 changes: 2 additions & 0 deletions COMputer/COMputer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ipch
Debug
45 changes: 45 additions & 0 deletions COMputer/COMputer/COMputer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// COMputer.cpp : Defines the entry point for the console application.
//


#include "stdafx.h"
#include "DeviceSuuntoEmu.h"
#include "DeviceNemoEmu.h"

int _tmain(int argc, _TCHAR* argv[])
{
unsigned int choice = 1;
ComDevice *com;

if (argc <= 1)
{
printf("Which computer would you like to emulate ?\n");
printf(" 1. Suunto Vyper\n");
printf(" 2. Mares Nemo Excel\n");
}
else {
choice = _wtoi(argv[1]);
}

switch (choice)
{
case 1:
com = new DeviceSuuntoEmu ("\\\\.\\CNCA0");
break;
case 2:
com = new DeviceNemoEmu ("\\\\.\\CNCA0");
break;
default:
printf("Choice unrecognised");
return(-1);
}

com->open();
com->run();

free(com);
return 0;
}



96 changes: 96 additions & 0 deletions COMputer/COMputer/COMputer.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{D43443E2-5AA5-493A-B1C7-E8047F3B92C7}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>COMputer</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Device.h" />
<ClInclude Include="DeviceNemoEmu.h" />
<ClInclude Include="DeviceSuuntoEmu.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="COMputer.cpp" />
<ClCompile Include="Device.cpp" />
<ClCompile Include="DeviceNemoEmu.cpp" />
<ClCompile Include="DeviceSuuntoEmu.cpp" />
<ClCompile Include="stdafx.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
54 changes: 54 additions & 0 deletions COMputer/COMputer/COMputer.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DeviceSuuntoEmu.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Device.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DeviceNemoEmu.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="COMputer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DeviceSuuntoEmu.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Device.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DeviceNemoEmu.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions COMputer/COMputer/COMputer.vcxproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
88 changes: 88 additions & 0 deletions COMputer/COMputer/Device.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Device.cpp
* FireBreath
*
* Created by Pascal Manchon on 27/11/10.
* Copyright 2010 __MyCompanyName__. All rights reserved.
*
*/

#include "Device.h"

#include <fcntl.h>
#include <string.h>
#include <exception>
/* for strptime prototype - see man strptime */
#ifndef __USE_XOPEN
#define __USE_XOPEN
#endif
#include <time.h>

#ifdef __MACH__
#include <sys/ioctl.h>
#include <sys/termios.h>
#include <stdio.h>
#endif


ComDevice::~ComDevice()
{
if (hCom)
close();
}


void ComDevice::set_rts(RTSStatus status)
{
#ifdef _WIN32
if(!EscapeCommFunction(hCom, status?CLRRTS:SETRTS))
throw std::exception("Error setting RTS on COM Port");
#elif __MACH__

unsigned int bits=TIOCM_RTS;

if(ioctl(hCom,status==RTS_STATUS_ON?TIOCMBIS:TIOCMBIC,&bits)==-1)
throw DBException("Error setting RTS on COM Port");

#else
#error Platform not supported
#endif
}

void ComDevice::set_dtr(DTRStatus status)
{
#ifdef _WIN32
if(!EscapeCommFunction(hCom, status?CLRDTR:SETDTR))
throw "Error setting RTS on COM Port";
#elif __MACH__

unsigned int bits;

if(ioctl(hCom,TIOCMGET,&bits))
throw DBException("Error setting RTS on COM Port");
if(status==DTR_STATUS_ON) bits|=TIOCM_DTR;
else bits&=TIOCM_DTR;
if(ioctl(hCom,TIOCMSET,&bits))
throw DBException("Error setting RTS on COM Port");

#else
#error Platform not supported
#endif
}


void ComDevice::close()
{
set_dtr(DTR_STATUS_OFF);
#ifdef _WIN32
if (!CloseHandle(hCom))
{}
// Logger::append("Warning - Error closing COM Port");
#elif __MACH__
::close(hCom);
#else
#error Platform not supported
//todo : tcsetattr(fd,TCSANOW,&old_termios);
#endif
hCom = NULL;
}
44 changes: 44 additions & 0 deletions COMputer/COMputer/Device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include "stdafx.h"
#include <string>
#include <windows.h>

#define SUUNTO_OK 0

#define SUUNTO_ERR_READ -3
#define SUUNTO_ERR_UNCONNECTED -30
#define SUUNTO_ERR_CRC -4

#define SUUNTO_ERR_CREATEFILE -5
#define SUUNTO_ERR_SETCOMMSTATE -6
#define SUUNTO_ERR_SETSIG -7



typedef enum {
DTR_STATUS_ON=0,
DTR_STATUS_OFF
}DTRStatus;

typedef enum {
RTS_STATUS_ON=0,
RTS_STATUS_OFF
}RTSStatus;



class ComDevice
{
public:
virtual void close();
virtual void run()=0;
virtual void open()=0;
virtual ~ComDevice();
protected:
HANDLE hCom;
void set_dtr(DTRStatus) ;
void set_rts(RTSStatus);
std::string filename;
};

Loading

0 comments on commit bdc1f0d

Please sign in to comment.