Trond Enger / d7a_1x

Fork of d7a_1x by WizziLab

Revision:
51:644de6fe1ee7
Parent:
49:81d5bddb02f0
Child:
52:c7a58fc48bd2
--- a/src/d7a_fs.cpp	Mon Sep 05 13:21:50 2016 +0000
+++ b/src/d7a_fs.cpp	Tue Sep 06 15:00:32 2016 +0000
@@ -157,16 +157,29 @@
                 else if (req->cmd == FS_OP_RD)
                 {
                     d7a_fs_com_resp_t* b = (d7a_fs_com_resp_t*)MALLOC(OP_SIZE_RETDATA + req->length);
+                    ASSERT(g_fs_ctx.read_file != NULL, "FS Read callback not implemented!\r\n");
                     uint32_t len = g_fs_ctx.read_file(req->fid, req->offset, req->length, &b->data[0]);
+                    
                     b->id     = req->id;
-                    b->length = len;
                     b->cmd    = FS_OP_RETDATA;
-                    b->status = FS_STAT_OK; // TODO
-                    d7a_fs_msg((uint8_t*)b, OP_SIZE_RETDATA + req->length, KAL_COM_FLOW_FS_RESP);
+                    if (len == req->length)
+                    {
+                        b->length = len;
+                        b->status = FS_STAT_OK;
+                    }
+                    else
+                    {
+                        b->length = 0;
+                        b->status = FS_STAT_ERR_FID_NOEXIST;
+                        WARNING(false, "FS_STAT_ERR_FID_NOEXIST\r\n");
+                    }
+                    
+                    d7a_fs_msg((uint8_t*)b, OP_SIZE_RETDATA + b->length, KAL_COM_FLOW_FS_RESP);
                     FREE(b);
                 }
                 else if (req->cmd == FS_OP_WR)
                 {
+                    ASSERT(g_fs_ctx.write_file != NULL, "FS Write callback not implemented!\r\n");
                     buf.length = g_fs_ctx.write_file(req->fid, req->offset, req->length, &pkt->buffer[OP_SIZE_WR]);
                     d7a_fs_msg((uint8_t*)&buf, OP_SIZE_RETSTAT, KAL_COM_FLOW_FS_RESP);
                 }