#ifndef _LOCOMOTIVE_H_ #define _LOCOMOTIVE_H_ #include "modelbahn.h" #include "server.h" #define LOCO_F_REVERSE 0x0001 #define LOCO_F_CARGO 0x0002 #define LOCO_F_AUTO 0x0100 #define LOCO_F_RANDOM 0x0200 enum { LOCO_INT_UNDEF = 0, LOCO_INT_DCC14, LOCO_INT_DCC28, LOCO_INT_DCC128 }; struct s_Locomotive { char name[REFERENCENAME_LEN]; // name char ifname[REFERENCENAME_LEN]; // ref. of interface int addr; // address on bus int stepcode; // stepcoding LOCO_INT_DCC... int flags; // flags int vmin; // speed - below this we always set 0 int vslow; // speed - slow entry in trainstation int vmid; // speed - for normal trains (max for cargo trains, on automode) int vfast; // speed - for normal trains int vmax; // speed - maximum speed // dynamic data int speed; // current speed int64_t func; // function enabled ... light... char blockassign; // currently assigned block [+BLOCKREFNAME ... -BLOCKREFNAME] char blocknext; // next block to go to char blockprev; // prev block (mostly assigned block char blockdestination; // destination block } typedef Locomotive; class Locomotives { private: Locomotive *locomotives; int max; int changed; pthread_mutex_t mtx; int Lock(); int UnLock(); // not thread safe JSONParse _GetJSON(int idx); public: Locomotives(); ~Locomotives(); bool IsChanged() { return changed; } void ClearChanged() { changed = 0; }; int Change(Locomotive *loco); int Delete(string name); int SetSpeed(string name, int speed); int SetReverse(string name, int reverse); int SetFunction(string name, int func, int value); int SetSpeedFromBus (string ifname, int addr, int speed); int SetFunctionFromBus (string ifname, int addr, int func); string GetName(int idx); JSONParse GetJSON(string name); void GetJSONAll(JSONParse *json); Locomotive GetLocomotiveFromJSON(JSONParse *j); }; #endif