Desktop Station gateway software for mbed
Dependents: DSGatewayMBED_Nucleo DSGatewayMBED_Nucleo_Step128
This library provides to control DCC and Marklin Motorola 2 locomtoives and turnouts via DCC/MM2 Shield. Please check our wiki site(http://desktopstation.net/wiki/).
Diff: DSGatewayMBED.h
- Revision:
- 0:96eb8cc345dc
- Child:
- 1:39249e22e9f5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DSGatewayMBED.h Sat Jan 17 01:48:50 2015 +0000 @@ -0,0 +1,98 @@ + + +#ifndef DSGATEWAYLIB_H +#define DSGATEWAYLIB_H + +#include "mbed.h" + +#define DSGATEWAY_VERSION 0x01 +#define DEBUG false +#define SIZE_PACKET 8 +#define TIME_REPLY 200 +#define SPI_SSPIN 10 + +#define ADDR_MM2 0x0000 // MM2 locomotive +#define ADDR_SX1 0x0800 // Selectrix (old) locomotive +#define ADDR_MFX 0x4000 // MFX locomotive +#define ADDR_SX2 0x8000 // Selectrix (new) locomotive +#define ADDR_DCC 0xC000 // DCC locomotive +#define ADDR_ACC_SX1 0x2000 // Selectrix (old) magnetic accessory +#define ADDR_ACC_MM2 0x2FFF // MM2 magnetic accessory +#define ADDR_ACC_DCC 0x37FF // DCC magnetic accessory + +#define SPEEDSTEP_DCC28 0 +#define SPEEDSTEP_DCC14 1 +#define SPEEDSTEP_DCC127 2 +#define SPEEDSTEP_MM14 0 +#define SPEEDSTEP_MM28 1 + +#define CMD_PWR_OFF 0x00 +#define CMD_PWR_ON 0xF0 + +#define CMD_WAIT 0xD0 +#define CMD_OK 0x80 +#define CMD_CRCERR 0x90 +#define CMD_CMDERR 0xA0 +#define CMD_UNKERR 0xC0 +#define CMD_DCC_IDLE 0xC0 +#define CMD_SPEED 0x10 +#define CMD_ACCESSORY 0x20 +#define CMD_FUNCTION 0x30 +#define CMD_CVWRITE 0x40 +#define CMD_DIRECTION 0x50 +#define CMD_CVREAD 0x60 +#define CMD_EXTENTION 0x70 + + +/* 特殊・拡張機能用 */ +#define EXCMD_NONE 0 + +// typedefs + +typedef unsigned char prog_uchar; +typedef unsigned char prog_uint8_t; +typedef unsigned int prog_uint16_t; +typedef unsigned int prog_uint32_t; +typedef unsigned char byte; +typedef bool boolean; +typedef unsigned char prog_uchar; +typedef signed char prog_char; +typedef signed long int word; + +byte lowByte(short int low); +byte highByte(short int high); + +/* Defined functions */ +class DSGatewayLib +{ + private: + void sendPacket(unsigned char *inPackets); + bool sendMessage(unsigned char *inPackets); + bool exchangeMessage(unsigned char *inPackets, word timeout); + void clearMessage(unsigned char *inPackets); + unsigned char generateCRC(unsigned char *inPackets, unsigned char inLen); + byte convertAcc_MMDCC(word address, byte inSwitch); + bool poweron; + + public: + DSGatewayLib(); + ~DSGatewayLib(); + void begin(); + + bool IsPower(); + + bool SetPower(boolean power); + bool SetPowerEx(boolean power); + bool SetLocoSpeed(word address, int inSpeed); + bool SetLocoSpeedEx(word address, int inSpeed, int inProtcol); + bool SetLocoFunction(word address, unsigned char inFunction, unsigned char inPower); + bool SetLocoDirection(word address, unsigned char inDirection); + //boolean SetTurnout(word address, boolean straight); + bool SetTurnout(word address, byte inSwitch); + bool WriteConfig(word address, word number, byte value); + bool ReadConfig(word address, word number, byte *value); + word GetLocIDProtocol(byte address); + +}; + +#endif \ No newline at end of file