Merge pull request #162 from Telecominfraproject/host_sw_copy

Host sw copy
This commit is contained in:
mdlewisfb
2018-10-29 08:16:54 -07:00
committed by GitHub
45 changed files with 10404 additions and 0 deletions

44
firmware/host/Makefile Normal file
View File

@@ -0,0 +1,44 @@
#Makefile for ocmw and cli
CC=gcc
CFLAGS= -I./ocwdg -I./include -I./../ec -I./../ec/common -I./../ec/platform/oc-sdr/schema -I./../ec/common/inc/global -Wall -Werror -g -fshort-enums
LIBS = -lpthread -ledit -lm -lrt
src_ocmw = $(wildcard ocmw/*.c) $(wildcard ocwdg/*.c) $(wildcard util/*.c) $(wildcard ../ec/platform/oc-sdr/schema/*.c)
src_occli = $(wildcard occli/*.c) $(wildcard util/*.c) $(wildcard ../ec/platform/oc-sdr/schema/*.c)
src_ocware_stub = $(wildcard ocwarestub/*.c) $(wildcard ../ec/platform/oc-sdr/schema/*.c)
output_dir = bin
# --- Build binary and executable files
default:
@mkdir -p $(output_dir)
make all
all: ocmw_uart ocmw_usb ocmw_eth occli ocmw_eth_stub ocware_stub
.PHONY: occli
ocmw_uart: $(OBJECTS)
$(CC) $(src_ocmw) -o $(output_dir)/ocmw_uart $(LIBS) $(CFLAGS) -DOCWARE_HOST
ocmw_usb: $(OBJECTS)
$(CC) $(src_ocmw) -o $(output_dir)/ocmw_usb $(LIBS) $(CFLAGS) -DINTERFACE_USB -DOCWARE_HOST
ocmw_eth: $(OBJECTS)
$(CC) $(src_ocmw) -o $(output_dir)/ocmw_eth $(LIBS) $(CFLAGS) -DINTERFACE_ETHERNET -DOCWARE_HOST
ocmw_eth_stub: $(OBJECTS)
$(CC) $(src_ocmw) -o $(output_dir)/ocmw_eth_stub $(LIBS) $(CFLAGS) -DINTERFACE_STUB_EC -DOCWARE_HOST
ocware_stub: $(OBJECTS)
$(CC) $(src_ocware_stub) -o $(output_dir)/ocware_stub $(LIBS) $(CFLAGS) -DOCWARE_HOST
occli: $(OBJECTS)
$(CC) $(src_occli) -o $(output_dir)/occli $(LIBS) $(CFLAGS) -DOCWARE_HOST
ln -sf occli $(output_dir)/occmd
# --- remove binary and executable files
clean:
rm -fr $(output_dir)/ocmw_eth_stub $(output_dir)/ocmw_eth $(output_dir)/ocmw_usb $(output_dir)/ocmw_uart $(output_dir)/occli $(output_dir)/ocware_stub

View File

@@ -0,0 +1,59 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#ifndef __LOGGER_H__
#define __LOGGER_H__
#include <syslog.h>
#include <libgen.h>
#define __filename__ (basename(__FILE__))
#ifdef CONSOLE_LOG
#define logit(facility, fmt, ...) \
{ \
if(facility != LOG_DEBUG) \
printf(fmt "\n", ##__VA_ARGS__); \
else \
printf ("[%s:%d, %s()]:" fmt "\n", __filename__, \
__LINE__, __func__, ##__VA_ARGS__); \
}
#else /* syslog */
#define logit(facility, fmt, ...) \
{ \
if(facility != LOG_DEBUG) \
syslog(facility, fmt "\n", ##__VA_ARGS__); \
else \
syslog(facility, "<d> [%s:%d, %s()]: " fmt "\n", \
__filename__, __LINE__, __func__, ##__VA_ARGS__); \
}
#endif
#define logemerg(fmt, ...) logit(LOG_EMERG, "<E> " fmt, ##__VA_ARGS__)
#define logalert(fmt, ...) logit(LOG_ALERT, "<A> " fmt, ##__VA_ARGS__)
#define logcrit(fmt, ...) logit(LOG_CRIT, "<C> " fmt, ##__VA_ARGS__)
#define logerr(fmt, ...) logit(LOG_ERR, "<e> " fmt, ##__VA_ARGS__)
#define logwarn(fmt, ...) logit(LOG_WARNING, "<w> " fmt, ##__VA_ARGS__)
#define lognotice(fmt, ...) logit(LOG_NOTICE, "<n> " fmt, ##__VA_ARGS__)
#define loginfo(fmt, ...) logit(LOG_INFO, "<i> " fmt, ##__VA_ARGS__)
#define logdebug(fmt, ...) logit(LOG_DEBUG, fmt, ##__VA_ARGS__)
/*
* @param ident an input value (by pointer)
*
*/
void initlog(const char* ident);
/*
* deinitialize the logging routine
*
*/
void deinitlog(void);
#endif /* __LOGGER_H__ */

View File

@@ -0,0 +1,190 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#ifndef _OCCLI_COMM_H_
#define _OCCLI_COMM_H_
/* OC Inlucdes */
#include <stdbool.h>
#include <ocmw_helper.h>
#include <Framework.h>
#define HIT_FILE_BUFF_SIZE 50
#define OCCLI_STRING_SIZE 128
#define RES_STR_BUFF_SIZE 10000
#define OCMP_MAX_SIZE 10
#define OCCLI_CHAR_ARRAY_SIZE 30
#define OCMW_MAX_SUBSYSTEM 11
/* This timeout must be more than OCMW timeout */
#define OCCLI_TIMEOUT_PERIOD 12
#define FAILED -1
#define SUCCESS 0
#define OCCLI_SNPRINTF_MAX_LEN 200
#define OCCLI_HELP_MAX_SIZE 400
typedef struct {
char option;
int sizeNum;
int totalStr;
}OCCLI_ARRAY_PARAM;
typedef struct {
char subsystem[OCCLI_CHAR_ARRAY_SIZE];
char component[OCCLI_CHAR_ARRAY_SIZE];
char subcomponent[OCCLI_CHAR_ARRAY_SIZE];
char msgtype[OCCLI_CHAR_ARRAY_SIZE];
char parameter[OCCLI_CHAR_ARRAY_SIZE];
}strMsgFrame;
typedef struct {
int8_t subsystem;
int8_t component;
int8_t msgtype;
int16_t parameter;
}sMsgParam;
typedef struct{
char *subsystem;
char *component;
char *msgtype;
char *subcomponent;
char *parameter;
} OCCLI_STRING_MSG;
typedef struct {
int32_t totalNum;
struct name {
int32_t number;
char name[OCCLI_CHAR_ARRAY_SIZE];
} Info[OCCLI_CHAR_ARRAY_SIZE];
}subSystemInfo;
//Help Menu structure
typedef struct {
char subSystem[OCMW_MAX_SUBSYSTEM_SIZE];
char component[OCMW_HELP_FRAME_SIZE];
char subComponent[OCMW_HELP_FRAME_SIZE];
char msgType[OCMW_MAX_MSGTYPE_SIZE];
char actionType[OCMW_MAX_ACTION_SIZE];
char arguments[OCMW_HELP_FRAME_SIZE];
char parameter[OCMW_HELP_FRAME_SIZE];
}helpMenu;
typedef struct {
char subsystem[OCCLI_CHAR_ARRAY_SIZE];
char component[OCCLI_CHAR_ARRAY_SIZE];
char subComponent[OCCLI_CHAR_ARRAY_SIZE];
}commandFrame;
/*
* Initialize the ocmw communication
*/
int32_t occli_init_comm(void);
/*
* Deinitialize the ocmw communication
*/
int8_t occli_deinit_comm(void);
/*
* @param cmd an input string (by pointer)
* @param cmdlen an input value (by value)
*
* @return true if function succeeds, false otherwise
*/
int32_t occli_send_cmd_to_ocmw(const char *cmd, int32_t cmdlen);
/*
* @param resp an output value (by pointer)
* @param resplen an output value (by value)
*
* @return true if function succeeds, false otherwise
*/
int32_t occli_recv_cmd_resp_from_ocmw(char *resp, int32_t resplen);
/*
* @param resp an output value (by pointer)
* @param resplen an output value (by value)
*
* @return true if function succeeds, false otherwise
*/
int32_t occli_recv_alertmsg_from_ocmw(char *resp, int32_t resplen);
/*
* @param root an input value (by pointer)
* @param msgFrame an input value (by pointer)
* @param ecSendBuf an input value (by pointer)
* @param actiontype an input value (by value)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_parse_msgframe(const Component *root, strMsgFrame *msgFrame,
uint8_t actiontype,ocmwSchemaSendBuf *ecSendBuf);
/*
* @param root an output value (by pointer)
* @param dMsgFrameParam an output value (by pointer)
* @param ecReceivedMsg an output value (by pointer)
*
* @return true if function succeeds, false otherwise
*/
void ocmw_deserialization_msgframe(const Component *root,
sMsgParam *dMsgFrameParam,
OCMPMessageFrame *ecReceivedMsg);
/*
* @param compBase an output value (by pointer)
* @param msgFrame an output value (by pointer)
* @param ecSendBuf an output value (by pointer)
* @param actiontype an output value (by value)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_parse_command_msgframe(const Component *compBase,
strMsgFrame *msgFrame, uint8_t actiontype,
ocmwSchemaSendBuf *ecSendBuf);
/*
* @param compBase an output value (by pointer)
* @param msgFrame an output value (by pointer)
* @param ecSendBuf an output value (by pointer)
* @param actiontype an output value (by value)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_parse_post_msgframe(const Component *compBase,
strMsgFrame *msgFrame, uint8_t actiontype,
ocmwSchemaSendBuf *ecSendBuf);
/*
* @param root an output value (by pointer)
* @param systemInfo an output value (by pointer)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_frame_subsystem_from_schema(const Component *root,
subSystemInfo *systemInfo);
/*
* @param root an output value (by pointer)
* @param systemInfo an output value (by pointer)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_frame_postTable_from_schema(const Component *root);
/*
* @param pointer to global memory
*
* @return NONE
*/
extern inline void ocmw_free_global_pointer(void **ptr);
/*
* @param root an output value (by pointer)
* @param systemInfo an output value (by pointer)
*
* @return true if function succeeds, false otherwise
*/
int8_t occli_printHelpMenu(const Component *root,char *cmd);
/*Display CLI window*/
void occli_print_opencelluar();
#endif /* _OCCLI_COMM_H_ */

View File

@@ -0,0 +1,68 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#ifndef _OCMW_CORE_H_
#define _OCMW_CORE_H_
/* OC includes */
#include <ocmw_helper.h>
sem_t semecMsgParser;
sem_t semCliReturn;
sem_t semCommandPost;
/* This timeout must be less than CLI timeout */
#define OCMW_SEM_WAIT_TIME 10
#define OCMW_BUSY_WAIT_INDEX 0
#define OCMW_TIMED_WAIT_INDEX 1
#define PARAM_STR_MAX_BUFF_SIZE 100
int32_t ocmw_init();
/*
* @param actionType an input enum value (by value)
* @param msgType an input enum value (by value)
* @param paramStr an input string (by pointer)
* @param interface an input enum value (by value)
* @param paramVal an input value (by pointer)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_msg_packetize_and_send(char * argv[], uint8_t actionType,
uint8_t msgType, const int8_t * paramStr, uint8_t interface,
void* paramVal);
/*
* Message parser module
*
*/
void ocmw_ec_msgparser(void);
/*
* Thread to parse the data coming from EC to AP through uart
* @param pthreadData an input value (by pointer)
*/
void * ocmw_thread_uartmsgparser(void *pthreadData);
/*
* Thread to parse the data coming from EC to AP through ethernet
* @param pthreadData an input value (by pointer)
*/
void * ocmw_thread_ethmsgparser(void *pthreadData);
/*
* @param ecMsgFrame an input structure (by value)
* @param interface an input enum value (by value)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_send_msg(OCMPMessageFrame ecMsgFrame, uint8_t interface);
/*
* @param semId an input value (by pointer)
* @param semWaitType an input value (by value)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_sem_wait(sem_t *semId, int32_t semWaitType);
#endif /* _OCMW_CORE_H_ */

View File

@@ -0,0 +1,55 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#ifndef _OCCLI_IPC_COMM_H_
#define _OCCLI_IPC_COMM_H_
/* stdlib includes */
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdbool.h>
#include <errno.h>
#include <pthread.h>
#include <unistd.h>
#include <stdint.h>
#define OCMW_EC_DEV 1
#define OCMW_EC_STUB_DEV 2
/*
* Initialize the ocmw ethernet communication
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_init_eth_comm(int32_t sentDev);
/*
* Deinitialize the ocmw ethernet communication
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_deinit_eth_comm(int32_t sentDev);
/*
* @param cmd an input string (by pointer)
* @param cmdlen an input value (by value)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_send_eth_msgto_ec(const int8_t *cmd, int32_t cmdlen,int32_t sentDev);
/*
* @param resp an input value (by pointer)
* @param resplen an input value (by value)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_recv_eth_msgfrom_ec(int8_t *resp, int32_t resplen, int32_t sentDev);
#endif /* _OCCLI_IPC_COMM_H_ */

View File

@@ -0,0 +1,183 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#ifndef _OCMW_HELPER_H_
#define _OCMW_HELPER_H_
/* stdlib includes */
#include <unistd.h>
#include <stdint.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <semaphore.h>
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <math.h>
/* OC includes */
#include <ocmp_frame.h>
#include <ocmw_uart_comm.h>
#define Buf_PARAM_STRUCT_MAX_SIZE 16
#define MAX_PARM_COUNT (OCMP_MSG_SIZE - (sizeof(OCMPMessage)\
- sizeof(void *) + sizeof (OCMPHeader)))
#define DEBUG_SUBSYSTEM_NBR 11
#define DEBUG_I2C 3
#define DEBUG_MDIO 8
#define PARAM_STR_BUFF_SIZE 100
#define PARAM_TYPE_BUFF_SIZE 32
#define OCMW_MAX_SUBSYSTEM_SIZE 16
#define OCMW_MAX_ACTION_SIZE 16
#define OCMW_MAX_MSGTYPE_SIZE 16
#define OCMW_COMMAND_BUFF_SIZE 20
#define OCMW_POST_DESC_SIZE 24
#define OCMW_HELP_FRAME_SIZE 40
#define OCMW_POST_DEVICE_SIZE 40
#define EEPROM_STATUS_MAX_SIZE 21
#define EEPROM_SDR_STATUS_SIZE 19
#define EEPROM_CONFIG_MAX_SIZE 14
#define EEPROM_CONFIG_SIZE 18
#define OCMW_MAX_POST_CODE_SIZE 100
#define TEMP_STR_BUFF_SIZE 100
typedef enum {
VOID = 0,
CHAR = 1,
UCHAR = 1,
SHORT = 2,
USHORT = 2,
INT = 4,
UINT = 4,
FLOAT = 4
} DATA_TYPE;
typedef enum {
FAILED = -1,
SUCCESS,
INVALID_POINTER,
} ocmw_db_ret;
typedef struct {
int32_t paramindex;
int32_t paramval;
} bufParam;
typedef struct {
int8_t msgType;
int8_t componentId;
int8_t subsystem;
int8_t actionType;
int16_t paramInfo;
int32_t numOfele;
int8_t pbuf[MAX_PARM_COUNT];
int32_t paramSizebuf[MAX_PARM_COUNT];
} ocmwSendRecvBuf;
typedef struct {
int8_t subsystem;
int8_t componentId;
int8_t msgType;
int8_t actionType;
int16_t paramId;
int8_t paramPos;
int8_t paramSize;
char commandType[OCMW_COMMAND_BUFF_SIZE];
} ocmwSchemaSendBuf;
typedef struct __attribute__((packed, aligned(1))){
uint8_t devsn; /* device serial Number */
uint8_t subsystem;
char subsysName[OCMW_MAX_SUBSYSTEM_SIZE]; /* Subsystem Name */
char deviceName[OCMW_POST_DEVICE_SIZE]; /* Device Name */
uint8_t status; /* device status */
}ocwarePostResultData;
typedef struct {
unsigned int count; /* Device Status count */
ocwarePostResultData results[OCMW_MAX_POST_CODE_SIZE]; /* Post result structure */
} ocwarePostResults;
typedef struct {
uint8_t msgtype; /* Post Message tyep */
uint8_t replycode; /* Reply type */
char desc[OCMW_POST_DESC_SIZE]; /* Device description */
} ocwarePostReplyCode;
/*
* @param sem an input value (by pointer)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_sem_wait_nointr(sem_t *sem);
/*
* @param sem an input value (by pointer)
* @param timeout an input value (by pointer)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_sem_timedwait_nointr(sem_t *sem, const struct timespec *timeout);
/*
* @param paramindex an input value (by value)
* @param paramSizebuf an input value (by pointer)
* @param dataSize an output value (by pointer)
* @param pos an output value (by pointer)
*
*/
void ocmw_dataparsing_from_db(int32_t paramIndex, int32_t *paramSizebuf,
int32_t *dataSize, int32_t *pos);
/*
* @param input an input buffer (by pointer)
* @param bufParamStruct an output buffer (by pointer)
*
*/
void ocmw_dataparsing_from_ec(ocmwSendRecvBuf *input,
bufParam * bufParamStruct);
/*
* @param uartInputBuf an input buffer (by pointer)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_fill_inputstruct(ocmwSendRecvBuf *uartInputBuf);
/*
* @param ecInputData an input data (by value)
*
* @return true if function succeeds, false otherwise
*/
int8_t ocmw_parse_eepromdata_from_ec (ocmwSendRecvBuf ecInputData);
/*
* @param ecInputData an input data (by value)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_parse_obc_from_ec(ocmwSendRecvBuf ecInputData);
/*
* @param ecInputData an input data (by value)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_parse_testingmodule_from_ec(ocmwSendRecvBuf ecInputData);
/*
* @param msgaction an input value (by value)
* @param msgtype an input value (by value)
* @param paramstr an input string (by pointer)
* @param paramvalue an input value (by pointer)
*
*/
//int ocmw_msgproc_send_msg(int8_t msgaction, int8_t msgtype,
// const int8_t* paramstr, void* paramvalue);
#endif /* _OCMW_HELPER_H_ */

View File

@@ -0,0 +1,17 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#ifndef _OCMW_MSGPROC_H_
#define _OCMW_MSGPROC_H_
#include "ocmp_frame.h"
int ocmw_msgproc_send_msg(char * argv[], uint8_t action, int8_t msgtype,
const int8_t* paramstr, void* paramvalue);
#endif /* _OCMW_MSGPROC_H_ */

View File

@@ -0,0 +1,128 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#ifndef _OCMW_IPC_COMM_H_
#define _OCMW_IPC_COMM_H_
#include <ocmw_helper.h>
#define PARAMSTR_NUMBER_LEN 12
#define TESTMOD_MAX_LEN 16
#define RES_STR_BUFF_SIZE 10000
#define TEMP_STR_BUFF_SIZE 100
#define ALERT_STR_BUFF_SIZE 128
#define CMD_STR_BUFF_SIZE 100
#define OCMW_MAX_IMEI_SIZE 15
#define OCMW_MAX_MSG_SIZE 20
typedef struct {
int8_t pin;
int8_t value;
}debugGPIOData;
typedef struct {
uint16_t regAddress;
uint16_t regValue;
}debugMDIOData;
typedef struct __attribute__((packed, aligned(1))){
uint8_t slaveAddress;
uint8_t numOfBytes;
uint8_t regAddress;
uint16_t regValue;
}debugI2CData;
typedef enum {
SET_STR,
GET_STR,
RESET_STR,
ENABLE_STR,
DISABLE_STR,
ACTIVE_STR,
ECHO_STR,
DISCONNECT_STR,
CONNECT_STR,
SEND_STR,
DIAL_STR,
ANSWER_STR,
HANGUP_STR,
ELOOPBK_STR,
DLOOPBK_STR,
EPKTGEN_STR,
DPKTGEN_STR,
MAX_STR
} ocmw_token_t;
typedef enum {
HCI_STR,
DEBUG_STR,
RESULT_STR,
ENABLE_SET_STR,
GETSETMAX
} ocmw_setGet;
/*
* Initialize the ocmw cli communication
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_init_occli_comm(void);
/*
* Deinitialize the ocmw cli communication
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_deinit_occli_comm(void);
/*
* @param cmd an input string (by pointer)
* @param cmdlen an input value (by value)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_recv_clicmd_from_occli(char* cmdstr, int32_t cmdlen);
/*
* @param resp an input value (by pointer)
* @param resplen an input value (by value)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_send_clicmd_resp_to_occli(const char* resp, int32_t resplen);
/*
* @param cmdstr an input value (by pointer)
* @param response an output value (by pointer)
*
* @return true if function succeeds, false otherwise
*/
int ocmw_clicmd_handler(const char *cmdstr, char *response);
/*
* Initialize the ocmw alert communication
*
* @return true if function succeeds, false otherwise
*/
int32_t init_occli_alert_comm();
/*
* Deinitialize the ocmw alert communication
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_deinit_occli_alert_comm(void);
/*
* @param buf an input value (by pointer)
* @param buflen an input value (by value)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_send_alert_to_occli(const char* buf, int32_t buflen);
char ocmw_retrieve_post_results_count(ocwarePostResults *psData);
char ocmw_retrieve_post_results(ocwarePostResults *psData);
char ocmw_retrieve_reply_code_desc(ocwarePostReplyCode *replyCode);
#endif /* _OCMW_IPC_COMM_H_ */

View File

@@ -0,0 +1,52 @@
/* OC Includes */
#include <occli_common.h>
#ifndef _OCMW_SCHEMA_H_
#define _OCMW_SCHEMA_H_
#define OCMW_VALUE_TYPE_UINT8 1
#define OCMW_VALUE_TYPE_INT8 2
#define OCMW_VALUE_TYPE_UINT16 3
#define OCMW_VALUE_TYPE_INT16 6
#define OCMW_VALUE_TYPE_UINT32 11
#define OCMW_VALUE_TYPE_ENUM 9
#define OCMW_VALUE_TYPE_MFG 10
#define OCMW_VALUE_TYPE_MODEL 4
#define OCMW_VALUE_TYPE_GETMODEL 5
#define OCMW_VALUE_TYPE_STRUCT 7
#define OCMW_VALUE_TYPE_NWOP_STRUCT 12
#define IRIDIUM_LASTERR_ERROR_CODE_OFFSET 2
#define TWO_G_SIM_NET_OPTR_STATUS_OFFSET 2
#define BUF_SIZE 50
#define ENUM_BUF_SIZE 30
#define OCMW_VALUE_TYPE_COMPLEX 3
static const char *DATA_TYPE_MAP[] = {
[TYPE_NULL] = "NULL",
[TYPE_INT8] = "int8",
[TYPE_UINT8] = "uint8",
[TYPE_INT16] = "int16",
[TYPE_UINT16] = "uint16",
[TYPE_INT32] = "int32",
[TYPE_UINT32] = "uint32",
[TYPE_INT64] = "int64",
[TYPE_UINT64] = "uint64",
[TYPE_STR] = "string",
[TYPE_BOOL] = "bool",
[TYPE_ENUM] = "enum",
};
typedef enum ErrorSource {
ERR_RC_INTERNAL = 0,
ERR_SRC_CMS = 1,
ERR_SRC_CME = 2
}Source;
typedef enum OperatorStat {
TWOG_SIM_STAT_UNKNOWN = 0x00,
TWOG_SIM_STAT_AVAILABLE = 0x01,
TWOG_SIM_STAT_CURRENT = 0x02,
TWOG_SIM_STAT_FORBIDDEN = 0x03,
}eOperatorStat;
#endif /* _OCMW_SCHEMA_H_ */

View File

@@ -0,0 +1,42 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#ifndef _OCMW_SOCK_COMM_H_
#define _OCMW_SOCK_COMM_H_
#define OCMW_SOCK_SERVER_IP ("127.0.0.1")
#define OCMW_SOCK_SERVER_PORT (5000)
#define OCMW_SOCK_SERVER_ALERT_PORT (6000)
#define OCMW_SOCK_SERVER_CONN_COUNT (1)
#define OCMW_SOCK_SERVER_ALERT_CONN_COUNT (2)
#define OCMW_SOCK_DOMAIN (AF_INET)
#define OCMW_SOCK_TYPE (SOCK_DGRAM)
#define OCMW_SOCK_PROTOCOL (IPPROTO_UDP)
#define OCMW_SOCK_ALERT_SERVER_IP ("127.0.0.1")
#define OCMW_SOCK_ALERT_SERVER_PORT (6000)
#define OCMW_SOCK_ALERT_DOMAIN (AF_INET)
#define OCMW_SOCK_ALERT_TYPE (SOCK_DGRAM)
#define OCMW_SOCK_ALERT_PROTOCOL (IPPROTO_UDP)
#define OCMW_ETH_SOCK_SERVER_IP ("192.168.1.2")
#define OCMW_ETH_SOCK_SERVER_PORT (1000)
#define OCMW_ETH_SOCK_DOMAIN (AF_INET)
#define OCMW_ETH_SOCK_TYPE (SOCK_STREAM)
#define OCMW_ETH_SOCK_PROTOCOL (IPPROTO_TCP)
#define OCMW_SOCKET_ERROR_SIZE 256
#define OCMW_SOCK_STUB_SERVER_IP ("127.0.0.1")
#define OCMW_SOCK_STUB_SERVER_PORT (2000)
#define OCMW_SOCK_STUB_DOMAIN (AF_INET)
#define OCMW_SOCK_STUB_TYPE (SOCK_DGRAM)
#define OCMW_SOCK_STUB_PROTOCOL (IPPROTO_UDP)
#endif /* _OCMW_SOCK_COMM_H_ */

View File

@@ -0,0 +1,59 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#ifndef _OCMW_UART_COMM_H_
#define _OCMW_UART_COMM_H_
#ifdef INTERFACE_USB
#define ECTTY "sudo find /dev/ -iname \"ttyACM*\" | tr -cd [:digit:]"
#else
#define ECTTY "/dev/ttyS4"
#endif
#define OCMP_MSG_SIZE (64)
/*
* @param msgstr an input value (by pointer)
* @param msgsize an input value (by value)
*
* @return the function handler
*/
typedef void
(*handle_msg_from_ec_t)(const unsigned char* msgstr, int32_t msgsize);
/*
* @param msgstr an input value (by pointer)
* @param msgsize an input value (by value)
*
*/
void ocmw_ec_uart_msg_hndlr(const unsigned char* msgstr, int32_t msgsize);
/*
* Initialize the ocmw ec communication
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_init_ec_comm(handle_msg_from_ec_t msghndlr);
/*
* Deinitialize the ocmw ec communication
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_deinit_ec_comm(void);
/*
* @param msgstr an input value (by pointer)
* @param size an input value (by value)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_send_uart_msg_to_ec(const uint8_t* msgstr, int32_t size);
/*
* @param pathName an input value (by pointer)
*
* @return true if function succeeds, false otherwise
*/
int32_t ocmw_find_ttyacm_port(char *pathName);
#endif /* _OCMW_UART_COMM_H_ */

View File

@@ -0,0 +1,16 @@
#ifndef _STUB_ETH_COMM_H_
#define _STUB_ETH_COMM_H_
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define OCMW_STUB_ETH_SOCK_DOMAIN (AF_INET)
#define OCMW_STUB_ETH_SOCK_TYPE (SOCK_DGRAM)
#define OCMW_STUB_ETH_SOCK_PROTOCOL (IPPROTO_UDP)
#define OCMW_STUB_ETH_SOCK_SERVER_PORT (2000)
#define OCMW_STUB_ETH_SOCK_SERVER_IP ("127.0.0.1")
#define OCWARE_STUB_ERR_STR_LEN (80)
#endif /* _STUB_ETH_COMM_H_ */

View File

@@ -0,0 +1,266 @@
#ifndef _OCMW_STUB_H_
#define _OCMW_STUB_H_
#include <stdio.h>
#include <errno.h>
#include <syslog.h>
#include <string.h>
#include <logger.h>
#include <stdlib.h>
#include <unistd.h>
#include <error.h>
#include <malloc.h>
#include <string.h>
#include <stdint.h>
#include <occli_common.h>
#include <ocmw_occli_comm.h>
#include <math.h>
#include <ocmp_frame.h>
#define OC_EC_MSG_SIZE (64)
#define MAX_PAYLOAD_COUNT (OC_EC_MSG_SIZE - sizeof (OCMPHeader))
/* Max parameters to be stored in database */
#define MAX_NUMBER_PARAM 400
#define MAX_POST_DEVICE 400
#define MAX_I2C_COMP_NBR 1
#define MAX_GPIO_COMP_NBR 1
#define MAX_MDIO_COMP_NBR 1
/* Default values in the database */
#define DEFAULT_INT8 0x11
#define DEFAULT_INT16 0x2222
#define DEFAULT_INT32 0x33333333
#define DEFAULT_INT64 0x4444444444444444
#define DEFAULT_ENUM 0x05
#define DEFAULT_STRING "stub"
/* default values in the debug subsystem */
#define I2C_SLAVE_ADDRESS 1
#define I2C_NUM_BYTES 1
#define I2C_REG_ADDRESS 1
#define I2C_REG_VALUE 1
#define GPIO_PIN_NBR 1
#define GPIO_VALUE 1
/* size of strings and enum dataypes in schema */
#define SIZE_OF_TYPE_REGISTRATION 1
#define SIZE_OF_NWOP_STRUCT 3
#define SIZE_OF_LAST_ERROR 3
#define SIZE_OF_TYPE_MFG 10
#define SIZE_OF_TYPE_GETMODEL 5
#define SIZE_OF_TYPE_MODEL 4
#define SIZE_OF_NWOP_STRUCT 3
#define SIZE_OF_LAST_ERROR 3
#define SIZE_OF_TYPE_OCSERIAL_INFO 18
#define SIZE_OF_TYPE_GBCBOARD_INFO 18
#define SIZE_OF_TYPE_MACADDR 13
/* Masking related defines */
#define MASK_MSB 0xFF00
#define MASK_LSB 0xFF
#define SHIFT_NIBBLE 8
typedef struct {
uint8_t subsystemId;
uint8_t componentId;
uint8_t msgtype;
uint16_t paramId;
uint8_t paramSize;
uint8_t paramPos;
uint8_t datatype;
void *data;
}OCWareStubDatabase;
typedef struct{
uint8_t SubsystemId;
uint8_t DeviceNumber;
ePostCode Status;
}OCWareStubPostData;
typedef enum {
OCSTUB_VALUE_ZERO,
OCSTUB_VALUE_TYPE_MFG,
OCSTUB_VALUE_TYPE_GETMODEL,
OCSTUB_VALUE_TYPE_MODEL,
OCSTUB_VALUE_TYPE_REGISTRATION,
OCSTUB_VALUE_TYPE_NWOP_STRUCT,
OCSTUB_VALUE_TYPE_LAST_ERROR,
OCSTUB_VALUE_TYPE_OCSERIAL_INFO,
OCSTUB_VALUE_TYPE_GBCBOARD_INFO,
OCSTUB_VALUE_TYPE_I2C_DEBUG,
OCSTUB_VALUE_TYPE_GPIO_DEBUG,
OCSTUB_VALUE_TYPE_MDIO_DEBUG,
}OCWareStubsizeflag;
typedef struct {
uint8_t slaveAddress;
uint8_t numOfBytes;
uint8_t regAddress;
uint16_t regValue;
}OCWareDebugI2Cinfo;
typedef struct {
uint16_t regAddress;
uint16_t regValue;
}OCWareDebugMDIOinfo;
typedef struct {
uint8_t pin_nbr;
uint8_t value;
}OCWareDebugGPIOinfo;
typedef enum ocware_ret{
STUB_FAILED = -1,
STUB_SUCCESS = 0
}ocware_stub_ret;
extern int8_t debugGetCommand;
extern int8_t debugSetCommand;
extern int8_t PostResult;
extern int8_t PostEnable;
/******************************************************************************
* Function Name : ocware_stub_parse_post_get_message
* Description : Parse post messages from MW
*
* @param buffer - output pointer to the message from MW
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_parse_post_get_message(char *buffer);
/******************************************************************************
* Function Name : ocware_stub_parse_command_message
* Description : Parse command messages from MW
*
* @param buffer - output pointer to the message from MW
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_parse_command_message(char *buffer);
/******************************************************************************
* Function Name : ocware_stub_get_set_params
* Description : Function to check if GET/SET operation is to be performed
*
* @param msgFrameData - Pointer to the message frame field of the message
* from MW (by reference)
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_get_set_params(OCMPMessage *msgFrameData);
/******************************************************************************
* Function Name : ocware_stub_init_database
* Description : Parse the schema and add entries in the DB
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_init_database(void);
/******************************************************************************
* Function Name : ocware_stub_send_msgframe_middleware
* Description : send message to the MW
*
* @param bufferlen - length of the message (by value)
* @param buffer - pointer to the message to be sent to MW (by reference)
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_send_msgframe_middleware(char **buffer, int32_t bufferlen);
/******************************************************************************
* Function Name : ocware_stub_init_ethernet_comm
* Description : initialise the socket IPC
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_init_ethernet_comm(void);
/******************************************************************************
* Function Name : ocware_stub_deinit_ethernet_comm
* Description : close the IPC socket
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_deinit_ethernet_comm();
/******************************************************************************
* Function Name : ocware_stub_recv_msgfrom_middleware
* Description : Receive message from MW
*
* @param bufferlen - length of the message (by value)
* @param buffer - pointer to the location where the message from MW is to be
* stored for further processing (by reference)
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_recv_msgfrom_middleware(char **buffer, int32_t bufferlen);
/******************************************************************************
* Function Name : ocware_stub_get_database
* Description : Function to retrieve data from the DB
*
* @param msgFrameData - Pointer to the message frame field of the message
* from MW (by reference)
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_get_database(OCMPMessage *msgFrameData);
/******************************************************************************
* Function Name : ocware_stub_set_database
* Description : Function to modify data in the DB
*
* @param msgFrameData - Pointer to the message frame field of the message
* from MW (by reference)
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_set_database(OCMPMessage *msgFrameData);
/******************************************************************************
* Function Name : ocware_stub_get_post_result_paramvalue_from_table
* Description : Fill payload with the post information
*
* @param message - output pointer to the message from MW
* @param payload - output pointer to the payload field of the message from MW
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_get_post_result_paramvalue_from_table(
OCMPMessage *msgFrameData,
int8_t *payload);
/******************************************************************************
* Function Name : ocware_stub_parse_debug_actiontype
* Description : Convert debug actiontype into the SET/GET
*
* @param msgFrameData - output pointer to the OCMPheader field of the message
* from MW (by reference)
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_parse_debug_actiontype(OCMPMessage *msgFrameData);
/******************************************************************************
* Function Name : ocware_stub_get_post_database
* Description : extract device number and status from the post database
* depending on the subsytem id
*
* @param msgFrameData - output pointer to the OCMPheader field of the message
* from MW (by reference)
* @param payload - output pointer to the payload field of the message from MW
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_get_post_database(OCMPMessage *msgFrameData,
char *payload);
#endif /* __OCMW_STUB_H__ */

View File

@@ -0,0 +1,30 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#ifndef _OCWGD_DAEMON_H_
#define _OCWGD_DAEMON_H_
/* OC includes */
#include <ocmw_core.h>
#include <ocmw_uart_comm.h>
#include <ocmw_eth_comm.h>
sem_t semEcWdgMsg;
/*
* Initialize the watchdog daemon
*
* @return true if function succeeds, false otherwise
*/
int32_t ocwdg_init(void);
/*
* @param pthreadData an input value (by pointer)
*
*/
void * ocwdg_thread_comm_with_ec(void *pthreadData);
#endif /* _OCWGD_DAEMON_H_ */

View File

@@ -0,0 +1,23 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#ifndef _POST_H_
#define _POST_H_
/* stdlib includes */
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#define POST_MAIN_PAYLOAD_SIZE 3
#define POST_MAIN_PAYLOAD_SUBSYSTEM_OFFSET 0
#define POST_MAIN_PAYLOAD_DEVSN_OFFSET 1
#define POST_MAIN_PAYLOAD_STATUS_OFFSET 2
#endif /* _POST_H_ */

View File

@@ -0,0 +1,19 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#ifndef _UTIL_H_
#define _UTIL_H_
/*
* @param buf an input value (by pointer)
* @param buflen an input value (by value)
*
*/
void hexdisp(const unsigned char* buf, int buflen);
#endif /* _UTIL_H_ */

View File

@@ -0,0 +1,460 @@
#include <stdint.h>
#include <stdlib.h>
#include <logger.h>
#include <occli_common.h>
/**************************************************************************
* Function Name : occli_print_opencelluar
* Description : This Function print Opencelluar at prompt
* Input(s) :
* Output(s) :
***************************************************************************/
void occli_print_opencelluar()
{
printf("\nHELP Usage:\n\t\"subsystem --help\""
" OR \"subsystem.component --help\"");
printf("\nEXIT:\n\t\"quit\"");
printf("\nDisplay:\n\t\"Press Double TAB\"");
printf("\nClear Screen:\n\t\"Press CTRL + L \"\n\n");
return;
}
/**************************************************************************
* Function Name : occli_fill_data_from_param
* Description : This Function fill array data based on msgType
* Input(s) : param, helpMsgType, index
* Output(s) : index, helpMenuArray
***************************************************************************/
int8_t occli_fill_data_from_param(const Parameter *param,
helpMenu *helpMenuArray[], int32_t *index, char *helpMsgType)
{
int32_t helpIndex = *index;
if ((helpMenuArray == NULL)) {
logerr("Invalid Memory \n");
return FAILED;
}
if (param && param->name) {
strncpy(helpMenuArray[helpIndex]->msgType,
helpMsgType,strlen(helpMsgType));
if (strcmp(helpMsgType, "config") == 0) {
strncpy(helpMenuArray[helpIndex]->actionType,
"get/set", strlen("get/set"));
} else {
strncpy(helpMenuArray[helpIndex]->actionType, "get", strlen("get"));
}
do {
strncpy(helpMenuArray[helpIndex]->parameter,
param->name, strlen(param->name));
param += 1;
helpIndex++;
} while (param && param->name);
*index = helpIndex;
}
return SUCCESS;
}
/**************************************************************************
* Function Name : occli_fill_data_from_command
* Description : This Function fill array data for command
* Input(s) : command, index
* Output(s) : index, helpMenuArray
***************************************************************************/
int8_t occli_fill_data_from_command(const Command *command,
helpMenu *helpMenuArray[], int32_t *index,
char *subSysComp)
{
int32_t helpIndex = *index;
if ((helpMenuArray == NULL)) {
logerr("Invalid Memory \n");
return FAILED;
}
if (command && command->name) {
strncpy(helpMenuArray[helpIndex]->msgType,
"command", strlen("command"));
while (command && command->name) {
strncpy(helpMenuArray[helpIndex]->actionType,
command->name, strlen(command->name));
if (strncmp(subSysComp, "debug", strlen("debug")) == 0) {
if (strstr(subSysComp, "I2C")) {
if (strcmp(command->name, "get") == 0) {
strcpy(helpMenuArray[helpIndex++]->arguments,
"Slave Address(Decimal)");
strcpy(helpMenuArray[helpIndex++]->arguments,
"Number of Bytes(1/2)");
strcpy(helpMenuArray[helpIndex++]->arguments,
"Register Address(Decimal)");
} else {
strcpy(helpMenuArray[helpIndex++]->arguments,
"Slave Address(Decimal)");
strcpy(helpMenuArray[helpIndex++]->arguments,
"Number of Bytes(1/2)");
strcpy(helpMenuArray[helpIndex++]->arguments,
"Register Address(Decimal)");
strcpy(helpMenuArray[helpIndex]->arguments,
"Register Data(Decimal)");
}
} else {
if (strcmp(command->name, "get") == 0) {
strcpy(helpMenuArray[helpIndex++]->arguments,
"Pin Number");
} else {
strcpy(helpMenuArray[helpIndex++]->arguments,
"Pin Number");
strcpy(helpMenuArray[helpIndex]->arguments,
"Value(0/1)");
}
}
} else if ((strncmp(subSysComp, "hci", strlen("hci")) == 0) &&
(strcmp(command->name, "set") == 0)) {
strcpy(helpMenuArray[helpIndex++]->arguments, "Off/Red/Green");
}
if (strcmp(command->name, "send") == 0) {
strcpy(helpMenuArray[helpIndex++]->arguments, "MSISDN Number");
strcpy(helpMenuArray[helpIndex]->arguments, "Message");
} else if (strcmp(command->name, "dial") == 0) {
strcpy(helpMenuArray[helpIndex]->arguments, "MSISDN Number");
}
command += 1;
helpIndex++;
}
*index = helpIndex;
}
return SUCCESS;
}
/**************************************************************************
* Function Name : occli_fill_data_from_post
* Description : This Function fill array data for command
* Input(s) : post, index
* Output(s) : index, helpMenuArray
***************************************************************************/
int8_t occli_fill_data_from_post(const Post *post,
helpMenu *helpMenuArray[], int32_t *index,
char *subSysComp)
{
int32_t helpIndex = *index;
if ((helpMenuArray == NULL)) {
logerr("Invalid Memory \n");
return FAILED;
}
if (post && post->name) {
strncpy(helpMenuArray[helpIndex]->msgType,
"post", strlen("post"));
while (post && post->name) {
strncpy(helpMenuArray[helpIndex]->actionType,
post->name, strlen(post->name));
post += 1;
helpIndex++;
}
*index = helpIndex;
}
return SUCCESS;
}
/**************************************************************************
* Function Name : occli_fill_data_from_driver
* Description : This Function will fill array data from driver
* Input(s) : devDriver
* Output(s) : helpMenuArray, index
***************************************************************************/
int8_t occli_fill_data_from_driver(const Driver *devDriver,
helpMenu *helpMenuArray[], int32_t *index, char *subSysComp)
{
const Parameter *param = NULL;
const Command *command = NULL;
const Post *post = NULL;
int8_t ret = FAILED;
if ((helpMenuArray == NULL) || (devDriver == NULL)) {
logerr("Invalid Memory \n");
return FAILED;
}
param = devDriver->config;
ret = occli_fill_data_from_param(param, helpMenuArray, index, "config");
param = devDriver->status;
ret = occli_fill_data_from_param(param, helpMenuArray, index, "status");
command = devDriver->commands;
ret = occli_fill_data_from_command(command, helpMenuArray,
index, subSysComp);
post = devDriver->post;
ret = occli_fill_data_from_post (post, helpMenuArray,
index, subSysComp);
return ret;
}
/**************************************************************************
* Function Name : occli_printHelpMenu_on_console
* Description : This Function will print CLI help Menu
* Input(s) : helpMenuArray, index, subSystem
* Output(s) : NA
***************************************************************************/
void occli_printHelpMenu_on_console(helpMenu *helpMenuArray[],
int32_t index, char *subSystem)
{
int32_t printIndex = 0;
if ((strcmp(subSystem, "testmodule") == 0) ||
(strcmp(subSystem, "hci") == 0)) {
/*Printing for testmodule and hci subSystem */
printf("\nExample :\n");
if (strcmp(subSystem, "testmodule") == 0) {
printf("testmodule.2gsim send 9789799425 hi\n");
printf("testmodule.2gsim dial 9789799425\n");
printf("testmodule.2gsim connect_nw\n\n");
} else {
printf("hci.led set 1\n\n");
}
printf("----------------------------------------------------------"
"-------------------------------------------\n");
printf("%-12s%-12s%-15s%-10s%-15s%-20s%-15s\n",
"Subsystem", "Component", "SubComponent", "MsgType",
"ActionType", "Parameter", "Arguments");
printf("----------------------------------------------------------"
"-------------------------------------------\n");
for(printIndex = 0; printIndex < index; printIndex++) {
printf("%-12s%-12s%-15s%-10s%-15s%-20s%-15s\n",
helpMenuArray[printIndex]->subSystem,
helpMenuArray[printIndex]->component,
helpMenuArray[printIndex]->subComponent,
helpMenuArray[printIndex]->msgType,
helpMenuArray[printIndex]->actionType,
helpMenuArray[printIndex]->parameter,
helpMenuArray[printIndex]->arguments);
}
printf("----------------------------------------------------------"
"-------------------------------------------\n");
} else if (strcmp(subSystem, "debug") == 0) {
/*Printing for debug subSystem */
printf("\nGet Example :\n");
printf("debug.I2C.bus0 get 104 2 58\n");
printf("debug.gbc.ioexpanderx70 get 1\n\n");
printf("Set Example :\n");
printf("debug.I2C.bus0 set 104 2 58 1\n");
printf("debug.gbc.ioexpanderx70 set 1 0\n");
printf("\n-------------------------------------------------------"
"----------------------------------------"
"---------\n");
printf("%-15s%-15s%-15s%-15s%-15s%-20s\n",
"Subsystem", "Component", "SubComponent", "MsgType",
"ActionType", "Arguments");
printf("-------------------------------------------------------"
"----------------------------------------"
"---------\n");
for(printIndex = 0; printIndex < index; printIndex++) {
printf("%-15s%-15s%-15s%-15s%-15s%-20s\n",
helpMenuArray[printIndex]->subSystem,
helpMenuArray[printIndex]->component,
helpMenuArray[printIndex]->subComponent,
helpMenuArray[printIndex]->msgType,
helpMenuArray[printIndex]->actionType,
helpMenuArray[printIndex]->arguments);
}
printf("-------------------------------------------------------"
"----------------------------------------"
"---------\n");
} else {
/*Printing for all othere subSystem */
/* Dispalay of parameter default value and unit in help menu
* will be take care with common schema factory config
*/
printf("\n------------------------------------------------------------"
"----------------------------------\n");
printf("%-12s%-17s%-18s%-12s%-12s%-23s\n",
"Subsystem", "Component", "SubComponent", "MsgType",
"ActionType", "Parameter");
printf("\n------------------------------------------------------------"
"----------------------------------\n");
for(printIndex = 0; printIndex < index; printIndex++) {
printf("%-12s%-17s%-18s%-12s%-12s%-23s\n",
helpMenuArray[printIndex]->subSystem,
helpMenuArray[printIndex]->component,
helpMenuArray[printIndex]->subComponent,
helpMenuArray[printIndex]->msgType,
helpMenuArray[printIndex]->actionType,
helpMenuArray[printIndex]->parameter);
}
printf("\n------------------------------------------------------------"
"----------------------------------\n");
}
}
/**************************************************************************
* Function Name : occli_free_helpMenupointer
* Description : This is an inline function to free memory
* Input(s) : helpMenuArray
* Output(s) : helpMenuArray
***************************************************************************/
inline void occli_free_helpMenupointer(helpMenu *helpMenuArray[])
{
int32_t mallocIndex = 0;
for (mallocIndex = 0; mallocIndex < OCCLI_HELP_MAX_SIZE; mallocIndex++) {
if(helpMenuArray[mallocIndex])
free(helpMenuArray[mallocIndex]);
}
return;
}
/**************************************************************************
* Function Name : occli_printHelpMenu
* Description : This Function will print CLI help Menu
* Input(s) : root, cmd
* Output(s) : NA
***************************************************************************/
int8_t occli_printHelpMenu(const Component *root, char *cmd)
{
int32_t index = 0;
int32_t mallocIndex = 0;
const Component *subSystem = root;
const Component *component = NULL;
const Component *subComponent = NULL;
const Driver *devDriver = NULL;
const Command *command = NULL;
char *token = NULL;
char *cliStr = NULL;
char *cmdBkp = NULL;
char componentStr[OCCLI_CHAR_ARRAY_SIZE] = {0};
char subSys[OCCLI_CHAR_ARRAY_SIZE] = {0};
char subSysComp[OCCLI_CHAR_ARRAY_SIZE] = {0};
int8_t ret = FAILED;
int8_t count = 1;
int8_t subCount = 0;
int8_t compCount = 0;
helpMenu *helpMenuArray[OCCLI_HELP_MAX_SIZE];
if ((subSystem == NULL) || (cmd == NULL)) {
logerr("Invalid Memory \n");
return FAILED;
}
cmdBkp = (char *)malloc (sizeof(cmd));
if (cmdBkp == NULL) {
logerr("Invalid Memory \n");
return FAILED;
}
strcpy(cmdBkp,cmd);
/* Tokenizing string for subsystem and component */
cliStr = strtok(cmd, " ");
if ((cliStr == NULL) || (strstr(cliStr, "help"))) {
printf("%s : Error : Incorrect request\n", cmdBkp);
printf ("Usage : subsystem --help or subsystem.component --help\n");
free(cmdBkp);
return FAILED;
} else {
token = strtok(cliStr, " .");
strcpy(subSys, token);
while (token) {
token = strtok(NULL, " .");
if (token == NULL)
break;
count++;
if (count > 2) {
printf("%s : Error : Incorrect request\n", cmdBkp);
printf ("Usage : subsystem --help"
" OR subsystem.component --help\n");
free(cmdBkp);
return FAILED;
}
strcpy(componentStr, token);
}
}
for (mallocIndex = 0; mallocIndex < OCCLI_HELP_MAX_SIZE; mallocIndex++) {
helpMenuArray[mallocIndex] = (helpMenu *)malloc(sizeof(helpMenu));
if (helpMenuArray[mallocIndex] == NULL) {
logerr("Invalid Memory \n");
free(cmdBkp);
return FAILED;
} else {
memset(helpMenuArray[mallocIndex], '\0', sizeof(helpMenu));
}
}
/* Parsing schema */
while (subSystem && subSystem->name) {
if (strcmp(subSys, subSystem->name) == 0) {
subCount++;
strncpy((helpMenuArray[index++]->subSystem),
subSystem->name, strlen(subSystem->name));
component = subSystem->components;
while (component && component->name) {
if ((count == 2)) {
if (strcmp(component->name, componentStr)) {
component += 1;
continue;
} else {
compCount++;
}
}
strncpy((helpMenuArray[index]->component),
component->name, strlen(component->name));
sprintf(subSysComp, "%s.%s", subSystem->name, component->name);
command = component->commands;
ret = occli_fill_data_from_command(command,
helpMenuArray, &index, subSysComp);
devDriver = component->driver;
if (devDriver != NULL) {
ret = occli_fill_data_from_driver(devDriver,
helpMenuArray, &index, subSysComp);
if (ret == FAILED) {
logerr("\noccli_fill_data_from_driver Error");
occli_free_helpMenupointer(helpMenuArray);
return ret;
}
}
index++;
subComponent = component->components;
while (subComponent && subComponent->name) {
strncpy((helpMenuArray[index]->subComponent),
subComponent->name, strlen(subComponent->name));
command = subComponent->commands;
ret = occli_fill_data_from_command(command,
helpMenuArray, &index, subSysComp);
devDriver = subComponent->driver;
if (devDriver != NULL) {
ret = occli_fill_data_from_driver(devDriver,
helpMenuArray, &index, subSysComp);
if (ret == FAILED) {
logerr("\noccli_fill_data_from_driver Error");
occli_free_helpMenupointer(helpMenuArray);
return ret;
}
}
index++;
subComponent += 1;
}
component += 1;
}
if ((count == 2) && (compCount == 0)) {
printf("%s : Error : Invalid Component\n", cmdBkp);
occli_free_helpMenupointer(helpMenuArray);
free(cmdBkp);
return FAILED;
}
}
subSystem += 1;
}
if (subCount == 0) {
printf("%s : Error : Invalid Subsystem\n", cmdBkp);
occli_free_helpMenupointer(helpMenuArray);
free(cmdBkp);
return FAILED;
}
occli_printHelpMenu_on_console(helpMenuArray, index, subSys);
occli_free_helpMenupointer(helpMenuArray);
free(cmdBkp);
return SUCCESS;
}

View File

@@ -0,0 +1,860 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/* stdlib includes */
#include <ctype.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <logger.h>
#include <util.h>
/* sudo apt-get install libedit-dev : Install editline */
#include <editline/readline.h>
/* OC includes */
#include <occli_common.h>
#define HISTORY ".occli_history" /* Saved under ${HOME} direcotory */
#define SWAP(s, e) do { \
int32_t t; t = s; s = e; e = t; \
} while (0)
/* MAX_CLIENTRY represents the maximum entries which autofill can take */
#define OCCLI_MAX_CLISTRING 1000
#define OCCLI_MAX_SUBSTRING 75
#define OCCLI_STRING_MAX_LEN 100
#define OCCLI_CALC_SCHEMA_SIZE 1
#define OCCLI_PARSE_SCHEMA 2
#define MAX_ETHERNET_PORT 4
#define OPENCELLULAR "opencellular# "
extern char *rl_line_buffer;
static char *s_allParams[OCCLI_MAX_CLISTRING];
static char *s_subSetParams[OCCLI_MAX_SUBSTRING];
static char *s_strCli = NULL;
extern const Component sys_schema[];
/**************************************************************************
* Function Name : occli_trim_extra_spaces
* Description : This Function used to remove extra space inbetween
* words and trailing spaces from the string
* Input(s) : string
* Output(s) : string
***************************************************************************/
int8_t occli_trim_extra_spaces(char *string)
{
int8_t length = 0;
char *end = NULL;
if (string == NULL) {
logerr("Invalid memory location \n");
return FAILED;
}
/* Logic to remove trailing spaces */
length = strlen(string);
end = string + length - 1;
while(end >= string && isblank(*end)) {
end--;
}
*(end + 1) = '\0';
return SUCCESS;
}
/**************************************************************************
* Function Name : occli_copy_text
* Description : This Function Return a copy of the string entered
by the user in cli
* Input(s) :
* Output(s) : s_strCli
***************************************************************************/
static int8_t occli_copy_text ()
{
int8_t ret = FAILED;
int16_t length;
if (isblank(rl_line_buffer[0])) {
printf("\nBlank Space is not allowed as the first character\n");
printf("Please press ctrl+L to clear screen\n");
return ret;
}
length = rl_point;
s_strCli = (char*)realloc(s_strCli, length + 1);
if (s_strCli == NULL) {
printf("\n ERROR: realloc");
} else {
ret = SUCCESS;
strncpy (s_strCli, rl_line_buffer, length);
s_strCli[length] = '\0';
}
if (ret == SUCCESS) {
ret = occli_trim_extra_spaces(s_strCli);
}
return ret;
}
/**************************************************************************
* Function Name : occli_init_subSetParams
* Description : This Function is used to allocate memory for
* subSetParams
* Input(s) : text
* Output(s) :
***************************************************************************/
static int8_t occli_init_subSetParams(const char *text)
{
char *paramStr = NULL;
int32_t len = 0;
int16_t listIdx = 0;
int16_t subsetIdx = 0;
if (text == NULL) {
logerr("Invalid memory location \n");
return FAILED;
}
if (s_subSetParams != NULL) {
for (listIdx = 0; (s_subSetParams[listIdx] != NULL &&
listIdx < OCCLI_MAX_SUBSTRING) ; listIdx++) {
free(s_subSetParams[listIdx]);
s_subSetParams[listIdx] = NULL;
}
}
len = strlen(text);
listIdx = 0;
while ((paramStr = s_allParams[listIdx])) {
if (strncmp(text, paramStr, len) == 0) {
subsetIdx++;
if(subsetIdx >= OCCLI_MAX_SUBSTRING) {
break;
}
}
listIdx++;
}
for (listIdx= 0; listIdx < subsetIdx; listIdx++) {
s_subSetParams[listIdx] = (char *)calloc(1, OCCLI_STRING_MAX_LEN);
if ((s_subSetParams[listIdx]) == NULL) {
logerr("calloc error");
return -ENOMEM;
}
}
return SUCCESS;
}
/**************************************************************************
* Function Name : occli_all_param_generator
* Description : This Function used to generate the all param
* list
* Input(s) : text, state
* Output(s) :
***************************************************************************/
static char* occli_all_param_generator(const char* text, int32_t state)
{
char *paramstr = NULL;
char *token = NULL;
char subStr[OCCLI_STRING_MAX_LEN] = {0};
char tempStr[OCCLI_STRING_MAX_LEN] = {0};
static int32_t s_listidx = 0;
static int32_t s_subSetIdx = 0;
static int32_t s_len = 0;
int8_t index = 0 ;
bool isEntryFound = false;
if (text == NULL) {
logerr("Invalid memory location \n");
rl_attempted_completion_over = 1;
return NULL;
}
if (state == 0) {
s_listidx = 0;
s_subSetIdx = 0;
s_len = strlen(text);
if (occli_init_subSetParams(text) != SUCCESS) {
rl_attempted_completion_over = 1;
return NULL;
}
}
while ((paramstr = s_allParams[s_listidx]) != NULL) {
isEntryFound = false;
s_listidx++;
if (strncmp(s_strCli, paramstr, s_len) == 0) {
strcpy(subStr, paramstr);
token = strtok(subStr + s_len, ".");
memset(tempStr, 0, OCCLI_STRING_MAX_LEN);
rl_completion_append_character = '\0';
if (token == NULL) {
/*
* case where the user has entered the complete string,
* autofill is not needed in this case , append a space
*/
sprintf(tempStr, "%s ", text);
} else {
/* Autofill will be needed in all cases here */
if (strncmp(text, "", 1) == 0) {
/* case where the user hasn't entered any string */
sprintf(tempStr, "%s", token);
} else if(strncmp(paramstr + s_len, "." , 1) == 0) {
/*
* case where the user has entered complete string
* for either subsystem/component (ie) "system"
*/
sprintf(tempStr, "%s.%s", text,token);
} else {
/*
* case where the user has entered subset of the string
* for example "sys"
*/
sprintf(tempStr, "%s%s", text,token);
}
}
/*
* The for loop below is to ensure that duplicate entries arent
* displayed in the cli
*/
for (index = 0; index < s_subSetIdx; index++) {
if (strcmp(s_subSetParams[index], tempStr) == 0) {
isEntryFound = true;
break;
}
}
if(isEntryFound != true) {
strcpy(s_subSetParams[s_subSetIdx], tempStr);
s_subSetIdx++;
return strdup(s_subSetParams[s_subSetIdx - 1]);
}
}
}
return NULL;
}
/**************************************************************************
* Function Name : occli_custom_completion
* Description : This Function used to handle the TAB operation
* Input(s) : text, start, end
* Output(s) :
***************************************************************************/
static char** occli_custom_completion(const char* text, int32_t start,
int32_t end)
{
char** matches = NULL;
int8_t ret = FAILED;
if (text == NULL) {
logerr("Invalid memory location \n");
rl_attempted_completion_over = 1;
return NULL;
}
ret = occli_copy_text();
if (ret != SUCCESS) {
rl_attempted_completion_over = 1;
return NULL;
}
if (start == 0) {
matches = rl_completion_matches(text, occli_all_param_generator);
} else {
rl_attempted_completion_over = 1;
}
return matches;
}
/**************************************************************************
* Function Name : occli_strjoin
* Description : This Function used to join the string
* Input(s) : srcstr, delimstr
* Output(s) : deststrPtr
***************************************************************************/
static int8_t occli_strjoin(char **deststrPtr, const char *srcstr,
const char *delimstr)
{
char *tmp;
const int32_t alloclen = OCCLI_STRING_SIZE;
size_t destSize, deststrLen, srcstrLen, delimstrLen;
if (deststrPtr == NULL || srcstr == NULL || delimstr == NULL) {
logerr("NULL pointer error");
return -EFAULT;
}
if (*deststrPtr == NULL) {
*deststrPtr = calloc(alloclen, sizeof(char));
if (*deststrPtr == NULL) {
logerr("calloc error");
return -ENOMEM;
}
deststrLen = strlen(*deststrPtr);
} else {
delimstrLen = strlen(delimstr);
srcstrLen = strlen(srcstr);
deststrLen = strlen(*deststrPtr);
destSize = ((deststrLen / alloclen) + 1) * alloclen;
if ((srcstrLen + delimstrLen + 1) > (destSize - deststrLen)) {
/* allocate more memory to concatenate the srcstr */
tmp = *deststrPtr;
*deststrPtr = realloc(*deststrPtr, destSize + alloclen);
if (*deststrPtr == NULL) {
logerr("realloc error");
free(tmp);
return -ENOMEM;
}
}
}
/* strcat the delimiting string to deststr, only when the deststr is not
an empty string */
if (deststrLen > 0) {
strcat(*deststrPtr, delimstr);
}
/* strcat the new string */
strcat(*deststrPtr, srcstr);
logdebug("*deststrPtr='%s'", *deststrPtr);
return SUCCESS;
}
/**************************************************************************
* Function Name : occli_alertthread_messenger_to_ocmw
* Description : This Function is used to handle the alert message
* Input(s) : pThreadData
* Output(s) :
***************************************************************************/
void * occli_alertthread_messenger_to_ocmw(void *pThreadData)
{
char response[RES_STR_BUFF_SIZE] = {0};
int32_t ret = 0;
/* Receive the CLI command execution response string from OCMW over UDP
* socket */
while (1) {
memset(response, 0, sizeof(response));
ret = occli_recv_alertmsg_from_ocmw(response, sizeof(response));
if (ret < 0) {
printf("occli_recv_alertmsg_from_ocmw failed: error value : %d\n", ret);
} else {
printf("%s\n", response);
}
}
}
/**************************************************************************
* Function Name : occli_parse_cliString
* Description : This Function is used to check the validity of the
* cli string
* Input(s) : cliString
* Output(s) : SUCCESS/FAILURE
***************************************************************************/
int8_t occli_parse_cliString(char *cliString)
{
int8_t ret = FAILED;
int16_t index = 0;
char tempStr[OCCLI_STRING_MAX_LEN] = {0};
char *token = NULL;
strcpy(tempStr, cliString);
token = strtok(tempStr, " ");
for(index = 0; ((index < OCCLI_MAX_CLISTRING) &&
(s_allParams[index] != NULL)); index++) {
if (strcmp(token, s_allParams[index]) == 0) {
ret = SUCCESS;
break;
}
}
return ret;
}
/**************************************************************************
* Function Name : occli_frame_commands
* Description : This Function is used to frame the cli commands
* Input(s) : root, occliData->option
* Output(s) : s_allParams, occliData->totalStr, occliData->sizeNum
***************************************************************************/
int8_t occli_frame_commands(const Component *root,
OCCLI_ARRAY_PARAM *occliData)
{
const Component *subSystem = root;
const Component *component = subSystem->components;
const Component *subComponent = NULL;
const Command *command = NULL;
const Driver *driver = NULL;
if ((root == NULL) ||
(occliData == NULL)) {
logerr("Invalid Memory \n");
return FAILED;
}
/* subsytem->component->command */
subSystem = root;
while (subSystem && subSystem->name) {
component = subSystem->components;
while (component && component->name) {
command = component->commands;
while (command &&
command->name) {
if (occliData->option == OCCLI_CALC_SCHEMA_SIZE) {
occliData->sizeNum += 1;
} else {
snprintf(s_allParams[occliData->totalStr++],
OCCLI_SNPRINTF_MAX_LEN, "%s.%s.%s",
subSystem->name, component->name, command->name);
}
command += 1;
}
component += 1;
}
subSystem += 1;
}
/* subsytem->component->driver->command */
subSystem = root;
while (subSystem && subSystem->name) {
component = subSystem->components;
while (component && component->name) {
driver = component->driver;
if(driver != NULL) {
command = driver->commands;
while (command &&
command->name) {
if (occliData->option == OCCLI_CALC_SCHEMA_SIZE) {
occliData->sizeNum += 1;
} else {
snprintf(s_allParams[occliData->totalStr++],
OCCLI_SNPRINTF_MAX_LEN, "%s.%s.%s",
subSystem->name, component->name,
command->name);
}
command += 1;
}
}
component += 1;
}
subSystem += 1;
}
/* subsytem->component->subComponent->driver->command */
subSystem = root;
while (subSystem && subSystem->name) {
component = subSystem->components;
while (component && component->name) {
subComponent = component->components;
while (subComponent && subComponent->name) {
driver = subComponent->driver;
if(driver != NULL) {
command = driver->commands;
while (command &&
command->name) {
if (occliData->option == OCCLI_CALC_SCHEMA_SIZE) {
occliData->sizeNum += 1;
} else {
snprintf(s_allParams[occliData->totalStr++],
OCCLI_STRING_MAX_LEN, "%s.%s.%s.%s",
subSystem->name, component->name,
subComponent->name, command->name);
}
command += 1;
}
}
subComponent += 1;
}
component += 1;
}
subSystem += 1;
}
return SUCCESS;
}
/**************************************************************************
* Function Name : occli_frame_string_from_schemaDriver
* Description : This Function is used to frame the cli string
* Input(s) : param, strFrame, msgTypeStr
* Output(s) : ocmwclistr, occliData
***************************************************************************/
int8_t occli_frame_string_from_schemaDriver(const Parameter *param,
OCCLI_ARRAY_PARAM *occliData,
strMsgFrame *strFrame)
{
if ((occliData == NULL) || (param == NULL) || (strFrame == NULL)) {
logerr("Invalid Memory \n");
return FAILED;
}
if (occliData->option == OCCLI_CALC_SCHEMA_SIZE) {
occliData->sizeNum += 1;
} else {
if (strlen(strFrame->subcomponent)) {
snprintf(s_allParams[occliData->totalStr++],
OCCLI_SNPRINTF_MAX_LEN, "%s.%s.%s.%s.%s.%s",
strFrame->subsystem, strFrame->component,
strFrame->msgtype, strFrame->subcomponent,
param->name, strFrame->parameter);
} else {
snprintf(s_allParams[occliData->totalStr++],
OCCLI_SNPRINTF_MAX_LEN, "%s.%s.%s.%s.%s",
strFrame->subsystem, strFrame->component,
strFrame->msgtype, param->name, strFrame->parameter);
}
}
return SUCCESS;
}
// TO use for POST
/**************************************************************************
* Function Name : occli_frame_string_from_postDriver
* Description : This Function is used to frame the cli string
* Input(s) : param, strFrame, msgTypeStr
* Output(s) : ocmwclistr, occliData
***************************************************************************/
int8_t occli_frame_string_from_postDriver(const Post *param,
OCCLI_ARRAY_PARAM *occliData,
strMsgFrame *strFrame)
{
if ((occliData == NULL) || (param == NULL) || (strFrame == NULL)) {
logerr("Invalid Memory \n");
return FAILED;
}
if (occliData->option == OCCLI_CALC_SCHEMA_SIZE) {
occliData->sizeNum += 1;
} else {
if (strlen(strFrame->subcomponent)) {
snprintf(s_allParams[occliData->totalStr++],
OCCLI_SNPRINTF_MAX_LEN, "%s.%s.%s.%s.%s.%s",
strFrame->subsystem, strFrame->component,
strFrame->msgtype, strFrame->subcomponent,
param->name, strFrame->parameter);
} else {
snprintf(s_allParams[occliData->totalStr++],
OCCLI_SNPRINTF_MAX_LEN, "%s.%s.%s.%s.%s",
strFrame->subsystem, strFrame->component,
strFrame->msgtype, param->name, strFrame->parameter);
}
}
return SUCCESS;
}
/**************************************************************************
* Function Name : occli_frame_string_from_schema
* Description : This Function is used to frame the cli string
* Input(s) : devDriver, strFrame
* Output(s) : ocmwclistr, occliData
***************************************************************************/
int8_t occli_frame_string_from_schema(const Driver *devDriver,
OCCLI_ARRAY_PARAM *occliData,
strMsgFrame *strFrame)
{
const Post *postParam = NULL;
const Parameter *param = NULL;
int8_t ret = SUCCESS;
if ((devDriver == NULL) || (occliData == NULL) || (strFrame == NULL)) {
logerr("Invalid Memory \n");
return FAILED;
}
postParam = devDriver->post;
while (postParam && postParam->name) {
strcpy(strFrame->msgtype, "post");
if (strncmp(postParam->name, "enable", strlen(postParam->name)) == 0) {
strcpy(strFrame->parameter, "set");
} else {
strcpy(strFrame->parameter, "get");
}
ret = occli_frame_string_from_postDriver(postParam, occliData, strFrame);
postParam++;
}
param = devDriver->config;
while (param && param->name) {
strcpy(strFrame->msgtype, "config");
strcpy(strFrame->parameter, "set");
ret = occli_frame_string_from_schemaDriver(param, occliData, strFrame);
strcpy(strFrame->parameter, "get");
ret = occli_frame_string_from_schemaDriver(param, occliData, strFrame);
param++;
}
param = devDriver->status;
while (param && param->name) {
strcpy(strFrame->msgtype, "status");
strcpy(strFrame->parameter, "get");
ret = occli_frame_string_from_schemaDriver(param, occliData, strFrame);
param++;
}
#ifdef OCCLI_ALERT_STRING
param = devDriver->alerts;
strcpy(strFrame->msgtype, "alert");
ret = occli_frame_string_from_schemaDriver(param, occliData, strFrame);
#endif
return ret;
}
/**************************************************************************
* Function Name : occli_frame_string
* Description : This Function is used to frame the cli string
* Input(s) : root
* Output(s) : ocmwclistr, occliData
***************************************************************************/
int8_t occli_frame_string(const Component *root, OCCLI_ARRAY_PARAM *occliData)
{
const Component *component = NULL, *subComponent = NULL, *subSystem = root;
const Driver *devDriver = NULL;
int8_t ret = 0;
strMsgFrame *strFrame = (strMsgFrame *) malloc(sizeof(strMsgFrame));
if ((strFrame == NULL) || (root == NULL) ||
(occliData == NULL)) {
logerr("Invalid Memory \n");
return FAILED;
}
/* Config/Status/Alerts Table array entry Creation */
while (subSystem && subSystem->name) {
memset(strFrame, '\0', sizeof(strMsgFrame));
strcpy(strFrame->subsystem, subSystem->name);
component = subSystem->components;
while (component && component->name) {
memset(strFrame->subcomponent, '\0', OCCLI_CHAR_ARRAY_SIZE);
strcpy(strFrame->component, component->name);
devDriver = component->driver;
if (devDriver != NULL) {
ret = occli_frame_string_from_schema(devDriver,
occliData, strFrame);
if (ret == FAILED) {
return ret;
}
}
subComponent = component->components;
while (subComponent && subComponent->name) {
strcpy(strFrame->subcomponent, subComponent->name);
devDriver = subComponent->driver;
if (devDriver != NULL) {
ret = occli_frame_string_from_schema(devDriver,
occliData, strFrame);
if (ret == FAILED) {
return ret;
}
}
subComponent += 1;
}
component += 1;
}
subSystem += 1;
}
free(strFrame);
return SUCCESS;
}
/**************************************************************************
* Function Name : main
* Description :
* Input(s) : argc, argv
* Output(s) :
***************************************************************************/
int32_t main(int32_t argc, char *argv[])
{
char *line = NULL;
char *clistr = NULL;
char response[RES_STR_BUFF_SIZE] = {0};
char historyFile[HIT_FILE_BUFF_SIZE];
char *cmdstr = NULL;
const char* prompt = "opencellular# ";
int32_t index = 0;
int32_t ret = 0;
pthread_t alertThreadId;
sMsgParam msgFrameParam;
OCCLI_ARRAY_PARAM occliArray;
/* Initialize logging */
initlog("occli");
memset(&msgFrameParam, 0, sizeof(sMsgParam));
memset (&occliArray, 0, sizeof(OCCLI_ARRAY_PARAM));
occliArray.option = OCCLI_CALC_SCHEMA_SIZE;
ret = occli_frame_string(sys_schema, &occliArray);
if (ret != 0) {
logerr("init_ocmw_comm() failed.");
return FAILED;
}
ret = occli_frame_commands(sys_schema, &occliArray);
if (ret != 0) {
logerr("init_ocmw_comm() failed.");
return FAILED;
}
for (index= 0; index< occliArray.sizeNum; index++) {
if(!(s_allParams[index] = (char *)malloc(OCCLI_STRING_MAX_LEN))) {
return FAILED;
}
}
occliArray.option = OCCLI_PARSE_SCHEMA;
ret = occli_frame_string(sys_schema, &occliArray);
if (ret != 0) {
logerr("init_ocmw_comm() failed.");
return FAILED;
}
ret = occli_frame_commands(sys_schema, &occliArray);
if (ret != 0) {
logerr("init_ocmw_comm() failed.");
return FAILED;
}
/* Initialize Middleware IPC communication */
ret = occli_init_comm();
if (ret != 0) {
logerr("init_ocmw_comm() failed.");
return FAILED;
}
/* Execute the OC command (argv[1:]) and exit */
if (strcmp("occmd", basename(argv[0])) == 0) {
for (index= 1; index < argc; index++) {
if (occli_strjoin(&cmdstr, argv[index], " ") != 0) {
logerr("occli_strjoin error");
break;
}
}
ret = occli_parse_cliString(cmdstr);
if (ret != SUCCESS) {
printf("%s : Error : Invalid String\n", cmdstr);
free(cmdstr);
cmdstr = NULL;
}
if (cmdstr != NULL) {
logdebug("cmdstr='%s'", cmdstr);
occli_send_cmd_to_ocmw(cmdstr, strlen(cmdstr));
memset(response, 0, sizeof(response));
occli_recv_cmd_resp_from_ocmw(response, sizeof(response));
printf("%s\n", response);
free(cmdstr);
} else {
printf("internal error\n");
}
}
/* Entering interactive CLI */
else if (strcmp("occli", basename(argv[0])) == 0) {
ret = pthread_create(&alertThreadId, NULL,
occli_alertthread_messenger_to_ocmw, NULL);
if (ret != 0) {
return ret;
}
/* Initialize readline */
using_history();
if ((snprintf(historyFile, HIT_FILE_BUFF_SIZE, "%s/%s", getenv("HOME"),
HISTORY)) < 0) {
return FAILED;
}
read_history(historyFile);
rl_attempted_completion_function = occli_custom_completion;
/*Printing hints at the start of opencelluar */
occli_print_opencelluar();
while (1) {
line = readline(prompt);
if (line == NULL) {
break;
}
clistr = line;
/* trim initial white spaces */
while (isblank(*clistr)) {
++clistr;
}
occli_trim_extra_spaces(clistr);
if (strcmp(clistr, "") == 0) {
continue;
}
/* Quit the CLI, when command 'quit' is received */
if (strcmp(clistr, "quit") == 0) {
free(line);
break;
}
/* Print the help manu */
if((strstr(clistr, "help"))) {
if ((strstr(clistr, "--help"))) {
ret = occli_printHelpMenu(sys_schema, clistr);
if (ret == FAILED) {
logerr("occli_printHelpMenu failed.\n");
}
continue;
} else {
printf("%s : Error : Incorrect request\n", clistr);
printf ("Usage : subsystem --help"
" OR subsystem.component --help\n");
continue;
}
}
ret = occli_parse_cliString(clistr);
if (ret != SUCCESS) {
printf("%s : Error : Invalid String\n", clistr);
continue;
}
add_history(clistr);
occli_send_cmd_to_ocmw(clistr, strlen(clistr));
memset(response, 0, sizeof(response));
occli_recv_cmd_resp_from_ocmw(response, sizeof(response));
/* Print the command execution results in the CLI */
printf("%s\n", response);
free(line);
}
write_history(historyFile);
}
for (index= 0; ((s_allParams[index] != NULL) &&
(index < OCCLI_MAX_CLISTRING)); index++) {
free(s_allParams[index]);
}
for (index= 0; ((s_subSetParams[index] != NULL) &&
(index < OCCLI_MAX_SUBSTRING)); index++) {
free(s_subSetParams[index]);
}
occli_deinit_comm();
deinitlog();
return SUCCESS;
}

View File

@@ -0,0 +1,192 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/* stdlib includes */
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdbool.h>
#include <errno.h>
#include <pthread.h>
#include <unistd.h>
#include <util.h>
#include <logger.h>
/* OC includes */
#include <ocmw_socket_comm.h>
#include <occli_common.h>
static int32_t s_sockFd = 0;
static int32_t s_alertSockFd = 0;
static struct sockaddr_in s_siServer, s_alertServer;
static char s_displayStr[OCCLI_SNPRINTF_MAX_LEN];
/**************************************************************************
* Function Name : occli_init_comm
* Description : This Function used to initialize the communication
* between middleware code
* Input(s) :
* Output(s) :
***************************************************************************/
int32_t occli_init_comm(void)
{
int32_t ret = 0;
int32_t inetAtonRet = 0;
struct timeval timeValObj;
timeValObj.tv_sec = OCCLI_TIMEOUT_PERIOD;
timeValObj.tv_usec = 0;
/* Create socket */
s_sockFd = socket(OCMW_SOCK_DOMAIN, OCMW_SOCK_TYPE, OCMW_SOCK_PROTOCOL);
if (s_sockFd < 0) {
ret = -errno;
logerr("socket creation error [%d-%s]", errno, strerror(errno));
return ret;
}
/* Initialize socket structure */
memset(&s_siServer, 0, sizeof(s_siServer));
s_siServer.sin_family = OCMW_SOCK_DOMAIN;
s_siServer.sin_port = htons(OCMW_SOCK_SERVER_PORT);
inetAtonRet = inet_aton(OCMW_SOCK_SERVER_IP, &s_siServer.sin_addr);
if (inetAtonRet == 0) {
logerr("inet_aton failed");
ret = FAILED;
return ret;
}
if (setsockopt(s_sockFd, SOL_SOCKET, SO_RCVTIMEO,
&timeValObj, sizeof(timeValObj)) < 0) {
logerr("setsockopt failed");
ret = FAILED;
return ret;
}
/* For Alert Capture */
s_alertSockFd = socket(OCMW_SOCK_ALERT_DOMAIN, OCMW_SOCK_ALERT_TYPE,
OCMW_SOCK_ALERT_PROTOCOL);
if (s_alertSockFd < 0) {
ret = -errno;
logerr("socket creation error [%d-%s]", errno, strerror(errno));
return ret;
}
/* Initialize socket structure */
memset(&s_alertServer, 0, sizeof(s_alertServer));
s_alertServer.sin_family = OCMW_SOCK_ALERT_DOMAIN;
s_alertServer.sin_port = htons(OCMW_SOCK_ALERT_SERVER_PORT);
inetAtonRet = inet_aton(OCMW_SOCK_ALERT_SERVER_IP, &s_alertServer.sin_addr);
if (inetAtonRet == 0) {
logerr("inet_aton failed");
ret = FAILED;
return ret;
}
/* Bind host address to the socket */
ret = bind(s_alertSockFd, (struct sockaddr*) &s_alertServer,
sizeof(s_alertServer));
if (ret < 0) {
ret = -errno;
logerr("bind error [%d-%s]", errno, strerror(errno));
return ret;
}
return SUCCESS;
}
/**************************************************************************
* Function Name : occli_deinit_comm
* Description : This Function used to deinitialize the communication
* betwwen middleware code
* Input(s) :
* Output(s) :
***************************************************************************/
int8_t occli_deinit_comm(void)
{
/* Close the IPC socket */
close(s_sockFd);
s_sockFd = 0;
return SUCCESS;
}
/**************************************************************************
* Function Name : occli_send_cmd_to_ocmw
* Description : This Function used to send command to middleware
* Input(s) : cmd, cmdlen
* Output(s) :
***************************************************************************/
int32_t occli_send_cmd_to_ocmw(const char *cmd, int32_t cmdlen)
{
char errstr[OCMW_SOCKET_ERROR_SIZE];
int32_t ret = 0;
int32_t strLen = sizeof(s_siServer);
strncpy(s_displayStr, cmd, cmdlen);
/* Send the CLI command string to OCMW over UDP socket */
ret = sendto(s_sockFd, cmd, cmdlen, 0,
(const struct sockaddr *) &s_siServer, strLen);
if (ret < 0) {
strerror_r(errno, errstr, OCMW_SOCKET_ERROR_SIZE);
logerr("Error: 'sendto' [%d-%s]", errno, errstr);
printf("%s : Error : Socket error", s_displayStr);
}
return ret;
}
/**************************************************************************
* Function Name : occli_recv_cmd_resp_from_ocmw
* Description : This Function used to receive message from middlware
* Input(s) :
* Output(s) : resp, resplen
***************************************************************************/
int32_t occli_recv_cmd_resp_from_ocmw(char *resp, int32_t resplen)
{
char errstr[OCMW_SOCKET_ERROR_SIZE];
int32_t ret = 0;
int32_t strLen = sizeof(s_siServer);
/* Receive the CLI command execution response string from OCMW over UDP
socket */
ret = recvfrom(s_sockFd, resp, resplen, 0,
(struct sockaddr*) &s_siServer, (socklen_t*) &strLen);
if (ret < 0) {
strerror_r(errno, errstr, OCMW_SOCKET_ERROR_SIZE);
logerr("Error: 'recvfrom' [%d-%s]", ret, errstr);
printf("%s : Error : Timeout from Middleware", s_displayStr);
}
return ret;
}
/**************************************************************************
* Function Name : occli_recv_alertmsg_from_ocmw
* Description : This Function used to receive alert message from
* middleware
* Input(s) :
* Output(s) : resp, resplen
***************************************************************************/
int32_t occli_recv_alertmsg_from_ocmw(char *resp, int32_t resplen)
{
char errstr[OCMW_SOCKET_ERROR_SIZE];
int32_t ret = 0;
int32_t strLen = sizeof(s_alertServer);
/* Receive the Alert Message string from OCMW over UDP socket */
ret = recvfrom(s_alertSockFd, resp, resplen, 0,
(struct sockaddr*) &s_alertServer, (socklen_t*) &strLen);
if (ret < 0) {
strerror_r(errno, errstr, OCMW_SOCKET_ERROR_SIZE);
logerr("Error: 'recvfrom' [%d-%s]", ret, errstr);
printf("Error: 'recvfrom' [%d-%s]", ret, errstr);
}
return ret;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,818 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/* OC includes */
#include <logger.h>
#include <ocmw_core.h>
#include <ocmw_eth_comm.h>
#include <ocmw_uart_comm.h>
#include <ocwdg_daemon.h>
#include <postframe.h>
#include <occli_common.h>
#include <ocmw_occli_comm.h>
static int32_t loopCountPost = 0;
extern debugI2CData I2CInfo;
extern debugMDIOData MDIOInfo;
extern uint8_t mcuMsgBuf[OCMP_MSG_SIZE];
extern ocmwSchemaSendBuf *ecSendBufBkp;
int32_t responseCount = 0;
static int8_t s_paramInfoBackup[MAX_PARM_COUNT];
static int32_t s_semTimeOut;
static int32_t s_totalSubsystem = 0;
extern const Component sys_schema[];
subSystemInfo systemInfo;
extern ocwarePostResultData ocwarePostArray[TEMP_STR_BUFF_SIZE];
extern uint8_t ocwarePostArrayIndex;
ocwarePostReplyCode ocmwReplyCode[] = {
/* Message Type, reply code, Description */
{OCMP_MSG_TYPE_POST, POST_DEV_NOSTATUS , "POST DEV NOSTATUS"},
{OCMP_MSG_TYPE_POST, POST_DEV_MISSING, "DEV MISSING"},
{OCMP_MSG_TYPE_POST, POST_DEV_ID_MISMATCH, "DEV ID MISMATCH"},
{OCMP_MSG_TYPE_POST, POST_DEV_FOUND, "DEV FOUND"},
{OCMP_MSG_TYPE_POST, POST_DEV_CFG_DONE, "CFG DONE"},
{OCMP_MSG_TYPE_POST, POST_DEV_NO_CFG_REQ, "NO CFG REQUIRED"},
{OCMP_MSG_TYPE_POST, POST_DEV_CFG_FAIL, "CFG FAILED"},
{OCMP_MSG_TYPE_POST, POST_DEV_FAULTY, "FAULT"},
{OCMP_MSG_TYPE_POST, POST_DEV_CRITICAL_FAULT, "CRITICAL FAULT"},
{OCMP_MSG_TYPE_POST, POST_DEV_NO_DRIVER_EXIST, "NO DRIVER EXIST"}
};
/******************************************************************************
* Function Name : ocmw_free_global_pointer
* Description : This Function used to free the memory allocated for
* global variable
* Input(s) : ptr
* Output(s) :
******************************************************************************/
inline void ocmw_free_global_pointer(void **ptr)
{
if(*ptr != NULL) {
free(*ptr);
*ptr = NULL;
}
return;
}
/******************************************************************************
* Function Name : ocmw_retrieve_post_results_count
* Description : This Function used to count the post structure size
* Input(s) : postResult
* Output(s) :
******************************************************************************/
char ocmw_retrieve_post_results_count (ocwarePostResults *postResult)
{
postResult->count =
sizeof(ocwarePostArray)/sizeof(ocwarePostArray[0]);
return SUCCESS;
}
/******************************************************************************
* Function Name : ocmw_retrieve_post_results
* Description : This Function used to get the post results
* Input(s) : postResult
* Output(s) :
******************************************************************************/
char ocmw_retrieve_post_results (ocwarePostResults *postResult)
{
memcpy(postResult->results, ocwarePostArray,
postResult->count * sizeof(ocwarePostResultData));
memset(ocwarePostArray,0,sizeof(ocwarePostResultData));
return SUCCESS;
}
/******************************************************************************
* Function Name : ocmw_retrieve_reply_code_desc
* Description : This Function used to get the reply code based the post
result data
* Input(s) : replyCode
* Output(s) :
******************************************************************************/
char ocmw_retrieve_reply_code_desc (ocwarePostReplyCode *replyCode)
{
int32_t postSize = 0;
int32_t sysIndex = 0;
postSize = sizeof(ocmwReplyCode)/sizeof(ocmwReplyCode[0]);
for (sysIndex = 0; sysIndex < postSize; sysIndex++) {
if ((ocmwReplyCode[sysIndex].msgtype == replyCode->msgtype) &&
(ocmwReplyCode[sysIndex].replycode == replyCode->replycode)) {
memset(replyCode->desc, 0, OCMW_POST_DESC_SIZE);
strncpy(replyCode->desc, ocmwReplyCode[sysIndex].desc,
strlen(ocmwReplyCode[sysIndex].desc));
}
}
return SUCCESS;
}
/******************************************************************************
* Function Name : ocmw_update_post_status
* Description : This Function used to update the post results
* Input(s) : subsystem, devsn, status
* Output(s) :
******************************************************************************/
char ocmw_update_post_status(uint8_t subsystem, uint8_t devsn,
uint8_t status)
{
int32_t sysIndex = 0;
for (sysIndex = 0; sysIndex < ocwarePostArrayIndex; sysIndex++) {
if ((ocwarePostArray[sysIndex].subsystem == subsystem) &&
(ocwarePostArray[sysIndex].devsn == devsn)) {
ocwarePostArray[sysIndex].status = status;
}
}
return SUCCESS;
}
/******************************************************************************
* Function Name : ocmw_init
* Description : This Function used to initialize the mware
* Input(s) :
* Output(s) :
******************************************************************************/
int32_t ocmw_init()
{
#ifdef INTERFACE_ETHERNET
pthread_t ethMsgPaserThreadId;
#else
pthread_t uartMsgPaserThreadId;
#endif
int32_t ret = 0;
ret = sem_init(&semecMsgParser, 0, 0);
if (ret != 0) {
logerr("sem_init(): semecMsgParser failed.");
return ret;
}
ret = ocwdg_init();
if (ret != 0) {
logerr("ocwdg_init() failed.");
return ret;
}
ret = sem_init(&semCliReturn, 0, 0);
if (ret != 0) {
logerr("sem_init(): semCliReturn failed.");
return ret;
}
ret = sem_init(&semCommandPost, 0, 0);
if (ret != 0) {
logerr("sem_init(): semCommandPost failed.");
return ret;
} else {
#ifdef INTERFACE_ETHERNET
/* Create the msg parser thread to parse
* the msg coming from ethernet ec to ap
*/
ret = pthread_create(&ethMsgPaserThreadId, NULL,
ocmw_thread_ethmsgparser, NULL);
if (ret != 0) {
return ret;
}
#else
/* Create the msg parser thread to parse
* the msg coming from uart ec to ap
*/
ret = pthread_create(&uartMsgPaserThreadId, NULL,
ocmw_thread_uartmsgparser, NULL);
if (ret != 0) {
logerr("pthread_create() failed.");
}
#endif /* INTERFACE_ETHERNET */
}
return ret;
}
/**************************************************************************
* Function Name : ocmw_tokenize_class_str
* Description : This Function used to extract the Subsystem,componentID, Messagetype,
* parameter and Subcomponent from the param string
* Input(s) : str
* Output(s) : msgFrame
***************************************************************************/
static int32_t ocmw_tokenize_class_str( const int8_t *str,
strMsgFrame *msgFrame, uint8_t msgtype)
{
char *token;
int32_t count = 0;
char *tempstr = (char *)malloc(PARAM_STR_MAX_BUFF_SIZE);
if(str == NULL)
return FAILED;
memset(tempstr,0,PARAM_STR_MAX_BUFF_SIZE);
memcpy(tempstr, str,PARAM_STR_MAX_BUFF_SIZE);
memset(msgFrame,0,sizeof(strMsgFrame));
token = strtok(tempstr, " .");
if (token == NULL)
return FAILED;
if (msgtype == OCMP_MSG_TYPE_COMMAND) {
if ((strcmp(token,"set") != 0) &&
((strcmp(token,"get") != 0))) {
strcpy(msgFrame->parameter, token);
while (token) {
if (count == 1) {
strcpy(msgFrame->subsystem, token);
} else if (count == 2) {
strcpy(msgFrame->component, token);
}
token = strtok(NULL, " .");
count ++;
if (token == NULL)
break;
}
if (count == 2) {
strcpy(msgFrame->component, "comp_all");
}
} else {
while (token) {
if (count == 1) {
strcpy(msgFrame->subsystem, token);
} else if (count == 2) {
strcpy(msgFrame->component, token);
} else if (count == 3) {
strcpy(msgFrame->subcomponent, token);
} else if (count == 0) {
strcpy(msgFrame->parameter, token);
}
token = strtok(NULL, " .");
count ++;
if (token == NULL)
break;
}
if (count == 2) {
strcpy(msgFrame->component, "comp_all");
}
}
} else {
strcpy(msgFrame->subsystem, token);
while (token) {
if (count == 1) {
strcpy(msgFrame->component, token);
} else if (count == 2) {
strcpy(msgFrame->msgtype, token);
} else if (count == 3) {
strcpy(msgFrame->subcomponent, token);
} else if(count == 4) {
strcpy(msgFrame->parameter, token);
}
token = strtok(NULL, " .");
count++;
}
if (count < 5) {
strcpy(msgFrame->parameter, msgFrame->subcomponent);
}
if (strncmp (msgFrame->component, "post", strlen("post")) == 0) {
strcpy(msgFrame->component, "post");
strcpy(msgFrame->msgtype, "post");
strcpy(msgFrame->parameter, msgFrame->subcomponent);
}
}
free(tempstr);
return SUCCESS;
}
/******************************************************************************
* Function Name : ocmw_fill_payload_data_for_commands
* Description : Packetize the msg payload for commands
* Input(s) :strTokenArray, msgFrame, ecMsgFrame, paramVal
* Output(s) :
******************************************************************************/
void ocmw_fill_payload_data_for_commands(char * strTokenArray[],
strMsgFrame *msgFrame, OCMPMessageFrame *ecMsgFrame, void* paramVal)
{
if (msgFrame == NULL) {
return;
}
// Handling sending data for test module
if (strncmp("testmodule", msgFrame->subsystem,
strlen(msgFrame->subsystem)) == 0 ) {
if ((strncmp(strTokenArray[1], "send", strlen("send")) == 0) ||
(strncmp(strTokenArray[1], "dial", strlen("dial")) == 0)) {
memcpy(&ecMsgFrame->message.info[0], paramVal,
MAX_PARM_COUNT);
} else {
memset(ecMsgFrame->message.info, 0, MAX_PARM_COUNT);
}
}
// Handling ethernet packet genrator command
if (strncmp("ethernet", msgFrame->subsystem,
strlen(msgFrame->subsystem)) == 0 ) {
if(strstr(strTokenArray[1], "loopBk")) {
memcpy(&ecMsgFrame->message.info[0], paramVal, sizeof(uint8_t));
} else if ((strncmp(strTokenArray[1], "en_pktGen",
strlen("en_pktGen")) == 0)) {
memcpy(&ecMsgFrame->message.info[0],
(uint16_t *)paramVal, sizeof(uint16_t));
}
}
}
/******************************************************************************
* Function Name : ocmw_msg_packetize_and_send
* Description : Packetize the msg frame before sending data to ec
* Input(s) :actionType, msgType, paramStr, interface, paramVal
* Output(s) :
******************************************************************************/
int32_t ocmw_msg_packetize_and_send(char * strTokenArray[], uint8_t action,
uint8_t msgType, const int8_t * paramStr, uint8_t interface, void* paramVal)
{
int32_t ret = 0;
int32_t paramValue = 0;
int32_t dataSize = 0;
int32_t pos = 0;
int32_t paramValLen = 0;
int32_t paramValFlag = 0;
const int8_t *tempStr = paramStr;
strMsgFrame msgFramestruct;
OCMPMessageFrame ecMsgFrame;
OCMPHeader ecMsgHeader;
OCMPMessage ecCoreMsg;
static int32_t loopCountSend = 0;
ocmwSchemaSendBuf ecSendBuf;
paramValLen = strlen((char *)paramVal);
if (!((msgType == OCMP_MSG_TYPE_COMMAND) &&
((strncmp(strTokenArray[1], "get", strlen("get")) == 0) ||
(strncmp(strTokenArray[1], "set", strlen("get")) == 0)))) {
if (paramValLen == 1 || paramValLen <= 5) {
logdebug ("Paramvalue is of integer type : %d\n", atoi( paramVal));
}
else {
paramValFlag = 1;
logdebug ("Paramvalue is of string type : %s \n", (char *)paramVal);
}
} else {
paramValFlag = 1;
logdebug ("Paramvalue is of string type : %s \n", (char *)paramVal);
}
if (paramStr == NULL) {
logdebug(" Paramstr is NULL \n");
return ret = FAILED;
} else {
ocmw_tokenize_class_str(tempStr,&msgFramestruct,msgType);
if (msgType == OCMP_MSG_TYPE_COMMAND) {
ret = ocmw_parse_command_msgframe(sys_schema, &msgFramestruct,
action, &ecSendBuf);
} else if (msgType == OCMP_MSG_TYPE_POST) {
strcpy((char*)s_paramInfoBackup,msgFramestruct.parameter);
ret = ocmw_parse_post_msgframe(sys_schema, &msgFramestruct,
action, &ecSendBuf);
} else {
ret = ocmw_parse_msgframe(sys_schema, &msgFramestruct, action,
&ecSendBuf);
}
if (ret < 0) {
return ret;
}
}
/* Frame the header packet for sending data to ec */
ecMsgHeader.ocmpFrameLen = 0;
ecMsgHeader.ocmpInterface = interface;
ecMsgHeader.ocmpSeqNumber = 0;
ecMsgHeader.ocmpSof = OCMP_MSG_SOF;
ecMsgHeader.ocmpTimestamp = 0;
/* Frame the Core packet for sending data to ec */
ecCoreMsg.action = ecSendBuf.actionType;
ecCoreMsg.msgtype = ecSendBuf.msgType;
ecCoreMsg.componentID = ecSendBuf.componentId;
ecCoreMsg.parameters = ecSendBuf.paramId;
ecCoreMsg.subsystem = ecSendBuf.subsystem;
/* Construct the final packet */
ecMsgFrame.header = ecMsgHeader;
ecMsgFrame.message = ecCoreMsg;
/* Populate the Core packet payload */
ecMsgFrame.message.info = (int8_t *) malloc(
sizeof(int8_t) * MAX_PARM_COUNT);
if (ecMsgFrame.message.info == NULL) {
logdebug("\n Memory allocation failed \n");
return ret = FAILED;
}
memset(ecMsgFrame.message.info, 0, MAX_PARM_COUNT);
if ((msgType == OCMP_MSG_TYPE_POST) &&
(strncmp(strTokenArray[1], "set", strlen("set"))== 0)) {
logdebug("OCMP_MSG_TYPE_POST:ENABLE:%s()\n", __func__);
}
if(strncmp(msgFramestruct.subsystem,"debug",strlen("debug")) == 0) {
if (strncmp(msgFramestruct.component,"I2C",
strlen("I2C")) == 0) {
if((strncmp(strTokenArray[1], "get", strlen("get")) == 0)) {
dataSize = 3 * sizeof (int8_t);
} else {
dataSize = sizeof(debugI2CData);
}
} else if (strncmp(msgFramestruct.component,"ethernet",
strlen("ethernet")) == 0) {
if((strncmp(strTokenArray[1], "get", strlen("get")) == 0)) {
dataSize = sizeof (uint16_t);
} else {
dataSize = sizeof(debugMDIOData);
}
} else {
if((strncmp(strTokenArray[1], "get", strlen("get")) == 0)) {
dataSize = sizeof (int8_t);
} else {
dataSize = sizeof(debugGPIOData);
}
}
paramValLen = dataSize;
} else {
dataSize = ecSendBuf.paramSize;
}
if((strncmp(strTokenArray[1], "set", strlen("set")) == 0) &&
(msgType != OCMP_MSG_TYPE_POST)) {
pos = ecSendBuf.paramPos;
if (paramValFlag == 0) {
paramValue = atoi( paramVal);
memcpy(&ecMsgFrame.message.info[pos], &paramValue, dataSize);
} else {
if (strncmp(msgFramestruct.component,"I2C",
strlen("I2C")) == 0) {
ecMsgFrame.message.info[pos] = I2CInfo.slaveAddress;
ecMsgFrame.message.info[pos + 1] =
I2CInfo.numOfBytes;
ecMsgFrame.message.info[pos + 2] =
I2CInfo.regAddress;
if (I2CInfo.numOfBytes == 1) {
ecMsgFrame.message.info[pos + 3] =
(uint8_t)I2CInfo.regValue;
} else {
ecMsgFrame.message.info[pos + 4] =
(uint8_t)(I2CInfo.regValue & 0xff);
ecMsgFrame.message.info[pos + 3] =
(uint8_t)
((I2CInfo.regValue & 0xff00) >> 8);
}
} else if (strncmp(msgFramestruct.component,"ethernet",
strlen("ethernet")) == 0) {
ecMsgFrame.message.info[pos] = (uint8_t)
(MDIOInfo.regAddress & 0xff);
ecMsgFrame.message.info[pos + 1] = (uint8_t)
((MDIOInfo.regAddress & 0xff00) >> 8);
ecMsgFrame.message.info[pos + 2] =
(uint8_t)(MDIOInfo.regValue & 0xff);
ecMsgFrame.message.info[pos + 3] =
(uint8_t)
((MDIOInfo.regValue & 0xff00) >> 8);
} else {
memcpy(&ecMsgFrame.message.info[pos], (char *) paramVal,
paramValLen);
}
}
}
if((strncmp(strTokenArray[1], "get", strlen("get")) == 0) &&
(ecMsgFrame.message.subsystem == DEBUG_SUBSYSTEM_NBR)) {
pos = ecSendBuf.paramPos;
memcpy(&ecMsgFrame.message.info[pos], (char *) paramVal,
paramValLen);
}
//Fill payload data for commands
ocmw_fill_payload_data_for_commands(&strTokenArray[0], &msgFramestruct,
&ecMsgFrame, paramVal);
if (!((msgType == OCMP_MSG_TYPE_POST) &&
(strncmp(strTokenArray[1], "get", strlen("get")) == 0))) {
ocmw_send_msg(ecMsgFrame, interface);
}
/* Wait on the POST msgtype semaphore */
if ((msgType == OCMP_MSG_TYPE_POST) &&
((strncmp(strTokenArray[1], "get", strlen("get")) == 0))) {
ocmw_frame_subsystem_from_schema(sys_schema, &systemInfo);
s_totalSubsystem = systemInfo.totalNum;
ocmw_frame_postTable_from_schema(sys_schema);
loopCountSend = systemInfo.Info[0].number;
loopCountPost = systemInfo.Info[0].number;
while(loopCountSend < s_totalSubsystem) {
memset(&(ecMsgFrame.message.info[0]),
loopCountSend, 1);
/* Send the message to ec */
ocmw_send_msg(ecMsgFrame, interface);
loopCountSend++;
/* Waiting on the lock to be released by receiving thread */
ret = ocmw_sem_wait(&semCommandPost, OCMW_TIMED_WAIT_INDEX);
if (ret != 0) {
perror("sem_wait");
}
/*
* Logic to check if firmware has sent post data currently we
* expect only actiontype mismatch other errors can be taken care
* as required
*/
if (loopCountSend != loopCountPost) {
logerr("POST: Error : Actiontype mismatch in message from FW");
free(ecMsgFrame.message.info);
return FAILED;
}
}
loopCountPost = systemInfo.Info[0].number;
loopCountSend = systemInfo.Info[0].number;
}
free(ecMsgFrame.message.info);
/* Semaphore wait function call */
ret = ocmw_sem_wait(&semCliReturn, OCMW_TIMED_WAIT_INDEX);
if (ret == FAILED) {
logdebug("Message is not received from EC: releasing the lock \n");
return ret;
}
if (responseCount == 0) {
ret = FAILED;
} else {
ret = 0;
responseCount = 0;
}
logdebug(" \n Semaphore released : %s() \n", __func__);
return ret;
}
/******************************************************************************
* Function Name : ocmw_thread_uartmsgparser
* Description : Thread to parse the data coming from EC to AP
* through uart communication
* Input(s) : pthreadData
* Output(s) :
******************************************************************************/
void * ocmw_thread_uartmsgparser(void *pthreadData)
{
logdebug("Uart task created \n");
while (1) {
/* Waiting on the semecMsgParser to be released by uart */
sem_wait(&semecMsgParser);
ocmw_ec_msgparser();
}
}
/******************************************************************************
* Function Name : ocmw_thread_ethmsgparser
* Description : Thread to parse the data coming from EC to AP
* through ethernet communication
* Input(s) : pthreadData
* Output(s) :
******************************************************************************/
void * ocmw_thread_ethmsgparser(void *pthreadData)
{
int8_t ethRecvBuf[OCMP_MSG_SIZE] = {0};
logdebug("Ethernet task created \n");
while (1) {
memset(ethRecvBuf, 0, sizeof(ethRecvBuf));
ocmw_recv_eth_msgfrom_ec(ethRecvBuf, sizeof(ethRecvBuf),OCMW_EC_DEV);
ocmw_ec_msgparser();
}
}
/******************************************************************************
* Function Name : ocmw_ec_msgparser
* Description : parse the data coming from EC to AP
* Input(s) :
* Output(s) :
******************************************************************************/
void ocmw_ec_msgparser(void)
{
uint8_t msgType = 0;
uint8_t actionType = 0;
uint8_t subsystemPost = 0;
uint8_t devsn = 0;
uint8_t status = 0;
uint8_t indexCount = 0;
uint16_t paramInfo = 0;
int32_t ret = 0;
int32_t sendPktNonpayloadSize = 0;
sMsgParam dmsgFrameParam;
OCMPMessageFrame ecReceivedMsg;
sendPktNonpayloadSize = (sizeof(OCMPMessage) - sizeof(void *)
+ sizeof(OCMPHeader));
ecReceivedMsg.message.info = (void *) malloc(
sizeof(char) * MAX_PARM_COUNT);
if (ecReceivedMsg.message.info == NULL) {
logerr("Memory allocation failed for "
"ecReceivedMsg.message.info \n");
return;
}
/* parse the data packet */
memcpy((void *) &ecReceivedMsg, (void *) mcuMsgBuf, sendPktNonpayloadSize);
memcpy(ecReceivedMsg.message.info, &mcuMsgBuf[sendPktNonpayloadSize],
MAX_PARM_COUNT);
msgType = ecReceivedMsg.message.msgtype;
actionType = ecReceivedMsg.message.action;
paramInfo = ecReceivedMsg.message.parameters;
/*
* TODO:Temporary fix for handling alerts
*/
if (msgType == OCMP_MSG_TYPE_ALERT) {
free(ecReceivedMsg.message.info);
return;
}
printf("Received from ec :\n");
for (indexCount = 0; indexCount < OCMP_MSG_SIZE; indexCount++) {
printf("0x%x ", mcuMsgBuf[indexCount]);
}
printf("\n");
/* In case of timeout, return from the thread
* without processing the data to avoid sync issue.
*/
if (s_semTimeOut) {
s_semTimeOut = 0;
ocmw_free_global_pointer((void**)&ecSendBufBkp);
return;
}
if ((msgType == OCMP_MSG_TYPE_POST) &&
strcmp((char*)s_paramInfoBackup,"set") == 0) {
if (actionType == OCMP_AXN_TYPE_REPLY) {
responseCount++;
}
/* Release the lock on which cli is waiting */
ocmw_free_global_pointer((void**)&ecSendBufBkp);
sem_post(&semCliReturn);
return;
}
/* Release the lock on the POST msgtype semaphore */
if (msgType == OCMP_MSG_TYPE_POST) {
if (actionType != OCMP_AXN_TYPE_REPLY) {
ocmw_free_global_pointer((void**)&ecSendBufBkp);
ret = sem_post(&semCommandPost);
if (ret != 0) {
perror("sem_wait");
}
return;
}
for (; loopCountPost < s_totalSubsystem;) {
/* Waiting on the lock to be released by receiving thread */
for (indexCount = 0; indexCount < paramInfo; indexCount++) {
subsystemPost = ecReceivedMsg.message.info[indexCount
* POST_MAIN_PAYLOAD_SIZE
+ POST_MAIN_PAYLOAD_SUBSYSTEM_OFFSET];
devsn = ecReceivedMsg.message.info[indexCount
* POST_MAIN_PAYLOAD_SIZE
+ POST_MAIN_PAYLOAD_DEVSN_OFFSET];
status = ecReceivedMsg.message.info[indexCount
* POST_MAIN_PAYLOAD_SIZE
+ POST_MAIN_PAYLOAD_STATUS_OFFSET];
ret = ocmw_update_post_status(subsystemPost, devsn, status);
}
loopCountPost++;
ret = sem_post(&semCommandPost);
if (ret != 0) {
perror("sem_wait");
}
if (loopCountPost < s_totalSubsystem) {
/* Do Nothing */
} else {
/* Release the lock on which watchdog thread is waiting */
responseCount++;
ocmw_free_global_pointer((void**)&ecSendBufBkp);
sem_post(&semCliReturn);
}
return;
}
}
memset(&dmsgFrameParam, 0, sizeof(sMsgParam));
ocmw_deserialization_msgframe(sys_schema, &dmsgFrameParam, &ecReceivedMsg);
/* Released the lock so that cli is released from the lock */
if (ecReceivedMsg.message.info) {
free(ecReceivedMsg.message.info);
}
sem_post(&semCliReturn);
}
/******************************************************************************
* Function Name : ocmw_send_msg
* Description : Send the message from ap to ec via uart/usb/ethernet.
* Input(s) : ecMsgFrame, interface
* Output(s) :
******************************************************************************/
int32_t ocmw_send_msg(OCMPMessageFrame ecMsgFrame, uint8_t interface)
{
int32_t ret = 0;
int32_t sentDev = OCMW_EC_DEV;
#ifdef INTERFACE_STUB_EC
int8_t ethRecvBuf[OCMP_MSG_SIZE];
#endif
switch (interface) {
case OCMP_COMM_IFACE_UART:
case OCMP_COMM_IFACE_USB:
/* Send the packetize data to ec through uart*/
ret = ocmw_send_uart_msg_to_ec((uint8_t *) &ecMsgFrame,
OCMP_MSG_SIZE);
break;
case OCMP_COMM_IFACE_ETHERNET:
sentDev = OCMW_EC_DEV;
#ifdef INTERFACE_STUB_EC
sentDev = OCMW_EC_STUB_DEV;
#else
sentDev = OCMW_EC_DEV;
#endif
/* Send the packetize data to ec through ethernet*/
ret = ocmw_send_eth_msgto_ec((int8_t *) &ecMsgFrame,
OCMP_MSG_SIZE, sentDev);
#ifdef INTERFACE_STUB_EC
memset(ethRecvBuf, 0, sizeof(ethRecvBuf));
ocmw_recv_eth_msgfrom_ec(ethRecvBuf, sizeof(ethRecvBuf), OCMW_EC_STUB_DEV);
ocmw_ec_msgparser();
#endif
break;
case OCMP_COMM_IFACE_SBD:
break;
default:
break;
}
if (ret != 0) {
logerr("ocmw_send_msg() failed \n");
}
return ret;
}
/******************************************************************************
* Function Name : ocmw_sem_wait
* Description : semaphore wait function to wait either for infinite time
* or for timeout period.
* Input(s) : semId, semWaitType
* Output(s) :
******************************************************************************/
int32_t ocmw_sem_wait(sem_t *semId, int32_t semWaitType)
{
int32_t ret = 0;
struct timespec timeSpecObj;
if (semId == NULL) {
logerr("Invalid semId \n");
ret = FAILED;
return ret;
}
if (semWaitType == OCMW_BUSY_WAIT_INDEX) {
/* Waiting on the lock to be released by receiving thread */
ret = ocmw_sem_wait_nointr(semId);
if (ret != 0) {
perror("sem_wait");
}
} else if (semWaitType == OCMW_TIMED_WAIT_INDEX) {
ret = clock_gettime(CLOCK_REALTIME, &timeSpecObj);
if (ret != 0) {
perror("clock_gettime");
}
timeSpecObj.tv_sec += OCMW_SEM_WAIT_TIME;
timeSpecObj.tv_nsec += 0;
ret = ocmw_sem_timedwait_nointr(semId, &timeSpecObj);
if (ret != 0) {
if (errno == ETIMEDOUT) {
logdebug("sem_timedwait() timed out\n");
} else {
perror("sem_timedwait");
}
logdebug("Message is not received from EC: releasing the lock \n");
s_semTimeOut = 1;
}
} else {
printf("Invalid param \n");
}
return ret;
}

View File

@@ -0,0 +1,236 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/* stdlib includes */
#include <util.h>
#include <logger.h>
/* OC includes */
#include <ocmp_frame.h>
#include <ocmw_core.h>
#include <ocmw_eth_comm.h>
#include <ocmw_socket_comm.h>
#define OCMW_ERR_STR_LEN 80
#define OCWARE_STUB_TIMEOUT_PERIOD 12
extern uint8_t mcuMsgBuf[OCMP_MSG_SIZE];
static int32_t comSockfd = 0, stub_sockfd = 0;
static struct sockaddr_in sicomServer, stub_server;
/**************************************************************************
* Function Name : ocmw_init_eth_comm
* Description : This Function used to initialize the ethernet
* communication
* Input(s) :
* Output(s) :
***************************************************************************/
int32_t ocmw_init_eth_comm(int32_t sentDev)
{
int32_t rc = 0;
int32_t inetAton = 0;
printf("Ethernet init start \n");
struct timeval timeValObj;
timeValObj.tv_sec = OCWARE_STUB_TIMEOUT_PERIOD;
timeValObj.tv_usec = 0;
if (sentDev == OCMW_EC_DEV){
/* Create socket */
comSockfd = socket(OCMW_ETH_SOCK_DOMAIN, OCMW_ETH_SOCK_TYPE,
OCMW_ETH_SOCK_PROTOCOL);
if (comSockfd < 0) {
rc = -errno;
logerr("socket creation error [%d-%s]", errno, strerror(errno));
}
/* Initialize socket structure */
memset(&sicomServer, 0, sizeof(sicomServer));
sicomServer.sin_family = OCMW_ETH_SOCK_DOMAIN;
sicomServer.sin_port = htons(OCMW_ETH_SOCK_SERVER_PORT);
inetAton = inet_aton(OCMW_ETH_SOCK_SERVER_IP, &sicomServer.sin_addr);
if (inetAton == 0) {
printf("inet_aton failed");
rc = -1;
}
rc = connect(comSockfd, (struct sockaddr *) &sicomServer,
sizeof(sicomServer));
if (rc != 0) {
perror("socket connect failed:");
}
if (rc != 0) {
ocmw_deinit_eth_comm(OCMW_EC_DEV);
} else {
printf("Ehernet init finished \n");
}
} else {
/* Create socket */
stub_sockfd = socket(OCMW_SOCK_STUB_DOMAIN, OCMW_SOCK_STUB_TYPE,
OCMW_SOCK_STUB_PROTOCOL);
if (stub_sockfd < 0) {
rc = -errno;
logerr("socket creation error [%d-%s]", errno, strerror(errno));
}
/* Initialize socket structure */
memset(&stub_server, 0, sizeof(stub_server));
stub_server.sin_family = OCMW_SOCK_STUB_DOMAIN;
stub_server.sin_port = htons(OCMW_SOCK_STUB_SERVER_PORT);
stub_server.sin_addr.s_addr = inet_addr(OCMW_SOCK_SERVER_IP);
inetAton = inet_aton(OCMW_SOCK_STUB_SERVER_IP, &stub_server.sin_addr);
if (inetAton == 0) {
printf("inet_aton failed");
rc = -1;
}
if (setsockopt(stub_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeValObj,
sizeof(timeValObj)) < 0) {
logerr("setsockopt failed");
rc = -1;
return rc;
}
if (rc != 0) {
ocmw_deinit_eth_comm(OCMW_EC_STUB_DEV);
} else {
printf("Ehernet init finished \n");
}
}
return rc;
}
/**************************************************************************
* Function Name : ocmw_deinit_eth_comm
* Description : This Function used to uninitialize the ethernet
* communication
* Input(s) :
* Output(s) :
***************************************************************************/
int32_t ocmw_deinit_eth_comm( int sentDev)
{
if (sentDev == OCMW_EC_DEV){
close(comSockfd);
comSockfd = 0; /* Close the IPC socket */
} else {
close(stub_sockfd);
stub_sockfd = 0; /* Close the IPC socket */
}
return 0;
}
/**************************************************************************
* Function Name : ocmw_send_eth_msgto_ec
* Description : This Function used to send the message to ec
* Input(s) : cmd, cmdlen
* Output(s) :
***************************************************************************/
int32_t ocmw_send_eth_msgto_ec(const int8_t *cmd, int32_t cmdlen, int sentDev)
{
const int32_t errstrLen = OCMW_ERR_STR_LEN;
char errstr[errstrLen];
uint8_t buf[OCMP_MSG_SIZE];
int32_t rc = 0;
int32_t loopCount = 0;
int32_t sendPktNonpayloadSize = 0;
OCMPMessageFrame *ecMsgFrame;
if (cmd == NULL) {
logerr("Error: Memory allocation problem");
return -1;
}
if (cmdlen > OCMP_MSG_SIZE) {
logerr("Error: msgstr size is more than %d bytes", OCMP_MSG_SIZE);
return -EMSGSIZE;
}
ecMsgFrame = (OCMPMessageFrame *) cmd;
sendPktNonpayloadSize = (sizeof(OCMPMessage) - sizeof(void *)
+ sizeof(OCMPHeader));
/* create message frame */
memset(buf, 0, sizeof(buf));
memcpy(buf, ecMsgFrame, sendPktNonpayloadSize);
memcpy(&buf[sendPktNonpayloadSize], ((ecMsgFrame->message).info),
MAX_PARM_COUNT);
#ifndef MSG_LOG
printf(" \n send_msg_to_ec \n");
for (loopCount = 0; loopCount < OCMP_MSG_SIZE; loopCount++) {
printf("0x%x ", buf[loopCount] & 0x00ff);
}
printf("\n");
#endif /* MSG_LOG */
if (sentDev == OCMW_EC_DEV){
rc = send(comSockfd, buf, OCMP_MSG_SIZE, 0);
if (rc < 0) {
strerror_r(errno, errstr, errstrLen);
logerr("Error: 'send' [%d-%s]", errno, errstr);
}
} else {
rc = sendto(stub_sockfd, buf, OCMP_MSG_SIZE, 0,
(struct sockaddr *) &stub_server, sizeof(stub_server) );
if (rc < 0) {
strerror_r(errno, errstr, errstrLen);
logerr("Error: 'send' [%d-%s]", errno, errstr);
}
}
return rc;
}
/**************************************************************************
* Function Name : ocmw_recv_eth_msgfrom_ec
* Description : This Function used to receive the ec message
* Input(s) :
* Output(s) : resp, resplen
***************************************************************************/
int32_t ocmw_recv_eth_msgfrom_ec(int8_t *resp, int32_t resplen, int sentDev)
{
#if defined(INTERFACE_STUB_EC) || defined(INTERFACE_ETHERNET)
const int32_t errstrLen = OCMW_ERR_STR_LEN;
char errstr[errstrLen];
#endif
int32_t rc = 0;
int32_t loopCount = 0;
#ifdef INTERFACE_STUB_EC
int32_t dataLen = sizeof(stub_server);
#endif
/*
* Receive the CLI command execution response string from OCMW over
* UDP socket
*/
#ifdef INTERFACE_ETHERNET
rc = recv(comSockfd, resp, resplen, 0);
if (rc < 0) {
strerror_r(rc, errstr, errstrLen);
logerr("Error: 'recv' [%d-%s]", rc, errstr);
}
#endif
#ifdef INTERFACE_STUB_EC
rc = recvfrom(stub_sockfd, resp, OCMP_MSG_SIZE, 0,
(struct sockaddr *) &stub_server,
(socklen_t*)&dataLen);
if (rc < 0) {
strerror_r(rc, errstr, errstrLen);
logerr("Error: 'recv' [%d-%s]", rc, errstr);
printf("\n Error: Recv from in OCWARE_STUB");
}
#endif
/* Store the ethernet msg into global buffer */
memcpy(mcuMsgBuf, resp, resplen);
printf("Message received from ec via ethernet :\n");
for (loopCount = 0; loopCount < resplen; loopCount++) {
printf("0x%x ", (0xff) & resp[loopCount]);
}
printf("\n");
return rc;
}

View File

@@ -0,0 +1,156 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/* OC includes */
#include <ocmw_core.h>
#include <ocmw_eth_comm.h>
#include <ocmw_uart_comm.h>
#include <ocwdg_daemon.h>
#include <logger.h>
#include <ocmw_occli_comm.h>
#define SIZE_INT sizeof (int32_t)
int8_t eepromStatusFlag = 0;
/******************************************************************************
* Function Name : ocmw_sem_wait_nointr
* Description : static inline function for avoiding interruption caused
* to sem_wait() library call
* Input(s) : sem
* Output(s) :
******************************************************************************/
inline int32_t ocmw_sem_wait_nointr(sem_t *sem)
{
while (sem_wait(sem))
if (errno == EINTR)
errno = 0;
else
return -1;
return SUCCESS;
}
/******************************************************************************
* Function Name : ocmw_sem_timedwait_nointr
* Description : static inline function for avoiding interruption caused
* to sem_timedwait() library call
* Input(s) : sem, timeout
* Output(s) :
******************************************************************************/
inline int32_t ocmw_sem_timedwait_nointr(sem_t *sem,
const struct timespec *timeout)
{
while (sem_timedwait(sem, timeout))
if (errno == EINTR)
errno = 0;
else
return -1;
return SUCCESS;
}
/******************************************************************************
* Function Name : ocmw_dataparsing_from_db
* Description : This Function used to parase the data from db
* Input(s) : paramIndex, paramSizebuf
* Output(s) : dataSize, pos
******************************************************************************/
void ocmw_dataparsing_from_db(int32_t paramIndex, int32_t *paramSizebuf,
int32_t *dataSize, int32_t *pos)
{
int32_t count;
int32_t paramIdPresence;
int32_t loc;
count = 0;
paramIdPresence = 0;
loc = 0;
if ((paramSizebuf == NULL) || (dataSize == NULL) || (pos == NULL)) {
return;
}
*dataSize = 0;
*pos = 0;
for (count = 0; count < MAX_PARM_COUNT; count++) {
paramIdPresence = (paramIndex) / ((int) pow(2, count));
if (paramIdPresence == 1) {
break;
}
else {
loc = loc + paramSizebuf[count];
}
}
*dataSize = paramSizebuf[count];
*pos = loc;
}
/******************************************************************************
* Function Name : ocmw_dataparsing_from_ec
* Description : This Function used to parse the uart message from ec
* Input(s) : input, bufParamStruct
* Output(s) :
******************************************************************************/
void ocmw_dataparsing_from_ec(ocmwSendRecvBuf *input,
bufParam * bufParamStruct)
{
int32_t count = 0;
int32_t paramIdPresence = 0;
int32_t pos = 0;
int32_t paramidSize = 0;
int32_t index = 0;
if ((input == NULL) || (bufParamStruct == NULL)) {
printf("Memory address is invalid : %s()\n", __func__);
return;
}
int16_t paramInfo = input->paramInfo;
int32_t numOfele = input->numOfele;
int8_t *pbuf = input->pbuf;
int32_t *paramSizebuf = input->paramSizebuf;
for (count = 0; count < numOfele; count++) {
bufParamStruct[count].paramindex = (paramInfo & ((int32_t) pow(2,
count + index)));
paramIdPresence = bufParamStruct[count].paramindex / pow(2,
count + index);
if (paramIdPresence == 0) {
paramidSize = 0;
} else {
paramidSize = paramSizebuf[count];
}
switch (paramidSize) {
case VOID:
bufParamStruct[count].paramval = 0;
break;
case CHAR:
bufParamStruct[count].paramval = *((int8_t *) &pbuf[pos]);
break;
case SHORT:
bufParamStruct[count].paramval = *((int16_t *) &pbuf[pos]);
break;
case INT:
bufParamStruct[count].paramval = *((int32_t *) &pbuf[pos]);
break;
default:
return;
break;
}
}
}

View File

@@ -0,0 +1,94 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/* stdlib includes */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdint.h>
/* OC includes */
#include <logger.h>
#include <ocmw_uart_comm.h>
#include <ocmw_core.h>
#include <ocmw_occli_comm.h>
#include <ocmw_eth_comm.h>
uint8_t mcuMsgBuf[OCMP_MSG_SIZE];
/**************************************************************************
* Function Name : main
* Description :
* Input(s) : argc, argv
* Output(s) :
***************************************************************************/
int32_t main(int32_t argc, char **argv)
{
char cmdstr[CMD_STR_BUFF_SIZE] = {0};
char response[RES_STR_BUFF_SIZE] = {0};
int32_t ret = 0;
/* Initialize logging */
initlog("ocmw");
ret = ocmw_init_occli_comm();
if (ret != 0) {
logerr("init_occli_comm() failed.");
return FAILED;
}
/* Initialize UART for EC communication */
ret = ocmw_init_ec_comm(&ocmw_ec_uart_msg_hndlr);
if (ret != 0) {
logerr("ocmw_init_ec_comm() failed.");
return FAILED;
}
#ifdef INTERFACE_ETHERNET
ret = ocmw_init_eth_comm(OCMW_EC_DEV);
if(ret != 0) {
printf ("ocmw_init_eth_comm() failed \n");
return FAILED;
}
#endif /* INTERFACE_ETHERNET */
#ifdef INTERFACE_STUB_EC
ret = ocmw_init_eth_comm(OCMW_EC_STUB_DEV);
if(ret != 0) {
printf ("init_eth_comm() failed \n");
return FAILED;
}
#endif /* INTERFACE_ETHERNET */
ret = ocmw_init();
if (ret != 0) {
logerr("ocmw_init() failed.");
return FAILED;
}
while (1) {
memset(cmdstr, 0, sizeof(cmdstr));
memset(response, 0, sizeof(response));
ret = ocmw_recv_clicmd_from_occli(cmdstr, sizeof(cmdstr));
if (ret == FAILED)
continue; /* retry on error */
ocmw_clicmd_handler(cmdstr, response);
ocmw_send_clicmd_resp_to_occli(response, strlen(response));
}
ocmw_deinit_occli_comm();
ocmw_deinit_occli_alert_comm();
ocmw_deinit_ec_comm();
deinitlog();
return SUCCESS;
}

View File

@@ -0,0 +1,43 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <logger.h>
#include "ocmw_core.h"
#include "ocmw_msgproc.h"
#include "ocmp_frame.h"
/**************************************************************************
* Function Name : ocmw_msgproc_send_msg
* Description : This Function configures the header
* Input(s) : strTokenArray, action, msgtype, paramstr
* Output(s) : paramvalue
***************************************************************************/
int ocmw_msgproc_send_msg(char * strTokenArray[], uint8_t action,
int8_t msgtype, const int8_t* paramstr, void *paramvalue)
{
int32_t ret = 0;
uint8_t interface = 0;
#if defined(INTERFACE_STUB_EC) || defined(INTERFACE_ETHERNET)
interface = OCMP_COMM_IFACE_ETHERNET;
#elif INTERFACE_USB
interface = OCMP_COMM_IFACE_USB;
#else
interface = OCMP_COMM_IFACE_UART;
#endif /* INTERFACE_ETHERNET */
ret = ocmw_msg_packetize_and_send(&strTokenArray[0], action, msgtype,
paramstr, interface, paramvalue);
if (ret != 0) {
logerr("ocmw_msg_packetize_and_send failed \n");
}
return ret;
}

View File

@@ -0,0 +1,185 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/* stdlib includes */
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <errno.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <pthread.h>
#include <util.h>
#include <logger.h>
/* OC includes */
#include <ocmw_socket_comm.h>
#include <ocmw_occli_comm.h>
#include <ocmw_core.h>
static int32_t s_ssockFd = 0;
static struct sockaddr_in s_siServer, s_siClient;
static int32_t s_ssockfdAlert = 0;
static struct sockaddr_in s_siServerAlert;
/**************************************************************************
* Function Name : ocmw_init_occli_comm
* Description : This Function used to initialize the cli communication
* Input(s) :
* Output(s) :
***************************************************************************/
int32_t ocmw_init_occli_comm()
{
int32_t ret = 0;
/* Create socket */
s_ssockFd = socket(OCMW_SOCK_DOMAIN, OCMW_SOCK_TYPE, OCMW_SOCK_PROTOCOL);
if (s_ssockFd < 0) {
ret = -errno;
logerr("socket creation error [%d-%s]", errno, strerror(errno));
return ret;
}
/* Initialize socket structure */
memset(&s_siServer, 0, sizeof(s_siServer));
s_siServer.sin_family = OCMW_SOCK_DOMAIN;
s_siServer.sin_addr.s_addr = INADDR_ANY;
s_siServer.sin_port = htons(OCMW_SOCK_SERVER_PORT);
/* Bind host address to the socket */
ret = bind(s_ssockFd, (struct sockaddr*) &s_siServer, sizeof(s_siServer));
if (ret < 0) {
ret = -errno;
logerr("bind error [%d-%s]", errno, strerror(errno));
return ret;
}
if (ret != 0) {
ocmw_deinit_occli_comm();
return ret;
}
/***** Alert related socket init *****/
/* Create socket */
s_ssockfdAlert = socket(OCMW_SOCK_DOMAIN, OCMW_SOCK_TYPE,
OCMW_SOCK_PROTOCOL);
if (s_ssockfdAlert < 0) {
ret = -errno;
logerr("socket creation error [%d-%s]", errno, strerror(errno));
return ret;
}
if (ret != 0) {
ocmw_deinit_occli_alert_comm();
} else {
/* Initialize socket structure */
memset(&s_siServerAlert, 0, sizeof(s_siServerAlert));
s_siServerAlert.sin_family = OCMW_SOCK_DOMAIN;
s_siServerAlert.sin_addr.s_addr = INADDR_ANY;
s_siServerAlert.sin_port = htons(OCMW_SOCK_SERVER_ALERT_PORT);
}
return ret;
}
/**************************************************************************
* Function Name : ocmw_deinit_occli_comm
* Description : This Function used to deinitialize the cli communication
* Input(s) :
* Output(s) :
***************************************************************************/
int32_t ocmw_deinit_occli_comm(void)
{
close(s_ssockFd);
s_ssockFd = 0; /* Close the IPC socket */
return SUCCESS;
}
/**************************************************************************
* Function Name : ocmw_deinit_occli_alert_comm
* Description : This Function used deinitialize the alert communication
* Input(s) :
* Output(s) :
***************************************************************************/
int32_t ocmw_deinit_occli_alert_comm(void)
{
close(s_ssockfdAlert);
s_ssockfdAlert = 0; /* Close the IPC socket */
return SUCCESS;
}
/**************************************************************************
* Function Name : ocmw_send_clicmd_resp_to_occli
* Description : This Function used to send command response to cli
* Input(s) : buf, buflen
* Output(s) :
***************************************************************************/
int32_t ocmw_send_clicmd_resp_to_occli(const char* buf, int32_t buflen)
{
char errstr[OCMW_SOCKET_ERROR_SIZE];
int32_t ret = 0;
int32_t destLen = sizeof(s_siClient);
/* Send the message buffer over IPC */
ret = sendto(s_ssockFd, buf, buflen, 0,
(const struct sockaddr *) &s_siClient, destLen);
if (ret == -1) {
strerror_r(errno, errstr, OCMW_SOCKET_ERROR_SIZE);
logerr("Error: 'sendto' [%d-%s]", errno, errstr);
}
return ret; /* error or number of bytes sent */
}
/**************************************************************************
* Function Name : ocmw_recv_clicmd_from_occli
* Description : This Function used to recv the command from cli
* Input(s) : buflen
* Output(s) : buf
***************************************************************************/
int32_t ocmw_recv_clicmd_from_occli(char* buf, int32_t buflen)
{
char errstr[OCMW_SOCKET_ERROR_SIZE];
int32_t ret = 0;
int32_t destLen = sizeof(s_siClient);
/* Receive oc messages from other processes */
ret = recvfrom(s_ssockFd, buf, buflen, 0,
(struct sockaddr*) &s_siClient, (socklen_t*) &destLen);
if (ret <= 0) {
strerror_r(errno, errstr, OCMW_SOCKET_ERROR_SIZE);
logerr("Error: 'recvfrom' [%d-%s]", errno, errstr);
ret = -1;
}
return ret; /* error or number of bytes received */
}
/**************************************************************************
* Function Name : ocmw_send_alert_to_occli
* Description : This Function used to send alerts to cli
* Input(s) : buf, buflen
* Output(s) :
***************************************************************************/
int32_t ocmw_send_alert_to_occli(const char* buf, int32_t buflen)
{
char errstr[OCMW_SOCKET_ERROR_SIZE];
int32_t ret = 0;
int32_t destLen = sizeof(s_siServerAlert);
/* Send the message buffer over IPC */
ret = sendto(s_ssockfdAlert, buf, buflen, 0,
(const struct sockaddr *) &s_siServerAlert, destLen);
if (ret == -1) {
strerror_r(errno, errstr, OCMW_SOCKET_ERROR_SIZE);
logerr("Error: 'sendto' [%d-%s]", errno, errstr);
}
return ret; /* error or number of bytes sent */
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,312 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/* stdlib includes */
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <sys/signal.h>
#include <pthread.h>
#include <stdbool.h>
#include <util.h>
#include <logger.h>
/* OC includes */
#include <ocmw_core.h>
#include <ocmw_uart_comm.h>
#include <ocmp_frame.h>
static int32_t s_fd = 0;
struct termios s_oldtio;
static handle_msg_from_ec_t s_uart_msg_hndlr = NULL;
static void sa_handler_read(int32_t status);
static bool S_STOP_UART_RX_SERVICE = true;
static pthread_t s_uartrxthread;
static volatile bool s_waitForUartMsg = true;
extern uint8_t mcuMsgBuf[OCMP_MSG_SIZE];
/**************************************************************************
* Function Name : ocmw_ec_uart_msg_hndlr
* Description : This Function used to handle uart messages
* Input(s) : msgstr, msgsize
* Output(s) :
***************************************************************************/
void ocmw_ec_uart_msg_hndlr(const unsigned char* msgstr, int32_t msgsize)
{
/* Process the OC message received from EC */
if (msgsize > OCMP_MSG_SIZE) {
logerr("message size is more than %d bytes", OCMP_MSG_SIZE);
return;
}
/* Store the uart msg into global buffer */
memcpy(mcuMsgBuf, msgstr, msgsize);
/* Signal the msg parser for ec uart msg */
sem_post(&semecMsgParser);
return;
}
/**************************************************************************
* Function Name : ocmw_recv_uart_msg_service
* Description : This Function used to receive uart messages
* Input(s) :
* Output(s) : args
***************************************************************************/
static void* ocmw_recv_uart_msg_service(void* args)
{
unsigned char msg[OCMP_MSG_SIZE] = {0};
unsigned char buf[OCMP_MSG_SIZE] = {0};
int32_t ret = 0;
const unsigned int msglen = OCMP_MSG_SIZE;
while (!S_STOP_UART_RX_SERVICE) {
/* Receive UART messages from EC */
if (s_waitForUartMsg) {
usleep(10);
continue;
}
s_waitForUartMsg = true;
/* Read message frame from tty */
memset(msg, 0, msglen);
memset(buf, 0, OCMP_MSG_SIZE);
ret = read(s_fd, msg, msglen);
if (ret < 0) {
logerr("Error reading from %s (%d - %s)", ECTTY, errno,
strerror(errno));
continue;
}
if (memcmp(msg, buf, OCMP_MSG_SIZE) == 0) {
continue; /* Not a valid UART message */
}
/* printf("Data from EC:\n"); */
/* hexdisp(msg, msglen); */
if (s_uart_msg_hndlr != NULL) {
(*s_uart_msg_hndlr)(msg, msglen);
}
}
return NULL;
}
/**************************************************************************
* Function Name : sa_handler_read
* Description : This Function used to read the handler
* Input(s) : status
* Output(s) :
***************************************************************************/
static void sa_handler_read(int32_t status)
{
s_waitForUartMsg = false;
return;
}
/**************************************************************************
* Function Name : ocmw_init_ec_comm
* Description : This Function used to initialize the ec communication
* Input(s) : msghndlr
* Output(s) :
***************************************************************************/
int32_t ocmw_init_ec_comm(handle_msg_from_ec_t msghndlr)
{
char pathName[100] = {0};
int32_t ret = 0;
struct termios newtio;
struct sigaction saio;
memset(pathName, 0, sizeof(pathName));
#ifdef INTERFACE_USB
ret = ocmw_find_ttyacm_port(pathName);
if (ret != 0) {
return ret;
}
#else
memcpy(pathName, (char *) ECTTY, sizeof(ECTTY));
#endif
/*
* Open the HSUART-1 port for communicating with EC
*
* O_NOCTTY - Not an interactive console
* O_NONBLOCK - Read need not be a blocking call
*/
s_fd = open(pathName, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (s_fd == -1) {
if (s_fd == -1) {
logerr("Error opening %s (%d - %s)", ECTTY, errno,
strerror(errno));
return -1;
}
}
/* Install signal handler for asynchronous read */
saio.sa_handler = sa_handler_read;
sigemptyset(&saio.sa_mask);
saio.sa_flags = SA_RESTART;
saio.sa_restorer = NULL;
sigaction(SIGIO, &saio, NULL);
/* Allow this process to receive SIGIO */
fcntl(s_fd, F_SETOWN, getpid());
/* Set file descriptor to handle asynchronous reads */
fcntl(s_fd, F_SETFL, O_ASYNC);
tcgetattr(s_fd, &s_oldtio);
memset(&newtio, 0, sizeof(newtio));
cfsetispeed(&newtio, B115200); /* Baud rate = 115200 */
cfsetospeed(&newtio, B115200);
newtio.c_cflag &= ~PARENB; /* No parity check */
newtio.c_cflag &= ~CSTOPB; /* 1 STOP bit */
newtio.c_cflag &= ~CSIZE; /* 8 DATA bits */
newtio.c_cflag |= CS8;
newtio.c_cflag &= ~CRTSCTS; /* No HW flow control */
/* Enable always. CREAD - Enable receiver.
* CLOCAL - program doesn't own the tty. */
newtio.c_cflag |= (CLOCAL | CREAD);
newtio.c_cc[VTIME] = 10; /* Inter character TIME=t*0.1s, where t=10. */
newtio.c_cc[VMIN] = 0; //33; /* EC message frame size = 32 bytes */
newtio.c_iflag &= ~(IXON | IXOFF | IXANY); /* No SW flow control */
newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
newtio.c_oflag &= ~OPOST;
tcflush(s_fd, TCIFLUSH);
tcsetattr(s_fd, TCSANOW, &newtio);
S_STOP_UART_RX_SERVICE = false;
ret = pthread_create(&s_uartrxthread, NULL, ocmw_recv_uart_msg_service,
NULL);
if (ret != 0) {
logerr("pthread creation failed [%d-%s]", errno, strerror(errno));
} else {
s_uart_msg_hndlr = msghndlr;
}
if (ret != 0) {
ocmw_deinit_ec_comm();
}
return ret;
}
/**************************************************************************
* Function Name : ocmw_deinit_ec_comm
* Description : This Function used to deinitialize the ec communication
* Input(s) :
* Output(s) :
***************************************************************************/
int32_t ocmw_deinit_ec_comm(void)
{
S_STOP_UART_RX_SERVICE = true;
tcsetattr(s_fd, TCSANOW, &s_oldtio);
if (s_fd > 0) {
close(s_fd);
s_fd = 0;
}
if (s_uart_msg_hndlr != NULL) {
s_uart_msg_hndlr = NULL;
}
return SUCCESS;
}
/**************************************************************************
* Function Name : ocmw_send_uart_msg_to_ec
* Description : This Function used to send uart message to ec
* Input(s) : msgstr, msgsize
* Output(s) :
***************************************************************************/
int32_t ocmw_send_uart_msg_to_ec(const uint8_t* msgstr, int32_t msgsize)
{
uint8_t buf[OCMP_MSG_SIZE] = {0};
int32_t ret = 0, bufWriteCount = 0;
int32_t sendPktNonpayloadSize = 0;
int32_t loopCount = 0;
OCMPMessageFrame *ecMsgFrame;
ecMsgFrame = (OCMPMessageFrame *) msgstr;
sendPktNonpayloadSize = (sizeof(OCMPMessage) - sizeof(void *)
+ sizeof(OCMPHeader));
if (msgstr == NULL) {
logerr("Error: Memory allocation problem");
return -1;
}
if (msgsize > OCMP_MSG_SIZE) {
logerr("Error: msgstr size is more than %d bytes", OCMP_MSG_SIZE);
return -EMSGSIZE;
}
/* create message frame */
memset(buf, 0, sizeof(buf));
memcpy(buf, msgstr, sendPktNonpayloadSize);
memcpy(&buf[sendPktNonpayloadSize], ((ecMsgFrame->message).info),
MAX_PARM_COUNT);
/* Write message frame to tty */
bufWriteCount = write(s_fd, buf, sizeof(buf));
if (bufWriteCount < 0) {
ret = errno;
logerr("Error writing to %s (%d - %s)", ECTTY, ret, strerror(errno));
return -ret;
}
#ifndef MSG_LOG
printf(" \n send_msg_to_ec \n");
for (loopCount = 0; loopCount < OCMP_MSG_SIZE; loopCount++) {
printf("0x%x ", buf[loopCount] & 0x00ff);
}
printf("\n");
#endif /* MSG_LOG */
return ret;
}
/**************************************************************************
* Function Name : ocmw_find_ttyacm_port
* Description : This Function used to find the tty port
* Input(s) :
* Output(s) : pathName
***************************************************************************/
int32_t ocmw_find_ttyacm_port(char *pathName)
{
FILE *fp;
int32_t nodeNum = -1;
int32_t ret = 0;
if (pathName == NULL) {
return ret = -1;
}
/* Open the command for reading. */
fp = popen(ECTTY, "r");
if (fp == NULL) {
printf("Failed to run command\n");
return ret = -1;
}
fscanf(fp, "%d", &nodeNum);
if (nodeNum < 0) {
/* close */
pclose(fp);
printf(" No ttyACM port found \n");
return ret = -1;
} else {
sprintf(pathName, "/dev/ttyACM%d", nodeNum);
printf(" ttyACM port = %s \n", pathName);
/* close */
pclose(fp);
}
return ret;
}

View File

@@ -0,0 +1,390 @@
#!/bin/sh
if [ -z "$1" ]; then
echo "Invalid Option"
echo "Usage : ./get_params <subsystem> <class>"
exit
elif [ $1 = "bms" ]; then
if [ $2 = "config" ]; then
../bin/occmd bms.ec.config.temp_sensor1.lowlimit.get
../bin/occmd bms.ec.config.temp_sensor1.highlimit.get
../bin/occmd bms.ec.config.temp_sensor1.critlimit.get
../bin/occmd bms.ec.config.current_sensor1.currlimit.get
../bin/occmd bms.ec.config.current_sensor2.currlimit.get
elif [ $2 = "status" ]; then
../bin/occmd bms.ec.status.temp_sensor1.temperature.get
../bin/occmd bms.ec.status.current_sensor1.busvoltage.get
../bin/occmd bms.ec.status.current_sensor1.shuntvoltage.get
../bin/occmd bms.ec.status.current_sensor1.current.get
../bin/occmd bms.ec.status.current_sensor1.power.get
../bin/occmd bms.ec.status.current_sensor2.busvoltage.get
../bin/occmd bms.ec.status.current_sensor2.shuntvoltage.get
../bin/occmd bms.ec.status.current_sensor2.current.get
../bin/occmd bms.ec.status.current_sensor2.power.get
else
echo "Invalid Option"
fi
elif [ $1 = "gpp" ]; then
if [ $2 = "config" ]; then
../bin/occmd gpp.ap.config.temp_sensor1.lowlimit.get
../bin/occmd gpp.ap.config.temp_sensor1.highlimit.get
../bin/occmd gpp.ap.config.temp_sensor1.critlimit.get
../bin/occmd gpp.ap.config.temp_sensor2.lowlimit.get
../bin/occmd gpp.ap.config.temp_sensor2.highlimit.get
../bin/occmd gpp.ap.config.temp_sensor2.critlimit.get
../bin/occmd gpp.ap.config.temp_sensor3.lowlimit.get
../bin/occmd gpp.ap.config.temp_sensor3.highlimit.get
../bin/occmd gpp.ap.config.temp_sensor3.critlimit.get
../bin/occmd gpp.ap.config.current_sensor1.currlimit.get
../bin/occmd gpp.msata.config.current_sensor1.currlimit.get
elif [ $2 = "status" ]; then
../bin/occmd gpp.ap.status.temp_sensor1.temperature.get
../bin/occmd gpp.ap.status.temp_sensor2.temperature.get
../bin/occmd gpp.ap.status.temp_sensor3.temperature.get
../bin/occmd gpp.ap.status.current_sensor1.busvoltage.get
../bin/occmd gpp.ap.status.current_sensor1.shuntvoltage.get
../bin/occmd gpp.ap.status.current_sensor1.current.get
../bin/occmd gpp.ap.status.current_sensor1.power.get
../bin/occmd gpp.msata.status.current_sensor1.busvoltage.get
../bin/occmd gpp.msata.status.current_sensor1.shuntvoltage.get
../bin/occmd gpp.msata.status.current_sensor1.current.get
../bin/occmd gpp.msata.status.current_sensor1.power.get
else
echo "Invalid Option"
fi
elif [ $1 = "sdr" ]; then
if [ $2 = "config" ]; then
../bin/occmd sdr.comp_all.config.current_sensor1.currlimit.get
../bin/occmd sdr.fpga.config.temp_sensor1.lowlimit.get
../bin/occmd sdr.fpga.config.temp_sensor1.highlimit.get
../bin/occmd sdr.fpga.config.temp_sensor1.critlimit.get
../bin/occmd sdr.fpga.config.current_sensor1.currlimit.get
elif [ $2 = "status" ]; then
../bin/occmd sdr.comp_all.status.current_sensor1.busvoltage.get
../bin/occmd sdr.comp_all.status.current_sensor1.shuntvoltage.get
../bin/occmd sdr.comp_all.status.current_sensor1.current.get
../bin/occmd sdr.comp_all.status.current_sensor1.power.get
../bin/occmd sdr.fpga.status.temp_sensor1.temperature.get
../bin/occmd sdr.fpga.status.current_sensor1.busvoltage.get
../bin/occmd sdr.fpga.status.current_sensor1.shuntvoltage.get
../bin/occmd sdr.fpga.status.current_sensor1.current.get
../bin/occmd sdr.fpga.status.current_sensor1.power.get
../bin/occmd sdr.comp_all.status.eeprom.dev_id.get
else
echo "Invalid Option"
fi
elif [ $1 = "rf" ]; then
if [ $2 = "config" ]; then
../bin/occmd rffe.ch1_sensor.config.temp_sensor1.lowlimit.get
../bin/occmd rffe.ch1_sensor.config.temp_sensor1.highlimit.get
../bin/occmd rffe.ch1_sensor.config.temp_sensor1.critlimit.get
../bin/occmd rffe.ch1_sensor.config.current_sensor1.currlimit.get
../bin/occmd rffe.ch2_sensor.config.temp_sensor1.lowlimit.get
../bin/occmd rffe.ch2_sensor.config.temp_sensor1.highlimit.get
../bin/occmd rffe.ch2_sensor.config.temp_sensor1.critlimit.get
../bin/occmd rffe.ch2_sensor.config.current_sensor1.currlimit.get
#../bin/occmd rffe.ch1_fe.config.rf.band get
#../bin/occmd rffe.ch1_fe.config.rf.arfcn get
../bin/occmd rffe.ch1_fe.config.tx.atten.get
../bin/occmd rffe.ch1_fe.config.rx.atten.get
#../bin/occmd rffe.ch2_fe.config.rf.band get
#../bin/occmd rffe.ch2_fe.config.rf.arfcn get
../bin/occmd rffe.ch2_fe.config.tx.atten.get
../bin/occmd rffe.ch2_fe.config.rx.atten.get
elif [ $2 = "status" ]; then
../bin/occmd rffe.ch1_sensor.status.temp_sensor1.temperature.get
../bin/occmd rffe.ch1_sensor.status.current_sensor1.busvoltage.get
../bin/occmd rffe.ch1_sensor.status.current_sensor1.shuntvoltage.get
../bin/occmd rffe.ch1_sensor.status.current_sensor1.current.get
../bin/occmd rffe.ch1_sensor.status.current_sensor1.power.get
../bin/occmd rffe.ch2_sensor.status.temp_sensor1.temperature.get
../bin/occmd rffe.ch2_sensor.status.current_sensor1.busvoltage.get
../bin/occmd rffe.ch2_sensor.status.current_sensor1.shuntvoltage.get
../bin/occmd rffe.ch2_sensor.status.current_sensor1.current.get
../bin/occmd rffe.ch2_sensor.status.current_sensor1.power.get
../bin/occmd rffe.ch1_fe.status.power.forward.get
../bin/occmd rffe.ch1_fe.status.power.reverse.get
../bin/occmd rffe.ch2_fe.status.power.forward.get
../bin/occmd rffe.ch2_fe.status.power.reverse.get
../bin/occmd rffe.comp_all.status.eeprom.dev_id.get
else
echo "Invalid Option"
fi
elif [ $1 = "power" ]; then
if [ $2 = "config" ]; then
../bin/occmd power.leadacid_sensor.config.temp_sensor1.lowlimit.get
../bin/occmd power.leadacid_sensor.config.temp_sensor1.highlimit.get
../bin/occmd power.leadacid_sensor.config.temp_sensor1.critlimit.get
../bin/occmd power.leadacid.config.battery.batteryVoltageLow.get
../bin/occmd power.leadacid.config.battery.batteryVoltageHigh.get
../bin/occmd power.leadacid.config.battery.batteryCurrentLow.get
../bin/occmd power.leadacid.config.battery.inputVoltageLow.get
../bin/occmd power.leadacid.config.battery.inputCurrentHigh.get
../bin/occmd power.leadacid.config.battery.inputCurrentLimit.get
../bin/occmd power.leadacid.config.battery.icharge.get
../bin/occmd power.leadacid.config.battery.vcharge.get
../bin/occmd power.lion.config.battery.batteryVoltageLow.get
../bin/occmd power.lion.config.battery.batteryVoltageHigh.get
../bin/occmd power.lion.config.battery.batteryCurrentLow.get
../bin/occmd power.lion.config.battery.inputVoltageLow.get
../bin/occmd power.lion.config.battery.inputCurrentHigh.get
../bin/occmd power.lion.config.battery.inputCurrentLimit.get
../bin/occmd power.lion.config.battery.icharge.get
../bin/occmd power.lion.config.battery.vcharge.get
elif [ $2 = "status" ]; then
../bin/occmd power.leadacid_sensor.status.temp_sensor1.temperature.get
../bin/occmd power.leadacid.status.battery.batteryVoltage.get
../bin/occmd power.leadacid.status.battery.batteryCurrent.get
../bin/occmd power.leadacid.status.battery.systemVoltage.get
../bin/occmd power.leadacid.status.battery.inputVoltage.get
../bin/occmd power.leadacid.status.battery.inputCurrent.get
../bin/occmd power.leadacid.status.battery.dieTemperature.get
../bin/occmd power.lion.status.battery.batteryVoltage.get
../bin/occmd power.lion.status.battery.batteryCurrent.get
../bin/occmd power.lion.status.battery.systemVoltage.get
../bin/occmd power.lion.status.battery.inputVoltage.get
../bin/occmd power.lion.status.battery.inputCurrent.get
../bin/occmd power.lion.status.battery.dieTemperature.get
../bin/occmd power.comp_all.status.powerSource.extBattAccessebility.get
../bin/occmd power.comp_all.status.powerSource.extBattAvailability.get
../bin/occmd power.comp_all.status.powerSource.intBattAccessebility.get
../bin/occmd power.comp_all.status.powerSource.intBattAvailability.get
../bin/occmd power.comp_all.status.powerSource.poeAccessebility.get
../bin/occmd power.comp_all.status.powerSource.poeAvailability.get
../bin/occmd power.comp_all.status.powerSource.solarAccessebility.get
../bin/occmd power.comp_all.status.powerSource.solarAvailability.get
else
echo "Invalid Option"
fi
elif [ $1 = "ethernet" ]; then
if [ $2 = "config" ]; then
../bin/occmd ethernet.port0.config.speed.get
../bin/occmd ethernet.port0.config.duplex.get
../bin/occmd ethernet.port0.config.powerDown.get
../bin/occmd ethernet.port0.config.enable_sleepMode.get
../bin/occmd ethernet.port0.config.enable_interrupt.get
#../bin/occmd ethernet.port0.config.switch_reset get
#../bin/occmd ethernet.port0.config.restart_autoneg get
../bin/occmd ethernet.port1.config.speed.get
../bin/occmd ethernet.port1.config.duplex.get
../bin/occmd ethernet.port1.config.powerDown.get
../bin/occmd ethernet.port1.config.enable_sleepMode.get
../bin/occmd ethernet.port1.config.enable_interrupt.get
#../bin/occmd ethernet.port1.config.switch_reset get
#../bin/occmd ethernet.port1.config.restart_autoneg get
../bin/occmd ethernet.port2.config.speed.get
../bin/occmd ethernet.port2.config.duplex.get
../bin/occmd ethernet.port2.config.powerDown.get
../bin/occmd ethernet.port2.config.enable_sleepMode.get
../bin/occmd ethernet.port3.config.enable_interrupt.get
#../bin/occmd ethernet.port2.config.switch_reset get
#../bin/occmd ethernet.port2.config.restart_autoneg get
../bin/occmd ethernet.port3.config.speed.get
../bin/occmd ethernet.port3.config.duplex.get
../bin/occmd ethernet.port3.config.powerDown.get
../bin/occmd ethernet.port3.config.enable_sleepMode.get
../bin/occmd ethernet.port3.config.enable_interrupt.get
#../bin/occmd ethernet.port3.config.switch_reset get
#../bin/occmd ethernet.port3.config.restart_autoneg get
../bin/occmd ethernet.port4.config.speed.get
../bin/occmd ethernet.port4.config.duplex.get
../bin/occmd ethernet.port4.config.powerDown.get
../bin/occmd ethernet.port4.config.enable_sleepMode.get
../bin/occmd ethernet.port4.config.enable_interrupt.get
#../bin/occmd ethernet.port4.config.switch_reset get
#../bin/occmd ethernet.port4.config.restart_autoneg get
elif [ $2 = "status" ]; then
../bin/occmd ethernet.port0.status.speed.get
../bin/occmd ethernet.port0.status.duplex.get
../bin/occmd ethernet.port0.status.sleep_mode_en.get
../bin/occmd ethernet.port0.status.autoneg_on.get
../bin/occmd ethernet.port0.status.autoneg_complete.get
../bin/occmd ethernet.port0.status.link_up.get
../bin/occmd ethernet.port1.status.speed.get
../bin/occmd ethernet.port1.status.duplex.get
../bin/occmd ethernet.port1.status.sleep_mode_en.get
../bin/occmd ethernet.port1.status.autoneg_on.get
../bin/occmd ethernet.port1.status.autoneg_complete.get
../bin/occmd ethernet.port1.status.link_up.get
../bin/occmd ethernet.port2.status.speed.get
../bin/occmd ethernet.port2.status.duplex.get
../bin/occmd ethernet.port2.status.sleep_mode_en.get
../bin/occmd ethernet.port2.status.autoneg_on.get
../bin/occmd ethernet.port2.status.autoneg_complete.get
../bin/occmd ethernet.port2.status.link_up.get
../bin/occmd ethernet.port3.status.speed.get
../bin/occmd ethernet.port3.status.duplex.get
../bin/occmd ethernet.port3.status.sleep_mode_en.get
../bin/occmd ethernet.port3.status.autoneg_on.get
../bin/occmd ethernet.port3.status.autoneg_complete.get
../bin/occmd ethernet.port3.status.link_up.get
../bin/occmd ethernet.port4.status.speed.get
../bin/occmd ethernet.port4.status.duplex.get
../bin/occmd ethernet.port4.status.sleep_mode_en.get
../bin/occmd ethernet.port4.status.autoneg_on.get
../bin/occmd ethernet.port4.status.autoneg_complete.get
../bin/occmd ethernet.port4.status.link_up.get
else
echo "Invalid Option"
fi
elif [ $1 = "sync" ]; then
if [ $2 = "config" ]; then
../bin/occmd sync.sensor.config.temp_sensor1.lowlimit.get
../bin/occmd sync.sensor.config.temp_sensor1.highlimit.get
../bin/occmd sync.sensor.config.temp_sensor1.critlimit.get
elif [ $2 = "status" ]; then
../bin/occmd sync.gps.status.gps_lock.get
../bin/occmd sync.sensor.status.temp_sensor1.temperature.get
else
echo "Invalid Option"
fi
elif [ $1 = "testmodule" ]; then
if [ $2 = "status" ]; then
../bin/occmd testmodule.2gsim.status.imei.get
../bin/occmd testmodule.2gsim.status.imsi.get
../bin/occmd testmodule.2gsim.status.mfg.get
../bin/occmd testmodule.2gsim.status.model.get
../bin/occmd testmodule.2gsim.status.rssi.get
../bin/occmd testmodule.2gsim.status.ber.get
../bin/occmd testmodule.2gsim.status.registration.get
../bin/occmd testmodule.2gsim.status.network_operatorinfo.get
../bin/occmd testmodule.2gsim.status.cellid.get
../bin/occmd testmodule.2gsim.status.bsic.get
../bin/occmd testmodule.2gsim.status.lasterror.get
else
echo "Invalid Option"
fi
elif [ $1 = "obc" ]; then
if [ $2 = "status" ]; then
../bin/occmd obc.iridium.status.imei.get
../bin/occmd obc.iridium.status.mfg.get
../bin/occmd obc.iridium.status.model.get
../bin/occmd obc.iridium.status.signal_quality.get
../bin/occmd obc.iridium.status.registration.get
../bin/occmd obc.iridium.status.numberofoutgoingmessage.get
../bin/occmd obc.iridium.status.lasterror.get
else
echo "Invalid Option"
fi
elif [ $1 = "hci" ]; then
if [ $2 = "config" ]; then
../bin/occmd hci.led.config.temp_sensor1.lowlimit.get
../bin/occmd hci.led.config.temp_sensor1.highlimit.get
../bin/occmd hci.led.config.temp_sensor1.critlimit.get
elif [ $2 = "status" ]; then
../bin/occmd hci.led.status.temp_sensor1.temperature.get
#../bin/occmd hci.led.config.ledstate get
else
echo "Invalid Option"
fi
elif [ $1 = "system" ]; then
if [ $2 = "status" ]; then
../bin/occmd system.comp_all.status.eeprom_sid.gbcboardinfo.get
../bin/occmd system.comp_all.status.eeprom_sid.ocserialinfo.get
../bin/occmd system.comp_all.config.eeprom_mac.address.get
../bin/occmd system.comp_all.echo
../bin/occmd system.comp_all.reset
../bin/occmd testmodule.2gsim.disconnect_nw
../bin/occmd testmodule.2gsim.connect_nw
../bin/occmd testmodule.2gsim.send 9789799425 hi
../bin/occmd testmodule.2gsim.dial 9789799425
../bin/occmd testmodule.2gsim.answer_call
../bin/occmd testmodule.2gsim.hangup_call
../bin/occmd testmodule.comp_all.reset
../bin/occmd obc.iridium.reset
../bin/occmd ethernet.port0.reset
../bin/occmd ethernet.port1.reset
../bin/occmd ethernet.port2.reset
../bin/occmd ethernet.port3.reset
../bin/occmd power.pse.reset
../bin/occmd rffe.comp_all.reset
../bin/occmd gpp.ap.reset
../bin/occmd hci.led.fw.set 1
../bin/occmd rffe.ch1_fe.enable
../bin/occmd rffe.ch1_fe.disable
../bin/occmd rffe.ch2_fe.disable
../bin/occmd rffe.ch2_fe.enable
../bin/occmd testmodule.2gsim.enable
../bin/occmd testmodule.2gsim.disable
../bin/occmd sdr.comp_all.reset
../bin/occmd sdr.fx3.reset
../bin/occmd ethernet.port0.en_loopBk 0
../bin/occmd ethernet.port0.en_pktGen 8374
../bin/occmd ethernet.port0.dis_pktGen
../bin/occmd ethernet.port0.dis_loopBk 0
../bin/occmd ethernet.port1.en_loopBk 0
../bin/occmd ethernet.port1.en_pktGen 8374
../bin/occmd ethernet.port1.dis_pktGen
../bin/occmd ethernet.port1.dis_loopBk 0
../bin/occmd ethernet.port2.en_loopBk 0
../bin/occmd ethernet.port2.en_pktGen 8374
../bin/occmd ethernet.port2.dis_pktGen
../bin/occmd ethernet.port2.dis_loopBk 0
../bin/occmd ethernet.port3.en_loopBk 0
../bin/occmd ethernet.port3.en_pktGen 8374
../bin/occmd ethernet.port3.dis_pktGen
../bin/occmd ethernet.port3.dis_loopBk 0
../bin/occmd ethernet.port4.en_loopBk 0
../bin/occmd ethernet.port4.en_pktGen 8374
../bin/occmd ethernet.port4.dis_pktGen
../bin/occmd ethernet.port4.dis_loopBk 0
else
echo "Invalid Option"
fi
elif [ $1 = "debug" ]; then
if [ $2 = "I2C" ]; then
../bin/occmd debug.I2C.bus0.get 104 2 58
../bin/occmd debug.I2C.bus1.get 24 2 2
../bin/occmd debug.I2C.bus2.get 29 1 0
../bin/occmd debug.I2C.bus3.get 68 2 255
../bin/occmd debug.I2C.bus4.get 65 2 254
../bin/occmd debug.I2C.bus6.get 64 2 5
../bin/occmd debug.I2C.bus7.get 69 2 5
../bin/occmd debug.I2C.bus8.get 26 2 6
elif [ $2 = "GPIO" ]; then
../bin/occmd debug.ec.PA.get 1
../bin/occmd debug.ec.PB.get 1
../bin/occmd debug.ec.PC.get 1
../bin/occmd debug.ec.PD.get 7
../bin/occmd debug.ec.PE.get 1
../bin/occmd debug.ec.PF.get 1
../bin/occmd debug.ec.PG.get 1
../bin/occmd debug.ec.PJ.get 1
../bin/occmd debug.ec.PK.get 1
../bin/occmd debug.ec.PL.get 5
../bin/occmd debug.ec.PM.get 1
../bin/occmd debug.ec.PN.get 1
../bin/occmd debug.ec.PP.get 3
../bin/occmd debug.ec.PQ.get 1
../bin/occmd debug.gbc.ioexpanderx70.get 1
../bin/occmd debug.gbc.ioexpanderx71.get 0
../bin/occmd debug.sdr.ioexpanderx1E.get 1
../bin/occmd debug.fe.ioexpanderx18.get 1
../bin/occmd debug.fe.ioexpanderx1A.get 0
../bin/occmd debug.fe.ioexpanderx1B.get 1
../bin/occmd debug.fe.ioexpanderx1C.get 1
../bin/occmd debug.fe.ioexpanderx1D.get 1
../bin/occmd debug.sync.ioexpanderx71.get 1
elif [ $2 = "MDIO" ]; then
../bin/occmd debug.ethernet.port0.get 1
../bin/occmd debug.ethernet.port1.get 1
../bin/occmd debug.ethernet.port2.get 1
../bin/occmd debug.ethernet.port3.get 1
../bin/occmd debug.ethernet.port4.get 1
../bin/occmd debug.ethernet.global1.get 1
../bin/occmd debug.ethernet.global2.get 1
../bin/occmd debug.ethernet.swport0.get 1
../bin/occmd debug.ethernet.swport1.get 1
../bin/occmd debug.ethernet.swport2.get 1
../bin/occmd debug.ethernet.swport3.get 1
../bin/occmd debug.ethernet.swport4.get 1
../bin/occmd debug.ethernet.swport5.get 1
../bin/occmd debug.ethernet.swport6.get 1
else
echo "Invalid Option"
fi
else
echo "Invalid Option"
fi
echo "Done..."

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,135 @@
#include <ocware_stub_eth_comm.h>
#include <ocware_stub_main_module.h>
static int32_t s_stubSockFd;
static struct sockaddr_in s_ocmwStubServer;
/******************************************************************************
* Function Name : ocware_stub_init_ethernet_comm
* Description : initialise the socket IPC
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_init_ethernet_comm(void)
{
int32_t rc = 0;
int32_t inet_atom = 0;
/* Create socket */
s_stubSockFd = socket(OCMW_STUB_ETH_SOCK_DOMAIN,
OCMW_STUB_ETH_SOCK_TYPE, OCMW_STUB_ETH_SOCK_PROTOCOL);
if (s_stubSockFd < 0) {
printf("socket creation error [%d-%s]", errno, strerror(errno));
return STUB_FAILED;
}
/* Initialize socket structure */
memset(&s_ocmwStubServer, 0, sizeof(s_ocmwStubServer));
s_ocmwStubServer.sin_family = OCMW_STUB_ETH_SOCK_DOMAIN;
s_ocmwStubServer.sin_port = htons(OCMW_STUB_ETH_SOCK_SERVER_PORT);
s_ocmwStubServer.sin_addr.s_addr = inet_addr(OCMW_STUB_ETH_SOCK_SERVER_IP);
inet_atom = inet_aton(OCMW_STUB_ETH_SOCK_SERVER_IP,
&s_ocmwStubServer.sin_addr);
if (inet_atom == 0) {
printf("inet_aton failed");
return STUB_FAILED;
}
memset(s_ocmwStubServer.sin_zero, '\0', sizeof(s_ocmwStubServer.sin_zero));
/*Bind socket with address struct*/
rc = bind(s_stubSockFd, (struct sockaddr *) &s_ocmwStubServer,
sizeof(s_ocmwStubServer));
if (rc != 0) {
ocware_stub_deinit_ethernet_comm();
printf("Ehernet init failed \n");
return STUB_FAILED;
}
return STUB_SUCCESS;
}
/******************************************************************************
* Function Name : ocware_stub_deinit_ethernet_comm
* Description : close the IPC socket
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_deinit_ethernet_comm()
{
close(s_stubSockFd);
s_stubSockFd = 0; /* Close the IPC socket */
return STUB_SUCCESS;
}
/******************************************************************************
* Function Name : ocware_stub_send_msgframe_middleware
* Description : send message to the MW
*
* @param bufferlen - length of the message (by value)
* @param buffer - pointer to the message to be sent to MW (by reference)
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_send_msgframe_middleware(char **buffer,
int32_t bufferlen)
{
int32_t rc = 0;
const int32_t errstr_len = OCWARE_STUB_ERR_STR_LEN;
char errstr[errstr_len];
int8_t data[OC_EC_MSG_SIZE] = { 0 };
int32_t dataLen = sizeof(s_ocmwStubServer);
if (buffer == NULL) {
return STUB_FAILED;
}
memcpy(data, *buffer, sizeof(data));
rc = sendto(s_stubSockFd, data, OC_EC_MSG_SIZE, 0,
(struct sockaddr *) &s_ocmwStubServer,
dataLen);
if (rc < 0) {
strerror_r(errno, errstr, errstr_len);
printf("Error: 'send' [%d-%s]", errno, errstr);
return STUB_FAILED;
}
return STUB_SUCCESS;
}
/******************************************************************************
* Function Name : ocware_stub_recv_msgfrom_middleware
* Description : Receive message from MW
*
* @param bufferlen - length of the message (by value)
* @param buffer - pointer to the location where the message from MW is to be
* stored for further processing (by reference)
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_recv_msgfrom_middleware(
char **buffer, int32_t bufferlen)
{
int32_t rc = 0;
const int32_t errstr_len = OCWARE_STUB_ERR_STR_LEN;
char errstr[errstr_len];
int8_t data[OC_EC_MSG_SIZE] = { 0 };
int32_t dataLen = sizeof(s_ocmwStubServer);
if (buffer == NULL) {
return STUB_FAILED;
}
/* Receive the CLI command execution response string from OCMW over UDP socket */
rc = recvfrom(s_stubSockFd, data, OC_EC_MSG_SIZE,
0, (struct sockaddr *) &s_ocmwStubServer,
(socklen_t*)&dataLen);
if (rc < 0) {
strerror_r(rc, errstr, errstr_len);
logerr("Error: 'recv' [%d-%s]", rc, errstr);
return STUB_FAILED;
}
memcpy(*buffer, data, sizeof(data));
return STUB_SUCCESS;
}

