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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
|
/****************************************************************************
(c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
www.systec-electronic.com
Project: openPOWERLINK
Description: source file for SDO Command Layer module
License:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of SYSTEC electronic GmbH nor the names of its
contributors may be used to endorse or promote products derived
from this software without prior written permission. For written
permission, please contact info@systec-electronic.com.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Severability Clause:
If a provision of this License is or becomes illegal, invalid or
unenforceable in any jurisdiction, that shall not affect:
1. the validity or enforceability in that jurisdiction of any other
provision of this License; or
2. the validity or enforceability in other jurisdictions of that or
any other provision of this License.
-------------------------------------------------------------------------
$RCSfile: EplSdoComu.c,v $
$Author: D.Krueger $
$Revision: 1.14 $ $Date: 2008/10/17 15:32:32 $
$State: Exp $
Build Environment:
GCC V3.4
-------------------------------------------------------------------------
Revision History:
2006/06/26 k.t.: start of the implementation
****************************************************************************/
#include "user/EplSdoComu.h"
#if ((((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) == 0) &&\
(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) == 0) )
#error 'ERROR: At least SDO Server or SDO Client should be activate!'
#endif
#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0)
#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDU)) == 0) && (EPL_OBD_USE_KERNEL == FALSE)
#error 'ERROR: SDO Server needs OBDu module!'
#endif
#endif
/***************************************************************************/
/* */
/* */
/* G L O B A L D E F I N I T I O N S */
/* */
/* */
/***************************************************************************/
//---------------------------------------------------------------------------
// const defines
//---------------------------------------------------------------------------
#ifndef EPL_MAX_SDO_COM_CON
#define EPL_MAX_SDO_COM_CON 5
#endif
//---------------------------------------------------------------------------
// local types
//---------------------------------------------------------------------------
// intern events
typedef enum {
kEplSdoComConEventSendFirst = 0x00, // first frame to send
kEplSdoComConEventRec = 0x01, // frame received
kEplSdoComConEventConEstablished = 0x02, // connection established
kEplSdoComConEventConClosed = 0x03, // connection closed
kEplSdoComConEventAckReceived = 0x04, // acknowledge received by lower layer
// -> continue sending
kEplSdoComConEventFrameSended = 0x05, // lower has send a frame
kEplSdoComConEventInitError = 0x06, // error duringinitialisiation
// of the connection
kEplSdoComConEventTimeout = 0x07 // timeout in lower layer
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
,
kEplSdoComConEventInitCon = 0x08, // init connection (only client)
kEplSdoComConEventAbort = 0x09 // abort sdo transfer (only client)
#endif
} tEplSdoComConEvent;
typedef enum {
kEplSdoComSendTypeReq = 0x00, // send a request
kEplSdoComSendTypeAckRes = 0x01, // send a resonse without data
kEplSdoComSendTypeRes = 0x02, // send response with data
kEplSdoComSendTypeAbort = 0x03 // send abort
} tEplSdoComSendType;
// state of the state maschine
typedef enum {
// General State
kEplSdoComStateIdle = 0x00, // idle state
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0)
// Server States
kEplSdoComStateServerSegmTrans = 0x01, // send following frames
#endif
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
// Client States
kEplSdoComStateClientWaitInit = 0x10, // wait for init connection
// on lower layer
kEplSdoComStateClientConnected = 0x11, // connection established
kEplSdoComStateClientSegmTrans = 0x12 // send following frames
#endif
} tEplSdoComState;
// control structure for transaction
typedef struct {
tEplSdoSeqConHdl m_SdoSeqConHdl; // if != 0 -> entry used
tEplSdoComState m_SdoComState;
u8 m_bTransactionId;
unsigned int m_uiNodeId; // NodeId of the target
// -> needed to reinit connection
// after timeout
tEplSdoTransType m_SdoTransType; // Auto, Expedited, Segmented
tEplSdoServiceType m_SdoServiceType; // WriteByIndex, ReadByIndex
tEplSdoType m_SdoProtType; // protocol layer: Auto, Udp, Asnd, Pdo
u8 *m_pData; // pointer to data
unsigned int m_uiTransSize; // number of bytes
// to transfer
unsigned int m_uiTransferredByte; // number of bytes
// already transferred
tEplSdoFinishedCb m_pfnTransferFinished; // callback function of the
// application
// -> called in the end of
// the SDO transfer
void *m_pUserArg; // user definable argument pointer
DWORD m_dwLastAbortCode; // save the last abort code
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
// only for client
unsigned int m_uiTargetIndex; // index to access
unsigned int m_uiTargetSubIndex; // subiondex to access
// for future use
unsigned int m_uiTimeout; // timeout for this connection
#endif
} tEplSdoComCon;
// instance table
typedef struct {
tEplSdoComCon m_SdoComCon[EPL_MAX_SDO_COM_CON];
#if defined(WIN32) || defined(_WIN32)
LPCRITICAL_SECTION m_pCriticalSection;
CRITICAL_SECTION m_CriticalSection;
#endif
} tEplSdoComInstance;
//---------------------------------------------------------------------------
// modul globale vars
//---------------------------------------------------------------------------
static tEplSdoComInstance SdoComInstance_g;
//---------------------------------------------------------------------------
// local function prototypes
//---------------------------------------------------------------------------
tEplKernel EplSdoComReceiveCb(tEplSdoSeqConHdl SdoSeqConHdl_p,
tEplAsySdoCom *pAsySdoCom_p,
unsigned int uiDataSize_p);
tEplKernel EplSdoComConCb(tEplSdoSeqConHdl SdoSeqConHdl_p,
tEplAsySdoConState AsySdoConState_p);
static tEplKernel EplSdoComSearchConIntern(tEplSdoSeqConHdl SdoSeqConHdl_p,
tEplSdoComConEvent SdoComConEvent_p,
tEplAsySdoCom * pAsySdoCom_p);
static tEplKernel EplSdoComProcessIntern(tEplSdoComConHdl SdoComCon_p,
tEplSdoComConEvent SdoComConEvent_p,
tEplAsySdoCom * pAsySdoCom_p);
static tEplKernel EplSdoComTransferFinished(tEplSdoComConHdl SdoComCon_p,
tEplSdoComCon * pSdoComCon_p,
tEplSdoComConState
SdoComConState_p);
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0)
static tEplKernel EplSdoComServerInitReadByIndex(tEplSdoComCon * pSdoComCon_p,
tEplAsySdoCom * pAsySdoCom_p);
static tEplKernel EplSdoComServerSendFrameIntern(tEplSdoComCon * pSdoComCon_p,
unsigned int uiIndex_p,
unsigned int uiSubIndex_p,
tEplSdoComSendType SendType_p);
static tEplKernel EplSdoComServerInitWriteByIndex(tEplSdoComCon * pSdoComCon_p,
tEplAsySdoCom * pAsySdoCom_p);
#endif
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
static tEplKernel EplSdoComClientSend(tEplSdoComCon * pSdoComCon_p);
static tEplKernel EplSdoComClientProcessFrame(tEplSdoComConHdl SdoComCon_p,
tEplAsySdoCom * pAsySdoCom_p);
static tEplKernel EplSdoComClientSendAbort(tEplSdoComCon * pSdoComCon_p,
DWORD dwAbortCode_p);
#endif
/***************************************************************************/
/* */
/* */
/* C L A S S <SDO Command Layer> */
/* */
/* */
/***************************************************************************/
//
// Description: SDO Command layer Modul
//
//
/***************************************************************************/
//=========================================================================//
// //
// P U B L I C F U N C T I O N S //
// //
//=========================================================================//
//---------------------------------------------------------------------------
//
// Function: EplSdoComInit
//
// Description: Init first instance of the module
//
//
//
// Parameters:
//
//
// Returns: tEplKernel = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
tEplKernel EplSdoComInit(void)
{
tEplKernel Ret;
Ret = EplSdoComAddInstance();
return Ret;
}
//---------------------------------------------------------------------------
//
// Function: EplSdoComAddInstance
//
// Description: Init additional instance of the module
//
//
//
// Parameters:
//
//
// Returns: tEplKernel = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
tEplKernel EplSdoComAddInstance(void)
{
tEplKernel Ret;
Ret = kEplSuccessful;
// init controll structure
EPL_MEMSET(&SdoComInstance_g, 0x00, sizeof(SdoComInstance_g));
// init instance of lower layer
Ret = EplSdoAsySeqAddInstance(EplSdoComReceiveCb, EplSdoComConCb);
if (Ret != kEplSuccessful) {
goto Exit;
}
#if defined(WIN32) || defined(_WIN32)
// create critical section for process function
SdoComInstance_g.m_pCriticalSection =
&SdoComInstance_g.m_CriticalSection;
InitializeCriticalSection(SdoComInstance_g.m_pCriticalSection);
#endif
Exit:
return Ret;
}
//---------------------------------------------------------------------------
//
// Function: EplSdoComDelInstance
//
// Description: delete instance of the module
//
//
//
// Parameters:
//
//
// Returns: tEplKernel = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
tEplKernel EplSdoComDelInstance(void)
{
tEplKernel Ret;
Ret = kEplSuccessful;
#if defined(WIN32) || defined(_WIN32)
// delete critical section for process function
DeleteCriticalSection(SdoComInstance_g.m_pCriticalSection);
#endif
Ret = EplSdoAsySeqDelInstance();
if (Ret != kEplSuccessful) {
goto Exit;
}
Exit:
return Ret;
}
//---------------------------------------------------------------------------
//
// Function: EplSdoComDefineCon
//
// Description: function defines a SDO connection to another node
// -> init lower layer and returns a handle for the connection.
// Two client connections to the same node via the same protocol
// are not allowed. If this function detects such a situation
// it will return kEplSdoComHandleExists and the handle of
// the existing connection in pSdoComConHdl_p.
// Using of existing server connections is possible.
//
// Parameters: pSdoComConHdl_p = pointer to the buffer of the handle
// uiTargetNodeId_p = NodeId of the targetnode
// ProtType_p = type of protocol to use for connection
//
//
// Returns: tEplKernel = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
tEplKernel EplSdoComDefineCon(tEplSdoComConHdl *pSdoComConHdl_p,
unsigned int uiTargetNodeId_p,
tEplSdoType ProtType_p)
{
tEplKernel Ret;
unsigned int uiCount;
unsigned int uiFreeHdl;
tEplSdoComCon *pSdoComCon;
// check Parameter
ASSERT(pSdoComConHdl_p != NULL);
// check NodeId
if ((uiTargetNodeId_p == EPL_C_ADR_INVALID)
|| (uiTargetNodeId_p >= EPL_C_ADR_BROADCAST)) {
Ret = kEplInvalidNodeId;
}
// search free control structure
pSdoComCon = &SdoComInstance_g.m_SdoComCon[0];
uiCount = 0;
uiFreeHdl = EPL_MAX_SDO_COM_CON;
while (uiCount < EPL_MAX_SDO_COM_CON) {
if (pSdoComCon->m_SdoSeqConHdl == 0) { // free entry
uiFreeHdl = uiCount;
} else if ((pSdoComCon->m_uiNodeId == uiTargetNodeId_p)
&& (pSdoComCon->m_SdoProtType == ProtType_p)) { // existing client connection with same node ID and same protocol type
*pSdoComConHdl_p = uiCount;
Ret = kEplSdoComHandleExists;
goto Exit;
}
uiCount++;
pSdoComCon++;
}
if (uiFreeHdl == EPL_MAX_SDO_COM_CON) {
Ret = kEplSdoComNoFreeHandle;
goto Exit;
}
pSdoComCon = &SdoComInstance_g.m_SdoComCon[uiFreeHdl];
// save handle for application
*pSdoComConHdl_p = uiFreeHdl;
// save parameters
pSdoComCon->m_SdoProtType = ProtType_p;
pSdoComCon->m_uiNodeId = uiTargetNodeId_p;
// set Transaction Id
pSdoComCon->m_bTransactionId = 0;
// check protocol
switch (ProtType_p) {
// udp
case kEplSdoTypeUdp:
{
// call connection int function of lower layer
Ret = EplSdoAsySeqInitCon(&pSdoComCon->m_SdoSeqConHdl,
pSdoComCon->m_uiNodeId,
kEplSdoTypeUdp);
if (Ret != kEplSuccessful) {
goto Exit;
}
break;
}
// Asend
case kEplSdoTypeAsnd:
{
// call connection int function of lower layer
Ret = EplSdoAsySeqInitCon(&pSdoComCon->m_SdoSeqConHdl,
pSdoComCon->m_uiNodeId,
kEplSdoTypeAsnd);
if (Ret != kEplSuccessful) {
goto Exit;
}
break;
}
// Pdo -> not supported
case kEplSdoTypePdo:
default:
{
Ret = kEplSdoComUnsupportedProt;
goto Exit;
}
} // end of switch(m_ProtType_p)
// call process function
Ret = EplSdoComProcessIntern(uiFreeHdl,
kEplSdoComConEventInitCon, NULL);
Exit:
return Ret;
}
#endif
//---------------------------------------------------------------------------
//
// Function: EplSdoComInitTransferByIndex
//
// Description: function init SDO Transfer for a defined connection
//
//
//
// Parameters: SdoComTransParam_p = Structure with parameters for connection
//
//
// Returns: tEplKernel = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
tEplKernel EplSdoComInitTransferByIndex(tEplSdoComTransParamByIndex *pSdoComTransParam_p)
{
tEplKernel Ret;
tEplSdoComCon *pSdoComCon;
// check parameter
if ((pSdoComTransParam_p->m_uiSubindex >= 0xFF)
|| (pSdoComTransParam_p->m_uiIndex == 0)
|| (pSdoComTransParam_p->m_uiIndex > 0xFFFF)
|| (pSdoComTransParam_p->m_pData == NULL)
|| (pSdoComTransParam_p->m_uiDataSize == 0)) {
Ret = kEplSdoComInvalidParam;
goto Exit;
}
if (pSdoComTransParam_p->m_SdoComConHdl >= EPL_MAX_SDO_COM_CON) {
Ret = kEplSdoComInvalidHandle;
goto Exit;
}
// get pointer to control structure of connection
pSdoComCon =
&SdoComInstance_g.m_SdoComCon[pSdoComTransParam_p->m_SdoComConHdl];
// check if handle ok
if (pSdoComCon->m_SdoSeqConHdl == 0) {
Ret = kEplSdoComInvalidHandle;
goto Exit;
}
// check if command layer is idle
if ((pSdoComCon->m_uiTransferredByte + pSdoComCon->m_uiTransSize) > 0) { // handle is not idle
Ret = kEplSdoComHandleBusy;
goto Exit;
}
// save parameter
// callback function for end of transfer
pSdoComCon->m_pfnTransferFinished =
pSdoComTransParam_p->m_pfnSdoFinishedCb;
pSdoComCon->m_pUserArg = pSdoComTransParam_p->m_pUserArg;
// set type of SDO command
if (pSdoComTransParam_p->m_SdoAccessType == kEplSdoAccessTypeRead) {
pSdoComCon->m_SdoServiceType = kEplSdoServiceReadByIndex;
} else {
pSdoComCon->m_SdoServiceType = kEplSdoServiceWriteByIndex;
}
// save pointer to data
pSdoComCon->m_pData = pSdoComTransParam_p->m_pData;
// maximal bytes to transfer
pSdoComCon->m_uiTransSize = pSdoComTransParam_p->m_uiDataSize;
// bytes already transfered
pSdoComCon->m_uiTransferredByte = 0;
// reset parts of control structure
pSdoComCon->m_dwLastAbortCode = 0;
pSdoComCon->m_SdoTransType = kEplSdoTransAuto;
// save timeout
//pSdoComCon->m_uiTimeout = SdoComTransParam_p.m_uiTimeout;
// save index and subindex
pSdoComCon->m_uiTargetIndex = pSdoComTransParam_p->m_uiIndex;
pSdoComCon->m_uiTargetSubIndex = pSdoComTransParam_p->m_uiSubindex;
// call process function
Ret = EplSdoComProcessIntern(pSdoComTransParam_p->m_SdoComConHdl, kEplSdoComConEventSendFirst, // event to start transfer
NULL);
Exit:
return Ret;
}
#endif
//---------------------------------------------------------------------------
//
// Function: EplSdoComUndefineCon
//
// Description: function undefine a SDO connection
//
//
//
// Parameters: SdoComConHdl_p = handle for the connection
//
//
// Returns: tEplKernel = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
tEplKernel EplSdoComUndefineCon(tEplSdoComConHdl SdoComConHdl_p)
{
tEplKernel Ret;
tEplSdoComCon *pSdoComCon;
Ret = kEplSuccessful;
if (SdoComConHdl_p >= EPL_MAX_SDO_COM_CON) {
Ret = kEplSdoComInvalidHandle;
goto Exit;
}
// get pointer to control structure
pSdoComCon = &SdoComInstance_g.m_SdoComCon[SdoComConHdl_p];
// $$$ d.k. abort a running transfer before closing the sequence layer
if (((pSdoComCon->m_SdoSeqConHdl & ~EPL_SDO_SEQ_HANDLE_MASK) !=
EPL_SDO_SEQ_INVALID_HDL)
&& (pSdoComCon->m_SdoSeqConHdl != 0)) {
// close connection in lower layer
switch (pSdoComCon->m_SdoProtType) {
case kEplSdoTypeAsnd:
case kEplSdoTypeUdp:
{
Ret =
EplSdoAsySeqDelCon(pSdoComCon->
m_SdoSeqConHdl);
break;
}
case kEplSdoTypePdo:
case kEplSdoTypeAuto:
default:
{
Ret = kEplSdoComUnsupportedProt;
goto Exit;
}
} // end of switch(pSdoComCon->m_SdoProtType)
}
// clean controll structure
EPL_MEMSET(pSdoComCon, 0x00, sizeof(tEplSdoComCon));
Exit:
return Ret;
}
#endif
//---------------------------------------------------------------------------
//
// Function: EplSdoComGetState
//
// Description: function returns the state fo the connection
//
//
//
// Parameters: SdoComConHdl_p = handle for the connection
// pSdoComFinished_p = pointer to structur for sdo state
//
//
// Returns: tEplKernel = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
tEplKernel EplSdoComGetState(tEplSdoComConHdl SdoComConHdl_p,
tEplSdoComFinished *pSdoComFinished_p)
{
tEplKernel Ret;
tEplSdoComCon *pSdoComCon;
Ret = kEplSuccessful;
if (SdoComConHdl_p >= EPL_MAX_SDO_COM_CON) {
Ret = kEplSdoComInvalidHandle;
goto Exit;
}
// get pointer to control structure
pSdoComCon = &SdoComInstance_g.m_SdoComCon[SdoComConHdl_p];
// check if handle ok
if (pSdoComCon->m_SdoSeqConHdl == 0) {
Ret = kEplSdoComInvalidHandle;
goto Exit;
}
pSdoComFinished_p->m_pUserArg = pSdoComCon->m_pUserArg;
pSdoComFinished_p->m_uiNodeId = pSdoComCon->m_uiNodeId;
pSdoComFinished_p->m_uiTargetIndex = pSdoComCon->m_uiTargetIndex;
pSdoComFinished_p->m_uiTargetSubIndex = pSdoComCon->m_uiTargetSubIndex;
pSdoComFinished_p->m_uiTransferredByte =
pSdoComCon->m_uiTransferredByte;
pSdoComFinished_p->m_dwAbortCode = pSdoComCon->m_dwLastAbortCode;
pSdoComFinished_p->m_SdoComConHdl = SdoComConHdl_p;
if (pSdoComCon->m_SdoServiceType == kEplSdoServiceWriteByIndex) {
pSdoComFinished_p->m_SdoAccessType = kEplSdoAccessTypeWrite;
} else {
pSdoComFinished_p->m_SdoAccessType = kEplSdoAccessTypeRead;
}
if (pSdoComCon->m_dwLastAbortCode != 0) { // sdo abort
pSdoComFinished_p->m_SdoComConState =
kEplSdoComTransferRxAborted;
// delete abort code
pSdoComCon->m_dwLastAbortCode = 0;
} else if ((pSdoComCon->m_SdoSeqConHdl & ~EPL_SDO_SEQ_HANDLE_MASK) == EPL_SDO_SEQ_INVALID_HDL) { // check state
pSdoComFinished_p->m_SdoComConState =
kEplSdoComTransferLowerLayerAbort;
} else if (pSdoComCon->m_SdoComState == kEplSdoComStateClientWaitInit) {
// finished
pSdoComFinished_p->m_SdoComConState =
kEplSdoComTransferNotActive;
} else if (pSdoComCon->m_uiTransSize == 0) { // finished
pSdoComFinished_p->m_SdoComConState =
kEplSdoComTransferFinished;
}
Exit:
return Ret;
}
#endif
//---------------------------------------------------------------------------
//
// Function: EplSdoComSdoAbort
//
// Description: function abort a sdo transfer
//
//
//
// Parameters: SdoComConHdl_p = handle for the connection
// dwAbortCode_p = abort code
//
//
// Returns: tEplKernel = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
tEplKernel EplSdoComSdoAbort(tEplSdoComConHdl SdoComConHdl_p,
DWORD dwAbortCode_p)
{
tEplKernel Ret;
tEplSdoComCon *pSdoComCon;
if (SdoComConHdl_p >= EPL_MAX_SDO_COM_CON) {
Ret = kEplSdoComInvalidHandle;
goto Exit;
}
// get pointer to control structure of connection
pSdoComCon = &SdoComInstance_g.m_SdoComCon[SdoComConHdl_p];
// check if handle ok
if (pSdoComCon->m_SdoSeqConHdl == 0) {
Ret = kEplSdoComInvalidHandle;
goto Exit;
}
// save pointer to abort code
pSdoComCon->m_pData = (u8 *) & dwAbortCode_p;
Ret = EplSdoComProcessIntern(SdoComConHdl_p,
kEplSdoComConEventAbort,
(tEplAsySdoCom *) NULL);
Exit:
return Ret;
}
#endif
//=========================================================================//
// //
// P R I V A T E F U N C T I O N S //
// //
//=========================================================================//
//---------------------------------------------------------------------------
//
// Function: EplSdoComReceiveCb
//
// Description: callback function for SDO Sequence Layer
// -> indicates new data
//
//
//
// Parameters: SdoSeqConHdl_p = Handle for connection
// pAsySdoCom_p = pointer to data
// uiDataSize_p = size of data ($$$ not used yet, but it should)
//
//
// Returns:
//
//
// State:
//
//---------------------------------------------------------------------------
tEplKernel EplSdoComReceiveCb(tEplSdoSeqConHdl SdoSeqConHdl_p,
tEplAsySdoCom *pAsySdoCom_p,
unsigned int uiDataSize_p)
{
tEplKernel Ret;
// search connection internally
Ret = EplSdoComSearchConIntern(SdoSeqConHdl_p,
kEplSdoComConEventRec, pAsySdoCom_p);
EPL_DBGLVL_SDO_TRACE3
("EplSdoComReceiveCb SdoSeqConHdl: 0x%X, First Byte of pAsySdoCom_p: 0x%02X, uiDataSize_p: 0x%04X\n",
SdoSeqConHdl_p, (WORD) pAsySdoCom_p->m_le_abCommandData[0],
uiDataSize_p);
return Ret;
}
//---------------------------------------------------------------------------
//
// Function: EplSdoComConCb
//
// Description: callback function called by SDO Sequence Layer to inform
// command layer about state change of connection
//
//
//
// Parameters: SdoSeqConHdl_p = Handle of the connection
// AsySdoConState_p = Event of the connection
//
//
// Returns: tEplKernel = Errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
tEplKernel EplSdoComConCb(tEplSdoSeqConHdl SdoSeqConHdl_p,
tEplAsySdoConState AsySdoConState_p)
{
tEplKernel Ret;
tEplSdoComConEvent SdoComConEvent = kEplSdoComConEventSendFirst;
Ret = kEplSuccessful;
// check state
switch (AsySdoConState_p) {
case kAsySdoConStateConnected:
{
EPL_DBGLVL_SDO_TRACE0("Connection established\n");
SdoComConEvent = kEplSdoComConEventConEstablished;
// start transmission if needed
break;
}
case kAsySdoConStateInitError:
{
EPL_DBGLVL_SDO_TRACE0("Error during initialisation\n");
SdoComConEvent = kEplSdoComConEventInitError;
// inform app about error and close sequence layer handle
break;
}
case kAsySdoConStateConClosed:
{
EPL_DBGLVL_SDO_TRACE0("Connection closed\n");
SdoComConEvent = kEplSdoComConEventConClosed;
// close sequence layer handle
break;
}
case kAsySdoConStateAckReceived:
{
EPL_DBGLVL_SDO_TRACE0("Acknowlage received\n");
SdoComConEvent = kEplSdoComConEventAckReceived;
// continue transmission
break;
}
case kAsySdoConStateFrameSended:
{
EPL_DBGLVL_SDO_TRACE0("One Frame sent\n");
SdoComConEvent = kEplSdoComConEventFrameSended;
// to continue transmission
break;
}
case kAsySdoConStateTimeout:
{
EPL_DBGLVL_SDO_TRACE0("Timeout\n");
SdoComConEvent = kEplSdoComConEventTimeout;
// close sequence layer handle
break;
}
} // end of switch(AsySdoConState_p)
Ret = EplSdoComSearchConIntern(SdoSeqConHdl_p,
SdoComConEvent, (tEplAsySdoCom *) NULL);
return Ret;
}
//---------------------------------------------------------------------------
//
// Function: EplSdoComSearchConIntern
//
// Description: search a Sdo Sequence Layer connection handle in the
// control structure of the Command Layer
//
// Parameters: SdoSeqConHdl_p = Handle to search
// SdoComConEvent_p = event to process
// pAsySdoCom_p = pointer to received frame
//
// Returns: tEplKernel
//
//
// State:
//
//---------------------------------------------------------------------------
static tEplKernel EplSdoComSearchConIntern(tEplSdoSeqConHdl SdoSeqConHdl_p,
tEplSdoComConEvent SdoComConEvent_p,
tEplAsySdoCom * pAsySdoCom_p)
{
tEplKernel Ret;
tEplSdoComCon *pSdoComCon;
tEplSdoComConHdl HdlCount;
tEplSdoComConHdl HdlFree;
Ret = kEplSdoComNotResponsible;
// get pointer to first element of the array
pSdoComCon = &SdoComInstance_g.m_SdoComCon[0];
HdlCount = 0;
HdlFree = 0xFFFF;
while (HdlCount < EPL_MAX_SDO_COM_CON) {
if (pSdoComCon->m_SdoSeqConHdl == SdoSeqConHdl_p) { // matching command layer handle found
Ret = EplSdoComProcessIntern(HdlCount,
SdoComConEvent_p,
pAsySdoCom_p);
} else if ((pSdoComCon->m_SdoSeqConHdl == 0)
&& (HdlFree == 0xFFFF)) {
HdlFree = HdlCount;
}
pSdoComCon++;
HdlCount++;
}
if (Ret == kEplSdoComNotResponsible) { // no responsible command layer handle found
if (HdlFree == 0xFFFF) { // no free handle
// delete connection immediately
// 2008/04/14 m.u./d.k. This connection actually does not exist.
// pSdoComCon is invalid.
// Ret = EplSdoAsySeqDelCon(pSdoComCon->m_SdoSeqConHdl);
Ret = kEplSdoComNoFreeHandle;
} else { // create new handle
HdlCount = HdlFree;
pSdoComCon = &SdoComInstance_g.m_SdoComCon[HdlCount];
pSdoComCon->m_SdoSeqConHdl = SdoSeqConHdl_p;
Ret = EplSdoComProcessIntern(HdlCount,
SdoComConEvent_p,
pAsySdoCom_p);
}
}
return Ret;
}
//---------------------------------------------------------------------------
//
// Function: EplSdoComProcessIntern
//
// Description: search a Sdo Sequence Layer connection handle in the
// control structer of the Command Layer
//
//
//
// Parameters: SdoComCon_p = index of control structure of connection
// SdoComConEvent_p = event to process
// pAsySdoCom_p = pointer to received frame
//
// Returns: tEplKernel = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
static tEplKernel EplSdoComProcessIntern(tEplSdoComConHdl SdoComCon_p,
tEplSdoComConEvent SdoComConEvent_p,
tEplAsySdoCom * pAsySdoCom_p)
{
tEplKernel Ret;
tEplSdoComCon *pSdoComCon;
u8 bFlag;
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0)
DWORD dwAbortCode;
unsigned int uiSize;
#endif
#if defined(WIN32) || defined(_WIN32)
// enter critical section for process function
EnterCriticalSection(SdoComInstance_g.m_pCriticalSection);
EPL_DBGLVL_SDO_TRACE0
("\n\tEnterCiticalSection EplSdoComProcessIntern\n\n");
#endif
Ret = kEplSuccessful;
// get pointer to control structure
pSdoComCon = &SdoComInstance_g.m_SdoComCon[SdoComCon_p];
// process state maschine
switch (pSdoComCon->m_SdoComState) {
// idle state
case kEplSdoComStateIdle:
{
// check events
switch (SdoComConEvent_p) {
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
// init con for client
case kEplSdoComConEventInitCon:
{
// call of the init function already
// processed in EplSdoComDefineCon()
// only change state to kEplSdoComStateClientWaitInit
pSdoComCon->m_SdoComState =
kEplSdoComStateClientWaitInit;
break;
}
#endif
// int con for server
case kEplSdoComConEventRec:
{
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0)
// check if init of an transfer and no SDO abort
if ((pAsySdoCom_p->m_le_bFlags & 0x80) == 0) { // SDO request
if ((pAsySdoCom_p->m_le_bFlags & 0x40) == 0) { // no SDO abort
// save tansaction id
pSdoComCon->
m_bTransactionId =
AmiGetByteFromLe
(&pAsySdoCom_p->
m_le_bTransactionId);
// check command
switch (pAsySdoCom_p->
m_le_bCommandId)
{
case kEplSdoServiceNIL:
{ // simply acknowlegde NIL command on sequence layer
Ret =
EplSdoAsySeqSendData
(pSdoComCon->
m_SdoSeqConHdl,
0,
(tEplFrame
*)
NULL);
break;
}
case kEplSdoServiceReadByIndex:
{ // read by index
// search entry an start transfer
EplSdoComServerInitReadByIndex
(pSdoComCon,
pAsySdoCom_p);
// check next state
if (pSdoComCon->m_uiTransSize == 0) { // ready -> stay idle
pSdoComCon->
m_SdoComState
=
kEplSdoComStateIdle;
// reset abort code
pSdoComCon->
m_dwLastAbortCode
=
0;
} else { // segmented transfer
pSdoComCon->
m_SdoComState
=
kEplSdoComStateServerSegmTrans;
}
break;
}
case kEplSdoServiceWriteByIndex:
{
// search entry an start write
EplSdoComServerInitWriteByIndex
(pSdoComCon,
pAsySdoCom_p);
// check next state
if (pSdoComCon->m_uiTransSize == 0) { // already -> stay idle
pSdoComCon->
m_SdoComState
=
kEplSdoComStateIdle;
// reset abort code
pSdoComCon->
m_dwLastAbortCode
=
0;
} else { // segmented transfer
pSdoComCon->
m_SdoComState
=
kEplSdoComStateServerSegmTrans;
}
break;
}
default:
{
// unsupported command
// -> abort senden
dwAbortCode
=
EPL_SDOAC_UNKNOWN_COMMAND_SPECIFIER;
// send abort
pSdoComCon->
m_pData
=
(u8
*)
&
dwAbortCode;
Ret =
EplSdoComServerSendFrameIntern
(pSdoComCon,
0,
0,
kEplSdoComSendTypeAbort);
}
} // end of switch(pAsySdoCom_p->m_le_bCommandId)
}
} else { // this command layer handle is not responsible
// (wrong direction or wrong transaction ID)
Ret = kEplSdoComNotResponsible;
goto Exit;
}
#endif // end of #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0)
break;
}
// connection closed
case kEplSdoComConEventInitError:
case kEplSdoComConEventTimeout:
case kEplSdoComConEventConClosed:
{
Ret =
EplSdoAsySeqDelCon(pSdoComCon->
m_SdoSeqConHdl);
// clean control structure
EPL_MEMSET(pSdoComCon, 0x00,
sizeof(tEplSdoComCon));
break;
}
default:
// d.k. do nothing
break;
} // end of switch(SdoComConEvent_p)
break;
}
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0)
//-------------------------------------------------------------------------
// SDO Server part
// segmented transfer
case kEplSdoComStateServerSegmTrans:
{
// check events
switch (SdoComConEvent_p) {
// send next frame
case kEplSdoComConEventAckReceived:
case kEplSdoComConEventFrameSended:
{
// check if it is a read
if (pSdoComCon->m_SdoServiceType ==
kEplSdoServiceReadByIndex) {
// send next frame
EplSdoComServerSendFrameIntern
(pSdoComCon, 0, 0,
kEplSdoComSendTypeRes);
// if all send -> back to idle
if (pSdoComCon->m_uiTransSize == 0) { // back to idle
pSdoComCon->
m_SdoComState =
kEplSdoComStateIdle;
// reset abort code
pSdoComCon->
m_dwLastAbortCode =
0;
}
}
break;
}
// process next frame
case kEplSdoComConEventRec:
{
// check if the frame is a SDO response and has the right transaction ID
bFlag =
AmiGetByteFromLe(&pAsySdoCom_p->
m_le_bFlags);
if (((bFlag & 0x80) != 0)
&&
(AmiGetByteFromLe
(&pAsySdoCom_p->
m_le_bTransactionId) ==
pSdoComCon->m_bTransactionId)) {
// check if it is a abort
if ((bFlag & 0x40) != 0) { // SDO abort
// clear control structure
pSdoComCon->
m_uiTransSize = 0;
pSdoComCon->
m_uiTransferredByte
= 0;
// change state
pSdoComCon->
m_SdoComState =
kEplSdoComStateIdle;
// reset abort code
pSdoComCon->
m_dwLastAbortCode =
0;
// d.k.: do not execute anything further on this command
break;
}
// check if it is a write
if (pSdoComCon->
m_SdoServiceType ==
kEplSdoServiceWriteByIndex)
{
// write data to OD
uiSize =
AmiGetWordFromLe
(&pAsySdoCom_p->
m_le_wSegmentSize);
if (pSdoComCon->
m_dwLastAbortCode ==
0) {
EPL_MEMCPY
(pSdoComCon->
m_pData,
&pAsySdoCom_p->
m_le_abCommandData
[0],
uiSize);
}
// update counter
pSdoComCon->
m_uiTransferredByte
+= uiSize;
pSdoComCon->
m_uiTransSize -=
uiSize;
// update pointer
if (pSdoComCon->
m_dwLastAbortCode ==
0) {
( /*(u8*) */
pSdoComCon->
m_pData) +=
uiSize;
}
// check end of transfer
if ((pAsySdoCom_p->m_le_bFlags & 0x30) == 0x30) { // transfer ready
pSdoComCon->
m_uiTransSize
= 0;
if (pSdoComCon->
m_dwLastAbortCode
== 0) {
// send response
// send next frame
EplSdoComServerSendFrameIntern
(pSdoComCon,
0,
0,
kEplSdoComSendTypeRes);
// if all send -> back to idle
if (pSdoComCon->m_uiTransSize == 0) { // back to idle
pSdoComCon->
m_SdoComState
=
kEplSdoComStateIdle;
// reset abort code
pSdoComCon->
m_dwLastAbortCode
=
0;
}
} else { // send dabort code
// send abort
pSdoComCon->
m_pData
=
(u8
*)
&
pSdoComCon->
m_dwLastAbortCode;
Ret =
EplSdoComServerSendFrameIntern
(pSdoComCon,
0,
0,
kEplSdoComSendTypeAbort);
// reset abort code
pSdoComCon->
m_dwLastAbortCode
= 0;
}
} else {
// send acknowledge without any Command layer data
Ret =
EplSdoAsySeqSendData
(pSdoComCon->
m_SdoSeqConHdl,
0,
(tEplFrame
*) NULL);
}
}
} else { // this command layer handle is not responsible
// (wrong direction or wrong transaction ID)
Ret = kEplSdoComNotResponsible;
goto Exit;
}
break;
}
// connection closed
case kEplSdoComConEventInitError:
case kEplSdoComConEventTimeout:
case kEplSdoComConEventConClosed:
{
Ret =
EplSdoAsySeqDelCon(pSdoComCon->
m_SdoSeqConHdl);
// clean control structure
EPL_MEMSET(pSdoComCon, 0x00,
sizeof(tEplSdoComCon));
break;
}
default:
// d.k. do nothing
break;
} // end of switch(SdoComConEvent_p)
break;
}
#endif // endif of #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0)
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
//-------------------------------------------------------------------------
// SDO Client part
// wait for finish of establishing connection
case kEplSdoComStateClientWaitInit:
{
// if connection handle is invalid reinit connection
// d.k.: this will be done only on new events (i.e. InitTransfer)
if ((pSdoComCon->
m_SdoSeqConHdl & ~EPL_SDO_SEQ_HANDLE_MASK) ==
EPL_SDO_SEQ_INVALID_HDL) {
// check kind of connection to reinit
// check protocol
switch (pSdoComCon->m_SdoProtType) {
// udp
case kEplSdoTypeUdp:
{
// call connection int function of lower layer
Ret =
EplSdoAsySeqInitCon
(&pSdoComCon->
m_SdoSeqConHdl,
pSdoComCon->m_uiNodeId,
kEplSdoTypeUdp);
if (Ret != kEplSuccessful) {
goto Exit;
}
break;
}
// Asend -> not supported
case kEplSdoTypeAsnd:
{
// call connection int function of lower layer
Ret =
EplSdoAsySeqInitCon
(&pSdoComCon->
m_SdoSeqConHdl,
pSdoComCon->m_uiNodeId,
kEplSdoTypeAsnd);
if (Ret != kEplSuccessful) {
goto Exit;
}
break;
}
// Pdo -> not supported
case kEplSdoTypePdo:
default:
{
Ret = kEplSdoComUnsupportedProt;
goto Exit;
}
} // end of switch(m_ProtType_p)
// d.k.: reset transaction ID, because new sequence layer connection was initialized
// $$$ d.k. is this really necessary?
//pSdoComCon->m_bTransactionId = 0;
}
// check events
switch (SdoComConEvent_p) {
// connection established
case kEplSdoComConEventConEstablished:
{
//send first frame if needed
if ((pSdoComCon->m_uiTransSize > 0)
&& (pSdoComCon->m_uiTargetIndex != 0)) { // start SDO transfer
Ret =
EplSdoComClientSend
(pSdoComCon);
if (Ret != kEplSuccessful) {
goto Exit;
}
// check if segemted transfer
if (pSdoComCon->
m_SdoTransType ==
kEplSdoTransSegmented) {
pSdoComCon->
m_SdoComState =
kEplSdoComStateClientSegmTrans;
goto Exit;
}
}
// goto state kEplSdoComStateClientConnected
pSdoComCon->m_SdoComState =
kEplSdoComStateClientConnected;
goto Exit;
}
case kEplSdoComConEventSendFirst:
{
// infos for transfer already saved by function EplSdoComInitTransferByIndex
break;
}
case kEplSdoComConEventConClosed:
case kEplSdoComConEventInitError:
case kEplSdoComConEventTimeout:
{
// close sequence layer handle
Ret =
EplSdoAsySeqDelCon(pSdoComCon->
m_SdoSeqConHdl);
pSdoComCon->m_SdoSeqConHdl |=
EPL_SDO_SEQ_INVALID_HDL;
// call callback function
if (SdoComConEvent_p ==
kEplSdoComConEventTimeout) {
pSdoComCon->m_dwLastAbortCode =
EPL_SDOAC_TIME_OUT;
} else {
pSdoComCon->m_dwLastAbortCode =
0;
}
Ret =
EplSdoComTransferFinished
(SdoComCon_p, pSdoComCon,
kEplSdoComTransferLowerLayerAbort);
// d.k.: do not clean control structure
break;
}
default:
// d.k. do nothing
break;
} // end of switch(SdoComConEvent_p)
break;
}
// connected
case kEplSdoComStateClientConnected:
{
// check events
switch (SdoComConEvent_p) {
// send a frame
case kEplSdoComConEventSendFirst:
case kEplSdoComConEventAckReceived:
case kEplSdoComConEventFrameSended:
{
Ret = EplSdoComClientSend(pSdoComCon);
if (Ret != kEplSuccessful) {
goto Exit;
}
// check if read transfer finished
if ((pSdoComCon->m_uiTransSize == 0)
&& (pSdoComCon->
m_uiTransferredByte != 0)
&& (pSdoComCon->m_SdoServiceType ==
kEplSdoServiceReadByIndex)) {
// inc transaction id
pSdoComCon->m_bTransactionId++;
// call callback of application
pSdoComCon->m_dwLastAbortCode =
0;
Ret =
EplSdoComTransferFinished
(SdoComCon_p, pSdoComCon,
kEplSdoComTransferFinished);
goto Exit;
}
// check if segemted transfer
if (pSdoComCon->m_SdoTransType ==
kEplSdoTransSegmented) {
pSdoComCon->m_SdoComState =
kEplSdoComStateClientSegmTrans;
goto Exit;
}
break;
}
// frame received
case kEplSdoComConEventRec:
{
// check if the frame is a SDO response and has the right transaction ID
bFlag =
AmiGetByteFromLe(&pAsySdoCom_p->
m_le_bFlags);
if (((bFlag & 0x80) != 0)
&&
(AmiGetByteFromLe
(&pAsySdoCom_p->
m_le_bTransactionId) ==
pSdoComCon->m_bTransactionId)) {
// check if abort or not
if ((bFlag & 0x40) != 0) {
// send acknowledge without any Command layer data
Ret =
EplSdoAsySeqSendData
(pSdoComCon->
m_SdoSeqConHdl, 0,
(tEplFrame *)
NULL);
// inc transaction id
pSdoComCon->
m_bTransactionId++;
// save abort code
pSdoComCon->
m_dwLastAbortCode =
AmiGetDwordFromLe
(&pAsySdoCom_p->
m_le_abCommandData
[0]);
// call callback of application
Ret =
EplSdoComTransferFinished
(SdoComCon_p,
pSdoComCon,
kEplSdoComTransferRxAborted);
goto Exit;
} else { // normal frame received
// check frame
Ret =
EplSdoComClientProcessFrame
(SdoComCon_p,
pAsySdoCom_p);
// check if transfer ready
if (pSdoComCon->
m_uiTransSize ==
0) {
// send acknowledge without any Command layer data
Ret =
EplSdoAsySeqSendData
(pSdoComCon->
m_SdoSeqConHdl,
0,
(tEplFrame
*) NULL);
// inc transaction id
pSdoComCon->
m_bTransactionId++;
// call callback of application
pSdoComCon->
m_dwLastAbortCode
= 0;
Ret =
EplSdoComTransferFinished
(SdoComCon_p,
pSdoComCon,
kEplSdoComTransferFinished);
goto Exit;
}
}
} else { // this command layer handle is not responsible
// (wrong direction or wrong transaction ID)
Ret = kEplSdoComNotResponsible;
goto Exit;
}
break;
}
// connection closed event go back to kEplSdoComStateClientWaitInit
case kEplSdoComConEventConClosed:
{ // connection closed by communication partner
// close sequence layer handle
Ret =
EplSdoAsySeqDelCon(pSdoComCon->
m_SdoSeqConHdl);
// set handle to invalid and enter kEplSdoComStateClientWaitInit
pSdoComCon->m_SdoSeqConHdl |=
EPL_SDO_SEQ_INVALID_HDL;
// change state
pSdoComCon->m_SdoComState =
kEplSdoComStateClientWaitInit;
// call callback of application
pSdoComCon->m_dwLastAbortCode = 0;
Ret =
EplSdoComTransferFinished
(SdoComCon_p, pSdoComCon,
kEplSdoComTransferLowerLayerAbort);
goto Exit;
break;
}
// abort to send from higher layer
case kEplSdoComConEventAbort:
{
EplSdoComClientSendAbort(pSdoComCon,
*((DWORD *)
pSdoComCon->
m_pData));
// inc transaction id
pSdoComCon->m_bTransactionId++;
// call callback of application
pSdoComCon->m_dwLastAbortCode =
*((DWORD *) pSdoComCon->m_pData);
Ret =
EplSdoComTransferFinished
(SdoComCon_p, pSdoComCon,
kEplSdoComTransferTxAborted);
break;
}
case kEplSdoComConEventInitError:
case kEplSdoComConEventTimeout:
{
// close sequence layer handle
Ret =
EplSdoAsySeqDelCon(pSdoComCon->
m_SdoSeqConHdl);
pSdoComCon->m_SdoSeqConHdl |=
EPL_SDO_SEQ_INVALID_HDL;
// change state
pSdoComCon->m_SdoComState =
kEplSdoComStateClientWaitInit;
// call callback of application
pSdoComCon->m_dwLastAbortCode =
EPL_SDOAC_TIME_OUT;
Ret =
EplSdoComTransferFinished
(SdoComCon_p, pSdoComCon,
kEplSdoComTransferLowerLayerAbort);
}
default:
// d.k. do nothing
break;
} // end of switch(SdoComConEvent_p)
break;
}
// process segmented transfer
case kEplSdoComStateClientSegmTrans:
{
// check events
switch (SdoComConEvent_p) {
// sned a frame
case kEplSdoComConEventSendFirst:
case kEplSdoComConEventAckReceived:
case kEplSdoComConEventFrameSended:
{
Ret = EplSdoComClientSend(pSdoComCon);
if (Ret != kEplSuccessful) {
goto Exit;
}
// check if read transfer finished
if ((pSdoComCon->m_uiTransSize == 0)
&& (pSdoComCon->m_SdoServiceType ==
kEplSdoServiceReadByIndex)) {
// inc transaction id
pSdoComCon->m_bTransactionId++;
// change state
pSdoComCon->m_SdoComState =
kEplSdoComStateClientConnected;
// call callback of application
pSdoComCon->m_dwLastAbortCode =
0;
Ret =
EplSdoComTransferFinished
(SdoComCon_p, pSdoComCon,
kEplSdoComTransferFinished);
goto Exit;
}
break;
}
// frame received
case kEplSdoComConEventRec:
{
// check if the frame is a response
bFlag =
AmiGetByteFromLe(&pAsySdoCom_p->
m_le_bFlags);
if (((bFlag & 0x80) != 0)
&&
(AmiGetByteFromLe
(&pAsySdoCom_p->
m_le_bTransactionId) ==
pSdoComCon->m_bTransactionId)) {
// check if abort or not
if ((bFlag & 0x40) != 0) {
// send acknowledge without any Command layer data
Ret =
EplSdoAsySeqSendData
(pSdoComCon->
m_SdoSeqConHdl, 0,
(tEplFrame *)
NULL);
// inc transaction id
pSdoComCon->
m_bTransactionId++;
// change state
pSdoComCon->
m_SdoComState =
kEplSdoComStateClientConnected;
// save abort code
pSdoComCon->
m_dwLastAbortCode =
AmiGetDwordFromLe
(&pAsySdoCom_p->
m_le_abCommandData
[0]);
// call callback of application
Ret =
EplSdoComTransferFinished
(SdoComCon_p,
pSdoComCon,
kEplSdoComTransferRxAborted);
goto Exit;
} else { // normal frame received
// check frame
Ret =
EplSdoComClientProcessFrame
(SdoComCon_p,
pAsySdoCom_p);
// check if transfer ready
if (pSdoComCon->
m_uiTransSize ==
0) {
// send acknowledge without any Command layer data
Ret =
EplSdoAsySeqSendData
(pSdoComCon->
m_SdoSeqConHdl,
0,
(tEplFrame
*) NULL);
// inc transaction id
pSdoComCon->
m_bTransactionId++;
// change state
pSdoComCon->
m_SdoComState
=
kEplSdoComStateClientConnected;
// call callback of application
pSdoComCon->
m_dwLastAbortCode
= 0;
Ret =
EplSdoComTransferFinished
(SdoComCon_p,
pSdoComCon,
kEplSdoComTransferFinished);
}
}
}
break;
}
// connection closed event go back to kEplSdoComStateClientWaitInit
case kEplSdoComConEventConClosed:
{ // connection closed by communication partner
// close sequence layer handle
Ret =
EplSdoAsySeqDelCon(pSdoComCon->
m_SdoSeqConHdl);
// set handle to invalid and enter kEplSdoComStateClientWaitInit
pSdoComCon->m_SdoSeqConHdl |=
EPL_SDO_SEQ_INVALID_HDL;
// change state
pSdoComCon->m_SdoComState =
kEplSdoComStateClientWaitInit;
// inc transaction id
pSdoComCon->m_bTransactionId++;
// call callback of application
pSdoComCon->m_dwLastAbortCode = 0;
Ret =
EplSdoComTransferFinished
(SdoComCon_p, pSdoComCon,
kEplSdoComTransferFinished);
break;
}
// abort to send from higher layer
case kEplSdoComConEventAbort:
{
EplSdoComClientSendAbort(pSdoComCon,
*((DWORD *)
pSdoComCon->
m_pData));
// inc transaction id
pSdoComCon->m_bTransactionId++;
// change state
pSdoComCon->m_SdoComState =
kEplSdoComStateClientConnected;
// call callback of application
pSdoComCon->m_dwLastAbortCode =
*((DWORD *) pSdoComCon->m_pData);
Ret =
EplSdoComTransferFinished
(SdoComCon_p, pSdoComCon,
kEplSdoComTransferTxAborted);
break;
}
case kEplSdoComConEventInitError:
case kEplSdoComConEventTimeout:
{
// close sequence layer handle
Ret =
EplSdoAsySeqDelCon(pSdoComCon->
m_SdoSeqConHdl);
pSdoComCon->m_SdoSeqConHdl |=
EPL_SDO_SEQ_INVALID_HDL;
// change state
pSdoComCon->m_SdoComState =
kEplSdoComStateClientWaitInit;
// call callback of application
pSdoComCon->m_dwLastAbortCode =
EPL_SDOAC_TIME_OUT;
Ret =
EplSdoComTransferFinished
(SdoComCon_p, pSdoComCon,
kEplSdoComTransferLowerLayerAbort);
}
default:
// d.k. do nothing
break;
} // end of switch(SdoComConEvent_p)
break;
}
#endif // endo of #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
} // end of switch(pSdoComCon->m_SdoComState)
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
Exit:
#endif
#if defined(WIN32) || defined(_WIN32)
// leave critical section for process function
EPL_DBGLVL_SDO_TRACE0
("\n\tLeaveCriticalSection EplSdoComProcessIntern\n\n");
LeaveCriticalSection(SdoComInstance_g.m_pCriticalSection);
#endif
return Ret;
}
//---------------------------------------------------------------------------
//
// Function: EplSdoComServerInitReadByIndex
//
// Description: function start the processing of an read by index command
//
//
//
// Parameters: pSdoComCon_p = pointer to control structure of connection
// pAsySdoCom_p = pointer to received frame
//
// Returns: tEplKernel = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0)
static tEplKernel EplSdoComServerInitReadByIndex(tEplSdoComCon * pSdoComCon_p,
tEplAsySdoCom * pAsySdoCom_p)
{
tEplKernel Ret;
unsigned int uiIndex;
unsigned int uiSubindex;
tEplObdSize EntrySize;
tEplObdAccess AccessType;
DWORD dwAbortCode;
dwAbortCode = 0;
// a init of a read could not be a segmented transfer
// -> no variable part of header
// get index and subindex
uiIndex = AmiGetWordFromLe(&pAsySdoCom_p->m_le_abCommandData[0]);
uiSubindex = AmiGetByteFromLe(&pAsySdoCom_p->m_le_abCommandData[2]);
// check accesstype of entry
// existens of entry
//#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDU)) != 0)
Ret = EplObduGetAccessType(uiIndex, uiSubindex, &AccessType);
/*#else
Ret = kEplObdSubindexNotExist;
AccessType = 0;
#endif*/
if (Ret == kEplObdSubindexNotExist) { // subentry doesn't exist
dwAbortCode = EPL_SDOAC_SUB_INDEX_NOT_EXIST;
// send abort
pSdoComCon_p->m_pData = (u8 *) & dwAbortCode;
Ret = EplSdoComServerSendFrameIntern(pSdoComCon_p,
uiIndex,
uiSubindex,
kEplSdoComSendTypeAbort);
goto Exit;
} else if (Ret != kEplSuccessful) { // entry doesn't exist
dwAbortCode = EPL_SDOAC_OBJECT_NOT_EXIST;
// send abort
pSdoComCon_p->m_pData = (u8 *) & dwAbortCode;
Ret = EplSdoComServerSendFrameIntern(pSdoComCon_p,
uiIndex,
uiSubindex,
kEplSdoComSendTypeAbort);
goto Exit;
}
// compare accesstype must be read or const
if (((AccessType & kEplObdAccRead) == 0)
&& ((AccessType & kEplObdAccConst) == 0)) {
if ((AccessType & kEplObdAccWrite) != 0) {
// entry read a write only object
dwAbortCode = EPL_SDOAC_READ_TO_WRITE_ONLY_OBJ;
} else {
dwAbortCode = EPL_SDOAC_UNSUPPORTED_ACCESS;
}
// send abort
pSdoComCon_p->m_pData = (u8 *) & dwAbortCode;
Ret = EplSdoComServerSendFrameIntern(pSdoComCon_p,
uiIndex,
uiSubindex,
kEplSdoComSendTypeAbort);
goto Exit;
}
// save service
pSdoComCon_p->m_SdoServiceType = kEplSdoServiceReadByIndex;
// get size of object to see iof segmented or expedited transfer
//#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDU)) != 0)
EntrySize = EplObduGetDataSize(uiIndex, uiSubindex);
/*#else
EntrySize = 0;
#endif*/
if (EntrySize > EPL_SDO_MAX_PAYLOAD) { // segmented transfer
pSdoComCon_p->m_SdoTransType = kEplSdoTransSegmented;
// get pointer to object-entry data
//#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDU)) != 0)
pSdoComCon_p->m_pData =
EplObduGetObjectDataPtr(uiIndex, uiSubindex);
//#endif
} else { // expedited transfer
pSdoComCon_p->m_SdoTransType = kEplSdoTransExpedited;
}
pSdoComCon_p->m_uiTransSize = EntrySize;
pSdoComCon_p->m_uiTransferredByte = 0;
Ret = EplSdoComServerSendFrameIntern(pSdoComCon_p,
uiIndex,
uiSubindex, kEplSdoComSendTypeRes);
if (Ret != kEplSuccessful) {
// error -> abort
dwAbortCode = EPL_SDOAC_GENERAL_ERROR;
// send abort
pSdoComCon_p->m_pData = (u8 *) & dwAbortCode;
Ret = EplSdoComServerSendFrameIntern(pSdoComCon_p,
uiIndex,
uiSubindex,
kEplSdoComSendTypeAbort);
goto Exit;
}
Exit:
return Ret;
}
#endif
//---------------------------------------------------------------------------
//
// Function: EplSdoComServerSendFrameIntern();
//
// Description: function creats and send a frame for server
//
//
//
// Parameters: pSdoComCon_p = pointer to control structure of connection
// uiIndex_p = index to send if expedited transfer else 0
// uiSubIndex_p = subindex to send if expedited transfer else 0
// SendType_p = to of frame to send
//
// Returns: tEplKernel = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0)
static tEplKernel EplSdoComServerSendFrameIntern(tEplSdoComCon * pSdoComCon_p,
unsigned int uiIndex_p,
unsigned int uiSubIndex_p,
tEplSdoComSendType SendType_p)
{
tEplKernel Ret;
u8 abFrame[EPL_MAX_SDO_FRAME_SIZE];
tEplFrame *pFrame;
tEplAsySdoCom *pCommandFrame;
unsigned int uiSizeOfFrame;
u8 bFlag;
Ret = kEplSuccessful;
pFrame = (tEplFrame *) & abFrame[0];
EPL_MEMSET(&abFrame[0], 0x00, sizeof(abFrame));
// build generic part of frame
// get pointer to command layerpart of frame
pCommandFrame =
&pFrame->m_Data.m_Asnd.m_Payload.m_SdoSequenceFrame.
m_le_abSdoSeqPayload;
AmiSetByteToLe(&pCommandFrame->m_le_bCommandId,
pSdoComCon_p->m_SdoServiceType);
AmiSetByteToLe(&pCommandFrame->m_le_bTransactionId,
pSdoComCon_p->m_bTransactionId);
// set size to header size
uiSizeOfFrame = 8;
// check SendType
switch (SendType_p) {
// requestframe to send
case kEplSdoComSendTypeReq:
{
// nothing to do for server
//-> error
Ret = kEplSdoComInvalidSendType;
break;
}
// response without data to send
case kEplSdoComSendTypeAckRes:
{
// set response flag
AmiSetByteToLe(&pCommandFrame->m_le_bFlags, 0x80);
// send frame
Ret = EplSdoAsySeqSendData(pSdoComCon_p->m_SdoSeqConHdl,
uiSizeOfFrame, pFrame);
break;
}
// responsframe to send
case kEplSdoComSendTypeRes:
{
// set response flag
bFlag = AmiGetByteFromLe(&pCommandFrame->m_le_bFlags);
bFlag |= 0x80;
AmiSetByteToLe(&pCommandFrame->m_le_bFlags, bFlag);
// check type of resonse
if (pSdoComCon_p->m_SdoTransType == kEplSdoTransExpedited) { // Expedited transfer
// copy data in frame
//#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDU)) != 0)
Ret = EplObduReadEntryToLe(uiIndex_p,
uiSubIndex_p,
&pCommandFrame->
m_le_abCommandData
[0],
(tEplObdSize *) &
pSdoComCon_p->
m_uiTransSize);
if (Ret != kEplSuccessful) {
goto Exit;
}
//#endif
// set size of frame
AmiSetWordToLe(&pCommandFrame->
m_le_wSegmentSize,
(WORD) pSdoComCon_p->
m_uiTransSize);
// correct byte-counter
uiSizeOfFrame += pSdoComCon_p->m_uiTransSize;
pSdoComCon_p->m_uiTransferredByte +=
pSdoComCon_p->m_uiTransSize;
pSdoComCon_p->m_uiTransSize = 0;
// send frame
uiSizeOfFrame += pSdoComCon_p->m_uiTransSize;
Ret =
EplSdoAsySeqSendData(pSdoComCon_p->
m_SdoSeqConHdl,
uiSizeOfFrame, pFrame);
} else if (pSdoComCon_p->m_SdoTransType == kEplSdoTransSegmented) { // segmented transfer
// distinguish between init, segment and complete
if (pSdoComCon_p->m_uiTransferredByte == 0) { // init
// set init flag
bFlag =
AmiGetByteFromLe(&pCommandFrame->
m_le_bFlags);
bFlag |= 0x10;
AmiSetByteToLe(&pCommandFrame->
m_le_bFlags, bFlag);
// init variable header
AmiSetDwordToLe(&pCommandFrame->
m_le_abCommandData[0],
pSdoComCon_p->
m_uiTransSize);
// copy data in frame
EPL_MEMCPY(&pCommandFrame->
m_le_abCommandData[4],
pSdoComCon_p->m_pData,
(EPL_SDO_MAX_PAYLOAD - 4));
// correct byte-counter
pSdoComCon_p->m_uiTransSize -=
(EPL_SDO_MAX_PAYLOAD - 4);
pSdoComCon_p->m_uiTransferredByte +=
(EPL_SDO_MAX_PAYLOAD - 4);
// move data pointer
pSdoComCon_p->m_pData +=
(EPL_SDO_MAX_PAYLOAD - 4);
// set segment size
AmiSetWordToLe(&pCommandFrame->
m_le_wSegmentSize,
(EPL_SDO_MAX_PAYLOAD -
4));
// send frame
uiSizeOfFrame += EPL_SDO_MAX_PAYLOAD;
Ret =
EplSdoAsySeqSendData(pSdoComCon_p->
m_SdoSeqConHdl,
uiSizeOfFrame,
pFrame);
} else
if ((pSdoComCon_p->m_uiTransferredByte > 0)
&& (pSdoComCon_p->m_uiTransSize > EPL_SDO_MAX_PAYLOAD)) { // segment
// set segment flag
bFlag =
AmiGetByteFromLe(&pCommandFrame->
m_le_bFlags);
bFlag |= 0x20;
AmiSetByteToLe(&pCommandFrame->
m_le_bFlags, bFlag);
// copy data in frame
EPL_MEMCPY(&pCommandFrame->
m_le_abCommandData[0],
pSdoComCon_p->m_pData,
EPL_SDO_MAX_PAYLOAD);
// correct byte-counter
pSdoComCon_p->m_uiTransSize -=
EPL_SDO_MAX_PAYLOAD;
pSdoComCon_p->m_uiTransferredByte +=
EPL_SDO_MAX_PAYLOAD;
// move data pointer
pSdoComCon_p->m_pData +=
EPL_SDO_MAX_PAYLOAD;
// set segment size
AmiSetWordToLe(&pCommandFrame->
m_le_wSegmentSize,
EPL_SDO_MAX_PAYLOAD);
// send frame
uiSizeOfFrame += EPL_SDO_MAX_PAYLOAD;
Ret =
EplSdoAsySeqSendData(pSdoComCon_p->
m_SdoSeqConHdl,
uiSizeOfFrame,
pFrame);
} else {
if ((pSdoComCon_p->m_uiTransSize == 0)
&& (pSdoComCon_p->
m_SdoServiceType !=
kEplSdoServiceWriteByIndex)) {
goto Exit;
}
// complete
// set segment complete flag
bFlag =
AmiGetByteFromLe(&pCommandFrame->
m_le_bFlags);
bFlag |= 0x30;
AmiSetByteToLe(&pCommandFrame->
m_le_bFlags, bFlag);
// copy data in frame
EPL_MEMCPY(&pCommandFrame->
m_le_abCommandData[0],
pSdoComCon_p->m_pData,
pSdoComCon_p->m_uiTransSize);
// correct byte-counter
pSdoComCon_p->m_uiTransferredByte +=
pSdoComCon_p->m_uiTransSize;
// move data pointer
pSdoComCon_p->m_pData +=
pSdoComCon_p->m_uiTransSize;
// set segment size
AmiSetWordToLe(&pCommandFrame->
m_le_wSegmentSize,
(WORD) pSdoComCon_p->
m_uiTransSize);
// send frame
uiSizeOfFrame +=
pSdoComCon_p->m_uiTransSize;
pSdoComCon_p->m_uiTransSize = 0;
Ret =
EplSdoAsySeqSendData(pSdoComCon_p->
m_SdoSeqConHdl,
uiSizeOfFrame,
pFrame);
}
}
break;
}
// abort to send
case kEplSdoComSendTypeAbort:
{
// set response and abort flag
bFlag = AmiGetByteFromLe(&pCommandFrame->m_le_bFlags);
bFlag |= 0xC0;
AmiSetByteToLe(&pCommandFrame->m_le_bFlags, bFlag);
// copy abortcode to frame
AmiSetDwordToLe(&pCommandFrame->m_le_abCommandData[0],
*((DWORD *) pSdoComCon_p->m_pData));
// set size of segment
AmiSetWordToLe(&pCommandFrame->m_le_wSegmentSize,
sizeof(DWORD));
// update counter
pSdoComCon_p->m_uiTransferredByte = sizeof(DWORD);
pSdoComCon_p->m_uiTransSize = 0;
// calc framesize
uiSizeOfFrame += sizeof(DWORD);
Ret = EplSdoAsySeqSendData(pSdoComCon_p->m_SdoSeqConHdl,
uiSizeOfFrame, pFrame);
break;
}
} // end of switch(SendType_p)
Exit:
return Ret;
}
#endif
//---------------------------------------------------------------------------
//
// Function: EplSdoComServerInitWriteByIndex
//
// Description: function start the processing of an write by index command
//
//
//
// Parameters: pSdoComCon_p = pointer to control structure of connection
// pAsySdoCom_p = pointer to received frame
//
// Returns: tEplKernel = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0)
static tEplKernel EplSdoComServerInitWriteByIndex(tEplSdoComCon * pSdoComCon_p,
tEplAsySdoCom * pAsySdoCom_p)
{
tEplKernel Ret = kEplSuccessful;
unsigned int uiIndex;
unsigned int uiSubindex;
unsigned int uiBytesToTransfer;
tEplObdSize EntrySize;
tEplObdAccess AccessType;
DWORD dwAbortCode;
u8 *pbSrcData;
dwAbortCode = 0;
// a init of a write
// -> variable part of header possible
// check if expedited or segmented transfer
if ((pAsySdoCom_p->m_le_bFlags & 0x30) == 0x10) { // initiate segmented transfer
pSdoComCon_p->m_SdoTransType = kEplSdoTransSegmented;
// get index and subindex
uiIndex =
AmiGetWordFromLe(&pAsySdoCom_p->m_le_abCommandData[4]);
uiSubindex =
AmiGetByteFromLe(&pAsySdoCom_p->m_le_abCommandData[6]);
// get source-pointer for copy
pbSrcData = &pAsySdoCom_p->m_le_abCommandData[8];
// save size
pSdoComCon_p->m_uiTransSize =
AmiGetDwordFromLe(&pAsySdoCom_p->m_le_abCommandData[0]);
} else if ((pAsySdoCom_p->m_le_bFlags & 0x30) == 0x00) { // expedited transfer
pSdoComCon_p->m_SdoTransType = kEplSdoTransExpedited;
// get index and subindex
uiIndex =
AmiGetWordFromLe(&pAsySdoCom_p->m_le_abCommandData[0]);
uiSubindex =
AmiGetByteFromLe(&pAsySdoCom_p->m_le_abCommandData[2]);
// get source-pointer for copy
pbSrcData = &pAsySdoCom_p->m_le_abCommandData[4];
// save size
pSdoComCon_p->m_uiTransSize =
AmiGetWordFromLe(&pAsySdoCom_p->m_le_wSegmentSize);
// subtract header
pSdoComCon_p->m_uiTransSize -= 4;
} else {
// just ignore any other transfer type
goto Exit;
}
// check accesstype of entry
// existens of entry
//#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDU)) != 0)
Ret = EplObduGetAccessType(uiIndex, uiSubindex, &AccessType);
/*#else
Ret = kEplObdSubindexNotExist;
AccessType = 0;
#endif*/
if (Ret == kEplObdSubindexNotExist) { // subentry doesn't exist
pSdoComCon_p->m_dwLastAbortCode = EPL_SDOAC_SUB_INDEX_NOT_EXIST;
// send abort
// d.k. This is wrong: k.t. not needed send abort on end of write
/*pSdoComCon_p->m_pData = (u8*)pSdoComCon_p->m_dwLastAbortCode;
Ret = EplSdoComServerSendFrameIntern(pSdoComCon_p,
uiIndex,
uiSubindex,
kEplSdoComSendTypeAbort); */
goto Abort;
} else if (Ret != kEplSuccessful) { // entry doesn't exist
pSdoComCon_p->m_dwLastAbortCode = EPL_SDOAC_OBJECT_NOT_EXIST;
// send abort
// d.k. This is wrong: k.t. not needed send abort on end of write
/*
pSdoComCon_p->m_pData = (u8*)&dwAbortCode;
Ret = EplSdoComServerSendFrameIntern(pSdoComCon_p,
uiIndex,
uiSubindex,
kEplSdoComSendTypeAbort); */
goto Abort;
}
// compare accesstype must be read
if ((AccessType & kEplObdAccWrite) == 0) {
if ((AccessType & kEplObdAccRead) != 0) {
// entry write a read only object
pSdoComCon_p->m_dwLastAbortCode =
EPL_SDOAC_WRITE_TO_READ_ONLY_OBJ;
} else {
pSdoComCon_p->m_dwLastAbortCode =
EPL_SDOAC_UNSUPPORTED_ACCESS;
}
// send abort
// d.k. This is wrong: k.t. not needed send abort on end of write
/*pSdoComCon_p->m_pData = (u8*)&dwAbortCode;
Ret = EplSdoComServerSendFrameIntern(pSdoComCon_p,
uiIndex,
uiSubindex,
kEplSdoComSendTypeAbort); */
goto Abort;
}
// save service
pSdoComCon_p->m_SdoServiceType = kEplSdoServiceWriteByIndex;
pSdoComCon_p->m_uiTransferredByte = 0;
// write data to OD
if (pSdoComCon_p->m_SdoTransType == kEplSdoTransExpedited) { // expedited transfer
// size checking is done by EplObduWriteEntryFromLe()
//#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDU)) != 0)
Ret = EplObduWriteEntryFromLe(uiIndex,
uiSubindex,
pbSrcData,
pSdoComCon_p->m_uiTransSize);
switch (Ret) {
case kEplSuccessful:
{
break;
}
case kEplObdAccessViolation:
{
pSdoComCon_p->m_dwLastAbortCode =
EPL_SDOAC_UNSUPPORTED_ACCESS;
// send abort
goto Abort;
}
case kEplObdValueLengthError:
{
pSdoComCon_p->m_dwLastAbortCode =
EPL_SDOAC_DATA_TYPE_LENGTH_NOT_MATCH;
// send abort
goto Abort;
}
case kEplObdValueTooHigh:
{
pSdoComCon_p->m_dwLastAbortCode =
EPL_SDOAC_VALUE_RANGE_TOO_HIGH;
// send abort
goto Abort;
}
case kEplObdValueTooLow:
{
pSdoComCon_p->m_dwLastAbortCode =
EPL_SDOAC_VALUE_RANGE_TOO_LOW;
// send abort
goto Abort;
}
default:
{
pSdoComCon_p->m_dwLastAbortCode =
EPL_SDOAC_GENERAL_ERROR;
// send abort
goto Abort;
}
}
//#endif
// send command acknowledge
Ret = EplSdoComServerSendFrameIntern(pSdoComCon_p,
0,
0,
kEplSdoComSendTypeAckRes);
pSdoComCon_p->m_uiTransSize = 0;
goto Exit;
} else {
// get size of the object to check if it fits
// because we directly write to the destination memory
// d.k. no one calls the user OD callback function
//#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDU)) != 0)
EntrySize = EplObduGetDataSize(uiIndex, uiSubindex);
/*#else
EntrySize = 0;
#endif */
if (EntrySize < pSdoComCon_p->m_uiTransSize) { // parameter too big
pSdoComCon_p->m_dwLastAbortCode =
EPL_SDOAC_DATA_TYPE_LENGTH_TOO_HIGH;
// send abort
// d.k. This is wrong: k.t. not needed send abort on end of write
/*pSdoComCon_p->m_pData = (u8*)&dwAbortCode;
Ret = EplSdoComServerSendFrameIntern(pSdoComCon_p,
uiIndex,
uiSubindex,
kEplSdoComSendTypeAbort); */
goto Abort;
}
uiBytesToTransfer =
AmiGetWordFromLe(&pAsySdoCom_p->m_le_wSegmentSize);
// eleminate header (Command header (8) + variable part (4) + Command header (4))
uiBytesToTransfer -= 16;
// get pointer to object entry
//#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDU)) != 0)
pSdoComCon_p->m_pData = EplObduGetObjectDataPtr(uiIndex,
uiSubindex);
//#endif
if (pSdoComCon_p->m_pData == NULL) {
pSdoComCon_p->m_dwLastAbortCode =
EPL_SDOAC_GENERAL_ERROR;
// send abort
// d.k. This is wrong: k.t. not needed send abort on end of write
/* pSdoComCon_p->m_pData = (u8*)&pSdoComCon_p->m_dwLastAbortCode;
Ret = EplSdoComServerSendFrameIntern(pSdoComCon_p,
uiIndex,
uiSubindex,
kEplSdoComSendTypeAbort);*/
goto Abort;
}
// copy data
EPL_MEMCPY(pSdoComCon_p->m_pData, pbSrcData, uiBytesToTransfer);
// update internal counter
pSdoComCon_p->m_uiTransferredByte = uiBytesToTransfer;
pSdoComCon_p->m_uiTransSize -= uiBytesToTransfer;
// update target pointer
( /*(u8*) */ pSdoComCon_p->m_pData) += uiBytesToTransfer;
// send acknowledge without any Command layer data
Ret = EplSdoAsySeqSendData(pSdoComCon_p->m_SdoSeqConHdl,
0, (tEplFrame *) NULL);
goto Exit;
}
Abort:
if (pSdoComCon_p->m_dwLastAbortCode != 0) {
// send abort
pSdoComCon_p->m_pData =
(u8 *) & pSdoComCon_p->m_dwLastAbortCode;
Ret =
EplSdoComServerSendFrameIntern(pSdoComCon_p, uiIndex,
uiSubindex,
kEplSdoComSendTypeAbort);
// reset abort code
pSdoComCon_p->m_dwLastAbortCode = 0;
pSdoComCon_p->m_uiTransSize = 0;
goto Exit;
}
Exit:
return Ret;
}
#endif
//---------------------------------------------------------------------------
//
// Function: EplSdoComClientSend
//
// Description: function starts an sdo transfer an send all further frames
//
//
//
// Parameters: pSdoComCon_p = pointer to control structure of connection
//
// Returns: tEplKernel = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
static tEplKernel EplSdoComClientSend(tEplSdoComCon * pSdoComCon_p)
{
tEplKernel Ret;
u8 abFrame[EPL_MAX_SDO_FRAME_SIZE];
tEplFrame *pFrame;
tEplAsySdoCom *pCommandFrame;
unsigned int uiSizeOfFrame;
u8 bFlags;
u8 *pbPayload;
Ret = kEplSuccessful;
pFrame = (tEplFrame *) & abFrame[0];
EPL_MEMSET(&abFrame[0], 0x00, sizeof(abFrame));
// build generic part of frame
// get pointer to command layerpart of frame
pCommandFrame =
&pFrame->m_Data.m_Asnd.m_Payload.m_SdoSequenceFrame.
m_le_abSdoSeqPayload;
AmiSetByteToLe(&pCommandFrame->m_le_bCommandId,
pSdoComCon_p->m_SdoServiceType);
AmiSetByteToLe(&pCommandFrame->m_le_bTransactionId,
pSdoComCon_p->m_bTransactionId);
// set size constant part of header
uiSizeOfFrame = 8;
// check if first frame to send -> command header needed
if (pSdoComCon_p->m_uiTransSize > 0) {
if (pSdoComCon_p->m_uiTransferredByte == 0) { // start SDO transfer
// check if segmented or expedited transfer
// only for write commands
switch (pSdoComCon_p->m_SdoServiceType) {
case kEplSdoServiceReadByIndex:
{ // first frame of read access always expedited
pSdoComCon_p->m_SdoTransType =
kEplSdoTransExpedited;
pbPayload =
&pCommandFrame->
m_le_abCommandData[0];
// fill rest of header
AmiSetWordToLe(&pCommandFrame->
m_le_wSegmentSize, 4);
// create command header
AmiSetWordToLe(pbPayload,
(WORD) pSdoComCon_p->
m_uiTargetIndex);
pbPayload += 2;
AmiSetByteToLe(pbPayload,
(u8) pSdoComCon_p->
m_uiTargetSubIndex);
// calc size
uiSizeOfFrame += 4;
// set pSdoComCon_p->m_uiTransferredByte to one
pSdoComCon_p->m_uiTransferredByte = 1;
break;
}
case kEplSdoServiceWriteByIndex:
{
if (pSdoComCon_p->m_uiTransSize > EPL_SDO_MAX_PAYLOAD) { // segmented transfer
// -> variable part of header needed
// save that transfer is segmented
pSdoComCon_p->m_SdoTransType =
kEplSdoTransSegmented;
// fill variable part of header
AmiSetDwordToLe(&pCommandFrame->
m_le_abCommandData
[0],
pSdoComCon_p->
m_uiTransSize);
// set pointer to real payload
pbPayload =
&pCommandFrame->
m_le_abCommandData[4];
// fill rest of header
AmiSetWordToLe(&pCommandFrame->
m_le_wSegmentSize,
EPL_SDO_MAX_PAYLOAD);
bFlags = 0x10;
AmiSetByteToLe(&pCommandFrame->
m_le_bFlags,
bFlags);
// create command header
AmiSetWordToLe(pbPayload,
(WORD)
pSdoComCon_p->
m_uiTargetIndex);
pbPayload += 2;
AmiSetByteToLe(pbPayload,
(u8)
pSdoComCon_p->
m_uiTargetSubIndex);
// on byte for reserved
pbPayload += 2;
// calc size
uiSizeOfFrame +=
EPL_SDO_MAX_PAYLOAD;
// copy payload
EPL_MEMCPY(pbPayload,
pSdoComCon_p->
m_pData,
(EPL_SDO_MAX_PAYLOAD
- 8));
pSdoComCon_p->m_pData +=
(EPL_SDO_MAX_PAYLOAD - 8);
// correct intern counter
pSdoComCon_p->m_uiTransSize -=
(EPL_SDO_MAX_PAYLOAD - 8);
pSdoComCon_p->
m_uiTransferredByte =
(EPL_SDO_MAX_PAYLOAD - 8);
} else { // expedited trandsfer
// save that transfer is expedited
pSdoComCon_p->m_SdoTransType =
kEplSdoTransExpedited;
pbPayload =
&pCommandFrame->
m_le_abCommandData[0];
// create command header
AmiSetWordToLe(pbPayload,
(WORD)
pSdoComCon_p->
m_uiTargetIndex);
pbPayload += 2;
AmiSetByteToLe(pbPayload,
(u8)
pSdoComCon_p->
m_uiTargetSubIndex);
// + 2 -> one byte for subindex and one byte reserved
pbPayload += 2;
// copy data
EPL_MEMCPY(pbPayload,
pSdoComCon_p->
m_pData,
pSdoComCon_p->
m_uiTransSize);
// calc size
uiSizeOfFrame +=
(4 +
pSdoComCon_p->
m_uiTransSize);
// fill rest of header
AmiSetWordToLe(&pCommandFrame->
m_le_wSegmentSize,
(WORD) (4 +
pSdoComCon_p->
m_uiTransSize));
pSdoComCon_p->
m_uiTransferredByte =
pSdoComCon_p->m_uiTransSize;
pSdoComCon_p->m_uiTransSize = 0;
}
break;
}
case kEplSdoServiceNIL:
default:
// invalid service requested
Ret = kEplSdoComInvalidServiceType;
goto Exit;
} // end of switch(pSdoComCon_p->m_SdoServiceType)
} else // (pSdoComCon_p->m_uiTransferredByte > 0)
{ // continue SDO transfer
switch (pSdoComCon_p->m_SdoServiceType) {
// for expedited read is nothing to do
// -> server sends data
case kEplSdoServiceWriteByIndex:
{ // send next frame
if (pSdoComCon_p->m_SdoTransType ==
kEplSdoTransSegmented) {
if (pSdoComCon_p->m_uiTransSize > EPL_SDO_MAX_PAYLOAD) { // next segment
pbPayload =
&pCommandFrame->
m_le_abCommandData
[0];
// fill rest of header
AmiSetWordToLe
(&pCommandFrame->
m_le_wSegmentSize,
EPL_SDO_MAX_PAYLOAD);
bFlags = 0x20;
AmiSetByteToLe
(&pCommandFrame->
m_le_bFlags,
bFlags);
// copy data
EPL_MEMCPY(pbPayload,
pSdoComCon_p->
m_pData,
EPL_SDO_MAX_PAYLOAD);
pSdoComCon_p->m_pData +=
EPL_SDO_MAX_PAYLOAD;
// correct intern counter
pSdoComCon_p->
m_uiTransSize -=
EPL_SDO_MAX_PAYLOAD;
pSdoComCon_p->
m_uiTransferredByte
=
EPL_SDO_MAX_PAYLOAD;
// calc size
uiSizeOfFrame +=
EPL_SDO_MAX_PAYLOAD;
} else { // end of transfer
pbPayload =
&pCommandFrame->
m_le_abCommandData
[0];
// fill rest of header
AmiSetWordToLe
(&pCommandFrame->
m_le_wSegmentSize,
(WORD)
pSdoComCon_p->
m_uiTransSize);
bFlags = 0x30;
AmiSetByteToLe
(&pCommandFrame->
m_le_bFlags,
bFlags);
// copy data
EPL_MEMCPY(pbPayload,
pSdoComCon_p->
m_pData,
pSdoComCon_p->
m_uiTransSize);
pSdoComCon_p->m_pData +=
pSdoComCon_p->
m_uiTransSize;
// calc size
uiSizeOfFrame +=
pSdoComCon_p->
m_uiTransSize;
// correct intern counter
pSdoComCon_p->
m_uiTransSize = 0;
pSdoComCon_p->
m_uiTransferredByte
=
pSdoComCon_p->
m_uiTransSize;
}
} else {
goto Exit;
}
break;
}
default:
{
goto Exit;
}
} // end of switch(pSdoComCon_p->m_SdoServiceType)
}
} else {
goto Exit;
}
// call send function of lower layer
switch (pSdoComCon_p->m_SdoProtType) {
case kEplSdoTypeAsnd:
case kEplSdoTypeUdp:
{
Ret = EplSdoAsySeqSendData(pSdoComCon_p->m_SdoSeqConHdl,
uiSizeOfFrame, pFrame);
break;
}
default:
{
Ret = kEplSdoComUnsupportedProt;
}
} // end of switch(pSdoComCon_p->m_SdoProtType)
Exit:
return Ret;
}
#endif
//---------------------------------------------------------------------------
//
// Function: EplSdoComClientProcessFrame
//
// Description: function process a received frame
//
//
//
// Parameters: SdoComCon_p = connection handle
// pAsySdoCom_p = pointer to frame to process
//
// Returns: tEplKernel = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
static tEplKernel EplSdoComClientProcessFrame(tEplSdoComConHdl SdoComCon_p,
tEplAsySdoCom * pAsySdoCom_p)
{
tEplKernel Ret;
u8 bBuffer;
unsigned int uiBuffer;
unsigned int uiDataSize;
unsigned long ulBuffer;
tEplSdoComCon *pSdoComCon;
Ret = kEplSuccessful;
// get pointer to control structure
pSdoComCon = &SdoComInstance_g.m_SdoComCon[SdoComCon_p];
// check if transaction Id fit
bBuffer = AmiGetByteFromLe(&pAsySdoCom_p->m_le_bTransactionId);
if (pSdoComCon->m_bTransactionId != bBuffer) {
// incorrect transaction id
// if running transfer
if ((pSdoComCon->m_uiTransferredByte != 0)
&& (pSdoComCon->m_uiTransSize != 0)) {
pSdoComCon->m_dwLastAbortCode = EPL_SDOAC_GENERAL_ERROR;
// -> send abort
EplSdoComClientSendAbort(pSdoComCon,
pSdoComCon->m_dwLastAbortCode);
// call callback of application
Ret =
EplSdoComTransferFinished(SdoComCon_p, pSdoComCon,
kEplSdoComTransferTxAborted);
}
} else { // check if correct command
bBuffer = AmiGetByteFromLe(&pAsySdoCom_p->m_le_bCommandId);
if (pSdoComCon->m_SdoServiceType != bBuffer) {
// incorrect command
// if running transfer
if ((pSdoComCon->m_uiTransferredByte != 0)
&& (pSdoComCon->m_uiTransSize != 0)) {
pSdoComCon->m_dwLastAbortCode =
EPL_SDOAC_GENERAL_ERROR;
// -> send abort
EplSdoComClientSendAbort(pSdoComCon,
pSdoComCon->
m_dwLastAbortCode);
// call callback of application
Ret =
EplSdoComTransferFinished(SdoComCon_p,
pSdoComCon,
kEplSdoComTransferTxAborted);
}
} else { // switch on command
switch (pSdoComCon->m_SdoServiceType) {
case kEplSdoServiceWriteByIndex:
{ // check if confirmation from server
// nothing more to do
break;
}
case kEplSdoServiceReadByIndex:
{ // check if it is an segmented or an expedited transfer
bBuffer =
AmiGetByteFromLe(&pAsySdoCom_p->
m_le_bFlags);
// mask uninteressting bits
bBuffer &= 0x30;
switch (bBuffer) {
// expedited transfer
case 0x00:
{
// check size of buffer
uiBuffer =
AmiGetWordFromLe
(&pAsySdoCom_p->
m_le_wSegmentSize);
if (uiBuffer > pSdoComCon->m_uiTransSize) { // buffer provided by the application is to small
// copy only a part
uiDataSize =
pSdoComCon->
m_uiTransSize;
} else { // buffer fits
uiDataSize =
uiBuffer;
}
// copy data
EPL_MEMCPY(pSdoComCon->
m_pData,
&pAsySdoCom_p->
m_le_abCommandData
[0],
uiDataSize);
// correct counter
pSdoComCon->
m_uiTransSize = 0;
pSdoComCon->
m_uiTransferredByte
= uiDataSize;
break;
}
// start of a segmented transfer
case 0x10:
{ // get total size of transfer
ulBuffer =
AmiGetDwordFromLe
(&pAsySdoCom_p->
m_le_abCommandData
[0]);
if (ulBuffer <= pSdoComCon->m_uiTransSize) { // buffer fit
pSdoComCon->
m_uiTransSize
=
(unsigned
int)
ulBuffer;
} else { // buffer to small
// send abort
pSdoComCon->
m_dwLastAbortCode
=
EPL_SDOAC_DATA_TYPE_LENGTH_TOO_HIGH;
// -> send abort
EplSdoComClientSendAbort
(pSdoComCon,
pSdoComCon->
m_dwLastAbortCode);
// call callback of application
Ret =
EplSdoComTransferFinished
(SdoComCon_p,
pSdoComCon,
kEplSdoComTransferRxAborted);
goto Exit;
}
// get segment size
// check size of buffer
uiBuffer =
AmiGetWordFromLe
(&pAsySdoCom_p->
m_le_wSegmentSize);
// subtract size of vaiable header from datasize
uiBuffer -= 4;
// copy data
EPL_MEMCPY(pSdoComCon->
m_pData,
&pAsySdoCom_p->
m_le_abCommandData
[4],
uiBuffer);
// correct counter an pointer
pSdoComCon->m_pData +=
uiBuffer;
pSdoComCon->
m_uiTransferredByte
+= uiBuffer;
pSdoComCon->
m_uiTransSize -=
uiBuffer;
break;
}
// segment
case 0x20:
{
// get segment size
// check size of buffer
uiBuffer =
AmiGetWordFromLe
(&pAsySdoCom_p->
m_le_wSegmentSize);
// check if data to copy fit to buffer
if (uiBuffer >= pSdoComCon->m_uiTransSize) { // to much data
uiBuffer =
(pSdoComCon->
m_uiTransSize
- 1);
}
// copy data
EPL_MEMCPY(pSdoComCon->
m_pData,
&pAsySdoCom_p->
m_le_abCommandData
[0],
uiBuffer);
// correct counter an pointer
pSdoComCon->m_pData +=
uiBuffer;
pSdoComCon->
m_uiTransferredByte
+= uiBuffer;
pSdoComCon->
m_uiTransSize -=
uiBuffer;
break;
}
// last segment
case 0x30:
{
// get segment size
// check size of buffer
uiBuffer =
AmiGetWordFromLe
(&pAsySdoCom_p->
m_le_wSegmentSize);
// check if data to copy fit to buffer
if (uiBuffer > pSdoComCon->m_uiTransSize) { // to much data
uiBuffer =
(pSdoComCon->
m_uiTransSize
- 1);
}
// copy data
EPL_MEMCPY(pSdoComCon->
m_pData,
&pAsySdoCom_p->
m_le_abCommandData
[0],
uiBuffer);
// correct counter an pointer
pSdoComCon->m_pData +=
uiBuffer;
pSdoComCon->
m_uiTransferredByte
+= uiBuffer;
pSdoComCon->
m_uiTransSize = 0;
break;
}
} // end of switch(bBuffer & 0x30)
break;
}
case kEplSdoServiceNIL:
default:
// invalid service requested
// $$$ d.k. What should we do?
break;
} // end of switch(pSdoComCon->m_SdoServiceType)
}
}
Exit:
return Ret;
}
#endif
//---------------------------------------------------------------------------
//
// Function: EplSdoComClientSendAbort
//
// Description: function send a abort message
//
//
//
// Parameters: pSdoComCon_p = pointer to control structure of connection
// dwAbortCode_p = Sdo abort code
//
// Returns: tEplKernel = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
static tEplKernel EplSdoComClientSendAbort(tEplSdoComCon * pSdoComCon_p,
DWORD dwAbortCode_p)
{
tEplKernel Ret;
u8 abFrame[EPL_MAX_SDO_FRAME_SIZE];
tEplFrame *pFrame;
tEplAsySdoCom *pCommandFrame;
unsigned int uiSizeOfFrame;
Ret = kEplSuccessful;
pFrame = (tEplFrame *) & abFrame[0];
EPL_MEMSET(&abFrame[0], 0x00, sizeof(abFrame));
// build generic part of frame
// get pointer to command layerpart of frame
pCommandFrame =
&pFrame->m_Data.m_Asnd.m_Payload.m_SdoSequenceFrame.
m_le_abSdoSeqPayload;
AmiSetByteToLe(&pCommandFrame->m_le_bCommandId,
pSdoComCon_p->m_SdoServiceType);
AmiSetByteToLe(&pCommandFrame->m_le_bTransactionId,
pSdoComCon_p->m_bTransactionId);
uiSizeOfFrame = 8;
// set response and abort flag
pCommandFrame->m_le_bFlags |= 0x40;
// copy abortcode to frame
AmiSetDwordToLe(&pCommandFrame->m_le_abCommandData[0], dwAbortCode_p);
// set size of segment
AmiSetWordToLe(&pCommandFrame->m_le_wSegmentSize, sizeof(DWORD));
// update counter
pSdoComCon_p->m_uiTransferredByte = sizeof(DWORD);
pSdoComCon_p->m_uiTransSize = 0;
// calc framesize
uiSizeOfFrame += sizeof(DWORD);
// save abort code
pSdoComCon_p->m_dwLastAbortCode = dwAbortCode_p;
// call send function of lower layer
switch (pSdoComCon_p->m_SdoProtType) {
case kEplSdoTypeAsnd:
case kEplSdoTypeUdp:
{
Ret = EplSdoAsySeqSendData(pSdoComCon_p->m_SdoSeqConHdl,
uiSizeOfFrame, pFrame);
break;
}
default:
{
Ret = kEplSdoComUnsupportedProt;
}
} // end of switch(pSdoComCon_p->m_SdoProtType)
return Ret;
}
#endif
//---------------------------------------------------------------------------
//
// Function: EplSdoComTransferFinished
//
// Description: calls callback function of application if available
// and clears entry in control structure
//
// Parameters: pSdoComCon_p = pointer to control structure of connection
// SdoComConState_p = state of SDO transfer
//
// Returns: tEplKernel = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
static tEplKernel EplSdoComTransferFinished(tEplSdoComConHdl SdoComCon_p,
tEplSdoComCon * pSdoComCon_p,
tEplSdoComConState SdoComConState_p)
{
tEplKernel Ret;
Ret = kEplSuccessful;
if (pSdoComCon_p->m_pfnTransferFinished != NULL) {
tEplSdoFinishedCb pfnTransferFinished;
tEplSdoComFinished SdoComFinished;
SdoComFinished.m_pUserArg = pSdoComCon_p->m_pUserArg;
SdoComFinished.m_uiNodeId = pSdoComCon_p->m_uiNodeId;
SdoComFinished.m_uiTargetIndex = pSdoComCon_p->m_uiTargetIndex;
SdoComFinished.m_uiTargetSubIndex =
pSdoComCon_p->m_uiTargetSubIndex;
SdoComFinished.m_uiTransferredByte =
pSdoComCon_p->m_uiTransferredByte;
SdoComFinished.m_dwAbortCode = pSdoComCon_p->m_dwLastAbortCode;
SdoComFinished.m_SdoComConHdl = SdoComCon_p;
SdoComFinished.m_SdoComConState = SdoComConState_p;
if (pSdoComCon_p->m_SdoServiceType ==
kEplSdoServiceWriteByIndex) {
SdoComFinished.m_SdoAccessType = kEplSdoAccessTypeWrite;
} else {
SdoComFinished.m_SdoAccessType = kEplSdoAccessTypeRead;
}
// reset transfer state so this handle is not busy anymore
pSdoComCon_p->m_uiTransferredByte = 0;
pSdoComCon_p->m_uiTransSize = 0;
pfnTransferFinished = pSdoComCon_p->m_pfnTransferFinished;
// delete function pointer to inform application only once for each transfer
pSdoComCon_p->m_pfnTransferFinished = NULL;
// call application's callback function
pfnTransferFinished(&SdoComFinished);
}
return Ret;
}
// EOF
|