Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daniel/duo/unserialize harden #224

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3af51cc
testing changes
Unreal-Dan Apr 11, 2024
868506c
some test changes
Unreal-Dan Apr 11, 2024
721dd74
don't need this
Unreal-Dan Apr 11, 2024
e497c5c
more stuff
Unreal-Dan Apr 12, 2024
24d8742
more crap
Unreal-Dan Apr 12, 2024
e46ebc1
more work
Unreal-Dan Apr 16, 2024
ade0f6e
makefile adjustments
Unreal-Dan Apr 19, 2024
5db153f
flash storage kinda works
Unreal-Dan Apr 19, 2024
9cd94c3
storage changes
Unreal-Dan Apr 20, 2024
d1786db
Merge branch 'daniel/duo/storage_slots' into daniel/duo/unserialize_h…
Unreal-Dan Apr 20, 2024
00e6486
lots of changes
Unreal-Dan Apr 20, 2024
3fb9138
fixes
Unreal-Dan Apr 20, 2024
c34316c
fixes
Unreal-Dan Apr 20, 2024
2b75deb
fixes
Unreal-Dan Apr 20, 2024
3ca27e9
fixes
Unreal-Dan Apr 20, 2024
8ba99a9
fixes
Unreal-Dan Apr 20, 2024
015b816
fixes
Unreal-Dan Apr 20, 2024
bca5ed8
fixes
Unreal-Dan Apr 20, 2024
909c739
fixes
Unreal-Dan Apr 20, 2024
54351ef
fixes
Unreal-Dan Apr 20, 2024
1b24754
fixes
Unreal-Dan Apr 20, 2024
9930749
fixes
Unreal-Dan Apr 20, 2024
728bb79
fixes
Unreal-Dan Apr 20, 2024
f5726ea
fixes
Unreal-Dan Apr 20, 2024
dd579c7
8 modes for the lols
Unreal-Dan Apr 20, 2024
1c313e0
fixed auto cycler in randomizer
Unreal-Dan Apr 20, 2024
d2ad36a
minor fix
Unreal-Dan Apr 20, 2024
3d9ec28
fix to storage on desktop and auto cycle disable
Unreal-Dan Apr 20, 2024
52ce052
fix for linux storage code
Unreal-Dan Apr 20, 2024
a7a13d8
fixed up tests and autocycle
Unreal-Dan Apr 20, 2024
7238cea
fixed tests
Unreal-Dan Apr 20, 2024
6acb6d9
don't need this
Unreal-Dan Apr 20, 2024
fbe4eda
don't need this
Unreal-Dan Apr 20, 2024
eec9c3f
adjustments
Unreal-Dan Apr 21, 2024
85bda45
fixes
Unreal-Dan Apr 21, 2024
8d4512b
Merge branch 'duo' into daniel/duo/unserialize_harden
Unreal-Dan Apr 26, 2024
b69bfca
added serialize hardening too
Unreal-Dan Apr 26, 2024
45a58aa
restored modesharing and serialize unsafety
Unreal-Dan Apr 26, 2024
98912a0
minor fix
Unreal-Dan Apr 27, 2024
4afaedd
adjusted test list with q's
Unreal-Dan Apr 27, 2024
96a33ff
fixed test lits and added python to regen
Unreal-Dan Apr 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,31 @@ CPU_SPEED = 10000000L
# the port for serial upload
SERIAL_PORT = COM11

# whether eeprom is erased on flash (must write this fuse first to take effect)
SAVE_EEPROM = 1
FUSE0 = 0b00000000
FUSE2 = 0x02
FUSE5 = 0b1100010$(SAVE_EEPROM)
FUSE6 = 0x04

