Skip to content
Snippets Groups Projects
Commit d5eb8527 authored by Carl Philipp Klemm's avatar Carl Philipp Klemm
Browse files

Converted into Client libary for coincellhell

parent a84f1e0e
No related branches found
No related tags found
No related merge requests found
Showing
with 175 additions and 103 deletions
SUBSYSTEM=="usb", ATTRS{idVendor}=="fe17", GROUP="uucp"
cmake_minimum_required(VERSION 3.0)
project(eismultiplexer)
project(coincellhell)
find_package(PkgConfig REQUIRED)
find_package(Doxygen)
......@@ -10,7 +10,7 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "..." FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(SRC_FILES eismultiplexer.c usbshm.c)
set(SRC_FILES coincellhell.c usbshm.c)
message("Platform " ${CMAKE_SYSTEM_NAME})
if(WIN32)
......@@ -27,7 +27,7 @@ target_link_libraries(${PROJECT_NAME} ${LIBUSB_LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC ${LIBUSB_INCLUDE_DIRS})
add_definitions("-std=c17 -Wall -O2 -fno-strict-aliasing")
install(TARGETS ${PROJECT_NAME} DESTINATION lib)
install(FILES ./eismultiplexer.h DESTINATION include)
install(FILES ./coincellhell.c DESTINATION include)
link_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(${PROJECT_NAME}_cli main.c)
......@@ -56,5 +56,5 @@ endif (DOXYGEN_FOUND)
if(CMAKE_SYSTEM_NAME MATCHES "^Linux")
set(UDEV_RULES_INSTALL_DIR /lib/udev/rules.d CACHE PATH "install directory for linux udev config")
install(FILES 90-eismultiplexer.rules DESTINATION ${UDEV_RULES_INSTALL_DIR})
install(FILES 90-coincellhell.rules DESTINATION ${UDEV_RULES_INSTALL_DIR})
endif()
File deleted
;!@Install@!UTF-8!
RunProgram="dpscat.exe"
RunProgram="x86:dpinst32.exe"
RunProgram="x64:dpinst64.exe"
GUIMode="2"
;!@InstallEnd@!
\ No newline at end of file
File deleted
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File deleted
File deleted
File deleted
File deleted
File deleted
<!--
Summary of the DPInst XML Elements:
http://msdn.microsoft.com/en-us/library/windows/hardware/ff553383%28v=vs.85%29.aspx
Enabling Language Customization:
http://msdn.microsoft.com/en-us/library/windows/hardware/ff544886%28v=vs.85%29.aspx
Customizing the Items That Appear on the Wizard Pages:
http://msdn.microsoft.com/en-us/library/windows/hardware/ff540265%28v=vs.85%29.aspx
Dpinst.xml Example:
http://msdn.microsoft.com/en-us/library/windows/hardware/ff544778%28v=vs.85%29.aspx
-->
<?xml version="1.0"?>
<dpinst>
<forceIfDriverIsNotBetter>1</forceIfDriverIsNotBetter>
<installAllOrNone>1</installAllOrNone>
</dpinst>
File deleted
File deleted
File deleted
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
SET FILES_TO_PACK=*.inf dpinst* dpscat.* .\data* .\x86* .\amd64*
SET SFX_MODULE=7zDP_LZMA.sfx
SET SFX_MODULE_CFG=7zDP_LZMA.cfg
SET INSTALL_DRIVER_EXE=InstallDriver.exe
SET DRIVER_FILES_7Z=_DriverFiles.7z
SET 7Z_SWITCHES=-air0 -mx
SET CMD_EXIT_CODE=0
IF EXIST "!7ZA_EXE!" (SET 7Z_RUN="!7ZA_EXE!") ELSE CALL :Find7Zip 7za.exe 7z.exe 7zan.exe
IF !7Z_RUN! EQU "" (
ECHO 7Zip is required to re-pack this installer.
ECHO 1] Download and install 7Zip. http://www.7-zip.org/
ECHO 2] Add the bin folder to the PATH environment variable.
ECHO "Control Panel->System->Advanced->Environment Variables..."
SET CMD_EXIT_CODE=1
GOTO Error
)
IF EXIST "!INSTALL_DRIVER_EXE!" DEL /Q "!INSTALL_DRIVER_EXE!"
IF NOT "!ERRORLEVEL!" EQU "0" (
ECHO Access denied or file in-use "!INSTALL_DRIVER_EXE!"
SET CMD_EXIT_CODE=2
GOTO Error
)
IF EXIST "!DRIVER_FILES_7Z!" DEL /Q "!DRIVER_FILES_7Z!"
IF NOT "!ERRORLEVEL!" EQU "0" (
ECHO Access denied or file in-use "!DRIVER_FILES_7Z!"
SET CMD_EXIT_CODE=3
GOTO Error
)
!7Z_RUN! a "!DRIVER_FILES_7Z!" !FILES_TO_PACK! !7Z_SWITCHES!
IF NOT "!ERRORLEVEL!" EQU "0" (
ECHO Failed re-packing. Check your 7Zip installation at
ECHO !7Z_RUN!
SET CMD_EXIT_CODE=4
GOTO Error
)
COPY /B "!SFX_MODULE!"+"!SFX_MODULE_CFG!"+"!DRIVER_FILES_7Z!" "!INSTALL_DRIVER_EXE!"
ECHO.
ECHO Done.
ECHO "!INSTALL_DRIVER_EXE!" re-packed!
GOTO :EOF
:Find7Zip
IF EXIST "%~dp0\%~1" (
SET 7Z_RUN="%~dp0\%~1"
ECHO 7Zip found at: !7Z_RUN!
GOTO :EOF
)
SET 7Z_RUN="%~$PATH:1"
IF NOT !7Z_RUN! EQU "" (
ECHO 7Zip found at: !7Z_RUN!
SET 7Z_RUN="%~1"
GOTO :EOF
)
SHIFT /1
IF "%~1" EQU "" GOTO :EOF
GOTO Find7Zip
GOTO :EOF
:Error
IF NOT DEFINED NO_REPACK_ERROR_WAIT PAUSE
EXIT %CMD_EXIT_CODE%
GOTO :EOF
\ No newline at end of file
File deleted
File deleted
File deleted
......@@ -28,11 +28,17 @@
#define _POSIX_C_SOURCE 199309L
#include <stdint.h>
#include "eismultiplexer.h"
#include "usbshm.h"
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <assert.h>
#include "coincellhell.h"
#include "usbshm.h"
#include "usbcommands.h"
#define VID 0xfe17
#define PID 0x08dc
static void usleep(uint64_t microseconds)
{
......@@ -42,90 +48,124 @@ static void usleep(uint64_t microseconds)
nanosleep(&ts, NULL);
}
int eismultiplexer_connect(struct eismultiplexer* muliplexer, uint16_t serial)
int coincellhell_connect(struct coincellhell* hell, uint16_t serial)
{
int ret;
muliplexer->priv = malloc(sizeof(*muliplexer->priv));
if(!muliplexer->priv)
hell->priv = malloc(sizeof(*hell->priv));
if(!hell->priv)
return -1;
ret = usbshm_init(muliplexer->priv, NULL, muliplexer);
ret = usbshm_init(hell->priv, NULL, hell);
if(ret)
return -2;
unsigned char serialStr[5];
snprintf((char*)serialStr, sizeof(serialStr), "%04hu", serial);
ret = usbshm_open(muliplexer->priv, 0xfe17, 0x07dc , serial == 0 ? NULL : serialStr);
ret = usbshm_open(hell->priv, VID, PID , serial == 0 ? NULL : serialStr);
if(ret)
return -3;
return 0;
}
int eismultiplexer_connect_channel_exclusive(struct eismultiplexer* muliplexer, channel_t channel)
int coincellhell_get_temperature(struct coincellhell* hell, uint8_t heater, temperature_sensor_location_t location, float* temperature)
{
uint16_t wValue;
// we compile with fno-strict-aliasing
uint8_t* wValChar = (uint8_t*)&wValue;
wValChar[0] = channel;
wValChar[1] = 0;
int16_t temperatureRaw = 0;
uint8_t *dataPtr = (uint8_t*)&temperatureRaw;
int ret;
while((ret = usbshm_writeControlTransfer(muliplexer->priv, 2, NULL, 0, wValue, 0)) == USBSHM_ERROR_AGAIN)
while((ret = usbshm_readControlTransferSync(hell->priv, COMMAND_GET_TEMPERATURE, location, heater, dataPtr, 2)) == USBSHM_ERROR_AGAIN)
usleep(1000000);
*temperature = temperatureRaw/10.0f;
return ret;
}
int eismultiplexer_connect_channel(struct eismultiplexer* muliplexer, channel_t channel)
int coincellhell_set_temperature(struct coincellhell* hell, uint8_t heater, float temperature)
{
channel_t channels = eismultiplexer_get_connected(muliplexer);
channels |= channel;
return eismultiplexer_connect_channel_exclusive(muliplexer, channels);
if(temperature*10.0f > INT16_MAX || temperature*10.0f < INT16_MIN)
return -6;
int ret;
while((ret = usbshm_writeControlTransfer(hell->priv, COMMAND_SET_TEMPERATURE, NULL, 0, temperature*10.0f, heater)) == USBSHM_ERROR_AGAIN)
usleep(100000);
return ret;
}
int eismultiplexer_disconnect_channel(struct eismultiplexer* muliplexer, channel_t channel)
int coincellhell_get_temperature_setpoint(struct coincellhell* hell, uint8_t heater, float* temperature)
{
channel_t channels = CHANNEL_NONE;
if(channel != CHANNEL_NONE)
int16_t temperatureRaw = 0;
uint8_t *dataPtr = (uint8_t*)&temperatureRaw;
int ret;
while((ret = usbshm_readControlTransferSync(hell->priv, COMMAND_GET_TEMPERATURE_SETPOINT, 0, heater, dataPtr, 2)) == USBSHM_ERROR_AGAIN)
usleep(100000);
*temperature = temperatureRaw/10.0f;
return ret;
}
int coincellhell_check_ready(struct coincellhell* hell, bool* ready)
{
channels = eismultiplexer_get_connected(muliplexer);
channels &= ~channel;
*ready = false;
int ret;
while((ret = usbshm_readControlTransferSync(hell->priv, COMMAND_READY, 0, 0, (uint8_t*)ready, 1)) == USBSHM_ERROR_AGAIN)
usleep(100000);
return ret;
}
return eismultiplexer_connect_channel_exclusive(muliplexer, channels);
int coincellhell_set_temperature_ramp(struct coincellhell* hell, uint8_t heater, time_t end_time, float temperature)
{
return -1;
}
channel_t eismultiplexer_get_connected(struct eismultiplexer* muliplexer)
int coincellhell_cancle_ramp(struct coincellhell* hell, uint8_t heater)
{
uint8_t buffer[2] = {};
usbshm_readControlTransferSync(muliplexer->priv, 3, 0, 0, buffer, 1);
return buffer[0];
return -1;
}
int coincellhell_get_ramping(struct coincellhell* hell, uint8_t heater, bool* ramping)
{
return -1;
}
int eismultiplexer_set_led(struct eismultiplexer* muliplexer, bool on)
int coincellhell_set_led(struct coincellhell* hell, bool on)
{
int ret;
while((ret = usbshm_writeControlTransfer(muliplexer->priv, on, NULL, 0, 0, 0)) == USBSHM_ERROR_AGAIN)
usleep(1000000);
while((ret = usbshm_writeControlTransfer(hell->priv, on ? COMMAND_LED_ON : COMMAND_LED_OFF, NULL, 0, 0, 0)) == USBSHM_ERROR_AGAIN)
usleep(100000);
return ret;
}
int eismultiplexer_write_eeprom(struct eismultiplexer* muliplexer, uint16_t addr, uint16_t value)
int coincellhell_write_eeprom(struct coincellhell* hell, uint16_t addr, uint16_t value)
{
int ret;
while((ret = usbshm_writeControlTransfer(muliplexer->priv, 5, NULL, 0, value, addr)) == USBSHM_ERROR_AGAIN)
usleep(1000000);
while((ret = usbshm_writeControlTransfer(hell->priv, COMMAND_WRITE_EEPROM, NULL, 0, value, addr)) == USBSHM_ERROR_AGAIN)
usleep(100000);
return ret;
}
uint16_t eismultiplexer_read_eeprom(struct eismultiplexer* muliplexer, uint16_t addr)
uint16_t coincellhell_read_eeprom(struct coincellhell* hell, uint16_t addr)
{
uint8_t buffer[2] = {};
usbshm_readControlTransferSync(muliplexer->priv, 4, 0, addr, buffer, 2);
usbshm_readControlTransferSync(hell->priv, COMMAND_READ_EEPROM, 0, addr, buffer, 2);
return *((uint16_t*)buffer);
}
void eismultiplexer_disconnect(struct eismultiplexer* muliplexer)
uint8_t coincellhell_read_oscal(struct coincellhell* hell)
{
usbshm_distroy(muliplexer->priv);
free(muliplexer->priv);
muliplexer->priv = NULL;
uint8_t oscal;
usbshm_readControlTransferSync(hell->priv, COMMAND_READ_OSCAL, 0, 0, &oscal, 1);
return oscal;
}
uint32_t coincellhell_get_seconds(struct coincellhell* hell)
{
uint32_t seconds;
usbshm_readControlTransferSync(hell->priv, COMMAND_GET_SECONDS, 0, 0, (uint8_t*)&seconds, 4);
return seconds;
}
void coincellhell_disconnect(struct coincellhell* hell)
{
usbshm_distroy(hell->priv);
free(hell->priv);
hell->priv = NULL;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment