Go to the documentation of this file.00001
00040 #ifndef LibMultiSense_SysFlashOpMessage
00041 #define LibMultiSense_SysFlashOpMessage
00042
00043 #include <typeinfo>
00044
00045 #include "details/utility/Portability.hh"
00046
00047 namespace crl {
00048 namespace multisense {
00049 namespace details {
00050 namespace wire {
00051
00052 class SysFlashOp {
00053 public:
00054 static CRL_CONSTEXPR IdType ID = ID_CMD_SYS_FLASH_OP;
00055 static CRL_CONSTEXPR VersionType VERSION = 1;
00056
00057
00058
00059
00060 static CRL_CONSTEXPR uint32_t MAX_LENGTH = 1024;
00061
00062
00063
00064
00065 static CRL_CONSTEXPR uint32_t OP_STATUS = 0;
00066 static CRL_CONSTEXPR uint32_t OP_ERASE = 1;
00067 static CRL_CONSTEXPR uint32_t OP_PROGRAM = 2;
00068 static CRL_CONSTEXPR uint32_t OP_VERIFY = 3;
00069
00070 uint32_t operation;
00071
00072
00073
00074
00075 static CRL_CONSTEXPR uint32_t RGN_BITSTREAM = 0;
00076 static CRL_CONSTEXPR uint32_t RGN_FIRMWARE = 1;
00077
00078 uint32_t region;
00079
00080
00081
00082
00083 uint32_t start_address;
00084 uint32_t length;
00085
00086 uint8_t data[MAX_LENGTH];
00087
00088
00089
00090
00091 SysFlashOp(utility::BufferStreamReader&r, VersionType v) {serialize(r,v);};
00092 SysFlashOp(uint32_t op=OP_STATUS,
00093 uint32_t r=RGN_BITSTREAM,
00094 uint32_t s=0,
00095 uint32_t l=0) : operation(op),
00096 region(r),
00097 start_address(s),
00098 length(l) {};
00099
00100
00101
00102 template<class Archive>
00103 void serialize(Archive& message,
00104 const VersionType version)
00105 {
00106 message & operation;
00107 message & region;
00108
00109 switch(operation) {
00110 case OP_PROGRAM:
00111 case OP_VERIFY:
00112
00113 message & start_address;
00114 message & length;
00115
00116 if(length > MAX_LENGTH)
00117 CRL_EXCEPTION("length (%u) exceeds MAX_LENGTH (%u)",
00118 length, MAX_LENGTH);
00119
00120 if (typeid(Archive) == typeid(utility::BufferStreamWriter))
00121 message.write(data, length);
00122 else
00123 message.read(data, length);
00124
00125 break;
00126 case OP_STATUS:
00127 case OP_ERASE:
00128
00129 break;
00130 default:
00131 CRL_EXCEPTION("unknown operation (%d)", (int)operation);
00132 }
00133
00134 switch(region) {
00135 case RGN_BITSTREAM:
00136 case RGN_FIRMWARE:
00137 break;
00138 default:
00139 CRL_EXCEPTION("unknown region (%d)", (int)region);
00140 }
00141 }
00142 };
00143
00144 }}}};
00145
00146 #endif