# WDTCFG { PERIOD=OFF, WINDOW=OFF }
WDTCFG = 0b00000000
# BODCFG { SLEEP=DIS, ACTIVE=DIS, SAMPFREQ=1KHZ, LVL=BODLEVEL0 }
BODCFG = 0x00
# OSCCFG { FREQSEL=20mhz, OSCLOCK=CLEAR }
OSCCFG = 0x02
# RESERVED
#FUSE3 = 0x00
# TCD0CFG { CMPA=CLEAR, CMPB=CLEAR, CMPC=CLEAR, CMPD=CLEAR, CMPAEN=CLEAR, CPMCEN=CLEAR, CMPDEN=CLEAR }
TCD0CFG = 0x00
# SYSCFG0
SYSCFG0 = 0b1100010$(SAVE_EEPROM)
# SYSCFG1 { SUT=64ms }
SYSCFG1 = 0x07
# fuse7 = APPEND
FUSE7 = 0x00
APPEND = 0x00
# fuse8 = BOOTEND
FUSE8 = 0x7e
# This controls the amount of storage for modes at the end of the flash memory,
# it is the boundary for the segment that can be rewritten by the program, 0x7e
# means 0x7e00/0x8000 bytes are program and 0x200 bytes are reserved for flash
# storage of modes, this does not include the eeprom.
BOOTEND = 0x7e

CFLAGS = -g \
-Os \
Expand Down Expand Up @@ -107,7 +123,7 @@ all: $(TARGET).hex
$(OBJDUMP) --disassemble --source --line-numbers --demangle --section=.text $(TARGET).elf > $(TARGET).lst
$(NM) --numeric-sort --line-numbers --demangle --print-size --format=s $(TARGET).elf > $(TARGET).map
chmod +x avrsize.sh
./avrsize.sh $(TARGET).elf
./avrsize.sh $(TARGET).elf $(BOOTEND)00

$(TARGET).hex: $(TARGET).elf
$(OBJCOPY) -O binary -R .eeprom $(TARGET).elf $(TARGET).bin
Expand All @@ -124,11 +140,21 @@ $(TARGET).elf: $(OBJS)
$(CC) $(CFLAGS) -c $< -o $@

upload: $(TARGET).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -Ufuse0:w:$(FUSE0):m -Ufuse2:w:$(FUSE2):m -Ufuse5:w:$(FUSE5):m -Ufuse6:w:$(FUSE6):m -Ufuse7:w:$(FUSE7):m -Ufuse8:w:$(FUSE8):m -Uflash:w:$(TARGET).hex:i
$(AVRDUDE) $(AVRDUDE_FLAGS) \
-Ufuse0:w:$(WDTCFG):m \
-Ufuse1:w:$(BODCFG):m \
-Ufuse2:w:$(OSCCFG):m \
-Ufuse4:w:$(TCD0CFG):m \
-Ufuse5:w:$(SYSCFG0):m \
-Ufuse6:w:$(SYSCFG1):m \
-Ufuse7:w:$(APPEND):m \
-Ufuse8:w:$(BOOTEND):m \
-Uflash:w:$(TARGET).hex:i

# upload via SerialUPDI
serial: $(TARGET).hex
$(PYTHON) -u $(PYPROG) -t uart -u $(SERIAL_PORT) -b 921600 -d $(AVRDUDE_CHIP) --fuses 0:$(FUSE0) 2:$(FUSE2) 5:$(FUSE5) 6:$(FUSE6) 7:$(FUSE7) 8:$(FUSE8) -f $< -a write -v
$(PYTHON) -u $(PYPROG) -t uart -u $(SERIAL_PORT) -b 921600 -d $(AVRDUDE_CHIP) \
--fuses 0:$(WDTCFG) 1:$(BODCFG) 2:$(OSCCFG) 4:$(TCD0CFG) 5:$(SYSCFG0) 6:$(SYSCFG1) 7:$(APPEND) 8:$(BOOTEND) -f $< -a write -v

ifneq ($(OS),Windows_NT) # Linux
build: all
Expand Down
8 changes: 1 addition & 7 deletions VortexEngine/VortexEngine.cppproj
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@
<Compile Include="src\Patterns\Multi\LighthousePattern.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="src\Patterns\Multi\MateriaPattern.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="src\Patterns\Multi\MeteorPattern.cpp">
<SubType>compile</SubType>
</Compile>
Expand Down Expand Up @@ -455,9 +452,6 @@
<Compile Include="src\Patterns\Multi\LighthousePattern.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="src\Patterns\Multi\MateriaPattern.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="src\Patterns\Multi\MeteorPattern.h">
<SubType>compile</SubType>
</Compile>
Expand Down Expand Up @@ -606,4 +600,4 @@
<Folder Include="src\Wireless\" />
</ItemGroup>
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
</Project>
</Project>
33 changes: 24 additions & 9 deletions VortexEngine/src/Colors/Colorset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,36 +466,51 @@ void Colorset::serialize(ByteStream &buffer) const
}
}

void Colorset::unserialize(ByteStream &buffer)
bool Colorset::unserialize(ByteStream &buffer)
{
buffer.unserialize(&m_numColors);
initPalette(m_numColors);
if (!buffer.unserialize(&m_numColors)) {
return false;
}
if (m_numColors > MAX_COLOR_SLOTS) {
return false;
}
if (!initPalette(m_numColors)) {
return false;
}
for (uint8_t i = 0; i < m_numColors; ++i) {
buffer.unserialize(&m_palette[i].red);
if (!buffer.unserialize(&m_palette[i].red)) {
return false;
}
}
for (uint8_t i = 0; i < m_numColors; ++i) {
buffer.unserialize(&m_palette[i].green);
if (!buffer.unserialize(&m_palette[i].green)) {
return false;
}
}
for (uint8_t i = 0; i < m_numColors; ++i) {
buffer.unserialize(&m_palette[i].blue);
if (!buffer.unserialize(&m_palette[i].blue)) {
return false;
}
}
return true;
}

void Colorset::initPalette(uint8_t numColors)
bool Colorset::initPalette(uint8_t numColors)
{
if (m_palette) {
delete[] m_palette;
m_palette = nullptr;
}
if (!numColors) {
return;
return true;
}
//m_palette = (RGBColor *)vcalloc(numColors, sizeof(RGBColor));
m_palette = new RGBColor[numColors];
if (!m_palette) {
ERROR_OUT_OF_MEMORY();
return;
return false;
}
m_numColors = numColors;
return true;
}

4 changes: 2 additions & 2 deletions VortexEngine/src/Colors/Colorset.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ class Colorset

// serialize the colorset to save/load
void serialize(ByteStream &buffer) const;
void unserialize(ByteStream &buffer);
bool unserialize(ByteStream &buffer);

private:
// pre-allocate the palette
void initPalette(uint8_t numColors);
bool initPalette(uint8_t numColors);

// palette of colors
RGBColor *m_palette;
Expand Down
39 changes: 1 addition & 38 deletions VortexEngine/src/Menus/MenuList/ColorSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ ColorSelect::ColorSelect(const RGBColor &col, bool advanced) :
// function uses a different algorithm to generate the colors that results
// in a smaller color space with less bright colors. The tradeoff is you lose
// the bright colors but the rainbow looks a lot better
if (!m_advanced) {
g_hsv_rgb_alg = HSV_TO_RGB_RAINBOW;
}
g_hsv_rgb_alg = HSV_TO_RGB_RAINBOW;
}

ColorSelect::~ColorSelect()
Expand All @@ -57,12 +55,6 @@ bool ColorSelect::init()
m_ledSelected = true;
}
m_state = STATE_INIT;
if (m_advanced) {
// turn off force sleep while in this adv menu
VortexEngine::toggleForceSleep(false);
m_previewMode.setColorset(Colorset(RGB_RED, RGB_RED));
m_previewMode.init();
}
DEBUG_LOG("Entered color select");
return true;
}
Expand All @@ -74,17 +66,6 @@ Menu::MenuAction ColorSelect::run()
return result;
}

if (m_advanced) {
// leave after several clicks
if (g_pButton->onConsecutivePresses(LEAVE_ADV_COL_SELECT_CLICKS)) {
return MENU_QUIT;
}
// just render the current pattern for active color picking
// iterate all patterns and plkay
m_previewMode.play();
return MENU_CONTINUE;
}

