Desktop Station gateway software for mbed

Dependents:   DSGatewayMBED_Nucleo DSGatewayMBED_Nucleo_Step128

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DSGatewayMBED.h Source File

DSGatewayMBED.h

00001 
00002 
00003 #ifndef DSGATEWAYLIB_H
00004 #define DSGATEWAYLIB_H
00005 
00006 #include "mbed.h"
00007 
00008 #define DSGATEWAY_VERSION 0x01
00009 #define DEBUG false
00010 #define SIZE_PACKET 8
00011 #define TIME_REPLY 200
00012 #define SPI_SSPIN 10
00013 
00014 #define ADDR_MM2     0x0000 // MM2 locomotive
00015 #define ADDR_SX1     0x0800 // Selectrix (old) locomotive
00016 #define ADDR_MFX     0x4000 // MFX locomotive
00017 #define ADDR_SX2     0x8000 // Selectrix (new) locomotive
00018 #define ADDR_DCC     0xC000 // DCC locomotive
00019 #define ADDR_ACC_SX1 0x2000 // Selectrix (old) magnetic accessory
00020 #define ADDR_ACC_MM2 0x2FFF // MM2 magnetic accessory
00021 #define ADDR_ACC_DCC 0x37FF // DCC magnetic accessory
00022 
00023 #define SPEEDSTEP_DCC28 0
00024 #define SPEEDSTEP_DCC14 1
00025 #define SPEEDSTEP_DCC127 2
00026 #define SPEEDSTEP_MM14 0
00027 #define SPEEDSTEP_MM28 1
00028 
00029 #define CMD_PWR_OFF 0x00
00030 #define CMD_PWR_ON  0xF0
00031 
00032 #define CMD_WAIT    0xD0
00033 #define CMD_OK      0x80
00034 #define CMD_CRCERR  0x90
00035 #define CMD_CMDERR  0xA0
00036 #define CMD_UNKERR  0xC0
00037 #define CMD_DCC_IDLE    0xC0
00038 #define CMD_SPEED       0x10
00039 #define CMD_ACCESSORY   0x20
00040 #define CMD_FUNCTION    0x30
00041 #define CMD_CVWRITE     0x40
00042 #define CMD_DIRECTION   0x50
00043 #define CMD_CVREAD      0x60
00044 #define CMD_EXTENTION   0x70
00045 
00046 
00047 /* 特殊・拡張機能用 */
00048 #define EXCMD_NONE      0
00049 
00050 // typedefs
00051  
00052 typedef unsigned char prog_uchar;
00053 typedef unsigned char prog_uint8_t;
00054 typedef unsigned int prog_uint16_t;
00055 typedef unsigned int prog_uint32_t;
00056 typedef unsigned char byte;
00057 typedef bool boolean;
00058 typedef unsigned char prog_uchar;
00059 typedef signed char prog_char;
00060 typedef signed long int word;
00061 
00062 byte lowByte(short int low);
00063 byte highByte(short int high);
00064 unsigned char reverseByte(unsigned char inByte);
00065 
00066 /* Defined functions */
00067 class DSGatewayLib
00068 {
00069   private:
00070     void sendPacket(unsigned char *inPackets);
00071     bool sendMessage(unsigned char *inPackets);
00072     bool exchangeMessage(unsigned char *inPackets, word timeout);
00073     void clearMessage(unsigned char *inPackets);
00074     unsigned char generateCRC(unsigned char *inPackets, unsigned char inLen);
00075     byte convertAcc_MMDCC(word address, byte inSwitch);
00076     bool poweron;
00077     
00078   public:
00079     DSGatewayLib();
00080     ~DSGatewayLib();
00081     void begin();
00082     
00083     bool IsPower();
00084     
00085     bool SetPower(byte power);
00086     bool SetPowerEx(byte power);
00087     bool SetLocoSpeed(word address, int inSpeed);
00088     bool SetLocoSpeedEx(word address, int inSpeed, int inProtcol);
00089     bool SetLocoFunction(word address, unsigned char inFunction, unsigned char inPower);
00090     bool SetLocoDirection(word address, unsigned char inDirection);
00091     //boolean SetTurnout(word address, boolean straight);
00092     bool SetTurnout(word address, byte inSwitch);
00093     bool WriteConfig(word address, word number, byte value);
00094     bool ReadConfig(word address, word number, byte *value);
00095     word GetLocIDProtocol(byte address);
00096 
00097 };
00098 
00099 #endif