aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/BTSR/BTSR.h
blob: db8f2879bf4c6641f368ccfb2d2e296f9b9113ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
 * BTSR.h
 *
 *  Created on: 1 Dec 2020
 *      Author: avi
 */

#ifndef DRIVERS_UART_COMM_BTSR_BTSR_H_
#define DRIVERS_UART_COMM_BTSR_BTSR_H_

#define  Max_BTSR_RX_Bytes 55
#define  Max_BTSR_TX_Bytes 40

#define BTSR_ROLLER_RADIUS 0.021//meter


typedef enum
{
    SOCKS          = 1 ,
    REVERSE_SOCKS  = 2 ,
    MEDICAL_SOCKS  = 3 ,
    PANTYHOSE      = 4 ,
    SEAMLESS       = 5 ,
    KNIT           = 6 ,
    REVERSE_KNIT   = 7 ,
    RASCHEL        = 8 ,
    SEWING         = 9 ,
    FLAT_KNIT      = 10,
    SMALL_LOOM     = 11,
    SHOES          = 12,
    FLAT_SHOES     = 21,
    INLAY          = 22,
    WARP           = 34,
    REWIND         = 35,
}BTSR_APPLICATION;

typedef enum
{
    ELASTOMERIC_YARN = 1,
    ALL_YARNS        = 2,
    ALL_YARNS2       = 3,
    ALL_YARNS3       = 4,
    ELASTIC2         = 5,
    ELASTIC3         = 6,
}BTSR_YARN_TYPE;

typedef enum
{
    BTSR_RISP_OK = 0xFB,
    BTSR_RISP_FAILED = 0xFA,
    BTSR_RISP_OUT_OF_RANFE = 0xF9,
}BTSR_RISP_BYTE;

typedef enum
{
    //BTSR_READ (Read - The highest priority first)
    METER_TOTAL_COUNTER_READ_37_39_41        ,//0
    ALARM_AND_ENABLING_STATUS_READ_30        ,//1
    PC_LINK_READ_32                          ,//2
    ADVANCED_TENSION_READ_23                 ,//3
    ADVANCED_PROGRAMMING_READ_18             ,//4
    APPLICATION_AND_YARN_TYPOLOGY_READ_28    ,//5
    DEVICE_INFORMATION_READ_10               ,//6

    MAX_BTSR_READ                            ,//7

    //BTSR_SET (Set - The highest priority first)
    //Return 0xFA/0xFB/0xF9:
    BAUDRATE_SET_13                          ,//8
    DISPLAY_LANGUAGE_SET_14                  ,//9
    DEVICE_CALIBRATION_11                    ,//10
    CONFIGURATION_SET_15                     ,//11
    ADVANCED_CONFIGURATION_SET_17            ,//12
    //return device + Function code:
    METERS_TOTAL_COUNTER_RESET_38_40_42      ,//13
    //Return 0xFA/0xFB/0xF9:
    RESETS_ALL_THE_COUNTERS_36               ,//14
    ALARM_STATUS_RESET_35                    ,//15
    WORK_TENSION_AND_OPERATION_STATUS_SET_29 ,//16
    ADVANCED_TENSION_PROGRAMMING_21          ,//17
    ADVANCED_STYLE_LOAD_25                   ,//18
    APPLICATION_AND_YARN_TYPOLOGY_SET_27     ,//19
    INPUT_CURRENT_CONTROL_SET_20             ,//20

    MAX_BTSR_SET                              //21
}BTSR_CMD;

typedef enum
{
    RUFeeder1 = 0,
    //RUFeeder2 = 1,
    //RUFeeder3 = 2,
    //RUFeeder4 = 3,

    MaxUFeeders,
}UFeeder_Index;

//BTSR_ALARM_AND_ENABLING_STATUS_READ
typedef struct
{
    bool D0 : 1;//0
    bool D1 : 1;//1
    bool D2 : 1;//2
    bool D3 : 1;//3
    bool D4 : 1;//4
    bool D5 : 1;//5
    bool D6 : 1;//6
    bool D7 : 1;//7
}BITS;


