Skip to content

Commit 89c1a70

Browse files
committed
bytestreamToUMP.h now has a dumpSysex7State. If a Start Sysex is provided before the end of another sysex it will dump the current sysex as UMP and then restart.
umpProcessor.cpp now sets the value of System Messages regardless of type Moved tests into their own directory
1 parent a82e800 commit 89c1a70

File tree

5 files changed

+167
-5
lines changed

5 files changed

+167
-5
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ dirs:
1111
mkdir -p build
1212

1313
tests:
14-
g++ $(OPTS) -I . -I ./include -o tests $(SOURCES) tests.cpp
15-
./tests
14+
g++ $(OPTS) -I . -I ./include -o test $(SOURCES) tests/tests.cpp
15+
./test
1616

1717
build/%.o: src/%.cpp
1818
g++ $(OPTS) -I . -I ./include \
@@ -23,4 +23,4 @@ midi2: $(OBJECTS)
2323

2424
clean:
2525
rm -rf build
26-
rm tests
26+
rm test

include/bytestreamToUMP.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,24 @@ class bytestreamToUMP{
114114
}
115115
return mess;
116116
}
117+
118+
void dumpSysex7State(bool reset) {
119+
if (sysex7State > 0 && sysex7Pos > 0) {
120+
//Then dump current bytes
121+
umpMess[writeIndex] = ((UMP_SYSEX7 << 4) + defaultGroup + 0L) << 24;
122+
umpMess[writeIndex] += (sysex7State + 0L) << 20;
123+
umpMess[writeIndex] += ((sysex7Pos + 0L) << 16);
124+
umpMess[writeIndex] += (sysex[0] << 8) + sysex[1];
125+
increaseWrite();
126+
umpMess[writeIndex] = ((sysex[2] + 0L) << 24) + ((sysex[3] + 0L)<< 16) + (sysex[4] << 8) + sysex[5] + 0L;
127+
increaseWrite();
128+
M2Utils::clear(sysex, 0, sizeof(sysex));
129+
if (sysex7State==1)sysex7State=2;
130+
}
131+
132+
if (reset)sysex7State = 1;
133+
sysex7Pos = 0;
134+
}
117135

