blob: 0784851ab163d41c4b58d586ecf918b3e0c80d74 (
plain)
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
|
/*
ArdOSC - OSC Library for Arduino.
-------- Lisence -----------------------------------------------------------
ArdOSC
The MIT License
Copyright (c) 2009 - 2010 recotana( http://recotana.com ) All right reserved
*/
#include <stdlib.h>
#include <string.h>
#include "OSCcommon.h"
#include "OSCDecoder.h"
int16_t OSCDecoder::decode( OSCMessage::OSCMessage *mes ,const uint8_t *recData ){
//=========== BIN -> OSC Address(String) Decode ===========
const uint8_t *packStartPtr=recData;
mes->setOSCAddress((char*)packStartPtr);
packStartPtr += mes->oscAdrPacSize;
//=========== BIN -> TypeTag (String) Decode ===========
mes->setTypeTags((char*)(packStartPtr+1));
packStartPtr += mes->typeTagPacSize;
//=========== BIN -> Auguments Decode ===========
if (mes->arguments!=NULL) free(mes->arguments);
mes->arguments=(void**)calloc(mes->argsNum, sizeof(void*));
mes->argsPacSize=0;
uint8_t *tmpPtr;
uint16_t tmpSize;
for (uint16_t i=0; i< mes->argsNum ; i++) {
switch (mes->typeTag[i]) {
case 'i':
tmpPtr=(uint8_t*)calloc(1, 4);
*(tmpPtr+3)=*(uint8_t*)packStartPtr++;
*(tmpPtr+2)=*(uint8_t*)packStartPtr++;
*(tmpPtr+1)=*(uint8_t*)packStartPtr++;
*tmpPtr=*(uint8_t*)packStartPtr++;
mes->arguments[i]=(uint32_t*)tmpPtr;
mes->argsPacSize += 4;
break;
#ifdef _USE_FLOAT_
case 'f':
tmpPtr=(uint8_t*)calloc(1, 4);
*(tmpPtr+3)=*(uint8_t*)packStartPtr++;
*(tmpPtr+2)=*(uint8_t*)packStartPtr++;
*(tmpPtr+1)=*(uint8_t*)packStartPtr++;
*tmpPtr=*(uint8_t*)packStartPtr++;
mes->arguments[i]=(float*)tmpPtr;
mes->argsPacSize += 4;
break;
#endif
#ifdef _USE_STRING_
case 's':
tmpSize=strlen((char*)packStartPtr);
if(tmpSize > kMaxStringCharactor){
DBG_LOGLN("decode max str err");
return 1;
}
tmpPtr=(uint8_t*)calloc(tmpSize+1, 1);
strcpy((char*)tmpPtr,(char*)packStartPtr);
mes->arguments[i]=tmpPtr;
tmpSize = mes->getPackSize(tmpSize);
packStartPtr += tmpSize;
mes->argsPacSize += tmpSize;
break;
#endif
}
}
return 0;
}
|