-
Notifications
You must be signed in to change notification settings - Fork 0
/
Communication.cpp
96 lines (81 loc) · 1.57 KB
/
Communication.cpp
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
#include "StdAfx.h"
#include "Communication.h"
#define PORT
#define WRITE2FILE2
#define SENDSPEED2
HWND Communication::hWnd = (HWND) 10068;
Communication::Communication(void)
{
portState = false;
}
Communication::~Communication(void)
{
}
Communication::Communication(CodeType type)
{
codeType = type;
}
void Communication::startComm()
{
#ifdef PORT
BOOL state = mSerial.InitPort(hWnd, portNr, baud);
if (state > 0)
{
portState = true;
mSerial.StartMonitoring();
}
else
{
portState = false;
}
#else
portState = false;
#endif
printf("Initiate Port %s\n", portState?"Started":"Failed");
}
void Communication::stopComm()
{
if (portState)
{
mSerial.StopMonitoring();
mSerial.ClosePort();
portState = false;
}
}
void Communication::send(ArmInfo *arm, int status)
{
char msg[15];
int *angles = arm->getAngles();
int startJoint = 1;
if (status == Object::grabber)
startJoint = ArmInfo::GRABBER_INIT_JOINT;
#ifdef WRITE2FILE
FILE *out = fopen("F:/matlab project/angle1.txt", "w");
#endif
#ifdef SENDSPEED
sprintf(msg,"#%d*", (int)(arm->getSpeed()));
printf("%s\n", msg);
mSerial.WriteToPort(msg);
#endif
for (int i=startJoint; i<=ArmInfo::ANGLE_COUNT; i++)
{
//if (i != 5) continue;
if (codeType == IIICode)
sprintf(msg, "#%d#%03d*", i-1, angles[i]);
else
if (angles[i] > 0)
sprintf(msg,"#%d#%04d*", i-1, angles[i]);
else
sprintf(msg,"#%d#1%03d*", i-1, -angles[i]);
printf("%s\n", msg);
#ifdef PORT
mSerial.WriteToPort(msg);
#endif
#ifdef WRITE2FILE
fprintf(out, "%d ", angles[i]);
#endif
}
#ifdef WRITE2FILE
fclose(out);
#endif
}