118136
void bytestreamParse(uint8_t midi1Byte){
119137
if (midi1Byte == TUNEREQUEST
@@ -132,8 +150,7 @@ class bytestreamToUMP{
132150
d0 = midi1Byte;
133151
d1 = 255;
134152
if (midi1Byte == SYSEX_START){
135-
sysex7State = 1;
136-
sysex7Pos = 0;
153+
dumpSysex7State(true);
137154
}
138155
else if (midi1Byte == SYSEX_STOP){
139156
umpMess[writeIndex] = ((UMP_SYSEX7 << 4) + defaultGroup + 0L) << 24;

src/umpProcessor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void umpProcessor::processUMP(uint32_t UMP){
6161
systemMessage(mess);
6262
break;
6363
default:
64+
mess.value = umpMess[0] & 0xFFFF;
6465
systemMessage(mess);
6566
break;
6667
}

tests/testbadsysex.cpp

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
//
2+
// Created by andrew on 3/05/24.
3+
//
4+
5+
#include "include/bytestreamToUMP.h"
6+
#include <cstdio>
7+
8+
#include "umpToMIDI2Protocol.h"
9+
10+
bytestreamToUMP BS2UMP;
11+
12+
13+
int testPassed = 0;
14+
int testFailed = 0;
15+
16+
void passFail (uint32_t v1, uint32_t v2)
17+
{
18+
if(v1 == v2)
19+
{
20+
printf(".");
21+
testPassed++;
22+
}else
23+
{
24+
printf(" fail %#08x != %#08x ", v1, v2);
25+
testFailed++;
26+
}
27+
}
28+
29+
void testRun_bsToUmp(const char* heading, uint8_t *bytes, int btyelength, uint32_t * testCheck, int outlength)
30+
{
31+
va_list args;
32+
vprintf (heading, args);
33+
34+
int testCounter = 0;
35+
36+
for(int i=0; i<btyelength; i++){
37+
if(bytes[i] == 0xFF){
38+
BS2UMP.dumpSysex7State(false);
39+
}else{
40+
BS2UMP.bytestreamParse(bytes[i]);
41+
}
42+
while(BS2UMP.availableUMP()){
43+
uint32_t ump = BS2UMP.readUMP();
44+
//ump contains a ump 32 bit value. UMP messages that have 64bit will produce 2 UMP words
45+
passFail (ump, testCheck[testCounter++]);
46+
47+
}
48+
}
49+
printf(" length :");passFail (outlength, testCounter);
50+
printf("\n");
51+
}
52+
53+
54+
55+
56+
57+
void testRun_umpToump(const char* heading, uint32_t * in, int inlength, uint32_t * out)
58+
{
59+
va_list args;
60+
vprintf (heading, args);
61+
for(int i=0; i<inlength; i++){
62+
passFail (in[i], out[i]);
63+
}
64+
printf("\n");
65+
}
66+
67+
int main(){
68+
printf("Starting Tests...\n");
69+
70+
//******** ByteSteam to UMP ***************
71+
printf("ByteSteam to UMP \n");
72+
uint8_t bytes1[] = {0xf0, 0x11 ,0x22 ,0x33, 0xf0, 0x44, 0x55, 0xf7};
73+
uint32_t tests1[] = {0x30131122, 0x33000000, 0x30024455, 0x00000000};
74+
75+
testRun_bsToUmp(" Bad Sysex 1: ", bytes1, 8, tests1,4);
76+
77+
printf("ByteSteam to UMP \n");
78+
uint8_t bytes2[] = {0xf0, 0x10 ,0x11 ,0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0xFF/*this forces a dump*/, 0x18, 0x19, 0x1A, 0xf7};
79+
uint32_t tests2[] = {0x30161011, 0x12131415, 0x30221617, 0x00000000,0x30331819, 0x1A000000 };
80+
81+
testRun_bsToUmp(" Sysex w/Dump: ", bytes2, 14, tests2,6);
82+
83+
uint8_t bytes4[] = {0xF0, 0x7E, 0x7F, 0x0D, 0x70, 0x02, 0x4B, 0x60, 0x7A, 0x73, 0x7F, 0x7F, 0x7F, 0x7F, 0x7D,
84+
0x00 , 0x00, 0x00 , 0x00, 0x01 , 0x00, 0x00 , 0x00 , 0x03 , 0x00, 0x00, 0x00 , 0x10 , 0x00 , 0x00, 0x00, 0xF7};
85+
uint32_t tests4[] = {
86+
0x30167e7f, 0x0d70024b,
87+
0x3026607a, 0x737f7f7f,
88+
0x30267f7d, 0x00000000,
89+
0x30260100,0x00000300,
90+
0x30360000,0x10000000
91+
};
92+
testRun_bsToUmp(" Test 4 Sysex : ", bytes4, 32, tests4,10);
93+
94+
95+
96+
uint8_t bytesSyesex[] = {
97+
0xf0, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e,0x1d, 0x1f, 0xf7,
98+
0xf0, 0x2a, 0x2b, 0x2c, 0x2d, 0x2f, 0x3a, 0x3b,
99+
0xf8,
100+
0x3c, 0x3d, 0x3e, 0x3f, 0xf7,
101+
0xf0, 0x4a, 0x4b, 0x4c, 0x4d, 0x4f, 0xf7,
102+
103+
0xf0, 0x5a, 0x5b,
104+
0xf8,
105+
0x5c, 0x5d, 0xf7,
106+
0xf0, 0x6a, 0x6b, 0x6c, 0xf7,
107+
0xf0, 0x7a, 0x7b, 0xf7,
108+
0xf8,
109+
0xf0, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
110+
0xf8,
111+
0x1a, 0x1b, 0x1c, 0x1d,
112+
0xf8,
113+
0x1e,0x1d, 0x1f, 0xf7
114+
115+
};
116+
117+
uint32_t testsSysex2[] = {
118+
0x30160a0b, 0x0c0d0e0f,
119+
0x30261a1b, 0x1c1d1e1d,
120+
0x30311f00, 0x000000,
121+
0x30162a2b, 0x2c2d2f3a,
122+
0x10f80000,
123+
0x30353b3c, 0x3d3e3f00,
124+
0x30054a4b, 0x4c4d4f00,
125+
0x10f80000,
126+
0x30045a5b, 0x5c5d0000,
127+
0x30036a6b, 0x6c000000,
128+
0x30027a7b, 0x00000000,
129+
0x10f80000,
130+
0x10f80000, //This is slightly out of order because otherwise of the way the parser handles end of sysex
131+
0x30160a0b, 0x0c0d0e0f,
132+
0x10f80000,
133+
0x30261a1b, 0x1c1d1e1d,
134+
0x30311f00, 0x000000
135+
};
136+
137+
testRun_bsToUmp(" Test 11 sysex 2 w/Timing Clock : ", bytesSyesex, 70, testsSysex2,29);
138+
139+
140+
141+
///****************************
142+
printf("Tests Passed: %d Failed : %d\n",testPassed, testFailed);
143+
144+
}
File renamed without changes.

0 commit comments

Comments
 (0)