View File

@@ -0,0 +1,204 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include <ocware_stub_main_module.h>
/******************************************************************************
* Function Name : ocware_stub_frame_newmsgframe
* Description : Frame the response packet from stub function
*
* @param buf - pointer to complete message from MW (by reference)
* @param option - success or failure (by value)
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_frame_newmsgframe(char *buffer, int32_t option)
{
int32_t ret = 0, index = 0;
OCMPMessageFrame *msgFrame = (OCMPMessageFrame *)buffer;
OCMPMessage *msgFrameData = (OCMPMessage*)&msgFrame->message;
/* Frame the header packet for sending data to ec */
msgFrame->header.ocmpFrameLen = 0;
msgFrame->header.ocmpInterface = OCMP_COMM_IFACE_ETHERNET;
msgFrame->header.ocmpSeqNumber = 0;
msgFrame->header.ocmpSof = OCMP_MSG_SOF;
msgFrame->header.ocmpTimestamp = 0;
switch(msgFrameData->msgtype) {
case OCMP_MSG_TYPE_COMMAND:
ret = ocware_stub_parse_command_message(buffer);
break;
case OCMP_MSG_TYPE_POST:
ret = ocware_stub_parse_post_get_message(buffer);
break;
default:
ret = ocware_stub_get_set_params(msgFrameData);
}
if (ret == STUB_SUCCESS) {
/* Setting the action type as REPLY */
msgFrame->message.action = OCMP_AXN_TYPE_REPLY;
printf(" \n Sending Data :\n");
for (index = 0; index < OC_EC_MSG_SIZE; index++) {
printf("0x%x ", buffer[index] & 0xff);
}
}
return ret;
}
/******************************************************************************
* Function Name : ocware_stub_validate_msgframe_header
* Description : validate the msgframe header
*
* @param buf - pointer to complete message from MW (by reference)
* @param msgFrameData - pointer to ocmpgeader field of the message from
* MW (by reference)
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_validate_msgframe_header(char *buf,
OCMPMessage *msgFrameData)
{
OCMPMessageFrame *MsgFrame = (OCMPMessageFrame *)buf;
OCMPHeader *header = (OCMPHeader *)&MsgFrame->header;
if (header->ocmpFrameLen == 0) {
if (header->ocmpSeqNumber == 0) {
if (header->ocmpSof == OCMP_MSG_SOF) {
if (header->ocmpTimestamp == 0) {
memcpy(msgFrameData, &MsgFrame->message,
sizeof(OCMPMessage));
return STUB_SUCCESS;
}
}
}
}
return STUB_FAILED;
}
/******************************************************************************
* Function Name : host_ocstubmain_func
* Description : Handle all the functionality for stub
*
* @param argc - number of argunents passed (by value)
* @param argv - arguments passed when invoking stub (by reference)
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
int32_t host_ocstubmain_func(int32_t argc, char *argv[])
{
int32_t rc = 0;
char *buffer = NULL;
int32_t loopCount = 0;
char *rootpath = NULL;
OCMPMessageFrame *msgFrame = NULL;
rc = ocware_stub_init_ethernet_comm();
if ( rc != STUB_SUCCESS) {
printf("\n ERROR: Init Failed - %d", __LINE__);
ocware_stub_deinit_ethernet_comm();
return STUB_FAILED;
}
msgFrame = (OCMPMessageFrame *) malloc(sizeof(OCMPMessageFrame));
if (msgFrame == NULL) {
printf("\n ERROR: malloc");
ocware_stub_deinit_ethernet_comm();
return STUB_FAILED;
}
buffer = (char *) malloc(OC_EC_MSG_SIZE);
if (buffer == NULL) {
printf("\n ERROR: malloc");
ocware_stub_deinit_ethernet_comm();
return STUB_FAILED;
}
rootpath = (char *)malloc(100);
if (rootpath == NULL) {
printf("\n ERROR: malloc");
ocware_stub_deinit_ethernet_comm();
return STUB_FAILED;
}
ocware_stub_init_database();
printf("\n\n OCWARE STUB APllication Started...\n");
while (1) {
memset(buffer, 0, sizeof(OCMPMessageFrame));
rc = ocware_stub_recv_msgfrom_middleware(&buffer,
sizeof(OCMPMessageFrame));
if (rc != STUB_SUCCESS) {
printf("ocware_stub_recv_msgfrom_middleware failed: error value :"
" %d\n", rc);
return STUB_FAILED;
}
//#ifndef OCWARE_STUB_DEBUG
printf(" \n Received Data :\n");
for (loopCount = 0; loopCount < OC_EC_MSG_SIZE; loopCount++) {
printf("0x%x ", buffer[loopCount] & 0xff);
}
//#endif
rc = ocware_stub_validate_msgframe_header(buffer, &msgFrame->message);
if (rc != STUB_SUCCESS) {
printf("ocware_stub_validate_msgframe_header failed: error value :"
"%d\n", rc);
return STUB_FAILED;
}
rc = ocware_stub_frame_newmsgframe(buffer, rc);
if (rc != STUB_SUCCESS) {
printf("ocware_stub_frame_newmsgframe failed: error value :"
"%d\n", rc);
return STUB_FAILED;
}
rc = ocware_stub_send_msgframe_middleware(&buffer,
sizeof(OCMPMessageFrame));
if (rc != STUB_SUCCESS) {
printf("ocware_stub_send_msgframe_middleware failed: error value :"
"%d\n", rc);
return STUB_FAILED;
}
}
free(msgFrame);
free(buffer);
return STUB_SUCCESS;
}
/******************************************************************************
* Function Name : main
* Description : start the stub process
*
* @param argc - number of argunents passed (by value)
* @param argv - arguments passed when invoking stub (by reference)
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
#ifndef OCWARE_UNITY_TEST
int32_t main(int32_t argc, char *argv[])
{
int32_t ret = 0;
ret = host_ocstubmain_func(argc, argv);
return ret;
}
#else
int32_t host_ocwaremain(int32_t argc, char *argv[])
{
int32_t ret = 0;
ret = host_ocstubmain_func(argc, argv);
return ret;
}
#endif

View File

@@ -0,0 +1,124 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include <occli_common.h>
#include <ocmw_occli_comm.h>
#include <ocware_stub_main_module.h>
/******************************************************************************
* Function Name : ocware_stub_parse_debug_actiontype
* Description : Convert debug actiontype into the SET/GET
*
* @param msgFrameData - output pointer to the OCMPheader field of the message
* from MW (by reference)
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
*******************************************************************************/
ocware_stub_ret ocware_stub_parse_debug_actiontype(OCMPMessage *msgFrameData)
{
ocware_stub_ret ret = STUB_SUCCESS;
if ((debugSetCommand != STUB_FAILED) ||
(debugGetCommand != STUB_FAILED)) {
if ((msgFrameData->action) == debugGetCommand) {
msgFrameData->action = OCMP_AXN_TYPE_GET;
} else if ((msgFrameData->action) == debugSetCommand) {
msgFrameData->action = OCMP_AXN_TYPE_SET;
} else {
ret = STUB_FAILED;
}
} else {
ret = STUB_FAILED;
}
return ret;
}
/******************************************************************************
* Function Name : ocware_stub_handle_post_enable
* Description : Process the post enable message
*
* @param msgFrameData - output pointer to the OCMPheader field of the message
* from MW (by reference)
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_handle_post_enable(OCMPMessage *msgFrameData)
{
return STUB_SUCCESS;
}
/******************************************************************************
* Function Name : ocware_stub_get_set_params
* Description : Function to check if GET/SET operation is to be performed
*
* @param msgFrameData - Pointer to the message frame field of the message
* from MW (by reference)
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_get_set_params(OCMPMessage *msgFrameData)
{
ocware_stub_ret ret = STUB_FAILED;
if (msgFrameData == NULL) {
return ret;
}
switch (msgFrameData->action) {
case OCMP_AXN_TYPE_GET:
ret = ocware_stub_get_database(msgFrameData);
break;
case OCMP_AXN_TYPE_SET:
ret = ocware_stub_set_database(msgFrameData);
break;
default:
ret = STUB_FAILED;
}
return ret;
}
/******************************************************************************
* Function Name : ocware_stub_parse_post_get_message
* Description : Parse post messages from MW
*
* @param buffer - output pointer to the message from MW
*
* @return STUB_SUCCESS - for success
* STUB_FAILED - for failure
******************************************************************************/
ocware_stub_ret ocware_stub_parse_post_get_message(char *buffer)
{
ocware_stub_ret ret = STUB_FAILED;
OCMPMessageFrame *msgFrame = NULL;
OCMPMessage *msgFrameData = NULL;
uint16_t paramId;
char *payload = NULL;
if(buffer == NULL) {
return ret;
}
msgFrame = (OCMPMessageFrame *)buffer;
msgFrameData = (OCMPMessage*)&msgFrame->message;
payload = (char *)&msgFrameData->info;
msgFrameData->action = OCMP_AXN_TYPE_REPLY;
paramId = msgFrameData->parameters;
if(paramId == PostResult) {
ret = ocware_stub_get_post_database(msgFrameData, payload);
} else if (paramId == PostEnable) {
ret = ocware_stub_handle_post_enable(msgFrameData);
}
return ret;
}

