Christian Heimke commited on 2011-07-15 09:04:53
Showing 15 changed files, with 767 additions and 70 deletions.
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
/* BlinkenLib |
2 |
- * version 0.5.1 date 2005-12-14 |
|
3 |
- * Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info> |
|
2 |
+ * version 0.5.2 date 2006-05-10 |
|
3 |
+ * Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info> |
|
4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
5 | 5 |
* a blinkenarea.org project |
6 | 6 |
*/ |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
/* BlinkenLib |
2 |
- * version 0.5.1 date 2005-12-14 |
|
3 |
- * Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info> |
|
2 |
+ * version 0.5.2 date 2006-05-10 |
|
3 |
+ * Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info> |
|
4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
5 | 5 |
* a blinkenarea.org project |
6 | 6 |
*/ |
... | ... |
@@ -20,8 +20,8 @@ int main( int argCnt, char * * args ) |
20 | 20 |
|
21 | 21 |
//print info |
22 | 22 |
printf( "BlinkenLib - BlinkenConv\n" |
23 |
- "version 0.5.1 date 2005-12-14\n" |
|
24 |
- "Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info>\n" |
|
23 |
+ "version 0.5.2 date 2006-05-10\n" |
|
24 |
+ "Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info>\n" |
|
25 | 25 |
"Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n" |
26 | 26 |
"a blinkenarea.org project\n\n" ); |
27 | 27 |
|
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
/* BlinkenLib |
2 |
- * version 0.5.1 date 2005-12-14 |
|
3 |
- * Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info> |
|
2 |
+ * version 0.5.2 date 2006-05-10 |
|
3 |
+ * Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info> |
|
4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
5 | 5 |
* a blinkenarea.org project |
6 | 6 |
*/ |
... | ... |
@@ -8,8 +8,15 @@ |
8 | 8 |
#include <stdio.h> |
9 | 9 |
#include <stdlib.h> |
10 | 10 |
#include <string.h> |
11 |
+#ifdef WIN32 |
|
12 |
+#include <winsock2.h> |
|
13 |
+#include <windows.h> |
|
14 |
+typedef WORD uint16_t; |
|
15 |
+typedef DWORD uint32_t; |
|
16 |
+#else |
|
11 | 17 |
#include <stdint.h> |
12 | 18 |
#include <netinet/in.h> |
19 |
+#endif |
|
13 | 20 |
|
14 | 21 |
#include "BlinkenConstants.h" |
15 | 22 |
#include "BlinkenFrame.h" |
... | ... |
@@ -207,12 +214,14 @@ void BlinkenFrameSetPixel( stBlinkenFrame * pFrame, int y, int x, int c, unsigne |
207 | 214 |
|
208 | 215 |
unsigned long BlinkenFrameGetColor( stBlinkenFrame * pFrame, int y, int x ) |
209 | 216 |
{ |
217 |
+ int i; |
|
218 |
+ |
|
210 | 219 |
if( pFrame == NULL || |
211 | 220 |
y < 0 || y >= pFrame->height || |
212 | 221 |
x < 0 || x >= pFrame->width ) |
213 | 222 |
return 0; |
214 | 223 |
|
215 |
- int i = x * pFrame->channels; |
|
224 |
+ i = x * pFrame->channels; |
|
216 | 225 |
|
217 | 226 |
if( pFrame->channels == 1 ) |
218 | 227 |
return (((unsigned long)pFrame->ppData[y][i + 0] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 16 | |
... | ... |
@@ -228,14 +237,14 @@ unsigned long BlinkenFrameGetColor( stBlinkenFrame * pFrame, int y, int x ) |
228 | 237 |
|
229 | 238 |
void BlinkenFrameSetColor( stBlinkenFrame * pFrame, int y, int x, unsigned long color ) |
230 | 239 |
{ |
231 |
- int alpha, alpha_, c; |
|
240 |
+ int i, alpha, alpha_, c; |
|
232 | 241 |
|
233 | 242 |
if( pFrame == NULL || |
234 | 243 |
y < 0 || y >= pFrame->height || |
235 | 244 |
x < 0 || x >= pFrame->width ) |
236 | 245 |
return; |
237 | 246 |
|
238 |
- int i = x * pFrame->channels; |
|
247 |
+ i = x * pFrame->channels; |
|
239 | 248 |
|
240 | 249 |
alpha = (color >> 24) & 0xFF; |
241 | 250 |
alpha_ = 255 - alpha; |
... | ... |
@@ -513,8 +522,8 @@ int BlinkenFrameToNetwork( stBlinkenFrame * pFrame, etBlinkenProto proto, char * |
513 | 522 |
return -1; |
514 | 523 |
((stBlinkenProtoBlpHdr *)pData)->magic = htonl( BlinkenProtoBlpMagic ); //build header |
515 | 524 |
((stBlinkenProtoBlpHdr *)pData)->frameNo = htonl( 0 ); |
516 |
- ((stBlinkenProtoBlpHdr *)pData)->width = htons( pFrame->width ); |
|
517 |
- ((stBlinkenProtoBlpHdr *)pData)->height = htons( pFrame->height ); |
|
525 |
+ ((stBlinkenProtoBlpHdr *)pData)->width = htons( (uint16_t)pFrame->width ); |
|
526 |
+ ((stBlinkenProtoBlpHdr *)pData)->height = htons( (uint16_t)pFrame->height ); |
|
518 | 527 |
i = sizeof( stBlinkenProtoBlpHdr ); //put data into packet |
519 | 528 |
for( y = 0; y < pFrame->height; y++ ) |
520 | 529 |
{ |
... | ... |
@@ -533,8 +542,8 @@ int BlinkenFrameToNetwork( stBlinkenFrame * pFrame, etBlinkenProto proto, char * |
533 | 542 |
return -1; |
534 | 543 |
((stBlinkenProtoEblpHdr *)pData)->magic = htonl( BlinkenProtoEblpMagic ); //build header |
535 | 544 |
((stBlinkenProtoEblpHdr *)pData)->frameNo = htonl( 0 ); |
536 |
- ((stBlinkenProtoEblpHdr *)pData)->width = htons( pFrame->width ); |
|
537 |
- ((stBlinkenProtoEblpHdr *)pData)->height = htons( pFrame->height ); |
|
545 |
+ ((stBlinkenProtoEblpHdr *)pData)->width = htons( (uint16_t)pFrame->width ); |
|
546 |
+ ((stBlinkenProtoEblpHdr *)pData)->height = htons( (uint16_t)pFrame->height ); |
|
538 | 547 |
i = sizeof( stBlinkenProtoEblpHdr ); //put data into packet |
539 | 548 |
for( y = 0; y < pFrame->height; y++ ) |
540 | 549 |
{ |
... | ... |
@@ -554,10 +563,10 @@ int BlinkenFrameToNetwork( stBlinkenFrame * pFrame, etBlinkenProto proto, char * |
554 | 563 |
if( maxLength < (int)sizeof( stBlinkenProtoMcufHdr ) + pFrame->height * pFrame->width * pFrame->channels ) //buffer too short |
555 | 564 |
return -1; |
556 | 565 |
((stBlinkenProtoMcufHdr *)pData)->magic = htonl( BlinkenProtoMcufMagic ); //build header |
557 |
- ((stBlinkenProtoMcufHdr *)pData)->height = htons( pFrame->height ); |
|
558 |
- ((stBlinkenProtoMcufHdr *)pData)->width = htons( pFrame->width ); |
|
559 |
- ((stBlinkenProtoMcufHdr *)pData)->channels = htons( pFrame->channels ); |
|
560 |
- ((stBlinkenProtoMcufHdr *)pData)->maxval = htons( pFrame->maxval ); |
|
566 |
+ ((stBlinkenProtoMcufHdr *)pData)->height = htons( (uint16_t)pFrame->height ); |
|
567 |
+ ((stBlinkenProtoMcufHdr *)pData)->width = htons( (uint16_t)pFrame->width ); |
|
568 |
+ ((stBlinkenProtoMcufHdr *)pData)->channels = htons( (uint16_t)pFrame->channels ); |
|
569 |
+ ((stBlinkenProtoMcufHdr *)pData)->maxval = htons( (uint16_t)pFrame->maxval ); |
|
561 | 570 |
i = sizeof( stBlinkenProtoMcufHdr ); //put data into packet |
562 | 571 |
for( y = 0; y < pFrame->height; y++ ) |
563 | 572 |
for( x = 0, j = 0; x < pFrame->width; x++ ) |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
/* BlinkenLib |
2 |
- * version 0.5.1 date 2005-12-14 |
|
3 |
- * Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info> |
|
2 |
+ * version 0.5.2 date 2006-05-10 |
|
3 |
+ * Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info> |
|
4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
5 | 5 |
* a blinkenarea.org project |
6 | 6 |
*/ |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
/* BlinkenLib |
2 |
- * version 0.5.1 date 2005-12-14 |
|
3 |
- * Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info> |
|
2 |
+ * version 0.5.2 date 2006-05-10 |
|
3 |
+ * Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info> |
|
4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
5 | 5 |
* a blinkenarea.org project |
6 | 6 |
*/ |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
/* BlinkenLib |
2 |
- * version 0.5.1 date 2005-12-14 |
|
3 |
- * Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info> |
|
2 |
+ * version 0.5.2 date 2006-05-10 |
|
3 |
+ * Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info> |
|
4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
5 | 5 |
* a blinkenarea.org project |
6 | 6 |
*/ |
... | ... |
@@ -8,11 +8,16 @@ |
8 | 8 |
#include <stdio.h> |
9 | 9 |
#include <stdlib.h> |
10 | 10 |
#include <string.h> |
11 |
+#ifdef WIN32 |
|
12 |
+#include <winsock2.h> |
|
13 |
+#include <windows.h> |
|
14 |
+#else |
|
11 | 15 |
#include <unistd.h> |
12 | 16 |
#include <sys/time.h> |
13 | 17 |
#include <sys/types.h> |
14 | 18 |
#include <sys/socket.h> |
15 | 19 |
#include <sys/select.h> |
20 |
+#endif |
|
16 | 21 |
|
17 | 22 |
#include "BlinkenConstants.h" |
18 | 23 |
#include "BlinkenFrame.h" |
... | ... |
@@ -31,6 +36,34 @@ struct sBlinkenMovie |
31 | 36 |
stBlinkenFrame * * ppFrames; |
32 | 37 |
}; |
33 | 38 |
|
39 |
+#ifdef WIN32 |
|
40 |
+ |
|
41 |
+static void msleep( unsigned int ms ) |
|
42 |
+{ |
|
43 |
+ Sleep( ms ); |
|
44 |
+} |
|
45 |
+ |
|
46 |
+static unsigned int get_ms( ) |
|
47 |
+{ |
|
48 |
+ return GetTickCount( ); |
|
49 |
+} |
|
50 |
+ |
|
51 |
+#else |
|
52 |
+ |
|
53 |
+static void msleep( unsigned int ms ) |
|
54 |
+{ |
|
55 |
+ usleep( ms * 1000 ); |
|
56 |
+} |
|
57 |
+ |
|
58 |
+static unsigned int get_ms( ) |
|
59 |
+{ |
|
60 |
+ struct timeval tv; |
|
61 |
+ gettimeofday( &tv, NULL ); |
|
62 |
+ return (unsigned int)(tv.tv_usec / 1000 + tv.tv_sec * 1000); |
|
63 |
+} |
|
64 |
+ |
|
65 |
+#endif |
|
66 |
+ |
|
34 | 67 |
stBlinkenMovie * BlinkenMovieNew( int height, int width, int channels, int maxval ) |
35 | 68 |
{ |
36 | 69 |
stBlinkenMovie * pMovie; |
... | ... |
@@ -603,7 +636,7 @@ stBlinkenMovie * BlinkenMovieLoadBlm( char * pFilename ) |
603 | 636 |
{ |
604 | 637 |
for( x = 0; ; x++ ) |
605 | 638 |
{ |
606 |
- BlinkenFrameSetPixel( pFrame, y, x, 0, pixel[0] == '1' ? 1 : 0 ); //set pixel |
|
639 |
+ BlinkenFrameSetPixel( pFrame, y, x, 0, (unsigned char)(pixel[0] == '1' ? 1 : 0) ); //set pixel |
|
607 | 640 |
if( fscanf( pFile, "%1[01]", pixel ) != 1 ) //read next pixel |
608 | 641 |
break; |
609 | 642 |
} |
... | ... |
@@ -1407,7 +1440,7 @@ int BlinkenMovieSave( stBlinkenMovie * pMovie, char * pFilename ) |
1407 | 1440 |
return -1; |
1408 | 1441 |
} |
1409 | 1442 |
|
1410 |
-void BlinkenMovieSend( stBlinkenMovie * pMovie, int udpSocket, etBlinkenProto proto ) |
|
1443 |
+void BlinkenMovieSend( stBlinkenMovie * pMovie, SOCKET udpSocket, etBlinkenProto proto ) |
|
1411 | 1444 |
//udp socket must be "connected" |
1412 | 1445 |
{ |
1413 | 1446 |
int i, len; |
... | ... |
@@ -1418,11 +1451,11 @@ void BlinkenMovieSend( stBlinkenMovie * pMovie, int udpSocket, etBlinkenProto pr |
1418 | 1451 |
len = BlinkenFrameToNetwork( pMovie->ppFrames[i], proto, buffer, sizeof( buffer ) ); |
1419 | 1452 |
if( len > 0 ) |
1420 | 1453 |
send( udpSocket, buffer, len, 0 ); |
1421 |
- usleep( BlinkenFrameGetDuration( pMovie->ppFrames[i] ) * 1000 ); |
|
1454 |
+ msleep( BlinkenFrameGetDuration( pMovie->ppFrames[i] ) ); |
|
1422 | 1455 |
} |
1423 | 1456 |
} |
1424 | 1457 |
|
1425 |
-stBlinkenMovie * BlinkenMovieReceive( int udpSocket, int timeout, etBlinkenProto * pProto ) |
|
1458 |
+stBlinkenMovie * BlinkenMovieReceive( SOCKET udpSocket, int timeout, etBlinkenProto * pProto ) |
|
1426 | 1459 |
//udp socket must be "bound" and should be "connected" |
1427 | 1460 |
//after timeout ms of no reception, the movie is considered to be complete |
1428 | 1461 |
//returns protocol in *pProto if pProto not NULL |
... | ... |
@@ -1431,7 +1464,8 @@ stBlinkenMovie * BlinkenMovieReceive( int udpSocket, int timeout, etBlinkenProto |
1431 | 1464 |
stBlinkenFrame * pLastFrame, * pFrame; |
1432 | 1465 |
etBlinkenProto proto, p; |
1433 | 1466 |
fd_set readFds; |
1434 |
- struct timeval timeo, lastTime, curTime; |
|
1467 |
+ struct timeval timeo; |
|
1468 |
+ unsigned int lastTime, curTime; |
|
1435 | 1469 |
char buffer[65536]; //64kB is more than maximum UDP size |
1436 | 1470 |
int len; |
1437 | 1471 |
|
... | ... |
@@ -1443,6 +1477,7 @@ stBlinkenMovie * BlinkenMovieReceive( int udpSocket, int timeout, etBlinkenProto |
1443 | 1477 |
pMovie = NULL; |
1444 | 1478 |
proto = BlinkenProtoNone; |
1445 | 1479 |
pLastFrame = NULL; |
1480 |
+ lastTime = get_ms( ); |
|
1446 | 1481 |
for( ; ; ) |
1447 | 1482 |
{ |
1448 | 1483 |
//wait for next frame |
... | ... |
@@ -1490,11 +1525,10 @@ stBlinkenMovie * BlinkenMovieReceive( int udpSocket, int timeout, etBlinkenProto |
1490 | 1525 |
if( BlinkenMovieAppendFrame( pMovie, pFrame ) == 0 ) |
1491 | 1526 |
{ |
1492 | 1527 |
//get current time |
1493 |
- gettimeofday( &curTime, NULL ); |
|
1528 |
+ curTime = get_ms( ); |
|
1494 | 1529 |
//set duration of last frame |
1495 | 1530 |
if( pLastFrame != NULL ) |
1496 |
- BlinkenFrameSetDuration( pLastFrame, (curTime.tv_sec - lastTime.tv_sec) * 1000 |
|
1497 |
- + (curTime.tv_usec - lastTime.tv_usec) / 1000 ); |
|
1531 |
+ BlinkenFrameSetDuration( pLastFrame, curTime - lastTime ); |
|
1498 | 1532 |
//remember this frame as last frame appended to movie |
1499 | 1533 |
pLastFrame = pFrame; |
1500 | 1534 |
pFrame = NULL; //do not free this frame (it was appended) |
... | ... |
@@ -1509,11 +1543,10 @@ stBlinkenMovie * BlinkenMovieReceive( int udpSocket, int timeout, etBlinkenProto |
1509 | 1543 |
} //for( ; ; ) |
1510 | 1544 |
|
1511 | 1545 |
//get current time |
1512 |
- gettimeofday( &curTime, NULL ); |
|
1546 |
+ curTime = get_ms( ); |
|
1513 | 1547 |
//set duration of last frame |
1514 | 1548 |
if( pLastFrame != NULL ) |
1515 |
- BlinkenFrameSetDuration( pLastFrame, (curTime.tv_sec - lastTime.tv_sec) * 1000 |
|
1516 |
- + (curTime.tv_usec - lastTime.tv_usec) / 1000 ); |
|
1549 |
+ BlinkenFrameSetDuration( pLastFrame, curTime - lastTime ); |
|
1517 | 1550 |
|
1518 | 1551 |
//return protocol |
1519 | 1552 |
if( pProto != NULL ) |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
/* BlinkenLib |
2 |
- * version 0.5.1 date 2005-12-14 |
|
3 |
- * Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info> |
|
2 |
+ * version 0.5.2 date 2006-05-10 |
|
3 |
+ * Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info> |
|
4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
5 | 5 |
* a blinkenarea.org project |
6 | 6 |
*/ |
... | ... |
@@ -10,6 +10,13 @@ |
10 | 10 |
|
11 | 11 |
#include "BlinkenFrame.h" |
12 | 12 |
|
13 |
+#ifdef WIN32 |
|
14 |
+#include <winsock2.h> |
|
15 |
+#else |
|
16 |
+#define SOCKET int |
|
17 |
+#define INVALID_SOCKET -1 |
|
18 |
+#endif |
|
19 |
+ |
|
13 | 20 |
typedef struct sBlinkenMovie stBlinkenMovie; |
14 | 21 |
|
15 | 22 |
stBlinkenMovie * BlinkenMovieNew( int height, int width, int channels, int maxval ); |
... | ... |
@@ -58,10 +65,10 @@ int BlinkenMovieSaveBml( stBlinkenMovie * pMovie, char * pFilename ); |
58 | 65 |
int BlinkenMovieSaveBbm( stBlinkenMovie * pMovie, char * pFilename ); |
59 | 66 |
int BlinkenMovieSave( stBlinkenMovie * pMovie, char * pFilename ); |
60 | 67 |
|
61 |
-void BlinkenMovieSend( stBlinkenMovie * pMovie, int udpSocket, etBlinkenProto proto ); |
|
68 |
+void BlinkenMovieSend( stBlinkenMovie * pMovie, SOCKET udpSocket, etBlinkenProto proto ); |
|
62 | 69 |
//udp socket must be "connected" |
63 | 70 |
|
64 |
-stBlinkenMovie * BlinkenMovieReceive( int udpSocket, int timeout, etBlinkenProto * pProto ); |
|
71 |
+stBlinkenMovie * BlinkenMovieReceive( SOCKET udpSocket, int timeout, etBlinkenProto * pProto ); |
|
65 | 72 |
//udp socket must be "bound" and should be "connected" |
66 | 73 |
//after timeout ms of no reception, the movie is considered to be complete |
67 | 74 |
//returns protocol in *pProto if pProto not NULL |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
/* BlinkenLib |
2 |
- * version 0.5.1 date 2005-12-14 |
|
3 |
- * Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info> |
|
2 |
+ * version 0.5.2 date 2006-05-10 |
|
3 |
+ * Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info> |
|
4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
5 | 5 |
* a blinkenarea.org project |
6 | 6 |
*/ |
... | ... |
@@ -149,7 +149,7 @@ static int serial_settings_set( int fd, int settings ) |
149 | 149 |
//receive frames from socket and output them |
150 | 150 |
//dev_fd may be -1 for not doing anything with device |
151 | 151 |
//returns error code (not for device-errors, 0 for success) |
152 |
-static int recv_and_out( int udpSocket, int dev_fd, |
|
152 |
+static int recv_and_out( SOCKET udpSocket, int dev_fd, |
|
153 | 153 |
int * p_device_output_active, |
154 | 154 |
unsigned int format_change, |
155 | 155 |
unsigned int format_height, unsigned int format_width, |
... | ... |
@@ -271,9 +271,9 @@ static int recv_and_out( int udpSocket, int dev_fd, |
271 | 271 |
if( use_msecs ) |
272 | 272 |
{ |
273 | 273 |
//get time elapsed |
274 |
- gettimeofday( &end, NULL ); |
|
275 | 274 |
int sec, usec; |
276 | 275 |
unsigned int msec; |
276 |
+ gettimeofday( &end, NULL ); |
|
277 | 277 |
sec = end.tv_sec - start.tv_sec; |
278 | 278 |
usec = end.tv_usec - start.tv_usec; |
279 | 279 |
if( usec < 0 ) |
... | ... |
@@ -299,7 +299,7 @@ static int recv_and_out( int udpSocket, int dev_fd, |
299 | 299 |
|
300 | 300 |
//open device and output frames |
301 | 301 |
//returns error code (not for device-errors, 0 for success) |
302 |
-static int open_and_output( int udpSocket, char * device, |
|
302 |
+static int open_and_output( SOCKET udpSocket, char * device, |
|
303 | 303 |
int * p_device_output_active, |
304 | 304 |
int serial_settings_change, int serial_settings, |
305 | 305 |
unsigned int format_change, |
... | ... |
@@ -347,7 +347,7 @@ static int open_and_output( int udpSocket, char * device, |
347 | 347 |
|
348 | 348 |
//open device and output frames in a loop |
349 | 349 |
//returns error code (not for device-errors, 0 for success) |
350 |
-static int open_and_output_loop( int udpSocket, char * device, |
|
350 |
+static int open_and_output_loop( SOCKET udpSocket, char * device, |
|
351 | 351 |
int serial_settings_change, int serial_settings, |
352 | 352 |
int reopen_device, unsigned int reopen_device_ms, |
353 | 353 |
unsigned int format_change, |
... | ... |
@@ -396,7 +396,8 @@ static int open_and_output_loop( int udpSocket, char * device, |
396 | 396 |
|
397 | 397 |
int main( int argCnt, char * * args ) |
398 | 398 |
{ |
399 |
- int i, udpSocket, bound, serial_settings; |
|
399 |
+ int i, bound, serial_settings; |
|
400 |
+ SOCKET udpSocket; |
|
400 | 401 |
etBlinkenProto proto; |
401 | 402 |
unsigned int format_change, format_height, format_width, format_channels, format_colors; |
402 | 403 |
unsigned int height, width, channels, colors, reopen_device_ms; |
... | ... |
@@ -408,8 +409,8 @@ int main( int argCnt, char * * args ) |
408 | 409 |
|
409 | 410 |
//print info |
410 | 411 |
printf( "BlinkenLib - BlinkenOutput\n" |
411 |
- "version 0.5.1 date 2005-12-14\n" |
|
412 |
- "Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info>\n" |
|
412 |
+ "version 0.5.2 date 2006-05-10\n" |
|
413 |
+ "Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info>\n" |
|
413 | 414 |
"Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n" |
414 | 415 |
"a blinkenarea.org project\n\n" ); |
415 | 416 |
|
... | ... |
@@ -440,7 +441,7 @@ int main( int argCnt, char * * args ) |
440 | 441 |
|
441 | 442 |
//create udp socket |
442 | 443 |
udpSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); |
443 |
- if( udpSocket == -1 ) |
|
444 |
+ if( udpSocket == INVALID_SOCKET ) |
|
444 | 445 |
{ |
445 | 446 |
printf( "cannot create UDP socket\n" ); |
446 | 447 |
return -1; |
... | ... |
@@ -0,0 +1,603 @@ |
1 |
+/* BlinkenLib |
|
2 |
+ * version 0.5.2 date 2006-05-10 |
|
3 |
+ * Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info> |
|
4 |
+ * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
5 |
+ * a blinkenarea.org project |
|
6 |
+ */ |
|
7 |
+ |
|
8 |
+#include <fcntl.h> |
|
9 |
+#include <stdlib.h> |
|
10 |
+#include <stdio.h> |
|
11 |
+#include <string.h> |
|
12 |
+#include <winsock2.h> |
|
13 |
+#include <windows.h> |
|
14 |
+ |
|
15 |
+#include "BlinkenLib.h" |
|
16 |
+ |
|
17 |
+//get serial settings from text |
|
18 |
+static int serial_settings_parse( char * str ) |
|
19 |
+{ |
|
20 |
+ int baud, data, stop; |
|
21 |
+ char parity; |
|
22 |
+ int set = 0; |
|
23 |
+ |
|
24 |
+ //split and parse settings string |
|
25 |
+ if( sscanf( str, "%i,%c,%i,%i", &baud, &parity, &data, &stop ) != 4 ) |
|
26 |
+ return 0; |
|
27 |
+ |
|
28 |
+ //baud rate |
|
29 |
+ if( baud != 300 && |
|
30 |
+ baud != 600 && |
|
31 |
+ baud != 1200 && |
|
32 |
+ baud != 2400 && |
|
33 |
+ baud != 4800 && |
|
34 |
+ baud != 9600 && |
|
35 |
+ baud != 19200 && |
|
36 |
+ baud != 38400 && |
|
37 |
+ baud != 57600 && |
|
38 |
+ baud != 115200 ) |
|
39 |
+ { |
|
40 |
+ printf( "illegal baudrate: %d\n", baud ); |
|
41 |
+ return 0; |
|
42 |
+ } |
|
43 |
+ |
|
44 |
+ //parity |
|
45 |
+ if( parity != 'n' && parity != 'N' && |
|
46 |
+ parity != 'e' && parity != 'E' && |
|
47 |
+ parity != 'o' && parity != 'O' ) |
|
48 |
+ { |
|
49 |
+ printf( "invalid parity: %c\n", parity ); |
|
50 |
+ return 0; |
|
51 |
+ } |
|
52 |
+ |
|
53 |
+ //data bits |
|
54 |
+ if( data != 5 && |
|
55 |
+ data != 6 && |
|
56 |
+ data != 7 && |
|
57 |
+ data != 8 ) |
|
58 |
+ { |
|
59 |
+ printf( "illegal number of data bits: %d\n", data ); |
|
60 |
+ return 0; |
|
61 |
+ } |
|
62 |
+ |
|
63 |
+ //stop bits |
|
64 |
+ if( stop != 1 && |
|
65 |
+ stop == 2 ) |
|
66 |
+ { |
|
67 |
+ printf( "illegal number of stop bits: %d\n", stop ); |
|
68 |
+ return 0; |
|
69 |
+ } |
|
70 |
+ |
|
71 |
+ //success |
|
72 |
+ return 1; |
|
73 |
+} |
|
74 |
+ |
|
75 |
+//set serial settings for fd |
|
76 |
+static int serial_settings_set( HANDLE hDev, char * settings ) |
|
77 |
+{ |
|
78 |
+ DCB PortDcb; |
|
79 |
+ COMMTIMEOUTS CommTimeouts; |
|
80 |
+ |
|
81 |
+ //set serial parameters |
|
82 |
+ if( ! GetCommState( hDev, &PortDcb ) ) |
|
83 |
+ { |
|
84 |
+ printf( "error getting device comm state: error %u\n", GetLastError( ) ); |
|
85 |
+ return 0; |
|
86 |
+ } |
|
87 |
+ if( ! BuildCommDCB( hDev, &PortDcb ) ) |
|
88 |
+ { |
|
89 |
+ printf( "error building comm state: error %u\n", GetLastError( ) ); |
|
90 |
+ return 0; |
|
91 |
+ } |
|
92 |
+ if( ! SetCommState( hDev, &PortDcb ) ) |
|
93 |
+ { |
|
94 |
+ printf( "error setting device comm state: error %u\n", GetLastError( ) ); |
|
95 |
+ return 0; |
|
96 |
+ } |
|
97 |
+ |
|
98 |
+ //set timeout parameters |
|
99 |
+ //maximum time between arrival of two characters: 10 ms |
|
100 |
+ //if this time elapses, read command will return even if buffer is not filled completely |
|
101 |
+ CommTimeouts.ReadIntervalTimeout = 10; |
|
102 |
+ //disable read timeouts |
|
103 |
+ CommTimeouts.ReadTotalTimeoutConstant = 0; |
|
104 |
+ CommTimeouts.ReadTotalTimeoutMultiplier = 0; |
|
105 |
+ //disable write timeouts |
|
106 |
+ CommTimeouts.WriteTotalTimeoutConstant = 0; |
|
107 |
+ CommTimeouts.WriteTotalTimeoutMultiplier = 0; |
|
108 |
+ if( ! SetCommTimeouts( hDev, &CommTimeouts ) ) |
|
109 |
+ { |
|
110 |
+ printf( "error setting device timeout parameters: error %u\n", GetLastError( ) ); |
|
111 |
+ return 0; |
|
112 |
+ } |
|
113 |
+ |
|
114 |
+ //success |
|
115 |
+ return 1; |
|
116 |
+} |
|
117 |
+ |
|
118 |
+//receive frames from socket and output them |
|
119 |
+//hDev may be INVALID_HANDLE_VALUE for not doing anything with device |
|
120 |
+//returns error code (not for device-errors, 0 for success) |
|
121 |
+static int recv_and_out( SOCKET udpSocket, HANDLE hDev, |
|
122 |
+ int * p_device_output_active, |
|
123 |
+ unsigned int format_change, |
|
124 |
+ unsigned int format_height, unsigned int format_width, |
|
125 |
+ unsigned int format_channels, unsigned int format_colors, |
|
126 |
+ etBlinkenProto proto, |
|
127 |
+ int use_msecs, unsigned int msecs, int is_serial_device ) |
|
128 |
+{ |
|
129 |
+ fd_set readFds, errFds; |
|
130 |
+ stBlinkenFrame * pFrame; |
|
131 |
+ char buffer[65536]; //64kB is more than maximum UDP size |
|
132 |
+ int len, dev_eof; |
|
133 |
+ struct timeval timeout, * p_timeout; |
|
134 |
+ DWORD DevWrLen, Err, start, end; |
|
135 |
+ COMSTAT ComStat; |
|
136 |
+ |
|
137 |
+ dev_eof = 0; |
|
138 |
+ for( ; ; ) |
|
139 |
+ { |
|
140 |
+ //wait for next frame |
|
141 |
+ FD_ZERO( &readFds ); |
|
142 |
+ FD_SET( udpSocket, &readFds ); |
|
143 |
+ FD_ZERO( &errFds ); |
|
144 |
+ FD_SET( udpSocket, &errFds ); |
|
145 |
+ if( use_msecs ) //timeout |
|
146 |
+ { |
|
147 |
+ start = GetTickCount( ); |
|
148 |
+ timeout.tv_sec = msecs / 1000; |
|
149 |
+ timeout.tv_usec = msecs % 1000 * 1000; |
|
150 |
+ p_timeout = &timeout; |
|
151 |
+ } |
|
152 |
+ else |
|
153 |
+ p_timeout = NULL; |
|
154 |
+ if( select( 0, &readFds, NULL, &errFds, p_timeout ) < 0 ) //error |
|
155 |
+ { |
|
156 |
+ printf( "error during select: %s\n", strerror( errno ) ); |
|
157 |
+ return -1; |
|
158 |
+ } |
|
159 |
+ |
|
160 |
+ //error on socket |
|
161 |
+ if( FD_ISSET( udpSocket, &errFds ) ) |
|
162 |
+ { |
|
163 |
+ printf( "error on socket\n" ); |
|
164 |
+ return -1; |
|
165 |
+ } |
|
166 |
+ |
|
167 |
+ //received frame |
|
168 |
+ if( FD_ISSET( udpSocket, &readFds ) ) |
|
169 |
+ { |
|
170 |
+ //fetch data |
|
171 |
+ len = recv( udpSocket, buffer, sizeof( buffer ), 0 ); |
|
172 |
+ if( len < 0 ) |
|
173 |
+ { |
|
174 |
+ printf( "could not read from socket\n" ); |
|
175 |
+ return -1; |
|
176 |
+ } |
|
177 |
+ if( len == 0 ) |
|
178 |
+ return -1; |
|
179 |
+ |
|
180 |
+ //get frame from data |
|
181 |
+ pFrame = BlinkenFrameFromNetwork( buffer, len, NULL ); |
|
182 |
+ if( pFrame != NULL ) |
|
183 |
+ { |
|
184 |
+ //change format |
|
185 |
+ if( format_change ) |
|
186 |
+ BlinkenFrameResize( pFrame, format_height, format_width, format_channels, format_colors - 1 ); |
|
187 |
+ |
|
188 |
+ //create output data from frame |
|
189 |
+ len = BlinkenFrameToNetwork( pFrame, proto, buffer, sizeof( buffer ) ); |
|
190 |
+ |
|
191 |
+ //free frame |
|
192 |
+ BlinkenFrameFree( pFrame ); |
|
193 |
+ |
|
194 |
+ //output data to device |
|
195 |
+ if( hDev != INVALID_HANDLE_VALUE && len > 0 ) |
|
196 |
+ { |
|
197 |
+ if( ! WriteFile( hDev, buffer, len, &DevWrLen, NULL ) || (int)DevWrLen != len ) |
|
198 |
+ { |
|
199 |
+ if( *p_device_output_active ) |
|
200 |
+ printf( "error writing to device: error %lu\n", GetLastError( ) ); |
|
201 |
+ break; |
|
202 |
+ } |
|
203 |
+ //message: output to device was restarted |
|
204 |
+ if( ! *p_device_output_active ) |
|
205 |
+ printf( "restarted output to device...\n" ); |
|
206 |
+ *p_device_output_active = 1; |
|
207 |
+ } |
|
208 |
+ } |
|
209 |
+ } |
|
210 |
+ |
|
211 |
+ //get state of serial device |
|
212 |
+ if( hDev != INVALID_HANDLE_VALUE && is_serial_device ) |
|
213 |
+ { |
|
214 |
+ ClearCommError( hDev, &Err, &ComStat ); |
|
215 |
+ //reception error |
|
216 |
+ if( Err & (CE_BREAK | CE_FRAME | CE_OVERRUN | CE_RXOVER | CE_RXPARITY) ) |
|
217 |
+ { |
|
218 |
+ if( *p_device_output_active ) |
|
219 |
+ printf( "error reading from device (comm err=%X)\n", Err ); |
|
220 |
+ break; |
|
221 |
+ } |
|
222 |
+ } |
|
223 |
+ |
|
224 |
+ //using time limit |
|
225 |
+ if( use_msecs ) |
|
226 |
+ { |
|
227 |
+ unsigned int msec; |
|
228 |
+ //get time elapsed |
|
229 |
+ end = GetTickCount( ); |
|
230 |
+ msec = end - start; |
|
231 |
+ //more than rest of timeout (or exact match) |
|
232 |
+ if( msec >= msecs ) |
|
233 |
+ break; |
|
234 |
+ msecs -= msec; |
|
235 |
+ } |
|
236 |
+ |
|
237 |
+ } //for( ; ; ) |
|
238 |
+ |
|
239 |
+ return 0; |
|
240 |
+} |
|
241 |
+ |
|
242 |
+//open device and output frames |
|
243 |
+//returns error code (not for device-errors, 0 for success) |
|
244 |
+static int open_and_output( SOCKET udpSocket, char * device, |
|
245 |
+ int * p_device_output_active, |
|
246 |
+ int serial_settings_change, char * serial_settings, |
|
247 |
+ unsigned int format_change, |
|
248 |
+ unsigned int format_height, unsigned int format_width, |
|
249 |
+ unsigned int format_channels, unsigned int format_colors, |
|
250 |
+ etBlinkenProto proto ) |
|
251 |
+{ |
|
252 |
+ HANDLE hDev; |
|
253 |
+ int err; |
|
254 |
+ |
|
255 |
+ //open device |
|
256 |
+ hDev = CreateFile( device, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL ); |
|
257 |
+ if( hDev == INVALID_HANDLE_VALUE ) |
|
258 |
+ { |
|
259 |
+ if( *p_device_output_active ) |
|
260 |
+ printf( "could not open \"%s\": error %u\n", device, GetLastError( ) ); |
|
261 |
+ return 0; |
|
262 |
+ } |
|
263 |
+ |
|
264 |
+ //setup serial port |
|
265 |
+ if( serial_settings_change ) |
|
266 |
+ { |
|
267 |
+ if( ! serial_settings_set( hDev, serial_settings ) ) |
|
268 |
+ { |
|
269 |
+ if( *p_device_output_active ) |
|
270 |
+ printf( "could not set serial port to \"%s\"\n", serial_settings ); |
|
271 |
+ CloseHandle( hDev ); |
|
272 |
+ return 0; |
|
273 |
+ } |
|
274 |
+ } |
|
275 |
+ |
|
276 |
+ //receive frames and output to device |
|
277 |
+ err = recv_and_out( udpSocket, hDev, p_device_output_active, |
|
278 |
+ format_change, format_height, format_width, format_channels, format_colors, |
|
279 |
+ proto, 0, 0, serial_settings_change ); |
|
280 |
+ |
|
281 |
+ //close device |
|
282 |
+ CloseHandle( hDev ); |
|
283 |
+ |
|
284 |
+ return err; |
|
285 |
+} |
|
286 |
+ |
|
287 |
+//open device and output frames in a loop |
|
288 |
+//returns error code (not for device-errors, 0 for success) |
|
289 |
+static int open_and_output_loop( SOCKET udpSocket, char * device, |
|
290 |
+ int serial_settings_change, char * serial_settings, |
|
291 |
+ int reopen_device, unsigned int reopen_device_ms, |
|
292 |
+ unsigned int format_change, |
|
293 |
+ unsigned int format_height, unsigned int format_width, |
|
294 |
+ unsigned int format_channels, unsigned int format_colors, |
|
295 |
+ etBlinkenProto proto ) |
|
296 |
+{ |
|
297 |
+ int device_output_active, err; |
|
298 |
+ |
|
299 |
+ printf( "receiving frames and outputting them to \"%s\"...\n", device ); |
|
300 |
+ device_output_active = 1; |
|
301 |
+ |
|
302 |
+ for( ; ; ) |
|
303 |
+ { |
|
304 |
+ |
|
305 |
+ //try to open device and output frames |
|
306 |
+ err = open_and_output( udpSocket, device, |
|
307 |
+ &device_output_active, |
|
308 |
+ serial_settings_change, serial_settings, |
|
309 |
+ format_change, format_height, format_width, format_channels, format_colors, |
|
310 |
+ proto ); |
|
311 |
+ if( err != 0 || ! reopen_device ) |
|
312 |
+ break; |
|
313 |
+ |
|
314 |
+ //output to device stopped |
|
315 |
+ if( device_output_active ) |
|
316 |
+ printf( "output to device stopped...\n" ); |
|
317 |
+ device_output_active = 0; |
|
318 |
+ |
|
319 |
+ //only fetch data from socket for a short time |
|
320 |
+ err = recv_and_out( udpSocket, INVALID_HANDLE_VALUE, &device_output_active, |
|
321 |
+ format_change, format_height, format_width, format_channels, format_colors, |
|
322 |
+ proto, 1, reopen_device_ms, serial_settings_change ); |
|
323 |
+ if( err != 0 ) |
|
324 |
+ break; |
|
325 |
+ |
|
326 |
+ } |
|
327 |
+ |
|
328 |
+ //output to device finshed |
|
329 |
+ if( device_output_active ) |
|
330 |
+ printf( "output to device finished...\n" ); |
|
331 |
+ device_output_active = 0; |
|
332 |
+ |
|
333 |
+ return err; |
|
334 |
+} |
|
335 |
+ |
|
336 |
+int main( int argCnt, char * * args ) |
|
337 |
+{ |
|
338 |
+ WSADATA WsaData; |
|
339 |
+ int i, bound; |
|
340 |
+ SOCKET udpSocket; |
|
341 |
+ char * serial_settings; |
|
342 |
+ etBlinkenProto proto; |
|
343 |
+ unsigned int format_change, format_height, format_width, format_channels, format_colors; |
|
344 |
+ unsigned int height, width, channels, colors, reopen_device_ms; |
|
345 |
+ int serial_settings_change, reopen_device, unblock; |
|
346 |
+ char txt[64]; |
|
347 |
+ unsigned short port; |
|
348 |
+ struct sockaddr_in addr; |
|
349 |
+ char * device; |
|
350 |
+ |
|
351 |
+ //print info |
|
352 |
+ printf( "BlinkenLib - BlinkenOutput\n" |
|
353 |
+ "version 0.5.2 date 2006-05-10\n" |
|
354 |
+ "Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info>\n" |
|
355 |
+ "Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n" |
|
356 |
+ "a blinkenarea.org project\n\n" ); |
|
357 |
+ |
|
358 |
+ //print syntax |
|
359 |
+ if( argCnt <= 1 ) |
|
360 |
+ { |
|
361 |
+ printf( "syntax: %s <parameter> [...]\n\n" |
|
362 |
+ "parameters:\n" |
|
363 |
+ " -l [<ip>:]<port>\n" |
|
364 |
+ " local address (defaults to 0.0.0.0:2323)\n" |
|
365 |
+ " must occur before -r, may only occur once\n" |
|
366 |
+ " -r <ip>[:<port>]\n" |
|
367 |
+ " remote addess (defaults to every remote address)\n" |
|
368 |
+ " -p [BLP|EBLP|MCUF]\n" |
|
369 |
+ " protocol to output frames in (defaults to MCUF)\n" |
|
370 |
+ " -f <width>x<height>-<channels>/<colors>\n" |
|
371 |
+ " format to output frames in (defaults to no change)\n" |
|
372 |
+ " -d <device>\n" |
|
373 |
+ " device to output frames to (defaults to \"NUL\")\n" |
|
374 |
+ " -s <baud-rate>,<parity>,<data-bits>,<stop-bits>\n" |
|
375 |
+ " settings to use for serial devices (defaults to no change)\n" |
|
376 |
+ " -o <milliseconds>\n" |
|
377 |
+ " reopen device after short time on error (defaults to not reopen)\n" |
|
378 |
+ "\n", |
|
379 |
+ args[0] ); |
|
380 |
+ return 0; |
|
381 |
+ } |
|
382 |
+ |
|
383 |
+ WSAStartup( 0x0101, &WsaData ); |
|
384 |
+ |
|
385 |
+ //create udp socket |
|
386 |
+ udpSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); |
|
387 |
+ if( udpSocket == INVALID_SOCKET ) |
|
388 |
+ { |
|
389 |
+ printf( "cannot create UDP socket: error %lu\n", WSAGetLastError( ) ); |
|
390 |
+ WSACleanup( ); |
|
391 |
+ return -1; |
|
392 |
+ } |
|
393 |
+ bound = 0; |
|
394 |
+ |
|
395 |
+ //unblock udp socket |
|
396 |
+ unblock = 1; |
|
397 |
+ if( ioctlsocket( udpSocket, FIONBIO, &unblock ) == SOCKET_ERROR ) |
|
398 |
+ { |
|
399 |
+ printf( "cannot unblock UDP socket: error %lu\n", WSAGetLastError( ) ); |
|
400 |
+ closesocket( udpSocket ); |
|
401 |
+ WSACleanup( ); |
|
402 |
+ return -1; |
|
403 |
+ } |
|
404 |
+ |
|
405 |
+ //process parameters |
|
406 |
+ proto = BlinkenProtoMcuf; |
|
407 |
+ format_change = 0; |
|
408 |
+ format_height = 0; |
|
409 |
+ format_width = 0; |
|
410 |
+ format_channels = 0; |
|
411 |
+ format_colors = 0; |
|
412 |
+ device = "NUL"; |
|
413 |
+ serial_settings_change = 0; |
|
414 |
+ reopen_device = 0; |
|
415 |
+ for( i = 1; i < argCnt; i++ ) |
|
416 |
+ { |
|
417 |
+ |
|
418 |
+ //local address |
|
419 |
+ if( strcmp( args[i], "-l" ) == 0 ) |
|
420 |
+ { |
|
421 |
+ if( i + 1 < argCnt ) |
|
422 |
+ { |
|
423 |
+ i++; |
|
424 |
+ if( sscanf( args[i], "%32[0-9.]:%hu", txt, &port ) == 2 ) |
|
425 |
+ { |
|
426 |
+ addr.sin_family = AF_INET; |
|
427 |
+ addr.sin_port = htons( port ); |
|
428 |
+ addr.sin_addr.s_addr = inet_addr( txt ); |
|
429 |
+ if( bind( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) |
|
430 |
+ printf( "could not set local address to \"%s\"\n", args[i] ); |
|
431 |
+ else |
|
432 |
+ bound = 1; |
|
433 |
+ } |
|
434 |
+ else if( sscanf( args[i], "%hu", &port ) == 1 ) |
|
435 |
+ { |
|
436 |
+ addr.sin_family = AF_INET; |
|
437 |
+ addr.sin_port = htons( port ); |
|
438 |
+ addr.sin_addr.s_addr = htonl( INADDR_ANY ); |
|
439 |
+ if( bind( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) |
|
440 |
+ printf( "could not set local address to \"%s\"\n", args[i] ); |
|
441 |
+ else |
|
442 |
+ bound = 1; |
|
443 |
+ } |
|
444 |
+ else |
|
445 |
+ printf( "invalid local address \"%s\"\n", args[i] ); |
|
446 |
+ } |
|
447 |
+ else |
|
448 |
+ printf( "missing local address for \"-l\"\n" ); |
|
449 |
+ } |
|
450 |
+ |
|
451 |
+ //remote address |
|
452 |
+ else if( strcmp( args[i], "-r" ) == 0 ) |
|
453 |
+ { |
|
454 |
+ if( i + 1 < argCnt ) |
|
455 |
+ { |
|
456 |
+ i++; |
|
457 |
+ if( sscanf( args[i], "%32[0-9.]:%hu", txt, &port ) == 2 ) |
|
458 |
+ { |
|
459 |
+ addr.sin_family = AF_INET; |
|
460 |
+ addr.sin_port = htons( port ); |
|
461 |
+ addr.sin_addr.s_addr = inet_addr( txt ); |
|
462 |
+ if( connect( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) |
|
463 |
+ printf( "could not set remote address to \"%s\"\n", args[i] ); |
|
464 |
+ } |
|
465 |
+ else if( sscanf( args[i], "%32[0-9.]", txt ) == 1 ) |
|
466 |
+ { |
|
467 |
+ addr.sin_family = AF_INET; |
|
468 |
+ addr.sin_port = htons( 23230 ); |
|
469 |
+ addr.sin_addr.s_addr = inet_addr( txt ); |
|
470 |
+ if( connect( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) |
|
471 |
+ printf( "could not set remote address to \"%s\"\n", args[i] ); |
|
472 |
+ } |
|
473 |
+ else |
|
474 |
+ printf( "invalid remote address \"%s\"\n", args[i] ); |
|
475 |
+ } |
|
476 |
+ else |
|
477 |
+ printf( "missing remote address for \"-r\"\n" ); |
|
478 |
+ } |
|
479 |
+ |
|
480 |
+ //protocol to output frames in |
|
481 |
+ else if( strcmp( args[i], "-p" ) == 0 ) |
|
482 |
+ { |
|
483 |
+ if( i + 1 < argCnt ) |
|
484 |
+ { |
|
485 |
+ i++; |
|
486 |
+ if( stricmp( args[i], "BLP" ) == 0 ) |
|
487 |
+ proto = BlinkenProtoBlp; |
|
488 |
+ else if( stricmp( args[i], "EBLP" ) == 0 ) |
|
489 |
+ proto = BlinkenProtoEblp; |
|
490 |
+ else if( stricmp( args[i], "MCUF" ) == 0 ) |
|
491 |
+ proto = BlinkenProtoMcuf; |
|
492 |
+ else |
|
493 |
+ printf( "unknown protocol \"%s\"\n", args[i] ); |
|
494 |
+ } |
|
495 |
+ else |
|
496 |
+ printf( "missing protocol for \"-p\"\n" ); |
|
497 |
+ } |
|
498 |
+ |
|
499 |
+ //format to output frames in |
|
500 |
+ else if( strcmp( args[i], "-f" ) == 0 ) |
|
501 |
+ { |
|
502 |
+ if( i + 1 < argCnt ) |
|
503 |
+ { |
|
504 |
+ i++; |
|
505 |
+ if( sscanf( args[i], "%ux%u-%u/%u", &width, &height, &channels, &colors ) == 4 && |
|
506 |
+ width > 0 && width < 1000 && height > 0 && height < 1000 && |
|
507 |
+ channels > 0 && channels < 20 && colors > 1 && colors <= 256 ) |
|
508 |
+ { |
|
509 |
+ format_change = 1; |
|
510 |
+ format_height = height; |
|
511 |
+ format_width = width; |
|
512 |
+ format_channels = channels; |
|
513 |
+ format_colors = colors; |
|
514 |
+ } |
|
515 |
+ else |
|
516 |
+ printf( "invalid frame format \"%s\"\n", args[i] ); |
|
517 |
+ } |
|
518 |
+ else |
|
519 |
+ printf( "missing frame format for \"-r\"\n" ); |
|
520 |
+ } |
|
521 |
+ |
|
522 |
+ //device to output frames to |
|
523 |
+ else if( strcmp( args[i], "-d" ) == 0 ) |
|
524 |
+ { |
|
525 |
+ if( i + 1 < argCnt ) |
|
526 |
+ { |
|
527 |
+ i++; |
|
528 |
+ device = args[i]; |
|
529 |
+ } |
|
530 |
+ else |
|
531 |
+ printf( "missing device name for \"-d\"\n" ); |
|
532 |
+ } |
|
533 |
+ |
|
534 |
+ //settings for serial output devices |
|
535 |
+ else if( strcmp( args[i], "-s" ) == 0 ) |
|
536 |
+ { |
|
537 |
+ if( i + 1 < argCnt ) |
|
538 |
+ { |
|
539 |
+ i++; |
|
540 |
+ if( serial_settings_parse( args[i] ) ) |
|
541 |
+ { |
|
542 |
+ serial_settings_change = 1; |
|
543 |
+ serial_settings = args[i]; |
|
544 |
+ } |
|
545 |
+ else |
|
546 |
+ printf( "invalid serial settings \"%s\"\n", args[i] ); |
|
547 |
+ } |
|
548 |
+ else |
|
549 |
+ printf( "missing serial settings for \"-s\"\n" ); |
|
550 |
+ } |
|
551 |
+ |
|
552 |
+ //reopen device on error after some time |
|
553 |
+ else if( strcmp( args[i], "-o" ) == 0 ) |
|
554 |
+ { |
|
555 |
+ if( i + 1 < argCnt ) |
|
556 |
+ { |
|
557 |
+ i++; |
|
558 |
+ if( sscanf( args[i], "%u", &reopen_device_ms ) == 1 && reopen_device_ms >= 1 ) |
|
559 |
+ reopen_device = 1; |
|
560 |
+ else |
|
561 |
+ printf( "invalid number of milliseconds \"%s\"\n", args[i] ); |
|
562 |
+ } |
|
563 |
+ else |
|
564 |
+ printf( "missing time for \"-o\"\n" ); |
|
565 |
+ } |
|
566 |
+ |
|
567 |
+ //unknown parameter |
|
568 |
+ else |
|
569 |
+ printf( "unknown parameter \"%s\", call without parameters to get help\n", args[i] ); |
|
570 |
+ |
|
571 |
+ } //for( i ... |
|
572 |
+ |
|
573 |
+ //try to bind if not bound |
|
574 |
+ if( ! bound ) |
|
575 |
+ { |
|
576 |
+ printf( "no local address to receive frames on,\n" |
|
577 |
+ " using default local address \"0.0.0.0:2323\"\n" ); |
|
578 |
+ addr.sin_family = AF_INET; |
|
579 |
+ addr.sin_port = htons( 2323 ); |
|
580 |
+ addr.sin_addr.s_addr = htonl( INADDR_ANY ); |
|
581 |
+ if( bind( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) == 0 ) |
|
582 |
+ bound = 1; |
|
583 |
+ else |
|
584 |
+ { |
|
585 |
+ printf( "could not set local address to \"0.0.0.0:2323\"\n" ); |
|
586 |
+ closesocket( udpSocket ); |
|
587 |
+ return -1; |
|
588 |
+ } |
|
589 |
+ } |
|
590 |
+ |
|
591 |
+ //open device and output frames in a loop |
|
592 |
+ open_and_output_loop( udpSocket, device, |
|
593 |
+ serial_settings_change, serial_settings, |
|
594 |
+ reopen_device, reopen_device_ms, |
|
595 |
+ format_change, format_height, format_width, format_channels, format_colors, |
|
596 |
+ proto ); |
|
597 |
+ |
|
598 |
+ //close socket |
|
599 |
+ closesocket( udpSocket ); |
|
600 |
+ |
|
601 |
+ WSACleanup( ); |
|
602 |
+ return 0; |
|
603 |
+} |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
/* BlinkenLib |
2 |
- * version 0.5.1 date 2005-12-14 |
|
3 |
- * Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info> |
|
2 |
+ * version 0.5.2 date 2006-05-10 |
|
3 |
+ * Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info> |
|
4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
5 | 5 |
* a blinkenarea.org project |
6 | 6 |
*/ |
... | ... |
@@ -8,17 +8,23 @@ |
8 | 8 |
#include <stdio.h> |
9 | 9 |
#include <stdlib.h> |
10 | 10 |
#include <string.h> |
11 |
+#ifdef WIN32 |
|
12 |
+#include <winsock2.h> |
|
13 |
+#define close closesocket |
|
14 |
+#else |
|
11 | 15 |
#include <unistd.h> |
12 | 16 |
#include <sys/types.h> |
13 | 17 |
#include <sys/socket.h> |
14 | 18 |
#include <netinet/in.h> |
15 | 19 |
#include <arpa/inet.h> |
20 |
+#endif |
|
16 | 21 |
|
17 | 22 |
#include "BlinkenLib.h" |
18 | 23 |
|
19 | 24 |
int main( int argCnt, char * * args ) |
20 | 25 |
{ |
21 |
- int i, udpSocket, bound, val, timeout; |
|
26 |
+ int i, bound, val, timeout; |
|
27 |
+ SOCKET udpSocket; |
|
22 | 28 |
char txt[64]; |
23 | 29 |
unsigned short port; |
24 | 30 |
struct sockaddr_in addr; |
... | ... |
@@ -26,8 +32,8 @@ int main( int argCnt, char * * args ) |
26 | 32 |
|
27 | 33 |
//print info |
28 | 34 |
printf( "BlinkenLib - BlinkenRecv\n" |
29 |
- "version 0.5.1 date 2005-12-14\n" |
|
30 |
- "Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info>\n" |
|
35 |
+ "version 0.5.2 date 2006-05-10\n" |
|
36 |
+ "Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info>\n" |
|
31 | 37 |
"Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n" |
32 | 38 |
"a blinkenarea.org project\n\n" ); |
33 | 39 |
|
... | ... |
@@ -49,11 +55,21 @@ int main( int argCnt, char * * args ) |
49 | 55 |
return 0; |
50 | 56 |
} |
51 | 57 |
|
58 |
+#ifdef WIN32 |
|
59 |
+ { |
|
60 |
+ WSADATA WsaData; |
|
61 |
+ WSAStartup( 0x0101, &WsaData ); |
|
62 |
+ } |
|
63 |
+#endif |
|
64 |
+ |
|
52 | 65 |
//create udp socket |
53 | 66 |
udpSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); |
54 |
- if( udpSocket == -1 ) |
|
67 |
+ if( udpSocket == INVALID_SOCKET ) |
|
55 | 68 |
{ |
56 | 69 |
printf( "cannot create UDP socket\n" ); |
70 |
+#ifdef WIN32 |
|
71 |
+ WSACleanup( ); |
|
72 |
+#endif |
|
57 | 73 |
return -1; |
58 | 74 |
} |
59 | 75 |
bound = 0; |
... | ... |
@@ -189,5 +205,8 @@ int main( int argCnt, char * * args ) |
189 | 205 |
//close socket |
190 | 206 |
close( udpSocket ); |
191 | 207 |
|
208 |
+#ifdef WIN32 |
|
209 |
+ WSACleanup( ); |
|
210 |
+#endif |
|
192 | 211 |
return 0; |
193 | 212 |
} |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
/* BlinkenLib |
2 |
- * version 0.5.1 date 2005-12-14 |
|
3 |
- * Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info> |
|
2 |
+ * version 0.5.2 date 2006-05-10 |
|
3 |
+ * Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info> |
|
4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
5 | 5 |
* a blinkenarea.org project |
6 | 6 |
*/ |
... | ... |
@@ -8,17 +8,24 @@ |
8 | 8 |
#include <stdio.h> |
9 | 9 |
#include <stdlib.h> |
10 | 10 |
#include <string.h> |
11 |
+#ifdef WIN32 |
|
12 |
+#include <winsock2.h> |
|
13 |
+#define close closesocket |
|
14 |
+#define strcasecmp stricmp |
|
15 |
+#else |
|
11 | 16 |
#include <unistd.h> |
12 | 17 |
#include <sys/types.h> |
13 | 18 |
#include <sys/socket.h> |
14 | 19 |
#include <netinet/in.h> |
15 | 20 |
#include <arpa/inet.h> |
21 |
+#endif |
|
16 | 22 |
|
17 | 23 |
#include "BlinkenLib.h" |
18 | 24 |
|
19 | 25 |
int main( int argCnt, char * * args ) |
20 | 26 |
{ |
21 |
- int i, udpSocket, connected; |
|
27 |
+ int i, connected; |
|
28 |
+ SOCKET udpSocket; |
|
22 | 29 |
etBlinkenProto proto; |
23 | 30 |
unsigned int send_cnt, loop_cnt, loop, ui; |
24 | 31 |
char txt[64]; |
... | ... |
@@ -28,8 +35,8 @@ int main( int argCnt, char * * args ) |
28 | 35 |
|
29 | 36 |
//print info |
30 | 37 |
printf( "BlinkenLib - BlinkenSend\n" |
31 |
- "version 0.5.1 date 2005-12-14\n" |
|
32 |
- "Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info>\n" |
|
38 |
+ "version 0.5.2 date 2006-05-10\n" |
|
39 |
+ "Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info>\n" |
|
33 | 40 |
"Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n" |
34 | 41 |
"a blinkenarea.org project\n\n" ); |
35 | 42 |
|
... | ... |
@@ -55,11 +62,21 @@ int main( int argCnt, char * * args ) |
55 | 62 |
return 0; |
56 | 63 |
} |
57 | 64 |
|
65 |
+#ifdef WIN32 |
|
66 |
+ { |
|
67 |
+ WSADATA WsaData; |
|
68 |
+ WSAStartup( 0x0101, &WsaData ); |
|
69 |
+ } |
|
70 |
+#endif |
|
71 |
+ |
|
58 | 72 |
//create udp socket |
59 | 73 |
udpSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); |
60 |
- if( udpSocket == -1 ) |
|
74 |
+ if( udpSocket == INVALID_SOCKET ) |
|
61 | 75 |
{ |
62 | 76 |
printf( "cannot create UDP socket\n" ); |
77 |
+#ifdef WIN32 |
|
78 |
+ WSACleanup( ); |
|
79 |
+#endif |
|
63 | 80 |
return -1; |
64 | 81 |
} |
65 | 82 |
|
... | ... |
@@ -245,5 +262,8 @@ int main( int argCnt, char * * args ) |
245 | 262 |
//close socket |
246 | 263 |
close( udpSocket ); |
247 | 264 |
|
265 |
+#ifdef WIN32 |
|
266 |
+ WSACleanup( ); |
|
267 |
+#endif |
|
248 | 268 |
return 0; |
249 | 269 |
} |
... | ... |
@@ -1,11 +1,16 @@ |
1 |
+0.5.2 2006-05-10 |
|
2 |
+---------------- |
|
3 |
+adaptions for Windows |
|
4 |
+windows version for BlinkenOutput |
|
5 |
+ |
|
1 | 6 |
0.5.1 2005-12-14 |
2 | 7 |
---------------- |
3 |
-added possibility to reopen device on errors |
|
8 |
+added possibility to reopen device on errors to BlinkenOutput |
|
4 | 9 |
|
5 | 10 |
0.5 2005-12-06 |
6 | 11 |
-------------- |
7 | 12 |
added BlinkenOutput to output streams to devices |
8 |
-removed no longer needed (since 0.4) malloc3D from Tools |
|
13 |
+removed malloc3D no longer needed (since 0.4) from Tools |
|
9 | 14 |
|
10 | 15 |
0.4.1 2005-12-05 |
11 | 16 |
---------------- |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
# BlinkenLib |
2 |
-# version 0.5.1 date 2005-12-14 |
|
3 |
-# Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info> |
|
2 |
+# version 0.5.2 date 2006-05-10 |
|
3 |
+# Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info> |
|
4 | 4 |
# Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
5 | 5 |
# a blinkenarea.org project |
6 | 6 |
|
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
/* BlinkenLib |
2 |
- * version 0.5.1 date 2005-12-14 |
|
3 |
- * Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info> |
|
2 |
+ * version 0.5.2 date 2006-05-10 |
|
3 |
+ * Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info> |
|
4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
5 | 5 |
* a blinkenarea.org project |
6 | 6 |
*/ |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
/* BlinkenLib |
2 |
- * version 0.5.1 date 2005-12-14 |
|
3 |
- * Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info> |
|
2 |
+ * version 0.5.2 date 2006-05-10 |
|
3 |
+ * Copyright 2004-2006 Stefan Schuermans <1stein@schuermans.info> |
|
4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
5 | 5 |
* a blinkenarea.org project |
6 | 6 |
*/ |
7 | 7 |