MultiTech / libmDot-mbed5

Dependents:   mdot_two_way unh-hackathon-example unh-hackathon-example-raw TelitSensorToCloud ... more

Fork of libmDot-dev-mbed5-deprecated by MultiTech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FragmentationSession.h Source File

FragmentationSession.h

00001 /**********************************************************************
00002 * COPYRIGHT 2018 MULTI-TECH SYSTEMS, INC.
00003 *
00004 * ALL RIGHTS RESERVED BY AND FOR THE EXCLUSIVE BENEFIT OF
00005 * MULTI-TECH SYSTEMS, INC.
00006 *
00007 * MULTI-TECH SYSTEMS, INC. - CONFIDENTIAL AND PROPRIETARY
00008 * INFORMATION AND/OR TRADE SECRET.
00009 *
00010 * NOTICE: ALL CODE, PROGRAM, INFORMATION, SCRIPT, INSTRUCTION,
00011 * DATA, AND COMMENT HEREIN IS AND SHALL REMAIN THE CONFIDENTIAL
00012 * INFORMATION AND PROPERTY OF MULTI-TECH SYSTEMS, INC.
00013 * USE AND DISCLOSURE THEREOF, EXCEPT AS STRICTLY AUTHORIZED IN A
00014 * WRITTEN AGREEMENT SIGNED BY MULTI-TECH SYSTEMS, INC. IS PROHIBITED.
00015 *
00016 ***********************************************************************/
00017 
00018 #ifndef _FRAGMENTATION_SESSION_H
00019 #define _FRAGMENTATION_SESSION_H
00020 #ifdef FOTA
00021 
00022 #include "mbed.h"
00023 #include "FragmentationMath.h"
00024 #include "mDot.h"
00025 #include "WriteFile.h"
00026 
00027 #define MAX_PARITY 300
00028 #define FRAG_OFFSET 3
00029 #define MULTICAST_SESSIONS 3
00030 
00031 class FragmentationSession {
00032 
00033     public:
00034         FragmentationSession(mDot* dot, std::vector<uint8_t>* ret, bool* filled, uint32_t* delay);
00035         ~FragmentationSession();
00036         void processCmd(uint8_t* payload, uint8_t size);
00037         void reset();
00038         bool isComplete() const;
00039         bool cleanUp();
00040 
00041         enum FragCmd {
00042             PACKAGE_VERSION_FRAG,
00043             FRAG_STATUS,
00044             FRAG_SESSION_SETUP,
00045             FRAG_SESSION_DELETE,
00046             DATA_FRAGMENT = 0x08,
00047             CHECKSUM = 0x80,
00048             FRAG_SESSION_COMPLETE = 0x90
00049         };
00050 
00051     private:
00052 
00053         typedef struct {
00054             uint8_t  Padding;
00055             uint8_t  FragmentSize;
00056             uint16_t NumberOfFragments;
00057         } FragmentationSessionOpts_t;
00058 
00059         typedef struct {
00060             bool reset;
00061             bool failed;
00062             uint8_t fragMatrix;
00063             uint8_t blockAckDelay;
00064             uint8_t total_sessions;
00065             uint8_t mcGroupBitMask;
00066             uint8_t current_session;
00067             uint16_t index;
00068             uint16_t last_frag_num;
00069             uint32_t total_frags;
00070             FragmentationMath* math;
00071             FragmentationSessionOpts_t opts;
00072         } fragGroup;
00073 
00074 
00075         enum FragResult {
00076             FRAG_OK,
00077             FRAG_SIZE_INCORRECT,
00078             FRAG_FLASH_WRITE_ERROR,
00079             FRAG_NO_MEMORY,
00080             FRAG_COMPLETE
00081         };
00082 
00083         void reset(uint16_t num);
00084         void upgradeFile(uint8_t sessionIndex);
00085         bool processFrame(uint8_t fragIndex, uint16_t index, uint8_t buffer[], size_t size);
00086         uint32_t getDescriptor() { return _descriptor; }
00087 
00088         mDot* _dot;
00089         WriteFile* _fh;
00090         fragGroup _sessions[MULTICAST_SESSIONS];
00091 
00092         uint8_t ans;
00093         bool* _filled;
00094         uint32_t* _delay;
00095         uint8_t _session_index;
00096         uint32_t _descriptor;
00097         std::vector<uint8_t>* _ret;
00098         bool _complete;
00099         bool _validated;
00100 };
00101 #endif
00102 #endif // _FRAGMENTATION_SESSION_H