View File

@@ -0,0 +1,73 @@
#!/bin/sh
echo "##############################"
echo " GET CONFIG PARAMS - 1 "
echo "##############################"
./get_params_stub.sh bms config
./get_params_stub.sh gpp config
./get_params_stub.sh sdr config
./get_params_stub.sh rf config
./get_params_stub.sh power config
./get_params_stub.sh ethernet config
./get_params_stub.sh sync config
echo "##############################"
echo " SET CONFIG PARAMS "
echo "##############################"
../scripts/set_config_params.sh bms
../scripts/set_config_params.sh gpp
../scripts/set_config_params.sh sdr
../scripts/set_config_params.sh rf
../scripts/set_config_params.sh power
../scripts/set_config_params.sh ethernet
../scripts/set_config_params.sh sync
echo "##############################"
echo " GET CONFIG PARAMS - 2 "
echo "##############################"
./get_params_stub.sh bms config
./get_params_stub.sh gpp config
./get_params_stub.sh sdr config
./get_params_stub.sh rf config
./get_params_stub.sh power config
./get_params_stub.sh ethernet config
./get_params_stub.sh sync config
echo "##############################"
echo " GET STATUS PARAMS "
echo "##############################"
./get_params_stub.sh bms status
./get_params_stub.sh gpp status
./get_params_stub.sh sdr status
./get_params_stub.sh rf status
./get_params_stub.sh power status
./get_params_stub.sh ethernet status
./get_params_stub.sh sync status
./get_params_stub.sh testmodule status
./get_params_stub.sh obc status
./get_params_stub.sh hci status
./get_params_stub.sh system status
echo "##############################"
echo " GET DEBUG COMMANDS - 1 "
echo "##############################"
./get_params_stub.sh debug I2C
./get_params_stub.sh debug GPIO
./get_params_stub.sh debug MDIO
echo "##############################"
echo " SET DEBUG COMMANDS "
echo "##############################"
../scripts/set_config_params.sh debug I2C
../scripts/set_config_params.sh debug GPIO
../scripts/set_config_params.sh debug MDIO
echo "##############################"
echo " GET DEBUG COMMANDS - 2 "
echo "##############################"
./get_params_stub.sh debug I2C
./get_params_stub.sh debug GPIO
./get_params_stub.sh debug MDIO
echo " >>> TESTING DONE <<< "

View File

@@ -0,0 +1,119 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/* OC includes */
#include <ocwdg_daemon.h>
#include <logger.h>
#define OCWDG_NUMBER_ZERO 0
#define OCWDG_NUMBER_ONE 1
extern int32_t ocmw_sem_wait_nointr(sem_t *sem);
/******************************************************************************
* Function Name : ocwdg_init
* Description : This Function used to initialize the watchdog semaphore
* and thread.
* Input(s) :
* Output(s) :
******************************************************************************/
int32_t ocwdg_init(void)
{
pthread_t ocWdgThreadid;
int32_t ret = OCWDG_NUMBER_ZERO;
printf("inside ocwdg_init() \n");
ret = sem_init(&semEcWdgMsg, OCWDG_NUMBER_ZERO, OCWDG_NUMBER_ZERO);
if (ret != OCWDG_NUMBER_ZERO) {
return ret;
} else {
/* Create the msg parser thread to parse
* the msg coming from UART ec to ap
*/
ret = pthread_create(&ocWdgThreadid, NULL, ocwdg_thread_comm_with_ec,
NULL);
if (ret != OCWDG_NUMBER_ZERO) {
return ret;
}
}
return ret;
}
/******************************************************************************
* Function Name : ocwdg_thread_comm_with_ec
* Description : Thread to send watchdog response to ec
* through uart or ethernet communication
* Input(s) : pthreadData
* Output(s) :
******************************************************************************/
void * ocwdg_thread_comm_with_ec(void *pthreadData)
{
OCMPMessageFrame ecMsgFrame;
OCMPHeader ecMsgHeader;
OCMPMessage ecCoreMsg;
int32_t ret = OCWDG_NUMBER_ZERO;
while (OCWDG_NUMBER_ONE) {
/* Waiting on the semEcWdgMsg to be released by
* msg receiving thread from ec
*/
ret = ocmw_sem_wait_nointr(&semEcWdgMsg);
if (ret != OCWDG_NUMBER_ZERO) {
perror("ocwdg_thread_comm_with_ec: ocmw_sem_wait_nointr");
continue;
}
/* Frame the header packet for sending data to ec */
ecMsgHeader.ocmpFrameLen = OCWDG_NUMBER_ZERO;
#ifdef INTERFACE_ETHERNET
ecMsgHeader.ocmpInterface = OCMP_COMM_IFACE_ETHERNET;
#else
ecMsgHeader.ocmpInterface = OCMP_COMM_IFACE_UART;
#endif /* INTERFACE_ETHERNET */
ecMsgHeader.ocmpSeqNumber = OCWDG_NUMBER_ZERO;
ecMsgHeader.ocmpSof = OCMP_MSG_SOF;
ecMsgHeader.ocmpTimestamp = OCWDG_NUMBER_ZERO;
/* Frame the Core packet for sending data to ec */
ecCoreMsg.action = OCMP_AXN_TYPE_REPLY;
ecCoreMsg.msgtype = OCMP_MSG_TYPE_WATCHDOG;
ecCoreMsg.parameters = 0;
/* Construct the final packet */
ecMsgFrame.header = ecMsgHeader;
ecMsgFrame.message = ecCoreMsg;
/* Populate the Core packet payload */
ecMsgFrame.message.info = (int8_t *) malloc(
sizeof(char) * MAX_PARM_COUNT);
if (ecMsgFrame.message.info == NULL) {
printf("\n Memory allocation failed \n");
}
memset(ecMsgFrame.message.info, OCWDG_NUMBER_ZERO, MAX_PARM_COUNT);
#ifdef INTERFACE_ETHERNET
/* Send the packetize data to ec through ethernet*/
ret = ocmw_send_eth_msgto_ec((int8_t *)&ecMsgFrame, (int32_t)32,
OCMW_EC_DEV);
if (ret != OCWDG_NUMBER_ZERO) {
logerr ("ocmw_send_eth_msgto_ec() failed");
}
#else
/* Send the packetize data to ec through uart*/
ret = ocmw_send_uart_msg_to_ec((uint8_t *) &ecMsgFrame,
sizeof(ecMsgFrame));
if (ret != OCWDG_NUMBER_ZERO) {
logerr("ocmw_send_uart_msg_to_ec() failed");
}
#endif /* INTERFACE_ETHERNET */
printf("Watchdog reply message sent to ec \n");
}
}