typedef union
{
    BITS Bit[6];
    uint8_t Byte[6];
}BTSR_ALARM_AND_ENABLING_STATUS_READ;

typedef union
{
    struct
    {
        uint8_t SW_VERSION;//0XDE
        uint8_t SW_UNDER_VERSION;//0X01
        uint8_t BYTE_U0X55;//0X55
        uint8_t BYTE_F0X46;//0X46
        uint8_t PRODUCT_CODE;//0X13
        uint8_t TENSION_SENSOR_END_SCALE;//0X65
        uint8_t BOARD_HW_VERSION;//0X02
        uint8_t BOOTLOADER_SW_VERSION;//0X0A
        uint8_t BYTE_0X32;//0X32
        uint8_t SPARE;//0X00
        uint8_t CHECKSUM_LSB;//0X60
        uint8_t CHECKSUM_MSB;//0X01
    }Byte;
uint8_t Buf[12];
}BTSR_DEVICE_INFORMATION_READ;

typedef struct
{
    uint8_t  ID;
    bool     DirectionCCW;
    bool     Flip_Display;
    bool     Lock_Keyboard_Menue;
    float    Radius_Meter;
    uint8_t  Command[MAX_BTSR_SET];
    uint8_t  Application;
    uint8_t  Yarn_Type;
    uint16_t Tension;
    uint16_t Tension_Err;
    uint16_t Alarm_Time;
    uint8_t  Length_Resolution;

    float    LengthInMeter;
    BTSR_ALARM_AND_ENABLING_STATUS_READ  Status;
    BTSR_DEVICE_INFORMATION_READ Info;

}BTSR_t;

extern uint8_t BTSR_RX_Buff[Max_BTSR_RX_Bytes];

unsigned long UARTStatus();
bool BTSR_Change_Comm_Mode(uint8_t Mode);
uint8_t BTSR_Auto_Identify(uint8_t BTSR_ID);//AUTOMATIC IDENTIFICATION PROCEDURE (IDENTIFY)
uint8_t BTSR_Set_Parmeters(uint8_t BTSR_ID, uint8_t Application, uint8_t Yarn_Type );

uint8_t BTSR_Send_Buf(uint8_t *Buf, uint8_t size);
uint8_t BTSR_RECEIVE_Buf(uint8_t *Buf, uint8_t size);
uint8_t BTSR_Calculate_CheckSum(uint8_t *Buf, uint8_t size_without_Checksum);
uint8_t Check_Received_CheckSum(uint8_t CODE_STRING, uint8_t Function_Code, uint8_t *Buf, uint8_t size_include_Checksum);
uint8_t BTSR_Send_Buf_3xADD1(uint8_t *Buf, uint8_t size);//Only for commands with 3 bytes with Address 1 (0x06/0xFD)
void InitConsole_BTSR_UART4(int32_t ui32SysClock);

uint8_t BTSR_State_Machine(UFeeder_Index UFeeder_i);

void BTSR_Init();
void BTSR_RML_Settings(UFeeder_Index UFeeder_i, BTSR_APPLICATION Application, BTSR_YARN_TYPE Yarn_Type, uint16_t Tension, uint16_t Tension_Err, uint16_t Alarm_Time );
void BTSR_Reset_Counters(UFeeder_Index UFeeder_i);//After errors
void BTSR_Reset_Status(UFeeder_Index UFeeder_i);//After errors
void BTSR_Reset_Length(UFeeder_Index UFeeder_i, uint8_t Length_Resolution);//Before job
void BTSR_Read_Length(UFeeder_Index UFeeder_i, uint8_t Length_Resolution);//Every 100msec during thread movement
void BTSR_Read_Errors_Status(UFeeder_Index UFeeder_i);//Every 1 second. 3 seconds debouce for on/off

#endif /* DRIVERS_UART_COMM_BTSR_BTSR_H_ */