Trond Enger / d7a_1x

Fork of d7a_1x by WizziLab

Revision:
58:38a366236bda
Parent:
56:da34fc11e760
Child:
59:b42eae56b51b
diff -r fd9c8b67ffdc -r 38a366236bda include/d7a_alp.h
--- a/include/d7a_alp.h	Thu Sep 08 10:44:05 2016 +0000
+++ b/include/d7a_alp.h	Mon Sep 12 16:36:09 2016 +0000
@@ -65,24 +65,6 @@
 
 } alp_opcodes_t;
 
-// =======================================================================
-// d7a_id_t
-// -----------------------------------------------------------------------
-// Identifier types enumerator
-// =======================================================================
-typedef enum
-{
-    // Void identifier (broadcast) 
-    // with indication of number of reached devices
-    D7A_ID_NBID = 0,
-    // Void identifier (broadcast)
-    D7A_ID_NOID = 1,
-    // Unique Identifier
-    D7A_ID_UID  = 2,
-    // Virtual identifier
-    D7A_ID_VID  = 3,
-
-} d7a_id_t;
 
 typedef enum {
     ALP_RESP_TYPE_UNKNOWN = 0,
@@ -160,11 +142,18 @@
 
 TYPEDEF_STRUCT_PACKED 
 {
+    // Tag
+    uint8_t s_tag;
     uint8_t tag;
-    uint8_t tag_status;
-    uint8_t nb_status;
-    d7a_alp_rsp_status_t status[5];
-    uint32_t length;
+    // Status
+    uint8_t s_status;
+    d7a_alp_rsp_status_t status;
+    // IStatus
+    uint8_t s_istatus;
+    int8_t lb;
+    uint8_t id[D7A_UID_LEN];
+    // Data
+    uint32_t data_len;
     uint8_t* data;
 } d7a_alp_rsp_t;
 
@@ -242,11 +231,108 @@
 } alp_d7a_itf_t;
 
 
+// =======================================================================
+// d7a_ch_header_t
+// -----------------------------------------------------------------------
+/// Bitfield structure of the channel identifier
+// =======================================================================
+typedef union
+{
+    // bit access fields
+    struct {
+        /// Coding scheme
+        uint8_t cs   : 2;
+        /// Channel Class
+        uint8_t cl   : 2;
+        /// Channel Band
+        uint8_t band : 3;
+        /// RFU
+        uint8_t rfu  : 1;
+    } bf;
+
+    // byte access
+    uint8_t byte;
+
+} d7a_ch_header_t;
+
+// =======================================================================
+// d7a_sp_status_t
+// -----------------------------------------------------------------------
+/// Bitfield structure of the D7ASP segment status byte
+// =======================================================================
+typedef union
+{
+    // bit access fields
+    struct {
+        /// RFU
+        uint8_t rfu          : 4;
+        /// Identifier type of the received segment
+        uint8_t idf          : 2; 
+        /// Current seqnum was already received
+        uint8_t retry        : 1;
+        /// There are not received seqnums anterior to the current seqnum
+        uint8_t missed       : 1;
+    } bf;
+
+    // byte access
+    uint8_t byte;
+
+} d7a_sp_status_t;
+
+// =======================================================================
+// d7a_nwl_security_t
+// -----------------------------------------------------------------------
+/// NWL Security File structure
+// =======================================================================
+TYPEDEF_STRUCT_PACKED
+{
+    /// Key counter
+    uint8_t key_counter;
+    /// Frame counter
+    uint32_t frame_counter;
+
+} d7a_nwl_security_t;
+
+
+// =======================================================================
+// d7a_sp_res_t
+// -----------------------------------------------------------------------
+/// D7A specific segment metadata
+// =======================================================================
+TYPEDEF_STRUCT_PACKED
+{
+    /// channel header
+    d7a_ch_header_t header;    
+    /// channel index
+    uint16_t idx;
+    /// RSSI in -dBm
+    int8_t  rxlev;
+    /// Link budget in dB
+    int8_t  lb;
+    /// Target RXLEV in -dBm
+    int8_t  target_rxlev;
+    /// D7ASP status
+    d7a_sp_status_t status;
+    /// D7ASP Token
+    uint8_t  token;
+    /// D7ASP Sequence number
+    uint8_t  seq;
+    /// Response timeout
+    uint32_t resp_to;
+    /// Addressee
+    d7a_addressee_t addressee;
+    /// NLS security state (optional)
+    d7a_nwl_security_t nls_state;
+
+} d7a_sp_res_t;
+
+
+
 d7a_errors_t d7a_alp_open(void);
 d7a_errors_t d7a_alp_close(void);
 void d7a_alp_new_pkt(d7a_com_rx_msg_t* pkt);
 d7a_com_rx_msg_t* d7a_alp_wait_pkt(uint32_t millisec = osWaitForever);
-d7a_errors_t d7a_alp_write_file(const uint8_t file_id, const uint32_t offset, const uint32_t size, const uint8_t* const buf, d7a_addressee_t* addressee = NULL, uint8_t retry = 0, bool resp = true);
-d7a_errors_t d7a_alp_read_file(const uint8_t file_id, const uint32_t offset, const uint32_t size, const uint8_t* const buf, d7a_addressee_t* addressee = NULL, uint8_t retry = 0);
+d7a_msg_t** d7a_alp_write_file(const uint8_t file_id, const uint32_t offset, const uint32_t size, const uint8_t* const buf, d7a_addressee_t* addressee = NULL, uint8_t retry = 0, bool resp = true);
+d7a_msg_t** d7a_alp_read_file(const uint8_t file_id, const uint32_t offset, const uint32_t size, d7a_addressee_t* addressee = NULL, uint8_t retry = 0);
 
 #endif // _D7A_ALP_H_