/*

  *.PbcCapt File Format

*/

// At the beginning of ever .PbcCapt file
typedef struct
{
    WORD    Mark;   // Fixed value for verification
    WORD    Baud;
    DWORD   AnxIp;
    char    AnxName[32];
} PBC_CAPTFILE_HDR;

// defines related to Mark
#define PBC_CAPTFILE_MARK   0xa502

// defines related to Baud
#define PBCAP_BAUD_12M      1   // TmeStmp  48     Mhz (Baud X  4)
#define PBCAP_BAUD_6M       2   // TmeStmp  48     Mhz (Baud X  8)
#define PBCAP_BAUD_3M       3   // TmeStmp  48     Mhz (Baud X 16)
#define PBCAP_BAUD_1M5      4   // TmeStmp  24     Mhz (Baud X 16)
#define PBCAP_BAUD_500K     5   // TmeStmp   8     Mhz (Baud X 16)
#define PBCAP_BAUD_187K5    6   // TmeStmp   3     Mhz (Baud X 16)
#define PBCAP_BAUD_93K75    7   // TmeStmp   1.5   Mhz (Baud X 16)
#define PBCAP_BAUD_19K2     8   // TmeStmp 307.200 Khz (Baud X 16)
#define PBCAP_BAUD_9K6      9   // TmeStmp 153.600 Khz (Baud X 16)

typedef struct
{
    BYTE    SyncMark;
    BYTE    TmeStmp[6]; // 24 bit time stamp
    BYTE    Len;        // Length of Data in bytes
    BYTE    Data[1];    // Variable length Data
//  BYTE    Sts;        // Byte after all Data
} PBC_FRM_HDR;

// defines related to SyncMark
#define PBC_SYNC_MARK       0xdd

// TmeStmp Conversion to pico seconds
//       Baud  TmeStmpClk        Mult    Div
// ----------  ----------  ---------- ------
// 12,000,000  48,000,000       1,000     48
//  6,000,000  48,000,000       1,000     48
//  3,000,000  48,000,000       1,000     48
//  1,500,000  24,000,000       1,000     24
//    500,000   8,000,000       1,000      8
//    187,500   3,000,000       1,000      3
//     93,750   1,500,000      10,000     15
//     19,200     307,200  10,000,000  3,072
//      9,600     153,600  10,000,000  1,536

// defines related to Sts
#define PBC_STS_OK           0x00
#define PBC_STS_STP_ERR      0x01
#define PBC_STS_PAR_ERR      0x02
#define PBC_STS_SD_ERR       0x04
#define PBC_STS_RPT_ERR      0x08
#define PBC_STS_UND_ERR      0x10
#define PBC_STS_OVR_ERR      0x20
#define PBC_STS_FCS_ERR      0x40
#define PBC_STS_ED_ERR       0x80

// Defines related to Profibus Frames
#define PBC_SD_SD1           0x10
#define PBC_SD_SD2           0x68
#define PBC_SD_SD3           0xa2
#define PBC_SD_SD4           0xdc
#define PBC_SD_SC            0xe5
#define PBC_ED               0x16

#define PBC_FCS_SmTIME1      0x00
#define PBC_FCS_SmSRD        0x01
#define PBC_FCS_SmSDN        0x02
#define PBC_FCS_SDAL         0x03
#define PBC_FCS_SDNL         0x04
#define PBC_FCS_SDAH         0x05
#define PBC_FCS_SDNH         0x06
#define PBC_FCS_RDD          0x07
#define PBC_FCS_DiagSRD      0x08
#define PBC_FCS_RFDL         0x09
#define PBC_FCS_SmSRDSltDel  0x0a
#define PBC_FCS_SmSRDSltKeep 0x0b
#define PBC_FCS_SRDL         0x0c
#define PBC_FCS_SRDH         0x0d
#define PBC_FCS_RIR          0x0e
#define PBC_FCS_RLSR         0x0f
#define PBC_FCS_SmTIME2      0x80

#define PBC_FCR_OK           0x0
#define PBC_FCR_UE           0x1
#define PBC_FCR_RR           0x2
#define PBC_FCR_RS           0x3
#define PBC_FCR_DL           0x8
#define PBC_FCR_NR           0x9
#define PBC_FCR_DH           0xa
#define PBC_FCR_RDL          0xc
#define PBC_FCR_RDH          0xd