View File

@@ -0,0 +1,20 @@
#This config is used to start the watchdog-daemon at boot time and if daemon got
#killed anyway. This file should be put in /etc/init folder after that
# run the command sudo service ocwdg_daemon restart
# Command used to check the syntax of config script : init-checkconf /etc/init/ocwdg_daemon.conf
description "Watchdog Daemon"
start on filesystem or runlevel [2345]
stop on runlevel [06]
#Replace the path with the location of watchdog-daemon
exec /home/oc/Desktop/Fb_code/ocmw --daemon
# Restart the process if it dies with a signal
# or exit code not given by the 'normal exit' stanza.
respawn
# Give up if restart occurs 10 times in 90 seconds.
respawn limit 10 90

View File

@@ -0,0 +1,29 @@
modprobe i2c-i801
#i2cdetect -l
#i2cdetect -r -y 9
#i2cdetect -r -y 0
#Valid only for ubuntu-14.04.4 : Kernel-> 4.2.0-42
bus=`i2cdetect -l | awk -F ' |-|\t' '/DesignWare/ {print $2}' | head -1`
i2cdetect -r -y $bus
# Read Chip revision register from PMIC (0x5E) on i2c-0
# Sleep for a second
#PMIC(0X5E) o/p- chip revision: 0x05
x=1
while [ $x -le 100 ]
do
#i2cget -f -y 0 0x5e 0x01 b
i2cget -f -y $bus 0x5e 0x01 b
echo "Reading Chip revision register from PMIC (0x5E) on i2c-0 and sleeping for 1 sec"
sleep 1
x=$(( $x + 1 ))
done

View File

@@ -0,0 +1,18 @@
modprobe i2c-i801
i2cdetect -l
x=1
while [ $x -le 10 ]
do
#Temperature sensor(0X4C) : o/p-> ( Device id: 0x3d : 0x81) (manufacture id: 0x3e : 0x41)
i2cdetect -y 9
echo "Checking presence of ADT7481 temperature sensor and DDR3 DIMM-0 SPD memory"
sleep 1
x=$(( $x + 1 ))
done

View File

@@ -0,0 +1,27 @@
modprobe i2c-i801
i2cdetect -l
i2cdetect -r -y 9
#i2cdetect -r -y 0
x=1
while [ $x -le 100 ]
do
#Read device register address from 128 to 145 from device DDR3 SPD (0x50) on i2c-9
y=128
while [ $y -le 145 ]
do
i2cget -f -y 9 0x50 $y b
y=$(( $y + 1 ))
done
echo "Reading device register address from 128 to 145 from device DDR3 SPD (0x50) on i2c-9 and sleeping for 1 sec "
sleep 1
x=$(( $x + 1 ))
done

View File

@@ -0,0 +1,25 @@
modprobe i2c-i801
i2cdetect -l
i2cdetect -r -y 9
#i2cdetect -r -y 0
x=1
while [ $x -le 100 ]
do
#Temperature sensor(0X4C) : o/p-> ( Device id: 0x3d : 0x81) (manufacture id: 0x3e : 0x41)
i2cget -f -y 9 0x1f 0x3d b
echo "Reading -> Device id: 0x3d : 0x81 from temperature sensor and sleeping for 1 sec"
sleep 1
i2cget -f -y 9 0x1f 0x3e b
echo "Reading -> Manufacture id: 0x3e : 0x41 from temperature sensor and sleeping for 1 sec"
sleep 1
x=$(( $x + 1 ))
done

View File

@@ -0,0 +1,849 @@
#!/bin/bash
bmsParam=("bms.ec.config.temp_sensor1.lowlimit.get"
"bms.ec.config.temp_sensor1.highlimit.get"
"bms.ec.config.temp_sensor1.critlimit.get"
"bms.ec.config.current_sensor1.currlimit.get"
"bms.ec.config.current_sensor2.currlimit.get")
defaultBms=("bms.ec.config.temp_sensor1.lowlimit.get=-20"
"bms.ec.config.temp_sensor1.highlimit.get=75"
"bms.ec.config.temp_sensor1.critlimit.get=80"
"bms.ec.config.current_sensor1.currlimit.get=1000"
"bms.ec.config.current_sensor2.currlimit.get=1000")
setBmsVal=("bms.ec.config.temp_sensor1.lowlimit.get=-19"
"bms.ec.config.temp_sensor1.highlimit.get=76"
"bms.ec.config.temp_sensor1.critlimit.get=85"
"bms.ec.config.current_sensor1.currlimit.get=1498"
"bms.ec.config.current_sensor2.currlimit.get=1498")
bmsStatusParam=("bms.ec.status.temp_sensor1.temperature.get"
"bms.ec.status.current_sensor1.busvoltage.get"
"bms.ec.status.current_sensor1.shuntvoltage.get"
"bms.ec.status.current_sensor1.current.get"
"bms.ec.status.current_sensor1.power.get"
"bms.ec.status.current_sensor2.busvoltage.get"
"bms.ec.status.current_sensor2.shuntvoltage.get"
"bms.ec.status.current_sensor2.current.get"
"bms.ec.status.current_sensor2.power.get")
bmsStatusMinVal=(-20 11400 250 100 1100 2970 800 400 1200)
bmsStatusMaxVal=(75 12600 1400 600 7500 3630 2000 800 2900)
gppParam=("gpp.ap.config.temp_sensor1.lowlimit.get"
"gpp.ap.config.temp_sensor1.highlimit.get"
"gpp.ap.config.temp_sensor1.critlimit.get"
"gpp.ap.config.temp_sensor2.lowlimit.get"
"gpp.ap.config.temp_sensor2.highlimit.get"
"gpp.ap.config.temp_sensor2.critlimit.get"
"gpp.ap.config.temp_sensor3.lowlimit.get"
"gpp.ap.config.temp_sensor3.highlimit.get"
"gpp.ap.config.temp_sensor3.critlimit.get"
"gpp.ap.config.current_sensor1.currlimit.get"
"gpp.msata.config.current_sensor1.currlimit.get")
defaultGpp=("gpp.ap.config.temp_sensor1.lowlimit.get=-20"
"gpp.ap.config.temp_sensor1.highlimit.get=75"
"gpp.ap.config.temp_sensor1.critlimit.get=80"
"gpp.ap.config.temp_sensor2.lowlimit.get=-20"
"gpp.ap.config.temp_sensor2.highlimit.get=75"
"gpp.ap.config.temp_sensor2.critlimit.get=80"
"gpp.ap.config.temp_sensor3.lowlimit.get=-20"
"gpp.ap.config.temp_sensor3.highlimit.get=75"
"gpp.ap.config.temp_sensor3.critlimit.get=80"
"gpp.ap.config.current_sensor1.currlimit.get=1498"
"gpp.msata.config.current_sensor1.currlimit.get=1498")
setGppVal=("gpp.ap.config.temp_sensor1.lowlimit.get=-19"
"gpp.ap.config.temp_sensor1.highlimit.get=81"
"gpp.ap.config.temp_sensor1.critlimit.get=86"
"gpp.ap.config.temp_sensor2.lowlimit.get=-19"
"gpp.ap.config.temp_sensor2.highlimit.get=81"
"gpp.ap.config.temp_sensor2.critlimit.get=86"
"gpp.ap.config.temp_sensor3.lowlimit.get=-19"
"gpp.ap.config.temp_sensor3.highlimit.get=81"
"gpp.ap.config.temp_sensor3.critlimit.get=86"
"gpp.ap.config.current_sensor1.currlimit.get=2010"
"gpp.msata.config.current_sensor1.currlimit.get=2010")
gppStatusParam=("gpp.ap.status.temp_sensor1.temperature.get"
"gpp.ap.status.temp_sensor2.temperature.get"
"gpp.ap.status.temp_sensor3.temperature.get"
"gpp.ap.status.current_sensor1.busvoltage.get"
"gpp.ap.status.current_sensor1.shuntvoltage.get"
"gpp.ap.status.current_sensor1.current.get"
"gpp.ap.status.current_sensor1.power.get"
"gpp.msata.status.current_sensor1.busvoltage.get"
"gpp.msata.status.current_sensor1.shuntvoltage.get"
"gpp.msata.status.current_sensor1.current.get"
"gpp.msata.status.current_sensor1.power.get")
gppStatusMinVal=(-20 -20 -20 11400 700 400 5000 3135 140 50 250)
gppStatusMaxVal=(80 80 80 12600 1400 1200 8300 3465 500 300 800)
hciParam=("hci.led.config.temp_sensor1.lowlimit.get"
"hci.led.config.temp_sensor1.highlimit.get"
"hci.led.config.temp_sensor1.critlimit.get")
defaultHci=("hci.led.config.temp_sensor1.lowlimit.get=-20"
"hci.led.config.temp_sensor1.highlimit.get=80"
"hci.led.config.temp_sensor1.critlimit.get=85")
setHciVal=("hci.led.config.temp_sensor1.lowlimit.get=-19"
"hci.led.config.temp_sensor1.highlimit.get=76"
"hci.led.config.temp_sensor1.critlimit.get=85")
hciStatusParam=("hci.led.status.temp_sensor1.temperature.get")
hciStatusMinVal=(-20)
hciStatusMaxVal=(80)
sdrParam=("sdr.comp_all.config.current_sensor1.currlimit.get"
"sdr.fpga.config.temp_sensor1.lowlimit.get"
"sdr.fpga.config.temp_sensor1.highlimit.get"
"sdr.fpga.config.temp_sensor1.critlimit.get"
"sdr.fpga.config.current_sensor1.currlimit.get")
defaultSdr=("sdr.comp_all.config.current_sensor1.currlimit.get=2998"
"sdr.fpga.config.temp_sensor1.lowlimit.get=-20"
"sdr.fpga.config.temp_sensor1.highlimit.get=75"
"sdr.fpga.config.temp_sensor1.critlimit.get=85"
"sdr.fpga.config.current_sensor1.currlimit.get=500")
setSdrVal=("sdr.comp_all.config.current_sensor1.currlimit.get=2010"
"sdr.fpga.config.temp_sensor1.lowlimit.get=-19"
"sdr.fpga.config.temp_sensor1.highlimit.get=76"
"sdr.fpga.config.temp_sensor1.critlimit.get=81"
"sdr.fpga.config.current_sensor1.currlimit.get=510")
sdrStatusParam=("sdr.comp_all.status.current_sensor1.busvoltage.get"
"sdr.comp_all.status.current_sensor1.shuntvoltage.get"
"sdr.comp_all.status.current_sensor1.current.get"
"sdr.comp_all.status.current_sensor1.power.get"
"sdr.fpga.status.temp_sensor1.temperature.get"
"sdr.fpga.status.current_sensor1.busvoltage.get"
"sdr.fpga.status.current_sensor1.shuntvoltage.get"
"sdr.fpga.status.current_sensor1.current.get"
"sdr.fpga.status.current_sensor1.power.get")
sdrStatusMinVal=(11400 2762 1381 15742 0 11400 60 30 342)
sdrStatusMaxVal=(12600 4173 2087 26292 80 12600 240 120 1512)
rfParam=("rffe.ch1_sensor.config.temp_sensor1.lowlimit.get"
"rffe.ch1_sensor.config.temp_sensor1.highlimit.get"
"rffe.ch1_sensor.config.temp_sensor1.critlimit.get"
"rffe.ch1_sensor.config.current_sensor1.currlimit.get"
"rffe.ch2_sensor.config.temp_sensor1.lowlimit.get"
"rffe.ch2_sensor.config.temp_sensor1.highlimit.get"
"rffe.ch2_sensor.config.temp_sensor1.critlimit.get"
"rffe.ch2_sensor.config.current_sensor1.currlimit.get"
"rffe.ch1_fe.config.ch1_band.band.get"
"rffe.ch1_fe.config.tx.atten.get"
"rffe.ch1_fe.config.rx.atten.get"
"rffe.ch2_fe.config.ch2_band.band.get"
"rffe.ch2_fe.config.tx.atten.get"
"rffe.ch2_fe.config.rx.atten.get")
defaultRf=("rffe.ch1_sensor.config.temp_sensor1.lowlimit.get=-20"
"rffe.ch1_sensor.config.temp_sensor1.highlimit.get=80"
"rffe.ch1_sensor.config.temp_sensor1.critlimit.get=85"
"rffe.ch1_sensor.config.current_sensor1.currlimit.get=2000"
"rffe.ch2_sensor.config.temp_sensor1.lowlimit.get=-20"
"rffe.ch2_sensor.config.temp_sensor1.highlimit.get=80"
"rffe.ch2_sensor.config.temp_sensor1.critlimit.get=85"
"rffe.ch2_sensor.config.current_sensor1.currlimit.get=2000"
"rffe.ch1_fe.config.ch1_band.band.get=3"
"rffe.ch1_fe.config.tx.atten.get=63"
"rffe.ch1_fe.config.rx.atten.get=31"
"rffe.ch2_fe.config.ch2_band.band.get=3"
"rffe.ch2_fe.config.tx.atten.get=63"
"rffe.ch2_fe.config.rx.atten.get=31")
setRfVal=("rffe.ch1_sensor.config.temp_sensor1.lowlimit.get=-19"
"rffe.ch1_sensor.config.temp_sensor1.highlimit.get=76"
"rffe.ch1_sensor.config.temp_sensor1.critlimit.get=81"
"rffe.ch1_sensor.config.current_sensor1.currlimiti.get=1467"
"rffe.ch2_sensor.config.temp_sensor1.lowlimit.get=-19"
"rffe.ch2_sensor.config.temp_sensor1.highlimit.get=76"
"rffe.ch2_sensor.config.temp_sensor1.critlimit.get=81"
"rffe.ch2_sensor.config.current_sensor1.currlimit.get=510"
"rffe.ch1_fe.config.ch1_band.band.get=3"
"rffe.ch1_fe.config.tx.atten.get=60"
"rffe.ch1_fe.config.rx.atten.get=20"
"rffe.ch2_fe.config.ch2_band.band.get=3"
"rffe.ch2_fe.config.tx.atten.get=60"
"rffe.ch2_fe.config.rx.atten.get=20")
rfStatusParam=("rffe.ch1_sensor.status.temp_sensor1.temperature.get"
"rffe.ch1_sensor.status.current_sensor1.busvoltage.get"
"rffe.ch1_sensor.status.current_sensor1.shuntvoltage.get"
"rffe.ch1_sensor.status.current_sensor1.current.get"
"rffe.ch1_sensor.status.current_sensor1.power.get"
"rffe.ch2_sensor.status.temp_sensor1.temperature.get"
"rffe.ch2_sensor.status.current_sensor1.busvoltage.get"
"rffe.ch2_sensor.status.current_sensor1.shuntvoltage.get"
"rffe.ch2_sensor.status.current_sensor1.current.get"
"rffe.ch2_sensor.status.current_sensor1.power.get"
"rffe.ch1_fe.status.power.forward.get"
"rffe.ch1_fe.status.power.reverse.get"
"rffe.ch2_fe.status.power.forward.get"
"rffe.ch2_fe.status.power.reverse.get")
rfStatusMinVal=(10 5500 2800 1400 7700 10 5500 2800 1400 7700 0 0 0 0)
rfStatusMaxVal=(80 5900 4200 2100 12390 80 5900 4200 2100 12390 10 10 10 10)
powerParam=("power.leadacid_sensor.config.temp_sensor1.lowlimit.get"
"power.leadacid_sensor.config.temp_sensor1.highlimit.get"
"power.leadacid_sensor.config.temp_sensor1.critlimit.get"
"power.leadacid.config.battery.batteryVoltageLow.get"
"power.leadacid.config.battery.batteryVoltageHigh.get"
"power.leadacid.config.battery.batteryCurrentLow.get"
"power.leadacid.config.battery.inputVoltageLow.get"
"power.leadacid.config.battery.inputCurrentHigh.get"
"power.leadacid.config.battery.inputCurrentLimit.get"
"power.lion.config.battery.batteryVoltageLow.get"
"power.lion.config.battery.batteryVoltageHigh.get"
"power.lion.config.battery.batteryCurrentLow.get"
"power.lion.config.battery.inputVoltageLow.get"
"power.lion.config.battery.inputCurrentHigh.get"
"power.lion.config.battery.inputCurrentLimit.get"
"power.pse.config.operatingMode.get"
"power.pse.config.detectEnable.get"
"power.pse.config.interruptMask.get"
"power.pse.config.interruptEnable.get"
"power.pse.config.enableHighpower.get")
defaultPower=("power.leadacid_sensor.config.temp_sensor1.lowlimit.get=-20"
"power.leadacid_sensor.config.temp_sensor1.highlimit.get=75"
"power.leadacid_sensor.config.temp_sensor1.critlimit.get=80"
"power.leadacid.config.battery.batteryVoltageLow.get=12666"
"power.leadacid.config.battery.batteryVoltageHigh.get=16799"
"power.leadacid.config.battery.batteryCurrentLow.get=999"
"power.leadacid.config.battery.inputVoltageLow.get=16199"
"power.leadacid.config.battery.inputCurrentHigh.get=17499"
"power.leadacid.config.battery.inputCurrentLimit.get=16000"
"power.lion.config.battery.batteryVoltageLow.get=9499"
"power.lion.config.battery.batteryVoltageHigh.get=12599"
"power.lion.config.battery.batteryCurrentLow.get=99"
"power.lion.config.battery.inputVoltageLow.get=16199"
"power.lion.config.battery.inputCurrentHigh.get=4999"
"power.lion.config.battery.inputCurrentLimit.get=4571"
"power.pse.config.operatingMode.get=17"
"power.pse.config.detectEnable.get=17"
"power.pse.config.interruptMask.get=17"
"power.pse.config.interruptEnable.get=17"
"power.pse.config.enableHighpower.get=17")
setPowerVal=("power.leadacid_sensor.config.temp_sensor1.lowlimit.get=-19"
"power.leadacid_sensor.config.temp_sensor1.highlimit.get=76"
"power.leadacid_sensor.config.temp_sensor1.critlimit.get=81"
"power.leadacid.config.battery.batteryVoltageLow.get=12499"
"power.leadacid.config.battery.batteryVoltageHigh.get=16499"
"power.leadacid.config.battery.batteryCurrentLow.get=899"
"power.leadacid.config.battery.inputVoltageLow.get=16209"
"power.leadacid.config.battery.inputCurrentHigh.get=17399"
"power.leadacid.config.battery.inputCurrentLimit.get=15000"
"power.lion.config.battery.batteryVoltageLow.get=9009"
"power.lion.config.battery.batteryVoltageHigh.get=12699"
"power.lion.config.battery.batteryCurrentLow.get=109"
"power.lion.config.battery.inputVoltageLow.get=16209"
"power.lion.config.battery.inputCurrentHigh.get=5009"
"power.lion.config.battery.inputCurrentLimit.get=3571"
"power.pse.config.operatingMode.get=3"
"power.pse.config.detectEnable.get=64"
"power.pse.config.interruptMask.get=195"
"power.pse.config.interruptEnable.get=128"
"power.pse.config.enableHighpower.get=17")
ethParam=("ethernet.port0.config.speed.get"
"ethernet.port0.config.duplex.get"
"ethernet.port0.config.powerDown.get"
"ethernet.port0.config.enable_sleepMode.get"
"ethernet.port0.config.enable_interrupt.get"
"ethernet.port1.config.speed.get"
"ethernet.port1.config.duplex.get"
"ethernet.port1.config.powerDown.get"
"ethernet.port1.config.enable_sleepMode.get"
"ethernet.port1.config.enable_interrupt.get"
"ethernet.port2.config.speed.get"
"ethernet.port2.config.duplex.get"
"ethernet.port2.config.powerDown.get"
"ethernet.port2.config.enable_sleepMode.get"
"ethernet.port2.config.enable_interrupt.get"
"ethernet.port3.config.speed.get"
"ethernet.port3.config.duplex.get"
"ethernet.port3.config.powerDown.get"
"ethernet.port3.config.enable_sleepMode.get"
"ethernet.port3.config.enable_interrupt.get"
"ethernet.port4.config.speed.get"
"ethernet.port4.config.duplex.get"
"ethernet.port4.config.powerDown.get"
"ethernet.port4.config.enable_sleepMode.get"
"ethernet.port4.config.enable_interrupt.get")
defaultEth=("ethernet.port0.config.speed.get=2"
"ethernet.port0.config.duplex.get=2"
"ethernet.port0.config.powerDown.get=0"
"ethernet.port0.config.enable_sleepMode.get=0"
"ethernet.port0.config.enable_interrupt.get=0"
"ethernet.port1.config.speed.get=2"
"ethernet.port1.config.duplex.get=2"
"ethernet.port1.config.powerDown.get=0"
"ethernet.port1.config.enable_sleepMode.get=0"
"ethernet.port1.config.enable_interrupt.get=0"
"ethernet.port2.config.speed.get=2"
"ethernet.port2.config.duplex.get=2"
"ethernet.port2.config.powerDown.get=0"
"ethernet.port2.config.enable_sleepMode.get=0"
"ethernet.port2.config.enable_interrupt.get=0"
"ethernet.port3.config.speed.get=2"
"ethernet.port3.config.duplex.get=2"
"ethernet.port3.config.powerDown.get=0"
"ethernet.port3.config.enable_sleepMode.get=0"
"ethernet.port3.config.enable_interrupt.get=0"
"ethernet.port4.config.speed.get=2"
"ethernet.port4.config.duplex.get=2"
"ethernet.port4.config.powerDown.get=0"
"ethernet.port4.config.enable_sleepMode.get=0"
"ethernet.port4.config.enable_interrupt.get=0")
setEthVal=("ethernet.port0.config.speed.get=2"
"ethernet.port0.config.duplex.get=2"
"ethernet.port0.config.powerDown.get=0"
"ethernet.port0.config.enable_sleepMode.get=1"
"ethernet.port0.config.enable_interrupt.get=0"
"ethernet.port1.config.speed.get=1"
"ethernet.port1.config.duplex.get=0"
"ethernet.port1.config.powerDown.get=1"
"ethernet.port1.config.enable_sleepMode.get=0"
"ethernet.port1.config.enable_interrupt.get=0"
"ethernet.port2.config.speed.get=1"
"ethernet.port2.config.duplex.get=1"
"ethernet.port2.config.powerDown.get=1"
"ethernet.port2.config.enable_sleepMode.get=1"
"ethernet.port2.config.enable_interrupt.get=0"
"ethernet.port3.config.speed.get=1"
"ethernet.port3.config.duplex.get=0"
"ethernet.port3.config.powerDown.get=0"
"ethernet.port3.config.enable_sleepMode.get=1"
"ethernet.port3.config.enable_interrupt.get=0"
"ethernet.port4.config.speed.get=1"
"ethernet.port4.config.duplex.get=1"
"ethernet.port4.config.powerDown.get=1"
"ethernet.port4.config.enable_sleepMode.get=1"
"ethernet.port4.config.enable_interrupt.get=0")
ethernetStatusParam=("ethernet.port0.status.speed.get"
"ethernet.port0.status.duplex.get"
"ethernet.port1.status.speed.get"
"ethernet.port1.status.duplex.get"
"ethernet.port2.status.speed.get"
"ethernet.port2.status.duplex.get"
"ethernet.port3.status.speed.get"
"ethernet.port3.status.duplex.get"
"ethernet.port4.status.speed.get"
"ethernet.port4.status.duplex.get")
ethernetStatusMinVal=(1 1 1 1 1 1 1 1 1 1)
ethernetStatusMaxVal=(1 1 1 1 1 1 1 1 1 1)
syncParam=("sync.sensor.config.temp_sensor1.lowlimit.get"
"sync.sensor.config.temp_sensor1.highlimit.get"
"sync.sensor.config.temp_sensor1.critlimit.get")
defaultSync=("sync.sensor.config.temp_sensor1.lowlimit.get=-20"
"sync.sensor.config.temp_sensor1.highlimit.get=80"
"sync.sensor.config.temp_sensor1.critlimit.get=85")
setSyncVal=("sync.sensor.config.temp_sensor1.lowlimit.get=-19"
"sync.sensor.config.temp_sensor1.highlimit.get=81"
"sync.sensor.config.temp_sensor1.critlimit.get=86")
syncStatusParam=("sync.sensor.status.temp_sensor1.temperature.get")
syncStatusMinVal=(-20)
syncStatusMaxVal=(80)
debugI2CParam=("debug.I2C.bus0.get 104 2 58"
"debug.I2C.bus1.get 24 2 2"
"debug.I2C.bus2.get 29 1 0"
"debug.I2C.bus3.get 68 2 255"
"debug.I2C.bus4.get 65 2 254"
"debug.I2C.bus6.get 64 2 5"
"debug.I2C.bus7.get 69 2 5"
"debug.I2C.bus8.get 26 2 6")
defaultDebugI2C=("debug.I2C.bus0(slaveaddress:104noOfBytes:2RegisterAddress:58)get=9984"
"debug.I2C.bus1(slaveaddress:24noOfBytes:2RegisterAddress:2)get=1216"
"debug.I2C.bus2(slaveaddress:29noOfBytes:1RegisterAddress:0)get=115"
"debug.I2C.bus3(slaveaddress:68noOfBytes:2RegisterAddress:255)get=8800"
"debug.I2C.bus4(slaveaddress:65noOfBytes:2RegisterAddress:254)get=21577"
"debug.I2C.bus6(slaveaddress:64noOfBytes:2RegisterAddress:5)get=25600"
"debug.I2C.bus7(slaveaddress:69noOfBytes:2RegisterAddress:5)get=25600"
"debug.I2C.bus8(slaveaddress:26noOfBytes:2RegisterAddress:6)get=0")
setDebugI2CVal=("debug.I2C.bus0(slaveaddress:104noOfBytes:2RegisterAddress:58)get=7000"
"debug.I2C.bus1(slaveaddress:24noOfBytes:2RegisterAddress:2)get=1024"
"debug.I2C.bus2(slaveaddress:29noOfBytes:1RegisterAddress:0)get=100"
"debug.I2C.bus3(slaveaddress:68noOfBytes:2RegisterAddress:255)get=8000"
"debug.I2C.bus4(slaveaddress:65noOfBytes:2RegisterAddress:254)get=21500"
"debug.I2C.bus6(slaveaddress:64noOfBytes:2RegisterAddress:5)get=25500"
"debug.I2C.bus7(slaveaddress:69noOfBytes:2RegisterAddress:5)get=25500"
"debug.I2C.bus8(slaveaddress:26noOfBytes:2RegisterAddress:6)get=4000")
debugGpioParam=("debug.ec.PA.get 1"
"debug.ec.PB.get 1"
"debug.ec.PC.get 1"
"debug.ec.PD.get 7"
"debug.ec.PE.get 1"
"debug.ec.PF.get 1"
"debug.ec.PG.get 1"
"debug.ec.PH.get 1"
"debug.ec.PJ.get 1"
"debug.ec.PK.get 1"
"debug.ec.PL.get 5"
"debug.ec.PM.get 1"
"debug.ec.PN.get 1"
"debug.ec.PP.get 3"
"debug.ec.PQ.get 1"
"debug.gbc.ioexpanderx70.get 1"
"debug.gbc.ioexpanderx71.get 0"
"debug.sdr.ioexpanderx1E.get 1"
"debug.fe.ioexpanderx18.get 1"
"debug.fe.ioexpanderx1A.get 0"
"debug.fe.ioexpanderx1B.get 1"
"debug.fe.ioexpanderx1C.get 1"
"debug.fe.ioexpanderx1D.get 1"
"debug.sync.ioexpanderx71.get 1")
defaultDebugGpio=("debug.ec.PA(PinNo:1)get=0"
"debug.ec.PB(PinNo:1)get=0"
"debug.ec.PC(PinNo:1)get=0"
"debug.ec.PD(PinNo:7)get=1"
"debug.ec.PE(PinNo:1)get=1"
"debug.ec.PF(PinNo:1)get=0"
"debug.ec.PG(PinNo:1)get=0"
"debug.ec.PH(PinNo:1)get=0"
"debug.ec.PJ(PinNo:1)get=0"
"debug.ec.PK(PinNo:1)get=0"
"debug.ec.PL(PinNo:5)get=0"
"debug.ec.PM(PinNo:1)get=0"
"debug.ec.PN(PinNo:1)get=0"
"debug.ec.PP(PinNo:3)get=0"
"debug.ec.PQ(PinNo:1)get=1"
"debug.gbc.ioexpanderx70(PinNo:1)get=1"
"debug.gbc.ioexpanderx71(PinNo:0)get=1"
"debug.sdr.ioexpanderx1E(PinNo:1)get=1"
"debug.fe.ioexpanderx18(PinNo:1)get=1"
"debug.fe.ioexpanderx1A(PinNo:0)get=1"
"debug.fe.ioexpanderx1B(PinNo:1)get=1"
"debug.fe.ioexpanderx1C(PinNo:1)get=1"
"debug.fe.ioexpanderx1D(PinNo:1)get=0"
"debug.sync.ioexpanderx71(PinNo:1)get=0")
setDebugGpioVal=("debug.ec.PA(PinNo:1)get=1"
"debug.ec.PB(PinNo:1)get=1"
"debug.ec.PC(Pin No:1)get=1"
"debug.ec.PD(Pin No:7)get=0"
"debug.ec.PE(Pin No:1)get=0"
"debug.ec.PF(PinNo:1)get=1"
"debug.ec.PG(Pin No:1)get=1"
"debug.ec.PH(PinNo:1)get=1"
"debug.ec.PJ(PinNo:1)get=1"
"debug.ec.PK(PinNo:1)get=1"
"debug.ec.PL(PinNo:5)get=1"
"debug.ec.PM(PinNo:1)get=0"
"debug.ec.PN(PinNo:1)get=0"
"debug.ec.PP(PinNo:3)get=0"
"debug.ec.PQ(PinNo:1)get=0"
"debug.gbc.ioexpanderx70(PinNo:1)get=0"
"debug.gbc.ioexpanderx71(PinNo:0)get=0"
"debug.sdr.ioexpanderx1E(PinNo:1)get=0"
"debug.fe.ioexpanderx18(PinNo:1)get=0"
"debug.fe.ioexpanderx1A(PinNo:0)get=0"
"debug.fe.ioexpanderx1B(PinNo:1)get=0"
"debug.fe.ioexpanderx1C(PinNo:1)get=0"
"debug.fe.ioexpanderx1D(PinNo:1)get=1"
"debug.sync.ioexpanderx71(PinNo:1)get=1")
debugMdioParam=("debug.ethernet.port0.get 18"
"debug.ethernet.global1.get 4"
"debug.ethernet.global2.get 1"
"debug.ethernet.swport0.get 1")
defaultDebugMdio=("debug.ethernet.port0(RegisterAddress:18)get=9216"
"debug.ethernet.global1(RegisterAddress:4)get=1"
"debug.ethernet.global2(RegisterAddress:1)get=0"
"debug.ethernet.swport0(RegisterAddress:1)get=3")
setDebugMdioVal=("debug.ethernet.port0(RegisterAddress:18)get=1024"
"debug.ethernet.global1(RegisterAddress:4)get=128"
"debug.ethernet.global2(RegisterAddress:1)get=31"
"debug.ethernet.swport0(RegisterAddress:1)get=1")
function compareValue() {
local -n paramArray=$1
local -n valueArray=$2
i=0
for index in "${paramArray[@]}"
do
val=${valueArray[$i]}
value=$(../bin/occmd $index)
valueStr=$value
printf -v value '%s' $value
if [ "$value" = "$val" ]; then
echo "${paramArray[$i]} Passed"
echo "$valueStr"
else
echo "${paramArray[$i]} FAILED"
if [[ "$value" =~ "Failed" ]]; then
echo "Failed from TIVA"
else
echo "Value Mismatch"
echo "$valueStr"
fi
fi
((i++))
done
}
function errorPrint() {
if [[ "$1" =~ "Failed" ]]; then
echo "Failed from TIVA"
else
echo "Value not in range: Max=$2 Min=$3 value=$4"
fi
}
function compareStatusValue() {
local -n paramStatusArray=$1
local -n minArray=$2
local -n maxArray=$3
i=0
for index in "${paramStatusArray[@]}"
do
minVal=${minArray[$i]}
maxVal=${maxArray[$i]}
value=$(../bin/occmd $index)
valueStr=$value
printf -v value '%s' $value
IFS='=' read -ra token <<< "$value"
statusVal=${token[1]}
if [[ ("$value" =~ "ethernet") ]]; then
if [[ ($statusVal -eq $maxVal) ]]; then
echo "$valueStr Passed"
else
echo "$valueStr Failed"
errorPrint $value $maxVal $minVal $statusVal
fi
elif [[ ($statusVal -le $maxVal) ]]; then
if [[ ($statusVal -ge $minVal) ]]; then
echo "$valueStr Passed"
else
echo "$valueStr Failed"
errorPrint $value $maxVal $minVal $statusVal
fi
else
echo "$valueStr Failed"
errorPrint $value $maxVal $minVal $statusVal
fi
((i++))
done
}
if [ -z "$1" ]; then
echo "Invalid Option"
echo "Usage : ./get_params <subsystem> <class> <verify/default>"
exit
elif [ $1 = "bms" ]; then
if [ $2 = "config" ]; then
if [ $3 = "default" ]; then
compareValue bmsParam defaultBms
elif [ $3 = "verify" ]; then
compareValue bmsParam setBmsVal
else
echo "Invalid Option"
fi
elif [ $2 = "status" ]; then
compareStatusValue bmsStatusParam bmsStatusMinVal bmsStatusMaxVal
else
echo "Invalid Option"
fi
elif [ $1 = "gpp" ]; then
if [ $2 = "config" ]; then
if [ $3 = "default" ]; then
compareValue gppParam defaultGpp
elif [ $3 = "verify" ]; then
compareValue gppParam setGppVal
else
echo "Invalid Option"
fi
elif [ $2 = "status" ]; then
compareStatusValue gppStatusParam gppStatusMinVal gppStatusMaxVal
else
echo "Invalid Option"
fi
elif [ $1 = "sdr" ]; then
if [ $2 = "config" ]; then
if [ $3 = "default" ]; then
compareValue sdrParam defaultSdr
elif [ $3 = "verify" ]; then
compareValue sdrParam setSdrVal
else
echo "Invalid Option"
fi
elif [ $2 = "status" ]; then
compareStatusValue sdrStatusParam sdrStatusMinVal sdrStatusMaxVal
../bin/occmd sdr.comp_all.status.eeprom.dev_id.get
else
echo "Invalid Option"
fi
elif [ $1 = "rf" ]; then
if [ $2 = "config" ]; then
if [ $3 = "default" ]; then
compareValue rfParam defaultRf
elif [ $3 = "verify" ]; then
compareValue rfParam setRfVal
else
echo "Invalid Option"
fi
elif [ $2 = "status" ]; then
compareStatusValue rfStatusParam rfStatusMinVal rfStatusMaxVal
../bin/occmd rffe.comp_all.status.eeprom.dev_id.get
else
echo "Invalid Option"
fi
elif [ $1 = "power" ]; then
if [ $2 = "config" ]; then
if [ $3 = "default" ]; then
compareValue powerParam defaultPower
elif [ $3 = "verify" ]; then
compareValue powerParam setPowerVal
else
echo "Invalid Option"
fi
elif [ $2 = "status" ]; then
../bin/occmd power.leadacid_sensor.status.temp_sensor1.temperature.get
../bin/occmd power.leadacid.status.battery.batteryVoltage.get
../bin/occmd power.leadacid.status.battery.batteryCurrent.get
../bin/occmd power.leadacid.status.battery.systemVoltage.get
../bin/occmd power.leadacid.status.battery.inputVoltage.get
../bin/occmd power.leadacid.status.battery.inputCurrent.get
../bin/occmd power.leadacid.status.battery.dieTemperature.get
../bin/occmd power.lion.status.battery.batteryVoltage.get
../bin/occmd power.lion.status.battery.batteryCurrent.get
../bin/occmd power.lion.status.battery.systemVoltage.get
../bin/occmd power.lion.status.battery.inputVoltage.get
../bin/occmd power.lion.status.battery.inputCurrent.get
../bin/occmd power.lion.status.battery.dieTemperature.get
../bin/occmd power.pse.status.detection.get
../bin/occmd power.pse.status.class.get
../bin/occmd power.pse.status.powerGood.get
# Commented as of now as PD Driver doesnt have enum values defined
#../bin/occmd power.pd.status.class.get
#../bin/occmd power.pd.status.powerGoodState.get
../bin/occmd power.comp_all.status.powerSource.extBattAccessebility.get
../bin/occmd power.comp_all.status.powerSource.extBattAvailability.get
../bin/occmd power.comp_all.status.powerSource.intBattAccessebility.get
../bin/occmd power.comp_all.status.powerSource.intBattAvailability.get
../bin/occmd power.comp_all.status.powerSource.poeAccessebility.get
../bin/occmd power.comp_all.status.powerSource.poeAvailability.get
../bin/occmd power.comp_all.status.powerSource.solarAccessebility.get
../bin/occmd power.comp_all.status.powerSource.solarAvailability.get
else
echo "Invalid Option"
fi
elif [ $1 = "ethernet" ]; then
if [ $2 = "config" ]; then
if [ $3 = "default" ]; then
compareValue ethParam defaultEth
elif [ $3 = "verify" ]; then
compareValue ethParam setEthVal
else
echo "Invalid Option"
fi
elif [ $2 = "status" ]; then
compareStatusValue ethernetStatusParam ethernetStatusMinVal ethernetStatusMaxVal
../bin/occmd ethernet.port0.status.sleep_mode_en.get
../bin/occmd ethernet.port0.status.autoneg_on.get
../bin/occmd ethernet.port0.status.autoneg_complete.get
../bin/occmd ethernet.port0.status.link_up.get
../bin/occmd ethernet.port1.status.sleep_mode_en.get
../bin/occmd ethernet.port1.status.autoneg_on.get
../bin/occmd ethernet.port1.status.autoneg_complete.get
../bin/occmd ethernet.port1.status.link_up.get
../bin/occmd ethernet.port2.status.sleep_mode_en.get
../bin/occmd ethernet.port2.status.autoneg_on.get
../bin/occmd ethernet.port2.status.autoneg_complete.get
../bin/occmd ethernet.port2.status.link_up.get
../bin/occmd ethernet.port3.status.sleep_mode_en.get
../bin/occmd ethernet.port3.status.autoneg_on.get
../bin/occmd ethernet.port3.status.autoneg_complete.get
../bin/occmd ethernet.port3.status.link_up.get
../bin/occmd ethernet.port4.status.sleep_mode_en.get
../bin/occmd ethernet.port4.status.autoneg_on.get
../bin/occmd ethernet.port4.status.autoneg_complete.get
../bin/occmd ethernet.port4.status.link_up.get
else
echo "Invalid Option"
fi
elif [ $1 = "sync" ]; then
if [ $2 = "config" ]; then
if [ $3 = "default" ]; then
compareValue syncParam defaultSync
elif [ $3 = "verify" ]; then
compareValue syncParam setSyncVal
else
echo "Invalid Option"
fi
elif [ $2 = "status" ]; then
compareStatusValue syncStatusParam syncStatusMinVal syncStatusMaxVal
../bin/occmd sync.gps.status.gps_lock.get
else
echo "Invalid Option"
fi
elif [ $1 = "testmodule" ]; then
if [ $2 = "status" ]; then
../bin/occmd testmodule.2gsim.status.imei.get
../bin/occmd testmodule.2gsim.status.imsi.get
../bin/occmd testmodule.2gsim.status.mfg.get
../bin/occmd testmodule.2gsim.status.model.get
../bin/occmd testmodule.2gsim.status.rssi.get
../bin/occmd testmodule.2gsim.status.ber.get
../bin/occmd testmodule.2gsim.status.registration.get
../bin/occmd testmodule.2gsim.status.network_operatorinfo.get
../bin/occmd testmodule.2gsim.status.cellid.get
../bin/occmd testmodule.2gsim.status.bsic.get
../bin/occmd testmodule.2gsim.status.lasterror.get
else
echo "Invalid Option"
fi
elif [ $1 = "obc" ]; then
if [ $2 = "status" ]; then
../bin/occmd obc.iridium.status.imei.get
../bin/occmd obc.iridium.status.mfg.get
../bin/occmd obc.iridium.status.model.get
../bin/occmd obc.iridium.status.signal_quality.get
../bin/occmd obc.iridium.status.registration.get
../bin/occmd obc.iridium.status.numberofoutgoingmessage.get
../bin/occmd obc.iridium.status.lasterror.get
else
echo "Invalid Option"
fi
elif [ $1 = "hci" ]; then
if [ $2 = "config" ]; then
if [ $3 = "default" ]; then
compareValue hciParam defaultHci
elif [ $3 = "verify" ]; then
compareValue hciParam setHciVal
else
echo "Invalid Option"
fi
elif [ $2 = "status" ]; then
compareStatusValue hciStatusParam hciStatusMinVal hciStatusMaxVal
else
echo "Invalid Option"
fi
elif [ $1 = "system" ]; then
if [ $2 = "status" ]; then
../bin/occmd system.comp_all.status.eeprom_sid.gbcboardinfo.get
../bin/occmd system.comp_all.status.eeprom_sid.ocserialinfo.get
../bin/occmd system.comp_all.config.eeprom_mac.address.get
elif [ $2 = "post" ]; then
../bin/occmd system.comp_all.post.results.get
../bin/occmd system.comp_all.post.enable.set
else
echo "Invalid Option"
fi
elif [ $1 = "debug" ]; then
if [ $2 = "I2C" ]; then
if [ $3 = "default" ]; then
compareValue debugI2CParam defaultDebugI2C
elif [ $3 = "verify" ]; then
compareValue debugI2CParam setDebugI2CVal
else
echo "Invalid Option"
fi
elif [ $2 = "GPIO" ]; then
if [ $3 = "default" ]; then
compareValue debugGpioParam defaultDebugGpio
elif [ $3 = "verify" ]; then
compareValue debugGpioParam setDebugGpioVal
else
echo "Invalid Option"
fi
elif [ $2 = "MDIO" ]; then
if [ $3 = "default" ]; then
compareValue debugMdioParam defaultDebugMdio
elif [ $3 = "verify" ]; then
compareValue debugMdioParam setDebugMdioVal
else
echo "Invalid Option"
fi
else
echo "Invalid Option"
fi
elif [ $1 = "command" ]; then
../bin/occmd system.comp_all.echo
../bin/occmd ethernet.port0.reset
../bin/occmd ethernet.port1.reset
../bin/occmd ethernet.port2.reset
../bin/occmd ethernet.port3.reset
../bin/occmd ethernet.port4.reset
#../bin/occmd power.pse.reset
../bin/occmd rffe.comp_all.reset
../bin/occmd hci.led.fw.set 1
../bin/occmd rffe.ch1_fe.enable
../bin/occmd rffe.ch1_fe.disable
../bin/occmd rffe.ch2_fe.disable
../bin/occmd rffe.ch2_fe.enable
../bin/occmd testmodule.2gsim.enable
../bin/occmd testmodule.2gsim.disable
../bin/occmd testmodule.2gsim.disconnect_nw
../bin/occmd testmodule.2gsim.connect_nw
../bin/occmd testmodule.2gsim.send 9789799425 hi
../bin/occmd testmodule.2gsim.dial 9789799425
../bin/occmd testmodule.2gsim.answer
../bin/occmd testmodule.2gsim.hangup
../bin/occmd testmodule.comp_all.reset
../bin/occmd sdr.comp_all.reset
../bin/occmd sdr.fx3.reset
../bin/occmd obc.iridium.reset
../bin/occmd sync.comp_all.reset
../bin/occmd ethernet.port0.en_loopBk 0
../bin/occmd ethernet.port0.en_pktGen 8374
../bin/occmd ethernet.port0.dis_pktGen
../bin/occmd ethernet.port0.dis_loopBk 0
../bin/occmd ethernet.port1.en_loopBk 0
../bin/occmd ethernet.port1.en_pktGen 8374
../bin/occmd ethernet.port1.dis_pktGen
../bin/occmd ethernet.port1.dis_loopBk 0
../bin/occmd ethernet.port2.en_loopBk 0
../bin/occmd ethernet.port2.en_pktGen 8374
../bin/occmd ethernet.port2.dis_pktGen
../bin/occmd ethernet.port2.dis_loopBk 0
../bin/occmd ethernet.port3.en_loopBk 0
../bin/occmd ethernet.port3.en_pktGen 8374
../bin/occmd ethernet.port3.dis_pktGen
../bin/occmd ethernet.port3.dis_loopBk 0
../bin/occmd ethernet.port4.en_loopBk 0
../bin/occmd ethernet.port4.en_pktGen 8374
../bin/occmd ethernet.port4.dis_pktGen
../bin/occmd ethernet.port4.dis_loopBk 0
else
echo "Invalid Option"
fi
echo "Done..."

View File

@@ -0,0 +1,198 @@
#!/bin/sh
if [ -z "$1" ]; then
echo "Invalid Option"
echo "Usage : ./set_config_params <subsystem>"
exit
elif [ $1 = "post" ]; then
../bin/occmd system.comp_all.post.test.enable.set
elif [ $1 = "bms" ]; then
../bin/occmd bms.ec.config.temp_sensor1.lowlimit.set -19
../bin/occmd bms.ec.config.temp_sensor1.highlimit.set 76
../bin/occmd bms.ec.config.temp_sensor1.critlimit.set 85
../bin/occmd bms.ec.config.current_sensor1.currlimit.set 1500
../bin/occmd bms.ec.config.current_sensor2.currlimit.set 1500
elif [ $1 = "gpp" ]; then
../bin/occmd gpp.ap.config.temp_sensor1.lowlimit.set -19
../bin/occmd gpp.ap.config.temp_sensor1.highlimit.set 81
../bin/occmd gpp.ap.config.temp_sensor1.critlimit.set 86
../bin/occmd gpp.ap.config.temp_sensor2.lowlimit.set -19
../bin/occmd gpp.ap.config.temp_sensor2.highlimit.set 81
../bin/occmd gpp.ap.config.temp_sensor2.critlimit.set 86
../bin/occmd gpp.ap.config.current_sensor1.currlimit.set 2010
../bin/occmd gpp.ap.config.temp_sensor3.lowlimit.set -19
../bin/occmd gpp.ap.config.temp_sensor3.highlimit.set 81
../bin/occmd gpp.ap.config.temp_sensor3.critlimit.set 86
../bin/occmd gpp.msata.config.current_sensor1.currlimit.set 2010
elif [ $1 = "sdr" ]; then
../bin/occmd sdr.comp_all.config.current_sensor1.currlimit.set 2010
../bin/occmd sdr.fpga.config.temp_sensor1.lowlimit.set -19
../bin/occmd sdr.fpga.config.temp_sensor1.highlimit.set 76
../bin/occmd sdr.fpga.config.temp_sensor1.critlimit.set 81
../bin/occmd sdr.fpga.config.current_sensor1.currlimit.set 510
elif [ $1 = "rf" ]; then
../bin/occmd rffe.ch1_sensor.config.temp_sensor1.lowlimit.set -19
../bin/occmd rffe.ch1_sensor.config.temp_sensor1.highlimit.set 76
../bin/occmd rffe.ch1_sensor.config.temp_sensor1.critlimit.set 81
../bin/occmd rffe.ch1_sensor.config.current_sensor1.currlimit.set 1500
../bin/occmd rffe.ch2_sensor.config.temp_sensor1.lowlimit.set -19
../bin/occmd rffe.ch2_sensor.config.temp_sensor1.highlimit.set 76
../bin/occmd rffe.ch2_sensor.config.temp_sensor1.critlimit.set 81
../bin/occmd rffe.ch2_sensor.config.current_sensor1.currlimit.set 510
../bin/occmd rffe.ch1_fe.config.ch1_band.band.set 3
../bin/occmd rffe.ch1_fe.config.tx.atten.set 60
../bin/occmd rffe.ch1_fe.config.rx.atten.set 20
../bin/occmd rffe.ch2_fe.config.tx.atten.set 60
../bin/occmd rffe.ch2_fe.config.rx.atten.set 20
../bin/occmd rffe.ch2_fe.config.ch2_band.band.set 3
elif [ $1 = "power" ]; then
../bin/occmd power.leadacid_sensor.config.temp_sensor1.lowlimit.set -19
../bin/occmd power.leadacid_sensor.config.temp_sensor1.highlimit.set 76
../bin/occmd power.leadacid_sensor.config.temp_sensor1.critlimit.set 81
../bin/occmd power.leadacid.config.battery.batteryVoltageLow.set 12500
../bin/occmd power.leadacid.config.battery.batteryVoltageHigh.set 16500
../bin/occmd power.leadacid.config.battery.batteryCurrentLow.set 900
../bin/occmd power.leadacid.config.battery.inputVoltageLow.set 16210
../bin/occmd power.leadacid.config.battery.inputCurrentHigh.set 17400
../bin/occmd power.leadacid.config.battery.inputCurrentLimit.set 15000
#../bin/occmd power.leadacid.config.battery.maxcurr_chargesetting.set 10000
../bin/occmd power.leadacid.config.battery.vcharge.set 10660
../bin/occmd power.leadacid.config.battery.icharge.set 12000
../bin/occmd power.lion.config.battery.batteryVoltageLow.set 9010
../bin/occmd power.lion.config.battery.batteryVoltageHigh.set 12700
../bin/occmd power.lion.config.battery.batteryCurrentLow.set 110
../bin/occmd power.lion.config.battery.inputVoltageLow.set 16210
../bin/occmd power.lion.config.battery.inputCurrentHigh.set 5010
../bin/occmd power.lion.config.battery.inputCurrentLimit.set 3580
../bin/occmd power.lion.config.battery.vcharge.set 10660
../bin/occmd power.lion.config.battery.icharge.set 12000
../bin/occmd power.pse.config.operatingMode.set 3
../bin/occmd power.pse.config.detectEnable.set 64
../bin/occmd power.pse.config.interruptMask.set 195
../bin/occmd power.pse.config.interruptEnable.set 128
../bin/occmd power.pse.config.enableHighpower.set 17
elif [ $1 = "ethernet" ]; then
../bin/occmd ethernet.port0.config.speed.set 0
../bin/occmd ethernet.port0.config.duplex.set 2
../bin/occmd ethernet.port0.config.powerDown.set 0
../bin/occmd ethernet.port0.config.enable_sleepMode.set 1
../bin/occmd ethernet.port0.config.enable_interrupt.set 10
../bin/occmd ethernet.port1.config.speed.set 1
../bin/occmd ethernet.port1.config.duplex.set 0
../bin/occmd ethernet.port1.config.powerDown.set 1
../bin/occmd ethernet.port1.config.enable_sleepMode.set 0
../bin/occmd ethernet.port1.config.enable_interrupt.set 1
../bin/occmd ethernet.port2.config.speed.set 1
../bin/occmd ethernet.port2.config.duplex.set 1
../bin/occmd ethernet.port2.config.powerDown.set 1
../bin/occmd ethernet.port2.config.enable_sleepMode.set 1
../bin/occmd ethernet.port2.config.enable_interrupt.set 0
../bin/occmd ethernet.port3.config.speed.set 1
../bin/occmd ethernet.port3.config.duplex.set 0
../bin/occmd ethernet.port3.config.powerDown.set 0
../bin/occmd ethernet.port3.config.enable_sleepMode.set 1
../bin/occmd ethernet.port3.config.enable_interrupt.set 1
../bin/occmd ethernet.port4.config.speed.set 1
../bin/occmd ethernet.port4.config.duplex.set 1
../bin/occmd ethernet.port4.config.powerDown.set 1
../bin/occmd ethernet.port4.config.enable_sleepMode.set 1
../bin/occmd ethernet.port4.config.enable_interrupt.set 1
elif [ $1 = "sync" ]; then
../bin/occmd sync.sensor.config.temp_sensor1.lowlimit.set -19
../bin/occmd sync.sensor.config.temp_sensor1.highlimit.set 81
../bin/occmd sync.sensor.config.temp_sensor1.critlimit.set 86
elif [ $1 = "hci" ]; then
../bin/occmd hci.led.config.temp_sensor1.lowlimit.set -19
../bin/occmd hci.led.config.temp_sensor1.highlimit.set 76
../bin/occmd hci.led.config.temp_sensor1.critlimit.set 85
elif [ $1 = "debug" ]; then
if [ $2 = "I2C" ]; then
if [ $3 = "stub" ]; then
../bin/occmd debug.I2C.bus0.set 1 1 1 1
../bin/occmd debug.I2C.bus1.set 1 1 1 1024
../bin/occmd debug.I2C.bus2.set 1 1 1 2
../bin/occmd debug.I2C.bus3.set 1 1 1 1025
../bin/occmd debug.I2C.bus4.set 1 1 1 3
../bin/occmd debug.I2C.bus6.set 1 1 1 4
../bin/occmd debug.I2C.bus7.set 1 1 1 1027
../bin/occmd debug.I2C.bus8.set 1 1 1 5
elif [ $3 = "FW" ]; then
../bin/occmd debug.I2C.bus0.set 104 2 58 7000
../bin/occmd debug.I2C.bus1.set 24 2 2 1024
../bin/occmd debug.I2C.bus2.set 29 1 0 100
../bin/occmd debug.I2C.bus3.set 68 2 255 8000
../bin/occmd debug.I2C.bus4.set 65 2 254 21500
../bin/occmd debug.I2C.bus6.set 64 2 5 25500
../bin/occmd debug.I2C.bus7.set 69 2 5 25500
../bin/occmd debug.I2C.bus8.set 26 2 6 4000
else
echo "Invalid Option"
fi
elif [ $2 = "GPIO" ]; then
if [ $3 = "stub" ]; then
../bin/occmd debug.ec.PA.set 1 1
../bin/occmd debug.ec.PB.set 1 1
../bin/occmd debug.ec.PC.set 1 1
../bin/occmd debug.ec.PD.set 1 0
../bin/occmd debug.ec.PE.set 1 0
../bin/occmd debug.ec.PF.set 1 1
../bin/occmd debug.ec.PG.set 1 1
../bin/occmd debug.ec.PJ.set 1 1
../bin/occmd debug.ec.PK.set 1 1
../bin/occmd debug.ec.PL.set 1 1
../bin/occmd debug.ec.PM.set 1 0
../bin/occmd debug.ec.PN.set 1 0
../bin/occmd debug.ec.PP.set 1 0
../bin/occmd debug.ec.PQ.set 1 0
../bin/occmd debug.gbc.ioexpanderx70.set 1 0
../bin/occmd debug.gbc.ioexpanderx71.set 1 0
../bin/occmd debug.sdr.ioexpanderx1E.set 1 0
../bin/occmd debug.fe.ioexpanderx18.set 1 0
../bin/occmd debug.fe.ioexpanderx1A.set 1 1
../bin/occmd debug.fe.ioexpanderx1B.set 1 0
../bin/occmd debug.fe.ioexpanderx1C.set 1 0
../bin/occmd debug.fe.ioexpanderx1D.set 1 1
../bin/occmd debug.sync.ioexpanderx71.set 1 1
elif [ $3 = "FW" ]; then
../bin/occmd debug.ec.PA.set 1 1
../bin/occmd debug.ec.PB.set 1 1
../bin/occmd debug.ec.PC.set 1 1
../bin/occmd debug.ec.PD.set 7 0
../bin/occmd debug.ec.PE.set 1 0
../bin/occmd debug.ec.PF.set 1 1
../bin/occmd debug.ec.PG.set 1 1
../bin/occmd debug.ec.PH.set 1 1
../bin/occmd debug.ec.PJ.set 1 1
../bin/occmd debug.ec.PK.set 1 1
../bin/occmd debug.ec.PL.set 5 1
../bin/occmd debug.ec.PM.set 1 0
../bin/occmd debug.ec.PN.set 1 0
../bin/occmd debug.ec.PP.set 3 0
../bin/occmd debug.ec.PQ.set 1 0
../bin/occmd debug.gbc.ioexpanderx70.set 1 0
../bin/occmd debug.gbc.ioexpanderx71.set 0 0
../bin/occmd debug.sdr.ioexpanderx1E.set 1 0
../bin/occmd debug.fe.ioexpanderx18.set 1 0
../bin/occmd debug.fe.ioexpanderx1A.set 0 1
../bin/occmd debug.fe.ioexpanderx1B.set 1 0
../bin/occmd debug.fe.ioexpanderx1C.set 1 0
../bin/occmd debug.fe.ioexpanderx1D.set 1 1
../bin/occmd debug.sync.ioexpanderx71.set 1 1
else
echo "Invalid Option"
fi
elif [ $2 = "MDIO" ]; then
../bin/occmd debug.ethernet.port0.set 18 1024
../bin/occmd debug.ethernet.global1.set 4 128
../bin/occmd debug.ethernet.global2.set 1 31
../bin/occmd debug.ethernet.swport0.set 1 1
else
echo "Invalid Option"
fi
else
echo "Invalid Option"
fi
echo "Done..."

View File

@@ -0,0 +1,85 @@
#!/bin/sh
echo "##############################"
echo " GET CONFIG PARAMS - 1 "
echo "##############################"
./get_params.sh bms config default
./get_params.sh gpp config default
./get_params.sh sdr config default
./get_params.sh rf config default
./get_params.sh power config default
./get_params.sh ethernet config default
./get_params.sh sync config default
./get_params.sh hci config default
echo "##############################"
echo " SET CONFIG PARAMS "
echo "##############################"
./set_config_params.sh bms
./set_config_params.sh gpp
./set_config_params.sh sdr
./set_config_params.sh rf
./set_config_params.sh power
./set_config_params.sh ethernet
./set_config_params.sh sync
./set_config_params.sh hci
echo "##############################"
echo " GET CONFIG PARAMS - 2 "
echo "##############################"
./get_params.sh bms config verify
./get_params.sh gpp config verify
./get_params.sh sdr config verify
./get_params.sh rf config verify
./get_params.sh power config verify
./get_params.sh ethernet config verify
./get_params.sh sync config verify
./get_params.sh hci config verify
echo "##############################"
echo " POST COMMANDS "
echo "##############################"
./get_params.sh system post
echo "##############################"
echo " GET STATUS PARAMS "
echo "##############################"
./get_params.sh bms status
./get_params.sh gpp status
./get_params.sh sdr status
./get_params.sh rf status
./get_params.sh power status
./get_params.sh ethernet status
./get_params.sh sync status
./get_params.sh testmodule status
./get_params.sh obc status
./get_params.sh hci status
./get_params.sh system status
echo "##############################"
echo " GET COMMANDS - 1 "
echo "##############################"
./get_params.sh command
echo "##############################"
echo " GET DEBUG COMMANDS - 1 "
echo "##############################"
./get_params.sh debug I2C default
./get_params.sh debug GPIO default
./get_params.sh debug MDIO default
echo "##############################"
echo " SET DEBUG COMMANDS "
echo "##############################"
./set_config_params.sh debug I2C FW
./set_config_params.sh debug GPIO FW
./set_config_params.sh debug MDIO
echo "##############################"
echo " GET DEBUG COMMANDS - 2 "
echo "##############################"
./get_params.sh debug I2C verify
./get_params.sh debug GPIO verify
./get_params.sh debug MDIO verify
echo " >>> TESTING DONE <<< "

View File

@@ -0,0 +1,35 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/* OC includes */
#include <logger.h>
/**************************************************************************
* Function Name : initlog
* Description : This Function used to initialize the logging
* functionality
* Input(s) : ident
* Output(s) :
***************************************************************************/
void initlog(const char* ident)
{
openlog(ident, LOG_CONS | LOG_PID, LOG_USER);
}
/**************************************************************************
* Function Name : deinitlog
* Description : This Function used to uninitialize logging
* functionality
* Input(s) :
* Output(s) :
***************************************************************************/
void deinitlog(void)
{
closelog();
}

29
firmware/host/util/util.c Normal file
View File

@@ -0,0 +1,29 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/* stdlib includes */
#include <stdio.h>
#include <util.h>
#define UTIL_NUMBER_ZERO 0
void hexdisp(const unsigned char* buf, int buflen)
{
int c=UTIL_NUMBER_ZERO, i=UTIL_NUMBER_ZERO;
for (c=UTIL_NUMBER_ZERO; c<buflen; c++) {
printf("0x%02x ", buf[c]);
if ((c+1)%8 == UTIL_NUMBER_ZERO) {
printf("\t");
for(i=(c+1)-8; i<=(c+1); i++)
printf("%c", (buf[i]>0x20 && buf[i]<0x7F) ? buf[i] : '.');
printf("\n");
}
}
printf("\n");
}