Appendix M - Ttt_Vision.C
1:  #include "Ttt_Vision.H"
2:  
3:  
4:  Ttt_Vision::Ttt_Vision (int sock_number, int32 device_id, int frame_height,
5:  			int frame_width)
6:  {
7:    sock = sock_number;
8:    id = device_id;
9:  
10:    height = frame_height;
11:    width = frame_width;
12:  
13:    // what we're doing
14:    int8 val = AGENT_SEND_TO_DEVICE;
15:    shelley_sockets_write (sock, (char*) &val, sizeof (int8));
16:  
17:    // to which device
18:    int32 val32 = id;
19:    shelley_sockets_write (sock, (char*) &val32, sizeof (int32));
20:  
21:    // how long the message is
22:    val32 = sizeof (int8) + sizeof(int32) * 2;
23:    shelley_sockets_write (sock, (char*) &val32, sizeof (int32));
24:  
25:    // the message (it's about time)
26:    val = TTT_VISION_SET_RESOLUTION;
27:    shelley_sockets_write (sock, (char*) &val, sizeof (int8));
28:    
29:    // the next thing going out is the resolution
30:    shelley_sockets_write (sock, (char*) &width, sizeof (int32));
31:    shelley_sockets_write (sock, (char*) &height, sizeof (int32));
32:  
33:    shelley_sockets_read (sock, (char*) &val, sizeof (int8));
34:  }
35:  
36:  
37:  
38:  void Ttt_Vision::find_ttt(unsigned char* data, unsigned char game[3][3])
39:  {
40:    unsigned char* i;
41:  
42:    /*********************************/
43:    // what we're doing
44:    int8 val = AGENT_SEND_TO_DEVICE;
45:    shelley_sockets_write (sock, (char*) &val, sizeof (int8));
46:  
47:    // to which device
48:    int32 val32 = id;
49:    shelley_sockets_write (sock, (char*) &val32, sizeof (int32));
50:  
51:    // how long the message is
52:    val32 = sizeof (int8) + (height * width * 3);
53:    shelley_sockets_write (sock, (char*) &val32, sizeof (int32));
54:  
55:    // the message (it's about time)
56:    val = TTT_VISION_FIND_TTT;
57:    shelley_sockets_write (sock, (char*) &val, sizeof (int8));
58:    shelley_sockets_write (sock, (char*)data, val32 - 1);
59:  
60:    // the next thing coming back is the responce
61:    shelley_sockets_read (sock, (char*)game, sizeof (unsigned char) * 9);
62:  }
63: