<commit_before>/*
The OpenTRV project licenses this file to you
under the Apache Licence, Version 2.0 (the "Licence");
you may not use this file except in compliance
with the Licence. You may obtain a copy of the Licence at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the Licence is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the Licence for the
specific language governing permissions and limitations
under the Licence.

Author(s) / Copyright (s): <NAME> 2016
                           <NAME> 2016
*/

#include "OTV0P2BASE_CLI.h"

#include "OTV0P2BASE_EEPROM.h"
#include "OTV0P2BASE_RTC.h"
#include "OTV0P2BASE_Security.h"
#include "OTV0P2BASE_Sleep.h"
#include "OTV0P2BASE_Util.h"


namespace OTV0P2BASE {
namespace CLI {


// Prints warning to serial (that must be up and running) that invalid (CLI) input has been ignored.
// Probably should not be inlined, to avoid creating duplicate strings in Flash.
void InvalidIgnored() { Serial.println(F("Invalid, ignored.")); }


// Set / clear node association(s) (nodes to accept frames from) (eg "A hh hh hh hh hh hh hh hh").
//        To add a new node: "A hh hh hh hh hh hh hh hh"
//        - Reads first two bytes of each token in hex and ignores the rest.
//        - Prints number of nodes set to serial
//        - Stops adding nodes once EEPROM full
//        - No error checking yet.
//        - Only accepts upper case for hex values.
//        To clear all nodes: "A *".
//        To query current status "A ?".
bool SetNodeAssoc::doCommand(char *const buf, const uint8_t buflen)
    {
    char *last; // Used by strtok_r().
    char *tok1;
    // Minimum 3 character sequence makes sense and is safe to tokenise, eg "A *".
    if((buflen >= 3) && (NULL != (tok1 = strtok_r(buf + 2, " ", &last))))
        {
        if('?' == *tok1)
            {
            // Query current association status.
            Serial.print(F("Nodes: "));
            const uint8_t nn = countNodeAssociations();
            Serial.println(nn);
            // Print first two bytes (and last) of each association's node ID.
            for(uint8_t i = 0; i < nn; ++i)
                {
                uint8_t nodeID[OpenTRV_Node_ID_Bytes];
                getNodeAssociation(i, nodeID);
                Serial.print(nodeID[0], HEX);
                Serial.print(' ');
                Serial.print(nodeID[1], HEX);
                Serial.println(F(" ... "));
                Serial.print(nodeID[OpenTRV_Node_ID_Bytes - 1], HEX);
                Serial.println();
                }
            }
        else if('*' == *tok1)
            {
            // Clear node IDs.
            OTV0P2BASE::clearAllNodeAssociations();
            Serial.println(F("Cleared"));<commit_msg>TODO-721<commit_after>/*
The OpenTRV project licenses this file to you
under the Apache Licence, Version 2.0 (the "Licence");
you may not use this file except in compliance
with the Licence. You may obtain a copy of the Licence at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the Licence is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the Licence for the
specific language governing permissions and limitations
under the Licence.

Author(s) / Copyright (s): <NAME> 2016
                           <NAME> 2016
*/

#include "OTV0P2BASE_CLI.h"

#include "OTV0P2BASE_EEPROM.h"
#include "OTV0P2BASE_RTC.h"
#include "OTV0P2BASE_Security.h"
#include "OTV0P2BASE_Sleep.h"
#include "OTV0P2BASE_Util.h"


namespace OTV0P2BASE {
namespace CLI {


// Prints warning to serial (that must be up and running) that invalid (CLI) input has been ignored.
// Probably should not be inlined, to avoid creating duplicate strings in Flash.
void InvalidIgnored() { Serial.println(F("Invalid, ignored.")); }


// Set / clear node association(s) (nodes to accept frames from) (eg "A hh hh hh hh hh hh hh hh").
//        To add a new node: "A hh hh hh hh hh hh hh hh"
//        - Reads first two bytes of each token in hex and ignores the rest.
//        - Prints number of nodes set to serial
//        - Stops adding nodes once EEPROM full
//        - No error checking yet.
//        - Only accepts upper case for hex values.
//        To clear all nodes: "A *".
//        To query current status "A ?".
bool SetNodeAssoc::doCommand(char *const buf, const uint8_t buflen)
    {
    char *last; // Used by strtok_r().
    char *tok1;
    // Minimum 3 character sequence makes sense and is safe to tokenise, eg "A *".
    if((buflen >= 3) && (NULL != (tok1 = strtok_r(buf + 2, " ", &last))))
        {
        if('?' == *tok1)
            {
            // Query current association status.
            Serial.print(F("Nodes: "));
            const uint8_t nn = countNodeAssociations();
            Serial.println(nn);
            // Print first two bytes (and last) of each association's node ID.
            for(uint8_t i = 0; i < nn; ++i)
                {
                uint8_t nodeID[OpenTRV_Node_ID_Bytes];
                getNodeAssociation(i, nodeID);
                Serial.print(nodeID[0], HEX);
                Serial.print(' ');
                Serial.print(nodeID[1], HEX);
                Serial.print(F(" ... "));
                Serial.print(nodeID[OpenTRV_Node_ID_Bytes - 1], HEX);
                Serial.println();
                }
            }
        else if('*' == *tok1)
            {
            // Clear node IDs.
            OTV0P2BASE::clearAllNodeAssociations();
            Serial.println(F("Cleared"));
{'fraction_non_alphanumeric': 0.10769767847791936, 'fraction_numerical': 0.015534997381742015, 'mean_word_length': 2.2154882154882154, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6029729', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1712, 'n_words': 613}