Curreently you can only set up new OPCodes
Setting up new OPCodes
- Important
- Although you can define new opcode, the current version doesnt let you make use of user-defined Commands as of 0.0.1-alpha
One thing to note is that you do not define whole OPCodes but you define each part of the OPCode one by one with a String definitoin of each Member, which means you define the Category, then the Sub-Category and so on
- Warning
- Never Add/Modify Base OPCode Members!
- Note
- Every OPCode Member that is of Command Rank, it will have always by default a Detail 0 called SNF_OPCODE_BASE_DET_UNDETAILED
Example Let's Say we have to define this hierachy
- Category 1 its definition is "Category for Vehicle Commands"
- Sub Category 1 "Category for Vehicle Screen Commands"
- Command 1 "Change Vehicle Screen Bightness Command"
- Detail 1 "Maximum Brightness"
- Detail 2 "Minimum Brightness"
- Command 2 "Toggle Vehicle Screen Command"
#include <SNF.h>
#include <stdlib.h>
int main() {
0x01,
"Category for Vehicle Commands"
);
0x01,
0x00,
"Category for Vehicle Screen Commands"
);
0x01,
0x00,
0x00,
"Change Vehicle Screen Bightness Command"
);
0x01,
0x00,
0x00,
0x01,
"Maximum Brightness"
);
0x01,
0x00,
0x00,
0x02,
"Minimum Brightness"
);
0x01,
0x00,
0x01,
"Toggle Vehicle Screen Command"
);
return EXIT_SUCCESS;
}
int snf_opcode_define_category(SNF_opcode_mmbr_t Code, const char *Definition)
Defines an opcode Category.
int snf_opcode_define_detail(SNF_opcode_mmbr_t Category, SNF_opcode_mmbr_t SubCategory, SNF_opcode_mmbr_t Command, SNF_opcode_mmbr_t Code, const char *Definition)
Defines an opcode Detail.
int snf_opcode_define_sub_category(SNF_opcode_mmbr_t Category, SNF_opcode_mmbr_t Code, const char *Definition)
Defines an opcode Sub-Category.
int snf_opcode_init()
Initializes the SNF's opcodes.
int snf_opcode_define_command(SNF_opcode_mmbr_t Category, SNF_opcode_mmbr_t SubCategory, SNF_opcode_mmbr_t Code, const char *Definition)
Defines an opcode Command.
Getting an OPCode Member
Assuming that we use the OPCodes Defined in Setting up new OPCodes if we want to get the OPCode Member we use snf_opcode_get_{Rank}(..)
- Note
- if you want to get a OPCode Member use snf_opcode_get_base_{Rank}(..)
Example:
#include <SNF.h>
#include <stdlib.h>
int main() {
0x01
);
return EXIT_SUCCESS;
}
SNF_opcode_LL_item * snf_opcode_get_category(SNF_opcode_mmbr_t Category)
Fetches the opcode Category from the opcode's data structure.
SNF_opcode_LL_item * snf_opcode_get_base_category()
Fetches the base opcode Category from the opcode's data structure.
Structure used to save registred opcode members.
Definition opcode.h:60
- Warning
- Do not free any SNF_opcode_LL_item !!
Generating an OPCode
if we want to get a fully structured OPCode we use snf_opcode_get for Detailed Commands, and snf_opcode_getu
- Note
- if you want to get a Base OPCode use snf_opcode_get_base and snf_opcode_getu_base respectively
Example:
#include <SNF.h>
#include <stdlib.h>
int main() {
0x01,
0x00,
0x00,
0x01
);
0x01,
0x00,
0x00,
);
return EXIT_SUCCESS;
}
SNF_opcode * snf_opcode_getu(SNF_opcode_mmbr_t Category, SNF_opcode_mmbr_t SubCategory, SNF_opcode_mmbr_t Command)
Fetches a fully structured OPcode using the default Detail.
SNF_opcode * snf_opcode_get(SNF_opcode_mmbr_t Category, SNF_opcode_mmbr_t SubCategory, SNF_opcode_mmbr_t Command, SNF_opcode_mmbr_t Detail)
Fetches a fully structured OPcode.
Structure for the opcode.
Definition opcode.h:29
Generating a Request
Generating Request depends on either it's as a response request, or as a server request to the client, See SNF_Request_t::UID for more detail about the difference, to apply either we'll split this into Two parts:
A Response Request
To generate a response Request we use one of the following
- snf_request_gen_response
ClientReq,
op,
arg
);
SNF_RQST * snf_request_gen_response(SNF_RQST *Original, SNF_opcode *OPCODE, SNF_RQST_ARG *Args)
Generates a new response request.
SNF_RQST_ARG * snf_request_arg_gen(const char *arg)
Generates a new Argumment.
The Structure for saving Requests.
Definition request.h:29
- snf_request_gen_wUID
- Note
- UID of the response request MUST be the same as the Client's original request so preferrably use snf_request_gen_response as it's simpler to use unles this is what you want to use
ClientReq -> UID
);
SNF_RQST * snf_request_gen_wUID(const char UID[16])
Generates a new empty request that has an UID.
void snf_request_arg_insert(SNF_RQST *Request, SNF_RQST_ARG *arg)
Inserts an arguments to the end of Request's SNF_RQST_ARG List.
SNF_opcode * OPCODE
Defines The OPCODE of the request.
Definition request.h:42
- snf_request_gen_base (In Case you want to generate a response Using a Base OPCode Command )
ClientReq,
0xXX,
0xXX
);
SNF_RQST * snf_request_gen_base(SNF_RQST *Original, SNF_opcode_mmbr_t Command, SNF_opcode_mmbr_t Detail)
Generates a response request using base OPCode.
- snf_request_genu_base (In Case you want to generate a response Using an Undetailed Base OPCode )
ClientReq,
0xXX,
);
SNF_RQST * snf_request_genu_base(SNF_RQST *Original, SNF_opcode_mmbr_t Command)
Generates a response request using undetailed base OPCode.
A Server Request
Assuming you want to sent a request to a client (eg: Broadcasting a message or a Server Event) then we can formulate a Server Request using:
Generating Arguments and adding them into a Request
Generating Requests is by simply calling snf_request_arg_gen
even adding them is simple just use snf_request_arg_insert
- Note
- how ever the more arguments your request already have, the more time it would take to add new arguments you could how even only require to use snf_request_arg_insert once the following way
.
.
.
SNF_RQST_ARG * next
The next argument.
Definition request.h:52
Sending the request
To send the request use snf_request_send
void snf_request_send(SNF_CLT *Client, SNF_RQST *Request)
Send a request to a Client.
Starting the Framework
To Start the Framwork all you have to do is simply call snf_network_init and it will do everything on the background
- Warning
- Set Everything BEFORE running this function
void snf_network_init()
Initializes the Network Framwork.