// all states start with a blank slate
Leds::clearAll();
switch (m_state) {
Expand Down Expand Up @@ -125,18 +106,6 @@ void ColorSelect::onLedSelected()

void ColorSelect::onShortClick()
{
if (m_advanced) {
// grab one of the colorsets of the targeted leds
Colorset set = m_previewMode.getColorset(ledmapGetFirstLed(m_targetLeds));
// grab the first color convert it to hsv
HSVColor col = set.get(1);
col.hue += 15;
// set the color again after adjusting
set.set(1, col);
// update the colorset
m_previewMode.setColorsetMap(m_targetLeds, set);
return;
}
// increment selection
m_curSelection++;
if (m_state == STATE_PICK_SLOT) {
Expand All @@ -148,12 +117,6 @@ void ColorSelect::onShortClick()

void ColorSelect::onLongClick()
{
if (m_advanced) {
Colorset set = m_previewMode.getColorset();
set.set(0, set.get(1));
m_previewMode.setColorset(set);
return;
}
// if we're on 'exit' and we're on any menu past the slot selection
if (m_curSelection == 4 && m_state > STATE_PICK_SLOT) {
// move back to the previous selection
Expand Down
52 changes: 1 addition & 51 deletions VortexEngine/src/Menus/MenuList/PatternSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
PatternSelect::PatternSelect(const RGBColor &col, bool advanced) :
Menu(col, advanced),
m_srcLed(LED_FIRST),
m_argIndex(0),
m_started(false)
{
}
Expand All @@ -43,7 +42,7 @@ Menu::MenuAction PatternSelect::run()
// run the current mode
m_previewMode.play();
// show dimmer selections in advanced mode
Menus::showSelection(m_advanced ? RGB_GREEN0 : RGB_WHITE5);
Menus::showSelection(RGB_WHITE5);
return MENU_CONTINUE;
}

Expand All @@ -54,47 +53,6 @@ void PatternSelect::onLedSelected()

void PatternSelect::onShortClick()
{
if (m_advanced) {
// double click = skip 10
bool doSkip = g_pButton->onConsecutivePresses(2);
MAP_FOREACH_LED(m_targetLeds) {
Pattern *pat = m_previewMode.getPattern(pos);
if (pat->getNumArgs() <= m_argIndex) {
continue;
}
uint8_t &arg = pat->argRef(m_argIndex);
if (doSkip) {
arg += 10 - (arg % 10);
} else {
arg++;
}
// on/off/gap/dash duration max 100
uint8_t max = 100;
if (m_argIndex == 6) {
// blend number of numflips
max = 4;
} else if (m_argIndex > 3) {
// group size, solid index, blendspeed
max = 20;
}
if (arg > max) {
// red flash indicates reaching end
Leds::holdAll(RGB_RED);
arg %= (max + 1);
}
// do not let argument0 be reset to 0
if (!m_argIndex && !arg) {
arg = 1;
}
}
m_previewMode.init();
if (doSkip) {
// hold white for a moment to show they are skipping 25
Leds::holdAll(RGB_YELLOW1);
}
return;
}

PatternID newID = (PatternID)(m_previewMode.getPatternID(m_srcLed) + 1);
if (newID > PATTERN_SINGLE_LAST) {
newID = PATTERN_SINGLE_FIRST;
Expand All @@ -116,14 +74,6 @@ void PatternSelect::onShortClick()

void PatternSelect::onLongClick()
{
if (m_advanced) {
m_argIndex++;
if (m_argIndex < m_previewMode.getPattern(m_srcLed)->getNumArgs()) {
// if we haven't reached number of args yet then just return and kee pgoing
return;
}
Leds::holdAll(m_menuColor);
}
// store the mode as current mode
Modes::updateCurMode(&m_previewMode);
leaveMenu(true);
Expand Down
3 changes: 0 additions & 3 deletions VortexEngine/src/Menus/MenuList/PatternSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ class PatternSelect : public Menu
// helpful member
LedPos m_srcLed;

// used for adv pat select
uint8_t m_argIndex;

// the pat select starts by showing the current pattern
// then the first click begin cycling the list of pats
bool m_started;
Expand Down
Loading
Loading