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
| // Cguisignal.cpp*: fichier d'implémentation
//
#include "stdafx.h"
#include "GUI_SNN3.h"
#include "Cguisignal.h"
#include "afxdialogex.h"
#include "Cguisignal.h"
#include "Watchdog_actif.h"
#include "Watchdog_ohneP.h"
#include "Watchdog_back.h"
#include "timer4watchdog.h"
#include "timer.h"
#include "trigger.h"
#include <winsock2.h>
#include <ws2tcpip.h>
#include <winerror.h>
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <cstring>
#include <sstream>
#include <iostream>
#include <string>
#include <csignal>
// Boîte de dialogue Cguisignal
IMPLEMENT_DYNAMIC(Cguisignal, CDialog)
Cguisignal::Cguisignal(CWnd* pParent /*=NULL*/)
: CDialog(Cguisignal::IDD, pParent)
{
}
Cguisignal::~Cguisignal()
{
}
void Cguisignal::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_picture1, m_picture);
}
BEGIN_MESSAGE_MAP(Cguisignal, CDialog)
// ON_COMMAND(ID_APPLICATION_GUISIGNAL, &Cguisignal::OnApplicationGuisignal)
// ON_WM_HELPINFO()
ON_WM_PAINT()
ON_BN_CLICKED(IDC_BUTTON445, &Cguisignal::OnClickedButton445)
END_MESSAGE_MAP()
}
///////////////////////////// Activation module pattern /////////////////////////////////////////////////
void Cguisignal::OnClickedButton445()
{
watchdog_actif();
// new socket
WSADATA sysdataPattern1;
SOCKET SocketPattern1;
char RecvBufPattern1[1500];
char RecvDataPattern1[1500];
int BufLenPattern1 = 1500;
int iResultPattern1;
int iRecvLenPattern1;
sockaddr_in RecvAddrPattern1;
sockaddr_in SenderAddrPattern1;
int SenderAddrSizePattern1 = sizeof(SenderAddrPattern1);
int RecvAddrSizePattern1 = sizeof(RecvAddrPattern1);
unsigned short PortPattern1 = 35429; // Port für TCP-Verbindung (UDP: 35428)
// Initialize Winsock
iResultPattern1 = WSAStartup(MAKEWORD(2, 2), &sysdataPattern1);
if (iResultPattern1 != NO_ERROR)
{
//printf("WSAStartup failed");
}
// Ansteuerungsbefehl
char SenderPattern1[] = {0x84, 0x01, 0xC8, 0x8C, 0xEF};
//{0x84, 0x01, 0xC8, 0x8C, 0xEF};
/* 0x84 --> CMD
0x01 --> nombre de paramètre
0xC8 --> Module pattern (Bit3) und VAS4 (Bit6 und Bit7)
0x8C --> CRC
0xEF --> CRC
*/
// Create a socket to receive data
SocketPattern1 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (SocketPattern1 == INVALID_SOCKET)
{
//printf("socket failed with error");
}
// Bind the socket to address an specified port
RecvAddrPattern1.sin_family = AF_INET;
RecvAddrPattern1.sin_port = htons(PortPattern1); //192.168.203.150
RecvAddrPattern1.sin_addr.S_un.S_un_b.s_b1 = (unsigned char) 192;
RecvAddrPattern1.sin_addr.S_un.S_un_b.s_b2 = (unsigned char) 168;
RecvAddrPattern1.sin_addr.S_un.S_un_b.s_b3 = (unsigned char) 203;
RecvAddrPattern1.sin_addr.S_un.S_un_b.s_b4 = (unsigned char) 150;
// Connect to server.
iResultPattern1 = connect(SocketPattern1,(SOCKADDR*) &RecvAddrPattern1, sizeof(RecvAddrPattern1));
if (iResultPattern1 == SOCKET_ERROR)
{
closesocket(SocketPattern1);
SocketPattern1 = INVALID_SOCKET;
}
if (SocketPattern1 == INVALID_SOCKET)
{
//printf("Unable to connect to server!\n");
WSACleanup();
connection_error();
Cguisignal::OnInitDialog();
return;
}
// Send data to socket
iResultPattern1 = send(SocketPattern1, SenderPattern1, BufLenPattern1, 0);
int iLastErrorPattern1 = WSAGetLastError();
if (iResultPattern1 == SOCKET_ERROR)
{
//printf("sendto failed with error");
closesocket(SocketPattern1);
WSACleanup();
}
// recv-function
//printf("Receiving data...\n");
iRecvLenPattern1 = recv(SocketPattern1, RecvBufPattern1, BufLenPattern1, 0);
if (iRecvLenPattern1 == -1)
{
connection_error();
Cguisignal::OnInitDialog();
return;
}
// Socket schließen
closesocket(SocketPattern1);
WSACleanup();
watchdog_ohneP();
//////////////////////////////////////////////////////////////////////////////////////
///////////////////////// CROSS DOWNLOAD //////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
// Nouveau socket
WSADATA sysdataCrossdownload;
SOCKET SocketCrossdownload;
char RecvBufCrossdownload[1500];
char RecvDataCrossdownload[1500];
int BufLenCrossdownload = 1500;
int iResultCrossdownload;
int iRecvLenCrossdownload;
sockaddr_in RecvAddrCrossdownload;
sockaddr_in SenderAddrCrossdownload;
int SenderAddrSizeCrossdownload = sizeof(SenderAddrCrossdownload);
int RecvAddrSizeCrossdownload = sizeof(RecvAddrCrossdownload);
unsigned short PortCrossdownload = 35429; // Port liaison TCP (UDP: 35428)
// Initialisation de Winsock
iResultCrossdownload = WSAStartup(MAKEWORD(2, 2), &sysdataCrossdownload);
if (iResultCrossdownload != NO_ERROR)
{
//printf("WSAStartup failed");
}
char SenderBufCrossdownload[] = {0x91, 0x01, 0x0C, 0xBD, 0xB4};
/* 0x91 = commando
0x01 = nombre de paramètre
0x10 = couleur bit 7: pixel transparent
bit 5 4: bleu
bit 3 2: vert
bit 1 0: rouge
*/
// Creation d'un socket pour recevoir les données
SocketCrossdownload = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (SocketCrossdownload == INVALID_SOCKET)
{
//printf("socket failed with error");
}
// Liaison d'un socket a une adresse spécifique
RecvAddrCrossdownload.sin_family = AF_INET;
RecvAddrCrossdownload.sin_port = htons(PortCrossdownload); //192.168.203.150
RecvAddrCrossdownload.sin_addr.S_un.S_un_b.s_b1 = (unsigned char) 192;
RecvAddrCrossdownload.sin_addr.S_un.S_un_b.s_b2 = (unsigned char) 168;
RecvAddrCrossdownload.sin_addr.S_un.S_un_b.s_b3 = (unsigned char) 203;
RecvAddrCrossdownload.sin_addr.S_un.S_un_b.s_b4 = (unsigned char) 150;
// Connection au serveur
iResultCrossdownload = connect(SocketCrossdownload,(SOCKADDR*) &RecvAddrCrossdownload, sizeof(RecvAddrCrossdownload));
if (iResultCrossdownload == SOCKET_ERROR)
{
closesocket(SocketCrossdownload);
SocketCrossdownload = INVALID_SOCKET;
}
if (SocketCrossdownload == INVALID_SOCKET)
{
//printf("Unable to connect to server!\n");
WSACleanup();
connection_error();
Cguisignal::OnInitDialog();
return;
}
//Envoie des données au socket
iResultCrossdownload = send(SocketCrossdownload, SenderBufCrossdownload, BufLenCrossdownload, 0);
int iLastErrorCrossdownload = WSAGetLastError();
if (iResultCrossdownload == SOCKET_ERROR)
{
//printf("sendto failed with error");
closesocket(SocketCrossdownload);
WSACleanup();
}
// recv-function
//printf("Receiving data...\n");
iRecvLenCrossdownload = recv(SocketCrossdownload, RecvBufCrossdownload, BufLenCrossdownload, 0);
if (iRecvLenCrossdownload == -1)
{
connection_error();
Cguisignal::OnInitDialog();
return;
}
// Fermeture socket
closesocket(SocketCrossdownload);
WSACleanup();
watchdog_ohneP();
//////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////// configuration pattern /////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
// Nouveau socket
WSADATA sysdataPattern;
SOCKET SocketPattern;
char RecvBufPattern[1500];
char RecvDataPattern[1500];
int BufLenPattern = 1500;
int iResultPattern;
int iRecvLenPattern;
sockaddr_in RecvAddrPattern;
sockaddr_in SenderAddrPattern;
int SenderAddrSizePattern = sizeof(SenderAddrPattern);
int RecvAddrSizePattern = sizeof(RecvAddrPattern);
unsigned short PortPattern = 35429; // Port Liaison TCP (UDP: 35428)
// Initialisation de Winsock
iResultPattern = WSAStartup(MAKEWORD(2, 2), &sysdataPattern);
if (iResultPattern != NO_ERROR)
{
//printf("WSAStartup failed");
}
// Commande
char SenderBufPattern[] = {0x90, 0x06, 0xFC, 0xAB, 0x32, 0x32, 0x4C, 0x01, 0x0F, 0x10};
/*
0x90 = commando
0x06 = nombre de paramètre
0xFC = Bit 0 et 1 : luminosité et nx de gris, Bit 2: pas de synchronisation verticale
Bit 3: pas de synchronisation horizontale, Bit 4 à 7 : quadrant
0xAB = Bit0 sortie video, Bit 1 modele synchronisation verticale, Bit3 à 4 point, croix , image
Bit 5,6,7 echiquier 101 128*96
0x32 = Xcoordonne 50 0 gauche, 112 milieu, 224 droit
0x32 = Ycoordonne 50 0 gauche, 112 milieu, 224 droit
0xFC = couleur du premier plan
0x01 = couleur arriere plan
*/
// Creation d'un socket pour recevoir les données
SocketPattern = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (SocketPattern == INVALID_SOCKET)
{
//printf("socket failed with error");
}
// Liaison d'un socket a une adresse spécifique
RecvAddrPattern.sin_family = AF_INET;
RecvAddrPattern.sin_port = htons(PortPattern); //192.168.203.150
RecvAddrPattern.sin_addr.S_un.S_un_b.s_b1 = (unsigned char) 192;
RecvAddrPattern.sin_addr.S_un.S_un_b.s_b2 = (unsigned char) 168;
RecvAddrPattern.sin_addr.S_un.S_un_b.s_b3 = (unsigned char) 203;
RecvAddrPattern.sin_addr.S_un.S_un_b.s_b4 = (unsigned char) 150;
// Connection au serveur
iResultPattern = connect(SocketPattern,(SOCKADDR*) &RecvAddrPattern, sizeof(RecvAddrPattern));
if (iResultPattern == SOCKET_ERROR)
{
closesocket(SocketPattern);
SocketPattern = INVALID_SOCKET;
}
if (SocketPattern == INVALID_SOCKET)
{
//printf("Unable to connect to server!\n");
WSACleanup();
connection_error();
Cguisignal::OnInitDialog();
return;
}
// Send data to socket
iResultPattern = send(SocketPattern, SenderBufPattern, BufLenPattern, 0);
int iLastErrorPattern = WSAGetLastError();
if (iResultPattern == SOCKET_ERROR)
{
//printf("sendto failed with error");
closesocket(SocketPattern);
WSACleanup();
}
// recv-function
//printf("Receiving data...\n");
iRecvLenPattern = recv(SocketPattern, RecvBufPattern, BufLenPattern, 0);
if (iRecvLenPattern == -1)
{
connection_error();
Cguisignal::OnInitDialog();
return;
}
// Fermeture socket
closesocket(SocketPattern);
WSACleanup();
watchdog_ohneP();
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// CROSS POSITION //////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
// Nouveau socket
WSADATA sysdataCrossposition;
SOCKET SocketCrossposition;
char RecvBufCrossposition[1500];
char RecvDataCrossposition[1500];
int BufLenCrossposition = 1500;
int iResultCrossposition;
int iRecvLenCrossposition;
sockaddr_in RecvAddrCrossposition;
sockaddr_in SenderAddrCrossposition;
int SenderAddrSizeCrossposition = sizeof(SenderAddrCrossposition);
int RecvAddrSizeCrossposition = sizeof(RecvAddrCrossposition);
unsigned short PortCrossposition = 35429; // Port liaison TCP (UDP: 35428)
// Initialisation de Winsock
iResultCrossposition = WSAStartup(MAKEWORD(2, 2), &sysdataCrossposition);
if (iResultCrossposition != NO_ERROR)
{
//printf("WSAStartup failed");
}
// Commande
char SenderBufCrossposition[] = {0x92,0x02,0x32,0x32,0x30,0x71};
/* 0x93 = commando
0x06 = X coordonnée (0..224 = gauche...droite avec 112 au milieu)
0x05 = Y coordonnée (0..160 = haut...bas avec 80 au milieu)
*/
// Creation d'un socket pour recevoir les données
SocketCrossposition = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (SocketCrossposition == INVALID_SOCKET)
{
//printf("socket failed with error");
}
// Liaison d'un socket a une adresse spécifique
RecvAddrCrossposition.sin_family = AF_INET;
RecvAddrCrossposition.sin_port = htons(PortCrossposition); //192.168.203.150
RecvAddrCrossposition.sin_addr.S_un.S_un_b.s_b1 = (unsigned char) 192;
RecvAddrCrossposition.sin_addr.S_un.S_un_b.s_b2 = (unsigned char) 168;
RecvAddrCrossposition.sin_addr.S_un.S_un_b.s_b3 = (unsigned char) 203;
RecvAddrCrossposition.sin_addr.S_un.S_un_b.s_b4 = (unsigned char) 150;
// Connection au serveur
iResultCrossposition = connect(SocketCrossposition,(SOCKADDR*) &RecvAddrCrossposition, sizeof(RecvAddrCrossposition));
if (iResultCrossposition == SOCKET_ERROR)
{
closesocket(SocketCrossposition);
SocketCrossposition = INVALID_SOCKET;
}
if (SocketCrossposition == INVALID_SOCKET)
{
//printf("Unable to connect to server!\n");
WSACleanup();
connection_error();
Cguisignal::OnInitDialog();
return;
}
// Send data to socket
iResultCrossposition = send(SocketCrossposition, SenderBufCrossposition, BufLenCrossposition, 0);
int iLastErrorCrossposition = WSAGetLastError();
if (iResultCrossposition == SOCKET_ERROR)
{
//printf("sendto failed with error");
closesocket(SocketCrossposition);
WSACleanup();
}
// recv-function
//printf("Receiving data...\n");
iRecvLenCrossposition = recv(SocketCrossposition, RecvBufCrossposition, BufLenCrossposition, 0);
if (iRecvLenCrossposition == -1)
{
connection_error();
Cguisignal::OnInitDialog();
return;
}
// Fermeture socket
closesocket(SocketCrossposition);
WSACleanup();
watchdog_ohneP();
/////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////// CROSS MOUVEMENT ///////////////////////////////////
// Nouveau socket
WSADATA sysdataCrossmovement;
SOCKET SocketCrossmovement;
char RecvBufCrossmovement[1500];
char RecvDataCrossmovement[1500];
int BufLenCrossmovement = 1500;
int iResultCrossmovement;
int iRecvLenCrossmovement;
sockaddr_in RecvAddrCrossmovement;
sockaddr_in SenderAddrCrossmovement;
int SenderAddrSizeCrossmovement = sizeof(SenderAddrCrossmovement);
int RecvAddrSizeCrossmovement = sizeof(RecvAddrCrossmovement);
unsigned short PortCrossmovement = 35429; // Port liaison TCP (UDP: 35428)
// Initialisation de Winsock
iResultCrossmovement = WSAStartup(MAKEWORD(2, 2), &sysdataCrossmovement);
if (iResultCrossmovement != NO_ERROR)
{
//printf("WSAStartup failed");
}
// Commande
char SenderBufCrossmovement[] = {0x93, 0x06, 0x05, 0x05, 0x00, 0x01, 0x50, 0x80, 0x61, 0x34};
/* 0x93 = commando
0x06 = nombre de paramètre
0x05 = temps de montée 5 * 1/10 = 5 dixième de seconde
0x05 = temps de descente 5 * 1/10 = 5 dixième de seconde
0x00 = variable boolean 0: mouvement verticale, 1: mouvement horizontale
0x01 = variable boolean 0: mouvement linéaire, 1: mouvement sinusoidale
0x03 = "minimaler ausschlag"
0x02 = "maximaler ausschlag"
50
*/
// Creation d'un socket pour recevoir les données
SocketCrossmovement = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (SocketCrossmovement == INVALID_SOCKET)
{
//printf("socket failed with error");
}
// Liaison d'un socket a une adresse spécifique
RecvAddrCrossmovement.sin_family = AF_INET;
RecvAddrCrossmovement.sin_port = htons(PortCrossmovement); //192.168.203.150
RecvAddrCrossmovement.sin_addr.S_un.S_un_b.s_b1 = (unsigned char) 192;
RecvAddrCrossmovement.sin_addr.S_un.S_un_b.s_b2 = (unsigned char) 168;
RecvAddrCrossmovement.sin_addr.S_un.S_un_b.s_b3 = (unsigned char) 203;
RecvAddrCrossmovement.sin_addr.S_un.S_un_b.s_b4 = (unsigned char) 150;
// Connection au serveur
iResultCrossmovement = connect(SocketCrossmovement,(SOCKADDR*) &RecvAddrCrossmovement, sizeof(RecvAddrCrossmovement));
if (iResultCrossmovement == SOCKET_ERROR)
{
closesocket(SocketCrossmovement);
SocketCrossmovement = INVALID_SOCKET;
}
if (SocketCrossmovement == INVALID_SOCKET)
{
//printf("Unable to connect to server!\n");
WSACleanup();
connection_error();
Cguisignal::OnInitDialog();
return;
}
// Send data to socket
iResultCrossmovement = send(SocketCrossmovement, SenderBufCrossmovement, BufLenCrossmovement, 0);
int iLastErrorCrossmovement = WSAGetLastError();
if (iResultCrossmovement == SOCKET_ERROR)
{
//printf("sendto failed with error");
closesocket(SocketCrossmovement);
WSACleanup();
}
// recv-function
//printf("Receiving data...\n");
iRecvLenCrossmovement = recv(SocketCrossmovement, RecvBufCrossmovement, BufLenCrossmovement, 0);
if (iRecvLenCrossmovement == -1)
{
connection_error();
Cguisignal::OnInitDialog();
return;
}
// Fermeture socket
closesocket(SocketCrossmovement);
WSACleanup();
watchdog_back();
triggerOne();
timerOne();
timer4watchdog();
} |
Partager