You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
2.7 KiB
106 lines
2.7 KiB
|
|
#ifndef _BLOCK_H_
|
|
#define _BLOCK_H_
|
|
|
|
|
|
#include <list>
|
|
#include <string>
|
|
#include <string.h>
|
|
|
|
using namespace std;
|
|
|
|
#include "modelbahn.h"
|
|
#include "server.h"
|
|
|
|
|
|
#define BLOCK_F_OFF 0x0001
|
|
#define BLOCK_F_SPLIT 0x0002 // is this a split block? only works for short
|
|
#define BLOCK_F_SPLITPOS 0x0004 // is this a split block? only works for short
|
|
#define BLOCK_F_SHORT 0x0010
|
|
#define BLOCK_F_ENDSTATION 0x0040
|
|
#define BLOCK_F_STATION 0x0080
|
|
#define BLOCK_F_SPEEDLIMIT 0x0100
|
|
#define BLOCK_F_ONLYCARGO 0x0200
|
|
#define BLOCK_F_ONLYPASSENGER 0x0400
|
|
|
|
/*
|
|
* FIXME: long trains on split blocks
|
|
* FIXME: sample how to set up positive entry side
|
|
*
|
|
* Dirction Pos: from Left to Right Neg: from Right to Left
|
|
* Dirction Pos: from Top to Bottom Neg: from Bottom to Top
|
|
*
|
|
* pos SPLIT BLOCK neg SPLIT BLOCK
|
|
* F_SPLIT | F_SPLITPOS F_SPLIT
|
|
* >----o-------------o------o-------------o---> entry direction
|
|
*
|
|
* ^ ^ ^
|
|
* | | |
|
|
* s_enter[0] s_shortstop[0] | positive_block
|
|
* s_stop[0] negative block
|
|
*/
|
|
|
|
struct s_Block {
|
|
char name[REFERENCENAME_LEN];
|
|
|
|
// default sensors [0].. positive side [1] negative side
|
|
char s_enter[2][REFERENCENAME_LEN];
|
|
char s_slow[2][REFERENCENAME_LEN];
|
|
char s_stop[2][REFERENCENAME_LEN];
|
|
char s_shortstop[2][REFERENCENAME_LEN];
|
|
|
|
char secondblock[REFERENCENAME_LEN]; // short two blocks segment.
|
|
|
|
int flags;
|
|
|
|
char lockedby[REFERENCENAME_LEN]; // element locked by locreference (only set by server, not by JSON/Webinterface)
|
|
} typedef Block;
|
|
|
|
class Blocks {
|
|
private:
|
|
Block *blocks;
|
|
int max;
|
|
int changed;
|
|
|
|
pthread_mutex_t mtx;
|
|
int Lock();
|
|
int UnLock();
|
|
|
|
// not thread safe
|
|
JSONParse _GetJSON(Block *bl);
|
|
JSONParse _GetJSON(int idx) { return _GetJSON(&blocks[idx]); };
|
|
|
|
int last_blockidx; // to speed up things
|
|
Block* FindBlock(string name);
|
|
public:
|
|
Blocks();
|
|
~Blocks();
|
|
|
|
bool IsChanged() { return changed; }
|
|
void ClearChanged() { changed = 0; };
|
|
|
|
int Change(Block *se);
|
|
int Delete(string name);
|
|
|
|
JSONParse GetJSON(string name);
|
|
void GetJSONAll(JSONParse *json);
|
|
Block GetBlockFromJSON(JSONParse *j);
|
|
|
|
int SetOff(string blname);
|
|
int IsOff(string blname);
|
|
|
|
string GetSensorEnter (int direction, string blname);
|
|
string GetSensorSlow (int direction, string blname);
|
|
string GetSensorStop (int direction, string blname);
|
|
string GetSensorShortStop (int direction, string blname);
|
|
int GetFlags (string blname);
|
|
|
|
int SetLockedby (string blname, string lockedby, int lock_onoff);
|
|
string GetLockedby (string blname);
|
|
void ClearLockedby(string name);
|
|
|
|
int Clear(string name);
|
|
};
|
|
|
|
#endif
|